3 * Copyright (c) 1996-2001, Darren Hiebert
5 * This source code is released for free distribution under the terms of the
6 * GNU General Public License.
8 * This module contains functions to process command line options.
14 #include "general.h" /* must always come first */
19 #include <ctype.h> /* to declare isspace () */
29 #define CTAGS_ENVIRONMENT "CTAGS"
31 #define CTAGS_FILE "tags"
34 /* The following separators are permitted for list options.
36 #define EXTENSION_SEPARATOR '.'
37 #define PATTERN_START '('
38 #define PATTERN_STOP ')'
39 #define IGNORE_SEPARATORS ", \t\n"
41 #ifndef DEFAULT_FILE_FORMAT
42 # define DEFAULT_FILE_FORMAT 2
45 #if defined (MSDOS) || defined (WIN32) || defined (OS2) || defined (AMIGA) || defined (HAVE_OPENDIR)
46 # define RECURSE_SUPPORTED
49 #define isCompoundOption(c) (boolean) (strchr ("fohiILpDb", (c)) != NULL)
57 optionValues Option
= {
59 FALSE
, /* --extra=f */
60 FALSE
, /* --extra=q */
61 TRUE
, /* --file-scope */
66 FALSE
, /* -fields=m */
68 FALSE
, /* -fields=k */
71 FALSE
, /* -fields=l */
81 #ifdef MACROS_USE_PATTERNS
82 EX_PATTERN
, /* -n, --excmd */
84 EX_MIX
, /* -n, --excmd */
87 TRUE
, /* -u, --sort */
93 DEFAULT_FILE_FORMAT
,/* --format */
95 FALSE
, /* --kind-long */
96 LANG_AUTO
, /* --lang */
99 NULL
, /* --filter-terminator */
100 FALSE
, /* --qualified-tags */
101 FALSE
, /* --tag-relative */
102 FALSE
, /* --totals */
103 FALSE
, /* --line-directives */
108 extern void verbose (const char *const format
, ...)
112 extern void freeList (stringList
** const pList
)
116 stringListDelete (*pList
);
121 extern void setDefaultTagFileName (void)
123 Option
.tagFileName
= eStrdup (CTAGS_FILE
);
127 * File extension and language mapping
129 extern const char *fileExtension (const char *const fileName
)
131 const char *extension
;
132 const char *pDelimiter
= NULL
;
134 if (pDelimiter
== NULL
)
135 pDelimiter
= strrchr (fileName
, '.');
137 if (pDelimiter
== NULL
)
140 extension
= pDelimiter
+ 1; /* skip to first char of extension */
145 /* Determines whether the specified file name is considered to be a header
146 * file for the purposes of determining whether enclosed tags are global or
149 extern boolean
isIncludeFile (const char *const fileName
)
154 /* tags_ignore is a NULL-terminated array of strings, read from ~/.config/geany/ignore.tags.
155 * This file contains a space or newline separated list of symbols which should be ignored
156 * by the C/C++ parser, see -I command line option of ctags for details. */
157 gchar
**c_tags_ignore
= NULL
;
159 /* Determines whether or not "name" should be ignored, per the ignore list.
161 extern boolean
isIgnoreToken (const char *const name
,
162 boolean
*const pIgnoreParens
,
163 const char **const replacement
)
165 boolean result
= FALSE
;
167 if (c_tags_ignore
!= NULL
)
169 const size_t nameLen
= strlen (name
);
171 guint len
= g_strv_length (c_tags_ignore
);
173 if (pIgnoreParens
!= NULL
)
174 *pIgnoreParens
= FALSE
;
176 for (i
= 0 ; i
< len
; ++i
)
178 vString
*token
= vStringNewInit (c_tags_ignore
[i
]);
180 if (strncmp (vStringValue (token
), name
, nameLen
) == 0)
182 const size_t tokenLen
= vStringLength (token
);
184 if (nameLen
== tokenLen
)
189 else if (tokenLen
== nameLen
+ 1 &&
190 vStringChar (token
, tokenLen
- 1) == '+')
193 if (pIgnoreParens
!= NULL
)
194 *pIgnoreParens
= TRUE
;
197 else if (vStringChar (token
, nameLen
) == '=')
199 if (replacement
!= NULL
)
200 *replacement
= vStringValue (token
) + nameLen
+ 1;
204 vStringDelete (token
);
210 void addIgnoreListFromFile (const char *const fileName
)
212 stringList
* tokens
= stringListNewFromFile (fileName
);
213 if (Option
.ignore
== NULL
)
214 Option
.ignore
= tokens
;
216 stringListCombine (Option
.ignore
, tokens
);
222 * Generic option parsing
224 #define readOptionConfiguration
226 #define freeOptionResources
228 /* vi:set tabstop=8 shiftwidth=4: */