3 * Copyright (c) 2000-2001, Darren Hiebert
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 config files.
14 #include "general.h" /* must always come first */
30 static kindOption ConfKinds
[] = {
31 { TRUE
, 'n', "namespace", "sections"},
32 { TRUE
, 'm', "macro", "keys"}
36 * FUNCTION DEFINITIONS
39 static boolean
isIdentifier (int c
)
41 /* allow whitespace within keys and sections */
42 return (boolean
)(isalnum (c
) || isspace (c
) || c
== '_');
45 static void findConfTags (void)
47 vString
*name
= vStringNew ();
48 vString
*scope
= vStringNew ();
49 const unsigned char *line
;
51 while ((line
= fileReadLine ()) != NULL
)
53 const unsigned char* cp
= line
;
54 boolean possible
= TRUE
;
56 if (isspace ((int) *cp
) || *cp
== '#' || (*cp
!= '\0' && *cp
== '/' && *(cp
+1) == '/'))
59 /* look for a section */
60 if (*cp
!= '\0' && *cp
== '[')
63 while (*cp
!= '\0' && *cp
!= ']')
65 vStringPut (name
, (int) *cp
);
68 vStringTerminate (name
);
69 makeSimpleTag (name
, ConfKinds
, K_SECTION
);
70 /* remember section name */
71 vStringCopy (scope
, name
);
72 vStringTerminate (scope
);
79 /* We look for any sequence of identifier characters following a white space */
80 if (possible
&& isIdentifier ((int) *cp
))
82 while (isIdentifier ((int) *cp
))
84 vStringPut (name
, (int) *cp
);
87 vStringTerminate (name
);
88 vStringStripTrailing (name
);
89 while (isspace ((int) *cp
))
93 if (vStringLength (scope
) > 0)
94 makeSimpleScopedTag (name
, ConfKinds
, K_KEY
,
95 "section", vStringValue(scope
), NULL
);
97 makeSimpleTag (name
, ConfKinds
, K_KEY
);
101 else if (isspace ((int) *cp
))
110 vStringDelete (name
);
111 vStringDelete (scope
);
114 extern parserDefinition
* ConfParser (void)
116 static const char *const patterns
[] = { "*.ini", "*.conf", NULL
};
117 static const char *const extensions
[] = { "conf", NULL
};
118 parserDefinition
* const def
= parserNew ("Conf");
119 def
->kinds
= ConfKinds
;
120 def
->kindCount
= KIND_COUNT (ConfKinds
);
121 def
->patterns
= patterns
;
122 def
->extensions
= extensions
;
123 def
->parser
= findConfTags
;
127 /* vi:set tabstop=8 shiftwidth=4: */