My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
Singular
feOpt.cc
Go to the documentation of this file.
1
/****************************************
2
* Computer Algebra System SINGULAR *
3
****************************************/
4
/*
5
* ABSTRACT: Implementation of option buisness
6
*/
7
8
9
#include <string.h>
10
11
#include "
kernel/mod2.h
"
12
13
#include "
factory/factory.h
"
14
15
#define FE_OPT_STRUCTURE
16
#include "
feOpt.h
"
17
18
#if !defined(GENERATE_OPTION_INDEX) && !defined(ESINGULAR) && !defined(TSINGULAR)
19
#include "
misc/options.h
"
20
#include "
misc/sirandom.h
"
21
#endif
22
23
#include "
fehelp.h
"
24
25
#ifdef HAVE_FLINT
26
#include <flint/flint.h>
27
#endif
28
29
const
char
SHORT_OPTS_STRING
[] =
"bdhpqstvxec:r:u:"
;
30
31
//////////////////////////////////////////////////////////////
32
//
33
// Generation of feOptIndex
34
//
35
#ifdef GENERATE_OPTION_INDEX
36
37
#include <stdio.h>
38
//#include <unistd.h>
39
//#include <stdlib.h>
40
int
main
()
41
{
42
FILE*
fd
;
43
#ifdef ESINGULAR
44
fd
= fopen(
"feOptES.xx"
,
"w"
);
45
#elif defined(TSINGULAR)
46
fd
= fopen(
"feOptTS.xx"
,
"w"
);
47
#else
48
fd
= fopen(
"feOpt.xx"
,
"w"
);
49
#endif
50
51
if
(
fd
==
NULL
) exit(1);
52
53
int
i
= 0;
54
55
fputs(
"typedef enum\n{\n"
,
fd
);
56
57
while
(
feOptSpec
[
i
].
name
!=
NULL
)
58
{
59
const
char
*
name
=
feOptSpec
[
i
].name;
60
fputs(
"FE_OPT_"
,
fd
);
61
while
(*
name
!= 0)
62
{
63
if
(*
name
==
'-'
)
64
{
65
putc(
'_'
,
fd
);
66
}
67
else
if
(*
name
>= 97 && *
name
<= 122)
68
{
69
putc(*
name
- 32,
fd
);
70
}
71
else
72
{
73
putc(*
name
,
fd
);
74
}
75
name
++;
76
}
77
if
(
i
== 0)
78
{
79
fputs(
"=0"
,
fd
);
80
}
81
i
++;
82
fputs(
",\n "
,
fd
);
83
}
84
85
fprintf(
fd
,
"FE_OPT_UNDEF\n} feOptIndex;\n"
);
86
fclose(
fd
);
87
#ifdef ESINGULAR
88
rename(
"feOptES.xx"
,
"feOptES.inc"
);
89
#elif defined(TSINGULAR)
90
rename(
"feOptTS.xx"
,
"feOptTS.inc"
);
91
#else
92
rename(
"feOpt.xx"
,
"feOpt.inc"
);
93
#endif
94
return
(0);
95
}
96
97
#else
// ! GENERATE_OPTION_INDEX
98
99
///////////////////////////////////////////////////////////////
100
//
101
// Getting Values
102
//
103
104
feOptIndex
feGetOptIndex
(
const
char
*
name
)
105
{
106
int
opt = 0;
107
108
while
(opt != (
int
)
FE_OPT_UNDEF
)
109
{
110
if
(strcmp(
feOptSpec
[opt].
name
,
name
) == 0)
111
return
(
feOptIndex
) opt;
112
opt = opt + 1;
113
}
114
return
FE_OPT_UNDEF
;
115
}
116
117
feOptIndex
feGetOptIndex
(
int
optc)
118
{
119
int
opt = 0;
120
121
if
(optc ==
LONG_OPTION_RETURN
)
return
FE_OPT_UNDEF
;
122
123
while
(opt != (
int
)
FE_OPT_UNDEF
)
124
{
125
if
(
feOptSpec
[opt].val == optc)
126
return
(
feOptIndex
) opt;
127
opt = opt + 1;
128
}
129
return
FE_OPT_UNDEF
;
130
}
131
132
///////////////////////////////////////////////////////////////
133
//
134
// Setting Values
135
//
136
//
137
// Return: NULL -- everything ok
138
// "error-string" on error
139
#if !defined(ESINGULAR) && !defined(TSINGULAR)
140
141
#include "
omalloc/omalloc.h
"
142
#include "
resources/feResource.h
"
143
#include "
kernel/oswrapper/feread.h
"
144
#include "
kernel/oswrapper/timer.h
"
145
146
#include "
ipshell.h
"
147
#include "
tok.h
"
148
#include "
sdb.h
"
149
#include "
cntrlc.h
"
150
151
#include <errno.h>
152
153
static
const
char
*
feOptAction
(
feOptIndex
opt);
154
const
char
*
feSetOptValue
(
feOptIndex
opt,
char
* optarg)
155
{
156
if
(opt ==
FE_OPT_UNDEF
)
return
"option undefined"
;
157
158
if
(
feOptSpec
[opt].type !=
feOptUntyped
)
159
{
160
if
(
feOptSpec
[opt].type !=
feOptString
)
161
{
162
if
(optarg !=
NULL
)
163
{
164
errno = 0;
165
feOptSpec
[opt].value = (
void
*) strtol(optarg,
NULL
, 10);
166
if
(errno)
return
"invalid integer argument"
;
167
}
168
else
169
{
170
feOptSpec
[opt].value = (
void
*) 0;
171
}
172
}
173
else
174
{
175
assume
(
feOptSpec
[opt].type ==
feOptString
);
176
if
(
feOptSpec
[opt].set &&
feOptSpec
[opt].value !=
NULL
)
177
omFree
(
feOptSpec
[opt].value);
178
if
(optarg !=
NULL
)
179
feOptSpec
[opt].value =
omStrDup
(optarg);
180
else
181
feOptSpec
[opt].value =
NULL
;
182
feOptSpec
[opt].set = 1;
183
}
184
}
185
return
feOptAction
(opt);
186
}
187
188
const
char
*
feSetOptValue
(
feOptIndex
opt,
int
optarg)
189
{
190
if
(opt ==
FE_OPT_UNDEF
)
return
"option undefined"
;
191
192
if
(
feOptSpec
[opt].type !=
feOptUntyped
)
193
{
194
if
(
feOptSpec
[opt].type ==
feOptString
)
195
return
"option value needs to be an integer"
;
196
197
feOptSpec
[opt].value = (
void
*)(
long
) optarg;
198
}
199
return
feOptAction
(opt);
200
}
201
202
static
const
char
*
feOptAction
(
feOptIndex
opt)
203
{
204
// do some special actions
205
switch
(opt)
206
{
207
case
FE_OPT_BATCH:
208
if
(
feOptSpec
[FE_OPT_BATCH].value)
209
fe_fgets_stdin
=
fe_fgets_dummy
;
210
return
NULL
;
211
212
case
FE_OPT_HELP:
213
feOptHelp
(
feArgv0
);
214
return
NULL
;
215
216
case
FE_OPT_PROFILE:
217
traceit
=1024;
218
return
NULL
;
219
220
case
FE_OPT_QUIET:
221
if
(
feOptSpec
[FE_OPT_QUIET].value)
222
si_opt_2
&= ~(
Sy_bit
(0)|
Sy_bit
(
V_LOAD_LIB
));
223
else
224
si_opt_2
|=
Sy_bit
(
V_LOAD_LIB
)|
Sy_bit
(0);
225
return
NULL
;
226
227
case
FE_OPT_NO_TTY:
228
if
(
feOptSpec
[FE_OPT_NO_TTY].value)
229
fe_fgets_stdin
=
fe_fgets
;
230
return
NULL
;
231
232
case
FE_OPT_SDB:
233
#ifdef HAVE_SDB
234
if
(
feOptSpec
[FE_OPT_SDB].value)
235
sdb_flags
= 1;
236
else
237
sdb_flags
= 0;
238
#endif
239
return
NULL
;
240
241
case
FE_OPT_VERSION:
242
{
243
char
*
s
=
versionString
();
244
printf(
"%s"
,
s
);
245
omFree
(
s
);
246
return
NULL
;
247
}
248
249
case
FE_OPT_ECHO:
250
si_echo
= (int) ((
long
)(
feOptSpec
[FE_OPT_ECHO].value));
251
if
(
si_echo < 0 || si_echo >
9)
252
return
"argument of option is not in valid range 0..9"
;
253
return
NULL
;
254
255
case
FE_OPT_RANDOM:
256
siRandomStart
= (
unsigned
int) ((
unsigned
long
)
257
(
feOptSpec
[FE_OPT_RANDOM].value));
258
siSeed
=
siRandomStart
;
259
factoryseed
(
siRandomStart
);
260
return
NULL
;
261
262
case
FE_OPT_EMACS:
263
if
(
feOptSpec
[FE_OPT_EMACS].value)
264
{
265
// print EmacsDir and InfoFile so that Emacs
266
// mode can pcik it up
267
Warn
(
"EmacsDir: %s"
, (
feResource
(
'e'
/*"EmacsDir"*/
) !=
NULL
?
268
feResource
(
'e'
/*"EmacsDir"*/
) :
""
));
269
Warn
(
"InfoFile: %s"
, (
feResource
(
'i'
/*"InfoFile"*/
) !=
NULL
?
270
feResource
(
'i'
/*"InfoFile"*/
) :
""
));
271
}
272
return
NULL
;
273
274
case
FE_OPT_NO_WARN:
275
if
(
feOptSpec
[FE_OPT_NO_WARN].value)
276
feWarn
=
FALSE
;
277
else
278
feWarn
=
TRUE
;
279
return
NULL
;
280
281
case
FE_OPT_NO_OUT:
282
if
(
feOptSpec
[FE_OPT_NO_OUT].value)
283
feOut
=
FALSE
;
284
else
285
feOut
=
TRUE
;
286
return
NULL
;
287
288
case
FE_OPT_MIN_TIME:
289
{
290
double
mintime
= atof((
char
*)
feOptSpec
[FE_OPT_MIN_TIME].value);
291
if
(
mintime
<= 0)
return
"invalid float argument"
;
292
SetMinDisplayTime
(
mintime
);
293
return
NULL
;
294
}
295
296
case
FE_OPT_BROWSER:
297
feHelpBrowser
((
char
*)
feOptSpec
[FE_OPT_BROWSER].value, 1);
298
299
case
FE_OPT_TICKS_PER_SEC:
300
{
301
int
ticks = (int) ((
long
)(
feOptSpec
[FE_OPT_TICKS_PER_SEC].value));
302
if
(ticks <= 0)
303
return
"integer argument must be larger than 0"
;
304
SetTimerResolution
(ticks);
305
return
NULL
;
306
}
307
308
case
FE_OPT_DUMP_VERSIONTUPLE:
309
{
310
feOptDumpVersionTuple
();
311
return
NULL
;
312
}
313
314
case
FE_OPT_FLINT_THREADS:
315
{
316
long
nthreads = (long)
feOptSpec
[FE_OPT_FLINT_THREADS].value;
317
#ifdef HAVE_FLINT
318
#if __FLINT_RELEASE >= 20503
319
nthreads = FLINT_MAX(nthreads, WORD(1));
320
flint_set_num_threads(nthreads);
321
int
* cpu_affinities =
new
int
[nthreads];
322
for
(
slong
i
= 0;
i
< nthreads;
i
++)
323
cpu_affinities[
i
] = (
int
)
i
;
324
flint_set_thread_affinity(cpu_affinities, nthreads);
325
delete
[] cpu_affinities;
326
return
NULL
;
327
#endif
328
#endif
329
#ifdef HAVE_NTL
330
#if NTL_MAJOR_VERSION>=10
331
#ifdef NTL_THREAD_BOOST
332
SetNumThreads(nthreads);
333
#endif
334
#endif
335
#endif
336
}
337
338
default
:
339
return
NULL
;
340
}
341
}
342
343
// Prints usage message
344
void
fePrintOptValues
()
345
{
346
int
i
= 0;
347
348
while
(
feOptSpec
[
i
].
name
!= 0)
349
{
350
if
(
feOptSpec
[
i
].
help
!=
NULL
&&
feOptSpec
[
i
].type !=
feOptUntyped
351
#ifndef
SING_NDEBUG
352
&& *(
feOptSpec
[
i
].
help
) !=
'/'
353
#endif
354
)
355
{
356
if
(
feOptSpec
[
i
].type ==
feOptString
)
357
{
358
if
(
feOptSpec
[
i
].value ==
NULL
)
359
{
360
Print
(
"// --%-15s\n"
,
feOptSpec
[
i
].
name
);
361
}
362
else
363
{
364
Print
(
"// --%-15s \"%s\"\n"
,
feOptSpec
[
i
].
name
, (
char
*)
feOptSpec
[
i
].value);
365
}
366
}
367
else
368
{
369
Print
(
"// --%-15s %d\n"
,
feOptSpec
[
i
].
name
, (
int
)(
long
)
feOptSpec
[
i
].value);
370
}
371
}
372
i
++;
373
}
374
}
375
376
#endif
// ! ESingular
377
378
// Prints help message
379
void
feOptHelp
(
const
char
*
name
)
380
{
381
int
i
= 0;
382
char
tmp[60];
383
#if defined(ESINGULAR)
384
printf(
"ESingular starts up Singular within emacs;\n"
);
385
#elif defined(TSINGULAR)
386
printf(
"TSingular starts up Singular within a terminal window;\n"
);
387
#endif
388
printf(
"Singular is a Computer Algebra System (CAS) for Polynomial Computations.\n"
);
389
printf(
"Usage: %s [options] [file1 [file2 ...]]\n"
,
name
);
390
printf(
"Options:\n"
);
391
392
while
(
feOptSpec
[
i
].
name
!= 0)
393
{
394
if
(
feOptSpec
[
i
].
help
!=
NULL
395
#ifdef
SING_NDEBUG
396
&& *(
feOptSpec
[
i
].
help
) !=
'/'
397
#endif
398
)
399
{
400
if
(
feOptSpec
[
i
].has_arg > 0)
401
{
402
if
(
feOptSpec
[
i
].has_arg > 1)
403
snprintf(tmp,60,
"%s[=%s]"
,
feOptSpec
[
i
].
name
,
feOptSpec
[
i
].arg_name);
404
else
405
snprintf(tmp,60,
"%s=%s"
,
feOptSpec
[
i
].
name
,
feOptSpec
[
i
].arg_name);
406
407
printf(
" %c%c --%-20s %s\n"
,
408
(
feOptSpec
[
i
].val !=
LONG_OPTION_RETURN
?
'-'
:
' '
),
409
(
feOptSpec
[
i
].val !=
LONG_OPTION_RETURN
?
feOptSpec
[
i
].val :
' '
),
410
tmp,
411
feOptSpec
[
i
].
help
);
412
}
413
else
414
{
415
printf(
" %c%c --%-20s %s\n"
,
416
(
feOptSpec
[
i
].val !=
LONG_OPTION_RETURN
?
'-'
:
' '
),
417
(
feOptSpec
[
i
].val !=
LONG_OPTION_RETURN
?
feOptSpec
[
i
].val :
' '
),
418
feOptSpec
[
i
].
name
,
419
feOptSpec
[
i
].
help
);
420
}
421
}
422
i
++;
423
}
424
425
printf(
"\nFor more information, type `help;' from within Singular or visit\n"
);
426
printf(
"https://www.singular.uni-kl.de or consult the\n"
);
427
printf(
"Singular manual (available as on-line info or html manual).\n"
);
428
}
429
430
void
feOptDumpVersionTuple
(
void
)
431
{
432
printf(
"%s\n"
,
VERSION
);
433
}
434
435
#endif
// GENERATE_OPTION_INDEX
TRUE
#define TRUE
Definition
auxiliary.h:101
FALSE
#define FALSE
Definition
auxiliary.h:97
i
int i
Definition
cfEzgcd.cc:132
factoryseed
void factoryseed(int s)
random seed initializer
Definition
cf_random.cc:186
siRandomStart
VAR int siRandomStart
Definition
cntrlc.cc:99
cntrlc.h
Print
#define Print
Definition
emacs.cc:80
Warn
#define Warn
Definition
emacs.cc:77
slong
#define slong
s
const CanonicalForm int s
Definition
facAbsFact.cc:51
factory.h
factory.h' is the user interface to Factory.
VERSION
#define VERSION
Definition
factoryconf.h:279
SING_NDEBUG
#define SING_NDEBUG
Definition
factoryconf.h:259
feOptIndex
feOptIndex
Definition
feOptGen.h:15
FE_OPT_UNDEF
@ FE_OPT_UNDEF
Definition
feOptGen.h:15
LONG_OPTION_RETURN
#define LONG_OPTION_RETURN
Definition
feOptTab.h:4
fePrintOptValues
void fePrintOptValues()
Definition
feOpt.cc:344
SHORT_OPTS_STRING
const char SHORT_OPTS_STRING[]
Definition
feOpt.cc:29
feGetOptIndex
feOptIndex feGetOptIndex(const char *name)
Definition
feOpt.cc:104
feSetOptValue
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition
feOpt.cc:154
feOptAction
static const char * feOptAction(feOptIndex opt)
Definition
feOpt.cc:202
feOptDumpVersionTuple
void feOptDumpVersionTuple(void)
Definition
feOpt.cc:430
feOptHelp
void feOptHelp(const char *name)
Definition
feOpt.cc:379
feOpt.h
feOptSpec
EXTERN_VAR struct fe_option feOptSpec[]
Definition
feOpt.h:17
feArgv0
VAR char * feArgv0
Definition
feResource.cc:19
feResource
static char * feResource(feResourceConfig config, int warn)
Definition
feResource.cc:244
feResource.h
si_echo
VAR int si_echo
Definition
febase.cc:35
feOptUntyped
@ feOptUntyped
Definition
fegetopt.h:77
feOptString
@ feOptString
Definition
fegetopt.h:77
feHelpBrowser
const char * feHelpBrowser(char *which, int warn)
Definition
fehelp.cc:249
fehelp.h
fe_fgets_dummy
char * fe_fgets_dummy(const char *, char *, int)
Definition
feread.cc:455
fe_fgets_stdin
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition
feread.cc:32
fe_fgets
char * fe_fgets(const char *pr, char *s, int size)
Definition
feread.cc:309
feread.h
ipshell.h
versionString
char * versionString()
Definition
misc_ip.cc:771
help
#define help
Definition
libparse.cc:1230
mod2.h
assume
#define assume(x)
Definition
mod2.h:389
omStrDup
#define omStrDup(s)
Definition
omAllocDecl.h:263
omFree
#define omFree(addr)
Definition
omAllocDecl.h:261
NULL
#define NULL
Definition
omList.c:12
omalloc.h
si_opt_2
VAR unsigned si_opt_2
Definition
options.c:6
options.h
Sy_bit
#define Sy_bit(x)
Definition
options.h:31
V_LOAD_LIB
#define V_LOAD_LIB
Definition
options.h:47
main
int main()
Definition
p_Procs_Generate.cc:219
feWarn
VAR BOOLEAN feWarn
Definition
reporter.cc:49
feOut
VAR BOOLEAN feOut
Definition
reporter.cc:50
traceit
EXTERN_VAR int traceit
Definition
reporter.h:24
sdb_flags
VAR int sdb_flags
Definition
sdb.cc:31
sdb.h
fd
int status int fd
Definition
si_signals.h:69
siSeed
VAR int siSeed
Definition
sirandom.c:30
sirandom.h
name
int name
New type name for int.
Definition
templateForC.h:21
SetMinDisplayTime
void SetMinDisplayTime(double mtime)
Definition
timer.cc:27
mintime
STATIC_VAR double mintime
Definition
timer.cc:20
SetTimerResolution
void SetTimerResolution(int res)
Definition
timer.cc:22
timer.h
tok.h
Generated on
for My Project by
doxygen 1.17.0
for
Singular