Update HACKING for changed doc generation instructions
[geany-mirror.git] / tagmanager / ctags / options.c
blob070265d0cff3c3e6f600e57c44440a8072e3741c
1 /*
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.
9 */
12 * INCLUDE FILES
14 #include "general.h" /* must always come first */
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdio.h>
19 #include <ctype.h> /* to declare isspace () */
21 #include "ctags.h"
22 #include "main.h"
23 #define OPTION_WRITE
24 #include "options.h"
25 #include "parse.h"
27 #include <glib.h>
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
43 #endif
45 #if defined (MSDOS) || defined (WIN32) || defined (OS2) || defined (AMIGA) || defined (HAVE_OPENDIR)
46 # define RECURSE_SUPPORTED
47 #endif
49 #define isCompoundOption(c) (boolean) (strchr ("fohiILpDb", (c)) != NULL)
54 * DATA DEFINITIONS
57 optionValues Option = {
59 FALSE, /* --extra=f */
60 FALSE, /* --extra=q */
61 TRUE, /* --file-scope */
64 TRUE, /* -fields=a */
65 TRUE, /* -fields=f */
66 FALSE, /* -fields=m */
67 TRUE, /* -fields=i */
68 FALSE, /* -fields=k */
69 TRUE, /* -fields=z */
70 TRUE, /* -fields=K */
71 FALSE, /* -fields=l */
72 TRUE, /* -fields=n */
73 TRUE, /* -fields=s */
74 TRUE, /* -fields=P */
75 TRUE /* -fields=A */
77 NULL, /* -I */
78 FALSE, /* -a */
79 FALSE, /* -B */
80 FALSE, /* -e */
81 #ifdef MACROS_USE_PATTERNS
82 EX_PATTERN, /* -n, --excmd */
83 #else
84 EX_MIX, /* -n, --excmd */
85 #endif
86 FALSE, /* -R */
87 TRUE, /* -u, --sort */
88 FALSE, /* -V */
89 FALSE, /* -x */
90 NULL, /* -L */
91 NULL, /* -o */
92 NULL, /* -h */
93 DEFAULT_FILE_FORMAT,/* --format */
94 FALSE, /* --if0 */
95 FALSE, /* --kind-long */
96 LANG_AUTO, /* --lang */
97 TRUE, /* --links */
98 FALSE, /* --filter */
99 NULL, /* --filter-terminator */
100 FALSE, /* --qualified-tags */
101 FALSE, /* --tag-relative */
102 FALSE, /* --totals */
103 FALSE, /* --line-directives */
104 FALSE,
108 extern void verbose (const char *const format, ...)
112 extern void freeList (stringList** const pList)
114 if (*pList != NULL)
116 stringListDelete (*pList);
117 *pList = NULL;
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)
137 extension = "";
138 else
139 extension = pDelimiter + 1; /* skip to first char of extension */
141 return 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
146 * static.
148 extern boolean isIncludeFile (const char *const fileName)
150 return FALSE;
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);
169 unsigned int i;
170 guint len = g_strv_length (c_tags_ignore);
171 vString *token = vStringNew();
173 if (pIgnoreParens != NULL)
174 *pIgnoreParens = FALSE;
176 for (i = 0 ; i < len ; ++i)
178 size_t tokenLen;
180 vStringCopyS (token, c_tags_ignore[i]);
181 vStringTerminate (token);
182 tokenLen = vStringLength (token);
184 if (tokenLen >= 2 && vStringChar (token, tokenLen - 1) == '*' &&
185 strncmp (vStringValue (token), name, tokenLen - 1) == 0)
187 result = TRUE;
188 break;
190 if (strncmp (vStringValue (token), name, nameLen) == 0)
192 if (nameLen == tokenLen)
194 result = TRUE;
195 break;
197 else if (tokenLen == nameLen + 1 &&
198 vStringChar (token, tokenLen - 1) == '+')
200 result = TRUE;
201 if (pIgnoreParens != NULL)
202 *pIgnoreParens = TRUE;
203 break;
205 else if (vStringChar (token, nameLen) == '=')
207 if (replacement != NULL)
208 *replacement = vStringValue (token) + nameLen + 1;
209 break;
213 vStringDelete (token);
215 return result;
218 void addIgnoreListFromFile (const char *const fileName)
220 stringList* tokens = stringListNewFromFile (fileName);
221 if (Option.ignore == NULL)
222 Option.ignore = tokens;
223 else
224 stringListCombine (Option.ignore, tokens);
230 * Generic option parsing
232 #define readOptionConfiguration
233 #define initOptions
234 #define freeOptionResources
236 /* vi:set tabstop=8 shiftwidth=4: */