1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id$ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT: generate mpsr_Tok.inc |
---|
8 | */ |
---|
9 | |
---|
10 | #include <stdlib.h> |
---|
11 | #include <string.h> |
---|
12 | #include <ctype.h> |
---|
13 | #include <stdio.h> |
---|
14 | #include <time.h> |
---|
15 | #include <unistd.h> |
---|
16 | |
---|
17 | #include <Singular/mod2.h> |
---|
18 | #include <Singular/tok.h> |
---|
19 | #include <Singular/grammar.h> |
---|
20 | |
---|
21 | #define ALLOW_PLURAL 1 |
---|
22 | #define NO_PLURAL 0 |
---|
23 | #define COMM_PLURAL 2 |
---|
24 | #define PLURAL_MASK 3 |
---|
25 | |
---|
26 | #define ALLOW_RING 4 |
---|
27 | #define NO_RING 0 |
---|
28 | |
---|
29 | |
---|
30 | /*=============== types =====================*/ |
---|
31 | struct _scmdnames |
---|
32 | { |
---|
33 | const char *name; |
---|
34 | short alias; |
---|
35 | short tokval; |
---|
36 | short toktype; |
---|
37 | }; |
---|
38 | typedef struct _scmdnames cmdnames; |
---|
39 | |
---|
40 | |
---|
41 | struct sValCmd2 |
---|
42 | { |
---|
43 | int p; |
---|
44 | short cmd; |
---|
45 | short res; |
---|
46 | short arg1; |
---|
47 | short arg2; |
---|
48 | short valid_for; |
---|
49 | }; |
---|
50 | struct sValCmd1 |
---|
51 | { |
---|
52 | int p; |
---|
53 | short cmd; |
---|
54 | short res; |
---|
55 | short arg; |
---|
56 | short valid_for; |
---|
57 | }; |
---|
58 | struct sValCmd3 |
---|
59 | { |
---|
60 | int p; |
---|
61 | short cmd; |
---|
62 | short res; |
---|
63 | short arg1; |
---|
64 | short arg2; |
---|
65 | short arg3; |
---|
66 | short valid_for; |
---|
67 | }; |
---|
68 | struct sValCmdM |
---|
69 | { |
---|
70 | int p; |
---|
71 | short cmd; |
---|
72 | short res; |
---|
73 | short number_of_args; /* -1: any, -2: any >0, .. */ |
---|
74 | short valid_for; |
---|
75 | }; |
---|
76 | |
---|
77 | |
---|
78 | #define jjWRONG 1 |
---|
79 | #define jjWRONG2 1 |
---|
80 | #define jjWRONG3 1 |
---|
81 | #define XS(A) A |
---|
82 | |
---|
83 | |
---|
84 | #define D(A) 2 |
---|
85 | #define IPARITH |
---|
86 | #define GENTABLE |
---|
87 | |
---|
88 | #include "table.h" |
---|
89 | |
---|
90 | const char * Tok2Cmdname(int tok) |
---|
91 | { |
---|
92 | int i = 0; |
---|
93 | if (tok < 0) |
---|
94 | { |
---|
95 | return cmds[0].name; |
---|
96 | } |
---|
97 | if (tok==COMMAND) return "command"; |
---|
98 | if (tok==ANY_TYPE) return "any_type"; |
---|
99 | if (tok==NONE) return "nothing"; |
---|
100 | //if (tok==IFBREAK) return "if_break"; |
---|
101 | //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys"; |
---|
102 | //if (tok==ORDER_VECTOR) return "ordering"; |
---|
103 | //if (tok==REF_VAR) return "ref"; |
---|
104 | //if (tok==OBJECT) return "object"; |
---|
105 | //if (tok==PRINT_EXPR) return "print_expr"; |
---|
106 | if (tok==IDHDL) return "identifier"; |
---|
107 | // we do not blackbox objects during table generation: |
---|
108 | // if (tok>MAX_TOK) return getBlackboxName(tok); |
---|
109 | while (cmds[i].tokval!=0) |
---|
110 | { |
---|
111 | if ((cmds[i].tokval == tok)&&(cmds[i].alias==0)) |
---|
112 | { |
---|
113 | return cmds[i].name; |
---|
114 | } |
---|
115 | i++; |
---|
116 | } |
---|
117 | return cmds[0].name; |
---|
118 | } |
---|
119 | |
---|
120 | const char * iiTwoOps(int t) |
---|
121 | { |
---|
122 | if (t<127) |
---|
123 | { |
---|
124 | static char ch[2]; |
---|
125 | switch (t) |
---|
126 | { |
---|
127 | case '&': |
---|
128 | return "and"; |
---|
129 | case '|': |
---|
130 | return "or"; |
---|
131 | default: |
---|
132 | ch[0]=t; |
---|
133 | ch[1]='\0'; |
---|
134 | return ch; |
---|
135 | } |
---|
136 | } |
---|
137 | switch (t) |
---|
138 | { |
---|
139 | case COLONCOLON: return "::"; |
---|
140 | case DOTDOT: return ".."; |
---|
141 | //case PLUSEQUAL: return "+="; |
---|
142 | //case MINUSEQUAL: return "-="; |
---|
143 | case MINUSMINUS: return "--"; |
---|
144 | case PLUSPLUS: return "++"; |
---|
145 | case EQUAL_EQUAL: return "=="; |
---|
146 | case LE: return "<="; |
---|
147 | case GE: return ">="; |
---|
148 | case NOTEQUAL: return "<>"; |
---|
149 | default: return Tok2Cmdname(t); |
---|
150 | } |
---|
151 | } |
---|
152 | /*-------------------------------------------------------------------*/ |
---|
153 | |
---|
154 | // some special cmds which do not fit in with the others, and |
---|
155 | // nevertheless need to be transmitted |
---|
156 | short ExtraCmds[] = |
---|
157 | { |
---|
158 | OPTION_CMD, |
---|
159 | NAMES_CMD, |
---|
160 | // RESERVEDNAME_CMD, |
---|
161 | PROC_CMD, |
---|
162 | MAP_CMD, |
---|
163 | PACKAGE_CMD, |
---|
164 | '=', |
---|
165 | 0 |
---|
166 | }; |
---|
167 | |
---|
168 | // This returns 1 if tok is a token which can appear in a Singular |
---|
169 | // (quoted) command, and 0 otherwise |
---|
170 | short IsCmdToken(short tok) |
---|
171 | { |
---|
172 | int i = 0; |
---|
173 | // cmds with one arg |
---|
174 | while (dArith1[i].cmd != 0) |
---|
175 | if (dArith1[i].cmd == tok) return 1; |
---|
176 | else i++; |
---|
177 | |
---|
178 | // cmds with two args |
---|
179 | i=0; |
---|
180 | while (dArith2[i].cmd != 0) |
---|
181 | if (dArith2[i].cmd == tok) return 1; |
---|
182 | else i++; |
---|
183 | |
---|
184 | // cmds with three args |
---|
185 | i=0; |
---|
186 | while (dArith3[i].cmd != 0) |
---|
187 | if (dArith3[i].cmd == tok) return 1; |
---|
188 | else i++; |
---|
189 | |
---|
190 | // cmds with many args |
---|
191 | i=0; |
---|
192 | while (dArithM[i].cmd != 0) |
---|
193 | if (dArithM[i].cmd == tok) return 1; |
---|
194 | else i++; |
---|
195 | |
---|
196 | // cmds which are somewhat special (like those having 0 args) |
---|
197 | i=0; |
---|
198 | while (ExtraCmds[i] != 0) |
---|
199 | if (ExtraCmds[i] == tok) return 1; |
---|
200 | else i++; |
---|
201 | |
---|
202 | return 0; |
---|
203 | } |
---|
204 | |
---|
205 | #ifdef HAVE_MPSR |
---|
206 | #include <Singular/mpsr.h> |
---|
207 | #include <Singular/mpsr_Tok.h> |
---|
208 | #define MAX_COP 256 // there may be at most 256 cops |
---|
209 | |
---|
210 | // this is the main data struct for storing the relation |
---|
211 | // Singular token <-> (Dict, OP) |
---|
212 | typedef struct mpsr_cmd |
---|
213 | { |
---|
214 | |
---|
215 | short tok; // The Singular token encoding |
---|
216 | |
---|
217 | // The MP Dict tag in which this token is defined, |
---|
218 | MP_DictTag_t dict; |
---|
219 | |
---|
220 | // The MP operator corresponding to this token |
---|
221 | MP_Common_t cop; // operator |
---|
222 | } mpsr_cmd; |
---|
223 | |
---|
224 | #define MAX_SR_DICT 5 |
---|
225 | |
---|
226 | // this provides a mapping from MP dict tags to more useful (small) |
---|
227 | // array indicies |
---|
228 | inline short mpdict2srdict(MP_DictTag_t dict) |
---|
229 | { |
---|
230 | if (dict == MP_SingularDict) return 0; |
---|
231 | else if (dict == MP_BasicDict) return 1; |
---|
232 | else if (dict == MP_PolyDict) return 2; |
---|
233 | else if (dict == MP_MatrixDict) return 3; |
---|
234 | else if (dict == MP_NumberDict) return 4; |
---|
235 | else return MAX_SR_DICT; |
---|
236 | } |
---|
237 | |
---|
238 | // This is the array which holds all mpsr_cmds |
---|
239 | // It is initialized in mpsr_tok.inc |
---|
240 | static mpsr_cmd mpsr_cmds[MAX_TOK]; |
---|
241 | |
---|
242 | // This is the array which stores the mapping from token to an mpsr_cmd |
---|
243 | // A value is either an index into mpsr_cmds, or MAX_TOK |
---|
244 | static short tok2mp[MAX_TOK]; |
---|
245 | |
---|
246 | // This is the array which stores the mapping from (dict, cop) to a |
---|
247 | // mpsr_cmd. First index mpdict2srdict(dict), second is cop |
---|
248 | static short mp2tok[MAX_SR_DICT][MAX_COP]; |
---|
249 | |
---|
250 | // This the list of all tokens which have an MP representation as a |
---|
251 | // cop in the Singular dictionary |
---|
252 | short sr_cmds[] = |
---|
253 | { |
---|
254 | OPTION_CMD, |
---|
255 | NAMES_CMD, |
---|
256 | ATTRIB_CMD, |
---|
257 | CHARSTR_CMD, |
---|
258 | CLOSE_CMD, |
---|
259 | DEF_CMD, |
---|
260 | DEGREE_CMD, |
---|
261 | DEFINED_CMD, |
---|
262 | E_CMD, |
---|
263 | EXECUTE_CMD, |
---|
264 | FREEMODULE_CMD, |
---|
265 | INT_CMD, |
---|
266 | INTERRED_CMD, |
---|
267 | INTMAT_CMD, |
---|
268 | INTVEC_CMD, |
---|
269 | IS_RINGVAR, |
---|
270 | KILLATTR_CMD, |
---|
271 | MAP_CMD, |
---|
272 | MEMORY_CMD, |
---|
273 | MONITOR_CMD, |
---|
274 | NAMEOF_CMD, |
---|
275 | NUMBER_CMD, |
---|
276 | NPARS_CMD, |
---|
277 | NVARS_CMD, |
---|
278 | OPEN_CMD, |
---|
279 | ORDSTR_CMD, |
---|
280 | PAR_CMD, |
---|
281 | PARSTR_CMD, |
---|
282 | PARDEG_CMD, |
---|
283 | POLY_CMD, |
---|
284 | PRINT_CMD, |
---|
285 | READ_CMD, |
---|
286 | SORTVEC_CMD, |
---|
287 | STRING_CMD, |
---|
288 | SYSTEM_CMD, |
---|
289 | TYPEOF_CMD, |
---|
290 | VECTOR_CMD, |
---|
291 | VAR_CMD, |
---|
292 | VARSTR_CMD, |
---|
293 | WEIGHT_CMD, |
---|
294 | '(', |
---|
295 | COEF_CMD, |
---|
296 | DELETE_CMD, |
---|
297 | FETCH_CMD, |
---|
298 | FIND_CMD, |
---|
299 | IMAP_CMD, |
---|
300 | INSERT_CMD, |
---|
301 | SIMPLIFY_CMD, |
---|
302 | SRES_CMD, |
---|
303 | DBPRINT_CMD, |
---|
304 | TEST_CMD, |
---|
305 | PROC_CMD, |
---|
306 | MSTD_CMD, |
---|
307 | RESERVEDNAME_CMD, |
---|
308 | WRITE_CMD, |
---|
309 | QRING_CMD, |
---|
310 | FGLM_CMD, |
---|
311 | FGLMQUOT_CMD, |
---|
312 | DUMP_CMD, |
---|
313 | GETDUMP_CMD, |
---|
314 | STATUS_CMD, |
---|
315 | LIB_CMD, |
---|
316 | PACKAGE_CMD |
---|
317 | }; |
---|
318 | |
---|
319 | // struct used for specifying the cmd <-> cop relations |
---|
320 | typedef struct cmd_cop |
---|
321 | { |
---|
322 | short cmd; |
---|
323 | MP_Common_t cop; |
---|
324 | } cmd_op; |
---|
325 | |
---|
326 | typedef struct cmd_dictcop |
---|
327 | { |
---|
328 | MP_DictTag_t dict; |
---|
329 | cmd_op cmd_ops[255]; |
---|
330 | } cmd_dictcop; |
---|
331 | |
---|
332 | cmd_dictcop cmd_dictcops[] = |
---|
333 | { |
---|
334 | { |
---|
335 | MP_PolyDict, |
---|
336 | // This is the list of all tokens which have an MP representation as a |
---|
337 | // cop in the Poly dictionary |
---|
338 | { |
---|
339 | {BETTI_CMD, MP_CopPolyBetti}, |
---|
340 | {CHARACTERISTIC_CMD, MP_CopPolyChar}, |
---|
341 | {CHAR_SERIES_CMD, MP_CopPolyCharSeries}, |
---|
342 | {CONTENT_CMD, MP_CopPolyClearDenom }, |
---|
343 | {DEG_CMD, MP_CopPolyDeg}, |
---|
344 | {DIM_CMD, MP_CopPolyDim}, |
---|
345 | {FAC_CMD, MP_CopPolyFactorize}, |
---|
346 | {FACSTD_CMD, MP_CopPolyFacStd}, |
---|
347 | {HILBERT_CMD, MP_CopPolyHilb}, |
---|
348 | {HOMOG_CMD, MP_CopPolyHomog}, |
---|
349 | {INDEPSET_CMD, MP_CopPolyInDepSet}, |
---|
350 | {IDEAL_CMD, MP_CopPolyIdeal}, |
---|
351 | {KBASE_CMD, MP_CopPolyKbase}, |
---|
352 | {LEAD_CMD, MP_CopPolyLead}, |
---|
353 | {LEADCOEF_CMD, MP_CopPolyLeadCoef}, |
---|
354 | {LEADEXP_CMD, MP_CopPolyLeadExp}, |
---|
355 | {MAXID_CMD, MP_CopPolyMaxIdeal}, |
---|
356 | {MINBASE_CMD, MP_CopPolyMinBase}, |
---|
357 | {MINRES_CMD, MP_CopPolyMinRes}, |
---|
358 | {MODUL_CMD, MP_CopPolyModule}, |
---|
359 | {MULTIPLICITY_CMD, MP_CopPolyMultiplicity}, |
---|
360 | {ORD_CMD, MP_CopPolyOrder}, |
---|
361 | {PRUNE_CMD, MP_CopPolyPrune}, |
---|
362 | {QHWEIGHT_CMD, MP_CopPolyQHWeight}, |
---|
363 | {REGULARITY_CMD, MP_CopPolyRegularity}, |
---|
364 | {RESULTANT_CMD, MP_CopPolyResultant}, |
---|
365 | {STD_CMD, MP_CopPolyStd}, |
---|
366 | {SYZYGY_CMD, MP_CopPolySyz}, |
---|
367 | {VDIM_CMD, MP_CopPolyVdim}, |
---|
368 | {COEFFS_CMD, MP_CopPolyCoeffs}, |
---|
369 | {CONTRACT_CMD, MP_CopPolyContract}, |
---|
370 | {ELIMINATION_CMD, MP_CopPolyEliminate}, |
---|
371 | {JET_CMD, MP_CopPolyJet}, |
---|
372 | {LIFT_CMD, MP_CopPolyLift}, |
---|
373 | {LIFTSTD_CMD, MP_CopPolyLiftstd}, |
---|
374 | {MODULO_CMD, MP_CopPolyModulo}, |
---|
375 | {MRES_CMD, MP_CopPolyMres}, |
---|
376 | {QUOTIENT_CMD, MP_CopPolyQuotient}, |
---|
377 | {REDUCE_CMD, MP_CopPolyReduce}, |
---|
378 | {PREIMAGE_CMD, MP_CopPolyPreimage}, |
---|
379 | {RES_CMD, MP_CopPolyRes}, |
---|
380 | {RING_CMD, MP_CopPolyRing}, |
---|
381 | {MAX_TOK, 0} |
---|
382 | } |
---|
383 | }, |
---|
384 | { |
---|
385 | MP_NumberDict, |
---|
386 | // This is the list of all tokens which have an MP representation as a |
---|
387 | // cop in the Number dictionary |
---|
388 | { |
---|
389 | {PRIME_CMD, MP_CopNumberPrime}, |
---|
390 | {EXTGCD_CMD, MP_CopNumberExtGcd}, |
---|
391 | {GCD_CMD, MP_CopNumberGcd}, |
---|
392 | {RANDOM_CMD, MP_CopNumberRandom}, |
---|
393 | {MAX_TOK, 0} |
---|
394 | } |
---|
395 | }, |
---|
396 | { |
---|
397 | MP_MatrixDict, |
---|
398 | // This is the list of all tokens which have an MP representation as a |
---|
399 | // cop in the Matrix dictionary |
---|
400 | { |
---|
401 | {BAREISS_CMD, MP_CopMatrixBareiss}, |
---|
402 | {COLS_CMD, MP_CopMatrixCols}, |
---|
403 | {DET_CMD, MP_CopMatrixDet}, |
---|
404 | {JACOB_CMD, MP_CopMatrixJacobi}, |
---|
405 | {MATRIX_CMD, MP_CopMatrixDenseMatrix}, |
---|
406 | {ROWS_CMD, MP_CopMatrixRows}, |
---|
407 | {TRACE_CMD, MP_CopMatrixTrace}, |
---|
408 | {TRANSPOSE_CMD, MP_CopMatrixTranspose}, |
---|
409 | {KOSZUL_CMD, MP_CopMatrixKoszul}, |
---|
410 | {MINOR_CMD, MP_CopMatrixMinor}, |
---|
411 | {WEDGE_CMD, MP_CopMatrixWedge}, |
---|
412 | {MAX_TOK, 0} |
---|
413 | } |
---|
414 | }, |
---|
415 | { |
---|
416 | MP_BasicDict, |
---|
417 | // This is the list of all tokens which have an MP representation as a |
---|
418 | // cop in the MP Basic dictionary |
---|
419 | { |
---|
420 | {PLUSPLUS, MP_CopBasicInc}, |
---|
421 | {MINUSMINUS, MP_CopBasicDec}, |
---|
422 | {COUNT_CMD, MP_CopBasicSize}, |
---|
423 | {LIST_CMD, MP_CopBasicList}, |
---|
424 | {'+', MP_CopBasicAdd}, |
---|
425 | {'-', MP_CopBasicMinus}, |
---|
426 | {'*', MP_CopBasicMult}, |
---|
427 | {'/', MP_CopBasicDiv}, |
---|
428 | {'%', MP_CopBasicMod}, |
---|
429 | {'^', MP_CopBasicPow}, |
---|
430 | {GE, MP_CopBasicGreaterEqual}, |
---|
431 | {'<', MP_CopBasicGreater}, |
---|
432 | {LE, MP_CopBasicLessEqual}, |
---|
433 | {'>', MP_CopBasicLess}, |
---|
434 | {'&', MP_CopBasicAnd}, |
---|
435 | {'|', MP_CopBasicOr}, |
---|
436 | {'=', MP_CopBasicAssign}, |
---|
437 | {EQUAL_EQUAL, MP_CopBasicEqual}, |
---|
438 | {NOTEQUAL, MP_CopBasicNotEqual}, |
---|
439 | {DOTDOT, MP_CopBasicRange}, |
---|
440 | {'[', MP_CopBasicIndex}, |
---|
441 | {DIFF_CMD, MP_CopBasicDiff}, |
---|
442 | {INTERSECT_CMD, MP_CopBasicInterSect}, |
---|
443 | {SUBST_CMD, MP_CopBasicSubst}, |
---|
444 | {NOT, MP_CopBasicNot}, |
---|
445 | {COLONCOLON, MP_CopBasicPackage}, |
---|
446 | {MAX_TOK, 0} |
---|
447 | } |
---|
448 | } |
---|
449 | }; |
---|
450 | |
---|
451 | |
---|
452 | // Given a Singular token, find matching (dict,op): Return 1 if one is |
---|
453 | // found, 0, otherwise |
---|
454 | static short GetMPDictTok(short tok, MP_DictTag_t *dict, MP_Common_t *cop) |
---|
455 | { |
---|
456 | short i, l, j; |
---|
457 | cmd_op *cmd_ops; |
---|
458 | |
---|
459 | // first, look through Singular specific commands |
---|
460 | l = sizeof(sr_cmds)/sizeof(short); |
---|
461 | if (l > MAX_COP) |
---|
462 | { |
---|
463 | fprintf(stderr, |
---|
464 | "Error: There are more than 256 entries in MP_SingularDict\n"); |
---|
465 | exit(1); |
---|
466 | } |
---|
467 | for (i=0; i<l; i++) |
---|
468 | if (sr_cmds[i] == tok) |
---|
469 | { |
---|
470 | *dict = MP_SingularDict; |
---|
471 | *cop = i; |
---|
472 | return 1; |
---|
473 | } |
---|
474 | |
---|
475 | // look through all the other dicts |
---|
476 | for (j=0; j<MAX_SR_DICT-1; j++) |
---|
477 | { |
---|
478 | cmd_ops = cmd_dictcops[j].cmd_ops; |
---|
479 | for (i=0; (cmd_ops[i]).cmd != MAX_TOK; i++) |
---|
480 | { |
---|
481 | if (i > MAX_COP) |
---|
482 | { |
---|
483 | fprintf(stderr, |
---|
484 | "Error: There are more than 256 entries in dict %d's\n",j); |
---|
485 | exit(1); |
---|
486 | } |
---|
487 | if (cmd_ops[i].cmd == tok) |
---|
488 | { |
---|
489 | *dict = cmd_dictcops[j].dict; |
---|
490 | *cop = cmd_ops[i].cop; |
---|
491 | return 1; |
---|
492 | } |
---|
493 | } |
---|
494 | } |
---|
495 | return 0; |
---|
496 | } |
---|
497 | |
---|
498 | |
---|
499 | // This actually generates the tables of mpsr_tok.inc |
---|
500 | char *mpsr_Tok_inc; |
---|
501 | void mpsr_ttGen() |
---|
502 | { |
---|
503 | mpsr_cmd mpsrcmds[MAX_TOK]; |
---|
504 | short tok2mp[MAX_TOK]; |
---|
505 | short mp2tok[MAX_SR_DICT][MAX_COP]; |
---|
506 | short max_cmd = 0, i, j; |
---|
507 | MP_Common_t cop; |
---|
508 | FILE *outfile; |
---|
509 | MP_DictTag_t dict; |
---|
510 | |
---|
511 | |
---|
512 | // init all arrays |
---|
513 | for (i=0; i<MAX_TOK; i++) |
---|
514 | { |
---|
515 | mpsrcmds[i].tok = MAX_TOK; |
---|
516 | tok2mp[i] = MAX_TOK; |
---|
517 | } |
---|
518 | for (i=0; i<MAX_SR_DICT; i++) |
---|
519 | for (j=0; j<MAX_COP; j++) |
---|
520 | mp2tok[i][j] = MAX_TOK; |
---|
521 | |
---|
522 | // Now go through all the token and test them |
---|
523 | for (i=0; i<MAX_TOK; i++) |
---|
524 | { |
---|
525 | if (IsCmdToken(i)) |
---|
526 | { |
---|
527 | if (GetMPDictTok(i, &dict, &cop)) |
---|
528 | { |
---|
529 | mpsrcmds[max_cmd].tok = i; |
---|
530 | mpsrcmds[max_cmd].dict = dict; |
---|
531 | mpsrcmds[max_cmd].cop = cop; |
---|
532 | tok2mp[i] = max_cmd; |
---|
533 | mp2tok[mpdict2srdict(dict)][cop] = i; |
---|
534 | max_cmd++; |
---|
535 | } |
---|
536 | //else |
---|
537 | //{ |
---|
538 | // fprintf(stderr, "Warning: mpsr_ttGen: Unknown Cmd Token: %d(%s)\n", |
---|
539 | // i, iiTwoOps(i)); |
---|
540 | // } |
---|
541 | } |
---|
542 | } |
---|
543 | |
---|
544 | // Generate the template file |
---|
545 | mpsr_Tok_inc=strdup("mpsr_Tok.xxxxxxxx"); |
---|
546 | int pid=getpid(); |
---|
547 | mpsr_Tok_inc[8]=(pid %10)+'0'; pid/=10; |
---|
548 | mpsr_Tok_inc[9]=(pid %10)+'0'; pid/=10; |
---|
549 | mpsr_Tok_inc[10]=(pid %10)+'0'; pid/=10; |
---|
550 | mpsr_Tok_inc[11]=(pid %10)+'0'; pid/=10; |
---|
551 | mpsr_Tok_inc[12]=(pid %10)+'0'; pid/=10; |
---|
552 | mpsr_Tok_inc[13]=(pid %10)+'0'; |
---|
553 | |
---|
554 | outfile = fopen(mpsr_Tok_inc, "w"); |
---|
555 | if (outfile == NULL) |
---|
556 | { |
---|
557 | fprintf(stderr, "Error: mpsr_ttGen: Cannot open file mpsr_Tok.inc\n"); |
---|
558 | exit(1); |
---|
559 | } |
---|
560 | |
---|
561 | // header |
---|
562 | fprintf(outfile, |
---|
563 | "/***************************************************************\n" |
---|
564 | "*\n" |
---|
565 | "* File: mpsr_tok.inc\n" |
---|
566 | "* Purpose: tables for mapping Singular cmds to/from MP (dict, op)\n" |
---|
567 | "*\n" |
---|
568 | "* THIS FILE WAS AUTOMATICALLY GENERATED BY mpsr_ttGen(). DO NOT EDIT!\n" |
---|
569 | "*\n" |
---|
570 | "***************************************************************/\n" |
---|
571 | "#ifndef MPSR_STRING_TABLES\n" |
---|
572 | "mpsr_cmd mpsr_cmds[] =\n" |
---|
573 | "{\n" |
---|
574 | " { %d,\t %d,\t %d }", mpsrcmds[0].tok, mpsrcmds[0].dict, mpsrcmds[0].cop); |
---|
575 | |
---|
576 | // mpsrcmds |
---|
577 | for (i=1; i<max_cmd; i++) |
---|
578 | { |
---|
579 | fprintf(outfile, ",\n { %d,\t %d,\t %d }", |
---|
580 | mpsrcmds[i].tok, mpsrcmds[i].dict, mpsrcmds[i].cop); |
---|
581 | } |
---|
582 | fprintf(outfile,"\n};\n\n"); |
---|
583 | |
---|
584 | // tok2mp |
---|
585 | fprintf(outfile, "short tok2mp[] = { %d", tok2mp[0]); |
---|
586 | for (i=1; i<MAX_TOK; i++) |
---|
587 | fprintf(outfile, ", %d", tok2mp[i]); |
---|
588 | fprintf(outfile, "};\n\n"); |
---|
589 | |
---|
590 | // mp2tok |
---|
591 | fprintf(outfile, "short mp2tok[MAX_SR_DICT][MAX_COP] = \n{"); |
---|
592 | for (i=0; i<MAX_SR_DICT; i++) |
---|
593 | { |
---|
594 | fprintf(outfile, "\n{\n"); |
---|
595 | for (j=0; j<MAX_COP; j++) |
---|
596 | { |
---|
597 | fprintf(outfile, " %d",mp2tok[i][j]); |
---|
598 | if (j!=MAX_COP-1) fprintf(outfile, ","); |
---|
599 | } |
---|
600 | if (i!=MAX_SR_DICT-1) fprintf(outfile, "},"); |
---|
601 | else fprintf(outfile, "}"); |
---|
602 | } |
---|
603 | fprintf(outfile,"\n};\n\n"); |
---|
604 | |
---|
605 | fprintf(outfile, "#else /* MPSR_STRING_TABLE */\n" |
---|
606 | "mpsr_cmd mpsr_cmds[] =\n" |
---|
607 | "{\n" |
---|
608 | "{ \"%s\",\t %d,\t %d }", |
---|
609 | iiTwoOps(mpsrcmds[0].tok), mpsrcmds[0].dict, mpsrcmds[0].cop); |
---|
610 | |
---|
611 | for (i=1; i<max_cmd; i++) |
---|
612 | { |
---|
613 | fprintf(outfile, ",\n { \"%s\",\t %d,\t %d }", |
---|
614 | iiTwoOps(mpsrcmds[i].tok), mpsrcmds[i].dict, mpsrcmds[i].cop); |
---|
615 | } |
---|
616 | fprintf(outfile, ",\n { NULL, \t 0, \t 0}"); |
---|
617 | fprintf(outfile,"\n};\n\n#endif /* ! MPSR_STRING_TABLE */"); |
---|
618 | |
---|
619 | fclose(outfile); |
---|
620 | } // That's all |
---|
621 | |
---|
622 | #else |
---|
623 | void mpsr_ttGen() |
---|
624 | { |
---|
625 | system("touch mpsr_Tok.xx"); |
---|
626 | } |
---|
627 | #endif |
---|
628 | |
---|
629 | int main() |
---|
630 | { |
---|
631 | mpsr_ttGen(); |
---|
632 | #ifdef HAVE_MPSR |
---|
633 | rename(mpsr_Tok_inc,"mpsr_Tok.inc"); |
---|
634 | #endif |
---|
635 | return 0; |
---|
636 | } |
---|