Changeset 3b295e in git
- Timestamp:
- Sep 22, 1999, 5:42:13 PM (24 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- 824241e0feb57039b89a14bd31a86a23e5a87032
- Parents:
- 2bb771a6d877e2842019e777594b5edfacafda1b
- Location:
- Singular
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/feOpt.cc
r2bb771 r3b295e 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: feOpt.cc,v 1. 4 1999-09-21 16:40:14 obachmanExp $ */4 /* $Id: feOpt.cc,v 1.5 1999-09-22 15:42:12 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: Implementation of option buisness … … 14 14 { 15 15 // 16 // Has to be of the form 17 // {name, has_arg, flag,val,18 // arg_name, help, type, value, set} 16 // Has to be of the form 17 // {name, has_arg, val, 18 // arg_name, help, type, value, set} 19 19 // where: 20 20 // 21 21 // name is the name of the long option. 22 // 22 // 23 23 // has_arg 24 24 // is: no_argument (or 0) if the option does not take … … 26 26 // requires an argument, or optional_argument (or 2) 27 27 // if the option takes an optional argument. 28 // 29 // flag specifies how results are returned for a long 30 // option. If flag is NULL, then getopt_long() 31 // returns val. (For example, the calling program may 32 // set val to the equivalent short option character.) 33 // Otherwise, getopt_long() returns 0, and flag points 34 // to a variable which is set to val if the option is 35 // found, but left unchanged if the option is not 36 // found. 37 // SHOULD ALWAYS BE ZERO FOR SINGULAR 38 // 28 // 39 29 // val is the value to return, or to load into the 40 30 // variable pointed to by flag. … … 42 32 // short option char, for short option 43 33 // 44 // arg_name if set, uses this value as name for argument in 34 // arg_name if set, uses this value as name for argument in 45 35 // display of help 46 // 36 // 47 37 // help one-line description of option 48 38 // 49 // type one of feOptUntyped (value is never set), 39 // type one of feOptUntyped (value is never set), 50 40 // feOptBool, feOptInt, feOptString 51 // 41 // 52 42 // value (default) value of option 53 // 54 // set only relevant for feOptString: 43 // 44 // set only relevant for feOptString: 55 45 // 1: if value different from default value 56 // 0: otherwise 57 // 58 // The order in which options are specified is the order in which 46 // 0: otherwise 47 // 48 // The order in which options are specified is the order in which 59 49 // their help is printed on -h 60 50 // 61 51 // Options whose hel starts with an "//" are considered undocumented, 62 52 // i.e., their help is not printed on -h 63 // 53 // 64 54 #ifdef ESINGULAR 65 55 // options only relevant for ESINGULAR 66 {"emacs", required_argument, 0,LONG_OPTION_RETURN,56 {"emacs", required_argument, LONG_OPTION_RETURN, 67 57 "EMACS", "Use EMACS as emacs program to run Singular", feOptString, 0, 0}, 68 58 69 {"emacs-dir", required_argument, 0,LONG_OPTION_RETURN,59 {"emacs-dir", required_argument, LONG_OPTION_RETURN, 70 60 "DIR", "Use DIR as directory to look for emacs lisp files", feOptString, 0, 0}, 71 61 72 {"emacs-load", required_argument, 0,LONG_OPTION_RETURN,62 {"emacs-load", required_argument, LONG_OPTION_RETURN, 73 63 "FILE", "Load FILE on emacs start-up, instead of default", feOptString, 0, 0}, 74 75 {"singular", required_argument, 0,LONG_OPTION_RETURN,64 65 {"singular", required_argument, LONG_OPTION_RETURN, 76 66 "PROG", "Start PROG as Singular program within emacs", feOptString, 0, 0}, 77 67 78 {"no-emacs-call", no_argument, 0,LONG_OPTION_RETURN,68 {"no-emacs-call", no_argument, LONG_OPTION_RETURN, 79 69 0, "Do not start emacs. Print emacs-call to stdout", feOptBool, 0, 0}, 80 70 #endif 81 71 82 72 #ifdef HAVE_MPSR 83 {"batch", no_argument, 0,'b',73 {"batch", no_argument, 'b', 84 74 0, "Run in MP batch mode", feOptBool, 0, 0}, 85 75 #endif 86 76 87 {"execute", required_argument, 0,'c',77 {"execute", required_argument, 'c', 88 78 "STRING", "Execute STRING on start-up", feOptString, 0, 0}, 89 90 {"sdb", no_argument, 0,'d',79 80 {"sdb", no_argument, 'd', 91 81 0, "Enable source code debugger (experimental)", feOptBool, 0, 0}, 92 82 93 {"echo", optional_argument, 0,'e',83 {"echo", optional_argument, 'e', 94 84 "VAL", "Set value of variable `echo' to (integer) VAL", feOptInt, 0, 0}, 95 96 {"help", no_argument, 0,'h',85 86 {"help", no_argument, 'h', 97 87 0, "Print help message and exit", feOptUntyped, 0, 0}, 98 88 99 {"quiet", no_argument, 0,'q',89 {"quiet", no_argument, 'q', 100 90 0, "Do not print start-up banner and lib load messages", feOptBool, 0, 0}, 101 91 102 {"random", required_argument, 0,'r',92 {"random", required_argument, 'r', 103 93 "SEED", "Seed random generator with integer (integer) SEED", feOptInt, 0, 0}, 104 94 105 {"no-tty", no_argument, 0,'t',95 {"no-tty", no_argument, 't', 106 96 0, "Do not redefine the terminal characteristics", feOptBool, 0, 0}, 107 97 108 {"user-option", required_argument, 0,'u',98 {"user-option", required_argument, 'u', 109 99 "STRING", "Return STRING on `system(\"--user-option\")'", feOptString, 0, 0}, 110 100 111 {"version", no_argument, 0,'v',101 {"version", no_argument, 'v', 112 102 0, "Print extended version and configuration info", feOptUntyped, 0, 0}, 113 103 114 104 #ifdef HAVE_TCL 115 {"tclmode", no_argument, 0,'x',105 {"tclmode", no_argument, 'x', 116 106 0, "Run in TCL mode, i.e., with TCL user interface", feOptBool, 0, 0}, 117 107 #endif 118 108 119 {"allow-net", no_argument, 0,LONG_OPTION_RETURN,109 {"allow-net", no_argument, LONG_OPTION_RETURN, 120 110 0, "Allow to fetch (html) help pages from the net", feOptBool, 0, 0}, 121 111 122 {"browser", required_argument, 0,LONG_OPTION_RETURN,112 {"browser", required_argument, LONG_OPTION_RETURN, 123 113 "BROWSER", "Display help in BROWSER ([x,tk]info, netscape)", feOptString, 0, 0}, 124 114 125 115 #ifndef ESINGULAR 126 {"emacs", no_argument, 0,LONG_OPTION_RETURN,116 {"emacs", no_argument, LONG_OPTION_RETURN, 127 117 0, "Set defaults for running within emacs", feOptBool, 0, 0}, 128 118 #endif 129 119 130 {"no-stdlib", no_argument, 0,LONG_OPTION_RETURN,120 {"no-stdlib", no_argument, LONG_OPTION_RETURN, 131 121 0, "Do not load `standard.lib' on start-up", feOptBool, 0, 0}, 132 133 {"no-rc", no_argument, 0,LONG_OPTION_RETURN,122 123 {"no-rc", no_argument, LONG_OPTION_RETURN, 134 124 0, "Do not execute `.singularrc' file(s) on start-up", feOptBool, 0, 0}, 135 125 136 {"no-warn", no_argument, 0,LONG_OPTION_RETURN,126 {"no-warn", no_argument, LONG_OPTION_RETURN, 137 127 0, "Do not display warning messages", feOptBool, 0, 0}, 138 128 139 {"no-out", no_argument, 0,LONG_OPTION_RETURN,129 {"no-out", no_argument, LONG_OPTION_RETURN, 140 130 0, "Suppress all output", feOptBool, 0, 0}, 141 131 142 {"min-time", required_argument, 0,LONG_OPTION_RETURN,143 "SECS", "Do not display times smaller than SECS (in seconds)", feOptString, "0.5", 0}, 132 {"min-time", required_argument, LONG_OPTION_RETURN, 133 "SECS", "Do not display times smaller than SECS (in seconds)", feOptString, "0.5", 0}, 144 134 145 135 #ifdef HAVE_MPSR 146 {"MPport", required_argument, 0,LONG_OPTION_RETURN,136 {"MPport", required_argument, LONG_OPTION_RETURN, 147 137 "PORT", "Use PORT number for MP conections", feOptString, 0, 0}, 148 138 149 {"MPhost", required_argument, 0,LONG_OPTION_RETURN,139 {"MPhost", required_argument, LONG_OPTION_RETURN, 150 140 "HOST", "Use HOST for MP connections", feOptString, 0, 0}, 151 141 #endif 152 142 153 {"ticks-per-sec", required_argument, 0,LONG_OPTION_RETURN,143 {"ticks-per-sec", required_argument, LONG_OPTION_RETURN, 154 144 "TICKS", "Sets unit of timer to TICKS per second", feOptInt, (void*)1, 0}, 155 145 156 146 // undocumented options 157 147 #ifdef HAVE_MPSR 158 {"MPtransp", required_argument, 0,LONG_OPTION_RETURN,148 {"MPtransp", required_argument, LONG_OPTION_RETURN, 159 149 "TRANSP", "// Use TRANSP for MP connections", feOptString, 0, 0}, 160 161 {"MPmode", required_argument, 0,LONG_OPTION_RETURN,150 151 {"MPmode", required_argument, LONG_OPTION_RETURN, 162 152 "MODE", "// Use MODE for MP connections", feOptString, 0, 0}, 163 153 #endif 164 154 165 155 // terminator -- do NOT remove 166 { 0, 0, 0, 0 , 0, 0, feOptInt, 0, 0}156 { 0, 0, 0, 0, 0, feOptInt, 0, 0} 167 157 }; 168 158 … … 181 171 #ifdef ESINGULAR 182 172 fd = fopen("feOptES.inc", "w"); 183 #else 173 #else 184 174 fd = fopen("feOpt.inc", "w"); 185 175 #endif … … 188 178 189 179 int i = 0; 190 191 fputs("typedef enum\n{\n 192 180 181 fputs("typedef enum\n{\n", fd); 182 193 183 while (feOptSpec[i].name != NULL) 194 184 { … … 197 187 while (*name != 0) 198 188 { 199 if (*name == '-') 189 if (*name == '-') 200 190 { 201 191 putc('_', fd); … … 218 208 fputs(",\n ", fd); 219 209 } 220 210 221 211 fprintf(fd, "FE_OPT_UNDEF\n} feOptIndex;\n"); 222 212 fclose(fd); … … 234 224 { 235 225 int opt = 0; 236 226 237 227 while (opt != (int) FE_OPT_UNDEF) 238 228 { 239 if (strcmp(feOptSpec[opt].name, name) == 0) 229 if (strcmp(feOptSpec[opt].name, name) == 0) 240 230 return (feOptIndex) opt; 241 231 opt = opt + 1; … … 247 237 { 248 238 int opt = 0; 249 239 250 240 if (optc == LONG_OPTION_RETURN) return FE_OPT_UNDEF; 251 241 252 242 while (opt != (int) FE_OPT_UNDEF) 253 243 { … … 286 276 { 287 277 if (opt == FE_OPT_UNDEF) return "option undefined"; 288 278 289 279 if (feOptSpec[opt].type != feOptUntyped) 290 280 { … … 320 310 { 321 311 if (opt == FE_OPT_UNDEF) return "option undefined"; 322 312 323 313 if (feOptSpec[opt].type != feOptUntyped) 324 314 { 325 315 if (feOptSpec[opt].type == feOptString) 326 316 return "option value needs to be an integer"; 327 317 328 318 feOptSpec[opt].value = (void*) optarg; 329 319 } … … 393 383 return "argument of option is not in valid range 0..9"; 394 384 return NULL; 395 385 396 386 case FE_OPT_RANDOM: 397 387 siRandomStart = (unsigned int) feOptSpec[FE_OPT_RANDOM].value; … … 424 414 feWarn = TRUE; 425 415 return NULL; 426 416 427 417 case FE_OPT_NO_OUT: 428 418 if (feOptSpec[FE_OPT_NO_OUT].value) … … 499 489 #ifdef ESINGULAR 500 490 printf("ESingular: A Program that starts-up Singular within emacs, for\n"); 501 #endif 491 #endif 502 492 printf("Singular version %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1); 503 493 printf(" %s [options] [file1 [file2 ...]]\n", name); … … 506 496 while (feOptSpec[i].name != 0) 507 497 { 508 if (feOptSpec[i].help != NULL 498 if (feOptSpec[i].help != NULL 509 499 #ifdef NDEBUG 510 500 && *(feOptSpec[i].help) != '/' -
Singular/fegetopt.c
r2bb771 r3b295e 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: fegetopt.c,v 1. 2 1999-09-22 10:19:04Singular Exp $ */4 /* $Id: fegetopt.c,v 1.3 1999-09-22 15:42:13 Singular Exp $ */ 5 5 6 6 /* Getopt for GNU. … … 306 306 argument, it follows the option name in the same ARGV-element, separated 307 307 from the option name by a `=', or else the in next ARGV-element. 308 When `getopt' finds a long-named option, it returns 0 if that option's 309 `flag' field is nonzero, the value of the option's `val' field 310 if the `flag' field is zero. 308 When `getopt' finds a long-named option, it returns 309 the value of the option's `val' field. 311 310 312 311 The elements of ARGV aren't really const, because we permute them. … … 541 540 if (longind != NULL) 542 541 *longind = option_index; 543 if (pfound->flag)544 {545 *(pfound->flag) = pfound->val;546 return 0;547 }548 542 return pfound->val; 549 543 } -
Singular/fegetopt.h
r2bb771 r3b295e 69 69 optional_argument (or 2) if the option takes an optional argument. 70 70 71 If the field `flag' is not NULL, it points to a variable that is set72 to the value given in the field `val' when the option is found, but73 left unchanged if the option is not found.74 75 71 To have a long-named option do something other than set an `int' to 76 72 a compiled-in constant, such as set a value from `optarg', set the 77 option's `flag' field to zero and its `val' field to a nonzero 78 value (the equivalent single-letter option character, if there is 79 one). For long options that have a zero `flag' field, `getopt' 80 returns the contents of the `val' field. */ 73 `val' field to a nonzero value (the equivalent single-letter option 74 character, if there is one). 75 For long options `getopt' returns the contents of the `val' field. */ 81 76 82 77 typedef enum {feOptUntyped, feOptBool, feOptInt, feOptString} feOptType; … … 91 86 type mismatches in all the code that assumes it is an int. */ 92 87 int has_arg; 93 int *flag;94 88 int val; 95 89 /* Stuff added for Singular */
Note: See TracChangeset
for help on using the changeset viewer.