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