1 | /*************************************** 2 | $Header: /home/amb/cxref/RCS/html.c 1.34 2001/01/06 13:05:12 amb Exp $ 3 | 4 | C Cross Referencing & Documentation tool. Version 1.5c. 5 | 6 | Writes the HTML output. 7 | ******************/ /****************** 8 | Written by Andrew M. Bishop 9 | 10 | This file Copyright 1995,96,97,98,99,2001 Andrew M. Bishop 11 | It may be distributed under the GNU Public License, version 2, or 12 | any higher version. See section COPYING of the GNU Public license 13 | for conditions under which this file may be redistributed. 14 | ***************************************/ 15 | 16 | #include <stdlib.h> 17 | #include <stdio.h> 18 | #include <string.h> 19 | #include <sys/types.h> 20 | #include <sys/stat.h> 21 | #include <unistd.h> 22 | 23 | #include "memory.h" 24 | #include "datatype.h" 25 | #include "cxref.h" 26 | 27 | /*+ The file extension to use for the output files. +*/ 28 | #define HTML_FILE ".html" 29 | #define HTML_FILE_BACKUP ".html~" 30 | 31 | /*+ The file extension to use for the output source files. +*/ 32 | #define HTML_SRC_FILE ".src.html" 33 | 34 | /*+ The name of the output tex file that contains the appendix. +*/ 35 | #define HTML_APDX ".apdx" 36 | 37 | /*+ A macro to determine the HTML version we should produce. +*/ 38 | #define HTML20 (option_html&1) 39 | #define HTML32 (option_html&2) 40 | #define HTMLSRC (option_html&16) 41 | 42 | /*+ The comments are to be inserted verbatim. +*/ 43 | extern int option_verbatim_comments; 44 | 45 | /*+ The type of HTML output to produce. +*/ 46 | extern int option_html; 47 | 48 | /*+ The name of the directory for the output. +*/ 49 | extern char* option_odir; 50 | 51 | /*+ The base name of the file for the output. +*/ 52 | extern char* option_name; 53 | 54 | /*+ The information about the cxref run, +*/ 55 | extern char *run_command, /*+ the command line options. +*/ 56 | *run_cpp_command; /*+ the cpp command and options. +*/ 57 | 58 | /*+ The directories to go back to get to the base output directory. +*/ 59 | static char* goback=NULL; 60 | 61 | static void WriteHTMLFilePart(File file); 62 | static void WriteHTMLInclude(Include inc); 63 | static void WriteHTMLSubInclude(Include inc,int depth); 64 | static void WriteHTMLDefine(Define def); 65 | static void WriteHTMLTypedef(Typedef type); 66 | static void WriteHTMLStructUnion(StructUnion su,int depth); 67 | static void WriteHTMLVariable(Variable var); 68 | static void WriteHTMLFunction(Function func); 69 | 70 | static void WriteHTMLDocument(char* name,int appendix); 71 | static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile); 72 | static void WriteHTMLPostamble(FILE* f,int sourcefile); 73 | 74 | void WriteHTMLSource(char *name); 75 | 76 | static char* html(char* c,int verbatim); 77 | 78 | /*+ The output file for the HTML. +*/ 79 | static FILE* of; 80 | 81 | /*+ The name of the file. +*/ 82 | static char *filename; 83 | 84 | 85 | /*++++++++++++++++++++++++++++++++++++++ 86 | Write an html file for a complete File structure and all components. 87 | 88 | File file The File structure to output. 89 | ++++++++++++++++++++++++++++++++++++++*/ 90 | 91 | void WriteHTMLFile(File file) 92 | { 93 | char* ofile; 94 | int i; 95 | 96 | filename=file->name; 97 | 98 | /* Write the including file. */ 99 | 100 | WriteHTMLDocument(file->name,0); 101 | 102 | /* Open the file */ 103 | 104 | ofile=ConcatStrings(4,option_odir,"/",file->name,HTML_FILE); 105 | 106 | of=fopen(ofile,"w"); 107 | if(!of) 108 | { 109 | struct stat stat_buf; 110 | int i,ofl=strlen(ofile); 111 | 112 | for(i=strlen(option_odir)+1;i<ofl;i++) 113 | if(ofile[i]=='/') 114 | { 115 | ofile[i]=0; 116 | if(stat(ofile,&stat_buf)) 117 | mkdir(ofile,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); 118 | ofile[i]='/'; 119 | } 120 | 121 | of=fopen(ofile,"w"); 122 | } 123 | 124 | if(!of) 125 | {fprintf(stderr,"cxref: Failed to open the HTML output file '%s'\n",ofile);exit(1);} 126 | 127 | for(goback="",i=strlen(file->name);i>0;i--) 128 | if(file->name[i]=='/') 129 | goback=ConcatStrings(2,goback,"../"); 130 | 131 | /* Write out a header. */ 132 | 133 | WriteHTMLPreamble(of,ConcatStrings(5,"Cross reference for ",file->name," of ",option_name,"."),0); 134 | 135 | /*+ The file structure is broken into its components and they are each written out. +*/ 136 | 137 | WriteHTMLFilePart(file); 138 | 139 | if(file->includes) 140 | { 141 | Include inc =file->includes; 142 | fprintf(of,"\n<hr>\n<h2>Included Files</h2>\n\n"); 143 | do{ 144 | WriteHTMLInclude(inc); 145 | } 146 | while((inc=inc->next)); 147 | } 148 | 149 | if(file->defines) 150 | { 151 | Define def =file->defines; 152 | fprintf(of,"\n<hr>\n<h2>Preprocessor definitions</h2>\n\n"); 153 | do{ 154 | if(def!=file->defines) 155 | fprintf(of,"<p>\n"); 156 | WriteHTMLDefine(def); 157 | } 158 | while((def=def->next)); 159 | } 160 | 161 | if(file->typedefs) 162 | { 163 | Typedef type=file->typedefs; 164 | do{ 165 | WriteHTMLTypedef(type); 166 | } 167 | while((type=type->next)); 168 | } 169 | 170 | if(file->variables) 171 | { 172 | int any_to_mention=0; 173 | Variable var=file->variables; 174 | 175 | do{ 176 | if(var->scope&(GLOBAL|LOCAL|EXTERNAL|EXTERN_F)) 177 | any_to_mention=1; 178 | } 179 | while((var=var->next)); 180 | 181 | if(any_to_mention) 182 | { 183 | int first_ext=1,first_local=1; 184 | Variable var=file->variables; 185 | do{ 186 | if(var->scope&GLOBAL) 187 | WriteHTMLVariable(var); 188 | } 189 | while((var=var->next)); 190 | var=file->variables; 191 | do{ 192 | if(var->scope&(EXTERNAL|EXTERN_F) && !(var->scope&GLOBAL)) 193 | { 194 | if(first_ext) 195 | {fprintf(of,"\n<hr>\n<h2>External Variables</h2>\n\n"); first_ext=0;} 196 | else 197 | fprintf(of,"<p>\n"); 198 | WriteHTMLVariable(var); 199 | } 200 | } 201 | while((var=var->next)); 202 | var=file->variables; 203 | do{ 204 | if(var->scope&LOCAL) 205 | { 206 | if(first_local) 207 | {fprintf(of,"\n<hr>\n<h2>Local Variables</h2>\n\n"); first_local=0;} 208 | else 209 | fprintf(of,"<p>\n"); 210 | WriteHTMLVariable(var); 211 | } 212 | } 213 | while((var=var->next)); 214 | } 215 | } 216 | 217 | if(file->functions) 218 | { 219 | Function func=file->functions; 220 | do{ 221 | if(func->scope&(GLOBAL|EXTERNAL)) 222 | WriteHTMLFunction(func); 223 | } 224 | while((func=func->next)); 225 | func=file->functions; 226 | do{ 227 | if(func->scope&LOCAL) 228 | WriteHTMLFunction(func); 229 | } 230 | while((func=func->next)); 231 | } 232 | 233 | WriteHTMLPostamble(of,0); 234 | 235 | fclose(of); 236 | 237 | /* Write out the source file. */ 238 | 239 | if(HTMLSRC) 240 | WriteHTMLSource(file->name); 241 | 242 | /* Clear the memory in html() */ 243 | 244 | html(NULL,0); html(NULL,0); html(NULL,0); html(NULL,0); 245 | } 246 | 247 | 248 | /*++++++++++++++++++++++++++++++++++++++ 249 | Write a File structure out. 250 | 251 | File file The File to output. 252 | ++++++++++++++++++++++++++++++++++++++*/ 253 | 254 | static void WriteHTMLFilePart(File file) 255 | { 256 | int i; 257 | 258 | if(HTMLSRC) 259 | fprintf(of,"<h1><a name=\"file\" href=\"%s%s%s\">File %s</a></h1>\n",goback,file->name,HTML_SRC_FILE,html(file->name,0)); 260 | else 261 | fprintf(of,"<h1><a name=\"file\">File %s</a></h1>\n",html(file->name,0)); 262 | 263 | if(file->comment) 264 | { 265 | if(option_verbatim_comments) 266 | fprintf(of,"<pre>\n%s\n</pre>\n\n",html(file->comment,0)); 267 | else 268 | { 269 | char *rcs1=strstr(file->comment,"$Header"),*rcs2=NULL; 270 | if(rcs1) 271 | { 272 | rcs2=strstr(&rcs1[1],"$"); 273 | if(rcs2) 274 | { 275 | rcs2[0]=0; 276 | fprintf(of,"<b>RCS %s</b>\n<p>\n",html(&rcs1[1],0)); 277 | rcs2[0]='$'; 278 | } 279 | } 280 | if(rcs2) 281 | fprintf(of,"%s\n<p>\n",html(&rcs2[2],0)); 282 | else 283 | fprintf(of,"%s\n<p>\n",html(file->comment,0)); 284 | } 285 | } 286 | 287 | if(file->inc_in->n) 288 | { 289 | int i; 290 | 291 | if(HTML20) 292 | fprintf(of,"<dl compact>\n"); 293 | else 294 | fprintf(of,"<table>\n"); 295 | for(i=0;i<file->inc_in->n;i++) 296 | { 297 | if(HTML20 && i==0) 298 | fprintf(of,"<dt>Included in:\n<dd><ul>\n"); 299 | else if(HTML32 && i==0) 300 | fprintf(of,"<tr><td>Included in:\n"); 301 | else if(HTML32) 302 | fprintf(of,"<tr><td> \n"); 303 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a><br>\n",HTML20?"li":"td",goback,file->inc_in->s[i],html(file->inc_in->s[i],0)); 304 | } 305 | if(HTML20) 306 | fprintf(of,"</ul>\n</dl>\n"); 307 | else 308 | fprintf(of,"</table>\n"); 309 | } 310 | 311 | if(file->f_refs->n || file->v_refs->n) 312 | { 313 | if(HTML20) 314 | fprintf(of,"<dl compact>\n"); 315 | else 316 | fprintf(of,"<table>\n"); 317 | } 318 | 319 | if(file->f_refs->n) 320 | { 321 | int others=0; 322 | 323 | if(HTML20) 324 | fprintf(of,"<dt>References Functions:\n<dd><ul>\n"); 325 | else 326 | fprintf(of,"<tr><td>References Functions:\n"); 327 | 328 | for(i=0;i<file->f_refs->n;i++) 329 | if(file->f_refs->s2[i]) 330 | { 331 | if(HTML32 && i!=others) 332 | fprintf(of,"<tr><td> \n"); 333 | if(HTML20) 334 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s1[i],0),html(file->f_refs->s2[i],0)); 335 | else 336 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s1[i],0),goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file-337 | >f_refs->s2[i],0)); 338 | } 339 | else 340 | others++; 341 | 342 | if(others) 343 | { 344 | if(HTML20) 345 | fprintf(of,"<li>"); 346 | else if(i==others) 347 | fprintf(of,"<td colspan=2>"); 348 | else 349 | fprintf(of,"<tr><td> \n<td colspan=2>"); 350 | for(i=0;i<file->f_refs->n;i++) 351 | if(!file->f_refs->s2[i]) 352 | fprintf(of,--others?" %s(),":" %s()",html(file->f_refs->s1[i],0)); 353 | fprintf(of,"\n"); 354 | } 355 | 356 | if(HTML20) 357 | fprintf(of,"</ul>\n"); 358 | } 359 | 360 | if(file->v_refs->n) 361 | { 362 | int others=0; 363 | 364 | if(HTML20) 365 | fprintf(of,"<dt>References Variables:\n<dd><ul>\n"); 366 | else 367 | fprintf(of,"<tr><td>References Variables:\n"); 368 | 369 | for(i=0;i<file->v_refs->n;i++) 370 | if(file->v_refs->s2[i]) 371 | { 372 | if(HTML32 && i!=others) 373 | fprintf(of,"<tr><td> \n"); 374 | if(HTML20) 375 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s : %s</a>\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s1[i],0),html(file->v_refs->s2[i],0)); 376 | else 377 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a><td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s1[i],0),goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_r378 | efs->s2[i],0)); 379 | } 380 | else 381 | others++; 382 | 383 | if(others) 384 | { 385 | if(HTML20) 386 | fprintf(of,"<li>"); 387 | else if(i==others) 388 | fprintf(of,"<td colspan=2>"); 389 | else 390 | fprintf(of,"<tr><td> \n<td colspan=2>"); 391 | for(i=0;i<file->v_refs->n;i++) 392 | if(!file->v_refs->s2[i]) 393 | fprintf(of,--others?" %s,":" %s",html(file->v_refs->s1[i],0)); 394 | fprintf(of,"\n"); 395 | } 396 | 397 | if(HTML20) 398 | fprintf(of,"</ul>\n"); 399 | } 400 | 401 | if(file->f_refs->n || file->v_refs->n) 402 | { 403 | if(HTML20) 404 | fprintf(of,"</dl>\n"); 405 | else 406 | fprintf(of,"</table>\n"); 407 | } 408 | } 409 | 410 | 411 | /*++++++++++++++++++++++++++++++++++++++ 412 | Write an Include structure out. 413 | 414 | Include inc The Include structure to output. 415 | ++++++++++++++++++++++++++++++++++++++*/ 416 | 417 | static void WriteHTMLInclude(Include inc) 418 | { 419 | if(inc->comment) 420 | fprintf(of,"%s\n<p>\n",html(inc->comment,0)); 421 | 422 | fprintf(of,"<ul>\n"); 423 | 424 | if(inc->scope==LOCAL) 425 | fprintf(of,"<li><tt><a href=\"%s%s"HTML_FILE"#file\">#include "%s"</a></tt>\n",goback,inc->name,html(inc->name,0)); 426 | else 427 | fprintf(of,"<li><tt>#include <%s></tt>\n",html(inc->name,0)); 428 | 429 | if(inc->includes) 430 | WriteHTMLSubInclude(inc->includes,1); 431 | 432 | fprintf(of,"</ul>\n"); 433 | } 434 | 435 | 436 | /*++++++++++++++++++++++++++++++++++++++ 437 | Write an Sub Include structure out. (An include structure that is included from another file.) 438 | 439 | Include inc The Include structure to output. 440 | 441 | int depth The depth of the include hierarchy. 442 | ++++++++++++++++++++++++++++++++++++++*/ 443 | 444 | static void WriteHTMLSubInclude(Include inc,int depth) 445 | { 446 | fprintf(of,"<ul>\n"); 447 | 448 | while(inc) 449 | { 450 | if(inc->scope==LOCAL) 451 | fprintf(of,"<li><tt><a href=\"%s%s"HTML_FILE"#file\">#include "%s"</a></tt>\n",goback,inc->name,html(inc->name,0)); 452 | else 453 | fprintf(of,"<li><tt>#include <%s></tt>\n",html(inc->name,0)); 454 | 455 | if(inc->includes) 456 | WriteHTMLSubInclude(inc->includes,depth+1); 457 | 458 | inc=inc->next; 459 | } 460 | 461 | fprintf(of,"</ul>\n"); 462 | } 463 | 464 | 465 | /*++++++++++++++++++++++++++++++++++++++ 466 | Write a Define structure out. 467 | 468 | Define def The Define structure to output. 469 | ++++++++++++++++++++++++++++++++++++++*/ 470 | 471 | static void WriteHTMLDefine(Define def) 472 | { 473 | int i; 474 | int pargs=0; 475 | 476 | if(def->comment) 477 | fprintf(of,"%s\n<p>\n",html(def->comment,0)); 478 | 479 | if(HTMLSRC) 480 | fprintf(of,"<tt><a href=\"%s%s%s#line%d\">#define %s</a>",goback,filename,HTML_SRC_FILE,def->lineno,html(def->name,0)); 481 | else 482 | fprintf(of,"<tt>#define %s",html(def->name,0)); 483 | 484 | if(def->value) 485 | fprintf(of," %s",html(def->value,0)); 486 | 487 | if(def->args->n) 488 | { 489 | fprintf(of,"( "); 490 | for(i=0;i<def->args->n;i++) 491 | fprintf(of,i?", %s":"%s",html(def->args->s1[i],0)); 492 | fprintf(of," )"); 493 | } 494 | fprintf(of,"</tt><br>\n"); 495 | 496 | for(i=0;i<def->args->n;i++) 497 | if(def->args->s2[i]) 498 | pargs=1; 499 | 500 | if(pargs) 501 | { 502 | fprintf(of,"<dl compact>\n"); 503 | for(i=0;i<def->args->n;i++) 504 | fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(def->args->s1[i],0),def->args->s2[i]?html(def->args->s2[i],0):""); 505 | fprintf(of,"</dl>\n"); 506 | } 507 | } 508 | 509 | 510 | /*++++++++++++++++++++++++++++++++++++++ 511 | Write a Typedef structure out. 512 | 513 | Typedef type The Typedef structure to output. 514 | ++++++++++++++++++++++++++++++++++++++*/ 515 | 516 | static void WriteHTMLTypedef(Typedef type) 517 | { 518 | fprintf(of,"\n<hr>\n<h2>"); 519 | 520 | if(!strncmp("enum",type->name,4)) 521 | fprintf(of,"<a name=\"type-enum-%s\">",&type->name[5]); 522 | else 523 | if(!strncmp("union",type->name,5)) 524 | fprintf(of,"<a name=\"type-union-%s\">",&type->name[6]); 525 | else 526 | if(!strncmp("struct",type->name,6)) 527 | fprintf(of,"<a name=\"type-struct-%s\">",&type->name[7]); 528 | else 529 | fprintf(of,"<a name=\"type-%s\">",type->name); 530 | 531 | if(type->type) 532 | fprintf(of,"Typedef %s",html(type->name,0)); 533 | else 534 | fprintf(of,"Type %s",html(type->name,0)); 535 | 536 | fprintf(of,"</a></h2>\n"); 537 | 538 | if(type->comment) 539 | fprintf(of,"%s\n<p>\n",html(type->comment,0)); 540 | 541 | if(type->type) 542 | { 543 | if(HTMLSRC) 544 | fprintf(of,"<tt><a href=\"%s%s%s#line%d\">typedef %s</a></tt><br>\n",goback,filename,HTML_SRC_FILE,type->lineno,html(type->type,0)); 545 | else 546 | fprintf(of,"<tt>typedef %s</tt><br>\n",html(type->type,0)); 547 | } 548 | else if(type->sutype) 549 | { 550 | if(HTMLSRC) 551 | fprintf(of,"<tt><a href=\"%s%s%s#line%d\">%s</a></tt><br>\n",goback,filename,HTML_SRC_FILE,type->lineno,html(type->sutype->name,0)); 552 | else 553 | fprintf(of,"<tt>%s</tt><br>\n",html(type->sutype->name,0)); 554 | } 555 | 556 | if(type->sutype) 557 | { 558 | if(HTML20) 559 | fprintf(of,"<ul>\n"); 560 | else 561 | fprintf(of,"<table>\n"); 562 | WriteHTMLStructUnion(type->sutype,0); 563 | if(HTML20) 564 | fprintf(of,"</ul>\n"); 565 | else 566 | fprintf(of,"</table>\n"); 567 | } 568 | else 569 | if(type->typexref) 570 | { 571 | fprintf(of,"<dl compact>\n<dt>See:\n<dd><ul>\n"); 572 | if(type->typexref->type) 573 | fprintf(of,"<li><a href=\"#type-%s\">Typedef %s</a>\n",type->typexref->name,html(type->typexref->name,0)); 574 | else 575 | if(!strncmp("enum",type->typexref->name,4)) 576 | fprintf(of,"<li><a href=\"#type-enum-%s\">Type %s</a>\n",&type->typexref->name[5],html(type->typexref->name,0)); 577 | else 578 | if(!strncmp("union",type->typexref->name,5)) 579 | fprintf(of,"<li><a href=\"#type-union-%s\">Type %s</a>\n",&type->typexref->name[6],html(type->typexref->name,0)); 580 | else 581 | if(!strncmp("struct",type->typexref->name,6)) 582 | fprintf(of,"<li><a href=\"#type-struct-%s\">Type %s</a>\n",&type->typexref->name[7],html(type->typexref->name,0)); 583 | fprintf(of,"</ul>\n</dl>\n"); 584 | } 585 | } 586 | 587 | 588 | /*++++++++++++++++++++++++++++++++++++++ 589 | Write a structure / union structure out. 590 | 591 | StructUnion su The structure / union to write. 592 | 593 | int depth The current depth within the structure. 594 | ++++++++++++++++++++++++++++++++++++++*/ 595 | 596 | static void WriteHTMLStructUnion(StructUnion su, int depth) 597 | { 598 | int i; 599 | char* splitsu=NULL; 600 | 601 | splitsu=strstr(su->name,"{...}"); 602 | if(splitsu) splitsu[-1]=0; 603 | 604 | if(HTML20) 605 | { 606 | if(depth && su->comment && !su->comps) 607 | fprintf(of,"<li><tt>%s; </tt>%s<br>\n",html(su->name,0),html(su->comment,0)); 608 | else if(!depth || su->comps) 609 | fprintf(of,"<li><tt>%s</tt><br>\n",html(su->name,0)); 610 | else 611 | fprintf(of,"<li><tt>%s;</tt><br>\n",html(su->name,0)); 612 | } 613 | else 614 | { 615 | fprintf(of,"<tr><td>"); 616 | for(i=0;i<depth;i++) 617 | fprintf(of," "); 618 | if(!depth || su->comps) 619 | fprintf(of,"<tt>%s</tt>",html(su->name,0)); 620 | else 621 | fprintf(of,"<tt>%s;</tt>",html(su->name,0)); 622 | fprintf(of,"<td>"); 623 | if(depth && su->comment && !su->comps) 624 | fprintf(of,html(su->comment,0)); 625 | else 626 | fprintf(of," "); 627 | fprintf(of,"\n"); 628 | } 629 | 630 | if(!depth || su->comps) 631 | { 632 | if(HTML20) 633 | { 634 | fprintf(of,"<ul>\n"); 635 | fprintf(of,"<li><tt>{</tt><br>\n"); 636 | } 637 | else 638 | { 639 | fprintf(of,"<tr><td>"); 640 | for(i=0;i<depth;i++) 641 | fprintf(of," "); 642 | fprintf(of," <tt>{</tt>"); 643 | fprintf(of,"<td> \n"); 644 | } 645 | 646 | for(i=0;i<su->n_comp;i++) 647 | WriteHTMLStructUnion(su->comps[i],depth+1); 648 | 649 | if(HTML20) 650 | { 651 | fprintf(of,"<li><tt>}</tt><br>\n"); 652 | fprintf(of,"</ul>\n"); 653 | } 654 | else 655 | { 656 | fprintf(of,"<tr><td>"); 657 | for(i=0;i<depth;i++) 658 | fprintf(of," "); 659 | fprintf(of," <tt>}</tt>"); 660 | fprintf(of,"<td> \n"); 661 | } 662 | 663 | if(splitsu) 664 | { 665 | if(HTML20) 666 | { 667 | if(depth && su->comment) 668 | fprintf(of,"<li><tt>%s; </tt>%s<br>\n",splitsu[5]?html(&splitsu[6],0):"",html(su->comment,0)); 669 | else 670 | fprintf(of,"<li><tt>%s;</tt><br>\n",splitsu[5]?html(&splitsu[6],0):""); 671 | } 672 | else 673 | { 674 | fprintf(of,"<tr><td>"); 675 | for(i=0;i<depth;i++) 676 | fprintf(of," "); 677 | fprintf(of,"<tt>%s;</tt>",splitsu[5]?html(&splitsu[6],0):""); 678 | if(depth && su->comment) 679 | fprintf(of,"<td>%s\n",html(su->comment,0)); 680 | else 681 | fprintf(of,"<td> \n"); 682 | } 683 | } 684 | } 685 | 686 | if(splitsu) splitsu[-1]=' '; 687 | } 688 | 689 | 690 | /*++++++++++++++++++++++++++++++++++++++ 691 | Write a Variable structure out. 692 | 693 | Variable var The Variable structure to output. 694 | ++++++++++++++++++++++++++++++++++++++*/ 695 | 696 | static void WriteHTMLVariable(Variable var) 697 | { 698 | int i; 699 | 700 | if(var->scope&GLOBAL) 701 | fprintf(of,"\n<hr>\n<h2><a name=\"var-%s\">Global Variable %s</a></h2>\n",var->name,html(var->name,0)); 702 | else 703 | fprintf(of,"<b><a name=\"var-%s\">%s</a></b><br>\n",var->name,html(var->name,0)); 704 | 705 | if(var->comment) 706 | fprintf(of,"%s\n<p>\n",html(var->comment,0)); 707 | 708 | if(HTMLSRC) 709 | fprintf(of,"<tt><a href=\"%s%s%s#line%d\">",goback,filename,HTML_SRC_FILE,var->lineno); 710 | else 711 | fprintf(of,"<tt>"); 712 | 713 | if(var->scope&LOCAL) 714 | fprintf(of,"static "); 715 | else 716 | if(!(var->scope&GLOBAL) && var->scope&(EXTERNAL|EXTERN_F)) 717 | fprintf(of,"extern "); 718 | 719 | fprintf(of,"%s",html(var->type,0)); 720 | 721 | if(HTMLSRC) 722 | fprintf(of,"</a></tt><br>\n"); 723 | else 724 | fprintf(of,"</tt><br>\n"); 725 | 726 | if(var->scope&(GLOBAL|LOCAL)) 727 | { 728 | if(var->incfrom || var->visible->n || var->used->n) 729 | { 730 | if(HTML20) 731 | fprintf(of,"<dl compact>\n"); 732 | else 733 | fprintf(of,"<table>\n"); 734 | } 735 | 736 | if(var->incfrom) 737 | { 738 | if(HTML20) 739 | fprintf(of,"<dt>Included from:\n<dd><ul>\n"); 740 | else 741 | fprintf(of,"<tr><td>Included from\n"); 742 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",HTML20?"li":"td",goback,var->incfrom,var->name,html(var->incfrom,0)); 743 | if(HTML20) 744 | fprintf(of,"</ul>\n"); 745 | } 746 | 747 | if(var->visible->n) 748 | { 749 | for(i=0;i<var->visible->n;i++) 750 | { 751 | if(HTML20 && i==0) 752 | fprintf(of,"<dt>Visible in:\n<dd><ul>\n"); 753 | else if(HTML32 && i==0) 754 | fprintf(of,"<tr><td>Visible in:\n"); 755 | else if(HTML32) 756 | fprintf(of,"<tr><td> \n"); 757 | if(var->visible->s1[i][0]=='$' && !var->visible->s1[i][1]) 758 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td> <td",goback,var->visible->s2[i],html(var->visible->s2[i],0)); 759 | else 760 | if(HTML20) 761 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s1[i],0),html(var->visible->s2[i],0)); 762 | else 763 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,var->visible->s2[i],var->visible->s1[i],html(var->visible->s1[i],0),goback,var->visible->s2[i],var->visible->s1[i],html(va764 | r->visible->s2[i],0)); 765 | } 766 | if(HTML20) 767 | fprintf(of,"</ul>\n"); 768 | } 769 | 770 | if(var->used->n) 771 | { 772 | for(i=0;i<var->used->n;i++) 773 | { 774 | if(HTML20 && i==0) 775 | fprintf(of,"<dt>Used in:\n<dd><ul>\n"); 776 | else if(HTML32 && i==0) 777 | fprintf(of,"<tr><td>Used in:\n"); 778 | else if(HTML32) 779 | fprintf(of,"<tr><td> \n"); 780 | if(var->used->s1[i][0]=='$' && !var->used->s1[i][1]) 781 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td> <td",goback,var->used->s2[i],html(var->used->s2[i],0)); 782 | else 783 | { 784 | if(var->scope&LOCAL) 785 | fprintf(of,"<%s><a href=\"#func-%s\">%s()</a>\n",HTML20?"li":"td",var->used->s1[i],html(var->used->s1[i],0)); 786 | else 787 | if(HTML20) 788 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,var->used->s2[i],var->used->s1[i],html(var->used->s1[i],0),html(var->used->s2[i],0)); 789 | else 790 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,var->used->s2[i],var->used->s1[i],html(var->used->s1[i],0),goback,var->used->s2[i],var->used->s1[i],html(var->used->s2[791 | i],0)); 792 | } 793 | } 794 | if(HTML20) 795 | fprintf(of,"</ul>\n"); 796 | } 797 | 798 | if(var->incfrom || var->visible->n || var->used->n) 799 | { 800 | if(HTML20) 801 | fprintf(of,"</dl>\n"); 802 | else 803 | fprintf(of,"\n</table>\n"); 804 | } 805 | } 806 | else 807 | if(var->scope&(EXTERNAL|EXTERN_F) && var->defined) 808 | { 809 | if(HTML20) 810 | fprintf(of,"<dl compact>\n"); 811 | else 812 | fprintf(of,"<table>\n"); 813 | if(HTML20) 814 | fprintf(of,"<dt>Defined in:\n<dd><ul>\n"); 815 | else 816 | fprintf(of,"<tr><td>Defined in:\n"); 817 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",HTML20?"li":"td",goback,var->defined,html(var->name,0),var->defined); 818 | if(HTML20) 819 | fprintf(of,"</ul>\n</dl>\n"); 820 | else 821 | fprintf(of,"\n</table>\n"); 822 | } 823 | } 824 | 825 | 826 | /*++++++++++++++++++++++++++++++++++++++ 827 | Write a Function structure out. 828 | 829 | Function func The Function structure to output. 830 | ++++++++++++++++++++++++++++++++++++++*/ 831 | 832 | static void WriteHTMLFunction(Function func) 833 | { 834 | int i,pret,pargs; 835 | char* comment2=NULL,*type; 836 | 837 | if(func->scope&GLOBAL) 838 | fprintf(of,"\n<hr>\n<h2><a name=\"func-%s\">Global Function %s()</a></h2>\n",func->name,html(func->name,0)); 839 | else 840 | fprintf(of,"\n<hr>\n<h2><a name=\"func-%s\">Local Function %s()</a></h2>\n",func->name,html(func->name,0)); 841 | 842 | if(func->comment) 843 | { 844 | if(option_verbatim_comments) 845 | fprintf(of,"<pre>\n%s\n</pre>\n\n",html(func->comment,0)); 846 | else 847 | { 848 | comment2=strstr(func->comment,"\n\n"); 849 | if(comment2) 850 | comment2[0]=0; 851 | fprintf(of,"%s\n<p>\n",html(func->comment,0)); 852 | } 853 | } 854 | 855 | if(HTMLSRC) 856 | fprintf(of,"<tt><a href=\"%s%s%s#line%d\">",goback,filename,HTML_SRC_FILE,func->lineno); 857 | else 858 | fprintf(of,"<tt>"); 859 | 860 | if(func->scope&LOCAL) 861 | fprintf(of,"static "); 862 | if(func->scope&INLINED) 863 | fprintf(of,"inline "); 864 | 865 | if((type=strstr(func->type,"()"))) 866 | type[0]=0; 867 | fprintf(of,"%s ( ",html(func->type,0)); 868 | 869 | for(i=0;i<func->args->n;i++) 870 | fprintf(of,i?", %s":"%s",html(func->args->s1[i],0)); 871 | 872 | if(type) 873 | {fprintf(of," %s",html(&type[1],0));type[0]='(';} 874 | else 875 | fprintf(of," )"); 876 | 877 | if(HTMLSRC) 878 | fprintf(of,"</a></tt><br>\n"); 879 | else 880 | fprintf(of,"</tt><br>\n"); 881 | 882 | pret =strncmp("void ",func->type,5) && func->cret; 883 | for(pargs=0,i=0;i<func->args->n;i++) 884 | pargs = pargs || ( strcmp("void",func->args->s1[i]) && func->args->s2[i] ); 885 | 886 | if(pret || pargs) 887 | { 888 | fprintf(of,"<dl compact>\n"); 889 | if(pret) 890 | fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(func->type,0),func->cret?html(func->cret,0):"&nbs;"); 891 | if(pargs) 892 | for(i=0;i<func->args->n;i++) 893 | fprintf(of,"<dt><tt>%s</tt>\n<dd>%s\n",html(func->args->s1[i],0),func->args->s2[i]?html(func->args->s2[i],0):"&nbs;"); 894 | fprintf(of,"</dl>\n"); 895 | } 896 | 897 | if(comment2) 898 | { 899 | fprintf(of,"%s\n<p>\n",html(&comment2[2],0)); 900 | comment2[0]='\n'; 901 | } 902 | 903 | if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n) 904 | { 905 | if(HTML20) 906 | fprintf(of,"<dl compact>\n"); 907 | else 908 | fprintf(of,"<table>\n"); 909 | } 910 | 911 | if(func->protofile) 912 | { 913 | if(HTML20) 914 | fprintf(of,"<dt>Prototyped in:\n<dd><ul>\n"); 915 | else 916 | fprintf(of,"<tr><td>Prototyped in:\n"); 917 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td colspan=2",goback,func->protofile,html(func->protofile,0)); 918 | if(HTML20) 919 | fprintf(of,"</ul>\n"); 920 | } 921 | 922 | if(func->incfrom) 923 | { 924 | if(HTML20) 925 | fprintf(of,"<dt>Included from:\n<dd><ul>\n"); 926 | else 927 | fprintf(of,"<tr><td>Included from:\n"); 928 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",HTML20?"li":"td colspan=2",goback,func->incfrom,func->name,html(func->incfrom,0)); 929 | if(HTML20) 930 | fprintf(of,"</ul>\n"); 931 | } 932 | 933 | if(func->calls->n) 934 | { 935 | int others=0; 936 | 937 | if(HTML20) 938 | fprintf(of,"<dt>Calls:\n<dd><ul>\n"); 939 | else 940 | fprintf(of,"<tr><td>Calls:\n"); 941 | 942 | for(i=0;i<func->calls->n;i++) 943 | if(func->calls->s2[i]) 944 | { 945 | if(HTML32 && i!=others) 946 | fprintf(of,"<tr><td> \n"); 947 | if(HTML20) 948 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s1[i],0),html(func->calls->s2[i],0)); 949 | else 950 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->calls->s2[i],func->calls->s1[i],html(func->calls->s1[i],0),goback,func->calls->s2[i],func->calls->s1[i],html(func->call951 | s->s2[i],0)); 952 | } 953 | else 954 | others++; 955 | 956 | if(others) 957 | { 958 | if(HTML20) 959 | fprintf(of,"<li>"); 960 | else if(i==others) 961 | fprintf(of,"<td colspan=2>"); 962 | else 963 | fprintf(of,"<tr><td> \n<td colspan=2>"); 964 | for(i=0;i<func->calls->n;i++) 965 | if(!func->calls->s2[i]) 966 | fprintf(of,--others?"%s(), ":"%s()",html(func->calls->s1[i],0)); 967 | fprintf(of,"\n"); 968 | } 969 | 970 | if(HTML20) 971 | fprintf(of,"</ul>\n"); 972 | } 973 | 974 | if(func->called->n) 975 | { 976 | if(HTML20) 977 | fprintf(of,"<dt>Called by:\n<dd><ul>\n"); 978 | else 979 | fprintf(of,"<tr><td>Called by:\n"); 980 | for(i=0;i<func->called->n;i++) 981 | { 982 | if(HTML32 && i!=0) 983 | fprintf(of,"<tr><td> \n"); 984 | if(HTML20) 985 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->called->s2[i],func->called->s1[i],html(func->called->s1[i],0),html(func->called->s2[i],0)); 986 | else 987 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->called->s2[i],func->called->s1[i],html(func->called->s1[i],0),goback,func->called->s2[i],func->called->s1[i],html(func->ca988 | lled->s2[i],0)); 989 | } 990 | if(HTML20) 991 | fprintf(of,"</ul>\n"); 992 | } 993 | 994 | if(func->used->n) 995 | { 996 | if(HTML20) 997 | fprintf(of,"<dt>Used in:\n<dd><ul>\n"); 998 | else 999 | fprintf(of,"<tr><td>Used in:\n"); 1000 | for(i=0;i<func->used->n;i++) 1001 | { 1002 | if(HTML32 && i!=0) 1003 | fprintf(of,"<tr><td> \n"); 1004 | if(func->used->s1[i][0]=='$' && !func->used->s1[i][1]) 1005 | fprintf(of,"<%s><a href=\"%s%s"HTML_FILE"#file\">%s</a>\n",HTML20?"li":"td> <td",goback,func->used->s2[i],html(func->used->s2[i],0)); 1006 | else 1007 | if(HTML20) 1008 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->used->s2[i],func->used->s1[i],html(func->used->s1[i],0),html(func->used->s2[i],0)); 1009 | else 1010 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->used->s2[i],func->used->s1[i],html(func->used->s1[i],0),goback,func->used->s2[i],func->used->s1[i],html(func->used->s2[1011 | i],0)); 1012 | } 1013 | if(HTML20) 1014 | fprintf(of,"</ul>\n"); 1015 | } 1016 | 1017 | if(func->f_refs->n) 1018 | { 1019 | int others=0; 1020 | 1021 | if(HTML20) 1022 | fprintf(of,"<dt>References Functions:\n<dd><ul>\n"); 1023 | else 1024 | fprintf(of,"<tr><td>References Functions:\n"); 1025 | 1026 | for(i=0;i<func->f_refs->n;i++) 1027 | if(func->f_refs->s2[i]) 1028 | { 1029 | if(HTML32 && i!=others) 1030 | fprintf(of,"<tr><td> \n"); 1031 | if(HTML20) 1032 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s1[i],0),html(func->f_refs->s2[i],0)); 1033 | else 1034 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#func-%s\">%s()</a><td><a href=\"%s%s"HTML_FILE"#func-%s\">%s</a>\n",goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func->f_refs->s1[i],0),goback,func->f_refs->s2[i],func->f_refs->s1[i],html(func-1035 | >f_refs->s2[i],0)); 1036 | } 1037 | else 1038 | others++; 1039 | 1040 | if(others) 1041 | { 1042 | if(HTML20) 1043 | fprintf(of,"<li>"); 1044 | else if(i==others) 1045 | fprintf(of,"<td colspan=2>"); 1046 | else 1047 | fprintf(of,"<tr><td> \n<td colspan=2>"); 1048 | for(i=0;i<func->f_refs->n;i++) 1049 | if(!func->f_refs->s2[i]) 1050 | fprintf(of,--others?"%s(), ":"%s()",html(func->f_refs->s1[i],0)); 1051 | fprintf(of,"\n"); 1052 | } 1053 | 1054 | if(HTML20) 1055 | fprintf(of,"</ul>\n"); 1056 | } 1057 | 1058 | if(func->v_refs->n) 1059 | { 1060 | int others=0; 1061 | 1062 | if(HTML20) 1063 | fprintf(of,"<dt>References Variables:\n<dd><ul>\n"); 1064 | else 1065 | fprintf(of,"<tr><td>References Variables:\n"); 1066 | 1067 | for(i=0;i<func->v_refs->n;i++) 1068 | if(func->v_refs->s2[i]) 1069 | { 1070 | if(HTML32 && i!=others) 1071 | fprintf(of,"<tr><td> \n"); 1072 | if(HTML20) 1073 | fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s : %s</a>\n",goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s1[i],0),html(func->v_refs->s2[i],0)); 1074 | else 1075 | fprintf(of,"<td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a><td><a href=\"%s%s"HTML_FILE"#var-%s\">%s</a>\n",goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_refs->s1[i],0),goback,func->v_refs->s2[i],func->v_refs->s1[i],html(func->v_r1076 | efs->s2[i],0)); 1077 | } 1078 | else 1079 | others++; 1080 | 1081 | if(others) 1082 | { 1083 | if(HTML20) 1084 | fprintf(of,"<li>"); 1085 | else if(i==others) 1086 | fprintf(of,"<td colspan=2>"); 1087 | else 1088 | fprintf(of,"<tr><td> \n<td colspan=2>"); 1089 | for(i=0;i<func->v_refs->n;i++) 1090 | if(!func->v_refs->s2[i]) 1091 | fprintf(of,--others?"%s, ":"%s",html(func->v_refs->s1[i],0)); 1092 | fprintf(of,"\n"); 1093 | } 1094 | 1095 | if(HTML20) 1096 | fprintf(of,"</ul>\n"); 1097 | } 1098 | 1099 | if(func->protofile || func->incfrom || func->calls->n || func->called->n || func->used->n || func->f_refs->n || func->v_refs->n) 1100 | { 1101 | if(HTML20) 1102 | fprintf(of,"</dl>\n"); 1103 | else 1104 | fprintf(of,"\n</table>\n"); 1105 | } 1106 | } 1107 | 1108 | 1109 | /*++++++++++++++++++++++++++++++++++++++ 1110 | Write out a file that will include the current information. 1111 | 1112 | char* name The name of the file. 1113 | 1114 | int appendix set to non-zero if the appendix file is to be added, else a normal source file. 1115 | ++++++++++++++++++++++++++++++++++++++*/ 1116 | 1117 | static void WriteHTMLDocument(char* name,int appendix) 1118 | { 1119 | FILE *in,*out; 1120 | char line[256]; 1121 | int seen=0; 1122 | char *inc_file,*ofile,*ifile; 1123 | 1124 | if(appendix) 1125 | inc_file=ConcatStrings(4,"<a href=\"",name,HTML_FILE,"\">Appendix</a><br>\n"); 1126 | else 1127 | inc_file=ConcatStrings(6,"<a href=\"",name,HTML_FILE,"#file\">",name,"</a><br>\n"); 1128 | ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE); 1129 | ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP); 1130 | 1131 | in =fopen(ifile,"r"); 1132 | if(!in) 1133 | { 1134 | in =fopen(ifile,"w"); 1135 | if(!in) 1136 | {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ifile);exit(1);} 1137 | 1138 | WriteHTMLPreamble(in,ConcatStrings(3,"Cross Reference Of ",option_name,"."),1); 1139 | WriteHTMLPostamble(in,1); 1140 | fclose(in); 1141 | 1142 | in =fopen(ifile,"r"); 1143 | } 1144 | 1145 | out=fopen(ofile,"w"); 1146 | 1147 | if(!out) 1148 | {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ofile);exit(1);} 1149 | 1150 | while(fgets(line,256,in)) 1151 | { 1152 | if(!strcmp(inc_file,line) || 1153 | (!strncmp("<!--",line,4) && !strncmp(inc_file,line+4,strlen(inc_file))) || 1154 | (!strncmp("<!-- ",line,5) && !strncmp(inc_file,line+5,strlen(inc_file)))) 1155 | {seen=1;break;} 1156 | if(line[0]=='<' && !strcmp("<!-- End-Of-Source-Files -->\n",line)) 1157 | { 1158 | if(appendix) 1159 | { 1160 | fputs(line,out); 1161 | fputs("\n",out); 1162 | fputs("<!-- Appendix -->\n",out); 1163 | fputs("\n",out); 1164 | fputs("<hr>\n",out); 1165 | fputs("<h1>Appendix</h1>\n",out); 1166 | fputs("\n",out); 1167 | fputs(inc_file,out); 1168 | } 1169 | else 1170 | { 1171 | fputs(inc_file,out); 1172 | fputs("\n",out); 1173 | fputs(line,out); 1174 | } 1175 | } 1176 | else 1177 | fputs(line,out); 1178 | } 1179 | 1180 | fclose(in); 1181 | fclose(out); 1182 | 1183 | if(!seen) 1184 | { 1185 | unlink(ifile); 1186 | rename(ofile,ifile); 1187 | } 1188 | else 1189 | unlink(ofile); 1190 | } 1191 | 1192 | 1193 | /*++++++++++++++++++++++++++++++++++++++ 1194 | Write out a standard pre-amble. 1195 | 1196 | FILE* f The file to write the pre amble to. 1197 | 1198 | char* title The title of the file. 1199 | 1200 | int sourcefile True if the Source-Files line is to be included. 1201 | ++++++++++++++++++++++++++++++++++++++*/ 1202 | 1203 | static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile) 1204 | { 1205 | if(HTML20) 1206 | fputs("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n",f); 1207 | else 1208 | fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n",f); 1209 | fputs("\n",f); 1210 | fputs("<!-- This HTML file generated by cxref. -->\n",f); 1211 | fputs("<!-- cxref program (c) Andrew M. Bishop 1995,96,97,98,99. -->\n",f); 1212 | fputs("\n",f); 1213 | if(!sourcefile) 1214 | { 1215 | fputs("<!--\n",f); 1216 | if(filename) 1217 | fprintf(f,"Cxref: %s %s\n",run_command,filename); 1218 | else 1219 | fprintf(f,"Cxref: %s\n",run_command); 1220 | fprintf(f,"CPP : %s\n",run_cpp_command); 1221 | fputs("-->\n",f); 1222 | fputs("\n",f); 1223 | } 1224 | fputs("<HTML>\n",f); 1225 | fputs("\n",f); 1226 | fputs("<HEAD>\n",f); 1227 | fputs("<TITLE>",f); 1228 | fputs(title,f); 1229 | fputs("</TITLE>\n",f); 1230 | fputs("</HEAD>\n",f); 1231 | fputs("\n",f); 1232 | fputs("<BODY>\n",f); 1233 | fputs("\n",f); 1234 | if(sourcefile) 1235 | { 1236 | fputs("<h1>Source Files</h1>\n",f); 1237 | fputs("\n",f); 1238 | fputs("<!-- Begin-Of-Source-Files -->\n",f); 1239 | } 1240 | } 1241 | 1242 | 1243 | /*++++++++++++++++++++++++++++++++++++++ 1244 | Write out a standard post-amble. This includes the end of document marker. 1245 | 1246 | FILE* f The file to write the post amble to. 1247 | 1248 | int sourcefile True if the Source-Files line is to be included. 1249 | ++++++++++++++++++++++++++++++++++++++*/ 1250 | 1251 | static void WriteHTMLPostamble(FILE* f,int sourcefile) 1252 | { 1253 | if(sourcefile) 1254 | { 1255 | fputs("\n",f); 1256 | fputs("<!-- End-Of-Source-Files -->\n",f); 1257 | } 1258 | fputs("\n",f); 1259 | fputs("</BODY>\n",f); 1260 | fputs("</HTML>\n",f); 1261 | } 1262 | 1263 | 1264 | /*++++++++++++++++++++++++++++++++++++++ 1265 | Write out the appendix information. 1266 | 1267 | StringList files The list of files to write. 1268 | 1269 | StringList2 funcs The list of functions to write. 1270 | 1271 | StringList2 vars The list of variables to write. 1272 | 1273 | StringList2 types The list of types to write. 1274 | ++++++++++++++++++++++++++++++++++++++*/ 1275 | 1276 | void WriteHTMLAppendix(StringList files,StringList2 funcs,StringList2 vars,StringList2 types) 1277 | { 1278 | char* ofile; 1279 | int i; 1280 | 1281 | filename=NULL; 1282 | 1283 | /* Write the bits to the including file. */ 1284 | 1285 | WriteHTMLDocument(ConcatStrings(2,option_name,HTML_APDX),1); 1286 | 1287 | /* Open the file */ 1288 | 1289 | ofile=ConcatStrings(5,option_odir,"/",option_name,HTML_APDX,HTML_FILE); 1290 | 1291 | of=fopen(ofile,"w"); 1292 | 1293 | if(!of) 1294 | {fprintf(stderr,"cxref: Failed to open the HTML appendix file '%s'\n",ofile);exit(1);} 1295 | 1296 | /* Write the file structure out */ 1297 | 1298 | WriteHTMLPreamble(of,ConcatStrings(3,"Cross reference index of ",option_name,"."),0); 1299 | 1300 | fprintf(of,"<h1>Cross References</h1>\n"); 1301 | 1302 | /* Write out the appendix of files. */ 1303 | 1304 | if(files->n) 1305 | { 1306 | fprintf(of,"\n<hr>\n<h2><a name=\"files\">Files</a></h2>\n"); 1307 | fprintf(of,"<ul>\n"); 1308 | for(i=0;i<files->n;i++) 1309 | fprintf(of,"<li><a href=\"%s"HTML_FILE"#file\">%s</a>\n",files->s[i],html(files->s[i],0)); 1310 | fprintf(of,"</ul>\n"); 1311 | } 1312 | 1313 | /* Write out the appendix of functions. */ 1314 | 1315 | if(funcs->n) 1316 | { 1317 | fprintf(of,"\n<hr>\n<h2><a name=\"functions\">Global Functions</a></h2>\n"); 1318 | fprintf(of,"<ul>\n"); 1319 | for(i=0;i<funcs->n;i++) 1320 | fprintf(of,"<li><a href=\"%s"HTML_FILE"#func-%s\">%s() : %s</a>\n",funcs->s2[i],funcs->s1[i],html(funcs->s1[i],0),html(funcs->s2[i],0)); 1321 | fprintf(of,"</ul>\n"); 1322 | } 1323 | 1324 | /* Write out the appendix of variables. */ 1325 | 1326 | if(vars->n) 1327 | { 1328 | fprintf(of,"\n<hr>\n<h2><a name=\"variables\">Global Variables</a></h2>\n"); 1329 | fprintf(of,"<ul>\n"); 1330 | for(i=0;i<vars->n;i++) 1331 | fprintf(of,"<li><a href=\"%s"HTML_FILE"#var-%s\">%s : %s</a>\n",vars->s2[i],vars->s1[i],html(vars->s1[i],0),html(vars->s2[i],0)); 1332 | fprintf(of,"</ul>\n"); 1333 | } 1334 | 1335 | /* Write out the appendix of types. */ 1336 | 1337 | if(types->n) 1338 | { 1339 | fprintf(of,"\n<hr>\n<h2><a name=\"types\">Defined Types</a></h2>\n"); 1340 | fprintf(of,"<ul>\n"); 1341 | for(i=0;i<types->n;i++) 1342 | if(!strncmp("enum",types->s1[i],4)) 1343 | fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-enum-%s\">%s : %s</a>\n",types->s2[i],&types->s1[i][5],html(types->s1[i],0),html(types->s2[i],0)); 1344 | else 1345 | if(!strncmp("union",types->s1[i],5)) 1346 | fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-union-%s\">%s : %s</a>\n",types->s2[i],&types->s1[i][6],html(types->s1[i],0),html(types->s2[i],0)); 1347 | else 1348 | if(!strncmp("struct",types->s1[i],6)) 1349 | fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-struct-%s\">%s : %s</a>\n",types->s2[i],&types->s1[i][7],html(types->s1[i],0),html(types->s2[i],0)); 1350 | else 1351 | fprintf(of,"<li><a href=\"%s"HTML_FILE"#type-%s\">%s : %s</a>\n",types->s2[i],types->s1[i],html(types->s1[i],0),html(types->s2[i],0)); 1352 | fprintf(of,"</ul>\n"); 1353 | } 1354 | 1355 | WriteHTMLPostamble(of,0); 1356 | 1357 | fclose(of); 1358 | 1359 | /* Clear the memory in html(,0) */ 1360 | 1361 | html(NULL,0); html(NULL,0); html(NULL,0); html(NULL,0); 1362 | } 1363 | 1364 | 1365 | /*++++++++++++++++++++++++++++++++++++++ 1366 | Delete the HTML file and main file reference that belong to the named file. 1367 | 1368 | char *name The name of the file to delete. 1369 | ++++++++++++++++++++++++++++++++++++++*/ 1370 | 1371 | void WriteHTMLFileDelete(char *name) 1372 | { 1373 | FILE *in,*out; 1374 | char line[256]; 1375 | int seen=0; 1376 | char *inc_file,*ofile,*ifile; 1377 | 1378 | ofile=ConcatStrings(4,option_odir,"/",name,HTML_FILE); 1379 | unlink(ofile); 1380 | 1381 | inc_file=ConcatStrings(6,"<a href=\"",name,HTML_FILE,"#file\">",name,"</a><br>\n"); 1382 | ifile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE); 1383 | ofile=ConcatStrings(4,option_odir,"/",option_name,HTML_FILE_BACKUP); 1384 | 1385 | in =fopen(ifile,"r"); 1386 | out=fopen(ofile,"w"); 1387 | 1388 | if(in && !out) 1389 | {fprintf(stderr,"cxref: Failed to open the main HTML output file '%s'\n",ofile);fclose(in);} 1390 | else if(in) 1391 | { 1392 | while(fgets(line,256,in)) 1393 | { 1394 | if(!strcmp(inc_file,line) || 1395 | (!strncmp("<!--",line,4) && !strncmp(inc_file,line+4,strlen(inc_file)-1)) || 1396 | (!strncmp("<!-- ",line,5) && !strncmp(inc_file,line+5,strlen(inc_file)-1))) 1397 | seen=1; 1398 | else 1399 | fputs(line,out); 1400 | } 1401 | 1402 | fclose(in); 1403 | fclose(out); 1404 | 1405 | if(seen) 1406 | { 1407 | unlink(ifile); 1408 | rename(ofile,ifile); 1409 | } 1410 | else 1411 | unlink(ofile); 1412 | } 1413 | else if(out) 1414 | { 1415 | fclose(out); 1416 | unlink(ofile); 1417 | } 1418 | } 1419 | 1420 | 1421 | /*++++++++++++++++++++++++++++++++++++++ 1422 | Write out the source file. 1423 | 1424 | char *name The name of the source file. 1425 | ++++++++++++++++++++++++++++++++++++++*/ 1426 | 1427 | void WriteHTMLSource(char *name) 1428 | { 1429 | FILE *in,*out; 1430 | char line[256]; 1431 | char *ofile,*ifile; 1432 | int lineno=0; 1433 | char pad[5]; 1434 | 1435 | ifile=name; 1436 | ofile=ConcatStrings(4,option_odir,"/",name,HTML_SRC_FILE); 1437 | 1438 | in =fopen(ifile,"r"); 1439 | if(!in) 1440 | {fprintf(stderr,"cxref: Failed to open the source file '%s'\n",ifile);exit(1);} 1441 | 1442 | out=fopen(ofile,"w"); 1443 | if(!out) 1444 | {fprintf(stderr,"cxref: Failed to open the HTML output source file '%s'\n",ofile);exit(1);} 1445 | 1446 | WriteHTMLPreamble(out,ConcatStrings(2,"Source File ",name),0); 1447 | fputs("<pre>\n",out); 1448 | 1449 | strcpy(pad," "); 1450 | 1451 | while(fgets(line,256,in)) 1452 | { 1453 | lineno++; 1454 | if(lineno==10) 1455 | pad[3]=0; 1456 | else if(lineno==100) 1457 | pad[2]=0; 1458 | else if(lineno==1000) 1459 | pad[1]=0; 1460 | else if(lineno==10000) 1461 | pad[0]=0; 1462 | fprintf(out,"<a name=\"line%d\">%d%s|</a> %s",lineno,lineno,pad,html(line,1)); 1463 | } 1464 | 1465 | fputs("</pre>\n",out); 1466 | WriteHTMLPostamble(out,0); 1467 | 1468 | fclose(in); 1469 | fclose(out); 1470 | } 1471 | 1472 | 1473 | /*++++++++++++++++++++++++++++++++++++++ 1474 | Make the input string safe to output as HTML ( not <, >, & or " ). 1475 | 1476 | char* html Returns a safe HTML string. 1477 | 1478 | char* c A non-safe HTML string. 1479 | 1480 | int verbatim Set to true if the text is to be output verbatim ignoring the comment +html+ directives. 1481 | 1482 | The function can only be called four times in each fprintf() since it returns one of only four static strings. 1483 | ++++++++++++++++++++++++++++++++++++++*/ 1484 | 1485 | static char* html(char* c,int verbatim) 1486 | { 1487 | static char safe[4][256],*malloced[4]={NULL,NULL,NULL,NULL}; 1488 | static int which=0; 1489 | int copy=0,skip=0; 1490 | int i=0,j=0,delta=7,len=256-delta; 1491 | char* ret; 1492 | 1493 | which=(which+1)%4; 1494 | ret=safe[which]; 1495 | 1496 | safe[which][0]=0; 1497 | 1498 | if(malloced[which]) 1499 | {Free(malloced[which]);malloced[which]=NULL;} 1500 | 1501 | if(c) 1502 | { 1503 | if(!verbatim) 1504 | i=CopyOrSkip(c,"html",©,&skip); 1505 | 1506 | while(1) 1507 | { 1508 | for(;j<len && c[i];i++) 1509 | { 1510 | if(copy) 1511 | {ret[j++]=c[i]; if(c[i]=='\n') copy=0;} 1512 | else if(skip) 1513 | { if(c[i]=='\n') skip=0;} 1514 | else 1515 | switch(c[i]) 1516 | { 1517 | case '<': 1518 | strcpy(&ret[j],"<");j+=4; 1519 | break; 1520 | case '>': 1521 | strcpy(&ret[j],">");j+=4; 1522 | break; 1523 | case '"': 1524 | strcpy(&ret[j],""");j+=6; 1525 | break; 1526 | case '&': 1527 | strcpy(&ret[j],"&");j+=5; 1528 | break; 1529 | case '\n': 1530 | if(j && ret[j-1]=='\n') 1531 | { 1532 | strcpy(&ret[j],"<br>");j+=4; 1533 | } 1534 | ret[j++]=c[i]; 1535 | break; 1536 | default: 1537 | ret[j++]=c[i]; 1538 | } 1539 | if(c[i]=='\n') 1540 | if(!verbatim) 1541 | i+=CopyOrSkip(c+i,"html",©,&skip); 1542 | } 1543 | 1544 | if(c[i]) /* Not finished */ 1545 | { 1546 | if(malloced[which]) 1547 | malloced[which]=Realloc(malloced[which],len+delta+256); 1548 | else 1549 | {malloced[which]=Malloc(len+delta+256); strncpy(malloced[which],ret,(unsigned)j);} 1550 | ret=malloced[which]; 1551 | len+=256; 1552 | } 1553 | else 1554 | {ret[j]=0; break;} 1555 | } 1556 | } 1557 | 1558 | return(ret); 1559 | }