2 * Copyright (c) 2009, Eric Forgeot
4 * Based on work by Jon Strait
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 Txt2tags files.
15 #include "general.h" /* must always come first */
29 K_SECTION
= 0, K_HEADER
32 static kindOption Txt2tagsKinds
[] = {
33 { TRUE
, 'm', "member", "sections" },
34 { TRUE
, 's', "struct", "header1"}
38 * FUNCTION DEFINITIONS
41 static void parse_title (vString
* const name
, const char control_char
)
43 char *text
= vStringValue(name
);
46 boolean in_or_after_title
= FALSE
;
48 while (p
!= NULL
&& *p
!= '\0')
50 if (*p
== control_char
)
52 if (in_or_after_title
)
58 in_or_after_title
= TRUE
;
62 vStringCopyS(name
, text
+ offset_start
);
63 vStringStripLeading(name
);
64 vStringStripTrailing(name
);
67 static void makeTxt2tagsTag (const vString
* const name
, boolean name_before
, Txt2tagsKind type
)
70 kindOption
*kind
= &Txt2tagsKinds
[type
];
71 initTagEntry (&e
, vStringValue(name
));
74 e
.lineNumber
--; /* we want the line before the underline chars */
75 e
.kindName
= kind
->name
;
76 e
.kind
= kind
->letter
;
81 static void findTxt2tagsTags (void)
83 vString
*name
= vStringNew();
84 const unsigned char *line
;
86 while ((line
= fileReadLine()) != NULL
)
88 /*int name_len = vStringLength(name);*/
90 /* underlines must be the same length or more */
91 /*if (name_len > 0 && (line[0] == '=' || line[0] == '-') && issame((const char*) line))
93 makeTxt2tagsTag(name, TRUE);
95 if (line
[0] == '=' || line
[0] == '+') {
96 /*vStringClear(name);*/
97 vStringCatS(name
, (const char *) line
);
98 vStringTerminate(name
);
99 parse_title(name
, line
[0]);
100 makeTxt2tagsTag(name
, FALSE
, K_SECTION
);
102 /* TODO what exactly should this match?
103 * K_HEADER ('struct') isn't matched in src/symbols.c */
104 else if (strcmp((char*)line
, "°") == 0) {
105 /*vStringClear(name);*/
106 vStringCatS(name
, (const char *) line
);
107 vStringTerminate(name
);
108 makeTxt2tagsTag(name
, FALSE
, K_HEADER
);
112 if (! isspace(*line
))
113 vStringCatS(name
, (const char*) line
);
114 vStringTerminate(name
);
117 vStringDelete (name
);
120 extern parserDefinition
* Txt2tagsParser (void)
122 static const char *const patterns
[] = { "*.t2t", NULL
};
123 static const char *const extensions
[] = { "t2t", NULL
};
124 parserDefinition
* const def
= parserNew ("Txt2tags");
126 def
->kinds
= Txt2tagsKinds
;
127 def
->kindCount
= KIND_COUNT (Txt2tagsKinds
);
128 def
->patterns
= patterns
;
129 def
->extensions
= extensions
;
130 def
->parser
= findTxt2tagsTags
;