8#include "singular_resourcesconfig.h"
27#define SINGULAR_DEFAULT_DIR PREFIX
46 "%r/share/singular/LIB;"
47 "%b/../share/singular/LIB;"
58 "%r/lib/singular/MOD;"
59 LIB_DIR
"/singular/MOD;"
63 {
"Singular",
'S',
feResBinary,
"SINGULAR_EXECUTABLE",
"%d/Singular", (
char *)
""},
64 {
"BinDir",
'b',
feResDir,
"SINGULAR_BIN_DIR",
"", (
char *)
""},
66 {
"ProcDir",
'P',
feResPath,
"SINGULAR_PROCS_DIR",
70 "%r/lib/singular/MOD;"
71 LIB_DIR
"/singular/MOD;"
73 {
"RootDir",
'r',
feResDir,
"SINGULAR_ROOT_DIR",
"%b/..", (
char *)
""},
74 {
"DataDir",
'D',
feResDir,
"SINGULAR_DATA_DIR",
"%b/../share/", (
char *)
""},
76 {
"InfoFile",
'i',
feResFile,
"SINGULAR_INFO_FILE",
"%D/info/singular.info.gz", (
char *)
""},
77 {
"IdxFile",
'x',
feResFile,
"SINGULAR_IDX_FILE",
"%D/singular/singular.idx", (
char *)
""},
78 {
"HtmlDir",
'h',
feResDir,
"SINGULAR_HTML_DIR", DATA_TO_HTML_DIR, (
char *)
""},
79 {
"ManualUrl",
'u',
feResUrl,
"SINGULAR_URL",
"https://www.singular.uni-kl.de/Manual/", (
char *)
""},
80 {
"ExDir",
'm',
feResDir,
"SINGULAR_EXAMPLES_DIR",
"%r/examples", (
char *)
""},
84 {
"emacs",
'E',
feResBinary,
"ESINGULAR_EMACS",
"%b/emacs.exe", (
char *)
""},
85 {
"xemacs",
'A',
feResBinary,
"ESINGULAR_EMACS",
"%b/xemacs.exe", (
char *)
""},
86 {
"SingularEmacs",
'M',
feResBinary,
"ESINGULAR_SINGULAR",
"%b/Singular.exe", (
char *)
""},
88 {
"emacs",
'E',
feResBinary,
"ESINGULAR_EMACS",
"%b/emacs", (
char *)
""},
89 {
"xemacs",
'A',
feResBinary,
"ESINGULAR_EMACS",
"%b/xemacs", (
char *)
""},
90 {
"SingularEmacs",
'M',
feResBinary,
"ESINGULAR_SINGULAR",
"%b/Singular", (
char *)
""},
92 {
"EmacsLoad",
'l',
feResFile,
"ESINGULAR_EMACS_LOAD",
"%e/.emacs-singular", (
char *)
""},
93 {
"EmacsDir",
'e',
feResDir,
"ESINGULAR_EMACS_DIR",
"%D/singular/emacs", (
char *)
""},
94 {
"SingularXterm",
'M',
feResBinary,
"TSINGULAR_SINGULAR",
"%b/Singular", (
char *)
""},
96 {
"rxvt",
'X',
feResBinary,
"RXVT",
"%b/rxvt", (
char *)
""},
98 {
"xterm",
'X',
feResBinary,
"XTERM",
"%b/xterm", (
char *)
""},
100 {
"EmacsDir",
'e',
feResDir,
"SINGULAR_EMACS_DIR",
"%r/emacs", (
char *)
""},
111#define MAXRESOURCELEN 5*MAXPATHLEN
124static char*
feSprintf(
char*
s,
const char* fmt,
int warn = -1);
125#if defined(__CYGWIN__) && defined(__GNUC__)
127extern "C" int cygwin32_posix_path_list_p (
const char *path);
172 printf(
"feInitResources(argv0: '%s'): entering...\n",
feArgv0);
196 printf(
"feInitResources(): entering...\n");
236 if (config->value !=
NULL && *(config->value) !=
'\0')
return config->value;
252 printf(
"feInitResource(config->key: '%s', warn: '%d') : entering ...\n", config->key, warn);
258 if (config->env !=
NULL)
260 char* evalue =
getenv(config->env);
264 printf(
"feInitResource(config,warn): Found value from env:%s\n", evalue);
266 strcpy(value, evalue);
273 printf(
"feInitResource(config,warn): Set value of config (with key: '%s') to '%s'\n", config->key, value);
275 config->value =
strdup(value);
276 return config->value;
283 if (config->id ==
'S')
286 if (executable !=
NULL)
289 printf(
"exec:%s\n", executable);
291 strcpy(value, executable);
293 printf(
"value:%s\n", value);
299 else if (config->id ==
'b')
303 printf(
"feInitResource(config,warn): Get '%s' from \"%s\"\n", config->key, executable);
305 if (executable !=
NULL)
307 strcpy(value, executable);
308 executable = strrchr(value,
DIR_SEP);
309 if (executable !=
NULL) *executable =
'\0';
314 printf(
"value:%s\n", value);
317 if (*value ==
'\0' && config->fmt !=
NULL )
321 else if (config->fmt ==
NULL)
323 printf(
"Bug >>Wrong Resource Specification of '%s'<< at \"%s:%d\"\n",config->key,__FILE__,__LINE__);
333 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->key, value);
335 config->value =
strdup(value);
336 return config->value;
341 char* executable =
omFindExec(config->key, value);
342 if (executable !=
NULL)
347 config->value =
strdup(value);
349 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->key, config->value);
351 return config->value;
358 if (warn > 0 || (warn < 0 && config->value !=
NULL))
360 printf(
"// ** Could not get '%s'.\n", config->key);
361 printf(
"// ** Either set environment variable '%s' to '%s',\n",
362 config->env, config->key);
364 printf(
"// ** or make sure that '%s' is at \"%s\"\n", config->key, value);
367 printf(
"feInitResource(config,warn): Set value of '%s' to NULL", config->key);
369 config->value =
NULL;
378 printf(
"Bug >>feArgv0 == NULL<< at %s:%d\n",__FILE__,__LINE__);
380 printf(
"Bug >>feArgv0 == ''<< at %s:%d\n",__FILE__,__LINE__);
395 printf(
"feGetExpandedExecutable: calling find_exec with \"%s\"\n",
feArgv0);
400 printf(
"feGetExpandedExecutable: find_exec exited with \"%s\": %d\n", executable, access(executable, X_OK));
404 printf(
"Bug >>Could not get expanded executable from \"%s\"<< at %s:%d\n",
feArgv0,__FILE__,__LINE__);
414 printf(
"feVerifyResourceValue(type: %d, value: \"%s\"): entering\n", (
int)type, value);
415 printf(
"Access: ROK: %d, XOK: %d\n", access(value, R_OK), access(value, X_OK));
424 return ! access(value, R_OK);
428 return ! access(value, X_OK);
443 if (value ==
NULL || *value ==
'\0')
return value;
445 printf(
"Clean value:%s\n", value);
449 printf(
"Clean WINNT value:%s\n", value);
453 int l = strlen(value);
454 if (
l < 4 || (strcmp(&value[
l-4],
".exe") != 0 &&
455 strcmp(&value[
l-4],
".EXE") != 0))
456 strcat(value,
".exe");
471 printf(
"feCleanUpFile: entering with =%s=\n", fname);
474 for (fn = fname; *fn !=
'\0'; fn++)
480 if (fname != fn) *fn =
'\0';
483 if (*(fn + 1) ==
'/' && (fname != fn))
488 else if (*(fn+1) ==
'.')
490 if (*(fn+2) ==
'.' && (*(fn + 3) ==
'/' || *(fn + 3) ==
'\0'))
496 s = strrchr(fname,
'/');
499 mystrcpy(
s+1, fn + (*(fn + 3) !=
'\0' ? 4 : 3));
508 else if (*(fn+2) ==
'/' || *(fn+2) ==
'\0')
518 printf(
"feCleanUpFile: leaving with =%s=\n", fname);
527 printf(
"feCleanUpPath: entering with: =%s=\n", path);
529 if (path ==
NULL)
return path;
531 int n_comps = 1,
i,
j;
535 for (; *path !=
'\0'; path++)
538 else if (*path ==
';')
545 path_comps = (
char**)
malloc(n_comps*
sizeof(
char*));
557 path_comps[
i] = path+1;
559 if (
i == n_comps)
break;
565 for (
i=0;
i<n_comps;
i++)
568 printf(
"feCleanUpPath: after CleanUpName: ");
569 for (
i=0;
i<n_comps;
i++)
570 printf(
"%s:", path_comps[
i]);
574 for (
i=0;
i<n_comps;)
577 if (access(path_comps[
i], X_OK | R_OK))
578 printf(
"feCleanUpPath: remove %d:%s -- can not access\n",
i, path_comps[
i]);
580 if ( ! access(path_comps[
i], X_OK | R_OK))
585 if (strcmp(path_comps[
j], path_comps[
i]) == 0)
589 printf(
"feCleanUpPath: remove %d:%s -- equal to %d:%s\n",
j, path_comps[
j],
i, path_comps[
i]);
602 path_comps[
i] =
NULL;
603 for (
j=
i+1;
j<n_comps;
j++)
604 path_comps[
j-1] = path_comps[
j];
610 for (path=opath,
i=0;
i<n_comps-1;
i++)
613 path += strlen(path);
627 printf(
"feCleanUpPath: leaving with path=%s=\n", opath);
659 if (*fmt ==
'%' && *(fmt + 1) !=
'\0')
674 else if (*fmt ==
'$' && *(fmt + 1) !=
'\0')
678 while (*fmt ==
'_' ||
679 (*fmt >=
'A' && *fmt <=
'Z') ||
680 (*fmt >=
'a' && *fmt <=
'z'))
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
static char * feCleanUpFile(char *fname)
static feResourceConfig feGetResourceConfig(const char id)
static char * feResourceDefault(feResourceConfig config)
static char * feSprintf(char *s, const char *fmt, int warn=-1)
VAR feResourceConfig_s feResourceConfigs[]
static char * feInitResource(feResourceConfig config, int warn)
static char * feCleanUpPath(char *path)
static char * feResource(feResourceConfig config, int warn)
void feInitResources(const char *argv0)
static char * feGetExpandedExecutable()
static char * feCleanResourceValue(feResourceType type, char *value)
static int feVerifyResourceValue(feResourceType type, char *value)
char * feGetResource(const char id, int warn)
#define SINGULAR_DEFAULT_DIR
static void mystrcpy(char *d, char *s)
feResourceConfig_s * feResourceConfig
char * omFindExec(const char *name, char *exec)