4 * Copyright (c) 2000-2002, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions for generating tags for scripts for the
10 * Bourne shell (and its derivatives, the Korn and Z shells).
16 #include "general.h" /* must always come first */
32 static kindOption ShKinds
[] = {
33 { TRUE
, 'f', "function", "functions"}
37 * FUNCTION DEFINITIONS
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
44 static boolean
hackReject (const vString
* const tagName
)
46 const char *const scriptName
= baseFilename (vStringValue (File
.name
));
47 boolean result
= (boolean
) (
48 strcmp (scriptName
, "configure") == 0 &&
49 strcmp (vStringValue (tagName
), "main") == 0);
53 static void findShTags (void)
55 vString
*name
= vStringNew ();
56 const unsigned char *line
;
58 while ((line
= fileReadLine ()) != NULL
)
60 const unsigned char* cp
= line
;
61 boolean functionFound
= FALSE
;
68 if (strncmp ((const char*) cp
, "function", (size_t) 8) == 0 &&
69 isspace ((int) cp
[8]))
73 if (! isspace ((int) *cp
))
75 while (isspace ((int) *cp
))
78 if (! (isalnum ((int) *cp
) || *cp
== '_'))
80 while (isalnum ((int) *cp
) || *cp
== '_')
82 vStringPut (name
, (int) *cp
);
85 vStringTerminate (name
);
86 while (isspace ((int) *cp
))
90 while (isspace ((int) *cp
))
92 if (*cp
== ')' && ! hackReject (name
))
96 makeSimpleTag (name
, ShKinds
, K_FUNCTION
);
102 extern parserDefinition
* ShParser (void)
104 static const char *const extensions
[] = {
105 "sh", "SH", "bsh", "bash", "ksh", "zsh", NULL
107 parserDefinition
* def
= parserNew ("Sh");
108 def
->kinds
= ShKinds
;
109 def
->kindCount
= KIND_COUNT (ShKinds
);
110 def
->extensions
= extensions
;
111 def
->parser
= findShTags
;
115 /* vi:set tabstop=4 shiftwidth=4: */