/[anubis]/anubis/src/getopt.c
ViewVC logotype

Diff of /anubis/src/getopt.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by polak, Thu Jan 30 10:41:02 2003 UTC revision 1.2 by polak, Fri Jun 6 09:14:22 2003 UTC
# Line 2  Line 2 
2     NOTE: getopt is now part of the C library, so if you don't know what     NOTE: getopt is now part of the C library, so if you don't know what
3     "Keep this file name-space clean" means, talk to drepper@gnu.org     "Keep this file name-space clean" means, talk to drepper@gnu.org
4     before changing it!     before changing it!
5     Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001     Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002
6          Free Software Foundation, Inc.          Free Software Foundation, Inc.
7     This file is part of the GNU C Library.     This file is part of the GNU C Library.
8    
9     The GNU C Library is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or modify
10     modify it under the terms of the GNU Lesser General Public     it under the terms of the GNU General Public License as published by
11     License as published by the Free Software Foundation; either     the Free Software Foundation; either version 2, or (at your option)
12     version 2.1 of the License, or (at your option) any later version.     any later version.
13    
14     The GNU C Library is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     Lesser General Public License for more details.     GNU General Public License for more details.
18    
19     You should have received a copy of the GNU Lesser General Public     You should have received a copy of the GNU General Public License along
20     License along with the GNU C Library; if not, write to the Free     with this program; if not, write to the Free Software Foundation,
21     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    02111-1307 USA.  */  
22    
23  /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.  /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.
24     Ditto for AIX 3.2 and <stdlib.h>.  */     Ditto for AIX 3.2 and <stdlib.h>.  */
# Line 76  Line 75 
75  # endif  # endif
76  #endif  #endif
77    
78  #ifndef _  #ifdef _LIBC
79    # include <libintl.h>
80    #else
81  /* This is for other GNU distributions with internationalized messages.  */  /* This is for other GNU distributions with internationalized messages.  */
82  # if defined HAVE_LIBINTL_H || defined _LIBC  # include "gettext.h"
83  #  include <libintl.h>  #endif
84  #  ifndef _  #define _(msgid) gettext (msgid)
85  #   define _(msgid)     gettext (msgid)  
86  #  endif  #if defined _LIBC && defined USE_IN_LIBIO
87  # else  # include <wchar.h>
88  #  define _(msgid)      (msgid)  #endif
89  # endif  
90    #ifndef attribute_hidden
91    # define attribute_hidden
92  #endif  #endif
93    
94  /* This version of `getopt' appears to the caller like standard Unix `getopt'  /* This version of `getopt' appears to the caller like standard Unix `getopt'
# Line 131  int optind = 1; Line 134  int optind = 1;
134     causes problems with re-calling getopt as programs generally don't     causes problems with re-calling getopt as programs generally don't
135     know that. */     know that. */
136    
137  int __getopt_initialized;  int __getopt_initialized attribute_hidden;
138    
139  /* The next char to be scanned in the option-element  /* The next char to be scanned in the option-element
140     in which the last option character we returned was found.     in which the last option character we returned was found.
# Line 678  _getopt_internal (argc, argv, optstring, Line 681  _getopt_internal (argc, argv, optstring,
681        if (ambig && !exact)        if (ambig && !exact)
682          {          {
683            if (print_errors)            if (print_errors)
684              fprintf (stderr, _("%s: option `%s' is ambiguous\n"),              {
685                       argv[0], argv[optind]);  #if defined _LIBC && defined USE_IN_LIBIO
686                  char *buf;
687    
688                  if (__asprintf (&buf, _("%s: option `%s' is ambiguous\n"),
689                                  argv[0], argv[optind]) >= 0)
690                    {
691    
692                      if (_IO_fwide (stderr, 0) > 0)
693                        __fwprintf (stderr, L"%s", buf);
694                      else
695                        fputs (buf, stderr);
696    
697                      free (buf);
698                    }
699    #else
700                  fprintf (stderr, _("%s: option `%s' is ambiguous\n"),
701                           argv[0], argv[optind]);
702    #endif
703                }
704            nextchar += strlen (nextchar);            nextchar += strlen (nextchar);
705            optind++;            optind++;
706            optopt = 0;            optopt = 0;
# Line 700  _getopt_internal (argc, argv, optstring, Line 721  _getopt_internal (argc, argv, optstring,
721                  {                  {
722                    if (print_errors)                    if (print_errors)
723                      {                      {
724    #if defined _LIBC && defined USE_IN_LIBIO
725                          char *buf;
726                          int n;
727    #endif
728    
729                        if (argv[optind - 1][1] == '-')                        if (argv[optind - 1][1] == '-')
730                          /* --option */                          {
731                          fprintf (stderr,                            /* --option */
732                                   _("%s: option `--%s' doesn't allow an argument\n"),  #if defined _LIBC && defined USE_IN_LIBIO
733                                   argv[0], pfound->name);                            n = __asprintf (&buf, _("\
734    %s: option `--%s' doesn't allow an argument\n"),
735                                              argv[0], pfound->name);
736    #else
737                              fprintf (stderr, _("\
738    %s: option `--%s' doesn't allow an argument\n"),
739                                       argv[0], pfound->name);
740    #endif
741                            }
742                        else                        else
743                          /* +option or -option */                          {
744                          fprintf (stderr,                            /* +option or -option */
745                                   _("%s: option `%c%s' doesn't allow an argument\n"),  #if defined _LIBC && defined USE_IN_LIBIO
746                                   argv[0], argv[optind - 1][0], pfound->name);                            n = __asprintf (&buf, _("\
747    %s: option `%c%s' doesn't allow an argument\n"),
748                                              argv[0], argv[optind - 1][0],
749                                              pfound->name);
750    #else
751                              fprintf (stderr, _("\
752    %s: option `%c%s' doesn't allow an argument\n"),
753                                       argv[0], argv[optind - 1][0], pfound->name);
754    #endif
755                            }
756    
757    #if defined _LIBC && defined USE_IN_LIBIO
758                          if (n >= 0)
759                            {
760                              if (_IO_fwide (stderr, 0) > 0)
761                                __fwprintf (stderr, L"%s", buf);
762                              else
763                                fputs (buf, stderr);
764    
765                              free (buf);
766                            }
767    #endif
768                      }                      }
769    
770                    nextchar += strlen (nextchar);                    nextchar += strlen (nextchar);
# Line 725  _getopt_internal (argc, argv, optstring, Line 780  _getopt_internal (argc, argv, optstring,
780                else                else
781                  {                  {
782                    if (print_errors)                    if (print_errors)
783                      fprintf (stderr,                      {
784                             _("%s: option `%s' requires an argument\n"),  #if defined _LIBC && defined USE_IN_LIBIO
785                             argv[0], argv[optind - 1]);                        char *buf;
786    
787                          if (__asprintf (&buf, _("\
788    %s: option `%s' requires an argument\n"),
789                                          argv[0], argv[optind - 1]) >= 0)
790                            {
791                              if (_IO_fwide (stderr, 0) > 0)
792                                __fwprintf (stderr, L"%s", buf);
793                              else
794                                fputs (buf, stderr);
795    
796                              free (buf);
797                            }
798    #else
799                          fprintf (stderr,
800                                   _("%s: option `%s' requires an argument\n"),
801                                   argv[0], argv[optind - 1]);
802    #endif
803                        }
804                    nextchar += strlen (nextchar);                    nextchar += strlen (nextchar);
805                    optopt = pfound->val;                    optopt = pfound->val;
806                    return optstring[0] == ':' ? ':' : '?';                    return optstring[0] == ':' ? ':' : '?';
# Line 753  _getopt_internal (argc, argv, optstring, Line 826  _getopt_internal (argc, argv, optstring,
826          {          {
827            if (print_errors)            if (print_errors)
828              {              {
829    #if defined _LIBC && defined USE_IN_LIBIO
830                  char *buf;
831                  int n;
832    #endif
833    
834                if (argv[optind][1] == '-')                if (argv[optind][1] == '-')
835                  /* --option */                  {
836                  fprintf (stderr, _("%s: unrecognized option `--%s'\n"),                    /* --option */
837                           argv[0], nextchar);  #if defined _LIBC && defined USE_IN_LIBIO
838                      n = __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),
839                                      argv[0], nextchar);
840    #else
841                      fprintf (stderr, _("%s: unrecognized option `--%s'\n"),
842                               argv[0], nextchar);
843    #endif
844                    }
845                else                else
846                  /* +option or -option */                  {
847                  fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),                    /* +option or -option */
848                           argv[0], argv[optind][0], nextchar);  #if defined _LIBC && defined USE_IN_LIBIO
849                      n = __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),
850                                      argv[0], argv[optind][0], nextchar);
851    #else
852                      fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),
853                               argv[0], argv[optind][0], nextchar);
854    #endif
855                    }
856    
857    #if defined _LIBC && defined USE_IN_LIBIO
858                  if (n >= 0)
859                    {
860                      if (_IO_fwide (stderr, 0) > 0)
861                        __fwprintf (stderr, L"%s", buf);
862                      else
863                        fputs (buf, stderr);
864    
865                      free (buf);
866                    }
867    #endif
868              }              }
869            nextchar = (char *) "";            nextchar = (char *) "";
870            optind++;            optind++;
# Line 783  _getopt_internal (argc, argv, optstring, Line 887  _getopt_internal (argc, argv, optstring,
887        {        {
888          if (print_errors)          if (print_errors)
889            {            {
890    #if defined _LIBC && defined USE_IN_LIBIO
891                  char *buf;
892                  int n;
893    #endif
894    
895              if (posixly_correct)              if (posixly_correct)
896                /* 1003.2 specifies the format of this message.  */                {
897                fprintf (stderr, _("%s: illegal option -- %c\n"),                  /* 1003.2 specifies the format of this message.  */
898                         argv[0], c);  #if defined _LIBC && defined USE_IN_LIBIO
899                    n = __asprintf (&buf, _("%s: illegal option -- %c\n"),
900                                    argv[0], c);
901    #else
902                    fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);
903    #endif
904                  }
905              else              else
906                fprintf (stderr, _("%s: invalid option -- %c\n"),                {
907                         argv[0], c);  #if defined _LIBC && defined USE_IN_LIBIO
908                    n = __asprintf (&buf, _("%s: invalid option -- %c\n"),
909                                    argv[0], c);
910    #else
911                    fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);
912    #endif
913                  }
914    
915    #if defined _LIBC && defined USE_IN_LIBIO
916                if (n >= 0)
917                  {
918                    if (_IO_fwide (stderr, 0) > 0)
919                      __fwprintf (stderr, L"%s", buf);
920                    else
921                      fputs (buf, stderr);
922    
923                    free (buf);
924                  }
925    #endif
926            }            }
927          optopt = c;          optopt = c;
928          return '?';          return '?';
# Line 818  _getopt_internal (argc, argv, optstring, Line 951  _getopt_internal (argc, argv, optstring,
951              if (print_errors)              if (print_errors)
952                {                {
953                  /* 1003.2 specifies the format of this message.  */                  /* 1003.2 specifies the format of this message.  */
954    #if defined _LIBC && defined USE_IN_LIBIO
955                    char *buf;
956    
957                    if (__asprintf (&buf,
958                                    _("%s: option requires an argument -- %c\n"),
959                                    argv[0], c) >= 0)
960                      {
961                        if (_IO_fwide (stderr, 0) > 0)
962                          __fwprintf (stderr, L"%s", buf);
963                        else
964                          fputs (buf, stderr);
965    
966                        free (buf);
967                      }
968    #else
969                  fprintf (stderr, _("%s: option requires an argument -- %c\n"),                  fprintf (stderr, _("%s: option requires an argument -- %c\n"),
970                           argv[0], c);                           argv[0], c);
971    #endif
972                }                }
973              optopt = c;              optopt = c;
974              if (optstring[0] == ':')              if (optstring[0] == ':')
# Line 865  _getopt_internal (argc, argv, optstring, Line 1014  _getopt_internal (argc, argv, optstring,
1014          if (ambig && !exact)          if (ambig && !exact)
1015            {            {
1016              if (print_errors)              if (print_errors)
1017                fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),                {
1018                         argv[0], argv[optind]);  #if defined _LIBC && defined USE_IN_LIBIO
1019                    char *buf;
1020    
1021                    if (__asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),
1022                                    argv[0], argv[optind]) >= 0)
1023                      {
1024                        if (_IO_fwide (stderr, 0) > 0)
1025                          __fwprintf (stderr, L"%s", buf);
1026                        else
1027                          fputs (buf, stderr);
1028    
1029                        free (buf);
1030                      }
1031    #else
1032                    fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),
1033                             argv[0], argv[optind]);
1034    #endif
1035                  }
1036              nextchar += strlen (nextchar);              nextchar += strlen (nextchar);
1037              optind++;              optind++;
1038              return '?';              return '?';
# Line 883  _getopt_internal (argc, argv, optstring, Line 1049  _getopt_internal (argc, argv, optstring,
1049                  else                  else
1050                    {                    {
1051                      if (print_errors)                      if (print_errors)
1052                        fprintf (stderr, _("\                        {
1053    #if defined _LIBC && defined USE_IN_LIBIO
1054                            char *buf;
1055    
1056                            if (__asprintf (&buf, _("\
1057    %s: option `-W %s' doesn't allow an argument\n"),
1058                                            argv[0], pfound->name) >= 0)
1059                              {
1060                                if (_IO_fwide (stderr, 0) > 0)
1061                                  __fwprintf (stderr, L"%s", buf);
1062                                else
1063                                  fputs (buf, stderr);
1064    
1065                                free (buf);
1066                              }
1067    #else
1068                            fprintf (stderr, _("\
1069  %s: option `-W %s' doesn't allow an argument\n"),  %s: option `-W %s' doesn't allow an argument\n"),
1070                                 argv[0], pfound->name);                                   argv[0], pfound->name);
1071    #endif
1072                          }
1073    
1074                      nextchar += strlen (nextchar);                      nextchar += strlen (nextchar);
1075                      return '?';                      return '?';
# Line 898  _getopt_internal (argc, argv, optstring, Line 1082  _getopt_internal (argc, argv, optstring,
1082                  else                  else
1083                    {                    {
1084                      if (print_errors)                      if (print_errors)
1085                        fprintf (stderr,                        {
1086                                 _("%s: option `%s' requires an argument\n"),  #if defined _LIBC && defined USE_IN_LIBIO
1087                                 argv[0], argv[optind - 1]);                          char *buf;
1088    
1089                            if (__asprintf (&buf, _("\
1090    %s: option `%s' requires an argument\n"),
1091                                            argv[0], argv[optind - 1]) >= 0)
1092                              {
1093                                if (_IO_fwide (stderr, 0) > 0)
1094                                  __fwprintf (stderr, L"%s", buf);
1095                                else
1096                                  fputs (buf, stderr);
1097    
1098                                free (buf);
1099                              }
1100    #else
1101                            fprintf (stderr,
1102                                     _("%s: option `%s' requires an argument\n"),
1103                                     argv[0], argv[optind - 1]);
1104    #endif
1105                          }
1106                      nextchar += strlen (nextchar);                      nextchar += strlen (nextchar);
1107                      return optstring[0] == ':' ? ':' : '?';                      return optstring[0] == ':' ? ':' : '?';
1108                    }                    }
# Line 947  _getopt_internal (argc, argv, optstring, Line 1149  _getopt_internal (argc, argv, optstring,
1149                  if (print_errors)                  if (print_errors)
1150                    {                    {
1151                      /* 1003.2 specifies the format of this message.  */                      /* 1003.2 specifies the format of this message.  */
1152    #if defined _LIBC && defined USE_IN_LIBIO
1153                        char *buf;
1154    
1155                        if (__asprintf (&buf, _("\
1156    %s: option requires an argument -- %c\n"),
1157                                        argv[0], c) >= 0)
1158                          {
1159                            if (_IO_fwide (stderr, 0) > 0)
1160                              __fwprintf (stderr, L"%s", buf);
1161                            else
1162                              fputs (buf, stderr);
1163    
1164                            free (buf);
1165                          }
1166    #else
1167                      fprintf (stderr,                      fprintf (stderr,
1168                               _("%s: option requires an argument -- %c\n"),                               _("%s: option requires an argument -- %c\n"),
1169                               argv[0], c);                               argv[0], c);
1170    #endif
1171                    }                    }
1172                  optopt = c;                  optopt = c;
1173                  if (optstring[0] == ':')                  if (optstring[0] == ':')

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26