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 pDelimiter
= strrchr (fileName
, '.');
136 if (pDelimiter
== NULL
)
139 extension
= pDelimiter
+ 1; /* skip to first char of extension */
144 /* Determines whether the specified file name is considered to be a header
145 * file for the purposes of determining whether enclosed tags are global or
148 extern boolean
isIncludeFile (const char *const fileName
)
153 /* tags_ignore is a NULL-terminated array of strings, read from ~/.config/geany/ignore.tags.
154 * This file contains a space or newline separated list of symbols which should be ignored
155 * by the C/C++ parser, see -I command line option of ctags for details. */
156 gchar
**c_tags_ignore
= NULL
;
158 /* Determines whether or not "name" should be ignored, per the ignore list.
160 extern boolean
isIgnoreToken (const char *const name
,
161 boolean
*const pIgnoreParens
,
162 const char **const replacement
)
164 boolean result
= FALSE
;
166 if (c_tags_ignore
!= NULL
)
168 const size_t nameLen
= strlen (name
);
170 guint len
= g_strv_length (c_tags_ignore
);
172 if (pIgnoreParens
!= NULL
)
173 *pIgnoreParens
= FALSE
;
175 for (i
= 0 ; i
< len
; ++i
)
177 vString
*token
= vStringNewInit (c_tags_ignore
[i
]);
179 if (strncmp (vStringValue (token
), name
, nameLen
) == 0)
181 const size_t tokenLen
= vStringLength (token
);
183 if (nameLen
== tokenLen
)
188 else if (tokenLen
== nameLen
+ 1 &&
189 vStringChar (token
, tokenLen
- 1) == '+')
192 if (pIgnoreParens
!= NULL
)
193 *pIgnoreParens
= TRUE
;
196 else if (vStringChar (token
, nameLen
) == '=')
198 if (replacement
!= NULL
)
199 *replacement
= vStringValue (token
) + nameLen
+ 1;
203 vStringDelete (token
);
209 void addIgnoreListFromFile (const char *const fileName
)
211 stringList
* tokens
= stringListNewFromFile (fileName
);
212 if (Option
.ignore
== NULL
)
213 Option
.ignore
= tokens
;
215 stringListCombine (Option
.ignore
, tokens
);
221 * Generic option parsing
223 #define readOptionConfiguration
225 #define freeOptionResources
227 /* vi:set tabstop=8 shiftwidth=4: */