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).
15 #include "general.h" /* must always come first */
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
)
53 while ((*ref
!= '\0') && (*p
!= '\0') && (*ref
== *p
)) ref
++, p
++;
55 if (*ref
) return FALSE
;
62 static void createTag(docbookKind kind
, const char *buf
)
66 if (*buf
== '>') return;
68 buf
= strstr(buf
, "id=\"");
69 if (buf
== NULL
) return;
71 if (*buf
== '"') return;
76 vStringPut(name
, (int) *buf
);
78 } while ((*buf
!= '\0') && (*buf
!= '"'));
79 vStringTerminate(name
);
80 makeSimpleTag(name
, DocBookKinds
, kind
);
84 static void findDocBookTags(void)
88 while ((line
= (const char*)fileReadLine()) != NULL
)
90 const char *cp
= line
;
92 for (; *cp
!= '\0'; cp
++)
98 /* <section id="..."> */
99 if (getWord("section", &cp
))
101 createTag(K_SECTION
, cp
);
104 /* <sect1 id="..."> */
105 if (getWord("sect1", &cp
))
107 createTag(K_SECT1
, cp
);
110 /* <sect2 id="..."> */
111 if (getWord("sect2", &cp
))
113 createTag(K_SECT2
, cp
);
116 /* <sect3 id="..."> */
117 if (getWord("sect3", &cp
) ||
118 getWord("sect4", &cp
) ||
119 getWord("sect5", &cp
))
121 createTag(K_SECT3
, cp
);
124 /* <chapter id="..."> */
125 if (getWord("chapter", &cp
))
127 createTag(K_CHAPTER
, cp
);
130 /* <appendix id="..."> */
131 if (getWord("appendix", &cp
))
133 createTag(K_APPENDIX
, cp
);
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
;