Version bump.
[geany-mirror.git] / tagmanager / txt2tags.c
blob83991f15e47c82ca82f392b2be2c1fe04882f4ef
1 /*
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.
13 * INCLUDE FILES
15 #include "general.h" /* must always come first */
17 #include <ctype.h>
18 #include <string.h>
20 #include "parse.h"
21 #include "read.h"
22 #include "vstring.h"
25 * DATA DEFINITIONS
28 typedef enum {
29 K_SECTION = 0, K_HEADER
30 } Txt2tagsKind;
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);
44 char *p = text;
45 int offset_start = 0;
46 boolean in_or_after_title = FALSE;
48 while (p != NULL && *p != '\0')
50 if (*p == control_char)
52 if (in_or_after_title)
53 break;
54 else
55 offset_start++;
57 else
58 in_or_after_title = TRUE;
59 p++;
61 *p = '\0';
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)
69 tagEntryInfo e;
70 kindOption *kind = &Txt2tagsKinds[type];
71 initTagEntry (&e, vStringValue(name));
73 if (name_before)
74 e.lineNumber--; /* we want the line before the underline chars */
75 e.kindName = kind->name;
76 e.kind = kind->letter;
78 makeTagEntry(&e);
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);
94 }*/
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);
110 else {
111 vStringClear (name);
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;
131 return def;