8 #include "resourcesconfig.h"
16 #include <sys/param.h>
27 #if defined(HPUX_10) || defined(HPUX_9)
29 extern "C" int setenv(
const char *
name,
const char *value,
int overwrite);
40 #define SINGULAR_DEFAULT_DIR PREFIX
59 "%r/share/singular/LIB;"
60 "%b/../share/singular/LIB;"
62 "%D/singular/factory;"
63 "%r/share/singular/factory;"
65 "%b/../share/singular/factory;"
68 "%r/lib/singular/MOD;"
70 LIB_DIR
"/singular/MOD;"
71 LIBEXEC_DIR
"/singular/MOD;"
74 {
"Singular",
'S',
feResBinary,
"SINGULAR_EXECUTABLE",
"%d/Singular", (
char *)
""},
75 {
"BinDir",
'b',
feResDir,
"SINGULAR_BIN_DIR",
"", (
char *)
""},
77 {
"ProcDir",
'P',
feResPath,
"SINGULAR_PROCS_DIR",
79 "%r/lib/singular/MOD;"
81 LIB_DIR
"/singular/MOD;"
82 LIBEXEC_DIR
"/singular/MOD" , (
char *)
""},
83 {
"RootDir",
'r',
feResDir,
"SINGULAR_ROOT_DIR",
"%b/..", (
char *)
""},
84 {
"DataDir",
'D',
feResDir,
"SINGULAR_DATA_DIR",
"%b/../share/", (
char *)
""},
86 {
"InfoFile",
'i',
feResFile,
"SINGULAR_INFO_FILE",
"%D/info/singular.hlp", (
char *)
""},
87 {
"IdxFile",
'x',
feResFile,
"SINGULAR_IDX_FILE",
"%D/doc/singular.idx", (
char *)
""},
88 {
"HtmlDir",
'h',
feResDir,
"SINGULAR_HTML_DIR",
"%D/singular/html", (
char *)
""},
89 {
"ManualUrl",
'u',
feResUrl,
"SINGULAR_URL",
"http://www.singular.uni-kl.de/Manual/", (
char *)
""},
90 {
"ExDir",
'm',
feResDir,
"SINGULAR_EXAMPLES_DIR",
"%r/examples", (
char *)
""},
93 {
"emacs",
'E',
feResBinary,
"ESINGULAR_EMACS",
"%b/emacs", (
char *)
""},
94 {
"xemacs",
'A',
feResBinary,
"ESINGULAR_EMACS",
"%b/xemacs", (
char *)
""},
95 {
"SingularEmacs",
'M',
feResBinary,
"ESINGULAR_SINGULAR",
"%b/Singular", (
char *)
""},
96 {
"EmacsLoad",
'l',
feResFile,
"ESINGULAR_EMACS_LOAD",
"%e/.emacs-singular", (
char *)
""},
97 {
"EmacsDir",
'e',
feResDir,
"ESINGULAR_EMACS_DIR",
"%D/singular/emacs", (
char *)
""},
98 {
"SingularXterm",
'M',
feResBinary,
"TSINGULAR_SINGULAR",
"%b/Singular", (
char *)
""},
100 {
"rxvt",
'X',
feResBinary,
"RXVT",
"%b/rxvt", (
char *)
""},
102 {
"xterm",
'X',
feResBinary,
"XTERM",
"%b/xterm", (
char *)
""},
104 {
"EmacsDir",
'e',
feResDir,
"SINGULAR_EMACS_DIR",
"%r/emacs", (
char *)
""},
115 #define MAXRESOURCELEN 5*MAXPATHLEN
128 static char*
feSprintf(
char*
s,
const char* fmt,
int warn = -1);
129 #if defined(__CYGWIN__) && defined(__GNUC__)
131 extern "C" int cygwin32_posix_path_list_p (
const char *path);
175 #ifdef RESOURCE_DEBUG
176 printf(
"feInitResources(argv0: '%s'): entering...\n",
feArgv0);
185 #if defined(HAVE_SETENV) || defined(HAVE_PUTENV)
187 #ifdef RESOURCE_DEBUG
188 printf(
"feInitResources(argv0): setting path with '%s'\n", path);
191 if (path != NULL) {
char *
s=(
char *)
malloc(strlen(path)+6);
192 sprintf(s,
"PATH=%s",path);
196 if (path != NULL) setenv(
"PATH", path, 1);
204 while (feResourceConfigs[i].key != NULL)
206 if ((feResourceConfigs[i].value != NULL)
207 && (feResourceConfigs[i].value[0] !=
'\0'))
209 free(feResourceConfigs[i].value);
210 feResourceConfigs[
i].
value = (
char *)
"";
214 #ifdef RESOURCE_DEBUG
215 printf(
"feInitResources(): entering...\n");
232 while (feResourceConfigs[i].key != NULL)
234 if (feResourceConfigs[i].
id ==
id)
return &(feResourceConfigs[
i]);
243 while (feResourceConfigs[i].key != NULL)
245 if (strcmp(feResourceConfigs[i].key, key) == 0)
246 return &(feResourceConfigs[
i]);
254 if (config == NULL)
return NULL;
255 if (config->
value != NULL && *(config->
value) !=
'\0')
return config->
value;
261 if (config == NULL)
return NULL;
270 #ifdef RESOURCE_DEBUG
271 printf(
"feInitResource(config->key: '%s', warn: '%d') : entering ...\n", config->
key, warn);
277 if (config->
env != NULL)
282 #ifdef RESOURCE_DEBUG
283 printf(
"feInitResource(config,warn): Found value from env:%s\n", evalue);
285 strcpy(value, evalue);
291 #ifdef RESOURCE_DEBUG
292 printf(
"feInitResource(config,warn): Set value of config (with key: '%s') to '%s'\n", config->
key, value);
295 return config->
value;
302 if (config->
id ==
'S')
305 if (executable != NULL)
307 #ifdef RESOURCE_DEBUG
308 printf(
"exec:%s\n", executable);
310 strcpy(value, executable);
311 #ifdef RESOURCE_DEBUG
312 printf(
"value:%s\n", value);
318 else if (config->
id ==
'b')
321 #ifdef RESOURCE_DEBUG
322 printf(
"feInitResource(config,warn): Get '%s' from \"%s\"\n", config->
key, executable);
324 if (executable != NULL)
326 strcpy(value, executable);
327 executable = strrchr(value,
DIR_SEP);
328 if (executable != NULL) *executable =
'\0';
332 #ifdef RESOURCE_DEBUG
333 printf(
"value:%s\n", value);
336 if (*value ==
'\0' && config->
fmt != NULL )
340 else if (config->
fmt == NULL)
342 printf(
"Bug >>Wrong Resource Specification of '%s'<< at \"%s:%d\"\n",config->
key,__FILE__,__LINE__);
351 #ifdef RESOURCE_DEBUG
352 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->
key, value);
355 return config->
value;
361 if (executable != NULL)
367 #ifdef RESOURCE_DEBUG
368 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->
key, config->
value);
370 return config->
value;
377 if (warn > 0 || (warn < 0 && config->value != NULL))
379 printf(
"// ** Could not get '%s'.\n", config->
key);
380 printf(
"// ** Either set environment variable '%s' to '%s',\n",
381 config->
env, config->
key);
383 printf(
"// ** or make sure that '%s' is at \"%s\"\n", config->
key, value);
385 #ifdef RESOURCE_DEBUG
386 printf(
"feInitResource(config,warn): Set value of '%s' to NULL", config->
key);
397 printf(
"Bug >>feArgv0 == NULL<< at %s:%d\n",__FILE__,__LINE__);
399 printf(
"Bug >>feArgv0 == ''<< at %s:%d\n",__FILE__,__LINE__);
402 #ifdef __CYGWIN__ // stupid WINNT sometimes gives you argv[0] within ""
413 #ifdef RESOURCE_DEBUG
414 printf(
"feGetExpandedExecutable: calling find_exec with \"%s\"\n",
feArgv0);
418 #ifdef RESOURCE_DEBUG
419 printf(
"feGetExpandedExecutable: find_exec exited with \"%s\": %d\n", executable, access(executable, X_OK));
423 printf(
"Bug >>Could not get expanded executable from \"%s\"<< at %s:%d\n",
feArgv0,__FILE__,__LINE__);
432 #ifdef RESOURCE_DEBUG
433 printf(
"feVerifyResourceValue(type: %d, value: \"%s\"): entering\n", (
int)type, value);
434 printf(
"Access: ROK: %d, XOK: %d\n", access(value, R_OK), access(value, X_OK));
443 return ! access(value, R_OK);
447 return ! access(value, X_OK);
462 if (value == NULL || *value ==
'\0')
return value;
463 #ifdef RESOURCE_DEBUG
464 printf(
"Clean value:%s\n", value);
467 #ifdef RESOURCE_DEBUG
468 printf(
"Clean WINNT value:%s\n", value);
472 int l = strlen(value);
473 if (l < 4 || (strcmp(&value[l-4],
".exe") != 0 &&
474 strcmp(&value[l-4],
".EXE") != 0))
475 strcat(value,
".exe");
489 #ifdef RESOURCE_DEBUG
490 printf(
"feCleanUpFile: entering with =%s=\n", fname);
493 for (fn = fname; *fn !=
'\0'; fn++)
499 if (fname != fn) *fn =
'\0';
502 if (*(fn + 1) ==
'/' && (fname != fn))
507 else if (*(fn+1) ==
'.')
509 if (*(fn+2) ==
'.' && (*(fn + 3) ==
'/' || *(fn + 3) ==
'\0'))
515 s = strrchr(fname,
'/');
518 mystrcpy(
s+1, fn + (*(fn + 3) !=
'\0' ? 4 : 3));
527 else if (*(fn+2) ==
'/' || *(fn+2) ==
'\0')
536 #ifdef RESOURCE_DEBUG
537 printf(
"feCleanUpFile: leaving with =%s=\n", fname);
545 #ifdef RESOURCE_DEBUG
546 printf(
"feCleanUpPath: entering with: =%s=\n", path);
548 if (path == NULL)
return path;
550 int n_comps = 1,
i,
j;
554 for (; *path !=
'\0'; path++)
557 else if (*path ==
';')
564 path_comps = (
char**)
malloc(n_comps*
sizeof(
char*));
576 path_comps[
i] = path+1;
578 if (
i == n_comps)
break;
584 for (
i=0;
i<n_comps;
i++)
586 #ifdef RESOURCE_DEBUG
587 printf(
"feCleanUpPath: after CleanUpName: ");
588 for (i=0; i<n_comps; i++)
589 printf(
"%s:", path_comps[i]);
593 for (i=0; i<n_comps;)
595 #ifdef RESOURCE_DEBUG
596 if (access(path_comps[i], X_OK | R_OK))
597 printf(
"feCleanUpPath: remove %d:%s -- can not access\n", i, path_comps[i]);
599 if ( ! access(path_comps[i], X_OK | R_OK))
604 if (strcmp(path_comps[j], path_comps[i]) == 0)
607 #ifdef RESOURCE_DEBUG
608 printf(
"feCleanUpPath: remove %d:%s -- equal to %d:%s\n", j, path_comps[j], i, path_comps[i]);
621 path_comps[
i] =
NULL;
622 for (j=i+1; j<n_comps; j++)
623 path_comps[j-1] = path_comps[j];
629 for (path=opath, i=0;i<n_comps-1;i++)
632 path += strlen(path);
645 #ifdef RESOURCE_DEBUG
646 printf(
"feCleanUpPath: leaving with path=%s=\n", opath);
672 if (fmt == NULL)
return NULL;
678 if (*fmt ==
'%' && *(fmt + 1) !=
'\0')
693 else if (*fmt ==
'$' && *(fmt + 1) !=
'\0')
697 while (*fmt ==
'_' ||
698 (*fmt >=
'A' && *fmt <=
'Z') ||
699 (*fmt >=
'a' && *fmt <=
'z'))
708 if (v != NULL) strcpy(s, v);
const CanonicalForm int s
static int feVerifyResourceValue(feResourceType type, char *value)
static void mystrcpy(char *d, char *s)
static char * feCleanUpFile(char *fname)
static char * feResource(feResourceConfig config, int warn)
#define SINGULAR_DEFAULT_DIR
static feResourceConfig feGetResourceConfig(const char id)
void feInitResources(const char *argv0)
static char * feGetExpandedExecutable()
static char * feSprintf(char *s, const char *fmt, int warn=-1)
char * feGetResource(const char id, int warn)
void * malloc(size_t size)
const Variable & v
< [in] a sqrfree bivariate poly
char name(const Variable &v)
static char * feCleanUpPath(char *path)
static char * feResourceDefault(feResourceConfig config)
char * omFindExec(const char *name, char *exec)
feResourceConfig_s feResourceConfigs[]
static char * feInitResource(feResourceConfig config, int warn)
static char * feCleanResourceValue(feResourceType type, char *value)