xref: /Universal-ctags/parsers/awk.c (revision ba6da7fe4dea7d44306cc949fde6a58fcfb8e2ba)
1 /*
2  *   Copyright (c) 2000-2002, Darren Hiebert
3  *
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.
6  *
7  *   This module contains functions for generating tags for AWK functions.
8  */
9 
10 /*
11  *   INCLUDE FILES
12  */
13 #include "general.h"  /* must always come first */
14 
15 #include <string.h>
16 
17 #include "parse.h"
18 #include "read.h"
19 #include "routines.h"
20 #include "vstring.h"
21 
22 /*
23  *   DATA DEFINITIONS
24  */
25 typedef enum eAwkKinds {
26 	K_FUNCTION
27 } awkKind;
28 
29 static kindDefinition AwkKinds [] = {
30 	{ true, 'f', "function", "functions" }
31 };
32 
33 /*
34  *   FUNCTION DEFINITIONS
35  */
36 
findAwkTags(void)37 static void findAwkTags (void)
38 {
39 	vString *name = vStringNew ();
40 	const unsigned char *line;
41 
42 	while ((line = readLineFromInputFile ()) != NULL)
43 	{
44 		while (isspace ((int) *line))
45 			++line;
46 
47 		if (strncmp ((const char *) line, "function", (size_t) 8) == 0  &&
48 			isspace ((int) line [8]))
49 		{
50 			const unsigned char *cp = line + 8;
51 
52 			while (isspace ((int) *cp))
53 				++cp;
54 			while (isalnum ((int) *cp)  ||  *cp == '_')
55 			{
56 				vStringPut (name, (int) *cp);
57 				++cp;
58 			}
59 			while (isspace ((int) *cp))
60 				++cp;
61 			if (*cp == '(')
62 				makeSimpleTag (name, K_FUNCTION);
63 			vStringClear (name);
64 			if (*cp != '\0')
65 				++cp;
66 		}
67 	}
68 	vStringDelete (name);
69 }
70 
AwkParser(void)71 extern parserDefinition *AwkParser (void)
72 {
73 	static const char *const extensions [] = { "awk", "gawk", "mawk", NULL };
74 	static const char *const aliases [] = { "gawk", "mawk", NULL };
75 	parserDefinition *def = parserNew ("Awk");
76 	def->kindTable  = AwkKinds;
77 	def->kindCount  = ARRAY_SIZE (AwkKinds);
78 	def->extensions = extensions;
79 	def->aliases    = aliases;
80 	def->parser     = findAwkTags;
81 	return def;
82 }
83