| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
#include "mxml-config.h" |
| 52 |
#include "mxml.h" |
| 53 |
#include <time.h> |
| 54 |
#include <sys/stat.h> |
| 55 |
#ifndef WIN32 |
| 56 |
# include <dirent.h> |
| 57 |
# include <unistd.h> |
| 58 |
#endif |
| 59 |
#ifdef __APPLE__ |
| 60 |
# include <spawn.h> |
| 61 |
# include <sys/wait.h> |
| 62 |
extern char **environ; |
| 63 |
#endif |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
#define STATE_NONE 0 |
| 145 |
#define STATE_PREPROCESSOR 1 |
| 146 |
#define STATE_C_COMMENT 2 |
| 147 |
#define STATE_CXX_COMMENT 3 |
| 148 |
#define STATE_STRING 4 |
| 149 |
#define STATE_CHARACTER 5 |
| 150 |
#define STATE_IDENTIFIER 6 |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
#define OUTPUT_NONE 0 |
| 158 |
#define OUTPUT_HTML 1 |
| 159 |
#define OUTPUT_XML 2 |
| 160 |
#define OUTPUT_MAN 3 |
| 161 |
#define OUTPUT_TOKENS 4 |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
static mxml_node_t *add_variable(mxml_node_t *parent, const char *name, |
| 169 |
mxml_node_t *type); |
| 170 |
static mxml_node_t *find_public(mxml_node_t *node, mxml_node_t *top, |
| 171 |
const char *name); |
| 172 |
static char *get_comment_info(mxml_node_t *description); |
| 173 |
static char *get_text(mxml_node_t *node, char *buffer, int buflen); |
| 174 |
static mxml_type_t load_cb(mxml_node_t *node); |
| 175 |
static mxml_node_t *new_documentation(mxml_node_t **mxmldoc); |
| 176 |
static int remove_directory(const char *path); |
| 177 |
static void safe_strcpy(char *dst, const char *src); |
| 178 |
static int scan_file(const char *filename, FILE *fp, |
| 179 |
mxml_node_t *doc); |
| 180 |
static void sort_node(mxml_node_t *tree, mxml_node_t *func); |
| 181 |
static void update_comment(mxml_node_t *parent, |
| 182 |
mxml_node_t *comment); |
| 183 |
static void usage(const char *option); |
| 184 |
static void write_description(FILE *out, mxml_node_t *description, |
| 185 |
const char *element, int summary); |
| 186 |
static void write_element(FILE *out, mxml_node_t *doc, |
| 187 |
mxml_node_t *element, int mode); |
| 188 |
static void write_file(FILE *out, const char *file); |
| 189 |
static void write_function(FILE *out, mxml_node_t *doc, |
| 190 |
mxml_node_t *function, int level); |
| 191 |
static void write_html(const char *section, const char *title, |
| 192 |
const char *footerfile, |
| 193 |
const char *headerfile, |
| 194 |
const char *introfile, const char *cssfile, |
| 195 |
const char *framefile, |
| 196 |
const char *docset, const char *docversion, |
| 197 |
const char *feedname, const char *feedurl, |
| 198 |
mxml_node_t *doc); |
| 199 |
static void write_html_head(FILE *out, const char *section, |
| 200 |
const char *title, const char *cssfile); |
| 201 |
static void write_man(const char *man_name, const char *section, |
| 202 |
const char *title, const char *headerfile, |
| 203 |
const char *footerfile, const char *introfile, |
| 204 |
mxml_node_t *doc); |
| 205 |
static void write_scu(FILE *out, mxml_node_t *doc, |
| 206 |
mxml_node_t *scut); |
| 207 |
static void write_string(FILE *out, const char *s, int mode); |
| 208 |
static void write_toc(FILE *out, mxml_node_t *doc, |
| 209 |
const char *introfile, const char *target, |
| 210 |
int xml); |
| 211 |
static void write_tokens(FILE *out, mxml_node_t *doc, |
| 212 |
const char *path); |
| 213 |
static const char *ws_cb(mxml_node_t *node, int where); |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
int |
| 221 |
main(int argc, |
| 222 |
char *argv[]) |
| 223 |
{ |
| 224 |
int i; |
| 225 |
int len; |
| 226 |
FILE *fp; |
| 227 |
mxml_node_t *doc; |
| 228 |
mxml_node_t *mxmldoc; |
| 229 |
const char *cssfile, |
| 230 |
*docset, |
| 231 |
*docversion, |
| 232 |
*feedname, |
| 233 |
*feedurl, |
| 234 |
*footerfile, |
| 235 |
*framefile, |
| 236 |
*headerfile, |
| 237 |
*introfile, |
| 238 |
*name, |
| 239 |
*path, |
| 240 |
*section, |
| 241 |
*title, |
| 242 |
*xmlfile; |
| 243 |
int mode, |
| 244 |
update; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
cssfile = NULL; |
| 252 |
doc = NULL; |
| 253 |
docset = NULL; |
| 254 |
docversion = NULL; |
| 255 |
feedname = NULL; |
| 256 |
feedurl = NULL; |
| 257 |
footerfile = NULL; |
| 258 |
framefile = NULL; |
| 259 |
headerfile = NULL; |
| 260 |
introfile = NULL; |
| 261 |
mode = OUTPUT_HTML; |
| 262 |
mxmldoc = NULL; |
| 263 |
name = NULL; |
| 264 |
path = NULL; |
| 265 |
section = NULL; |
| 266 |
title = NULL; |
| 267 |
update = 0; |
| 268 |
xmlfile = NULL; |
| 269 |
|
| 270 |
for (i = 1; i < argc; i ++) |
| 271 |
if (!strcmp(argv[i], "--help")) |
| 272 |
{ |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
usage(NULL); |
| 278 |
} |
| 279 |
else if (!strcmp(argv[i], "--version")) |
| 280 |
{ |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
puts(MXML_VERSION + 10); |
| 286 |
return (0); |
| 287 |
} |
| 288 |
else if (!strcmp(argv[i], "--css") && !cssfile) |
| 289 |
{ |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
i ++; |
| 295 |
if (i < argc) |
| 296 |
cssfile = argv[i]; |
| 297 |
else |
| 298 |
usage(NULL); |
| 299 |
} |
| 300 |
else if (!strcmp(argv[i], "--docset") && !docset) |
| 301 |
{ |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
i ++; |
| 307 |
if (i < argc) |
| 308 |
docset = argv[i]; |
| 309 |
else |
| 310 |
usage(NULL); |
| 311 |
} |
| 312 |
else if (!strcmp(argv[i], "--docversion") && !docversion) |
| 313 |
{ |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
i ++; |
| 319 |
if (i < argc) |
| 320 |
docversion = argv[i]; |
| 321 |
else |
| 322 |
usage(NULL); |
| 323 |
} |
| 324 |
else if (!strcmp(argv[i], "--footer") && !footerfile) |
| 325 |
{ |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
i ++; |
| 331 |
if (i < argc) |
| 332 |
footerfile = argv[i]; |
| 333 |
else |
| 334 |
usage(NULL); |
| 335 |
} |
| 336 |
else if (!strcmp(argv[i], "--feedname") && !feedname) |
| 337 |
{ |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
i ++; |
| 343 |
if (i < argc) |
| 344 |
feedname = argv[i]; |
| 345 |
else |
| 346 |
usage(NULL); |
| 347 |
} |
| 348 |
else if (!strcmp(argv[i], "--feedurl") && !feedurl) |
| 349 |
{ |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
i ++; |
| 355 |
if (i < argc) |
| 356 |
feedurl = argv[i]; |
| 357 |
else |
| 358 |
usage(NULL); |
| 359 |
} |
| 360 |
else if (!strcmp(argv[i], "--framed") && !framefile) |
| 361 |
{ |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
i ++; |
| 367 |
if (i < argc) |
| 368 |
framefile = argv[i]; |
| 369 |
else |
| 370 |
usage(NULL); |
| 371 |
} |
| 372 |
else if (!strcmp(argv[i], "--header") && !headerfile) |
| 373 |
{ |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
i ++; |
| 379 |
if (i < argc) |
| 380 |
headerfile = argv[i]; |
| 381 |
else |
| 382 |
usage(NULL); |
| 383 |
} |
| 384 |
else if (!strcmp(argv[i], "--intro") && !introfile) |
| 385 |
{ |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
i ++; |
| 391 |
if (i < argc) |
| 392 |
introfile = argv[i]; |
| 393 |
else |
| 394 |
usage(NULL); |
| 395 |
} |
| 396 |
else if (!strcmp(argv[i], "--man") && !name) |
| 397 |
{ |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
i ++; |
| 403 |
if (i < argc) |
| 404 |
{ |
| 405 |
mode = OUTPUT_MAN; |
| 406 |
name = argv[i]; |
| 407 |
} |
| 408 |
else |
| 409 |
usage(NULL); |
| 410 |
} |
| 411 |
else if (!strcmp(argv[i], "--no-output")) |
| 412 |
mode = OUTPUT_NONE; |
| 413 |
else if (!strcmp(argv[i], "--section") && !section) |
| 414 |
{ |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
i ++; |
| 420 |
if (i < argc) |
| 421 |
section = argv[i]; |
| 422 |
else |
| 423 |
usage(NULL); |
| 424 |
} |
| 425 |
else if (!strcmp(argv[i], "--title") && !title) |
| 426 |
{ |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
i ++; |
| 432 |
if (i < argc) |
| 433 |
title = argv[i]; |
| 434 |
else |
| 435 |
usage(NULL); |
| 436 |
} |
| 437 |
else if (!strcmp(argv[i], "--tokens")) |
| 438 |
{ |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
mode = OUTPUT_TOKENS; |
| 444 |
|
| 445 |
i ++; |
| 446 |
if (i < argc) |
| 447 |
path = argv[i]; |
| 448 |
else |
| 449 |
usage(NULL); |
| 450 |
} |
| 451 |
else if (argv[i][0] == '-') |
| 452 |
{ |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
usage(argv[i]); |
| 458 |
} |
| 459 |
else |
| 460 |
{ |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
len = (int)strlen(argv[i]); |
| 466 |
if (len > 4 && !strcmp(argv[i] + len - 4, ".xml")) |
| 467 |
{ |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
if (xmlfile) |
| 473 |
usage(NULL); |
| 474 |
|
| 475 |
xmlfile = argv[i]; |
| 476 |
|
| 477 |
if (!doc) |
| 478 |
{ |
| 479 |
if ((fp = fopen(argv[i], "r")) != NULL) |
| 480 |
{ |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
doc = mxmlLoadFile(NULL, fp, load_cb); |
| 486 |
|
| 487 |
fclose(fp); |
| 488 |
|
| 489 |
if (!doc) |
| 490 |
{ |
| 491 |
mxmldoc = NULL; |
| 492 |
|
| 493 |
fprintf(stderr, |
| 494 |
"mxmldoc: Unable to read the XML documentation file " |
| 495 |
"\"%s\"!\n", argv[i]); |
| 496 |
} |
| 497 |
else if ((mxmldoc = mxmlFindElement(doc, doc, "mxmldoc", NULL, |
| 498 |
NULL, MXML_DESCEND)) == NULL) |
| 499 |
{ |
| 500 |
fprintf(stderr, |
| 501 |
"mxmldoc: XML documentation file \"%s\" is missing " |
| 502 |
"<mxmldoc> node!!\n", argv[i]); |
| 503 |
|
| 504 |
mxmlDelete(doc); |
| 505 |
doc = NULL; |
| 506 |
} |
| 507 |
} |
| 508 |
else |
| 509 |
{ |
| 510 |
doc = NULL; |
| 511 |
mxmldoc = NULL; |
| 512 |
} |
| 513 |
|
| 514 |
if (!doc) |
| 515 |
doc = new_documentation(&mxmldoc); |
| 516 |
} |
| 517 |
} |
| 518 |
else |
| 519 |
{ |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
update = 1; |
| 525 |
|
| 526 |
if (!doc) |
| 527 |
doc = new_documentation(&mxmldoc); |
| 528 |
|
| 529 |
if ((fp = fopen(argv[i], "r")) == NULL) |
| 530 |
{ |
| 531 |
fprintf(stderr, "mxmldoc: Unable to open source file \"%s\": %s\n", |
| 532 |
argv[i], strerror(errno)); |
| 533 |
mxmlDelete(doc); |
| 534 |
return (1); |
| 535 |
} |
| 536 |
else if (scan_file(argv[i], fp, mxmldoc)) |
| 537 |
{ |
| 538 |
fclose(fp); |
| 539 |
mxmlDelete(doc); |
| 540 |
return (1); |
| 541 |
} |
| 542 |
else |
| 543 |
fclose(fp); |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
if (update && xmlfile) |
| 548 |
{ |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
if ((fp = fopen(xmlfile, "w")) != NULL) |
| 554 |
{ |
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
mxmlSetWrapMargin(0); |
| 560 |
|
| 561 |
if (mxmlSaveFile(doc, fp, ws_cb)) |
| 562 |
{ |
| 563 |
fprintf(stderr, |
| 564 |
"mxmldoc: Unable to write the XML documentation file \"%s\": " |
| 565 |
"%s!\n", xmlfile, strerror(errno)); |
| 566 |
fclose(fp); |
| 567 |
mxmlDelete(doc); |
| 568 |
return (1); |
| 569 |
} |
| 570 |
|
| 571 |
fclose(fp); |
| 572 |
} |
| 573 |
else |
| 574 |
{ |
| 575 |
fprintf(stderr, |
| 576 |
"mxmldoc: Unable to create the XML documentation file \"%s\": " |
| 577 |
"%s!\n", xmlfile, strerror(errno)); |
| 578 |
mxmlDelete(doc); |
| 579 |
return (1); |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
switch (mode) |
| 584 |
{ |
| 585 |
case OUTPUT_HTML : |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
write_html(section, title ? title : "Documentation", footerfile, |
| 591 |
headerfile, introfile, cssfile, framefile, docset, |
| 592 |
docversion, feedname, feedurl, mxmldoc); |
| 593 |
break; |
| 594 |
|
| 595 |
case OUTPUT_MAN : |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
write_man(name, section, title, footerfile, headerfile, introfile, |
| 601 |
mxmldoc); |
| 602 |
break; |
| 603 |
|
| 604 |
case OUTPUT_TOKENS : |
| 605 |
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 606 |
"<Tokens version=\"1.0\">\n", stdout); |
| 607 |
|
| 608 |
write_tokens(stdout, mxmldoc, path); |
| 609 |
|
| 610 |
fputs("</Tokens>\n", stdout); |
| 611 |
break; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
mxmlDelete(doc); |
| 619 |
|
| 620 |
return (0); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
static mxml_node_t * |
| 629 |
add_variable(mxml_node_t *parent, |
| 630 |
const char *name, |
| 631 |
mxml_node_t *type) |
| 632 |
{ |
| 633 |
mxml_node_t *variable, |
| 634 |
*node, |
| 635 |
*next; |
| 636 |
char buffer[16384], |
| 637 |
*bufptr; |
| 638 |
|
| 639 |
|
| 640 |
#ifdef DEBUG |
| 641 |
fprintf(stderr, "add_variable(parent=%p, name=\"%s\", type=%p)\n", |
| 642 |
parent, name, type); |
| 643 |
#endif |
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
if (!type || !type->child) |
| 650 |
return (NULL); |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
variable = mxmlNewElement(parent, name); |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
for (node = type->child; node; node = node->next) |
| 663 |
if (!strcmp(node->value.text.string, "=")) |
| 664 |
break; |
| 665 |
|
| 666 |
if (node) |
| 667 |
{ |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
for (bufptr = buffer; node; bufptr += strlen(bufptr)) |
| 673 |
{ |
| 674 |
if (node->value.text.whitespace && bufptr > buffer) |
| 675 |
*bufptr++ = ' '; |
| 676 |
|
| 677 |
strcpy(bufptr, node->value.text.string); |
| 678 |
|
| 679 |
next = node->next; |
| 680 |
mxmlDelete(node); |
| 681 |
node = next; |
| 682 |
} |
| 683 |
|
| 684 |
mxmlElementSetAttr(variable, "default", buffer); |
| 685 |
} |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
if (type->last_child->value.text.string[0] == ')') |
| 692 |
{ |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
for (node = type->child; node; node = node->next) |
| 698 |
if (node->value.text.string[0] == '(') |
| 699 |
break; |
| 700 |
|
| 701 |
for (bufptr = buffer; node; bufptr += strlen(bufptr)) |
| 702 |
{ |
| 703 |
if (node->value.text.whitespace && bufptr > buffer) |
| 704 |
*bufptr++ = ' '; |
| 705 |
|
| 706 |
strcpy(bufptr, node->value.text.string); |
| 707 |
|
| 708 |
next = node->next; |
| 709 |
mxmlDelete(node); |
| 710 |
node = next; |
| 711 |
} |
| 712 |
} |
| 713 |
else |
| 714 |
{ |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
strcpy(buffer, type->last_child->value.text.string); |
| 720 |
mxmlDelete(type->last_child); |
| 721 |
} |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
mxmlElementSetAttr(variable, "name", buffer); |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
mxmlAdd(variable, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type); |
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
return (variable); |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
static mxml_node_t * |
| 748 |
find_public(mxml_node_t *node, |
| 749 |
mxml_node_t *top, |
| 750 |
const char *name) |
| 751 |
{ |
| 752 |
mxml_node_t *description, |
| 753 |
*comment; |
| 754 |
|
| 755 |
|
| 756 |
for (node = mxmlFindElement(node, top, name, NULL, NULL, |
| 757 |
node == top ? MXML_DESCEND_FIRST : |
| 758 |
MXML_NO_DESCEND); |
| 759 |
node; |
| 760 |
node = mxmlFindElement(node, top, name, NULL, NULL, MXML_NO_DESCEND)) |
| 761 |
{ |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
description = mxmlFindElement(node, node, "description", NULL, NULL, |
| 767 |
MXML_DESCEND_FIRST); |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
if (!description) |
| 774 |
continue; |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
for (comment = description->child; comment; comment = comment->next) |
| 781 |
if ((comment->type == MXML_TEXT && |
| 782 |
strstr(comment->value.text.string, "@private@")) || |
| 783 |
(comment->type == MXML_OPAQUE && |
| 784 |
strstr(comment->value.opaque, "@private@"))) |
| 785 |
break; |
| 786 |
|
| 787 |
if (!comment) |
| 788 |
{ |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
return (node); |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
return (NULL); |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
static char * |
| 810 |
get_comment_info( |
| 811 |
mxml_node_t *description) |
| 812 |
{ |
| 813 |
char text[10240], |
| 814 |
since[255], |
| 815 |
*ptr; |
| 816 |
static char info[1024]; |
| 817 |
|
| 818 |
|
| 819 |
if (!description) |
| 820 |
return (""); |
| 821 |
|
| 822 |
get_text(description, text, sizeof(text)); |
| 823 |
|
| 824 |
for (ptr = strchr(text, '@'); ptr; ptr = strchr(ptr + 1, '@')) |
| 825 |
{ |
| 826 |
if (!strncmp(ptr, "@deprecated@", 12)) |
| 827 |
return ("<span class=\"info\"> DEPRECATED </span>"); |
| 828 |
else if (!strncmp(ptr, "@since ", 7)) |
| 829 |
{ |
| 830 |
strncpy(since, ptr + 7, sizeof(since) - 1); |
| 831 |
since[sizeof(since) - 1] = '\0'; |
| 832 |
|
| 833 |
if ((ptr = strchr(since, '@')) != NULL) |
| 834 |
*ptr = '\0'; |
| 835 |
|
| 836 |
snprintf(info, sizeof(info), "<span class=\"info\"> %s </span>", since); |
| 837 |
return (info); |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
return (""); |
| 842 |
} |
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
static char * |
| 850 |
get_text(mxml_node_t *node, |
| 851 |
char *buffer, |
| 852 |
int buflen) |
| 853 |
{ |
| 854 |
char *ptr, |
| 855 |
*end; |
| 856 |
int len; |
| 857 |
mxml_node_t *current; |
| 858 |
|
| 859 |
|
| 860 |
ptr = buffer; |
| 861 |
end = buffer + buflen - 1; |
| 862 |
|
| 863 |
for (current = node->child; current && ptr < end; current = current->next) |
| 864 |
{ |
| 865 |
if (current->type == MXML_TEXT) |
| 866 |
{ |
| 867 |
if (current->value.text.whitespace) |
| 868 |
*ptr++ = ' '; |
| 869 |
|
| 870 |
len = (int)strlen(current->value.text.string); |
| 871 |
if (len > (int)(end - ptr)) |
| 872 |
len = (int)(end - ptr); |
| 873 |
|
| 874 |
memcpy(ptr, current->value.text.string, len); |
| 875 |
ptr += len; |
| 876 |
} |
| 877 |
else if (current->type == MXML_OPAQUE) |
| 878 |
{ |
| 879 |
len = (int)strlen(current->value.opaque); |
| 880 |
if (len > (int)(end - ptr)) |
| 881 |
len = (int)(end - ptr); |
| 882 |
|
| 883 |
memcpy(ptr, current->value.opaque, len); |
| 884 |
ptr += len; |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
*ptr = '\0'; |
| 889 |
|
| 890 |
return (buffer); |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
static mxml_type_t |
| 899 |
load_cb(mxml_node_t *node) |
| 900 |
{ |
| 901 |
if (!strcmp(node->value.element.name, "description")) |
| 902 |
return (MXML_OPAQUE); |
| 903 |
else |
| 904 |
return (MXML_TEXT); |
| 905 |
} |
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
static mxml_node_t * |
| 913 |
new_documentation(mxml_node_t **mxmldoc) |
| 914 |
{ |
| 915 |
mxml_node_t *doc; |
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
doc = mxmlNewXML(NULL); |
| 923 |
|
| 924 |
*mxmldoc = mxmlNewElement(doc, "mxmldoc"); |
| 925 |
|
| 926 |
mxmlElementSetAttr(*mxmldoc, "xmlns", "http://www.easysw.com"); |
| 927 |
mxmlElementSetAttr(*mxmldoc, "xmlns:xsi", |
| 928 |
"http://www.w3.org/2001/XMLSchema-instance"); |
| 929 |
mxmlElementSetAttr(*mxmldoc, "xsi:schemaLocation", |
| 930 |
"http://www.minixml.org/mxmldoc.xsd"); |
| 931 |
|
| 932 |
return (doc); |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
static int |
| 941 |
remove_directory(const char *path) |
| 942 |
{ |
| 943 |
#ifdef WIN32 |
| 944 |
|
| 945 |
|
| 946 |
#else |
| 947 |
DIR *dir; |
| 948 |
struct dirent *dent; |
| 949 |
char filename[1024]; |
| 950 |
struct stat fileinfo; |
| 951 |
|
| 952 |
|
| 953 |
if ((dir = opendir(path)) == NULL) |
| 954 |
{ |
| 955 |
fprintf(stderr, "mxmldoc: Unable to open directory \"%s\": %s\n", path, |
| 956 |
strerror(errno)); |
| 957 |
return (0); |
| 958 |
} |
| 959 |
|
| 960 |
while ((dent = readdir(dir)) != NULL) |
| 961 |
{ |
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) |
| 967 |
continue; |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
snprintf(filename, sizeof(filename), "%s/%s", path, dent->d_name); |
| 974 |
|
| 975 |
if (stat(filename, &fileinfo)) |
| 976 |
{ |
| 977 |
fprintf(stderr, "mxmldoc: Unable to stat \"%s\": %s\n", filename, |
| 978 |
strerror(errno)); |
| 979 |
closedir(dir); |
| 980 |
return (0); |
| 981 |
} |
| 982 |
|
| 983 |
if (S_ISDIR(fileinfo.st_mode)) |
| 984 |
{ |
| 985 |
if (!remove_directory(filename)) |
| 986 |
{ |
| 987 |
closedir(dir); |
| 988 |
return (0); |
| 989 |
} |
| 990 |
} |
| 991 |
else if (unlink(filename)) |
| 992 |
{ |
| 993 |
fprintf(stderr, "mxmldoc: Unable to remove \"%s\": %s\n", filename, |
| 994 |
strerror(errno)); |
| 995 |
closedir(dir); |
| 996 |
return (0); |
| 997 |
} |
| 998 |
} |
| 999 |
|
| 1000 |
closedir(dir); |
| 1001 |
|
| 1002 |
if (rmdir(path)) |
| 1003 |
{ |
| 1004 |
fprintf(stderr, "mxmldoc: Unable to remove directory \"%s\": %s\n", path, |
| 1005 |
strerror(errno)); |
| 1006 |
return (0); |
| 1007 |
} |
| 1008 |
#endif |
| 1009 |
|
| 1010 |
return (1); |
| 1011 |
} |
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
static void |
| 1019 |
safe_strcpy(char *dst, |
| 1020 |
const char *src) |
| 1021 |
{ |
| 1022 |
while (*src) |
| 1023 |
*dst++ = *src++; |
| 1024 |
|
| 1025 |
*dst = '\0'; |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
static int |
| 1034 |
scan_file(const char *filename, |
| 1035 |
FILE *fp, |
| 1036 |
mxml_node_t *tree) |
| 1037 |
{ |
| 1038 |
int state, |
| 1039 |
braces, |
| 1040 |
parens; |
| 1041 |
int ch; |
| 1042 |
char buffer[65536], |
| 1043 |
*bufptr; |
| 1044 |
const char *scope; |
| 1045 |
mxml_node_t *comment, |
| 1046 |
*constant, |
| 1047 |
*enumeration, |
| 1048 |
*function, |
| 1049 |
*fstructclass, |
| 1050 |
*structclass, |
| 1051 |
*typedefnode, |
| 1052 |
*variable, |
| 1053 |
*returnvalue, |
| 1054 |
*type, |
| 1055 |
*description, |
| 1056 |
*node, |
| 1057 |
*next; |
| 1058 |
#if DEBUG > 1 |
| 1059 |
mxml_node_t *temp; |
| 1060 |
int oldstate, |
| 1061 |
oldch; |
| 1062 |
static const char *states[] = |
| 1063 |
{ |
| 1064 |
"STATE_NONE", |
| 1065 |
"STATE_PREPROCESSOR", |
| 1066 |
"STATE_C_COMMENT", |
| 1067 |
"STATE_CXX_COMMENT", |
| 1068 |
"STATE_STRING", |
| 1069 |
"STATE_CHARACTER", |
| 1070 |
"STATE_IDENTIFIER" |
| 1071 |
}; |
| 1072 |
#endif |
| 1073 |
|
| 1074 |
|
| 1075 |
#ifdef DEBUG |
| 1076 |
fprintf(stderr, "scan_file(filename=\"%s\", fp=%p, tree=%p)\n", filename, |
| 1077 |
fp, tree); |
| 1078 |
#endif |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
state = STATE_NONE; |
| 1085 |
braces = 0; |
| 1086 |
parens = 0; |
| 1087 |
bufptr = buffer; |
| 1088 |
|
| 1089 |
comment = mxmlNewElement(MXML_NO_PARENT, "temp"); |
| 1090 |
constant = NULL; |
| 1091 |
enumeration = NULL; |
| 1092 |
function = NULL; |
| 1093 |
variable = NULL; |
| 1094 |
returnvalue = NULL; |
| 1095 |
type = NULL; |
| 1096 |
description = NULL; |
| 1097 |
typedefnode = NULL; |
| 1098 |
structclass = NULL; |
| 1099 |
fstructclass = NULL; |
| 1100 |
|
| 1101 |
if (!strcmp(tree->value.element.name, "class")) |
| 1102 |
scope = "private"; |
| 1103 |
else |
| 1104 |
scope = NULL; |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
while ((ch = getc(fp)) != EOF) |
| 1111 |
{ |
| 1112 |
#if DEBUG > 1 |
| 1113 |
oldstate = state; |
| 1114 |
oldch = ch; |
| 1115 |
#endif |
| 1116 |
|
| 1117 |
switch (state) |
| 1118 |
{ |
| 1119 |
case STATE_NONE : |
| 1120 |
switch (ch) |
| 1121 |
{ |
| 1122 |
case '/' : |
| 1123 |
ch = getc(fp); |
| 1124 |
bufptr = buffer; |
| 1125 |
|
| 1126 |
if (ch == '*') |
| 1127 |
state = STATE_C_COMMENT; |
| 1128 |
else if (ch == '/') |
| 1129 |
state = STATE_CXX_COMMENT; |
| 1130 |
else |
| 1131 |
{ |
| 1132 |
ungetc(ch, fp); |
| 1133 |
|
| 1134 |
if (type) |
| 1135 |
{ |
| 1136 |
#ifdef DEBUG |
| 1137 |
fputs("Identifier: <<<< / >>>\n", stderr); |
| 1138 |
#endif |
| 1139 |
ch = type->last_child->value.text.string[0]; |
| 1140 |
mxmlNewText(type, isalnum(ch) || ch == '_', "/"); |
| 1141 |
} |
| 1142 |
} |
| 1143 |
break; |
| 1144 |
|
| 1145 |
case '#' : |
| 1146 |
#ifdef DEBUG |
| 1147 |
fputs(" #preprocessor...\n", stderr); |
| 1148 |
#endif |
| 1149 |
state = STATE_PREPROCESSOR; |
| 1150 |
break; |
| 1151 |
|
| 1152 |
case '\'' : |
| 1153 |
state = STATE_CHARACTER; |
| 1154 |
bufptr = buffer; |
| 1155 |
*bufptr++ = ch; |
| 1156 |
break; |
| 1157 |
|
| 1158 |
case '\"' : |
| 1159 |
state = STATE_STRING; |
| 1160 |
bufptr = buffer; |
| 1161 |
*bufptr++ = ch; |
| 1162 |
break; |
| 1163 |
|
| 1164 |
case '{' : |
| 1165 |
#ifdef DEBUG |
| 1166 |
fprintf(stderr, " open brace, function=%p, type=%p...\n", |
| 1167 |
function, type); |
| 1168 |
if (type) |
| 1169 |
fprintf(stderr, " type->child=\"%s\"...\n", |
| 1170 |
type->child->value.text.string); |
| 1171 |
#endif |
| 1172 |
|
| 1173 |
if (function) |
| 1174 |
{ |
| 1175 |
if (fstructclass) |
| 1176 |
{ |
| 1177 |
sort_node(fstructclass, function); |
| 1178 |
fstructclass = NULL; |
| 1179 |
} |
| 1180 |
else |
| 1181 |
sort_node(tree, function); |
| 1182 |
|
| 1183 |
function = NULL; |
| 1184 |
} |
| 1185 |
else if (type && type->child && |
| 1186 |
((!strcmp(type->child->value.text.string, "typedef") && |
| 1187 |
type->child->next && |
| 1188 |
(!strcmp(type->child->next->value.text.string, "struct") || |
| 1189 |
!strcmp(type->child->next->value.text.string, "union") || |
| 1190 |
!strcmp(type->child->next->value.text.string, "class"))) || |
| 1191 |
!strcmp(type->child->value.text.string, "union") || |
| 1192 |
!strcmp(type->child->value.text.string, "struct") || |
| 1193 |
!strcmp(type->child->value.text.string, "class"))) |
| 1194 |
{ |
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
if (!strcmp(type->child->value.text.string, "typedef")) |
| 1200 |
{ |
| 1201 |
#ifdef DEBUG |
| 1202 |
fputs(" starting typedef...\n", stderr); |
| 1203 |
#endif |
| 1204 |
|
| 1205 |
typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef"); |
| 1206 |
mxmlDelete(type->child); |
| 1207 |
} |
| 1208 |
else |
| 1209 |
typedefnode = NULL; |
| 1210 |
|
| 1211 |
structclass = mxmlNewElement(MXML_NO_PARENT, |
| 1212 |
type->child->value.text.string); |
| 1213 |
|
| 1214 |
#ifdef DEBUG |
| 1215 |
fprintf(stderr, "%c%s: <<<< %s >>>\n", |
| 1216 |
toupper(type->child->value.text.string[0]), |
| 1217 |
type->child->value.text.string + 1, |
| 1218 |
type->child->next ? |
| 1219 |
type->child->next->value.text.string : "(noname)"); |
| 1220 |
|
| 1221 |
fputs(" type =", stderr); |
| 1222 |
for (node = type->child; node; node = node->next) |
| 1223 |
fprintf(stderr, " \"%s\"", node->value.text.string); |
| 1224 |
putc('\n', stderr); |
| 1225 |
|
| 1226 |
fprintf(stderr, " scope = %s\n", scope ? scope : "(null)"); |
| 1227 |
#endif |
| 1228 |
|
| 1229 |
if (type->child->next) |
| 1230 |
{ |
| 1231 |
mxmlElementSetAttr(structclass, "name", |
| 1232 |
type->child->next->value.text.string); |
| 1233 |
sort_node(tree, structclass); |
| 1234 |
} |
| 1235 |
|
| 1236 |
if (typedefnode && type->child) |
| 1237 |
type->child->value.text.whitespace = 0; |
| 1238 |
else if (structclass && type->child && |
| 1239 |
type->child->next && type->child->next->next) |
| 1240 |
{ |
| 1241 |
for (bufptr = buffer, node = type->child->next->next; |
| 1242 |
node; |
| 1243 |
bufptr += strlen(bufptr)) |
| 1244 |
{ |
| 1245 |
if (node->value.text.whitespace && bufptr > buffer) |
| 1246 |
*bufptr++ = ' '; |
| 1247 |
|
| 1248 |
strcpy(bufptr, node->value.text.string); |
| 1249 |
|
| 1250 |
next = node->next; |
| 1251 |
mxmlDelete(node); |
| 1252 |
node = next; |
| 1253 |
} |
| 1254 |
|
| 1255 |
mxmlElementSetAttr(structclass, "parent", buffer); |
| 1256 |
|
| 1257 |
mxmlDelete(type); |
| 1258 |
type = NULL; |
| 1259 |
} |
| 1260 |
else |
| 1261 |
{ |
| 1262 |
mxmlDelete(type); |
| 1263 |
type = NULL; |
| 1264 |
} |
| 1265 |
|
| 1266 |
if (typedefnode && comment->last_child) |
| 1267 |
{ |
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
mxmlNewText(comment, 0, |
| 1273 |
comment->last_child->value.text.string); |
| 1274 |
description = mxmlNewElement(typedefnode, "description"); |
| 1275 |
#ifdef DEBUG |
| 1276 |
fprintf(stderr, |
| 1277 |
" duplicating comment %p/%p for typedef...\n", |
| 1278 |
comment->last_child, comment->child); |
| 1279 |
#endif |
| 1280 |
update_comment(typedefnode, comment->last_child); |
| 1281 |
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, |
| 1282 |
comment->last_child); |
| 1283 |
} |
| 1284 |
|
| 1285 |
description = mxmlNewElement(structclass, "description"); |
| 1286 |
#ifdef DEBUG |
| 1287 |
fprintf(stderr, " adding comment %p/%p to %s...\n", |
| 1288 |
comment->last_child, comment->child, |
| 1289 |
structclass->value.element.name); |
| 1290 |
#endif |
| 1291 |
update_comment(structclass, comment->last_child); |
| 1292 |
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, |
| 1293 |
comment->last_child); |
| 1294 |
|
| 1295 |
if (scan_file(filename, fp, structclass)) |
| 1296 |
{ |
| 1297 |
mxmlDelete(comment); |
| 1298 |
return (-1); |
| 1299 |
} |
| 1300 |
|
| 1301 |
#ifdef DEBUG |
| 1302 |
fputs(" ended typedef...\n", stderr); |
| 1303 |
#endif |
| 1304 |
structclass = NULL; |
| 1305 |
break; |
| 1306 |
} |
| 1307 |
else if (type && type->child && type->child->next && |
| 1308 |
(!strcmp(type->child->value.text.string, "enum") || |
| 1309 |
(!strcmp(type->child->value.text.string, "typedef") && |
| 1310 |
!strcmp(type->child->next->value.text.string, "enum")))) |
| 1311 |
{ |
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
if (!strcmp(type->child->value.text.string, "typedef")) |
| 1317 |
{ |
| 1318 |
#ifdef DEBUG |
| 1319 |
fputs(" starting typedef...\n", stderr); |
| 1320 |
#endif |
| 1321 |
|
| 1322 |
typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef"); |
| 1323 |
mxmlDelete(type->child); |
| 1324 |
} |
| 1325 |
else |
| 1326 |
typedefnode = NULL; |
| 1327 |
|
| 1328 |
enumeration = mxmlNewElement(MXML_NO_PARENT, "enumeration"); |
| 1329 |
|
| 1330 |
#ifdef DEBUG |
| 1331 |
fprintf(stderr, "Enumeration: <<<< %s >>>\n", |
| 1332 |
type->child->next ? |
| 1333 |
type->child->next->value.text.string : "(noname)"); |
| 1334 |
#endif |
| 1335 |
|
| 1336 |
if (type->child->next) |
| 1337 |
{ |
| 1338 |
mxmlElementSetAttr(enumeration, "name", |
| 1339 |
type->child->next->value.text.string); |
| 1340 |
sort_node(tree, enumeration); |
| 1341 |
} |
| 1342 |
|
| 1343 |
if (typedefnode && type->child) |
| 1344 |
type->child->value.text.whitespace = 0; |
| 1345 |
else |
| 1346 |
{ |
| 1347 |
mxmlDelete(type); |
| 1348 |
type = NULL; |
| 1349 |
} |
| 1350 |
|
| 1351 |
if (typedefnode && comment->last_child) |
| 1352 |
{ |
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
mxmlNewText(comment, 0, |
| 1358 |
comment->last_child->value.text.string); |
| 1359 |
description = mxmlNewElement(typedefnode, "description"); |
| 1360 |
#ifdef DEBUG |
| 1361 |
fprintf(stderr, |
| 1362 |
" duplicating comment %p/%p for typedef...\n", |
| 1363 |
comment->last_child, comment->child); |
| 1364 |
#endif |
| 1365 |
update_comment(typedefnode, comment->last_child); |
| 1366 |
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, |
| 1367 |
comment->last_child); |
| 1368 |
} |
| 1369 |
|
| 1370 |
description = mxmlNewElement(enumeration, "description"); |
| 1371 |
#ifdef DEBUG |
| 1372 |
fprintf(stderr, " adding comment %p/%p to enumeration...\n", |
| 1373 |
comment->last_child, comment->child); |
| 1374 |
#endif |
| 1375 |
update_comment(enumeration, comment->last_child); |
| 1376 |
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, |
| 1377 |
comment->last_child); |
| 1378 |
} |
| 1379 |
else if (type && type->child && |
| 1380 |
!strcmp(type->child->value.text.string, "extern")) |
| 1381 |
{ |
| 1382 |
if (scan_file(filename, fp, tree)) |
| 1383 |
{ |
| 1384 |
mxmlDelete(comment); |
| 1385 |
return (-1); |
| 1386 |
} |
| 1387 |
} |
| 1388 |
else if (type) |
| 1389 |
{ |
| 1390 |
mxmlDelete(type); |
| 1391 |
type = NULL; |
| 1392 |
} |
| 1393 |
|
| 1394 |
braces ++; |
| 1395 |
function = NULL; |
| 1396 |
variable = NULL; |
| 1397 |
break; |
| 1398 |
|
| 1399 |
case '}' : |
| 1400 |
#ifdef DEBUG |
| 1401 |
fputs(" close brace...\n", stderr); |
| 1402 |
#endif |
| 1403 |
|
| 1404 |
if (structclass) |
| 1405 |
scope = NULL; |
| 1406 |
|
| 1407 |
if (!typedefnode) |
| 1408 |
enumeration = NULL; |
| 1409 |
|
| 1410 |
constant = NULL; |
| 1411 |
structclass = NULL; |
| 1412 |
|
| 1413 |
if (braces > 0) |
| 1414 |
braces --; |
| 1415 |
else |
| 1416 |
{ |
| 1417 |
mxmlDelete(comment); |
| 1418 |
return (0); |
| 1419 |
} |
| 1420 |
break; |
| 1421 |
|
| 1422 |
case '(' : |
| 1423 |
if (type) |
| 1424 |
{ |
| 1425 |
#ifdef DEBUG |
| 1426 |
fputs("Identifier: <<<< ( >>>\n", stderr); |
| 1427 |
#endif |
| 1428 |
mxmlNewText(type, 0, "("); |
| 1429 |
} |
| 1430 |
|
| 1431 |
parens ++; |
| 1432 |
break; |
| 1433 |
|
| 1434 |
case ')' : |
| 1435 |
if (type && parens) |
| 1436 |
{ |
| 1437 |
#ifdef DEBUG |
| 1438 |
fputs("Identifier: <<<< ) >>>\n", stderr); |
| 1439 |
#endif |
| 1440 |
mxmlNewText(type, 0, ")"); |
| 1441 |
} |
| 1442 |
|
| 1443 |
if (function && type && !parens) |
| 1444 |
{ |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
if (type->child && type->child->next) |
| 1450 |
variable = add_variable(function, "argument", type); |
| 1451 |
else |
| 1452 |
mxmlDelete(type); |
| 1453 |
|
| 1454 |
type = NULL; |
| 1455 |
} |
| 1456 |
|
| 1457 |
if (parens > 0) |
| 1458 |
parens --; |
| 1459 |
break; |
| 1460 |
|
| 1461 |
case ';' : |
| 1462 |
#ifdef DEBUG |
| 1463 |
fputs("Identifier: <<<< ; >>>\n", stderr); |
| 1464 |
fprintf(stderr, " enumeration=%p, function=%p, type=%p, type->child=%p, typedefnode=%p\n", |
| 1465 |
enumeration, function, type, type ? type->child : NULL, typedefnode); |
| 1466 |
#endif |
| 1467 |
|
| 1468 |
if (function) |
| 1469 |
{ |
| 1470 |
if (!strcmp(tree->value.element.name, "class")) |
| 1471 |
{ |
| 1472 |
#ifdef DEBUG |
| 1473 |
fputs(" ADDING FUNCTION TO CLASS\n", stderr); |
| 1474 |
#endif |
| 1475 |
sort_node(tree, function); |
| 1476 |
} |
| 1477 |
else |
| 1478 |
mxmlDelete(function); |
| 1479 |
|
| 1480 |
function = NULL; |
| 1481 |
variable = NULL; |
| 1482 |
} |
| 1483 |
|
| 1484 |
if (type) |
| 1485 |
{ |
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
if (type->child && |
| 1491 |
!strcmp(type->child->value.text.string, "typedef")) |
| 1492 |
{ |
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef"); |
| 1498 |
|
| 1499 |
for (node = type->child->next; node; node = node->next) |
| 1500 |
if (!strcmp(node->value.text.string, "(")) |
| 1501 |
break; |
| 1502 |
|
| 1503 |
if (node) |
| 1504 |
{ |
| 1505 |
for (node = node->next; node; node = node->next) |
| 1506 |
if (strcmp(node->value.text.string, "*")) |
| 1507 |
break; |
| 1508 |
} |
| 1509 |
|
| 1510 |
if (!node) |
| 1511 |
node = type->last_child; |
| 1512 |
|
| 1513 |
#ifdef DEBUG |
| 1514 |
fprintf(stderr, " ADDING TYPEDEF FOR %p(%s)...\n", |
| 1515 |
node, node->value.text.string); |
| 1516 |
#endif |
| 1517 |
|
| 1518 |
mxmlElementSetAttr(typedefnode, "name", |
| 1519 |
node->value.text.string); |
| 1520 |
sort_node(tree, typedefnode); |
| 1521 |
|
| 1522 |
if (type->child != node) |
| 1523 |
mxmlDelete(type->child); |
| 1524 |
|
| 1525 |
mxmlDelete(node); |
| 1526 |
|
| 1527 |
if (type->child) |
| 1528 |
type->child->value.text.whitespace = 0; |
| 1529 |
|
| 1530 |
mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, |
| 1531 |
type); |
| 1532 |
type = NULL; |
| 1533 |
break; |
| 1534 |
} |
| 1535 |
else if (typedefnode && enumeration) |
| 1536 |
{ |
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
node = type->child; |
| 1542 |
|
| 1543 |
#ifdef DEBUG |
| 1544 |
fprintf(stderr, " ADDING TYPEDEF FOR %p(%s)...\n", |
| 1545 |
node, node->value.text.string); |
| 1546 |
#endif |
| 1547 |
|
| 1548 |
mxmlElementSetAttr(typedefnode, "name", |
| 1549 |
node->value.text.string); |
| 1550 |
sort_node(tree, typedefnode); |
| 1551 |
mxmlDelete(type); |
| 1552 |
|
| 1553 |
type = mxmlNewElement(typedefnode, "type"); |
| 1554 |
mxmlNewText(type, 0, "enum"); |
| 1555 |
mxmlNewText(type, 1, |
| 1556 |
mxmlElementGetAttr(enumeration, "name")); |
| 1557 |
enumeration = NULL; |
| 1558 |
type = NULL; |
| 1559 |
break; |
| 1560 |
} |
| 1561 |
|
| 1562 |
mxmlDelete(type); |
| 1563 |
type = NULL; |
| 1564 |
} |
| 1565 |
break; |
| 1566 |
|
| 1567 |
case ':' : |
| 1568 |
if (type) |
| 1569 |
{ |
| 1570 |
#ifdef DEBUG |
| 1571 |
fputs("Identifier: <<<< : >>>\n", stderr); |
| 1572 |
#endif |
| 1573 |
mxmlNewText(type, 1, ":"); |
| 1574 |
} |
| 1575 |
break; |
| 1576 |
|
| 1577 |
case '*' : |
| 1578 |
if (type) |
| 1579 |
{ |
| 1580 |
#ifdef DEBUG |
| 1581 |
fputs("Identifier: <<<< * >>>\n", stderr); |
| 1582 |
#endif |
| 1583 |
ch = type->last_child->value.text.string[0]; |
| 1584 |
mxmlNewText(type, isalnum(ch) || ch == '_', "*"); |
| 1585 |
} |
| 1586 |
break; |
| 1587 |
|
| 1588 |
case ',' : |
| 1589 |
if (type && !enumeration) |
| 1590 |
{ |
| 1591 |
#ifdef DEBUG |
| 1592 |
fputs("Identifier: <<<< , >>>\n", stderr); |
| 1593 |
#endif |
| 1594 |
mxmlNewText(type, 0, ","); |
| 1595 |
} |
| 1596 |
break; |
| 1597 |
|
| 1598 |
case '&' : |
| 1599 |
if (type) |
| 1600 |
{ |
| 1601 |
#ifdef DEBUG |
| 1602 |
fputs("Identifier: <<<< & >>>\n", stderr); |
| 1603 |
#endif |
| 1604 |
mxmlNewText(type, 1, "&"); |
| 1605 |
} |
| 1606 |
break; |
| 1607 |
|
| 1608 |
case '+' : |
| 1609 |
if (type) |
| 1610 |
{ |
| 1611 |
#ifdef DEBUG |
| 1612 |
fputs("Identifier: <<<< + >>>\n", stderr); |
| 1613 |
#endif |
| 1614 |
ch = type->last_child->value.text.string[0]; |
| 1615 |
mxmlNewText(type, isalnum(ch) || ch == '_', "+"); |
| 1616 |
} |
| 1617 |
break; |
| 1618 |
|
| 1619 |
case '-' : |
| 1620 |
if (type) |
| 1621 |
{ |
| 1622 |
#ifdef DEBUG |
| 1623 |
fputs("Identifier: <<<< - >>>\n", stderr); |
| 1624 |
#endif |
| 1625 |
ch = type->last_child->value.text.string[0]; |
| 1626 |
mxmlNewText(type, isalnum(ch) || ch == '_', "-"); |
| 1627 |
} |
| 1628 |
break; |
| 1629 |
|
| 1630 |
case '=' : |
| 1631 |
if (type) |
| 1632 |
{ |
| 1633 |
#ifdef DEBUG |
| 1634 |
fputs("Identifier: <<<< = >>>\n", stderr); |
| 1635 |
#endif |
| 1636 |
ch = type->last_child->value.text.string[0]; |
| 1637 |
mxmlNewText(type, isalnum(ch) || ch == '_', "="); |
| 1638 |
} |
| 1639 |
break; |
| 1640 |
|
| 1641 |
default : |
| 1642 |
if (isalnum(ch) || ch == '_' || ch == '.' || ch == ':' || ch == '~') |
| 1643 |
{ |
| 1644 |
state = STATE_IDENTIFIER; |
| 1645 |
bufptr = buffer; |
| 1646 |
*bufptr++ = ch; |
| 1647 |
} |
| 1648 |
break; |
| 1649 |
} |
| 1650 |
break; |
| 1651 |
|
| 1652 |
case STATE_PREPROCESSOR : |
| 1653 |
if (ch == '\n') |
| 1654 |
state = STATE_NONE; |
| 1655 |
else if (ch == '\\') |
| 1656 |
getc(fp); |
| 1657 |
break; |
| 1658 |
|
| 1659 |
case STATE_C_COMMENT : |
| 1660 |
switch (ch) |
| 1661 |
{ |
| 1662 |
case '\n' : |
| 1663 |
while ((ch = getc(fp)) != EOF) |
| 1664 |
if (ch == '*') |
| 1665 |
{ |
| 1666 |
ch = getc(fp); |
| 1667 |
|
| 1668 |
if (ch == '/') |
| 1669 |
{ |
| 1670 |
*bufptr = '\0'; |
| 1671 |
|
| 1672 |
if (comment->child != comment->last_child) |
| 1673 |
{ |
| 1674 |
#ifdef DEBUG |
| 1675 |
fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n", |
| 1676 |
comment->child, |
| 1677 |
comment->child ? comment->child->value.text.string : "", |
| 1678 |
comment->last_child, |
| 1679 |
comment->last_child ? comment->last_child->value.text.string : ""); |
| 1680 |
#endif |
| 1681 |
mxmlDelete(comment->child); |
| 1682 |
#ifdef DEBUG |
| 1683 |
fprintf(stderr, " new comment %p, last comment %p...\n", |
| 1684 |
comment->child, comment->last_child); |
| 1685 |
#endif |
| 1686 |
} |
| 1687 |
|
| 1688 |
#ifdef DEBUG |
| 1689 |
fprintf(stderr, |
| 1690 |
" processing comment, variable=%p, " |
| 1691 |
"constant=%p, typedefnode=%p, tree=\"%s\"\n", |
| 1692 |
variable, constant, typedefnode, |
| 1693 |
tree->value.element.name); |
| 1694 |
#endif |
| 1695 |
|
| 1696 |
if (variable) |
| 1697 |
{ |
| 1698 |
if (strstr(buffer, "@private@")) |
| 1699 |
{ |
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
mxmlDelete(variable); |
| 1705 |
} |
| 1706 |
else |
| 1707 |
{ |
| 1708 |
description = mxmlNewElement(variable, "description"); |
| 1709 |
#ifdef DEBUG |
| 1710 |
fprintf(stderr, |
| 1711 |
" adding comment %p/%p to variable...\n", |
| 1712 |
comment->last_child, comment->child); |
| 1713 |
#endif |
| 1714 |
mxmlNewText(comment, 0, buffer); |
| 1715 |
update_comment(variable, |
| 1716 |
mxmlNewText(description, 0, buffer)); |
| 1717 |
} |
| 1718 |
|
| 1719 |
variable = NULL; |
| 1720 |
} |
| 1721 |
else if (constant) |
| 1722 |
{ |
| 1723 |
if (strstr(buffer, "@private@")) |
| 1724 |
{ |
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
mxmlDelete(constant); |
| 1730 |
} |
| 1731 |
else |
| 1732 |
{ |
| 1733 |
description = mxmlNewElement(constant, "description"); |
| 1734 |
#ifdef DEBUG |
| 1735 |
fprintf(stderr, |
| 1736 |
" adding comment %p/%p to constant...\n", |
| 1737 |
comment->last_child, comment->child); |
| 1738 |
#endif |
| 1739 |
mxmlNewText(comment, 0, buffer); |
| 1740 |
update_comment(constant, |
| 1741 |
mxmlNewText(description, 0, buffer)); |
| 1742 |
} |
| 1743 |
|
| 1744 |
constant = NULL; |
| 1745 |
} |
| 1746 |
else if (typedefnode) |
| 1747 |
{ |
| 1748 |
if (strstr(buffer, "@private@")) |
| 1749 |
{ |
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
mxmlDelete(typedefnode); |
| 1755 |
|
| 1756 |
if (structclass) |
| 1757 |
{ |
| 1758 |
mxmlDelete(structclass); |
| 1759 |
structclass = NULL; |
| 1760 |
} |
| 1761 |
|
| 1762 |
if (enumeration) |
| 1763 |
{ |
| 1764 |
mxmlDelete(enumeration); |
| 1765 |
enumeration = NULL; |
| 1766 |
} |
| 1767 |
} |
| 1768 |
else |
| 1769 |
{ |
| 1770 |
description = mxmlNewElement(typedefnode, "description"); |
| 1771 |
#ifdef DEBUG |
| 1772 |
fprintf(stderr, |
| 1773 |
" adding comment %p/%p to typedef %s...\n", |
| 1774 |
comment->last_child, comment->child, |
| 1775 |
mxmlElementGetAttr(typedefnode, "name")); |
| 1776 |
#endif |
| 1777 |
mxmlNewText(comment, 0, buffer); |
| 1778 |
update_comment(typedefnode, |
| 1779 |
mxmlNewText(description, 0, buffer)); |
| 1780 |
|
| 1781 |
if (structclass) |
| 1782 |
{ |
| 1783 |
description = mxmlNewElement(structclass, "description"); |
| 1784 |
update_comment(structclass, |
| 1785 |
mxmlNewText(description, 0, buffer)); |
| 1786 |
} |
| 1787 |
else if (enumeration) |
| 1788 |
{ |
| 1789 |
description = mxmlNewElement(enumeration, "description"); |
| 1790 |
update_comment(enumeration, |
| 1791 |
mxmlNewText(description, 0, buffer)); |
| 1792 |
} |
| 1793 |
} |
| 1794 |
|
| 1795 |
typedefnode = NULL; |
| 1796 |
} |
| 1797 |
else if (strcmp(tree->value.element.name, "mxmldoc") && |
| 1798 |
!mxmlFindElement(tree, tree, "description", |
| 1799 |
NULL, NULL, MXML_DESCEND_FIRST)) |
| 1800 |
{ |
| 1801 |
description = mxmlNewElement(tree, "description"); |
| 1802 |
#ifdef DEBUG |
| 1803 |
fprintf(stderr, " adding comment %p/%p to parent...\n", |
| 1804 |
comment->last_child, comment->child); |
| 1805 |
#endif |
| 1806 |
mxmlNewText(comment, 0, buffer); |
| 1807 |
update_comment(tree, |
| 1808 |
mxmlNewText(description, 0, buffer)); |
| 1809 |
} |
| 1810 |
else |
| 1811 |
{ |
| 1812 |
#ifdef DEBUG |
| 1813 |
fprintf(stderr, " before adding comment, child=%p, last_child=%p\n", |
| 1814 |
comment->child, comment->last_child); |
| 1815 |
#endif |
| 1816 |
mxmlNewText(comment, 0, buffer); |
| 1817 |
#ifdef DEBUG |
| 1818 |
fprintf(stderr, " after adding comment, child=%p, last_child=%p\n", |
| 1819 |
comment->child, comment->last_child); |
| 1820 |
#endif |
| 1821 |
} |
| 1822 |
#ifdef DEBUG |
| 1823 |
fprintf(stderr, "C comment: <<<< %s >>>\n", buffer); |
| 1824 |
#endif |
| 1825 |
|
| 1826 |
state = STATE_NONE; |
| 1827 |
break; |
| 1828 |
} |
| 1829 |
else |
| 1830 |
ungetc(ch, fp); |
| 1831 |
} |
| 1832 |
else if (ch == '\n' && bufptr > buffer && |
| 1833 |
bufptr < (buffer + sizeof(buffer) - 1)) |
| 1834 |
*bufptr++ = ch; |
| 1835 |
else if (!isspace(ch)) |
| 1836 |
break; |
| 1837 |
|
| 1838 |
if (ch != EOF) |
| 1839 |
ungetc(ch, fp); |
| 1840 |
|
| 1841 |
if (bufptr > buffer && bufptr < (buffer + sizeof(buffer) - 1)) |
| 1842 |
*bufptr++ = '\n'; |
| 1843 |
break; |
| 1844 |
|
| 1845 |
case '/' : |
| 1846 |
if (ch == '/' && bufptr > buffer && bufptr[-1] == '*') |
| 1847 |
{ |
| 1848 |
while (bufptr > buffer && |
| 1849 |
(bufptr[-1] == '*' || isspace(bufptr[-1] & 255))) |
| 1850 |
bufptr --; |
| 1851 |
*bufptr = '\0'; |
| 1852 |
|
| 1853 |
if (comment->child != comment->last_child) |
| 1854 |
{ |
| 1855 |
#ifdef DEBUG |
| 1856 |
fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n", |
| 1857 |
comment->child, |
| 1858 |
comment->child ? comment->child->value.text.string : "", |
| 1859 |
comment->last_child, |
| 1860 |
comment->last_child ? comment->last_child->value.text.string : ""); |
| 1861 |
#endif |
| 1862 |
mxmlDelete(comment->child); |
| 1863 |
#ifdef DEBUG |
| 1864 |
fprintf(stderr, " new comment %p, last comment %p...\n", |
| 1865 |
comment->child, comment->last_child); |
| 1866 |
#endif |
| 1867 |
} |
| 1868 |
|
| 1869 |
#ifdef DEBUG |
| 1870 |
fprintf(stderr, |
| 1871 |
" processing comment, variable=%p, " |
| 1872 |
"constant=%p, typedefnode=%p, tree=\"%s\"\n", |
| 1873 |
variable, constant, typedefnode, |
| 1874 |
tree->value.element.name); |
| 1875 |
#endif |
| 1876 |
|
| 1877 |
if (variable) |
| 1878 |
{ |
| 1879 |
if (strstr(buffer, "@private@")) |
| 1880 |
{ |
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
mxmlDelete(variable); |
| 1886 |
} |
| 1887 |
else |
| 1888 |
{ |
| 1889 |
description = mxmlNewElement(variable, "description"); |
| 1890 |
#ifdef DEBUG |
| 1891 |
fprintf(stderr, " adding comment %p/%p to variable...\n", |
| 1892 |
comment->last_child, comment->child); |
| 1893 |
#endif |
| 1894 |
mxmlNewText(comment, 0, buffer); |
| 1895 |
update_comment(variable, |
| 1896 |
mxmlNewText(description, 0, buffer)); |
| 1897 |
} |
| 1898 |
|
| 1899 |
variable = NULL; |
| 1900 |
} |
| 1901 |
else if (constant) |
| 1902 |
{ |
| 1903 |
if (strstr(buffer, "@private@")) |
| 1904 |
{ |
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
mxmlDelete(constant); |
| 1910 |
} |
| 1911 |
else |
| 1912 |
{ |
| 1913 |
description = mxmlNewElement(constant, "description"); |
| 1914 |
#ifdef DEBUG |
| 1915 |
fprintf(stderr, " adding comment %p/%p to constant...\n", |
| 1916 |
comment->last_child, comment->child); |
| 1917 |
#endif |
| 1918 |
mxmlNewText(comment, 0, buffer); |
| 1919 |
update_comment(constant, |
| 1920 |
mxmlNewText(description, 0, buffer)); |
| 1921 |
} |
| 1922 |
|
| 1923 |
constant = NULL; |
| 1924 |
} |
| 1925 |
else if (typedefnode) |
| 1926 |
{ |
| 1927 |
if (strstr(buffer, "@private@")) |
| 1928 |
{ |
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
mxmlDelete(typedefnode); |
| 1934 |
|
| 1935 |
if (structclass) |
| 1936 |
{ |
| 1937 |
mxmlDelete(structclass); |
| 1938 |
structclass = NULL; |
| 1939 |
} |
| 1940 |
|
| 1941 |
if (enumeration) |
| 1942 |
{ |
| 1943 |
mxmlDelete(enumeration); |
| 1944 |
enumeration = NULL; |
| 1945 |
} |
| 1946 |
} |
| 1947 |
else |
| 1948 |
{ |
| 1949 |
description = mxmlNewElement(typedefnode, "description"); |
| 1950 |
#ifdef DEBUG |
| 1951 |
fprintf(stderr, |
| 1952 |
" adding comment %p/%p to typedef %s...\n", |
| 1953 |
comment->last_child, comment->child, |
| 1954 |
mxmlElementGetAttr(typedefnode, "name")); |
| 1955 |
#endif |
| 1956 |
mxmlNewText(comment, 0, buffer); |
| 1957 |
update_comment(typedefnode, |
| 1958 |
mxmlNewText(description, 0, buffer)); |
| 1959 |
|
| 1960 |
if (structclass) |
| 1961 |
{ |
| 1962 |
description = mxmlNewElement(structclass, "description"); |
| 1963 |
update_comment(structclass, |
| 1964 |
mxmlNewText(description, 0, buffer)); |
| 1965 |
} |
| 1966 |
else if (enumeration) |
| 1967 |
{ |
| 1968 |
description = mxmlNewElement(enumeration, "description"); |
| 1969 |
update_comment(enumeration, |
| 1970 |
mxmlNewText(description, 0, buffer)); |
| 1971 |
} |
| 1972 |
} |
| 1973 |
|
| 1974 |
typedefnode = NULL; |
| 1975 |
} |
| 1976 |
else if (strcmp(tree->value.element.name, "mxmldoc") && |
| 1977 |
!mxmlFindElement(tree, tree, "description", |
| 1978 |
NULL, NULL, MXML_DESCEND_FIRST)) |
| 1979 |
{ |
| 1980 |
description = mxmlNewElement(tree, "description"); |
| 1981 |
#ifdef DEBUG |
| 1982 |
fprintf(stderr, " adding comment %p/%p to parent...\n", |
| 1983 |
comment->last_child, comment->child); |
| 1984 |
#endif |
| 1985 |
mxmlNewText(comment, 0, buffer); |
| 1986 |
update_comment(tree, |
| 1987 |
mxmlNewText(description, 0, buffer)); |
| 1988 |
} |
| 1989 |
else |
| 1990 |
mxmlNewText(comment, 0, buffer); |
| 1991 |
|
| 1992 |
#ifdef DEBUG |
| 1993 |
fprintf(stderr, "C comment: <<<< %s >>>\n", buffer); |
| 1994 |
#endif |
| 1995 |
|
| 1996 |
state = STATE_NONE; |
| 1997 |
break; |
| 1998 |
} |
| 1999 |
|
| 2000 |
default : |
| 2001 |
if (ch == ' ' && bufptr == buffer) |
| 2002 |
break; |
| 2003 |
|
| 2004 |
if (bufptr < (buffer + sizeof(buffer) - 1)) |
| 2005 |
*bufptr++ = ch; |
| 2006 |
break; |
| 2007 |
} |
| 2008 |
break; |
| 2009 |
|
| 2010 |
case STATE_CXX_COMMENT : |
| 2011 |
if (ch == '\n') |
| 2012 |
{ |
| 2013 |
state = STATE_NONE; |
| 2014 |
*bufptr = '\0'; |
| 2015 |
|
| 2016 |
if (comment->child != comment->last_child) |
| 2017 |
{ |
| 2018 |
#ifdef DEBUG |
| 2019 |
fprintf(stderr, " removing comment %p(%20.20s), last comment %p(%20.20s)...\n", |
| 2020 |
comment->child, |
| 2021 |
comment->child ? comment->child->value.text.string : "", |
| 2022 |
comment->last_child, |
| 2023 |
comment->last_child ? comment->last_child->value.text.string : ""); |
| 2024 |
#endif |
| 2025 |
mxmlDelete(comment->child); |
| 2026 |
#ifdef DEBUG |
| 2027 |
fprintf(stderr, " new comment %p, last comment %p...\n", |
| 2028 |
comment->child, comment->last_child); |
| 2029 |
#endif |
| 2030 |
} |
| 2031 |
|
| 2032 |
if (variable) |
| 2033 |
{ |
| 2034 |
if (strstr(buffer, "@private@")) |
| 2035 |
{ |
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
mxmlDelete(variable); |
| 2041 |
} |
| 2042 |
else |
| 2043 |
{ |
| 2044 |
description = mxmlNewElement(variable, "description"); |
| 2045 |
#ifdef DEBUG |
| 2046 |
fprintf(stderr, " adding comment %p/%p to variable...\n", |
| 2047 |
comment->last_child, comment->child); |
| 2048 |
#endif |
| 2049 |
mxmlNewText(comment, 0, buffer); |
| 2050 |
update_comment(variable, |
| 2051 |
mxmlNewText(description, 0, buffer)); |
| 2052 |
} |
| 2053 |
|
| 2054 |
variable = NULL; |
| 2055 |
} |
| 2056 |
else if (constant) |
| 2057 |
{ |
| 2058 |
if (strstr(buffer, "@private@")) |
| 2059 |
{ |
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
mxmlDelete(constant); |
| 2065 |
} |
| 2066 |
else |
| 2067 |
{ |
| 2068 |
description = mxmlNewElement(constant, "description"); |
| 2069 |
#ifdef DEBUG |
| 2070 |
fprintf(stderr, " adding comment %p/%p to constant...\n", |
| 2071 |
comment->last_child, comment->child); |
| 2072 |
#endif |
| 2073 |
mxmlNewText(comment, 0, buffer); |
| 2074 |
update_comment(constant, |
| 2075 |
mxmlNewText(description, 0, buffer)); |
| 2076 |
} |
| 2077 |
|
| 2078 |
constant = NULL; |
| 2079 |
} |
| 2080 |
else if (typedefnode) |
| 2081 |
{ |
| 2082 |
if (strstr(buffer, "@private@")) |
| 2083 |
{ |
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
mxmlDelete(typedefnode); |
| 2089 |
typedefnode = NULL; |
| 2090 |
|
| 2091 |
if (structclass) |
| 2092 |
{ |
| 2093 |
mxmlDelete(structclass); |
| 2094 |
structclass = NULL; |
| 2095 |
} |
| 2096 |
|
| 2097 |
if (enumeration) |
| 2098 |
{ |
| 2099 |
mxmlDelete(enumeration); |
| 2100 |
enumeration = NULL; |
| 2101 |
} |
| 2102 |
} |
| 2103 |
else |
| 2104 |
{ |
| 2105 |
description = mxmlNewElement(typedefnode, "description"); |
| 2106 |
#ifdef DEBUG |
| 2107 |
fprintf(stderr, " adding comment %p/%p to typedef %s...\n", |
| 2108 |
comment->last_child, comment->child, |
| 2109 |
mxmlElementGetAttr(typedefnode, "name")); |
| 2110 |
#endif |
| 2111 |
mxmlNewText(comment, 0, buffer); |
| 2112 |
update_comment(typedefnode, |
| 2113 |
mxmlNewText(description, 0, buffer)); |
| 2114 |
|
| 2115 |
if (structclass) |
| 2116 |
{ |
| 2117 |
description = mxmlNewElement(structclass, "description"); |
| 2118 |
update_comment(structclass, |
| 2119 |
mxmlNewText(description, 0, buffer)); |
| 2120 |
} |
| 2121 |
else if (enumeration) |
| 2122 |
{ |
| 2123 |
description = mxmlNewElement(enumeration, "description"); |
| 2124 |
update_comment(enumeration, |
| 2125 |
mxmlNewText(description, 0, buffer)); |
| 2126 |
} |
| 2127 |
} |
| 2128 |
} |
| 2129 |
else if (strcmp(tree->value.element.name, "mxmldoc") && |
| 2130 |
!mxmlFindElement(tree, tree, "description", |
| 2131 |
NULL, NULL, MXML_DESCEND_FIRST)) |
| 2132 |
{ |
| 2133 |
description = mxmlNewElement(tree, "description"); |
| 2134 |
#ifdef DEBUG |
| 2135 |
fprintf(stderr, " adding comment %p/%p to parent...\n", |
| 2136 |
comment->last_child, comment->child); |
| 2137 |
#endif |
| 2138 |
mxmlNewText(comment, 0, buffer); |
| 2139 |
update_comment(tree, |
| 2140 |
mxmlNewText(description, 0, buffer)); |
| 2141 |
} |
| 2142 |
else |
| 2143 |
mxmlNewText(comment, 0, buffer); |
| 2144 |
|
| 2145 |
#ifdef DEBUG |
| 2146 |
fprintf(stderr, "C++ comment: <<<< %s >>>\n", buffer); |
| 2147 |
#endif |
| 2148 |
} |
| 2149 |
else if (ch == ' ' && bufptr == buffer) |
| 2150 |
break; |
| 2151 |
else if (bufptr < (buffer + sizeof(buffer) - 1)) |
| 2152 |
*bufptr++ = ch; |
| 2153 |
break; |
| 2154 |
|
| 2155 |
case STATE_STRING : |
| 2156 |
*bufptr++ = ch; |
| 2157 |
|
| 2158 |
if (ch == '\\') |
| 2159 |
*bufptr++ = getc(fp); |
| 2160 |
else if (ch == '\"') |
| 2161 |
{ |
| 2162 |
*bufptr = '\0'; |
| 2163 |
|
| 2164 |
if (type) |
| 2165 |
mxmlNewText(type, type->child != NULL, buffer); |
| 2166 |
|
| 2167 |
state = STATE_NONE; |
| 2168 |
} |
| 2169 |
break; |
| 2170 |
|
| 2171 |
case STATE_CHARACTER : |
| 2172 |
*bufptr++ = ch; |
| 2173 |
|
| 2174 |
if (ch == '\\') |
| 2175 |
*bufptr++ = getc(fp); |
| 2176 |
else if (ch == '\'') |
| 2177 |
{ |
| 2178 |
*bufptr = '\0'; |
| 2179 |
|
| 2180 |
if (type) |
| 2181 |
mxmlNewText(type, type->child != NULL, buffer); |
| 2182 |
|
| 2183 |
state = STATE_NONE; |
| 2184 |
} |
| 2185 |
break; |
| 2186 |
|
| 2187 |
case STATE_IDENTIFIER : |
| 2188 |
if (isalnum(ch) || ch == '_' || ch == '[' || ch == ']' || |
| 2189 |
(ch == ',' && (parens > 1 || (type && !enumeration && !function))) || |
| 2190 |
ch == ':' || ch == '.' || ch == '~') |
| 2191 |
{ |
| 2192 |
if (bufptr < (buffer + sizeof(buffer) - 1)) |
| 2193 |
*bufptr++ = ch; |
| 2194 |
} |
| 2195 |
else |
| 2196 |
{ |
| 2197 |
ungetc(ch, fp); |
| 2198 |
*bufptr = '\0'; |
| 2199 |
state = STATE_NONE; |
| 2200 |
|
| 2201 |
#ifdef DEBUG |
| 2202 |
fprintf(stderr, " braces=%d, type=%p, type->child=%p, buffer=\"%s\"\n", |
| 2203 |
braces, type, type ? type->child : NULL, buffer); |
| 2204 |
#endif |
| 2205 |
|
| 2206 |
if (!braces) |
| 2207 |
{ |
| 2208 |
if (!type || !type->child) |
| 2209 |
{ |
| 2210 |
if (!strcmp(tree->value.element.name, "class")) |
| 2211 |
{ |
| 2212 |
if (!strcmp(buffer, "public") || |
| 2213 |
!strcmp(buffer, "public:")) |
| 2214 |
{ |
| 2215 |
scope = "public"; |
| 2216 |
#ifdef DEBUG |
| 2217 |
fputs(" scope = public\n", stderr); |
| 2218 |
#endif |
| 2219 |
break; |
| 2220 |
} |
| 2221 |
else if (!strcmp(buffer, "private") || |
| 2222 |
!strcmp(buffer, "private:")) |
| 2223 |
{ |
| 2224 |
scope = "private"; |
| 2225 |
#ifdef DEBUG |
| 2226 |
fputs(" scope = private\n", stderr); |
| 2227 |
#endif |
| 2228 |
break; |
| 2229 |
} |
| 2230 |
else if (!strcmp(buffer, "protected") || |
| 2231 |
!strcmp(buffer, "protected:")) |
| 2232 |
{ |
| 2233 |
scope = "protected"; |
| 2234 |
#ifdef DEBUG |
| 2235 |
fputs(" scope = protected\n", stderr); |
| 2236 |
#endif |
| 2237 |
break; |
| 2238 |
} |
| 2239 |
} |
| 2240 |
} |
| 2241 |
|
| 2242 |
if (!type) |
| 2243 |
type = mxmlNewElement(MXML_NO_PARENT, "type"); |
| 2244 |
|
| 2245 |
#ifdef DEBUG |
| 2246 |
fprintf(stderr, " function=%p (%s), type->child=%p, ch='%c', parens=%d\n", |
| 2247 |
function, |
| 2248 |
function ? mxmlElementGetAttr(function, "name") : "null", |
| 2249 |
type->child, ch, parens); |
| 2250 |
#endif |
| 2251 |
|
| 2252 |
if (!function && ch == '(') |
| 2253 |
{ |
| 2254 |
if (type->child && |
| 2255 |
!strcmp(type->child->value.text.string, "extern")) |
| 2256 |
{ |
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
mxmlDelete(type); |
| 2262 |
type = NULL; |
| 2263 |
break; |
| 2264 |
} |
| 2265 |
|
| 2266 |
if (type->child && |
| 2267 |
!strcmp(type->child->value.text.string, "static") && |
| 2268 |
!strcmp(tree->value.element.name, "mxmldoc")) |
| 2269 |
{ |
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
mxmlDelete(type); |
| 2275 |
type = NULL; |
| 2276 |
break; |
| 2277 |
} |
| 2278 |
|
| 2279 |
function = mxmlNewElement(MXML_NO_PARENT, "function"); |
| 2280 |
if ((bufptr = strchr(buffer, ':')) != NULL && bufptr[1] == ':') |
| 2281 |
{ |
| 2282 |
*bufptr = '\0'; |
| 2283 |
bufptr += 2; |
| 2284 |
|
| 2285 |
if ((fstructclass = |
| 2286 |
mxmlFindElement(tree, tree, "class", "name", buffer, |
| 2287 |
MXML_DESCEND_FIRST)) == NULL) |
| 2288 |
fstructclass = |
| 2289 |
mxmlFindElement(tree, tree, "struct", "name", buffer, |
| 2290 |
MXML_DESCEND_FIRST); |
| 2291 |
} |
| 2292 |
else |
| 2293 |
bufptr = buffer; |
| 2294 |
|
| 2295 |
mxmlElementSetAttr(function, "name", bufptr); |
| 2296 |
|
| 2297 |
if (scope) |
| 2298 |
mxmlElementSetAttr(function, "scope", scope); |
| 2299 |
|
| 2300 |
#ifdef DEBUG |
| 2301 |
fprintf(stderr, "function: %s\n", buffer); |
| 2302 |
fprintf(stderr, " scope = %s\n", scope ? scope : "(null)"); |
| 2303 |
fprintf(stderr, " comment = %p\n", comment); |
| 2304 |
fprintf(stderr, " child = (%p) %s\n", |
| 2305 |
comment->child, |
| 2306 |
comment->child ? |
| 2307 |
comment->child->value.text.string : "(null)"); |
| 2308 |
fprintf(stderr, " last_child = (%p) %s\n", |
| 2309 |
comment->last_child, |
| 2310 |
comment->last_child ? |
| 2311 |
comment->last_child->value.text.string : "(null)"); |
| 2312 |
#endif |
| 2313 |
|
| 2314 |
if (type->last_child && |
| 2315 |
strcmp(type->last_child->value.text.string, "void")) |
| 2316 |
{ |
| 2317 |
returnvalue = mxmlNewElement(function, "returnvalue"); |
| 2318 |
|
| 2319 |
mxmlAdd(returnvalue, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type); |
| 2320 |
|
| 2321 |
description = mxmlNewElement(returnvalue, "description"); |
| 2322 |
#ifdef DEBUG |
| 2323 |
fprintf(stderr, " adding comment %p/%p to returnvalue...\n", |
| 2324 |
comment->last_child, comment->child); |
| 2325 |
#endif |
| 2326 |
update_comment(returnvalue, comment->last_child); |
| 2327 |
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, |
| 2328 |
comment->last_child); |
| 2329 |
} |
| 2330 |
else |
| 2331 |
mxmlDelete(type); |
| 2332 |
|
| 2333 |
description = mxmlNewElement(function, "description"); |
| 2334 |
#ifdef DEBUG |
| 2335 |
fprintf(stderr, " adding comment %p/%p to function...\n", |
| 2336 |
comment->last_child, comment->child); |
| 2337 |
#endif |
| 2338 |
update_comment(function, comment->last_child); |
| 2339 |
mxmlAdd(description, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, |
| 2340 |
comment->last_child); |
| 2341 |
|
| 2342 |
type = NULL; |
| 2343 |
} |
| 2344 |
else if (function && ((ch == ')' && parens == 1) || ch == ',')) |
| 2345 |
{ |
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
if (strcmp(buffer, "void")) |
| 2351 |
{ |
| 2352 |
mxmlNewText(type, type->child != NULL && |
| 2353 |
type->last_child->value.text.string[0] != '(' && |
| 2354 |
type->last_child->value.text.string[0] != '*', |
| 2355 |
buffer); |
| 2356 |
|
| 2357 |
#ifdef DEBUG |
| 2358 |
fprintf(stderr, "Argument: <<<< %s >>>\n", buffer); |
| 2359 |
#endif |
| 2360 |
|
| 2361 |
variable = add_variable(function, "argument", type); |
| 2362 |
} |
| 2363 |
else |
| 2364 |
mxmlDelete(type); |
| 2365 |
|
| 2366 |
type = NULL; |
| 2367 |
} |
| 2368 |
else if (type->child && !function && (ch == ';' || ch == ',')) |
| 2369 |
{ |
| 2370 |
#ifdef DEBUG |
| 2371 |
fprintf(stderr, " got semicolon, typedefnode=%p, structclass=%p\n", |
| 2372 |
typedefnode, structclass); |
| 2373 |
#endif |
| 2374 |
|
| 2375 |
if (typedefnode || structclass) |
| 2376 |
{ |
| 2377 |
#ifdef DEBUG |
| 2378 |
fprintf(stderr, "Typedef/struct/class: <<<< %s >>>>\n", buffer); |
| 2379 |
#endif |
| 2380 |
|
| 2381 |
if (typedefnode) |
| 2382 |
{ |
| 2383 |
mxmlElementSetAttr(typedefnode, "name", buffer); |
| 2384 |
|
| 2385 |
sort_node(tree, typedefnode); |
| 2386 |
} |
| 2387 |
|
| 2388 |
if (structclass && !mxmlElementGetAttr(structclass, "name")) |
| 2389 |
{ |
| 2390 |
#ifdef DEBUG |
| 2391 |
fprintf(stderr, "setting struct/class name to %s!\n", |
| 2392 |
type->last_child->value.text.string); |
| 2393 |
#endif |
| 2394 |
mxmlElementSetAttr(structclass, "name", buffer); |
| 2395 |
|
| 2396 |
sort_node(tree, structclass); |
| 2397 |
structclass = NULL; |
| 2398 |
} |
| 2399 |
|
| 2400 |
if (typedefnode) |
| 2401 |
mxmlAdd(typedefnode, MXML_ADD_BEFORE, MXML_ADD_TO_PARENT, |
| 2402 |
type); |
| 2403 |
else |
| 2404 |
mxmlDelete(type); |
| 2405 |
|
| 2406 |
type = NULL; |
| 2407 |
typedefnode = NULL; |
| 2408 |
} |
| 2409 |
else if (type->child && |
| 2410 |
!strcmp(type->child->value.text.string, "typedef")) |
| 2411 |
{ |
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
#ifdef DEBUG |
| 2417 |
fprintf(stderr, "Typedef: <<<< %s >>>\n", buffer); |
| 2418 |
#endif |
| 2419 |
|
| 2420 |
typedefnode = mxmlNewElement(MXML_NO_PARENT, "typedef"); |
| 2421 |
mxmlElementSetAttr(typedefnode, "name", buffer); |
| 2422 |
mxmlDelete(type->child); |
| 2423 |
|
| 2424 |
sort_node(tree, typedefnode); |
| 2425 |
|
| 2426 |
if (type->child) |
| 2427 |
type->child->value.text.whitespace = 0; |
| 2428 |
|
| 2429 |
mxmlAdd(typedefnode, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, type); |
| 2430 |
type = NULL; |
| 2431 |
} |
| 2432 |
else if (!parens) |
| 2433 |
{ |
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
if (type->child && |
| 2439 |
!strcmp(type->child->value.text.string, "static") && |
| 2440 |
!strcmp(tree->value.element.name, "mxmldoc")) |
| 2441 |
{ |
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
mxmlDelete(type); |
| 2447 |
type = NULL; |
| 2448 |
break; |
| 2449 |
} |
| 2450 |
|
| 2451 |
mxmlNewText(type, type->child != NULL && |
| 2452 |
type->last_child->value.text.string[0] != '(' && |
| 2453 |
type->last_child->value.text.string[0] != '*', |
| 2454 |
buffer); |
| 2455 |
|
| 2456 |
#ifdef DEBUG |
| 2457 |
fprintf(stderr, "Variable: <<<< %s >>>>\n", buffer); |
| 2458 |
fprintf(stderr, " scope = %s\n", scope ? scope : "(null)"); |
| 2459 |
#endif |
| 2460 |
|
| 2461 |
variable = add_variable(MXML_NO_PARENT, "variable", type); |
| 2462 |
type = NULL; |
| 2463 |
|
| 2464 |
sort_node(tree, variable); |
| 2465 |
|
| 2466 |
if (scope) |
| 2467 |
mxmlElementSetAttr(variable, "scope", scope); |
| 2468 |
} |
| 2469 |
} |
| 2470 |
else |
| 2471 |
{ |
| 2472 |
#ifdef DEBUG |
| 2473 |
fprintf(stderr, "Identifier: <<<< %s >>>>\n", buffer); |
| 2474 |
#endif |
| 2475 |
|
| 2476 |
mxmlNewText(type, type->child != NULL && |
| 2477 |
type->last_child->value.text.string[0] != '(' && |
| 2478 |
type->last_child->value.text.string[0] != '*', |
| 2479 |
buffer); |
| 2480 |
} |
| 2481 |
} |
| 2482 |
else if (enumeration && !isdigit(buffer[0] & 255)) |
| 2483 |
{ |
| 2484 |
#ifdef DEBUG |
| 2485 |
fprintf(stderr, "Constant: <<<< %s >>>\n", buffer); |
| 2486 |
#endif |
| 2487 |
|
| 2488 |
constant = mxmlNewElement(MXML_NO_PARENT, "constant"); |
| 2489 |
mxmlElementSetAttr(constant, "name", buffer); |
| 2490 |
sort_node(enumeration, constant); |
| 2491 |
} |
| 2492 |
else if (type) |
| 2493 |
{ |
| 2494 |
mxmlDelete(type); |
| 2495 |
type = NULL; |
| 2496 |
} |
| 2497 |
} |
| 2498 |
break; |
| 2499 |
} |
| 2500 |
|
| 2501 |
#if DEBUG > 1 |
| 2502 |
if (state != oldstate) |
| 2503 |
{ |
| 2504 |
fprintf(stderr, " changed states from %s to %s on receipt of character '%c'...\n", |
| 2505 |
states[oldstate], states[state], oldch); |
| 2506 |
fprintf(stderr, " variable = %p\n", variable); |
| 2507 |
if (type) |
| 2508 |
{ |
| 2509 |
fputs(" type =", stderr); |
| 2510 |
for (temp = type->child; temp; temp = temp->next) |
| 2511 |
fprintf(stderr, " \"%s\"", temp->value.text.string); |
| 2512 |
fputs("\n", stderr); |
| 2513 |
} |
| 2514 |
} |
| 2515 |
#endif |
| 2516 |
} |
| 2517 |
|
| 2518 |
mxmlDelete(comment); |
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
return (0); |
| 2525 |
} |
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
static void |
| 2533 |
sort_node(mxml_node_t *tree, |
| 2534 |
mxml_node_t *node) |
| 2535 |
{ |
| 2536 |
mxml_node_t *temp; |
| 2537 |
const char *tempname, |
| 2538 |
*nodename, |
| 2539 |
*scope; |
| 2540 |
|
| 2541 |
|
| 2542 |
#if DEBUG > 1 |
| 2543 |
fprintf(stderr, " sort_node(tree=%p, node=%p)\n", tree, node); |
| 2544 |
#endif |
| 2545 |
|
| 2546 |
|
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
if (!tree || !node || node->parent == tree) |
| 2551 |
return; |
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
if ((nodename = mxmlElementGetAttr(node, "name")) == NULL) |
| 2558 |
return; |
| 2559 |
|
| 2560 |
if (nodename[0] == '_') |
| 2561 |
return; |
| 2562 |
|
| 2563 |
#if DEBUG > 1 |
| 2564 |
fprintf(stderr, " nodename=%p (\"%s\")\n", nodename, nodename); |
| 2565 |
#endif |
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
if ((temp = mxmlFindElement(tree, tree, node->value.element.name, |
| 2572 |
"name", nodename, MXML_DESCEND_FIRST)) != NULL) |
| 2573 |
{ |
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
if ((scope = mxmlElementGetAttr(temp, "scope")) != NULL && |
| 2579 |
mxmlElementGetAttr(node, "scope") == NULL) |
| 2580 |
{ |
| 2581 |
#ifdef DEBUG |
| 2582 |
fprintf(stderr, " copying scope %s for %s\n", scope, nodename); |
| 2583 |
#endif |
| 2584 |
|
| 2585 |
mxmlElementSetAttr(node, "scope", scope); |
| 2586 |
} |
| 2587 |
|
| 2588 |
mxmlDelete(temp); |
| 2589 |
} |
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
for (temp = tree->child; temp; temp = temp->next) |
| 2596 |
{ |
| 2597 |
#if DEBUG > 1 |
| 2598 |
fprintf(stderr, " temp=%p\n", temp); |
| 2599 |
#endif |
| 2600 |
|
| 2601 |
if ((tempname = mxmlElementGetAttr(temp, "name")) == NULL) |
| 2602 |
continue; |
| 2603 |
|
| 2604 |
#if DEBUG > 1 |
| 2605 |
fprintf(stderr, " tempname=%p (\"%s\")\n", tempname, tempname); |
| 2606 |
#endif |
| 2607 |
|
| 2608 |
if (strcmp(nodename, tempname) < 0) |
| 2609 |
break; |
| 2610 |
} |
| 2611 |
|
| 2612 |
if (temp) |
| 2613 |
mxmlAdd(tree, MXML_ADD_BEFORE, temp, node); |
| 2614 |
else |
| 2615 |
mxmlAdd(tree, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, node); |
| 2616 |
} |
| 2617 |
|
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
static void |
| 2624 |
update_comment(mxml_node_t *parent, |
| 2625 |
mxml_node_t *comment) |
| 2626 |
{ |
| 2627 |
char *ptr; |
| 2628 |
|
| 2629 |
|
| 2630 |
#ifdef DEBUG |
| 2631 |
fprintf(stderr, "update_comment(parent=%p, comment=%p)\n", |
| 2632 |
parent, comment); |
| 2633 |
#endif |
| 2634 |
|
| 2635 |
|
| 2636 |
|
| 2637 |
|
| 2638 |
|
| 2639 |
if (!parent || !comment) |
| 2640 |
return; |
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
for (ptr = strstr(comment->value.text.string, "\\/"); |
| 2647 |
ptr; |
| 2648 |
ptr = strstr(ptr, "\\/")) |
| 2649 |
safe_strcpy(ptr, ptr + 1); |
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
ptr = comment->value.text.string; |
| 2656 |
|
| 2657 |
if (*ptr == '\'') |
| 2658 |
{ |
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
for (ptr ++; *ptr && *ptr != '\''; ptr ++); |
| 2664 |
|
| 2665 |
if (*ptr == '\'') |
| 2666 |
{ |
| 2667 |
ptr ++; |
| 2668 |
while (isspace(*ptr & 255)) |
| 2669 |
ptr ++; |
| 2670 |
|
| 2671 |
if (*ptr == '-') |
| 2672 |
ptr ++; |
| 2673 |
|
| 2674 |
while (isspace(*ptr & 255)) |
| 2675 |
ptr ++; |
| 2676 |
|
| 2677 |
safe_strcpy(comment->value.text.string, ptr); |
| 2678 |
} |
| 2679 |
} |
| 2680 |
else if (!strncmp(ptr, "I ", 2) || !strncmp(ptr, "O ", 2) || |
| 2681 |
!strncmp(ptr, "IO ", 3)) |
| 2682 |
{ |
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
ptr = strchr(ptr, ' '); |
| 2689 |
*ptr++ = '\0'; |
| 2690 |
|
| 2691 |
if (!strcmp(parent->value.element.name, "argument")) |
| 2692 |
mxmlElementSetAttr(parent, "direction", comment->value.text.string); |
| 2693 |
|
| 2694 |
while (isspace(*ptr & 255)) |
| 2695 |
ptr ++; |
| 2696 |
|
| 2697 |
if (*ptr == '-') |
| 2698 |
ptr ++; |
| 2699 |
|
| 2700 |
while (isspace(*ptr & 255)) |
| 2701 |
ptr ++; |
| 2702 |
|
| 2703 |
safe_strcpy(comment->value.text.string, ptr); |
| 2704 |
} |
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
for (ptr = comment->value.text.string; *ptr == '*'; ptr ++); |
| 2711 |
for (; isspace(*ptr & 255); ptr ++); |
| 2712 |
if (ptr > comment->value.text.string) |
| 2713 |
safe_strcpy(comment->value.text.string, ptr); |
| 2714 |
|
| 2715 |
for (ptr = comment->value.text.string + strlen(comment->value.text.string) - 1; |
| 2716 |
ptr > comment->value.text.string && *ptr == '*'; |
| 2717 |
ptr --) |
| 2718 |
*ptr = '\0'; |
| 2719 |
for (; ptr > comment->value.text.string && isspace(*ptr & 255); ptr --) |
| 2720 |
*ptr = '\0'; |
| 2721 |
|
| 2722 |
#ifdef DEBUG |
| 2723 |
fprintf(stderr, " updated comment = %s\n", comment->value.text.string); |
| 2724 |
#endif |
| 2725 |
} |
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
static void |
| 2733 |
usage(const char *option) |
| 2734 |
{ |
| 2735 |
if (option) |
| 2736 |
printf("mxmldoc: Bad option \"%s\"!\n\n", option); |
| 2737 |
|
| 2738 |
puts("Usage: mxmldoc [options] [filename.xml] [source files] >filename.html"); |
| 2739 |
puts("Options:"); |
| 2740 |
puts(" --css filename.css Set CSS stylesheet file"); |
| 2741 |
puts(" --docset bundleid.docset Generate documentation set"); |
| 2742 |
puts(" --docversion version Set documentation version"); |
| 2743 |
puts(" --feedname name Set documentation set feed name"); |
| 2744 |
puts(" --feedurl url Set documentation set feed URL"); |
| 2745 |
puts(" --footer footerfile Set footer file"); |
| 2746 |
puts(" --framed basename Generate framed HTML to basename*.html"); |
| 2747 |
puts(" --header headerfile Set header file"); |
| 2748 |
puts(" --intro introfile Set introduction file"); |
| 2749 |
puts(" --man name Generate man page"); |
| 2750 |
puts(" --no-output Do no generate documentation file"); |
| 2751 |
puts(" --section section Set section name"); |
| 2752 |
puts(" --title title Set documentation title"); |
| 2753 |
puts(" --tokens path Generate Xcode docset Tokens.xml file"); |
| 2754 |
puts(" --version Show mxmldoc/Mini-XML version"); |
| 2755 |
|
| 2756 |
exit(1); |
| 2757 |
} |
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
static void |
| 2765 |
write_description( |
| 2766 |
FILE *out, |
| 2767 |
mxml_node_t *description, |
| 2768 |
const char *element, |
| 2769 |
int summary) |
| 2770 |
{ |
| 2771 |
char text[10240], |
| 2772 |
*start, |
| 2773 |
*ptr; |
| 2774 |
int col; |
| 2775 |
|
| 2776 |
|
| 2777 |
if (!description) |
| 2778 |
return; |
| 2779 |
|
| 2780 |
get_text(description, text, sizeof(text)); |
| 2781 |
|
| 2782 |
ptr = strstr(text, "\n\n"); |
| 2783 |
|
| 2784 |
if (summary) |
| 2785 |
{ |
| 2786 |
if (ptr) |
| 2787 |
*ptr = '\0'; |
| 2788 |
|
| 2789 |
ptr = text; |
| 2790 |
} |
| 2791 |
else if (!ptr || !ptr[2]) |
| 2792 |
return; |
| 2793 |
else |
| 2794 |
ptr += 2; |
| 2795 |
|
| 2796 |
if (element && *element) |
| 2797 |
fprintf(out, "<%s class=\"%s\">", element, |
| 2798 |
summary ? "description" : "discussion"); |
| 2799 |
else if (!summary) |
| 2800 |
fputs(".PP\n", out); |
| 2801 |
|
| 2802 |
for (col = 0; *ptr; ptr ++) |
| 2803 |
{ |
| 2804 |
if (*ptr == '@' && |
| 2805 |
(!strncmp(ptr + 1, "deprecated@", 11) || |
| 2806 |
!strncmp(ptr + 1, "since ", 6))) |
| 2807 |
{ |
| 2808 |
ptr ++; |
| 2809 |
while (*ptr && *ptr != '@') |
| 2810 |
ptr ++; |
| 2811 |
|
| 2812 |
if (!*ptr) |
| 2813 |
return; |
| 2814 |
} |
| 2815 |
else if (!strncmp(ptr, "@code ", 6)) |
| 2816 |
{ |
| 2817 |
for (ptr += 6; isspace(*ptr & 255); ptr ++); |
| 2818 |
|
| 2819 |
for (start = ptr, ptr ++; *ptr && *ptr != '@'; ptr ++); |
| 2820 |
|
| 2821 |
if (*ptr) |
| 2822 |
*ptr = '\0'; |
| 2823 |
else |
| 2824 |
ptr --; |
| 2825 |
|
| 2826 |
if (element && *element) |
| 2827 |
fprintf(out, "<code>%s</code>", start); |
| 2828 |
else if (element) |
| 2829 |
fputs(start, out); |
| 2830 |
else |
| 2831 |
fprintf(out, "\\fB%s\\fR", start); |
| 2832 |
} |
| 2833 |
else if (!strncmp(ptr, "@link ", 6)) |
| 2834 |
{ |
| 2835 |
for (ptr += 6; isspace(*ptr & 255); ptr ++); |
| 2836 |
|
| 2837 |
for (start = ptr, ptr ++; *ptr && *ptr != '@'; ptr ++); |
| 2838 |
|
| 2839 |
if (*ptr) |
| 2840 |
*ptr = '\0'; |
| 2841 |
else |
| 2842 |
ptr --; |
| 2843 |
|
| 2844 |
if (element && *element) |
| 2845 |
fprintf(out, "<a href=\"#%s\"><code>%s</code></a>", start, start); |
| 2846 |
else if (element) |
| 2847 |
fputs(start, out); |
| 2848 |
else |
| 2849 |
fprintf(out, "\\fI%s\\fR", start); |
| 2850 |
} |
| 2851 |
else if (element) |
| 2852 |
{ |
| 2853 |
if (*ptr == '&') |
| 2854 |
fputs("&", out); |
| 2855 |
else if (*ptr == '<') |
| 2856 |
fputs("<", out); |
| 2857 |
else if (*ptr == '>') |
| 2858 |
fputs(">", out); |
| 2859 |
else if (*ptr == '\"') |
| 2860 |
fputs(""", out); |
| 2861 |
else if (*ptr & 128) |
| 2862 |
{ |
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
int ch; |
| 2868 |
|
| 2869 |
|
| 2870 |
ch = *ptr & 255; |
| 2871 |
|
| 2872 |
if ((ch & 0xe0) == 0xc0) |
| 2873 |
{ |
| 2874 |
ch = ((ch & 0x1f) << 6) | (ptr[1] & 0x3f); |
| 2875 |
ptr ++; |
| 2876 |
} |
| 2877 |
else if ((ch & 0xf0) == 0xe0) |
| 2878 |
{ |
| 2879 |
ch = ((((ch * 0x0f) << 6) | (ptr[1] & 0x3f)) << 6) | (ptr[2] & 0x3f); |
| 2880 |
ptr += 2; |
| 2881 |
} |
| 2882 |
|
| 2883 |
if (ch == 0xa0) |
| 2884 |
{ |
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
fputs(" ", out); |
| 2890 |
} |
| 2891 |
else |
| 2892 |
fprintf(out, "&#x%x;", ch); |
| 2893 |
} |
| 2894 |
else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@') |
| 2895 |
{ |
| 2896 |
fputs("<br>\n<br>\n", out); |
| 2897 |
ptr ++; |
| 2898 |
} |
| 2899 |
else |
| 2900 |
putc(*ptr, out); |
| 2901 |
} |
| 2902 |
else if (*ptr == '\n' && ptr[1] == '\n' && ptr[2] && ptr[2] != '@') |
| 2903 |
{ |
| 2904 |
fputs("\n.PP\n", out); |
| 2905 |
ptr ++; |
| 2906 |
} |
| 2907 |
else |
| 2908 |
{ |
| 2909 |
if (*ptr == '\\' || (*ptr == '.' && col == 0)) |
| 2910 |
putc('\\', out); |
| 2911 |
|
| 2912 |
putc(*ptr, out); |
| 2913 |
|
| 2914 |
if (*ptr == '\n') |
| 2915 |
col = 0; |
| 2916 |
else |
| 2917 |
col ++; |
| 2918 |
} |
| 2919 |
} |
| 2920 |
|
| 2921 |
if (element && *element) |
| 2922 |
fprintf(out, "</%s>\n", element); |
| 2923 |
else if (!element) |
| 2924 |
putc('\n', out); |
| 2925 |
} |
| 2926 |
|
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
static void |
| 2933 |
write_element(FILE *out, |
| 2934 |
mxml_node_t *doc, |
| 2935 |
mxml_node_t *element, |
| 2936 |
int mode) |
| 2937 |
{ |
| 2938 |
mxml_node_t *node; |
| 2939 |
|
| 2940 |
|
| 2941 |
if (!element) |
| 2942 |
return; |
| 2943 |
|
| 2944 |
for (node = element->child; |
| 2945 |
node; |
| 2946 |
node = mxmlWalkNext(node, element, MXML_NO_DESCEND)) |
| 2947 |
if (node->type == MXML_TEXT) |
| 2948 |
{ |
| 2949 |
if (node->value.text.whitespace) |
| 2950 |
putc(' ', out); |
| 2951 |
|
| 2952 |
if (mode == OUTPUT_HTML && |
| 2953 |
(mxmlFindElement(doc, doc, "class", "name", node->value.text.string, |
| 2954 |
MXML_DESCEND) || |
| 2955 |
mxmlFindElement(doc, doc, "enumeration", "name", |
| 2956 |
node->value.text.string, MXML_DESCEND) || |
| 2957 |
mxmlFindElement(doc, doc, "struct", "name", node->value.text.string, |
| 2958 |
MXML_DESCEND) || |
| 2959 |
mxmlFindElement(doc, doc, "typedef", "name", node->value.text.string, |
| 2960 |
MXML_DESCEND) || |
| 2961 |
mxmlFindElement(doc, doc, "union", "name", node->value.text.string, |
| 2962 |
MXML_DESCEND))) |
| 2963 |
{ |
| 2964 |
fputs("<a href=\"#", out); |
| 2965 |
write_string(out, node->value.text.string, mode); |
| 2966 |
fputs("\">", out); |
| 2967 |
write_string(out, node->value.text.string, mode); |
| 2968 |
fputs("</a>", out); |
| 2969 |
} |
| 2970 |
else |
| 2971 |
write_string(out, node->value.text.string, mode); |
| 2972 |
} |
| 2973 |
|
| 2974 |
if (!strcmp(element->value.element.name, "type") && |
| 2975 |
element->last_child->value.text.string[0] != '*') |
| 2976 |
putc(' ', out); |
| 2977 |
} |
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
static void |
| 2985 |
write_file(FILE *out, |
| 2986 |
const char *file) |
| 2987 |
{ |
| 2988 |
FILE *fp; |
| 2989 |
char line[8192]; |
| 2990 |
|
| 2991 |
|
| 2992 |
if ((fp = fopen(file, "r")) == NULL) |
| 2993 |
{ |
| 2994 |
fprintf(stderr, "mxmldoc: Unable to open \"%s\": %s\n", file, |
| 2995 |
strerror(errno)); |
| 2996 |
return; |
| 2997 |
} |
| 2998 |
|
| 2999 |
while (fgets(line, sizeof(line), fp)) |
| 3000 |
fputs(line, out); |
| 3001 |
|
| 3002 |
fclose(fp); |
| 3003 |
} |
| 3004 |
|
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
static void |
| 3011 |
write_function(FILE *out, |
| 3012 |
mxml_node_t *doc, |
| 3013 |
mxml_node_t *function, |
| 3014 |
int level) |
| 3015 |
{ |
| 3016 |
mxml_node_t *arg, |
| 3017 |
*adesc, |
| 3018 |
*description, |
| 3019 |
*type, |
| 3020 |
*node; |
| 3021 |
const char *name, |
| 3022 |
*defval; |
| 3023 |
char prefix; |
| 3024 |
char *sep; |
| 3025 |
|
| 3026 |
|
| 3027 |
name = mxmlElementGetAttr(function, "name"); |
| 3028 |
description = mxmlFindElement(function, function, "description", NULL, |
| 3029 |
NULL, MXML_DESCEND_FIRST); |
| 3030 |
|
| 3031 |
fprintf(out, "<h%d class=\"%s\">%s<a name=\"%s\">%s</a></h%d>\n", |
| 3032 |
level, level == 3 ? "function" : "method", |
| 3033 |
get_comment_info(description), name, name, level); |
| 3034 |
|
| 3035 |
if (description) |
| 3036 |
write_description(out, description, "p", 1); |
| 3037 |
|
| 3038 |
fputs("<p class=\"code\">\n", out); |
| 3039 |
|
| 3040 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 3041 |
NULL, MXML_DESCEND_FIRST); |
| 3042 |
|
| 3043 |
if (arg) |
| 3044 |
write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 3045 |
NULL, MXML_DESCEND_FIRST), |
| 3046 |
OUTPUT_HTML); |
| 3047 |
else |
| 3048 |
fputs("void ", out); |
| 3049 |
|
| 3050 |
fprintf(out, "%s ", name); |
| 3051 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 3052 |
MXML_DESCEND_FIRST), prefix = '('; |
| 3053 |
arg; |
| 3054 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 3055 |
MXML_NO_DESCEND), prefix = ',') |
| 3056 |
{ |
| 3057 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 3058 |
MXML_DESCEND_FIRST); |
| 3059 |
|
| 3060 |
fprintf(out, "%c<br>\n ", prefix); |
| 3061 |
if (type->child) |
| 3062 |
write_element(out, doc, type, OUTPUT_HTML); |
| 3063 |
|
| 3064 |
fputs(mxmlElementGetAttr(arg, "name"), out); |
| 3065 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 3066 |
fprintf(out, " %s", defval); |
| 3067 |
} |
| 3068 |
|
| 3069 |
if (prefix == '(') |
| 3070 |
fputs("(void);</p>\n", out); |
| 3071 |
else |
| 3072 |
{ |
| 3073 |
fprintf(out, |
| 3074 |
"<br>\n);</p>\n" |
| 3075 |
"<h%d class=\"parameters\">Parameters</h%d>\n" |
| 3076 |
"<dl>\n", level + 1, level + 1); |
| 3077 |
|
| 3078 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 3079 |
MXML_DESCEND_FIRST); |
| 3080 |
arg; |
| 3081 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 3082 |
MXML_NO_DESCEND)) |
| 3083 |
{ |
| 3084 |
fprintf(out, "<dt>%s</dt>\n", mxmlElementGetAttr(arg, "name")); |
| 3085 |
|
| 3086 |
adesc = mxmlFindElement(arg, arg, "description", NULL, NULL, |
| 3087 |
MXML_DESCEND_FIRST); |
| 3088 |
|
| 3089 |
write_description(out, adesc, "dd", 1); |
| 3090 |
write_description(out, adesc, "dd", 0); |
| 3091 |
} |
| 3092 |
|
| 3093 |
fputs("</dl>\n", out); |
| 3094 |
} |
| 3095 |
|
| 3096 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 3097 |
NULL, MXML_DESCEND_FIRST); |
| 3098 |
|
| 3099 |
if (arg) |
| 3100 |
{ |
| 3101 |
fprintf(out, "<h%d class=\"returnvalue\">Return Value</h%d>\n", level + 1, |
| 3102 |
level + 1); |
| 3103 |
|
| 3104 |
adesc = mxmlFindElement(arg, arg, "description", NULL, NULL, |
| 3105 |
MXML_DESCEND_FIRST); |
| 3106 |
|
| 3107 |
write_description(out, adesc, "p", 1); |
| 3108 |
write_description(out, adesc, "p", 0); |
| 3109 |
} |
| 3110 |
|
| 3111 |
if (description) |
| 3112 |
{ |
| 3113 |
for (node = description->child; node; node = node->next) |
| 3114 |
if (node->value.text.string && |
| 3115 |
(sep = strstr(node->value.text.string, "\n\n")) != NULL) |
| 3116 |
{ |
| 3117 |
sep += 2; |
| 3118 |
if (*sep && strncmp(sep, "@since ", 7) && |
| 3119 |
strncmp(sep, "@deprecated@", 12)) |
| 3120 |
break; |
| 3121 |
} |
| 3122 |
|
| 3123 |
if (node) |
| 3124 |
{ |
| 3125 |
fprintf(out, "<h%d class=\"discussion\">Discussion</h%d>\n", level + 1, |
| 3126 |
level + 1); |
| 3127 |
write_description(out, description, "p", 0); |
| 3128 |
} |
| 3129 |
} |
| 3130 |
} |
| 3131 |
|
| 3132 |
|
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
static void |
| 3138 |
write_html(const char *section, |
| 3139 |
const char *title, |
| 3140 |
const char *footerfile, |
| 3141 |
const char *headerfile, |
| 3142 |
const char *introfile, |
| 3143 |
const char *cssfile, |
| 3144 |
const char *framefile, |
| 3145 |
const char *docset, |
| 3146 |
const char *docversion, |
| 3147 |
const char *feedname, |
| 3148 |
const char *feedurl, |
| 3149 |
mxml_node_t *doc) |
| 3150 |
{ |
| 3151 |
FILE *out; |
| 3152 |
mxml_node_t *function, |
| 3153 |
*scut, |
| 3154 |
*arg, |
| 3155 |
*description, |
| 3156 |
*type; |
| 3157 |
const char *name, |
| 3158 |
*defval, |
| 3159 |
*basename; |
| 3160 |
char filename[1024]; |
| 3161 |
|
| 3162 |
|
| 3163 |
if (framefile) |
| 3164 |
{ |
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
if ((basename = strrchr(framefile, '/')) != NULL) |
| 3170 |
basename ++; |
| 3171 |
else |
| 3172 |
basename = framefile; |
| 3173 |
|
| 3174 |
if (strstr(basename, ".html")) |
| 3175 |
fputs("mxmldoc: Frame base name should not contain .html extension!\n", |
| 3176 |
stderr); |
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
snprintf(filename, sizeof(filename), "%s.html", framefile); |
| 3183 |
|
| 3184 |
if ((out = fopen(filename, "w")) == NULL) |
| 3185 |
{ |
| 3186 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3187 |
strerror(errno)); |
| 3188 |
return; |
| 3189 |
} |
| 3190 |
|
| 3191 |
fputs("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" " |
| 3192 |
"\"http://www.w3.org/TR/html4/frameset.dtd\">\n" |
| 3193 |
"<html>\n" |
| 3194 |
"<head>\n" |
| 3195 |
"\t<title>", out); |
| 3196 |
write_string(out, title, OUTPUT_HTML); |
| 3197 |
fputs("</title>\n", out); |
| 3198 |
|
| 3199 |
if (section) |
| 3200 |
fprintf(out, "\t<meta name=\"keywords\" content=\"%s\">\n", section); |
| 3201 |
|
| 3202 |
fputs("\t<meta http-equiv=\"Content-Type\" " |
| 3203 |
"content=\"text/html;charset=utf-8\">\n" |
| 3204 |
"\t<meta name=\"creator\" content=\"" MXML_VERSION "\">\n" |
| 3205 |
"</head>\n", out); |
| 3206 |
|
| 3207 |
fputs("<frameset cols=\"250,*\">\n", out); |
| 3208 |
fprintf(out, "<frame src=\"%s-toc.html\">\n", basename); |
| 3209 |
fprintf(out, "<frame name=\"body\" src=\"%s-body.html\">\n", basename); |
| 3210 |
fputs("</frameset>\n" |
| 3211 |
"<noframes>\n" |
| 3212 |
"<h1>", out); |
| 3213 |
write_string(out, title, OUTPUT_HTML); |
| 3214 |
fprintf(out, |
| 3215 |
"</h1>\n" |
| 3216 |
"<ul>\n" |
| 3217 |
"\t<li><a href=\"%s-toc.html\">Table of Contents</a></li>\n" |
| 3218 |
"\t<li><a href=\"%s-body.html\">Body</a></li>\n" |
| 3219 |
"</ul>\n", basename, basename); |
| 3220 |
fputs("</noframes>\n" |
| 3221 |
"</html>\n", out); |
| 3222 |
fclose(out); |
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
snprintf(filename, sizeof(filename), "%s-toc.html", framefile); |
| 3229 |
|
| 3230 |
if ((out = fopen(filename, "w")) == NULL) |
| 3231 |
{ |
| 3232 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3233 |
strerror(errno)); |
| 3234 |
return; |
| 3235 |
} |
| 3236 |
|
| 3237 |
write_html_head(out, section, title, cssfile); |
| 3238 |
|
| 3239 |
snprintf(filename, sizeof(filename), "%s-body.html", basename); |
| 3240 |
|
| 3241 |
fputs("<div class=\"contents\">\n", out); |
| 3242 |
fprintf(out, "<h1 class=\"title\"><a href=\"%s\" target=\"body\">", |
| 3243 |
filename); |
| 3244 |
write_string(out, title, OUTPUT_HTML); |
| 3245 |
fputs("</a></h1>\n", out); |
| 3246 |
|
| 3247 |
write_toc(out, doc, introfile, filename, 0); |
| 3248 |
|
| 3249 |
fputs("</div>\n" |
| 3250 |
"</body>\n" |
| 3251 |
"</html>\n", out); |
| 3252 |
fclose(out); |
| 3253 |
|
| 3254 |
|
| 3255 |
|
| 3256 |
|
| 3257 |
|
| 3258 |
snprintf(filename, sizeof(filename), "%s-body.html", framefile); |
| 3259 |
|
| 3260 |
if ((out = fopen(filename, "w")) == NULL) |
| 3261 |
{ |
| 3262 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3263 |
strerror(errno)); |
| 3264 |
return; |
| 3265 |
} |
| 3266 |
} |
| 3267 |
else if (docset) |
| 3268 |
{ |
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
#ifdef __APPLE__ |
| 3275 |
const char *id; |
| 3276 |
|
| 3277 |
|
| 3278 |
if (!access(docset, 0) && !remove_directory(docset)) |
| 3279 |
return; |
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
if (mkdir(docset, 0755)) |
| 3286 |
{ |
| 3287 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", docset, |
| 3288 |
strerror(errno)); |
| 3289 |
return; |
| 3290 |
} |
| 3291 |
|
| 3292 |
snprintf(filename, sizeof(filename), "%s/Contents", docset); |
| 3293 |
if (mkdir(filename, 0755)) |
| 3294 |
{ |
| 3295 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3296 |
strerror(errno)); |
| 3297 |
return; |
| 3298 |
} |
| 3299 |
|
| 3300 |
snprintf(filename, sizeof(filename), "%s/Contents/Resources", docset); |
| 3301 |
if (mkdir(filename, 0755)) |
| 3302 |
{ |
| 3303 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3304 |
strerror(errno)); |
| 3305 |
return; |
| 3306 |
} |
| 3307 |
|
| 3308 |
snprintf(filename, sizeof(filename), "%s/Contents/Resources/Documentation", |
| 3309 |
docset); |
| 3310 |
if (mkdir(filename, 0755)) |
| 3311 |
{ |
| 3312 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3313 |
strerror(errno)); |
| 3314 |
return; |
| 3315 |
} |
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
if ((id = strrchr(docset, '/')) != NULL) |
| 3322 |
id ++; |
| 3323 |
else |
| 3324 |
id = docset; |
| 3325 |
|
| 3326 |
snprintf(filename, sizeof(filename), "%s/Contents/Info.plist", docset); |
| 3327 |
if ((out = fopen(filename, "w")) == NULL) |
| 3328 |
{ |
| 3329 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3330 |
strerror(errno)); |
| 3331 |
return; |
| 3332 |
} |
| 3333 |
|
| 3334 |
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 3335 |
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" |
| 3336 |
"<plist version=\"1.0\">\n" |
| 3337 |
"<dict>\n" |
| 3338 |
"\t<key>CFBundleIdentifier</key>\n" |
| 3339 |
"\t<string>", out); |
| 3340 |
write_string(out, id, OUTPUT_HTML); |
| 3341 |
fputs("</string>\n" |
| 3342 |
"\t<key>CFBundleName</key>\n" |
| 3343 |
"\t<string>", out); |
| 3344 |
write_string(out, title, OUTPUT_HTML); |
| 3345 |
fputs("</string>\n" |
| 3346 |
"\t<key>CFBundleVersion</key>\n" |
| 3347 |
"\t<string>", out); |
| 3348 |
write_string(out, docversion ? docversion : "0.0", OUTPUT_HTML); |
| 3349 |
fputs("</string>\n" |
| 3350 |
"\t<key>CFBundleShortVersionString</key>\n" |
| 3351 |
"\t<string>", out); |
| 3352 |
write_string(out, docversion ? docversion : "0.0", OUTPUT_HTML); |
| 3353 |
fputs("</string>\n", out); |
| 3354 |
|
| 3355 |
if (feedname) |
| 3356 |
{ |
| 3357 |
fputs("\t<key>DocSetFeedName</key>\n" |
| 3358 |
"\t<string>", out); |
| 3359 |
write_string(out, feedname ? feedname : title, OUTPUT_HTML); |
| 3360 |
fputs("</string>\n", out); |
| 3361 |
} |
| 3362 |
|
| 3363 |
if (feedurl) |
| 3364 |
{ |
| 3365 |
fputs("\t<key>DocSetFeedURL</key>\n" |
| 3366 |
"\t<string>", out); |
| 3367 |
write_string(out, feedurl, OUTPUT_HTML); |
| 3368 |
fputs("</string>\n", out); |
| 3369 |
} |
| 3370 |
|
| 3371 |
fputs("</dict>\n" |
| 3372 |
"</plist>\n", out); |
| 3373 |
|
| 3374 |
fclose(out); |
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
snprintf(filename, sizeof(filename), "%s/Contents/Resources/Nodes.xml", |
| 3381 |
docset); |
| 3382 |
if ((out = fopen(filename, "w")) == NULL) |
| 3383 |
{ |
| 3384 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3385 |
strerror(errno)); |
| 3386 |
return; |
| 3387 |
} |
| 3388 |
|
| 3389 |
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 3390 |
"<DocSetNodes version=\"1.0\">\n" |
| 3391 |
"<TOC>\n" |
| 3392 |
"<Node id=\"0\">\n" |
| 3393 |
"<Name>", out); |
| 3394 |
write_string(out, title, OUTPUT_HTML); |
| 3395 |
fputs("</Name>\n" |
| 3396 |
"<Path>Documentation/index.html</Path>\n" |
| 3397 |
"<Subnodes>\n", out); |
| 3398 |
|
| 3399 |
write_toc(out, doc, introfile, NULL, 1); |
| 3400 |
|
| 3401 |
fputs("</Subnodes>\n" |
| 3402 |
"</Node>\n" |
| 3403 |
"</TOC>\n" |
| 3404 |
"</DocSetNodes>\n", out); |
| 3405 |
|
| 3406 |
fclose(out); |
| 3407 |
|
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
snprintf(filename, sizeof(filename), "%s/Contents/Resources/Tokens.xml", |
| 3413 |
docset); |
| 3414 |
if ((out = fopen(filename, "w")) == NULL) |
| 3415 |
{ |
| 3416 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3417 |
strerror(errno)); |
| 3418 |
return; |
| 3419 |
} |
| 3420 |
|
| 3421 |
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 3422 |
"<Tokens version=\"1.0\">\n", out); |
| 3423 |
|
| 3424 |
write_tokens(out, doc, "index.html"); |
| 3425 |
|
| 3426 |
fputs("</Tokens>\n", out); |
| 3427 |
|
| 3428 |
fclose(out); |
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
snprintf(filename, sizeof(filename), |
| 3435 |
"%s/Contents/Resources/Documentation/index.html", |
| 3436 |
docset); |
| 3437 |
if ((out = fopen(filename, "w")) == NULL) |
| 3438 |
{ |
| 3439 |
fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", filename, |
| 3440 |
strerror(errno)); |
| 3441 |
return; |
| 3442 |
} |
| 3443 |
|
| 3444 |
#else |
| 3445 |
fputs("mxmldoc: Xcode documentation sets can only be created on " |
| 3446 |
"Mac OS X.\n", stderr); |
| 3447 |
return; |
| 3448 |
#endif |
| 3449 |
} |
| 3450 |
else |
| 3451 |
out = stdout; |
| 3452 |
|
| 3453 |
|
| 3454 |
|
| 3455 |
|
| 3456 |
|
| 3457 |
write_html_head(out, section, title, cssfile); |
| 3458 |
|
| 3459 |
fputs("<div class='body'>\n", out); |
| 3460 |
|
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
if (headerfile) |
| 3466 |
{ |
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
|
| 3471 |
write_file(out, headerfile); |
| 3472 |
} |
| 3473 |
else |
| 3474 |
{ |
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
fputs("<h1 class=\"title\">", out); |
| 3480 |
write_string(out, title, OUTPUT_HTML); |
| 3481 |
fputs("</h1>\n", out); |
| 3482 |
} |
| 3483 |
|
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
if (!framefile) |
| 3489 |
write_toc(out, doc, introfile, NULL, 0); |
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
if (introfile) |
| 3496 |
write_file(out, introfile); |
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
if ((scut = find_public(doc, doc, "class")) != NULL) |
| 3503 |
{ |
| 3504 |
fputs("<h2 class=\"title\"><a name=\"CLASSES\">Classes</a></h2>\n", out); |
| 3505 |
|
| 3506 |
while (scut) |
| 3507 |
{ |
| 3508 |
write_scu(out, doc, scut); |
| 3509 |
|
| 3510 |
scut = find_public(scut, doc, "class"); |
| 3511 |
} |
| 3512 |
} |
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
|
| 3518 |
if ((function = find_public(doc, doc, "function")) != NULL) |
| 3519 |
{ |
| 3520 |
fputs("<h2 class=\"title\"><a name=\"FUNCTIONS\">Functions</a></h2>\n", out); |
| 3521 |
|
| 3522 |
while (function) |
| 3523 |
{ |
| 3524 |
write_function(out, doc, function, 3); |
| 3525 |
|
| 3526 |
function = find_public(function, doc, "function"); |
| 3527 |
} |
| 3528 |
} |
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
if ((scut = find_public(doc, doc, "typedef")) != NULL) |
| 3535 |
{ |
| 3536 |
fputs("<h2 class=\"title\"><a name=\"TYPES\">Data Types</a></h2>\n", out); |
| 3537 |
|
| 3538 |
while (scut) |
| 3539 |
{ |
| 3540 |
name = mxmlElementGetAttr(scut, "name"); |
| 3541 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 3542 |
NULL, MXML_DESCEND_FIRST); |
| 3543 |
fprintf(out, "<h3 class=\"typedef\">%s<a name=\"%s\">%s</a></h3>\n", |
| 3544 |
get_comment_info(description), name, name); |
| 3545 |
|
| 3546 |
if (description) |
| 3547 |
write_description(out, description, "p", 1); |
| 3548 |
|
| 3549 |
fputs("<p class=\"code\">\n" |
| 3550 |
"typedef ", out); |
| 3551 |
|
| 3552 |
type = mxmlFindElement(scut, scut, "type", NULL, NULL, |
| 3553 |
MXML_DESCEND_FIRST); |
| 3554 |
|
| 3555 |
for (type = type->child; type; type = type->next) |
| 3556 |
if (!strcmp(type->value.text.string, "(")) |
| 3557 |
break; |
| 3558 |
else |
| 3559 |
{ |
| 3560 |
if (type->value.text.whitespace) |
| 3561 |
putc(' ', out); |
| 3562 |
|
| 3563 |
if (mxmlFindElement(doc, doc, "class", "name", |
| 3564 |
type->value.text.string, MXML_DESCEND) || |
| 3565 |
mxmlFindElement(doc, doc, "enumeration", "name", |
| 3566 |
type->value.text.string, MXML_DESCEND) || |
| 3567 |
mxmlFindElement(doc, doc, "struct", "name", |
| 3568 |
type->value.text.string, MXML_DESCEND) || |
| 3569 |
mxmlFindElement(doc, doc, "typedef", "name", |
| 3570 |
type->value.text.string, MXML_DESCEND) || |
| 3571 |
mxmlFindElement(doc, doc, "union", "name", |
| 3572 |
type->value.text.string, MXML_DESCEND)) |
| 3573 |
{ |
| 3574 |
fputs("<a href=\"#", out); |
| 3575 |
write_string(out, type->value.text.string, OUTPUT_HTML); |
| 3576 |
fputs("\">", out); |
| 3577 |
write_string(out, type->value.text.string, OUTPUT_HTML); |
| 3578 |
fputs("</a>", out); |
| 3579 |
} |
| 3580 |
else |
| 3581 |
write_string(out, type->value.text.string, OUTPUT_HTML); |
| 3582 |
} |
| 3583 |
|
| 3584 |
if (type) |
| 3585 |
{ |
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
if (type->prev && type->prev->value.text.string[0] != '*') |
| 3591 |
putc(' ', out); |
| 3592 |
|
| 3593 |
fprintf(out, "(*%s", name); |
| 3594 |
|
| 3595 |
for (type = type->next->next; type; type = type->next) |
| 3596 |
{ |
| 3597 |
if (type->value.text.whitespace) |
| 3598 |
putc(' ', out); |
| 3599 |
|
| 3600 |
if (mxmlFindElement(doc, doc, "class", "name", |
| 3601 |
type->value.text.string, MXML_DESCEND) || |
| 3602 |
mxmlFindElement(doc, doc, "enumeration", "name", |
| 3603 |
type->value.text.string, MXML_DESCEND) || |
| 3604 |
mxmlFindElement(doc, doc, "struct", "name", |
| 3605 |
type->value.text.string, MXML_DESCEND) || |
| 3606 |
mxmlFindElement(doc, doc, "typedef", "name", |
| 3607 |
type->value.text.string, MXML_DESCEND) || |
| 3608 |
mxmlFindElement(doc, doc, "union", "name", |
| 3609 |
type->value.text.string, MXML_DESCEND)) |
| 3610 |
{ |
| 3611 |
fputs("<a href=\"#", out); |
| 3612 |
write_string(out, type->value.text.string, OUTPUT_HTML); |
| 3613 |
fputs("\">", out); |
| 3614 |
write_string(out, type->value.text.string, OUTPUT_HTML); |
| 3615 |
fputs("</a>", out); |
| 3616 |
} |
| 3617 |
else |
| 3618 |
write_string(out, type->value.text.string, OUTPUT_HTML); |
| 3619 |
} |
| 3620 |
|
| 3621 |
fputs(";\n", out); |
| 3622 |
} |
| 3623 |
else |
| 3624 |
{ |
| 3625 |
type = mxmlFindElement(scut, scut, "type", NULL, NULL, |
| 3626 |
MXML_DESCEND_FIRST); |
| 3627 |
if (type->last_child->value.text.string[0] != '*') |
| 3628 |
putc(' ', out); |
| 3629 |
|
| 3630 |
fprintf(out, "%s;\n", name); |
| 3631 |
} |
| 3632 |
|
| 3633 |
fputs("</p>\n", out); |
| 3634 |
|
| 3635 |
scut = find_public(scut, doc, "typedef"); |
| 3636 |
} |
| 3637 |
} |
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
if ((scut = find_public(doc, doc, "struct")) != NULL) |
| 3644 |
{ |
| 3645 |
fputs("<h2 class=\"title\"><a name=\"STRUCTURES\">Structures</a></h2>\n", |
| 3646 |
out); |
| 3647 |
|
| 3648 |
while (scut) |
| 3649 |
{ |
| 3650 |
write_scu(out, doc, scut); |
| 3651 |
|
| 3652 |
scut = find_public(scut, doc, "struct"); |
| 3653 |
} |
| 3654 |
} |
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
if ((scut = find_public(doc, doc, "union")) != NULL) |
| 3661 |
{ |
| 3662 |
fputs("<h2 class=\"title\"><a name=\"UNIONS\">Unions</a></h2>\n", out); |
| 3663 |
|
| 3664 |
while (scut) |
| 3665 |
{ |
| 3666 |
write_scu(out, doc, scut); |
| 3667 |
|
| 3668 |
scut = find_public(scut, doc, "union"); |
| 3669 |
} |
| 3670 |
} |
| 3671 |
|
| 3672 |
|
| 3673 |
|
| 3674 |
|
| 3675 |
|
| 3676 |
if ((arg = find_public(doc, doc, "variable")) != NULL) |
| 3677 |
{ |
| 3678 |
fputs("<h2 class=\"title\"><a name=\"VARIABLES\">Variables</a></h2>\n", |
| 3679 |
out); |
| 3680 |
|
| 3681 |
while (arg) |
| 3682 |
{ |
| 3683 |
name = mxmlElementGetAttr(arg, "name"); |
| 3684 |
description = mxmlFindElement(arg, arg, "description", NULL, |
| 3685 |
NULL, MXML_DESCEND_FIRST); |
| 3686 |
fprintf(out, "<h3 class=\"variable\">%s<a name=\"%s\">%s</a></h3>\n", |
| 3687 |
get_comment_info(description), name, name); |
| 3688 |
|
| 3689 |
if (description) |
| 3690 |
write_description(out, description, "p", 1); |
| 3691 |
|
| 3692 |
fputs("<p class=\"code\">", out); |
| 3693 |
|
| 3694 |
write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 3695 |
NULL, MXML_DESCEND_FIRST), |
| 3696 |
OUTPUT_HTML); |
| 3697 |
fputs(mxmlElementGetAttr(arg, "name"), out); |
| 3698 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 3699 |
fprintf(out, " %s", defval); |
| 3700 |
fputs(";</p>\n", out); |
| 3701 |
|
| 3702 |
arg = find_public(arg, doc, "variable"); |
| 3703 |
} |
| 3704 |
} |
| 3705 |
|
| 3706 |
|
| 3707 |
|
| 3708 |
|
| 3709 |
|
| 3710 |
if ((scut = find_public(doc, doc, "enumeration")) != NULL) |
| 3711 |
{ |
| 3712 |
fputs("<h2 class=\"title\"><a name=\"ENUMERATIONS\">Constants</a></h2>\n", |
| 3713 |
out); |
| 3714 |
|
| 3715 |
while (scut) |
| 3716 |
{ |
| 3717 |
name = mxmlElementGetAttr(scut, "name"); |
| 3718 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 3719 |
NULL, MXML_DESCEND_FIRST); |
| 3720 |
fprintf(out, "<h3 class=\"enumeration\">%s<a name=\"%s\">%s</a></h3>\n", |
| 3721 |
get_comment_info(description), name, name); |
| 3722 |
|
| 3723 |
if (description) |
| 3724 |
write_description(out, description, "p", 1); |
| 3725 |
|
| 3726 |
fputs("<h4 class=\"constants\">Constants</h4>\n" |
| 3727 |
"<dl>\n", out); |
| 3728 |
|
| 3729 |
for (arg = mxmlFindElement(scut, scut, "constant", NULL, NULL, |
| 3730 |
MXML_DESCEND_FIRST); |
| 3731 |
arg; |
| 3732 |
arg = mxmlFindElement(arg, scut, "constant", NULL, NULL, |
| 3733 |
MXML_NO_DESCEND)) |
| 3734 |
{ |
| 3735 |
description = mxmlFindElement(arg, arg, "description", NULL, |
| 3736 |
NULL, MXML_DESCEND_FIRST); |
| 3737 |
fprintf(out, "<dt>%s %s</dt>\n", |
| 3738 |
mxmlElementGetAttr(arg, "name"), get_comment_info(description)); |
| 3739 |
|
| 3740 |
write_description(out, description, "dd", 1); |
| 3741 |
write_description(out, description, "dd", 0); |
| 3742 |
} |
| 3743 |
|
| 3744 |
fputs("</dl>\n", out); |
| 3745 |
|
| 3746 |
scut = find_public(scut, doc, "enumeration"); |
| 3747 |
} |
| 3748 |
} |
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
if (footerfile) |
| 3755 |
{ |
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
|
| 3760 |
write_file(out, footerfile); |
| 3761 |
} |
| 3762 |
|
| 3763 |
fputs("</div>\n" |
| 3764 |
"</body>\n" |
| 3765 |
"</html>\n", out); |
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
if (out != stdout) |
| 3772 |
fclose(out); |
| 3773 |
|
| 3774 |
#ifdef __APPLE__ |
| 3775 |
|
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
if (docset) |
| 3780 |
{ |
| 3781 |
const char *args[4]; |
| 3782 |
pid_t pid; |
| 3783 |
int status; |
| 3784 |
|
| 3785 |
|
| 3786 |
args[0] = "/Developer/usr/bin/docsetutil"; |
| 3787 |
args[1] = "index"; |
| 3788 |
args[2] = docset; |
| 3789 |
args[3] = NULL; |
| 3790 |
|
| 3791 |
if (posix_spawn(&pid, args[0], NULL, NULL, (char **)args, environ)) |
| 3792 |
{ |
| 3793 |
fprintf(stderr, "mxmldoc: Unable to index documentation set \"%s\": %s\n", |
| 3794 |
docset, strerror(errno)); |
| 3795 |
} |
| 3796 |
else |
| 3797 |
{ |
| 3798 |
while (wait(&status) != pid); |
| 3799 |
|
| 3800 |
if (status) |
| 3801 |
{ |
| 3802 |
if (WIFEXITED(status)) |
| 3803 |
fprintf(stderr, "mxmldoc: docsetutil exited with status %d\n", |
| 3804 |
WEXITSTATUS(status)); |
| 3805 |
else |
| 3806 |
fprintf(stderr, "mxmldoc: docsetutil crashed with signal %d\n", |
| 3807 |
WTERMSIG(status)); |
| 3808 |
} |
| 3809 |
else |
| 3810 |
{ |
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
snprintf(filename, sizeof(filename), "%s/Contents/Resources/Nodes.xml", |
| 3816 |
docset); |
| 3817 |
unlink(filename); |
| 3818 |
|
| 3819 |
snprintf(filename, sizeof(filename), "%s/Contents/Resources/Tokens.xml", |
| 3820 |
docset); |
| 3821 |
unlink(filename); |
| 3822 |
} |
| 3823 |
} |
| 3824 |
} |
| 3825 |
#endif |
| 3826 |
} |
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
static void |
| 3834 |
write_html_head(FILE *out, |
| 3835 |
const char *section, |
| 3836 |
const char *title, |
| 3837 |
const char *cssfile) |
| 3838 |
{ |
| 3839 |
fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " |
| 3840 |
"\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3841 |
"<html>\n", out); |
| 3842 |
|
| 3843 |
if (section) |
| 3844 |
fprintf(out, "<!-- SECTION: %s -->\n", section); |
| 3845 |
|
| 3846 |
fputs("<head>\n" |
| 3847 |
"\t<title>", out); |
| 3848 |
write_string(out, title, OUTPUT_HTML); |
| 3849 |
fputs("\t</title>\n", out); |
| 3850 |
|
| 3851 |
if (section) |
| 3852 |
fprintf(out, "\t<meta name=\"keywords\" content=\"%s\">\n", section); |
| 3853 |
|
| 3854 |
fputs("\t<meta http-equiv=\"Content-Type\" " |
| 3855 |
"content=\"text/html;charset=utf-8\">\n" |
| 3856 |
"\t<meta name=\"creator\" content=\"" MXML_VERSION "\">\n" |
| 3857 |
"<style type=\"text/css\"><!--\n", out); |
| 3858 |
|
| 3859 |
if (cssfile) |
| 3860 |
{ |
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
write_file(out, cssfile); |
| 3866 |
} |
| 3867 |
else |
| 3868 |
{ |
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
fputs("body, p, h1, h2, h3, h4 {\n" |
| 3874 |
" font-family: \"lucida grande\", geneva, helvetica, arial, " |
| 3875 |
"sans-serif;\n" |
| 3876 |
"}\n" |
| 3877 |
"div.body h1 {\n" |
| 3878 |
" font-size: 250%;\n" |
| 3879 |
" font-weight: bold;\n" |
| 3880 |
" margin: 0;\n" |
| 3881 |
"}\n" |
| 3882 |
"div.body h2 {\n" |
| 3883 |
" font-size: 250%;\n" |
| 3884 |
" margin-top: 1.5em;\n" |
| 3885 |
"}\n" |
| 3886 |
"div.body h3 {\n" |
| 3887 |
" font-size: 150%;\n" |
| 3888 |
" margin-bottom: 0.5em;\n" |
| 3889 |
" margin-top: 1.5em;\n" |
| 3890 |
"}\n" |
| 3891 |
"div.body h4 {\n" |
| 3892 |
" font-size: 110%;\n" |
| 3893 |
" margin-bottom: 0.5em;\n" |
| 3894 |
" margin-top: 1.5em;\n" |
| 3895 |
"}\n" |
| 3896 |
"div.body h5 {\n" |
| 3897 |
" font-size: 100%;\n" |
| 3898 |
" margin-bottom: 0.5em;\n" |
| 3899 |
" margin-top: 1.5em;\n" |
| 3900 |
"}\n" |
| 3901 |
"div.contents {\n" |
| 3902 |
" background: #e8e8e8;\n" |
| 3903 |
" border: solid thin black;\n" |
| 3904 |
" padding: 10px;\n" |
| 3905 |
"}\n" |
| 3906 |
"div.contents h1 {\n" |
| 3907 |
" font-size: 110%;\n" |
| 3908 |
"}\n" |
| 3909 |
"div.contents h2 {\n" |
| 3910 |
" font-size: 100%;\n" |
| 3911 |
"}\n" |
| 3912 |
"div.contents ul.contents {\n" |
| 3913 |
" font-size: 80%;\n" |
| 3914 |
"}\n" |
| 3915 |
".class {\n" |
| 3916 |
" border-bottom: solid 2px gray;\n" |
| 3917 |
"}\n" |
| 3918 |
".constants {\n" |
| 3919 |
"}\n" |
| 3920 |
".description {\n" |
| 3921 |
" margin-top: 0.5em;\n" |
| 3922 |
"}\n" |
| 3923 |
".discussion {\n" |
| 3924 |
"}\n" |
| 3925 |
".enumeration {\n" |
| 3926 |
" border-bottom: solid 2px gray;\n" |
| 3927 |
"}\n" |
| 3928 |
".function {\n" |
| 3929 |
" border-bottom: solid 2px gray;\n" |
| 3930 |
" margin-bottom: 0;\n" |
| 3931 |
"}\n" |
| 3932 |
".members {\n" |
| 3933 |
"}\n" |
| 3934 |
".method {\n" |
| 3935 |
"}\n" |
| 3936 |
".parameters {\n" |
| 3937 |
"}\n" |
| 3938 |
".returnvalue {\n" |
| 3939 |
"}\n" |
| 3940 |
".struct {\n" |
| 3941 |
" border-bottom: solid 2px gray;\n" |
| 3942 |
"}\n" |
| 3943 |
".typedef {\n" |
| 3944 |
" border-bottom: solid 2px gray;\n" |
| 3945 |
"}\n" |
| 3946 |
".union {\n" |
| 3947 |
" border-bottom: solid 2px gray;\n" |
| 3948 |
"}\n" |
| 3949 |
".variable {\n" |
| 3950 |
"}\n" |
| 3951 |
"code, p.code, pre, ul.code li {\n" |
| 3952 |
" font-family: monaco, courier, monospace;\n" |
| 3953 |
" font-size: 90%;\n" |
| 3954 |
"}\n" |
| 3955 |
"a:link, a:visited {\n" |
| 3956 |
" text-decoration: none;\n" |
| 3957 |
"}\n" |
| 3958 |
"span.info {\n" |
| 3959 |
" background: black;\n" |
| 3960 |
" border: solid thin black;\n" |
| 3961 |
" color: white;\n" |
| 3962 |
" font-size: 80%;\n" |
| 3963 |
" font-style: italic;\n" |
| 3964 |
" font-weight: bold;\n" |
| 3965 |
" white-space: nowrap;\n" |
| 3966 |
"}\n" |
| 3967 |
"h3 span.info, h4 span.info {\n" |
| 3968 |
" float: right;\n" |
| 3969 |
" font-size: 100%;\n" |
| 3970 |
"}\n" |
| 3971 |
"ul.code, ul.contents, ul.subcontents {\n" |
| 3972 |
" list-style-type: none;\n" |
| 3973 |
" margin: 0;\n" |
| 3974 |
" padding-left: 0;\n" |
| 3975 |
"}\n" |
| 3976 |
"ul.code li {\n" |
| 3977 |
" margin: 0;\n" |
| 3978 |
"}\n" |
| 3979 |
"ul.contents > li {\n" |
| 3980 |
" margin-top: 1em;\n" |
| 3981 |
"}\n" |
| 3982 |
"ul.contents li ul.code, ul.contents li ul.subcontents {\n" |
| 3983 |
" padding-left: 2em;\n" |
| 3984 |
"}\n" |
| 3985 |
"div.body dl {\n" |
| 3986 |
" margin-top: 0;\n" |
| 3987 |
"}\n" |
| 3988 |
"div.body dt {\n" |
| 3989 |
" font-style: italic;\n" |
| 3990 |
" margin-top: 0;\n" |
| 3991 |
"}\n" |
| 3992 |
"div.body dd {\n" |
| 3993 |
" margin-bottom: 0.5em;\n" |
| 3994 |
"}\n" |
| 3995 |
"h1.title {\n" |
| 3996 |
"}\n" |
| 3997 |
"h2.title {\n" |
| 3998 |
" border-bottom: solid 2px black;\n" |
| 3999 |
"}\n" |
| 4000 |
"h3.title {\n" |
| 4001 |
" border-bottom: solid 2px black;\n" |
| 4002 |
"}\n", out); |
| 4003 |
} |
| 4004 |
|
| 4005 |
fputs("--></style>\n" |
| 4006 |
"</head>\n" |
| 4007 |
"<body>\n", out); |
| 4008 |
} |
| 4009 |
|
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
static void |
| 4016 |
write_man(const char *man_name, |
| 4017 |
const char *section, |
| 4018 |
const char *title, |
| 4019 |
const char *footerfile, |
| 4020 |
const char *headerfile, |
| 4021 |
const char *introfile, |
| 4022 |
mxml_node_t *doc) |
| 4023 |
{ |
| 4024 |
int i; |
| 4025 |
mxml_node_t *function, |
| 4026 |
*scut, |
| 4027 |
*arg, |
| 4028 |
*description, |
| 4029 |
*type; |
| 4030 |
const char *name, |
| 4031 |
*cname, |
| 4032 |
*defval, |
| 4033 |
*parent; |
| 4034 |
int inscope; |
| 4035 |
char prefix; |
| 4036 |
time_t curtime; |
| 4037 |
struct tm *curdate; |
| 4038 |
char buffer[1024]; |
| 4039 |
static const char * const scopes[] = |
| 4040 |
{ |
| 4041 |
"private", |
| 4042 |
"protected", |
| 4043 |
"public" |
| 4044 |
}; |
| 4045 |
|
| 4046 |
|
| 4047 |
|
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
curtime = time(NULL); |
| 4052 |
curdate = localtime(&curtime); |
| 4053 |
strftime(buffer, sizeof(buffer), "%x", curdate); |
| 4054 |
|
| 4055 |
printf(".TH %s %s \"%s\" \"%s\" \"%s\"\n", man_name, section ? section : "3", |
| 4056 |
title ? title : "", buffer, title ? title : ""); |
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
if (headerfile) |
| 4063 |
{ |
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
write_file(stdout, headerfile); |
| 4069 |
} |
| 4070 |
else |
| 4071 |
{ |
| 4072 |
|
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
puts(".SH NAME"); |
| 4077 |
printf("%s \\- %s\n", man_name, title ? title : man_name); |
| 4078 |
} |
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
if (introfile) |
| 4085 |
write_file(stdout, introfile); |
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
if (find_public(doc, doc, "class")) |
| 4092 |
{ |
| 4093 |
puts(".SH CLASSES"); |
| 4094 |
|
| 4095 |
for (scut = find_public(doc, doc, "class"); |
| 4096 |
scut; |
| 4097 |
scut = find_public(scut, doc, "class")) |
| 4098 |
{ |
| 4099 |
cname = mxmlElementGetAttr(scut, "name"); |
| 4100 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 4101 |
NULL, MXML_DESCEND_FIRST); |
| 4102 |
printf(".SS %s\n", cname); |
| 4103 |
|
| 4104 |
write_description(stdout, description, NULL, 1); |
| 4105 |
|
| 4106 |
printf(".PP\n" |
| 4107 |
".nf\n" |
| 4108 |
"class %s", cname); |
| 4109 |
if ((parent = mxmlElementGetAttr(scut, "parent")) != NULL) |
| 4110 |
printf(" %s", parent); |
| 4111 |
puts("\n{"); |
| 4112 |
|
| 4113 |
for (i = 0; i < 3; i ++) |
| 4114 |
{ |
| 4115 |
inscope = 0; |
| 4116 |
|
| 4117 |
for (arg = mxmlFindElement(scut, scut, "variable", "scope", scopes[i], |
| 4118 |
MXML_DESCEND_FIRST); |
| 4119 |
arg; |
| 4120 |
arg = mxmlFindElement(arg, scut, "variable", "scope", scopes[i], |
| 4121 |
MXML_NO_DESCEND)) |
| 4122 |
{ |
| 4123 |
if (!inscope) |
| 4124 |
{ |
| 4125 |
inscope = 1; |
| 4126 |
printf(" %s:\n", scopes[i]); |
| 4127 |
} |
| 4128 |
|
| 4129 |
printf(" "); |
| 4130 |
write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4131 |
NULL, MXML_DESCEND_FIRST), |
| 4132 |
OUTPUT_MAN); |
| 4133 |
printf("%s;\n", mxmlElementGetAttr(arg, "name")); |
| 4134 |
} |
| 4135 |
|
| 4136 |
for (function = mxmlFindElement(scut, scut, "function", "scope", |
| 4137 |
scopes[i], MXML_DESCEND_FIRST); |
| 4138 |
function; |
| 4139 |
function = mxmlFindElement(function, scut, "function", "scope", |
| 4140 |
scopes[i], MXML_NO_DESCEND)) |
| 4141 |
{ |
| 4142 |
if (!inscope) |
| 4143 |
{ |
| 4144 |
inscope = 1; |
| 4145 |
printf(" %s:\n", scopes[i]); |
| 4146 |
} |
| 4147 |
|
| 4148 |
name = mxmlElementGetAttr(function, "name"); |
| 4149 |
|
| 4150 |
printf(" "); |
| 4151 |
|
| 4152 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 4153 |
NULL, MXML_DESCEND_FIRST); |
| 4154 |
|
| 4155 |
if (arg) |
| 4156 |
write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4157 |
NULL, MXML_DESCEND_FIRST), |
| 4158 |
OUTPUT_MAN); |
| 4159 |
else if (strcmp(cname, name) && strcmp(cname, name + 1)) |
| 4160 |
fputs("void ", stdout); |
| 4161 |
|
| 4162 |
printf("%s", name); |
| 4163 |
|
| 4164 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 4165 |
MXML_DESCEND_FIRST), prefix = '('; |
| 4166 |
arg; |
| 4167 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 4168 |
MXML_NO_DESCEND), prefix = ',') |
| 4169 |
{ |
| 4170 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 4171 |
MXML_DESCEND_FIRST); |
| 4172 |
|
| 4173 |
putchar(prefix); |
| 4174 |
if (prefix == ',') |
| 4175 |
putchar(' '); |
| 4176 |
|
| 4177 |
if (type->child) |
| 4178 |
write_element(stdout, doc, type, OUTPUT_MAN); |
| 4179 |
fputs(mxmlElementGetAttr(arg, "name"), stdout); |
| 4180 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 4181 |
printf(" %s", defval); |
| 4182 |
} |
| 4183 |
|
| 4184 |
if (prefix == '(') |
| 4185 |
puts("(void);"); |
| 4186 |
else |
| 4187 |
puts(");"); |
| 4188 |
} |
| 4189 |
} |
| 4190 |
|
| 4191 |
puts("};\n" |
| 4192 |
".fi"); |
| 4193 |
|
| 4194 |
write_description(stdout, description, NULL, 0); |
| 4195 |
} |
| 4196 |
} |
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
if (find_public(doc, doc, "enumeration")) |
| 4203 |
{ |
| 4204 |
puts(".SH ENUMERATIONS"); |
| 4205 |
|
| 4206 |
for (scut = find_public(doc, doc, "enumeration"); |
| 4207 |
scut; |
| 4208 |
scut = find_public(scut, doc, "enumeration")) |
| 4209 |
{ |
| 4210 |
name = mxmlElementGetAttr(scut, "name"); |
| 4211 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 4212 |
NULL, MXML_DESCEND_FIRST); |
| 4213 |
printf(".SS %s\n", name); |
| 4214 |
|
| 4215 |
write_description(stdout, description, NULL, 1); |
| 4216 |
write_description(stdout, description, NULL, 0); |
| 4217 |
|
| 4218 |
for (arg = mxmlFindElement(scut, scut, "constant", NULL, NULL, |
| 4219 |
MXML_DESCEND_FIRST); |
| 4220 |
arg; |
| 4221 |
arg = mxmlFindElement(arg, scut, "constant", NULL, NULL, |
| 4222 |
MXML_NO_DESCEND)) |
| 4223 |
{ |
| 4224 |
description = mxmlFindElement(arg, arg, "description", NULL, |
| 4225 |
NULL, MXML_DESCEND_FIRST); |
| 4226 |
printf(".TP 5\n%s\n.br\n", mxmlElementGetAttr(arg, "name")); |
| 4227 |
write_description(stdout, description, NULL, 1); |
| 4228 |
} |
| 4229 |
} |
| 4230 |
} |
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
if (find_public(doc, doc, "function")) |
| 4237 |
{ |
| 4238 |
puts(".SH FUNCTIONS"); |
| 4239 |
|
| 4240 |
for (function = find_public(doc, doc, "function"); |
| 4241 |
function; |
| 4242 |
function = find_public(function, doc, "function")) |
| 4243 |
{ |
| 4244 |
name = mxmlElementGetAttr(function, "name"); |
| 4245 |
description = mxmlFindElement(function, function, "description", NULL, |
| 4246 |
NULL, MXML_DESCEND_FIRST); |
| 4247 |
printf(".SS %s\n", name); |
| 4248 |
|
| 4249 |
write_description(stdout, description, NULL, 1); |
| 4250 |
|
| 4251 |
puts(".PP\n" |
| 4252 |
".nf"); |
| 4253 |
|
| 4254 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 4255 |
NULL, MXML_DESCEND_FIRST); |
| 4256 |
|
| 4257 |
if (arg) |
| 4258 |
write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4259 |
NULL, MXML_DESCEND_FIRST), |
| 4260 |
OUTPUT_MAN); |
| 4261 |
else |
| 4262 |
fputs("void", stdout); |
| 4263 |
|
| 4264 |
printf(" %s ", name); |
| 4265 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 4266 |
MXML_DESCEND_FIRST), prefix = '('; |
| 4267 |
arg; |
| 4268 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 4269 |
MXML_NO_DESCEND), prefix = ',') |
| 4270 |
{ |
| 4271 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 4272 |
MXML_DESCEND_FIRST); |
| 4273 |
|
| 4274 |
printf("%c\n ", prefix); |
| 4275 |
if (type->child) |
| 4276 |
write_element(stdout, doc, type, OUTPUT_MAN); |
| 4277 |
fputs(mxmlElementGetAttr(arg, "name"), stdout); |
| 4278 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 4279 |
printf(" %s", defval); |
| 4280 |
} |
| 4281 |
|
| 4282 |
if (prefix == '(') |
| 4283 |
puts("(void);"); |
| 4284 |
else |
| 4285 |
puts("\n);"); |
| 4286 |
|
| 4287 |
puts(".fi"); |
| 4288 |
|
| 4289 |
write_description(stdout, description, NULL, 0); |
| 4290 |
} |
| 4291 |
} |
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
if (find_public(doc, doc, "struct")) |
| 4298 |
{ |
| 4299 |
puts(".SH STRUCTURES"); |
| 4300 |
|
| 4301 |
for (scut = find_public(doc, doc, "struct"); |
| 4302 |
scut; |
| 4303 |
scut = find_public(scut, doc, "struct")) |
| 4304 |
{ |
| 4305 |
cname = mxmlElementGetAttr(scut, "name"); |
| 4306 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 4307 |
NULL, MXML_DESCEND_FIRST); |
| 4308 |
printf(".SS %s\n", cname); |
| 4309 |
|
| 4310 |
write_description(stdout, description, NULL, 1); |
| 4311 |
|
| 4312 |
printf(".PP\n" |
| 4313 |
".nf\n" |
| 4314 |
"struct %s\n{\n", cname); |
| 4315 |
for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL, |
| 4316 |
MXML_DESCEND_FIRST); |
| 4317 |
arg; |
| 4318 |
arg = mxmlFindElement(arg, scut, "variable", NULL, NULL, |
| 4319 |
MXML_NO_DESCEND)) |
| 4320 |
{ |
| 4321 |
printf(" "); |
| 4322 |
write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4323 |
NULL, MXML_DESCEND_FIRST), |
| 4324 |
OUTPUT_MAN); |
| 4325 |
printf("%s;\n", mxmlElementGetAttr(arg, "name")); |
| 4326 |
} |
| 4327 |
|
| 4328 |
for (function = mxmlFindElement(scut, scut, "function", NULL, NULL, |
| 4329 |
MXML_DESCEND_FIRST); |
| 4330 |
function; |
| 4331 |
function = mxmlFindElement(function, scut, "function", NULL, NULL, |
| 4332 |
MXML_NO_DESCEND)) |
| 4333 |
{ |
| 4334 |
name = mxmlElementGetAttr(function, "name"); |
| 4335 |
|
| 4336 |
printf(" "); |
| 4337 |
|
| 4338 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 4339 |
NULL, MXML_DESCEND_FIRST); |
| 4340 |
|
| 4341 |
if (arg) |
| 4342 |
write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4343 |
NULL, MXML_DESCEND_FIRST), |
| 4344 |
OUTPUT_MAN); |
| 4345 |
else if (strcmp(cname, name) && strcmp(cname, name + 1)) |
| 4346 |
fputs("void ", stdout); |
| 4347 |
|
| 4348 |
fputs(name, stdout); |
| 4349 |
|
| 4350 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 4351 |
MXML_DESCEND_FIRST), prefix = '('; |
| 4352 |
arg; |
| 4353 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 4354 |
MXML_NO_DESCEND), prefix = ',') |
| 4355 |
{ |
| 4356 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 4357 |
MXML_DESCEND_FIRST); |
| 4358 |
|
| 4359 |
putchar(prefix); |
| 4360 |
if (prefix == ',') |
| 4361 |
putchar(' '); |
| 4362 |
|
| 4363 |
if (type->child) |
| 4364 |
write_element(stdout, doc, type, OUTPUT_MAN); |
| 4365 |
fputs(mxmlElementGetAttr(arg, "name"), stdout); |
| 4366 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 4367 |
printf(" %s", defval); |
| 4368 |
} |
| 4369 |
|
| 4370 |
if (prefix == '(') |
| 4371 |
puts("(void);"); |
| 4372 |
else |
| 4373 |
puts(");"); |
| 4374 |
} |
| 4375 |
|
| 4376 |
puts("};\n" |
| 4377 |
".fi"); |
| 4378 |
|
| 4379 |
write_description(stdout, description, NULL, 0); |
| 4380 |
} |
| 4381 |
} |
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
if (find_public(doc, doc, "typedef")) |
| 4388 |
{ |
| 4389 |
puts(".SH TYPES"); |
| 4390 |
|
| 4391 |
for (scut = find_public(doc, doc, "typedef"); |
| 4392 |
scut; |
| 4393 |
scut = find_public(scut, doc, "typedef")) |
| 4394 |
{ |
| 4395 |
name = mxmlElementGetAttr(scut, "name"); |
| 4396 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 4397 |
NULL, MXML_DESCEND_FIRST); |
| 4398 |
printf(".SS %s\n", name); |
| 4399 |
|
| 4400 |
write_description(stdout, description, NULL, 1); |
| 4401 |
|
| 4402 |
fputs(".PP\n" |
| 4403 |
".nf\n" |
| 4404 |
"typedef ", stdout); |
| 4405 |
|
| 4406 |
type = mxmlFindElement(scut, scut, "type", NULL, NULL, |
| 4407 |
MXML_DESCEND_FIRST); |
| 4408 |
|
| 4409 |
for (type = type->child; type; type = type->next) |
| 4410 |
if (!strcmp(type->value.text.string, "(")) |
| 4411 |
break; |
| 4412 |
else |
| 4413 |
{ |
| 4414 |
if (type->value.text.whitespace) |
| 4415 |
putchar(' '); |
| 4416 |
|
| 4417 |
write_string(stdout, type->value.text.string, OUTPUT_MAN); |
| 4418 |
} |
| 4419 |
|
| 4420 |
if (type) |
| 4421 |
{ |
| 4422 |
|
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
printf(" (*%s", name); |
| 4427 |
|
| 4428 |
for (type = type->next->next; type; type = type->next) |
| 4429 |
{ |
| 4430 |
if (type->value.text.whitespace) |
| 4431 |
putchar(' '); |
| 4432 |
|
| 4433 |
write_string(stdout, type->value.text.string, OUTPUT_MAN); |
| 4434 |
} |
| 4435 |
|
| 4436 |
puts(";"); |
| 4437 |
} |
| 4438 |
else |
| 4439 |
printf(" %s;\n", name); |
| 4440 |
|
| 4441 |
puts(".fi"); |
| 4442 |
|
| 4443 |
write_description(stdout, description, NULL, 0); |
| 4444 |
} |
| 4445 |
} |
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
if (find_public(doc, doc, "union")) |
| 4452 |
{ |
| 4453 |
puts(".SH UNIONS"); |
| 4454 |
|
| 4455 |
for (scut = find_public(doc, doc, "union"); |
| 4456 |
scut; |
| 4457 |
scut = find_public(scut, doc, "union")) |
| 4458 |
{ |
| 4459 |
name = mxmlElementGetAttr(scut, "name"); |
| 4460 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 4461 |
NULL, MXML_DESCEND_FIRST); |
| 4462 |
printf(".SS %s\n", name); |
| 4463 |
|
| 4464 |
write_description(stdout, description, NULL, 1); |
| 4465 |
|
| 4466 |
printf(".PP\n" |
| 4467 |
".nf\n" |
| 4468 |
"union %s\n{\n", name); |
| 4469 |
for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL, |
| 4470 |
MXML_DESCEND_FIRST); |
| 4471 |
arg; |
| 4472 |
arg = mxmlFindElement(arg, scut, "variable", NULL, NULL, |
| 4473 |
MXML_NO_DESCEND)) |
| 4474 |
{ |
| 4475 |
printf(" "); |
| 4476 |
write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4477 |
NULL, MXML_DESCEND_FIRST), |
| 4478 |
OUTPUT_MAN); |
| 4479 |
printf("%s;\n", mxmlElementGetAttr(arg, "name")); |
| 4480 |
} |
| 4481 |
|
| 4482 |
puts("};\n" |
| 4483 |
".fi"); |
| 4484 |
|
| 4485 |
write_description(stdout, description, NULL, 0); |
| 4486 |
} |
| 4487 |
} |
| 4488 |
|
| 4489 |
|
| 4490 |
|
| 4491 |
|
| 4492 |
|
| 4493 |
if (find_public(doc, doc, "variable")) |
| 4494 |
{ |
| 4495 |
puts(".SH VARIABLES"); |
| 4496 |
|
| 4497 |
for (arg = find_public(doc, doc, "variable"); |
| 4498 |
arg; |
| 4499 |
arg = find_public(arg, doc, "variable")) |
| 4500 |
{ |
| 4501 |
name = mxmlElementGetAttr(arg, "name"); |
| 4502 |
description = mxmlFindElement(arg, arg, "description", NULL, |
| 4503 |
NULL, MXML_DESCEND_FIRST); |
| 4504 |
printf(".SS %s\n", name); |
| 4505 |
|
| 4506 |
write_description(stdout, description, NULL, 1); |
| 4507 |
|
| 4508 |
puts(".PP\n" |
| 4509 |
".nf"); |
| 4510 |
|
| 4511 |
write_element(stdout, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4512 |
NULL, MXML_DESCEND_FIRST), |
| 4513 |
OUTPUT_MAN); |
| 4514 |
fputs(mxmlElementGetAttr(arg, "name"), stdout); |
| 4515 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 4516 |
printf(" %s", defval); |
| 4517 |
puts(";\n" |
| 4518 |
".fi"); |
| 4519 |
|
| 4520 |
write_description(stdout, description, NULL, 0); |
| 4521 |
} |
| 4522 |
} |
| 4523 |
|
| 4524 |
if (footerfile) |
| 4525 |
{ |
| 4526 |
|
| 4527 |
|
| 4528 |
|
| 4529 |
|
| 4530 |
write_file(stdout, footerfile); |
| 4531 |
} |
| 4532 |
} |
| 4533 |
|
| 4534 |
|
| 4535 |
|
| 4536 |
|
| 4537 |
|
| 4538 |
|
| 4539 |
static void |
| 4540 |
write_scu(FILE *out, |
| 4541 |
mxml_node_t *doc, |
| 4542 |
mxml_node_t *scut) |
| 4543 |
{ |
| 4544 |
int i; |
| 4545 |
mxml_node_t *function, |
| 4546 |
*arg, |
| 4547 |
*description, |
| 4548 |
*type; |
| 4549 |
const char *name, |
| 4550 |
*cname, |
| 4551 |
*defval, |
| 4552 |
*parent, |
| 4553 |
*scope; |
| 4554 |
int inscope, |
| 4555 |
maxscope; |
| 4556 |
char prefix; |
| 4557 |
static const char * const scopes[] = |
| 4558 |
{ |
| 4559 |
"private", |
| 4560 |
"protected", |
| 4561 |
"public" |
| 4562 |
}; |
| 4563 |
|
| 4564 |
|
| 4565 |
cname = mxmlElementGetAttr(scut, "name"); |
| 4566 |
description = mxmlFindElement(scut, scut, "description", NULL, |
| 4567 |
NULL, MXML_DESCEND_FIRST); |
| 4568 |
|
| 4569 |
fprintf(out, "<h3 class=\"%s\">%s<a name=\"%s\">%s</a></h3>\n", |
| 4570 |
scut->value.element.name, get_comment_info(description), cname, |
| 4571 |
cname); |
| 4572 |
|
| 4573 |
if (description) |
| 4574 |
write_description(out, description, "p", 1); |
| 4575 |
|
| 4576 |
fprintf(out, "<p class=\"code\">%s %s", scut->value.element.name, cname); |
| 4577 |
if ((parent = mxmlElementGetAttr(scut, "parent")) != NULL) |
| 4578 |
fprintf(out, " %s", parent); |
| 4579 |
fputs(" {<br>\n", out); |
| 4580 |
|
| 4581 |
maxscope = !strcmp(scut->value.element.name, "class") ? 3 : 1; |
| 4582 |
|
| 4583 |
for (i = 0; i < maxscope; i ++) |
| 4584 |
{ |
| 4585 |
inscope = maxscope == 1; |
| 4586 |
|
| 4587 |
for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL, |
| 4588 |
MXML_DESCEND_FIRST); |
| 4589 |
arg; |
| 4590 |
arg = mxmlFindElement(arg, scut, "variable", NULL, NULL, |
| 4591 |
MXML_NO_DESCEND)) |
| 4592 |
{ |
| 4593 |
if (maxscope > 1 && |
| 4594 |
((scope = mxmlElementGetAttr(arg, "scope")) == NULL || |
| 4595 |
strcmp(scope, scopes[i]))) |
| 4596 |
continue; |
| 4597 |
|
| 4598 |
if (!inscope) |
| 4599 |
{ |
| 4600 |
inscope = 1; |
| 4601 |
fprintf(out, " %s:<br>\n", scopes[i]); |
| 4602 |
} |
| 4603 |
|
| 4604 |
fputs(" ", out); |
| 4605 |
write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4606 |
NULL, MXML_DESCEND_FIRST), |
| 4607 |
OUTPUT_HTML); |
| 4608 |
fprintf(out, "%s;<br>\n", mxmlElementGetAttr(arg, "name")); |
| 4609 |
} |
| 4610 |
|
| 4611 |
for (function = mxmlFindElement(scut, scut, "function", NULL, NULL, |
| 4612 |
MXML_DESCEND_FIRST); |
| 4613 |
function; |
| 4614 |
function = mxmlFindElement(function, scut, "function", NULL, NULL, |
| 4615 |
MXML_NO_DESCEND)) |
| 4616 |
{ |
| 4617 |
if (maxscope > 1 && |
| 4618 |
((scope = mxmlElementGetAttr(arg, "scope")) == NULL || |
| 4619 |
strcmp(scope, scopes[i]))) |
| 4620 |
continue; |
| 4621 |
|
| 4622 |
if (!inscope) |
| 4623 |
{ |
| 4624 |
inscope = 1; |
| 4625 |
fprintf(out, " %s:<br>\n", scopes[i]); |
| 4626 |
} |
| 4627 |
|
| 4628 |
name = mxmlElementGetAttr(function, "name"); |
| 4629 |
|
| 4630 |
fputs(" ", out); |
| 4631 |
|
| 4632 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 4633 |
NULL, MXML_DESCEND_FIRST); |
| 4634 |
|
| 4635 |
if (arg) |
| 4636 |
write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 4637 |
NULL, MXML_DESCEND_FIRST), |
| 4638 |
OUTPUT_HTML); |
| 4639 |
else if (strcmp(cname, name) && strcmp(cname, name + 1)) |
| 4640 |
fputs("void ", out); |
| 4641 |
|
| 4642 |
fprintf(out, "<a href=\"#%s.%s\">%s</a>", cname, name, name); |
| 4643 |
|
| 4644 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 4645 |
MXML_DESCEND_FIRST), prefix = '('; |
| 4646 |
arg; |
| 4647 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 4648 |
MXML_NO_DESCEND), prefix = ',') |
| 4649 |
{ |
| 4650 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 4651 |
MXML_DESCEND_FIRST); |
| 4652 |
|
| 4653 |
putc(prefix, out); |
| 4654 |
if (prefix == ',') |
| 4655 |
putc(' ', out); |
| 4656 |
|
| 4657 |
if (type->child) |
| 4658 |
write_element(out, doc, type, OUTPUT_HTML); |
| 4659 |
|
| 4660 |
fputs(mxmlElementGetAttr(arg, "name"), out); |
| 4661 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 4662 |
fprintf(out, " %s", defval); |
| 4663 |
} |
| 4664 |
|
| 4665 |
if (prefix == '(') |
| 4666 |
fputs("(void);<br>\n", out); |
| 4667 |
else |
| 4668 |
fputs(");<br>\n", out); |
| 4669 |
} |
| 4670 |
} |
| 4671 |
|
| 4672 |
fputs("};</p>\n" |
| 4673 |
"<h4 class=\"members\">Members</h4>\n" |
| 4674 |
"<dl>\n", out); |
| 4675 |
|
| 4676 |
for (arg = mxmlFindElement(scut, scut, "variable", NULL, NULL, |
| 4677 |
MXML_DESCEND_FIRST); |
| 4678 |
arg; |
| 4679 |
arg = mxmlFindElement(arg, scut, "variable", NULL, NULL, |
| 4680 |
MXML_NO_DESCEND)) |
| 4681 |
{ |
| 4682 |
description = mxmlFindElement(arg, arg, "description", NULL, |
| 4683 |
NULL, MXML_DESCEND_FIRST); |
| 4684 |
|
| 4685 |
fprintf(out, "<dt>%s %s</dt>\n", |
| 4686 |
mxmlElementGetAttr(arg, "name"), get_comment_info(description)); |
| 4687 |
|
| 4688 |
write_description(out, description, "dd", 1); |
| 4689 |
write_description(out, description, "dd", 0); |
| 4690 |
} |
| 4691 |
|
| 4692 |
fputs("</dl>\n", out); |
| 4693 |
|
| 4694 |
for (function = mxmlFindElement(scut, scut, "function", NULL, NULL, |
| 4695 |
MXML_DESCEND_FIRST); |
| 4696 |
function; |
| 4697 |
function = mxmlFindElement(function, scut, "function", NULL, NULL, |
| 4698 |
MXML_NO_DESCEND)) |
| 4699 |
{ |
| 4700 |
write_function(out, doc, function, 4); |
| 4701 |
} |
| 4702 |
} |
| 4703 |
|
| 4704 |
|
| 4705 |
|
| 4706 |
|
| 4707 |
|
| 4708 |
|
| 4709 |
static void |
| 4710 |
write_string(FILE *out, |
| 4711 |
const char *s, |
| 4712 |
int mode) |
| 4713 |
{ |
| 4714 |
switch (mode) |
| 4715 |
{ |
| 4716 |
case OUTPUT_HTML : |
| 4717 |
case OUTPUT_XML : |
| 4718 |
while (*s) |
| 4719 |
{ |
| 4720 |
if (*s == '&') |
| 4721 |
fputs("&", out); |
| 4722 |
else if (*s == '<') |
| 4723 |
fputs("<", out); |
| 4724 |
else if (*s == '>') |
| 4725 |
fputs(">", out); |
| 4726 |
else if (*s == '\"') |
| 4727 |
fputs(""", out); |
| 4728 |
else if (*s & 128) |
| 4729 |
{ |
| 4730 |
|
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
int ch; |
| 4735 |
|
| 4736 |
|
| 4737 |
ch = *s & 255; |
| 4738 |
|
| 4739 |
if ((ch & 0xe0) == 0xc0) |
| 4740 |
{ |
| 4741 |
ch = ((ch & 0x1f) << 6) | (s[1] & 0x3f); |
| 4742 |
s ++; |
| 4743 |
} |
| 4744 |
else if ((ch & 0xf0) == 0xe0) |
| 4745 |
{ |
| 4746 |
ch = ((((ch * 0x0f) << 6) | (s[1] & 0x3f)) << 6) | (s[2] & 0x3f); |
| 4747 |
s += 2; |
| 4748 |
} |
| 4749 |
|
| 4750 |
if (ch == 0xa0) |
| 4751 |
{ |
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
|
| 4756 |
fputs(" ", out); |
| 4757 |
} |
| 4758 |
else |
| 4759 |
fprintf(out, "&#x%x;", ch); |
| 4760 |
} |
| 4761 |
else |
| 4762 |
putc(*s, out); |
| 4763 |
|
| 4764 |
s ++; |
| 4765 |
} |
| 4766 |
break; |
| 4767 |
|
| 4768 |
case OUTPUT_MAN : |
| 4769 |
while (*s) |
| 4770 |
{ |
| 4771 |
if (*s == '\\' || *s == '-') |
| 4772 |
putc('\\', out); |
| 4773 |
|
| 4774 |
putc(*s++, out); |
| 4775 |
} |
| 4776 |
break; |
| 4777 |
} |
| 4778 |
} |
| 4779 |
|
| 4780 |
|
| 4781 |
|
| 4782 |
|
| 4783 |
|
| 4784 |
|
| 4785 |
static void |
| 4786 |
write_toc(FILE *out, |
| 4787 |
mxml_node_t *doc, |
| 4788 |
const char *introfile, |
| 4789 |
const char *target, |
| 4790 |
int xml) |
| 4791 |
{ |
| 4792 |
FILE *fp; |
| 4793 |
mxml_node_t *function, |
| 4794 |
*scut, |
| 4795 |
*arg, |
| 4796 |
*description; |
| 4797 |
const char *name, |
| 4798 |
*targetattr; |
| 4799 |
int xmlid = 1; |
| 4800 |
|
| 4801 |
|
| 4802 |
|
| 4803 |
|
| 4804 |
|
| 4805 |
|
| 4806 |
|
| 4807 |
if (target) |
| 4808 |
targetattr = " target=\"body\""; |
| 4809 |
else |
| 4810 |
targetattr = ""; |
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
|
| 4815 |
|
| 4816 |
|
| 4817 |
if (!xml) |
| 4818 |
fputs("<h2 class=\"title\">Contents</h2>\n" |
| 4819 |
"<ul class=\"contents\">\n", out); |
| 4820 |
|
| 4821 |
if (introfile && (fp = fopen(introfile, "r")) != NULL) |
| 4822 |
{ |
| 4823 |
char line[8192], |
| 4824 |
*ptr, |
| 4825 |
*end, |
| 4826 |
*anchor, |
| 4827 |
quote, |
| 4828 |
level = '2', |
| 4829 |
newlevel; |
| 4830 |
int inelement; |
| 4831 |
|
| 4832 |
|
| 4833 |
while (fgets(line, sizeof(line), fp)) |
| 4834 |
{ |
| 4835 |
|
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
if ((ptr = strstr(line, "<h")) == NULL && |
| 4840 |
(ptr = strstr(line, "<H")) == NULL) |
| 4841 |
continue; |
| 4842 |
|
| 4843 |
if (ptr[2] != '2' && ptr[2] != '3') |
| 4844 |
continue; |
| 4845 |
|
| 4846 |
newlevel = ptr[2]; |
| 4847 |
|
| 4848 |
|
| 4849 |
|
| 4850 |
|
| 4851 |
|
| 4852 |
while (!strstr(line, "</h") && !strstr(line, "</H")) |
| 4853 |
{ |
| 4854 |
end = line + strlen(line); |
| 4855 |
|
| 4856 |
if (end == (line + sizeof(line) - 1) || |
| 4857 |
!fgets(end, (int)(sizeof(line) - (end - line)), fp)) |
| 4858 |
break; |
| 4859 |
} |
| 4860 |
|
| 4861 |
|
| 4862 |
|
| 4863 |
|
| 4864 |
|
| 4865 |
for (ptr = line; *ptr; ptr ++) |
| 4866 |
if (isspace(*ptr & 255)) |
| 4867 |
*ptr = ' '; |
| 4868 |
|
| 4869 |
|
| 4870 |
|
| 4871 |
|
| 4872 |
|
| 4873 |
for (ptr = strchr(line, '<'); ptr; ptr = strchr(ptr + 1, '<')) |
| 4874 |
if (!strncmp(ptr, "<A NAME=", 8) || !strncmp(ptr, "<a name=", 8)) |
| 4875 |
break; |
| 4876 |
|
| 4877 |
if (!ptr) |
| 4878 |
continue; |
| 4879 |
|
| 4880 |
ptr += 8; |
| 4881 |
inelement = 1; |
| 4882 |
|
| 4883 |
if (*ptr == '\'' || *ptr == '\"') |
| 4884 |
{ |
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
quote = *ptr++; |
| 4890 |
anchor = ptr; |
| 4891 |
|
| 4892 |
while (*ptr && *ptr != quote) |
| 4893 |
ptr ++; |
| 4894 |
|
| 4895 |
if (!*ptr) |
| 4896 |
continue; |
| 4897 |
|
| 4898 |
*ptr++ = '\0'; |
| 4899 |
} |
| 4900 |
else |
| 4901 |
{ |
| 4902 |
|
| 4903 |
|
| 4904 |
|
| 4905 |
|
| 4906 |
anchor = ptr; |
| 4907 |
|
| 4908 |
while (*ptr && *ptr != '>' && !isspace(*ptr & 255)) |
| 4909 |
ptr ++; |
| 4910 |
|
| 4911 |
if (!*ptr) |
| 4912 |
continue; |
| 4913 |
|
| 4914 |
if (*ptr == '>') |
| 4915 |
inelement = 0; |
| 4916 |
|
| 4917 |
*ptr++ = '\0'; |
| 4918 |
} |
| 4919 |
|
| 4920 |
|
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
if (xml) |
| 4925 |
{ |
| 4926 |
if (newlevel < level) |
| 4927 |
fputs("</Node>\n" |
| 4928 |
"</Subnodes></Node>\n", out); |
| 4929 |
else if (newlevel > level && newlevel == '3') |
| 4930 |
fputs("<Subnodes>\n", out); |
| 4931 |
else if (xmlid > 1) |
| 4932 |
fputs("</Node>\n", out); |
| 4933 |
|
| 4934 |
level = newlevel; |
| 4935 |
|
| 4936 |
fprintf(out, "<Node id=\"%d\">\n" |
| 4937 |
"<Path>Documentation/index.html</Path>\n" |
| 4938 |
"<Anchor>%s</Anchor>\n" |
| 4939 |
"<Name>", xmlid ++, anchor); |
| 4940 |
|
| 4941 |
quote = 0; |
| 4942 |
|
| 4943 |
while (*ptr) |
| 4944 |
{ |
| 4945 |
if (inelement) |
| 4946 |
{ |
| 4947 |
if (*ptr == quote) |
| 4948 |
quote = 0; |
| 4949 |
else if (*ptr == '>') |
| 4950 |
inelement = 0; |
| 4951 |
else if (*ptr == '\'' || *ptr == '\"') |
| 4952 |
quote = *ptr; |
| 4953 |
} |
| 4954 |
else if (*ptr == '<') |
| 4955 |
{ |
| 4956 |
if (!strncmp(ptr, "</A>", 4) || !strncmp(ptr, "</a>", 4)) |
| 4957 |
break; |
| 4958 |
|
| 4959 |
inelement = 1; |
| 4960 |
} |
| 4961 |
else |
| 4962 |
putc(*ptr, out); |
| 4963 |
|
| 4964 |
ptr ++; |
| 4965 |
} |
| 4966 |
|
| 4967 |
fputs("</Name>\n", out); |
| 4968 |
} |
| 4969 |
else |
| 4970 |
{ |
| 4971 |
if (newlevel < level) |
| 4972 |
fputs("</li>\n" |
| 4973 |
"</ul></li>\n", out); |
| 4974 |
else if (newlevel > level) |
| 4975 |
fputs("<ul class=\"subcontents\">\n", out); |
| 4976 |
else if (xmlid > 1) |
| 4977 |
fputs("</li>\n", out); |
| 4978 |
|
| 4979 |
level = newlevel; |
| 4980 |
xmlid ++; |
| 4981 |
|
| 4982 |
fprintf(out, "%s<li><a href=\"%s#%s\"%s>", level > '2' ? "\t" : "", |
| 4983 |
target ? target : "", anchor, targetattr); |
| 4984 |
|
| 4985 |
quote = 0; |
| 4986 |
|
| 4987 |
while (*ptr) |
| 4988 |
{ |
| 4989 |
if (inelement) |
| 4990 |
{ |
| 4991 |
if (*ptr == quote) |
| 4992 |
quote = 0; |
| 4993 |
else if (*ptr == '>') |
| 4994 |
inelement = 0; |
| 4995 |
else if (*ptr == '\'' || *ptr == '\"') |
| 4996 |
quote = *ptr; |
| 4997 |
} |
| 4998 |
else if (*ptr == '<') |
| 4999 |
{ |
| 5000 |
if (!strncmp(ptr, "</A>", 4) || !strncmp(ptr, "</a>", 4)) |
| 5001 |
break; |
| 5002 |
|
| 5003 |
inelement = 1; |
| 5004 |
} |
| 5005 |
else |
| 5006 |
putc(*ptr, out); |
| 5007 |
|
| 5008 |
ptr ++; |
| 5009 |
} |
| 5010 |
|
| 5011 |
fputs("</a>", out); |
| 5012 |
} |
| 5013 |
} |
| 5014 |
|
| 5015 |
if (level > '1') |
| 5016 |
{ |
| 5017 |
if (xml) |
| 5018 |
{ |
| 5019 |
fputs("</Node>\n", out); |
| 5020 |
|
| 5021 |
if (level == '3') |
| 5022 |
fputs("</Subnodes></Node>\n", out); |
| 5023 |
} |
| 5024 |
else |
| 5025 |
{ |
| 5026 |
fputs("</li>\n", out); |
| 5027 |
|
| 5028 |
if (level == '3') |
| 5029 |
fputs("</ul></li>\n", out); |
| 5030 |
} |
| 5031 |
} |
| 5032 |
|
| 5033 |
fclose(fp); |
| 5034 |
} |
| 5035 |
|
| 5036 |
|
| 5037 |
|
| 5038 |
|
| 5039 |
|
| 5040 |
if ((scut = find_public(doc, doc, "class")) != NULL) |
| 5041 |
{ |
| 5042 |
if (xml) |
| 5043 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5044 |
"<Path>Documentation/index.html</Path>\n" |
| 5045 |
"<Anchor>CLASSES</Anchor>\n" |
| 5046 |
"<Name>Classes</Name>\n" |
| 5047 |
"<Subnodes>\n", xmlid ++); |
| 5048 |
else |
| 5049 |
fprintf(out, "<li><a href=\"%s#CLASSES\"%s>Classes</a>" |
| 5050 |
"<ul class=\"code\">\n", |
| 5051 |
target ? target : "", targetattr); |
| 5052 |
|
| 5053 |
while (scut) |
| 5054 |
{ |
| 5055 |
name = mxmlElementGetAttr(scut, "name"); |
| 5056 |
description = mxmlFindElement(scut, scut, "description", |
| 5057 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5058 |
|
| 5059 |
if (xml) |
| 5060 |
{ |
| 5061 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5062 |
"<Path>Documentation/index.html</Path>\n" |
| 5063 |
"<Anchor>%s</Anchor>\n" |
| 5064 |
"<Name>%s</Name>\n" |
| 5065 |
"</Node>\n", xmlid ++, name, name); |
| 5066 |
} |
| 5067 |
else |
| 5068 |
{ |
| 5069 |
fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"", |
| 5070 |
target ? target : "", name, targetattr); |
| 5071 |
write_description(out, description, "", 1); |
| 5072 |
fprintf(out, "\">%s</a></li>\n", name); |
| 5073 |
} |
| 5074 |
|
| 5075 |
scut = find_public(scut, doc, "class"); |
| 5076 |
} |
| 5077 |
|
| 5078 |
if (xml) |
| 5079 |
fputs("</Subnodes></Node>\n", out); |
| 5080 |
else |
| 5081 |
fputs("</ul></li>\n", out); |
| 5082 |
} |
| 5083 |
|
| 5084 |
|
| 5085 |
|
| 5086 |
|
| 5087 |
|
| 5088 |
if ((function = find_public(doc, doc, "function")) != NULL) |
| 5089 |
{ |
| 5090 |
if (xml) |
| 5091 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5092 |
"<Path>Documentation/index.html</Path>\n" |
| 5093 |
"<Anchor>FUNCTIONS</Anchor>\n" |
| 5094 |
"<Name>Functions</Name>\n" |
| 5095 |
"<Subnodes>\n", xmlid ++); |
| 5096 |
else |
| 5097 |
fprintf(out, "<li><a href=\"%s#FUNCTIONS\"%s>Functions</a>" |
| 5098 |
"<ul class=\"code\">\n", target ? target : "", targetattr); |
| 5099 |
|
| 5100 |
while (function) |
| 5101 |
{ |
| 5102 |
name = mxmlElementGetAttr(function, "name"); |
| 5103 |
description = mxmlFindElement(function, function, "description", |
| 5104 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5105 |
|
| 5106 |
if (xml) |
| 5107 |
{ |
| 5108 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5109 |
"<Path>Documentation/index.html</Path>\n" |
| 5110 |
"<Anchor>%s</Anchor>\n" |
| 5111 |
"<Name>%s</Name>\n" |
| 5112 |
"</Node>\n", xmlid ++, name, name); |
| 5113 |
} |
| 5114 |
else |
| 5115 |
{ |
| 5116 |
fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"", |
| 5117 |
target ? target : "", name, targetattr); |
| 5118 |
write_description(out, description, "", 1); |
| 5119 |
fprintf(out, "\">%s</a></li>\n", name); |
| 5120 |
} |
| 5121 |
|
| 5122 |
function = find_public(function, doc, "function"); |
| 5123 |
} |
| 5124 |
|
| 5125 |
if (xml) |
| 5126 |
fputs("</Subnodes></Node>\n", out); |
| 5127 |
else |
| 5128 |
fputs("</ul></li>\n", out); |
| 5129 |
} |
| 5130 |
|
| 5131 |
|
| 5132 |
|
| 5133 |
|
| 5134 |
|
| 5135 |
if ((scut = find_public(doc, doc, "typedef")) != NULL) |
| 5136 |
{ |
| 5137 |
if (xml) |
| 5138 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5139 |
"<Path>Documentation/index.html</Path>\n" |
| 5140 |
"<Anchor>TYPES</Anchor>\n" |
| 5141 |
"<Name>Data Types</Name>\n" |
| 5142 |
"<Subnodes>\n", xmlid ++); |
| 5143 |
else |
| 5144 |
fprintf(out, "<li><a href=\"%s#TYPES\"%s>Data Types</a>" |
| 5145 |
"<ul class=\"code\">\n", target ? target : "", targetattr); |
| 5146 |
|
| 5147 |
while (scut) |
| 5148 |
{ |
| 5149 |
name = mxmlElementGetAttr(scut, "name"); |
| 5150 |
description = mxmlFindElement(scut, scut, "description", |
| 5151 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5152 |
|
| 5153 |
if (xml) |
| 5154 |
{ |
| 5155 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5156 |
"<Path>Documentation/index.html</Path>\n" |
| 5157 |
"<Anchor>%s</Anchor>\n" |
| 5158 |
"<Name>%s</Name>\n" |
| 5159 |
"</Node>\n", xmlid ++, name, name); |
| 5160 |
} |
| 5161 |
else |
| 5162 |
{ |
| 5163 |
fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"", |
| 5164 |
target ? target : "", name, targetattr); |
| 5165 |
write_description(out, description, "", 1); |
| 5166 |
fprintf(out, "\">%s</a></li>\n", name); |
| 5167 |
} |
| 5168 |
|
| 5169 |
scut = find_public(scut, doc, "typedef"); |
| 5170 |
} |
| 5171 |
|
| 5172 |
if (xml) |
| 5173 |
fputs("</Subnodes></Node>\n", out); |
| 5174 |
else |
| 5175 |
fputs("</ul></li>\n", out); |
| 5176 |
} |
| 5177 |
|
| 5178 |
|
| 5179 |
|
| 5180 |
|
| 5181 |
|
| 5182 |
if ((scut = find_public(doc, doc, "struct")) != NULL) |
| 5183 |
{ |
| 5184 |
if (xml) |
| 5185 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5186 |
"<Path>Documentation/index.html</Path>\n" |
| 5187 |
"<Anchor>STRUCTURES</Anchor>\n" |
| 5188 |
"<Name>Structures</Name>\n" |
| 5189 |
"<Subnodes>\n", xmlid ++); |
| 5190 |
else |
| 5191 |
fprintf(out, "<li><a href=\"%s#STRUCTURES\"%s>Structures</a>" |
| 5192 |
"<ul class=\"code\">\n", target ? target : "", targetattr); |
| 5193 |
|
| 5194 |
while (scut) |
| 5195 |
{ |
| 5196 |
name = mxmlElementGetAttr(scut, "name"); |
| 5197 |
description = mxmlFindElement(scut, scut, "description", |
| 5198 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5199 |
|
| 5200 |
if (xml) |
| 5201 |
{ |
| 5202 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5203 |
"<Path>Documentation/index.html</Path>\n" |
| 5204 |
"<Anchor>%s</Anchor>\n" |
| 5205 |
"<Name>%s</Name>\n" |
| 5206 |
"</Node>\n", xmlid ++, name, name); |
| 5207 |
} |
| 5208 |
else |
| 5209 |
{ |
| 5210 |
fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"", |
| 5211 |
target ? target : "", name, targetattr); |
| 5212 |
write_description(out, description, "", 1); |
| 5213 |
fprintf(out, "\">%s</a></li>\n", name); |
| 5214 |
} |
| 5215 |
|
| 5216 |
scut = find_public(scut, doc, "struct"); |
| 5217 |
} |
| 5218 |
|
| 5219 |
if (xml) |
| 5220 |
fputs("</Subnodes></Node>\n", out); |
| 5221 |
else |
| 5222 |
fputs("</ul></li>\n", out); |
| 5223 |
} |
| 5224 |
|
| 5225 |
|
| 5226 |
|
| 5227 |
|
| 5228 |
|
| 5229 |
if ((scut = find_public(doc, doc, "union")) != NULL) |
| 5230 |
{ |
| 5231 |
if (xml) |
| 5232 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5233 |
"<Path>Documentation/index.html</Path>\n" |
| 5234 |
"<Anchor>UNIONS</Anchor>\n" |
| 5235 |
"<Name>Unions</Name>\n" |
| 5236 |
"<Subnodes>\n", xmlid ++); |
| 5237 |
else |
| 5238 |
fprintf(out, |
| 5239 |
"<li><a href=\"%s#UNIONS\"%s>Unions</a><ul class=\"code\">\n", |
| 5240 |
target ? target : "", targetattr); |
| 5241 |
|
| 5242 |
while (scut) |
| 5243 |
{ |
| 5244 |
name = mxmlElementGetAttr(scut, "name"); |
| 5245 |
description = mxmlFindElement(scut, scut, "description", |
| 5246 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5247 |
|
| 5248 |
if (xml) |
| 5249 |
{ |
| 5250 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5251 |
"<Path>Documentation/index.html</Path>\n" |
| 5252 |
"<Anchor>%s</Anchor>\n" |
| 5253 |
"<Name>%s</Name>\n" |
| 5254 |
"</Node>\n", xmlid ++, name, name); |
| 5255 |
} |
| 5256 |
else |
| 5257 |
{ |
| 5258 |
fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"", |
| 5259 |
target ? target : "", name, targetattr); |
| 5260 |
write_description(out, description, "", 1); |
| 5261 |
fprintf(out, "\">%s</a></li>\n", name); |
| 5262 |
} |
| 5263 |
|
| 5264 |
scut = find_public(scut, doc, "union"); |
| 5265 |
} |
| 5266 |
|
| 5267 |
if (xml) |
| 5268 |
fputs("</Subnodes></Node>\n", out); |
| 5269 |
else |
| 5270 |
fputs("</ul></li>\n", out); |
| 5271 |
} |
| 5272 |
|
| 5273 |
|
| 5274 |
|
| 5275 |
|
| 5276 |
|
| 5277 |
if ((arg = find_public(doc, doc, "variable")) != NULL) |
| 5278 |
{ |
| 5279 |
if (xml) |
| 5280 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5281 |
"<Path>Documentation/index.html</Path>\n" |
| 5282 |
"<Anchor>VARIABLES</Anchor>\n" |
| 5283 |
"<Name>Variables</Name>\n" |
| 5284 |
"<Subnodes>\n", xmlid ++); |
| 5285 |
else |
| 5286 |
fprintf(out, "<li><a href=\"%s#VARIABLES\"%s>Variables</a>" |
| 5287 |
"<ul class=\"code\">\n", target ? target : "", targetattr); |
| 5288 |
|
| 5289 |
while (arg) |
| 5290 |
{ |
| 5291 |
name = mxmlElementGetAttr(arg, "name"); |
| 5292 |
description = mxmlFindElement(arg, arg, "description", |
| 5293 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5294 |
|
| 5295 |
if (xml) |
| 5296 |
{ |
| 5297 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5298 |
"<Path>Documentation/index.html</Path>\n" |
| 5299 |
"<Anchor>%s</Anchor>\n" |
| 5300 |
"<Name>%s</Name>\n" |
| 5301 |
"</Node>\n", xmlid ++, name, name); |
| 5302 |
} |
| 5303 |
else |
| 5304 |
{ |
| 5305 |
fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"", |
| 5306 |
target ? target : "", name, targetattr); |
| 5307 |
write_description(out, description, "", 1); |
| 5308 |
fprintf(out, "\">%s</a></li>\n", name); |
| 5309 |
} |
| 5310 |
|
| 5311 |
arg = find_public(arg, doc, "variable"); |
| 5312 |
} |
| 5313 |
|
| 5314 |
if (xml) |
| 5315 |
fputs("</Subnodes></Node>\n", out); |
| 5316 |
else |
| 5317 |
fputs("</ul></li>\n", out); |
| 5318 |
} |
| 5319 |
|
| 5320 |
|
| 5321 |
|
| 5322 |
|
| 5323 |
|
| 5324 |
if ((scut = find_public(doc, doc, "enumeration")) != NULL) |
| 5325 |
{ |
| 5326 |
if (xml) |
| 5327 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5328 |
"<Path>Documentation/index.html</Path>\n" |
| 5329 |
"<Anchor>ENUMERATIONS</Anchor>\n" |
| 5330 |
"<Name>Constants</Name>\n" |
| 5331 |
"<Subnodes>\n", xmlid ++); |
| 5332 |
else |
| 5333 |
fprintf(out, "<li><a href=\"%s#ENUMERATIONS\"%s>Constants</a>" |
| 5334 |
"<ul class=\"code\">\n", target ? target : "", targetattr); |
| 5335 |
|
| 5336 |
while (scut) |
| 5337 |
{ |
| 5338 |
name = mxmlElementGetAttr(scut, "name"); |
| 5339 |
description = mxmlFindElement(scut, scut, "description", |
| 5340 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5341 |
|
| 5342 |
if (xml) |
| 5343 |
{ |
| 5344 |
fprintf(out, "<Node id=\"%d\">\n" |
| 5345 |
"<Path>Documentation/index.html</Path>\n" |
| 5346 |
"<Anchor>%s</Anchor>\n" |
| 5347 |
"<Name>%s</Name>\n" |
| 5348 |
"</Node>\n", xmlid ++, name, name); |
| 5349 |
} |
| 5350 |
else |
| 5351 |
{ |
| 5352 |
fprintf(out, "\t<li><a href=\"%s#%s\"%s title=\"", |
| 5353 |
target ? target : "", name, targetattr); |
| 5354 |
write_description(out, description, "", 1); |
| 5355 |
fprintf(out, "\">%s</a></li>\n", name); |
| 5356 |
} |
| 5357 |
|
| 5358 |
scut = find_public(scut, doc, "enumeration"); |
| 5359 |
} |
| 5360 |
|
| 5361 |
if (xml) |
| 5362 |
fputs("</Subnodes></Node>\n", out); |
| 5363 |
else |
| 5364 |
fputs("</ul></li>\n", out); |
| 5365 |
} |
| 5366 |
|
| 5367 |
|
| 5368 |
|
| 5369 |
|
| 5370 |
|
| 5371 |
if (!xml) |
| 5372 |
fputs("</ul>\n", out); |
| 5373 |
} |
| 5374 |
|
| 5375 |
|
| 5376 |
|
| 5377 |
|
| 5378 |
|
| 5379 |
|
| 5380 |
static void |
| 5381 |
write_tokens(FILE *out, |
| 5382 |
mxml_node_t *doc, |
| 5383 |
const char *path) |
| 5384 |
{ |
| 5385 |
mxml_node_t *function, |
| 5386 |
*scut, |
| 5387 |
*arg, |
| 5388 |
*description, |
| 5389 |
*type, |
| 5390 |
*node; |
| 5391 |
const char *name, |
| 5392 |
*cename, |
| 5393 |
*defval; |
| 5394 |
char prefix; |
| 5395 |
|
| 5396 |
|
| 5397 |
|
| 5398 |
|
| 5399 |
|
| 5400 |
|
| 5401 |
if ((scut = find_public(doc, doc, "class")) != NULL) |
| 5402 |
{ |
| 5403 |
while (scut) |
| 5404 |
{ |
| 5405 |
cename = mxmlElementGetAttr(scut, "name"); |
| 5406 |
description = mxmlFindElement(scut, scut, "description", |
| 5407 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5408 |
|
| 5409 |
fprintf(out, "<Token>\n" |
| 5410 |
"<Path>Documentation/%s</Path>\n" |
| 5411 |
"<Anchor>%s</Anchor>\n" |
| 5412 |
"<TokenIdentifier>//apple_ref/cpp/cl/%s</TokenIdentifier>\n" |
| 5413 |
"<Abstract>", path, cename, cename); |
| 5414 |
write_description(out, description, "", 1); |
| 5415 |
fputs("</Abstract>\n" |
| 5416 |
"</Token>\n", out); |
| 5417 |
|
| 5418 |
if ((function = find_public(scut, scut, "function")) != NULL) |
| 5419 |
{ |
| 5420 |
while (function) |
| 5421 |
{ |
| 5422 |
name = mxmlElementGetAttr(function, "name"); |
| 5423 |
description = mxmlFindElement(function, function, "description", |
| 5424 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5425 |
|
| 5426 |
fprintf(out, "<Token>\n" |
| 5427 |
"<Path>Documentation/%s</Path>\n" |
| 5428 |
"<Anchor>%s.%s</Anchor>\n" |
| 5429 |
"<TokenIdentifier>//apple_ref/cpp/clm/%s/%s", path, |
| 5430 |
cename, name, cename, name); |
| 5431 |
|
| 5432 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 5433 |
NULL, MXML_DESCEND_FIRST); |
| 5434 |
|
| 5435 |
if (arg && (type = mxmlFindElement(arg, arg, "type", NULL, |
| 5436 |
NULL, MXML_DESCEND_FIRST)) != NULL) |
| 5437 |
{ |
| 5438 |
for (node = type->child; node; node = node->next) |
| 5439 |
fputs(node->value.text.string, out); |
| 5440 |
} |
| 5441 |
else if (strcmp(cename, name) && strcmp(cename, name + 1)) |
| 5442 |
fputs("void", out); |
| 5443 |
|
| 5444 |
fputs("/", out); |
| 5445 |
|
| 5446 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 5447 |
MXML_DESCEND_FIRST), prefix = '('; |
| 5448 |
arg; |
| 5449 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 5450 |
MXML_NO_DESCEND), prefix = ',') |
| 5451 |
{ |
| 5452 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 5453 |
MXML_DESCEND_FIRST); |
| 5454 |
|
| 5455 |
putc(prefix, out); |
| 5456 |
|
| 5457 |
for (node = type->child; node; node = node->next) |
| 5458 |
fputs(node->value.text.string, out); |
| 5459 |
|
| 5460 |
fputs(mxmlElementGetAttr(arg, "name"), out); |
| 5461 |
} |
| 5462 |
|
| 5463 |
if (prefix == '(') |
| 5464 |
fputs("(void", out); |
| 5465 |
|
| 5466 |
fputs(")</TokenIdentifier>\n" |
| 5467 |
"<Abstract>", out); |
| 5468 |
write_description(out, description, "", 1); |
| 5469 |
fputs("</Abstract>\n" |
| 5470 |
"<Declaration>", out); |
| 5471 |
|
| 5472 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 5473 |
NULL, MXML_DESCEND_FIRST); |
| 5474 |
|
| 5475 |
if (arg) |
| 5476 |
write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 5477 |
NULL, MXML_DESCEND_FIRST), |
| 5478 |
OUTPUT_XML); |
| 5479 |
else if (strcmp(cename, name) && strcmp(cename, name + 1)) |
| 5480 |
fputs("void ", out); |
| 5481 |
|
| 5482 |
fputs(name, out); |
| 5483 |
|
| 5484 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 5485 |
MXML_DESCEND_FIRST), prefix = '('; |
| 5486 |
arg; |
| 5487 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 5488 |
MXML_NO_DESCEND), prefix = ',') |
| 5489 |
{ |
| 5490 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 5491 |
MXML_DESCEND_FIRST); |
| 5492 |
|
| 5493 |
putc(prefix, out); |
| 5494 |
if (prefix == ',') |
| 5495 |
putc(' ', out); |
| 5496 |
|
| 5497 |
if (type->child) |
| 5498 |
write_element(out, doc, type, OUTPUT_XML); |
| 5499 |
|
| 5500 |
fputs(mxmlElementGetAttr(arg, "name"), out); |
| 5501 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 5502 |
fprintf(out, " %s", defval); |
| 5503 |
} |
| 5504 |
|
| 5505 |
if (prefix == '(') |
| 5506 |
fputs("(void);", out); |
| 5507 |
else |
| 5508 |
fputs(");", out); |
| 5509 |
|
| 5510 |
fputs("</Declaration>\n" |
| 5511 |
"</Token>\n", out); |
| 5512 |
|
| 5513 |
function = find_public(function, doc, "function"); |
| 5514 |
} |
| 5515 |
} |
| 5516 |
scut = find_public(scut, doc, "class"); |
| 5517 |
} |
| 5518 |
} |
| 5519 |
|
| 5520 |
|
| 5521 |
|
| 5522 |
|
| 5523 |
|
| 5524 |
if ((function = find_public(doc, doc, "function")) != NULL) |
| 5525 |
{ |
| 5526 |
while (function) |
| 5527 |
{ |
| 5528 |
name = mxmlElementGetAttr(function, "name"); |
| 5529 |
description = mxmlFindElement(function, function, "description", |
| 5530 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5531 |
|
| 5532 |
fprintf(out, "<Token>\n" |
| 5533 |
"<Path>Documentation/%s</Path>\n" |
| 5534 |
"<Anchor>%s</Anchor>\n" |
| 5535 |
"<TokenIdentifier>//apple_ref/c/func/%s</TokenIdentifier>\n" |
| 5536 |
"<Abstract>", path, name, name); |
| 5537 |
write_description(out, description, "", 1); |
| 5538 |
fputs("</Abstract>\n" |
| 5539 |
"<Declaration>", out); |
| 5540 |
|
| 5541 |
arg = mxmlFindElement(function, function, "returnvalue", NULL, |
| 5542 |
NULL, MXML_DESCEND_FIRST); |
| 5543 |
|
| 5544 |
if (arg) |
| 5545 |
write_element(out, doc, mxmlFindElement(arg, arg, "type", NULL, |
| 5546 |
NULL, MXML_DESCEND_FIRST), |
| 5547 |
OUTPUT_XML); |
| 5548 |
else |
| 5549 |
fputs("void ", out); |
| 5550 |
|
| 5551 |
fputs(name, out); |
| 5552 |
|
| 5553 |
for (arg = mxmlFindElement(function, function, "argument", NULL, NULL, |
| 5554 |
MXML_DESCEND_FIRST), prefix = '('; |
| 5555 |
arg; |
| 5556 |
arg = mxmlFindElement(arg, function, "argument", NULL, NULL, |
| 5557 |
MXML_NO_DESCEND), prefix = ',') |
| 5558 |
{ |
| 5559 |
type = mxmlFindElement(arg, arg, "type", NULL, NULL, |
| 5560 |
MXML_DESCEND_FIRST); |
| 5561 |
|
| 5562 |
putc(prefix, out); |
| 5563 |
if (prefix == ',') |
| 5564 |
putc(' ', out); |
| 5565 |
|
| 5566 |
if (type->child) |
| 5567 |
write_element(out, doc, type, OUTPUT_XML); |
| 5568 |
|
| 5569 |
fputs(mxmlElementGetAttr(arg, "name"), out); |
| 5570 |
if ((defval = mxmlElementGetAttr(arg, "default")) != NULL) |
| 5571 |
fprintf(out, " %s", defval); |
| 5572 |
} |
| 5573 |
|
| 5574 |
if (prefix == '(') |
| 5575 |
fputs("(void);", out); |
| 5576 |
else |
| 5577 |
fputs(");", out); |
| 5578 |
|
| 5579 |
fputs("</Declaration>\n" |
| 5580 |
"</Token>\n", out); |
| 5581 |
|
| 5582 |
function = find_public(function, doc, "function"); |
| 5583 |
} |
| 5584 |
} |
| 5585 |
|
| 5586 |
|
| 5587 |
|
| 5588 |
|
| 5589 |
|
| 5590 |
if ((scut = find_public(doc, doc, "typedef")) != NULL) |
| 5591 |
{ |
| 5592 |
while (scut) |
| 5593 |
{ |
| 5594 |
name = mxmlElementGetAttr(scut, "name"); |
| 5595 |
description = mxmlFindElement(scut, scut, "description", |
| 5596 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5597 |
|
| 5598 |
fprintf(out, "<Token>\n" |
| 5599 |
"<Path>Documentation/%s</Path>\n" |
| 5600 |
"<Anchor>%s</Anchor>\n" |
| 5601 |
"<TokenIdentifier>//apple_ref/c/tdef/%s</TokenIdentifier>\n" |
| 5602 |
"<Abstract>", path, name, name); |
| 5603 |
write_description(out, description, "", 1); |
| 5604 |
fputs("</Abstract>\n" |
| 5605 |
"</Token>\n", out); |
| 5606 |
|
| 5607 |
scut = find_public(scut, doc, "typedef"); |
| 5608 |
} |
| 5609 |
} |
| 5610 |
|
| 5611 |
|
| 5612 |
|
| 5613 |
|
| 5614 |
|
| 5615 |
if ((scut = find_public(doc, doc, "struct")) != NULL) |
| 5616 |
{ |
| 5617 |
while (scut) |
| 5618 |
{ |
| 5619 |
name = mxmlElementGetAttr(scut, "name"); |
| 5620 |
description = mxmlFindElement(scut, scut, "description", |
| 5621 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5622 |
|
| 5623 |
fprintf(out, "<Token>\n" |
| 5624 |
"<Path>Documentation/%s</Path>\n" |
| 5625 |
"<Anchor>%s</Anchor>\n" |
| 5626 |
"<TokenIdentifier>//apple_ref/c/tag/%s</TokenIdentifier>\n" |
| 5627 |
"<Abstract>", path, name, name); |
| 5628 |
write_description(out, description, "", 1); |
| 5629 |
fputs("</Abstract>\n" |
| 5630 |
"</Token>\n", out); |
| 5631 |
|
| 5632 |
scut = find_public(scut, doc, "struct"); |
| 5633 |
} |
| 5634 |
} |
| 5635 |
|
| 5636 |
|
| 5637 |
|
| 5638 |
|
| 5639 |
|
| 5640 |
if ((scut = find_public(doc, doc, "union")) != NULL) |
| 5641 |
{ |
| 5642 |
while (scut) |
| 5643 |
{ |
| 5644 |
name = mxmlElementGetAttr(scut, "name"); |
| 5645 |
description = mxmlFindElement(scut, scut, "description", |
| 5646 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5647 |
|
| 5648 |
fprintf(out, "<Token>\n" |
| 5649 |
"<Path>Documentation/%s</Path>\n" |
| 5650 |
"<Anchor>%s</Anchor>\n" |
| 5651 |
"<TokenIdentifier>//apple_ref/c/tag/%s</TokenIdentifier>\n" |
| 5652 |
"<Abstract>", path, name, name); |
| 5653 |
write_description(out, description, "", 1); |
| 5654 |
fputs("</Abstract>\n" |
| 5655 |
"</Token>\n", out); |
| 5656 |
|
| 5657 |
scut = find_public(scut, doc, "union"); |
| 5658 |
} |
| 5659 |
} |
| 5660 |
|
| 5661 |
|
| 5662 |
|
| 5663 |
|
| 5664 |
|
| 5665 |
if ((arg = find_public(doc, doc, "variable")) != NULL) |
| 5666 |
{ |
| 5667 |
while (arg) |
| 5668 |
{ |
| 5669 |
name = mxmlElementGetAttr(arg, "name"); |
| 5670 |
description = mxmlFindElement(arg, arg, "description", |
| 5671 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5672 |
|
| 5673 |
fprintf(out, "<Token>\n" |
| 5674 |
"<Path>Documentation/%s</Path>\n" |
| 5675 |
"<Anchor>%s</Anchor>\n" |
| 5676 |
"<TokenIdentifier>//apple_ref/c/data/%s</TokenIdentifier>\n" |
| 5677 |
"<Abstract>", path, name, name); |
| 5678 |
write_description(out, description, "", 1); |
| 5679 |
fputs("</Abstract>\n" |
| 5680 |
"</Token>\n", out); |
| 5681 |
|
| 5682 |
arg = find_public(arg, doc, "variable"); |
| 5683 |
} |
| 5684 |
} |
| 5685 |
|
| 5686 |
|
| 5687 |
|
| 5688 |
|
| 5689 |
|
| 5690 |
if ((scut = find_public(doc, doc, "enumeration")) != NULL) |
| 5691 |
{ |
| 5692 |
while (scut) |
| 5693 |
{ |
| 5694 |
cename = mxmlElementGetAttr(scut, "name"); |
| 5695 |
description = mxmlFindElement(scut, scut, "description", |
| 5696 |
NULL, NULL, MXML_DESCEND_FIRST); |
| 5697 |
|
| 5698 |
fprintf(out, "<Token>\n" |
| 5699 |
"<Path>Documentation/%s</Path>\n" |
| 5700 |
"<Anchor>%s</Anchor>\n" |
| 5701 |
"<TokenIdentifier>//apple_ref/c/tag/%s</TokenIdentifier>\n" |
| 5702 |
"<Abstract>", path, cename, cename); |
| 5703 |
write_description(out, description, "", 1); |
| 5704 |
fputs("</Abstract>\n" |
| 5705 |
"</Token>\n", out); |
| 5706 |
|
| 5707 |
for (arg = mxmlFindElement(scut, scut, "constant", NULL, NULL, |
| 5708 |
MXML_DESCEND_FIRST); |
| 5709 |
arg; |
| 5710 |
arg = mxmlFindElement(arg, scut, "constant", NULL, NULL, |
| 5711 |
MXML_NO_DESCEND)) |
| 5712 |
{ |
| 5713 |
name = mxmlElementGetAttr(arg, "name"); |
| 5714 |
description = mxmlFindElement(arg, arg, "description", NULL, |
| 5715 |
NULL, MXML_DESCEND_FIRST); |
| 5716 |
fprintf(out, "<Token>\n" |
| 5717 |
"<Path>Documentation/%s</Path>\n" |
| 5718 |
"<Anchor>%s</Anchor>\n" |
| 5719 |
"<TokenIdentifier>//apple_ref/c/econst/%s</TokenIdentifier>\n" |
| 5720 |
"<Abstract>", path, cename, name); |
| 5721 |
write_description(out, description, "", 1); |
| 5722 |
fputs("</Abstract>\n" |
| 5723 |
"</Token>\n", out); |
| 5724 |
} |
| 5725 |
|
| 5726 |
scut = find_public(scut, doc, "enumeration"); |
| 5727 |
} |
| 5728 |
} |
| 5729 |
} |
| 5730 |
|
| 5731 |
|
| 5732 |
|
| 5733 |
|
| 5734 |
|
| 5735 |
|
| 5736 |
static const char * |
| 5737 |
ws_cb(mxml_node_t *node, |
| 5738 |
int where) |
| 5739 |
{ |
| 5740 |
const char *name; |
| 5741 |
int depth; |
| 5742 |
static const char *spaces = " "; |
| 5743 |
|
| 5744 |
|
| 5745 |
|
| 5746 |
name = node->value.element.name; |
| 5747 |
|
| 5748 |
switch (where) |
| 5749 |
{ |
| 5750 |
case MXML_WS_BEFORE_CLOSE : |
| 5751 |
if (strcmp(name, "argument") && |
| 5752 |
strcmp(name, "class") && |
| 5753 |
strcmp(name, "constant") && |
| 5754 |
strcmp(name, "enumeration") && |
| 5755 |
strcmp(name, "function") && |
| 5756 |
strcmp(name, "mxmldoc") && |
| 5757 |
strcmp(name, "namespace") && |
| 5758 |
strcmp(name, "returnvalue") && |
| 5759 |
strcmp(name, "struct") && |
| 5760 |
strcmp(name, "typedef") && |
| 5761 |
strcmp(name, "union") && |
| 5762 |
strcmp(name, "variable")) |
| 5763 |
return (NULL); |
| 5764 |
|
| 5765 |
for (depth = -4; node; node = node->parent, depth += 2); |
| 5766 |
if (depth > 40) |
| 5767 |
return (spaces); |
| 5768 |
else if (depth < 2) |
| 5769 |
return (NULL); |
| 5770 |
else |
| 5771 |
return (spaces + 40 - depth); |
| 5772 |
|
| 5773 |
case MXML_WS_AFTER_CLOSE : |
| 5774 |
return ("\n"); |
| 5775 |
|
| 5776 |
case MXML_WS_BEFORE_OPEN : |
| 5777 |
for (depth = -4; node; node = node->parent, depth += 2); |
| 5778 |
if (depth > 40) |
| 5779 |
return (spaces); |
| 5780 |
else if (depth < 2) |
| 5781 |
return (NULL); |
| 5782 |
else |
| 5783 |
return (spaces + 40 - depth); |
| 5784 |
|
| 5785 |
default : |
| 5786 |
case MXML_WS_AFTER_OPEN : |
| 5787 |
if (strcmp(name, "argument") && |
| 5788 |
strcmp(name, "class") && |
| 5789 |
strcmp(name, "constant") && |
| 5790 |
strcmp(name, "enumeration") && |
| 5791 |
strcmp(name, "function") && |
| 5792 |
strcmp(name, "mxmldoc") && |
| 5793 |
strcmp(name, "namespace") && |
| 5794 |
strcmp(name, "returnvalue") && |
| 5795 |
strcmp(name, "struct") && |
| 5796 |
strcmp(name, "typedef") && |
| 5797 |
strcmp(name, "union") && |
| 5798 |
strcmp(name, "variable") && |
| 5799 |
strncmp(name, "?xml", 4)) |
| 5800 |
return (NULL); |
| 5801 |
else |
| 5802 |
return ("\n"); |
| 5803 |
} |
| 5804 |
} |
| 5805 |
|
| 5806 |
|
| 5807 |
|
| 5808 |
|
| 5809 |
|