home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / uucp.subproj / getop1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-09  |  3.2 KB  |  145 lines

  1. /* Getopt for GNU.
  2.    Copyright (C) 1987, 88, 89, 90, 91, 1992 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify it
  5.    under the terms of the GNU General Public License as published by the
  6.    Free Software Foundation; either version 2, or (at your option) any
  7.    later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.    
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  
  18.    This file was modified slightly by Ian Lance Taylor, June 1992, for
  19.    Taylor UUCP.  */
  20.  
  21. #include "uucp.h"
  22.  
  23. #include "getopt.h"
  24.  
  25. int
  26. getopt_long (argc, argv, options, long_options, opt_index)
  27.      int argc;
  28.      char *const *argv;
  29.      const char *options;
  30.      const struct option *long_options;
  31.      int *opt_index;
  32. {
  33.   return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
  34. }
  35.  
  36. /* Like getopt_long, but '-' as well as '--' can indicate a long option.
  37.    If an option that starts with '-' (not '--') doesn't match a long option,
  38.    but does match a short option, it is parsed as a short option
  39.    instead.  */
  40.  
  41. int 
  42. getopt_long_only (argc, argv, options, long_options, opt_index)
  43.      int argc;
  44.      char *const *argv;
  45.      const char *options;
  46.      const struct option *long_options;
  47.      int *opt_index;
  48. {
  49.   return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
  50. }
  51.  
  52. #ifdef TEST
  53.  
  54. #include <stdio.h>
  55.  
  56. int
  57. main (argc, argv)
  58.      int argc;
  59.      char **argv;
  60. {
  61.   int c;
  62.   int digit_optind = 0;
  63.  
  64.   while (1)
  65.     {
  66.       int this_option_optind = optind ? optind : 1;
  67.       int option_index = 0;
  68.       static struct option long_options[] =
  69.       {
  70.     {"add", 1, 0, 0},
  71.     {"append", 0, 0, 0},
  72.     {"delete", 1, 0, 0},
  73.     {"verbose", 0, 0, 0},
  74.     {"create", 0, 0, 0},
  75.     {"file", 1, 0, 0},
  76.     {0, 0, 0, 0}
  77.       };
  78.  
  79.       c = getopt_long (argc, argv, "abc:d:0123456789",
  80.                long_options, &option_index);
  81.       if (c == EOF)
  82.     break;
  83.  
  84.       switch (c)
  85.     {
  86.     case 0:
  87.       printf ("option %s", long_options[option_index].name);
  88.       if (optarg)
  89.         printf (" with arg %s", optarg);
  90.       printf ("\n");
  91.       break;
  92.  
  93.     case '0':
  94.     case '1':
  95.     case '2':
  96.     case '3':
  97.     case '4':
  98.     case '5':
  99.     case '6':
  100.     case '7':
  101.     case '8':
  102.     case '9':
  103.       if (digit_optind != 0 && digit_optind != this_option_optind)
  104.         printf ("digits occur in two different argv-elements.\n");
  105.       digit_optind = this_option_optind;
  106.       printf ("option %c\n", c);
  107.       break;
  108.  
  109.     case 'a':
  110.       printf ("option a\n");
  111.       break;
  112.  
  113.     case 'b':
  114.       printf ("option b\n");
  115.       break;
  116.  
  117.     case 'c':
  118.       printf ("option c with value `%s'\n", optarg);
  119.       break;
  120.  
  121.     case 'd':
  122.       printf ("option d with value `%s'\n", optarg);
  123.       break;
  124.  
  125.     case '?':
  126.       break;
  127.  
  128.     default:
  129.       printf ("?? getopt returned character code 0%o ??\n", c);
  130.     }
  131.     }
  132.  
  133.   if (optind < argc)
  134.     {
  135.       printf ("non-option ARGV-elements: ");
  136.       while (optind < argc)
  137.     printf ("%s ", argv[optind++]);
  138.       printf ("\n");
  139.     }
  140.  
  141.   exit (0);
  142. }
  143.  
  144. #endif /* TEST */
  145.