Update HACKING for changed doc generation instructions
[geany-mirror.git] / tagmanager / ctags / sh.c
blob341aa09ed60b8e2c829ee2ef8e6c74606b2c1789
1 /*
2 * Copyright (c) 2000-2002, Darren Hiebert
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License.
7 * This module contains functions for generating tags for scripts for the
8 * Bourne shell (and its derivatives, the Korn and Z shells).
9 */
12 * INCLUDE FILES
14 #include "general.h" /* must always come first */
16 #include <string.h>
18 #include "parse.h"
19 #include "read.h"
20 #include "main.h"
21 #include "vstring.h"
24 * DATA DEFINITIONS
26 typedef enum {
27 K_FUNCTION
28 } shKind;
30 static kindOption ShKinds [] = {
31 { TRUE, 'f', "function", "functions"}
35 * FUNCTION DEFINITIONS
38 /* Reject any tag "main" from a file named "configure". These appear in
39 * here-documents in GNU autoconf scripts and will add a haystack to the
40 * needle.
42 static boolean hackReject (const vString* const tagName)
44 const char *const scriptName = baseFilename (vStringValue (File.name));
45 boolean result = (boolean) (strcmp (scriptName, "configure") == 0 &&
46 strcmp (vStringValue (tagName), "main") == 0);
47 return result;
50 static void findShTags (void)
52 vString *name = vStringNew ();
53 const unsigned char *line;
55 while ((line = fileReadLine ()) != NULL)
57 const unsigned char* cp = line;
58 boolean functionFound = FALSE;
60 if (line [0] == '#')
61 continue;
63 while (isspace (*cp))
64 cp++;
65 if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
66 isspace ((int) cp [8]))
68 functionFound = TRUE;
69 cp += 8;
70 if (! isspace ((int) *cp))
71 continue;
72 while (isspace ((int) *cp))
73 ++cp;
75 if (! (isalnum ((int) *cp) || *cp == '_'))
76 continue;
77 while (isalnum ((int) *cp) || *cp == '_')
79 vStringPut (name, (int) *cp);
80 ++cp;
82 vStringTerminate (name);
83 while (isspace ((int) *cp))
84 ++cp;
85 if (*cp++ == '(')
87 while (isspace ((int) *cp))
88 ++cp;
89 if (*cp == ')' && ! hackReject (name))
90 functionFound = TRUE;
92 if (functionFound)
93 makeSimpleTag (name, ShKinds, K_FUNCTION);
94 vStringClear (name);
96 vStringDelete (name);
99 extern parserDefinition* ShParser (void)
101 static const char *const extensions [] = {
102 "sh", "SH", "bsh", "bash", "ksh", "zsh", "ash", NULL
104 parserDefinition* def = parserNew ("Sh");
105 def->kinds = ShKinds;
106 def->kindCount = KIND_COUNT (ShKinds);
107 def->extensions = extensions;
108 def->parser = findShTags;
109 return def;
112 /* vi:set tabstop=8 shiftwidth=4: */