attempting to get rid of compiler warnings on every _single_ damn module,
authorLuke Leighton <lkcl@samba.org>
Fri, 31 Mar 2000 00:27:21 +0000 (00:27 +0000)
committerLuke Leighton <lkcl@samba.org>
Fri, 31 Mar 2000 00:27:21 +0000 (00:27 +0000)
because of a declaration of int getopt(), on sparc (which doesn't have
a working getopt()).

source/Makefile.in
source/include/lib_smb_proto.h
source/include/proto.h
source/lib/getopt.c
source/lib/getopt.h

index 88401722a98b138338bdc02006a0e6d3a09fe4a5..6c7d7f833eb4567cb13f6c14f2013915bf1caf04 100644 (file)
@@ -111,7 +111,7 @@ SPROGS = bin/smbd bin/lsarpcd bin/svcctld bin/spoolssd bin/samrd \
          bin/nmbd bin/swat
 PROGS1 = bin/smbclient bin/testparm bin/testprns bin/smbrun bin/smbstatus 
 PROGS2 = bin/rpcclient bin/smbpasswd bin/make_smbcodepage bin/debug2html 
-PROGS3 = bin/regedit bin/samedit bin/net bin/svccontrol bin/cmdat bin/ntprint
+PROGS3 = bin/regedit bin/samedit bin/net bin/svccontrol bin/cmdat bin/ntspool
 PROGS4 = @WRAP@ @WRAP32@
 #MPROGS = @MPROGS@
 PROGS = $(PROGS1) $(PROGS2) $(PROGS3) $(PROGS4) $(MPROGS) bin/nmblookup bin/make_printerdef 
@@ -983,7 +983,7 @@ bin/rpctorture: $(RPCTORTURE_LIBS) $(RPCTORTURE_OBJ) bin/.dummy
        @echo Linking $@
        @$(LINK) -o $@ $(RPCTORTURE_OBJ) $(RPCTORTURE_LIBS) $(LIBS)
 
-bin/ntprint: $(SPOOLCLIENT_LIBS) $(SPOOLCLIENT_OBJ) bin/.dummy
+bin/ntspool: $(SPOOLCLIENT_LIBS) $(SPOOLCLIENT_OBJ) bin/.dummy
        @echo Linking $@
        @$(LINK) -o $@ $(SPOOLCLIENT_OBJ) $(SPOOLCLIENT_LIBS) $(LIBS)
 
index 2682333c5d3996bc2ee17d5ca31f2e0dcfc9857e..4ea69a148b6f9e46ba9a2def9efa1b4c6658b3e4 100644 (file)
@@ -161,8 +161,7 @@ const char *get_nt_error_msg(uint32 nt_code);
 
 void pwd_init(struct pwd_info *pwd);
 BOOL pwd_is_nullpwd(const struct pwd_info *pwd);
-void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key);
-BOOL pwd_compare(const struct pwd_info *_pwd1, const struct pwd_info *_pwd2);
+BOOL pwd_compare(const struct pwd_info *pwd1, const struct pwd_info *pwd2);
 void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt);
 void pwd_set_nullpwd(struct pwd_info *pwd);
 void pwd_set_cleartext(struct pwd_info *pwd, char *clr);
@@ -191,7 +190,7 @@ void cred_hash1(uchar *out, const uchar *in, const uchar *key);
 void cred_hash2(uchar *out,uchar *in,uchar *key);
 void cred_hash3(uchar *out, const uchar *in,uchar *key, int forw);
 void SamOEMhash( uchar *data, const uchar *key, int val);
-void sam_pwd_hash(uint32 rid, const uchar *in, uchar *out, int forw);
+void sam_pwd_hash(unsigned int rid, const uchar *in, uchar *out, int forw);
 
 /*The following definitions come from  libsmb/smbencrypt.c  */
 
index 90b3f4cd73c4e92ee8a628b04530f6e3af35d10c..5b14e4bc9b8341d0b3ced04f279ee840e3b91658 100644 (file)
@@ -262,6 +262,10 @@ void generate_random_buffer( unsigned char *out, int len, BOOL re_seed);
 
 /*The following definitions come from  lib/getopt.c  */
 
+int getopt(int argc, char *const *argv, const char *optstring);
+int getopt_long(int argc, char *const *argv, const char *options,
+               const struct option *long_options, int *opt_index);
+void getopt_dummy(void);
 
 /*The following definitions come from  lib/getsmbpass.c  */
 
@@ -586,8 +590,7 @@ BOOL remote_password_change(const char *remote_machine, const char *user_name,
 
 void pwd_init(struct pwd_info *pwd);
 BOOL pwd_is_nullpwd(const struct pwd_info *pwd);
-void pwd_obfuscate_key(struct pwd_info *pwd, uint32 int_key, char *str_key);
-BOOL pwd_compare(const struct pwd_info *_pwd1, const struct pwd_info *_pwd2);
+BOOL pwd_compare(const struct pwd_info *pwd1, const struct pwd_info *pwd2);
 void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt);
 void pwd_set_nullpwd(struct pwd_info *pwd);
 void pwd_set_cleartext(struct pwd_info *pwd, char *clr);
@@ -620,7 +623,7 @@ void cred_hash1(uchar *out, const uchar *in, const uchar *key);
 void cred_hash2(uchar *out,uchar *in,uchar *key);
 void cred_hash3(uchar *out, const uchar *in,uchar *key, int forw);
 void SamOEMhash( uchar *data, const uchar *key, int val);
-void sam_pwd_hash(uint32 rid, const uchar *in, uchar *out, int forw);
+void sam_pwd_hash(unsigned int rid, const uchar *in, uchar *out, int forw);
 
 /*The following definitions come from  libsmb/smbencrypt.c  */
 
index cc9798429da785fcfe9caf2845e518d21356e014..3785cb200fdc9bf84795a3be5ebb347d1a49ff1c 100644 (file)
@@ -1,5 +1,6 @@
-#include "includes.h"
 #ifndef HAVE_GETOPT_LONG
+#include "getopt.h"
+#include <stdio.h>
 
 /* Getopt for GNU.
    NOTE: getopt is now part of the C library, so if you don't know what
@@ -135,8 +136,9 @@ int optopt = '?';
 
 static enum
 {
-  REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
-} ordering;
+       REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
+}
+ordering;
 
 /* Value of POSIXLY_CORRECT environment variable.  */
 static char *posixly_correct;
@@ -153,20 +155,19 @@ static char *posixly_correct;
 /* Avoid depending on library functions or files
    whose names are inconsistent.  */
 
-char *getenv ();
+char *getenv();
 
-static char *
-my_index (str, chr)
+static char *my_index(str, chr)
      const char *str;
      int chr;
 {
-  while (*str)
-    {
-      if (*str == chr)
-       return (char *) str;
-      str++;
-    }
-  return 0;
+       while (*str)
+       {
+               if (*str == chr)
+                       return (char *)str;
+               str++;
+       }
+       return 0;
 }
 
 /* If using GCC, we can safely declare strlen this way.
@@ -177,7 +178,7 @@ my_index (str, chr)
 #if !defined (__STDC__) || !__STDC__
 /* gcc with -traditional declares the built-in strlen to return int,
    and has done so at least since version 2.4.5. -- rms.  */
-extern int strlen (const char *);
+extern int strlen(const char *);
 #endif /* not __STDC__ */
 #endif /* __GNUC__ */
 
@@ -201,96 +202,95 @@ static int last_nonopt;
    `first_nonopt' and `last_nonopt' are relocated so that they describe
    the new indices of the non-options in ARGV after they are moved.  */
 
-static void
-exchange (argv)
+static void exchange(argv)
      char **argv;
 {
-  int bottom = first_nonopt;
-  int middle = last_nonopt;
-  int top = optind;
-  char *tem;
-
-  /* Exchange the shorter segment with the far end of the longer segment.
-     That puts the shorter segment into the right place.
-     It leaves the longer segment in the right place overall,
-     but it consists of two parts that need to be swapped next.  */
-
-  while (top > middle && middle > bottom)
-    {
-      if (top - middle > middle - bottom)
-       {
-         /* Bottom segment is the short one.  */
-         int len = middle - bottom;
-         register int i;
-
-         /* Swap it with the top part of the top segment.  */
-         for (i = 0; i < len; i++)
-           {
-             tem = argv[bottom + i];
-             argv[bottom + i] = argv[top - (middle - bottom) + i];
-             argv[top - (middle - bottom) + i] = tem;
-           }
-         /* Exclude the moved bottom segment from further swapping.  */
-         top -= len;
-       }
-      else
+       int bottom = first_nonopt;
+       int middle = last_nonopt;
+       int top = optind;
+       char *tem;
+
+       /* Exchange the shorter segment with the far end of the longer segment.
+          That puts the shorter segment into the right place.
+          It leaves the longer segment in the right place overall,
+          but it consists of two parts that need to be swapped next.  */
+
+       while (top > middle && middle > bottom)
        {
-         /* Top segment is the short one.  */
-         int len = top - middle;
-         register int i;
-
-         /* Swap it with the bottom part of the bottom segment.  */
-         for (i = 0; i < len; i++)
-           {
-             tem = argv[bottom + i];
-             argv[bottom + i] = argv[middle + i];
-             argv[middle + i] = tem;
-           }
-         /* Exclude the moved top segment from further swapping.  */
-         bottom += len;
+               if (top - middle > middle - bottom)
+               {
+                       /* Bottom segment is the short one.  */
+                       int len = middle - bottom;
+                       register int i;
+
+                       /* Swap it with the top part of the top segment.  */
+                       for (i = 0; i < len; i++)
+                       {
+                               tem = argv[bottom + i];
+                               argv[bottom + i] =
+                                       argv[top - (middle - bottom) + i];
+                               argv[top - (middle - bottom) + i] = tem;
+                       }
+                       /* Exclude the moved bottom segment from further swapping.  */
+                       top -= len;
+               }
+               else
+               {
+                       /* Top segment is the short one.  */
+                       int len = top - middle;
+                       register int i;
+
+                       /* Swap it with the bottom part of the bottom segment.  */
+                       for (i = 0; i < len; i++)
+                       {
+                               tem = argv[bottom + i];
+                               argv[bottom + i] = argv[middle + i];
+                               argv[middle + i] = tem;
+                       }
+                       /* Exclude the moved top segment from further swapping.  */
+                       bottom += len;
+               }
        }
-    }
 
-  /* Update records for the slots the non-options now occupy.  */
+       /* Update records for the slots the non-options now occupy.  */
 
-  first_nonopt += (optind - last_nonopt);
-  last_nonopt = optind;
+       first_nonopt += (optind - last_nonopt);
+       last_nonopt = optind;
 }
 
 /* Initialize the internal data when the first call is made.  */
 
-static const char *
-_getopt_initialize (optstring)
+static const char *_getopt_initialize(optstring)
      const char *optstring;
 {
-  /* Start processing options with ARGV-element 1 (since ARGV-element 0
-     is the program name); the sequence of previously skipped
-     non-option ARGV-elements is empty.  */
-
-  first_nonopt = last_nonopt = optind = 1;
-
-  nextchar = NULL;
-
-  posixly_correct = getenv ("POSIXLY_CORRECT");
-
-  /* Determine how to handle the ordering of options and nonoptions.  */
-
-  if (optstring[0] == '-')
-    {
-      ordering = RETURN_IN_ORDER;
-      ++optstring;
-    }
-  else if (optstring[0] == '+')
-    {
-      ordering = REQUIRE_ORDER;
-      ++optstring;
-    }
-  else if (posixly_correct != NULL)
-    ordering = REQUIRE_ORDER;
-  else
-    ordering = PERMUTE;
-
-  return optstring;
+       /* Start processing options with ARGV-element 1 (since ARGV-element 0
+          is the program name); the sequence of previously skipped
+          non-option ARGV-elements is empty.  */
+
+       first_nonopt = last_nonopt = optind = 1;
+
+       nextchar = NULL;
+
+       posixly_correct = getenv("POSIXLY_CORRECT");
+
+       /* Determine how to handle the ordering of options and nonoptions.  */
+
+       if (optstring[0] == '-')
+       {
+               ordering = RETURN_IN_ORDER;
+               ++optstring;
+       }
+       else if (optstring[0] == '+')
+       {
+               ordering = REQUIRE_ORDER;
+               ++optstring;
+       }
+       else if (posixly_correct != NULL)
+               ordering = REQUIRE_ORDER;
+       else
+               ordering = PERMUTE;
+
+       return optstring;
 }
 
 /* Scan elements of ARGV (whose length is ARGC) for option characters
@@ -349,8 +349,7 @@ _getopt_initialize (optstring)
    If LONG_ONLY is nonzero, '-' as well as '--' can introduce
    long-named options.  */
 
-int
-_getopt_internal (argc, argv, optstring, longopts, longind, long_only)
+static int _getopt_internal(argc, argv, optstring, longopts, longind, long_only)
      int argc;
      char *const *argv;
      const char *optstring;
@@ -358,395 +357,418 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
      int *longind;
      int long_only;
 {
-  optarg = NULL;
+       optarg = NULL;
 
-  if (optind == 0)
-    optstring = _getopt_initialize (optstring);
+       if (optind == 0)
+               optstring = _getopt_initialize(optstring);
 
-  if (nextchar == NULL || *nextchar == '\0')
-    {
-      /* Advance to the next ARGV-element.  */
-
-      if (ordering == PERMUTE)
+       if (nextchar == NULL || *nextchar == '\0')
        {
-         /* If we have just processed some options following some non-options,
-            exchange them so that the options come first.  */
+               /* Advance to the next ARGV-element.  */
 
-         if (first_nonopt != last_nonopt && last_nonopt != optind)
-           exchange ((char **) argv);
-         else if (last_nonopt != optind)
-           first_nonopt = optind;
+               if (ordering == PERMUTE)
+               {
+                       /* If we have just processed some options following some non-options,
+                          exchange them so that the options come first.  */
+
+                       if (first_nonopt != last_nonopt
+                           && last_nonopt != optind)
+                               exchange((char **)argv);
+                       else if (last_nonopt != optind)
+                               first_nonopt = optind;
+
+                       /* Skip any additional non-options
+                          and extend the range of non-options previously skipped.  */
+
+                       while (optind < argc
+                              && (argv[optind][0] != '-'
+                                  || argv[optind][1] == '\0'))
+                               optind++;
+                       last_nonopt = optind;
+               }
 
-         /* Skip any additional non-options
-            and extend the range of non-options previously skipped.  */
+               /* The special ARGV-element `--' means premature end of options.
+                  Skip it like a null option,
+                  then exchange with previous non-options as if it were an option,
+                  then skip everything else like a non-option.  */
 
-         while (optind < argc
-                && (argv[optind][0] != '-' || argv[optind][1] == '\0'))
-           optind++;
-         last_nonopt = optind;
-       }
+               if (optind != argc && !strcmp(argv[optind], "--"))
+               {
+                       optind++;
 
-      /* The special ARGV-element `--' means premature end of options.
-        Skip it like a null option,
-        then exchange with previous non-options as if it were an option,
-        then skip everything else like a non-option.  */
+                       if (first_nonopt != last_nonopt
+                           && last_nonopt != optind)
+                               exchange((char **)argv);
+                       else if (first_nonopt == last_nonopt)
+                               first_nonopt = optind;
+                       last_nonopt = argc;
 
-      if (optind != argc && !strcmp (argv[optind], "--"))
-       {
-         optind++;
+                       optind = argc;
+               }
 
-         if (first_nonopt != last_nonopt && last_nonopt != optind)
-           exchange ((char **) argv);
-         else if (first_nonopt == last_nonopt)
-           first_nonopt = optind;
-         last_nonopt = argc;
+               /* If we have done all the ARGV-elements, stop the scan
+                  and back over any non-options that we skipped and permuted.  */
 
-         optind = argc;
-       }
+               if (optind == argc)
+               {
+                       /* Set the next-arg-index to point at the non-options
+                          that we previously skipped, so the caller will digest them.  */
+                       if (first_nonopt != last_nonopt)
+                               optind = first_nonopt;
+                       return EOF;
+               }
 
-      /* If we have done all the ARGV-elements, stop the scan
-        and back over any non-options that we skipped and permuted.  */
+               /* If we have come to a non-option and did not permute it,
+                  either stop the scan or describe it to the caller and pass it by.  */
 
-      if (optind == argc)
-       {
-         /* Set the next-arg-index to point at the non-options
-            that we previously skipped, so the caller will digest them.  */
-         if (first_nonopt != last_nonopt)
-           optind = first_nonopt;
-         return EOF;
-       }
+               if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
+               {
+                       if (ordering == REQUIRE_ORDER)
+                               return EOF;
+                       optarg = argv[optind++];
+                       return 1;
+               }
 
-      /* If we have come to a non-option and did not permute it,
-        either stop the scan or describe it to the caller and pass it by.  */
+               /* We have found another option-ARGV-element.
+                  Skip the initial punctuation.  */
 
-      if ((argv[optind][0] != '-' || argv[optind][1] == '\0'))
-       {
-         if (ordering == REQUIRE_ORDER)
-           return EOF;
-         optarg = argv[optind++];
-         return 1;
+               nextchar = (argv[optind] + 1
+                           + (longopts != NULL && argv[optind][1] == '-'));
        }
 
-      /* We have found another option-ARGV-element.
-        Skip the initial punctuation.  */
-
-      nextchar = (argv[optind] + 1
-                 + (longopts != NULL && argv[optind][1] == '-'));
-    }
-
-  /* Decode the current option-ARGV-element.  */
-
-  /* Check whether the ARGV-element is a long option.
-
-     If long_only and the ARGV-element has the form "-f", where f is
-     a valid short option, don't consider it an abbreviated form of
-     a long option that starts with f.  Otherwise there would be no
-     way to give the -f short option.
-
-     On the other hand, if there's a long option "fubar" and
-     the ARGV-element is "-fu", do consider that an abbreviation of
-     the long option, just like "--fu", and not "-f" with arg "u".
-
-     This distinction seems to be the most useful approach.  */
-
-  if (longopts != NULL
-      && (argv[optind][1] == '-'
-         || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))
-    {
-      char *nameend;
-      const struct option *p;
-      const struct option *pfound = NULL;
-      int exact = 0;
-      int ambig = 0;
-      int indfound;
-      int option_index;
-
-      for (nameend = nextchar; *nameend && *nameend != '='; nameend++)
-       /* Do nothing.  */ ;
-
-      /* Test all long options for either exact match
-        or abbreviated matches.  */
-      for (p = longopts, option_index = 0; p->name; p++, option_index++)
-       if (!strncmp (p->name, nextchar, nameend - nextchar))
-         {
-           if (nameend - nextchar == strlen (p->name))
-             {
-               /* Exact match found.  */
-               pfound = p;
-               indfound = option_index;
-               exact = 1;
-               break;
-             }
-           else if (pfound == NULL)
-             {
-               /* First nonexact match found.  */
-               pfound = p;
-               indfound = option_index;
-             }
-           else
-             /* Second or later nonexact match found.  */
-             ambig = 1;
-         }
-
-      if (ambig && !exact)
-       {
-         if (opterr)
-           fprintf (stderr, gettext ("%s: option `%s' is ambiguous\n"),
-                    argv[0], argv[optind]);
-         nextchar += strlen (nextchar);
-         optind++;
-         return '?';
-       }
+       /* Decode the current option-ARGV-element.  */
+
+       /* Check whether the ARGV-element is a long option.
 
-      if (pfound != NULL)
+          If long_only and the ARGV-element has the form "-f", where f is
+          a valid short option, don't consider it an abbreviated form of
+          a long option that starts with f.  Otherwise there would be no
+          way to give the -f short option.
+
+          On the other hand, if there's a long option "fubar" and
+          the ARGV-element is "-fu", do consider that an abbreviation of
+          the long option, just like "--fu", and not "-f" with arg "u".
+
+          This distinction seems to be the most useful approach.  */
+
+       if (longopts != NULL
+           && (argv[optind][1] == '-'
+               || (long_only
+                   && (argv[optind][2]
+                       || !my_index(optstring, argv[optind][1])))))
        {
-         option_index = indfound;
-         optind++;
-         if (*nameend)
-           {
-             /* Don't test has_arg with >, because some C compilers don't
-                allow it to be used on enums.  */
-             if (pfound->has_arg)
-               optarg = nameend + 1;
-             else
+               char *nameend;
+               const struct option *p;
+               const struct option *pfound = NULL;
+               int exact = 0;
+               int ambig = 0;
+               int indfound;
+               int option_index;
+
+               for (nameend = nextchar; *nameend && *nameend != '=';
+                    nameend++)
+                       /* Do nothing.  */ ;
+
+               /* Test all long options for either exact match
+                  or abbreviated matches.  */
+               for (p = longopts, option_index = 0; p->name;
+                    p++, option_index++)
+                       if (!strncmp(p->name, nextchar, nameend - nextchar))
+                       {
+                               if (nameend - nextchar == strlen(p->name))
+                               {
+                                       /* Exact match found.  */
+                                       pfound = p;
+                                       indfound = option_index;
+                                       exact = 1;
+                                       break;
+                               }
+                               else if (pfound == NULL)
+                               {
+                                       /* First nonexact match found.  */
+                                       pfound = p;
+                                       indfound = option_index;
+                               }
+                               else
+                                       /* Second or later nonexact match found.  */
+                                       ambig = 1;
+                       }
+
+               if (ambig && !exact)
+               {
+                       if (opterr)
+                               fprintf(stderr,
+                                       gettext
+                                       ("%s: option `%s' is ambiguous\n"),
+                                       argv[0], argv[optind]);
+                       nextchar += strlen(nextchar);
+                       optind++;
+                       return '?';
+               }
+
+               if (pfound != NULL)
                {
-                 if (opterr)
-                  if (argv[optind - 1][1] == '-')
-                   /* --option */
-                   fprintf (stderr,
-                    gettext ("%s: option `--%s' doesn't allow an argument\n"),
-                    argv[0], pfound->name);
-                  else
-                   /* +option or -option */
-                   fprintf (stderr,
-                    gettext ("%s: option `%c%s' doesn't allow an argument\n"),
-                    argv[0], argv[optind - 1][0], pfound->name);
-
-                 nextchar += strlen (nextchar);
-                 return '?';
+                       option_index = indfound;
+                       optind++;
+                       if (*nameend)
+                       {
+                               /* Don't test has_arg with >, because some C compilers don't
+                                  allow it to be used on enums.  */
+                               if (pfound->has_arg)
+                                       optarg = nameend + 1;
+                               else
+                               {
+                                       if (opterr)
+                                               if (argv[optind - 1][1] ==
+                                                   '-')
+                                                       /* --option */
+                                                       fprintf(stderr,
+                                                               gettext
+                                                               ("%s: option `--%s' doesn't allow an argument\n"),
+                                                               argv[0],
+                                                               pfound->name);
+                                               else
+                                                       /* +option or -option */
+                                                       fprintf(stderr,
+                                                               gettext
+                                                               ("%s: option `%c%s' doesn't allow an argument\n"),
+                                                               argv[0],
+                                                               argv[optind -
+                                                                    1][0],
+                                                               pfound->name);
+
+                                       nextchar += strlen(nextchar);
+                                       return '?';
+                               }
+                       }
+                       else if (pfound->has_arg == 1)
+                       {
+                               if (optind < argc)
+                                       optarg = argv[optind++];
+                               else
+                               {
+                                       if (opterr)
+                                               fprintf(stderr,
+                                                       gettext
+                                                       ("%s: option `%s' requires an argument\n"),
+                                                       argv[0],
+                                                       argv[optind - 1]);
+                                       nextchar += strlen(nextchar);
+                                       return optstring[0] ==
+                                               ':' ? ':' : '?';
+                               }
+                       }
+                       nextchar += strlen(nextchar);
+                       if (longind != NULL)
+                               *longind = option_index;
+                       if (pfound->flag)
+                       {
+                               *(pfound->flag) = pfound->val;
+                               return 0;
+                       }
+                       return pfound->val;
                }
-           }
-         else if (pfound->has_arg == 1)
-           {
-             if (optind < argc)
-               optarg = argv[optind++];
-             else
+
+               /* Can't find it as a long option.  If this is not getopt_long_only,
+                  or the option starts with '--' or is not a valid short
+                  option, then it's an error.
+                  Otherwise interpret it as a short option.  */
+               if (!long_only || argv[optind][1] == '-'
+                   || my_index(optstring, *nextchar) == NULL)
                {
-                 if (opterr)
-                   fprintf (stderr,
-                          gettext ("%s: option `%s' requires an argument\n"),
-                          argv[0], argv[optind - 1]);
-                 nextchar += strlen (nextchar);
-                 return optstring[0] == ':' ? ':' : '?';
+                       if (opterr)
+                       {
+                               if (argv[optind][1] == '-')
+                                       /* --option */
+                                       fprintf(stderr,
+                                               gettext
+                                               ("%s: unrecognized option `--%s'\n"),
+                                               argv[0], nextchar);
+                               else
+                                       /* +option or -option */
+                                       fprintf(stderr,
+                                               gettext
+                                               ("%s: unrecognized option `%c%s'\n"),
+                                               argv[0], argv[optind][0],
+                                               nextchar);
+                       }
+                       nextchar = (char *)"";
+                       optind++;
+                       return '?';
                }
-           }
-         nextchar += strlen (nextchar);
-         if (longind != NULL)
-           *longind = option_index;
-         if (pfound->flag)
-           {
-             *(pfound->flag) = pfound->val;
-             return 0;
-           }
-         return pfound->val;
        }
 
-      /* Can't find it as a long option.  If this is not getopt_long_only,
-        or the option starts with '--' or is not a valid short
-        option, then it's an error.
-        Otherwise interpret it as a short option.  */
-      if (!long_only || argv[optind][1] == '-'
-         || my_index (optstring, *nextchar) == NULL)
+       /* Look at and handle the next short option-character.  */
+
        {
-         if (opterr)
-           {
-             if (argv[optind][1] == '-')
-               /* --option */
-               fprintf (stderr, gettext ("%s: unrecognized option `--%s'\n"),
-                        argv[0], nextchar);
-             else
-               /* +option or -option */
-               fprintf (stderr, gettext ("%s: unrecognized option `%c%s'\n"),
-                        argv[0], argv[optind][0], nextchar);
-           }
-         nextchar = (char *) "";
-         optind++;
-         return '?';
+               char c = *nextchar++;
+               char *temp = my_index(optstring, c);
+
+               /* Increment `optind' when we start to process its last character.  */
+               if (*nextchar == '\0')
+                       ++optind;
+
+               if (temp == NULL || c == ':')
+               {
+                       if (opterr)
+                       {
+                               if (posixly_correct)
+                                       /* 1003.2 specifies the format of this message.  */
+                                       fprintf(stderr,
+                                               gettext
+                                               ("%s: illegal option -- %c\n"),
+                                               argv[0], c);
+                               else
+                                       fprintf(stderr,
+                                               gettext
+                                               ("%s: invalid option -- %c\n"),
+                                               argv[0], c);
+                       }
+                       optopt = c;
+                       return '?';
+               }
+               if (temp[1] == ':')
+               {
+                       if (temp[2] == ':')
+                       {
+                               /* This is an option that accepts an argument optionally.  */
+                               if (*nextchar != '\0')
+                               {
+                                       optarg = nextchar;
+                                       optind++;
+                               }
+                               else
+                                       optarg = NULL;
+                               nextchar = NULL;
+                       }
+                       else
+                       {
+                               /* This is an option that requires an argument.  */
+                               if (*nextchar != '\0')
+                               {
+                                       optarg = nextchar;
+                                       /* If we end this ARGV-element by taking the rest as an arg,
+                                          we must advance to the next element now.  */
+                                       optind++;
+                               }
+                               else if (optind == argc)
+                               {
+                                       if (opterr)
+                                       {
+                                               /* 1003.2 specifies the format of this message.  */
+                                               fprintf(stderr,
+                                                       gettext
+                                                       ("%s: option requires an argument -- %c\n"),
+                                                       argv[0], c);
+                                       }
+                                       optopt = c;
+                                       if (optstring[0] == ':')
+                                               c = ':';
+                                       else
+                                               c = '?';
+                               }
+                               else
+                                       /* We already incremented `optind' once;
+                                          increment it again when taking next ARGV-elt as argument.  */
+                                       optarg = argv[optind++];
+                               nextchar = NULL;
+                       }
+               }
+               return c;
        }
-    }
-
-  /* Look at and handle the next short option-character.  */
-
-  {
-    char c = *nextchar++;
-    char *temp = my_index (optstring, c);
-
-    /* Increment `optind' when we start to process its last character.  */
-    if (*nextchar == '\0')
-      ++optind;
-
-    if (temp == NULL || c == ':')
-      {
-       if (opterr)
-         {
-           if (posixly_correct)
-             /* 1003.2 specifies the format of this message.  */
-             fprintf (stderr, gettext ("%s: illegal option -- %c\n"),
-                      argv[0], c);
-           else
-             fprintf (stderr, gettext ("%s: invalid option -- %c\n"),
-                      argv[0], c);
-         }
-       optopt = c;
-       return '?';
-      }
-    if (temp[1] == ':')
-      {
-       if (temp[2] == ':')
-         {
-           /* This is an option that accepts an argument optionally.  */
-           if (*nextchar != '\0')
-             {
-               optarg = nextchar;
-               optind++;
-             }
-           else
-             optarg = NULL;
-           nextchar = NULL;
-         }
-       else
-         {
-           /* This is an option that requires an argument.  */
-           if (*nextchar != '\0')
-             {
-               optarg = nextchar;
-               /* If we end this ARGV-element by taking the rest as an arg,
-                  we must advance to the next element now.  */
-               optind++;
-             }
-           else if (optind == argc)
-             {
-               if (opterr)
-                 {
-                   /* 1003.2 specifies the format of this message.  */
-                   fprintf (stderr,
-                          gettext ("%s: option requires an argument -- %c\n"),
-                          argv[0], c);
-                 }
-               optopt = c;
-               if (optstring[0] == ':')
-                 c = ':';
-               else
-                 c = '?';
-             }
-           else
-             /* We already incremented `optind' once;
-                increment it again when taking next ARGV-elt as argument.  */
-             optarg = argv[optind++];
-           nextchar = NULL;
-         }
-      }
-    return c;
-  }
 }
 
-int
-getopt (argc, argv, optstring)
-     int argc;
-     char *const *argv;
-     const char *optstring;
+int getopt(int argc, char *const *argv, const char *optstring)
 {
-  return _getopt_internal (argc, argv, optstring,
-                          (const struct option *) 0,
-                          (int *) 0,
-                          0);
+       return _getopt_internal(argc, argv, optstring,
+                               (const struct option *)0, (int *)0, 0);
 }
 
-int
-getopt_long (argc, argv, options, long_options, opt_index)
-     int argc;
-     char *const *argv;
-     const char *options;
-     const struct option *long_options;
-     int *opt_index;
+int getopt_long(int argc, char *const *argv, const char *options,
+               const struct option *long_options, int *opt_index)
 {
-  return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
+       return _getopt_internal(argc, argv, options, long_options, opt_index,
+                               0);
 }
 
-#endif /* _LIBC or not __GNU_LIBRARY__.  */
+#endif /* _LIBC or not __GNU_LIBRARY__.  */
 
 #ifdef TEST
 
 /* Compile with -DTEST to make an executable for use in testing
    the above definition of `getopt'.  */
 
-int
-main (argc, argv)
+ int main(argc, argv)
      int argc;
      char **argv;
 {
-  int c;
-  int digit_optind = 0;
+       int c;
+       int digit_optind = 0;
 
-  while (1)
-    {
-      int this_option_optind = optind ? optind : 1;
+       while (1)
+       {
+               int this_option_optind = optind ? optind : 1;
 
-      c = getopt (argc, argv, "abc:d:0123456789");
-      if (c == EOF)
-       break;
+               c = getopt(argc, argv, "abc:d:0123456789");
+               if (c == EOF)
+                       break;
 
-      switch (c)
-       {
-       case '0':
-       case '1':
-       case '2':
-       case '3':
-       case '4':
-       case '5':
-       case '6':
-       case '7':
-       case '8':
-       case '9':
-         if (digit_optind != 0 && digit_optind != this_option_optind)
-           printf ("digits occur in two different argv-elements.\n");
-         digit_optind = this_option_optind;
-         printf ("option %c\n", c);
-         break;
-
-       case 'a':
-         printf ("option a\n");
-         break;
-
-       case 'b':
-         printf ("option b\n");
-         break;
-
-       case 'c':
-         printf ("option c with value `%s'\n", optarg);
-         break;
-
-       case '?':
-         break;
-
-       default:
-         printf ("?? getopt returned character code 0%o ??\n", c);
+               switch (c)
+               {
+                       case '0':
+                       case '1':
+                       case '2':
+                       case '3':
+                       case '4':
+                       case '5':
+                       case '6':
+                       case '7':
+                       case '8':
+                       case '9':
+                               if (digit_optind != 0
+                                   && digit_optind != this_option_optind)
+                                       printf
+                                               ("digits occur in two different argv-elements.\n");
+                               digit_optind = this_option_optind;
+                               printf("option %c\n", c);
+                               break;
+
+                       case 'a':
+                               printf("option a\n");
+                               break;
+
+                       case 'b':
+                               printf("option b\n");
+                               break;
+
+                       case 'c':
+                               printf("option c with value `%s'\n", optarg);
+                               break;
+
+                       case '?':
+                               break;
+
+                       default:
+                               printf
+                                       ("?? getopt returned character code 0%o ??\n",
+                                        c);
+               }
        }
-    }
 
-  if (optind < argc)
-    {
-      printf ("non-option ARGV-elements: ");
-      while (optind < argc)
-       printf ("%s ", argv[optind++]);
-      printf ("\n");
-    }
+       if (optind < argc)
+       {
+               printf("non-option ARGV-elements: ");
+               while (optind < argc)
+                       printf("%s ", argv[optind++]);
+               printf("\n");
+       }
 
-  exit (0);
+       exit(0);
 }
 
 #endif /* TEST */
-#else  /* HAVE_GETOPT_LONG */
- void getopt_dummy(void) {}
+#else /* HAVE_GETOPT_LONG */
+void getopt_dummy(void)
+{
+}
 #endif
-
index 4ac33b71824d389cbc70c9eb0f5e0b2073b28567..843a32c97868ed2c31c0917a2c7b2a58e385dc5b 100644 (file)
@@ -94,33 +94,13 @@ struct option
 #define required_argument      1
 #define optional_argument      2
 
-#if defined (__STDC__) && __STDC__
-#ifdef __GNU_LIBRARY__
-/* Many other libraries have conflicting prototypes for getopt, with
-   differences in the consts, in stdlib.h.  To avoid compilation
-   errors, only prototype getopt for the GNU C library.  */
-extern int getopt (int argc, char *const *argv, const char *shortopts);
-#else /* not __GNU_LIBRARY__ */
-extern int getopt ();
-#endif /* __GNU_LIBRARY__ */
-extern int getopt_long (int argc, char *const *argv, const char *shortopts,
-                       const struct option *longopts, int *longind);
-extern int getopt_long_only (int argc, char *const *argv,
-                            const char *shortopts,
-                            const struct option *longopts, int *longind);
-
-/* Internal only.  Users should not call this directly.  */
-extern int _getopt_internal (int argc, char *const *argv,
-                            const char *shortopts,
-                            const struct option *longopts, int *longind,
-                            int long_only);
-#else /* not __STDC__ */
-extern int getopt ();
-extern int getopt_long ();
-extern int getopt_long_only ();
-
-extern int _getopt_internal ();
-#endif /* __STDC__ */
+#ifdef STANDALONE
+/*The following definitions come from  lib/getopt.c  */
+
+int getopt(int argc, char *const *argv, const char *optstring);
+int getopt_long(int argc, char *const *argv, const char *options,
+               const struct option *long_options, int *opt_index);
+#endif
 
 #ifdef __cplusplus
 }