Changeset 930


Ignore:
Timestamp:
Jan 2, 2004, 8:37:04 PM (22 years ago)
Author:
bird
Message:

Obsoleted, made it _emx_ specific.

Location:
trunk/src/emx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/getopt.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r929 r930  
    88#endif
    99
    10 extern char *optarg;       /* argument of current option                    */
    11 extern int optind;         /* index of next argument; default=0: initialize */
    12 extern int opterr;         /* 0=disable error messages; default=1: enable   */
    13 extern int optopt;         /* option character which caused the error       */
    14 extern char *optswchar;    /* characters introducing options; default="-"   */
     10extern char *_emx_optarg;       /* argument of current option                    */
     11extern int _emx_optind;         /* index of next argument; default=0: initialize */
     12extern int _emx_opterr;         /* 0=disable error messages; default=1: enable   */
     13extern int _emx_optopt;         /* option character which caused the error       */
     14extern char *_emx_optswchar;    /* characters introducing options; default="-"   */
    1515
    1616extern enum _optmode
     
    1919  GETOPT_ANY,              /* move non-options to the end                   */
    2020  GETOPT_KEEP              /* return options in order                       */
    21 } optmode;
     21} _emx_optmode;
    2222
    2323
     
    2525   array pointed to. */
    2626
    27 int getopt (int, char **, __const__ char *);
     27int _emx_getopt (int, char **, __const__ char *);
    2828
    2929#if defined (__cplusplus)
  • trunk/src/emx/src/lib/misc/getopt.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r929 r930  
    88#include <emx/umalloc.h>
    99
    10 char *optarg          = NULL;
    11 int optind            = 1;              /* Default: first call             */
    12 int opterr            = 1;              /* Default: error messages enabled */
    13 char *optswchar       = "-";            /* Default: '-' starts options     */
    14 enum _optmode optmode = GETOPT_UNIX;
    15 int optopt;
     10char *_emx_optarg          = NULL;
     11int _emx_optind            = 1;              /* Default: first call             */
     12int _emx_opterr            = 1;              /* Default: error messages enabled */
     13char *_emx_optswchar       = "-";            /* Default: '-' starts options     */
     14enum _optmode _emx_optmode = GETOPT_UNIX;
     15int _emx_optopt;
    1616
    1717static char * next_opt;             /* Next character in cluster of options */
     
    3030
    3131#define PUT(dst) BEGIN \
    32                   if (optmode == GETOPT_ANY) \
    33                     dst[dst##_count++] = argv[optind]; \
     32                  if (_emx_optmode == GETOPT_ANY) \
     33                    dst[dst##_count++] = argv[_emx_optind]; \
    3434                 END
    3535
    3636/* Note: `argv' is not const as GETOPT_ANY reorders argv[]. */
    3737
    38 int _STD(getopt) (int argc, char * argv[], const char *opt_str)
     38int _emx_getopt (int argc, char * argv[], const char *opt_str)
    3939{
    4040  char c, *q;
    4141  int i, j;
    4242
    43   if (!init || optind == 0)
     43  if (!init || _emx_optind == 0)
    4444    {
    45       if (optind == 0) optind = 1;
     45      if (_emx_optind == 0) _emx_optind = 1;
    4646      done = 0; init = 1;
    4747      next_opt = "";
    48       if (optmode == GETOPT_ANY)
     48      if (_emx_optmode == GETOPT_ANY)
    4949        {
    5050          options = (char **)_hmalloc (argc * sizeof (char *));
     
    6161    return -1;
    6262restart:
    63   optarg = NULL;
     63  _emx_optarg = NULL;
    6464  if (*next_opt == 0)
    6565    {
    66       if (optind >= argc)
     66      if (_emx_optind >= argc)
    6767        {
    68           if (optmode == GETOPT_ANY)
     68          if (_emx_optmode == GETOPT_ANY)
    6969            {
    7070              j = 1;
     
    7373              for (i = 0; i < non_options_count; ++i)
    7474                argv[j++] = non_options[i];
    75               optind = options_count+1;
     75              _emx_optind = options_count+1;
    7676              free (options); free (non_options);
    7777            }
     
    7979          return -1;
    8080        }
    81       else if (!strchr (optswchar, argv[optind][0]) || argv[optind][1] == 0)
     81      else if (!strchr (_emx_optswchar, argv[_emx_optind][0]) || argv[_emx_optind][1] == 0)
    8282        {
    83           if (optmode == GETOPT_UNIX)
     83          if (_emx_optmode == GETOPT_UNIX)
    8484            {
    8585              done = 1;
     
    8787            }
    8888          PUT (non_options);
    89           optarg = argv[optind++];
    90           if (optmode == GETOPT_ANY)
     89          _emx_optarg = argv[_emx_optind++];
     90          if (_emx_optmode == GETOPT_ANY)
    9191            goto restart;
    92           /* optmode==GETOPT_KEEP */
     92          /* _emx_optmode==GETOPT_KEEP */
    9393          return 0;
    9494        }
    95       else if (argv[optind][0] == argv[optind][1] && argv[optind][2] == 0)
     95      else if (argv[_emx_optind][0] == argv[_emx_optind][1] && argv[_emx_optind][2] == 0)
    9696        {
    97           if (optmode == GETOPT_ANY)
     97          if (_emx_optmode == GETOPT_ANY)
    9898            {
    9999              j = 1;
    100100              for (i = 0; i < options_count; ++i)
    101101                argv[j++] = options[i];
    102               argv[j++] = argv[optind];
     102              argv[j++] = argv[_emx_optind];
    103103              for (i = 0; i < non_options_count; ++i)
    104104                argv[j++] = non_options[i];
    105               for (i = optind+1; i < argc; ++i)
     105              for (i = _emx_optind+1; i < argc; ++i)
    106106                argv[j++] = argv[i];
    107               optind = options_count+2;
     107              _emx_optind = options_count+2;
    108108              free (options); free (non_options);
    109109            }
    110           ++optind;
     110          ++_emx_optind;
    111111          done = 1;
    112112          return -1;
     
    115115        {
    116116          PUT (options);
    117           sw_char = argv[optind][0];
    118           next_opt = argv[optind]+1;
     117          sw_char = argv[_emx_optind][0];
     118          next_opt = argv[_emx_optind]+1;
    119119        }
    120120    }
    121121  c = *next_opt++;
    122122  if (*next_opt == 0)  /* Move to next argument if end of argument reached */
    123     ++optind;
     123    ++_emx_optind;
    124124  if (c == ':' || (q = strchr (opt_str, c)) == NULL)
    125125    {
    126       if (opterr && opt_str[0] != ':')
     126      if (_emx_opterr && opt_str[0] != ':')
    127127        {
    128128          if (c < ' ' || c >= 127)
     
    133133                     argv[0], sw_char, c);
    134134        }
    135       optopt = c;
     135      _emx_optopt = c;
    136136      return '?';
    137137    }
     
    140140      if (*next_opt != 0)         /* Argument given */
    141141        {
    142           optarg = next_opt;
     142          _emx_optarg = next_opt;
    143143          next_opt = "";
    144           ++optind;
     144          ++_emx_optind;
    145145        }
    146146      else if (q[2] == ':')
    147         optarg = NULL;            /* Optional argument missing */
    148       else if (optind >= argc)
     147        _emx_optarg = NULL;            /* Optional argument missing */
     148      else if (_emx_optind >= argc)
    149149        {                         /* Required argument missing */
    150           if (opterr && opt_str[0] != ':')
     150          if (_emx_opterr && opt_str[0] != ':')
    151151            fprintf (stderr, "%s: no argument for `%c%c' option\n",
    152152                     argv[0], sw_char, c);
    153           optopt = c;
     153          _emx_optopt = c;
    154154          return (opt_str[0] == ':' ? ':' : '?');
    155155        }
     
    157157        {
    158158          PUT (options);
    159           optarg = argv[optind++];
     159          _emx_optarg = argv[_emx_optind++];
    160160        }
    161161    }
Note: See TracChangeset for help on using the changeset viewer.