home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 79 < prev    next >
Encoding:
Internet Message Format  |  1991-06-04  |  33.4 KB

  1. From: jac@yoko.rutgers.edu (Jonathan A. Chandross)
  2. Newsgroups: comp.sources.apple2
  3. Subject: v001SRC059:  coff -- Dump OMF Files Under Orca (GS), Part04/04
  4. Message-ID: <Jun.1.12.22.18.1991.13073@yoko.rutgers.edu>
  5. Date: 1 Jun 91 16:22:18 GMT
  6. Approved: jac@paul.rutgers.edu
  7.  
  8.  
  9. Submitted-by: Albert Chin (acmfiu@fiu.edu)
  10. Posting-number: Volume 1, Source:59
  11. Archive-name: util/gs/shell/orca/coff/part04
  12. Architecture: ONLY_2gs
  13. Version-number: 1.00
  14.  
  15.  
  16. =getopt.c
  17. -/* Getopt for GNU.
  18. -   Copyright (C) 1987, 1989, 1990 Free Software Foundation, Inc.
  19. -
  20. -   This program is free software; you can redistribute it and/or modify
  21. -   it under the terms of the GNU General Public License as published by
  22. -   the Free Software Foundation; either version 1, or (at your option)
  23. -   any later version.
  24. -
  25. -   This program is distributed in the hope that it will be useful,
  26. -   but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  28. -   GNU General Public License for more details.
  29. -
  30. -   You should have received a copy of the GNU General Public License
  31. -   along with this program; if not, write to the Free Software
  32. -   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  33. -
  34. -#pragma noroot
  35. -#pragma memorymodel    0
  36. -#pragma optimize    -1
  37. -
  38. -#ifdef __STDC__
  39. -#define CONST
  40. -#else
  41. -#define CONST
  42. -#endif
  43. -#include <stdio.h>
  44. -
  45. -/* This version of `getopt' appears to the caller like standard Unix `getopt'
  46. -   but it behaves differently for the user, since it allows the user
  47. -   to intersperse the options with the other arguments.
  48. -
  49. -   As `getopt' works, it permutes the elements of `argv' so that,
  50. -   when it is done, all the options precede everything else.  Thus
  51. -   all application programs are extended to handle flexible argument order.
  52. -
  53. -   Setting the environment variable _POSIX_OPTION_ORDER disables permutation.
  54. -   Then the behavior is completely standard.
  55. -
  56. -   GNU application programs can use a third alternative mode in which
  57. -   they can distinguish the relative order of options and other arguments.  */
  58. -
  59. -#include <stdio.h>
  60. -#define STDC_HEADERS
  61. -
  62. -/* If compiled with GNU C, use the built-in alloca */
  63. -#ifdef __GNUC__
  64. -#define alloca __builtin_alloca
  65. -#else /* not __GNUC__ */
  66. -#ifdef sparc
  67. -#include <alloca.h>
  68. -#else
  69. -char *alloca ();
  70. -#endif
  71. -#endif /* not __GNUC__ */
  72. -
  73. -#if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__)
  74. -#include <stdlib.h>
  75. -#include <string.h>
  76. -#define bcopy(s, d, n) memcpy ((d), (s), (n))
  77. -#define index strchr
  78. -#else
  79. -
  80. -#ifdef USG
  81. -#include <string.h>
  82. -#define bcopy(s, d, n) memcpy ((d), (s), (n))
  83. -#define index strchr
  84. -#else
  85. -#include <strings.h>
  86. -void bcopy ();
  87. -#endif
  88. -
  89. -char *getenv ();
  90. -char *malloc ();
  91. -#endif
  92. -
  93. -/* For communication from `getopt' to the caller.
  94. -   When `getopt' finds an option that takes an argument,
  95. -   the argument value is returned here.
  96. -   Also, when `ordering' is RETURN_IN_ORDER,
  97. -   each non-option ARGV-element is returned here.  */
  98. -
  99. -char *optarg = NULL;
  100. -
  101. -/* Index in ARGV of the next element to be scanned.
  102. -   This is used for communication to and from the caller
  103. -   and for communication between successive calls to `getopt'.
  104. -
  105. -   On entry to `getopt', zero means this is the first call; initialize.
  106. -
  107. -   When `getopt' returns EOF, this is the index of the first of the
  108. -   non-option elements that the caller should itself scan.
  109. -
  110. -   Otherwise, `optind' communicates from one call to the next
  111. -   how much of ARGV has been scanned so far.  */
  112. -
  113. -int optind = 0;
  114. -
  115. -/* The next char to be scanned in the option-element
  116. -   in which the last option character we returned was found.
  117. -   This allows us to pick up the scan where we left off.
  118. -
  119. -   If this is zero, or a null string, it means resume the scan
  120. -   by advancing to the next ARGV-element.  */
  121. -
  122. -static char *nextchar;
  123. -
  124. -/* Callers store zero here to inhibit the error message
  125. -   for unrecognized options.  */
  126. -
  127. -int opterr = 1;
  128. -
  129. -/* Describe how to deal with options that follow non-option ARGV-elements.
  130. -
  131. -   If the caller did not specify anything,
  132. -   the default is REQUIRE_ORDER if the environment variable
  133. -   _POSIX_OPTION_ORDER is defined, PERMUTE otherwise.
  134. -
  135. -   REQUIRE_ORDER means don't recognize them as options;
  136. -   stop option processing when the first non-option is seen.
  137. -   This is what Unix does.
  138. -   This mode of operation is selected by either setting the environment
  139. -   variable _POSIX_OPTION_ORDER, or using `+' as the first character
  140. -   of the list of option characters.
  141. -
  142. -   PERMUTE is the default.  We permute the contents of ARGV as we scan,
  143. -   so that eventually all the non-options are at the end.  This allows options
  144. -   to be given in any order, even with programs that were not written to
  145. -   expect this.
  146. -
  147. -   RETURN_IN_ORDER is an option available to programs that were written
  148. -   to expect options and other ARGV-elements in any order and that care about
  149. -   the ordering of the two.  We describe each non-option ARGV-element
  150. -   as if it were the argument of an option with character code 1.
  151. -   Using `-' as the first character of the list of option characters
  152. -   selects this mode of operation.
  153. -
  154. -   The special argument `--' forces an end of option-scanning regardless
  155. -   of the value of `ordering'.  In the case of RETURN_IN_ORDER, only
  156. -   `--' can cause `getopt' to return EOF with `optind' != ARGC.  */
  157. -
  158. -static enum
  159. -{
  160. -  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
  161. -} ordering;
  162. -
  163. -/* Describe the long-named options requested by the application.
  164. -   _GETOPT_LONG_OPTIONS is a vector of `struct option' terminated by an
  165. -   element containing a name which is zero.
  166. -   The field `has_arg' is 1 if the option takes an argument,
  167. -   2 if it takes an optional argument.  */
  168. -
  169. -struct option
  170. -{
  171. -  char *name;
  172. -  int has_arg;
  173. -  int *flag;
  174. -  int val;
  175. -};
  176. -
  177. -CONST struct option *_getopt_long_options;
  178. -
  179. -int _getopt_long_only = 0;
  180. -
  181. -/* Index in _GETOPT_LONG_OPTIONS of the long-named option actually found.
  182. -   Only valid when a long-named option was found. */
  183. -
  184. -int option_index;
  185. -
  186. -/* Handle permutation of arguments.  */
  187. -
  188. -/* Describe the part of ARGV that contains non-options that have
  189. -   been skipped.  `first_nonopt' is the index in ARGV of the first of them;
  190. -   `last_nonopt' is the index after the last of them.  */
  191. -
  192. -static int first_nonopt;
  193. -static int last_nonopt;
  194. -
  195. -/* Exchange two adjacent subsequences of ARGV.
  196. -   One subsequence is elements [first_nonopt,last_nonopt)
  197. -    which contains all the non-options that have been skipped so far.
  198. -   The other is elements [last_nonopt,optind), which contains all
  199. -    the options processed since those non-options were skipped.
  200. -
  201. -   `first_nonopt' and `last_nonopt' are relocated so that they describe
  202. -    the new indices of the non-options in ARGV after they are moved.  */
  203. -
  204. -static void
  205. -exchange (argv)
  206. -     char **argv;
  207. -{
  208. -  int nonopts_size = (last_nonopt - first_nonopt) * sizeof (char *);
  209. -  char **temp = (char **) malloc (nonopts_size);
  210. -
  211. -  /* Interchange the two blocks of data in ARGV.  */
  212. -
  213. -  bcopy (&argv[first_nonopt], temp, nonopts_size);
  214. -  bcopy (&argv[last_nonopt], &argv[first_nonopt],
  215. -     (optind - last_nonopt) * sizeof (char *));
  216. -  bcopy (temp, &argv[first_nonopt + optind - last_nonopt], nonopts_size);
  217. -
  218. -  /* Update records for the slots the non-options now occupy.  */
  219. -
  220. -  first_nonopt += (optind - last_nonopt);
  221. -  last_nonopt = optind;
  222. -  free (temp);
  223. -}
  224. -
  225. -/* Scan elements of ARGV (whose length is ARGC) for option characters
  226. -   given in OPTSTRING.
  227. -
  228. -   If an element of ARGV starts with '-', and is not exactly "-" or "--",
  229. -   then it is an option element.  The characters of this element
  230. -   (aside from the initial '-') are option characters.  If `getopt'
  231. -   is called repeatedly, it returns successively each of the option characters
  232. -   from each of the option elements.
  233. -
  234. -   If `getopt' finds another option character, it returns that character,
  235. -   updating `optind' and `nextchar' so that the next call to `getopt' can
  236. -   resume the scan with the following option character or ARGV-element.
  237. -
  238. -   If there are no more option characters, `getopt' returns `EOF'.
  239. -   Then `optind' is the index in ARGV of the first ARGV-element
  240. -   that is not an option.  (The ARGV-elements have been permuted
  241. -   so that those that are not options now come last.)
  242. -
  243. -   OPTSTRING is a string containing the legitimate option characters.
  244. -   If an option character is seen that is not listed in OPTSTRING,
  245. -   return '?' after printing an error message.  If you set `opterr' to
  246. -   zero, the error message is suppressed but we still return '?'.
  247. -
  248. -   If a char in OPTSTRING is followed by a colon, that means it wants an arg,
  249. -   so the following text in the same ARGV-element, or the text of the following
  250. -   ARGV-element, is returned in `optarg'.  Two colons mean an option that
  251. -   wants an optional arg; if there is text in the current ARGV-element,
  252. -   it is returned in `optarg', otherwise `optarg' is set to zero.
  253. -
  254. -   If OPTSTRING starts with `-' or `+', it requests different methods of
  255. -   handling the non-option ARGV-elements.
  256. -   See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
  257. -
  258. -   Long-named options begin with `+' instead of `-'.
  259. -   Their names may be abbreviated as long as the abbreviation is unique
  260. -   or is an exact match for some defined option.  If they have an
  261. -   argument, it follows the option name in the same ARGV-element, separated
  262. -   from the option name by a `=', or else the in next ARGV-element.
  263. -   When `getopt' finds a long-named option, it returns 0 if that option's
  264. -   `flag' field is nonzero, the value of the option's `val' field
  265. -   otherwise.  */
  266. -
  267. -int
  268. -getopt (argc, argv, optstring)
  269. -     int argc;
  270. -     char **argv;
  271. -     CONST char *optstring;
  272. -{
  273. -  optarg = NULL;
  274. -
  275. -  /* Initialize the internal data when the first call is made.
  276. -     Start processing options with ARGV-element 1 (since ARGV-element 0
  277. -     is the program name); the sequence of previously skipped
  278. -     non-option ARGV-elements is empty.  */
  279. -
  280. -  if (optind == 0)
  281. -    {
  282. -      first_nonopt = last_nonopt = optind = 1;
  283. -
  284. -      nextchar = NULL;
  285. -
  286. -      /* Determine how to handle the ordering of options and nonoptions.  */
  287. -
  288. -      if (optstring[0] == '-')
  289. -    {
  290. -      ordering = RETURN_IN_ORDER;
  291. -      ++optstring;
  292. -    }
  293. -      else if (optstring[0] == '+')
  294. -    {
  295. -      ordering = REQUIRE_ORDER;
  296. -      ++optstring;
  297. -    }
  298. -      else if (getenv ("_POSIX_OPTION_ORDER") != NULL)
  299. -    ordering = REQUIRE_ORDER;
  300. -      else
  301. -    ordering = PERMUTE;
  302. -    }
  303. -
  304. -  if (nextchar == NULL || *nextchar == 0)
  305. -    {
  306. -      if (ordering == PERMUTE)
  307. -    {
  308. -      /* If we have just processed some options following some non-options,
  309. -         exchange them so that the options come first.  */
  310. -
  311. -      if (first_nonopt != last_nonopt && last_nonopt != optind)
  312. -        exchange (argv);
  313. -      else if (last_nonopt != optind)
  314. -        first_nonopt = optind;
  315. -
  316. -      /* Now skip any additional non-options
  317. -         and extend the range of non-options previously skipped.  */
  318. -
  319. -      while (optind < argc
  320. -         && (argv[optind][0] != '-'
  321. -             || argv[optind][1] == 0)
  322. -         && (_getopt_long_options == NULL
  323. -             || argv[optind][0] != '+'
  324. -             || argv[optind][1] == 0))
  325. -        optind++;
  326. -      last_nonopt = optind;
  327. -    }
  328. -
  329. -      /* Special ARGV-element `--' means premature end of options.
  330. -     Skip it like a null option,
  331. -     then exchange with previous non-options as if it were an option,
  332. -     then skip everything else like a non-option.  */
  333. -
  334. -      if (optind != argc && !strcmp (argv[optind], "--"))
  335. -    {
  336. -      optind++;
  337. -
  338. -      if (first_nonopt != last_nonopt && last_nonopt != optind)
  339. -        exchange (argv);
  340. -      else if (first_nonopt == last_nonopt)
  341. -        first_nonopt = optind;
  342. -      last_nonopt = argc;
  343. -
  344. -      optind = argc;
  345. -    }
  346. -
  347. -      /* If we have done all the ARGV-elements, stop the scan
  348. -     and back over any non-options that we skipped and permuted.  */
  349. -
  350. -      if (optind == argc)
  351. -    {
  352. -      /* Set the next-arg-index to point at the non-options
  353. -         that we previously skipped, so the caller will digest them.  */
  354. -      if (first_nonopt != last_nonopt)
  355. -        optind = first_nonopt;
  356. -      return EOF;
  357. -    }
  358. -
  359. -      /* If we have come to a non-option and did not permute it,
  360. -     either stop the scan or describe it to the caller and pass it by.  */
  361. -
  362. -      if ((argv[optind][0] != '-' || argv[optind][1] == 0)
  363. -      && (_getopt_long_options == NULL
  364. -          || argv[optind][0] != '+' || argv[optind][1] == 0))
  365. -    {
  366. -      if (ordering == REQUIRE_ORDER)
  367. -        return EOF;
  368. -      optarg = argv[optind++];
  369. -      return 1;
  370. -    }
  371. -
  372. -      /* We have found another option-ARGV-element.
  373. -     Start decoding its characters.  */
  374. -
  375. -      nextchar = argv[optind] + 1;
  376. -    }
  377. -
  378. -  if (_getopt_long_options != NULL
  379. -      && (argv[optind][0] == '+'
  380. -      || (_getopt_long_only && argv[optind][0] == '-'))
  381. -    )
  382. -    {
  383. -      CONST struct option *p;
  384. -      char *s = nextchar;
  385. -      int exact = 0;
  386. -      int ambig = 0;
  387. -      CONST struct option *pfound = NULL;
  388. -      int indfound;
  389. -
  390. -      while (*s && *s != '=')
  391. -    s++;
  392. -
  393. -      /* Test all options for either exact match or abbreviated matches.  */
  394. -      for (p = _getopt_long_options, option_index = 0; p->name;
  395. -       p++, option_index++)
  396. -    if (!strncmp (p->name, nextchar, s - nextchar))
  397. -      {
  398. -        if (s - nextchar == strlen (p->name))
  399. -          {
  400. -        /* Exact match found.  */
  401. -        pfound = p;
  402. -        indfound = option_index;
  403. -        exact = 1;
  404. -        break;
  405. -          }
  406. -        else if (pfound == NULL)
  407. -          {
  408. -        /* First nonexact match found.  */
  409. -        pfound = p;
  410. -        indfound = option_index;
  411. -          }
  412. -        else
  413. -          /* Second nonexact match found.  */
  414. -          ambig = 1;
  415. -      }
  416. -
  417. -      if (ambig && !exact)
  418. -    {
  419. -      printf ("%s: option `%s' is ambiguous\n",
  420. -           argv[0], argv[optind]);
  421. -      nextchar += strlen (nextchar);
  422. -      optind++;
  423. -      return '?';
  424. -    }
  425. -
  426. -      if (pfound != NULL)
  427. -    {
  428. -      option_index = indfound;
  429. -      optind++;
  430. -      if (*s)
  431. -        {
  432. -          if (pfound->has_arg > 0)
  433. -        optarg = s + 1;
  434. -          else
  435. -        {
  436. -          printf ("%s: option `%c%s' doesn't allow an argument\n",
  437. -               argv[0], argv[optind - 1][0], pfound->name);
  438. -          nextchar += strlen (nextchar);
  439. -          return '?';
  440. -        }
  441. -        }
  442. -      else if (pfound->has_arg == 1)
  443. -        {
  444. -          if (optind < argc)
  445. -        optarg = argv[optind++];
  446. -          else
  447. -        {
  448. -          printf ("%s: option `%s' requires an argument\n",
  449. -               argv[0], argv[optind - 1]);
  450. -          nextchar += strlen (nextchar);
  451. -          return '?';
  452. -        }
  453. -        }
  454. -      nextchar += strlen (nextchar);
  455. -      if (pfound->flag)
  456. -        {
  457. -          *(pfound->flag) = pfound->val;
  458. -          return 0;
  459. -        }
  460. -      return pfound->val;
  461. -    }
  462. -      /* Can't find it as a long option.  If this is getopt_long_only,
  463. -     and the option starts with '-' and is a valid short
  464. -     option, then interpret it as a short option.  Otherwise it's
  465. -     an error.  */
  466. -      if (_getopt_long_only == 0 || argv[optind][0] == '+' ||
  467. -      index (optstring, *nextchar) == NULL)
  468. -    {
  469. -      if (opterr != 0)
  470. -        printf ("%s: unrecognized option `%c%s'\n",
  471. -             argv[0], argv[optind][0], nextchar);
  472. -      nextchar += strlen (nextchar);
  473. -      optind++;
  474. -      return '?';
  475. -    }
  476. -    }
  477. -
  478. -  /* Look at and handle the next option-character.  */
  479. -
  480. -  {
  481. -    char c = *nextchar;
  482. -    char *temp = index (optstring, c);
  483. -
  484. -    nextchar++;
  485. -    /* Increment `optind' when we start to process its last character.  */
  486. -    if (*nextchar == 0)
  487. -      optind++;
  488. -
  489. -    if (temp == NULL || c == ':')
  490. -      {
  491. -    if (opterr != 0)
  492. -      {
  493. -        if (c < 040 || c >= 0177)
  494. -          printf ("%s: unrecognized option, character code 0%o\n",
  495. -               argv[0], c);
  496. -        else
  497. -          printf ("%s: unrecognized option `-%c'\n",
  498. -               argv[0], c);
  499. -      }
  500. -    return '?';
  501. -      }
  502. -    if (temp[1] == ':')
  503. -      {
  504. -    if (temp[2] == ':')
  505. -      {
  506. -        /* This is an option that accepts an argument optionally.  */
  507. -        if (*nextchar != 0)
  508. -          {
  509. -        optarg = nextchar;
  510. -        optind++;
  511. -          }
  512. -        else
  513. -          optarg = NULL;
  514. -        nextchar = NULL;
  515. -      }
  516. -    else
  517. -      {
  518. -        /* This is an option that requires an argument.  */
  519. -        if (*nextchar != 0)
  520. -          {
  521. -        optarg = nextchar;
  522. -        /* If we end this ARGV-element by taking the rest as an arg,
  523. -           we must advance to the next element now.  */
  524. -        optind++;
  525. -          }
  526. -        else if (optind == argc)
  527. -          {
  528. -        if (opterr != 0)
  529. -          printf ("%s: option '-%c' requires an argument\n",
  530. -               argv[0], c);
  531. -        c = '?';
  532. -          }
  533. -        else
  534. -          /* We already incremented `optind' once;
  535. -         increment it again when taking next ARGV-elt as argument.  */
  536. -          optarg = argv[optind++];
  537. -        nextchar = NULL;
  538. -      }
  539. -      }
  540. -    return c;
  541. -  }
  542. -}
  543. -
  544. -#ifdef TEST
  545. -
  546. -/* Compile with -DTEST to make an executable for use in testing
  547. -   the above definition of `getopt'.  */
  548. -
  549. -int
  550. -main (argc, argv)
  551. -     int argc;
  552. -     char **argv;
  553. -{
  554. -  int c;
  555. -  int digit_optind = 0;
  556. -
  557. -  while (1)
  558. -    {
  559. -      int this_option_optind = optind ? optind : 1;
  560. -
  561. -      c = getopt (argc, argv, "abc:d:0123456789");
  562. -      if (c == EOF)
  563. -    break;
  564. -
  565. -      switch (c)
  566. -    {
  567. -    case '0':
  568. -    case '1':
  569. -    case '2':
  570. -    case '3':
  571. -    case '4':
  572. -    case '5':
  573. -    case '6':
  574. -    case '7':
  575. -    case '8':
  576. -    case '9':
  577. -      if (digit_optind != 0 && digit_optind != this_option_optind)
  578. -        printf ("digits occur in two different argv-elements.\n");
  579. -      digit_optind = this_option_optind;
  580. -      printf ("option %c\n", c);
  581. -      break;
  582. -
  583. -    case 'a':
  584. -      printf ("option a\n");
  585. -      break;
  586. -
  587. -    case 'b':
  588. -      printf ("option b\n");
  589. -      break;
  590. -
  591. -    case 'c':
  592. -      printf ("option c with value '%s'\n", optarg);
  593. -      break;
  594. -
  595. -    case '?':
  596. -      break;
  597. -
  598. -    default:
  599. -      printf ("?? getopt returned character code 0%o ??\n", c);
  600. -    }
  601. -    }
  602. -
  603. -  if (optind < argc)
  604. -    {
  605. -      printf ("non-option ARGV-elements: ");
  606. -      while (optind < argc)
  607. -    printf ("%s ", argv[optind++]);
  608. -      printf ("\n");
  609. -    }
  610. -
  611. -  exit (0);
  612. -}
  613. -
  614. -#endif /* TEST */
  615. -
  616. =getopt1.c
  617. -/* Getopt for GNU.
  618. -   Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  619. -
  620. -   This program is free software; you can redistribute it and/or modify
  621. -   it under the terms of the GNU General Public License as published by
  622. -   the Free Software Foundation; either version 1, or (at your option)
  623. -   any later version.
  624. -
  625. -   This program is distributed in the hope that it will be useful,
  626. -   but WITHOUT ANY WARRANTY; without even the implied warranty of
  627. -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  628. -   GNU General Public License for more details.
  629. -
  630. -   You should have received a copy of the GNU General Public License
  631. -   along with this program; if not, write to the Free Software
  632. -   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  633. -
  634. -#pragma noroot
  635. -#pragma memorymodel    0
  636. -#pragma optimize    -1
  637. -
  638. -#include <sys/getopt.h>
  639. -
  640. -#ifdef __STDC__
  641. -#define CONST
  642. -#else
  643. -#define CONST
  644. -#endif
  645. -
  646. -#define NULL (void *) 0L
  647. -
  648. -int
  649. -getopt_long (argc, argv, options, long_options, opt_index)
  650. -     int argc;
  651. -     char **argv;
  652. -     CONST char *options;
  653. -     CONST struct option *long_options;
  654. -     int *opt_index;
  655. -{
  656. -  int val;
  657. -
  658. -  _getopt_long_options = long_options;
  659. -  val = getopt (argc, argv, options);
  660. -  if (val == 0 && opt_index != NULL)
  661. -    *opt_index = option_index;
  662. -  return val;
  663. -}
  664. -
  665. -/* Like getopt_long, but '-' as well as '+' can indicate a long option.
  666. -   If an option that starts with '-' doesn't match a long option,
  667. -   but does match a short option, it is parsed as a short option
  668. -   instead. */
  669. -
  670. -int 
  671. -getopt_long_only (argc, argv, options, long_options, opt_index)
  672. -     int argc;
  673. -     char **argv;
  674. -     CONST char *options;
  675. -     CONST struct option *long_options;
  676. -     int *opt_index;
  677. -{
  678. -  int val;
  679. -
  680. -  _getopt_long_options = long_options;
  681. -  _getopt_long_only = 1;
  682. -  val = getopt (argc, argv, options);
  683. -  if (val == 0 && opt_index != NULL)
  684. -    *opt_index = option_index;
  685. -  return val;
  686. -}
  687. -
  688. -
  689. -#ifdef TEST
  690. -
  691. -#include <stdio.h>
  692. -
  693. -int
  694. -main (argc, argv)
  695. -     int argc;
  696. -     char **argv;
  697. -{
  698. -  int c;
  699. -  int digit_optind = 0;
  700. -
  701. -  while (1)
  702. -    {
  703. -      int this_option_optind = optind ? optind : 1;
  704. -      char *name = '\0';
  705. -      int option_index = 0;
  706. -      static struct option long_options[] =
  707. -      {
  708. -    {"add", 1, 0, 0},
  709. -    {"append", 0, 0, 0},
  710. -    {"delete", 1, 0, 0},
  711. -    {"verbose", 0, 0, 0},
  712. -    {"create", 0, 0, 0},
  713. -    {"file", 1, 0, 0},
  714. -    {0, 0, 0, 0}
  715. -      };
  716. -
  717. -      c = getopt_long (argc, argv, "abc:d:0123456789",
  718. -               long_options, &option_index);
  719. -      if (c == EOF)
  720. -    break;
  721. -
  722. -      switch (c)
  723. -    {
  724. -    case 0:
  725. -      printf ("option %s", (long_options[option_index]).name);
  726. -      if (optarg)
  727. -        printf (" with arg %s", optarg);
  728. -      printf ("\n");
  729. -      break;
  730. -
  731. -    case '0':
  732. -    case '1':
  733. -    case '2':
  734. -    case '3':
  735. -    case '4':
  736. -    case '5':
  737. -    case '6':
  738. -    case '7':
  739. -    case '8':
  740. -    case '9':
  741. -      if (digit_optind != 0 && digit_optind != this_option_optind)
  742. -        printf ("digits occur in two different argv-elements.\n");
  743. -      digit_optind = this_option_optind;
  744. -      printf ("option %c\n", c);
  745. -      break;
  746. -
  747. -    case 'a':
  748. -      printf ("option a\n");
  749. -      break;
  750. -
  751. -    case 'b':
  752. -      printf ("option b\n");
  753. -      break;
  754. -
  755. -    case 'c':
  756. -      printf ("option c with value `%s'\n", optarg);
  757. -      break;
  758. -
  759. -    case '?':
  760. -      break;
  761. -
  762. -    default:
  763. -      printf ("?? getopt returned character code 0%o ??\n", c);
  764. -    }
  765. -    }
  766. -
  767. -  if (optind < argc)
  768. -    {
  769. -      printf ("non-option ARGV-elements: ");
  770. -      while (optind < argc)
  771. -    printf ("%s ", argv[optind++]);
  772. -      printf ("\n");
  773. -    }
  774. -
  775. -  exit (0);
  776. -}
  777. -
  778. -#endif /* TEST */
  779. -
  780. =COPYING
  781. -
  782. -
  783. -            GNU GENERAL PUBLIC LICENSE
  784. -             Version 1, February 1989
  785. -
  786. - Copyright (C) 1989 Free Software Foundation, Inc.
  787. -                    675 Mass Ave, Cambridge, MA 02139, USA
  788. - Everyone is permitted to copy and distribute verbatim copies
  789. - of this license document, but changing it is not allowed.
  790. -
  791. -                Preamble
  792. -
  793. -  The license agreements of most software companies try to keep users
  794. -at the mercy of those companies.  By contrast, our General Public
  795. -License is intended to guarantee your freedom to share and change free
  796. -software--to make sure the software is free for all its users.  The
  797. -General Public License applies to the Free Software Foundation's
  798. -software and to any other program whose authors commit to using it.
  799. -You can use it for your programs, too.
  800. -
  801. -  When we speak of free software, we are referring to freedom, not
  802. -price.  Specifically, the General Public License is designed to make
  803. -sure that you have the freedom to give away or sell copies of free
  804. -software, that you receive source code or can get it if you want it,
  805. -that you can change the software or use pieces of it in new free
  806. -programs; and that you know you can do these things.
  807. -
  808. -  To protect your rights, we need to make restrictions that forbid
  809. -anyone to deny you these rights or to ask you to surrender the rights.
  810. -These restrictions translate to certain responsibilities for you if you
  811. -distribute copies of the software, or if you modify it.
  812. -
  813. -  For example, if you distribute copies of a such a program, whether
  814. -gratis or for a fee, you must give the recipients all the rights that
  815. -you have.  You must make sure that they, too, receive or can get the
  816. -source code.  And you must tell them their rights.
  817. -
  818. -  We protect your rights with two steps: (1) copyright the software, and
  819. -(2) offer you this license which gives you legal permission to copy,
  820. -distribute and/or modify the software.
  821. -
  822. -  Also, for each author's protection and ours, we want to make certain
  823. -that everyone understands that there is no warranty for this free
  824. -software.  If the software is modified by someone else and passed on, we
  825. -want its recipients to know that what they have is not the original, so
  826. -that any problems introduced by others will not reflect on the original
  827. -authors' reputations.
  828. -
  829. -  The precise terms and conditions for copying, distribution and
  830. -modification follow.
  831. -
  832. -            GNU GENERAL PUBLIC LICENSE
  833. -   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  834. -
  835. -  0. This License Agreement applies to any program or other work which
  836. -contains a notice placed by the copyright holder saying it may be
  837. -distributed under the terms of this General Public License.  The
  838. -"Program", below, refers to any such program or work, and a "work based
  839. -on the Program" means either the Program or any work containing the
  840. -Program or a portion of it, either verbatim or with modifications.  Each
  841. -licensee is addressed as "you".
  842. -
  843. -  1. You may copy and distribute verbatim copies of the Program's source
  844. -code as you receive it, in any medium, provided that you conspicuously and
  845. -appropriately publish on each copy an appropriate copyright notice and
  846. -disclaimer of warranty; keep intact all the notices that refer to this
  847. -General Public License and to the absence of any warranty; and give any
  848. -other recipients of the Program a copy of this General Public License
  849. -along with the Program.  You may charge a fee for the physical act of
  850. -transferring a copy.
  851. -
  852. -  2. You may modify your copy or copies of the Program or any portion of
  853. -it, and copy and distribute such modifications under the terms of Paragraph
  854. -1 above, provided that you also do the following:
  855. -
  856. -    a) cause the modified files to carry prominent notices stating that
  857. -    you changed the files and the date of any change; and
  858. -
  859. -    b) cause the whole of any work that you distribute or publish, that
  860. -    in whole or in part contains the Program or any part thereof, either
  861. -    with or without modifications, to be licensed at no charge to all
  862. -    third parties under the terms of this General Public License (except
  863. -    that you may choose to grant warranty protection to some or all
  864. -    third parties, at your option).
  865. -
  866. -    c) If the modified program normally reads commands interactively when
  867. -    run, you must cause it, when started running for such interactive use
  868. -    in the simplest and most usual way, to print or display an
  869. -    announcement including an appropriate copyright notice and a notice
  870. -    that there is no warranty (or else, saying that you provide a
  871. -    warranty) and that users may redistribute the program under these
  872. -    conditions, and telling the user how to view a copy of this General
  873. -    Public License.
  874. -
  875. -    d) You may charge a fee for the physical act of transferring a
  876. -    copy, and you may at your option offer warranty protection in
  877. -    exchange for a fee.
  878. -
  879. -Mere aggregation of another independent work with the Program (or its
  880. -derivative) on a volume of a storage or distribution medium does not bring
  881. -the other work under the scope of these terms.
  882. -
  883. -  3. You may copy and distribute the Program (or a portion or derivative of
  884. -it, under Paragraph 2) in object code or executable form under the terms of
  885. -Paragraphs 1 and 2 above provided that you also do one of the following:
  886. -
  887. -    a) accompany it with the complete corresponding machine-readable
  888. -    source code, which must be distributed under the terms of
  889. -    Paragraphs 1 and 2 above; or,
  890. -
  891. -    b) accompany it with a written offer, valid for at least three
  892. -    years, to give any third party free (except for a nominal charge
  893. -    for the cost of distribution) a complete machine-readable copy of the
  894. -    corresponding source code, to be distributed under the terms of
  895. -    Paragraphs 1 and 2 above; or,
  896. -
  897. -    c) accompany it with the information you received as to where the
  898. -    corresponding source code may be obtained.  (This alternative is
  899. -    allowed only for noncommercial distribution and only if you
  900. -    received the program in object code or executable form alone.)
  901. -
  902. -Source code for a work means the preferred form of the work for making
  903. -modifications to it.  For an executable file, complete source code means
  904. -all the source code for all modules it contains; but, as a special
  905. -exception, it need not include source code for modules which are standard
  906. -libraries that accompany the operating system on which the executable
  907. -file runs, or for standard header files or definitions files that
  908. -accompany that operating system.
  909. -
  910. -  4. You may not copy, modify, sublicense, distribute or transfer the
  911. -Program except as expressly provided under this General Public License.
  912. -Any attempt otherwise to copy, modify, sublicense, distribute or transfer
  913. -the Program is void, and will automatically terminate your rights to use
  914. -the Program under this License.  However, parties who have received
  915. -copies, or rights to use copies, from you under this General Public
  916. -License will not have their licenses terminated so long as such parties
  917. -remain in full compliance.
  918. -
  919. -  5. By copying, distributing or modifying the Program (or any work based
  920. -on the Program) you indicate your acceptance of this license to do so,
  921. -and all its terms and conditions.
  922. -
  923. -  6. Each time you redistribute the Program (or any work based on the
  924. -Program), the recipient automatically receives a license from the original
  925. -licensor to copy, distribute or modify the Program subject to these
  926. -terms and conditions.  You may not impose any further restrictions on the
  927. -recipients' exercise of the rights granted herein.
  928. -
  929. -  7. The Free Software Foundation may publish revised and/or new versions
  930. -of the General Public License from time to time.  Such new versions will
  931. -be similar in spirit to the present version, but may differ in detail to
  932. -address new problems or concerns.
  933. -
  934. -Each version is given a distinguishing version number.  If the Program
  935. -specifies a version number of the license which applies to it and "any
  936. -later version", you have the option of following the terms and conditions
  937. -either of that version or of any later version published by the Free
  938. -Software Foundation.  If the Program does not specify a version number of
  939. -the license, you may choose any version ever published by the Free Software
  940. -Foundation.
  941. -
  942. -  8. If you wish to incorporate parts of the Program into other free
  943. -programs whose distribution conditions are different, write to the author
  944. -to ask for permission.  For software which is copyrighted by the Free
  945. -Software Foundation, write to the Free Software Foundation; we sometimes
  946. -make exceptions for this.  Our decision will be guided by the two goals
  947. -of preserving the free status of all derivatives of our free software and
  948. -of promoting the sharing and reuse of software generally.
  949. -
  950. -                NO WARRANTY
  951. -
  952. -  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  953. -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  954. -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  955. -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  956. -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  957. -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  958. -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  959. -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  960. -REPAIR OR CORRECTION.
  961. -
  962. -  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  963. -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  964. -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  965. -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  966. -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  967. -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  968. -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  969. -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  970. -POSSIBILITY OF SUCH DAMAGES.
  971. -
  972. -             END OF TERMS AND CONDITIONS
  973. -
  974. -    Appendix: How to Apply These Terms to Your New Programs
  975. -
  976. -  If you develop a new program, and you want it to be of the greatest
  977. -possible use to humanity, the best way to achieve this is to make it
  978. -free software which everyone can redistribute and change under these
  979. -terms.
  980. -
  981. -  To do so, attach the following notices to the program.  It is safest to
  982. -attach them to the start of each source file to most effectively convey
  983. -the exclusion of warranty; and each file should have at least the
  984. -"copyright" line and a pointer to where the full notice is found.
  985. -
  986. -    <one line to give the program's name and a brief idea of what it does.>
  987. -    Copyright (C) 19yy  <name of author>
  988. -
  989. -    This program is free software; you can redistribute it and/or modify
  990. -    it under the terms of the GNU General Public License as published by
  991. -    the Free Software Foundation; either version 1, or (at your option)
  992. -    any later version.
  993. -
  994. -    This program is distributed in the hope that it will be useful,
  995. -    but WITHOUT ANY WARRANTY; without even the implied warranty of
  996. -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  997. -    GNU General Public License for more details.
  998. -
  999. -    You should have received a copy of the GNU General Public License
  1000. -    along with this program; if not, write to the Free Software
  1001. -    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1002. -
  1003. -Also add information on how to contact you by electronic and paper mail.
  1004. -
  1005. -If the program is interactive, make it output a short notice like this
  1006. -when it starts in an interactive mode:
  1007. -
  1008. -    Gnomovision version 69, Copyright (C) 19xx name of author
  1009. -    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  1010. -    This is free software, and you are welcome to redistribute it
  1011. -    under certain conditions; type `show c' for details.
  1012. -
  1013. -The hypothetical commands `show w' and `show c' should show the
  1014. -appropriate parts of the General Public License.  Of course, the
  1015. -commands you use may be called something other than `show w' and `show
  1016. -c'; they could even be mouse-clicks or menu items--whatever suits your
  1017. -program.
  1018. -
  1019. -You should also get your employer (if you work as a programmer) or your
  1020. -school, if any, to sign a "copyright disclaimer" for the program, if
  1021. -necessary.  Here a sample; alter the names:
  1022. -
  1023. -  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  1024. -  program `Gnomovision' (a program to direct compilers to make passes
  1025. -  at assemblers) written by James Hacker.
  1026. -
  1027. -  <signature of Ty Coon>, 1 April 1989
  1028. -  Ty Coon, President of Vice
  1029. -
  1030. -That's all there is to it!
  1031. -
  1032. -
  1033. + END OF ARCHIVE
  1034.