| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | # |
| 3 | # tries to parse the output of gtk-doc declaration files and make |
| 4 | # an XML reusable description from them |
| 5 | # |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 6 | import sys |
| 7 | import string |
| 8 | |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 9 | ids = {} |
| 10 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 11 | macros = {} |
| 12 | variables = {} |
| 13 | structs = {} |
| 14 | typedefs = {} |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 15 | enums = {} |
| 16 | functions = {} |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 17 | user_functions = {} |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 18 | ret_types = {} |
| 19 | types = {} |
| 20 | |
| 21 | sections = [] |
| 22 | files = {} |
| 23 | identifiers_file = {} |
| 24 | identifiers_type = {} |
| 25 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 26 | ################################################################## |
| 27 | # |
| Daniel Veillard | f859256 | 2002-01-23 17:58:17 +0000 | [diff] [blame] | 28 | # Indexer to generate the word index |
| 29 | # |
| 30 | ################################################################## |
| 31 | index = {} |
| 32 | |
| 33 | |
| 34 | def indexString(id, str): |
| 35 | str = string.replace(str, "'", ' ') |
| 36 | str = string.replace(str, '"', ' ') |
| 37 | str = string.replace(str, "/", ' ') |
| 38 | str = string.replace(str, '*', ' ') |
| 39 | str = string.replace(str, "[", ' ') |
| 40 | str = string.replace(str, "]", ' ') |
| 41 | str = string.replace(str, "(", ' ') |
| 42 | str = string.replace(str, ")", ' ') |
| 43 | str = string.replace(str, "<", ' ') |
| 44 | str = string.replace(str, '>', ' ') |
| 45 | str = string.replace(str, "&", ' ') |
| 46 | str = string.replace(str, '#', ' ') |
| 47 | str = string.replace(str, ",", ' ') |
| 48 | str = string.replace(str, '.', ' ') |
| 49 | str = string.replace(str, ';', ' ') |
| 50 | tokens = string.split(str) |
| 51 | for token in tokens: |
| 52 | try: |
| 53 | c = token[0] |
| 54 | if string.find(string.letters, c) < 0: |
| 55 | pass |
| 56 | elif len(token) < 3: |
| 57 | pass |
| 58 | else: |
| 59 | lower = string.lower(token) |
| 60 | # TODO: generalize this a bit |
| 61 | if lower == 'and' or lower == 'the': |
| 62 | pass |
| 63 | elif index.has_key(token): |
| 64 | index[token].append(id) |
| 65 | else: |
| 66 | index[token] = [id] |
| 67 | except: |
| 68 | pass |
| 69 | |
| 70 | |
| 71 | |
| 72 | ################################################################## |
| 73 | # |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 74 | # Parsing: libxml-decl.txt |
| 75 | # |
| 76 | ################################################################## |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 77 | def mormalizeTypeSpaces(raw, function): |
| 78 | global types |
| 79 | |
| 80 | tokens = string.split(raw) |
| 81 | type = '' |
| 82 | for token in tokens: |
| 83 | if type != '': |
| 84 | type = type + ' ' + token |
| 85 | else: |
| 86 | type = token |
| 87 | if types.has_key(type): |
| 88 | types[type].append(function) |
| 89 | else: |
| 90 | types[type] = [function] |
| 91 | return type |
| 92 | |
| 93 | def removeComments(raw): |
| 94 | while string.find(raw, '/*') > 0: |
| 95 | e = string.find(raw, '/*') |
| 96 | tmp = raw[0:e] |
| 97 | raw = raw[e:] |
| 98 | e = string.find(raw, '*/') |
| 99 | if e > 0: |
| 100 | raw = tmp + raw[e + 2:] |
| 101 | else: |
| 102 | raw = tmp |
| 103 | return raw |
| 104 | |
| 105 | def extractArgs(raw, function): |
| 106 | raw = removeComments(raw) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 107 | raw = string.replace(raw, '\n', ' ') |
| 108 | raw = string.replace(raw, '\r', ' ') |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 109 | list = string.split(raw, ",") |
| 110 | ret = [] |
| 111 | for arg in list: |
| 112 | i = len(arg) |
| 113 | if i == 0: |
| 114 | continue |
| 115 | i = i - 1 |
| 116 | c = arg[i] |
| 117 | while string.find(string.letters, c) >= 0 or \ |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 118 | string.find(string.digits, c) >= 0 or c == '_': |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 119 | i = i - 1 |
| 120 | if i < 0: |
| 121 | break |
| 122 | c = arg[i] |
| 123 | name = arg[i+1:] |
| 124 | while string.find(string.whitespace, c) >= 0: |
| 125 | i = i - 1 |
| 126 | if i < 0: |
| 127 | break |
| 128 | c = arg[i] |
| 129 | type = mormalizeTypeSpaces(arg[0:i+1], function) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 130 | if name == 'void' and type == '': |
| 131 | pass |
| 132 | else: |
| 133 | ret.append([type, name, '']) |
| 134 | |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 135 | return ret |
| 136 | |
| 137 | def extractTypes(raw, function): |
| 138 | global ret_types |
| 139 | |
| 140 | tokens = string.split(raw) |
| 141 | type = '' |
| 142 | for token in tokens: |
| 143 | if type != '': |
| 144 | type = type + ' ' + token |
| 145 | else: |
| 146 | type = token |
| 147 | if ret_types.has_key(type): |
| 148 | ret_types[type].append(function) |
| 149 | else: |
| 150 | ret_types[type] = [function] |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 151 | |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 152 | return type |
| 153 | |
| 154 | def parseMacro(): |
| 155 | global input |
| 156 | global macros |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 157 | global variables |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 158 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 159 | var = 1 |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 160 | line = input.readline()[:-1] |
| 161 | while line != "</MACRO>": |
| 162 | if line[0:6] == "<NAME>" and line[-7:] == "</NAME>": |
| 163 | name = line[6:-7] |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 164 | elif string.find(line, "#define") >= 0: |
| 165 | var = 0 |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 166 | line = input.readline()[:-1] |
| 167 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 168 | if var == 1: |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 169 | variables[name] = ['', ''] # type, info |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 170 | identifiers_type[name] = "variable" |
| 171 | else: |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 172 | macros[name] = [[], ''] # args, info |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 173 | identifiers_type[name] = "macro" |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 174 | |
| 175 | def parseStruct(): |
| 176 | global input |
| 177 | global structs |
| 178 | |
| 179 | line = input.readline()[:-1] |
| 180 | while line != "</STRUCT>": |
| 181 | if line[0:6] == "<NAME>" and line[-7:] == "</NAME>": |
| 182 | name = line[6:-7] |
| 183 | line = input.readline()[:-1] |
| 184 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 185 | structs[name] = '' |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 186 | identifiers_type[name] = "struct" |
| 187 | |
| 188 | def parseTypedef(): |
| 189 | global input |
| 190 | global typedefs |
| 191 | |
| 192 | line = input.readline()[:-1] |
| 193 | while line != "</TYPEDEF>": |
| 194 | if line[0:6] == "<NAME>" and line[-7:] == "</NAME>": |
| 195 | name = line[6:-7] |
| 196 | line = input.readline()[:-1] |
| 197 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 198 | typedefs[name] = '' |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 199 | identifiers_type[name] = "typedef" |
| 200 | |
| 201 | def parseEnum(): |
| 202 | global input |
| 203 | global enums |
| 204 | |
| 205 | line = input.readline()[:-1] |
| 206 | consts = [] |
| 207 | while line != "</ENUM>": |
| 208 | if line[0:6] == "<NAME>" and line[-7:] == "</NAME>": |
| 209 | name = line[6:-7] |
| 210 | elif string.find(line, 'enum') >= 0: |
| 211 | pass |
| 212 | elif string.find(line, '{') >= 0: |
| 213 | pass |
| 214 | elif string.find(line, '}') >= 0: |
| 215 | pass |
| 216 | elif string.find(line, ';') >= 0: |
| 217 | pass |
| 218 | else: |
| 219 | comment = string.find(line, '/*') |
| 220 | if comment >= 0: |
| 221 | line = line[0:comment] |
| 222 | decls = string.split(line, ",") |
| 223 | for decl in decls: |
| 224 | val = string.split(decl, "=")[0] |
| 225 | tokens = string.split(val) |
| 226 | if len(tokens) >= 1: |
| 227 | token = tokens[0] |
| 228 | if string.find(string.letters, token[0]) >= 0: |
| 229 | consts.append(token) |
| 230 | identifiers_type[token] = "const" |
| 231 | line = input.readline()[:-1] |
| 232 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 233 | enums[name] = [consts, ''] |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 234 | identifiers_type[name] = "enum" |
| 235 | |
| 236 | def parseStaticFunction(): |
| 237 | global input |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 238 | global user_functions |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 239 | |
| 240 | line = input.readline()[:-1] |
| 241 | type = None |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 242 | signature = "" |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 243 | while line != "</USER_FUNCTION>": |
| 244 | if line[0:6] == "<NAME>" and line[-7:] == "</NAME>": |
| 245 | name = line[6:-7] |
| 246 | elif line[0:9] == "<RETURNS>" and line[-10:] == "</RETURNS>": |
| 247 | type = extractTypes(line[9:-10], name) |
| 248 | else: |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 249 | signature = signature + line |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 250 | line = input.readline()[:-1] |
| 251 | |
| 252 | args = extractArgs(signature, name) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 253 | user_functions[name] = [[type, ''] , args, ''] |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 254 | identifiers_type[name] = "functype" |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 255 | |
| 256 | def parseFunction(): |
| 257 | global input |
| 258 | global functions |
| 259 | |
| 260 | line = input.readline()[:-1] |
| 261 | type = None |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 262 | signature = "" |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 263 | while line != "</FUNCTION>": |
| 264 | if line[0:6] == "<NAME>" and line[-7:] == "</NAME>": |
| 265 | name = line[6:-7] |
| 266 | elif line[0:9] == "<RETURNS>" and line[-10:] == "</RETURNS>": |
| 267 | type = extractTypes(line[9:-10], name) |
| 268 | else: |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 269 | signature = signature + line |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 270 | line = input.readline()[:-1] |
| 271 | |
| 272 | args = extractArgs(signature, name) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 273 | functions[name] = [[type, ''] , args, ''] |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 274 | identifiers_type[name] = "function" |
| 275 | |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 276 | print "Parsing: libxml-decl.txt" |
| 277 | input = open('libxml-decl.txt') |
| 278 | while 1: |
| 279 | line = input.readline() |
| 280 | if not line: |
| 281 | break |
| 282 | line = line[:-1] |
| 283 | if line == "<MACRO>": |
| 284 | parseMacro() |
| 285 | elif line == "<ENUM>": |
| 286 | parseEnum() |
| 287 | elif line == "<FUNCTION>": |
| 288 | parseFunction() |
| 289 | elif line == "<STRUCT>": |
| 290 | parseStruct() |
| 291 | elif line == "<TYPEDEF>": |
| 292 | parseTypedef() |
| 293 | elif line == "<USER_FUNCTION>": |
| 294 | parseStaticFunction() |
| 295 | elif len(line) >= 1 and line[0] == "<": |
| 296 | print "unhandled %s" % (line) |
| 297 | |
| 298 | print "Parsed: %d macros. %d structs, %d typedefs, %d enums" % ( |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 299 | len(macros.keys()), len(structs.keys()), len(typedefs.keys()), |
| 300 | len(enums)) |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 301 | c = 0 |
| 302 | for enum in enums.keys(): |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 303 | consts = enums[enum][0] |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 304 | c = c + len(consts) |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 305 | print " %d variables, %d constants, %d functions and %d functypes" % ( |
| 306 | len(variables.keys()), c, len(functions.keys()), |
| 307 | len(user_functions.keys())) |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 308 | print "The functions manipulates %d different types" % (len(types.keys())) |
| 309 | print "The functions returns %d different types" % (len(ret_types.keys())) |
| 310 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 311 | ################################################################## |
| 312 | # |
| 313 | # Parsing: libxml-decl-list.txt |
| 314 | # |
| 315 | ################################################################## |
| 316 | def parseSection(): |
| 317 | global input |
| 318 | global sections |
| 319 | global files |
| 320 | global identifiers_file |
| 321 | |
| 322 | tokens = [] |
| 323 | line = input.readline()[:-1] |
| 324 | while line != "</SECTION>": |
| 325 | if line[0:6] == "<FILE>" and line[-7:] == "</FILE>": |
| 326 | name = line[6:-7] |
| 327 | elif len(line) > 0: |
| 328 | tokens.append(line) |
| 329 | line = input.readline()[:-1] |
| 330 | |
| 331 | sections.append(name) |
| 332 | files[name] = tokens |
| 333 | for token in tokens: |
| 334 | identifiers_file[token] = name |
| 335 | # |
| 336 | # Small transitivity for enum values |
| 337 | # |
| 338 | if enums.has_key(token): |
| 339 | for const in enums[token][0]: |
| 340 | identifiers_file[const] = name |
| 341 | |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 342 | print "Parsing: libxml-decl-list.txt" |
| 343 | input = open('libxml-decl-list.txt') |
| 344 | while 1: |
| 345 | line = input.readline() |
| 346 | if not line: |
| 347 | break |
| 348 | line = line[:-1] |
| 349 | if line == "<SECTION>": |
| 350 | parseSection() |
| 351 | elif len(line) >= 1 and line[0] == "<": |
| 352 | print "unhandled %s" % (line) |
| 353 | |
| 354 | print "Parsed: %d files %d identifiers" % (len(files), len(identifiers_file.keys())) |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 355 | ################################################################## |
| 356 | # |
| 357 | # Parsing: xml/*.xml |
| 358 | # To enrich the existing info with extracted comments |
| 359 | # |
| 360 | ################################################################## |
| 361 | |
| 362 | nbcomments = 0 |
| 363 | |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 364 | def insertParameterComment(id, name, value, is_param): |
| 365 | global nbcomments |
| 366 | |
| Daniel Veillard | f859256 | 2002-01-23 17:58:17 +0000 | [diff] [blame] | 367 | indexString(id, value) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 368 | if functions.has_key(id): |
| 369 | if is_param == 1: |
| 370 | args = functions[id][1] |
| 371 | found = 0 |
| 372 | for arg in args: |
| 373 | if arg[1] == name: |
| 374 | arg[2] = value |
| 375 | found = 1 |
| 376 | break |
| 377 | if found == 0 and name != '...': |
| 378 | print "Arg %s not found on function %s description" % (name, id) |
| 379 | return |
| 380 | else: |
| 381 | ret = functions[id][0] |
| 382 | ret[1] = value |
| 383 | elif user_functions.has_key(id): |
| 384 | if is_param == 1: |
| 385 | args = user_functions[id][1] |
| 386 | found = 0 |
| 387 | for arg in args: |
| 388 | if arg[1] == name: |
| 389 | arg[2] = value |
| 390 | found = 1 |
| 391 | break |
| 392 | if found == 0 and name != '...': |
| 393 | print "Arg %s not found on functype %s description" % (name, id) |
| 394 | print args |
| 395 | return |
| 396 | else: |
| 397 | ret = user_functions[id][0] |
| 398 | ret[1] = value |
| 399 | elif macros.has_key(id): |
| 400 | if is_param == 1: |
| 401 | args = macros[id][0] |
| 402 | found = 0 |
| 403 | for arg in args: |
| 404 | if arg[0] == name: |
| 405 | arg[1] = value |
| 406 | found = 1 |
| 407 | break |
| 408 | if found == 0: |
| 409 | args.append([name, value]) |
| 410 | else: |
| 411 | print "Return info for macro %s: %s" % (id, value) |
| 412 | # ret = macros[id][0] |
| 413 | # ret[1] = value |
| 414 | else: |
| 415 | print "lost specific comment %s: %s: %s" % (id, name, value) |
| 416 | return |
| 417 | nbcomments = nbcomments + 1 |
| 418 | |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 419 | def insertComment(name, title, value, id): |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 420 | global nbcomments |
| 421 | |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 422 | ids[name] = id |
| Daniel Veillard | f859256 | 2002-01-23 17:58:17 +0000 | [diff] [blame] | 423 | indexString(name, value) |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 424 | if functions.has_key(name): |
| 425 | functions[name][2] = value |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 426 | return "function" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 427 | elif typedefs.has_key(name): |
| 428 | typedefs[name] = value |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 429 | return "typedef" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 430 | elif macros.has_key(name): |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 431 | macros[name][1] = value |
| 432 | return "macro" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 433 | elif variables.has_key(name): |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 434 | variables[name][1] = value |
| 435 | return "variable" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 436 | elif structs.has_key(name): |
| 437 | structs[name] = value |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 438 | return "struct" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 439 | elif enums.has_key(name): |
| 440 | enums[name][1] = value |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 441 | return "enum" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 442 | elif user_functions.has_key(name): |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 443 | user_functions[name][2] = value |
| 444 | return "user_function" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 445 | else: |
| 446 | print "lost comment %s: %s" % (name, value) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 447 | return "unknown" |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 448 | nbcomments = nbcomments + 1 |
| 449 | |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 450 | |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 451 | import os |
| 452 | import xmllib |
| 453 | try: |
| 454 | import sgmlop |
| 455 | except ImportError: |
| 456 | sgmlop = None # accelerator not available |
| 457 | |
| 458 | debug = 0 |
| 459 | |
| 460 | if sgmlop: |
| 461 | class FastParser: |
| 462 | """sgmlop based XML parser. this is typically 15x faster |
| 463 | than SlowParser...""" |
| 464 | |
| 465 | def __init__(self, target): |
| 466 | |
| 467 | # setup callbacks |
| 468 | self.finish_starttag = target.start |
| 469 | self.finish_endtag = target.end |
| 470 | self.handle_data = target.data |
| 471 | |
| 472 | # activate parser |
| 473 | self.parser = sgmlop.XMLParser() |
| 474 | self.parser.register(self) |
| 475 | self.feed = self.parser.feed |
| 476 | self.entity = { |
| 477 | "amp": "&", "gt": ">", "lt": "<", |
| 478 | "apos": "'", "quot": '"' |
| 479 | } |
| 480 | |
| 481 | def close(self): |
| 482 | try: |
| 483 | self.parser.close() |
| 484 | finally: |
| 485 | self.parser = self.feed = None # nuke circular reference |
| 486 | |
| 487 | def handle_entityref(self, entity): |
| 488 | # <string> entity |
| 489 | try: |
| 490 | self.handle_data(self.entity[entity]) |
| 491 | except KeyError: |
| 492 | self.handle_data("&%s;" % entity) |
| 493 | |
| 494 | else: |
| 495 | FastParser = None |
| 496 | |
| 497 | |
| 498 | class SlowParser(xmllib.XMLParser): |
| 499 | """slow but safe standard parser, based on the XML parser in |
| 500 | Python's standard library.""" |
| 501 | |
| 502 | def __init__(self, target): |
| 503 | self.unknown_starttag = target.start |
| 504 | self.handle_data = target.data |
| 505 | self.unknown_endtag = target.end |
| 506 | xmllib.XMLParser.__init__(self) |
| 507 | |
| 508 | def getparser(target = None): |
| 509 | # get the fastest available parser, and attach it to an |
| 510 | # unmarshalling object. return both objects. |
| 511 | if target == None: |
| 512 | target = docParser() |
| 513 | if FastParser: |
| 514 | return FastParser(target), target |
| 515 | return SlowParser(target), target |
| 516 | |
| 517 | class docParser: |
| 518 | def __init__(self): |
| 519 | self._methodname = None |
| 520 | self._data = [] |
| 521 | self.id = None |
| 522 | self.title = None |
| 523 | self.descr = None |
| 524 | self.string = None |
| 525 | |
| 526 | def close(self): |
| 527 | if debug: |
| 528 | print "close" |
| 529 | |
| 530 | def getmethodname(self): |
| 531 | return self._methodname |
| 532 | |
| 533 | def data(self, text): |
| 534 | if debug: |
| 535 | print "data %s" % text |
| 536 | self._data.append(text) |
| 537 | |
| 538 | def start(self, tag, attrs): |
| 539 | if debug: |
| 540 | print "start %s, %s" % (tag, attrs) |
| 541 | if tag == 'refsect2': |
| 542 | self.id = None |
| 543 | self.title = None |
| 544 | self.descr = None |
| 545 | self.string = None |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 546 | self.type = None |
| 547 | self.in_parameter = 0 |
| 548 | self.is_parameter = 0 |
| 549 | self.parameter = None |
| 550 | self.parameter_info = None |
| 551 | self.entry = 0 |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 552 | elif tag == 'para': |
| 553 | self._data = [] |
| 554 | elif tag == 'title': |
| 555 | self._data = [] |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 556 | elif tag == 'tgroup': |
| 557 | self.in_parameter = 1 |
| 558 | elif tag == 'row': |
| 559 | self._data = [] |
| 560 | self.entry = 0 |
| 561 | elif tag == 'entry': |
| 562 | self.entry = self.entry + 1 |
| 563 | elif tag == 'parameter' and self.in_parameter == 1: |
| 564 | self._data = [] |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 565 | elif tag == 'anchor' and self.id == None: |
| 566 | if attrs.has_key('id'): |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 567 | self.orig_id = attrs['id'] |
| 568 | self.id = string.replace(self.orig_id, '-CAPS', '') |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 569 | self.id = string.replace(self.id, '-', '_') |
| 570 | |
| 571 | def end(self, tag): |
| 572 | if debug: |
| 573 | print "end %s" % tag |
| 574 | if tag == 'refsect2': |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 575 | self.type = insertComment(self.id, self.title, self.string, |
| 576 | self.orig_id) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 577 | self.string = None |
| 578 | elif tag == 'row': |
| 579 | if self.parameter_info != None and self.parameter_info != '': |
| 580 | insertParameterComment(self.id, self.parameter, |
| 581 | self.parameter_info, self.is_parameter) |
| 582 | self.parameter_info = None |
| 583 | self.parameter = 0 |
| 584 | self.is_parameter = 0 |
| 585 | elif tag == 'parameter' and self.in_parameter == 1 and self.entry == 1: |
| 586 | str = '' |
| 587 | for c in self._data: |
| 588 | str = str + c |
| 589 | str = string.replace(str, '\n', ' ') |
| 590 | str = string.replace(str, '\r', ' ') |
| 591 | str = string.replace(str, ' ', ' ') |
| 592 | str = string.replace(str, ' ', ' ') |
| 593 | str = string.replace(str, ' ', ' ') |
| 594 | while len(str) >= 1 and str[0] == ' ': |
| 595 | str=str[1:] |
| 596 | self.parameter = str |
| 597 | self.is_parameter = 1 |
| 598 | self._data = [] |
| 599 | elif tag == 'para' or tag == 'entry': |
| 600 | str = '' |
| 601 | for c in self._data: |
| 602 | str = str + c |
| 603 | str = string.replace(str, '\n', ' ') |
| 604 | str = string.replace(str, '\r', ' ') |
| 605 | str = string.replace(str, ' ', ' ') |
| 606 | str = string.replace(str, ' ', ' ') |
| 607 | str = string.replace(str, ' ', ' ') |
| 608 | while len(str) >= 1 and str[0] == ' ': |
| 609 | str=str[1:] |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 610 | if self.string == None: |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 611 | self.string = str |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 612 | elif self.in_parameter == 1: |
| 613 | self.parameter_info = str |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 614 | self._data = [] |
| 615 | elif tag == 'title': |
| 616 | str = '' |
| 617 | for c in self._data: |
| 618 | str = str + c |
| 619 | str = string.replace(str, '\n', ' ') |
| 620 | str = string.replace(str, '\r', ' ') |
| 621 | str = string.replace(str, ' ', ' ') |
| 622 | str = string.replace(str, ' ', ' ') |
| 623 | str = string.replace(str, ' ', ' ') |
| 624 | while len(str) >= 1 and str[0] == ' ': |
| 625 | str=str[1:] |
| 626 | self.title = str |
| 627 | |
| 628 | xmlfiles = 0 |
| 629 | filenames = os.listdir("xml") |
| 630 | for filename in filenames: |
| 631 | try: |
| 632 | f = open("xml/" + filename, 'r') |
| 633 | except IOError, msg: |
| 634 | print file, ":", msg |
| 635 | continue |
| 636 | data = f.read() |
| 637 | (parser, target) = getparser() |
| 638 | parser.feed(data) |
| 639 | parser.close() |
| 640 | xmlfiles = xmlfiles + 1 |
| 641 | |
| 642 | print "Parsed: %d XML files collexting %d comments" % (xmlfiles, nbcomments) |
| 643 | |
| 644 | ################################################################## |
| 645 | # |
| 646 | # Saving: libxml2-api.xml |
| 647 | # |
| 648 | ################################################################## |
| 649 | |
| 650 | def escape(raw): |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 651 | raw = string.replace(raw, '&', '&') |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 652 | raw = string.replace(raw, '<', '<') |
| 653 | raw = string.replace(raw, '>', '>') |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 654 | raw = string.replace(raw, "'", ''') |
| 655 | raw = string.replace(raw, '"', '"') |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 656 | return raw |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 657 | |
| 658 | print "Saving XML description libxml2-api.xml" |
| 659 | output = open("libxml2-api.xml", "w") |
| Daniel Veillard | f859256 | 2002-01-23 17:58:17 +0000 | [diff] [blame] | 660 | output.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n') |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 661 | output.write("<api name='libxml2'>\n") |
| 662 | output.write(" <files>\n") |
| 663 | for file in files.keys(): |
| 664 | output.write(" <file name='%s'>\n" % file) |
| 665 | for symbol in files[file]: |
| 666 | output.write(" <exports symbol='%s'/>\n" % (symbol)) |
| 667 | output.write(" </file>\n") |
| 668 | output.write(" </files>\n") |
| 669 | |
| 670 | output.write(" <symbols>\n") |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 671 | symbols=macros.keys() |
| 672 | for i in structs.keys(): symbols.append(i) |
| 673 | for i in variables.keys(): variables.append(i) |
| 674 | for i in typedefs.keys(): symbols.append(i) |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 675 | for i in enums.keys(): |
| 676 | symbols.append(i) |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 677 | for j in enums[i][0]: |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 678 | symbols.append(j) |
| 679 | for i in functions.keys(): symbols.append(i) |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 680 | for i in user_functions.keys(): symbols.append(i) |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 681 | symbols.sort() |
| 682 | prev = None |
| 683 | for i in symbols: |
| 684 | if i == prev: |
| 685 | # print "Symbol %s redefined" % (i) |
| 686 | continue |
| 687 | else: |
| 688 | prev = i |
| 689 | if identifiers_type.has_key(i): |
| 690 | type = identifiers_type[i] |
| 691 | |
| 692 | if identifiers_file.has_key(i): |
| 693 | file = identifiers_file[i] |
| 694 | else: |
| 695 | file = None |
| 696 | |
| 697 | output.write(" <%s name='%s'" % (type, i)) |
| 698 | if file != None: |
| 699 | output.write(" file='%s'" % (file)) |
| 700 | if type == "function": |
| 701 | output.write(">\n"); |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 702 | (ret, args, doc) = functions[i] |
| 703 | if doc != None and doc != '': |
| 704 | output.write(" <info>%s</info>\n" % (escape(doc))) |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 705 | if ret[1] != None and ret[1] != '': |
| 706 | output.write(" <return type='%s' info='%s'/>\n" % ( |
| 707 | ret[0], escape(ret[1]))) |
| 708 | else: |
| 709 | if ret[0] != 'void' and\ |
| 710 | ret[0][0:4] != 'void': # This one is actually a bug in GTK Doc |
| 711 | print "Description for return on %s is missing" % (i) |
| 712 | output.write(" <return type='%s'/>\n" % (ret[0])) |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 713 | for arg in args: |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 714 | if arg[2] != None and arg[2] != '': |
| 715 | output.write(" <arg name='%s' type='%s' info='%s'/>\n" % |
| 716 | (arg[1], arg[0], escape(arg[2]))) |
| 717 | else: |
| 718 | if arg[0] != '...': |
| 719 | print "Description for %s on %s is missing" % (arg[1], i) |
| 720 | output.write(" <arg name='%s' type='%s'/>\n" % ( |
| 721 | arg[1], arg[0])) |
| 722 | output.write(" </%s>\n" % (type)); |
| 723 | elif type == 'functype': |
| 724 | output.write(">\n"); |
| 725 | (ret, args, doc) = user_functions[i] |
| 726 | if doc != None and doc != '': |
| 727 | output.write(" <info>%s</info>\n" % (escape(doc))) |
| 728 | if ret[1] != None and ret[1] != '': |
| 729 | output.write(" <return type='%s' info='%s'/>\n" % ( |
| 730 | ret[0], escape(ret[1]))) |
| 731 | else: |
| 732 | if ret[0] != 'void' and\ |
| 733 | ret[0][0:4] != 'void': # This one is actually a bug in GTK Doc |
| 734 | print "Description for return on %s is missing" % (i) |
| 735 | output.write(" <return type='%s'/>\n" % (ret[0])) |
| 736 | for arg in args: |
| 737 | if arg[2] != None and arg[2] != '': |
| 738 | output.write(" <arg name='%s' type='%s' info='%s'/>\n" % |
| 739 | (arg[1], arg[0], escape(arg[2]))) |
| 740 | else: |
| 741 | if arg[0] != '...': |
| 742 | print "Description for %s on %s is missing" % (arg[1], i) |
| 743 | output.write(" <arg name='%s' type='%s'/>\n" % ( |
| 744 | arg[1], arg[0])) |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 745 | output.write(" </%s>\n" % (type)); |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 746 | elif type == 'macro': |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 747 | output.write(">\n"); |
| 748 | if macros[i][1] != None and macros[i][1] != '': |
| 749 | output.write(" <info>%s</info>\n" % (escape(macros[i][1]))) |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 750 | else: |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 751 | print "Description for %s is missing" % (i) |
| 752 | args = macros[i][0] |
| 753 | for arg in args: |
| 754 | if arg[1] != None and arg[1] != '': |
| 755 | output.write(" <arg name='%s' info='%s'/>\n" % |
| 756 | (arg[0], escape(arg[1]))) |
| 757 | else: |
| 758 | print "Description for %s on %s is missing" % (arg[1], i) |
| 759 | output.write(" <arg name='%s'/>\n" % (arg[0])) |
| 760 | output.write(" </%s>\n" % (type)); |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 761 | elif type == 'struct': |
| 762 | if structs[i] != None and structs[i] != '': |
| 763 | output.write(" info='%s'/>\n" % (escape(structs[i]))) |
| 764 | else: |
| 765 | output.write("/>\n"); |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 766 | elif type == 'variable': |
| Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 767 | if variables[i][1] != None and variables[i][1] != '': |
| Daniel Veillard | 2d1464f | 2002-01-21 23:16:56 +0000 | [diff] [blame] | 768 | output.write(" info='%s'/>\n" % (escape(variables[i]))) |
| 769 | else: |
| 770 | output.write("/>\n"); |
| 771 | elif type == 'typedef': |
| 772 | if typedefs[i] != None and typedefs[i] != '': |
| 773 | output.write(" info='%s'/>\n" % (escape(typedefs[i]))) |
| 774 | else: |
| 775 | output.write("/>\n"); |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 776 | else: |
| 777 | output.write("/>\n"); |
| 778 | else: |
| 779 | print "Symbol %s not found in identifiers list" % (i) |
| 780 | output.write(" </symbols>\n") |
| 781 | output.write("</api>\n") |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 782 | output.close() |
| Daniel Veillard | 6100647 | 2002-01-21 17:31:47 +0000 | [diff] [blame] | 783 | print "generated XML for %d symbols" % (len(symbols)) |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 784 | |
| 785 | ################################################################## |
| 786 | # |
| 787 | # Saving: libxml2-api.xml |
| 788 | # |
| 789 | ################################################################## |
| 790 | |
| 791 | hash = {} |
| 792 | for file in files.keys(): |
| 793 | for symbol in files[file]: |
| 794 | hash[symbol] = file |
| 795 | |
| 796 | def link(id): |
| 797 | if ids.has_key(id): |
| 798 | target = string.upper(ids[id]) |
| 799 | else: |
| 800 | target = string.upper(id) |
| 801 | file = 'html/libxml-' + string.lower(hash[id]) + '.html'; |
| 802 | return file + '#' + target |
| 803 | |
| 804 | print "Saving XML crossreferences libxml2-refs.xml" |
| 805 | output = open("libxml2-refs.xml", "w") |
| Daniel Veillard | f859256 | 2002-01-23 17:58:17 +0000 | [diff] [blame] | 806 | output.write('<?xml version="1.0" encoding="ISO-8859-1"?>\n') |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 807 | output.write("<apirefs name='libxml2'>\n") |
| 808 | output.write(" <references>\n") |
| 809 | typ = ids.keys() |
| 810 | typ.sort() |
| 811 | for id in typ: |
| 812 | output.write(" <reference name='%s' href='%s'/>\n" % (id, link(id))) |
| 813 | output.write(" </references>\n") |
| 814 | output.write(" <alpha>\n") |
| 815 | letter = None |
| 816 | ids = ids.keys() |
| 817 | ids.sort() |
| 818 | for id in ids: |
| 819 | if id[0] != letter: |
| 820 | if letter != None: |
| 821 | output.write(" </letter>\n") |
| 822 | letter = id[0] |
| 823 | output.write(" <letter name='%s'>\n" % (letter)) |
| 824 | output.write(" <ref name='%s'/>\n" % (id)) |
| 825 | if letter != None: |
| 826 | output.write(" </letter>\n") |
| 827 | output.write(" </alpha>\n") |
| 828 | output.write(" <constructors>\n") |
| 829 | typ = ret_types.keys() |
| 830 | typ.sort() |
| 831 | for type in typ: |
| 832 | if type == '' or type == 'void' or type == "int" or type == "char *" or \ |
| 833 | type == "const char *" : |
| 834 | continue |
| 835 | output.write(" <type name='%s'>\n" % (type)) |
| 836 | ids = ret_types[type] |
| 837 | for id in ids: |
| 838 | output.write(" <ref name='%s'/>\n" % (id)) |
| 839 | output.write(" </type>\n") |
| 840 | output.write(" </constructors>\n") |
| 841 | output.write(" <functions>\n") |
| 842 | typ = types.keys() |
| 843 | typ.sort() |
| 844 | for type in typ: |
| 845 | if type == '' or type == 'void' or type == "int" or type == "char *" or \ |
| 846 | type == "const char *" : |
| 847 | continue |
| 848 | output.write(" <type name='%s'>\n" % (type)) |
| 849 | ids = types[type] |
| 850 | for id in ids: |
| 851 | output.write(" <ref name='%s'/>\n" % (id)) |
| 852 | output.write(" </type>\n") |
| 853 | output.write(" </functions>\n") |
| 854 | |
| 855 | output.write(" <files>\n") |
| 856 | typ = files.keys() |
| 857 | typ.sort() |
| 858 | for file in typ: |
| 859 | output.write(" <file name='%s'>\n" % (file)) |
| 860 | for id in files[file]: |
| 861 | output.write(" <ref name='%s'/>\n" % (id)) |
| 862 | output.write(" </file>\n") |
| 863 | output.write(" </files>\n") |
| Daniel Veillard | f859256 | 2002-01-23 17:58:17 +0000 | [diff] [blame] | 864 | |
| 865 | output.write(" <index>\n") |
| 866 | typ = index.keys() |
| 867 | typ.sort() |
| 868 | letter = None |
| 869 | count = 0 |
| 870 | chunk = 0 |
| 871 | chunks = [] |
| 872 | for id in typ: |
| 873 | if len(index[id]) > 30: |
| 874 | continue |
| 875 | if id[0] != letter: |
| 876 | if letter == None or count > 200: |
| 877 | if letter != None: |
| 878 | output.write(" </letter>\n") |
| 879 | output.write(" </chunk>\n") |
| 880 | count = 0 |
| 881 | chunks.append(["chunk%s" % (chunk -1), first_letter, letter]) |
| 882 | output.write(" <chunk name='chunk%s'>\n" % (chunk)) |
| 883 | first_letter = id[0] |
| 884 | chunk = chunk + 1 |
| 885 | elif letter != None: |
| 886 | output.write(" </letter>\n") |
| 887 | letter = id[0] |
| 888 | output.write(" <letter name='%s'>\n" % (letter)) |
| 889 | output.write(" <word name='%s'>\n" % (id)) |
| 890 | tokens = index[id]; |
| 891 | tokens.sort() |
| 892 | tok = None |
| 893 | for token in index[id]: |
| 894 | if tok == token: |
| 895 | continue |
| 896 | tok = token |
| 897 | output.write(" <ref name='%s'/>\n" % (token)) |
| 898 | count = count + 1 |
| 899 | output.write(" </word>\n") |
| 900 | if letter != None: |
| 901 | output.write(" </letter>\n") |
| 902 | output.write(" </chunk>\n") |
| 903 | output.write(" <chunks>\n") |
| 904 | for ch in chunks: |
| 905 | output.write(" <chunk name='%s' start='%s' end='%s'/>\n" % ( |
| 906 | ch[0], ch[1], ch[2])) |
| 907 | output.write(" </chunks>\n") |
| 908 | output.write(" </index>\n") |
| 909 | |
| Daniel Veillard | 3bf65be | 2002-01-23 12:36:34 +0000 | [diff] [blame] | 910 | output.write("</apirefs>\n") |
| 911 | output.close() |