1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT: |
---|
6 | */ |
---|
7 | |
---|
8 | #include <string.h> |
---|
9 | #include <unistd.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include <stddef.h> |
---|
12 | #include <stdlib.h> |
---|
13 | #include <time.h> |
---|
14 | #include <limits.h> |
---|
15 | |
---|
16 | #include "mod2.h" |
---|
17 | #include "tok.h" |
---|
18 | #include "febase.h" |
---|
19 | #include "cntrlc.h" |
---|
20 | #include "mmemory.h" |
---|
21 | #include "page.h" |
---|
22 | #include "ipid.h" |
---|
23 | #include "ipshell.h" |
---|
24 | #include "kstd1.h" |
---|
25 | #include "subexpr.h" |
---|
26 | #include "timer.h" |
---|
27 | #include "intvec.h" |
---|
28 | #include "ring.h" |
---|
29 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
30 | |
---|
31 | #ifdef HAVE_LIBPARSER |
---|
32 | # include "libparse.h" |
---|
33 | #endif /* HAVE_LIBPARSER */ |
---|
34 | |
---|
35 | #ifdef HAVE_FACTORY |
---|
36 | #include <factory.h> |
---|
37 | #endif |
---|
38 | |
---|
39 | /* version strings */ |
---|
40 | #ifdef HAVE_LIBFAC_P |
---|
41 | extern const char * libfac_version; |
---|
42 | extern const char * libfac_date; |
---|
43 | #endif |
---|
44 | extern "C" { |
---|
45 | #include <gmp.h> |
---|
46 | } |
---|
47 | #ifdef HAVE_MPSR |
---|
48 | #include <MP_Config.h> |
---|
49 | #endif |
---|
50 | |
---|
51 | /*0 implementation*/ |
---|
52 | |
---|
53 | /*2 |
---|
54 | * initialize components of Singular |
---|
55 | */ |
---|
56 | int inits(void) |
---|
57 | { |
---|
58 | int t; |
---|
59 | /*4 signal handler:*/ |
---|
60 | init_signals(); |
---|
61 | /*4 randomize: */ |
---|
62 | t=initTimer(); |
---|
63 | /*t=(int)time(NULL);*/ |
---|
64 | if (t==0) t=1; |
---|
65 | #ifdef HAVE_RTIMER |
---|
66 | initRTimer(); |
---|
67 | #endif |
---|
68 | #ifdef buildin_rand |
---|
69 | siSeed=t; |
---|
70 | #else |
---|
71 | srand((unsigned int)t); |
---|
72 | #endif |
---|
73 | #ifdef HAVE_FACTORY |
---|
74 | factoryseed(t); |
---|
75 | #endif |
---|
76 | /*4 private data of other modules*/ |
---|
77 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
78 | sLastPrinted.rtyp=NONE; |
---|
79 | #ifdef HAVE_MPSR |
---|
80 | extern void mpsr_Init(); |
---|
81 | mpsr_Init(); |
---|
82 | #endif |
---|
83 | return t; |
---|
84 | } |
---|
85 | |
---|
86 | /*2 |
---|
87 | * the global exit routine of Singular |
---|
88 | */ |
---|
89 | extern "C" { |
---|
90 | void m2_end(short i) |
---|
91 | { |
---|
92 | #ifdef PAGE_TEST |
---|
93 | mmEndStat(); |
---|
94 | #endif |
---|
95 | #ifdef HAVE_TCL |
---|
96 | if (tclmode) |
---|
97 | { |
---|
98 | PrintTCL('Q',0,NULL); |
---|
99 | } |
---|
100 | #endif |
---|
101 | if (i<=0) |
---|
102 | { |
---|
103 | #ifdef HAVE_TCL |
---|
104 | if (!tclmode) |
---|
105 | #endif |
---|
106 | if (BVERBOSE(0)) |
---|
107 | { |
---|
108 | if (i==0) |
---|
109 | printf("Auf Wiedersehen.\n"); |
---|
110 | else |
---|
111 | printf("\n$Bye.\n"); |
---|
112 | } |
---|
113 | #ifndef macintosh |
---|
114 | #ifdef HAVE_FEREAD |
---|
115 | #ifdef HAVE_ATEXIT |
---|
116 | fe_reset_input_mode(); |
---|
117 | #else |
---|
118 | fe_reset_input_mode(0,NULL); |
---|
119 | #endif |
---|
120 | #else |
---|
121 | #ifdef HAVE_READLINE |
---|
122 | fe_reset_input_mode(); |
---|
123 | #endif |
---|
124 | #endif |
---|
125 | #endif |
---|
126 | #ifdef sun |
---|
127 | #ifndef __svr4__ |
---|
128 | _cleanup(); |
---|
129 | _exit(0); |
---|
130 | #endif |
---|
131 | #endif |
---|
132 | exit(0); |
---|
133 | } |
---|
134 | else |
---|
135 | { |
---|
136 | #ifdef HAVE_TCL |
---|
137 | if (!tclmode) |
---|
138 | #endif |
---|
139 | printf("\nhalt %d\n",i); |
---|
140 | } |
---|
141 | exit(i); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | /*2 |
---|
146 | * the renice routine for very large jobs |
---|
147 | * works only on unix machines, |
---|
148 | * testet on : linux, HP 9.0 |
---|
149 | * |
---|
150 | *#ifndef MSDOS |
---|
151 | *#ifndef macintosh |
---|
152 | *#include <sys/times.h> |
---|
153 | *#include <sys/resource.h> |
---|
154 | *extern "C" int setpriority(int,int,int); |
---|
155 | *void very_nice() |
---|
156 | *{ |
---|
157 | *#ifndef NO_SETPRIORITY |
---|
158 | * setpriority(PRIO_PROCESS,0,19); |
---|
159 | *#endif |
---|
160 | * sleep(10); |
---|
161 | *} |
---|
162 | *#else |
---|
163 | *void very_nice(){} |
---|
164 | *#endif |
---|
165 | *#else |
---|
166 | *void very_nice(){} |
---|
167 | *#endif |
---|
168 | */ |
---|
169 | |
---|
170 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
171 | #ifdef buildin_rand |
---|
172 | /* |
---|
173 | * |
---|
174 | * A prime modulus multiplicative linear congruential |
---|
175 | * generator (PMMLCG), or "Lehmer generator". |
---|
176 | * Implementation directly derived from the article: |
---|
177 | * |
---|
178 | * S. K. Park and K. W. Miller |
---|
179 | * Random Number Generators: Good Ones are Hard to Find |
---|
180 | * CACM vol 31, #10. Oct. 1988. pp 1192-1201. |
---|
181 | * |
---|
182 | * Using the following multiplier and modulus, we obtain a |
---|
183 | * generator which: |
---|
184 | * |
---|
185 | * 1) Has a full period: 1 to 2^31 - 2. |
---|
186 | * 2) Is testably "random" (see the article). |
---|
187 | * 3) Has a known implementation by E. L. Schrage. |
---|
188 | */ |
---|
189 | |
---|
190 | |
---|
191 | #define A 16807L /* A "good" multiplier */ |
---|
192 | #define M 2147483647L /* Modulus: 2^31 - 1 */ |
---|
193 | #define Q 127773L /* M / A */ |
---|
194 | #define R 2836L /* M % A */ |
---|
195 | |
---|
196 | |
---|
197 | int siSeed = 1L; |
---|
198 | |
---|
199 | |
---|
200 | int siRand() |
---|
201 | { |
---|
202 | siSeed = A * (siSeed % Q) - R * (siSeed / Q); |
---|
203 | |
---|
204 | if ( siSeed < 0 ) |
---|
205 | siSeed += M; |
---|
206 | |
---|
207 | return( siSeed ); |
---|
208 | } |
---|
209 | #endif |
---|
210 | |
---|
211 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
212 | #define HELP_OK 0 |
---|
213 | |
---|
214 | #ifdef buildin_help |
---|
215 | |
---|
216 | #define FIN_INDEX '\037' |
---|
217 | #define not ! |
---|
218 | #define HELP_NOT_OPEN 1 |
---|
219 | #define HELP_NOT_FOUND 2 |
---|
220 | #ifndef macintosh |
---|
221 | #define Index_File SINGULAR_INFODIR "/singular.hlp" |
---|
222 | #define Help_File SINGULAR_INFODIR "/singular.hlp" |
---|
223 | #else |
---|
224 | #define Index_File SINGULAR_INFODIR "singular.hlp" |
---|
225 | #define Help_File SINGULAR_INFODIR "singular.hlp" |
---|
226 | #endif |
---|
227 | #define BUF_LEN 128 |
---|
228 | #define IDX_LEN 64 |
---|
229 | #define MAX_LINES 21 |
---|
230 | |
---|
231 | static int compare(char *s1,char *s2) |
---|
232 | { |
---|
233 | for(;*s1==*s2;s1++,s2++) |
---|
234 | if(*s2=='\0') return(0); |
---|
235 | return(*s2); |
---|
236 | } |
---|
237 | |
---|
238 | #ifdef macintosh |
---|
239 | static char tolow(char p) |
---|
240 | #else |
---|
241 | static inline char tolow(char p) |
---|
242 | #endif |
---|
243 | { |
---|
244 | if (('A'<=p)&&(p<='Z')) return p | 040; |
---|
245 | return p; |
---|
246 | } |
---|
247 | |
---|
248 | /*************************************************/ |
---|
249 | static int show(unsigned long offset,FILE *help, char *close) |
---|
250 | { char buffer[BUF_LEN+1]; |
---|
251 | int lines = 0; |
---|
252 | |
---|
253 | if( help== NULL) |
---|
254 | if( (help = feFopen(Help_File, "r")) == NULL) |
---|
255 | return HELP_NOT_OPEN; |
---|
256 | |
---|
257 | fseek(help, (long)(offset+1), (int)0); |
---|
258 | while( !feof(help) |
---|
259 | && *fgets(buffer, BUF_LEN, help) != EOF |
---|
260 | && buffer[0] != FIN_INDEX) |
---|
261 | { |
---|
262 | printf("%s", buffer); |
---|
263 | if(lines++> MAX_LINES) |
---|
264 | { |
---|
265 | #ifdef macintosh |
---|
266 | printf("\n Press <RETURN> to continue or x and <RETURN> to exit help.\n"); |
---|
267 | #else |
---|
268 | printf("\n Press <RETURN> to continue or x to exit help.\n"); |
---|
269 | #endif |
---|
270 | fflush(stdout); |
---|
271 | *close = (char)getchar(); |
---|
272 | if(*close=='x') |
---|
273 | { |
---|
274 | getchar(); |
---|
275 | break; |
---|
276 | } |
---|
277 | lines=0; |
---|
278 | } |
---|
279 | } |
---|
280 | if(*close!='x') |
---|
281 | { |
---|
282 | #ifdef macintosh |
---|
283 | printf("\nEnd of part. Press <RETURN> to continue or x and <RETURN> to exit help.\n"); |
---|
284 | #else |
---|
285 | printf("\nEnd of part. Press <RETURN> to continue or x to exit help.\n"); |
---|
286 | #endif |
---|
287 | fflush(stdout); |
---|
288 | *close = (char)getchar(); |
---|
289 | if(*close=='x') |
---|
290 | getchar(); |
---|
291 | } |
---|
292 | return HELP_OK; |
---|
293 | } |
---|
294 | |
---|
295 | /*************************************************/ |
---|
296 | int singular_manual(char *str) |
---|
297 | { FILE *index=NULL,*help=NULL; |
---|
298 | unsigned long offset; |
---|
299 | char *p,close; |
---|
300 | int done = 0; |
---|
301 | char buffer[BUF_LEN+1], |
---|
302 | Index[IDX_LEN+1], |
---|
303 | String[IDX_LEN+1]; |
---|
304 | |
---|
305 | if( (index = feFopen(Index_File, "r",NULL,TRUE)) == NULL) |
---|
306 | { |
---|
307 | return HELP_NOT_OPEN; |
---|
308 | } |
---|
309 | |
---|
310 | for(p=str; *p; p++) *p = tolow(*p);/* */ |
---|
311 | do |
---|
312 | { |
---|
313 | p--; |
---|
314 | } |
---|
315 | while ((p != str) && (*p<=' ')); |
---|
316 | p++; |
---|
317 | *p='\0'; |
---|
318 | (void)sprintf(String, " %s ", str); |
---|
319 | |
---|
320 | while(!feof(index) |
---|
321 | && fgets(buffer, BUF_LEN, index) != (char *)0 |
---|
322 | && buffer[0] != FIN_INDEX); |
---|
323 | |
---|
324 | while(!feof(index)) |
---|
325 | { |
---|
326 | (void)fgets(buffer, BUF_LEN, index); /* */ |
---|
327 | (void)sscanf(buffer, "Node:%[^\177]\177%ld\n", Index, &offset); |
---|
328 | for(p=Index; *p; p++) *p = tolow(*p);/* */ |
---|
329 | (void)strcat(Index, " "); |
---|
330 | if( strstr(Index, String)!=NULL) |
---|
331 | { |
---|
332 | done++; (void)show(offset, help, &close); |
---|
333 | } |
---|
334 | Index[0]='\0'; |
---|
335 | if(close=='x') |
---|
336 | break; |
---|
337 | } |
---|
338 | (void)fclose(index); |
---|
339 | (void)fclose(help); |
---|
340 | if(not done) |
---|
341 | { |
---|
342 | Warn("`%s` not found",String); |
---|
343 | return HELP_NOT_FOUND; |
---|
344 | } |
---|
345 | return HELP_OK; |
---|
346 | } |
---|
347 | #endif // buildin_help |
---|
348 | /*************************************************/ |
---|
349 | |
---|
350 | void singular_help(char *str,BOOLEAN example) |
---|
351 | { |
---|
352 | char *s=str; |
---|
353 | while (*s==' ') s++; |
---|
354 | char *ss=s; |
---|
355 | while (*ss!='\0') ss++; |
---|
356 | while (*ss<=' ') |
---|
357 | { |
---|
358 | *ss='\0'; |
---|
359 | ss--; |
---|
360 | } |
---|
361 | #ifdef HAVE_NAMESPACES |
---|
362 | idhdl h, ns; |
---|
363 | iiname2hdl(s, &ns, &h); |
---|
364 | #else /* HAVE_NAMESPACES */ |
---|
365 | /* --------- is it a proc ? --------------------------------*/ |
---|
366 | idhdl h=idroot->get(s,myynest); |
---|
367 | #endif /* HAVE_NAMESPACES */ |
---|
368 | if ((h!=NULL) && (IDTYP(h)==PROC_CMD) |
---|
369 | && (example ||(strcmp(IDPROC(h)->libname, "standard.lib")!=0))) |
---|
370 | { |
---|
371 | char *lib=iiGetLibName(IDPROC(h)); |
---|
372 | Print("// proc %s ",s); |
---|
373 | if((lib==NULL)||(*lib=='\0')) |
---|
374 | { |
---|
375 | PrintLn(); |
---|
376 | } |
---|
377 | else |
---|
378 | { |
---|
379 | Print("from lib %s\n",lib); |
---|
380 | s=iiGetLibProcBuffer(IDPROC(h), example ? 2 : 0); |
---|
381 | if (!example) |
---|
382 | { |
---|
383 | PrintS(s); |
---|
384 | FreeL((ADDRESS)s); |
---|
385 | } |
---|
386 | else |
---|
387 | { |
---|
388 | if (s!=NULL) |
---|
389 | { |
---|
390 | if (strlen(s)>5) iiEStart(s,IDPROC(h)); |
---|
391 | else FreeL((ADDRESS)s); |
---|
392 | } |
---|
393 | } |
---|
394 | } |
---|
395 | } |
---|
396 | else if (example) |
---|
397 | { |
---|
398 | Werror("%s not found",s); |
---|
399 | } |
---|
400 | else |
---|
401 | { |
---|
402 | /* --------- is it a library ? --------------------------------*/ |
---|
403 | char libnamebuf[128]; |
---|
404 | FILE *fp=NULL; |
---|
405 | if ((str[1]!='\0') |
---|
406 | && ((fp=feFopen(str,"rb", libnamebuf))!=NULL)) |
---|
407 | { |
---|
408 | #ifdef HAVE_LIBPARSER |
---|
409 | extern FILE *yylpin; |
---|
410 | lib_style_types lib_style; // = OLD_LIBSTYLE; |
---|
411 | |
---|
412 | yylpin = fp; |
---|
413 | # ifdef HAVE_NAMESPACES |
---|
414 | yylplex(str, libnamebuf, &lib_style, IDROOT, FALSE, GET_INFO); |
---|
415 | # else /* HAVE_NAMESPACES */ |
---|
416 | yylplex(str, libnamebuf, &lib_style, GET_INFO); |
---|
417 | # endif /* HAVE_NAMESPACES */ |
---|
418 | reinit_yylp(); |
---|
419 | if(lib_style == OLD_LIBSTYLE) |
---|
420 | { |
---|
421 | char buf[256]; |
---|
422 | fseek(fp, 0, SEEK_SET); |
---|
423 | #else /* HAVE_LIBPARSER */ |
---|
424 | { char buf[256]; |
---|
425 | #endif /* HAVE_LIBPARSER */ |
---|
426 | Warn( "library %s has an old format. Please fix it for the next time", |
---|
427 | str); |
---|
428 | BOOLEAN found=FALSE; |
---|
429 | while (fgets( buf, sizeof(buf), fp)) |
---|
430 | { |
---|
431 | if (strncmp(buf,"//",2)==0) |
---|
432 | { |
---|
433 | if (found) return; |
---|
434 | } |
---|
435 | else if ((strncmp(buf,"proc ",5)==0)||(strncmp(buf,"LIB ",4)==0)) |
---|
436 | { |
---|
437 | if (!found) Warn("no help part in library found"); |
---|
438 | return; |
---|
439 | } |
---|
440 | else |
---|
441 | { |
---|
442 | found=TRUE; |
---|
443 | PrintS(buf); |
---|
444 | } |
---|
445 | } |
---|
446 | } |
---|
447 | #ifdef HAVE_LIBPARSER |
---|
448 | else |
---|
449 | { |
---|
450 | fclose( yylpin ); |
---|
451 | PrintS(text_buffer); |
---|
452 | FreeL(text_buffer); |
---|
453 | } |
---|
454 | #endif /* HAVE_LIBPARSER */ |
---|
455 | } |
---|
456 | /* --------- everything else is for the manual ----------------*/ |
---|
457 | else |
---|
458 | { |
---|
459 | #ifdef HAVE_TCL |
---|
460 | if(!tclmode) |
---|
461 | #endif |
---|
462 | #ifdef buildin_help |
---|
463 | singular_manual(str); |
---|
464 | #else |
---|
465 | system(feGetInfoCall(str)); |
---|
466 | #ifndef MSDOS |
---|
467 | //sprintf(tmp,"clear"); |
---|
468 | //system(tmp); |
---|
469 | #endif |
---|
470 | #endif |
---|
471 | } |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | |
---|
476 | struct soptionStruct |
---|
477 | { |
---|
478 | char * name; |
---|
479 | int setval; |
---|
480 | int resetval; |
---|
481 | }; |
---|
482 | |
---|
483 | struct soptionStruct optionStruct[]= |
---|
484 | { |
---|
485 | {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) }, |
---|
486 | {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) }, |
---|
487 | /* 2 Gebauer/Moeller */ |
---|
488 | {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) }, |
---|
489 | {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) }, |
---|
490 | {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) }, |
---|
491 | {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) }, |
---|
492 | /* 7 cancel unit */ |
---|
493 | {"morePairs", Sy_bit(OPT_MOREPAIRS), ~Sy_bit(OPT_MOREPAIRS) }, |
---|
494 | /* 9 return SB in syz, quotient, intersect */ |
---|
495 | {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) }, |
---|
496 | {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) }, |
---|
497 | /* 11-19 sort in L/T */ |
---|
498 | /* 20 redBest */ |
---|
499 | {"keepvars", Sy_bit(OPT_KEEPVARS), ~Sy_bit(OPT_KEEPVARS) }, |
---|
500 | {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) }, |
---|
501 | {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) }, |
---|
502 | {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) }, |
---|
503 | /* 25 no redTail(p)/redTail(s) */ |
---|
504 | {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) }, |
---|
505 | {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) }, |
---|
506 | /* 27 stop at HC (finiteDeterminacyTest) */ |
---|
507 | {"minRes", Sy_bit(OPT_MINRES), ~Sy_bit(OPT_MINRES) }, |
---|
508 | /* 30: use not regularity for syz */ |
---|
509 | {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) }, |
---|
510 | {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) }, |
---|
511 | /*special for "none" and also end marker for showOption:*/ |
---|
512 | {"ne", 0, 0 } |
---|
513 | }; |
---|
514 | |
---|
515 | struct soptionStruct verboseStruct[]= |
---|
516 | { |
---|
517 | {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) }, |
---|
518 | {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) }, |
---|
519 | {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) }, |
---|
520 | {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) }, |
---|
521 | {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) }, |
---|
522 | {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) }, |
---|
523 | {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) }, |
---|
524 | {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) }, |
---|
525 | {"debugMem", Sy_bit(V_DEBUG_MEM), ~Sy_bit(V_DEBUG_MEM) }, |
---|
526 | {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) }, |
---|
527 | {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) }, |
---|
528 | {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) }, |
---|
529 | {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) }, |
---|
530 | /*special for "none" and also end marker for showOption:*/ |
---|
531 | {"ne", 0, 0 } |
---|
532 | }; |
---|
533 | |
---|
534 | BOOLEAN setOption(leftv res, leftv v) |
---|
535 | { |
---|
536 | char *n; |
---|
537 | do |
---|
538 | { |
---|
539 | if (v->Typ()==STRING_CMD) |
---|
540 | { |
---|
541 | n=(char *)v->CopyD(); |
---|
542 | } |
---|
543 | else |
---|
544 | { |
---|
545 | if (v->name==NULL) |
---|
546 | return TRUE; |
---|
547 | if (v->rtyp==0) |
---|
548 | { |
---|
549 | n=v->name; |
---|
550 | v->name=NULL; |
---|
551 | } |
---|
552 | else |
---|
553 | { |
---|
554 | n=mstrdup(v->name); |
---|
555 | } |
---|
556 | } |
---|
557 | |
---|
558 | int i; |
---|
559 | |
---|
560 | if(strcmp(n,"get")==0) |
---|
561 | { |
---|
562 | intvec *w=new intvec(2); |
---|
563 | (*w)[0]=test; |
---|
564 | (*w)[1]=verbose; |
---|
565 | res->rtyp=INTVEC_CMD; |
---|
566 | res->data=(void *)w; |
---|
567 | goto okay; |
---|
568 | } |
---|
569 | if(strcmp(n,"set")==0) |
---|
570 | { |
---|
571 | if((v->next!=NULL) |
---|
572 | &&(v->next->Typ()==INTVEC_CMD)) |
---|
573 | { |
---|
574 | v=v->next; |
---|
575 | intvec *w=(intvec*)v->Data(); |
---|
576 | test=(*w)[0]; |
---|
577 | verbose=(*w)[1]; |
---|
578 | |
---|
579 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
580 | && rField_has_simple_inverse()) |
---|
581 | { |
---|
582 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
583 | } |
---|
584 | goto okay; |
---|
585 | } |
---|
586 | } |
---|
587 | if(strcmp(n,"none")==0) |
---|
588 | { |
---|
589 | test=0; |
---|
590 | verbose=0; |
---|
591 | goto okay; |
---|
592 | } |
---|
593 | for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++) |
---|
594 | { |
---|
595 | if (strcmp(n,optionStruct[i].name)==0) |
---|
596 | { |
---|
597 | if (optionStruct[i].setval & validOpts) |
---|
598 | { |
---|
599 | test |= optionStruct[i].setval; |
---|
600 | } |
---|
601 | else |
---|
602 | Warn("cannot set option"); |
---|
603 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
604 | && rField_has_simple_inverse()) |
---|
605 | { |
---|
606 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
607 | } |
---|
608 | goto okay; |
---|
609 | } |
---|
610 | else if ((strncmp(n,"no",2)==0) |
---|
611 | && (strcmp(n+2,optionStruct[i].name)==0)) |
---|
612 | { |
---|
613 | if (optionStruct[i].setval & validOpts) |
---|
614 | { |
---|
615 | test &= optionStruct[i].resetval; |
---|
616 | } |
---|
617 | else |
---|
618 | Warn("cannot clear option"); |
---|
619 | goto okay; |
---|
620 | } |
---|
621 | } |
---|
622 | for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++) |
---|
623 | { |
---|
624 | if (strcmp(n,verboseStruct[i].name)==0) |
---|
625 | { |
---|
626 | verbose |= verboseStruct[i].setval; |
---|
627 | #ifdef YYDEBUG |
---|
628 | #if YYDEBUG |
---|
629 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
630 | else yydebug=0; |
---|
631 | #endif |
---|
632 | #endif |
---|
633 | goto okay; |
---|
634 | } |
---|
635 | else if ((strncmp(n,"no",2)==0) |
---|
636 | && (strcmp(n+2,verboseStruct[i].name)==0)) |
---|
637 | { |
---|
638 | verbose &= verboseStruct[i].resetval; |
---|
639 | #ifdef YYDEBUG |
---|
640 | #if YYDEBUG |
---|
641 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
642 | else yydebug=0; |
---|
643 | #endif |
---|
644 | #endif |
---|
645 | goto okay; |
---|
646 | } |
---|
647 | } |
---|
648 | Werror("unknown option `%s`",n); |
---|
649 | okay: |
---|
650 | FreeL((ADDRESS)n); |
---|
651 | v=v->next; |
---|
652 | } while (v!=NULL); |
---|
653 | #ifdef HAVE_TCL |
---|
654 | if (tclmode) |
---|
655 | { |
---|
656 | BITSET tmp; |
---|
657 | int i; |
---|
658 | StringSetS(""); |
---|
659 | if ((test!=0)||(verbose!=0)) |
---|
660 | { |
---|
661 | tmp=test; |
---|
662 | if(tmp) |
---|
663 | { |
---|
664 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
665 | { |
---|
666 | if (optionStruct[i].setval & test) |
---|
667 | { |
---|
668 | StringAppend(" %s",optionStruct[i].name); |
---|
669 | tmp &=optionStruct[i].resetval; |
---|
670 | } |
---|
671 | } |
---|
672 | } |
---|
673 | tmp=verbose; |
---|
674 | if (tmp) |
---|
675 | { |
---|
676 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
677 | { |
---|
678 | if (verboseStruct[i].setval & tmp) |
---|
679 | { |
---|
680 | StringAppend(" %s",verboseStruct[i].name); |
---|
681 | tmp &=verboseStruct[i].resetval; |
---|
682 | } |
---|
683 | } |
---|
684 | } |
---|
685 | PrintTCLS('O',StringAppendS("")); |
---|
686 | StringSetS(""); |
---|
687 | } |
---|
688 | else |
---|
689 | { |
---|
690 | PrintTCLS('O'," "); |
---|
691 | } |
---|
692 | } |
---|
693 | #endif |
---|
694 | return FALSE; |
---|
695 | } |
---|
696 | |
---|
697 | char * showOption() |
---|
698 | { |
---|
699 | int i; |
---|
700 | BITSET tmp; |
---|
701 | |
---|
702 | StringSetS("//options:"); |
---|
703 | if ((test!=0)||(verbose!=0)) |
---|
704 | { |
---|
705 | tmp=test; |
---|
706 | if(tmp) |
---|
707 | { |
---|
708 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
709 | { |
---|
710 | if (optionStruct[i].setval & test) |
---|
711 | { |
---|
712 | StringAppend(" %s",optionStruct[i].name); |
---|
713 | tmp &=optionStruct[i].resetval; |
---|
714 | } |
---|
715 | } |
---|
716 | for (i=0; i<32; i++) |
---|
717 | { |
---|
718 | if (tmp & Sy_bit(i)) StringAppend(" %d",i); |
---|
719 | } |
---|
720 | } |
---|
721 | tmp=verbose; |
---|
722 | if (tmp) |
---|
723 | { |
---|
724 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
725 | { |
---|
726 | if (verboseStruct[i].setval & tmp) |
---|
727 | { |
---|
728 | StringAppend(" %s",verboseStruct[i].name); |
---|
729 | tmp &=verboseStruct[i].resetval; |
---|
730 | } |
---|
731 | } |
---|
732 | for (i=1; i<32; i++) |
---|
733 | { |
---|
734 | if (tmp & Sy_bit(i)) StringAppend(" %d",i+32); |
---|
735 | } |
---|
736 | } |
---|
737 | return mstrdup(StringAppendS("")); |
---|
738 | } |
---|
739 | else |
---|
740 | return mstrdup(StringAppendS(" none")); |
---|
741 | } |
---|
742 | |
---|
743 | char * versionString() |
---|
744 | { |
---|
745 | StringSetS("\t"); |
---|
746 | #ifdef HAVE_FACTORY |
---|
747 | StringAppend("factory(%s),", factoryVersion); |
---|
748 | #endif |
---|
749 | #ifdef HAVE_LIBFAC_P |
---|
750 | StringAppend("libfac(%s,%s),\n\t",libfac_version,libfac_date); |
---|
751 | #endif |
---|
752 | #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR) |
---|
753 | StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR); |
---|
754 | #elif defined (HAVE_SMALLGMP) |
---|
755 | StringAppendS("SmallGMP(2.0.2.0),"); |
---|
756 | #else |
---|
757 | StringAppendS("GMP(1.3),"); |
---|
758 | #endif |
---|
759 | #ifdef HAVE_MPSR |
---|
760 | StringAppend("MP(%s),",MP_VERSION); |
---|
761 | #endif |
---|
762 | #if defined(HAVE_READLINE) && !defined(FEREAD) |
---|
763 | StringAppendS("libreadline,"); |
---|
764 | #else |
---|
765 | #ifdef HAVE_FEREAD |
---|
766 | StringAppendS("emulated libreadline,"); |
---|
767 | #endif |
---|
768 | #endif |
---|
769 | #ifdef SRING |
---|
770 | StringAppendS("super algebra,"); |
---|
771 | #endif |
---|
772 | #ifdef DRING |
---|
773 | StringAppendS("Weyl algebra,"); |
---|
774 | #endif |
---|
775 | #ifdef HAVE_DBM |
---|
776 | StringAppendS("DBM,\n\t"); |
---|
777 | #else |
---|
778 | StringAppendS("\n\t"); |
---|
779 | #endif |
---|
780 | #ifdef HAVE_INFO |
---|
781 | StringAppendS("info,"); |
---|
782 | #endif |
---|
783 | #ifdef HAVE_NAMESPACES |
---|
784 | StringAppendS("Namespaces,"); |
---|
785 | #endif |
---|
786 | #ifdef HAVE_DYNAMIC_LOADING |
---|
787 | StringAppendS("DynamicLoading,"); |
---|
788 | #endif |
---|
789 | #ifdef TEST |
---|
790 | StringAppendS("TESTs,"); |
---|
791 | #endif |
---|
792 | #if YYDEBUG |
---|
793 | StringAppendS("YYDEBUG=1,"); |
---|
794 | #endif |
---|
795 | #ifdef MDEBUG |
---|
796 | StringAppend("MDEBUG=%d,",MDEBUG); |
---|
797 | #endif |
---|
798 | #ifdef MTRACK |
---|
799 | StringAppendS("MTRACK,"); |
---|
800 | #endif |
---|
801 | #ifdef PDEBUG |
---|
802 | StringAppendS("PDEBUG,"); |
---|
803 | #endif |
---|
804 | #ifdef KDEBUG |
---|
805 | StringAppendS("KDEBUG,"); |
---|
806 | #endif |
---|
807 | #ifdef TEST_MAC_ORDER |
---|
808 | StringAppendS("mac_order,"); |
---|
809 | #endif |
---|
810 | #ifndef __OPTIMIZE__ |
---|
811 | #ifdef __MWERKS__ |
---|
812 | StringAppendS(" Codewarrior 2.0,"); |
---|
813 | #else |
---|
814 | StringAppendS("-g,"); |
---|
815 | #endif |
---|
816 | #endif |
---|
817 | StringAppend("random=%d\n",siRandomStart); |
---|
818 | #ifndef __MWERKS__ |
---|
819 | #ifdef HAVE_INFO |
---|
820 | StringAppend("InfoFile : %s\n", feGetInfoFile()); |
---|
821 | StringAppend("InfoProgram: %s\n", feGetInfoProgram()); |
---|
822 | #endif |
---|
823 | StringAppend("Singular : %s\n",feGetExpandedExecutable()); |
---|
824 | return StringAppend("SearchPath : %s", feGetSearchPath()); |
---|
825 | #endif |
---|
826 | } |
---|