Use non-symlinked VTE libraries on macOS (#1625)
[geany-mirror.git] / ctags / parsers / sh.c
blobfd371a510ba14e41518e56e3b10e085b15e29a56
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 version 2 or (at your option) any later version.
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 "routines.h"
21 #include "vstring.h"
22 #include "xtag.h"
25 * DATA DEFINITIONS
27 typedef enum {
28 K_FUNCTION
29 } shKind;
31 static kindOption ShKinds [] = {
32 { true, 'f', "function", "functions"}
36 * FUNCTION DEFINITIONS
39 /* Reject any tag "main" from a file named "configure". These appear in
40 * here-documents in GNU autoconf scripts and will add a haystack to the
41 * needle.
43 static bool hackReject (const vString* const tagName)
45 const char *const scriptName = baseFilename (getInputFileName ());
46 bool result = (bool) (strcmp (scriptName, "configure") == 0 &&
47 strcmp (vStringValue (tagName), "main") == 0);
48 return result;
51 static void findShTags (void)
53 vString *name = vStringNew ();
54 const unsigned char *line;
56 while ((line = readLineFromInputFile ()) != NULL)
58 const unsigned char* cp = line;
59 bool functionFound = false;
61 if (line [0] == '#')
62 continue;
64 while (isspace (*cp))
65 cp++;
66 if (strncmp ((const char*) cp, "function", (size_t) 8) == 0 &&
67 isspace ((int) cp [8]))
69 functionFound = true;
70 cp += 8;
71 if (! isspace ((int) *cp))
72 continue;
73 while (isspace ((int) *cp))
74 ++cp;
76 if (! (isalnum ((int) *cp) || *cp == '_'))
77 continue;
78 while (isalnum ((int) *cp) || *cp == '_')
80 vStringPut (name, (int) *cp);
81 ++cp;
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 = ARRAY_SIZE (ShKinds);
107 def->extensions = extensions;
108 def->parser = findShTags;
109 return def;