⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options.c

📁 VIM文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
*   $Id: options.c,v 6.11 1998/08/04 03:25:29 darren Exp $
*
*   Copyright (c) 1996-1998, Darren Hiebert
*
*   This source code is released for free distribution under the terms of the
*   GNU General Public License.
*
*   This module contains functions to process command line options.
*****************************************************************************/

/*============================================================================
=   Include files
============================================================================*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef DEBUG
# include <assert.h>
#endif

#include "ctags.h"

/*============================================================================
=   Defines
============================================================================*/

/*----------------------------------------------------------------------------
 *  Miscellaneous defines
 *--------------------------------------------------------------------------*/

#define CTAGS_INVOCATION  "\
  Usage: ctags [-aBeFnNRux] [-{f|o} name] [-h list] [-i [+-=]types]\n\
               [-I list] [-L file] [-p path] [--append] [--excmd=n|p|m]\n\
               [--format=level] [--help] [--if0] [--lang=lang] [--recurse]\n\
	       [--sort] [--totals] [--version] file(s)\n"

#define ETAGS_INVOCATION  "\
  Usage: etags [-aRx] [-{f|o} name] [-h list] [-i [+-=]types] [-I list]\n\
               [-L file] [-p path] [--append] [--help] [--if0] [--lang=lang]\n\
	       [--recurse] [--totals] [--version] file(s)\n"

#define CTAGS_ENVIRONMENT	"CTAGS"
#define ETAGS_ENVIRONMENT	"ETAGS"

/*  The following separators are permitted for list options.
 */
#define EXTENSION_SEPARATORS   "."
#define IGNORE_SEPARATORS   ", \t\n"

#ifndef DEFAULT_FILE_FORMAT
# define DEFAULT_FILE_FORMAT	2
#endif

/*============================================================================
=   Data declarations
============================================================================*/
typedef struct {
    int usedByEtags;
    const char *const description;
} optionDescription;

/*============================================================================
=   Data definitions
============================================================================*/

/*----------------------------------------------------------------------------
-   Globally shared
----------------------------------------------------------------------------*/

static const char *const CExtensionList[] = {
    "c", NULL
};
static const char *const CppExtensionList[] = {
#if !defined(MSDOS) && !defined(WIN32) && !defined(OS2)
    "C",
#endif
    "c++", "cc", "cpp", "cxx", NULL
};
static const char *const JavaExtensionList[] = {
    "java", NULL
};
static const char *const HeaderExtensionList[] = {
    "h", "H", "hh", "hpp", "hxx", "h++", NULL
};

optionValues Option = {
    {
	TRUE,		/* -ic */
	TRUE,		/* -id */
	TRUE,		/* -ie */
	TRUE,		/* -if */
	TRUE,		/* -ig */
	TRUE,		/* -ii */
	FALSE,		/* -im */
	TRUE,		/* -in */
	FALSE,		/* -ip */
	TRUE,		/* -is */
	TRUE,		/* -it */
	TRUE,		/* -iu */
	TRUE,		/* -iv */
	FALSE,		/* -ix */
	FALSE,		/* -iC */
	FALSE,		/* -iF */
	TRUE,		/* -iS */
    },
    { NULL, 0, 0 },	/* -I */
    FALSE,		/* -a */
    FALSE,		/* -B */
    FALSE,		/* -e */
#ifdef MACROS_USE_PATTERNS
    EX_PATTERN,		/* -n, --excmd */
#else
    EX_MIX,		/* -n, --excmd */
#endif
    NULL,		/* -p */
    FALSE,		/* -R */
    TRUE,		/* -u, --sort */
    FALSE,		/* -x */
    NULL,		/* -L */
    NULL,		/* -o */
    HeaderExtensionList,/* -h */
#ifdef DEBUG
    0, 0,		/* -D, -b */
#endif
    FALSE,		/* started as etags */
    FALSE,		/* brace formatting */
    DEFAULT_FILE_FORMAT,/* --format */
    FALSE,		/* --if0 */
    LANG_AUTO,		/* --lang */
    {			/* --langmap */
	CExtensionList,
	CppExtensionList,
	JavaExtensionList,
    },
    FALSE		/* --totals */
};

/*----------------------------------------------------------------------------
-   Locally used only
----------------------------------------------------------------------------*/

static optionDescription LongOptionDescription[] = {
 {1,"  -a   Append the tags to an existing tag file."},
#ifdef DEBUG
 {1,"  -b <line>"},
 {1,"       Set break line."},
#endif
 {0,"  -B   Use backward searching patterns (?...?)."},
#ifdef DEBUG
 {1,"  -D <level>"},
 {1,"       Set debug level."},
#endif
 {0,"  -e   Output tag file for use with Emacs."},
 {1,"  -f <name>"},
 {1,"       Output tags to the specified file (default is \"tags\"; or \"TAGS\""},
 {1,"       if -e is specified). If specified as \"-\", tags are written to"},
 {1,"       standard output."},
 {0,"  -F   Use forward searching patterns (/.../) (default)."},
 {1,"  -h <list>"},
 {1,"       Specifies a list of file extensions used for headers."},
 {1,"       The default list is \".h.H.hh.hpp.hxx.h++\"."},
 {1,"  -i <types>"},
 {1,"       Specifies the list of tag types to include in the output file."},
 {1,"       \"Types\" is a group of letters designating the types of tags"},
 {1,"       affected. Each letter or group of letters may be preceded by"},
 {1,"       either a '+' sign (default, if omitted) to add it to those already"},
 {1,"       included, a '-' sign to exclude it from the list (e.g. to exclude"},
 {1,"       a default tag type), or an '=' sign to include its corresponding"},
 {1,"       tag type at the exclusion of those not listed. A space separating"},
 {1,"       the option letter from the list is optional. The following tag"},
 {1,"       types are supported (default settings are on except as noted):"},
 {1,"          c   class names"},
 {1,"          d   macro definitions"},
 {1,"          e   enumerators (values inside an enumeration)"},
 {1,"          f   function (or method) definitions"},
 {1,"          g   enumeration names"},
 {1,"          i   interface names (Java only)"},
 {1,"          m   data members [off]"},
 {1,"          n   namespace names (C++ only)"},
 {1,"          p   function prototypes [off]"},
 {1,"          s   structure names"},
 {1,"          t   typedefs"},
 {1,"          u   union names"},
 {1,"          v   variable definitions"},
 {1,"          x   external variable declarations [off]"},
 {1,"       In addition, the following modifiers are accepted:"},
 {1,"          C   include extra, class-qualified member tag entries [off]"},
 {1,"          F   include source filenames as tags [off]"},
 {1,"          S   include static tags"},
 {1,"  -I <list | file>"},
 {1,"       A list of tokens to ignore is read from either the command line,"},
 {1,"       or the specified file (if leading character is '.', '/', or '\\')."},
 {1,"       Particularly useful when a function definition or declaration"},
 {1,"       contains some special macro before the parameter list."},
 {1,"  -L <file>"},
 {1,"       A list of source file names are read from the specified file."},
 {1,"       If specified as \"-\", then standard input is read."},
 {0,"  -n   Equivalent to --excmd=number."},
 {0,"  -N   Equivalent to --excmd=pattern."},
 {1,"  -o   Alternative for -f."},
 {1,"  -p <path>"},
 {1,"       Default path to use for all (relative path) filenames."},
#ifdef RECURSE_SUPPORTED
 {1,"  -R   Equivalent to --recurse=yes."},
#else
 {1,"  -R   Not supported on this platform."},
#endif
 {0,"  -u   Equivalent to --sort=no."},
 {1,"  -x   Print a tabular cross reference file to standard output."},
 {1,"  --append=[yes|no]"},
 {1,"       Indicates whether tags should be appended to existing tag file"},
 {1,"       (default=no)."},
 {0,"  --excmd=number|pattern|mix"},
#ifdef MACROS_USE_PATTERNS
 {0,"       Uses the specified type of EX command to locate tags (default=pattern)."},
#else
 {0,"       Uses the specified type of EX command to locate tags (default=mix)."},
#endif
 {0,"  --format=level"},
#if DEFAULT_FILE_FORMAT==1
 {0,"       Forces output of specified tag file format (default=1)."},
#else
 {0,"       Forces output of specified tag file format (default=2)."},
#endif
 {1,"  --help"},
 {1,"       Prints this option summary."},
 {1,"  --if0=[yes|no]"},
 {1,"       Indicates whether code within #if 0 conditional branches should"},
 {1,"       be examined for tags (default=no)."},
 {1,"  --lang=[c|c++|java]"},
 {1,"       Forces specified language, disabling automatic selection."},
 {1,"  --recurse=[yes|no]"},
#ifdef RECURSE_SUPPORTED
 {1,"       Recurse into directories supplied on command line (default=no)."},
#else
 {1,"       Not supported on this platform."},
#endif
 {0,"  --sort=[yes|no]"},
 {0,"       Indicates whether tags should be sorted (default=yes)."},
 {1,"  --totals=[yes|no]"},
 {1,"       Prints statistics about source and tag files (default=no)."},
 {1,"  --version"},
 {1,"       Prints a version identifier to standard output."},
 {1, NULL}
};

/*  Contains a set of strings describing the set of "features" compiled into
 *  the code.
 */
static const char *const Features[] = {
#ifdef DEBUG
    "debug",
#endif
#ifdef WIN32
    "win32",
#endif
#ifdef DJGPP
    "msdos_32",
#else
# ifdef MSDOS
    "msdos_16",
# endif
#endif
#ifdef OS2
    "os2",
#endif
#ifdef AMIGA
    "amiga",
#endif
#ifndef EXTERNAL_SORT
    "internal_sort",
#endif
    NULL
};

/*============================================================================
=   Function prototypes
============================================================================*/
static void printfFeatureList __ARGS((FILE *const where));
static void printProgramIdentification __ARGS((FILE *const where));
static void printInvocationDescription __ARGS((FILE *const where));
static void printOptionDescriptions __ARGS((const optionDescription *const optDesc, FILE *const where));
static void printHelp __ARGS((const optionDescription *const optDesc, FILE *const where));
static char *readOptionArg __ARGS((const int option, char **const pArg, char *const *const argList, int *const pArgNum));
static unsigned int countExtensions __ARGS((const char *const list));
static const char *const *readExtensionList __ARGS((const char *const list));
static void clearTagList __ARGS((void));
static void applyTagInclusionList __ARGS((const char *const list));
static char *saveString __ARGS((const char *const string));
static void resizeIgnoreList __ARGS((void));
static void saveIgnoreToken __ARGS((const char *const ignoreToken));
static void readIgnoreList __ARGS((char *const list));
static void readIgnoreListFromFile __ARGS((const char *const fileName));
static void processHeaderListOption __ARGS((const int option, char **const argP, char *const *const argList, int *const argNumP));
static void processIgnoreOption __ARGS((const int option, char **const argP, char *const *const argList, int *const argNumP));
static boolean getBooleanOption __ARGS((const char *const optionName, const char *const parameter, const boolean defaultValue));
static void processExcmdOption __ARGS((const char *const optionName, const char *const parameter));
static void processFormatOption __ARGS((const char *const optionName, const char *const parameter));
static langType getLangType __ARGS((const char *const name));
static void processLangOption __ARGS((const char *const optionName, const char *const parameter));
static void installLangMap __ARGS((char *const map));
static void processLangMapOption __ARGS((const char *const optionName, const char *const parameter));
static void processLongOption __ARGS((const char *const optionString));
static void processCompoundOption __ARGS((const int option, char **const pArg, char *const *const argList, int *const pArgNum));
static boolean processSimpleOption __ARGS((const int option));
static void parseStringToArgs __ARGS((const char *const string, char *parsedBuffer, char **const argList, const unsigned int maxArgs));
static unsigned int countStringWords __ARGS((const char *const string));
static char **creatArgListForString __ARGS((const char *const string));

/*============================================================================
=   Function definitions
============================================================================*/

static void printfFeatureList( where )
    FILE *const where;
{
    int i;

    for (i = 0 ; Features[i] != NULL ; ++i)
    {
	if (i == 0)
	    fputs(" (", where);
	fprintf(where, "%s+%s", (i>0 ? ", " : ""), Features[i]);
    }
    fputs(i>0 ? ")" : "", where);
}

static void printProgramIdentification( where )
    FILE *const where;
{
    fprintf(where, "%s %s, by %s", PROGRAM_NAME, PROGRAM_VERSION, AUTHOR_NAME);
    printfFeatureList(where);
    fputs("\n", where);
}

static void printInvocationDescription( where )
    FILE *const where;
{
    if (Option.startedAsEtags)
	fprintf(where, ETAGS_INVOCATION);
    else
	fprintf(where, CTAGS_INVOCATION);
}

static void printOptionDescriptions( optDesc, where )
    const optionDescription *const optDesc;
    FILE *const where;
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -