4 * Copyright (c) 2000-2005, Darren Hiebert
6 * This source code is released for free distribution under the terms of the
7 * GNU General Public License.
9 * This module contains functions for generating tags for makefiles.
15 #include "general.h" /* must always come first */
32 static kindOption MakeKinds
[] = {
33 { TRUE
, 'm', "macro", "macros"}
37 * FUNCTION DEFINITIONS
40 static int nextChar (void)
52 static void skipLine (void)
57 while (c
!= EOF
&& c
!= '\n');
62 static int skipToNonWhite (void)
67 while (c
!= '\n' && isspace (c
));
71 static boolean
isIdentifier (int c
)
73 return (boolean
)(c
!= '\0' && (isalnum (c
) || strchr (".-_", c
) != NULL
));
76 static void readIdentifier (const int first
, vString
*const id
)
80 while (isIdentifier (c
))
86 vStringTerminate (id
);
89 static void skipToMatch (const char *const pair
)
91 const int begin
= pair
[0], end
= pair
[1];
92 const unsigned long inputLineNumber
= getInputLineNumber ();
96 while (matchLevel
> 0)
107 verbose ("%s: failed to find match for '%c' at line %lu\n",
108 getInputFileName (), begin
, inputLineNumber
);
111 static void findMakeTags (void)
113 vString
*name
= vStringNew ();
114 boolean newline
= TRUE
;
115 boolean in_define
= FALSE
;
116 boolean in_rule
= FALSE
;
117 boolean variable_possible
= TRUE
;
120 while ((c
= nextChar ()) != EOF
)
128 skipLine (); /* skip rule */
134 variable_possible
= (boolean
)(!in_rule
);
139 else if (isspace (c
))
149 variable_possible
= TRUE
;
152 else if (variable_possible
&& isIdentifier (c
))
154 readIdentifier (c
, name
);
155 if (strcmp (vStringValue (name
), "endef") == 0)
159 else if (strcmp (vStringValue (name
), "define") == 0 &&
163 c
= skipToNonWhite ();
164 readIdentifier (c
, name
);
165 makeSimpleTag (name
, MakeKinds
, K_MACRO
);
169 c
= skipToNonWhite ();
170 if (strchr (":?+", c
) != NULL
)
172 boolean append
= (boolean
)(c
== '+');
186 makeSimpleTag (name
, MakeKinds
, K_MACRO
);
193 variable_possible
= FALSE
;
195 vStringDelete (name
);
198 extern parserDefinition
* MakefileParser (void)
200 static const char *const patterns
[] = { "[Mm]akefile", NULL
};
201 static const char *const extensions
[] = { "mak", "mk", NULL
};
202 parserDefinition
* const def
= parserNew ("Make");
203 def
->kinds
= MakeKinds
;
204 def
->kindCount
= KIND_COUNT (MakeKinds
);
205 def
->patterns
= patterns
;
206 def
->extensions
= extensions
;
207 def
->parser
= findMakeTags
;
211 /* vi:set tabstop=4 shiftwidth=4: */