#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 466 of file feResource.cc.
468 if (value ==
NULL || *value ==
'\0')
return value;
469 #ifdef RESOURCE_DEBUG 470 printf(
"Clean value:%s\n", value);
473 #ifdef RESOURCE_DEBUG 474 printf(
"Clean WINNT value:%s\n", value);
478 int l = strlen(value);
479 if (l < 4 || (strcmp(&value[l-4],
".exe") != 0 &&
480 strcmp(&value[l-4],
".EXE") != 0))
481 strcat(value,
".exe");
static char * feCleanUpFile(char *fname)
static char * feCleanUpPath(char *path)
static char * feCleanUpFile |
( |
char * |
fname | ) |
|
|
static |
Definition at line 491 of file feResource.cc.
495 #ifdef RESOURCE_DEBUG 496 printf(
"feCleanUpFile: entering with =%s=\n", fname);
499 for (fn = fname; *fn !=
'\0'; fn++)
505 if (fname != fn) *fn =
'\0';
508 if (*(fn + 1) ==
'/' && (fname != fn))
513 else if (*(fn+1) ==
'.')
515 if (*(fn+2) ==
'.' && (*(fn + 3) ==
'/' || *(fn + 3) ==
'\0'))
521 s = strrchr(fname,
'/');
524 mystrcpy(
s+1, fn + (*(fn + 3) !=
'\0' ? 4 : 3));
533 else if (*(fn+2) ==
'/' || *(fn+2) ==
'\0')
542 #ifdef RESOURCE_DEBUG 543 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 549 of file feResource.cc.
551 #ifdef RESOURCE_DEBUG 552 printf(
"feCleanUpPath: entering with: =%s=\n", path);
554 if (path ==
NULL)
return path;
556 int n_comps = 1,
i,
j;
560 for (; *path !=
'\0'; path++)
563 else if (*path ==
';')
570 path_comps = (
char**)
malloc(n_comps*
sizeof(
char*));
582 path_comps[
i] = path+1;
584 if (
i == n_comps)
break;
590 for (
i=0;
i<n_comps;
i++)
592 #ifdef RESOURCE_DEBUG 593 printf(
"feCleanUpPath: after CleanUpName: ");
594 for (i=0; i<n_comps; i++)
595 printf(
"%s:", path_comps[i]);
599 for (i=0; i<n_comps;)
601 #ifdef RESOURCE_DEBUG 602 if (access(path_comps[i], X_OK | R_OK))
603 printf(
"feCleanUpPath: remove %d:%s -- can not access\n", i, path_comps[i]);
605 if ( ! access(path_comps[i], X_OK | R_OK))
610 if (strcmp(path_comps[j], path_comps[i]) == 0)
613 #ifdef RESOURCE_DEBUG 614 printf(
"feCleanUpPath: remove %d:%s -- equal to %d:%s\n", j, path_comps[j], i, path_comps[i]);
627 path_comps[
i] =
NULL;
628 for (j=i+1; j<n_comps; j++)
629 path_comps[j-1] = path_comps[j];
635 for (path=opath, i=0;i<n_comps-1;i++)
638 path += strlen(path);
651 #ifdef RESOURCE_DEBUG 652 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 398 of file feResource.cc.
403 printf(
"Bug >>feArgv0 == NULL<< at %s:%d\n",__FILE__,__LINE__);
405 printf(
"Bug >>feArgv0 == ''<< at %s:%d\n",__FILE__,__LINE__);
408 #ifdef __CYGWIN__ // stupid WINNT sometimes gives you argv[0] within "" 419 #ifdef RESOURCE_DEBUG 420 printf(
"feGetExpandedExecutable: calling find_exec with \"%s\"\n",
feArgv0);
424 #ifdef RESOURCE_DEBUG 425 printf(
"feGetExpandedExecutable: find_exec exited with \"%s\": %d\n", executable, access(executable, X_OK));
429 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 155 of file feResource.cc.
static char * feResource(feResourceConfig config, int warn)
static feResourceConfig feGetResourceConfig(const char id)
Definition at line 235 of file feResource.cc.
feResourceConfig_s feResourceConfigs[]
Definition at line 246 of file feResource.cc.
feResourceConfig_s feResourceConfigs[]
Definition at line 273 of file feResource.cc.
276 #ifdef RESOURCE_DEBUG 277 printf(
"feInitResource(config->key: '%s', warn: '%d') : entering ...\n", config->
key, warn);
288 #ifdef RESOURCE_DEBUG 289 printf(
"feInitResource(config,warn): Found value from env:%s\n", evalue);
291 strcpy(value, evalue);
297 #ifdef RESOURCE_DEBUG 298 printf(
"feInitResource(config,warn): Set value of config (with key: '%s') to '%s'\n", config->
key, value);
301 return config->
value;
308 if (config->
id ==
'S')
311 if (executable !=
NULL)
313 #ifdef RESOURCE_DEBUG 314 printf(
"exec:%s\n", executable);
316 strcpy(value, executable);
317 #ifdef RESOURCE_DEBUG 318 printf(
"value:%s\n", value);
324 else if (config->
id ==
'b')
327 #ifdef RESOURCE_DEBUG 328 printf(
"feInitResource(config,warn): Get '%s' from \"%s\"\n", config->
key, executable);
330 if (executable !=
NULL)
332 strcpy(value, executable);
333 executable = strrchr(value,
DIR_SEP);
334 if (executable !=
NULL) *executable =
'\0';
338 #ifdef RESOURCE_DEBUG 339 printf(
"value:%s\n", value);
342 if (*value ==
'\0' && config->
fmt !=
NULL )
348 printf(
"Bug >>Wrong Resource Specification of '%s'<< at \"%s:%d\"\n",config->
key,__FILE__,__LINE__);
357 #ifdef RESOURCE_DEBUG 358 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->
key, value);
361 return config->
value;
367 if (executable !=
NULL)
373 #ifdef RESOURCE_DEBUG 374 printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n", config->
key, config->
value);
376 return config->
value;
383 if (warn > 0 || (warn < 0 && config->value !=
NULL))
385 printf(
"// ** Could not get '%s'.\n", config->
key);
386 printf(
"// ** Either set environment variable '%s' to '%s',\n",
387 config->
env, config->
key);
389 printf(
"// ** or make sure that '%s' is at \"%s\"\n", config->
key, value);
391 #ifdef RESOURCE_DEBUG 392 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 170 of file feResource.cc.
181 #ifdef RESOURCE_DEBUG 182 printf(
"feInitResources(argv0: '%s'): entering...\n",
feArgv0);
191 #if defined(HAVE_SETENV) || defined(HAVE_PUTENV) 193 #ifdef RESOURCE_DEBUG 194 printf(
"feInitResources(argv0): setting path with '%s'\n", path);
197 if (path !=
NULL) {
char *
s=(
char *)
malloc(strlen(path)+6);
198 sprintf(s,
"PATH=%s",path);
202 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 207 of file feResource.cc.
220 #ifdef RESOURCE_DEBUG 221 printf(
"feInitResources(): entering...\n");
static char * feResource(feResourceConfig config, int warn)
feResourceConfig_s feResourceConfigs[]
Definition at line 258 of file feResource.cc.
static char * feInitResource(feResourceConfig config, int warn)
char* feResource |
( |
const char * |
key, |
|
|
int |
warn |
|
) |
| |
Definition at line 145 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 150 of file feResource.cc.
static char * feResource(feResourceConfig config, int warn)
static feResourceConfig feGetResourceConfig(const char id)
Definition at line 265 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 160 of file feResource.cc.
static feResourceConfig feGetResourceConfig(const char id)
static char * feResourceDefault(feResourceConfig config)
char* feResourceDefault |
( |
const char * |
key | ) |
|
Definition at line 165 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 675 of file feResource.cc.
684 if (*fmt ==
'%' && *(fmt + 1) !=
'\0')
699 else if (*fmt ==
'$' && *(fmt + 1) !=
'\0')
703 while (*fmt ==
'_' ||
704 (*fmt >=
'A' && *fmt <=
'Z') ||
705 (*fmt >=
'a' && *fmt <=
'z'))
714 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 436 of file feResource.cc.
438 #ifdef RESOURCE_DEBUG 439 printf(
"feVerifyResourceValue(type: %d, value: \"%s\"): entering\n", (
int)type, value);
440 printf(
"Access: ROK: %d, XOK: %d\n", access(value, R_OK), access(value, X_OK));
449 return ! access(value, R_OK);
453 return ! access(value, X_OK);
static void mystrcpy |
( |
char * |
d, |
|
|
char * |
s |
|
) |
| |
|
static |