[0e1846] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[6d9cc6] | 4 | /* $Id: tesths.cc,v 1.64 1999-08-03 17:03:29 obachman Exp $ */ |
---|
[32df82] | 5 | |
---|
[0e1846] | 6 | /* |
---|
| 7 | * ABSTRACT - initialize SINGULARs components, run Script and start SHELL |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #include <unistd.h> |
---|
| 11 | #include <string.h> |
---|
| 12 | #include <stdio.h> |
---|
| 13 | #include <stddef.h> |
---|
| 14 | #include <stdlib.h> |
---|
| 15 | #include <time.h> |
---|
[32df82] | 16 | #include <errno.h> |
---|
[40edb03] | 17 | #include "version.h" |
---|
[0e1846] | 18 | #include "mod2.h" |
---|
| 19 | #include "tok.h" |
---|
| 20 | #include "ipshell.h" |
---|
[6a6dccc] | 21 | #include "sing_dld.h" |
---|
[0e1846] | 22 | #include "febase.h" |
---|
| 23 | #include "cntrlc.h" |
---|
| 24 | #include "mmemory.h" |
---|
| 25 | #include "silink.h" |
---|
[7def32f] | 26 | #include "ipid.h" |
---|
[ea986d] | 27 | #include "timer.h" |
---|
[473707b] | 28 | #include "sdb.h" |
---|
[43d6c5] | 29 | #ifdef HAVE_FACTORY |
---|
[fda54cc] | 30 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
| 31 | #include <factory.h> |
---|
[43d6c5] | 32 | #endif |
---|
[9c756f] | 33 | #include "getopt.h" |
---|
[eea2b0] | 34 | |
---|
| 35 | // define the long option names here |
---|
| 36 | #define LON_BATCH "batch" |
---|
[9c35ef] | 37 | #define LON_BROWSER "browser" |
---|
[eea2b0] | 38 | #define LON_EXECUTE "execute" |
---|
[6d9cc6] | 39 | #define LON_EMACS "emacs" |
---|
[eea2b0] | 40 | #define LON_ECHO "echo" |
---|
| 41 | #define LON_HELP "help" |
---|
| 42 | #define LON_RANDOM "random" |
---|
| 43 | #define LON_QUIET "quiet" |
---|
| 44 | #define LON_NO_TTY "no-tty" |
---|
| 45 | #define LON_USER_OPTION "user-option" |
---|
[5bfda2] | 46 | #define LON_VERSION "verbose" |
---|
[eea2b0] | 47 | #define LON_MIN_TIME "min-time" |
---|
| 48 | #define LON_NO_STDLIB "no-stdlib" |
---|
| 49 | #define LON_NO_RC "no-rc" |
---|
| 50 | #define LON_TICKS_PER_SEC "ticks-per-sec" |
---|
| 51 | #define LON_TCLMODE "tclmode" |
---|
| 52 | #define LON_MP_PORT "MPport" |
---|
| 53 | #define LON_MP_HOST "MPhost" |
---|
[12310e] | 54 | #define LON_NO_WARN "no-warn" |
---|
| 55 | #define LON_NO_OUT "no-out" |
---|
[f79b204] | 56 | #define LON_SDB "sdb" |
---|
[eea2b0] | 57 | // undocumented options |
---|
| 58 | #ifdef HAVE_MPSR |
---|
| 59 | #define LON_MP_TRANSP "MPtransp" |
---|
| 60 | #define LON_MP_MODE "MPmode" |
---|
| 61 | #endif |
---|
| 62 | |
---|
[04f9c7] | 63 | #define LONG_OPTION_RETURN 13 |
---|
[eea2b0] | 64 | static struct option longopts[] = |
---|
| 65 | { |
---|
| 66 | #ifdef HAVE_MPSR |
---|
[e54eb4] | 67 | {LON_BATCH, 0, 0, 'b'}, |
---|
[eea2b0] | 68 | #endif |
---|
[1a11bc] | 69 | {LON_EXECUTE, 1, 0, 'c'}, |
---|
[f79b204] | 70 | {LON_SDB, 0, 0, 'd'}, |
---|
[1a11bc] | 71 | {LON_ECHO, 2, 0, 'e'}, |
---|
[eea2b0] | 72 | {LON_HELP, 0, 0, 'h'}, |
---|
[e54eb4] | 73 | {LON_QUIET, 0, 0, 'q'}, |
---|
[1a11bc] | 74 | {LON_RANDOM, 1, 0, 'r'}, |
---|
[eea2b0] | 75 | {LON_NO_TTY, 0, 0, 't'}, |
---|
[1a11bc] | 76 | {LON_USER_OPTION, 1, 0, 'u'}, |
---|
[eea2b0] | 77 | {LON_VERSION, 0, 0, 'v'}, |
---|
| 78 | #ifdef HAVE_TCL |
---|
| 79 | {LON_TCLMODE, 0, 0, 'x'}, |
---|
| 80 | #endif |
---|
[9c35ef] | 81 | {LON_BROWSER, 1, 0, LONG_OPTION_RETURN}, |
---|
[6d9cc6] | 82 | {LON_EMACS, 0, 0, LONG_OPTION_RETURN}, |
---|
[5bfda2] | 83 | {LON_NO_STDLIB, 0, 0, LONG_OPTION_RETURN}, |
---|
| 84 | {LON_NO_RC, 0, 0, LONG_OPTION_RETURN}, |
---|
[12310e] | 85 | {LON_NO_WARN, 0, 0, LONG_OPTION_RETURN}, |
---|
[f79b204] | 86 | {LON_NO_OUT, 0, 0, LONG_OPTION_RETURN}, |
---|
[5bfda2] | 87 | {LON_MIN_TIME, 1, 0, LONG_OPTION_RETURN}, |
---|
[eea2b0] | 88 | #ifdef HAVE_MPSR |
---|
[5bfda2] | 89 | {LON_MP_PORT, 1, 0, LONG_OPTION_RETURN}, |
---|
| 90 | {LON_MP_HOST, 1, 0, LONG_OPTION_RETURN}, |
---|
[eea2b0] | 91 | #endif |
---|
[5bfda2] | 92 | {LON_TICKS_PER_SEC, 1, 0, LONG_OPTION_RETURN}, |
---|
[eea2b0] | 93 | // undocumented options |
---|
| 94 | #ifdef HAVE_MPSR |
---|
[5bfda2] | 95 | {LON_MP_TRANSP, 1, 0, LONG_OPTION_RETURN}, |
---|
| 96 | {LON_MP_MODE, 1, 0, LONG_OPTION_RETURN}, |
---|
[eea2b0] | 97 | #endif |
---|
| 98 | // terminator |
---|
| 99 | { 0, 0, 0, 0 } |
---|
| 100 | }; |
---|
| 101 | // #define SHORT_OPTS_STRING "bc:e::hqr:tu:v" |
---|
[f79b204] | 102 | #define SHORT_OPTS_STRING "bdhqtvxec:r:u:" |
---|
[eea2b0] | 103 | |
---|
| 104 | struct sing_option |
---|
| 105 | { |
---|
| 106 | const char* name; // as in option |
---|
| 107 | const char* arg_name;// name of argument, if has_arg > 0 |
---|
| 108 | const char* help; // (short) help string |
---|
[e54eb4] | 109 | char* val; // (default) value of option: 0: not set 1:set |
---|
[eea2b0] | 110 | // string:"" if has_arg > 0 |
---|
| 111 | }; |
---|
| 112 | |
---|
| 113 | // mention only documented options here |
---|
[e54eb4] | 114 | static struct sing_option sing_longopts[] = |
---|
[eea2b0] | 115 | { |
---|
| 116 | #ifdef HAVE_MPSR |
---|
[e54eb4] | 117 | {LON_BATCH, 0, "Run in MP batch mode", 0}, |
---|
[eea2b0] | 118 | #endif |
---|
[9c35ef] | 119 | {LON_BROWSER, "BROWSER", "Display help in BROWSER ([x,tk]info, netscape)", ""}, |
---|
[6d9cc6] | 120 | {LON_EMACS, 0, "Support singular-emacs mode", 0}, |
---|
[eea2b0] | 121 | {LON_HELP, 0, "Print help message and exit", 0}, |
---|
[9c35ef] | 122 | {LON_QUIET, 0, "Do not print start-up banner and library load messages", 0}, |
---|
[f79b204] | 123 | {LON_SDB, 0, "Enable sdb debugger (experimental)", 0}, |
---|
[eea2b0] | 124 | {LON_NO_TTY, 0, "Do not redefine the terminal characteristics", 0}, |
---|
| 125 | {LON_VERSION, 0, "Print extended version and configuration info", 0}, |
---|
| 126 | #ifdef HAVE_TCL |
---|
[de6147] | 127 | {LON_TCLMODE, 0, "Run in TCL mode, i.e., with TCL user interface", 0}, |
---|
[e54eb4] | 128 | #endif |
---|
[eea2b0] | 129 | {LON_ECHO, "VAL", "Set value of variable `echo' to (integer) VAL", ""}, |
---|
| 130 | {LON_EXECUTE, "STRING", "Execute STRING on start-up", ""}, |
---|
| 131 | {LON_RANDOM, "SEED", "Seed random generator with integer (integer) SEED", ""}, |
---|
| 132 | {LON_USER_OPTION, "STRING", "Return STRING on `system(\"--user-option\")'", ""}, |
---|
| 133 | {LON_NO_STDLIB, 0, "Do not load `standard.lib' on start-up", 0}, |
---|
| 134 | {LON_NO_RC, 0, "Do not execute `.singularrc' file on start-up", 0}, |
---|
[12310e] | 135 | {LON_NO_WARN, 0, "Do not display warning messages", 0}, |
---|
| 136 | {LON_NO_OUT, 0, "Suppress all output", 0}, |
---|
[eea2b0] | 137 | {LON_MIN_TIME, "SECS", "Do not display times smaller than SECS (in seconds)", "0.5"}, |
---|
| 138 | #ifdef HAVE_MPSR |
---|
| 139 | {LON_MP_PORT, "PORT", "Use PORT number for MP conections", ""}, |
---|
| 140 | {LON_MP_HOST, "HOST", "Use HOST for MP connections", ""}, |
---|
| 141 | #endif |
---|
| 142 | {LON_TICKS_PER_SEC, "TICKS", "Sets unit of timer to TICKS per second", "1"}, |
---|
| 143 | { 0, 0, 0, 0 } |
---|
| 144 | }; |
---|
| 145 | |
---|
| 146 | static struct sing_option* mainGetSingOption(const char* name) |
---|
| 147 | { |
---|
| 148 | int i = 0; |
---|
| 149 | while (sing_longopts[i].name != 0) |
---|
| 150 | { |
---|
| 151 | if (strcmp(name, sing_longopts[i].name) == 0) |
---|
| 152 | return &(sing_longopts[i]); |
---|
| 153 | i++; |
---|
| 154 | } |
---|
| 155 | return NULL; |
---|
| 156 | } |
---|
| 157 | |
---|
[9c35ef] | 158 | void mainSetSingOptionValue(const char* name, char* value) |
---|
[eea2b0] | 159 | { |
---|
| 160 | sing_option* sopt = mainGetSingOption(name); |
---|
| 161 | if (sopt != NULL) |
---|
| 162 | { |
---|
| 163 | sopt->val = value; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
[9c35ef] | 167 | char* mainGetSingOptionValue(const char* name) |
---|
[eea2b0] | 168 | { |
---|
| 169 | sing_option* sopt = mainGetSingOption(name); |
---|
| 170 | if (sopt!=NULL) |
---|
| 171 | return sopt->val; |
---|
| 172 | return NULL; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | // Prints help message |
---|
| 177 | static void mainHelp(const char* name) |
---|
| 178 | { |
---|
| 179 | int i = 0; |
---|
| 180 | struct sing_option *sopt; |
---|
| 181 | char tmp[20]; |
---|
| 182 | |
---|
[64c6d1] | 183 | printf("Singular version %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1); |
---|
[eea2b0] | 184 | printf(" %s [options] [file1 [file2 ...]]\n", name); |
---|
| 185 | printf("Options:\n"); |
---|
[e54eb4] | 186 | |
---|
[eea2b0] | 187 | while (longopts[i].name != 0) |
---|
| 188 | { |
---|
| 189 | sopt = mainGetSingOption(longopts[i].name); |
---|
| 190 | if (sopt != NULL) |
---|
| 191 | { |
---|
| 192 | if (longopts[i].has_arg > 0) |
---|
| 193 | { |
---|
| 194 | if (longopts[i].has_arg > 1) |
---|
| 195 | sprintf(tmp, "%s[=%s]", longopts[i].name, sopt->arg_name); |
---|
| 196 | else |
---|
| 197 | sprintf(tmp, "%s=%s", longopts[i].name, sopt->arg_name); |
---|
| 198 | |
---|
| 199 | printf(" %c%c --%-19s %s\n", |
---|
| 200 | (longopts[i].val != 0 ? '-' : ' '), |
---|
| 201 | (longopts[i].val != 0 ? longopts[i].val : ' '), |
---|
| 202 | tmp, |
---|
| 203 | sopt->help); |
---|
| 204 | } |
---|
| 205 | else |
---|
| 206 | { |
---|
| 207 | printf(" %c%c --%-19s %s\n", |
---|
| 208 | (longopts[i].val != 0 ? '-' : ' '), |
---|
| 209 | (longopts[i].val != 0 ? longopts[i].val : ' '), |
---|
| 210 | longopts[i].name, |
---|
| 211 | sopt->help); |
---|
| 212 | } |
---|
| 213 | } |
---|
[e54eb4] | 214 | #ifndef NDEBUG |
---|
[eea2b0] | 215 | else |
---|
| 216 | printf("--%s Undocumented\n", longopts[i].name); |
---|
| 217 | #endif |
---|
| 218 | i++; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | printf("\nFor more information, type `help;' from within Singular or visit\n"); |
---|
| 222 | printf("http://www.mathematik.uni-kl.de/~zca/Singular or consult the\n"); |
---|
| 223 | printf("Singular manual (available as on-line info or printed manual).\n"); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | // Prints usage message |
---|
| 227 | static void mainUsage(char* argv0) |
---|
| 228 | { |
---|
| 229 | printf("Use `%s --help' for a complete list of options\n", argv0); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | #ifndef NDEBUG |
---|
| 233 | void mainOptionValues() |
---|
| 234 | { |
---|
| 235 | int i = 0; |
---|
| 236 | struct sing_option *sopt; |
---|
| 237 | |
---|
| 238 | while (longopts[i].name != 0) |
---|
| 239 | { |
---|
| 240 | sopt = mainGetSingOption(longopts[i].name); |
---|
| 241 | if (sopt != NULL) |
---|
| 242 | { |
---|
| 243 | if (sopt->val == NULL || sopt->val == (char*) 1) |
---|
| 244 | Print("// --%-10s %d\n", sopt->name, sopt->val); |
---|
| 245 | else |
---|
[e54eb4] | 246 | Print("// --%-10s %s\n", sopt->name, sopt->val); |
---|
[eea2b0] | 247 | } |
---|
| 248 | else |
---|
| 249 | Print("// --%s Undocumented \n", longopts[i].name); |
---|
| 250 | i++; |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | #endif // NDEBUG |
---|
| 254 | |
---|
| 255 | BOOLEAN mainGetSingOptionValue(const char* name, char** val) |
---|
| 256 | { |
---|
| 257 | sing_option* sopt = mainGetSingOption(name); |
---|
| 258 | if (sopt == NULL) |
---|
| 259 | { |
---|
| 260 | *val = NULL; |
---|
| 261 | return FALSE; |
---|
| 262 | } |
---|
| 263 | else |
---|
| 264 | { |
---|
| 265 | *val = sopt->val; |
---|
| 266 | return TRUE; |
---|
| 267 | } |
---|
| 268 | } |
---|
[40edb03] | 269 | |
---|
[0e1846] | 270 | /*0 implementation*/ |
---|
| 271 | int main( /* main entry to Singular */ |
---|
| 272 | int argc, /* number of parameter */ |
---|
| 273 | char** argv) /* parameter array */ |
---|
| 274 | { |
---|
[07dacd] | 275 | char * thisfile; |
---|
[d754b7] | 276 | /* initialize components */ |
---|
[0e1846] | 277 | siRandomStart=inits(); |
---|
| 278 | #ifdef INIT_BUG |
---|
| 279 | jjInitTab1(); |
---|
| 280 | #endif |
---|
| 281 | #ifdef GENTABLE |
---|
[9c756f] | 282 | extern void ttGen1(); |
---|
| 283 | extern void ttGen2(); |
---|
| 284 | #ifndef __MWERKS__ |
---|
[99965c5] | 285 | extern mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables |
---|
| 286 | mpsr_ttGen(); |
---|
| 287 | #endif |
---|
[0e1846] | 288 | ttGen1(); |
---|
| 289 | ttGen2(); |
---|
| 290 | #else |
---|
[2c24d8d] | 291 | thisfile = argv[0]; |
---|
[9ea9c6] | 292 | BOOLEAN load_std_lib=TRUE; |
---|
[eea2b0] | 293 | BOOLEAN load_rc = TRUE; |
---|
| 294 | char* execute_string = NULL; |
---|
| 295 | int optc, option_index; |
---|
| 296 | |
---|
| 297 | // do this first, because -v might print version path |
---|
[9c35ef] | 298 | feInitResources(thisfile); |
---|
[eea2b0] | 299 | |
---|
| 300 | // parse command line options |
---|
| 301 | while((optc = getopt_long(argc, argv, |
---|
[e54eb4] | 302 | SHORT_OPTS_STRING, longopts, &option_index)) |
---|
[eea2b0] | 303 | != EOF) |
---|
[0e1846] | 304 | { |
---|
[eea2b0] | 305 | switch(optc) |
---|
[0e1846] | 306 | { |
---|
[e0d91c] | 307 | |
---|
[eea2b0] | 308 | case 'b': |
---|
[e0d91c] | 309 | #ifdef HAVE_MPSR |
---|
[eea2b0] | 310 | feBatch=TRUE; |
---|
| 311 | mainSetSingOptionValue(LON_BATCH, (char*) 1); |
---|
| 312 | break; |
---|
[40edb03] | 313 | #else |
---|
[eea2b0] | 314 | printf("%s: Option `-b' not supported in this configuration\n", argv[0]); |
---|
| 315 | mainUsage(argv[0]); |
---|
| 316 | exit(1); |
---|
| 317 | #endif |
---|
| 318 | case 'h': |
---|
| 319 | mainHelp(argv[0]); |
---|
| 320 | exit(0); |
---|
| 321 | |
---|
| 322 | case 'q': |
---|
| 323 | verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB)); |
---|
| 324 | mainSetSingOptionValue(LON_QUIET, (char*) 1); |
---|
| 325 | break; |
---|
| 326 | |
---|
| 327 | case 't': |
---|
| 328 | #if defined(HAVE_FEREAD) || defined(HAVE_READLINE) |
---|
| 329 | fe_use_fgets=TRUE; |
---|
[40edb03] | 330 | #endif |
---|
[eea2b0] | 331 | mainSetSingOptionValue(LON_NO_TTY, (char*) 1); |
---|
| 332 | break; |
---|
| 333 | |
---|
[f79b204] | 334 | case 'd': |
---|
| 335 | sdb_flags = 1; |
---|
| 336 | break; |
---|
| 337 | |
---|
[eea2b0] | 338 | case 'v': |
---|
[72f950] | 339 | printf("Singular for %s version %s (%d) %s %s\n", |
---|
| 340 | S_UNAME, S_VERSION1, |
---|
[eea2b0] | 341 | SINGULAR_VERSION_ID,__DATE__,__TIME__); |
---|
| 342 | printf("with\n"); |
---|
| 343 | printf(versionString()); |
---|
| 344 | printf("\n\n"); |
---|
| 345 | mainSetSingOptionValue(LON_VERSION, (char*) 1); |
---|
| 346 | break; |
---|
| 347 | |
---|
| 348 | case 'x': |
---|
| 349 | #ifdef HAVE_TCL |
---|
| 350 | tclmode = TRUE; |
---|
[de6147] | 351 | mainSetSingOptionValue(LON_TCLMODE, (char*) 1); |
---|
[e0d91c] | 352 | verbose|=Sy_bit(V_SHOW_MEM); |
---|
[eea2b0] | 353 | break; |
---|
| 354 | #else |
---|
| 355 | printf("%s: Option `-x' not supported in this configuration\n", argv[0]); |
---|
| 356 | mainUsage(argv[0]); |
---|
| 357 | exit(1); |
---|
| 358 | #endif |
---|
| 359 | |
---|
| 360 | case 'e': |
---|
| 361 | if (optarg != NULL) |
---|
[ea986d] | 362 | { |
---|
[eea2b0] | 363 | errno = 0; |
---|
| 364 | si_echo = strtol(optarg, NULL, 10); |
---|
| 365 | if (errno) |
---|
| 366 | { |
---|
| 367 | printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_ECHO); |
---|
| 368 | mainUsage(argv[0]); |
---|
| 369 | exit(1); |
---|
| 370 | } |
---|
| 371 | if (si_echo < 0 || si_echo > 9) |
---|
| 372 | { |
---|
| 373 | printf("%s: `%s' argument for option `--%s' is not in valid range 0..9\n", |
---|
| 374 | argv[0], optarg, LON_ECHO); |
---|
| 375 | mainUsage(argv[0]); |
---|
| 376 | exit(1); |
---|
| 377 | } |
---|
| 378 | mainSetSingOptionValue(LON_ECHO, optarg); |
---|
[ea986d] | 379 | } |
---|
| 380 | else |
---|
[eea2b0] | 381 | { |
---|
| 382 | si_echo = 1; |
---|
| 383 | mainSetSingOptionValue(LON_ECHO, "1"); |
---|
| 384 | } |
---|
| 385 | break; |
---|
[9ea9c6] | 386 | |
---|
[eea2b0] | 387 | case 'c': |
---|
| 388 | execute_string = optarg; |
---|
| 389 | mainSetSingOptionValue(LON_EXECUTE, optarg); |
---|
| 390 | break; |
---|
[e0d91c] | 391 | |
---|
[eea2b0] | 392 | case 'r': |
---|
| 393 | errno = 0; |
---|
| 394 | siRandomStart = strtol(optarg, NULL, 10); |
---|
[b1e0d72] | 395 | if (errno || siRandomStart == 0) |
---|
[eea2b0] | 396 | { |
---|
| 397 | printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_RANDOM); |
---|
| 398 | mainUsage(argv[0]); |
---|
| 399 | exit(1); |
---|
| 400 | } |
---|
| 401 | #ifdef buildin_rand |
---|
| 402 | siSeed=siRandomStart; |
---|
| 403 | #else |
---|
| 404 | srand((unsigned int)siRandomStart); |
---|
| 405 | #endif |
---|
| 406 | #ifdef HAVE_FACTORY |
---|
| 407 | factoryseed(siRandomStart); |
---|
| 408 | #endif |
---|
| 409 | mainSetSingOptionValue(LON_RANDOM, optarg); |
---|
| 410 | break; |
---|
[e0d91c] | 411 | |
---|
[eea2b0] | 412 | case 'u': |
---|
| 413 | mainSetSingOptionValue(LON_USER_OPTION, optarg); |
---|
| 414 | break; |
---|
| 415 | |
---|
[5bfda2] | 416 | case LONG_OPTION_RETURN: |
---|
[eea2b0] | 417 | if (strcmp(longopts[option_index].name, LON_NO_STDLIB) == 0) |
---|
| 418 | { |
---|
| 419 | load_std_lib = FALSE; |
---|
| 420 | mainSetSingOptionValue(LON_NO_STDLIB, (char*) 1); |
---|
| 421 | } |
---|
[9c35ef] | 422 | else if (strcmp(longopts[option_index].name, LON_BROWSER) == 0) |
---|
| 423 | { |
---|
| 424 | mainSetSingOptionValue(LON_BROWSER, optarg); |
---|
| 425 | } |
---|
[6d9cc6] | 426 | else if (strcmp(longopts[option_index].name, LON_EMACS) == 0) |
---|
| 427 | { |
---|
| 428 | mainSetSingOptionValue(LON_EMACS, (char*) 1); |
---|
| 429 | } |
---|
[eea2b0] | 430 | else if (strcmp(longopts[option_index].name, LON_NO_RC) == 0) |
---|
| 431 | { |
---|
| 432 | load_rc = FALSE; |
---|
| 433 | mainSetSingOptionValue(LON_NO_RC, (char*) 1); |
---|
| 434 | } |
---|
[12310e] | 435 | else if (strcmp(longopts[option_index].name, LON_NO_WARN) == 0) |
---|
| 436 | { |
---|
| 437 | feWarn = FALSE; |
---|
| 438 | mainSetSingOptionValue(LON_NO_WARN, (char*) 1); |
---|
| 439 | } |
---|
| 440 | else if (strcmp(longopts[option_index].name, LON_NO_OUT) == 0) |
---|
| 441 | { |
---|
| 442 | feOut = FALSE; |
---|
| 443 | mainSetSingOptionValue(LON_NO_OUT, (char*) 1); |
---|
| 444 | } |
---|
[eea2b0] | 445 | else if (strcmp(longopts[option_index].name, LON_MIN_TIME) == 0) |
---|
| 446 | { |
---|
| 447 | double mintime = atof(optarg); |
---|
| 448 | if (mintime <= 0) |
---|
| 449 | { |
---|
[e54eb4] | 450 | printf("%s: `%s' invalid float argument for option `--%s'\n", |
---|
[eea2b0] | 451 | argv[0], optarg, LON_MIN_TIME); |
---|
| 452 | mainUsage(argv[0]); |
---|
| 453 | exit(1); |
---|
[ea986d] | 454 | } |
---|
[eea2b0] | 455 | SetMinDisplayTime(mintime); |
---|
| 456 | mainSetSingOptionValue(LON_MIN_TIME, optarg); |
---|
| 457 | } |
---|
| 458 | #ifdef HAVE_MPSR |
---|
| 459 | else if (strcmp(longopts[option_index].name, LON_MP_PORT) == 0) |
---|
| 460 | { |
---|
| 461 | mainSetSingOptionValue(LON_MP_PORT, optarg); |
---|
| 462 | } |
---|
| 463 | else if (strcmp(longopts[option_index].name, LON_MP_HOST) == 0) |
---|
| 464 | { |
---|
| 465 | mainSetSingOptionValue(LON_MP_HOST, optarg); |
---|
| 466 | } |
---|
[e0d91c] | 467 | #endif |
---|
[eea2b0] | 468 | else if (strcmp(longopts[option_index].name, LON_TICKS_PER_SEC) == 0) |
---|
| 469 | { |
---|
| 470 | int ticks = atoi(optarg); |
---|
| 471 | if (ticks <= 0) |
---|
[ea986d] | 472 | { |
---|
[eea2b0] | 473 | printf("%s: `%s' invalid integer argument for option `--%s'\n", |
---|
| 474 | argv[0], optarg, LON_TICKS_PER_SEC); |
---|
| 475 | mainUsage(argv[0]); |
---|
| 476 | exit(1); |
---|
[ea986d] | 477 | } |
---|
[eea2b0] | 478 | SetTimerResolution(ticks); |
---|
| 479 | mainSetSingOptionValue(LON_TICKS_PER_SEC, optarg); |
---|
| 480 | } |
---|
| 481 | else |
---|
| 482 | // undocumented options |
---|
[0e1846] | 483 | #ifdef HAVE_MPSR |
---|
[eea2b0] | 484 | if (strcmp(longopts[option_index].name, LON_MP_MODE) == 0 || |
---|
| 485 | strcmp(longopts[option_index].name, LON_MP_TRANSP) == 0) |
---|
| 486 | { |
---|
| 487 | /* ignore */ |
---|
| 488 | } |
---|
| 489 | else |
---|
[ea986d] | 490 | #endif |
---|
[eea2b0] | 491 | assume(0); |
---|
| 492 | break; |
---|
| 493 | |
---|
| 494 | default: |
---|
| 495 | // Error message already emmited by getopt_long |
---|
| 496 | mainUsage(argv[0]); |
---|
| 497 | exit(1); |
---|
[0e1846] | 498 | } |
---|
| 499 | } |
---|
| 500 | /*. say hello */ |
---|
[77ff8e] | 501 | { |
---|
| 502 | idhdl h; |
---|
[0a3ddd] | 503 | namespaceroot->push(NULL, "Top", 0, TRUE); |
---|
[46d09b] | 504 | #ifdef HAVE_NAMESPACES |
---|
[77ff8e] | 505 | h=enterid(mstrdup("Top"), 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
| 506 | IDPACKAGE(h) = NSPACK(namespaceroot); |
---|
[daeb6d] | 507 | IDPACKAGE(h)->language = LANG_TOP; |
---|
[46d09b] | 508 | #endif /* HAVE_NAMESPACES */ |
---|
[77ff8e] | 509 | } |
---|
[eea2b0] | 510 | if (BVERBOSE(0) && !feBatch) |
---|
[0e1846] | 511 | { |
---|
| 512 | printf( |
---|
[3854a98] | 513 | " SINGULAR /" |
---|
| 514 | #ifndef MAKE_DISTRIBUTION |
---|
[9a11fe] | 515 | " Development" |
---|
[3854a98] | 516 | #endif |
---|
| 517 | "\n" |
---|
[49e4cf] | 518 | " A Computer Algebra System for Polynomial Computations / version %s\n" |
---|
[0cb8c8] | 519 | " 0<\n" |
---|
[451bcd] | 520 | " by: G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n" |
---|
[f306b3] | 521 | #ifdef SDRING |
---|
| 522 | " preliminary experimental version\n" |
---|
| 523 | #endif |
---|
[0cb8c8] | 524 | "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\\n" |
---|
[49eeee] | 525 | , S_VERSION1,S_VERSION2); |
---|
[0e1846] | 526 | } |
---|
| 527 | else |
---|
| 528 | { |
---|
[473707b] | 529 | sdb_flags = 0; |
---|
| 530 | if (!feBatch) |
---|
| 531 | { |
---|
[9c756f] | 532 | #ifdef __MWERKS__ |
---|
[473707b] | 533 | memcpy(stderr,stdout,sizeof(FILE)); |
---|
[0e1846] | 534 | #else |
---|
[473707b] | 535 | dup2(1,2); |
---|
[0e1846] | 536 | #endif |
---|
[473707b] | 537 | } |
---|
[0e1846] | 538 | } |
---|
| 539 | slStandardInit(); |
---|
| 540 | dlInit(thisfile); |
---|
| 541 | myynest=0; |
---|
[9ea9c6] | 542 | if (load_std_lib) |
---|
[055021a] | 543 | { |
---|
[e54eb4] | 544 | int vv=verbose; |
---|
| 545 | verbose &= ~Sy_bit(V_LOAD_LIB); |
---|
[0a3ddd] | 546 | #ifdef HAVE_NAMESPACES |
---|
| 547 | iiLibCmd(mstrdup("standard.lib"),TRUE, TRUE); |
---|
| 548 | #else /* HAVE_NAMESPACES */ |
---|
| 549 | iiLibCmd(mstrdup("standard.lib"), TRUE); |
---|
| 550 | #endif /* HAVE_NAMESPACES */ |
---|
[e54eb4] | 551 | verbose=vv; |
---|
| 552 | } |
---|
[9ea9c6] | 553 | errorreported = 0; |
---|
[6e5833] | 554 | mmMarkInitDBMCB(); |
---|
[dfc6b54] | 555 | #ifndef macintosh |
---|
[e0d91c] | 556 | #if defined(HAVE_READLINE) |
---|
[dfc6b54] | 557 | fe_set_input_mode(); |
---|
| 558 | #endif |
---|
| 559 | #endif |
---|
| 560 | setjmp(si_start_jmpbuf); |
---|
[eea2b0] | 561 | |
---|
| 562 | // Now, put things on the stack of stuff to do |
---|
| 563 | |
---|
| 564 | // Last thing to do is to execute given scripts |
---|
| 565 | if (optind < argc) |
---|
[057e93c] | 566 | { |
---|
[eea2b0] | 567 | int i = argc - 1; |
---|
| 568 | while (i >= optind) |
---|
| 569 | { |
---|
| 570 | newFile(argv[i]); |
---|
| 571 | i--; |
---|
| 572 | } |
---|
[057e93c] | 573 | } |
---|
| 574 | else |
---|
| 575 | { |
---|
| 576 | currentVoice=feInitStdin(); |
---|
| 577 | } |
---|
[eea2b0] | 578 | |
---|
| 579 | // before scripts, we execute -c, if it was given |
---|
| 580 | // now execute -c, if it was given |
---|
| 581 | if (execute_string != NULL) |
---|
| 582 | newBuffer(mstrdup(execute_string), BT_execute); |
---|
| 583 | |
---|
| 584 | // first thing, however, is to load .singularrc |
---|
| 585 | if (load_rc) |
---|
[7def32f] | 586 | { |
---|
[64c6d1] | 587 | FILE * rc=myfopen(".singularrc","r"); |
---|
[7def32f] | 588 | if (rc!=NULL) |
---|
| 589 | { |
---|
| 590 | fclose(rc); |
---|
[64c6d1] | 591 | newFile(".singularrc"); |
---|
| 592 | } |
---|
| 593 | else |
---|
| 594 | { |
---|
| 595 | char buf[MAXPATHLEN]; |
---|
| 596 | char *home = getenv("HOME"); |
---|
| 597 | if (home != NULL) |
---|
| 598 | { |
---|
| 599 | strcpy(buf, home); |
---|
| 600 | strcat(buf, "/.singularrc"); |
---|
| 601 | rc = myfopen(buf, "r"); |
---|
| 602 | if (rc != NULL) |
---|
| 603 | { |
---|
| 604 | fclose(rc); |
---|
| 605 | newFile(buf); |
---|
| 606 | } |
---|
| 607 | } |
---|
[7def32f] | 608 | } |
---|
| 609 | } |
---|
[eea2b0] | 610 | |
---|
[6d9cc6] | 611 | if (mainGetSingOptionValue(LON_EMACS)) |
---|
| 612 | { |
---|
| 613 | Warn("EmacsDir: %s", feResource("EmacsDir")); |
---|
| 614 | Warn("InfoFile: %s", feResource("InfoFile")); |
---|
| 615 | feHelpBrowser("emacs"); |
---|
| 616 | } |
---|
[0e1846] | 617 | /* start shell */ |
---|
| 618 | if (feBatch) |
---|
| 619 | { |
---|
[d754b7] | 620 | #ifdef HAVE_MPSR |
---|
[eea2b0] | 621 | extern int Batch_do(const char* port, const char* host); |
---|
| 622 | return Batch_do(mainGetSingOptionValue(LON_MP_PORT), |
---|
| 623 | mainGetSingOptionValue(LON_MP_HOST)); |
---|
[d754b7] | 624 | #else |
---|
[eea2b0] | 625 | assume(0); |
---|
| 626 | #endif |
---|
[0e1846] | 627 | } |
---|
[07dacd] | 628 | setjmp(si_start_jmpbuf); |
---|
[0e1846] | 629 | yyparse(); |
---|
| 630 | #endif |
---|
[057e93c] | 631 | //Print("at very end\n"); |
---|
| 632 | m2_end(0); |
---|
[0e1846] | 633 | return 0; |
---|
| 634 | } |
---|