1 #ifdef _cplusplus
2 extern "C" {
3 #endif
4 #include "dynfile.h"
5 #include "linesubs.h"
6
7 /* Function: make_pdoc_output(dfp,mod_name,ofp)
8 *
9 * Descrip: makes a pdoc for this file.
10 *
11 *
12 *
13 * Arg: dfp [UNKN ] DYNFILE object [DYNFILE *]
14 * Arg: mod_name [UNKN ] Undocumented argument [char *]
15 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
16 *
17 * Return [UNKN ] Undocumented return value [boolean]
18 *
19 */
20 # line 56 "dynfile.dy"
make_pdoc_output(DYNFILE * dfp,char * mod_name,FILE * ofp)21 boolean make_pdoc_output(DYNFILE * dfp,char * mod_name,FILE * ofp)
22 {
23 /*int i;*/
24
25 /*** first thing is to add the module name as a link to this file ***/
26
27 fprintf(ofp,"&%s\n",mod_name);
28
29 /*** at the moment we don't handle module info ***/
30
31 /*** ok - now write out a head-list for functions ***/
32
33 return TRUE;
34 }
35
36
37 /* Function: have_got_unknown_func_DYNFILE(dfp,no,should_complain)
38 *
39 * Descrip: reports back whether there are any undocumented
40 * file. if should_complain is TRUE, will issue
41 * warnings through warn. Writes the number of
42 * undocumented functions into no
43 *
44 *
45 * Arg: dfp [UNKN ] DYNFILE object [DYNFILE *]
46 * Arg: no [WRITE] pointer to some memory for the number of undoc'd funcs [int *]
47 * Arg: should_complain [UNKN ] if TRUE, will issue warn statements [boolean]
48 *
49 * Return [UNKN ] Undocumented return value [boolean]
50 *
51 */
52 # line 82 "dynfile.dy"
have_got_unknown_func_DYNFILE(DYNFILE * dfp,int * no,boolean should_complain)53 boolean have_got_unknown_func_DYNFILE(DYNFILE * dfp,int * no,boolean should_complain)
54 {
55 int i;
56 boolean ret = FALSE;
57
58
59 *no =0;
60
61 for(i=0;i<dfp->len;i++)
62 if( dfp->info[i]->functype == FI_UNKNOWN) {
63 ret = TRUE;
64 (*no)++;
65 if( should_complain == TRUE) {
66 warn("You have not documented %s",dfp->info[i]->name);
67 }
68 }
69
70 return ret;
71 }
72
73 /* Function: write_Dynamite_minimal_func(dfp)
74 *
75 * Descrip: writes basically just the #include "self.h" line
76 * in the dynamite file
77 *
78 *
79 * Arg: dfp [UNKN ] Undocumented argument [DYNFILE *]
80 *
81 */
82 # line 106 "dynfile.dy"
write_Dynamite_minimal_func(DYNFILE * dfp)83 void write_Dynamite_minimal_func(DYNFILE * dfp)
84 {
85 fprintf(dfp->func,"#include \"%s.h\"\n\n",dfp->sourceroot);
86 dfp->funcpos+=2;
87
88 return;
89 }
90
91 /* Function: FuncInfo_from_name_DYNFILE(dfp,name)
92 *
93 * Descrip: Finds a funcinfo with name. returns NULL
94 * if it cant find them
95 *
96 *
97 * Arg: dfp [UNKN ] Undocumented argument [DYNFILE *]
98 * Arg: name [UNKN ] Undocumented argument [char *]
99 *
100 * Return [UNKN ] Undocumented return value [FuncInfo *]
101 *
102 */
103 # line 118 "dynfile.dy"
FuncInfo_from_name_DYNFILE(DYNFILE * dfp,char * name)104 FuncInfo * FuncInfo_from_name_DYNFILE(DYNFILE * dfp,char * name)
105 {
106 int i;
107
108 for(i=0;i<dfp->len;i++)
109 if( strcmp(dfp->info[i]->name,name) == 0 )
110 return dfp->info[i];
111
112 return NULL;
113 }
114
115 /* Function: show_html_DYNFILE(dfp,ofp,type)
116 *
117 * Descrip: Deprecated - use pdoc
118 *
119 *
120 * Arg: dfp [UNKN ] Undocumented argument [DYNFILE *]
121 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
122 * Arg: type [UNKN ] Undocumented argument [FuncOrderType]
123 *
124 */
125 # line 133 "dynfile.dy"
show_html_DYNFILE(DYNFILE * dfp,FILE * ofp,FuncOrderType type)126 void show_html_DYNFILE(DYNFILE * dfp,FILE * ofp,FuncOrderType type)
127 {
128 int i;
129
130 sort_DYNFILE_FuncOrderType(dfp,type);
131
132 if( is_separated_types(type) == TRUE) {
133
134 fprintf(ofp,"Externally called functions functions\n<ul>");
135 for(i=0;i<dfp->len;i++) {
136 if( dfp->info[i]->functype != FI_CALLABLE) {
137 break;
138 }
139 fprintf(ofp,"<li><a href=\"#%s\"> %s </a>\n",dfp->info[i]->name,dfp->info[i]->complete_name);
140 }
141 fprintf(ofp,"</ul><p>Unplaced (no information about calling) functions\n<ul>");
142 for(;i<dfp->len;i++) {
143 if( dfp->info[i]->functype != FI_UNKNOWN) {
144 break;
145 }
146 fprintf(ofp,"<li><a href=\"#%s\"> %s </a>\n",dfp->info[i]->name,dfp->info[i]->complete_name);
147 }
148 fprintf(ofp,"</ul><p>Internal (unlikely to be called directly) functions\n<ul>");
149 for(;i<dfp->len;i++) {
150 fprintf(ofp,"<li><a href=\"#%s\"> %s </a>\n",dfp->info[i]->name,dfp->info[i]->complete_name);
151 }
152
153 fprintf(ofp,"</ul><hr>Externally called functions<p>\n");
154 for(i=0;i<dfp->len;i++) {
155 if( dfp->info[i]->functype != FI_CALLABLE) {
156 break;
157 }
158 fprintf(ofp,"<a name=\"%s\"> %s </a><p>Description<pre>\n",dfp->info[i]->name,dfp->info[i]->complete_name);
159 dump_Ftext(dfp->info[i]->ft,ofp);
160 fprintf(ofp,"</pre>\n");
161 }
162
163 fprintf(ofp,"<hr>Unplaced functions<p>\n");
164 for(;i<dfp->len;i++) {
165 if( dfp->info[i]->functype != FI_UNKNOWN) {
166 break;
167 }
168 fprintf(ofp,"<a name=\"%s\"> %s </a><p>Description<pre>\n",dfp->info[i]->name,dfp->info[i]->complete_name);
169 dump_Ftext(dfp->info[i]->ft,ofp);
170 fprintf(ofp,"</pre>\n");
171 }
172 fprintf(ofp,"<hr>Internal functions<p>\n");
173 for(;i<dfp->len;i++) {
174 fprintf(ofp,"<a name=\"%s\"> %s </a><p>Description<pre>\n",dfp->info[i]->name,dfp->info[i]->complete_name);
175 dump_Ftext(dfp->info[i]->ft,ofp);
176 fprintf(ofp,"</pre>\n");
177 }
178 } else {
179 warn("Can't currently handle no CUI sorted Html functions, yikes");
180 }
181
182 }
183
184 /* Function: place_func_decl(dfp,fi)
185 *
186 * Descrip: Places the function declaration potential with
187 * package protection
188 *
189 *
190 * Arg: dfp [UNKN ] Undocumented argument [DYNFILE *]
191 * Arg: fi [UNKN ] Undocumented argument [FuncInfo *]
192 *
193 * Return [UNKN ] Undocumented return value [int]
194 *
195 */
196 # line 196 "dynfile.dy"
place_func_decl(DYNFILE * dfp,FuncInfo * fi)197 int place_func_decl(DYNFILE * dfp,FuncInfo * fi)
198 {
199
200 fprintf(dfp->head,"%s ",fi->ret->type);
201
202 fprintf(dfp->head,"%s%s;\n",dfp->package_name == NULL ? "" : dfp->package_name,fi->stripped_return);
203 if( dfp->package_name != NULL ) {
204 fprintf(dfp->head,"#define %s %s%s\n",fi->name,dfp->package_name,fi->name);
205 return 2;
206 }
207 else {
208 return 1;
209 }
210 }
211
212
213 /* Function: place_declarations_DYNFILE(dfp,type)
214 *
215 * Descrip: writes the header declarations of functions
216 * into the header file, with documentation.
217 *
218 * The FuncOrderType is either the more common,
219 * usual order or alphabetical
220 *
221 *
222 * Arg: dfp [UNKN ] Undocumented argument [DYNFILE *]
223 * Arg: type [UNKN ] Undocumented argument [FuncOrderType]
224 *
225 */
226 # line 219 "dynfile.dy"
place_declarations_DYNFILE(DYNFILE * dfp,FuncOrderType type)227 void place_declarations_DYNFILE(DYNFILE * dfp,FuncOrderType type)
228 {
229 int i;
230
231 sort_DYNFILE_FuncOrderType(dfp,type);
232
233 if( is_separated_types(type) == TRUE) {
234 fprintf(dfp->head,"\n\n /***************************************************/\n");
235 fprintf(dfp->head, " /* Callable functions */\n");
236 fprintf(dfp->head, " /* These are the functions you are expected to use */\n");
237 fprintf(dfp->head, " /***************************************************/\n\n");
238 for(i=0;i<dfp->len;i++) {
239 if( dfp->info[i]->functype != FI_CALLABLE) {
240 break;
241 }
242 fprintf(dfp->head,"\n\n");
243 show_eddystyle_FuncInfo(dfp->info[i],dfp->head);
244 place_func_decl(dfp,dfp->info[i]);
245
246 }
247
248 fprintf(dfp->head,"\n\n /* Unplaced functions */\n");
249 fprintf(dfp->head," /* There has been no indication of the use of these functions */\n");
250 for(;i<dfp->len;i++) {
251 if( dfp->info[i]->functype != FI_UNKNOWN) {
252 break;
253 }
254
255 place_func_decl(dfp,dfp->info[i]);
256
257 }
258
259 fprintf(dfp->head,"\n\n /***************************************************/\n");
260 fprintf(dfp->head, " /* Internal functions */\n");
261 fprintf(dfp->head, " /* you are not expected to have to call these */\n");
262 fprintf(dfp->head, " /***************************************************/\n");
263 for(;i<dfp->len;i++) {
264 place_func_decl(dfp,dfp->info[i]);
265 }
266
267 } /*** not separated types ***/
268 else {
269 for(i=0;i<dfp->len;i++) {
270 fprintf(dfp->head,"\n\n");
271 show_eddystyle_FuncInfo(dfp->info[i],dfp->head);
272
273 place_func_decl(dfp,dfp->info[i]);
274
275 }
276 }
277
278
279
280 }
281
282 /* Function: sort_DYNFILE_FuncOrderType(dfp,type)
283 *
284 * Descrip: really a sub-routine. Sorts by the FuncOrderType
285 * which can be alphabetical or by original position
286 *
287 *
288 * Arg: dfp [UNKN ] Undocumented argument [DYNFILE *]
289 * Arg: type [UNKN ] Undocumented argument [FuncOrderType]
290 *
291 */
292 # line 279 "dynfile.dy"
sort_DYNFILE_FuncOrderType(DYNFILE * dfp,FuncOrderType type)293 void sort_DYNFILE_FuncOrderType(DYNFILE * dfp,FuncOrderType type)
294 {
295 switch (type) {
296 case FO_CUI_ALPHABETICAL :
297 sort_DYNFILE(dfp,compare_two_FuncInfo_alpha);
298 break;
299 case FO_CUI_POSITION :
300 sort_DYNFILE(dfp,compare_two_FuncInfo_pos);
301 break;
302 default :
303 warn("Got an unnw FuncOrderType %d",type);
304 }
305
306 return;
307
308
309 }
310
311 /* Function: is_separated_types(type)
312 *
313 * Descrip: Tells whether this sorting will separate
314 * things into Callable/unknown/internal. All
315 * sorts currently do
316 *
317 *
318 * Arg: type [UNKN ] Undocumented argument [FuncOrderType]
319 *
320 * Return [UNKN ] Undocumented return value [boolean]
321 *
322 */
323 # line 303 "dynfile.dy"
is_separated_types(FuncOrderType type)324 boolean is_separated_types(FuncOrderType type)
325 {
326 if( type == FO_CUI_ALPHABETICAL || type == FO_CUI_POSITION)
327 return TRUE;
328 return FALSE;
329 }
330
331 /* Function: compare_two_FuncInfo_alpha(one,two)
332 *
333 * Descrip: comparison function for sorting by functype then alphabetical
334 *
335 *
336 * Arg: one [UNKN ] Undocumented argument [FuncInfo *]
337 * Arg: two [UNKN ] Undocumented argument [FuncInfo *]
338 *
339 * Return [UNKN ] Undocumented return value [int]
340 *
341 */
342 # line 314 "dynfile.dy"
compare_two_FuncInfo_alpha(FuncInfo * one,FuncInfo * two)343 int compare_two_FuncInfo_alpha(FuncInfo * one,FuncInfo * two)
344 {
345 if( one->functype != two->functype ) {
346 return one->functype - two->functype;
347 }
348 return strcmp(one->name,two->name);
349 }
350
351
352 /* Function: compare_two_FuncInfo_pos(one,two)
353 *
354 * Descrip: comparison function for sorting by functype then by file position
355 *
356 *
357 * Arg: one [UNKN ] Undocumented argument [FuncInfo *]
358 * Arg: two [UNKN ] Undocumented argument [FuncInfo *]
359 *
360 * Return [UNKN ] Undocumented return value [int]
361 *
362 */
363 # line 327 "dynfile.dy"
compare_two_FuncInfo_pos(FuncInfo * one,FuncInfo * two)364 int compare_two_FuncInfo_pos(FuncInfo * one,FuncInfo * two)
365 {
366 if( one->functype != two->functype ) {
367 return one->functype - two->functype;
368 }
369 return one->infopos - two->infopos;
370 }
371
372 /* Function: positionify_DYNFILE(dfp)
373 *
374 * Descrip: places the positions of functions as read in the file
375 * (hopefully) into the funcinfos so can be sorted on
376 * them (and rearranged potentially)
377 *
378 *
379 * Arg: dfp [UNKN ] Undocumented argument [DYNFILE *]
380 *
381 */
382 # line 340 "dynfile.dy"
positionify_DYNFILE(DYNFILE * dfp)383 void positionify_DYNFILE(DYNFILE * dfp)
384 {
385 int i;
386
387 for(i=0;i<dfp->len;i++)
388 dfp->info[i]->infopos = i;
389 }
390
391
392 # line 349 "dynfile.dy"
show_FuncInfo_DYNFILE(DYNFILE * dfp,FuncInfo * fi)393 void show_FuncInfo_DYNFILE(DYNFILE * dfp,FuncInfo * fi)
394 {
395 switch (dfp->desc_type) {
396 case DYN_DESC_EDDY :
397 dfp->funcpos += show_eddystyle_FuncInfo(fi,dfp->func);
398 break;
399 default :
400 warn("No func descirption like %d",dfp->desc_type);
401 break;
402 }
403
404 }
405
406 /**
407 FuncInfo * find_FuncInfo_from_name_end(DYNFILE * dfp,char * name)
408 {
409 int i;
410
411 for(i=dfp->len-1;i >= 0;i--)
412 if( strcmp(dfp->info[i]->name,name) == 0 )
413 return dfp->info[i];
414
415 return NULL;
416 }
417 **/
418
419
420 /*** really for output ***/
421
422 /* Function: strinopen(target,probe)
423 *
424 * Descrip: complex function, better written with
425 * regex's. Tests whether the probe is actually
426 * a in a "open" string, ie. complete string
427 * outside of " or other things.
428 *
429 * this is mainly for use of finding if's and for's
430 * in C statements
431 *
432 * it is a horrible kludge, and hopefully now not used
433 *
434 *
435 * Arg: target [UNKN ] Undocumented argument [char *]
436 * Arg: probe [UNKN ] Undocumented argument [char *]
437 *
438 * Return [UNKN ] Undocumented return value [char *]
439 *
440 */
441 # line 390 "dynfile.dy"
strinopen(char * target,char * probe)442 char * strinopen(char * target,char * probe)
443 {
444 register char * p;
445 register char * t;
446 register char * start;
447
448 start = target;
449
450 for(;*target;target++)
451 {
452 if( *target == '"')
453 {
454 for(target++;*target && *target != '"';target++)
455 ;
456 if( *target != '"' )
457 break;
458 target++;
459 }
460 if( *target == *probe )
461 {
462 if( target != start )
463 if( isalpha(*(target-1)) )
464 continue;
465 for(p=probe,t=target;*p && *t;p++,t++)
466 if( *p != *t )
467 break;
468
469 if( isalpha(*(t)) )
470 continue;
471
472 if( *p == '\0')
473 return target;
474 }
475 }
476 return NULL;
477 }
478
479
480 # line 428 "dynfile.dy"
real_is_unfinished_expression(char * str)481 boolean real_is_unfinished_expression(char * str)
482 {
483 char * runner;
484
485 runner = str+strlen(str)-1;
486
487 while( isspace(*runner) && runner >= str )
488 runner--;
489
490 if( runner == str)
491 return FALSE;
492
493 if( strinopen(str,"if") != NULL || strinopen(str,"for") != NULL || strinopen(str,"while") != NULL || strinopen(str,"switch") != NULL ||
494 strinopen(str,"case") != NULL || strinopen(str,"default") )
495 return FALSE;
496
497 if( *str == '#' )
498 return FALSE;
499
500 if( *runner == ';')
501 return FALSE;
502 if( (runner=strinopen(str,"else")) != NULL)
503 {
504 for(;isalpha(*runner) && *runner;runner++)
505 ;
506 for(;!isalnum(*runner) && *runner;runner++)
507 ;
508 if( *runner == '\0')
509 return FALSE;
510 else return TRUE;
511 }
512 return TRUE;
513 }
514
515
516
517 # line 464 "dynfile.dy"
flush_line(DYNFILE * dfp)518 void flush_line(DYNFILE * dfp)
519 {
520 register char * temp;
521
522 if( *dfp->line != '\0') {
523 temp = scan_and_replace_line(dfp->line);
524 fprintf(dfp->func,"%s \n",temp);
525 strcpy(dfp->line,"");
526 dfp->funcpos++;
527 }
528 }
529
530 # line 476 "dynfile.dy"
flush_line_to_header(DYNFILE * dfp)531 void flush_line_to_header(DYNFILE * dfp)
532 {
533 register char * temp;
534
535 if( *dfp->line != '\0') {
536 temp = scan_and_replace_line(dfp->line);
537 fprintf(dfp->head,"%s \n",temp);
538 strcpy(dfp->line,"");
539 }
540 }
541
542
543
544 /*** this function is going to "pad" the line with spaces to the next
545 comment block level ***/
546
547 # line 492 "dynfile.dy"
pad_line(DYNFILE * dfp)548 void pad_line(DYNFILE * dfp)
549 {
550 register int i;
551 int len;
552 int nlen;
553
554 if(dfp->commentstart == 0 || strlen(dfp->line)+1 > dfp->commentstart) {
555 /** ok, have to find the new level **/
556 len = strlen(dfp->line);
557 nlen = len + (len%4 == 0 ? 0 : 4-len%4);
558 for(i=len;i<nlen;i++)
559 dfp->line[i] = ' ';
560 dfp->line[i]='\0';
561 }
562 else {
563 for(i=strlen(dfp->line);i<dfp->commentstart;i++)
564 dfp->line[i] = ' ';
565 dfp->line[i]='\0';
566 }
567 }
568
569 /** puts in a double break **/
570
571 # line 515 "dynfile.dy"
add_break(DYNFILE * dfp)572 void add_break(DYNFILE * dfp)
573 {
574 flush_line(dfp);
575
576 fprintf(dfp->func,"\n\n");
577 dfp->commentstart=0;
578 dfp->funcpos+=2;
579
580 }
581
582
583 # line 526 "dynfile.dy"
start_function(DYNFILE * dfp,char * str,...)584 void start_function(DYNFILE * dfp,char * str, ...)
585 {
586 FuncInfo * fi;
587 char buffer[MAXLINE];
588 va_list ap;
589
590 va_start(ap,str);
591 vsprintf(buffer,str,ap);
592 va_end(ap);
593
594 /** we have no FuncInfo - make a dummy! **/
595
596 fi = FuncInfo_from_str("Undocumented function from internal dynamite code");
597
598 start_function_FuncInfo(fi,dfp,buffer);
599
600 }
601
602 # line 544 "dynfile.dy"
start_function_FuncInfo(FuncInfo * fi,DYNFILE * dfp,char * str,...)603 void start_function_FuncInfo(FuncInfo * fi,DYNFILE * dfp,char * str, ... )
604 {
605 char buffer[MAXLINE];
606 va_list ap;
607
608 va_start(ap,str);
609 vsprintf(buffer,str,ap);
610 va_end(ap);
611
612 if( reconcile_FuncInfo_with_funcstr(fi,buffer) == FALSE ) {
613 warn("Internal error with function [%s]: Not reconciled with documentation");
614 add_break_to_Ftext(fi->ft);
615 add_line_to_Ftext(fi->ft,"WARNING: This function's internal documentation was not reconciled with its argument list");
616 }
617
618 show_FuncInfo_DYNFILE(dfp,fi);
619 fi->line_in_c = dfp->funcpos;
620 fi->complete_name = stringalloc(buffer);
621
622 add_DYNFILE(dfp,fi);
623
624 true_start_function(dfp,buffer);
625 }
626
627 # line 568 "dynfile.dy"
true_start_function(DYNFILE * dfp,char * str,...)628 void true_start_function(DYNFILE * dfp,char * str, ... )
629 {
630 va_list ap;
631 register int i;
632
633
634 /** put away whatever was there before **/
635 flush_line(dfp);
636
637
638 for(i=0;i<128;i++)
639 dfp->tag[i]=NULL;
640
641 va_start(ap,str);
642 vsprintf(dfp->line,str,ap);
643 va_end(ap);
644
645
646 if( dfp->bracelevel > 0 ) {
647 warn("In dynfile... you are attempting to start a function [%s] inside a separate brace syste. Bad bad news!",dfp->line);
648 }
649
650 flush_line(dfp);
651
652
653 /*** start function ***/
654
655 fprintf(dfp->func,"{\n");
656 dfp->funcpos++;
657 dfp->bracelevel++;
658 dfp->infunc = TRUE;
659
660 return;
661 }
662
663 # line 603 "dynfile.dy"
close_function(DYNFILE * dfp)664 void close_function(DYNFILE * dfp)
665 {
666 if( dfp->infunc == FALSE ){
667 warn("Attempting to close a function when you are not even in one... problem surely!");
668 }
669
670 flush_line(dfp);
671
672 dfp->bracelevel--;
673
674 strcpy(dfp->line,"} ");
675 dfp->commentstart=0;
676 pad_line(dfp);
677 }
678
679
680
681 # line 620 "dynfile.dy"
hang_expr(DYNFILE * dfp,char * str,...)682 void hang_expr(DYNFILE * dfp,char * str, ...)
683 {
684 char buffer[MAXLINE];
685 va_list ap;
686
687 flush_line(dfp);
688
689 dfp->bracelevel++;
690 current_indent(dfp);
691 dfp->bracelevel--;
692
693 va_start(ap,str);
694 vsprintf(buffer,str,ap);
695 va_end(ap);
696 strcat(dfp->line,buffer);
697
698 if( real_is_unfinished_expression(buffer) )
699 strcat(dfp->line,"; ");
700
701 pad_line(dfp);
702 }
703
704 # line 642 "dynfile.dy"
expr(DYNFILE * dfp,char * str,...)705 void expr(DYNFILE * dfp,char * str, ...)
706 {
707 char buffer[MAXLINE];
708 va_list ap;
709
710 flush_line(dfp);
711 current_indent(dfp);
712
713
714 va_start(ap,str);
715 vsprintf(buffer,str,ap);
716 va_end(ap);
717 strcat(dfp->line,buffer);
718
719 if( real_is_unfinished_expression(buffer) )
720 strcat(dfp->line,"; ");
721
722
723 pad_line(dfp);
724 }
725
726 # line 663 "dynfile.dy"
macro(DYNFILE * dfp,char * str,...)727 void macro(DYNFILE * dfp,char * str, ...)
728 {
729 char buffer[MAXLINE];
730 va_list ap;
731
732 flush_line(dfp);
733
734 va_start(ap,str);
735 vsprintf(buffer,str,ap);
736
737 if(buffer[0] != '#')
738 warn("asking for macro without # as first letter");
739
740
741 /** no ident! **/
742 strcat(dfp->line,buffer);
743
744 pad_line(dfp);
745 }
746
747
748 # line 684 "dynfile.dy"
warn_expr(DYNFILE * dfp,char * str,...)749 void warn_expr(DYNFILE * dfp,char * str, ...)
750 {
751 char buffer[MAXLINE];
752 char buf2[MAXLINE];
753 va_list ap;
754
755 flush_line(dfp);
756
757 current_indent(dfp);
758
759
760 va_start(ap,str);
761
762 vsprintf(buffer,str,ap);
763
764 sprintf(buf2,"warn(\"%s\");",buffer);
765
766 strcat(dfp->line,buf2);
767
768 pad_line(dfp);
769 }
770
771
772 # line 707 "dynfile.dy"
start_struct(DYNFILE * dfp,char * str,...)773 void start_struct(DYNFILE * dfp,char * str, ...)
774 {
775 char buffer[MAXLINE];
776 va_list ap;
777
778
779 flush_line_to_header(dfp);
780
781 va_start(ap,str);
782
783 vsprintf(buffer,str,ap);
784
785 strcat(dfp->line,buffer);
786 strcat(dfp->line," { ");
787 flush_line_to_header(dfp);
788 dfp->bracelevel=1;
789 }
790
791
792
793 # line 727 "dynfile.dy"
close_struct(DYNFILE * dfp,char * str,...)794 void close_struct(DYNFILE * dfp,char * str, ...)
795 {
796 char buffer[MAXLINE];
797 va_list ap;
798
799 flush_line_to_header(dfp);
800
801 va_start(ap,str);
802
803 vsprintf(buffer,str,ap);
804
805 current_indent(dfp);
806
807 strcat(dfp->line,"} ");
808 strcat(dfp->line,buffer);
809
810 pad_line(dfp);
811
812 dfp->bracelevel--;
813 flush_line_to_header(dfp);
814
815 }
816
817 # line 750 "dynfile.dy"
struct_macro(DYNFILE * dfp,char * str,...)818 void struct_macro(DYNFILE * dfp,char * str, ...)
819 {
820 char buffer[MAXLINE];
821 va_list ap;
822
823 flush_line_to_header(dfp);
824
825 va_start(ap,str);
826 vsprintf(buffer,str,ap);
827 va_end(ap);
828 strcat(dfp->line,buffer);
829
830 pad_line(dfp);
831 }
832
833 # line 765 "dynfile.dy"
struct_expr(DYNFILE * dfp,char * str,...)834 void struct_expr(DYNFILE * dfp,char * str, ...)
835 {
836 char buffer[MAXLINE];
837 va_list ap;
838
839 flush_line_to_header(dfp);
840 current_indent(dfp);
841
842
843 va_start(ap,str);
844 vsprintf(buffer,str,ap);
845 va_end(ap);
846 strcat(dfp->line,buffer);
847
848 if( real_is_unfinished_expression(buffer) )
849 strcat(dfp->line,"; ");
850
851
852 pad_line(dfp);
853 }
854
855
856
857 /*** Comments ***/
858
859 # line 790 "dynfile.dy"
add_block_comment(DYNFILE * dfp,char * str,...)860 void add_block_comment(DYNFILE * dfp,char * str, ...)
861 {
862 char buffer[MAXLINE];
863 va_list ap;
864
865 flush_line(dfp);
866
867 va_start(ap,str);
868 vsprintf(buffer,str,ap);
869 va_end(ap);
870
871 current_indent(dfp);
872
873 strcat(dfp->line,"/* ");
874 strcat(dfp->line,buffer);
875 strcat(dfp->line," */");
876
877 dfp->commentstart=0;
878
879 }
880
881 # line 811 "dynfile.dy"
add_end_comment(DYNFILE * dfp,char * str,...)882 void add_end_comment(DYNFILE * dfp,char * str, ...)
883 {
884 char buffer[MAXLINE];
885 va_list ap;
886
887
888 va_start(ap,str);
889
890 vsprintf(buffer,str,ap);
891
892 strcat(dfp->line,"/* ");
893 strcat(dfp->line,buffer);
894 strcat(dfp->line," */");
895
896 flush_line(dfp);
897 }
898
899 # line 828 "dynfile.dy"
add_end_comment_header(DYNFILE * dfp,char * str,...)900 void add_end_comment_header(DYNFILE * dfp,char * str, ...)
901 {
902 char buffer[MAXLINE];
903 va_list ap;
904
905
906 va_start(ap,str);
907
908 vsprintf(buffer,str,ap);
909
910 strcat(dfp->line,"/* ");
911 strcat(dfp->line,buffer);
912 strcat(dfp->line," */");
913
914 flush_line_to_header(dfp);
915 }
916
917
918 # line 846 "dynfile.dy"
set_commentstart(DYNFILE * dfp,int s)919 void set_commentstart(DYNFILE * dfp,int s)
920 {
921
922 dfp->commentstart=s;
923 }
924
925
926 # line 853 "dynfile.dy"
current_indent(DYNFILE * dfp)927 void current_indent(DYNFILE * dfp)
928 {
929 register int i;
930
931 dfp->line[0] = '\0';
932
933 if( dfp->bracelevel == 0)
934 return;
935
936 strcat(dfp->line," ");
937 for(i=0;i<dfp->bracelevel;i++ ){
938 strcat(dfp->line," ");
939 }
940
941 }
942
943 # line 869 "dynfile.dy"
startcase(DYNFILE * dfp)944 void startcase(DYNFILE * dfp)
945 {
946 flush_line(dfp);
947 dfp->bracelevel++;
948 }
949
950 # line 875 "dynfile.dy"
closecase(DYNFILE * dfp)951 void closecase(DYNFILE * dfp)
952 {
953 flush_line(dfp);
954 dfp->bracelevel--;
955 }
956
957
958
959
960 # line 884 "dynfile.dy"
startbrace_tag(DYNFILE * dfp,char * str)961 void startbrace_tag(DYNFILE * dfp,char * str)
962 {
963 strcat(dfp->line," { ");
964 dfp->bracelevel++;
965 strcat(dfp->line,"/*");
966 strcat(dfp->line,str);
967 strcat(dfp->line,"*/");
968 flush_line(dfp);
969 if( dfp->tag[dfp->bracelevel] != NULL) {
970 warn("Missalgined tags in tag brace. Bad bad bug");
971 dfp->tag[dfp->bracelevel] = NULL;
972 }
973
974 dfp->tag[dfp->bracelevel]=stringalloc(str);
975
976 }
977
978 # line 901 "dynfile.dy"
startbrace(DYNFILE * dfp)979 void startbrace(DYNFILE * dfp)
980 {
981 strcat(dfp->line," { ");
982 flush_line(dfp);
983 dfp->bracelevel++;
984 }
985
986 # line 908 "dynfile.dy"
closebrace(DYNFILE * dfp)987 void closebrace(DYNFILE * dfp)
988 {
989 flush_line(dfp);
990 current_indent(dfp);
991 strcat(dfp->line,"} ");
992 if( dfp->tag[dfp->bracelevel] != NULL) {
993 add_end_comment(dfp,"end of %s",dfp->tag[dfp->bracelevel]);
994 dfp->tag[dfp->bracelevel]=ckfree(dfp->tag[dfp->bracelevel]);
995 }
996
997 flush_line(dfp);
998 dfp->bracelevel--;
999 dfp->commentstart=0;
1000 }
1001
1002
1003 # line 924 "dynfile.dy"
fputs_func_DYNFILE(char * str,DYNFILE * dfp)1004 void fputs_func_DYNFILE(char * str,DYNFILE * dfp)
1005 {
1006 fputs(str,dfp->func);
1007 fputc('\n',dfp->func);
1008 dfp->funcpos++;
1009 }
1010
1011
1012 /** I/O stuff **/
1013
1014
1015 # line 935 "dynfile.dy"
open_std_no_html_dynfile(char * name)1016 DYNFILE * open_std_no_html_dynfile(char * name)
1017 {
1018 return open_std_dynfile(name,NULL);
1019 }
1020
1021 # line 940 "dynfile.dy"
open_std_dynfile(char * name,char * html_directory)1022 DYNFILE * open_std_dynfile(char * name,char * html_directory)
1023 {
1024 DYNFILE * dfp;
1025 char func_buf[512];
1026 char head_buf[512];
1027 char html_buf[1024];
1028 int len;
1029
1030 if( (len=strlen(name)) > 509 ) {
1031 warn("I can't believe this, but you are attempting to open a DYNFILE with a name longer than 509 letter. Surely not! [%s]",name);
1032 return NULL;
1033 }
1034
1035 if( html_directory != NULL && strlen(html_directory) + len > 1020 ) {
1036 warn("I can't believe this, but a combination of the html directory path and the dynamite name is over 1020 letters. Can't handle it [%s][%s]",html_directory,name);
1037 return NULL;
1038 }
1039
1040
1041 sprintf(func_buf,"%s.c",name);
1042 sprintf(head_buf,"%s.h",name);
1043 if( html_directory != NULL )
1044 sprintf(html_buf,"%s/%s.html",html_directory,name);
1045
1046
1047
1048 dfp = DYNFILE_alloc_std();
1049
1050 dfp->func = openfile(func_buf,"W");
1051 if( dfp->func == NULL ) {
1052 close_dynfile(dfp);
1053 warn("Could not open %s as a function file",func_buf);
1054 return NULL;
1055 }
1056
1057
1058 dfp->head = openfile(head_buf,"W");
1059 if( dfp->head == NULL ) {
1060 close_dynfile(dfp);
1061 warn("Could not open %s as a header file",head_buf);
1062 return NULL;
1063 }
1064
1065 if( html_directory != NULL ) {
1066 dfp->html = openfile(html_buf,"W");
1067 if( dfp->html == NULL ) {
1068 close_dynfile(dfp);
1069 warn("Could not open %s as a html file",html_buf);
1070 return NULL;
1071 }
1072 }
1073
1074 /*** put in "standard" headers etc ****/
1075
1076 fprintf(dfp->head,"#ifndef DYNAMITE%sHEADERFILE\n#define DYNAMITE%sHEADERFILE\n",name,name);
1077 fprintf(dfp->head,"#ifdef _cplusplus\nextern \"C\" {\n#endif\n");
1078 fprintf(dfp->func,"#ifdef _cplusplus\nextern \"C\" {\n#endif\n");
1079
1080 dfp->sourceroot = stringalloc(name);
1081
1082 /*** put in standard header ***/
1083
1084 dfp->funcpos = 3; /* function file on its 3rd line */
1085
1086
1087 return dfp;
1088 }
1089
1090 # line 1008 "dynfile.dy"
close_dynfile(DYNFILE * dfp)1091 void close_dynfile(DYNFILE * dfp)
1092 {
1093
1094 /*** finish C function file ***/
1095 flush_line(dfp);
1096
1097 /*** finish C header file ***/
1098
1099 fprintf(dfp->func,"\n#ifdef _cplusplus\n}\n#endif\n");
1100 fprintf(dfp->head,"\n#ifdef _cplusplus\n}\n#endif\n");
1101 fprintf(dfp->head,"\n#endif\n");
1102
1103
1104
1105 if( dfp->html != NULL)
1106 fclose(dfp->html);
1107
1108 if( dfp->head != NULL)
1109 fclose(dfp->head);
1110
1111 if( dfp->func != NULL)
1112 fclose(dfp->func);
1113
1114 dfp = free_DYNFILE(dfp);
1115
1116 }
1117
1118
1119
1120
1121
1122 # line 1095 "dynfile.c"
1123 /* Function: swap_DYNFILE(list,i,j)
1124 *
1125 * Descrip: swap function: an internal for qsort_DYNFILE
1126 * swaps two positions in the array
1127 *
1128 *
1129 * Arg: list [UNKN ] List of structures to swap in [FuncInfo **]
1130 * Arg: i [UNKN ] swap position [int]
1131 * Arg: j [UNKN ] swap position [int]
1132 *
1133 */
1134 /* swap function for qsort function */
swap_DYNFILE(FuncInfo ** list,int i,int j)1135 void swap_DYNFILE(FuncInfo ** list,int i,int j)
1136 {
1137 FuncInfo * temp;
1138 temp=list[i];
1139 list[i]=list[j];
1140 list[j]=temp;
1141 }
1142
1143
1144 /* Function: qsort_DYNFILE(list,left,right,comp)
1145 *
1146 * Descrip: qsort - lifted from K&R
1147 * sorts the array using quicksort
1148 * Probably much better to call sort_DYNFILE which sorts from start to end
1149 *
1150 *
1151 * Arg: list [UNKN ] List of structures to swap in [FuncInfo **]
1152 * Arg: left [UNKN ] left position [int]
1153 * Arg: right [UNKN ] right position [int]
1154 * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1155 *
1156 */
qsort_DYNFILE(FuncInfo ** list,int left,int right,int (* comp)(FuncInfo *,FuncInfo *))1157 void qsort_DYNFILE(FuncInfo ** list,int left,int right,int (*comp)(FuncInfo * ,FuncInfo * ))
1158 {
1159 int i,last;
1160 if( left >= right )
1161 return;
1162
1163
1164 swap_DYNFILE(list,left,(left+right)/2);
1165 last = left;
1166 for ( i=left+1; i <= right;i++) {
1167 if( (*comp)(list[i],list[left]) < 0)
1168 swap_DYNFILE (list,++last,i);
1169 }
1170 swap_DYNFILE (list,left,last);
1171 qsort_DYNFILE(list,left,last-1,comp);
1172 qsort_DYNFILE(list,last+1,right,comp);
1173 }
1174
1175
1176 /* Function: sort_DYNFILE(obj,comp)
1177 *
1178 * Descrip: sorts from start to end using comp
1179 * sorts the array using quicksort by calling qsort_DYNFILE
1180 *
1181 *
1182 * Arg: obj [UNKN ] Object containing list [DYNFILE *]
1183 * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1184 *
1185 */
sort_DYNFILE(DYNFILE * obj,int (* comp)(FuncInfo *,FuncInfo *))1186 void sort_DYNFILE(DYNFILE * obj,int (*comp)(FuncInfo *, FuncInfo *))
1187 {
1188 qsort_DYNFILE(obj->info,0,obj->len-1,comp);
1189 return;
1190 }
1191
1192
1193 /* Function: expand_DYNFILE(obj,len)
1194 *
1195 * Descrip: Really an internal function for add_DYNFILE
1196 *
1197 *
1198 * Arg: obj [UNKN ] Object which contains the list [DYNFILE *]
1199 * Arg: len [UNKN ] Length to add one [int]
1200 *
1201 * Return [UNKN ] Undocumented return value [boolean]
1202 *
1203 */
expand_DYNFILE(DYNFILE * obj,int len)1204 boolean expand_DYNFILE(DYNFILE * obj,int len)
1205 {
1206
1207
1208 if( obj->maxlen > obj->len ) {
1209 warn("expand_DYNFILE called with no need");
1210 return TRUE;
1211 }
1212
1213
1214 if( (obj->info = (FuncInfo ** ) ckrealloc (obj->info,sizeof(FuncInfo *)*len)) == NULL) {
1215 warn("ckrealloc failed for expand_DYNFILE, returning FALSE");
1216 return FALSE;
1217 }
1218 obj->maxlen = len;
1219 return TRUE;
1220 }
1221
1222
1223 /* Function: add_DYNFILE(obj,add)
1224 *
1225 * Descrip: Adds another object to the list. It will expand the list if necessary
1226 *
1227 *
1228 * Arg: obj [UNKN ] Object which contains the list [DYNFILE *]
1229 * Arg: add [OWNER] Object to add to the list [FuncInfo *]
1230 *
1231 * Return [UNKN ] Undocumented return value [boolean]
1232 *
1233 */
1234 /* will expand function if necessary */
add_DYNFILE(DYNFILE * obj,FuncInfo * add)1235 boolean add_DYNFILE(DYNFILE * obj,FuncInfo * add)
1236 {
1237 if( obj->len >= obj->maxlen) {
1238 if( expand_DYNFILE(obj,obj->len + DYNFILELISTLENGTH) == FALSE)
1239 return FALSE;
1240 }
1241
1242
1243 obj->info[obj->len++]=add;
1244 return TRUE;
1245 }
1246
1247
1248 /* Function: flush_DYNFILE(obj)
1249 *
1250 * Descrip: Frees the list elements, sets length to 0
1251 * If you want to save some elements, use hard_link_xxx
1252 * to protect them from being actually destroyed in the free
1253 *
1254 *
1255 * Arg: obj [UNKN ] Object which contains the list [DYNFILE *]
1256 *
1257 * Return [UNKN ] Undocumented return value [int]
1258 *
1259 */
flush_DYNFILE(DYNFILE * obj)1260 int flush_DYNFILE(DYNFILE * obj)
1261 {
1262 int i;
1263
1264
1265 for(i=0;i<obj->len;i++) { /*for i over list length*/
1266 if( obj->info[i] != NULL) {
1267 free_FuncInfo(obj->info[i]);
1268 obj->info[i] = NULL;
1269 }
1270 } /* end of for i over list length */
1271
1272
1273 obj->len = 0;
1274 return i;
1275 }
1276
1277
1278 /* Function: DYNFILE_alloc_std(void)
1279 *
1280 * Descrip: Equivalent to DYNFILE_alloc_len(DYNFILELISTLENGTH)
1281 *
1282 *
1283 *
1284 * Return [UNKN ] Undocumented return value [DYNFILE *]
1285 *
1286 */
DYNFILE_alloc_std(void)1287 DYNFILE * DYNFILE_alloc_std(void)
1288 {
1289 return DYNFILE_alloc_len(DYNFILELISTLENGTH);
1290 }
1291
1292
1293 /* Function: DYNFILE_alloc_len(len)
1294 *
1295 * Descrip: Allocates len length to all lists
1296 *
1297 *
1298 * Arg: len [UNKN ] Length of lists to allocate [int]
1299 *
1300 * Return [UNKN ] Undocumented return value [DYNFILE *]
1301 *
1302 */
DYNFILE_alloc_len(int len)1303 DYNFILE * DYNFILE_alloc_len(int len)
1304 {
1305 DYNFILE * out; /* out is exported at the end of function */
1306
1307
1308 /* Call alloc function: return NULL if NULL */
1309 /* Warning message alread in alloc function */
1310 if((out = DYNFILE_alloc()) == NULL)
1311 return NULL;
1312
1313
1314 /* Calling ckcalloc for list elements */
1315 if((out->info = (FuncInfo ** ) ckcalloc (len,sizeof(FuncInfo *))) == NULL) {
1316 warn("Warning, ckcalloc failed in DYNFILE_alloc_len");
1317 return NULL;
1318 }
1319 out->len = 0;
1320 out->maxlen = len;
1321
1322
1323 return out;
1324 }
1325
1326
1327 /* Function: hard_link_DYNFILE(obj)
1328 *
1329 * Descrip: Bumps up the reference count of the object
1330 * Meaning that multiple pointers can 'own' it
1331 *
1332 *
1333 * Arg: obj [UNKN ] Object to be hard linked [DYNFILE *]
1334 *
1335 * Return [UNKN ] Undocumented return value [DYNFILE *]
1336 *
1337 */
hard_link_DYNFILE(DYNFILE * obj)1338 DYNFILE * hard_link_DYNFILE(DYNFILE * obj)
1339 {
1340 if( obj == NULL ) {
1341 warn("Trying to hard link to a DYNFILE object: passed a NULL object");
1342 return NULL;
1343 }
1344 obj->dynamite_hard_link++;
1345 return obj;
1346 }
1347
1348
1349 /* Function: DYNFILE_alloc(void)
1350 *
1351 * Descrip: Allocates structure: assigns defaults if given
1352 *
1353 *
1354 *
1355 * Return [UNKN ] Undocumented return value [DYNFILE *]
1356 *
1357 */
DYNFILE_alloc(void)1358 DYNFILE * DYNFILE_alloc(void)
1359 {
1360 DYNFILE * out; /* out is exported at end of function */
1361
1362
1363 /* call ckalloc and see if NULL */
1364 if((out=(DYNFILE *) ckalloc (sizeof(DYNFILE))) == NULL) {
1365 warn("DYNFILE_alloc failed ");
1366 return NULL; /* calling function should respond! */
1367 }
1368 out->dynamite_hard_link = 1;
1369 #ifdef PTHREAD
1370 pthread_mutex_init(&(out->dynamite_mutex),NULL);
1371 #endif
1372 out->desc_type = DYN_DESC_EDDY;
1373 /* line[1024] is an array: no default possible */
1374 out->commentstart = 0;
1375 out->bracelevel = 0;
1376 out->infunc = FALSE;
1377 out->sourceroot = NULL;
1378 out->info = NULL;
1379 out->len = out->maxlen = 0;
1380 out->mi = NULL;
1381 out->funcpos = 0;
1382 out->code_debug_level = 0;
1383 out->should_hard_link = FALSE;
1384 out->package_name = NULL;
1385
1386
1387 return out;
1388 }
1389
1390
1391 /* Function: free_DYNFILE(obj)
1392 *
1393 * Descrip: Free Function: removes the memory held by obj
1394 * Will chain up to owned members and clear all lists
1395 *
1396 *
1397 * Arg: obj [UNKN ] Object that is free'd [DYNFILE *]
1398 *
1399 * Return [UNKN ] Undocumented return value [DYNFILE *]
1400 *
1401 */
free_DYNFILE(DYNFILE * obj)1402 DYNFILE * free_DYNFILE(DYNFILE * obj)
1403 {
1404 int return_early = 0;
1405 int i;
1406
1407
1408 if( obj == NULL) {
1409 warn("Attempting to free a NULL pointer to a DYNFILE obj. Should be trappable");
1410 return NULL;
1411 }
1412
1413
1414 #ifdef PTHREAD
1415 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1416 #endif
1417 if( obj->dynamite_hard_link > 1) {
1418 return_early = 1;
1419 obj->dynamite_hard_link--;
1420 }
1421 #ifdef PTHREAD
1422 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1423 #endif
1424 if( return_early == 1)
1425 return NULL;
1426 /* obj->*tag[128] is linked in */
1427 if( obj->sourceroot != NULL)
1428 ckfree(obj->sourceroot);
1429 /* obj->func is linked in */
1430 /* obj->head is linked in */
1431 /* obj->html is linked in */
1432 if( obj->info != NULL) {
1433 for(i=0;i<obj->len;i++) {
1434 if( obj->info[i] != NULL)
1435 free_FuncInfo(obj->info[i]);
1436 }
1437 ckfree(obj->info);
1438 }
1439 if( obj->mi != NULL)
1440 free_ModuleInfo(obj->mi);
1441 if( obj->package_name != NULL)
1442 ckfree(obj->package_name);
1443
1444
1445 ckfree(obj);
1446 return NULL;
1447 }
1448
1449
1450
1451 #ifdef _cplusplus
1452 }
1453 #endif
1454