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