forked from universal-ctags/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flags related code defined in lregex.c and could be used in the file. This patch makes the code usable outside of the file. evalFlags is renamed to flagsEval. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
- Loading branch information
Showing
4 changed files
with
106 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* | ||
* Copyright (c) 2000-2003, 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 | ||
*/ | ||
#include "general.h" /* must always come first */ | ||
|
||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include "flags.h" | ||
#include "vstring.h" | ||
#include "routines.h" | ||
|
||
#define LONG_FLAG_OPEN '{' | ||
#define LONG_FLAG_CLOSE '}' | ||
|
||
void flagsEval (const char* flags, flagDefinition* defs, unsigned int ndefs, void* data) | ||
{ | ||
unsigned int i, j; | ||
|
||
if (!flags) | ||
return; | ||
if (!defs) | ||
return; | ||
|
||
for (i = 0 ; flags [i] != '\0' ; ++i) | ||
{ | ||
if (flags [i] == LONG_FLAG_OPEN) | ||
{ | ||
const char* aflag = flags + i + 1; | ||
char* needle_close_paren = strchr(aflag, LONG_FLAG_CLOSE); | ||
const char* param; | ||
char* needle_eqaul; | ||
|
||
if (needle_close_paren == NULL) | ||
{ | ||
error (WARNING, "long flags specifier opened with `%c' is not closed `%c'", | ||
LONG_FLAG_OPEN, LONG_FLAG_CLOSE); | ||
break; | ||
} | ||
|
||
*needle_close_paren = '\0'; | ||
needle_eqaul = strchr(aflag, '='); | ||
if ((needle_eqaul == NULL || (needle_eqaul >= needle_close_paren))) | ||
{ | ||
needle_eqaul = NULL; | ||
param = NULL; | ||
} | ||
else | ||
{ | ||
param = needle_eqaul + 1; | ||
*needle_eqaul = '\0'; | ||
} | ||
|
||
for ( j = 0 ; j < ndefs ; ++j ) | ||
if (defs[j].long_str && (strcmp(aflag, defs[j].long_str) == 0)) | ||
defs[j].long_proc(aflag, param, data); | ||
|
||
if (needle_eqaul) | ||
*needle_eqaul = '='; | ||
*needle_close_paren = LONG_FLAG_CLOSE; | ||
|
||
i = needle_close_paren - flags; | ||
} | ||
else for (j = 0 ; j < ndefs ; ++j) | ||
if (flags[i] == defs[j].short_char) | ||
defs[j].short_proc(flags[i], data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* | ||
* | ||
* Copyright (c) 2000-2003, Darren Hiebert | ||
* | ||
* This source code is released for free distribution under the terms of the | ||
* GNU General Public License. | ||
* | ||
* Defines external interface to option processing. | ||
*/ | ||
#ifndef _FLAGS_H | ||
#define _FLAGS_H | ||
|
||
typedef struct { | ||
char short_char; | ||
char *long_str; | ||
void (* short_proc) (char c, void *data); | ||
void (* long_proc) (const char* const s, const char* const param, void *data); | ||
/* TODO: handler for help message */ | ||
} flagDefinition; | ||
|
||
extern void flagsEval (const char* flags, flagDefinition* defs, unsigned int ndefs, void* data); | ||
|
||
#endif /* _FLAGS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters