My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
resources
feResource.cc
Go to the documentation of this file.
1
/****************************************
2
* Computer Algebra System SINGULAR *
3
****************************************/
4
/*
5
* ABSTRACT: management of resources
6
*/
7
8
#include "singular_resourcesconfig.h"
9
#include "
feResource.h
"
10
#include "
omFindExec.h
"
11
12
#include <stdlib.h>
13
#include <unistd.h>
14
#include <string.h>
15
#include <stdio.h>
16
#include <sys/param.h>
17
18
19
VAR
char
*
feArgv0
=
NULL
;
20
21
//char* feResource(const char id, int warn = -1);
22
//char* feResource(const char* key, int warn = -1);
23
24
// define RESOURCE_DEBUG for chattering about resource management
25
// #define RESOURCE_DEBUG
26
27
#define SINGULAR_DEFAULT_DIR PREFIX
28
29
/*****************************************************************
30
*
31
* Declarations: Data structures
32
*
33
*****************************************************************/
34
// feSprintf transforms format strings as follows:
35
// 1.) substrings of the form %c (c being a letter) are replaced by respective resource value
36
// 2.) substrings of the form $string are replaced by value of resp. env variable
37
38
// feCleanResource makes furthermore the following transformations (except for URL resources)
39
// 1.) '/' characters are replaced by respective directory - separators
40
// 2.) ';' characters are replaced by respective path separators
41
VAR
feResourceConfig_s
feResourceConfigs
[] =
42
{
43
{
"SearchPath"
,
's'
,
feResPath
,
NULL
,
44
"$SINGULARPATH;"
45
"%D/singular/LIB;"
46
"%r/share/singular/LIB;"
47
"%b/../share/singular/LIB;"
48
// gftables:
49
"%D/singular/factory;"
50
"%r/share/singular/factory;"
51
////"%b/LIB;"
52
////"%b/../LIB;" // not installed, shared is in .libs/Singular
53
"%b/../share/singular/factory;"
54
////"%b/../../factory;" // not installed, shared is in .libs/Singular
55
// path for dynamic modules, should match ProcDir:
56
////"%b/MOD;"
57
////"%b/../MOD;" // Singular in .libs/Singular
58
"%r/lib/singular/MOD;"
59
LIB_DIR
"/singular/MOD;"
60
"%b;"
61
///"%b/..", // Singular in .libs/Singular
62
,(
char
*)
""
},
63
{
"Singular"
,
'S'
,
feResBinary
,
"SINGULAR_EXECUTABLE"
,
"%d/Singular"
, (
char
*)
""
},
64
{
"BinDir"
,
'b'
,
feResDir
,
"SINGULAR_BIN_DIR"
,
""
, (
char
*)
""
},
65
// should be changed to %b/../lib/singular/pProcs/:
66
{
"ProcDir"
,
'P'
,
feResPath
,
"SINGULAR_PROCS_DIR"
,
67
"%b/MOD;"
68
////"%b/../MOD;" // Singular in .libs/Singular
69
////"%b/..;" // Singular in .libs/Singular, programs in .
70
"%r/lib/singular/MOD;"
71
LIB_DIR
"/singular/MOD;"
72
,(
char
*)
""
},
73
{
"RootDir"
,
'r'
,
feResDir
,
"SINGULAR_ROOT_DIR"
,
"%b/.."
, (
char
*)
""
},
74
{
"DataDir"
,
'D'
,
feResDir
,
"SINGULAR_DATA_DIR"
,
"%b/../share/"
, (
char
*)
""
},
75
{
"DefaultDir"
,
'd'
,
feResDir
,
"SINGULAR_DEFAULT_DIR"
,
SINGULAR_DEFAULT_DIR
, (
char
*)
""
},
76
{
"InfoFile"
,
'i'
,
feResFile
,
"SINGULAR_INFO_FILE"
,
"%D/info/singular.info"
, (
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
*)
""
},
81
{
"Path"
,
'p'
,
feResPath
,
NULL
,
"%b;%P;$PATH"
, (
char
*)
""
},
82
83
#ifdef __CYGWIN__
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
*)
""
},
87
#else
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
*)
""
},
91
#endif
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
*)
""
},
95
#ifdef __CYGWIN__
96
{
"rxvt"
,
'X'
,
feResBinary
,
"RXVT"
,
"%b/rxvt"
, (
char
*)
""
},
97
#else
98
{
"xterm"
,
'X'
,
feResBinary
,
"XTERM"
,
"%b/xterm"
, (
char
*)
""
},
99
#endif
100
{
"EmacsDir"
,
'e'
,
feResDir
,
"SINGULAR_EMACS_DIR"
,
"%r/emacs"
, (
char
*)
""
},
101
{
NULL
, 0,
feResUndef
,
NULL
,
NULL
,
NULL
},
// must be the last record
102
};
103
104
105
/*****************************************************************
106
*
107
* Declarations: Local variables / functions
108
*
109
*****************************************************************/
110
111
#define MAXRESOURCELEN 5*MAXPATHLEN
112
113
static
feResourceConfig
feGetResourceConfig
(
const
char
id
);
114
static
feResourceConfig
feGetResourceConfig
(
const
char
* key);
115
static
char
*
feResource
(
feResourceConfig
config,
int
warn);
116
static
char
*
feResourceDefault
(
feResourceConfig
config);
117
static
char
*
feInitResource
(
feResourceConfig
config,
int
warn);
118
static
char
*
feGetExpandedExecutable
();
119
static
int
feVerifyResourceValue
(
feResourceType
type,
char
* value);
120
static
char
*
feCleanResourceValue
(
feResourceType
type,
char
* value);
121
static
char
*
feCleanUpFile
(
char
* fname);
122
static
char
*
feCleanUpPath
(
char
* path);
123
static
void
mystrcpy
(
char
* d,
char
*
s
);
124
static
char
*
feSprintf
(
char
*
s
,
const
char
* fmt,
int
warn = -1);
125
#if defined(__CYGWIN__) && defined(__GNUC__)
126
// utility function of Cygwin32:
127
extern
"C"
int
cygwin32_posix_path_list_p (
const
char
*path);
128
#endif
129
130
/*****************************************************************
131
*
132
* Public functions
133
*
134
*****************************************************************/
135
char
*
feResource
(
const
char
* key,
int
warn)
136
{
137
return
feResource
(
feGetResourceConfig
(key), warn);
138
}
139
140
char
*
feResource
(
const
char
id
,
int
warn)
141
{
142
return
feResource
(
feGetResourceConfig
(
id
), warn);
143
}
144
145
char
*
feGetResource
(
const
char
id
,
int
warn)
146
{
147
return
feResource
(
feGetResourceConfig
(
id
), warn);
148
}
149
150
char
*
feResourceDefault
(
const
char
id
)
151
{
152
return
feResourceDefault
(
feGetResourceConfig
(
id
));
153
}
154
155
char
*
feResourceDefault
(
const
char
* key)
156
{
157
return
feResourceDefault
(
feGetResourceConfig
(key));
158
}
159
160
void
feInitResources
(
const
char
*
argv0
)
161
{
162
if
(
argv0
==
NULL
)
163
{
164
//WarnS("illegal argv[0]==NULL");
165
feArgv0
= (
char
*)
malloc
(
MAXPATHLEN
+strlen(
"/Singular"
));
166
getcwd(
feArgv0
,
MAXPATHLEN
);
167
strcat(
feArgv0
,
"/Singular"
);
168
}
169
else
170
feArgv0
=
strdup
(
argv0
);
171
#ifdef RESOURCE_DEBUG
172
printf(
"feInitResources(argv0: '%s'): entering...\n"
,
feArgv0
);
173
#endif
174
// init some Resources
175
feResource
(
'b'
);
176
feResource
(
'r'
);
177
// don't complain about stuff when initializing SingularPath
178
feResource
(
's'
,0);
179
feResource
(
'P'
);
180
}
181
182
void
feReInitResources
()
183
{
184
int
i
= 0;
185
while
(
feResourceConfigs
[
i
].key !=
NULL
)
186
{
187
if
((
feResourceConfigs
[
i
].value !=
NULL
)
188
&& (
feResourceConfigs
[
i
].value[0] !=
'\0'
))
189
{
190
free
(
feResourceConfigs
[
i
].value);
191
feResourceConfigs
[
i
].value = (
char
*)
""
;
192
}
193
i
++;
194
}
195
#ifdef RESOURCE_DEBUG
196
printf(
"feInitResources(): entering...\n"
);
197
#endif
198
// init some Resources
199
feResource
(
'b'
);
200
feResource
(
'r'
);
201
// don't complain about stuff when initializing SingularPath
202
feResource
(
's'
,0);
203
}
204
205
/*****************************************************************
206
*
207
* Local functions
208
*
209
*****************************************************************/
210
static
feResourceConfig
feGetResourceConfig
(
const
char
id
)
211
{
212
int
i
= 0;
213
while
(
feResourceConfigs
[
i
].key !=
NULL
)
214
{
215
if
(
feResourceConfigs
[
i
].
id
==
id
)
return
&(
feResourceConfigs
[
i
]);
216
i
++;
217
}
218
return
NULL
;
219
}
220
221
static
feResourceConfig
feGetResourceConfig
(
const
char
* key)
222
{
223
int
i
= 0;
224
while
(
feResourceConfigs
[
i
].key !=
NULL
)
225
{
226
if
(strcmp(
feResourceConfigs
[
i
].key, key) == 0)
227
return
&(
feResourceConfigs
[
i
]);
228
i
++;
229
}
230
return
NULL
;
231
}
232
233
static
char
*
feResource
(
feResourceConfig
config,
int
warn)
234
{
235
if
(config ==
NULL
)
return
NULL
;
236
if
(config->value !=
NULL
&& *(config->value) !=
'\0'
)
return
config->value;
237
return
feInitResource
(config, warn);
238
}
239
240
static
char
*
feResourceDefault
(
feResourceConfig
config)
241
{
242
if
(config ==
NULL
)
return
NULL
;
243
char
* value = (
char
*)
malloc
(
MAXRESOURCELEN
);
244
feSprintf
(value, config->fmt, -1);
245
return
value;
246
}
247
248
static
char
*
feInitResource
(
feResourceConfig
config,
int
warn)
249
{
250
/*assume(config != NULL);*/
251
#ifdef RESOURCE_DEBUG
252
printf(
"feInitResource(config->key: '%s', warn: '%d') : entering ...\n"
, config->key, warn);
253
#endif
254
255
char
value[
MAXRESOURCELEN
];
256
// now we have to work
257
// First, check Environment variable
258
if
(config->env !=
NULL
)
259
{
260
char
* evalue =
getenv
(config->env);
261
if
(evalue !=
NULL
)
262
{
263
#ifdef RESOURCE_DEBUG
264
printf(
"feInitResource(config,warn): Found value from env:%s\n"
, evalue);
265
#endif
266
strcpy(value, evalue);
267
if
(config->type ==
feResBinary
// do not verify binaries
268
||
269
feVerifyResourceValue
(config->type,
270
feCleanResourceValue
(config->type, value)))
271
{
272
#ifdef RESOURCE_DEBUG
273
printf(
"feInitResource(config,warn): Set value of config (with key: '%s') to '%s'\n"
, config->key, value);
274
#endif
275
config->value =
strdup
(value);
276
return
config->value;
277
}
278
}
279
}
280
281
*value =
'\0'
;
282
// Special treatment of executable
283
if
(config->id ==
'S'
)
284
{
285
char
* executable =
feGetExpandedExecutable
();
286
if
(executable !=
NULL
)
287
{
288
#ifdef RESOURCE_DEBUG
289
printf(
"exec:%s\n"
, executable);
290
#endif
291
strcpy(value, executable);
292
#ifdef RESOURCE_DEBUG
293
printf(
"value:%s\n"
, value);
294
#endif
295
free
(executable);
296
}
297
}
298
// and bindir
299
else
if
(config->id ==
'b'
)
300
{
301
char
* executable =
feResource
(
'S'
);
302
#ifdef RESOURCE_DEBUG
303
printf(
"feInitResource(config,warn): Get '%s' from \"%s\"\n"
, config->key, executable);
304
#endif
305
if
(executable !=
NULL
)
306
{
307
strcpy(value, executable);
308
executable = strrchr(value,
DIR_SEP
);
309
if
(executable !=
NULL
) *executable =
'\0'
;
310
}
311
}
312
313
#ifdef RESOURCE_DEBUG
314
printf(
"value:%s\n"
, value);
315
#endif
316
317
if
(*value ==
'\0'
&& config->fmt !=
NULL
)
318
{
319
feSprintf
(value, config->fmt, warn);
320
}
321
else
if
(config->fmt ==
NULL
)
322
{
323
printf(
"Bug >>Wrong Resource Specification of '%s'<< at \"%s:%d\"\n"
,config->key,__FILE__,__LINE__);
324
// TODO: printf -> WarnS???
325
return
NULL
;
326
}
327
328
// Clean and verify
329
if
(
feVerifyResourceValue
(config->type,
330
feCleanResourceValue
(config->type, value)))
331
{
332
#ifdef RESOURCE_DEBUG
333
printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n"
, config->key, value);
334
#endif
335
config->value =
strdup
(value);
336
return
config->value;
337
}
338
else
if
(config->type ==
feResBinary
)
339
{
340
// for binaries, search through PATH once more
341
char
* executable =
omFindExec
(config->key, value);
342
if
(executable !=
NULL
)
343
{
344
if
(
feVerifyResourceValue
(config->type,
345
feCleanResourceValue
(config->type, value)))
346
{
347
config->value =
strdup
(value);
348
#ifdef RESOURCE_DEBUG
349
printf(
"feInitResource(config,warn): Set value of '%s' to \"%s\"\n"
, config->key, config->value);
350
#endif
351
return
config->value;
352
}
353
}
354
}
355
356
// issue warning if explicitely requested, or if
357
// this value is gotten for the first time
358
if
(warn > 0 || (warn < 0 && config->value !=
NULL
))
359
{
360
printf(
"// ** Could not get '%s'.\n"
, config->key);
361
printf(
"// ** Either set environment variable '%s' to '%s',\n"
,
362
config->env, config->key);
363
feSprintf
(value, config->fmt, warn);
364
printf(
"// ** or make sure that '%s' is at \"%s\"\n"
, config->key, value);
365
}
366
#ifdef RESOURCE_DEBUG
367
printf(
"feInitResource(config,warn): Set value of '%s' to NULL"
, config->key);
368
#endif
369
config->value =
NULL
;
370
return
NULL
;
371
}
372
373
static
char
*
feGetExpandedExecutable
()
374
{
375
if
(
feArgv0
==
NULL
|| *
feArgv0
==
'\0'
)
376
{
377
if
(
feArgv0
==
NULL
)
378
printf(
"Bug >>feArgv0 == NULL<< at %s:%d\n"
,__FILE__,__LINE__);
379
else
380
printf(
"Bug >>feArgv0 == ''<< at %s:%d\n"
,__FILE__,__LINE__);
381
return
NULL
;
382
}
383
#ifdef __CYGWIN__
// stupid WINNT sometimes gives you argv[0] within ""
384
if
(*
feArgv0
==
'"'
)
385
{
386
int
l
= strlen(
feArgv0
);
387
if
(
feArgv0
[
l
-1] ==
'"'
)
388
{
389
feArgv0
[
l
-1] =
'\0'
;
390
feArgv0
++;
391
}
392
}
393
#endif
394
#ifdef RESOURCE_DEBUG
395
printf(
"feGetExpandedExecutable: calling find_exec with \"%s\"\n"
,
feArgv0
);
396
#endif
397
char
executable[
MAXRESOURCELEN
];
398
char
* value =
omFindExec
(
feArgv0
, executable);
399
#ifdef RESOURCE_DEBUG
400
printf(
"feGetExpandedExecutable: find_exec exited with \"%s\": %d\n"
, executable, access(executable, X_OK));
401
#endif
402
if
(value ==
NULL
)
403
{
404
printf(
"Bug >>Could not get expanded executable from \"%s\"<< at %s:%d\n"
,
feArgv0
,__FILE__,__LINE__);
405
return
NULL
;
406
}
407
return
strdup
(value);
408
}
409
410
411
static
int
feVerifyResourceValue
(
feResourceType
type,
char
* value)
412
{
413
#ifdef RESOURCE_DEBUG
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));
416
#endif
417
switch
(type)
418
{
419
case
feResUrl
:
420
case
feResPath
:
421
return
1;
422
423
case
feResFile
:
424
return
! access(value, R_OK);
425
426
case
feResBinary
:
427
case
feResDir
:
428
return
! access(value, X_OK);
429
430
default
:
431
return
0;
432
}
433
}
434
435
/*****************************************************************
436
*
437
* Cleaning/Transformations of resource values
438
*
439
*****************************************************************/
440
441
static
char
*
feCleanResourceValue
(
feResourceType
type,
char
* value)
442
{
443
if
(value ==
NULL
|| *value ==
'\0'
)
return
value;
444
#ifdef RESOURCE_DEBUG
445
printf(
"Clean value:%s\n"
, value);
446
#endif
447
#ifdef __CYGWIN__
448
#ifdef RESOURCE_DEBUG
449
printf(
"Clean WINNT value:%s\n"
, value);
450
#endif
451
if
(type ==
feResBinary
)
452
{
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"
);
457
}
458
#endif
459
if
(type ==
feResFile
|| type ==
feResBinary
|| type ==
feResDir
)
460
return
feCleanUpFile
(value);
461
if
(type ==
feResPath
)
462
return
feCleanUpPath
(value);
463
return
value;
464
}
465
466
static
char
*
feCleanUpFile
(
char
* fname)
467
{
468
char
* fn;
469
470
#ifdef RESOURCE_DEBUG
471
printf(
"feCleanUpFile: entering with =%s=\n"
, fname);
472
#endif
473
// Remove unnecessary .. and //
474
for
(fn = fname; *fn !=
'\0'
; fn++)
475
{
476
if
(*fn ==
'/'
)
477
{
478
if
(*(fn+1) ==
'\0'
)
479
{
480
if
(fname != fn) *fn =
'\0'
;
481
break
;
482
}
483
if
(*(fn + 1) ==
'/'
&& (fname != fn))
484
{
485
mystrcpy
(fn, fn+1);
486
fn--;
487
}
488
else
if
(*(fn+1) ==
'.'
)
489
{
490
if
(*(fn+2) ==
'.'
&& (*(fn + 3) ==
'/'
|| *(fn + 3) ==
'\0'
))
491
{
492
#if 0
493
// this does not work: ./../../mmm will be changed to ./../mmm
494
// but we only want to change ././mmm to ./mmm
495
*fn =
'\0'
;
496
s
= strrchr(fname,
'/'
);
497
if
(
s
!=
NULL
)
498
{
499
mystrcpy
(
s
+1, fn + (*(fn + 3) !=
'\0'
? 4 : 3));
500
fn =
s
-1;
501
}
502
else
503
{
504
*fn =
'/'
;
505
}
506
#endif
507
}
508
else
if
(*(fn+2) ==
'/'
|| *(fn+2) ==
'\0'
)
509
{
510
mystrcpy
(fn+1, fn+3);
511
fn--;
512
}
513
}
514
}
515
}
516
517
#ifdef RESOURCE_DEBUG
518
printf(
"feCleanUpFile: leaving with =%s=\n"
, fname);
519
#endif
520
return
fname;
521
}
522
523
// remove duplicates dir resp. those which do not exist
524
static
char
*
feCleanUpPath
(
char
* path)
525
{
526
#ifdef RESOURCE_DEBUG
527
printf(
"feCleanUpPath: entering with: =%s=\n"
, path);
528
#endif
529
if
(path ==
NULL
)
return
path;
530
531
int
n_comps = 1,
i
,
j
;
532
char
* opath = path;
533
char
** path_comps;
534
535
for
(; *path !=
'\0'
; path++)
536
{
537
if
(*path ==
fePathSep
) n_comps++;
538
else
if
(*path ==
';'
)
539
{
540
*path =
fePathSep
;
541
n_comps++;
542
}
543
}
544
545
path_comps = (
char
**)
malloc
(n_comps*
sizeof
(
char
*));
546
path_comps[0]=opath;
547
path=opath;
548
i
= 1;
549
550
if
(
i
< n_comps)
551
{
552
while
(1)
553
{
554
if
(*path ==
fePathSep
)
555
{
556
*path =
'\0'
;
557
path_comps[
i
] = path+1;
558
i
++;
559
if
(
i
== n_comps)
break
;
560
}
561
path++;
562
}
563
}
564
565
for
(
i
=0;
i
<n_comps;
i
++)
566
path_comps[
i
] =
feCleanUpFile
(path_comps[
i
]);
567
#ifdef RESOURCE_DEBUG
568
printf(
"feCleanUpPath: after CleanUpName: "
);
569
for
(
i
=0;
i
<n_comps;
i
++)
570
printf(
"%s:"
, path_comps[
i
]);
571
printf(
"\n"
);
572
#endif
573
574
for
(
i
=0;
i
<n_comps;)
575
{
576
#ifdef RESOURCE_DEBUG
577
if
(access(path_comps[
i
], X_OK | R_OK))
578
printf(
"feCleanUpPath: remove %d:%s -- can not access\n"
,
i
, path_comps[
i
]);
579
#endif
580
if
( ! access(path_comps[
i
], X_OK | R_OK))
581
{
582
// x- permission is granted -- we assume that it is a dir
583
for
(
j
=0;
j
<
i
;
j
++)
584
{
585
if
(strcmp(path_comps[
j
], path_comps[
i
]) == 0)
586
{
587
// found a duplicate
588
#ifdef RESOURCE_DEBUG
589
printf(
"feCleanUpPath: remove %d:%s -- equal to %d:%s\n"
,
j
, path_comps[
j
],
i
, path_comps[
i
]);
590
#endif
591
j
=
i
+1;
592
break
;
593
}
594
}
595
if
(
j
==
i
)
596
{
597
i
++;
598
continue
;
599
}
600
}
601
// now we can either not access or found a duplicate
602
path_comps[
i
] =
NULL
;
603
for
(
j
=
i
+1;
j
<n_comps;
j
++)
604
path_comps[
j
-1] = path_comps[
j
];
605
n_comps--;
606
}
607
608
609
// assemble everything again
610
for
(path=opath,
i
=0;
i
<n_comps-1;
i
++)
611
{
612
mystrcpy
(path, path_comps[
i
]);
613
path += strlen(path);
614
*path =
fePathSep
;
615
path++;
616
}
617
if
(n_comps)
618
{
619
mystrcpy
(path, path_comps[
i
]);
620
}
621
else
622
{
623
*opath =
'\0'
;
624
}
625
free
(path_comps);
626
#ifdef RESOURCE_DEBUG
627
printf(
"feCleanUpPath: leaving with path=%s=\n"
, opath);
628
#endif
629
return
opath;
630
}
631
632
// strcpy where source and destination may overlap
633
static
void
mystrcpy
(
char
* d,
char
*
s
)
634
{
635
/*assume(d != NULL && s != NULL);*/
636
while
(*
s
!=
'\0'
)
637
{
638
*d = *
s
;
639
d++;
640
s
++;
641
}
642
*d =
'\0'
;
643
}
644
645
/*****************************************************************
646
*
647
* feSprintf
648
*
649
*****************************************************************/
650
static
char
*
feSprintf
(
char
*
s
,
const
char
* fmt,
int
warn)
651
{
652
char
* s_in =
s
;
653
if
(fmt ==
NULL
)
return
NULL
;
654
655
while
(*fmt !=
'\0'
)
656
{
657
*
s
= *fmt;
658
659
if
(*fmt ==
'%'
&& *(fmt + 1) !=
'\0'
)
660
{
661
fmt++;
662
char
* r =
feResource
(*fmt, warn);
663
if
(r !=
NULL
)
664
{
665
strcpy(
s
, r);
666
s
+= strlen(r) - 1;
667
}
668
else
669
{
670
s
++;
671
*
s
= *fmt;
672
}
673
}
674
else
if
(*fmt ==
'$'
&& *(fmt + 1) !=
'\0'
)
675
{
676
fmt++;
677
char
*
v
=
s
+ 1;
678
while
(*fmt ==
'_'
||
679
(*fmt >=
'A'
&& *fmt <=
'Z'
) ||
680
(*fmt >=
'a'
&& *fmt <=
'z'
))
681
{
682
*
v
= *fmt;
683
v
++;
684
fmt++;
685
}
686
fmt--;
687
*
v
=
'\0'
;
688
v
=
getenv
(
s
+ 1);
689
if
(
v
!=
NULL
) strcpy(
s
,
v
);
690
s
+= strlen(
s
) - 1;
691
}
692
s
++;
693
fmt++;
694
}
695
*
s
=
'\0'
;
696
return
s_in;
697
}
698
l
int l
Definition
cfEzgcd.cc:100
i
int i
Definition
cfEzgcd.cc:132
argv0
char * argv0
Definition
coeffs_test_runner.cpp:14
s
const CanonicalForm int s
Definition
facAbsFact.cc:51
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition
facBivar.h:39
j
int j
Definition
facHensel.cc:110
feCleanUpFile
static char * feCleanUpFile(char *fname)
Definition
feResource.cc:466
feGetResourceConfig
static feResourceConfig feGetResourceConfig(const char id)
Definition
feResource.cc:210
feResourceDefault
static char * feResourceDefault(feResourceConfig config)
Definition
feResource.cc:240
feReInitResources
void feReInitResources()
Definition
feResource.cc:182
feArgv0
VAR char * feArgv0
Definition
feResource.cc:19
feSprintf
static char * feSprintf(char *s, const char *fmt, int warn=-1)
Definition
feResource.cc:650
feResourceConfigs
VAR feResourceConfig_s feResourceConfigs[]
Definition
feResource.cc:41
feInitResource
static char * feInitResource(feResourceConfig config, int warn)
Definition
feResource.cc:248
feCleanUpPath
static char * feCleanUpPath(char *path)
Definition
feResource.cc:524
feResource
static char * feResource(feResourceConfig config, int warn)
Definition
feResource.cc:233
feInitResources
void feInitResources(const char *argv0)
Definition
feResource.cc:160
feGetExpandedExecutable
static char * feGetExpandedExecutable()
Definition
feResource.cc:373
feCleanResourceValue
static char * feCleanResourceValue(feResourceType type, char *value)
Definition
feResource.cc:441
feVerifyResourceValue
static int feVerifyResourceValue(feResourceType type, char *value)
Definition
feResource.cc:411
feGetResource
char * feGetResource(const char id, int warn)
Definition
feResource.cc:145
MAXRESOURCELEN
#define MAXRESOURCELEN
Definition
feResource.cc:111
SINGULAR_DEFAULT_DIR
#define SINGULAR_DEFAULT_DIR
Definition
feResource.cc:27
mystrcpy
static void mystrcpy(char *d, char *s)
Definition
feResource.cc:633
feResource.h
fePathSep
const char fePathSep
Definition
feResource.h:58
DIR_SEP
#define DIR_SEP
Definition
feResource.h:6
feResourceConfig
feResourceConfig_s * feResourceConfig
Definition
feResource.h:31
feResourceType
feResourceType
Definition
feResource.h:20
feResBinary
@ feResBinary
Definition
feResource.h:20
feResPath
@ feResPath
Definition
feResource.h:20
feResDir
@ feResDir
Definition
feResource.h:20
feResUrl
@ feResUrl
Definition
feResource.h:20
feResUndef
@ feResUndef
Definition
feResource.h:20
feResFile
@ feResFile
Definition
feResource.h:20
feResourceConfig_s
Definition
feResource.h:23
getenv
char * getenv()
VAR
#define VAR
Definition
globaldefs.h:5
free
#define free
Definition
omAllocFunc.c:14
strdup
#define strdup
Definition
omAllocFunc.c:18
malloc
#define malloc
Definition
omAllocFunc.c:12
omFindExec
char * omFindExec(const char *name, char *exec)
Definition
omFindExec.c:315
omFindExec.h
NULL
#define NULL
Definition
omList.c:12
MAXPATHLEN
#define MAXPATHLEN
Definition
omRet2Info.c:22
Generated on
for My Project by
doxygen 1.17.0
for
Singular