Changeset 3701


Ignore:
Timestamp:
Mar 16, 2011, 5:55:12 PM (14 years ago)
Author:
bird
Message:

emxomfar: Fixed and relaxed the command/option parsing so that they can be given with a dash (was broken) and in more than one argument. Should probably insist on the command comming first, but who cares. References #184.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/emx/src/emxomf/emxomfar.c

    r566 r3701  
    257257  page_size = 0;
    258258
    259   /* Parse the command line.  First, check for an -p# option. */
     259  /* Set initial values. */
     260
     261  verbose = FALSE;
     262  silent  = FALSE;
     263  cmd     = 0;
     264
     265  /* Skip a leading dash, it's optional. */
    260266
    261267  i = 1;
    262   if (i < argc && argv[i][0] == '-')
    263     {
    264       s = argv[i]+1;
    265       switch (*s)
    266         {
    267         case 'p':
    268           ++s;
    269           page_size = strtol (s, &s, 10);
    270           if (page_size < 1 || *s != 0)
    271             usage ();
    272           ++i;
    273           break;
    274         default:
    275           usage ();
    276         }
    277     }
    278 
    279   /* At least 2 arguments must be given: the command and the library
    280      name. */
    281 
    282   if (argc - i < 2)
    283     usage ();
    284 
    285   /* Set initial values. */
    286 
    287   verbose = FALSE; silent = FALSE; cmd = 0;
    288 
    289   /* Skip a leading - character, it's optional. */
    290 
    291268  s = argv[i++];
    292269  if (*s == '-')
    293270    ++s;
    294271
    295   /* Parse the command. */
    296 
    297   while (*s != 0)
    298     {
    299       new_cmd = 0;
    300       switch (*s)
    301         {
    302         case 'v':
    303           verbose = TRUE;
    304           break;
    305         case 'c':
    306           silent = TRUE;
    307           break;
    308         case 's':
    309           if (cmd == 0)
    310             new_cmd = 's';
    311           break;
    312         case 'd':
    313         case 'r':
    314         case 't':
    315         case 'x':
    316           new_cmd = *s;
    317           break;
    318         case 'q':
    319           new_cmd = 'r';
    320           break;
    321         case 'u':
    322           if (cmd == 0)
    323             new_cmd = 'r';
    324           break;
    325         case 'l':
    326         case 'o':
    327           break;
    328         default:
    329           usage ();
    330         }
    331       ++s;
    332       if (new_cmd != 0)
    333         {
    334           if (cmd != 0)
    335             usage ();
    336           cmd = new_cmd;
    337         }
    338     }
    339 
    340   /* Complain if no command letter was given. */
    341 
    342   if (cmd == 0)
     272  /* Parse the command and options. */
     273
     274  for (;;)
     275    {
     276      while (*s != 0)
     277        {
     278          new_cmd = 0;
     279          switch (*s)
     280            {
     281            case 'v':
     282              verbose = TRUE;
     283              break;
     284            case 'c':
     285              silent = TRUE;
     286              break;
     287            case 's':
     288              if (cmd == 0)
     289                new_cmd = 's';
     290              break;
     291            case 'd':
     292            case 'r':
     293            case 't':
     294            case 'x':
     295              new_cmd = *s;
     296              break;
     297            case 'q':
     298              new_cmd = 'r';
     299              break;
     300            case 'u':
     301              if (cmd == 0)
     302                new_cmd = 'r';
     303              break;
     304            case 'l':
     305            case 'o':
     306              break;
     307            case 'p':
     308              ++s;
     309              page_size = strtol (s, &s, 10);
     310              if (page_size < 1 || *s != 0)
     311                usage ();
     312              --s;
     313              break;
     314            default:
     315              usage ();
     316            }
     317          ++s;
     318          if (new_cmd != 0)
     319            {
     320              if (cmd != 0)
     321                usage ();
     322              cmd = new_cmd;
     323            }
     324        }
     325
     326      /* more options? */
     327
     328      if (i >= argc)
     329        usage ();
     330      s = argv[i];
     331      if (*s != '-')
     332        break; /* not an option */
     333     
     334      s++;
     335      i++;
     336      if (*s == '-' && !s[1])
     337        break; /* end of options: '--' */
     338    }
     339
     340  /* Complain if no command letter or library was given. */
     341
     342  if (cmd == 0 || i >= argc)
    343343    usage ();
    344344
Note: See TracChangeset for help on using the changeset viewer.