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