1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: tesths.cc,v 1.58 1999-03-19 17:42:33 obachman Exp $ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT - initialize SINGULARs components, run Script and start SHELL |
---|
8 | */ |
---|
9 | |
---|
10 | #include <unistd.h> |
---|
11 | #include <string.h> |
---|
12 | #include <stdio.h> |
---|
13 | #include <stddef.h> |
---|
14 | #include <stdlib.h> |
---|
15 | #include <time.h> |
---|
16 | #include <errno.h> |
---|
17 | #include "version.h" |
---|
18 | #include "mod2.h" |
---|
19 | #include "tok.h" |
---|
20 | #include "ipshell.h" |
---|
21 | #include "sing_dld.h" |
---|
22 | #include "febase.h" |
---|
23 | #include "cntrlc.h" |
---|
24 | #include "mmemory.h" |
---|
25 | #include "silink.h" |
---|
26 | #include "ipid.h" |
---|
27 | #include "timer.h" |
---|
28 | #ifdef HAVE_FACTORY |
---|
29 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
30 | #include <factory.h> |
---|
31 | #endif |
---|
32 | #include "getopt.h" |
---|
33 | |
---|
34 | #ifndef MAXPATHLEN |
---|
35 | #define MAXPATHLEN 1024 |
---|
36 | #endif |
---|
37 | |
---|
38 | // define the long option names here |
---|
39 | #define LON_BATCH "batch" |
---|
40 | #define LON_EXECUTE "execute" |
---|
41 | #define LON_ECHO "echo" |
---|
42 | #define LON_HELP "help" |
---|
43 | #define LON_RANDOM "random" |
---|
44 | #define LON_QUIET "quiet" |
---|
45 | #define LON_NO_TTY "no-tty" |
---|
46 | #define LON_USER_OPTION "user-option" |
---|
47 | #define LON_VERSION "verbose" |
---|
48 | #define LON_MIN_TIME "min-time" |
---|
49 | #define LON_NO_STDLIB "no-stdlib" |
---|
50 | #define LON_NO_RC "no-rc" |
---|
51 | #define LON_TICKS_PER_SEC "ticks-per-sec" |
---|
52 | #define LON_TCLMODE "tclmode" |
---|
53 | #define LON_MP_PORT "MPport" |
---|
54 | #define LON_MP_HOST "MPhost" |
---|
55 | #define LON_NO_WARN "no-warn" |
---|
56 | #define LON_NO_OUT "no-out" |
---|
57 | // undocumented options |
---|
58 | #ifdef HAVE_MPSR |
---|
59 | #define LON_MP_TRANSP "MPtransp" |
---|
60 | #define LON_MP_MODE "MPmode" |
---|
61 | #endif |
---|
62 | |
---|
63 | #define LONG_OPTION_RETURN 13 |
---|
64 | static struct option longopts[] = |
---|
65 | { |
---|
66 | #ifdef HAVE_MPSR |
---|
67 | {LON_BATCH, 0, 0, 'b'}, |
---|
68 | #endif |
---|
69 | {LON_EXECUTE, 1, 0, 'c'}, |
---|
70 | {LON_ECHO, 2, 0, 'e'}, |
---|
71 | {LON_HELP, 0, 0, 'h'}, |
---|
72 | {LON_QUIET, 0, 0, 'q'}, |
---|
73 | {LON_RANDOM, 1, 0, 'r'}, |
---|
74 | {LON_NO_TTY, 0, 0, 't'}, |
---|
75 | {LON_USER_OPTION, 1, 0, 'u'}, |
---|
76 | {LON_VERSION, 0, 0, 'v'}, |
---|
77 | #ifdef HAVE_TCL |
---|
78 | {LON_TCLMODE, 0, 0, 'x'}, |
---|
79 | #endif |
---|
80 | {LON_NO_STDLIB, 0, 0, LONG_OPTION_RETURN}, |
---|
81 | {LON_NO_RC, 0, 0, LONG_OPTION_RETURN}, |
---|
82 | {LON_NO_WARN, 0, 0, LONG_OPTION_RETURN}, |
---|
83 | {LON_NO_OUT, 0, 0, LONG_OPTION_RETURN}, |
---|
84 | {LON_MIN_TIME, 1, 0, LONG_OPTION_RETURN}, |
---|
85 | #ifdef HAVE_MPSR |
---|
86 | {LON_MP_PORT, 1, 0, LONG_OPTION_RETURN}, |
---|
87 | {LON_MP_HOST, 1, 0, LONG_OPTION_RETURN}, |
---|
88 | #endif |
---|
89 | {LON_TICKS_PER_SEC, 1, 0, LONG_OPTION_RETURN}, |
---|
90 | // undocumented options |
---|
91 | #ifdef HAVE_MPSR |
---|
92 | {LON_MP_TRANSP, 1, 0, LONG_OPTION_RETURN}, |
---|
93 | {LON_MP_MODE, 1, 0, LONG_OPTION_RETURN}, |
---|
94 | #endif |
---|
95 | // terminator |
---|
96 | { 0, 0, 0, 0 } |
---|
97 | }; |
---|
98 | // #define SHORT_OPTS_STRING "bc:e::hqr:tu:v" |
---|
99 | #define SHORT_OPTS_STRING "bhqtvxec:r:u:" |
---|
100 | |
---|
101 | struct sing_option |
---|
102 | { |
---|
103 | const char* name; // as in option |
---|
104 | const char* arg_name;// name of argument, if has_arg > 0 |
---|
105 | const char* help; // (short) help string |
---|
106 | char* val; // (default) value of option: 0: not set 1:set |
---|
107 | // string:"" if has_arg > 0 |
---|
108 | }; |
---|
109 | |
---|
110 | // mention only documented options here |
---|
111 | static struct sing_option sing_longopts[] = |
---|
112 | { |
---|
113 | #ifdef HAVE_MPSR |
---|
114 | {LON_BATCH, 0, "Run in MP batch mode", 0}, |
---|
115 | #endif |
---|
116 | {LON_HELP, 0, "Print help message and exit", 0}, |
---|
117 | {LON_QUIET, 0, "Do not print start-up banner and library load messages", 0}, |
---|
118 | {LON_NO_TTY, 0, "Do not redefine the terminal characteristics", 0}, |
---|
119 | {LON_VERSION, 0, "Print extended version and configuration info", 0}, |
---|
120 | #ifdef HAVE_TCL |
---|
121 | {LON_TCLMODE, 0, "Run in TCL mode, i.e., with TCL user interface", 0}, |
---|
122 | #endif |
---|
123 | {LON_ECHO, "VAL", "Set value of variable `echo' to (integer) VAL", ""}, |
---|
124 | {LON_EXECUTE, "STRING", "Execute STRING on start-up", ""}, |
---|
125 | {LON_RANDOM, "SEED", "Seed random generator with integer (integer) SEED", ""}, |
---|
126 | {LON_USER_OPTION, "STRING", "Return STRING on `system(\"--user-option\")'", ""}, |
---|
127 | {LON_NO_STDLIB, 0, "Do not load `standard.lib' on start-up", 0}, |
---|
128 | {LON_NO_RC, 0, "Do not execute `.singularrc' file on start-up", 0}, |
---|
129 | {LON_NO_WARN, 0, "Do not display warning messages", 0}, |
---|
130 | {LON_NO_OUT, 0, "Suppress all output", 0}, |
---|
131 | {LON_MIN_TIME, "SECS", "Do not display times smaller than SECS (in seconds)", "0.5"}, |
---|
132 | #ifdef HAVE_MPSR |
---|
133 | {LON_MP_PORT, "PORT", "Use PORT number for MP conections", ""}, |
---|
134 | {LON_MP_HOST, "HOST", "Use HOST for MP connections", ""}, |
---|
135 | #endif |
---|
136 | {LON_TICKS_PER_SEC, "TICKS", "Sets unit of timer to TICKS per second", "1"}, |
---|
137 | { 0, 0, 0, 0 } |
---|
138 | }; |
---|
139 | |
---|
140 | static struct sing_option* mainGetSingOption(const char* name) |
---|
141 | { |
---|
142 | int i = 0; |
---|
143 | while (sing_longopts[i].name != 0) |
---|
144 | { |
---|
145 | if (strcmp(name, sing_longopts[i].name) == 0) |
---|
146 | return &(sing_longopts[i]); |
---|
147 | i++; |
---|
148 | } |
---|
149 | return NULL; |
---|
150 | } |
---|
151 | |
---|
152 | static void mainSetSingOptionValue(const char* name, char* value) |
---|
153 | { |
---|
154 | sing_option* sopt = mainGetSingOption(name); |
---|
155 | if (sopt != NULL) |
---|
156 | { |
---|
157 | sopt->val = value; |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | static char* mainGetSingOptionValue(const char* name) |
---|
163 | { |
---|
164 | sing_option* sopt = mainGetSingOption(name); |
---|
165 | if (sopt!=NULL) |
---|
166 | return sopt->val; |
---|
167 | return NULL; |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | // Prints help message |
---|
172 | static void mainHelp(const char* name) |
---|
173 | { |
---|
174 | int i = 0; |
---|
175 | struct sing_option *sopt; |
---|
176 | char tmp[20]; |
---|
177 | |
---|
178 | printf("Singular version %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1); |
---|
179 | printf(" %s [options] [file1 [file2 ...]]\n", name); |
---|
180 | printf("Options:\n"); |
---|
181 | |
---|
182 | while (longopts[i].name != 0) |
---|
183 | { |
---|
184 | sopt = mainGetSingOption(longopts[i].name); |
---|
185 | if (sopt != NULL) |
---|
186 | { |
---|
187 | if (longopts[i].has_arg > 0) |
---|
188 | { |
---|
189 | if (longopts[i].has_arg > 1) |
---|
190 | sprintf(tmp, "%s[=%s]", longopts[i].name, sopt->arg_name); |
---|
191 | else |
---|
192 | sprintf(tmp, "%s=%s", longopts[i].name, sopt->arg_name); |
---|
193 | |
---|
194 | printf(" %c%c --%-19s %s\n", |
---|
195 | (longopts[i].val != 0 ? '-' : ' '), |
---|
196 | (longopts[i].val != 0 ? longopts[i].val : ' '), |
---|
197 | tmp, |
---|
198 | sopt->help); |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | printf(" %c%c --%-19s %s\n", |
---|
203 | (longopts[i].val != 0 ? '-' : ' '), |
---|
204 | (longopts[i].val != 0 ? longopts[i].val : ' '), |
---|
205 | longopts[i].name, |
---|
206 | sopt->help); |
---|
207 | } |
---|
208 | } |
---|
209 | #ifndef NDEBUG |
---|
210 | else |
---|
211 | printf("--%s Undocumented\n", longopts[i].name); |
---|
212 | #endif |
---|
213 | i++; |
---|
214 | } |
---|
215 | |
---|
216 | printf("\nFor more information, type `help;' from within Singular or visit\n"); |
---|
217 | printf("http://www.mathematik.uni-kl.de/~zca/Singular or consult the\n"); |
---|
218 | printf("Singular manual (available as on-line info or printed manual).\n"); |
---|
219 | } |
---|
220 | |
---|
221 | // Prints usage message |
---|
222 | static void mainUsage(char* argv0) |
---|
223 | { |
---|
224 | printf("Use `%s --help' for a complete list of options\n", argv0); |
---|
225 | } |
---|
226 | |
---|
227 | #ifndef NDEBUG |
---|
228 | void mainOptionValues() |
---|
229 | { |
---|
230 | int i = 0; |
---|
231 | struct sing_option *sopt; |
---|
232 | |
---|
233 | while (longopts[i].name != 0) |
---|
234 | { |
---|
235 | sopt = mainGetSingOption(longopts[i].name); |
---|
236 | if (sopt != NULL) |
---|
237 | { |
---|
238 | if (sopt->val == NULL || sopt->val == (char*) 1) |
---|
239 | Print("// --%-10s %d\n", sopt->name, sopt->val); |
---|
240 | else |
---|
241 | Print("// --%-10s %s\n", sopt->name, sopt->val); |
---|
242 | } |
---|
243 | else |
---|
244 | Print("// --%s Undocumented \n", longopts[i].name); |
---|
245 | i++; |
---|
246 | } |
---|
247 | } |
---|
248 | #endif // NDEBUG |
---|
249 | |
---|
250 | BOOLEAN mainGetSingOptionValue(const char* name, char** val) |
---|
251 | { |
---|
252 | sing_option* sopt = mainGetSingOption(name); |
---|
253 | if (sopt == NULL) |
---|
254 | { |
---|
255 | *val = NULL; |
---|
256 | return FALSE; |
---|
257 | } |
---|
258 | else |
---|
259 | { |
---|
260 | *val = sopt->val; |
---|
261 | return TRUE; |
---|
262 | } |
---|
263 | } |
---|
264 | |
---|
265 | /*0 implementation*/ |
---|
266 | int main( /* main entry to Singular */ |
---|
267 | int argc, /* number of parameter */ |
---|
268 | char** argv) /* parameter array */ |
---|
269 | { |
---|
270 | char * thisfile; |
---|
271 | /* initialize components */ |
---|
272 | siRandomStart=inits(); |
---|
273 | #ifdef INIT_BUG |
---|
274 | jjInitTab1(); |
---|
275 | #endif |
---|
276 | #ifdef GENTABLE |
---|
277 | extern void ttGen1(); |
---|
278 | extern void ttGen2(); |
---|
279 | #ifndef __MWERKS__ |
---|
280 | extern mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables |
---|
281 | mpsr_ttGen(); |
---|
282 | #endif |
---|
283 | ttGen1(); |
---|
284 | ttGen2(); |
---|
285 | #else |
---|
286 | thisfile = argv[0]; |
---|
287 | BOOLEAN load_std_lib=TRUE; |
---|
288 | BOOLEAN load_rc = TRUE; |
---|
289 | char* execute_string = NULL; |
---|
290 | int optc, option_index; |
---|
291 | |
---|
292 | // do this first, because -v might print version path |
---|
293 | #ifndef __MWERKS__ |
---|
294 | feInitPaths(thisfile); |
---|
295 | #endif |
---|
296 | |
---|
297 | // parse command line options |
---|
298 | while((optc = getopt_long(argc, argv, |
---|
299 | SHORT_OPTS_STRING, longopts, &option_index)) |
---|
300 | != EOF) |
---|
301 | { |
---|
302 | switch(optc) |
---|
303 | { |
---|
304 | |
---|
305 | case 'b': |
---|
306 | #ifdef HAVE_MPSR |
---|
307 | feBatch=TRUE; |
---|
308 | mainSetSingOptionValue(LON_BATCH, (char*) 1); |
---|
309 | break; |
---|
310 | #else |
---|
311 | printf("%s: Option `-b' not supported in this configuration\n", argv[0]); |
---|
312 | mainUsage(argv[0]); |
---|
313 | exit(1); |
---|
314 | #endif |
---|
315 | |
---|
316 | case 'h': |
---|
317 | mainHelp(argv[0]); |
---|
318 | exit(0); |
---|
319 | |
---|
320 | case 'q': |
---|
321 | verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB)); |
---|
322 | mainSetSingOptionValue(LON_QUIET, (char*) 1); |
---|
323 | break; |
---|
324 | |
---|
325 | case 't': |
---|
326 | #if defined(HAVE_FEREAD) || defined(HAVE_READLINE) |
---|
327 | fe_use_fgets=TRUE; |
---|
328 | #endif |
---|
329 | mainSetSingOptionValue(LON_NO_TTY, (char*) 1); |
---|
330 | break; |
---|
331 | |
---|
332 | case 'v': |
---|
333 | printf("Singular for %s version %s (%d) %s %s\n", |
---|
334 | S_UNAME, S_VERSION1, |
---|
335 | SINGULAR_VERSION_ID,__DATE__,__TIME__); |
---|
336 | printf("with\n"); |
---|
337 | printf(versionString()); |
---|
338 | printf("\n\n"); |
---|
339 | mainSetSingOptionValue(LON_VERSION, (char*) 1); |
---|
340 | break; |
---|
341 | |
---|
342 | case 'x': |
---|
343 | #ifdef HAVE_TCL |
---|
344 | tclmode = TRUE; |
---|
345 | mainSetSingOptionValue(LON_TCLMODE, (char*) 1); |
---|
346 | verbose|=Sy_bit(V_SHOW_MEM); |
---|
347 | break; |
---|
348 | #else |
---|
349 | printf("%s: Option `-x' not supported in this configuration\n", argv[0]); |
---|
350 | mainUsage(argv[0]); |
---|
351 | exit(1); |
---|
352 | #endif |
---|
353 | |
---|
354 | case 'e': |
---|
355 | if (optarg != NULL) |
---|
356 | { |
---|
357 | errno = 0; |
---|
358 | si_echo = strtol(optarg, NULL, 10); |
---|
359 | if (errno) |
---|
360 | { |
---|
361 | printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_ECHO); |
---|
362 | mainUsage(argv[0]); |
---|
363 | exit(1); |
---|
364 | } |
---|
365 | if (si_echo < 0 || si_echo > 9) |
---|
366 | { |
---|
367 | printf("%s: `%s' argument for option `--%s' is not in valid range 0..9\n", |
---|
368 | argv[0], optarg, LON_ECHO); |
---|
369 | mainUsage(argv[0]); |
---|
370 | exit(1); |
---|
371 | } |
---|
372 | mainSetSingOptionValue(LON_ECHO, optarg); |
---|
373 | } |
---|
374 | else |
---|
375 | { |
---|
376 | si_echo = 1; |
---|
377 | mainSetSingOptionValue(LON_ECHO, "1"); |
---|
378 | } |
---|
379 | break; |
---|
380 | |
---|
381 | case 'c': |
---|
382 | execute_string = optarg; |
---|
383 | mainSetSingOptionValue(LON_EXECUTE, optarg); |
---|
384 | break; |
---|
385 | |
---|
386 | case 'r': |
---|
387 | errno = 0; |
---|
388 | siRandomStart = strtol(optarg, NULL, 10); |
---|
389 | if (errno || siRandomStart == 0) |
---|
390 | { |
---|
391 | printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_RANDOM); |
---|
392 | mainUsage(argv[0]); |
---|
393 | exit(1); |
---|
394 | } |
---|
395 | #ifdef buildin_rand |
---|
396 | siSeed=siRandomStart; |
---|
397 | #else |
---|
398 | srand((unsigned int)siRandomStart); |
---|
399 | #endif |
---|
400 | #ifdef HAVE_FACTORY |
---|
401 | factoryseed(siRandomStart); |
---|
402 | #endif |
---|
403 | mainSetSingOptionValue(LON_RANDOM, optarg); |
---|
404 | break; |
---|
405 | |
---|
406 | case 'u': |
---|
407 | mainSetSingOptionValue(LON_USER_OPTION, optarg); |
---|
408 | break; |
---|
409 | |
---|
410 | case LONG_OPTION_RETURN: |
---|
411 | if (strcmp(longopts[option_index].name, LON_NO_STDLIB) == 0) |
---|
412 | { |
---|
413 | load_std_lib = FALSE; |
---|
414 | mainSetSingOptionValue(LON_NO_STDLIB, (char*) 1); |
---|
415 | } |
---|
416 | else if (strcmp(longopts[option_index].name, LON_NO_RC) == 0) |
---|
417 | { |
---|
418 | load_rc = FALSE; |
---|
419 | mainSetSingOptionValue(LON_NO_RC, (char*) 1); |
---|
420 | } |
---|
421 | else if (strcmp(longopts[option_index].name, LON_NO_WARN) == 0) |
---|
422 | { |
---|
423 | feWarn = FALSE; |
---|
424 | mainSetSingOptionValue(LON_NO_WARN, (char*) 1); |
---|
425 | } |
---|
426 | else if (strcmp(longopts[option_index].name, LON_NO_OUT) == 0) |
---|
427 | { |
---|
428 | feOut = FALSE; |
---|
429 | mainSetSingOptionValue(LON_NO_OUT, (char*) 1); |
---|
430 | } |
---|
431 | else if (strcmp(longopts[option_index].name, LON_MIN_TIME) == 0) |
---|
432 | { |
---|
433 | double mintime = atof(optarg); |
---|
434 | if (mintime <= 0) |
---|
435 | { |
---|
436 | printf("%s: `%s' invalid float argument for option `--%s'\n", |
---|
437 | argv[0], optarg, LON_MIN_TIME); |
---|
438 | mainUsage(argv[0]); |
---|
439 | exit(1); |
---|
440 | } |
---|
441 | SetMinDisplayTime(mintime); |
---|
442 | mainSetSingOptionValue(LON_MIN_TIME, optarg); |
---|
443 | } |
---|
444 | #ifdef HAVE_MPSR |
---|
445 | else if (strcmp(longopts[option_index].name, LON_MP_PORT) == 0) |
---|
446 | { |
---|
447 | mainSetSingOptionValue(LON_MP_PORT, optarg); |
---|
448 | } |
---|
449 | else if (strcmp(longopts[option_index].name, LON_MP_HOST) == 0) |
---|
450 | { |
---|
451 | mainSetSingOptionValue(LON_MP_HOST, optarg); |
---|
452 | } |
---|
453 | #endif |
---|
454 | else if (strcmp(longopts[option_index].name, LON_TICKS_PER_SEC) == 0) |
---|
455 | { |
---|
456 | int ticks = atoi(optarg); |
---|
457 | if (ticks <= 0) |
---|
458 | { |
---|
459 | printf("%s: `%s' invalid integer argument for option `--%s'\n", |
---|
460 | argv[0], optarg, LON_TICKS_PER_SEC); |
---|
461 | mainUsage(argv[0]); |
---|
462 | exit(1); |
---|
463 | } |
---|
464 | SetTimerResolution(ticks); |
---|
465 | mainSetSingOptionValue(LON_TICKS_PER_SEC, optarg); |
---|
466 | } |
---|
467 | else |
---|
468 | // undocumented options |
---|
469 | #ifdef HAVE_MPSR |
---|
470 | if (strcmp(longopts[option_index].name, LON_MP_MODE) == 0 || |
---|
471 | strcmp(longopts[option_index].name, LON_MP_TRANSP) == 0) |
---|
472 | { |
---|
473 | /* ignore */ |
---|
474 | } |
---|
475 | else |
---|
476 | #endif |
---|
477 | assume(0); |
---|
478 | break; |
---|
479 | |
---|
480 | default: |
---|
481 | // Error message already emmited by getopt_long |
---|
482 | mainUsage(argv[0]); |
---|
483 | exit(1); |
---|
484 | } |
---|
485 | } |
---|
486 | /*. say hello */ |
---|
487 | { |
---|
488 | idhdl h; |
---|
489 | namespaceroot->push(NULL, "Top", 0, TRUE); |
---|
490 | #ifdef HAVE_NAMESPACES |
---|
491 | h=enterid(mstrdup("Top"), 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
492 | IDPACKAGE(h) = NSPACK(namespaceroot); |
---|
493 | IDPACKAGE(h)->language = LANG_TOP; |
---|
494 | #endif /* HAVE_NAMESPACES */ |
---|
495 | } |
---|
496 | if (BVERBOSE(0) && !feBatch) |
---|
497 | { |
---|
498 | printf( |
---|
499 | " SINGULAR /\n" |
---|
500 | " A Computer Algebra System for Polynomial Computations / version %s\n" |
---|
501 | " 0<\n" |
---|
502 | " by: G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n" |
---|
503 | #ifdef SDRING |
---|
504 | " preliminary experimental version\n" |
---|
505 | #endif |
---|
506 | "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\\n" |
---|
507 | , S_VERSION1,S_VERSION2); |
---|
508 | } |
---|
509 | else |
---|
510 | if (!feBatch) |
---|
511 | { |
---|
512 | #ifdef __MWERKS__ |
---|
513 | memcpy(stderr,stdout,sizeof(FILE)); |
---|
514 | #else |
---|
515 | dup2(1,2); |
---|
516 | #endif |
---|
517 | } |
---|
518 | slStandardInit(); |
---|
519 | dlInit(thisfile); |
---|
520 | myynest=0; |
---|
521 | if (load_std_lib) |
---|
522 | { |
---|
523 | int vv=verbose; |
---|
524 | verbose &= ~Sy_bit(V_LOAD_LIB); |
---|
525 | #ifdef HAVE_NAMESPACES |
---|
526 | iiLibCmd(mstrdup("standard.lib"),TRUE, TRUE); |
---|
527 | #else /* HAVE_NAMESPACES */ |
---|
528 | iiLibCmd(mstrdup("standard.lib"), TRUE); |
---|
529 | #endif /* HAVE_NAMESPACES */ |
---|
530 | verbose=vv; |
---|
531 | } |
---|
532 | errorreported = 0; |
---|
533 | mmMarkInitDBMCB(); |
---|
534 | #ifndef macintosh |
---|
535 | #if defined(HAVE_READLINE) |
---|
536 | fe_set_input_mode(); |
---|
537 | #endif |
---|
538 | #endif |
---|
539 | setjmp(si_start_jmpbuf); |
---|
540 | |
---|
541 | // Now, put things on the stack of stuff to do |
---|
542 | |
---|
543 | // Last thing to do is to execute given scripts |
---|
544 | if (optind < argc) |
---|
545 | { |
---|
546 | int i = argc - 1; |
---|
547 | while (i >= optind) |
---|
548 | { |
---|
549 | newFile(argv[i]); |
---|
550 | i--; |
---|
551 | } |
---|
552 | } |
---|
553 | else |
---|
554 | { |
---|
555 | currentVoice=feInitStdin(); |
---|
556 | } |
---|
557 | |
---|
558 | // before scripts, we execute -c, if it was given |
---|
559 | // now execute -c, if it was given |
---|
560 | if (execute_string != NULL) |
---|
561 | newBuffer(mstrdup(execute_string), BT_execute); |
---|
562 | |
---|
563 | // first thing, however, is to load .singularrc |
---|
564 | if (load_rc) |
---|
565 | { |
---|
566 | FILE * rc=myfopen(".singularrc","r"); |
---|
567 | if (rc!=NULL) |
---|
568 | { |
---|
569 | fclose(rc); |
---|
570 | newFile(".singularrc"); |
---|
571 | } |
---|
572 | else |
---|
573 | { |
---|
574 | char buf[MAXPATHLEN]; |
---|
575 | char *home = getenv("HOME"); |
---|
576 | if (home != NULL) |
---|
577 | { |
---|
578 | strcpy(buf, home); |
---|
579 | strcat(buf, "/.singularrc"); |
---|
580 | rc = myfopen(buf, "r"); |
---|
581 | if (rc != NULL) |
---|
582 | { |
---|
583 | fclose(rc); |
---|
584 | newFile(buf); |
---|
585 | } |
---|
586 | } |
---|
587 | } |
---|
588 | } |
---|
589 | |
---|
590 | /* start shell */ |
---|
591 | if (feBatch) |
---|
592 | { |
---|
593 | #ifdef HAVE_MPSR |
---|
594 | extern int Batch_do(const char* port, const char* host); |
---|
595 | return Batch_do(mainGetSingOptionValue(LON_MP_PORT), |
---|
596 | mainGetSingOptionValue(LON_MP_HOST)); |
---|
597 | #else |
---|
598 | assume(0); |
---|
599 | #endif |
---|
600 | } |
---|
601 | setjmp(si_start_jmpbuf); |
---|
602 | yyparse(); |
---|
603 | #endif |
---|
604 | //Print("at very end\n"); |
---|
605 | m2_end(0); |
---|
606 | return 0; |
---|
607 | } |
---|