~ubuntu-branches/ubuntu/maverick/man-db/maverick

« back to all changes in this revision

Viewing changes to gnulib/lib/getopt1.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2010-02-17 00:56:08 UTC
  • mfrom: (1.1.10 upstream) (5.2.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100217005608-ko3mxv0qr29iaptz
Tags: 2.5.7-1
* New upstream release:
  - Make man(1) refer to the "Warnings" node in 'info groff' for a list of
    available warning names (closes: #545805).
  - Don't run tests if cross-compiling.
  - Add option to disable justification (closes: #440047).
  - Do what the user probably means when the full path to an executable is
    given as an argument (closes: #505465).
  - Search man<sec><ext> directories in the GNU layout (closes: #519807).
  - Prefer getting a page from the best manual section over getting a page
    in the correct language; I have my reservations about this, but it
    seems to be what people are requesting (closes: #519547).
  - 'man -f' and 'man -k' now pass through any -s option to apropos/whatis
    respectively.
  - All programs now support a MAN_DEBUG environment variable which can be
    used in place of the -d/--debug option. This is useful in some
    situations where a program is being called deep in a process tree.
  - Fix off-by-one error when write returns EAGAIN (thanks, Samuel
    Thibault; closes: #564818).
  - "%s: nothing appropriate." is an error; write it to stderr, not stdout
    (closes: #565255).
  - Don't bother printing error messages for SIGINT and SIGQUIT, since
    these correspond to explicit user actions (closes: #568000).
  - Fix sense of directory check while decompressing (closes: #537434).
  - Always save cat pages in UTF-8 (closes: #446741).
* Convert to source format 3.0 (quilt).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* getopt_long and getopt_long_only entry points for GNU getopt.
2
 
   Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98,2004,2006,2009
3
 
     Free Software Foundation, Inc.
 
2
   Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
 
3
   1998, 2004, 2006, 2009, 2010 Free Software Foundation, Inc.
4
4
   This file is part of the GNU C Library.
5
5
 
6
6
   This program is free software: you can redistribute it and/or modify
32
32
#include <stdlib.h>
33
33
#endif
34
34
 
35
 
#ifndef NULL
 
35
#ifndef NULL
36
36
#define NULL 0
37
37
#endif
38
38
 
39
39
int
40
40
getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
41
 
             const struct option *long_options, int *opt_index)
 
41
             const struct option *long_options, int *opt_index)
42
42
{
43
43
  return _getopt_internal (argc, (char **) argv, options, long_options,
44
 
                           opt_index, 0, 0);
 
44
                           opt_index, 0, 0);
45
45
}
46
46
 
47
47
int
48
48
_getopt_long_r (int argc, char **argv, const char *options,
49
 
                const struct option *long_options, int *opt_index,
50
 
                struct _getopt_data *d)
 
49
                const struct option *long_options, int *opt_index,
 
50
                struct _getopt_data *d)
51
51
{
52
52
  return _getopt_internal_r (argc, argv, options, long_options, opt_index,
53
 
                             0, 0, d);
 
53
                             0, d, 0);
54
54
}
55
55
 
56
56
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
60
60
 
61
61
int
62
62
getopt_long_only (int argc, char *__getopt_argv_const *argv,
63
 
                  const char *options,
64
 
                  const struct option *long_options, int *opt_index)
 
63
                  const char *options,
 
64
                  const struct option *long_options, int *opt_index)
65
65
{
66
66
  return _getopt_internal (argc, (char **) argv, options, long_options,
67
 
                           opt_index, 1, 0);
 
67
                           opt_index, 1, 0);
68
68
}
69
69
 
70
70
int
71
71
_getopt_long_only_r (int argc, char **argv, const char *options,
72
 
                     const struct option *long_options, int *opt_index,
73
 
                     struct _getopt_data *d)
 
72
                     const struct option *long_options, int *opt_index,
 
73
                     struct _getopt_data *d)
74
74
{
75
75
  return _getopt_internal_r (argc, argv, options, long_options, opt_index,
76
 
                             1, 0, d);
 
76
                             1, d, 0);
77
77
}
78
78
 
79
79
 
93
93
      int option_index = 0;
94
94
      static const struct option long_options[] =
95
95
      {
96
 
        {"add", 1, 0, 0},
97
 
        {"append", 0, 0, 0},
98
 
        {"delete", 1, 0, 0},
99
 
        {"verbose", 0, 0, 0},
100
 
        {"create", 0, 0, 0},
101
 
        {"file", 1, 0, 0},
102
 
        {0, 0, 0, 0}
 
96
        {"add", 1, 0, 0},
 
97
        {"append", 0, 0, 0},
 
98
        {"delete", 1, 0, 0},
 
99
        {"verbose", 0, 0, 0},
 
100
        {"create", 0, 0, 0},
 
101
        {"file", 1, 0, 0},
 
102
        {0, 0, 0, 0}
103
103
      };
104
104
 
105
105
      c = getopt_long (argc, argv, "abc:d:0123456789",
106
 
                       long_options, &option_index);
 
106
                       long_options, &option_index);
107
107
      if (c == -1)
108
 
        break;
 
108
        break;
109
109
 
110
110
      switch (c)
111
 
        {
112
 
        case 0:
113
 
          printf ("option %s", long_options[option_index].name);
114
 
          if (optarg)
115
 
            printf (" with arg %s", optarg);
116
 
          printf ("\n");
117
 
          break;
118
 
 
119
 
        case '0':
120
 
        case '1':
121
 
        case '2':
122
 
        case '3':
123
 
        case '4':
124
 
        case '5':
125
 
        case '6':
126
 
        case '7':
127
 
        case '8':
128
 
        case '9':
129
 
          if (digit_optind != 0 && digit_optind != this_option_optind)
130
 
            printf ("digits occur in two different argv-elements.\n");
131
 
          digit_optind = this_option_optind;
132
 
          printf ("option %c\n", c);
133
 
          break;
134
 
 
135
 
        case 'a':
136
 
          printf ("option a\n");
137
 
          break;
138
 
 
139
 
        case 'b':
140
 
          printf ("option b\n");
141
 
          break;
142
 
 
143
 
        case 'c':
144
 
          printf ("option c with value `%s'\n", optarg);
145
 
          break;
146
 
 
147
 
        case 'd':
148
 
          printf ("option d with value `%s'\n", optarg);
149
 
          break;
150
 
 
151
 
        case '?':
152
 
          break;
153
 
 
154
 
        default:
155
 
          printf ("?? getopt returned character code 0%o ??\n", c);
156
 
        }
 
111
        {
 
112
        case 0:
 
113
          printf ("option %s", long_options[option_index].name);
 
114
          if (optarg)
 
115
            printf (" with arg %s", optarg);
 
116
          printf ("\n");
 
117
          break;
 
118
 
 
119
        case '0':
 
120
        case '1':
 
121
        case '2':
 
122
        case '3':
 
123
        case '4':
 
124
        case '5':
 
125
        case '6':
 
126
        case '7':
 
127
        case '8':
 
128
        case '9':
 
129
          if (digit_optind != 0 && digit_optind != this_option_optind)
 
130
            printf ("digits occur in two different argv-elements.\n");
 
131
          digit_optind = this_option_optind;
 
132
          printf ("option %c\n", c);
 
133
          break;
 
134
 
 
135
        case 'a':
 
136
          printf ("option a\n");
 
137
          break;
 
138
 
 
139
        case 'b':
 
140
          printf ("option b\n");
 
141
          break;
 
142
 
 
143
        case 'c':
 
144
          printf ("option c with value `%s'\n", optarg);
 
145
          break;
 
146
 
 
147
        case 'd':
 
148
          printf ("option d with value `%s'\n", optarg);
 
149
          break;
 
150
 
 
151
        case '?':
 
152
          break;
 
153
 
 
154
        default:
 
155
          printf ("?? getopt returned character code 0%o ??\n", c);
 
156
        }
157
157
    }
158
158
 
159
159
  if (optind < argc)
160
160
    {
161
161
      printf ("non-option ARGV-elements: ");
162
162
      while (optind < argc)
163
 
        printf ("%s ", argv[optind++]);
 
163
        printf ("%s ", argv[optind++]);
164
164
      printf ("\n");
165
165
    }
166
166