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).
14 #include "general.h" /* must always come first */
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
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);
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
;
65 if (strncmp ((const char*) cp
, "function", (size_t) 8) == 0 &&
66 isspace ((int) cp
[8]))
70 if (! isspace ((int) *cp
))
72 while (isspace ((int) *cp
))
75 if (! (isalnum ((int) *cp
) || *cp
== '_'))
77 while (isalnum ((int) *cp
) || *cp
== '_')
79 vStringPut (name
, (int) *cp
);
82 vStringTerminate (name
);
83 while (isspace ((int) *cp
))
87 while (isspace ((int) *cp
))
89 if (*cp
== ')' && ! hackReject (name
))
93 makeSimpleTag (name
, ShKinds
, K_FUNCTION
);
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
;
112 /* vi:set tabstop=8 shiftwidth=4: */