ctags.rb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/Gemfile +2 -0
  2. data/Rakefile +23 -0
  3. data/ctags.rb.gemspec +23 -0
  4. data/ext/.gitignore +3 -0
  5. data/ext/extconf.rb +15 -0
  6. data/ext/vendor/exuberant-ctags/.gitignore +6 -0
  7. data/ext/vendor/exuberant-ctags/.indent.pro +31 -0
  8. data/ext/vendor/exuberant-ctags/COPYING +340 -0
  9. data/ext/vendor/exuberant-ctags/EXTENDING.html +386 -0
  10. data/ext/vendor/exuberant-ctags/FAQ +371 -0
  11. data/ext/vendor/exuberant-ctags/INSTALL +215 -0
  12. data/ext/vendor/exuberant-ctags/INSTALL.oth +73 -0
  13. data/ext/vendor/exuberant-ctags/MAINTAINERS +88 -0
  14. data/ext/vendor/exuberant-ctags/Makefile.in +222 -0
  15. data/ext/vendor/exuberant-ctags/NEWS +871 -0
  16. data/ext/vendor/exuberant-ctags/README +73 -0
  17. data/ext/vendor/exuberant-ctags/ant.c +42 -0
  18. data/ext/vendor/exuberant-ctags/argproc.c +505 -0
  19. data/ext/vendor/exuberant-ctags/args.c +274 -0
  20. data/ext/vendor/exuberant-ctags/args.h +63 -0
  21. data/ext/vendor/exuberant-ctags/asm.c +387 -0
  22. data/ext/vendor/exuberant-ctags/asp.c +328 -0
  23. data/ext/vendor/exuberant-ctags/awk.c +81 -0
  24. data/ext/vendor/exuberant-ctags/basic.c +203 -0
  25. data/ext/vendor/exuberant-ctags/beta.c +321 -0
  26. data/ext/vendor/exuberant-ctags/c.c +2932 -0
  27. data/ext/vendor/exuberant-ctags/cobol.c +50 -0
  28. data/ext/vendor/exuberant-ctags/config.h.in +277 -0
  29. data/ext/vendor/exuberant-ctags/configure +7704 -0
  30. data/ext/vendor/exuberant-ctags/configure.ac +532 -0
  31. data/ext/vendor/exuberant-ctags/ctags.1 +1186 -0
  32. data/ext/vendor/exuberant-ctags/ctags.h +28 -0
  33. data/ext/vendor/exuberant-ctags/ctags.html +2087 -0
  34. data/ext/vendor/exuberant-ctags/ctags.spec +40 -0
  35. data/ext/vendor/exuberant-ctags/debug.c +113 -0
  36. data/ext/vendor/exuberant-ctags/debug.h +70 -0
  37. data/ext/vendor/exuberant-ctags/descrip.mms +68 -0
  38. data/ext/vendor/exuberant-ctags/dosbatch.c +42 -0
  39. data/ext/vendor/exuberant-ctags/e_amiga.h +24 -0
  40. data/ext/vendor/exuberant-ctags/e_djgpp.h +47 -0
  41. data/ext/vendor/exuberant-ctags/e_mac.h +143 -0
  42. data/ext/vendor/exuberant-ctags/e_msoft.h +76 -0
  43. data/ext/vendor/exuberant-ctags/e_os2.h +37 -0
  44. data/ext/vendor/exuberant-ctags/e_qdos.h +34 -0
  45. data/ext/vendor/exuberant-ctags/e_riscos.h +58 -0
  46. data/ext/vendor/exuberant-ctags/e_vms.h +31 -0
  47. data/ext/vendor/exuberant-ctags/eiffel.c +1352 -0
  48. data/ext/vendor/exuberant-ctags/entry.c +847 -0
  49. data/ext/vendor/exuberant-ctags/entry.h +103 -0
  50. data/ext/vendor/exuberant-ctags/erlang.c +189 -0
  51. data/ext/vendor/exuberant-ctags/flex.c +2243 -0
  52. data/ext/vendor/exuberant-ctags/fortran.c +2197 -0
  53. data/ext/vendor/exuberant-ctags/general.h +127 -0
  54. data/ext/vendor/exuberant-ctags/get.c +669 -0
  55. data/ext/vendor/exuberant-ctags/get.h +50 -0
  56. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/all-wcprops +47 -0
  57. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/entries +112 -0
  58. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/README.txt.svn-base +5 -0
  59. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regcomp.c.svn-base +3818 -0
  60. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex.c.svn-base +74 -0
  61. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex.h.svn-base +575 -0
  62. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex_internal.c.svn-base +1713 -0
  63. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regex_internal.h.svn-base +773 -0
  64. data/ext/vendor/exuberant-ctags/gnu_regex/.svn/text-base/regexec.c.svn-base +4338 -0
  65. data/ext/vendor/exuberant-ctags/gnu_regex/README.txt +5 -0
  66. data/ext/vendor/exuberant-ctags/gnu_regex/regcomp.c +3818 -0
  67. data/ext/vendor/exuberant-ctags/gnu_regex/regex.c +74 -0
  68. data/ext/vendor/exuberant-ctags/gnu_regex/regex.h +575 -0
  69. data/ext/vendor/exuberant-ctags/gnu_regex/regex_internal.c +1713 -0
  70. data/ext/vendor/exuberant-ctags/gnu_regex/regex_internal.h +773 -0
  71. data/ext/vendor/exuberant-ctags/gnu_regex/regexec.c +4338 -0
  72. data/ext/vendor/exuberant-ctags/html.c +49 -0
  73. data/ext/vendor/exuberant-ctags/jscript.c +1572 -0
  74. data/ext/vendor/exuberant-ctags/keyword.c +258 -0
  75. data/ext/vendor/exuberant-ctags/keyword.h +34 -0
  76. data/ext/vendor/exuberant-ctags/lisp.c +139 -0
  77. data/ext/vendor/exuberant-ctags/lregex.c +704 -0
  78. data/ext/vendor/exuberant-ctags/lua.c +133 -0
  79. data/ext/vendor/exuberant-ctags/mac.c +273 -0
  80. data/ext/vendor/exuberant-ctags/magic.diff +21 -0
  81. data/ext/vendor/exuberant-ctags/main.c +584 -0
  82. data/ext/vendor/exuberant-ctags/main.h +32 -0
  83. data/ext/vendor/exuberant-ctags/maintainer.mak +476 -0
  84. data/ext/vendor/exuberant-ctags/make.c +217 -0
  85. data/ext/vendor/exuberant-ctags/matlab.c +44 -0
  86. data/ext/vendor/exuberant-ctags/mk_bc3.mak +46 -0
  87. data/ext/vendor/exuberant-ctags/mk_bc5.mak +49 -0
  88. data/ext/vendor/exuberant-ctags/mk_djg.mak +18 -0
  89. data/ext/vendor/exuberant-ctags/mk_manx.mak +65 -0
  90. data/ext/vendor/exuberant-ctags/mk_mingw.mak +31 -0
  91. data/ext/vendor/exuberant-ctags/mk_mpw.mak +130 -0
  92. data/ext/vendor/exuberant-ctags/mk_mvc.mak +40 -0
  93. data/ext/vendor/exuberant-ctags/mk_os2.mak +104 -0
  94. data/ext/vendor/exuberant-ctags/mk_qdos.mak +100 -0
  95. data/ext/vendor/exuberant-ctags/mk_sas.mak +63 -0
  96. data/ext/vendor/exuberant-ctags/mkinstalldirs +40 -0
  97. data/ext/vendor/exuberant-ctags/ocaml.c +1842 -0
  98. data/ext/vendor/exuberant-ctags/options.c +1842 -0
  99. data/ext/vendor/exuberant-ctags/options.h +155 -0
  100. data/ext/vendor/exuberant-ctags/parse.c +677 -0
  101. data/ext/vendor/exuberant-ctags/parse.h +129 -0
  102. data/ext/vendor/exuberant-ctags/parsers.h +63 -0
  103. data/ext/vendor/exuberant-ctags/pascal.c +267 -0
  104. data/ext/vendor/exuberant-ctags/perl.c +382 -0
  105. data/ext/vendor/exuberant-ctags/php.c +237 -0
  106. data/ext/vendor/exuberant-ctags/python.c +771 -0
  107. data/ext/vendor/exuberant-ctags/qdos.c +106 -0
  108. data/ext/vendor/exuberant-ctags/read.c +569 -0
  109. data/ext/vendor/exuberant-ctags/read.h +116 -0
  110. data/ext/vendor/exuberant-ctags/readtags.c +959 -0
  111. data/ext/vendor/exuberant-ctags/readtags.h +252 -0
  112. data/ext/vendor/exuberant-ctags/rexx.c +39 -0
  113. data/ext/vendor/exuberant-ctags/routines.c +891 -0
  114. data/ext/vendor/exuberant-ctags/routines.h +134 -0
  115. data/ext/vendor/exuberant-ctags/ruby.c +408 -0
  116. data/ext/vendor/exuberant-ctags/scheme.c +111 -0
  117. data/ext/vendor/exuberant-ctags/sh.c +115 -0
  118. data/ext/vendor/exuberant-ctags/slang.c +41 -0
  119. data/ext/vendor/exuberant-ctags/sml.c +212 -0
  120. data/ext/vendor/exuberant-ctags/sort.c +230 -0
  121. data/ext/vendor/exuberant-ctags/sort.h +32 -0
  122. data/ext/vendor/exuberant-ctags/source.mak +122 -0
  123. data/ext/vendor/exuberant-ctags/sql.c +2112 -0
  124. data/ext/vendor/exuberant-ctags/strlist.c +281 -0
  125. data/ext/vendor/exuberant-ctags/strlist.h +54 -0
  126. data/ext/vendor/exuberant-ctags/tcl.c +116 -0
  127. data/ext/vendor/exuberant-ctags/tex.c +524 -0
  128. data/ext/vendor/exuberant-ctags/verilog.c +340 -0
  129. data/ext/vendor/exuberant-ctags/vhdl.c +835 -0
  130. data/ext/vendor/exuberant-ctags/vim.c +636 -0
  131. data/ext/vendor/exuberant-ctags/vstring.c +232 -0
  132. data/ext/vendor/exuberant-ctags/vstring.h +85 -0
  133. data/ext/vendor/exuberant-ctags/yacc.c +40 -0
  134. data/lib/ctags/exuberant.rb +45 -0
  135. data/lib/ctags/version.rb +3 -0
  136. data/lib/ctags.rb +6 -0
  137. data/test/test_ctags.rb +24 -0
  138. metadata +233 -0
@@ -0,0 +1,115 @@
1
+ /*
2
+ * $Id: sh.c 443 2006-05-30 04:37:13Z darren $
3
+ *
4
+ * Copyright (c) 2000-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
+ * This module contains functions for generating tags for scripts for the
10
+ * Bourne shell (and its derivatives, the Korn and Z shells).
11
+ */
12
+
13
+ /*
14
+ * INCLUDE FILES
15
+ */
16
+ #include "general.h" /* must always come first */
17
+
18
+ #include <string.h>
19
+
20
+ #include "parse.h"
21
+ #include "read.h"
22
+ #include "routines.h"
23
+ #include "vstring.h"
24
+
25
+ /*
26
+ * DATA DEFINITIONS
27
+ */
28
+ typedef enum {
29
+ K_FUNCTION
30
+ } shKind;
31
+
32
+ static kindOption ShKinds [] = {
33
+ { TRUE, 'f', "function", "functions"}
34
+ };
35
+
36
+ /*
37
+ * FUNCTION DEFINITIONS
38
+ */
39
+
40
+ /* Reject any tag "main" from a file named "configure". These appear in
41
+ * here-documents in GNU autoconf scripts and will add a haystack to the
42
+ * needle.
43
+ */
44
+ static boolean hackReject (const vString* const tagName)
45
+ {
46
+ const char *const scriptName = baseFilename (vStringValue (File.name));
47
+ boolean result = (boolean) (
48
+ strcmp (scriptName, "configure") == 0 &&
49
+ strcmp (vStringValue (tagName), "main") == 0);
50
+ return result;
51
+ }
52
+
53
+ static void findShTags (void)
54
+ {
55
+ vString *name = vStringNew ();
56
+ const unsigned char *line;
57
+
58
+ while ((line = fileReadLine ()) != NULL)
59
+ {
60
+ const unsigned char* cp = line;
61
+ boolean functionFound = FALSE;
62
+
63
+ if (line [0] == '#')
64
+ continue;
65
+
66
+ while (isspace (*cp))
67
+ cp++;
68
+ if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
69
+ isspace ((int) cp [8]))
70
+ {
71
+ functionFound = TRUE;
72
+ cp += 8;
73
+ if (! isspace ((int) *cp))
74
+ continue;
75
+ while (isspace ((int) *cp))
76
+ ++cp;
77
+ }
78
+ if (! (isalnum ((int) *cp) || *cp == '_'))
79
+ continue;
80
+ while (isalnum ((int) *cp) || *cp == '_')
81
+ {
82
+ vStringPut (name, (int) *cp);
83
+ ++cp;
84
+ }
85
+ vStringTerminate (name);
86
+ while (isspace ((int) *cp))
87
+ ++cp;
88
+ if (*cp++ == '(')
89
+ {
90
+ while (isspace ((int) *cp))
91
+ ++cp;
92
+ if (*cp == ')' && ! hackReject (name))
93
+ functionFound = TRUE;
94
+ }
95
+ if (functionFound)
96
+ makeSimpleTag (name, ShKinds, K_FUNCTION);
97
+ vStringClear (name);
98
+ }
99
+ vStringDelete (name);
100
+ }
101
+
102
+ extern parserDefinition* ShParser (void)
103
+ {
104
+ static const char *const extensions [] = {
105
+ "sh", "SH", "bsh", "bash", "ksh", "zsh", NULL
106
+ };
107
+ parserDefinition* def = parserNew ("Sh");
108
+ def->kinds = ShKinds;
109
+ def->kindCount = KIND_COUNT (ShKinds);
110
+ def->extensions = extensions;
111
+ def->parser = findShTags;
112
+ return def;
113
+ }
114
+
115
+ /* vi:set tabstop=4 shiftwidth=4: */
@@ -0,0 +1,41 @@
1
+ /*
2
+ * $Id: slang.c 443 2006-05-30 04:37:13Z darren $
3
+ *
4
+ * Copyright (c) 2000-2001, Francesc Rocher
5
+ *
6
+ * Author: Francesc Rocher <f.rocher@computer.org>.
7
+ *
8
+ * This source code is released for free distribution under the terms of the
9
+ * GNU General Public License.
10
+ *
11
+ * This module contains functions for generating tags for S-Lang files.
12
+ */
13
+
14
+ /*
15
+ * INCLUDE FILES
16
+ */
17
+ #include "general.h" /* must always come first */
18
+ #include "parse.h"
19
+
20
+ /*
21
+ * FUNCTION DEFINITIONS
22
+ */
23
+ static void installSlangRegex (const langType language)
24
+ {
25
+ addTagRegex (language,
26
+ "^.*define[ \t]+([A-Z_][A-Z0-9_]*)[^;]*$",
27
+ "\\1", "f,function,functions", "i");
28
+ addTagRegex (language,
29
+ "^[ \t]*implements[ \t]+\\([ \t]*\"([^\"]*)\"[ \t]*\\)[ \t]*;",
30
+ "\\1", "n,namespace,namespaces", NULL);
31
+ }
32
+
33
+ extern parserDefinition* SlangParser (void)
34
+ {
35
+ static const char *const extensions [] = { "sl", NULL };
36
+ parserDefinition* const def = parserNew ("SLang");
37
+ def->extensions = extensions;
38
+ def->initialize = installSlangRegex;
39
+ def->regex = TRUE;
40
+ return def;
41
+ }
@@ -0,0 +1,212 @@
1
+ /*
2
+ * $Id: sml.c 536 2007-06-02 06:09:00Z elliotth $
3
+ *
4
+ * Copyright (c) 2002, Venkatesh Prasad Ranganath and Darren Hiebert
5
+ *
6
+ * This source code is released for free distribution under the terms of the
7
+ * GNU General Public License.
8
+ *
9
+ * This module contains functions for generating tags for SML language files.
10
+ */
11
+
12
+ /*
13
+ * INCLUDE FILES
14
+ */
15
+ #include "general.h" /* must always come first */
16
+
17
+ #include <string.h>
18
+
19
+ #include "entry.h"
20
+ #include "parse.h"
21
+ #include "read.h"
22
+ #include "vstring.h"
23
+
24
+ /*
25
+ * DATA DECLARATIONS
26
+ */
27
+ typedef enum {
28
+ K_AND = -2,
29
+ K_NONE = -1,
30
+ K_EXCEPTION,
31
+ K_FUNCTION,
32
+ K_FUNCTOR,
33
+ K_SIGNATURE,
34
+ K_STRUCTURE,
35
+ K_TYPE,
36
+ K_VAL
37
+ } smlKind;
38
+
39
+ /*
40
+ * DATA DEFINITIONS
41
+ */
42
+ static kindOption SmlKinds[] = {
43
+ { TRUE, 'e', "exception", "exception declarations" },
44
+ { TRUE, 'f', "function", "function definitions" },
45
+ { TRUE, 'c', "functor", "functor definitions" },
46
+ { TRUE, 's', "signature", "signature declarations" },
47
+ { TRUE, 'r', "structure", "structure declarations" },
48
+ { TRUE, 't', "type", "type definitions" },
49
+ { TRUE, 'v', "value", "value bindings" }
50
+ };
51
+
52
+ static struct {
53
+ const char *keyword;
54
+ smlKind kind;
55
+ } SmlKeywordTypes [] = {
56
+ { "abstype", K_TYPE },
57
+ { "and", K_AND },
58
+ { "datatype", K_TYPE },
59
+ { "exception", K_EXCEPTION },
60
+ { "functor", K_FUNCTOR },
61
+ { "fun", K_FUNCTION },
62
+ { "signature", K_SIGNATURE },
63
+ { "structure", K_STRUCTURE },
64
+ { "type", K_TYPE },
65
+ { "val", K_VAL }
66
+ };
67
+
68
+ static unsigned int CommentLevel = 0;
69
+
70
+ /*
71
+ * FUNCTION DEFINITIONS
72
+ */
73
+
74
+ static void makeSmlTag (smlKind type, vString *name)
75
+ {
76
+ tagEntryInfo tag;
77
+ initTagEntry (&tag, vStringValue (name));
78
+ tag.kindName = SmlKinds [type].name;
79
+ tag.kind = SmlKinds [type].letter;
80
+ makeTagEntry (&tag);
81
+ }
82
+
83
+ static const unsigned char *skipSpace (const unsigned char *cp)
84
+ {
85
+ while (isspace ((int) *cp))
86
+ ++cp;
87
+ return cp;
88
+ }
89
+
90
+ static boolean isIdentifier (int c)
91
+ {
92
+ boolean result = FALSE;
93
+ /* Consider '_' as an delimiter to aid user in tracking it's usage. */
94
+ const char *const alternateIdentifiers = "!%&$#+-<>=/?@\\~'^|*_";
95
+ if (isalnum (c))
96
+ result = TRUE;
97
+ else if (c != '\0' && strchr (alternateIdentifiers, c) != NULL)
98
+ result = TRUE;
99
+ return result;
100
+ }
101
+
102
+ static const unsigned char *parseIdentifier (
103
+ const unsigned char *cp, vString *const identifier)
104
+ {
105
+ boolean stringLit = FALSE;
106
+ vStringClear (identifier);
107
+ while (*cp != '\0' && (!isIdentifier ((int) *cp) || stringLit))
108
+ {
109
+ int oneback = *cp;
110
+ cp++;
111
+ if (oneback == '(' && *cp == '*' && stringLit == FALSE)
112
+ {
113
+ CommentLevel++;
114
+ return ++cp;
115
+ }
116
+ if (*cp == '"' && oneback != '\\')
117
+ {
118
+ stringLit = TRUE;
119
+ continue;
120
+ }
121
+ if (stringLit && *cp == '"' && oneback != '\\')
122
+ stringLit = FALSE;
123
+ }
124
+ if (strcmp ((const char *) cp, "") == 0 || cp == NULL)
125
+ return cp;
126
+
127
+ while (isIdentifier ((int) *cp))
128
+ {
129
+ vStringPut (identifier, (int) *cp);
130
+ cp++;
131
+ }
132
+ vStringTerminate (identifier);
133
+ return cp;
134
+ }
135
+
136
+ static smlKind findNextIdentifier (const unsigned char **cp)
137
+ {
138
+ smlKind result = K_NONE;
139
+ vString *const identifier = vStringNew ();
140
+ unsigned int count = sizeof (SmlKeywordTypes) / sizeof (SmlKeywordTypes [0]);
141
+ unsigned int i;
142
+ *cp = parseIdentifier (*cp, identifier);
143
+ for (i = 0 ; i < count && result == K_NONE ; ++i)
144
+ {
145
+ const char *id = vStringValue (identifier);
146
+ if (strcmp (id, SmlKeywordTypes [i].keyword) == 0)
147
+ result = SmlKeywordTypes [i].kind;
148
+ }
149
+ vStringDelete (identifier);
150
+ return result;
151
+ }
152
+
153
+ static void findSmlTags (void)
154
+ {
155
+ vString *const identifier = vStringNew ();
156
+ const unsigned char *line;
157
+ smlKind lastTag = K_NONE;
158
+
159
+ while ((line = fileReadLine ()) != NULL)
160
+ {
161
+ const unsigned char *cp = skipSpace (line);
162
+ do
163
+ {
164
+ smlKind foundTag;
165
+ if (CommentLevel != 0)
166
+ {
167
+ cp = (const unsigned char *) strstr ((const char *) cp, "*)");
168
+ if (cp == NULL)
169
+ continue;
170
+ else
171
+ {
172
+ --CommentLevel;
173
+ cp += 2;
174
+ }
175
+ }
176
+ foundTag = findNextIdentifier (&cp);
177
+ if (foundTag != K_NONE)
178
+ {
179
+ cp = skipSpace (cp);
180
+ cp = parseIdentifier (cp, identifier);
181
+ if (foundTag == K_AND)
182
+ makeSmlTag (lastTag, identifier);
183
+ else
184
+ {
185
+ makeSmlTag (foundTag, identifier);
186
+ lastTag = foundTag;
187
+ }
188
+ }
189
+ if (strstr ((const char *) cp, "(*") != NULL)
190
+ {
191
+ cp += 2;
192
+ cp = (const unsigned char *) strstr ((const char *) cp, "*)");
193
+ if (cp == NULL)
194
+ ++CommentLevel;
195
+ }
196
+ } while (cp != NULL && strcmp ((const char *) cp, "") != 0);
197
+ }
198
+ vStringDelete (identifier);
199
+ }
200
+
201
+ extern parserDefinition *SmlParser (void)
202
+ {
203
+ static const char *const extensions[] = { "sml", "sig", NULL };
204
+ parserDefinition *def = parserNew ("SML");
205
+ def->kinds = SmlKinds;
206
+ def->kindCount = KIND_COUNT (SmlKinds);
207
+ def->extensions = extensions;
208
+ def->parser = findSmlTags;
209
+ return def;
210
+ }
211
+
212
+ /* vi:set tabstop=4 shiftwidth=4: */
@@ -0,0 +1,230 @@
1
+ /*
2
+ * $Id: sort.c 498 2007-02-17 22:43:15Z dhiebert $
3
+ *
4
+ * Copyright (c) 1996-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
+ * This module contains functions to sort the tag entries.
10
+ */
11
+
12
+ /*
13
+ * INCLUDE FILES
14
+ */
15
+ #include "general.h" /* must always come first */
16
+
17
+ #if defined (HAVE_STDLIB_H)
18
+ # include <stdlib.h> /* to declare malloc () */
19
+ #endif
20
+ #include <string.h>
21
+ #include <stdio.h>
22
+
23
+ #include "debug.h"
24
+ #include "entry.h"
25
+ #include "options.h"
26
+ #include "read.h"
27
+ #include "routines.h"
28
+ #include "sort.h"
29
+
30
+ /*
31
+ * FUNCTION DEFINITIONS
32
+ */
33
+
34
+ extern void catFile (const char *const name)
35
+ {
36
+ FILE *const fp = fopen (name, "r");
37
+
38
+ if (fp != NULL)
39
+ {
40
+ int c;
41
+ while ((c = getc (fp)) != EOF)
42
+ putchar (c);
43
+ fflush (stdout);
44
+ fclose (fp);
45
+ }
46
+ }
47
+
48
+ #ifdef EXTERNAL_SORT
49
+
50
+ #ifdef NON_CONST_PUTENV_PROTOTYPE
51
+ # define PE_CONST
52
+ #else
53
+ # define PE_CONST const
54
+ #endif
55
+
56
+ extern void externalSortTags (const boolean toStdout)
57
+ {
58
+ const char *const sortNormalCommand = "sort -u -o";
59
+ const char *const sortFoldedCommand = "sort -u -f -o";
60
+ const char *sortCommand =
61
+ Option.sorted == SO_FOLDSORTED ? sortFoldedCommand : sortNormalCommand;
62
+ PE_CONST char *const sortOrder1 = "LC_COLLATE=C";
63
+ PE_CONST char *const sortOrder2 = "LC_ALL=C";
64
+ const size_t length = 4 + strlen (sortOrder1) + strlen (sortOrder2) +
65
+ strlen (sortCommand) + (2 * strlen (tagFileName ()));
66
+ char *const cmd = (char *) malloc (length + 1);
67
+ int ret = -1;
68
+
69
+ if (cmd != NULL)
70
+ {
71
+ /* Ensure ASCII value sort order.
72
+ */
73
+ #ifdef HAVE_SETENV
74
+ setenv ("LC_COLLATE", "C", 1);
75
+ setenv ("LC_ALL", "C", 1);
76
+ sprintf (cmd, "%s %s %s", sortCommand, tagFileName (), tagFileName ());
77
+ #else
78
+ # ifdef HAVE_PUTENV
79
+ putenv (sortOrder1);
80
+ putenv (sortOrder2);
81
+ sprintf (cmd, "%s %s %s", sortCommand, tagFileName (), tagFileName ());
82
+ # else
83
+ sprintf (cmd, "%s %s %s %s %s", sortOrder1, sortOrder2, sortCommand,
84
+ tagFileName (), tagFileName ());
85
+ # endif
86
+ #endif
87
+ verbose ("system (\"%s\")\n", cmd);
88
+ ret = system (cmd);
89
+ free (cmd);
90
+
91
+ }
92
+ if (ret != 0)
93
+ error (FATAL | PERROR, "cannot sort tag file");
94
+ else if (toStdout)
95
+ catFile (tagFileName ());
96
+ }
97
+
98
+ #else
99
+
100
+ /*
101
+ * These functions provide a basic internal sort. No great memory
102
+ * optimization is performed (e.g. recursive subdivided sorts),
103
+ * so have lots of memory if you have large tag files.
104
+ */
105
+
106
+ static void failedSort (FILE *const fp, const char* msg)
107
+ {
108
+ const char* const cannotSort = "cannot sort tag file";
109
+ if (fp != NULL)
110
+ fclose (fp);
111
+ if (msg == NULL)
112
+ error (FATAL | PERROR, cannotSort);
113
+ else
114
+ error (FATAL, "%s: %s", msg, cannotSort);
115
+ }
116
+
117
+ static int compareTagsFolded(const void *const one, const void *const two)
118
+ {
119
+ const char *const line1 = *(const char* const*) one;
120
+ const char *const line2 = *(const char* const*) two;
121
+
122
+ return struppercmp (line1, line2);
123
+ }
124
+
125
+ static int compareTags (const void *const one, const void *const two)
126
+ {
127
+ const char *const line1 = *(const char* const*) one;
128
+ const char *const line2 = *(const char* const*) two;
129
+
130
+ return strcmp (line1, line2);
131
+ }
132
+
133
+ static void writeSortedTags (
134
+ char **const table, const size_t numTags, const boolean toStdout)
135
+ {
136
+ FILE *fp;
137
+ size_t i;
138
+
139
+ /* Write the sorted lines back into the tag file.
140
+ */
141
+ if (toStdout)
142
+ fp = stdout;
143
+ else
144
+ {
145
+ fp = fopen (tagFileName (), "w");
146
+ if (fp == NULL)
147
+ failedSort (fp, NULL);
148
+ }
149
+ for (i = 0 ; i < numTags ; ++i)
150
+ {
151
+ /* Here we filter out identical tag *lines* (including search
152
+ * pattern) if this is not an xref file.
153
+ */
154
+ if (i == 0 || Option.xref || strcmp (table [i], table [i-1]) != 0)
155
+ if (fputs (table [i], fp) == EOF)
156
+ failedSort (fp, NULL);
157
+ }
158
+ if (toStdout)
159
+ fflush (fp);
160
+ else
161
+ fclose (fp);
162
+ }
163
+
164
+ extern void internalSortTags (const boolean toStdout)
165
+ {
166
+ vString *vLine = vStringNew ();
167
+ FILE *fp = NULL;
168
+ const char *line;
169
+ size_t i;
170
+ int (*cmpFunc)(const void *, const void *);
171
+
172
+ /* Allocate a table of line pointers to be sorted.
173
+ */
174
+ size_t numTags = TagFile.numTags.added + TagFile.numTags.prev;
175
+ const size_t tableSize = numTags * sizeof (char *);
176
+ char **const table = (char **) malloc (tableSize); /* line pointers */
177
+ DebugStatement ( size_t mallocSize = tableSize; ) /* cumulative total */
178
+
179
+
180
+ cmpFunc = Option.sorted == SO_FOLDSORTED ? compareTagsFolded : compareTags;
181
+ if (table == NULL)
182
+ failedSort (fp, "out of memory");
183
+
184
+ /* Open the tag file and place its lines into allocated buffers.
185
+ */
186
+ fp = fopen (tagFileName (), "r");
187
+ if (fp == NULL)
188
+ failedSort (fp, NULL);
189
+ for (i = 0 ; i < numTags && ! feof (fp) ; )
190
+ {
191
+ line = readLine (vLine, fp);
192
+ if (line == NULL)
193
+ {
194
+ if (! feof (fp))
195
+ failedSort (fp, NULL);
196
+ break;
197
+ }
198
+ else if (*line == '\0' || strcmp (line, "\n") == 0)
199
+ ; /* ignore blank lines */
200
+ else
201
+ {
202
+ const size_t stringSize = strlen (line) + 1;
203
+
204
+ table [i] = (char *) malloc (stringSize);
205
+ if (table [i] == NULL)
206
+ failedSort (fp, "out of memory");
207
+ DebugStatement ( mallocSize += stringSize; )
208
+ strcpy (table [i], line);
209
+ ++i;
210
+ }
211
+ }
212
+ numTags = i;
213
+ fclose (fp);
214
+ vStringDelete (vLine);
215
+
216
+ /* Sort the lines.
217
+ */
218
+ qsort (table, numTags, sizeof (*table), cmpFunc);
219
+
220
+ writeSortedTags (table, numTags, toStdout);
221
+
222
+ PrintStatus (("sort memory: %ld bytes\n", (long) mallocSize));
223
+ for (i = 0 ; i < numTags ; ++i)
224
+ free (table [i]);
225
+ free (table);
226
+ }
227
+
228
+ #endif
229
+
230
+ /* vi:set tabstop=4 shiftwidth=4: */
@@ -0,0 +1,32 @@
1
+ /*
2
+ * $Id: sort.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 sort.c
10
+ */
11
+ #ifndef _SORT_H
12
+ #define _SORT_H
13
+
14
+ /*
15
+ * INCLUDE FILES
16
+ */
17
+ #include "general.h" /* must always come first */
18
+
19
+ /*
20
+ * FUNCTION PROTOTYPES
21
+ */
22
+ extern void catFile (const char *const name);
23
+
24
+ #ifdef EXTERNAL_SORT
25
+ extern void externalSortTags (const boolean toStdout);
26
+ #else
27
+ extern void internalSortTags (const boolean toStdout);
28
+ #endif
29
+
30
+ #endif /* _SORT_H */
31
+
32
+ /* vi:set tabstop=4 shiftwidth=4: */