~p-ch-e/gnuhello/gnuhello

« back to all changes in this revision

Viewing changes to gnulib/m4/getopt.m4

  • Committer: Reuben Thomas
  • Date: 2011-12-17 11:23:38 UTC
  • Revision ID: rrt@sc3d.org-20111217112338-kurwdy8nu69g3t6f
Update gnulib and convert .cvsignore to .bzrignore.

        * gnulib: Update.
        * .bzrignore: Add.
        * .cvsignore: Remove.
        * contrib/.cvsignore: Likewise.
        * doc/.cvsignore: Likewise.
        * man/.cvsignore: Likewise.
        * po/.cvsignore: Likewise.
        * src/.cvsignore: Likewise.
        * tests/.cvsignore: Likewise.
        * build/mkinstalldirs: Remove: no longer needed.
        * po: Update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# getopt.m4 serial 34
 
1
# getopt.m4 serial 39
2
2
dnl Copyright (C) 2002-2006, 2008-2011 Free Software Foundation, Inc.
3
3
dnl This file is free software; the Free Software Foundation
4
4
dnl gives unlimited permission to copy and/or distribute it,
9
9
[
10
10
  m4_divert_text([DEFAULTS], [gl_getopt_required=POSIX])
11
11
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12
 
  gl_GETOPT_IFELSE([
13
 
    gl_REPLACE_GETOPT
14
 
  ],
15
 
  [])
 
12
  dnl Other modules can request the gnulib implementation of the getopt
 
13
  dnl functions unconditionally, by defining gl_REPLACE_GETOPT_ALWAYS.
 
14
  dnl argp.m4 does this.
 
15
  m4_ifdef([gl_REPLACE_GETOPT_ALWAYS], [
 
16
    gl_GETOPT_IFELSE([], [])
 
17
    REPLACE_GETOPT=1
 
18
  ], [
 
19
    REPLACE_GETOPT=0
 
20
    gl_GETOPT_IFELSE([
 
21
      REPLACE_GETOPT=1
 
22
    ],
 
23
    [])
 
24
  ])
 
25
  if test $REPLACE_GETOPT = 1; then
 
26
    dnl Arrange for getopt.h to be created.
 
27
    gl_GETOPT_SUBSTITUTE_HEADER
 
28
  fi
16
29
])
17
30
 
18
31
# Request a POSIX compliant getopt function with GNU extensions (such as
25
38
  AC_REQUIRE([gl_FUNC_GETOPT_POSIX])
26
39
])
27
40
 
28
 
# Request the gnulib implementation of the getopt functions unconditionally.
29
 
# argp.m4 uses this.
30
 
AC_DEFUN([gl_REPLACE_GETOPT],
31
 
[
32
 
  dnl Arrange for getopt.h to be created.
33
 
  gl_GETOPT_SUBSTITUTE_HEADER
34
 
  dnl Arrange for unistd.h to include getopt.h.
35
 
  GNULIB_UNISTD_H_GETOPT=1
36
 
  dnl Arrange to compile the getopt implementation.
37
 
  AC_LIBOBJ([getopt])
38
 
  AC_LIBOBJ([getopt1])
39
 
  gl_PREREQ_GETOPT
40
 
])
41
 
 
42
41
# emacs' configure.in uses this.
43
42
AC_DEFUN([gl_GETOPT_IFELSE],
44
43
[
88
87
    AC_CACHE_CHECK([whether getopt is POSIX compatible],
89
88
      [gl_cv_func_getopt_posix],
90
89
      [
91
 
        dnl BSD getopt_long uses an incompatible method to reset
92
 
        dnl option processing.  Existence of the variable, in and of
 
90
        dnl BSD getopt_long uses an incompatible method to reset option
 
91
        dnl processing.  Existence of the optreset variable, in and of
93
92
        dnl itself, is not a reason to replace getopt, but knowledge
94
93
        dnl of the variable is needed to determine how to reset and
95
94
        dnl whether a reset reparses the environment.  Solaris
96
95
        dnl supports neither optreset nor optind=0, but keeps no state
97
96
        dnl that needs a reset beyond setting optind=1; detect Solaris
98
97
        dnl by getopt_clip.
99
 
        AC_COMPILE_IFELSE(
 
98
        AC_LINK_IFELSE(
100
99
          [AC_LANG_PROGRAM(
101
100
             [[#include <unistd.h>]],
102
101
             [[int *p = &optreset; return optreset;]])],
120
119
main ()
121
120
{
122
121
  {
123
 
    int argc = 0;
124
 
    char *argv[10];
 
122
    static char program[] = "program";
 
123
    static char a[] = "-a";
 
124
    static char foo[] = "foo";
 
125
    static char bar[] = "bar";
 
126
    char *argv[] = { program, a, foo, bar, NULL };
125
127
    int c;
126
128
 
127
 
    argv[argc++] = "program";
128
 
    argv[argc++] = "-a";
129
 
    argv[argc++] = "foo";
130
 
    argv[argc++] = "bar";
131
 
    argv[argc] = NULL;
132
129
    optind = OPTIND_MIN;
133
130
    opterr = 0;
134
131
 
135
 
    c = getopt (argc, argv, "ab");
 
132
    c = getopt (4, argv, "ab");
136
133
    if (!(c == 'a'))
137
134
      return 1;
138
 
    c = getopt (argc, argv, "ab");
 
135
    c = getopt (4, argv, "ab");
139
136
    if (!(c == -1))
140
137
      return 2;
141
138
    if (!(optind == 2))
143
140
  }
144
141
  /* Some internal state exists at this point.  */
145
142
  {
146
 
    int argc = 0;
147
 
    char *argv[10];
 
143
    static char program[] = "program";
 
144
    static char donald[] = "donald";
 
145
    static char p[] = "-p";
 
146
    static char billy[] = "billy";
 
147
    static char duck[] = "duck";
 
148
    static char a[] = "-a";
 
149
    static char bar[] = "bar";
 
150
    char *argv[] = { program, donald, p, billy, duck, a, bar, NULL };
148
151
    int c;
149
152
 
150
 
    argv[argc++] = "program";
151
 
    argv[argc++] = "donald";
152
 
    argv[argc++] = "-p";
153
 
    argv[argc++] = "billy";
154
 
    argv[argc++] = "duck";
155
 
    argv[argc++] = "-a";
156
 
    argv[argc++] = "bar";
157
 
    argv[argc] = NULL;
158
153
    optind = OPTIND_MIN;
159
154
    opterr = 0;
160
155
 
161
 
    c = getopt (argc, argv, "+abp:q:");
 
156
    c = getopt (7, argv, "+abp:q:");
162
157
    if (!(c == -1))
163
158
      return 4;
164
159
    if (!(strcmp (argv[0], "program") == 0))
180
175
  }
181
176
  /* Detect MacOS 10.5, AIX 7.1 bug.  */
182
177
  {
183
 
    char *argv[3] = { "program", "-ab", NULL };
 
178
    static char program[] = "program";
 
179
    static char ab[] = "-ab";
 
180
    char *argv[3] = { program, ab, NULL };
184
181
    optind = OPTIND_MIN;
185
182
    opterr = 0;
186
183
    if (getopt (2, argv, "ab:") != 'a')
232
229
        [AC_LANG_PROGRAM([[#include <getopt.h>
233
230
                           #include <stddef.h>
234
231
                           #include <string.h>
 
232
           ]GL_NOCRASH[
235
233
           ]], [[
236
234
             int result = 0;
 
235
 
 
236
             nocrash_init();
 
237
 
237
238
             /* This code succeeds on glibc 2.8, OpenBSD 4.0, Cygwin, mingw,
238
239
                and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5,
239
240
                OSF/1 5.1, Solaris 10.  */
240
241
             {
241
 
               char *myargv[3];
242
 
               myargv[0] = "conftest";
243
 
               myargv[1] = "-+";
244
 
               myargv[2] = 0;
 
242
               static char conftest[] = "conftest";
 
243
               static char plus[] = "-+";
 
244
               char *argv[3] = { conftest, plus, NULL };
245
245
               opterr = 0;
246
 
               if (getopt (2, myargv, "+a") != '?')
 
246
               if (getopt (2, argv, "+a") != '?')
247
247
                 result |= 1;
248
248
             }
249
249
             /* This code succeeds on glibc 2.8, mingw,
250
250
                and fails on MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11,
251
251
                IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x.  */
252
252
             {
253
 
               char *argv[] = { "program", "-p", "foo", "bar", NULL };
 
253
               static char program[] = "program";
 
254
               static char p[] = "-p";
 
255
               static char foo[] = "foo";
 
256
               static char bar[] = "bar";
 
257
               char *argv[] = { program, p, foo, bar, NULL };
254
258
 
255
259
               optind = 1;
256
260
               if (getopt (4, argv, "p::") != 'p')
264
268
             }
265
269
             /* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0.  */
266
270
             {
267
 
               char *argv[] = { "program", "foo", "-p", NULL };
 
271
               static char program[] = "program";
 
272
               static char foo[] = "foo";
 
273
               static char p[] = "-p";
 
274
               char *argv[] = { program, foo, p, NULL };
268
275
               optind = 0;
269
276
               if (getopt (3, argv, "-p") != 1)
270
277
                 result |= 16;
273
280
             }
274
281
             /* This code fails on glibc 2.11.  */
275
282
             {
276
 
               char *argv[] = { "program", "-b", "-a", NULL };
 
283
               static char program[] = "program";
 
284
               static char b[] = "-b";
 
285
               static char a[] = "-a";
 
286
               char *argv[] = { program, b, a, NULL };
277
287
               optind = opterr = 0;
278
288
               if (getopt (3, argv, "+:a:b") != 'b')
279
289
                 result |= 64;
280
290
               else if (getopt (3, argv, "+:a:b") != ':')
281
291
                 result |= 64;
282
292
             }
 
293
             /* This code dumps core on glibc 2.14.  */
 
294
             {
 
295
               static char program[] = "program";
 
296
               static char w[] = "-W";
 
297
               static char dummy[] = "dummy";
 
298
               char *argv[] = { program, w, dummy, NULL };
 
299
               optind = opterr = 1;
 
300
               if (getopt (3, argv, "W;") != 'W')
 
301
                 result |= 128;
 
302
             }
283
303
             return result;
284
304
           ]])],
285
305
        [gl_cv_func_getopt_gnu=yes],