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 "%r/libexec/singular/MOD;"
60 LIB_DIR
"/singular/MOD;"
61 LIBEXEC_DIR
"/singular/MOD;"
65 {
"Singular",
'S',
feResBinary,
"SINGULAR_EXECUTABLE",
"%d/Singular", (
char *)
""},
66 {
"BinDir",
'b',
feResDir,
"SINGULAR_BIN_DIR",
"", (
char *)
""},
68 {
"ProcDir",
'P',
feResPath,
"SINGULAR_PROCS_DIR",
72 "%r/lib/singular/MOD;"
73 "%r/libexec/singular/MOD;"
74 LIB_DIR
"/singular/MOD;"
75 LIBEXEC_DIR
"/singular/MOD" , (
char *)
""},
76 {
"RootDir",
'r',
feResDir,
"SINGULAR_ROOT_DIR",
"%b/..", (
char *)
""},
77 {
"DataDir",
'D',
feResDir,
"SINGULAR_DATA_DIR",
"%b/../share/", (
char *)
""},
79 {
"InfoFile",
'i',
feResFile,
"SINGULAR_INFO_FILE",
"%D/info/singular.info", (
char *)
""},
80 {
"IdxFile",
'x',
feResFile,
"SINGULAR_IDX_FILE",
"%D/singular/singular.idx", (
char *)
""},
81 {
"HtmlDir",
'h',
feResDir,
"SINGULAR_HTML_DIR", DATA_TO_HTML_DIR, (
char *)
""},
82 {
"ManualUrl",
'u',
feResUrl,
"SINGULAR_URL",
"https://www.singular.uni-kl.de/Manual/", (
char *)
""},
83 {
"ExDir",
'm',
feResDir,
"SINGULAR_EXAMPLES_DIR",
"%r/examples", (
char *)
""},
87 {
"emacs",
'E',
feResBinary,
"ESINGULAR_EMACS",
"%b/emacs.exe", (
char *)
""},
88 {
"xemacs",
'A',
feResBinary,
"ESINGULAR_EMACS",
"%b/xemacs.exe", (
char *)
""},
89 {
"SingularEmacs",
'M',
feResBinary,
"ESINGULAR_SINGULAR",
"%b/Singular.exe", (
char *)
""},
91 {
"emacs",
'E',
feResBinary,
"ESINGULAR_EMACS",
"%b/emacs", (
char *)
""},
92 {
"xemacs",
'A',
feResBinary,
"ESINGULAR_EMACS",
"%b/xemacs", (
char *)
""},
93 {
"SingularEmacs",
'M',
feResBinary,
"ESINGULAR_SINGULAR",
"%b/Singular", (
char *)
""},
95 {
"EmacsLoad",
'l',
feResFile,
"ESINGULAR_EMACS_LOAD",
"%e/.emacs-singular", (
char *)
""},
96 {
"EmacsDir",
'e',
feResDir,
"ESINGULAR_EMACS_DIR",
"%D/singular/emacs", (
char *)
""},
97 {
"SingularXterm",
'M',
feResBinary,
"TSINGULAR_SINGULAR",
"%b/Singular", (
char *)
""},
99 {
"rxvt",
'X',
feResBinary,
"RXVT",
"%b/rxvt", (
char *)
""},
101 {
"xterm",
'X',
feResBinary,
"XTERM",
"%b/xterm", (
char *)
""},
103 {
"EmacsDir",
'e',
feResDir,
"SINGULAR_EMACS_DIR",
"%r/emacs", (
char *)
""},
114#define MAXRESOURCELEN 5*MAXPATHLEN
127static char*
feSprintf(
char*
s,
const char* fmt,
int warn = -1);
128#if defined(__CYGWIN__) && defined(__GNUC__)
130extern "C" int cygwin32_posix_path_list_p (
const char *path);
175 printf(
"feInitResources(argv0: '%s'): entering...\n",
feArgv0);
199 printf(
"feInitResources(): entering...\n");
239 if (config->value !=
NULL && *(config->value) !=
'\0')
return config->value;
255 printf(
"feInitResource(config->key: '%s', warn: '%d') : entering ...\n", config->key, warn);
261 if (config->env !=
NULL)
263 char* evalue =
getenv(config->env);
267 printf(
"feInitResource(config,warn): Found value from env:%s\n", evalue);
269 strcpy(value, evalue);
276 printf(
"feInitResource(config,warn): Set value of config (with key: '%s') to '%s'\n", config->key, value);
278 config->value =
strdup(value);
279 return config->value;
286 if (config->id ==
'S')
289 if (executable !=
NULL)
292 printf(
"exec:%s\n", executable);
294 strcpy(value, executable);
296 printf(
"value:%s\n", value);
302 else if (config->id ==
'b')
306 printf(
"feInitResource(config,warn): Get '%s' from \"%s\"\n", config->key, executable);
308 if (executable !=
NULL)
310 strcpy(value, executable);
311 executable = strrchr(value,
DIR_SEP);
312 if (executable !=
NULL) *executable =
'\0';
317 printf(
"value:%s\n", value);
320 if (*value ==
'\0' && config->fmt !=
NULL )
324 else if (config->fmt ==
NULL)
326 printf(
"Bug >>Wrong Resource Specification of '%s'<< at \"%s:%d\"\n",config->key,__FILE__,__LINE__);
336 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->key, value);
338 config->value =
strdup(value);
339 return config->value;
344 char* executable =
omFindExec(config->key, value);
345 if (executable !=
NULL)
350 config->value =
strdup(value);
352 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->key, config->value);
354 return config->value;
361 if (warn > 0 || (warn < 0 && config->value !=
NULL))
363 printf(
"// ** Could not get '%s'.\n", config->key);
364 printf(
"// ** Either set environment variable '%s' to '%s',\n",
365 config->env, config->key);
367 printf(
"// ** or make sure that '%s' is at \"%s\"\n", config->key, value);
370 printf(
"feInitResource(config,warn): Set value of '%s' to NULL", config->key);
372 config->value =
NULL;
381 printf(
"Bug >>feArgv0 == NULL<< at %s:%d\n",__FILE__,__LINE__);
383 printf(
"Bug >>feArgv0 == ''<< at %s:%d\n",__FILE__,__LINE__);
398 printf(
"feGetExpandedExecutable: calling find_exec with \"%s\"\n",
feArgv0);
403 printf(
"feGetExpandedExecutable: find_exec exited with \"%s\": %d\n", executable, access(executable, X_OK));
407 printf(
"Bug >>Could not get expanded executable from \"%s\"<< at %s:%d\n",
feArgv0,__FILE__,__LINE__);
417 printf(
"feVerifyResourceValue(type: %d, value: \"%s\"): entering\n", (
int)type, value);
418 printf(
"Access: ROK: %d, XOK: %d\n", access(value, R_OK), access(value, X_OK));
427 return ! access(value, R_OK);
431 return ! access(value, X_OK);
446 if (value ==
NULL || *value ==
'\0')
return value;
448 printf(
"Clean value:%s\n", value);
452 printf(
"Clean WINNT value:%s\n", value);
456 int l = strlen(value);
457 if (
l < 4 || (strcmp(&value[
l-4],
".exe") != 0 &&
458 strcmp(&value[
l-4],
".EXE") != 0))
459 strcat(value,
".exe");
474 printf(
"feCleanUpFile: entering with =%s=\n", fname);
477 for (fn = fname; *fn !=
'\0'; fn++)
483 if (fname != fn) *fn =
'\0';
486 if (*(fn + 1) ==
'/' && (fname != fn))
491 else if (*(fn+1) ==
'.')
493 if (*(fn+2) ==
'.' && (*(fn + 3) ==
'/' || *(fn + 3) ==
'\0'))
499 s = strrchr(fname,
'/');
502 mystrcpy(
s+1, fn + (*(fn + 3) !=
'\0' ? 4 : 3));
511 else if (*(fn+2) ==
'/' || *(fn+2) ==
'\0')
521 printf(
"feCleanUpFile: leaving with =%s=\n", fname);
530 printf(
"feCleanUpPath: entering with: =%s=\n", path);
532 if (path ==
NULL)
return path;
534 int n_comps = 1,
i,
j;
538 for (; *path !=
'\0'; path++)
541 else if (*path ==
';')
548 path_comps = (
char**)
malloc(n_comps*
sizeof(
char*));
560 path_comps[
i] = path+1;
562 if (
i == n_comps)
break;
568 for (
i=0;
i<n_comps;
i++)
571 printf(
"feCleanUpPath: after CleanUpName: ");
572 for (
i=0;
i<n_comps;
i++)
573 printf(
"%s:", path_comps[
i]);
577 for (
i=0;
i<n_comps;)
580 if (access(path_comps[
i], X_OK | R_OK))
581 printf(
"feCleanUpPath: remove %d:%s -- can not access\n",
i, path_comps[
i]);
583 if ( ! access(path_comps[
i], X_OK | R_OK))
588 if (strcmp(path_comps[
j], path_comps[
i]) == 0)
592 printf(
"feCleanUpPath: remove %d:%s -- equal to %d:%s\n",
j, path_comps[
j],
i, path_comps[
i]);
605 path_comps[
i] =
NULL;
606 for (
j=
i+1;
j<n_comps;
j++)
607 path_comps[
j-1] = path_comps[
j];
613 for (path=opath,
i=0;
i<n_comps-1;
i++)
616 path += strlen(path);
630 printf(
"feCleanUpPath: leaving with path=%s=\n", opath);
662 if (*fmt ==
'%' && *(fmt + 1) !=
'\0')
677 else if (*fmt ==
'$' && *(fmt + 1) !=
'\0')
681 while (*fmt ==
'_' ||
682 (*fmt >=
'A' && *fmt <=
'Z') ||
683 (*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)
char * omFindExec(const char *name, char *exec)