r5098
[geany-mirror.git] / tagmanager / nsis.c
blobb98fda9154102f41451109fa06ed61c4e94cd53c
1 /*
2 * $Id$
4 * Copyright (c) 2000-2002, Darren Hiebert
5 * Copyright (c) 2009-2010, Enrico Tröger
7 * This source code is released for free distribution under the terms of the
8 * GNU General Public License.
10 * This module contains functions for generating tags for NSIS scripts (based on sh.c).
14 * INCLUDE FILES
16 #include "general.h" /* must always come first */
18 #include <string.h>
20 #include "parse.h"
21 #include "read.h"
22 #include "main.h"
23 #include "vstring.h"
26 * DATA DEFINITIONS
28 typedef enum {
29 K_SECTION,
30 K_FUNCTION,
31 K_VARIABLE
32 } NsisKind;
34 static kindOption NsisKinds [] = {
35 { TRUE, 'n', "namespace", "sections"},
36 { TRUE, 'f', "function", "functions"},
37 { TRUE, 'v', "variable", "variables"}
41 * FUNCTION DEFINITIONS
44 static void findNsisTags (void)
46 vString *name = vStringNew ();
47 const unsigned char *line;
49 while ((line = fileReadLine ()) != NULL)
51 const unsigned char* cp = line;
53 while (isspace (*cp))
54 cp++;
56 if (*cp == '#' || *cp == ';')
57 continue;
59 /* functions */
60 if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0 &&
61 isspace ((int) cp [8]))
63 cp += 8;
64 /* skip all whitespace */
65 while (isspace ((int) *cp))
66 ++cp;
67 while (isalnum ((int) *cp) || *cp == '_' || *cp == '-' || *cp == '.' || *cp == '!')
69 vStringPut (name, (int) *cp);
70 ++cp;
72 vStringTerminate (name);
73 makeSimpleTag (name, NsisKinds, K_FUNCTION);
74 vStringClear (name);
76 /* variables */
77 else if (strncasecmp ((const char*) cp, "var", (size_t) 3) == 0 &&
78 isspace ((int) cp [3]))
80 cp += 3;
81 /* skip all whitespace */
82 while (isspace ((int) *cp))
83 ++cp;
84 /* skip any flags */
85 while (*cp == '/')
87 ++cp;
88 while (! isspace ((int) *cp))
89 ++cp;
90 while (isspace ((int) *cp))
91 ++cp;
93 while (isalnum ((int) *cp) || *cp == '_')
95 vStringPut (name, (int) *cp);
96 ++cp;
98 vStringTerminate (name);
99 makeSimpleTag (name, NsisKinds, K_VARIABLE);
100 vStringClear (name);
102 /* sections */
103 else if (strncasecmp ((const char*) cp, "section", (size_t) 7) == 0 &&
104 isspace ((int) cp [7]))
106 boolean in_quotes = FALSE;
107 cp += 7;
108 /* skip all whitespace */
109 while (isspace ((int) *cp))
110 ++cp;
111 while (isalnum ((int) *cp) || isspace ((int) *cp) ||
112 *cp == '_' || *cp == '-' || *cp == '.' || *cp == '!' || *cp == '"')
114 if (*cp == '"')
116 if (in_quotes)
117 break;
118 else
120 in_quotes = TRUE;
121 ++cp;
122 continue;
125 vStringPut (name, (int) *cp);
126 ++cp;
128 vStringTerminate (name);
129 makeSimpleTag (name, NsisKinds, K_SECTION);
130 vStringClear (name);
133 vStringDelete (name);
136 extern parserDefinition* NsisParser (void)
138 static const char *const extensions [] = {
139 "nsi", "nsh", NULL
141 parserDefinition* def = parserNew ("NSIS");
142 def->kinds = NsisKinds;
143 def->kindCount = KIND_COUNT (NsisKinds);
144 def->extensions = extensions;
145 def->parser = findNsisTags;
146 return def;
149 /* vi:set tabstop=8 shiftwidth=4: */