ctags.rb 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Rakefile +23 -0
- data/ctags.rb.gemspec +23 -0
- data/ext/.gitignore +3 -0
- data/ext/extconf.rb +15 -0
- data/ext/vendor/exuberant-ctags/.gitignore +6 -0
- data/ext/vendor/exuberant-ctags/.indent.pro +31 -0
- data/ext/vendor/exuberant-ctags/COPYING +340 -0
- data/ext/vendor/exuberant-ctags/EXTENDING.html +386 -0
- data/ext/vendor/exuberant-ctags/FAQ +371 -0
- data/ext/vendor/exuberant-ctags/INSTALL +215 -0
- data/ext/vendor/exuberant-ctags/INSTALL.oth +73 -0
- data/ext/vendor/exuberant-ctags/MAINTAINERS +88 -0
- data/ext/vendor/exuberant-ctags/Makefile.in +222 -0
- data/ext/vendor/exuberant-ctags/NEWS +871 -0
- data/ext/vendor/exuberant-ctags/README +73 -0
- data/ext/vendor/exuberant-ctags/ant.c +42 -0
- data/ext/vendor/exuberant-ctags/argproc.c +505 -0
- data/ext/vendor/exuberant-ctags/args.c +274 -0
- data/ext/vendor/exuberant-ctags/args.h +63 -0
- data/ext/vendor/exuberant-ctags/asm.c +387 -0
- data/ext/vendor/exuberant-ctags/asp.c +328 -0
- data/ext/vendor/exuberant-ctags/awk.c +81 -0
- data/ext/vendor/exuberant-ctags/basic.c +203 -0
- data/ext/vendor/exuberant-ctags/beta.c +321 -0
- data/ext/vendor/exuberant-ctags/c.c +2932 -0
- data/ext/vendor/exuberant-ctags/cobol.c +50 -0
- data/ext/vendor/exuberant-ctags/config.h.in +277 -0
- data/ext/vendor/exuberant-ctags/configure +7704 -0
- data/ext/vendor/exuberant-ctags/configure.ac +532 -0
- data/ext/vendor/exuberant-ctags/ctags.1 +1186 -0
- data/ext/vendor/exuberant-ctags/ctags.h +28 -0
- data/ext/vendor/exuberant-ctags/ctags.html +2087 -0
- data/ext/vendor/exuberant-ctags/ctags.spec +40 -0
- data/ext/vendor/exuberant-ctags/debug.c +113 -0
- data/ext/vendor/exuberant-ctags/debug.h +70 -0
- data/ext/vendor/exuberant-ctags/descrip.mms +68 -0
- data/ext/vendor/exuberant-ctags/dosbatch.c +42 -0
- data/ext/vendor/exuberant-ctags/e_amiga.h +24 -0
- data/ext/vendor/exuberant-ctags/e_djgpp.h +47 -0
- data/ext/vendor/exuberant-ctags/e_mac.h +143 -0
- data/ext/vendor/exuberant-ctags/e_msoft.h +76 -0
- data/ext/vendor/exuberant-ctags/e_os2.h +37 -0
- data/ext/vendor/exuberant-ctags/e_qdos.h +34 -0
- data/ext/vendor/exuberant-ctags/e_riscos.h +58 -0
- data/ext/vendor/exuberant-ctags/e_vms.h +31 -0
- data/ext/vendor/exuberant-ctags/eiffel.c +1352 -0
- data/ext/vendor/exuberant-ctags/entry.c +847 -0
- data/ext/vendor/exuberant-ctags/entry.h +103 -0
- data/ext/vendor/exuberant-ctags/erlang.c +189 -0
- data/ext/vendor/exuberant-ctags/flex.c +2243 -0
- data/ext/vendor/exuberant-ctags/fortran.c +2197 -0
- data/ext/vendor/exuberant-ctags/general.h +127 -0
- data/ext/vendor/exuberant-ctags/get.c +669 -0
- data/ext/vendor/exuberant-ctags/get.h +50 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/all-wcprops +47 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/entries +112 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/README.txt.svn-base +5 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regcomp.c.svn-base +3818 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex.c.svn-base +74 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex.h.svn-base +575 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex_internal.c.svn-base +1713 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex_internal.h.svn-base +773 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regexec.c.svn-base +4338 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/README.txt +5 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/regcomp.c +3818 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/regex.c +74 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/regex.h +575 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/regex_internal.c +1713 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/regex_internal.h +773 -0
- data/ext/vendor/exuberant-ctags/gnu_regex/regexec.c +4338 -0
- data/ext/vendor/exuberant-ctags/html.c +49 -0
- data/ext/vendor/exuberant-ctags/jscript.c +1572 -0
- data/ext/vendor/exuberant-ctags/keyword.c +258 -0
- data/ext/vendor/exuberant-ctags/keyword.h +34 -0
- data/ext/vendor/exuberant-ctags/lisp.c +139 -0
- data/ext/vendor/exuberant-ctags/lregex.c +704 -0
- data/ext/vendor/exuberant-ctags/lua.c +133 -0
- data/ext/vendor/exuberant-ctags/mac.c +273 -0
- data/ext/vendor/exuberant-ctags/magic.diff +21 -0
- data/ext/vendor/exuberant-ctags/main.c +584 -0
- data/ext/vendor/exuberant-ctags/main.h +32 -0
- data/ext/vendor/exuberant-ctags/maintainer.mak +476 -0
- data/ext/vendor/exuberant-ctags/make.c +217 -0
- data/ext/vendor/exuberant-ctags/matlab.c +44 -0
- data/ext/vendor/exuberant-ctags/mk_bc3.mak +46 -0
- data/ext/vendor/exuberant-ctags/mk_bc5.mak +49 -0
- data/ext/vendor/exuberant-ctags/mk_djg.mak +18 -0
- data/ext/vendor/exuberant-ctags/mk_manx.mak +65 -0
- data/ext/vendor/exuberant-ctags/mk_mingw.mak +31 -0
- data/ext/vendor/exuberant-ctags/mk_mpw.mak +130 -0
- data/ext/vendor/exuberant-ctags/mk_mvc.mak +40 -0
- data/ext/vendor/exuberant-ctags/mk_os2.mak +104 -0
- data/ext/vendor/exuberant-ctags/mk_qdos.mak +100 -0
- data/ext/vendor/exuberant-ctags/mk_sas.mak +63 -0
- data/ext/vendor/exuberant-ctags/mkinstalldirs +40 -0
- data/ext/vendor/exuberant-ctags/ocaml.c +1842 -0
- data/ext/vendor/exuberant-ctags/options.c +1842 -0
- data/ext/vendor/exuberant-ctags/options.h +155 -0
- data/ext/vendor/exuberant-ctags/parse.c +677 -0
- data/ext/vendor/exuberant-ctags/parse.h +129 -0
- data/ext/vendor/exuberant-ctags/parsers.h +63 -0
- data/ext/vendor/exuberant-ctags/pascal.c +267 -0
- data/ext/vendor/exuberant-ctags/perl.c +382 -0
- data/ext/vendor/exuberant-ctags/php.c +237 -0
- data/ext/vendor/exuberant-ctags/python.c +771 -0
- data/ext/vendor/exuberant-ctags/qdos.c +106 -0
- data/ext/vendor/exuberant-ctags/read.c +569 -0
- data/ext/vendor/exuberant-ctags/read.h +116 -0
- data/ext/vendor/exuberant-ctags/readtags.c +959 -0
- data/ext/vendor/exuberant-ctags/readtags.h +252 -0
- data/ext/vendor/exuberant-ctags/rexx.c +39 -0
- data/ext/vendor/exuberant-ctags/routines.c +891 -0
- data/ext/vendor/exuberant-ctags/routines.h +134 -0
- data/ext/vendor/exuberant-ctags/ruby.c +408 -0
- data/ext/vendor/exuberant-ctags/scheme.c +111 -0
- data/ext/vendor/exuberant-ctags/sh.c +115 -0
- data/ext/vendor/exuberant-ctags/slang.c +41 -0
- data/ext/vendor/exuberant-ctags/sml.c +212 -0
- data/ext/vendor/exuberant-ctags/sort.c +230 -0
- data/ext/vendor/exuberant-ctags/sort.h +32 -0
- data/ext/vendor/exuberant-ctags/source.mak +122 -0
- data/ext/vendor/exuberant-ctags/sql.c +2112 -0
- data/ext/vendor/exuberant-ctags/strlist.c +281 -0
- data/ext/vendor/exuberant-ctags/strlist.h +54 -0
- data/ext/vendor/exuberant-ctags/tcl.c +116 -0
- data/ext/vendor/exuberant-ctags/tex.c +524 -0
- data/ext/vendor/exuberant-ctags/verilog.c +340 -0
- data/ext/vendor/exuberant-ctags/vhdl.c +835 -0
- data/ext/vendor/exuberant-ctags/vim.c +636 -0
- data/ext/vendor/exuberant-ctags/vstring.c +232 -0
- data/ext/vendor/exuberant-ctags/vstring.h +85 -0
- data/ext/vendor/exuberant-ctags/yacc.c +40 -0
- data/lib/ctags/exuberant.rb +45 -0
- data/lib/ctags/version.rb +3 -0
- data/lib/ctags.rb +6 -0
- data/test/test_ctags.rb +24 -0
- metadata +233 -0
@@ -0,0 +1,584 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: main.c 536 2007-06-02 06:09:00Z elliotth $
|
3
|
+
*
|
4
|
+
* Copyright (c) 1996-2003, Darren Hiebert
|
5
|
+
*
|
6
|
+
* Author: Darren Hiebert <dhiebert@users.sourceforge.net>
|
7
|
+
* http://ctags.sourceforge.net
|
8
|
+
*
|
9
|
+
* This source code is released for free distribution under the terms of the
|
10
|
+
* GNU General Public License. It is provided on an as-is basis and no
|
11
|
+
* responsibility is accepted for its failure to perform as expected.
|
12
|
+
*
|
13
|
+
* This is a reimplementation of the ctags (1) program. It is an attempt to
|
14
|
+
* provide a fully featured ctags program which is free of the limitations
|
15
|
+
* which most (all?) others are subject to.
|
16
|
+
*
|
17
|
+
* This module contains the start-up code and routines to determine the list
|
18
|
+
* of files to parsed for tags.
|
19
|
+
*/
|
20
|
+
|
21
|
+
/*
|
22
|
+
* INCLUDE FILES
|
23
|
+
*/
|
24
|
+
#include "general.h" /* must always come first */
|
25
|
+
|
26
|
+
#include <string.h>
|
27
|
+
|
28
|
+
/* To provide timings features if available.
|
29
|
+
*/
|
30
|
+
#ifdef HAVE_CLOCK
|
31
|
+
# ifdef HAVE_TIME_H
|
32
|
+
# include <time.h>
|
33
|
+
# endif
|
34
|
+
#else
|
35
|
+
# ifdef HAVE_TIMES
|
36
|
+
# ifdef HAVE_SYS_TIMES_H
|
37
|
+
# include <sys/times.h>
|
38
|
+
# endif
|
39
|
+
# endif
|
40
|
+
#endif
|
41
|
+
|
42
|
+
/* To provide directory searching for recursion feature.
|
43
|
+
*/
|
44
|
+
#ifdef AMIGA
|
45
|
+
# include <dos/dosasl.h> /* for struct AnchorPath */
|
46
|
+
# include <clib/dos_protos.h> /* function prototypes */
|
47
|
+
# define ANCHOR_BUF_SIZE 512
|
48
|
+
# define ANCHOR_SIZE (sizeof (struct AnchorPath) + ANCHOR_BUF_SIZE)
|
49
|
+
# ifdef __SASC
|
50
|
+
extern struct DosLibrary *DOSBase;
|
51
|
+
# include <pragmas/dos_pragmas.h>
|
52
|
+
# endif
|
53
|
+
#endif
|
54
|
+
|
55
|
+
#ifdef HAVE_DIRENT_H
|
56
|
+
# ifdef __BORLANDC__
|
57
|
+
# define boolean BORLAND_boolean
|
58
|
+
# endif
|
59
|
+
# ifdef HAVE_SYS_TYPES_H
|
60
|
+
# include <sys/types.h> /* required by dirent.h */
|
61
|
+
# endif
|
62
|
+
# include <dirent.h> /* to declare opendir() */
|
63
|
+
# undef boolean
|
64
|
+
#endif
|
65
|
+
#ifdef HAVE_DIRECT_H
|
66
|
+
# include <direct.h> /* to _getcwd() */
|
67
|
+
#endif
|
68
|
+
#ifdef HAVE_DOS_H
|
69
|
+
# include <dos.h> /* to declare FA_DIREC */
|
70
|
+
#endif
|
71
|
+
#ifdef HAVE_DIR_H
|
72
|
+
# include <dir.h> /* to declare findfirst() and findnext */
|
73
|
+
#endif
|
74
|
+
#ifdef HAVE_IO_H
|
75
|
+
# include <io.h> /* to declare _findfirst() */
|
76
|
+
#endif
|
77
|
+
|
78
|
+
|
79
|
+
#include "debug.h"
|
80
|
+
#include "keyword.h"
|
81
|
+
#include "main.h"
|
82
|
+
#include "options.h"
|
83
|
+
#include "read.h"
|
84
|
+
#include "routines.h"
|
85
|
+
|
86
|
+
/*
|
87
|
+
* MACROS
|
88
|
+
*/
|
89
|
+
#define plural(value) (((unsigned long)(value) == 1L) ? "" : "s")
|
90
|
+
|
91
|
+
/*
|
92
|
+
* DATA DEFINITIONS
|
93
|
+
*/
|
94
|
+
static struct { long files, lines, bytes; } Totals = { 0, 0, 0 };
|
95
|
+
|
96
|
+
#ifdef AMIGA
|
97
|
+
# include "ctags.h"
|
98
|
+
static const char *VERsion = "$VER: "PROGRAM_NAME" "PROGRAM_VERSION" "
|
99
|
+
# ifdef __SASC
|
100
|
+
__AMIGADATE__
|
101
|
+
# else
|
102
|
+
__DATE__
|
103
|
+
# endif
|
104
|
+
" "AUTHOR_NAME" $";
|
105
|
+
#endif
|
106
|
+
|
107
|
+
/*
|
108
|
+
* FUNCTION PROTOTYPES
|
109
|
+
*/
|
110
|
+
static boolean createTagsForEntry (const char *const entryName);
|
111
|
+
|
112
|
+
/*
|
113
|
+
* FUNCTION DEFINITIONS
|
114
|
+
*/
|
115
|
+
|
116
|
+
extern void addTotals (
|
117
|
+
const unsigned int files, const long unsigned int lines,
|
118
|
+
const long unsigned int bytes)
|
119
|
+
{
|
120
|
+
Totals.files += files;
|
121
|
+
Totals.lines += lines;
|
122
|
+
Totals.bytes += bytes;
|
123
|
+
}
|
124
|
+
|
125
|
+
extern boolean isDestinationStdout (void)
|
126
|
+
{
|
127
|
+
boolean toStdout = FALSE;
|
128
|
+
|
129
|
+
if (Option.xref || Option.filter ||
|
130
|
+
(Option.tagFileName != NULL && (strcmp (Option.tagFileName, "-") == 0
|
131
|
+
#if defined (VMS)
|
132
|
+
|| strcmp (Option.tagFileName, "sys$output") == 0
|
133
|
+
#else
|
134
|
+
|| strcmp (Option.tagFileName, "/dev/stdout") == 0
|
135
|
+
#endif
|
136
|
+
)))
|
137
|
+
toStdout = TRUE;
|
138
|
+
return toStdout;
|
139
|
+
}
|
140
|
+
|
141
|
+
#if defined (HAVE_OPENDIR)
|
142
|
+
static boolean recurseUsingOpendir (const char *const dirName)
|
143
|
+
{
|
144
|
+
boolean resize = FALSE;
|
145
|
+
DIR *const dir = opendir (dirName);
|
146
|
+
if (dir == NULL)
|
147
|
+
error (WARNING | PERROR, "cannot recurse into directory \"%s\"", dirName);
|
148
|
+
else
|
149
|
+
{
|
150
|
+
struct dirent *entry;
|
151
|
+
while ((entry = readdir (dir)) != NULL)
|
152
|
+
{
|
153
|
+
if (strcmp (entry->d_name, ".") != 0 &&
|
154
|
+
strcmp (entry->d_name, "..") != 0)
|
155
|
+
{
|
156
|
+
vString *filePath;
|
157
|
+
if (strcmp (dirName, ".") == 0)
|
158
|
+
filePath = vStringNewInit (entry->d_name);
|
159
|
+
else
|
160
|
+
filePath = combinePathAndFile (dirName, entry->d_name);
|
161
|
+
resize |= createTagsForEntry (vStringValue (filePath));
|
162
|
+
vStringDelete (filePath);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
closedir (dir);
|
166
|
+
}
|
167
|
+
return resize;
|
168
|
+
}
|
169
|
+
|
170
|
+
#elif defined (HAVE_FINDFIRST) || defined (HAVE__FINDFIRST)
|
171
|
+
|
172
|
+
static boolean createTagsForWildcardEntry (
|
173
|
+
const char *const pattern, const size_t dirLength,
|
174
|
+
const char *const entryName)
|
175
|
+
{
|
176
|
+
boolean resize = FALSE;
|
177
|
+
/* we must not recurse into the directories "." or ".." */
|
178
|
+
if (strcmp (entryName, ".") != 0 && strcmp (entryName, "..") != 0)
|
179
|
+
{
|
180
|
+
vString *const filePath = vStringNew ();
|
181
|
+
vStringNCopyS (filePath, pattern, dirLength);
|
182
|
+
vStringCatS (filePath, entryName);
|
183
|
+
resize = createTagsForEntry (vStringValue (filePath));
|
184
|
+
vStringDelete (filePath);
|
185
|
+
}
|
186
|
+
return resize;
|
187
|
+
}
|
188
|
+
|
189
|
+
static boolean createTagsForWildcardUsingFindfirst (const char *const pattern)
|
190
|
+
{
|
191
|
+
boolean resize = FALSE;
|
192
|
+
const size_t dirLength = baseFilename (pattern) - pattern;
|
193
|
+
#if defined (HAVE_FINDFIRST)
|
194
|
+
struct ffblk fileInfo;
|
195
|
+
int result = findfirst (pattern, &fileInfo, FA_DIREC);
|
196
|
+
while (result == 0)
|
197
|
+
{
|
198
|
+
const char *const entry = (const char *) fileInfo.ff_name;
|
199
|
+
resize |= createTagsForWildcardEntry (pattern, dirLength, entry);
|
200
|
+
result = findnext (&fileInfo);
|
201
|
+
}
|
202
|
+
#elif defined (HAVE__FINDFIRST)
|
203
|
+
struct _finddata_t fileInfo;
|
204
|
+
findfirst_t hFile = _findfirst (pattern, &fileInfo);
|
205
|
+
if (hFile != -1L)
|
206
|
+
{
|
207
|
+
do
|
208
|
+
{
|
209
|
+
const char *const entry = (const char *) fileInfo.name;
|
210
|
+
resize |= createTagsForWildcardEntry (pattern, dirLength, entry);
|
211
|
+
} while (_findnext (hFile, &fileInfo) == 0);
|
212
|
+
_findclose (hFile);
|
213
|
+
}
|
214
|
+
#endif
|
215
|
+
return resize;
|
216
|
+
}
|
217
|
+
|
218
|
+
#elif defined (AMIGA)
|
219
|
+
|
220
|
+
static boolean createTagsForAmigaWildcard (const char *const pattern)
|
221
|
+
{
|
222
|
+
boolean resize = FALSE;
|
223
|
+
struct AnchorPath *const anchor =
|
224
|
+
(struct AnchorPath *) eMalloc ((size_t) ANCHOR_SIZE);
|
225
|
+
LONG result;
|
226
|
+
|
227
|
+
memset (anchor, 0, (size_t) ANCHOR_SIZE);
|
228
|
+
anchor->ap_Strlen = ANCHOR_BUF_SIZE;
|
229
|
+
/* Allow '.' for current directory */
|
230
|
+
#ifdef APF_DODOT
|
231
|
+
anchor->ap_Flags = APF_DODOT | APF_DOWILD;
|
232
|
+
#else
|
233
|
+
anchor->ap_Flags = APF_DoDot | APF_DoWild;
|
234
|
+
#endif
|
235
|
+
result = MatchFirst ((UBYTE *) pattern, anchor);
|
236
|
+
while (result == 0)
|
237
|
+
{
|
238
|
+
resize |= createTagsForEntry ((char *) anchor->ap_Buf);
|
239
|
+
result = MatchNext (anchor);
|
240
|
+
}
|
241
|
+
MatchEnd (anchor);
|
242
|
+
eFree (anchor);
|
243
|
+
return resize;
|
244
|
+
}
|
245
|
+
#endif
|
246
|
+
|
247
|
+
static boolean recurseIntoDirectory (const char *const dirName)
|
248
|
+
{
|
249
|
+
boolean resize = FALSE;
|
250
|
+
if (isRecursiveLink (dirName))
|
251
|
+
verbose ("ignoring \"%s\" (recursive link)\n", dirName);
|
252
|
+
else if (! Option.recurse)
|
253
|
+
verbose ("ignoring \"%s\" (directory)\n", dirName);
|
254
|
+
else
|
255
|
+
{
|
256
|
+
verbose ("RECURSING into directory \"%s\"\n", dirName);
|
257
|
+
#if defined (HAVE_OPENDIR)
|
258
|
+
resize = recurseUsingOpendir (dirName);
|
259
|
+
#elif defined (HAVE_FINDFIRST) || defined (HAVE__FINDFIRST)
|
260
|
+
{
|
261
|
+
vString *const pattern = vStringNew ();
|
262
|
+
vStringCopyS (pattern, dirName);
|
263
|
+
vStringPut (pattern, OUTPUT_PATH_SEPARATOR);
|
264
|
+
vStringCatS (pattern, "*.*");
|
265
|
+
resize = createTagsForWildcardUsingFindfirst (vStringValue (pattern));
|
266
|
+
vStringDelete (pattern);
|
267
|
+
}
|
268
|
+
#elif defined (AMIGA)
|
269
|
+
{
|
270
|
+
vString *const pattern = vStringNew ();
|
271
|
+
if (*dirName != '\0' && strcmp (dirName, ".") != 0)
|
272
|
+
{
|
273
|
+
vStringCopyS (pattern, dirName);
|
274
|
+
if (dirName [strlen (dirName) - 1] != '/')
|
275
|
+
vStringPut (pattern, '/');
|
276
|
+
}
|
277
|
+
vStringCatS (pattern, "#?");
|
278
|
+
resize = createTagsForAmigaWildcard (vStringValue (pattern));
|
279
|
+
vStringDelete (pattern);
|
280
|
+
}
|
281
|
+
#endif
|
282
|
+
}
|
283
|
+
return resize;
|
284
|
+
}
|
285
|
+
|
286
|
+
static boolean createTagsForEntry (const char *const entryName)
|
287
|
+
{
|
288
|
+
boolean resize = FALSE;
|
289
|
+
fileStatus *status = eStat (entryName);
|
290
|
+
|
291
|
+
Assert (entryName != NULL);
|
292
|
+
if (isExcludedFile (entryName))
|
293
|
+
verbose ("excluding \"%s\"\n", entryName);
|
294
|
+
else if (status->isSymbolicLink && ! Option.followLinks)
|
295
|
+
verbose ("ignoring \"%s\" (symbolic link)\n", entryName);
|
296
|
+
else if (! status->exists && ! Option.stdinFileName)
|
297
|
+
error (WARNING | PERROR, "cannot open source file \"%s\"", entryName);
|
298
|
+
else if (status->isDirectory)
|
299
|
+
resize = recurseIntoDirectory (entryName);
|
300
|
+
else if (! status->isNormalFile)
|
301
|
+
verbose ("ignoring \"%s\" (special file)\n", entryName);
|
302
|
+
else
|
303
|
+
resize = parseFile (entryName);
|
304
|
+
|
305
|
+
eStatFree (status);
|
306
|
+
return resize;
|
307
|
+
}
|
308
|
+
|
309
|
+
#ifdef MANUAL_GLOBBING
|
310
|
+
|
311
|
+
static boolean createTagsForWildcardArg (const char *const arg)
|
312
|
+
{
|
313
|
+
boolean resize = FALSE;
|
314
|
+
vString *const pattern = vStringNewInit (arg);
|
315
|
+
char *patternS = vStringValue (pattern);
|
316
|
+
|
317
|
+
#if defined (HAVE_FINDFIRST) || defined (HAVE__FINDFIRST)
|
318
|
+
/* We must transform the "." and ".." forms into something that can
|
319
|
+
* be expanded by the findfirst/_findfirst functions.
|
320
|
+
*/
|
321
|
+
if (Option.recurse &&
|
322
|
+
(strcmp (patternS, ".") == 0 || strcmp (patternS, "..") == 0))
|
323
|
+
{
|
324
|
+
vStringPut (pattern, OUTPUT_PATH_SEPARATOR);
|
325
|
+
vStringCatS (pattern, "*.*");
|
326
|
+
}
|
327
|
+
resize |= createTagsForWildcardUsingFindfirst (patternS);
|
328
|
+
#endif
|
329
|
+
vStringDelete (pattern);
|
330
|
+
return resize;
|
331
|
+
}
|
332
|
+
|
333
|
+
#endif
|
334
|
+
|
335
|
+
static boolean createTagsForArgs (cookedArgs *const args)
|
336
|
+
{
|
337
|
+
boolean resize = FALSE;
|
338
|
+
|
339
|
+
/* Generate tags for each argument on the command line.
|
340
|
+
*/
|
341
|
+
while (! cArgOff (args))
|
342
|
+
{
|
343
|
+
const char *const arg = cArgItem (args);
|
344
|
+
|
345
|
+
#ifdef MANUAL_GLOBBING
|
346
|
+
resize |= createTagsForWildcardArg (arg);
|
347
|
+
#else
|
348
|
+
resize |= createTagsForEntry (arg);
|
349
|
+
#endif
|
350
|
+
cArgForth (args);
|
351
|
+
parseOptions (args);
|
352
|
+
}
|
353
|
+
return resize;
|
354
|
+
}
|
355
|
+
|
356
|
+
/* Read from an opened file a list of file names for which to generate tags.
|
357
|
+
*/
|
358
|
+
static boolean createTagsFromFileInput (FILE *const fp, const boolean filter)
|
359
|
+
{
|
360
|
+
boolean resize = FALSE;
|
361
|
+
if (fp != NULL)
|
362
|
+
{
|
363
|
+
cookedArgs *args = cArgNewFromLineFile (fp);
|
364
|
+
parseOptions (args);
|
365
|
+
while (! cArgOff (args))
|
366
|
+
{
|
367
|
+
resize |= createTagsForEntry (cArgItem (args));
|
368
|
+
if (filter)
|
369
|
+
{
|
370
|
+
if (Option.filterTerminator != NULL)
|
371
|
+
fputs (Option.filterTerminator, stdout);
|
372
|
+
fflush (stdout);
|
373
|
+
}
|
374
|
+
cArgForth (args);
|
375
|
+
parseOptions (args);
|
376
|
+
}
|
377
|
+
cArgDelete (args);
|
378
|
+
}
|
379
|
+
return resize;
|
380
|
+
}
|
381
|
+
|
382
|
+
/* Read from a named file a list of file names for which to generate tags.
|
383
|
+
*/
|
384
|
+
static boolean createTagsFromListFile (const char *const fileName)
|
385
|
+
{
|
386
|
+
boolean resize;
|
387
|
+
Assert (fileName != NULL);
|
388
|
+
if (strcmp (fileName, "-") == 0)
|
389
|
+
resize = createTagsFromFileInput (stdin, FALSE);
|
390
|
+
else
|
391
|
+
{
|
392
|
+
FILE *const fp = fopen (fileName, "r");
|
393
|
+
if (fp == NULL)
|
394
|
+
error (FATAL | PERROR, "cannot open list file \"%s\"", fileName);
|
395
|
+
resize = createTagsFromFileInput (fp, FALSE);
|
396
|
+
fclose (fp);
|
397
|
+
}
|
398
|
+
return resize;
|
399
|
+
}
|
400
|
+
|
401
|
+
#if defined (HAVE_CLOCK)
|
402
|
+
# define CLOCK_AVAILABLE
|
403
|
+
# ifndef CLOCKS_PER_SEC
|
404
|
+
# define CLOCKS_PER_SEC 1000000
|
405
|
+
# endif
|
406
|
+
#elif defined (HAVE_TIMES)
|
407
|
+
# define CLOCK_AVAILABLE
|
408
|
+
# define CLOCKS_PER_SEC 60
|
409
|
+
static clock_t clock (void)
|
410
|
+
{
|
411
|
+
struct tms buf;
|
412
|
+
|
413
|
+
times (&buf);
|
414
|
+
return (buf.tms_utime + buf.tms_stime);
|
415
|
+
}
|
416
|
+
#else
|
417
|
+
# define clock() (clock_t)0
|
418
|
+
#endif
|
419
|
+
|
420
|
+
static void printTotals (const clock_t *const timeStamps)
|
421
|
+
{
|
422
|
+
const unsigned long totalTags = TagFile.numTags.added +
|
423
|
+
TagFile.numTags.prev;
|
424
|
+
|
425
|
+
fprintf (errout, "%ld file%s, %ld line%s (%ld kB) scanned",
|
426
|
+
Totals.files, plural (Totals.files),
|
427
|
+
Totals.lines, plural (Totals.lines),
|
428
|
+
Totals.bytes/1024L);
|
429
|
+
#ifdef CLOCK_AVAILABLE
|
430
|
+
{
|
431
|
+
const double interval = ((double) (timeStamps [1] - timeStamps [0])) /
|
432
|
+
CLOCKS_PER_SEC;
|
433
|
+
|
434
|
+
fprintf (errout, " in %.01f seconds", interval);
|
435
|
+
if (interval != (double) 0.0)
|
436
|
+
fprintf (errout, " (%lu kB/s)",
|
437
|
+
(unsigned long) (Totals.bytes / interval) / 1024L);
|
438
|
+
}
|
439
|
+
#endif
|
440
|
+
fputc ('\n', errout);
|
441
|
+
|
442
|
+
fprintf (errout, "%lu tag%s added to tag file",
|
443
|
+
TagFile.numTags.added, plural (TagFile.numTags.added));
|
444
|
+
if (Option.append)
|
445
|
+
fprintf (errout, " (now %lu tags)", totalTags);
|
446
|
+
fputc ('\n', errout);
|
447
|
+
|
448
|
+
if (totalTags > 0 && Option.sorted != SO_UNSORTED)
|
449
|
+
{
|
450
|
+
fprintf (errout, "%lu tag%s sorted", totalTags, plural (totalTags));
|
451
|
+
#ifdef CLOCK_AVAILABLE
|
452
|
+
fprintf (errout, " in %.02f seconds",
|
453
|
+
((double) (timeStamps [2] - timeStamps [1])) / CLOCKS_PER_SEC);
|
454
|
+
#endif
|
455
|
+
fputc ('\n', errout);
|
456
|
+
}
|
457
|
+
|
458
|
+
#ifdef DEBUG
|
459
|
+
fprintf (errout, "longest tag line = %lu\n",
|
460
|
+
(unsigned long) TagFile.max.line);
|
461
|
+
#endif
|
462
|
+
}
|
463
|
+
|
464
|
+
static boolean etagsInclude (void)
|
465
|
+
{
|
466
|
+
return (boolean)(Option.etags && Option.etagsInclude != NULL);
|
467
|
+
}
|
468
|
+
|
469
|
+
static void makeTags (cookedArgs *args)
|
470
|
+
{
|
471
|
+
clock_t timeStamps [3];
|
472
|
+
boolean resize = FALSE;
|
473
|
+
boolean files = (boolean)(! cArgOff (args) || Option.fileList != NULL
|
474
|
+
|| Option.filter);
|
475
|
+
|
476
|
+
if (! files)
|
477
|
+
{
|
478
|
+
if (filesRequired ())
|
479
|
+
error (FATAL, "No files specified. Try \"%s --help\".",
|
480
|
+
getExecutableName ());
|
481
|
+
else if (! Option.recurse && ! Option.stdinFileName && ! etagsInclude ())
|
482
|
+
return;
|
483
|
+
}
|
484
|
+
|
485
|
+
#define timeStamp(n) timeStamps[(n)]=(Option.printTotals ? clock():(clock_t)0)
|
486
|
+
if (! Option.filter)
|
487
|
+
openTagFile ();
|
488
|
+
|
489
|
+
timeStamp (0);
|
490
|
+
|
491
|
+
if (! cArgOff (args))
|
492
|
+
{
|
493
|
+
verbose ("Reading command line arguments\n");
|
494
|
+
resize = createTagsForArgs (args);
|
495
|
+
}
|
496
|
+
if (Option.fileList != NULL)
|
497
|
+
{
|
498
|
+
verbose ("Reading list file\n");
|
499
|
+
resize = (boolean) (createTagsFromListFile (Option.fileList) || resize);
|
500
|
+
}
|
501
|
+
if (Option.filter)
|
502
|
+
{
|
503
|
+
verbose ("Reading filter input\n");
|
504
|
+
resize = (boolean) (createTagsFromFileInput (stdin, TRUE) || resize);
|
505
|
+
}
|
506
|
+
if (! files && Option.recurse)
|
507
|
+
resize = recurseIntoDirectory (".");
|
508
|
+
|
509
|
+
if (Option.stdinFileName)
|
510
|
+
{
|
511
|
+
resize = createTagsForEntry(Option.stdinFileName);
|
512
|
+
}
|
513
|
+
|
514
|
+
timeStamp (1);
|
515
|
+
|
516
|
+
if (! Option.filter)
|
517
|
+
closeTagFile (resize);
|
518
|
+
|
519
|
+
timeStamp (2);
|
520
|
+
|
521
|
+
if (Option.printTotals)
|
522
|
+
printTotals (timeStamps);
|
523
|
+
#undef timeStamp
|
524
|
+
}
|
525
|
+
|
526
|
+
/*
|
527
|
+
* Start up code
|
528
|
+
*/
|
529
|
+
|
530
|
+
extern int main (int __unused__ argc, char **argv)
|
531
|
+
{
|
532
|
+
cookedArgs *args;
|
533
|
+
#ifdef VMS
|
534
|
+
extern int getredirection (int *ac, char ***av);
|
535
|
+
|
536
|
+
/* do wildcard expansion and I/O redirection */
|
537
|
+
getredirection (&argc, &argv);
|
538
|
+
#endif
|
539
|
+
|
540
|
+
#ifdef AMIGA
|
541
|
+
/* This program doesn't work when started from the Workbench */
|
542
|
+
if (argc == 0)
|
543
|
+
exit (1);
|
544
|
+
#endif
|
545
|
+
|
546
|
+
#ifdef __EMX__
|
547
|
+
_wildcard (&argc, &argv); /* expand wildcards in argument list */
|
548
|
+
#endif
|
549
|
+
|
550
|
+
#if defined (macintosh) && BUILD_MPW_TOOL == 0
|
551
|
+
argc = ccommand (&argv);
|
552
|
+
#endif
|
553
|
+
|
554
|
+
setCurrentDirectory ();
|
555
|
+
setExecutableName (*argv++);
|
556
|
+
checkRegex ();
|
557
|
+
|
558
|
+
args = cArgNewFromArgv (argv);
|
559
|
+
previewFirstOption (args);
|
560
|
+
testEtagsInvocation ();
|
561
|
+
initializeParsing ();
|
562
|
+
initOptions ();
|
563
|
+
readOptionConfiguration ();
|
564
|
+
verbose ("Reading initial options from command line\n");
|
565
|
+
parseOptions (args);
|
566
|
+
checkOptions ();
|
567
|
+
makeTags (args);
|
568
|
+
|
569
|
+
/* Clean up.
|
570
|
+
*/
|
571
|
+
cArgDelete (args);
|
572
|
+
freeKeywordTable ();
|
573
|
+
freeRoutineResources ();
|
574
|
+
freeSourceFileResources ();
|
575
|
+
freeTagFileResources ();
|
576
|
+
freeOptionResources ();
|
577
|
+
freeParserResources ();
|
578
|
+
freeRegexResources ();
|
579
|
+
|
580
|
+
exit (0);
|
581
|
+
return 0;
|
582
|
+
}
|
583
|
+
|
584
|
+
/* vi:set tabstop=4 shiftwidth=4: */
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: main.h 443 2006-05-30 04:37:13Z darren $
|
3
|
+
*
|
4
|
+
* Copyright (c) 1998-2002, Darren Hiebert
|
5
|
+
*
|
6
|
+
* This source code is released for free distribution under the terms of the
|
7
|
+
* GNU General Public License.
|
8
|
+
*
|
9
|
+
* External interface to main.c
|
10
|
+
*/
|
11
|
+
#ifndef _MAIN_H
|
12
|
+
#define _MAIN_H
|
13
|
+
|
14
|
+
/*
|
15
|
+
* INCLUDE FILES
|
16
|
+
*/
|
17
|
+
#include "general.h" /* must always come first */
|
18
|
+
|
19
|
+
#include <stdio.h>
|
20
|
+
|
21
|
+
#include "vstring.h"
|
22
|
+
|
23
|
+
/*
|
24
|
+
* FUNCTION PROTOTYPES
|
25
|
+
*/
|
26
|
+
extern void addTotals (const unsigned int files, const long unsigned int lines, const long unsigned int bytes);
|
27
|
+
extern boolean isDestinationStdout (void);
|
28
|
+
extern int main (int argc, char **argv);
|
29
|
+
|
30
|
+
#endif /* _MAIN_H */
|
31
|
+
|
32
|
+
/* vi:set tabstop=4 shiftwidth=4: */
|