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).
17 #include "general.h" /* must always come first */
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
)
55 while ((*ref
!= '\0') && (*p
!= '\0') && (*ref
== *p
)) ref
++, p
++;
57 if (*ref
) return FALSE
;
64 static void createTag(docbookKind kind
, const char *buf
)
68 if (*buf
== '>') return;
70 buf
= strstr(buf
, "id=\"");
71 if (buf
== NULL
) return;
73 if (*buf
== '"') return;
78 vStringPut(name
, (int) *buf
);
80 } while ((*buf
!= '\0') && (*buf
!= '"'));
81 vStringTerminate(name
);
82 makeSimpleTag(name
, DocBookKinds
, kind
);
86 static void findDocBookTags(void)
90 while ((line
= (const char*)fileReadLine()) != NULL
)
92 const char *cp
= line
;
94 for (; *cp
!= '\0'; cp
++)
100 /* <section id="..."> */
101 if (getWord("section", &cp
))
103 createTag(K_SECTION
, cp
);
106 /* <sect1 id="..."> */
107 if (getWord("sect1", &cp
))
109 createTag(K_SECT1
, cp
);
112 /* <sect2 id="..."> */
113 if (getWord("sect2", &cp
))
115 createTag(K_SECT2
, cp
);
118 /* <sect3 id="..."> */
119 if (getWord("sect3", &cp
) ||
120 getWord("sect4", &cp
) ||
121 getWord("sect5", &cp
))
123 createTag(K_SECT3
, cp
);
126 /* <chapter id="..."> */
127 if (getWord("chapter", &cp
))
129 createTag(K_CHAPTER
, cp
);
132 /* <appendix id="..."> */
133 if (getWord("appendix", &cp
))
135 createTag(K_APPENDIX
, cp
);
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
;