OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2741 lines
80 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../rrdtool/rrdtool-1.2.19-rrd_getopt.patch
  5. # Copyright (C) 2007 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. renamed getopt to rrd_getopt to avoid confusion on some systems
  17. --- ./src/getopt1.c (Revision 1006)
  18. +++ ./src/getopt1.c (Revision 1007)
  19. @@ -1,189 +0,0 @@
  20. -/* getopt_long and getopt_long_only entry points for GNU getopt.
  21. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
  22. -
  23. - This file is part of the GNU C Library. Its master source is NOT part of
  24. - the C library, however. The master source lives in /gd/gnu/lib.
  25. -
  26. - The GNU C Library is free software; you can redistribute it and/or
  27. - modify it under the terms of the GNU Library General Public License as
  28. - published by the Free Software Foundation; either version 2 of the
  29. - License, or (at your option) any later version.
  30. -
  31. - The GNU C Library is distributed in the hope that it will be useful,
  32. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. - Library General Public License for more details.
  35. -
  36. - You should have received a copy of the GNU Library General Public
  37. - License along with the GNU C Library; see the file COPYING.LIB. If not,
  38. - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  39. - Boston, MA 02111-1307, USA. */
  40. -
  41. -#ifdef HAVE_CONFIG_H
  42. -#include "../rrd_config.h"
  43. -#endif
  44. -
  45. -#include "getopt.h"
  46. -
  47. -#if !defined (__STDC__) || !__STDC__
  48. -/* This is a separate conditional since some stdc systems
  49. - reject `defined (const)'. */
  50. -#ifndef const
  51. -#define const
  52. -#endif
  53. -#endif
  54. -
  55. -#include <stdio.h>
  56. -
  57. -/* Comment out all this code if we are using the GNU C Library, and are not
  58. - actually compiling the library itself. This code is part of the GNU C
  59. - Library, but also included in many other GNU distributions. Compiling
  60. - and linking in this code is a waste when using the GNU C library
  61. - (especially if it is a shared library). Rather than having every GNU
  62. - program understand `configure --with-gnu-libc' and omit the object files,
  63. - it is simpler to just do this in the source for each such file. */
  64. -
  65. -#define GETOPT_INTERFACE_VERSION 2
  66. -#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
  67. -#include <gnu-versions.h>
  68. -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  69. -#define ELIDE_CODE
  70. -#endif
  71. -#endif
  72. -
  73. -#ifndef ELIDE_CODE
  74. -
  75. -
  76. -/* This needs to come after some library #include
  77. - to get __GNU_LIBRARY__ defined. */
  78. -#ifdef __GNU_LIBRARY__
  79. -#include <stdlib.h>
  80. -#endif
  81. -
  82. -#ifndef NULL
  83. -#define NULL 0
  84. -#endif
  85. -
  86. -int
  87. -getopt_long (argc, argv, options, long_options, opt_index)
  88. - int argc;
  89. - char *const *argv;
  90. - const char *options;
  91. - const struct option *long_options;
  92. - int *opt_index;
  93. -{
  94. - return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
  95. -}
  96. -
  97. -/* Like getopt_long, but '-' as well as '--' can indicate a long option.
  98. - If an option that starts with '-' (not '--') doesn't match a long option,
  99. - but does match a short option, it is parsed as a short option
  100. - instead. */
  101. -
  102. -int
  103. -getopt_long_only (argc, argv, options, long_options, opt_index)
  104. - int argc;
  105. - char *const *argv;
  106. - const char *options;
  107. - const struct option *long_options;
  108. - int *opt_index;
  109. -{
  110. - return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
  111. -}
  112. -
  113. -
  114. -#endif /* Not ELIDE_CODE. */
  115. -
  116. -#ifdef TEST
  117. -
  118. -#include <stdio.h>
  119. -
  120. -int
  121. -main (argc, argv)
  122. - int argc;
  123. - char **argv;
  124. -{
  125. - int c;
  126. - int digit_optind = 0;
  127. -
  128. - while (1)
  129. - {
  130. - int this_option_optind = optind ? optind : 1;
  131. - int option_index = 0;
  132. - static struct option long_options[] =
  133. - {
  134. - {"add", 1, 0, 0},
  135. - {"append", 0, 0, 0},
  136. - {"delete", 1, 0, 0},
  137. - {"verbose", 0, 0, 0},
  138. - {"create", 0, 0, 0},
  139. - {"file", 1, 0, 0},
  140. - {0, 0, 0, 0}
  141. - };
  142. -
  143. - c = getopt_long (argc, argv, "abc:d:0123456789",
  144. - long_options, &option_index);
  145. - if (c == -1)
  146. - break;
  147. -
  148. - switch (c)
  149. - {
  150. - case 0:
  151. - printf ("option %s", long_options[option_index].name);
  152. - if (optarg)
  153. - printf (" with arg %s", optarg);
  154. - printf ("\n");
  155. - break;
  156. -
  157. - case '0':
  158. - case '1':
  159. - case '2':
  160. - case '3':
  161. - case '4':
  162. - case '5':
  163. - case '6':
  164. - case '7':
  165. - case '8':
  166. - case '9':
  167. - if (digit_optind != 0 && digit_optind != this_option_optind)
  168. - printf ("digits occur in two different argv-elements.\n");
  169. - digit_optind = this_option_optind;
  170. - printf ("option %c\n", c);
  171. - break;
  172. -
  173. - case 'a':
  174. - printf ("option a\n");
  175. - break;
  176. -
  177. - case 'b':
  178. - printf ("option b\n");
  179. - break;
  180. -
  181. - case 'c':
  182. - printf ("option c with value `%s'\n", optarg);
  183. - break;
  184. -
  185. - case 'd':
  186. - printf ("option d with value `%s'\n", optarg);
  187. - break;
  188. -
  189. - case '?':
  190. - break;
  191. -
  192. - default:
  193. - printf ("?? getopt returned character code 0%o ??\n", c);
  194. - }
  195. - }
  196. -
  197. - if (optind < argc)
  198. - {
  199. - printf ("non-option ARGV-elements: ");
  200. - while (optind < argc)
  201. - printf ("%s ", argv[optind++]);
  202. - printf ("\n");
  203. - }
  204. -
  205. - exit (0);
  206. -}
  207. -
  208. -#endif /* TEST */
  209. --- ./src/getopt.c (Revision 1006)
  210. +++ ./src/getopt.c (Revision 1007)
  211. @@ -1,1002 +0,0 @@
  212. -/* Getopt for GNU.
  213. - NOTE: getopt is now part of the C library, so if you don't know what
  214. - "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
  215. - before changing it!
  216. -
  217. - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
  218. - Free Software Foundation, Inc.
  219. -
  220. - This file is part of the GNU C Library. Its master source is NOT part of
  221. - the C library, however. The master source lives in /gd/gnu/lib.
  222. -
  223. - The GNU C Library is free software; you can redistribute it and/or
  224. - modify it under the terms of the GNU Library General Public License as
  225. - published by the Free Software Foundation; either version 2 of the
  226. - License, or (at your option) any later version.
  227. -
  228. - The GNU C Library is distributed in the hope that it will be useful,
  229. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  230. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  231. - Library General Public License for more details.
  232. -
  233. - You should have received a copy of the GNU Library General Public
  234. - License along with the GNU C Library; see the file COPYING.LIB. If not,
  235. - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  236. - Boston, MA 02111-1307, USA. */
  237. -
  238. -/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
  239. - Ditto for AIX 3.2 and <stdlib.h>. */
  240. -#ifndef _NO_PROTO
  241. -#define _NO_PROTO
  242. -#endif
  243. -
  244. -#ifdef HAVE_CONFIG_H
  245. -#include "../rrd_config.h"
  246. -#endif
  247. -
  248. -#if !defined (__STDC__) || !__STDC__
  249. -/* This is a separate conditional since some stdc systems
  250. - reject `defined (const)'. */
  251. -#ifndef const
  252. -#define const
  253. -#endif
  254. -#endif
  255. -
  256. -#include <stdio.h>
  257. -
  258. -/* Comment out all this code if we are using the GNU C Library, and are not
  259. - actually compiling the library itself. This code is part of the GNU C
  260. - Library, but also included in many other GNU distributions. Compiling
  261. - and linking in this code is a waste when using the GNU C library
  262. - (especially if it is a shared library). Rather than having every GNU
  263. - program understand `configure --with-gnu-libc' and omit the object files,
  264. - it is simpler to just do this in the source for each such file. */
  265. -
  266. -#define GETOPT_INTERFACE_VERSION 2
  267. -#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
  268. -#include <gnu-versions.h>
  269. -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  270. -#define ELIDE_CODE
  271. -#endif
  272. -#endif
  273. -
  274. -#ifndef ELIDE_CODE
  275. -
  276. -
  277. -/* This needs to come after some library #include
  278. - to get __GNU_LIBRARY__ defined. */
  279. -#ifdef __GNU_LIBRARY__
  280. -/* Don't include stdlib.h for non-GNU C libraries because some of them
  281. - contain conflicting prototypes for getopt. */
  282. -#include <stdlib.h>
  283. -#include <unistd.h>
  284. -#endif /* GNU C library. */
  285. -
  286. -#ifdef VMS
  287. -#include <unixlib.h>
  288. -#if HAVE_STRING_H - 0
  289. -#include <string.h>
  290. -#endif
  291. -#endif
  292. -
  293. -#if defined (_WIN32) && !defined (__CYGWIN32__)
  294. -/* It's not Unix, really. See? Capital letters. */
  295. -#include <windows.h>
  296. -#define getpid() GetCurrentProcessId()
  297. -#endif
  298. -
  299. -#ifndef _
  300. -/* This is for other GNU distributions with internationalized messages.
  301. - When compiling libc, the _ macro is predefined. */
  302. -#ifdef HAVE_LIBINTL_H
  303. -# include <libintl.h>
  304. -# define _(msgid) gettext (msgid)
  305. -#else
  306. -# define _(msgid) (msgid)
  307. -#endif
  308. -#endif
  309. -
  310. -/* This version of `getopt' appears to the caller like standard Unix `getopt'
  311. - but it behaves differently for the user, since it allows the user
  312. - to intersperse the options with the other arguments.
  313. -
  314. - As `getopt' works, it permutes the elements of ARGV so that,
  315. - when it is done, all the options precede everything else. Thus
  316. - all application programs are extended to handle flexible argument order.
  317. -
  318. - Setting the environment variable POSIXLY_CORRECT disables permutation.
  319. - Then the behavior is completely standard.
  320. -
  321. - GNU application programs can use a third alternative mode in which
  322. - they can distinguish the relative order of options and other arguments. */
  323. -
  324. -#include "getopt.h"
  325. -
  326. -/* For communication from `getopt' to the caller.
  327. - When `getopt' finds an option that takes an argument,
  328. - the argument value is returned here.
  329. - Also, when `ordering' is RETURN_IN_ORDER,
  330. - each non-option ARGV-element is returned here. */
  331. -
  332. -char *optarg = NULL;
  333. -
  334. -/* Index in ARGV of the next element to be scanned.
  335. - This is used for communication to and from the caller
  336. - and for communication between successive calls to `getopt'.
  337. -
  338. - On entry to `getopt', zero means this is the first call; initialize.
  339. -
  340. - When `getopt' returns -1, this is the index of the first of the
  341. - non-option elements that the caller should itself scan.
  342. -
  343. - Otherwise, `optind' communicates from one call to the next
  344. - how much of ARGV has been scanned so far. */
  345. -
  346. -/* 1003.2 says this must be 1 before any call. */
  347. -int optind = 1;
  348. -
  349. -/* Formerly, initialization of getopt depended on optind==0, which
  350. - causes problems with re-calling getopt as programs generally don't
  351. - know that. */
  352. -
  353. -int __getopt_initialized = 0;
  354. -
  355. -/* The next char to be scanned in the option-element
  356. - in which the last option character we returned was found.
  357. - This allows us to pick up the scan where we left off.
  358. -
  359. - If this is zero, or a null string, it means resume the scan
  360. - by advancing to the next ARGV-element. */
  361. -
  362. -static char *nextchar;
  363. -
  364. -/* Callers store zero here to inhibit the error message
  365. - for unrecognized options. */
  366. -
  367. -int opterr = 1;
  368. -
  369. -/* Set to an option character which was unrecognized.
  370. - This must be initialized on some systems to avoid linking in the
  371. - system's own getopt implementation. */
  372. -
  373. -int optopt = '?';
  374. -
  375. -/* Describe how to deal with options that follow non-option ARGV-elements.
  376. -
  377. - If the caller did not specify anything,
  378. - the default is REQUIRE_ORDER if the environment variable
  379. - POSIXLY_CORRECT is defined, PERMUTE otherwise.
  380. -
  381. - REQUIRE_ORDER means don't recognize them as options;
  382. - stop option processing when the first non-option is seen.
  383. - This is what Unix does.
  384. - This mode of operation is selected by either setting the environment
  385. - variable POSIXLY_CORRECT, or using `+' as the first character
  386. - of the list of option characters.
  387. -
  388. - PERMUTE is the default. We permute the contents of ARGV as we scan,
  389. - so that eventually all the non-options are at the end. This allows options
  390. - to be given in any order, even with programs that were not written to
  391. - expect this.
  392. -
  393. - RETURN_IN_ORDER is an option available to programs that were written
  394. - to expect options and other ARGV-elements in any order and that care about
  395. - the ordering of the two. We describe each non-option ARGV-element
  396. - as if it were the argument of an option with character code 1.
  397. - Using `-' as the first character of the list of option characters
  398. - selects this mode of operation.
  399. -
  400. - The special argument `--' forces an end of option-scanning regardless
  401. - of the value of `ordering'. In the case of RETURN_IN_ORDER, only
  402. - `--' can cause `getopt' to return -1 with `optind' != ARGC. */
  403. -
  404. -static enum
  405. -{
  406. - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
  407. -} ordering;
  408. -
  409. -/* Value of POSIXLY_CORRECT environment variable. */
  410. -static char *posixly_correct;
  411. -
  412. -/* we must include string as there are warnings without it ... */
  413. -#include <string.h>
  414. -
  415. -#ifdef __GNU_LIBRARY__
  416. -/* We want to avoid inclusion of string.h with non-GNU libraries
  417. - because there are many ways it can cause trouble.
  418. - On some systems, it contains special magic macros that don't work
  419. - in GCC. */
  420. -#define my_index strchr
  421. -#else
  422. -
  423. -/* Avoid depending on library functions or files
  424. - whose names are inconsistent. */
  425. -
  426. -char *getenv ();
  427. -
  428. -static char *
  429. -my_index (str, chr)
  430. - const char *str;
  431. - int chr;
  432. -{
  433. - while (*str)
  434. - {
  435. - if (*str == chr)
  436. - return (char *) str;
  437. - str++;
  438. - }
  439. - return 0;
  440. -}
  441. -
  442. -/* If using GCC, we can safely declare strlen this way.
  443. - If not using GCC, it is ok not to declare it. */
  444. -#ifdef __GNUC__
  445. -/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
  446. - That was relevant to code that was here before. */
  447. -#if !defined (__STDC__) || !__STDC__
  448. -/* gcc with -traditional declares the built-in strlen to return int,
  449. - and has done so at least since version 2.4.5. -- rms. */
  450. -extern int strlen (const char *);
  451. -#endif /* not __STDC__ */
  452. -#endif /* __GNUC__ */
  453. -
  454. -#endif /* not __GNU_LIBRARY__ */
  455. -
  456. -/* Handle permutation of arguments. */
  457. -
  458. -/* Describe the part of ARGV that contains non-options that have
  459. - been skipped. `first_nonopt' is the index in ARGV of the first of them;
  460. - `last_nonopt' is the index after the last of them. */
  461. -
  462. -static int first_nonopt;
  463. -static int last_nonopt;
  464. -
  465. -#ifdef _LIBC
  466. -/* Bash 2.0 gives us an environment variable containing flags
  467. - indicating ARGV elements that should not be considered arguments. */
  468. -
  469. -static const char *nonoption_flags;
  470. -static int nonoption_flags_len;
  471. -
  472. -static int original_argc;
  473. -static char *const *original_argv;
  474. -
  475. -/* Make sure the environment variable bash 2.0 puts in the environment
  476. - is valid for the getopt call we must make sure that the ARGV passed
  477. - to getopt is that one passed to the process. */
  478. -static void store_args (int argc, char *const *argv) __attribute__ ((unused));
  479. -static void
  480. -store_args (int argc, char *const *argv)
  481. -{
  482. - /* XXX This is no good solution. We should rather copy the args so
  483. - that we can compare them later. But we must not use malloc(3). */
  484. - original_argc = argc;
  485. - original_argv = argv;
  486. -}
  487. -text_set_element (__libc_subinit, store_args);
  488. -#endif
  489. -
  490. -/* Exchange two adjacent subsequences of ARGV.
  491. - One subsequence is elements [first_nonopt,last_nonopt)
  492. - which contains all the non-options that have been skipped so far.
  493. - The other is elements [last_nonopt,optind), which contains all
  494. - the options processed since those non-options were skipped.
  495. -
  496. - `first_nonopt' and `last_nonopt' are relocated so that they describe
  497. - the new indices of the non-options in ARGV after they are moved. */
  498. -
  499. -#if defined (__STDC__) && __STDC__
  500. -static void exchange (char **);
  501. -#endif
  502. -
  503. -static void
  504. -exchange (argv)
  505. - char **argv;
  506. -{
  507. - int bottom = first_nonopt;
  508. - int middle = last_nonopt;
  509. - int top = optind;
  510. - char *tem;
  511. -
  512. - /* Exchange the shorter segment with the far end of the longer segment.
  513. - That puts the shorter segment into the right place.
  514. - It leaves the longer segment in the right place overall,
  515. - but it consists of two parts that need to be swapped next. */
  516. -
  517. - while (top > middle && middle > bottom)
  518. - {
  519. - if (top - middle > middle - bottom)
  520. - {
  521. - /* Bottom segment is the short one. */
  522. - int len = middle - bottom;
  523. - register int i;
  524. -
  525. - /* Swap it with the top part of the top segment. */
  526. - for (i = 0; i < len; i++)
  527. - {
  528. - tem = argv[bottom + i];
  529. - argv[bottom + i] = argv[top - (middle - bottom) + i];
  530. - argv[top - (middle - bottom) + i] = tem;
  531. - }
  532. - /* Exclude the moved bottom segment from further swapping. */
  533. - top -= len;
  534. - }
  535. - else
  536. - {
  537. - /* Top segment is the short one. */
  538. - int len = top - middle;
  539. - register int i;
  540. -
  541. - /* Swap it with the bottom part of the bottom segment. */
  542. - for (i = 0; i < len; i++)
  543. - {
  544. - tem = argv[bottom + i];
  545. - argv[bottom + i] = argv[middle + i];
  546. - argv[middle + i] = tem;
  547. - }
  548. - /* Exclude the moved top segment from further swapping. */
  549. - bottom += len;
  550. - }
  551. - }
  552. -
  553. - /* Update records for the slots the non-options now occupy. */
  554. -
  555. - first_nonopt += (optind - last_nonopt);
  556. - last_nonopt = optind;
  557. -}
  558. -
  559. -/* Initialize the internal data when the first call is made. */
  560. -
  561. -#if defined (__STDC__) && __STDC__
  562. -static const char *_getopt_initialize (int, char *const *, const char *);
  563. -#endif
  564. -static const char *
  565. -_getopt_initialize (argc, argv, optstring)
  566. - int argc;
  567. - char *const *argv;
  568. - const char *optstring;
  569. -{
  570. - /* Start processing options with ARGV-element 1 (since ARGV-element 0
  571. - is the program name); the sequence of previously skipped
  572. - non-option ARGV-elements is empty. */
  573. -
  574. - first_nonopt = last_nonopt = optind = 1;
  575. -
  576. - nextchar = NULL;
  577. -
  578. - posixly_correct = getenv ("POSIXLY_CORRECT");
  579. -
  580. - /* Determine how to handle the ordering of options and nonoptions. */
  581. -
  582. - if (optstring[0] == '-')
  583. - {
  584. - ordering = RETURN_IN_ORDER;
  585. - ++optstring;
  586. - }
  587. - else if (optstring[0] == '+')
  588. - {
  589. - ordering = REQUIRE_ORDER;
  590. - ++optstring;
  591. - }
  592. - else if (posixly_correct != NULL)
  593. - ordering = REQUIRE_ORDER;
  594. - else
  595. - ordering = PERMUTE;
  596. -
  597. -#ifdef _LIBC
  598. - if (posixly_correct == NULL
  599. - && argc == original_argc && argv == original_argv)
  600. - {
  601. - /* Bash 2.0 puts a special variable in the environment for each
  602. - command it runs, specifying which ARGV elements are the results of
  603. - file name wildcard expansion and therefore should not be
  604. - considered as options. */
  605. - char var[100];
  606. - sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ());
  607. - nonoption_flags = getenv (var);
  608. - if (nonoption_flags == NULL)
  609. - nonoption_flags_len = 0;
  610. - else
  611. - nonoption_flags_len = strlen (nonoption_flags);
  612. - }
  613. - else
  614. - nonoption_flags_len = 0;
  615. -#endif
  616. -
  617. - return optstring;
  618. -}
  619. -
  620. -/* Scan elements of ARGV (whose length is ARGC) for option characters
  621. - given in OPTSTRING.
  622. -
  623. - If an element of ARGV starts with '-', and is not exactly "-" or "--",
  624. - then it is an option element. The characters of this element
  625. - (aside from the initial '-') are option characters. If `getopt'
  626. - is called repeatedly, it returns successively each of the option characters
  627. - from each of the option elements.
  628. -
  629. - If `getopt' finds another option character, it returns that character,
  630. - updating `optind' and `nextchar' so that the next call to `getopt' can
  631. - resume the scan with the following option character or ARGV-element.
  632. -
  633. - If there are no more option characters, `getopt' returns -1.
  634. - Then `optind' is the index in ARGV of the first ARGV-element
  635. - that is not an option. (The ARGV-elements have been permuted
  636. - so that those that are not options now come last.)
  637. -
  638. - OPTSTRING is a string containing the legitimate option characters.
  639. - If an option character is seen that is not listed in OPTSTRING,
  640. - return '?' after printing an error message. If you set `opterr' to
  641. - zero, the error message is suppressed but we still return '?'.
  642. -
  643. - If a char in OPTSTRING is followed by a colon, that means it wants an arg,
  644. - so the following text in the same ARGV-element, or the text of the following
  645. - ARGV-element, is returned in `optarg'. Two colons mean an option that
  646. - wants an optional arg; if there is text in the current ARGV-element,
  647. - it is returned in `optarg', otherwise `optarg' is set to zero.
  648. -
  649. - If OPTSTRING starts with `-' or `+', it requests different methods of
  650. - handling the non-option ARGV-elements.
  651. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
  652. -
  653. - Long-named options begin with `--' instead of `-'.
  654. - Their names may be abbreviated as long as the abbreviation is unique
  655. - or is an exact match for some defined option. If they have an
  656. - argument, it follows the option name in the same ARGV-element, separated
  657. - from the option name by a `=', or else the in next ARGV-element.
  658. - When `getopt' finds a long-named option, it returns 0 if that option's
  659. - `flag' field is nonzero, the value of the option's `val' field
  660. - if the `flag' field is zero.
  661. -
  662. - The elements of ARGV aren't really const, because we permute them.
  663. - But we pretend they're const in the prototype to be compatible
  664. - with other systems.
  665. -
  666. - LONGOPTS is a vector of `struct option' terminated by an
  667. - element containing a name which is zero.
  668. -
  669. - LONGIND returns the index in LONGOPT of the long-named option found.
  670. - It is only valid when a long-named option has been found by the most
  671. - recent call.
  672. -
  673. - If LONG_ONLY is nonzero, '-' as well as '--' can introduce
  674. - long-named options. */
  675. -
  676. -int
  677. -_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
  678. - int argc;
  679. - char *const *argv;
  680. - const char *optstring;
  681. - const struct option *longopts;
  682. - int *longind;
  683. - int long_only;
  684. -{
  685. - optarg = NULL;
  686. -
  687. - if (!__getopt_initialized || optind == 0)
  688. - {
  689. - optstring = _getopt_initialize (argc, argv, optstring);
  690. - optind = 1; /* Don't scan ARGV[0], the program name. */
  691. - __getopt_initialized = 1;
  692. - }
  693. -
  694. - /* Test whether ARGV[optind] points to a non-option argument.
  695. - Either it does not have option syntax, or there is an environment flag
  696. - from the shell indicating it is not an option. The later information
  697. - is only used when the used in the GNU libc. */
  698. -#ifdef _LIBC
  699. -#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
  700. - || (optind < nonoption_flags_len \
  701. - && nonoption_flags[optind] == '1'))
  702. -#else
  703. -#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
  704. -#endif
  705. -
  706. - if (nextchar == NULL || *nextchar == '\0')
  707. - {
  708. - /* Advance to the next ARGV-element. */
  709. -
  710. - /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
  711. - moved back by the user (who may also have changed the arguments). */
  712. - if (last_nonopt > optind)
  713. - last_nonopt = optind;
  714. - if (first_nonopt > optind)
  715. - first_nonopt = optind;
  716. -
  717. - if (ordering == PERMUTE)
  718. - {
  719. - /* If we have just processed some options following some non-options,
  720. - exchange them so that the options come first. */
  721. -
  722. - if (first_nonopt != last_nonopt && last_nonopt != optind)
  723. - exchange ((char **) argv);
  724. - else if (last_nonopt != optind)
  725. - first_nonopt = optind;
  726. -
  727. - /* Skip any additional non-options
  728. - and extend the range of non-options previously skipped. */
  729. -
  730. - while (optind < argc && NONOPTION_P)
  731. - optind++;
  732. - last_nonopt = optind;
  733. - }
  734. -
  735. - /* The special ARGV-element `--' means premature end of options.
  736. - Skip it like a null option,
  737. - then exchange with previous non-options as if it were an option,
  738. - then skip everything else like a non-option. */
  739. -
  740. - if (optind != argc && !strcmp (argv[optind], "--"))
  741. - {
  742. - optind++;
  743. -
  744. - if (first_nonopt != last_nonopt && last_nonopt != optind)
  745. - exchange ((char **) argv);
  746. - else if (first_nonopt == last_nonopt)
  747. - first_nonopt = optind;
  748. - last_nonopt = argc;
  749. -
  750. - optind = argc;
  751. - }
  752. -
  753. - /* If we have done all the ARGV-elements, stop the scan
  754. - and back over any non-options that we skipped and permuted. */
  755. -
  756. - if (optind == argc)
  757. - {
  758. - /* Set the next-arg-index to point at the non-options
  759. - that we previously skipped, so the caller will digest them. */
  760. - if (first_nonopt != last_nonopt)
  761. - optind = first_nonopt;
  762. - return -1;
  763. - }
  764. -
  765. - /* If we have come to a non-option and did not permute it,
  766. - either stop the scan or describe it to the caller and pass it by. */
  767. -
  768. - if (NONOPTION_P)
  769. - {
  770. - if (ordering == REQUIRE_ORDER)
  771. - return -1;
  772. - optarg = argv[optind++];
  773. - return 1;
  774. - }
  775. -
  776. - /* We have found another option-ARGV-element.
  777. - Skip the initial punctuation. */
  778. -
  779. - nextchar = (argv[optind] + 1
  780. - + (longopts != NULL && argv[optind][1] == '-'));
  781. - }
  782. -
  783. - /* Decode the current option-ARGV-element. */
  784. -
  785. - /* Check whether the ARGV-element is a long option.
  786. -
  787. - If long_only and the ARGV-element has the form "-f", where f is
  788. - a valid short option, don't consider it an abbreviated form of
  789. - a long option that starts with f. Otherwise there would be no
  790. - way to give the -f short option.
  791. -
  792. - On the other hand, if there's a long option "fubar" and
  793. - the ARGV-element is "-fu", do consider that an abbreviation of
  794. - the long option, just like "--fu", and not "-f" with arg "u".
  795. -
  796. - This distinction seems to be the most useful approach. */
  797. -
  798. - if (longopts != NULL
  799. - && (argv[optind][1] == '-'
  800. - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
  801. - {
  802. - char *nameend;
  803. - const struct option *p;
  804. - const struct option *pfound = NULL;
  805. - int exact = 0;
  806. - int ambig = 0;
  807. - int indfound = -1;
  808. - int option_index;
  809. -
  810. - for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
  811. - /* Do nothing. */ ;
  812. -
  813. - /* Test all long options for either exact match
  814. - or abbreviated matches. */
  815. - for (p = longopts, option_index = 0; p->name; p++, option_index++)
  816. - if (!strncmp (p->name, nextchar, nameend - nextchar))
  817. - {
  818. - if ((unsigned int) (nameend - nextchar)
  819. - == (unsigned int) strlen (p->name))
  820. - {
  821. - /* Exact match found. */
  822. - pfound = p;
  823. - indfound = option_index;
  824. - exact = 1;
  825. - break;
  826. - }
  827. - else if (pfound == NULL)
  828. - {
  829. - /* First nonexact match found. */
  830. - pfound = p;
  831. - indfound = option_index;
  832. - }
  833. - else
  834. - /* Second or later nonexact match found. */
  835. - ambig = 1;
  836. - }
  837. -
  838. - if (ambig && !exact)
  839. - {
  840. - if (opterr)
  841. - fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
  842. - argv[0], argv[optind]);
  843. - nextchar += strlen (nextchar);
  844. - optind++;
  845. - optopt = 0;
  846. - return '?';
  847. - }
  848. -
  849. - if (pfound != NULL)
  850. - {
  851. - option_index = indfound;
  852. - optind++;
  853. - if (*nameend)
  854. - {
  855. - /* Don't test has_arg with >, because some C compilers don't
  856. - allow it to be used on enums. */
  857. - if (pfound->has_arg)
  858. - optarg = nameend + 1;
  859. - else
  860. - {
  861. - if (opterr) {
  862. - if (argv[optind - 1][1] == '-')
  863. - /* --option */
  864. - fprintf (stderr,
  865. - _("%s: option `--%s' doesn't allow an argument\n"),
  866. - argv[0], pfound->name);
  867. - else
  868. - /* +option or -option */
  869. - fprintf (stderr,
  870. - _("%s: option `%c%s' doesn't allow an argument\n"),
  871. - argv[0], argv[optind - 1][0], pfound->name);
  872. - }
  873. - nextchar += strlen (nextchar);
  874. -
  875. - optopt = pfound->val;
  876. - return '?';
  877. - }
  878. - }
  879. - else if (pfound->has_arg == 1)
  880. - {
  881. - if (optind < argc)
  882. - optarg = argv[optind++];
  883. - else
  884. - {
  885. - if (opterr)
  886. - fprintf (stderr,
  887. - _("%s: option `%s' requires an argument\n"),
  888. - argv[0], argv[optind - 1]);
  889. - nextchar += strlen (nextchar);
  890. - optopt = pfound->val;
  891. - return optstring[0] == ':' ? ':' : '?';
  892. - }
  893. - }
  894. - nextchar += strlen (nextchar);
  895. - if (longind != NULL)
  896. - *longind = option_index;
  897. - if (pfound->flag)
  898. - {
  899. - *(pfound->flag) = pfound->val;
  900. - return 0;
  901. - }
  902. - return pfound->val;
  903. - }
  904. -
  905. - /* Can't find it as a long option. If this is not getopt_long_only,
  906. - or the option starts with '--' or is not a valid short
  907. - option, then it's an error.
  908. - Otherwise interpret it as a short option. */
  909. - if (!long_only || argv[optind][1] == '-'
  910. - || my_index (optstring, *nextchar) == NULL)
  911. - {
  912. - if (opterr)
  913. - {
  914. - if (argv[optind][1] == '-')
  915. - /* --option */
  916. - fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
  917. - argv[0], nextchar);
  918. - else
  919. - /* +option or -option */
  920. - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
  921. - argv[0], argv[optind][0], nextchar);
  922. - }
  923. - nextchar = (char *) "";
  924. - optind++;
  925. - optopt = 0;
  926. - return '?';
  927. - }
  928. - }
  929. -
  930. - /* Look at and handle the next short option-character. */
  931. -
  932. - {
  933. - char c = *nextchar++;
  934. - char *temp = my_index (optstring, c);
  935. -
  936. - /* Increment `optind' when we start to process its last character. */
  937. - if (*nextchar == '\0')
  938. - ++optind;
  939. -
  940. - if (temp == NULL || c == ':')
  941. - {
  942. - if (opterr)
  943. - {
  944. - if (posixly_correct)
  945. - /* 1003.2 specifies the format of this message. */
  946. - fprintf (stderr, _("%s: illegal option -- %c\n"),
  947. - argv[0], c);
  948. - else
  949. - fprintf (stderr, _("%s: invalid option -- %c\n"),
  950. - argv[0], c);
  951. - }
  952. - optopt = c;
  953. - return '?';
  954. - }
  955. - /* Convenience. Treat POSIX -W foo same as long option --foo */
  956. - if (temp[0] == 'W' && temp[1] == ';')
  957. - {
  958. - char *nameend;
  959. - const struct option *p;
  960. - const struct option *pfound = NULL;
  961. - int exact = 0;
  962. - int ambig = 0;
  963. - int indfound = 0;
  964. - int option_index;
  965. -
  966. - /* This is an option that requires an argument. */
  967. - if (*nextchar != '\0')
  968. - {
  969. - optarg = nextchar;
  970. - /* If we end this ARGV-element by taking the rest as an arg,
  971. - we must advance to the next element now. */
  972. - optind++;
  973. - }
  974. - else if (optind == argc)
  975. - {
  976. - if (opterr)
  977. - {
  978. - /* 1003.2 specifies the format of this message. */
  979. - fprintf (stderr, _("%s: option requires an argument -- %c\n"),
  980. - argv[0], c);
  981. - }
  982. - optopt = c;
  983. - if (optstring[0] == ':')
  984. - c = ':';
  985. - else
  986. - c = '?';
  987. - return c;
  988. - }
  989. - else
  990. - /* We already incremented `optind' once;
  991. - increment it again when taking next ARGV-elt as argument. */
  992. - optarg = argv[optind++];
  993. -
  994. - /* optarg is now the argument, see if it's in the
  995. - table of longopts. */
  996. -
  997. - for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
  998. - /* Do nothing. */ ;
  999. -
  1000. - /* Test all long options for either exact match
  1001. - or abbreviated matches. */
  1002. - for (p = longopts, option_index = 0; p->name; p++, option_index++)
  1003. - if (!strncmp (p->name, nextchar, nameend - nextchar))
  1004. - {
  1005. - if ((unsigned int) (nameend - nextchar) == strlen (p->name))
  1006. - {
  1007. - /* Exact match found. */
  1008. - pfound = p;
  1009. - indfound = option_index;
  1010. - exact = 1;
  1011. - break;
  1012. - }
  1013. - else if (pfound == NULL)
  1014. - {
  1015. - /* First nonexact match found. */
  1016. - pfound = p;
  1017. - indfound = option_index;
  1018. - }
  1019. - else
  1020. - /* Second or later nonexact match found. */
  1021. - ambig = 1;
  1022. - }
  1023. - if (ambig && !exact)
  1024. - {
  1025. - if (opterr)
  1026. - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
  1027. - argv[0], argv[optind]);
  1028. - nextchar += strlen (nextchar);
  1029. - optind++;
  1030. - return '?';
  1031. - }
  1032. - if (pfound != NULL)
  1033. - {
  1034. - option_index = indfound;
  1035. - if (*nameend)
  1036. - {
  1037. - /* Don't test has_arg with >, because some C compilers don't
  1038. - allow it to be used on enums. */
  1039. - if (pfound->has_arg)
  1040. - optarg = nameend + 1;
  1041. - else
  1042. - {
  1043. - if (opterr)
  1044. - fprintf (stderr, _("\
  1045. -%s: option `-W %s' doesn't allow an argument\n"),
  1046. - argv[0], pfound->name);
  1047. -
  1048. - nextchar += strlen (nextchar);
  1049. - return '?';
  1050. - }
  1051. - }
  1052. - else if (pfound->has_arg == 1)
  1053. - {
  1054. - if (optind < argc)
  1055. - optarg = argv[optind++];
  1056. - else
  1057. - {
  1058. - if (opterr)
  1059. - fprintf (stderr,
  1060. - _("%s: option `%s' requires an argument\n"),
  1061. - argv[0], argv[optind - 1]);
  1062. - nextchar += strlen (nextchar);
  1063. - return optstring[0] == ':' ? ':' : '?';
  1064. - }
  1065. - }
  1066. - nextchar += strlen (nextchar);
  1067. - if (longind != NULL)
  1068. - *longind = option_index;
  1069. - if (pfound->flag)
  1070. - {
  1071. - *(pfound->flag) = pfound->val;
  1072. - return 0;
  1073. - }
  1074. - return pfound->val;
  1075. - }
  1076. - nextchar = NULL;
  1077. - return 'W'; /* Let the application handle it. */
  1078. - }
  1079. - if (temp[1] == ':')
  1080. - {
  1081. - if (temp[2] == ':')
  1082. - {
  1083. - /* This is an option that accepts an argument optionally. */
  1084. - if (*nextchar != '\0')
  1085. - {
  1086. - optarg = nextchar;
  1087. - optind++;
  1088. - }
  1089. - else
  1090. - optarg = NULL;
  1091. - nextchar = NULL;
  1092. - }
  1093. - else
  1094. - {
  1095. - /* This is an option that requires an argument. */
  1096. - if (*nextchar != '\0')
  1097. - {
  1098. - optarg = nextchar;
  1099. - /* If we end this ARGV-element by taking the rest as an arg,
  1100. - we must advance to the next element now. */
  1101. - optind++;
  1102. - }
  1103. - else if (optind == argc)
  1104. - {
  1105. - if (opterr)
  1106. - {
  1107. - /* 1003.2 specifies the format of this message. */
  1108. - fprintf (stderr,
  1109. - _("%s: option requires an argument -- %c\n"),
  1110. - argv[0], c);
  1111. - }
  1112. - optopt = c;
  1113. - if (optstring[0] == ':')
  1114. - c = ':';
  1115. - else
  1116. - c = '?';
  1117. - }
  1118. - else
  1119. - /* We already incremented `optind' once;
  1120. - increment it again when taking next ARGV-elt as argument. */
  1121. - optarg = argv[optind++];
  1122. - nextchar = NULL;
  1123. - }
  1124. - }
  1125. - return c;
  1126. - }
  1127. -}
  1128. -
  1129. -int
  1130. -getopt (argc, argv, optstring)
  1131. - int argc;
  1132. - char *const *argv;
  1133. - const char *optstring;
  1134. -{
  1135. - return _getopt_internal (argc, argv, optstring,
  1136. - (const struct option *) 0,
  1137. - (int *) 0,
  1138. - 0);
  1139. -}
  1140. -
  1141. -#endif /* Not ELIDE_CODE. */
  1142. -
  1143. -#ifdef TEST
  1144. -
  1145. -/* Compile with -DTEST to make an executable for use in testing
  1146. - the above definition of `getopt'. */
  1147. -
  1148. -int
  1149. -main (argc, argv)
  1150. - int argc;
  1151. - char **argv;
  1152. -{
  1153. - int c;
  1154. - int digit_optind = 0;
  1155. -
  1156. - while (1)
  1157. - {
  1158. - int this_option_optind = optind ? optind : 1;
  1159. -
  1160. - c = getopt (argc, argv, "abc:d:0123456789");
  1161. - if (c == -1)
  1162. - break;
  1163. -
  1164. - switch (c)
  1165. - {
  1166. - case '0':
  1167. - case '1':
  1168. - case '2':
  1169. - case '3':
  1170. - case '4':
  1171. - case '5':
  1172. - case '6':
  1173. - case '7':
  1174. - case '8':
  1175. - case '9':
  1176. - if (digit_optind != 0 && digit_optind != this_option_optind)
  1177. - printf ("digits occur in two different argv-elements.\n");
  1178. - digit_optind = this_option_optind;
  1179. - printf ("option %c\n", c);
  1180. - break;
  1181. -
  1182. - case 'a':
  1183. - printf ("option a\n");
  1184. - break;
  1185. -
  1186. - case 'b':
  1187. - printf ("option b\n");
  1188. - break;
  1189. -
  1190. - case 'c':
  1191. - printf ("option c with value `%s'\n", optarg);
  1192. - break;
  1193. -
  1194. - case '?':
  1195. - break;
  1196. -
  1197. - default:
  1198. - printf ("?? getopt returned character code 0%o ??\n", c);
  1199. - }
  1200. - }
  1201. -
  1202. - if (optind < argc)
  1203. - {
  1204. - printf ("non-option ARGV-elements: ");
  1205. - while (optind < argc)
  1206. - printf ("%s ", argv[optind++]);
  1207. - printf ("\n");
  1208. - }
  1209. -
  1210. - exit (0);
  1211. -}
  1212. -
  1213. -#endif /* TEST */
  1214. --- ./src/getopt.h (Revision 1006)
  1215. +++ ./src/getopt.h (Revision 1007)
  1216. @@ -1,133 +0,0 @@
  1217. -/* Declarations for getopt.
  1218. - Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
  1219. -
  1220. - This file is part of the GNU C Library. Its master source is NOT part of
  1221. - the C library, however. The master source lives in /gd/gnu/lib.
  1222. -
  1223. - The GNU C Library is free software; you can redistribute it and/or
  1224. - modify it under the terms of the GNU Library General Public License as
  1225. - published by the Free Software Foundation; either version 2 of the
  1226. - License, or (at your option) any later version.
  1227. -
  1228. - The GNU C Library is distributed in the hope that it will be useful,
  1229. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  1230. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1231. - Library General Public License for more details.
  1232. -
  1233. - You should have received a copy of the GNU Library General Public
  1234. - License along with the GNU C Library; see the file COPYING.LIB. If not,
  1235. - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  1236. - Boston, MA 02111-1307, USA. */
  1237. -
  1238. -#ifndef _GETOPT_H
  1239. -#define _GETOPT_H 1
  1240. -
  1241. -#ifdef __cplusplus
  1242. -extern "C" {
  1243. -#endif
  1244. -
  1245. -/* For communication from `getopt' to the caller.
  1246. - When `getopt' finds an option that takes an argument,
  1247. - the argument value is returned here.
  1248. - Also, when `ordering' is RETURN_IN_ORDER,
  1249. - each non-option ARGV-element is returned here. */
  1250. -
  1251. -extern char *optarg;
  1252. -
  1253. -/* Index in ARGV of the next element to be scanned.
  1254. - This is used for communication to and from the caller
  1255. - and for communication between successive calls to `getopt'.
  1256. -
  1257. - On entry to `getopt', zero means this is the first call; initialize.
  1258. -
  1259. - When `getopt' returns -1, this is the index of the first of the
  1260. - non-option elements that the caller should itself scan.
  1261. -
  1262. - Otherwise, `optind' communicates from one call to the next
  1263. - how much of ARGV has been scanned so far. */
  1264. -
  1265. -extern int optind;
  1266. -
  1267. -/* Callers store zero here to inhibit the error message `getopt' prints
  1268. - for unrecognized options. */
  1269. -
  1270. -extern int opterr;
  1271. -
  1272. -/* Set to an option character which was unrecognized. */
  1273. -
  1274. -extern int optopt;
  1275. -
  1276. -/* Describe the long-named options requested by the application.
  1277. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  1278. - of `struct option' terminated by an element containing a name which is
  1279. - zero.
  1280. -
  1281. - The field `has_arg' is:
  1282. - no_argument (or 0) if the option does not take an argument,
  1283. - required_argument (or 1) if the option requires an argument,
  1284. - optional_argument (or 2) if the option takes an optional argument.
  1285. -
  1286. - If the field `flag' is not NULL, it points to a variable that is set
  1287. - to the value given in the field `val' when the option is found, but
  1288. - left unchanged if the option is not found.
  1289. -
  1290. - To have a long-named option do something other than set an `int' to
  1291. - a compiled-in constant, such as set a value from `optarg', set the
  1292. - option's `flag' field to zero and its `val' field to a nonzero
  1293. - value (the equivalent single-letter option character, if there is
  1294. - one). For long options that have a zero `flag' field, `getopt'
  1295. - returns the contents of the `val' field. */
  1296. -
  1297. -struct option
  1298. -{
  1299. -#if defined (__STDC__) && __STDC__
  1300. - const char *name;
  1301. -#else
  1302. - char *name;
  1303. -#endif
  1304. - /* has_arg can't be an enum because some compilers complain about
  1305. - type mismatches in all the code that assumes it is an int. */
  1306. - int has_arg;
  1307. - int *flag;
  1308. - int val;
  1309. -};
  1310. -
  1311. -/* Names for the values of the `has_arg' field of `struct option'. */
  1312. -
  1313. -#define no_argument 0
  1314. -#define required_argument 1
  1315. -#define optional_argument 2
  1316. -
  1317. -#if defined (__STDC__) && __STDC__
  1318. -#ifdef __GNU_LIBRARY__
  1319. -/* Many other libraries have conflicting prototypes for getopt, with
  1320. - differences in the consts, in stdlib.h. To avoid compilation
  1321. - errors, only prototype getopt for the GNU C library. */
  1322. -extern int getopt (int argc, char *const *argv, const char *shortopts);
  1323. -#else /* not __GNU_LIBRARY__ */
  1324. -extern int getopt ();
  1325. -#endif /* __GNU_LIBRARY__ */
  1326. -extern int getopt_long (int argc, char *const *argv, const char *shortopts,
  1327. - const struct option *longopts, int *longind);
  1328. -extern int getopt_long_only (int argc, char *const *argv,
  1329. - const char *shortopts,
  1330. - const struct option *longopts, int *longind);
  1331. -
  1332. -/* Internal only. Users should not call this directly. */
  1333. -extern int _getopt_internal (int argc, char *const *argv,
  1334. - const char *shortopts,
  1335. - const struct option *longopts, int *longind,
  1336. - int long_only);
  1337. -#else /* not __STDC__ */
  1338. -extern int getopt ();
  1339. -extern int getopt_long ();
  1340. -extern int getopt_long_only ();
  1341. -
  1342. -extern int _getopt_internal ();
  1343. -#endif /* __STDC__ */
  1344. -
  1345. -#ifdef __cplusplus
  1346. -}
  1347. -#endif
  1348. -
  1349. -#endif /* _GETOPT_H */
  1350. --- ./src/rrd_getopt.c (Revision 0)
  1351. +++ ./src/rrd_getopt.c (Revision 1007)
  1352. @@ -0,0 +1,1002 @@
  1353. +/* Getopt for GNU.
  1354. + NOTE: getopt is now part of the C library, so if you don't know what
  1355. + "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu
  1356. + before changing it!
  1357. +
  1358. + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97
  1359. + Free Software Foundation, Inc.
  1360. +
  1361. + This file is part of the GNU C Library. Its master source is NOT part of
  1362. + the C library, however. The master source lives in /gd/gnu/lib.
  1363. +
  1364. + The GNU C Library is free software; you can redistribute it and/or
  1365. + modify it under the terms of the GNU Library General Public License as
  1366. + published by the Free Software Foundation; either version 2 of the
  1367. + License, or (at your option) any later version.
  1368. +
  1369. + The GNU C Library is distributed in the hope that it will be useful,
  1370. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1371. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1372. + Library General Public License for more details.
  1373. +
  1374. + You should have received a copy of the GNU Library General Public
  1375. + License along with the GNU C Library; see the file COPYING.LIB. If not,
  1376. + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  1377. + Boston, MA 02111-1307, USA. */
  1378. +
  1379. +/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
  1380. + Ditto for AIX 3.2 and <stdlib.h>. */
  1381. +#ifndef _NO_PROTO
  1382. +#define _NO_PROTO
  1383. +#endif
  1384. +
  1385. +#ifdef HAVE_CONFIG_H
  1386. +#include "../rrd_config.h"
  1387. +#endif
  1388. +
  1389. +#if !defined (__STDC__) || !__STDC__
  1390. +/* This is a separate conditional since some stdc systems
  1391. + reject `defined (const)'. */
  1392. +#ifndef const
  1393. +#define const
  1394. +#endif
  1395. +#endif
  1396. +
  1397. +#include <stdio.h>
  1398. +
  1399. +/* Comment out all this code if we are using the GNU C Library, and are not
  1400. + actually compiling the library itself. This code is part of the GNU C
  1401. + Library, but also included in many other GNU distributions. Compiling
  1402. + and linking in this code is a waste when using the GNU C library
  1403. + (especially if it is a shared library). Rather than having every GNU
  1404. + program understand `configure --with-gnu-libc' and omit the object files,
  1405. + it is simpler to just do this in the source for each such file. */
  1406. +
  1407. +#define GETOPT_INTERFACE_VERSION 2
  1408. +#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
  1409. +#include <gnu-versions.h>
  1410. +#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  1411. +#define ELIDE_CODE
  1412. +#endif
  1413. +#endif
  1414. +
  1415. +#ifndef ELIDE_CODE
  1416. +
  1417. +
  1418. +/* This needs to come after some library #include
  1419. + to get __GNU_LIBRARY__ defined. */
  1420. +#ifdef __GNU_LIBRARY__
  1421. +/* Don't include stdlib.h for non-GNU C libraries because some of them
  1422. + contain conflicting prototypes for getopt. */
  1423. +#include <stdlib.h>
  1424. +#include <unistd.h>
  1425. +#endif /* GNU C library. */
  1426. +
  1427. +#ifdef VMS
  1428. +#include <unixlib.h>
  1429. +#if HAVE_STRING_H - 0
  1430. +#include <string.h>
  1431. +#endif
  1432. +#endif
  1433. +
  1434. +#if defined (_WIN32) && !defined (__CYGWIN32__)
  1435. +/* It's not Unix, really. See? Capital letters. */
  1436. +#include <windows.h>
  1437. +#define getpid() GetCurrentProcessId()
  1438. +#endif
  1439. +
  1440. +#ifndef _
  1441. +/* This is for other GNU distributions with internationalized messages.
  1442. + When compiling libc, the _ macro is predefined. */
  1443. +#ifdef HAVE_LIBINTL_H
  1444. +# include <libintl.h>
  1445. +# define _(msgid) gettext (msgid)
  1446. +#else
  1447. +# define _(msgid) (msgid)
  1448. +#endif
  1449. +#endif
  1450. +
  1451. +/* This version of `getopt' appears to the caller like standard Unix `getopt'
  1452. + but it behaves differently for the user, since it allows the user
  1453. + to intersperse the options with the other arguments.
  1454. +
  1455. + As `getopt' works, it permutes the elements of ARGV so that,
  1456. + when it is done, all the options precede everything else. Thus
  1457. + all application programs are extended to handle flexible argument order.
  1458. +
  1459. + Setting the environment variable POSIXLY_CORRECT disables permutation.
  1460. + Then the behavior is completely standard.
  1461. +
  1462. + GNU application programs can use a third alternative mode in which
  1463. + they can distinguish the relative order of options and other arguments. */
  1464. +
  1465. +#include "rrd_getopt.h"
  1466. +
  1467. +/* For communication from `getopt' to the caller.
  1468. + When `getopt' finds an option that takes an argument,
  1469. + the argument value is returned here.
  1470. + Also, when `ordering' is RETURN_IN_ORDER,
  1471. + each non-option ARGV-element is returned here. */
  1472. +
  1473. +char *optarg = NULL;
  1474. +
  1475. +/* Index in ARGV of the next element to be scanned.
  1476. + This is used for communication to and from the caller
  1477. + and for communication between successive calls to `getopt'.
  1478. +
  1479. + On entry to `getopt', zero means this is the first call; initialize.
  1480. +
  1481. + When `getopt' returns -1, this is the index of the first of the
  1482. + non-option elements that the caller should itself scan.
  1483. +
  1484. + Otherwise, `optind' communicates from one call to the next
  1485. + how much of ARGV has been scanned so far. */
  1486. +
  1487. +/* 1003.2 says this must be 1 before any call. */
  1488. +int optind = 1;
  1489. +
  1490. +/* Formerly, initialization of getopt depended on optind==0, which
  1491. + causes problems with re-calling getopt as programs generally don't
  1492. + know that. */
  1493. +
  1494. +int __getopt_initialized = 0;
  1495. +
  1496. +/* The next char to be scanned in the option-element
  1497. + in which the last option character we returned was found.
  1498. + This allows us to pick up the scan where we left off.
  1499. +
  1500. + If this is zero, or a null string, it means resume the scan
  1501. + by advancing to the next ARGV-element. */
  1502. +
  1503. +static char *nextchar;
  1504. +
  1505. +/* Callers store zero here to inhibit the error message
  1506. + for unrecognized options. */
  1507. +
  1508. +int opterr = 1;
  1509. +
  1510. +/* Set to an option character which was unrecognized.
  1511. + This must be initialized on some systems to avoid linking in the
  1512. + system's own getopt implementation. */
  1513. +
  1514. +int optopt = '?';
  1515. +
  1516. +/* Describe how to deal with options that follow non-option ARGV-elements.
  1517. +
  1518. + If the caller did not specify anything,
  1519. + the default is REQUIRE_ORDER if the environment variable
  1520. + POSIXLY_CORRECT is defined, PERMUTE otherwise.
  1521. +
  1522. + REQUIRE_ORDER means don't recognize them as options;
  1523. + stop option processing when the first non-option is seen.
  1524. + This is what Unix does.
  1525. + This mode of operation is selected by either setting the environment
  1526. + variable POSIXLY_CORRECT, or using `+' as the first character
  1527. + of the list of option characters.
  1528. +
  1529. + PERMUTE is the default. We permute the contents of ARGV as we scan,
  1530. + so that eventually all the non-options are at the end. This allows options
  1531. + to be given in any order, even with programs that were not written to
  1532. + expect this.
  1533. +
  1534. + RETURN_IN_ORDER is an option available to programs that were written
  1535. + to expect options and other ARGV-elements in any order and that care about
  1536. + the ordering of the two. We describe each non-option ARGV-element
  1537. + as if it were the argument of an option with character code 1.
  1538. + Using `-' as the first character of the list of option characters
  1539. + selects this mode of operation.
  1540. +
  1541. + The special argument `--' forces an end of option-scanning regardless
  1542. + of the value of `ordering'. In the case of RETURN_IN_ORDER, only
  1543. + `--' can cause `getopt' to return -1 with `optind' != ARGC. */
  1544. +
  1545. +static enum
  1546. +{
  1547. + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
  1548. +} ordering;
  1549. +
  1550. +/* Value of POSIXLY_CORRECT environment variable. */
  1551. +static char *posixly_correct;
  1552. +
  1553. +/* we must include string as there are warnings without it ... */
  1554. +#include <string.h>
  1555. +
  1556. +#ifdef __GNU_LIBRARY__
  1557. +/* We want to avoid inclusion of string.h with non-GNU libraries
  1558. + because there are many ways it can cause trouble.
  1559. + On some systems, it contains special magic macros that don't work
  1560. + in GCC. */
  1561. +#define my_index strchr
  1562. +#else
  1563. +
  1564. +/* Avoid depending on library functions or files
  1565. + whose names are inconsistent. */
  1566. +
  1567. +char *getenv ();
  1568. +
  1569. +static char *
  1570. +my_index (str, chr)
  1571. + const char *str;
  1572. + int chr;
  1573. +{
  1574. + while (*str)
  1575. + {
  1576. + if (*str == chr)
  1577. + return (char *) str;
  1578. + str++;
  1579. + }
  1580. + return 0;
  1581. +}
  1582. +
  1583. +/* If using GCC, we can safely declare strlen this way.
  1584. + If not using GCC, it is ok not to declare it. */
  1585. +#ifdef __GNUC__
  1586. +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.
  1587. + That was relevant to code that was here before. */
  1588. +#if !defined (__STDC__) || !__STDC__
  1589. +/* gcc with -traditional declares the built-in strlen to return int,
  1590. + and has done so at least since version 2.4.5. -- rms. */
  1591. +extern int strlen (const char *);
  1592. +#endif /* not __STDC__ */
  1593. +#endif /* __GNUC__ */
  1594. +
  1595. +#endif /* not __GNU_LIBRARY__ */
  1596. +
  1597. +/* Handle permutation of arguments. */
  1598. +
  1599. +/* Describe the part of ARGV that contains non-options that have
  1600. + been skipped. `first_nonopt' is the index in ARGV of the first of them;
  1601. + `last_nonopt' is the index after the last of them. */
  1602. +
  1603. +static int first_nonopt;
  1604. +static int last_nonopt;
  1605. +
  1606. +#ifdef _LIBC
  1607. +/* Bash 2.0 gives us an environment variable containing flags
  1608. + indicating ARGV elements that should not be considered arguments. */
  1609. +
  1610. +static const char *nonoption_flags;
  1611. +static int nonoption_flags_len;
  1612. +
  1613. +static int original_argc;
  1614. +static char *const *original_argv;
  1615. +
  1616. +/* Make sure the environment variable bash 2.0 puts in the environment
  1617. + is valid for the getopt call we must make sure that the ARGV passed
  1618. + to getopt is that one passed to the process. */
  1619. +static void store_args (int argc, char *const *argv) __attribute__ ((unused));
  1620. +static void
  1621. +store_args (int argc, char *const *argv)
  1622. +{
  1623. + /* XXX This is no good solution. We should rather copy the args so
  1624. + that we can compare them later. But we must not use malloc(3). */
  1625. + original_argc = argc;
  1626. + original_argv = argv;
  1627. +}
  1628. +text_set_element (__libc_subinit, store_args);
  1629. +#endif
  1630. +
  1631. +/* Exchange two adjacent subsequences of ARGV.
  1632. + One subsequence is elements [first_nonopt,last_nonopt)
  1633. + which contains all the non-options that have been skipped so far.
  1634. + The other is elements [last_nonopt,optind), which contains all
  1635. + the options processed since those non-options were skipped.
  1636. +
  1637. + `first_nonopt' and `last_nonopt' are relocated so that they describe
  1638. + the new indices of the non-options in ARGV after they are moved. */
  1639. +
  1640. +#if defined (__STDC__) && __STDC__
  1641. +static void exchange (char **);
  1642. +#endif
  1643. +
  1644. +static void
  1645. +exchange (argv)
  1646. + char **argv;
  1647. +{
  1648. + int bottom = first_nonopt;
  1649. + int middle = last_nonopt;
  1650. + int top = optind;
  1651. + char *tem;
  1652. +
  1653. + /* Exchange the shorter segment with the far end of the longer segment.
  1654. + That puts the shorter segment into the right place.
  1655. + It leaves the longer segment in the right place overall,
  1656. + but it consists of two parts that need to be swapped next. */
  1657. +
  1658. + while (top > middle && middle > bottom)
  1659. + {
  1660. + if (top - middle > middle - bottom)
  1661. + {
  1662. + /* Bottom segment is the short one. */
  1663. + int len = middle - bottom;
  1664. + register int i;
  1665. +
  1666. + /* Swap it with the top part of the top segment. */
  1667. + for (i = 0; i < len; i++)
  1668. + {
  1669. + tem = argv[bottom + i];
  1670. + argv[bottom + i] = argv[top - (middle - bottom) + i];
  1671. + argv[top - (middle - bottom) + i] = tem;
  1672. + }
  1673. + /* Exclude the moved bottom segment from further swapping. */
  1674. + top -= len;
  1675. + }
  1676. + else
  1677. + {
  1678. + /* Top segment is the short one. */
  1679. + int len = top - middle;
  1680. + register int i;
  1681. +
  1682. + /* Swap it with the bottom part of the bottom segment. */
  1683. + for (i = 0; i < len; i++)
  1684. + {
  1685. + tem = argv[bottom + i];
  1686. + argv[bottom + i] = argv[middle + i];
  1687. + argv[middle + i] = tem;
  1688. + }
  1689. + /* Exclude the moved top segment from further swapping. */
  1690. + bottom += len;
  1691. + }
  1692. + }
  1693. +
  1694. + /* Update records for the slots the non-options now occupy. */
  1695. +
  1696. + first_nonopt += (optind - last_nonopt);
  1697. + last_nonopt = optind;
  1698. +}
  1699. +
  1700. +/* Initialize the internal data when the first call is made. */
  1701. +
  1702. +#if defined (__STDC__) && __STDC__
  1703. +static const char *_getopt_initialize (int, char *const *, const char *);
  1704. +#endif
  1705. +static const char *
  1706. +_getopt_initialize (argc, argv, optstring)
  1707. + int argc;
  1708. + char *const *argv;
  1709. + const char *optstring;
  1710. +{
  1711. + /* Start processing options with ARGV-element 1 (since ARGV-element 0
  1712. + is the program name); the sequence of previously skipped
  1713. + non-option ARGV-elements is empty. */
  1714. +
  1715. + first_nonopt = last_nonopt = optind = 1;
  1716. +
  1717. + nextchar = NULL;
  1718. +
  1719. + posixly_correct = getenv ("POSIXLY_CORRECT");
  1720. +
  1721. + /* Determine how to handle the ordering of options and nonoptions. */
  1722. +
  1723. + if (optstring[0] == '-')
  1724. + {
  1725. + ordering = RETURN_IN_ORDER;
  1726. + ++optstring;
  1727. + }
  1728. + else if (optstring[0] == '+')
  1729. + {
  1730. + ordering = REQUIRE_ORDER;
  1731. + ++optstring;
  1732. + }
  1733. + else if (posixly_correct != NULL)
  1734. + ordering = REQUIRE_ORDER;
  1735. + else
  1736. + ordering = PERMUTE;
  1737. +
  1738. +#ifdef _LIBC
  1739. + if (posixly_correct == NULL
  1740. + && argc == original_argc && argv == original_argv)
  1741. + {
  1742. + /* Bash 2.0 puts a special variable in the environment for each
  1743. + command it runs, specifying which ARGV elements are the results of
  1744. + file name wildcard expansion and therefore should not be
  1745. + considered as options. */
  1746. + char var[100];
  1747. + sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ());
  1748. + nonoption_flags = getenv (var);
  1749. + if (nonoption_flags == NULL)
  1750. + nonoption_flags_len = 0;
  1751. + else
  1752. + nonoption_flags_len = strlen (nonoption_flags);
  1753. + }
  1754. + else
  1755. + nonoption_flags_len = 0;
  1756. +#endif
  1757. +
  1758. + return optstring;
  1759. +}
  1760. +
  1761. +/* Scan elements of ARGV (whose length is ARGC) for option characters
  1762. + given in OPTSTRING.
  1763. +
  1764. + If an element of ARGV starts with '-', and is not exactly "-" or "--",
  1765. + then it is an option element. The characters of this element
  1766. + (aside from the initial '-') are option characters. If `getopt'
  1767. + is called repeatedly, it returns successively each of the option characters
  1768. + from each of the option elements.
  1769. +
  1770. + If `getopt' finds another option character, it returns that character,
  1771. + updating `optind' and `nextchar' so that the next call to `getopt' can
  1772. + resume the scan with the following option character or ARGV-element.
  1773. +
  1774. + If there are no more option characters, `getopt' returns -1.
  1775. + Then `optind' is the index in ARGV of the first ARGV-element
  1776. + that is not an option. (The ARGV-elements have been permuted
  1777. + so that those that are not options now come last.)
  1778. +
  1779. + OPTSTRING is a string containing the legitimate option characters.
  1780. + If an option character is seen that is not listed in OPTSTRING,
  1781. + return '?' after printing an error message. If you set `opterr' to
  1782. + zero, the error message is suppressed but we still return '?'.
  1783. +
  1784. + If a char in OPTSTRING is followed by a colon, that means it wants an arg,
  1785. + so the following text in the same ARGV-element, or the text of the following
  1786. + ARGV-element, is returned in `optarg'. Two colons mean an option that
  1787. + wants an optional arg; if there is text in the current ARGV-element,
  1788. + it is returned in `optarg', otherwise `optarg' is set to zero.
  1789. +
  1790. + If OPTSTRING starts with `-' or `+', it requests different methods of
  1791. + handling the non-option ARGV-elements.
  1792. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
  1793. +
  1794. + Long-named options begin with `--' instead of `-'.
  1795. + Their names may be abbreviated as long as the abbreviation is unique
  1796. + or is an exact match for some defined option. If they have an
  1797. + argument, it follows the option name in the same ARGV-element, separated
  1798. + from the option name by a `=', or else the in next ARGV-element.
  1799. + When `getopt' finds a long-named option, it returns 0 if that option's
  1800. + `flag' field is nonzero, the value of the option's `val' field
  1801. + if the `flag' field is zero.
  1802. +
  1803. + The elements of ARGV aren't really const, because we permute them.
  1804. + But we pretend they're const in the prototype to be compatible
  1805. + with other systems.
  1806. +
  1807. + LONGOPTS is a vector of `struct option' terminated by an
  1808. + element containing a name which is zero.
  1809. +
  1810. + LONGIND returns the index in LONGOPT of the long-named option found.
  1811. + It is only valid when a long-named option has been found by the most
  1812. + recent call.
  1813. +
  1814. + If LONG_ONLY is nonzero, '-' as well as '--' can introduce
  1815. + long-named options. */
  1816. +
  1817. +int
  1818. +_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
  1819. + int argc;
  1820. + char *const *argv;
  1821. + const char *optstring;
  1822. + const struct option *longopts;
  1823. + int *longind;
  1824. + int long_only;
  1825. +{
  1826. + optarg = NULL;
  1827. +
  1828. + if (!__getopt_initialized || optind == 0)
  1829. + {
  1830. + optstring = _getopt_initialize (argc, argv, optstring);
  1831. + optind = 1; /* Don't scan ARGV[0], the program name. */
  1832. + __getopt_initialized = 1;
  1833. + }
  1834. +
  1835. + /* Test whether ARGV[optind] points to a non-option argument.
  1836. + Either it does not have option syntax, or there is an environment flag
  1837. + from the shell indicating it is not an option. The later information
  1838. + is only used when the used in the GNU libc. */
  1839. +#ifdef _LIBC
  1840. +#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \
  1841. + || (optind < nonoption_flags_len \
  1842. + && nonoption_flags[optind] == '1'))
  1843. +#else
  1844. +#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')
  1845. +#endif
  1846. +
  1847. + if (nextchar == NULL || *nextchar == '\0')
  1848. + {
  1849. + /* Advance to the next ARGV-element. */
  1850. +
  1851. + /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
  1852. + moved back by the user (who may also have changed the arguments). */
  1853. + if (last_nonopt > optind)
  1854. + last_nonopt = optind;
  1855. + if (first_nonopt > optind)
  1856. + first_nonopt = optind;
  1857. +
  1858. + if (ordering == PERMUTE)
  1859. + {
  1860. + /* If we have just processed some options following some non-options,
  1861. + exchange them so that the options come first. */
  1862. +
  1863. + if (first_nonopt != last_nonopt && last_nonopt != optind)
  1864. + exchange ((char **) argv);
  1865. + else if (last_nonopt != optind)
  1866. + first_nonopt = optind;
  1867. +
  1868. + /* Skip any additional non-options
  1869. + and extend the range of non-options previously skipped. */
  1870. +
  1871. + while (optind < argc && NONOPTION_P)
  1872. + optind++;
  1873. + last_nonopt = optind;
  1874. + }
  1875. +
  1876. + /* The special ARGV-element `--' means premature end of options.
  1877. + Skip it like a null option,
  1878. + then exchange with previous non-options as if it were an option,
  1879. + then skip everything else like a non-option. */
  1880. +
  1881. + if (optind != argc && !strcmp (argv[optind], "--"))
  1882. + {
  1883. + optind++;
  1884. +
  1885. + if (first_nonopt != last_nonopt && last_nonopt != optind)
  1886. + exchange ((char **) argv);
  1887. + else if (first_nonopt == last_nonopt)
  1888. + first_nonopt = optind;
  1889. + last_nonopt = argc;
  1890. +
  1891. + optind = argc;
  1892. + }
  1893. +
  1894. + /* If we have done all the ARGV-elements, stop the scan
  1895. + and back over any non-options that we skipped and permuted. */
  1896. +
  1897. + if (optind == argc)
  1898. + {
  1899. + /* Set the next-arg-index to point at the non-options
  1900. + that we previously skipped, so the caller will digest them. */
  1901. + if (first_nonopt != last_nonopt)
  1902. + optind = first_nonopt;
  1903. + return -1;
  1904. + }
  1905. +
  1906. + /* If we have come to a non-option and did not permute it,
  1907. + either stop the scan or describe it to the caller and pass it by. */
  1908. +
  1909. + if (NONOPTION_P)
  1910. + {
  1911. + if (ordering == REQUIRE_ORDER)
  1912. + return -1;
  1913. + optarg = argv[optind++];
  1914. + return 1;
  1915. + }
  1916. +
  1917. + /* We have found another option-ARGV-element.
  1918. + Skip the initial punctuation. */
  1919. +
  1920. + nextchar = (argv[optind] + 1
  1921. + + (longopts != NULL && argv[optind][1] == '-'));
  1922. + }
  1923. +
  1924. + /* Decode the current option-ARGV-element. */
  1925. +
  1926. + /* Check whether the ARGV-element is a long option.
  1927. +
  1928. + If long_only and the ARGV-element has the form "-f", where f is
  1929. + a valid short option, don't consider it an abbreviated form of
  1930. + a long option that starts with f. Otherwise there would be no
  1931. + way to give the -f short option.
  1932. +
  1933. + On the other hand, if there's a long option "fubar" and
  1934. + the ARGV-element is "-fu", do consider that an abbreviation of
  1935. + the long option, just like "--fu", and not "-f" with arg "u".
  1936. +
  1937. + This distinction seems to be the most useful approach. */
  1938. +
  1939. + if (longopts != NULL
  1940. + && (argv[optind][1] == '-'
  1941. + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
  1942. + {
  1943. + char *nameend;
  1944. + const struct option *p;
  1945. + const struct option *pfound = NULL;
  1946. + int exact = 0;
  1947. + int ambig = 0;
  1948. + int indfound = -1;
  1949. + int option_index;
  1950. +
  1951. + for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
  1952. + /* Do nothing. */ ;
  1953. +
  1954. + /* Test all long options for either exact match
  1955. + or abbreviated matches. */
  1956. + for (p = longopts, option_index = 0; p->name; p++, option_index++)
  1957. + if (!strncmp (p->name, nextchar, nameend - nextchar))
  1958. + {
  1959. + if ((unsigned int) (nameend - nextchar)
  1960. + == (unsigned int) strlen (p->name))
  1961. + {
  1962. + /* Exact match found. */
  1963. + pfound = p;
  1964. + indfound = option_index;
  1965. + exact = 1;
  1966. + break;
  1967. + }
  1968. + else if (pfound == NULL)
  1969. + {
  1970. + /* First nonexact match found. */
  1971. + pfound = p;
  1972. + indfound = option_index;
  1973. + }
  1974. + else
  1975. + /* Second or later nonexact match found. */
  1976. + ambig = 1;
  1977. + }
  1978. +
  1979. + if (ambig && !exact)
  1980. + {
  1981. + if (opterr)
  1982. + fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
  1983. + argv[0], argv[optind]);
  1984. + nextchar += strlen (nextchar);
  1985. + optind++;
  1986. + optopt = 0;
  1987. + return '?';
  1988. + }
  1989. +
  1990. + if (pfound != NULL)
  1991. + {
  1992. + option_index = indfound;
  1993. + optind++;
  1994. + if (*nameend)
  1995. + {
  1996. + /* Don't test has_arg with >, because some C compilers don't
  1997. + allow it to be used on enums. */
  1998. + if (pfound->has_arg)
  1999. + optarg = nameend + 1;
  2000. + else
  2001. + {
  2002. + if (opterr) {
  2003. + if (argv[optind - 1][1] == '-')
  2004. + /* --option */
  2005. + fprintf (stderr,
  2006. + _("%s: option `--%s' doesn't allow an argument\n"),
  2007. + argv[0], pfound->name);
  2008. + else
  2009. + /* +option or -option */
  2010. + fprintf (stderr,
  2011. + _("%s: option `%c%s' doesn't allow an argument\n"),
  2012. + argv[0], argv[optind - 1][0], pfound->name);
  2013. + }
  2014. + nextchar += strlen (nextchar);
  2015. +
  2016. + optopt = pfound->val;
  2017. + return '?';
  2018. + }
  2019. + }
  2020. + else if (pfound->has_arg == 1)
  2021. + {
  2022. + if (optind < argc)
  2023. + optarg = argv[optind++];
  2024. + else
  2025. + {
  2026. + if (opterr)
  2027. + fprintf (stderr,
  2028. + _("%s: option `%s' requires an argument\n"),
  2029. + argv[0], argv[optind - 1]);
  2030. + nextchar += strlen (nextchar);
  2031. + optopt = pfound->val;
  2032. + return optstring[0] == ':' ? ':' : '?';
  2033. + }
  2034. + }
  2035. + nextchar += strlen (nextchar);
  2036. + if (longind != NULL)
  2037. + *longind = option_index;
  2038. + if (pfound->flag)
  2039. + {
  2040. + *(pfound->flag) = pfound->val;
  2041. + return 0;
  2042. + }
  2043. + return pfound->val;
  2044. + }
  2045. +
  2046. + /* Can't find it as a long option. If this is not getopt_long_only,
  2047. + or the option starts with '--' or is not a valid short
  2048. + option, then it's an error.
  2049. + Otherwise interpret it as a short option. */
  2050. + if (!long_only || argv[optind][1] == '-'
  2051. + || my_index (optstring, *nextchar) == NULL)
  2052. + {
  2053. + if (opterr)
  2054. + {
  2055. + if (argv[optind][1] == '-')
  2056. + /* --option */
  2057. + fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
  2058. + argv[0], nextchar);
  2059. + else
  2060. + /* +option or -option */
  2061. + fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
  2062. + argv[0], argv[optind][0], nextchar);
  2063. + }
  2064. + nextchar = (char *) "";
  2065. + optind++;
  2066. + optopt = 0;
  2067. + return '?';
  2068. + }
  2069. + }
  2070. +
  2071. + /* Look at and handle the next short option-character. */
  2072. +
  2073. + {
  2074. + char c = *nextchar++;
  2075. + char *temp = my_index (optstring, c);
  2076. +
  2077. + /* Increment `optind' when we start to process its last character. */
  2078. + if (*nextchar == '\0')
  2079. + ++optind;
  2080. +
  2081. + if (temp == NULL || c == ':')
  2082. + {
  2083. + if (opterr)
  2084. + {
  2085. + if (posixly_correct)
  2086. + /* 1003.2 specifies the format of this message. */
  2087. + fprintf (stderr, _("%s: illegal option -- %c\n"),
  2088. + argv[0], c);
  2089. + else
  2090. + fprintf (stderr, _("%s: invalid option -- %c\n"),
  2091. + argv[0], c);
  2092. + }
  2093. + optopt = c;
  2094. + return '?';
  2095. + }
  2096. + /* Convenience. Treat POSIX -W foo same as long option --foo */
  2097. + if (temp[0] == 'W' && temp[1] == ';')
  2098. + {
  2099. + char *nameend;
  2100. + const struct option *p;
  2101. + const struct option *pfound = NULL;
  2102. + int exact = 0;
  2103. + int ambig = 0;
  2104. + int indfound = 0;
  2105. + int option_index;
  2106. +
  2107. + /* This is an option that requires an argument. */
  2108. + if (*nextchar != '\0')
  2109. + {
  2110. + optarg = nextchar;
  2111. + /* If we end this ARGV-element by taking the rest as an arg,
  2112. + we must advance to the next element now. */
  2113. + optind++;
  2114. + }
  2115. + else if (optind == argc)
  2116. + {
  2117. + if (opterr)
  2118. + {
  2119. + /* 1003.2 specifies the format of this message. */
  2120. + fprintf (stderr, _("%s: option requires an argument -- %c\n"),
  2121. + argv[0], c);
  2122. + }
  2123. + optopt = c;
  2124. + if (optstring[0] == ':')
  2125. + c = ':';
  2126. + else
  2127. + c = '?';
  2128. + return c;
  2129. + }
  2130. + else
  2131. + /* We already incremented `optind' once;
  2132. + increment it again when taking next ARGV-elt as argument. */
  2133. + optarg = argv[optind++];
  2134. +
  2135. + /* optarg is now the argument, see if it's in the
  2136. + table of longopts. */
  2137. +
  2138. + for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)
  2139. + /* Do nothing. */ ;
  2140. +
  2141. + /* Test all long options for either exact match
  2142. + or abbreviated matches. */
  2143. + for (p = longopts, option_index = 0; p->name; p++, option_index++)
  2144. + if (!strncmp (p->name, nextchar, nameend - nextchar))
  2145. + {
  2146. + if ((unsigned int) (nameend - nextchar) == strlen (p->name))
  2147. + {
  2148. + /* Exact match found. */
  2149. + pfound = p;
  2150. + indfound = option_index;
  2151. + exact = 1;
  2152. + break;
  2153. + }
  2154. + else if (pfound == NULL)
  2155. + {
  2156. + /* First nonexact match found. */
  2157. + pfound = p;
  2158. + indfound = option_index;
  2159. + }
  2160. + else
  2161. + /* Second or later nonexact match found. */
  2162. + ambig = 1;
  2163. + }
  2164. + if (ambig && !exact)
  2165. + {
  2166. + if (opterr)
  2167. + fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
  2168. + argv[0], argv[optind]);
  2169. + nextchar += strlen (nextchar);
  2170. + optind++;
  2171. + return '?';
  2172. + }
  2173. + if (pfound != NULL)
  2174. + {
  2175. + option_index = indfound;
  2176. + if (*nameend)
  2177. + {
  2178. + /* Don't test has_arg with >, because some C compilers don't
  2179. + allow it to be used on enums. */
  2180. + if (pfound->has_arg)
  2181. + optarg = nameend + 1;
  2182. + else
  2183. + {
  2184. + if (opterr)
  2185. + fprintf (stderr, _("\
  2186. +%s: option `-W %s' doesn't allow an argument\n"),
  2187. + argv[0], pfound->name);
  2188. +
  2189. + nextchar += strlen (nextchar);
  2190. + return '?';
  2191. + }
  2192. + }
  2193. + else if (pfound->has_arg == 1)
  2194. + {
  2195. + if (optind < argc)
  2196. + optarg = argv[optind++];
  2197. + else
  2198. + {
  2199. + if (opterr)
  2200. + fprintf (stderr,
  2201. + _("%s: option `%s' requires an argument\n"),
  2202. + argv[0], argv[optind - 1]);
  2203. + nextchar += strlen (nextchar);
  2204. + return optstring[0] == ':' ? ':' : '?';
  2205. + }
  2206. + }
  2207. + nextchar += strlen (nextchar);
  2208. + if (longind != NULL)
  2209. + *longind = option_index;
  2210. + if (pfound->flag)
  2211. + {
  2212. + *(pfound->flag) = pfound->val;
  2213. + return 0;
  2214. + }
  2215. + return pfound->val;
  2216. + }
  2217. + nextchar = NULL;
  2218. + return 'W'; /* Let the application handle it. */
  2219. + }
  2220. + if (temp[1] == ':')
  2221. + {
  2222. + if (temp[2] == ':')
  2223. + {
  2224. + /* This is an option that accepts an argument optionally. */
  2225. + if (*nextchar != '\0')
  2226. + {
  2227. + optarg = nextchar;
  2228. + optind++;
  2229. + }
  2230. + else
  2231. + optarg = NULL;
  2232. + nextchar = NULL;
  2233. + }
  2234. + else
  2235. + {
  2236. + /* This is an option that requires an argument. */
  2237. + if (*nextchar != '\0')
  2238. + {
  2239. + optarg = nextchar;
  2240. + /* If we end this ARGV-element by taking the rest as an arg,
  2241. + we must advance to the next element now. */
  2242. + optind++;
  2243. + }
  2244. + else if (optind == argc)
  2245. + {
  2246. + if (opterr)
  2247. + {
  2248. + /* 1003.2 specifies the format of this message. */
  2249. + fprintf (stderr,
  2250. + _("%s: option requires an argument -- %c\n"),
  2251. + argv[0], c);
  2252. + }
  2253. + optopt = c;
  2254. + if (optstring[0] == ':')
  2255. + c = ':';
  2256. + else
  2257. + c = '?';
  2258. + }
  2259. + else
  2260. + /* We already incremented `optind' once;
  2261. + increment it again when taking next ARGV-elt as argument. */
  2262. + optarg = argv[optind++];
  2263. + nextchar = NULL;
  2264. + }
  2265. + }
  2266. + return c;
  2267. + }
  2268. +}
  2269. +
  2270. +int
  2271. +getopt (argc, argv, optstring)
  2272. + int argc;
  2273. + char *const *argv;
  2274. + const char *optstring;
  2275. +{
  2276. + return _getopt_internal (argc, argv, optstring,
  2277. + (const struct option *) 0,
  2278. + (int *) 0,
  2279. + 0);
  2280. +}
  2281. +
  2282. +#endif /* Not ELIDE_CODE. */
  2283. +
  2284. +#ifdef TEST
  2285. +
  2286. +/* Compile with -DTEST to make an executable for use in testing
  2287. + the above definition of `getopt'. */
  2288. +
  2289. +int
  2290. +main (argc, argv)
  2291. + int argc;
  2292. + char **argv;
  2293. +{
  2294. + int c;
  2295. + int digit_optind = 0;
  2296. +
  2297. + while (1)
  2298. + {
  2299. + int this_option_optind = optind ? optind : 1;
  2300. +
  2301. + c = getopt (argc, argv, "abc:d:0123456789");
  2302. + if (c == -1)
  2303. + break;
  2304. +
  2305. + switch (c)
  2306. + {
  2307. + case '0':
  2308. + case '1':
  2309. + case '2':
  2310. + case '3':
  2311. + case '4':
  2312. + case '5':
  2313. + case '6':
  2314. + case '7':
  2315. + case '8':
  2316. + case '9':
  2317. + if (digit_optind != 0 && digit_optind != this_option_optind)
  2318. + printf ("digits occur in two different argv-elements.\n");
  2319. + digit_optind = this_option_optind;
  2320. + printf ("option %c\n", c);
  2321. + break;
  2322. +
  2323. + case 'a':
  2324. + printf ("option a\n");
  2325. + break;
  2326. +
  2327. + case 'b':
  2328. + printf ("option b\n");
  2329. + break;
  2330. +
  2331. + case 'c':
  2332. + printf ("option c with value `%s'\n", optarg);
  2333. + break;
  2334. +
  2335. + case '?':
  2336. + break;
  2337. +
  2338. + default:
  2339. + printf ("?? getopt returned character code 0%o ??\n", c);
  2340. + }
  2341. + }
  2342. +
  2343. + if (optind < argc)
  2344. + {
  2345. + printf ("non-option ARGV-elements: ");
  2346. + while (optind < argc)
  2347. + printf ("%s ", argv[optind++]);
  2348. + printf ("\n");
  2349. + }
  2350. +
  2351. + exit (0);
  2352. +}
  2353. +
  2354. +#endif /* TEST */
  2355. Eigenschafts�nderungen: src/rrd_getopt.c
  2356. ___________________________________________________________________
  2357. Name: svn:keywords
  2358. + Author Date Id Revision
  2359. Name: svn:eol-style
  2360. + native
  2361. --- ./src/rrd_getopt.h (Revision 0)
  2362. +++ ./src/rrd_getopt.h (Revision 1007)
  2363. @@ -0,0 +1,133 @@
  2364. +/* Declarations for getopt.
  2365. + Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
  2366. +
  2367. + This file is part of the GNU C Library. Its master source is NOT part of
  2368. + the C library, however. The master source lives in /gd/gnu/lib.
  2369. +
  2370. + The GNU C Library is free software; you can redistribute it and/or
  2371. + modify it under the terms of the GNU Library General Public License as
  2372. + published by the Free Software Foundation; either version 2 of the
  2373. + License, or (at your option) any later version.
  2374. +
  2375. + The GNU C Library is distributed in the hope that it will be useful,
  2376. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2377. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2378. + Library General Public License for more details.
  2379. +
  2380. + You should have received a copy of the GNU Library General Public
  2381. + License along with the GNU C Library; see the file COPYING.LIB. If not,
  2382. + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  2383. + Boston, MA 02111-1307, USA. */
  2384. +
  2385. +#ifndef _GETOPT_H
  2386. +#define _GETOPT_H 1
  2387. +
  2388. +#ifdef __cplusplus
  2389. +extern "C" {
  2390. +#endif
  2391. +
  2392. +/* For communication from `getopt' to the caller.
  2393. + When `getopt' finds an option that takes an argument,
  2394. + the argument value is returned here.
  2395. + Also, when `ordering' is RETURN_IN_ORDER,
  2396. + each non-option ARGV-element is returned here. */
  2397. +
  2398. +extern char *optarg;
  2399. +
  2400. +/* Index in ARGV of the next element to be scanned.
  2401. + This is used for communication to and from the caller
  2402. + and for communication between successive calls to `getopt'.
  2403. +
  2404. + On entry to `getopt', zero means this is the first call; initialize.
  2405. +
  2406. + When `getopt' returns -1, this is the index of the first of the
  2407. + non-option elements that the caller should itself scan.
  2408. +
  2409. + Otherwise, `optind' communicates from one call to the next
  2410. + how much of ARGV has been scanned so far. */
  2411. +
  2412. +extern int optind;
  2413. +
  2414. +/* Callers store zero here to inhibit the error message `getopt' prints
  2415. + for unrecognized options. */
  2416. +
  2417. +extern int opterr;
  2418. +
  2419. +/* Set to an option character which was unrecognized. */
  2420. +
  2421. +extern int optopt;
  2422. +
  2423. +/* Describe the long-named options requested by the application.
  2424. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  2425. + of `struct option' terminated by an element containing a name which is
  2426. + zero.
  2427. +
  2428. + The field `has_arg' is:
  2429. + no_argument (or 0) if the option does not take an argument,
  2430. + required_argument (or 1) if the option requires an argument,
  2431. + optional_argument (or 2) if the option takes an optional argument.
  2432. +
  2433. + If the field `flag' is not NULL, it points to a variable that is set
  2434. + to the value given in the field `val' when the option is found, but
  2435. + left unchanged if the option is not found.
  2436. +
  2437. + To have a long-named option do something other than set an `int' to
  2438. + a compiled-in constant, such as set a value from `optarg', set the
  2439. + option's `flag' field to zero and its `val' field to a nonzero
  2440. + value (the equivalent single-letter option character, if there is
  2441. + one). For long options that have a zero `flag' field, `getopt'
  2442. + returns the contents of the `val' field. */
  2443. +
  2444. +struct option
  2445. +{
  2446. +#if defined (__STDC__) && __STDC__
  2447. + const char *name;
  2448. +#else
  2449. + char *name;
  2450. +#endif
  2451. + /* has_arg can't be an enum because some compilers complain about
  2452. + type mismatches in all the code that assumes it is an int. */
  2453. + int has_arg;
  2454. + int *flag;
  2455. + int val;
  2456. +};
  2457. +
  2458. +/* Names for the values of the `has_arg' field of `struct option'. */
  2459. +
  2460. +#define no_argument 0
  2461. +#define required_argument 1
  2462. +#define optional_argument 2
  2463. +
  2464. +#if defined (__STDC__) && __STDC__
  2465. +#ifdef __GNU_LIBRARY__
  2466. +/* Many other libraries have conflicting prototypes for getopt, with
  2467. + differences in the consts, in stdlib.h. To avoid compilation
  2468. + errors, only prototype getopt for the GNU C library. */
  2469. +extern int getopt (int argc, char *const *argv, const char *shortopts);
  2470. +#else /* not __GNU_LIBRARY__ */
  2471. +extern int getopt ();
  2472. +#endif /* __GNU_LIBRARY__ */
  2473. +extern int getopt_long (int argc, char *const *argv, const char *shortopts,
  2474. + const struct option *longopts, int *longind);
  2475. +extern int getopt_long_only (int argc, char *const *argv,
  2476. + const char *shortopts,
  2477. + const struct option *longopts, int *longind);
  2478. +
  2479. +/* Internal only. Users should not call this directly. */
  2480. +extern int _getopt_internal (int argc, char *const *argv,
  2481. + const char *shortopts,
  2482. + const struct option *longopts, int *longind,
  2483. + int long_only);
  2484. +#else /* not __STDC__ */
  2485. +extern int getopt ();
  2486. +extern int getopt_long ();
  2487. +extern int getopt_long_only ();
  2488. +
  2489. +extern int _getopt_internal ();
  2490. +#endif /* __STDC__ */
  2491. +
  2492. +#ifdef __cplusplus
  2493. +}
  2494. +#endif
  2495. +
  2496. +#endif /* _GETOPT_H */
  2497. Eigenschafts�nderungen: src/rrd_getopt.h
  2498. ___________________________________________________________________
  2499. Name: svn:keywords
  2500. + Author Date Id Revision
  2501. Name: svn:eol-style
  2502. + native
  2503. --- ./src/rrd_tool.h (Revision 1006)
  2504. +++ ./src/rrd_tool.h (Revision 1007)
  2505. @@ -115,7 +115,7 @@
  2506. #endif
  2507. /* local include files -- need to be after the system ones */
  2508. -#include "getopt.h"
  2509. +#include "rrd_getopt.h"
  2510. #include "rrd_format.h"
  2511. #ifndef max
  2512. --- ./src/rrd_getopt1.c (Revision 0)
  2513. +++ ./src/rrd_getopt1.c (Revision 1007)
  2514. @@ -0,0 +1,189 @@
  2515. +/* getopt_long and getopt_long_only entry points for GNU getopt.
  2516. + Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
  2517. +
  2518. + This file is part of the GNU C Library. Its master source is NOT part of
  2519. + the C library, however. The master source lives in /gd/gnu/lib.
  2520. +
  2521. + The GNU C Library is free software; you can redistribute it and/or
  2522. + modify it under the terms of the GNU Library General Public License as
  2523. + published by the Free Software Foundation; either version 2 of the
  2524. + License, or (at your option) any later version.
  2525. +
  2526. + The GNU C Library is distributed in the hope that it will be useful,
  2527. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2528. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2529. + Library General Public License for more details.
  2530. +
  2531. + You should have received a copy of the GNU Library General Public
  2532. + License along with the GNU C Library; see the file COPYING.LIB. If not,
  2533. + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  2534. + Boston, MA 02111-1307, USA. */
  2535. +
  2536. +#ifdef HAVE_CONFIG_H
  2537. +#include "../rrd_config.h"
  2538. +#endif
  2539. +
  2540. +#include "rrd_getopt.h"
  2541. +
  2542. +#if !defined (__STDC__) || !__STDC__
  2543. +/* This is a separate conditional since some stdc systems
  2544. + reject `defined (const)'. */
  2545. +#ifndef const
  2546. +#define const
  2547. +#endif
  2548. +#endif
  2549. +
  2550. +#include <stdio.h>
  2551. +
  2552. +/* Comment out all this code if we are using the GNU C Library, and are not
  2553. + actually compiling the library itself. This code is part of the GNU C
  2554. + Library, but also included in many other GNU distributions. Compiling
  2555. + and linking in this code is a waste when using the GNU C library
  2556. + (especially if it is a shared library). Rather than having every GNU
  2557. + program understand `configure --with-gnu-libc' and omit the object files,
  2558. + it is simpler to just do this in the source for each such file. */
  2559. +
  2560. +#define GETOPT_INTERFACE_VERSION 2
  2561. +#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
  2562. +#include <gnu-versions.h>
  2563. +#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  2564. +#define ELIDE_CODE
  2565. +#endif
  2566. +#endif
  2567. +
  2568. +#ifndef ELIDE_CODE
  2569. +
  2570. +
  2571. +/* This needs to come after some library #include
  2572. + to get __GNU_LIBRARY__ defined. */
  2573. +#ifdef __GNU_LIBRARY__
  2574. +#include <stdlib.h>
  2575. +#endif
  2576. +
  2577. +#ifndef NULL
  2578. +#define NULL 0
  2579. +#endif
  2580. +
  2581. +int
  2582. +getopt_long (argc, argv, options, long_options, opt_index)
  2583. + int argc;
  2584. + char *const *argv;
  2585. + const char *options;
  2586. + const struct option *long_options;
  2587. + int *opt_index;
  2588. +{
  2589. + return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
  2590. +}
  2591. +
  2592. +/* Like getopt_long, but '-' as well as '--' can indicate a long option.
  2593. + If an option that starts with '-' (not '--') doesn't match a long option,
  2594. + but does match a short option, it is parsed as a short option
  2595. + instead. */
  2596. +
  2597. +int
  2598. +getopt_long_only (argc, argv, options, long_options, opt_index)
  2599. + int argc;
  2600. + char *const *argv;
  2601. + const char *options;
  2602. + const struct option *long_options;
  2603. + int *opt_index;
  2604. +{
  2605. + return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
  2606. +}
  2607. +
  2608. +
  2609. +#endif /* Not ELIDE_CODE. */
  2610. +
  2611. +#ifdef TEST
  2612. +
  2613. +#include <stdio.h>
  2614. +
  2615. +int
  2616. +main (argc, argv)
  2617. + int argc;
  2618. + char **argv;
  2619. +{
  2620. + int c;
  2621. + int digit_optind = 0;
  2622. +
  2623. + while (1)
  2624. + {
  2625. + int this_option_optind = optind ? optind : 1;
  2626. + int option_index = 0;
  2627. + static struct option long_options[] =
  2628. + {
  2629. + {"add", 1, 0, 0},
  2630. + {"append", 0, 0, 0},
  2631. + {"delete", 1, 0, 0},
  2632. + {"verbose", 0, 0, 0},
  2633. + {"create", 0, 0, 0},
  2634. + {"file", 1, 0, 0},
  2635. + {0, 0, 0, 0}
  2636. + };
  2637. +
  2638. + c = getopt_long (argc, argv, "abc:d:0123456789",
  2639. + long_options, &option_index);
  2640. + if (c == -1)
  2641. + break;
  2642. +
  2643. + switch (c)
  2644. + {
  2645. + case 0:
  2646. + printf ("option %s", long_options[option_index].name);
  2647. + if (optarg)
  2648. + printf (" with arg %s", optarg);
  2649. + printf ("\n");
  2650. + break;
  2651. +
  2652. + case '0':
  2653. + case '1':
  2654. + case '2':
  2655. + case '3':
  2656. + case '4':
  2657. + case '5':
  2658. + case '6':
  2659. + case '7':
  2660. + case '8':
  2661. + case '9':
  2662. + if (digit_optind != 0 && digit_optind != this_option_optind)
  2663. + printf ("digits occur in two different argv-elements.\n");
  2664. + digit_optind = this_option_optind;
  2665. + printf ("option %c\n", c);
  2666. + break;
  2667. +
  2668. + case 'a':
  2669. + printf ("option a\n");
  2670. + break;
  2671. +
  2672. + case 'b':
  2673. + printf ("option b\n");
  2674. + break;
  2675. +
  2676. + case 'c':
  2677. + printf ("option c with value `%s'\n", optarg);
  2678. + break;
  2679. +
  2680. + case 'd':
  2681. + printf ("option d with value `%s'\n", optarg);
  2682. + break;
  2683. +
  2684. + case '?':
  2685. + break;
  2686. +
  2687. + default:
  2688. + printf ("?? getopt returned character code 0%o ??\n", c);
  2689. + }
  2690. + }
  2691. +
  2692. + if (optind < argc)
  2693. + {
  2694. + printf ("non-option ARGV-elements: ");
  2695. + while (optind < argc)
  2696. + printf ("%s ", argv[optind++]);
  2697. + printf ("\n");
  2698. + }
  2699. +
  2700. + exit (0);
  2701. +}
  2702. +
  2703. +#endif /* TEST */
  2704. Eigenschafts�nderungen: src/rrd_getopt1.c
  2705. ___________________________________________________________________
  2706. Name: svn:keywords
  2707. + Author Date Id Revision
  2708. Name: svn:eol-style
  2709. + native
  2710. --- ./src/Makefile.am (Revision 1006)
  2711. +++ ./src/Makefile.am (Revision 1007)
  2712. @@ -13,8 +13,8 @@
  2713. AM_CPPFLAGS = -DRRD_DEFAULT_FONT=\"$(RRD_DEFAULT_FONT)\" -DNUMVERS=@NUMVERS@
  2714. UPD_C_FILES = \
  2715. - getopt.c \
  2716. - getopt1.c \
  2717. + rrd_getopt.c \
  2718. + rrd_getopt1.c \
  2719. parsetime.c \
  2720. rrd_hw.c \
  2721. rrd_diff.c \
  2722. @@ -51,7 +51,7 @@
  2723. art_rgba_svp.h \
  2724. unused.h \
  2725. rrd_gfx.h \
  2726. - getopt.h parsetime.h \
  2727. + rrd_getopt.h parsetime.h \
  2728. rrd_format.h rrd_tool.h rrd_xport.h rrd.h rrd_hw.h rrd_rpncalc.h \
  2729. rrd_nan_inf.h fnv.h rrd_graph.h rrd_afm.h rrd_afm_data.h \
  2730. rrd_is_thread_safe.h