forked from vhda/ctags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.c
2042 lines (1856 loc) · 51 KB
/
options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* $Id$
*
* Copyright (c) 1996-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 */
#define _GNU_SOURCE /* for asprintf */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h> /* to declare isspace () */
#if defined(HAVE_SCANDIR)
#include <dirent.h>
#endif
#include "ctags.h"
#include "debug.h"
#include "main.h"
#define OPTION_WRITE
#include "options.h"
#include "parse.h"
#include "routines.h"
/*
* MACROS
*/
#define INVOCATION "Usage: %s [options] [file(s)]\n"
#define CTAGS_ENVIRONMENT "CTAGS"
#define ETAGS_ENVIRONMENT "ETAGS"
#define CTAGS_FILE "tags"
#define ETAGS_FILE "TAGS"
#ifndef ETAGS
# define ETAGS "etags" /* name which causes default use of to -e */
#endif
/* The following separators are permitted for list options.
*/
#define EXTENSION_SEPARATOR '.'
#define PATTERN_START '('
#define PATTERN_STOP ')'
#define IGNORE_SEPARATORS ", \t\n"
#ifndef DEFAULT_FILE_FORMAT
# define DEFAULT_FILE_FORMAT 2
#endif
#if defined (HAVE_OPENDIR) || defined (HAVE_FINDFIRST) || defined (HAVE__FINDFIRST) || defined (AMIGA)
# define RECURSE_SUPPORTED
#endif
#define isCompoundOption(c) (boolean) (strchr ("fohiILpDb", (c)) != NULL)
/*
* Data declarations
*/
enum eOptionLimits {
MaxHeaderExtensions = 100, /* maximum number of extensions in -h option */
MaxSupportedTagFormat = 2
};
typedef struct sOptionDescription {
int usedByEtags;
const char *description;
} optionDescription;
typedef void (*parametricOptionHandler) (const char *const option, const char *const parameter);
typedef const struct {
const char* name; /* name of option as specified by user */
parametricOptionHandler handler; /* routine to handle option */
boolean initOnly; /* option must be specified before any files */
} parametricOption;
typedef const struct {
const char* name; /* name of option as specified by user */
boolean* pValue; /* pointer to option value */
boolean initOnly; /* option must be specified before any files */
} booleanOption;
/*
* DATA DEFINITIONS
*/
static boolean NonOptionEncountered;
static stringList *OptionFiles;
static stringList* Excluded;
static boolean FilesRequired = TRUE;
static boolean SkipConfiguration;
static const char *const HeaderExtensions [] = {
"h", "H", "hh", "hpp", "hxx", "h++", "inc", "def", NULL
};
optionValues Option = {
{
FALSE, /* --extra=f */
FALSE, /* --extra=q */
TRUE, /* --file-scope */
},
{
FALSE, /* -fields=a */
TRUE, /* -fields=f */
FALSE, /* -fields=m */
FALSE, /* -fields=i */
TRUE, /* -fields=k */
FALSE, /* -fields=z */
FALSE, /* -fields=K */
FALSE, /* -fields=l */
FALSE, /* -fields=n */
TRUE, /* -fields=s */
FALSE, /* -fields=S */
TRUE /* -fields=t */
},
NULL, /* -I */
FALSE, /* -a */
FALSE, /* -B */
FALSE, /* -e */
#ifdef MACROS_USE_PATTERNS
EX_PATTERN, /* -n, --excmd */
#else
EX_MIX, /* -n, --excmd */
#endif
FALSE, /* -R */
SO_SORTED, /* -u, --sort */
FALSE, /* -V */
FALSE, /* -x */
NULL, /* -L */
NULL, /* -o */
NULL, /* -h */
NULL, /* --config-filename */
NULL, /* --etags-include */
DEFAULT_FILE_FORMAT,/* --format */
FALSE, /* --if0 */
FALSE, /* --kind-long */
LANG_AUTO, /* --lang */
TRUE, /* --links */
FALSE, /* --filter */
NULL, /* --filter-terminator */
FALSE, /* --tag-relative */
FALSE, /* --totals */
FALSE, /* --line-directives */
#ifdef DEBUG
0, 0 /* -D, -b */
#endif
};
/*
- Locally used only
*/
static optionDescription LongOptionDescription [] = {
{1," -a Append the tags to an existing tag file."},
#ifdef DEBUG
{1," -b <line>"},
{1," Set break line."},
#endif
{0," -B Use backward searching patterns (?...?)."},
#ifdef DEBUG
{1," -D <level>"},
{1," Set debug level."},
#endif
{0," -e Output tag file for use with Emacs."},
{1," -f <name>"},
{1," Write tags to specified file. Value of \"-\" writes tags to stdout"},
{1," [\"tags\"; or \"TAGS\" when -e supplied]."},
{0," -F Use forward searching patterns (/.../) (default)."},
{1," -h <list>"},
{1," Specify list of file extensions to be treated as include files."},
{1," [\".h.H.hh.hpp.hxx.h++\"]."},
{1," -I <list|@file>"},
{1," A list of tokens to be specially handled is read from either the"},
{1," command line or the specified file."},
{1," -L <file>"},
{1," A list of source file names are read from the specified file."},
{1," If specified as \"-\", then standard input is read."},
{0," -n Equivalent to --excmd=number."},
{0," -N Equivalent to --excmd=pattern."},
{1," -o Alternative for -f."},
#ifdef RECURSE_SUPPORTED
{1," -R Equivalent to --recurse."},
#else
{1," -R Not supported on this platform."},
#endif
{0," -u Equivalent to --sort=no."},
{1," -V Equivalent to --verbose."},
{1," -x Print a tabular cross reference file to standard output."},
{1," --append=[yes|no]"},
{1," Should tags should be appended to existing tag file [no]?"},
{1," --config-filename=fileName"},
{1," Use 'fileName' instead of 'ctags' in option file names."},
{1," --etags-include=file"},
{1," Include reference to 'file' in Emacs-style tag file (requires -e)."},
{1," --exclude=pattern"},
{1," Exclude files and directories matching 'pattern'."},
{0," --excmd=number|pattern|mix"},
#ifdef MACROS_USE_PATTERNS
{0," Uses the specified type of EX command to locate tags [pattern]."},
#else
{0," Uses the specified type of EX command to locate tags [mix]."},
#endif
{1," --extra=[+|-]flags"},
{1," Include extra tag entries for selected information (flags: \"fq\")."},
{1," --fields=[+|-]flags"},
{1," Include selected extension fields (flags: \"afmikKlnsStz\") [fks]."},
{1," --file-scope=[yes|no]"},
{1," Should tags scoped only for a single file (e.g. \"static\" tags"},
{1," be included in the output [yes]?"},
{1," --filter=[yes|no]"},
{1," Behave as a filter, reading file names from standard input and"},
{1," writing tags to standard output [no]."},
{1," --filter-terminator=string"},
{1," Specify string to print to stdout following the tags for each file"},
{1," parsed when --filter is enabled."},
{0," --format=level"},
#if DEFAULT_FILE_FORMAT == 1
{0," Force output of specified tag file format [1]."},
#else
{0," Force output of specified tag file format [2]."},
#endif
{1," --help"},
{1," Print this option summary."},
{1," --if0=[yes|no]"},
{1," Should C code within #if 0 conditional branches be parsed [no]?"},
{1," --<LANG>-kinds=[+|-]kinds"},
{1," Enable/disable tag kinds for language <LANG>."},
{1," --langdef=name"},
{1," Define a new language to be parsed with regular expressions."},
{1," --langmap=map(s)"},
{1," Override default mapping of language to source file extension."},
{1," --language-force=language"},
{1," Force all files to be interpreted using specified language."},
{1," --languages=[+|-]list"},
{1," Restrict files scanned for tags to those mapped to langauges"},
{1," specified in the comma-separated 'list'. The list can contain any"},
{1," built-in or user-defined language [all]."},
{1," --license"},
{1," Print details of software license."},
{0," --line-directives=[yes|no]"},
{0," Should #line directives be processed [no]?"},
{1," --links=[yes|no]"},
{1," Indicate whether symbolic links should be followed [yes]."},
{1," --list-kinds=[language|all]"},
{1," Output a list of all tag kinds for specified language or all."},
{1," --list-languages"},
{1," Output list of supported languages."},
{1," --list-maps=[language|all]"},
{1," Output list of language mappings."},
{1," --options=file"},
{1," Specify file from which command line options should be read."},
{1," --recurse=[yes|no]"},
#ifdef RECURSE_SUPPORTED
{1," Recurse into directories supplied on command line [no]."},
#else
{1," Not supported on this platform."},
#endif
#ifdef HAVE_REGEX
{1," --regex-<LANG>=/line_pattern/name_pattern/[flags]"},
{1," Define regular expression for locating tags in specific language."},
#endif
{0," --sort=[yes|no|foldcase]"},
{0," Should tags be sorted (optionally ignoring case) [yes]?."},
{0," --tag-relative=[yes|no]"},
{0," Should paths be relative to location of tag file [no; yes when -e]?"},
{1," --totals=[yes|no]"},
{1," Print statistics about source and tag files [no]."},
{1," --verbose=[yes|no]"},
{1," Enable verbose messages describing actions on each source file."},
{1," --version"},
{1," Print version identifier to standard output."},
{1, NULL}
};
static const char* const License1 =
"This program is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU General Public License\n"
"as published by the Free Software Foundation; either version 2\n"
"of the License, or (at your option) any later version.\n"
"\n";
static const char* const License2 =
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"GNU General Public License for more details.\n"
"\n"
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
"Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n";
/* Contains a set of strings describing the set of "features" compiled into
* the code.
*/
static const char *const Features [] = {
#ifdef WIN32
"win32",
#endif
#ifdef DJGPP
"msdos_32",
#else
# ifdef MSDOS
"msdos_16",
# endif
#endif
#ifdef OS2
"os2",
#endif
#ifdef AMIGA
"amiga",
#endif
#ifdef VMS
"vms",
#endif
#ifdef HAVE_FNMATCH
"wildcards",
#endif
#ifdef HAVE_REGEX
"regex",
#endif
#ifndef EXTERNAL_SORT
"internal-sort",
#endif
#ifdef CUSTOM_CONFIGURATION_FILE
"custom-conf",
#endif
#if (defined (MSDOS) || defined (WIN32) || defined (OS2)) && defined (UNIX_PATH_SEPARATOR)
"unix-path-separator",
#endif
#ifdef DEBUG
"debug",
#endif
NULL
};
/*
* FUNCTION PROTOTYPES
*/
static boolean parseFileOptions (const char *const fileName);
static boolean parseAllConfigurationFilesOptionsInDirectory(const char *const fileName);
/*
* FUNCTION DEFINITIONS
*/
#if defined(_WIN32)
/* Some versions of MinGW are missing _vscprintf's declaration, although they
* still provide the symbol in the import library.
*/
#ifdef __MINGW32__
_CRTIMP int _vscprintf(const char *format, va_list argptr);
#endif
#ifndef va_copy
#define va_copy(dest, src) (dest = src)
#endif
int asprintf(char **strp, const char *fmt, ...)
{
va_list args;
va_list args_copy;
int length;
size_t size;
va_start(args, fmt);
va_copy(args_copy, args);
#ifdef _WIN32
/* We need to use _vcsprintf to calculate the length as vsnprintf returns -1
* if the number of characters to write is greater than count.
*/
length = _vscprintf(fmt, args_copy);
#else
char dummy;
length = vsnprintf(&dummy, sizeof dummy, fmt, args_copy);
#endif
va_end(args_copy);
Assert(length >= 0);
size = length + 1;
*strp = malloc(size);
if (!*strp) {
return -1;
}
va_start(args, fmt);
vsnprintf(*strp, size, fmt, args);
va_end(args);
return length;
}
#endif
#if (defined (__SVR4) && defined (__sun))
int vasprintf(char **ret, const char *format, va_list args)
{
va_list copy;
va_copy(copy, args);
/* Make sure it is determinate, despite manuals indicating otherwise */
*ret = 0;
int count = vsnprintf(NULL, 0, format, args);
if (count >= 0) {
char* buffer = malloc(count + 1);
if (buffer != NULL) {
count = vsnprintf(buffer, count + 1, format, copy);
if (count < 0)
free(buffer);
else
*ret = buffer;
}
}
va_end(args); // Each va_start() or va_copy() needs a va_end()
return count;
}
int asprintf(char **strp, const char *fmt, ...)
{
s32 size;
va_list args;
va_start(args, fmt);
size = vasprintf(strp, fmt, args);
va_end(args);
return size;
}
#endif
extern void verbose (const char *const format, ...)
{
if (Option.verbose)
{
va_list ap;
va_start (ap, format);
vprintf (format, ap);
va_end (ap);
}
}
static char *stringCopy (const char *const string)
{
char* result = NULL;
if (string != NULL)
result = eStrdup (string);
return result;
}
static void freeString (char **const pString)
{
if (*pString != NULL)
{
eFree (*pString);
*pString = NULL;
}
}
extern void freeList (stringList** const pList)
{
if (*pList != NULL)
{
stringListDelete (*pList);
*pList = NULL;
}
}
extern void setDefaultTagFileName (void)
{
if (Option.tagFileName != NULL)
; /* accept given name */
else if (Option.etags)
Option.tagFileName = stringCopy (ETAGS_FILE);
else
Option.tagFileName = stringCopy (CTAGS_FILE);
}
extern boolean filesRequired (void)
{
boolean result = FilesRequired;
if (Option.recurse)
result = FALSE;
return result;
}
extern void checkOptions (void)
{
const char* notice;
if (Option.xref)
{
notice = "xref output";
if (Option.include.fileNames)
{
error (WARNING, "%s disables file name tags", notice);
Option.include.fileNames = FALSE;
}
}
if (Option.append)
{
notice = "append mode is not compatible with";
if (isDestinationStdout ())
error (FATAL, "%s tags to stdout", notice);
}
if (Option.filter)
{
notice = "filter mode";
if (Option.printTotals)
{
error (WARNING, "%s disables totals", notice);
Option.printTotals = FALSE;
}
if (Option.tagFileName != NULL)
error (WARNING, "%s ignores output tag file name", notice);
}
}
static void setEtagsMode (void)
{
Option.etags = TRUE;
Option.sorted = SO_UNSORTED;
Option.lineDirectives = FALSE;
Option.tagRelative = TRUE;
}
extern void testEtagsInvocation (void)
{
char* const execName = eStrdup (getExecutableName ());
char* const etags = eStrdup (ETAGS);
#ifdef CASE_INSENSITIVE_FILENAMES
toLowerString (execName);
toLowerString (etags);
#endif
if (strstr (execName, etags) != NULL)
{
verbose ("Running in etags mode\n");
setEtagsMode ();
}
eFree (execName);
eFree (etags);
}
/*
* Cooked argument parsing
*/
static void parseShortOption (cookedArgs *const args)
{
args->simple [0] = *args->shortOptions++;
args->simple [1] = '\0';
args->item = args->simple;
if (! isCompoundOption (*args->simple))
args->parameter = "";
else if (*args->shortOptions == '\0')
{
argForth (args->args);
if (argOff (args->args))
args->parameter = NULL;
else
args->parameter = argItem (args->args);
args->shortOptions = NULL;
}
else
{
args->parameter = args->shortOptions;
args->shortOptions = NULL;
}
}
static void parseLongOption (cookedArgs *const args, const char *item)
{
const char* const equal = strchr (item, '=');
if (equal == NULL)
{
args->item = eStrdup (item); /* FIXME: memory leak. */
args->parameter = "";
}
else
{
const size_t length = equal - item;
args->item = xMalloc (length + 1, char); /* FIXME: memory leak. */
strncpy (args->item, item, length);
args->item [length] = '\0';
args->parameter = equal + 1;
}
Assert (args->item != NULL);
Assert (args->parameter != NULL);
}
static void cArgRead (cookedArgs *const current)
{
char* item;
Assert (current != NULL);
if (! argOff (current->args))
{
item = argItem (current->args);
current->shortOptions = NULL;
Assert (item != NULL);
if (strncmp (item, "--", (size_t) 2) == 0)
{
current->isOption = TRUE;
current->longOption = TRUE;
parseLongOption (current, item + 2);
Assert (current->item != NULL);
Assert (current->parameter != NULL);
}
else if (*item == '-')
{
current->isOption = TRUE;
current->longOption = FALSE;
current->shortOptions = item + 1;
parseShortOption (current);
}
else
{
current->isOption = FALSE;
current->longOption = FALSE;
current->item = item;
current->parameter = NULL;
}
}
}
extern cookedArgs* cArgNewFromString (const char* string)
{
cookedArgs* const result = xMalloc (1, cookedArgs);
memset (result, 0, sizeof (cookedArgs));
result->args = argNewFromString (string);
cArgRead (result);
return result;
}
extern cookedArgs* cArgNewFromArgv (char* const* const argv)
{
cookedArgs* const result = xMalloc (1, cookedArgs);
memset (result, 0, sizeof (cookedArgs));
result->args = argNewFromArgv (argv);
cArgRead (result);
return result;
}
extern cookedArgs* cArgNewFromFile (FILE* const fp)
{
cookedArgs* const result = xMalloc (1, cookedArgs);
memset (result, 0, sizeof (cookedArgs));
result->args = argNewFromFile (fp);
cArgRead (result);
return result;
}
extern cookedArgs* cArgNewFromLineFile (FILE* const fp)
{
cookedArgs* const result = xMalloc (1, cookedArgs);
memset (result, 0, sizeof (cookedArgs));
result->args = argNewFromLineFile (fp);
cArgRead (result);
return result;
}
extern void cArgDelete (cookedArgs* const current)
{
Assert (current != NULL);
argDelete (current->args);
memset (current, 0, sizeof (cookedArgs));
eFree (current);
}
static boolean cArgOptionPending (cookedArgs* const current)
{
boolean result = FALSE;
if (current->shortOptions != NULL)
if (*current->shortOptions != '\0')
result = TRUE;
return result;
}
extern boolean cArgOff (cookedArgs* const current)
{
Assert (current != NULL);
return (boolean) (argOff (current->args) && ! cArgOptionPending (current));
}
extern boolean cArgIsOption (cookedArgs* const current)
{
Assert (current != NULL);
return current->isOption;
}
extern const char* cArgItem (cookedArgs* const current)
{
Assert (current != NULL);
return current->item;
}
extern void cArgForth (cookedArgs* const current)
{
Assert (current != NULL);
Assert (! cArgOff (current));
if (cArgOptionPending (current))
parseShortOption (current);
else
{
Assert (! argOff (current->args));
argForth (current->args);
if (! argOff (current->args))
cArgRead (current);
else
{
current->isOption = FALSE;
current->longOption = FALSE;
current->shortOptions = NULL;
current->item = NULL;
current->parameter = NULL;
}
}
}
/*
* File extension and language mapping
*/
static void addExtensionList (
stringList *const slist, const char *const elist, const boolean clear)
{
char *const extensionList = eStrdup (elist);
const char *extension = NULL;
boolean first = TRUE;
if (clear)
{
verbose (" clearing\n");
stringListClear (slist);
}
verbose (" adding: ");
if (elist != NULL && *elist != '\0')
{
extension = extensionList;
if (elist [0] == EXTENSION_SEPARATOR)
++extension;
}
while (extension != NULL)
{
char *separator = strchr (extension, EXTENSION_SEPARATOR);
if (separator != NULL)
*separator = '\0';
verbose ("%s%s", first ? "" : ", ",
*extension == '\0' ? "(NONE)" : extension);
stringListAdd (slist, vStringNewInit (extension));
first = FALSE;
if (separator == NULL)
extension = NULL;
else
extension = separator + 1;
}
if (Option.verbose)
{
printf ("\n now: ");
stringListPrint (slist);
putchar ('\n');
}
eFree (extensionList);
}
static boolean isFalse (const char *parameter)
{
return (boolean) (
strcasecmp (parameter, "0" ) == 0 ||
strcasecmp (parameter, "n" ) == 0 ||
strcasecmp (parameter, "no" ) == 0 ||
strcasecmp (parameter, "off") == 0);
}
static boolean isTrue (const char *parameter)
{
return (boolean) (
strcasecmp (parameter, "1" ) == 0 ||
strcasecmp (parameter, "y" ) == 0 ||
strcasecmp (parameter, "yes") == 0 ||
strcasecmp (parameter, "on" ) == 0);
}
/* Determines whether the specified file name is considered to be a header
* file for the purposes of determining whether enclosed tags are global or
* static.
*/
extern boolean isIncludeFile (const char *const fileName)
{
boolean result = FALSE;
const char *const extension = fileExtension (fileName);
if (Option.headerExt != NULL)
result = stringListExtensionMatched (Option.headerExt, extension);
return result;
}
/*
* Specific option processing
*/
static void processConfigFilenameOption (
const char *const option __unused__, const char *const parameter)
{
freeString (&Option.configFilename);
Option.configFilename = stringCopy (parameter);
}
static void processEtagsInclude (
const char *const option, const char *const parameter)
{
if (! Option.etags)
error (FATAL, "Etags must be enabled to use \"%s\" option", option);
else
{
vString *const file = vStringNewInit (parameter);
if (Option.etagsInclude == NULL)
Option.etagsInclude = stringListNew ();
stringListAdd (Option.etagsInclude, file);
FilesRequired = FALSE;
}
}
static void processExcludeOption (
const char *const option __unused__, const char *const parameter)
{
const char *const fileName = parameter + 1;
if (parameter [0] == '\0')
freeList (&Excluded);
else if (parameter [0] == '@')
{
stringList* const sl = stringListNewFromFile (fileName);
if (sl == NULL)
error (FATAL | PERROR, "cannot open \"%s\"", fileName);
if (Excluded == NULL)
Excluded = sl;
else
stringListCombine (Excluded, sl);
verbose (" adding exclude patterns from %s\n", fileName);
}
else
{
vString *const item = vStringNewInit (parameter);
if (Excluded == NULL)
Excluded = stringListNew ();
stringListAdd (Excluded, item);
verbose (" adding exclude pattern: %s\n", parameter);
}
}
extern boolean isExcludedFile (const char* const name)
{
const char* base = baseFilename (name);
boolean result = FALSE;
if (Excluded != NULL)
{
result = stringListFileMatched (Excluded, base);
if (! result && name != base)
result = stringListFileMatched (Excluded, name);
}
#ifdef AMIGA
/* not a good solution, but the only one which works often */
if (! result)
result = (boolean) (strcmp (name, TagFile.name) == 0);
#endif
return result;
}
static void processExcmdOption (
const char *const option, 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 \"%s\" option", option);
break;
}
}
static void processExtraTagsOption (
const char *const option, const char *const parameter)
{
struct sInclude *const inc = &Option.include;
const char *p = parameter;
boolean mode = TRUE;
int c;
if (*p != '+' && *p != '-')
{
inc->fileNames = FALSE;
inc->qualifiedTags = FALSE;
#if 0
inc->fileScope = FALSE;
#endif
}
while ((c = *p++) != '\0') switch (c)
{
case '+': mode = TRUE; break;
case '-': mode = FALSE; break;
case 'f': inc->fileNames = mode; break;
case 'q': inc->qualifiedTags = mode; break;
#if 0
case 'F': inc->fileScope = mode; break;
#endif
default: error(WARNING, "Unsupported parameter '%c' for \"%s\" option",
c, option);
break;
}
}
static void resetFieldsOption (
struct sExtFields *field, boolean mode)
{
memset(field, mode? ~0: 0, sizeof(*field));
}
static void processFieldsOption (
const char *const option, const char *const parameter)
{
struct sExtFields *field = &Option.extensionFields;
const char *p = parameter;
boolean mode = TRUE;
int c;
if (*p == '*')
{
resetFieldsOption(field, TRUE);
p++;
}
else if (*p != '+' && *p != '-')
resetFieldsOption(field, FALSE);
while ((c = *p++) != '\0') switch (c)
{
case '+': mode = TRUE; break;
case '-': mode = FALSE; break;
case 'a': field->access = mode; break;
case 'f': field->fileScope = mode; break;
case 'm': field->implementation = mode; break;
case 'i': field->inheritance = mode; break;
case 'k': field->kind = mode; break;
case 'K': field->kindLong = mode; break;
case 'l': field->language = mode; break;
case 'n': field->lineNumber = mode; break;
case 's': field->scope = mode; break;
case 'S': field->signature = mode; break;
case 'z': field->kindKey = mode; break;
case 't': field->typeRef = mode; break;
default: error(WARNING, "Unsupported parameter '%c' for \"%s\" option",
c, option);
break;
}
}
static void processFilterTerminatorOption (
const char *const option __unused__, const char *const parameter)
{
freeString (&Option.filterTerminator);
Option.filterTerminator = stringCopy (parameter);
}
static void processFormatOption (
const char *const option, const char *const parameter)
{
unsigned int format;
if (sscanf (parameter, "%u", &format) < 1)
error (FATAL, "Invalid value for \"%s\" option",option);
else if (format <= (unsigned int) MaxSupportedTagFormat)
Option.tagFileFormat = format;
else
error (FATAL, "Unsupported value for \"%s\" option", option);
}
static void printInvocationDescription (void)
{