Changeset eea2b0 in git
- Timestamp:
- Apr 16, 1998, 6:10:24 PM (25 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 66be51317f9400a7183a651dba28b63c4ebbdf83
- Parents:
- 5821c1b832ca2803db683e6554957c7aac511380
- Location:
- Singular
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/ChangeLog
r5821c1 reea2b0 1 1998-04-16 Olaf Bachmann <obachman@mathematik.uni-kl.de> 2 3 * mpsr_PutPoly.cc: Took out normalization of rational numbers 4 before they are put -- might have side effects 5 6 * extra.cc: added system("--option") which returns value of 7 option; in debug mode: system("OptionValues") lists all option 8 values 9 10 * sing_mp.cc: use long option names for MP link options 11 * MPtcp:launch: Uses find_exec as default application 12 13 * tesths.cc: New (handling of) command line options (long 14 options, usage of getopt_long): Parse more than one argument 15 script, etc .. 16 * added getopt.[c,h]for parsing of command lines 17 18 * mod2.h.in, configure.in: Got rid off str* tests 19 1 20 1998-04-07 Olaf Bachmann <obachman@mathematik.uni-kl.de> 2 21 -
Singular/Makefile.in
r5821c1 reea2b0 99 99 ndbm.cc spSpolyLoop.cc libparse.cc 100 100 101 CSOURCES=mmalloc.c mmallocb.c mmallocs.c mmblock.c mmheap.c mmspec.c mmutil.c weight0.c find_exec.c 101 CSOURCES=mmalloc.c mmallocb.c mmallocs.c mmblock.c mmheap.c mmspec.c mmutil.c weight0.c find_exec.c getopt.c 102 102 103 103 SOURCES=${CSOURCES} ${CXXSOURCES} grammar.y scanner.l libparse.l spSpolyLoop.pl … … 114 114 kstdfac.h mpsr_Get.h spolys.h \ 115 115 kutil.h mpsr_Put.h spolys0.h \ 116 ndbm.h spSpolyLoop.h polys-impl.h polys-comp.h 116 ndbm.h spSpolyLoop.h polys-impl.h polys-comp.h getopt.h 117 117 118 118 TESTS=${testdir}/comparecheck ${testdir}/fac_test.in ${testdir}/fac_test.out\ … … 144 144 mpsr_Error.o mpsr_Put.o mpsr_PutPoly.o mpsr_GetPoly.o \ 145 145 mpsr_Get.o mpsr_GetMisc.o ndbm.o spSpolyLoop.o libparse.o \ 146 find_exec.o 146 find_exec.o getopt.o 147 147 148 148 ## … … 398 398 399 399 OBJG2= mmalloc.og mmallocb.og mmallocs.og mmblock.og mmheap.og \ 400 mmspec.og mmutil.og weight0.og find_exec.og 400 mmspec.og mmutil.og weight0.og find_exec.og getopt.og 401 401 402 402 … … 472 472 473 473 OBJP2= mmalloc.op mmallocb.op mmallocs.op mmblock.op mmheap.op \ 474 mmspec.op mmutil.op weight0.op find_exec.op 474 mmspec.op mmutil.op weight0.op find_exec.op getopt.op 475 475 476 476 OBJP=$(OBJP1) $(OBJP2) claptmpl.op … … 497 497 498 498 OBJB2= mmalloc.ob mmallocb.ob mmallocs.ob mmblock.ob mmheap.ob \ 499 mmspec.ob mmutil.ob weight0.ob find_exec.ob 499 mmspec.ob mmutil.ob weight0.ob find_exec.ob getopt.ob 500 500 501 501 OBJB=$(OBJB1) $(OBJB2) claptmpl.ob -
Singular/extra.cc
r5821c1 reea2b0 2 2 * Computer Algebra System SINGULAR * 3 3 *****************************************/ 4 /* $Id: extra.cc,v 1.3 6 1998-04-16 11:45:39 SingularExp $ */4 /* $Id: extra.cc,v 1.37 1998-04-16 16:10:13 obachman Exp $ */ 5 5 /* 6 6 * ABSTRACT: general interface to internals of Singular ("system" command) … … 251 251 res->data=(void*)feGetExpandedExecutable(); 252 252 if (res->data != NULL) 253 res->data = mstrdup((char*) res->data); 254 else 255 res->data = mstrdup(""); 256 return FALSE; 257 } 253 res->data = (void*) mstrdup((char*) res->data); 254 else 255 res->data = (void*) mstrdup(""); 256 return FALSE; 257 } 258 else 259 /*==================== options ==================================*/ 260 if (strstr((char*)(h->data), "--") == (char*)(h->data)) 261 { 262 BOOLEAN mainGetSingOptionValue(const char* name, char** result); 263 char* val; 264 265 if (mainGetSingOptionValue(&((char*)(h->data))[2], &val)) 266 { 267 res->data = (void*) val; 268 if ((int) val > 1) 269 { 270 res->rtyp=STRING_CMD; 271 res->data = (void*) mstrdup((char*) res->data); 272 } 273 else 274 res->rtyp=INT_CMD; 275 return FALSE; 276 } 277 else 278 { 279 Werror("Unknown option %s\n", (char*)(h->data)); 280 return TRUE; 281 } 282 } 283 else 284 /*==================== print all option values =================*/ 285 #ifndef NDEBUG 286 if (strcmp((char*)(h->data), "OptionValues") == 0) 287 { 288 void mainOptionValues(); 289 mainOptionValues(); 290 return FALSE; 291 } 292 else 293 #endif 258 294 /*==================== HC ==================================*/ 259 295 if (strcmp((char*)(h->data),"HC")==0) -
Singular/find_exec.c
r5821c1 reea2b0 9 9 This file is part of the GNU Dld Library. */ 10 10 11 /* Adapted for use with Singular by obachman 11 /* Adapted for use with Singular by obachman@mathematik.uni-kl.de 4/98*/ 12 12 13 13 #include "mod2.h" … … 31 31 #include "mmemory.h" 32 32 33 #ifndef MAXPATHLEN 34 #define MAXPATHLEN 1024 35 #endif 33 36 34 37 -
Singular/mpsr_Get.cc
r5821c1 reea2b0 3 3 ****************************************/ 4 4 5 /* $Id: mpsr_Get.cc,v 1.1 5 1998-04-07 18:35:25obachman Exp $ */5 /* $Id: mpsr_Get.cc,v 1.16 1998-04-16 16:10:21 obachman Exp $ */ 6 6 /*************************************************************** 7 7 * … … 857 857 #ifdef MPSR_DEBUG 858 858 command cmd = (command) mlv.lv->data; 859 Print("Dump got %s \n", cmd->arg1.name); 859 fprintf(stdout, "Dump got %s \n", cmd->arg1.name); 860 fflush(stdout); 860 861 #endif 861 862 mpsr_SetCurrRingHdl(mlv.r); -
Singular/mpsr_PutPoly.cc
r5821c1 reea2b0 3 3 ****************************************/ 4 4 5 /* $Id: mpsr_PutPoly.cc,v 1.1 0 1998-03-27 11:40:59obachman Exp $ */5 /* $Id: mpsr_PutPoly.cc,v 1.11 1998-04-16 16:10:22 obachman Exp $ */ 6 6 7 7 /*************************************************************** … … 161 161 // Now we have a fraction 162 162 // normalize, if necessary 163 if ((a->s) == 0)164 {165 nlNormalize(a);166 return PutRationalNumber(link, a);167 }163 // if ((a->s) == 0) 164 // { 165 // // nlNormalize(a); 166 // return PutRationalNumber(link, a); 167 // } 168 168 169 169 // send number itself -
Singular/sing_mp.cc
r5821c1 reea2b0 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: sing_mp.cc,v 1.1 4 1997-06-11 08:00:15obachman Exp $ */4 /* $Id: sing_mp.cc,v 1.15 1998-04-16 16:10:23 obachman Exp $ */ 5 5 6 6 /* … … 25 25 static int Batch_ReadEval(si_link silink); 26 26 27 #ifndef MAXPATHLEN 28 #define MAXPATHLEN 1024 29 #endif 30 31 #define MPSR_DEBUG 32 27 33 #ifdef MPSR_DEBUG 28 34 #define MP_SET_LINK_OPTIONS(link) \ … … 57 63 char *s2=mstrdup(str); 58 64 59 char *appl = strstr(s2, "- MPapplication");65 char *appl = strstr(s2, "--MPapplication"); 60 66 if (appl != NULL) 61 67 { … … 91 97 if (appl != NULL) 92 98 { 93 (*argv)[*argc -2] = mstrdup("- MPapplication");99 (*argv)[*argc -2] = mstrdup("--MPapplication"); 94 100 (*argv)[*argc -1] = mstrdup(&(appl[15])); 95 101 } … … 107 113 static BOOLEAN slOpenMPFile(si_link l, short flag) 108 114 { 109 char *argv[] = {"- MPtransp", "FILE", "-MPmode", "append",110 "- MPfile", "/tmp/mpout"};115 char *argv[] = {"--MPtransp", "FILE", "--MPmode", "append", 116 "--MPfile", "/tmp/mpout"}; 111 117 char *mode; 112 118 … … 164 170 * 165 171 ***************************************************************/ 172 extern BOOLEAN mainGetSingOptionValue(const char* name, char** val); 173 166 174 167 175 static MP_Link_pt slOpenMPConnect(int n_argc, char **n_argv) 168 176 { 169 char *argv[] = {"-MPtransp", "TCP", "-MPmode", "connect", "-MPport", 170 "1025", "-MPhost", "localhost"}; 171 char *port = IMP_GetCmdlineArg(n_argc, n_argv, "-MPport"); 172 char *host = IMP_GetCmdlineArg(n_argc, n_argv, "-MPhost"); 173 177 char *argv[] = {"--MPtransp", "TCP", "--MPmode", "connect", "--MPport", 178 "1025", "--MPhost", "localhost"}; 179 180 char *port = IMP_GetCmdlineArg(n_argc, n_argv, "--MPport"); 181 char *host = IMP_GetCmdlineArg(n_argc, n_argv, "--MPhost"); 182 183 if (port == NULL) mainGetSingOptionValue("--MPport", &port); 184 if (host == NULL) mainGetSingOptionValue("--MPhost", &host); 185 186 if (port != NULL) 187 argv[5] = port; 188 if (host != NULL) 189 argv[7] = host; 190 else 191 argv[7] = mp_Env->thishost; 192 193 return MP_OpenLink(mp_Env, 8, argv); 194 } 195 196 static MP_Link_pt slOpenMPListen(int n_argc, char **n_argv) 197 { 198 char *argv[] = {"--MPtransp", "TCP", "--MPmode", "listen", 199 "--MPport", "1025"}; 200 char *port = IMP_GetCmdlineArg(n_argc, n_argv, "--MPport"); 201 202 if (port == NULL) mainGetSingOptionValue("--MPport", &port); 174 203 175 204 if (port != NULL) argv[5] = port; 176 205 206 return MP_OpenLink(mp_Env, 6, argv); 207 } 208 209 static MP_Link_pt slOpenMPLaunch(int n_argc, char **n_argv) 210 { 211 char *argv[] = {"--MPtransp", "TCP", "--MPmode", "launch", 212 "--MPhost", "localhost", 213 "--MPapplication", "Singular -bq --no-stdlib --no-rc"}; 214 char *appl = IMP_GetCmdlineArg(n_argc, n_argv, "--MPapplication"); 215 char *host = IMP_GetCmdlineArg(n_argc, n_argv, "--MPhost"); 216 char* nappl = NULL; 217 MP_Link_pt link; 218 219 220 if (appl == NULL && (host == NULL || 221 strcmp(host, "localhost") == 0)) 222 { 223 appl = feGetExpandedExecutable(); 224 225 if (appl != NULL) 226 { 227 nappl = (char*) Alloc(MAXPATHLEN + 24); 228 strcpy(nappl, appl); 229 strcat(nappl, " -bq --no-stdlib --no-rc"); 230 appl = nappl; 231 } 232 } 233 234 if (appl != NULL) 235 argv[7] = appl; 236 177 237 if (host == NULL) 178 238 { 179 argv[7] = mp_Env->thishost;180 }181 else182 argv[7] = host;183 184 return MP_OpenLink(mp_Env, 8, argv);185 }186 187 static MP_Link_pt slOpenMPListen(int n_argc, char **n_argv)188 {189 char *argv[] = {"-MPtransp", "TCP", "-MPmode", "listen", "-MPport", "1025"};190 char *port = IMP_GetCmdlineArg(n_argc, n_argv, "-MPport");191 192 if (port != NULL) argv[5] = port;193 194 return MP_OpenLink(mp_Env, 6, argv);195 }196 197 static MP_Link_pt slOpenMPLaunch(int n_argc, char **n_argv)198 {199 char *argv[] = {"-MPtransp", "TCP", "-MPmode", "launch",200 "-MPhost", "localhost", "-MPapplication", "Singular -b"};201 char *appl = IMP_GetCmdlineArg(n_argc, n_argv, "-MPapplication");202 char *host = IMP_GetCmdlineArg(n_argc, n_argv, "-MPhost");203 204 205 if (appl != NULL) argv[7] = appl;206 207 if (host == NULL)208 {209 239 argv[5] = mp_Env->thishost; 210 240 } … … 212 242 argv[5] = host; 213 243 214 return MP_OpenLink(mp_Env, 8, argv); 244 link = MP_OpenLink(mp_Env, 8, argv); 245 if (nappl != NULL) Free(nappl, MAXPATHLEN + 24); 246 return link; 215 247 } 216 248 … … 218 250 { 219 251 MP_Link_pt link = NULL; 220 char *argv[] = {"- MPtransp", "TCP", "-MPmode", "fork", "-MPport", "1703"};221 char *port = IMP_GetCmdlineArg(n_argc, n_argv, "- MPport");252 char *argv[] = {"--MPtransp", "TCP", "--MPmode", "fork", "--MPport", "1703"}; 253 char *port = IMP_GetCmdlineArg(n_argc, n_argv, "--MPport"); 222 254 223 255 if (port != NULL) argv[5] = port; … … 460 492 #endif 461 493 462 int Batch_do(int argc, char **argv) 494 495 int Batch_do(const char* port, const char* host) 463 496 { 464 497 #ifdef MPSR_BATCH_DEBUG … … 467 500 #endif 468 501 si_link silink = (si_link) Alloc0(sizeof(sip_link)); 469 char *port = IMP_GetCmdlineArg(argc, argv, "-MPport");470 char *host = IMP_GetCmdlineArg(argc, argv, "-MPhost");471 502 char *istr; 472 503 … … 475 506 { 476 507 fprintf(stderr, 477 "Need '- MPport portnumber' command line argument in batch modus\n");508 "Need '--MPport portnumber' command line argument in batch modus\n"); 478 509 return 1; 479 510 } … … 481 512 { 482 513 fprintf(stderr, 483 "Need '- MPhost hostname' command line argument in batch modus\n");514 "Need '--MPhost hostname' command line argument in batch modus\n"); 484 515 return 1; 485 516 } … … 487 518 // initialize si_link 488 519 istr = (char *) AllocL((strlen(port) + strlen(host) + 40)*sizeof(char)); 489 sprintf(istr, "MPtcp:connect - MPport %s-MPhost %s", port, host);520 sprintf(istr, "MPtcp:connect --MPport %s --MPhost %s", port, host); 490 521 slInit(silink, istr); 491 522 FreeL(istr); … … 500 531 return Batch_ReadEval(silink); 501 532 } 502 503 533 504 534 /*************************************************************** -
Singular/tesths.cc
r5821c1 reea2b0 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: tesths.cc,v 1.3 2 1998-04-06 17:59:37obachman Exp $ */4 /* $Id: tesths.cc,v 1.33 1998-04-16 16:10:24 obachman Exp $ */ 5 5 6 6 /* … … 33 33 #endif 34 34 35 #include <getopt.h> 36 37 // define the long option names here 38 #define LON_BATCH "batch" 39 #define LON_EXECUTE "execute" 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" 46 #define LON_VERSION "version" 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" 54 // undocumented options 55 #ifdef HAVE_MPSR 56 #define LON_MP_TRANSP "MPtransp" 57 #define LON_MP_MODE "MPmode" 58 #endif 59 60 static struct option longopts[] = 61 { 62 #ifdef HAVE_MPSR 63 {LON_BATCH, 0, 0, 'b'}, 64 #endif 65 {LON_HELP, 0, 0, 'h'}, 66 {LON_QUIET, 0, 0, 'q'}, 67 {LON_NO_TTY, 0, 0, 't'}, 68 {LON_VERSION, 0, 0, 'v'}, 69 #ifdef HAVE_TCL 70 {LON_TCLMODE, 0, 0, 'x'}, 71 #endif 72 {LON_ECHO, 2, 0, 'e'}, 73 {LON_EXECUTE, 1, 0, 'c'}, 74 {LON_RANDOM, 1, 0, 'r'}, 75 {LON_USER_OPTION, 1, 0, 'u'}, 76 {LON_NO_STDLIB, 0, 0, 0}, 77 {LON_NO_RC, 0, 0, 0}, 78 {LON_MIN_TIME, 1, 0, 0}, 79 #ifdef HAVE_MPSR 80 {LON_MP_PORT, 1, 0, 0}, 81 {LON_MP_HOST, 1, 0, 0}, 82 #endif 83 {LON_TICKS_PER_SEC, 1, 0, 0}, 84 // undocumented options 85 #ifdef HAVE_MPSR 86 {LON_MP_TRANSP, 1, 0, 0}, 87 {LON_MP_MODE, 1, 0, 0}, 88 #endif 89 // terminator 90 { 0, 0, 0, 0 } 91 }; 92 // #define SHORT_OPTS_STRING "bc:e::hqr:tu:v" 93 #define SHORT_OPTS_STRING "bhqtvxe::c:r:u:" 94 95 struct sing_option 96 { 97 const char* name; // as in option 98 const char* arg_name;// name of argument, if has_arg > 0 99 const char* help; // (short) help string 100 char* val; // (default) value of option: 0: not set 1:set 101 // string:"" if has_arg > 0 102 }; 103 104 // mention only documented options here 105 static struct sing_option sing_longopts[] = 106 { 107 #ifdef HAVE_MPSR 108 {LON_BATCH, 0, "Run in MP batch mode", 0}, 109 #endif 110 {LON_HELP, 0, "Print help message and exit", 0}, 111 {LON_QUIET, 0, "Do not print start-up banner and warnings", 0}, 112 {LON_NO_TTY, 0, "Do not redefine the terminal characteristics", 0}, 113 {LON_VERSION, 0, "Print extended version and configuration info", 0}, 114 #ifdef HAVE_TCL 115 {LON_TCLMODE 0, "Run in TCL mode, i.e., with TCL user interface", 0}, 116 #endif 117 {LON_ECHO, "VAL", "Set value of variable `echo' to (integer) VAL", ""}, 118 {LON_EXECUTE, "STRING", "Execute STRING on start-up", ""}, 119 {LON_RANDOM, "SEED", "Seed random generator with integer (integer) SEED", ""}, 120 {LON_USER_OPTION, "STRING", "Return STRING on `system(\"--user-option\")'", ""}, 121 {LON_NO_STDLIB, 0, "Do not load `standard.lib' on start-up", 0}, 122 {LON_NO_RC, 0, "Do not execute `.singularrc' file on start-up", 0}, 123 {LON_MIN_TIME, "SECS", "Do not display times smaller than SECS (in seconds)", "0.5"}, 124 #ifdef HAVE_MPSR 125 {LON_MP_PORT, "PORT", "Use PORT number for MP conections", ""}, 126 {LON_MP_HOST, "HOST", "Use HOST for MP connections", ""}, 127 #endif 128 {LON_TICKS_PER_SEC, "TICKS", "Sets unit of timer to TICKS per second", "1"}, 129 { 0, 0, 0, 0 } 130 }; 131 132 static struct sing_option* mainGetSingOption(const char* name) 133 { 134 int i = 0; 135 while (sing_longopts[i].name != 0) 136 { 137 if (strcmp(name, sing_longopts[i].name) == 0) 138 return &(sing_longopts[i]); 139 i++; 140 } 141 return NULL; 142 } 143 144 static void mainSetSingOptionValue(const char* name, char* value) 145 { 146 sing_option* sopt = mainGetSingOption(name); 147 if (sopt != NULL) 148 { 149 sopt->val = value; 150 } 151 } 152 153 154 static char* mainGetSingOptionValue(const char* name) 155 { 156 sing_option* sopt = mainGetSingOption(name); 157 if (sopt!=NULL) 158 return sopt->val; 159 return NULL; 160 } 161 162 163 // Prints help message 164 static void mainHelp(const char* name) 165 { 166 int i = 0; 167 struct sing_option *sopt; 168 char tmp[20]; 169 170 printf("Singular %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1); 171 printf(" %s [options] [file1 [file2 ...]]\n", name); 172 printf("Options:\n"); 173 174 while (longopts[i].name != 0) 175 { 176 sopt = mainGetSingOption(longopts[i].name); 177 if (sopt != NULL) 178 { 179 if (longopts[i].has_arg > 0) 180 { 181 if (longopts[i].has_arg > 1) 182 sprintf(tmp, "%s[=%s]", longopts[i].name, sopt->arg_name); 183 else 184 sprintf(tmp, "%s=%s", longopts[i].name, sopt->arg_name); 185 186 printf(" %c%c --%-19s %s\n", 187 (longopts[i].val != 0 ? '-' : ' '), 188 (longopts[i].val != 0 ? longopts[i].val : ' '), 189 tmp, 190 sopt->help); 191 } 192 else 193 { 194 printf(" %c%c --%-19s %s\n", 195 (longopts[i].val != 0 ? '-' : ' '), 196 (longopts[i].val != 0 ? longopts[i].val : ' '), 197 longopts[i].name, 198 sopt->help); 199 } 200 } 201 #ifndef NDEBUG 202 else 203 printf("--%s Undocumented\n", longopts[i].name); 204 #endif 205 i++; 206 } 207 208 printf("\nFor more information, type `help;' from within Singular or visit\n"); 209 printf("http://www.mathematik.uni-kl.de/~zca/Singular or consult the\n"); 210 printf("Singular manual (available as on-line info or printed manual).\n"); 211 } 212 213 // Prints usage message 214 static void mainUsage(char* argv0) 215 { 216 printf("Use `%s --help' for a complete list of options\n", argv0); 217 } 218 219 #ifndef NDEBUG 220 void mainOptionValues() 221 { 222 int i = 0; 223 struct sing_option *sopt; 224 225 while (longopts[i].name != 0) 226 { 227 sopt = mainGetSingOption(longopts[i].name); 228 if (sopt != NULL) 229 { 230 if (sopt->val == NULL || sopt->val == (char*) 1) 231 Print("// --%-10s %d\n", sopt->name, sopt->val); 232 else 233 Print("// --%-10s %s\n", sopt->name, sopt->val); 234 } 235 else 236 Print("// --%s Undocumented \n", longopts[i].name); 237 i++; 238 } 239 } 240 #endif // NDEBUG 241 242 BOOLEAN mainGetSingOptionValue(const char* name, char** val) 243 { 244 sing_option* sopt = mainGetSingOption(name); 245 if (sopt == NULL) 246 { 247 *val = NULL; 248 return FALSE; 249 } 250 else 251 { 252 *val = sopt->val; 253 return TRUE; 254 } 255 } 35 256 36 257 /*0 implementation*/ … … 58 279 thisfile = argv[0]; 59 280 BOOLEAN load_std_lib=TRUE; 281 BOOLEAN load_rc = TRUE; 282 char* execute_string = NULL; 283 int optc, option_index; 284 285 // do this first, because -v might print version path 60 286 feGetSearchPath(thisfile); 61 62 /*. process parameters */ 63 for (;(argc > 1) && (!feBatch); --argc, ++argv) 64 { 65 if (strcmp(argv[1], "-m") == 0) 287 288 // parse command line options 289 while((optc = getopt_long(argc, argv, 290 SHORT_OPTS_STRING, longopts, &option_index)) 291 != EOF) 292 { 293 switch(optc) 66 294 { 67 { 68 if (argc > 2) 69 { 70 char* ptr = NULL; 71 #ifdef HAVE_STRTOD 72 double mintime = strtod(argv[2], &ptr); 73 if (errno != ERANGE && ptr != argv[2]) 295 296 case 'b': 297 #ifdef HAVE_MPSR 298 feBatch=TRUE; 299 mainSetSingOptionValue(LON_BATCH, (char*) 1); 300 break; 74 301 #else 75 double mintime = 0; 76 sscanf(argv[2],"%f", &mintime); 77 if (mintime != 0.0) 78 #endif 79 { 80 argc--; 81 argv++; 302 printf("%s: Option `-b' not supported in this configuration\n", argv[0]); 303 mainUsage(argv[0]); 304 exit(1); 305 #endif 306 307 case 'h': 308 mainHelp(argv[0]); 309 exit(0); 310 311 case 'q': 312 verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB)); 313 mainSetSingOptionValue(LON_QUIET, (char*) 1); 314 break; 315 316 case 't': 317 #if defined(HAVE_FEREAD) || defined(HAVE_READLINE) 318 fe_use_fgets=TRUE; 319 #endif 320 mainSetSingOptionValue(LON_NO_TTY, (char*) 1); 321 break; 322 323 case 'v': 324 printf("Singular %s %s (%d) %s %s\n", 325 S_VERSION1,S_VERSION2, 326 SINGULAR_VERSION_ID,__DATE__,__TIME__); 327 printf("with\n"); 328 printf(versionString()); 329 printf("\n\n"); 330 mainSetSingOptionValue(LON_VERSION, (char*) 1); 331 break; 332 333 case 'x': 334 #ifdef HAVE_TCL 335 tclmode = TRUE; 336 mainSetSingOptionValue(LON_TCL-MODE, (char*) 1); 337 break; 338 #else 339 printf("%s: Option `-x' not supported in this configuration\n", argv[0]); 340 mainUsage(argv[0]); 341 exit(1); 342 #endif 343 344 case 'e': 345 if (optarg != NULL) 346 { 347 errno = 0; 348 si_echo = strtol(optarg, NULL, 10); 349 if (errno) 350 { 351 printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_ECHO); 352 mainUsage(argv[0]); 353 exit(1); 354 } 355 if (si_echo < 0 || si_echo > 9) 356 { 357 printf("%s: `%s' argument for option `--%s' is not in valid range 0..9\n", 358 argv[0], optarg, LON_ECHO); 359 mainUsage(argv[0]); 360 exit(1); 361 } 362 mainSetSingOptionValue(LON_ECHO, optarg); 363 } 364 else 365 { 366 si_echo = 1; 367 mainSetSingOptionValue(LON_ECHO, "1"); 368 } 369 break; 370 371 case 'c': 372 execute_string = optarg; 373 mainSetSingOptionValue(LON_EXECUTE, optarg); 374 break; 375 376 case 'r': 377 errno = 0; 378 siRandomStart = strtol(optarg, NULL, 10); 379 if (errno) 380 { 381 printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_RANDOM); 382 mainUsage(argv[0]); 383 exit(1); 384 } 385 #ifdef buildin_rand 386 siSeed=siRandomStart; 387 #else 388 srand((unsigned int)siRandomStart); 389 #endif 390 #ifdef HAVE_FACTORY 391 factoryseed(siRandomStart); 392 #endif 393 mainSetSingOptionValue(LON_RANDOM, optarg); 394 break; 395 396 case 'u': 397 mainSetSingOptionValue(LON_USER_OPTION, optarg); 398 break; 399 400 case 0: 401 if (strcmp(longopts[option_index].name, LON_NO_STDLIB) == 0) 402 { 403 load_std_lib = FALSE; 404 mainSetSingOptionValue(LON_NO_STDLIB, (char*) 1); 405 } 406 else if (strcmp(longopts[option_index].name, LON_NO_RC) == 0) 407 { 408 load_rc = FALSE; 409 mainSetSingOptionValue(LON_NO_RC, (char*) 1); 410 } 411 else if (strcmp(longopts[option_index].name, LON_MIN_TIME) == 0) 412 { 413 double mintime = atof(optarg); 414 if (mintime <= 0) 415 { 416 printf("%s: `%s' invalid float argument for option `--%s'\n", 417 argv[0], optarg, LON_MIN_TIME); 418 mainUsage(argv[0]); 419 exit(1); 420 } 82 421 SetMinDisplayTime(mintime); 422 mainSetSingOptionValue(LON_MIN_TIME, optarg); 423 } 424 #ifdef HAVE_MPSR 425 else if (strcmp(longopts[option_index].name, LON_MP_PORT) == 0) 426 { 427 mainSetSingOptionValue(LON_MP_PORT, optarg); 428 } 429 else if (strcmp(longopts[option_index].name, LON_MP_HOST) == 0) 430 { 431 mainSetSingOptionValue(LON_MP_HOST, optarg); 432 } 433 #endif 434 else if (strcmp(longopts[option_index].name, LON_TICKS_PER_SEC) == 0) 435 { 436 int ticks = atoi(optarg); 437 if (ticks <= 0) 438 { 439 printf("%s: `%s' invalid integer argument for option `--%s'\n", 440 argv[0], optarg, LON_TICKS_PER_SEC); 441 mainUsage(argv[0]); 442 exit(1); 443 } 444 SetTimerResolution(ticks); 445 mainSetSingOptionValue(LON_TICKS_PER_SEC, optarg); 83 446 } 84 447 else 85 fprintf(stderr, "Can not convert %s to a float\n", argv[2]); 86 } 87 else 88 { 89 fprintf(stderr, "Need a float to set mintime"); 90 } 91 } 448 // undocumented options 449 #ifdef HAVE_MPSR 450 if (strcmp(longopts[option_index].name, LON_MP_MODE) == 0 || 451 strcmp(longopts[option_index].name, LON_MP_TRANSP) == 0) 452 { 453 /* ignore */ 454 } 455 else 456 #endif 457 assume(0); 458 break; 459 460 default: 461 // Error message already emmited by getopt_long 462 mainUsage(argv[0]); 463 exit(1); 92 464 } 93 else if (strcmp(argv[1], "-d") == 0) 94 { 95 96 if (argc > 2) 97 { 98 char* ptr = NULL; 99 // OLAF: try to avoid using long: 100 #ifdef HAVE_STRTOL 101 long res = strtol(argv[2], &ptr, 10); 102 if (errno != ERANGE && ptr != argv[2] && res > 0) 103 #else 104 long res = 0; 105 sscanf(argv[2],"%d", &res); 106 if (res > 0) 107 #endif 108 { 109 argc--; 110 argv++; 111 i=0; 112 SetTimerResolution(res); 113 } 114 else 115 fprintf(stderr,"Can not convert %s to an integer > 0\n", argv[2]); 116 } 117 else 118 { 119 long res=0; 120 while ((argv[1][i+1]>='0') && (argv[1][i+1]<='9')) 121 { 122 i++; 123 res = res*10+(int)(argv[1][i] - '0'); 124 SetTimerResolution(res); 125 } 126 } 127 } 128 else 129 { 130 131 if ((argv[1][0] != '-') ||(argv[1][1] == '-')) 132 break; 133 for (i=1;argv[1][i]!='\0';i++) 134 { 135 switch (argv[1][i]) 136 { 137 case 'V': 138 case 'v':{ 139 printf("Singular %s %s (%d) %s %s\n", 140 S_VERSION1,S_VERSION2, 141 SINGULAR_VERSION_ID,__DATE__,__TIME__); 142 printf("with\n"); 143 printf(versionString()); 144 printf("\n\n"); 145 break; 146 } 147 case 'e': if ((argv[1][i+1]>'0') && (argv[1][i+1]<='9')) 148 { 149 i++; 150 si_echo = (int)(argv[1][i] - '0'); 151 } 152 else si_echo = 1; 153 break; 154 case 'r': siRandomStart = 0; 155 while((argv[1][i+1]>='0') && (argv[1][i+1]<='9')) 156 { 157 i++; 158 siRandomStart = siRandomStart*10+(int)(argv[1][i] - '0'); 159 } 160 #ifdef buildin_rand 161 siSeed=siRandomStart; 162 #else 163 srand((unsigned int)siRandomStart); 164 #endif 165 #ifdef HAVE_FACTORY 166 factoryseed(siRandomStart); 167 #endif 168 break; 169 #ifdef HAVE_TCL 170 case 'x': tclmode=TRUE; 171 break; 172 #endif 173 #ifdef HAVE_MPSR 174 case 'b': feBatch=TRUE; 175 #endif 176 case 'q': verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB)); 177 break; 178 case 't': 179 #if defined(HAVE_FEREAD) || defined(HAVE_READLINE) 180 fe_use_fgets=TRUE; 181 #endif 182 break; 183 case 'n': 184 load_std_lib=FALSE; 185 break; 186 default : printf("Unknown option -%c\n",argv[1][i]); 187 printf("Usage: %s [-bemqtvx] [file]\n",thisfile); 188 exit(1); 189 } 190 } 191 } 192 } 193 194 465 } 195 466 /*. say hello */ 196 if (BVERBOSE(0) )467 if (BVERBOSE(0) && !feBatch) 197 468 { 198 469 printf( … … 207 478 printf("%s %s (%d)",S_VERSION1,S_VERSION2, SINGULAR_VERSION_ID); 208 479 printf("\n\nPlease note: EVERY COMMAND MUST END WITH A SEMICOLON \";" 209 "\"\n(e.g. help; help command; help General syntax; help ring; quit;)\n\n");480 "\"\n(e.g., help; help command; help General syntax; help ring; quit;)\n\n"); 210 481 } 211 482 else … … 232 503 #endif 233 504 setjmp(si_start_jmpbuf); 234 /* if script is given */ 235 if ((argc > 1)&&(argv[1][0]!='-')) 236 { 237 /* read and run the Script */ 238 argc=1; 239 newFile(argv[1]); 505 506 // Now, put things on the stack of stuff to do 507 508 // Last thing to do is to execute given scripts 509 if (optind < argc) 510 { 511 int i = argc - 1; 512 while (i >= optind) 513 { 514 newFile(argv[i]); 515 i--; 516 } 240 517 } 241 518 else … … 243 520 currentVoice=feInitStdin(); 244 521 } 245 // set up voice for .singularc 246 { 522 523 // before scripts, we execute -c, if it was given 524 // now execute -c, if it was given 525 if (execute_string != NULL) 526 newBuffer(mstrdup(execute_string), BT_execute); 527 528 // first thing, however, is to load .singularrc 529 if (load_rc) 530 { 531 // Hmm, we should look into $cwd and then into $HOME, only 247 532 char * where=(char *)AllocL(256); 248 533 FILE * rc=feFopen(".singularrc","r",where,FALSE); … … 254 539 FreeL((ADDRESS)where); 255 540 } 541 256 542 /* start shell */ 257 543 if (feBatch) 258 544 { 259 545 #ifdef HAVE_MPSR 260 extern int Batch_do(int argc, char **argv); 261 return Batch_do(argc,argv); 546 extern int Batch_do(const char* port, const char* host); 547 return Batch_do(mainGetSingOptionValue(LON_MP_PORT), 548 mainGetSingOptionValue(LON_MP_HOST)); 262 549 #else 263 fprintf(stderr, "Option -b not supported in this version"); 264 return 1; 265 #endif // HAVE_MPSR 550 assume(0); 551 #endif 266 552 } 267 553 setjmp(si_start_jmpbuf);
Note: See TracChangeset
for help on using the changeset viewer.