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

📄 options.c

📁 VIM文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
    int i;

    for (i = 0 ; optDesc[i].description != NULL ; ++i)
    {
	if (! Option.startedAsEtags || optDesc[i].usedByEtags)
	{
	    fputs(optDesc[i].description, where);
	    fputc('\n', where);
	}
    }
}

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

    printProgramIdentification(where);
    fputs("\n", where);
    printInvocationDescription(where);
    fputs("\n", where);
    printOptionDescriptions(optDesc, where);
}

static char *readOptionArg( option, pArg, argList, pArgNum )
    const int option;
    char **const pArg;
    char *const *const argList;
    int *const pArgNum;
{
    char *list;

    if ((*pArg)[0] != '\0')	    /* does list immediately follow option? */
    {
	list = *pArg;
	*pArg += strlen(*pArg);
    }
    else if ((list = argList[++(*pArgNum)]) == NULL) /* at least 1 more arg? */
	error(FATAL, "-%c: Parameter missing", option);

    DebugStatement( if (debug(DEBUG_OPTION)) fputs(list, errout); )

    return list;
}

/*  Reads a list of file extensions.
 */
static unsigned int countExtensions( list )
    const char *const list;
{
    unsigned int count = 0;
    const char *p;

    /*  Increase count by one if list does not begin with a separator.
     */
    if (strchr(EXTENSION_SEPARATORS, list[0]) == NULL)
	++count;

    for (p = list  ;  *p != '\0'  ;  ++p)
    {
	if (strchr(EXTENSION_SEPARATORS, *p) != NULL)
	    ++count;
    }
    return count + 1;
}

static const char *const *readExtensionList( list )
    const char *const list;
{
    int extIndex = 0;
    const char *extension;
    const unsigned int numExtensions = countExtensions(list);
    char *const extensionList  = (char *)malloc(strlen(list) + 1);
    const char **const extensionArray = (const char **)malloc(
					(numExtensions + 1) * sizeof(char *));

    if (extensionList == NULL  ||  extensionArray == NULL)
	error(FATAL | PERROR, "");
    strcpy(extensionList, list);
    extension = strtok(extensionList, EXTENSION_SEPARATORS);
    while (extension != NULL)
    {
	DebugStatement( if (debug(DEBUG_STATUS))
			    printf("extension: %s\n", extension); )
	extensionArray[extIndex++] = extension;
	extension = strtok(NULL, EXTENSION_SEPARATORS);
    }
    extensionArray[extIndex] = NULL;

    return extensionArray;
}

static void clearTagList()
{
    Option.include.classNames		= FALSE;	/* -ic */
    Option.include.defines		= FALSE;	/* -id */
    Option.include.enumerators		= FALSE;	/* -ie */
    Option.include.functions		= FALSE;	/* -if */
    Option.include.enumNames		= FALSE;	/* -ig */
    Option.include.interfaceNames	= FALSE;	/* -ii */
    Option.include.members		= FALSE;	/* -im */
    Option.include.namespaceNames	= FALSE;	/* -in */
    Option.include.prototypes		= FALSE;	/* -ip */
    Option.include.structNames		= FALSE;	/* -is */
    Option.include.typedefs		= FALSE;	/* -it */
    Option.include.unionNames		= FALSE;	/* -iu */
    Option.include.variables		= FALSE;	/* -iC */
    Option.include.sourceFiles		= FALSE;	/* -iF */
    Option.include.statics		= FALSE;	/* -iS */
}

static void applyTagInclusionList( list )
    const char *const list;
{
    boolean mode = TRUE;	/* default mode is to add following types */
    const char *p;

    for (p = list  ;  *p != '\0'  ;  ++p)
	switch (*p)
	{
	    case '=':	/* exclusive mode; ONLY types following are included */
		clearTagList();
		mode = TRUE;
		break;

	    case '+':	mode = TRUE;	break;	/* include types following */
	    case '-':	mode = FALSE;	break;	/* exclude types following */

	    case 'c':	Option.include.classNames	= mode;		break;
	    case 'd':	Option.include.defines		= mode;		break;
	    case 'e':	Option.include.enumerators	= mode;		break;
	    case 'f':	Option.include.functions	= mode;		break;
	    case 'g':	Option.include.enumNames	= mode;		break;
	    case 'i':	Option.include.interfaceNames	= mode;		break;
	    case 'm':	Option.include.members		= mode;		break;
	    case 'n':	Option.include.namespaceNames	= mode;		break;
	    case 'p':	Option.include.prototypes	= mode;		break;
	    case 's':	Option.include.structNames	= mode;		break;
	    case 't':	Option.include.typedefs		= mode;		break;
	    case 'u':	Option.include.unionNames	= mode;		break;
	    case 'v':	Option.include.variables	= mode;		break;
	    case 'x':	Option.include.externVars	= mode;		break;
	    case 'C':	Option.include.classPrefix	= mode;		break;
	    case 'F':	Option.include.sourceFiles	= mode;		break;
	    case 'S':	Option.include.statics		= mode;		break;

	    default: error(FATAL, "-i: Invalid tag option '%c'", *p);	break;
	}
}

/*  Determines whether or not "name" should be ignored, per the ignore list.
 */
extern boolean isIgnoreToken( name )
    const char *const name;
{
    boolean ignore = FALSE;
    unsigned int i;

    for (i = 0  ;  i < Option.ignore.count ; ++i)
    {
	if (strcmp(Option.ignore.list[i], name) == 0)
	{
	    ignore = TRUE;
	    break;
	}
    }
    return ignore;
}

static char *saveString( string )
    const char *const string;
{
    char *const here = (char *)malloc(strlen(string) + 1);

    if (here == NULL)
	error(FATAL | PERROR, "");
    strcpy(here, string);

    return here;
}

static void resizeIgnoreList()
{
    size_t newSize;

    Option.ignore.max = Option.ignore.count + 10;
    newSize = Option.ignore.max * sizeof(char *);

    if (Option.ignore.list == NULL)
	Option.ignore.list = (char **)malloc(newSize);
    else
	Option.ignore.list = (char **)realloc(Option.ignore.list, newSize);
    if (Option.ignore.list == NULL)
	error(FATAL | PERROR, "cannot create ignore list");
}

static void saveIgnoreToken( ignoreToken )
    const char *const ignoreToken;
{
    const unsigned int i = Option.ignore.count++;

    if (Option.ignore.count > Option.ignore.max)
	resizeIgnoreList();
    Option.ignore.list[i] = saveString(ignoreToken);
    DebugStatement( if (debug(DEBUG_STATUS))
			printf("ignore token: %s\n", ignoreToken); )
}

static void readIgnoreList( list )
    char *const list;
{
    const char *token = strtok(list, IGNORE_SEPARATORS);

    while (token != NULL)
    {
	saveIgnoreToken(token);
	token = strtok(NULL, IGNORE_SEPARATORS);
    }
}

static void readIgnoreListFromFile( fileName )
    const char *const fileName;
{
    FILE *const fp = fopen(fileName, "r");

    if (fp == NULL)
	error(FATAL | PERROR, "cannot open \"%s\"", fileName);
    else
    {
	char ignoreToken[MaxNameLength];

	while (fscanf(fp, "%255s", ignoreToken) == 1)
	    saveIgnoreToken(ignoreToken);
    }
}

extern void freeIgnoreList()
{
    while (Option.ignore.count > 0)
	free(Option.ignore.list[--Option.ignore.count]);

    if (Option.ignore.list != NULL)
	free(Option.ignore.list);

    Option.ignore.list = NULL;
    Option.ignore.max = 0;
}

static void processHeaderListOption( option, argP, argList, argNumP )
    const int option;
    char **const argP;
    char *const *const argList;
    int *const argNumP;
{
    char *const list = readOptionArg(option, argP, argList, argNumP);

    /*  Check to make sure that the user did not enter "ctags -h *.c"
     *  by testing to see if the list is a filename that exists.
     */
    if (doesFileExist(list) == 0)
	error(FATAL, "-h: Invalid list");
    else
    {
	DebugStatement( if (debug(DEBUG_STATUS))
			    printf("Header Extensions:\n"); )
	Option.headerExt = readExtensionList(list);
    }
}

static void processIgnoreOption( option, argP, argList, argNumP )
    const int option;
    char **const argP;
    char *const *const argList;
    int *const argNumP;
{
    char *const list = readOptionArg(option, argP, argList, argNumP);

    if (strchr("./\\", list[0]) != NULL)
	readIgnoreListFromFile(list);
    else
	readIgnoreList(list);
}

static boolean getBooleanOption( optionName, parameter, defaultValue )
    const char *const optionName;
    const char *const parameter;
    const boolean defaultValue;
{
    boolean selection = defaultValue;

    if (parameter[0] == '\0')
	selection = defaultValue;
    else if (strcmp(parameter, "0") == 0  ||  strcmp(parameter, "no") == 0)
	selection = FALSE;
    else if (strcmp(parameter, "1") == 0  ||  strcmp(parameter, "yes") == 0)
	selection = TRUE;
    else
	error(FATAL, "Invalid value for option --%s", optionName);

    return selection;
}

static void processExcmdOption( optionName, parameter )
    const char *const optionName;
    const char *const parameter;
{
    switch (*parameter)
    {
	case 'm':	Option.locate = EX_MIX;		break;
	case 'n':	Option.locate = EX_LINENUM;	break;
	case 'p':	Option.locate = EX_PATTERN;	break;
	default:
	    error(FATAL, "Invalid value for option --%s", optionName);
	    break;
    }
}

static void processFormatOption( optionName, parameter )
    const char *const optionName;
    const char *const parameter;
{
    unsigned int format;

    if (sscanf(parameter, "%u", &format) < 1)
	error(FATAL, "Missing or invalid value for \"--%s\" option",optionName);
    else if (format <= (unsigned int)MaxSupportedTagFormat)
	Option.tagFileFormat = format;
    else
	error(FATAL, "Unsupported value for \"--%s\" option", optionName);
}

extern const char *getLanguageName( language )
    const langType language;
{
    static const char *const names[] = { "c", "c++", "java" };

    DebugStatement( if (sizeof(names)/sizeof(names[0]) != LANG_COUNT)
	error(FATAL, "LangNames array not consistent with LANG enumeration"); )

    return names[(int)language];
}

extern boolean strequiv( s1, s2 )
    const char *s1;
    const char *s2;
{
    boolean equivalent;

    if (strcmp(s1, s2) == 0)
	equivalent = TRUE;

⌨️ 快捷键说明

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