资源简介
Grep-2.6的源码,且包含自身测试文件
代码片段和文件信息
/* -*- buffer-read-only: t -*- vi: set ro: */
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
/* argmatch.c -- find a match for a string in an array
Copyright (C) 1990 1998 1999 2001 2002 2003 2004 2005 2006 2007
2009 2010 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
the Free Software Foundation; either version 3 of the License or
(at your option) any later version.
This program is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 see . */
/* Written by David MacKenzie
Modified by Akim Demaille */
#include
/* Specification. */
#include “argmatch.h“
#include
#include
#include
#include
#include “gettext.h“
#define _(msgid) gettext (msgid)
#include “error.h“
#include “quotearg.h“
#include “quote.h“
#if USE_UNLOCKED_IO
# include “unlocked-io.h“
#endif
/* When reporting an invalid argument show nonprinting characters
by using the quoting style ARGMATCH_QUOTING_style. Do not use
literal_quoting_style. */
#ifndef ARGMATCH_QUOTING_style
# define ARGMATCH_QUOTING_style locale_quoting_style
#endif
/* Non failing version of argmatch call this function after failing. */
#ifndef ARGMATCH_DIE
# include “exitfail.h“
# define ARGMATCH_DIE exit (exit_failure)
#endif
#ifdef ARGMATCH_DIE_DECL
ARGMATCH_DIE_DECL;
#endif
static void
__argmatch_die (void)
{
ARGMATCH_DIE;
}
/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
Default to __argmatch_die but allow caller to change this at run-time. */
argmatch_exit_fn argmatch_die = __argmatch_die;
/* If ARG is an unambiguous match for an element of the
NULL-terminated array ARGLIST return the index in ARGLIST
of the matched element else -1 if it does not match any element
or -2 if it is ambiguous (is a prefix of more than one element).
If VALLIST is none null use it to resolve ambiguities limited to
synonyms i.e. for
“yes“ “yop“ -> 0
“no“ “nope“ -> 1
“y“ is a valid argument for ‘0‘ and “n“ for ‘1‘. */
ptrdiff_t
argmatch (const char *arg const char *const *arglist
const char *vallist size_t valsize)
{
size_t i; /* Temporary index in ARGLIST. */
size_t arglen; /* Length of ARG. */
ptrdiff_t matchind = -1; /* Index of first nonexact match. */
bool ambiguous = false; /* If true multiple nonexact match(es). */
arglen = strlen (arg);
/* Test all elements for either exact match or abbreviated matches. */
评论
共有 条评论