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