X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fargmatch.c;h=f180f1a262fec9e0aab150f32409a5d05d77bfeb;hb=140b7a20b7c376347dac834c95baee91af125394;hp=f3f1a50d229c7b6472d11c8a5a19c43e9cf14527;hpb=d87c39464604e74f580c7fae835be31a4c125c36;p=gnulib.git diff --git a/lib/argmatch.c b/lib/argmatch.c index f3f1a50d2..f180f1a26 100644 --- a/lib/argmatch.c +++ b/lib/argmatch.c @@ -1,5 +1,5 @@ /* argmatch.c -- find a match for a string in an array - Copyright (C) 1990 Free Software Foundation, Inc. + Copyright (C) 1990, 1997 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -12,17 +12,26 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + along with this program; see the file COPYING. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Written by David MacKenzie */ +/* Written by David MacKenzie */ -#include -#ifdef STDC_HEADERS -#include +#if HAVE_CONFIG_H +# include #endif -extern char *program_name; +#include + +#include + +#include +#if HAVE_STRING_H +# include +#else +# include +#endif /* If ARG is an unambiguous match for an element of the null-terminated array OPTLIST, return the index in OPTLIST @@ -30,17 +39,15 @@ extern char *program_name; or -2 if it is ambiguous (is a prefix of more than one element). */ int -argmatch (arg, optlist) - char *arg; - char **optlist; +argmatch (const char *arg, const char *const *optlist) { int i; /* Temporary index in OPTLIST. */ - int arglen; /* Length of ARG. */ + size_t arglen; /* Length of ARG. */ int matchind = -1; /* Index of first nonexact match. */ int ambiguous = 0; /* If nonzero, multiple nonexact match(es). */ - + arglen = strlen (arg); - + /* Test all elements for either exact match or abbreviated matches. */ for (i = 0; optlist[i]; i++) { @@ -69,15 +76,10 @@ argmatch (arg, optlist) PROBLEM is the return value from argmatch. */ void -invalid_arg (kind, value, problem) - char *kind; - char *value; - int problem; +invalid_arg (const char *kind, const char *value, int problem) { - fprintf (stderr, "%s: ", program_name); - if (problem == -1) - fprintf (stderr, "invalid"); - else /* Assume -2. */ - fprintf (stderr, "ambiguous"); - fprintf (stderr, " %s `%s'\n", kind, value); + const char *fmt = (problem == -1 + ? "%s: invalid %s `%s'\n" + : "%s: ambiguous %s `%s'\n"); + fprintf (stderr, fmt, program_name, kind, value); }