Changeset 3b295e in git


Ignore:
Timestamp:
Sep 22, 1999, 5:42:13 PM (24 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
Children:
824241e0feb57039b89a14bd31a86a23e5a87032
Parents:
2bb771a6d877e2842019e777594b5edfacafda1b
Message:
*hannes: simplified getopt


git-svn-id: file:///usr/local/Singular/svn/trunk@3649 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Singular/feOpt.cc

    r2bb771 r3b295e  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: feOpt.cc,v 1.4 1999-09-21 16:40:14 obachman Exp $ */
     4/* $Id: feOpt.cc,v 1.5 1999-09-22 15:42:12 Singular Exp $ */
    55/*
    66* ABSTRACT: Implementation of option buisness
     
    1414{
    1515//
    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}
    1919//  where:
    2020//
    2121//        name   is the name of the long option.
    22 // 
     22//
    2323//        has_arg
    2424//               is:  no_argument (or 0) if the option does not take
     
    2626//               requires  an  argument, or optional_argument (or 2)
    2727//               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//
    3929//        val    is  the  value  to  return,  or  to  load  into the
    4030//               variable pointed to by flag.
     
    4232//                           short option char,  for short option
    4333//
    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
    4535//                display of help
    46 //     
     36//
    4737//        help  one-line description of option
    4838//
    49 //        type  one of feOptUntyped (value is never set), 
     39//        type  one of feOptUntyped (value is never set),
    5040//                     feOptBool, feOptInt, feOptString
    51 //                     
     41//
    5242//        value (default) value of option
    53 //         
    54 //       set   only relevant for feOptString: 
     43//
     44//       set   only relevant for feOptString:
    5545//             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
    5949// their help is printed on -h
    6050//
    6151// Options whose hel starts with an "//" are considered undocumented,
    6252// i.e., their help is not printed on -h
    63 // 
     53//
    6454#ifdef ESINGULAR
    6555// options only relevant for ESINGULAR
    66   {"emacs",         required_argument,  0,  LONG_OPTION_RETURN,
     56  {"emacs",         required_argument,      LONG_OPTION_RETURN,
    6757   "EMACS",     "Use EMACS as emacs program to run Singular",          feOptString, 0,   0},
    6858
    69   {"emacs-dir",         required_argument,  0,  LONG_OPTION_RETURN,
     59  {"emacs-dir",         required_argument,  LONG_OPTION_RETURN,
    7060   "DIR",       "Use DIR as directory to look for emacs lisp files",   feOptString, 0,   0},
    7161
    72   {"emacs-load",        required_argument,  0,  LONG_OPTION_RETURN,
     62  {"emacs-load",        required_argument,  LONG_OPTION_RETURN,
    7363   "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,
    7666   "PROG",      "Start PROG as Singular program within emacs",         feOptString, 0,   0},
    7767
    78   {"no-emacs-call",     no_argument,  0,  LONG_OPTION_RETURN,
     68  {"no-emacs-call",     no_argument,        LONG_OPTION_RETURN,
    7969   0,          "Do not start emacs. Print emacs-call to stdout",       feOptBool,   0,   0},
    8070#endif
    8171
    8272#ifdef HAVE_MPSR
    83   {"batch",             no_argument,  0,  'b',
     73  {"batch",             no_argument,        'b',
    8474   0,          "Run in MP batch mode",                                 feOptBool,    0,     0},
    8575#endif
    8676
    87   {"execute",           required_argument,  0,  'c',
     77  {"execute",           required_argument,  'c',
    8878   "STRING",   "Execute STRING on start-up",                           feOptString, 0,   0},
    89    
    90   {"sdb",               no_argument,  0,  'd',
     79
     80  {"sdb",               no_argument,        'd',
    9181   0,          "Enable source code debugger (experimental)",           feOptBool,    0,      0},
    9282
    93   {"echo",              optional_argument, 0, 'e',
     83  {"echo",              optional_argument, 'e',
    9484   "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',
    9787   0,          "Print help message and exit",                          feOptUntyped,    0,      0},
    9888
    99   {"quiet",             no_argument,  0,  'q',
     89  {"quiet",             no_argument,        'q',
    10090   0,          "Do not print start-up banner and lib load messages",   feOptBool,    0,      0},
    10191
    102   {"random",            required_argument,  0,  'r',
     92  {"random",            required_argument,  'r',
    10393   "SEED",     "Seed random generator with integer (integer) SEED",    feOptInt,    0,      0},
    10494
    105   {"no-tty",            no_argument,  0,  't',
     95  {"no-tty",            no_argument,        't',
    10696   0,          "Do not redefine the terminal characteristics",         feOptBool,    0,      0},
    10797
    108   {"user-option",       required_argument,  0,  'u',
     98  {"user-option",       required_argument,  'u',
    10999   "STRING",   "Return STRING on `system(\"--user-option\")'",         feOptString, 0,   0},
    110100
    111   {"version",           no_argument,  0,  'v',
     101  {"version",           no_argument,        'v',
    112102   0,          "Print extended version and configuration info",        feOptUntyped,    0,      0},
    113103
    114104#ifdef HAVE_TCL
    115   {"tclmode",           no_argument,  0,  'x',
     105  {"tclmode",           no_argument,        'x',
    116106   0,          "Run in TCL mode, i.e., with TCL user interface",       feOptBool,    0,      0},
    117107#endif
    118108
    119   {"allow-net",         no_argument,  0,  LONG_OPTION_RETURN,
     109  {"allow-net",         no_argument,        LONG_OPTION_RETURN,
    120110   0,          "Allow to fetch (html) help pages from the net",                feOptBool,    0,      0},
    121111
    122   {"browser",           required_argument,  0,  LONG_OPTION_RETURN,
     112  {"browser",           required_argument,  LONG_OPTION_RETURN,
    123113   "BROWSER",  "Display help in BROWSER ([x,tk]info, netscape)",       feOptString, 0,   0},
    124114
    125115#ifndef ESINGULAR
    126   {"emacs",             no_argument,  0,  LONG_OPTION_RETURN,
     116  {"emacs",             no_argument,        LONG_OPTION_RETURN,
    127117   0,          "Set defaults for running within emacs",                feOptBool,    0,      0},
    128118#endif
    129119
    130   {"no-stdlib",         no_argument,  0,  LONG_OPTION_RETURN,
     120  {"no-stdlib",         no_argument,        LONG_OPTION_RETURN,
    131121   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,
    134124   0,          "Do not execute `.singularrc' file(s) on start-up",     feOptBool,    0,      0},
    135125
    136   {"no-warn",           no_argument,  0,  LONG_OPTION_RETURN,
     126  {"no-warn",           no_argument,        LONG_OPTION_RETURN,
    137127   0,          "Do not display warning messages",                      feOptBool,    0,      0},
    138128
    139   {"no-out",            no_argument,  0,  LONG_OPTION_RETURN,
     129  {"no-out",            no_argument,        LONG_OPTION_RETURN,
    140130   0,          "Suppress all output",                                  feOptBool,    0,      0},
    141131
    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},
    144134
    145135#ifdef HAVE_MPSR
    146   {"MPport",           required_argument,  0, LONG_OPTION_RETURN,
     136  {"MPport",           required_argument,  LONG_OPTION_RETURN,
    147137   "PORT",     "Use PORT number for MP conections",                    feOptString,    0,      0},
    148138
    149   {"MPhost",           required_argument,  0, LONG_OPTION_RETURN,
     139  {"MPhost",           required_argument,  LONG_OPTION_RETURN,
    150140   "HOST",     "Use HOST for MP connections",                          feOptString,    0,   0},
    151141#endif
    152142
    153   {"ticks-per-sec",     required_argument,  0,  LONG_OPTION_RETURN,
     143  {"ticks-per-sec",     required_argument,  LONG_OPTION_RETURN,
    154144   "TICKS",     "Sets unit of timer to TICKS per second",               feOptInt,    (void*)1,      0},
    155145
    156146// undocumented options
    157147#ifdef HAVE_MPSR
    158   {"MPtransp",         required_argument,  0, LONG_OPTION_RETURN,
     148  {"MPtransp",         required_argument,  LONG_OPTION_RETURN,
    159149   "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,
    162152   "MODE",      "// Use MODE for MP connections",                       feOptString,    0,   0},
    163153#endif
    164    
     154
    165155// terminator -- do NOT remove
    166   { 0, 0, 0, 0 , 0, 0, feOptInt, 0, 0}
     156  { 0, 0, 0, 0, 0, feOptInt, 0, 0}
    167157};
    168158
     
    181171#ifdef ESINGULAR
    182172  fd = fopen("feOptES.inc", "w");
    183 #else 
     173#else
    184174  fd = fopen("feOpt.inc", "w");
    185175#endif
     
    188178
    189179  int i = 0;
    190  
    191   fputs("typedef enum\n{\n  ", fd);
    192  
     180
     181  fputs("typedef enum\n{\n", fd);
     182
    193183  while (feOptSpec[i].name != NULL)
    194184  {
     
    197187    while (*name != 0)
    198188    {
    199       if (*name == '-') 
     189      if (*name == '-')
    200190      {
    201191        putc('_', fd);
     
    218208    fputs(",\n  ", fd);
    219209  }
    220  
     210
    221211  fprintf(fd, "FE_OPT_UNDEF\n} feOptIndex;\n");
    222212  fclose(fd);
     
    234224{
    235225  int opt = 0;
    236  
     226
    237227  while (opt != (int) FE_OPT_UNDEF)
    238228  {
    239     if (strcmp(feOptSpec[opt].name, name) == 0) 
     229    if (strcmp(feOptSpec[opt].name, name) == 0)
    240230      return (feOptIndex) opt;
    241231    opt = opt + 1;
     
    247237{
    248238  int opt = 0;
    249  
     239
    250240  if (optc == LONG_OPTION_RETURN) return FE_OPT_UNDEF;
    251  
     241
    252242  while (opt != (int) FE_OPT_UNDEF)
    253243  {
     
    286276{
    287277  if (opt == FE_OPT_UNDEF) return "option undefined";
    288  
     278
    289279  if (feOptSpec[opt].type != feOptUntyped)
    290280  {
     
    320310{
    321311  if (opt == FE_OPT_UNDEF) return "option undefined";
    322  
     312
    323313  if (feOptSpec[opt].type != feOptUntyped)
    324314  {
    325315    if (feOptSpec[opt].type == feOptString)
    326316      return "option value needs to be an integer";
    327  
     317
    328318    feOptSpec[opt].value = (void*) optarg;
    329319  }
     
    393383          return "argument of option is not in valid range 0..9";
    394384        return NULL;
    395        
     385
    396386      case FE_OPT_RANDOM:
    397387        siRandomStart = (unsigned int) feOptSpec[FE_OPT_RANDOM].value;
     
    424414          feWarn = TRUE;
    425415        return NULL;
    426        
     416
    427417      case FE_OPT_NO_OUT:
    428418        if (feOptSpec[FE_OPT_NO_OUT].value)
     
    499489#ifdef ESINGULAR
    500490  printf("ESingular: A Program that starts-up Singular within emacs, for\n");
    501 #endif 
     491#endif
    502492  printf("Singular version %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1);
    503493  printf("   %s [options] [file1 [file2 ...]]\n", name);
     
    506496  while (feOptSpec[i].name != 0)
    507497  {
    508     if (feOptSpec[i].help != NULL 
     498    if (feOptSpec[i].help != NULL
    509499#ifdef NDEBUG
    510500        && *(feOptSpec[i].help) != '/'
  • Singular/fegetopt.c

    r2bb771 r3b295e  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: fegetopt.c,v 1.2 1999-09-22 10:19:04 Singular Exp $ */
     4/* $Id: fegetopt.c,v 1.3 1999-09-22 15:42:13 Singular Exp $ */
    55
    66/* Getopt for GNU.
     
    306306   argument, it follows the option name in the same ARGV-element, separated
    307307   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.
    311310
    312311   The elements of ARGV aren't really const, because we permute them.
     
    541540          if (longind != NULL)
    542541            *longind = option_index;
    543           if (pfound->flag)
    544             {
    545               *(pfound->flag) = pfound->val;
    546               return 0;
    547             }
    548542          return pfound->val;
    549543        }
  • Singular/fegetopt.h

    r2bb771 r3b295e  
    6969   optional_argument         (or 2) if the option takes an optional argument.
    7070
    71    If the field `flag' is not NULL, it points to a variable that is set
    72    to the value given in the field `val' when the option is found, but
    73    left unchanged if the option is not found.
    74 
    7571   To have a long-named option do something other than set an `int' to
    7672   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.  */
    8176
    8277typedef enum {feOptUntyped, feOptBool, feOptInt, feOptString} feOptType;
     
    9186     type mismatches in all the code that assumes it is an int.  */
    9287  int has_arg;
    93   int *flag;
    9488  int val;
    9589  /* Stuff added for Singular  */
Note: See TracChangeset for help on using the changeset viewer.