1 /***************************************
4 C Cross Referencing & Documentation tool. Version 1.5e.
6 Collects the comments from the parser.
7 ******************/ /******************
8 Written by Andrew M. Bishop
10 This file Copyright 1995,96,97,98 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 ***************************************/
16 /*+ Turn on the debugging in this file. +*/
27 static void TidyCommentString(char **string
,int spaces
);
29 /*+ The option to insert the comments verbatim into the output. +*/
30 extern int option_verbatim_comments
;
32 /*+ The file that is currently being processed. +*/
35 /*+ The name of the current file. +*/
36 extern char* parse_file
;
38 /*+ The current (latest) comment. +*/
39 static char* current_comment
=NULL
;
41 /*+ The malloced string for the current comment. +*/
42 static char* malloc_comment
=NULL
;
44 /*+ The status of the current comment. +*/
45 static int comment_ended
=0;
48 /*++++++++++++++++++++++++++++++++++++++
49 Function that is called when a comment or part of one is seen. The comment is built up until an end of comment is signaled.
51 char* c The comment text.
53 int flag A flag to indicate the type of comment that it is.
54 if flag==0 then it is a comment of some sort.
55 If flag==1 then it is the end of a file (/ * * comment * * /) comment
56 if flag==2 then it is the end of the other special comment (/ * + comment + * /).
57 if flag==3 then it is the end of a normal comment (/ * comment * /).
58 ++++++++++++++++++++++++++++++++++++++*/
60 void SeenComment(char* c
,int flag
)
66 printf("#Comment.c# Seen comment /**\n%s\n**/\n",current_comment
);
68 TidyCommentString(¤t_comment
,0);
69 if(!CurFile
->comment
&& !strcmp(CurFile
->name
,parse_file
))
70 SeenFileComment(current_comment
);
72 if(malloc_comment
) *malloc_comment
=0;
78 printf("#Comment.c# Seen comment /*+\n%s\n+*/\n",current_comment
);
80 TidyCommentString(¤t_comment
,0);
81 if(SeenFuncIntComment(current_comment
))
84 if(malloc_comment
) *malloc_comment
=0;
91 printf("#Comment.c# Seen comment /*\n%s\n*/\n",current_comment
);
93 TidyCommentString(¤t_comment
,!option_verbatim_comments
);
94 if(!CurFile
->comment
&& !strcmp(CurFile
->name
,parse_file
))
96 SeenFileComment(current_comment
);
98 if(malloc_comment
) *malloc_comment
=0;
107 current_comment
=NULL
;
108 if(malloc_comment
) *malloc_comment
=0;
111 if(malloc_comment
==NULL
)
113 malloc_comment
=Malloc(strlen(c
)+1);
114 strcpy(malloc_comment
,c
);
118 malloc_comment
=Realloc(malloc_comment
,strlen(c
)+strlen(malloc_comment
)+1);
119 strcat(malloc_comment
,c
);
122 current_comment
=malloc_comment
;
127 /*++++++++++++++++++++++++++++++++++++++
128 Provide the current (latest) comment.
130 char* GetCurrentComment Returns the current (latest) comment.
131 ++++++++++++++++++++++++++++++++++++++*/
133 char* GetCurrentComment(void)
135 char* comment
=current_comment
;
138 printf("#Comment.c# GetCurrentComment returns <<<%s>>>\n",comment
);
141 current_comment
=NULL
;
147 /*++++++++++++++++++++++++++++++++++++++
148 Set the current (latest) comment.
150 char* comment The comment.
151 ++++++++++++++++++++++++++++++++++++++*/
153 void SetCurrentComment(char* comment
)
156 printf("#Comment.c# SetCurrentComment set to <<<%s>>>\n",comment
);
161 if(malloc_comment
!=comment
)
163 malloc_comment
=Realloc(malloc_comment
,strlen(comment
)+1);
164 strcpy(malloc_comment
,comment
);
166 current_comment
=malloc_comment
;
170 current_comment
=NULL
;
171 if(malloc_comment
) *malloc_comment
=0;
176 /*++++++++++++++++++++++++++++++++++++++
177 A function to split out the arguments etc from a comment,
178 for example the function argument comments are separated using this.
180 char* SplitComment Returns the required comment.
182 char** original A pointer to the original comment, this is altered in the process.
184 char* name The name that is to be cut out from the comment.
186 A most clever function that ignores spaces so that 'char* b' and 'char *b' match.
187 ++++++++++++++++++++++++++++++++++++++*/
189 char* SplitComment(char** original
,char* name
)
205 for(i
=j
=0;i
<l
;i
++,j
++)
207 while(name
[i
]==' ') i
++;
208 while(c
[j
]==' ') j
++;
210 if(!c
[j
] || name
[i
]!=c
[j
])
217 char* end
=strstr(c
,"\n\n");
220 *original
=MallocString(ConcatStrings(2,*original
,end
));
225 *original
=MallocString(*original
);
229 if(end
&& &c
[j
+1]>=end
)
233 c
=CopyString(&c
[j
+1]);
234 TidyCommentString(&c
,1);
243 while((c
=strstr(c
,"\n\n")));
250 /*++++++++++++++++++++++++++++++++++++++
251 Tidy up the current comment string by snipping off trailing and leading junk.
253 char **string The string that is to be tidied.
255 int spaces Indicates that leading and trailing whitespace are to be removed as well.
256 ++++++++++++++++++++++++++++++++++++++*/
258 static void TidyCommentString(char **string
,int spaces
)
261 char *to
=*string
,*from
=*string
,*str
;
266 /* Remove CR characters. */
277 /* Remove leading blank lines. */
286 if(*str
!=' ' && *str
!='\t')
289 while(whitespace
&& *str
&& *++str
!='\n');
298 /* Remove trailing blank lines. */
301 str
=*string
+strlen(*string
)-1;
307 if(*str
!=' ' && *str
!='\t')
310 while(whitespace
&& str
>*string
&& *--str
!='\n');
319 /* Replace lines containing just whitespace with empty lines. */
333 while(*str
&& *++str
!='\n')
335 if(*str
!=' ' && *str
!='\t')
343 while((*start
++=*str
++));
352 /*++++++++++++++++++++++++++++++++++++++
353 Delete the malloced string for the comment
354 ++++++++++++++++++++++++++++++++++++++*/
356 void DeleteComment(void)
358 current_comment
=NULL
;
360 Free(malloc_comment
);