Fix font rendering in the Scintilla when using Cairo
[geany-mirror.git] / tagmanager / docbook.c
blobb04b91e2bdc3cacdabd54e23b0ea53d123aa33a4
1 /*
2 * $Id$
4 * Copyright (c) 2000-2001, Jérôme Plût
5 * Copyright (c) 2006, Enrico Tröger
7 * This source code is released for free distribution under the terms of the
8 * GNU General Public License.
10 * This module contains functions for generating tags for source files
11 * for docbook files(based on TeX parser from Jérôme Plût).
15 * INCLUDE FILES
17 #include "general.h" /* must always come first */
19 #include <ctype.h>
20 #include <string.h>
22 #include "parse.h"
23 #include "read.h"
24 #include "vstring.h"
27 * DATA DEFINITIONS
29 typedef enum {
30 K_CHAPTER,
31 K_SECTION,
32 K_SECT1,
33 K_SECT2,
34 K_SECT3,
35 K_APPENDIX
36 } docbookKind;
38 static kindOption DocBookKinds [] = {
39 { TRUE, 'f', "function", "chapters"},
40 { TRUE, 'c', "class", "sections"},
41 { TRUE, 'm', "member", "sect1"},
42 { TRUE, 'd', "macro", "sect2"},
43 { TRUE, 'v', "variable", "sect3"},
44 { TRUE, 's', "struct", "appendix"}
48 * FUNCTION DEFINITIONS
51 static int getWord(const char *ref, const char **ptr)
53 const char *p = *ptr;
55 while ((*ref != '\0') && (*p != '\0') && (*ref == *p)) ref++, p++;
57 if (*ref) return FALSE;
59 *ptr = p;
60 return TRUE;
64 static void createTag(docbookKind kind, const char *buf)
66 vString *name;
68 if (*buf == '>') return;
70 buf = strstr(buf, "id=\"");
71 if (buf == NULL) return;
72 buf += 4;
73 if (*buf == '"') return;
74 name = vStringNew();
78 vStringPut(name, (int) *buf);
79 ++buf;
80 } while ((*buf != '\0') && (*buf != '"'));
81 vStringTerminate(name);
82 makeSimpleTag(name, DocBookKinds, kind);
86 static void findDocBookTags(void)
88 const char *line;
90 while ((line = (const char*)fileReadLine()) != NULL)
92 const char *cp = line;
94 for (; *cp != '\0'; cp++)
96 if (*cp == '<')
98 cp++;
100 /* <section id="..."> */
101 if (getWord("section", &cp))
103 createTag(K_SECTION, cp);
104 continue;
106 /* <sect1 id="..."> */
107 if (getWord("sect1", &cp))
109 createTag(K_SECT1, cp);
110 continue;
112 /* <sect2 id="..."> */
113 if (getWord("sect2", &cp))
115 createTag(K_SECT2, cp);
116 continue;
118 /* <sect3 id="..."> */
119 if (getWord("sect3", &cp) ||
120 getWord("sect4", &cp) ||
121 getWord("sect5", &cp))
123 createTag(K_SECT3, cp);
124 continue;
126 /* <chapter id="..."> */
127 if (getWord("chapter", &cp))
129 createTag(K_CHAPTER, cp);
130 continue;
132 /* <appendix id="..."> */
133 if (getWord("appendix", &cp))
135 createTag(K_APPENDIX, cp);
136 continue;
143 extern parserDefinition* DocBookParser (void)
145 static const char *const extensions [] = { "sgml", "docbook", NULL };
146 parserDefinition* def = parserNew ("Docbook");
147 def->extensions = extensions;
148 def->kinds = DocBookKinds;
149 def->kindCount = KIND_COUNT (DocBookKinds);
150 def->parser = findDocBookTags;
151 return def;