FreeBasic: Update keywords
[geany-mirror.git] / tagmanager / ctags / docbook.c
blob118b1adbeb977655896a095cc957ba7048820233
1 /*
2 * Copyright (c) 2000-2001, Jérôme Plût
3 * Copyright (c) 2006, 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 source files
9 * for docbook files(based on TeX parser from Jérôme Plût).
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
27 typedef enum {
28 K_CHAPTER,
29 K_SECTION,
30 K_SECT1,
31 K_SECT2,
32 K_SECT3,
33 K_APPENDIX
34 } docbookKind;
36 static kindOption DocBookKinds [] = {
37 { TRUE, 'f', "function", "chapters"},
38 { TRUE, 'c', "class", "sections"},
39 { TRUE, 'm', "member", "sect1"},
40 { TRUE, 'd', "macro", "sect2"},
41 { TRUE, 'v', "variable", "sect3"},
42 { TRUE, 's', "struct", "appendix"}
46 * FUNCTION DEFINITIONS
49 static int getWord(const char *ref, const char **ptr)
51 const char *p = *ptr;
53 while ((*ref != '\0') && (*p != '\0') && (*ref == *p)) ref++, p++;
55 if (*ref) return FALSE;
57 *ptr = p;
58 return TRUE;
62 static void createTag(docbookKind kind, const char *buf)
64 vString *name;
66 if (*buf == '>') return;
68 buf = strstr(buf, "id=\"");
69 if (buf == NULL) return;
70 buf += 4;
71 if (*buf == '"') return;
72 name = vStringNew();
76 vStringPut(name, (int) *buf);
77 ++buf;
78 } while ((*buf != '\0') && (*buf != '"'));
79 vStringTerminate(name);
80 makeSimpleTag(name, DocBookKinds, kind);
84 static void findDocBookTags(void)
86 const char *line;
88 while ((line = (const char*)fileReadLine()) != NULL)
90 const char *cp = line;
92 for (; *cp != '\0'; cp++)
94 if (*cp == '<')
96 cp++;
98 /* <section id="..."> */
99 if (getWord("section", &cp))
101 createTag(K_SECTION, cp);
102 continue;
104 /* <sect1 id="..."> */
105 if (getWord("sect1", &cp))
107 createTag(K_SECT1, cp);
108 continue;
110 /* <sect2 id="..."> */
111 if (getWord("sect2", &cp))
113 createTag(K_SECT2, cp);
114 continue;
116 /* <sect3 id="..."> */
117 if (getWord("sect3", &cp) ||
118 getWord("sect4", &cp) ||
119 getWord("sect5", &cp))
121 createTag(K_SECT3, cp);
122 continue;
124 /* <chapter id="..."> */
125 if (getWord("chapter", &cp))
127 createTag(K_CHAPTER, cp);
128 continue;
130 /* <appendix id="..."> */
131 if (getWord("appendix", &cp))
133 createTag(K_APPENDIX, cp);
134 continue;
141 extern parserDefinition* DocBookParser (void)
143 static const char *const extensions [] = { "sgml", "docbook", NULL };
144 parserDefinition* def = parserNew ("Docbook");
145 def->extensions = extensions;
146 def->kinds = DocBookKinds;
147 def->kindCount = KIND_COUNT (DocBookKinds);
148 def->parser = findDocBookTags;
149 return def;