1 /***************************************
4 C Cross Referencing & Documentation tool. Version 1.5f.
6 Writes the SGML output.
7 ******************/ /******************
8 Written by Andrew M. Bishop
10 This file Copyright 1995,96,97,98,2001,04 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 ***************************************/
19 #include <sys/types.h>
27 /*+ The name of the output tex file that includes each of the others. +*/
28 #define SGML_FILE ".sgml"
29 #define SGML_FILE_BACKUP ".sgml~"
31 /*+ The name of the output tex file that contains the appendix. +*/
32 #define SGML_APDX ".apdx"
34 /*+ The comments are to be inserted verbatim. +*/
35 extern int option_verbatim_comments
;
37 /*+ The name of the directory for the output. +*/
38 extern char* option_odir
;
40 /*+ The base name of the file for the output. +*/
41 extern char* option_name
;
43 /*+ The information about the cxref run, +*/
44 extern char *run_command
, /*+ the command line options. +*/
45 *run_cpp_command
; /*+ the cpp command and options. +*/
47 /*+ The directories to go back to get to the base output directory. +*/
48 static char* goback
=NULL
;
50 static void WriteSGMLFilePart(File file
);
51 static void WriteSGMLInclude(Include inc
);
52 static void WriteSGMLSubInclude(Include inc
,int depth
);
53 static void WriteSGMLDefine(Define def
);
54 static void WriteSGMLTypedef(Typedef type
);
55 static void WriteSGMLStructUnion(StructUnion su
,int depth
);
56 static void WriteSGMLVariable(Variable var
);
57 static void WriteSGMLFunction(Function func
);
59 static void WriteSGMLPreamble(FILE* f
,char* title
);
60 static void WriteSGMLPostamble(FILE* f
);
62 static char* sgml(char* c
,int verbatim
);
64 /*+ The output file for the SGML. +*/
67 /*+ The name of the file. +*/
68 static char *filename
;
71 /*++++++++++++++++++++++++++++++++++++++
72 Write an sgml file for a complete File structure and all components.
74 File file The File structure to output.
75 ++++++++++++++++++++++++++++++++++++++*/
77 void WriteSGMLFile(File file
)
86 ofile
=ConcatStrings(4,option_odir
,"/",file
->name
,SGML_FILE
);
92 int i
,ofl
=strlen(ofile
);
94 for(i
=strlen(option_odir
)+1;i
<ofl
;i
++)
98 if(stat(ofile
,&stat_buf
))
99 mkdir(ofile
,S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IXGRP
|S_IROTH
|S_IXOTH
);
107 {fprintf(stderr
,"cxref: Failed to open the SGML output file '%s'\n",ofile
);exit(1);}
109 for(goback
="",i
=strlen(file
->name
);i
>0;i
--)
110 if(file
->name
[i
]=='/')
111 goback
=ConcatStrings(2,goback
,"../");
113 /* Write out a header. */
115 WriteSGMLPreamble(of
,ConcatStrings(5,"Cross reference for ",file
->name
," of ",option_name
,"."));
117 /*+ The file structure is broken into its components and they are each written out. +*/
119 WriteSGMLFilePart(file
);
123 Include inc
=file
->includes
;
124 fprintf(of
,"\n<sect1>Included Files\n\n<p>\n");
126 WriteSGMLInclude(inc
);
128 while((inc
=inc
->next
));
133 Define def
=file
->defines
;
134 fprintf(of
,"\n<sect1>Preprocessor definitions\n\n<p>\n");
136 if(def
!=file
->defines
)
138 WriteSGMLDefine(def
);
140 while((def
=def
->next
));
145 Typedef type
=file
->typedefs
;
147 WriteSGMLTypedef(type
);
149 while((type
=type
->next
));
154 int any_to_mention
=0;
155 Variable var
=file
->variables
;
158 if(var
->scope
&(GLOBAL
|LOCAL
|EXTERNAL
|EXTERN_F
))
161 while((var
=var
->next
));
165 int first_ext
=1,first_local
=1;
166 Variable var
=file
->variables
;
168 if(var
->scope
&GLOBAL
)
169 WriteSGMLVariable(var
);
171 while((var
=var
->next
));
174 if(var
->scope
&(EXTERNAL
|EXTERN_F
) && !(var
->scope
&GLOBAL
))
177 {fprintf(of
,"\n<sect1>External Variables\n\n"); first_ext
=0;}
179 WriteSGMLVariable(var
);
182 while((var
=var
->next
));
188 {fprintf(of
,"\n<sect1>Local Variables\n\n"); first_local
=0;}
190 WriteSGMLVariable(var
);
193 while((var
=var
->next
));
199 Function func
=file
->functions
;
201 if(func
->scope
&(GLOBAL
|EXTERNAL
))
202 WriteSGMLFunction(func
);
204 while((func
=func
->next
));
205 func
=file
->functions
;
207 if(func
->scope
&LOCAL
)
208 WriteSGMLFunction(func
);
210 while((func
=func
->next
));
213 WriteSGMLPostamble(of
);
217 /* Clear the memory in sgml() */
219 sgml(NULL
,0); sgml(NULL
,0); sgml(NULL
,0); sgml(NULL
,0);
223 /*++++++++++++++++++++++++++++++++++++++
224 Write a File structure out.
226 File file The File to output.
227 ++++++++++++++++++++++++++++++++++++++*/
229 static void WriteSGMLFilePart(File file
)
233 fprintf(of
,"<sect>File %s\n",sgml(file
->name
,0));
237 if(option_verbatim_comments
)
238 fprintf(of
,"<p><tscreen><verb>\n%s\n</verb></tscreen>\n\n",sgml(file
->comment
,1));
241 char *rcs1
=strstr(file
->comment
,"$Header"),*rcs2
=NULL
;
244 rcs2
=strstr(&rcs1
[1],"$");
248 fprintf(of
,"<bf>RCS %s</bf>\n<p>\n",sgml(&rcs1
[1],0));
253 fprintf(of
,"%s\n<p>\n",sgml(&rcs2
[2],0));
255 fprintf(of
,"%s\n<p>\n",sgml(file
->comment
,0));
263 fprintf(of
,"<p>\n<descrip>\n<tag>Included in:</tag>\n<itemize>\n");
264 for(i
=0;i
<file
->inc_in
->n
;i
++)
265 fprintf(of
,"<item>%s\n",sgml(file
->inc_in
->s
[i
],0));
266 fprintf(of
,"</itemize>\n</descrip>\n");
269 if(file
->f_refs
->n
|| file
->v_refs
->n
)
270 fprintf(of
,"<descrip>\n");
275 fprintf(of
,"<tag>References Functions:</tag>\n<itemize>\n");
276 for(i
=0;i
<file
->f_refs
->n
;i
++)
277 if(file
->f_refs
->s2
[i
])
278 fprintf(of
,"<item>%s() : %s\n",sgml(file
->f_refs
->s1
[i
],0),sgml(file
->f_refs
->s2
[i
],0));
284 fprintf(of
,"<item>");
285 for(i
=0;i
<file
->f_refs
->n
;i
++)
286 if(!file
->f_refs
->s2
[i
])
287 fprintf(of
,--others
?" %s(),":" %s()",sgml(file
->f_refs
->s1
[i
],0));
290 fprintf(of
,"</itemize>\n");
296 fprintf(of
,"<tag>References Variables:</tag>\n<itemize>\n");
297 for(i
=0;i
<file
->v_refs
->n
;i
++)
299 if(file
->v_refs
->s2
[i
])
300 fprintf(of
,"<item>%s : %s\n",sgml(file
->v_refs
->s1
[i
],0),sgml(file
->v_refs
->s2
[i
],0));
307 fprintf(of
,"<item>");
308 for(i
=0;i
<file
->v_refs
->n
;i
++)
309 if(!file
->v_refs
->s2
[i
])
310 fprintf(of
,--others
?" %s,":" %s",sgml(file
->v_refs
->s1
[i
],0));
313 fprintf(of
,"</itemize>\n");
316 if(file
->f_refs
->n
|| file
->v_refs
->n
)
317 fprintf(of
,"</descrip>\n");
321 /*++++++++++++++++++++++++++++++++++++++
322 Write an Include structure out.
324 Include inc The Include structure to output.
325 ++++++++++++++++++++++++++++++++++++++*/
327 static void WriteSGMLInclude(Include inc
)
330 fprintf(of
,"%s\n<p>\n",sgml(inc
->comment
,0));
332 fprintf(of
,"<itemize>\n");
334 if(inc
->scope
==LOCAL
)
335 fprintf(of
,"<item><tt>#include "%s"</tt>\n",sgml(inc
->name
,0));
337 fprintf(of
,"<item><tt>#include <%s></tt>\n",sgml(inc
->name
,0));
340 WriteSGMLSubInclude(inc
->includes
,1);
342 fprintf(of
,"</itemize>\n");
346 /*++++++++++++++++++++++++++++++++++++++
347 Write an Sub Include structure out. (An include structure that is included from another file.)
349 Include inc The Include structure to output.
351 int depth The depth of the include hierarchy.
352 ++++++++++++++++++++++++++++++++++++++*/
354 static void WriteSGMLSubInclude(Include inc
,int depth
)
356 fprintf(of
,"<itemize>\n");
360 if(inc
->scope
==LOCAL
)
361 fprintf(of
,"<item><tt>#include "%s"</tt>\n",sgml(inc
->name
,0));
363 fprintf(of
,"<item><tt>#include <%s></tt>\n",sgml(inc
->name
,0));
366 WriteSGMLSubInclude(inc
->includes
,depth
+1);
371 fprintf(of
,"</itemize>\n");
375 /*++++++++++++++++++++++++++++++++++++++
376 Write a Define structure out.
378 Define def The Define structure to output.
379 ++++++++++++++++++++++++++++++++++++++*/
381 static void WriteSGMLDefine(Define def
)
387 fprintf(of
,"%s\n<p>\n",sgml(def
->comment
,0));
389 fprintf(of
,"<tt>#define %s",sgml(def
->name
,0));
392 fprintf(of
," %s",sgml(def
->value
,0));
397 for(i
=0;i
<def
->args
->n
;i
++)
398 fprintf(of
,i
?", %s":"%s",sgml(def
->args
->s1
[i
],0));
401 fprintf(of
,"</tt><newline>\n");
403 for(i
=0;i
<def
->args
->n
;i
++)
409 fprintf(of
,"<descrip>\n");
410 for(i
=0;i
<def
->args
->n
;i
++)
411 fprintf(of
,"<tag><tt>%s</tt></tag>\n%s\n",sgml(def
->args
->s1
[i
],0),def
->args
->s2
[i
]?sgml(def
->args
->s2
[i
],0):"");
412 fprintf(of
,"</descrip>\n");
417 /*++++++++++++++++++++++++++++++++++++++
418 Write a Typedef structure out.
420 Typedef type The Typedef structure to output.
421 ++++++++++++++++++++++++++++++++++++++*/
423 static void WriteSGMLTypedef(Typedef type
)
425 fprintf(of
,"\n<sect1>");
428 fprintf(of
,"Typedef %s",sgml(type
->name
,0));
430 fprintf(of
,"Type %s",sgml(type
->name
,0));
432 fprintf(of
,"\n\n<p>\n");
435 fprintf(of
,"%s\n<p>\n",sgml(type
->comment
,0));
438 fprintf(of
,"<tt>typedef %s</tt><newline>\n",sgml(type
->type
,0));
442 fprintf(of
,"<itemize>\n");
443 WriteSGMLStructUnion(type
->sutype
,0);
444 fprintf(of
,"</itemize>\n");
449 fprintf(of
,"<descrip>\n<tag>See:</tag>\n<itemize>\n");
450 if(type
->typexref
->type
)
451 fprintf(of
,"<item>Typedef %s\n",sgml(type
->typexref
->name
,0));
453 if(!strncmp("enum",type
->typexref
->name
,4))
454 fprintf(of
,"<item>Type %s\n",sgml(type
->typexref
->name
,0));
456 if(!strncmp("union",type
->typexref
->name
,5))
457 fprintf(of
,"<item>Type %s\n",sgml(type
->typexref
->name
,0));
459 if(!strncmp("struct",type
->typexref
->name
,6))
460 fprintf(of
,"<item>Type %s\n",sgml(type
->typexref
->name
,0));
461 fprintf(of
,"</itemize>\n</descrip>\n");
466 /*++++++++++++++++++++++++++++++++++++++
467 Write a structure / union structure out.
469 StructUnion su The structure / union to write.
471 int depth The current depth within the structure.
472 ++++++++++++++++++++++++++++++++++++++*/
474 static void WriteSGMLStructUnion(StructUnion su
, int depth
)
479 splitsu
=strstr(su
->name
,"{...}");
480 if(splitsu
) splitsu
[-1]=0;
482 if(depth
&& su
->comment
&& !su
->comps
)
483 fprintf(of
,"<item><tt>%s; </tt>%s<newline>\n",sgml(su
->name
,0),sgml(su
->comment
,0));
484 else if(!depth
|| su
->comps
)
485 fprintf(of
,"<item><tt>%s</tt><newline>\n",sgml(su
->name
,0));
487 fprintf(of
,"<item><tt>%s;</tt><newline>\n",sgml(su
->name
,0));
489 if(!depth
|| su
->comps
)
491 fprintf(of
,"<itemize>\n");
493 fprintf(of
,"<item><tt>{</tt><newline>\n");
495 for(i
=0;i
<su
->n_comp
;i
++)
496 WriteSGMLStructUnion(su
->comps
[i
],depth
+1);
498 fprintf(of
,"<item><tt>}</tt><newline>\n");
500 fprintf(of
,"</itemize>\n");
504 if(depth
&& su
->comment
)
505 fprintf(of
,"<item><tt>%s; </tt>%s<newline>\n",splitsu
[5]?sgml(&splitsu
[6],0):"",sgml(su
->comment
,0));
507 fprintf(of
,"<item><tt>%s;</tt><newline>\n",splitsu
[5]?sgml(&splitsu
[6],0):"");
511 if(splitsu
) splitsu
[-1]=' ';
515 /*++++++++++++++++++++++++++++++++++++++
516 Write a Variable structure out.
518 Variable var The Variable structure to output.
519 ++++++++++++++++++++++++++++++++++++++*/
521 static void WriteSGMLVariable(Variable var
)
525 if(var
->scope
&GLOBAL
)
526 fprintf(of
,"\n<sect1>Global Variable %s\n\n<p>\n",sgml(var
->name
,0));
528 fprintf(of
,"<bf>%s</bf><newline>\n",sgml(var
->name
,0));
531 fprintf(of
,"%s\n<p>\n",sgml(var
->comment
,0));
536 fprintf(of
,"static ");
538 if(!(var
->scope
&GLOBAL
) && var
->scope
&(EXTERNAL
|EXTERN_F
))
539 fprintf(of
,"extern ");
541 fprintf(of
,"%s</tt><newline>\n",sgml(var
->type
,0));
543 if(var
->scope
&(GLOBAL
|LOCAL
))
545 if(var
->incfrom
|| var
->visible
->n
|| var
->used
->n
)
546 fprintf(of
,"<descrip>\n");
550 fprintf(of
,"<tag>Included from:</tag>\n<itemize>\n");
551 fprintf(of
,"<item>%s\n",sgml(var
->incfrom
,0));
552 fprintf(of
,"</itemize>\n");
557 fprintf(of
,"<tag>Visible in:</tag>\n<itemize>\n");
558 for(i
=0;i
<var
->visible
->n
;i
++)
559 if(var
->visible
->s1
[i
][0]=='$' && !var
->visible
->s1
[i
][1])
560 fprintf(of
,"<item>%s\n",sgml(var
->visible
->s2
[i
],0));
562 fprintf(of
,"<item>%s() : %s\n",sgml(var
->visible
->s1
[i
],0),sgml(var
->visible
->s2
[i
],0));
563 fprintf(of
,"</itemize>\n");
568 fprintf(of
,"<tag>Used in:</tag>\n<itemize>\n");
569 for(i
=0;i
<var
->used
->n
;i
++)
571 if(var
->used
->s1
[i
][0]=='$' && !var
->used
->s1
[i
][1])
572 fprintf(of
,"<item>%s\n",sgml(var
->used
->s2
[i
],0));
576 fprintf(of
,"<item>%s()\n",sgml(var
->used
->s1
[i
],0));
578 fprintf(of
,"<item>%s() : %s\n",sgml(var
->used
->s1
[i
],0),sgml(var
->used
->s2
[i
],0));
581 fprintf(of
,"</itemize>\n");
584 if(var
->incfrom
|| var
->visible
->n
|| var
->used
->n
)
585 fprintf(of
,"</descrip>\n");
588 if(var
->scope
&(EXTERNAL
|EXTERN_F
) && var
->defined
)
590 fprintf(of
,"<descrip>\n<tag>Defined in:</tag>\n<itemize>\n");
591 fprintf(of
,"<item>%s",sgml(var
->name
,0));
592 fprintf(of
,"</itemize>\n</descrip>\n");
597 /*++++++++++++++++++++++++++++++++++++++
598 Write a Function structure out.
600 Function func The Function structure to output.
601 ++++++++++++++++++++++++++++++++++++++*/
603 static void WriteSGMLFunction(Function func
)
606 char* comment2
=NULL
,*type
;
608 if(func
->scope
&(GLOBAL
|EXTERNAL
))
609 fprintf(of
,"\n<sect1>Global Function %s()\n\n<p>",sgml(func
->name
,0));
611 fprintf(of
,"\n<sect1>Local Function %s()\n\n<p>",sgml(func
->name
,0));
615 if(option_verbatim_comments
)
616 fprintf(of
,"<tscreen><verb>\n%s\n</verb></tscreen>\n\n",sgml(func
->comment
,1));
619 comment2
=strstr(func
->comment
,"\n\n");
622 fprintf(of
,"%s\n<p>\n",sgml(func
->comment
,0));
628 if(func
->scope
&LOCAL
)
629 fprintf(of
,"static ");
630 if(func
->scope
&INLINED
)
631 fprintf(of
,"inline ");
633 if((type
=strstr(func
->type
,"()")))
635 fprintf(of
,"%s ( ",sgml(func
->type
,0));
637 for(i
=0;i
<func
->args
->n
;i
++)
638 fprintf(of
,i
?", %s":"%s",sgml(func
->args
->s1
[i
],0));
641 {fprintf(of
," %s</tt><newline>\n",sgml(&type
[1],0));type
[0]='(';}
643 fprintf(of
," )</tt><newline>\n");
645 pret
=strncmp("void ",func
->type
,5) && func
->cret
;
646 for(pargs
=0,i
=0;i
<func
->args
->n
;i
++)
647 pargs
= pargs
|| ( strcmp("void",func
->args
->s1
[i
]) && func
->args
->s2
[i
] );
651 fprintf(of
,"<descrip>\n");
653 fprintf(of
,"<tag><tt>%s</tt></tag>\n%s\n",sgml(func
->type
,0),func
->cret
?sgml(func
->cret
,0):" ");
655 for(i
=0;i
<func
->args
->n
;i
++)
656 fprintf(of
,"<tag><tt>%s</tt></tag>\n%s\n",sgml(func
->args
->s1
[i
],0),func
->args
->s2
[i
]?sgml(func
->args
->s2
[i
],0):" ");
657 fprintf(of
,"</descrip>\n");
662 fprintf(of
,"%s\n<p>\n",sgml(&comment2
[2],0));
666 if(func
->protofile
|| func
->incfrom
|| func
->calls
->n
|| func
->called
->n
|| func
->used
->n
|| func
->f_refs
->n
|| func
->v_refs
->n
)
667 fprintf(of
,"<descrip>\n");
671 fprintf(of
,"<tag>Prototyped in:</tag>\n<itemize>\n");
672 fprintf(of
,"<item>%s\n",sgml(func
->protofile
,0));
673 fprintf(of
,"</itemize>\n");
678 fprintf(of
,"<tag>Included from:</tag>\n<itemize>\n");
679 fprintf(of
,"<item>%s\n",sgml(func
->incfrom
,0));
680 fprintf(of
,"</itemize>\n");
686 fprintf(of
,"<tag>Calls:</tag>\n<itemize>\n");
687 for(i
=0;i
<func
->calls
->n
;i
++)
689 if(func
->calls
->s2
[i
])
690 fprintf(of
,"<item>%s() : %s\n",sgml(func
->calls
->s1
[i
],0),sgml(func
->calls
->s2
[i
],0));
697 fprintf(of
,"<item>");
698 for(i
=0;i
<func
->calls
->n
;i
++)
699 if(!func
->calls
->s2
[i
])
700 fprintf(of
,--others
?"%s(), ":"%s()",sgml(func
->calls
->s1
[i
],0));
703 fprintf(of
,"</itemize>\n");
708 fprintf(of
,"<tag>Called by:</tag>\n<itemize>\n");
709 for(i
=0;i
<func
->called
->n
;i
++)
710 fprintf(of
,"<item>%s() : %s\n",sgml(func
->called
->s1
[i
],0),sgml(func
->called
->s2
[i
],0));
711 fprintf(of
,"</itemize>\n");
716 fprintf(of
,"<tag>Used in:</tag>\n<itemize>\n");
717 for(i
=0;i
<func
->used
->n
;i
++)
719 if(func
->used
->s1
[i
][0]=='$' && !func
->used
->s1
[i
][1])
720 fprintf(of
,"<item>%s\n",sgml(func
->used
->s2
[i
],0));
722 fprintf(of
,"<item>%s() : %s\n",sgml(func
->used
->s1
[i
],0),sgml(func
->used
->s2
[i
],0));
724 fprintf(of
,"</itemize>\n");
730 fprintf(of
,"<tag>References Functions:</tag>\n<itemize>\n");
731 for(i
=0;i
<func
->f_refs
->n
;i
++)
733 if(func
->f_refs
->s2
[i
])
734 fprintf(of
,"<item>%s() : %s\n",sgml(func
->f_refs
->s1
[i
],0),sgml(func
->f_refs
->s2
[i
],0));
741 fprintf(of
,"<item>");
742 for(i
=0;i
<func
->f_refs
->n
;i
++)
743 if(!func
->f_refs
->s2
[i
])
744 fprintf(of
,--others
?"%s(), ":"%s()",sgml(func
->f_refs
->s1
[i
],0));
747 fprintf(of
,"</itemize>\n");
753 fprintf(of
,"<tag>References Variables:</tag>\n<itemize>\n");
754 for(i
=0;i
<func
->v_refs
->n
;i
++)
756 if(func
->v_refs
->s2
[i
])
757 fprintf(of
,"<item>%s : %s\n",sgml(func
->v_refs
->s1
[i
],0),sgml(func
->v_refs
->s2
[i
],0));
764 fprintf(of
,"<item>");
765 for(i
=0;i
<func
->v_refs
->n
;i
++)
766 if(!func
->v_refs
->s2
[i
])
767 fprintf(of
,--others
?"%s, ":"%s",sgml(func
->v_refs
->s1
[i
],0));
770 fprintf(of
,"</itemize>\n");
773 if(func
->protofile
|| func
->incfrom
|| func
->calls
->n
|| func
->called
->n
|| func
->used
->n
|| func
->f_refs
->n
|| func
->v_refs
->n
)
774 fprintf(of
,"</descrip>\n");
778 /*++++++++++++++++++++++++++++++++++++++
779 Write out a standard pre-amble.
781 FILE* f The file to write the pre amble to.
783 char* title The title of the file.
784 ++++++++++++++++++++++++++++++++++++++*/
786 static void WriteSGMLPreamble(FILE* f
,char* title
)
788 fputs("<!DOCTYPE LINUXDOC SYSTEM>\n",f
);
790 fputs("<!-- This SGML file generated by cxref. -->\n",f
);
791 fputs("<!-- cxref program (c) Andrew M. Bishop 1995,96,97,98,99. -->\n",f
);
795 fprintf(f
,"Cxref: %s %s\n",run_command
,filename
);
797 fprintf(f
,"Cxref: %s\n",run_command
);
798 fprintf(f
,"CPP : %s\n",run_cpp_command
);
801 fputs("<article>\n",f
);
806 fputs("<author>cxref\n",f
);
811 /*++++++++++++++++++++++++++++++++++++++
812 Write out a standard post-amble. This includes the end of document marker.
814 FILE* f The file to write the post amble to.
815 ++++++++++++++++++++++++++++++++++++++*/
817 static void WriteSGMLPostamble(FILE* f
)
820 fputs("</article>\n",f
);
824 /*++++++++++++++++++++++++++++++++++++++
825 Write out the appendix information.
827 StringList files The list of files to write.
829 StringList2 funcs The list of functions to write.
831 StringList2 vars The list of variables to write.
833 StringList2 types The list of types to write.
834 ++++++++++++++++++++++++++++++++++++++*/
836 void WriteSGMLAppendix(StringList files
,StringList2 funcs
,StringList2 vars
,StringList2 types
)
845 ofile
=ConcatStrings(5,option_odir
,"/",option_name
,SGML_APDX
,SGML_FILE
);
850 {fprintf(stderr
,"cxref: Failed to open the SGML appendix file '%s'\n",ofile
);exit(1);}
852 /* Write the file structure out */
854 WriteSGMLPreamble(of
,ConcatStrings(3,"Cross reference index of ",option_name
,"."));
856 fprintf(of
,"<sect>Cross References\n");
858 /* Write out the appendix of files. */
862 fprintf(of
,"\n<sect1>Files\n\n<p>\n");
863 fprintf(of
,"<itemize>\n");
864 for(i
=0;i
<files
->n
;i
++)
865 fprintf(of
,"<item>%s>\n",sgml(files
->s
[i
],0));
866 fprintf(of
,"</itemize>\n");
869 /* Write out the appendix of functions. */
873 fprintf(of
,"\n<sect1>Global Functions\n\n<p>\n");
874 fprintf(of
,"<itemize>\n");
875 for(i
=0;i
<funcs
->n
;i
++)
876 fprintf(of
,"<item>%s() : %s\n",sgml(funcs
->s1
[i
],0),sgml(funcs
->s2
[i
],0));
877 fprintf(of
,"</itemize>\n");
880 /* Write out the appendix of variables. */
884 fprintf(of
,"\n<sect1>Global Variables\n\n<p>\n");
885 fprintf(of
,"<itemize>\n");
886 for(i
=0;i
<vars
->n
;i
++)
887 fprintf(of
,"<item>%s : %s\n",sgml(vars
->s1
[i
],0),sgml(vars
->s2
[i
],0));
888 fprintf(of
,"</itemize>\n");
891 /* Write out the appendix of types. */
895 fprintf(of
,"\n<sect1>Defined Types\n\n<p>\n");
896 fprintf(of
,"<itemize>\n");
897 for(i
=0;i
<types
->n
;i
++)
898 if(!strncmp("enum",types
->s1
[i
],4))
899 fprintf(of
,"<item>%s : %s\n",sgml(types
->s1
[i
],0),sgml(types
->s2
[i
],0));
901 if(!strncmp("union",types
->s1
[i
],5))
902 fprintf(of
,"<item>%s : %s\n",sgml(types
->s1
[i
],0),sgml(types
->s2
[i
],0));
904 if(!strncmp("struct",types
->s1
[i
],6))
905 fprintf(of
,"<item>%s : %s\n",sgml(types
->s1
[i
],0),sgml(types
->s2
[i
],0));
907 fprintf(of
,"<item>%s : %s\n",sgml(types
->s1
[i
],0),sgml(types
->s2
[i
],0));
908 fprintf(of
,"</itemize>\n");
911 WriteSGMLPostamble(of
);
915 /* Clear the memory in sgml(,0) */
917 sgml(NULL
,0); sgml(NULL
,0); sgml(NULL
,0); sgml(NULL
,0);
921 /*++++++++++++++++++++++++++++++++++++++
922 Delete the SGML file and main file reference that belong to the named file.
924 char *name The name of the file to delete.
925 ++++++++++++++++++++++++++++++++++++++*/
927 void WriteSGMLFileDelete(char *name
)
931 ofile
=ConcatStrings(4,option_odir
,"/",name
,SGML_FILE
);
936 /*++++++++++++++++++++++++++++++++++++++
937 Make the input string safe to output as SGML ( not <, >, &, ", $, #, % or ~ ).
939 char* sgml Returns a safe SGML string.
941 char* c A non-safe SGML string.
943 int verbatim Set to true inside a verbatim environment.
945 The function can only be called four times in each fprintf() since it returns one of only four static strings.
946 ++++++++++++++++++++++++++++++++++++++*/
948 static char* sgml(char* c
,int verbatim
)
950 static char safe
[4][256],*malloced
[4]={NULL
,NULL
,NULL
,NULL
};
953 int i
=0,j
=0,delta
=10,len
=256-delta
;
962 {Free(malloced
[which
]);malloced
[which
]=NULL
;}
966 i
=CopyOrSkip(c
,"sgml",©
,&skip
);
970 for(;j
<len
&& c
[i
];i
++)
973 {ret
[j
++]=c
[i
]; if(c
[i
]=='\n') copy
=0;}
975 { if(c
[i
]=='\n') skip
=0;}
980 strcpy(&ret
[j
],"&ero;");j
+=5;
984 {strcpy(&ret
[j
],"&etago;");j
+=7; break;}
993 {strcpy(&ret
[j
],"&etago;");j
+=7;}
995 {strcpy(&ret
[j
],"<");j
+=4;}
998 strcpy(&ret
[j
],">");j
+=4;
1001 strcpy(&ret
[j
],""");j
+=6;
1004 strcpy(&ret
[j
],"&");j
+=5;
1007 strcpy(&ret
[j
],"$");j
+=8;
1010 strcpy(&ret
[j
],"#");j
+=5;
1013 strcpy(&ret
[j
],"%");j
+=8;
1016 strcpy(&ret
[j
],"˜");j
+=7;
1019 if(j
&& ret
[j
-1]=='\n')
1021 strcpy(&ret
[j
],"<newline>");j
+=9;
1029 i
+=CopyOrSkip(c
+i
,"sgml",©
,&skip
);
1032 if(c
[i
]) /* Not finished */
1035 malloced
[which
]=Realloc(malloced
[which
],len
+delta
+256);
1037 {malloced
[which
]=Malloc(len
+delta
+256); strncpy(malloced
[which
],ret
,(unsigned)j
);}
1038 ret
=malloced
[which
];