#include "resourcesconfig.h"
#include "feResource.h"
#include "omFindExec.h"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/param.h>
Go to the source code of this file.
|
static feResourceConfig | feGetResourceConfig (const char id) |
|
static feResourceConfig | feGetResourceConfig (const char *key) |
|
static char * | feResource (feResourceConfig config, int warn) |
|
static char * | feResourceDefault (feResourceConfig config) |
|
static char * | feInitResource (feResourceConfig config, int warn) |
|
static char * | feGetExpandedExecutable () |
|
static int | feVerifyResourceValue (feResourceType type, char *value) |
|
static char * | feCleanResourceValue (feResourceType type, char *value) |
|
static char * | feCleanUpFile (char *fname) |
|
static char * | feCleanUpPath (char *path) |
|
static void | mystrcpy (char *d, char *s) |
|
static char * | feSprintf (char *s, const char *fmt, int warn=-1) |
|
char * | feResource (const char *key, int warn) |
|
char * | feResource (const char id, int warn) |
|
char * | feGetResource (const char id, int warn) |
|
char * | feResourceDefault (const char id) |
|
char * | feResourceDefault (const char *key) |
|
void | feInitResources (const char *argv0) |
|
void | feReInitResources () |
|
#define SINGULAR_DEFAULT_DIR PREFIX |
static char * feCleanResourceValue |
( |
feResourceType |
type, |
|
|
char * |
value |
|
) |
| |
|
static |
Definition at line 460 of file feResource.cc.
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");
static char * feCleanUpFile(char *fname)
static char * feCleanUpPath(char *path)
static char * feCleanUpFile |
( |
char * |
fname | ) |
|
|
static |
Definition at line 485 of file feResource.cc.
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);
const CanonicalForm int s
static void mystrcpy(char *d, char *s)
static char * feCleanUpPath |
( |
char * |
path | ) |
|
|
static |
Definition at line 543 of file feResource.cc.
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);
static void mystrcpy(char *d, char *s)
static char * feCleanUpFile(char *fname)
void * malloc(size_t size)
static char * feGetExpandedExecutable |
( |
| ) |
|
|
static |
Definition at line 392 of file feResource.cc.
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__);
char * omFindExec(const char *name, char *exec)
char* feGetResource |
( |
const char |
id, |
|
|
int |
warn |
|
) |
| |
Definition at line 149 of file feResource.cc.
static char * feResource(feResourceConfig config, int warn)
static feResourceConfig feGetResourceConfig(const char id)
Definition at line 229 of file feResource.cc.
feResourceConfig_s feResourceConfigs[]
Definition at line 240 of file feResource.cc.
feResourceConfig_s feResourceConfigs[]
Definition at line 267 of file feResource.cc.
270 #ifdef RESOURCE_DEBUG 271 printf(
"feInitResource(config->key: '%s', warn: '%d') : entering ...\n", config->
key, warn);
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 )
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);
static int feVerifyResourceValue(feResourceType type, char *value)
static char * feResource(feResourceConfig config, int warn)
static char * feGetExpandedExecutable()
static char * feSprintf(char *s, const char *fmt, int warn=-1)
char * omFindExec(const char *name, char *exec)
static char * feCleanResourceValue(feResourceType type, char *value)
void feInitResources |
( |
const char * |
argv0 | ) |
|
Definition at line 164 of file feResource.cc.
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);
const CanonicalForm int s
static char * feResource(feResourceConfig config, int warn)
void * malloc(size_t size)
void feReInitResources |
( |
| ) |
|
Definition at line 201 of file feResource.cc.
214 #ifdef RESOURCE_DEBUG 215 printf(
"feInitResources(): entering...\n");
static char * feResource(feResourceConfig config, int warn)
feResourceConfig_s feResourceConfigs[]
Definition at line 252 of file feResource.cc.
static char * feInitResource(feResourceConfig config, int warn)
char* feResource |
( |
const char * |
key, |
|
|
int |
warn |
|
) |
| |
Definition at line 139 of file feResource.cc.
static char * feResource(feResourceConfig config, int warn)
static feResourceConfig feGetResourceConfig(const char id)
char* feResource |
( |
const char |
id, |
|
|
int |
warn |
|
) |
| |
Definition at line 144 of file feResource.cc.
static char * feResource(feResourceConfig config, int warn)
static feResourceConfig feGetResourceConfig(const char id)
Definition at line 259 of file feResource.cc.
static char * feSprintf(char *s, const char *fmt, int warn=-1)
void * malloc(size_t size)
char* feResourceDefault |
( |
const char |
id | ) |
|
Definition at line 154 of file feResource.cc.
static feResourceConfig feGetResourceConfig(const char id)
static char * feResourceDefault(feResourceConfig config)
char* feResourceDefault |
( |
const char * |
key | ) |
|
Definition at line 159 of file feResource.cc.
static feResourceConfig feGetResourceConfig(const char id)
static char * feResourceDefault(feResourceConfig config)
static char * feSprintf |
( |
char * |
s, |
|
|
const char * |
fmt, |
|
|
int |
warn = -1 |
|
) |
| |
|
static |
Definition at line 669 of file feResource.cc.
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 char * feResource(feResourceConfig config, int warn)
const Variable & v
< [in] a sqrfree bivariate poly
static int feVerifyResourceValue |
( |
feResourceType |
type, |
|
|
char * |
value |
|
) |
| |
|
static |
Definition at line 430 of file feResource.cc.
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);
static void mystrcpy |
( |
char * |
d, |
|
|
char * |
s |
|
) |
| |
|
static |