Recognize #!/bin/dash as shebang for Shell files (closes #3470986)
[geany-mirror.git] / tagmanager / nsis.c
blob88b902bf5013965c02cb5300f5fcdb5818933a0b
1 /*
2 * Copyright (c) 2000-2002, Darren Hiebert
3 * Copyright (c) 2009-2011, Enrico Tröger
5 * This source code is released for free distribution under the terms of the
6 * GNU General Public License.
8 * This module contains functions for generating tags for NSIS scripts (based on sh.c).
9 */
12 * INCLUDE FILES
14 #include "general.h" /* must always come first */
16 #include <string.h>
18 #include "parse.h"
19 #include "read.h"
20 #include "main.h"
21 #include "vstring.h"
24 * DATA DEFINITIONS
26 typedef enum {
27 K_SECTION,
28 K_FUNCTION,
29 K_VARIABLE
30 } NsisKind;
32 static kindOption NsisKinds [] = {
33 { TRUE, 'n', "namespace", "sections"},
34 { TRUE, 'f', "function", "functions"},
35 { TRUE, 'v', "variable", "variables"}
39 * FUNCTION DEFINITIONS
42 static void findNsisTags (void)
44 vString *name = vStringNew ();
45 const unsigned char *line;
47 while ((line = fileReadLine ()) != NULL)
49 const unsigned char* cp = line;
51 while (isspace (*cp))
52 cp++;
54 if (*cp == '#' || *cp == ';')
55 continue;
57 /* functions */
58 if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0 &&
59 isspace ((int) cp [8]))
61 cp += 8;
62 /* skip all whitespace */
63 while (isspace ((int) *cp))
64 ++cp;
65 while (isalnum ((int) *cp) || *cp == '_' || *cp == '-' || *cp == '.' || *cp == '!')
67 vStringPut (name, (int) *cp);
68 ++cp;
70 vStringTerminate (name);
71 makeSimpleTag (name, NsisKinds, K_FUNCTION);
72 vStringClear (name);
74 /* variables */
75 else if (strncasecmp ((const char*) cp, "var", (size_t) 3) == 0 &&
76 isspace ((int) cp [3]))
78 cp += 3;
79 /* skip all whitespace */
80 while (isspace ((int) *cp))
81 ++cp;
82 /* skip any flags */
83 while (*cp == '/')
85 ++cp;
86 while (! isspace ((int) *cp))
87 ++cp;
88 while (isspace ((int) *cp))
89 ++cp;
91 while (isalnum ((int) *cp) || *cp == '_')
93 vStringPut (name, (int) *cp);
94 ++cp;
96 vStringTerminate (name);
97 makeSimpleTag (name, NsisKinds, K_VARIABLE);
98 vStringClear (name);
100 /* sections */
101 else if (strncasecmp ((const char*) cp, "section", (size_t) 7) == 0 &&
102 isspace ((int) cp [7]))
104 boolean in_quotes = FALSE;
105 cp += 7;
106 /* skip all whitespace */
107 while (isspace ((int) *cp))
108 ++cp;
109 while (isalnum ((int) *cp) || isspace ((int) *cp) ||
110 *cp == '_' || *cp == '-' || *cp == '.' || *cp == '!' || *cp == '"')
112 if (*cp == '"')
114 if (in_quotes)
115 break;
116 else
118 in_quotes = TRUE;
119 ++cp;
120 continue;
123 vStringPut (name, (int) *cp);
124 ++cp;
126 vStringTerminate (name);
127 makeSimpleTag (name, NsisKinds, K_SECTION);
128 vStringClear (name);
131 vStringDelete (name);
134 extern parserDefinition* NsisParser (void)
136 static const char *const extensions [] = {
137 "nsi", "nsh", NULL
139 parserDefinition* def = parserNew ("NSIS");
140 def->kinds = NsisKinds;
141 def->kindCount = KIND_COUNT (NsisKinds);
142 def->extensions = extensions;
143 def->parser = findNsisTags;
144 return def;
147 /* vi:set tabstop=8 shiftwidth=4: */