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).
14 #include "general.h" /* must always come first */
31 static kindDefinition 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
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);
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;
66 if (strncmp ((const char*) cp
, "function", (size_t) 8) == 0 &&
67 isspace ((int) cp
[8]))
71 if (! isspace ((int) *cp
))
73 while (isspace ((int) *cp
))
76 if (! (isalnum ((int) *cp
) || *cp
== '_'))
78 while (isalnum ((int) *cp
) || *cp
== '_')
80 vStringPut (name
, (int) *cp
);
83 while (isspace ((int) *cp
))
87 while (isspace ((int) *cp
))
89 if (*cp
== ')' && ! hackReject (name
))
93 makeSimpleTag (name
, 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
->kindTable
= ShKinds
;
106 def
->kindCount
= ARRAY_SIZE (ShKinds
);
107 def
->extensions
= extensions
;
108 def
->parser
= findShTags
;