/[MITgcm]/mitgcm.org/devel/buildweb/code-browser/F90Mapper/main.c
ViewVC logotype

Contents of /mitgcm.org/devel/buildweb/code-browser/F90Mapper/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download)
Thu Jan 17 21:05:34 2008 UTC (17 years, 6 months ago) by cnh
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +2 -1 lines
File MIME type: text/plain
Standard incs that need to be there these days.

1 /* $Id: main.c,v 1.3 2004/02/17 15:37:34 edhill Exp $ */
2
3 /*
4 Driver routine for generating hypertext instrumented code
5 from a tree of Fortran source. Hypertext instrumentation allows
6 symbols (subroutine names, variable names etc... )
7 to be selected in a browser. When a symbol is selected
8 a table showing the definition of that symbol and all
9 its occurences within the full code tree appears.
10 For each occurence synopsis information, for example
11 the line number the file name and the source text of the
12 line referred to is shown.
13 This table is also hypertext. By selecting entries in the
14 table, for example the line number or the file name or
15 a variable in the source text line that is reproduced
16 other elements of the hypertext can be brought up.
17 A mechanism for displaying attributes related to symbols
18 is also includeed. Attributes describe what class or
19 classes a symbol belongs to, for example is the symbol
20 a function name, an input parameter, a compile time
21 operator etc... Summary tables are also generated
22 for viewing the output by attribute.
23 A mechanism for linking to an external document, such
24 as a text manual, is also included.
25 */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
31
32 #include "DD.h"
33 #include "FD.h"
34 #include "GLOBALS.h"
35
36 /* Variable Dictionary Parser */
37 FILE *VarDicin;
38 int VarDicParseError = 0;
39 int VarDicdebug;
40 char *vDictTitleWord = NULL;
41 static char vDictDefaultTitleWord[] = "DICTIONARY";
42
43 /* F90 Symbol Parser */
44 FILE *F90symin;
45 int nSrcFile=0; /* Counter for source file number */
46 int F90symdebug;
47
48 /* Command Line Arguments */
49 struct{
50 char *dictFile; /* Variable dictionary file */
51 char *outDir; /* Output directory */
52 int nSFiles; /* No. files in source list */
53 char **srcFiles; /* Files containing source */
54 } argList;
55
56 main (argc, argv)
57 int argc;
58 char *argv[];
59 {
60 char vdictName[MAXPATHNAM];
61 char procdictName[MAXPATHNAM];
62 char parmdictName[MAXPATHNAM];
63 char compdictName[MAXPATHNAM];
64 FILE *htout;
65
66 /* Process inout args */
67 if ( GetArgs(argc, argv) == 0 ) {
68 fprintf(stderr,
69 "Usage: %s [-d Dictionary] [-o OutputDirectory] file(s)\n",argv[0]);
70 exit(0);
71 }
72
73 /* Create output directory */
74 if ( argList.outDir == NULL ) {
75 argList.outDir = OUTDIR;
76 }
77 if ( makeOutputDirectories(argList.outDir) != 0 ) {
78 fprintf(stderr,"Unables to create output directory structure\n");
79 fprintf(stderr,"%s\n",argList.outDir);
80 fprintf(stderr,"%s/%s\n",argList.outDir,SRCSUF);
81 fprintf(stderr,"%s/%s\n",argList.outDir,VARSUF);
82 exit(0);
83 }
84
85 /* Scan input name definition table */
86 VarDicdebug=0;
87 ParseVarDic();
88 if ( VarDicParseError != 0 )
89 {
90 if ( argList.dictFile != NULL ) {
91 fprintf(stderr,"Error(s) occured reading dictionary \"%s\".",
92 argList.dictFile);
93 }
94 fprintf(stderr," Program ending.\n");
95 exit(0);
96 }
97
98 /* Scan code to get all variable names */
99 /* Set initial state of F77/F90 analyser */
100 F90symdebug=0;
101 inNameList=0;
102 inIfdef=0;
103 clearNameIsProcName();
104 /* Run the analysis */
105 ParseF90Code();
106
107 /* Sort the table of variable uses */
108 tblSort();
109
110 /* Print out the data dictionary */
111 ddPrint();
112
113 /* Generate individual variable description tables */
114 GenerateVarTables();
115
116 /* Generate large single table */
117 ddSort();
118
119 sprintf(vdictName,"%s/%s",rootDir,VDICT);
120 vdictfd = fopen(vdictName,"w");
121
122 sprintf(procdictName,"%s/%s%s",rootDir,PROCDICT,HTMLSUF);
123 procdictfd = fopen(procdictName,"w");
124
125 sprintf(parmdictName,"%s/%s%s",rootDir,PARMDICT,HTMLSUF);
126 parmdictfd = fopen(parmdictName,"w");
127
128 sprintf(compdictName,"%s/%s%s",rootDir,COMPDICT,HTMLSUF);
129 compdictfd = fopen(compdictName,"w");
130
131
132 /* Table of all symbols */
133 GenerateVDict();
134 /* Table of just procedure names */
135 ddSetCurrent(0);
136 GenerateProcDict();
137 /* Table of just compile time switching symbols */
138 ddSetCurrent(0);
139 GeneratePrecompDict();
140 /* Table of just runtime parameters */
141 ddSetCurrent(0);
142 GenerateParamDict();
143
144 /* Generate index of variables */
145 ddSetCurrent(0);
146 GenerateVDictIndex();
147
148 ddSetCurrent(0);
149 /* Generate tables of source files and directories */
150 fdTab();
151
152 /* Generate the HTML menus */
153 /* Top level menu */
154 mainMenu();
155 /* Submenu for browsing all symbol list */
156 ddSetCurrent(0);
157 allSymbolsMenu();
158 /* Submenu for browsing functions and procedures list */
159 ddSetCurrent(0);
160 allSubfuncMenu();
161 /* Submenu for browsing runtime parameters list */
162 ddSetCurrent(0);
163 allRTParmMenu();
164 /* Submenu for browsing compile time switches list */
165 ddSetCurrent(0);
166 allCTParmMenu();
167 /* Submenu for browsing source by directory and file name */
168 allDFMenu();
169
170 }
171
172 mainMenu() {
173 FILE *htout;
174 /* Try a bit of extra HTML */
175 /* Main Menu */
176 htout=fopen("code_reference.htm","w");
177 html_start(htout); html_ul(htout);
178
179 html_entryli(htout,"Overview","callTree.html target=mainBodyFrame","h3");
180 html_entryli(htout,"Subroutines and Functions","code_reference-subfunc_exp.htm","h3");
181 html_entryli(htout,"Runtime Parameters","code_reference-rtparm_exp.htm","h3");
182 html_entryli(htout,"Compile Time Parameters","code_reference-ctparm_exp.htm","h3");
183 html_entryli(htout,"Source Files","code_reference-sf_exp.htm","h3");
184 html_entryli(htout,"All Symbols","code_reference-vi_exp.htm","h3");
185
186 html_eul(htout); html_end(htout);
187 fprintf(htout,"\n");
188 fclose(htout);
189
190 }
191
192 allSymbolsMenu() {
193 FILE *htout;
194 ddRecord *curRec;
195 char curLetter = ' ';
196 char clstr[2];
197 char subURL[MAXPATHNAM];
198
199 /* VI Sub-Menu */
200 htout=fopen("code_reference-vi_exp.htm","w");
201 html_start(htout);
202 fprintf(htout,"\n");
203 html_ul(htout);
204 fprintf(htout,"<H3>%s</H3>","Variable Index");
205
206 html_ul(htout);
207 html_entryli(htout,"All (compact form)","vdb/index.htm target=codeBrowserWindow","h4");
208 html_entryli(htout,"All (detailed form)","vdb/vdict.htm target=codeBrowserWindow","h4");
209 html_li(htout);
210 while ( ddGetCurrent(&curRec) != 0 ){
211 if ( toupper(curRec->name[0]) != curLetter ){
212 curLetter = toupper(curRec->name[0]);
213 sprintf(subURL,"%s/%s_pref%c%s target=codeBrowserWindow",
214 rootDir,"vdict",curLetter,HTMLSUF);
215 clstr[0]=curLetter;clstr[1]='\0';
216 html_entry(htout,clstr,subURL,"h4"); fprintf(htout,", ");
217 }
218 }
219 html_eli(htout);
220 html_eul(htout);
221
222 html_eul(htout);
223 html_end(htout);
224 fprintf(htout,"\n");
225 fclose(htout);
226 }
227
228 allSubfuncMenu() {
229 FILE *htout;
230 ddRecord *curRec;
231 char curLetter = ' ';
232 char clstr[2];
233 char subURL[MAXPATHNAM];
234
235 /* VI Sub-Menu */
236 htout=fopen("code_reference-subfunc_exp.htm","w");
237 html_start(htout);
238 fprintf(htout,"\n");
239
240 fprintf(htout,"<H3>%s</H3","Subroutines and Functions");
241 html_ul(htout);
242 sprintf(subURL,"%s/%s%s target=codeBrowserWindow",
243 rootDir,PROCDICT,HTMLSUF);
244 html_entryli(htout,"All",subURL,"h4");
245 html_li(htout);
246 while ( ddGetCurrent(&curRec) != 0 ){
247 if ( curRec->isProcName == 1 ) {
248 if ( toupper(curRec->name[0]) != curLetter ){
249 curLetter = toupper(curRec->name[0]);
250 sprintf(subURL,"%s/%s_pref%c%s target=codeBrowserWindow",
251 rootDir,PROCDICT,curLetter,HTMLSUF);
252 clstr[0]=curLetter;clstr[1]='\0';
253 html_entry(htout,clstr,subURL,"h4"); fprintf(htout,", ");
254 }
255 }
256 }
257 html_eli(htout);
258 html_eul(htout);
259
260 html_end(htout);
261 fprintf(htout,"\n");
262 fclose(htout);
263 }
264
265 allRTParmMenu() {
266 FILE *htout;
267 ddRecord *curRec;
268 char curLetter = ' ';
269 char clstr[2];
270 char subURL[MAXPATHNAM];
271
272 /* RTparm Sub-Menu */
273 htout=fopen("code_reference-rtparm_exp.htm","w");
274 html_start(htout);
275 html_start(htout);
276
277 fprintf(htout,"<H3>%s</H3>","Runtime Parameters");
278 html_ul(htout);
279 sprintf(subURL,"%s/%s%s target=codeBrowserWindow",
280 rootDir,PARMDICT,HTMLSUF);
281 html_entryli(htout,"All",subURL,"h4");
282 html_li(htout);
283 while ( ddGetCurrent(&curRec) != 0 ){
284 if ( curRec->isInNameList == 1 ) {
285 if ( toupper(curRec->name[0]) != curLetter ){
286 curLetter = toupper(curRec->name[0]);
287 sprintf(subURL,"%s/%s_pref%c%s target=codeBrowserWindow",
288 rootDir,PARMDICT,curLetter,HTMLSUF);
289 clstr[0]=curLetter;clstr[1]='\0';
290 html_entry(htout,clstr,subURL,"h4"); fprintf(htout,", ");
291 }
292 }
293 }
294 html_eli(htout);
295 html_eul(htout);
296
297 html_end(htout);
298 fprintf(htout,"\n");
299 fclose(htout);
300 }
301
302 allCTParmMenu() {
303 FILE *htout;
304 ddRecord *curRec;
305 char curLetter = ' ';
306 char clstr[2];
307 char subURL[MAXPATHNAM];
308
309 /* CTparm Sub-Menu */
310 htout=fopen("code_reference-ctparm_exp.htm","w");
311 html_start(htout); html_ul(htout);
312 fprintf(htout,"\n");
313
314 html_entryli(htout,"Overview","callTree.html target=mainBodyFrame","h3");
315 html_entryli(htout,"Subroutines and Functions","code_reference-subfunc_exp.htm","h3");
316 html_entryli(htout,"Runtime Parameters","code_reference-rtparm_exp.htm","h3");
317 html_entryli(htout,"Compile Time Parameters","code_reference.htm","h3");
318 html_ul(htout);
319 sprintf(subURL,"%s/%s%s target=mainBodyFrame",
320 rootDir,COMPDICT,HTMLSUF);
321 html_entryli(htout,"All",subURL,"h4");
322 html_li(htout);
323 while ( ddGetCurrent(&curRec) != 0 ){
324 if ( curRec->isInIfdef == 1 ) {
325 if ( toupper(curRec->name[0]) != curLetter ){
326 curLetter = toupper(curRec->name[0]);
327 sprintf(subURL,"%s/%s_pref%c%s target=mainBodyFrame",
328 rootDir,COMPDICT,curLetter,HTMLSUF);
329 clstr[0]=curLetter;clstr[1]='\0';
330 html_entry(htout,clstr,subURL,"h4"); fprintf(htout,", ");
331 }
332 }
333 }
334 html_eli(htout);
335 html_eul(htout);
336 html_entryli(htout,"Source Files","code_reference-sf_exp.htm","h3");
337 html_entryli(htout,"All Symbols","code_reference-vi_exp.htm","h3");
338
339 html_eul(htout); html_end(htout);
340 fprintf(htout,"\n");
341 fclose(htout);
342 }
343
344 allDFMenu() {
345 FILE *htout;
346 ddRecord *curRec;
347 char curLetter = ' ';
348 char clstr[2];
349 char subURL[MAXPATHNAM];
350
351 /* CTparm Sub-Menu */
352 htout=fopen("code_reference-sf_exp.htm","w");
353 html_start(htout);
354 fprintf(htout,"\n");
355 fprintf(htout,"<H3>%s</H3>","Source Tree");
356
357 html_ul(htout);
358 sprintf(subURL,"%s/%s%s target=codeBrowserWindow",
359 rootDir,SFDICT,HTMLSUF);
360 html_entryli(htout,"All",subURL,"h4");
361 fdFlistAlpha(htout);
362 fdDirList(htout);
363 html_eli(htout);
364 html_eul(htout);
365
366 html_end(htout);
367 fprintf(htout,"\n");
368 fclose(htout);
369 }
370
371 int GetArgs( argc, argv)
372 /* Process inout args */
373 int argc; char *argv[];
374 {
375 char *curArg; int i; char curOp; int rc;
376
377 rc =1;
378
379 for ( i = 1; i<argc; ++i){
380 curArg = argv[i];
381 if ( curArg[0] == '-' ) {
382 curOp = argv[i][1];
383 } else {
384 switch (curOp) {
385 case 'd':
386 argList.dictFile = argv[i];
387 curOp='\0';
388 break;
389 case 'o':
390 curOp='\0';
391 argList.outDir = argv[i];
392 break;
393 case '\0':
394 if ( argList.srcFiles == NULL ){
395 argList.srcFiles = (char **)malloc( sizeof(*(argList.srcFiles)) );
396 } else {
397 argList.srcFiles = (char **)
398 realloc(argList.srcFiles,
399 (argList.nSFiles+1)*sizeof(*(argList.srcFiles)) );
400 }
401 argList.nSFiles = argList.nSFiles+1;
402 if ( argList.srcFiles != NULL ) {
403 *(argList.srcFiles+(argList.nSFiles-1)) = argv[i];
404 }
405 break;
406 default:
407 fprintf(stderr,"Unknown option \"%c\"\n",curOp);
408 curOp='\0';
409 rc = 0;
410 break;
411 }
412 }
413 }
414 return(rc);
415 }
416
417 VarDicerror(s)
418 char *s;
419 {
420 fprintf(stderr,"Error: unrecognised input. <%s> Line %d Column %d\n",
421 currentFile,Lno,Cno);
422 VarDicParseError=1;
423 }
424
425 ParseVarDic()
426 {
427 int i; FILE *file;
428 /* Parser variable initialisation */
429 curName = NULL;
430 curHref = NULL;
431 curText = NULL;
432 curUnits = NULL;
433 curFootNotes = NULL;
434
435 if ( argList.dictFile != NULL ){
436 file = fopen(argList.dictFile,"r");
437 if (!file){
438 fprintf(stderr,"Unable to open file \"%s\"\n",argList.dictFile);
439 }
440 else
441 {VarDicin = file; currentFile=argList.dictFile;
442 Lno=1; Cno=1;
443 VarDicparse();
444 fclose(file);
445 }
446 }
447 }
448
449 GenerateParamDict()
450 /*
451 Generate tables of runtime parameters
452 */
453 {
454 ddRecord *curRec;
455 char *note;
456 char curLetter = ' ';
457 FILE *vdictfd_sub = NULL;
458 char vdictSubName[MAXPATHNAM];
459 char vDictSubHeader[1024];
460 static char vDictHeader[] = "Alphabetic table of All Runtime Parameters";
461
462 fprintf(stderr,"Hi there \n");
463 /* HTML headers */
464 vDictTitleWord=vDictHeader;
465 vDictStart(parmdictfd);
466 vDictTitleWord=NULL;
467
468 /* Table Entry */
469 while ( ddGetCurrent(&curRec) != 0 ){
470 if ( curRec->isInNameList == 1 ) {
471 if ( toupper(curRec->name[0]) != curLetter ){
472 curLetter = toupper(curRec->name[0]);
473 html_indexRecord(parmdictfd,curLetter);
474 html_columnHeading(parmdictfd);
475
476 /* Do sub listing for this letter and/or symbol */
477 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
478 sprintf(vdictSubName,"%s/%s_pref%c%s",rootDir,PARMDICT,curLetter,HTMLSUF);
479 vdictfd_sub = fopen(vdictSubName,"w");
480 sprintf(vDictSubHeader,"Table of runtime parameters starting with \"%c\"",curLetter);
481 vDictTitleWord=vDictSubHeader;
482 vDictStart(vdictfd_sub);
483 vDictTitleWord=NULL;
484 html_columnHeading(vdictfd_sub);
485 }
486
487 /* Start row */
488 fprintf(parmdictfd,"<TR>\n");
489 fprintf(vdictfd_sub,"<TR>\n");
490
491 /* Variable name column */
492 vDictNameCol( parmdictfd, curRec );
493 vDictNameCol( vdictfd_sub, curRec );
494
495 /* Variable def, units, refs column */
496 vDictDefnCol( parmdictfd, curRec );
497 vDictDefnCol( vdictfd_sub, curRec );
498
499 /* Variable use count */
500 vDictUsesCol( parmdictfd, curRec );
501 vDictUsesCol( vdictfd_sub, curRec );
502
503 /* End of row */
504 fprintf(parmdictfd,"</TR>\n");
505 fprintf(parmdictfd,"\n");
506 fprintf(vdictfd_sub,"</TR>\n");
507 fprintf(vdictfd_sub,"\n");
508 }
509 }
510
511 if ( parmdictfd != NULL ) {
512 /* End last Table of uses */
513 fprintf(parmdictfd,"</TABLE>");
514 /* End document */
515 fprintf(parmdictfd,"</HTML>\n");
516 fclose(parmdictfd);
517 }
518 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
519 }
520
521 GeneratePrecompDict()
522 /*
523 Generate tables of compile time parameters
524 */
525 {
526 ddRecord *curRec;
527 char *note;
528 char curLetter = ' ';
529 FILE *vdictfd_sub = NULL;
530 char vdictSubName[MAXPATHNAM];
531 char vDictSubHeader[1024];
532 static char vDictHeader[] = "Alphabetic table of All Compile Time Parameters";
533
534 fprintf(stderr,"Hi there \n");
535 /* HTML headers */
536 vDictTitleWord=vDictHeader;
537 vDictStart(compdictfd);
538 vDictTitleWord=NULL;
539
540 /* Table Entry */
541 while ( ddGetCurrent(&curRec) != 0 ){
542 if ( curRec->isInIfdef == 1 ) {
543 if ( toupper(curRec->name[0]) != curLetter ){
544 curLetter = toupper(curRec->name[0]);
545 html_indexRecord(compdictfd,curLetter);
546 html_columnHeading(compdictfd);
547
548 /* Do sub listing for this letter and/or symbol */
549 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
550 sprintf(vdictSubName,"%s/%s_pref%c%s",rootDir,COMPDICT,curLetter,HTMLSUF);
551 vdictfd_sub = fopen(vdictSubName,"w");
552 sprintf(vDictSubHeader,"Table of compile time parameters starting with \"%c\"",curLetter);
553 vDictTitleWord=vDictSubHeader;
554 vDictStart(vdictfd_sub);
555 vDictTitleWord=NULL;
556 html_columnHeading(vdictfd_sub);
557 }
558
559 /* Start row */
560 fprintf(compdictfd,"<TR>\n");
561 fprintf(vdictfd_sub,"<TR>\n");
562
563 /* Variable name column */
564 vDictNameCol( compdictfd, curRec );
565 vDictNameCol( vdictfd_sub, curRec );
566
567 /* Variable def, units, refs column */
568 vDictDefnCol( compdictfd, curRec );
569 vDictDefnCol( vdictfd_sub, curRec );
570
571 /* Variable use count */
572 vDictUsesCol( compdictfd, curRec );
573 vDictUsesCol( vdictfd_sub, curRec );
574
575 /* End of row */
576 fprintf(compdictfd,"</TR>\n");
577 fprintf(compdictfd,"\n");
578 fprintf(vdictfd_sub,"</TR>\n");
579 fprintf(vdictfd_sub,"\n");
580 }
581 }
582
583 if ( compdictfd != NULL ) {
584 /* End last Table of uses */
585 fprintf(compdictfd,"</TABLE>");
586 /* End document */
587 fprintf(compdictfd,"</HTML>\n");
588 fclose(compdictfd);
589 }
590 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
591 }
592
593 GenerateProcDict()
594 /*
595 Generate tables of procedures
596 */
597 {
598 ddRecord *curRec;
599 char *note;
600 char curLetter = ' ';
601 FILE *vdictfd_sub = NULL;
602 char vdictSubName[MAXPATHNAM];
603 char vDictSubHeader[1024];
604 static char vDictHeader[] = "Alphabetic table of all subroutines and functions";
605
606 fprintf(stderr,"Hi there \n");
607 /* HTML headers */
608 vDictTitleWord=vDictHeader;
609 vDictStart(procdictfd);
610 vDictTitleWord=NULL;
611
612 /* Table Entry */
613 while ( ddGetCurrent(&curRec) != 0 ) {
614 if ( curRec->isProcName == 1 ) {
615 if ( toupper(curRec->name[0]) != curLetter ){
616 curLetter = toupper(curRec->name[0]);
617 html_indexRecord(procdictfd,curLetter);
618 html_columnHeading(procdictfd);
619
620 /* Do sub listing for this letter and/or symbol */
621 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
622 sprintf(vdictSubName,"%s/%s_pref%c%s",rootDir,PROCDICT,curLetter,HTMLSUF);
623 vdictfd_sub = fopen(vdictSubName,"w");
624 sprintf(vDictSubHeader,"Table of subroutines anf functions starting with \"%c\"",curLetter);
625 vDictTitleWord=vDictSubHeader;
626 vDictStart(vdictfd_sub);
627 vDictTitleWord=NULL;
628 html_columnHeading(vdictfd_sub);
629
630 }
631
632 /* Start row */
633 fprintf(procdictfd,"<TR>\n");
634 fprintf(vdictfd_sub,"<TR>\n");
635
636 /* Variable name column */
637 vDictNameCol( procdictfd, curRec );
638 vDictNameCol( vdictfd_sub, curRec );
639
640 /* Variable def, units, refs column */
641 vDictDefnCol( procdictfd, curRec );
642 vDictDefnCol( vdictfd_sub, curRec );
643
644 /* Variable use count */
645 vDictUsesCol( procdictfd, curRec );
646 vDictUsesCol( vdictfd_sub, curRec );
647
648 /* End of row */
649 fprintf(procdictfd,"</TR>\n");
650 fprintf(procdictfd,"\n");
651 fprintf(vdictfd_sub,"</TR>\n");
652 fprintf(vdictfd_sub,"\n");
653 }
654 }
655
656 if ( procdictfd != NULL ) {
657 /* End last Table of uses */
658 fprintf(procdictfd,"</TABLE>");
659 /* End document */
660 fprintf(procdictfd,"</HTML>\n");
661 fclose(procdictfd);
662 }
663 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
664 }
665
666 GenerateVDict()
667 {
668 ddRecord *curRec;
669 char *note;
670 char curLetter = ' ';
671 FILE *vdictfd_sub = NULL;
672 char vdictSubName[MAXPATHNAM];
673 char vDictSubHeader[1024];
674 static char vDictHeader[] = "Alphabetic table of all symbols";
675
676 fprintf(stderr,"Hi there \n");
677 /* HTML headers */
678 vDictTitleWord=vDictHeader;
679 vDictStart(vdictfd);
680 vDictTitleWord=NULL;
681
682 /* Table Entry */
683 while ( ddGetCurrent(&curRec) != 0 ){
684 if ( toupper(curRec->name[0]) != curLetter ){
685 curLetter = toupper(curRec->name[0]);
686 html_indexRecord(vdictfd,curLetter);
687 html_columnHeading(vdictfd);
688
689 /* Do sub listing for this letter and/or symbol */
690 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
691 sprintf(vdictSubName,"%s/%s_pref%c%s",rootDir,"vdict",curLetter,HTMLSUF);
692 vdictfd_sub = fopen(vdictSubName,"w");
693 sprintf(vDictSubHeader,"Table of symbols starting with \"%c\"",curLetter);
694 vDictTitleWord=vDictSubHeader;
695 vDictStart(vdictfd_sub);
696 vDictTitleWord=NULL;
697 html_columnHeading(vdictfd_sub);
698
699 }
700
701 /* Start row */
702 fprintf(vdictfd,"<TR>\n");
703 fprintf(vdictfd_sub,"<TR>\n");
704
705 /* Variable name column */
706 vDictNameCol( vdictfd, curRec );
707 vDictNameCol( vdictfd_sub, curRec );
708
709 /* Variable def, units, refs column */
710 vDictDefnCol( vdictfd, curRec );
711 vDictDefnCol( vdictfd_sub, curRec );
712
713 /* Variable use count */
714 vDictUsesCol( vdictfd, curRec );
715 vDictUsesCol( vdictfd_sub, curRec );
716
717 /* End of row */
718 fprintf(vdictfd,"</TR>\n");
719 fprintf(vdictfd,"\n");
720 fprintf(vdictfd_sub,"</TR>\n");
721 fprintf(vdictfd_sub,"\n");
722
723 }
724
725 if ( vdictfd != NULL ) {
726 /* End last Table of uses */
727 fprintf(vdictfd,"</TABLE>");
728 /* End document */
729 fprintf(vdictfd,"</HTML>\n");
730 fclose(vdictfd);
731 }
732 if ( vdictfd_sub != NULL ) { vDictClose(vdictfd_sub); }
733
734 }
735 GenerateVDictIndex()
736 {
737 FILE *fd; char fName[MAXPATHNAM];
738 char curLetter = ' ';
739 ddRecord *curRec;
740
741 /* HTML headers */
742 sprintf(fName,"%s/%s%s",rootDir,"index",HTMLSUF);
743 fd = fopen(fName,"w");
744 fprintf(fd,"<HTML>"); fprintf(fd,"<HEAD>"); fprintf(fd,"</HEAD>");
745 fprintf(fd,"<TITLE>Name Index</TITLE>\n");
746 fprintf(fd,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\">");
747
748 while ( ddGetCurrent(&curRec) != 0 ){
749 if ( toupper(curRec->name[0]) != curLetter ){
750 curLetter = toupper(curRec->name[0]);
751 /*
752 fprintf(fd,"<BR><FONT SIZE=8 ><B>%c</A></B></FONT>\n",curLetter);
753 fprintf(fd,"<FONT SIZE=2 ><B> \n"); */
754 fprintf(fd,"<BR><BR> \n");
755 fprintf(fd,"</LI><LI> \n");
756 } else {
757 fprintf(fd,",\n");
758 }
759 if ( curRec->active > 0 ) {
760 fprintf(fd,"<A HREF=%s/%s%s>",VARSUF,curRec->key,HTMLSUF);
761 fprintf(fd,"%s</A>",curRec->name);
762 } else {
763 fprintf(fd,"%s",curRec->name);
764 }
765 }
766 /* End document */
767 fprintf(fd,"</BODY>\n");
768 fprintf(fd,"</HTML>\n");
769 fclose(fd);
770
771 }
772
773 int html_indexRecord(curFd, letter)
774 FILE *curFd;
775 char letter;
776 {
777 int i;
778
779 fprintf(curFd,"<TR>\n");
780 fprintf(curFd," <TD COLSPAN=3>\n");
781 fprintf(curFd," <FONT SIZE=8 ><B><A NAME=i_%c>%c</A></B></FONT>\n",letter,letter);
782 fprintf(curFd," <FONT SIZE=2 ><B>\n");
783 for (i=0;i<24;i=i+3){
784 fprintf(curFd," <A HREF=#i_%c><U>%c</U></A>",'A'+i,'A'+i);
785 fprintf(curFd," <A HREF=#i_%c><U>%c</U></A>",'A'+i+1,'A'+i+1);
786 fprintf(curFd," <A HREF=#i_%c><U>%c</U></A>\n",'A'+i+2,'A'+i+2);
787 }
788 fprintf(curFd," <A HREF=#i_%c><U>%c</U></A>",'Y','Y');
789 fprintf(curFd," <A HREF=#i_%c><U>%c</U></A>\n",'Z','Z');
790 fprintf(curFd," </FONT></B>\n");
791 fprintf(curFd," </TD>\n");
792 fprintf(curFd,"</TR>\n");
793 fprintf(curFd,"\n");
794 }
795
796 int html_columnHeading(FILE *curFd)
797 {
798 fprintf(curFd,"<TR>\n");
799 fprintf(curFd," <TD VALIGN=\"CENTER\" HEIGHT=40 ALIGN=\"CENTER\"> ");
800 fprintf(curFd," <FONT SIZE=5><B><U>Symbol </U></B></FONT>");
801 fprintf(curFd," </TD>\n");
802 fprintf(curFd," <TD VALIGN=\"CENTER\" HEIGHT=40 ALIGN=\"CENTER\"> ");
803 fprintf(curFd," <FONT SIZE=5><B><U>Description</U></B></FONT>");
804 fprintf(curFd," </TD>\n");
805 fprintf(curFd," <TD VALIGN=\"CENTER\" HEIGHT=40 ALIGN=\"CENTER\"> ");
806 fprintf(curFd," <FONT SIZE=5><B><U>Uses</U></B></FONT>");
807 fprintf(curFd," </TD>\n");
808 fprintf(curFd,"</TR>\n");
809 fprintf(curFd,"\n");
810 }
811
812 int vDictClose(FILE *curFd)
813 {
814 /* End last Table of uses */
815 fprintf(curFd,"</TABLE>");
816 /* End document */
817 fprintf(curFd,"</BODY></HTML>\n");
818 fclose(curFd);
819 }
820
821 int vDictStart(FILE *curFd)
822 {
823 fprintf(curFd,"<HTML>\n");
824 fprintf(curFd,"<HEAD>\n");
825 fprintf(curFd,"</HEAD>\n");
826 if ( vDictTitleWord == NULL ) vDictTitleWord = vDictDefaultTitleWord;
827 fprintf(curFd,"<TITLE>%s</TITLE>\n",vDictTitleWord);
828 fprintf(curFd,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\">");
829 /* Begin table */
830 fprintf(curFd,
831 "<TABLE BORDER CELLSPACING=1 BORDERCOLOR=\"#000000\" CELLPADDING=2 >\n");
832 }
833
834 int vDictNameCol(FILE *vdictfd, ddRecord *curRec)
835 {
836 if ( curRec->active > 0 ) {
837 fprintf(vdictfd," <TD>\n <B><FONT FACE=\"Courier\"><A HREF=%s/%s%s> ",
838 VARSUF,curRec->key,HTMLSUF);
839 fprintf(vdictfd,"%s </A></B></FONT>\n </TD>\n",curRec->name);
840 } else {
841 fprintf(vdictfd," <TD>\n <B><FONT FACE=\"Courier\">");
842 fprintf(vdictfd,"%s </B></FONT>\n </TD>\n",curRec->name);
843 }
844 }
845
846 vDictDefnCol(FILE *vdictfd, ddRecord *curRec )
847 {
848 char *note;
849 fprintf(vdictfd," <TD>\n");
850 fprintf(vdictfd," <A NAME=var.%s>",curRec->name);
851 if ( curRec->textEntry != NULL ) {
852 fprintf(vdictfd," %s</A>\n",curRec->textEntry);
853 } else {
854 fprintf(vdictfd," <B><U> </U></B></A>\n");
855 /* fprintf(vdictfd," <B><U>%s %s %s %s</U></B></A>\n",
856 "*** NO DEFINITION ***", "*** NO DEFINITION ***",
857 "*** NO DEFINITION ***", "*** NO DEFINITION ***"); */
858 }
859 if ( curRec->unitsEntry != NULL && strlen(curRec->unitsEntry) != 0 ){
860 fprintf(vdictfd," (<I>units</I>: %s ) \n",curRec->unitsEntry);
861 }
862 if ( curRec->hrefEntry != NULL && strlen(curRec->hrefEntry) != 0 ){
863 fprintf(vdictfd," <sub><A HREF=%s><IMG SRC=\"OpenBookIcon.gif\"",curRec->hrefEntry);
864 fprintf(vdictfd,"WIDTH=30 HEIGHT=15 ALT=\"Goto Manual\"></A></sub>\n");
865 }
866 if ( curRec->footNotesEntry != NULL ){
867 fprintf(vdictfd," <sup><B>");
868 note=strtok(curRec->footNotesEntry," ");
869 fprintf(vdictfd,"<A HREF=#footnote_%s>%s</A>",note,note);
870 while ( (note = strtok((char *)NULL," ")) != (char *)NULL ) {
871 fprintf(vdictfd,"\n, <A HREF=#footnote_%s>%s</A>",note,note);
872 }
873 fprintf(vdictfd,"</B></sup>\n");
874 }
875 fprintf(vdictfd," </TD>\n");
876 }
877
878 int vDictUsesCol(FILE *vdictfd, ddRecord *curRec)
879 {
880 fprintf(vdictfd," <TD>\n");
881 fprintf(vdictfd," %d\n",curRec->active);
882 fprintf(vdictfd," </TD>\n");
883 }
884
885 /* Record new entry in dd */
886 int addRecord()
887 {
888 ddRecord rec; int recNo;
889 rec.name = curName;
890 rec.hrefEntry = curHref;
891 rec.textEntry = curText;
892 rec.unitsEntry = curUnits;
893 rec.footNotesEntry = curFootNotes;
894 rec.active = 0;
895 fprintf(stdout,"Adding DD record %s\n",rec.name);
896 fflush(stdout);
897
898 /* Make dd entry */
899 ddAdd(&rec);
900
901 /* Free temporary name string copies */
902 if ( curName != NULL ) {
903 fprintf(stdout,"Free %s\n",curName);fflush(stdout);
904 free(curName);curName=NULL;
905 }
906 if ( curHref != NULL ) {
907 fprintf(stdout,"Free %s\n",curHref);fflush(stdout);
908 free(curHref);curHref=NULL;
909 }
910 if ( curText != NULL ) {
911 fprintf(stdout,"Free %s\n",curText);fflush(stdout);
912 free(curText);curText=NULL;
913 }
914 if ( curUnits != NULL ) {
915 fprintf(stdout,"Free %s\n",curUnits);fflush(stdout);
916 free(curUnits);curUnits=NULL;
917 }
918 if ( curFootNotes != NULL ) {
919 fprintf(stdout,"Free %s\n",curFootNotes);fflush(stdout);
920 free(curFootNotes);curFootNotes=NULL;
921 }
922
923 fprintf(stdout,"Added DD record \n");
924 fflush(stdout);
925 }
926
927 /* Join two strdup created strings and free the originals */
928 char *strjoin(s1, s2)
929 char *s1; char *s2;
930 {
931 char *s;
932
933 fprintf(stdout, "strjoin called \n");
934 fflush(stdout);
935
936 /* DEBUG - Die if both strings are NULL */
937 /* if ( s1 == NULL && s2 == NULL ) exit(); */
938
939 /* If either string is NULL return other */
940 if ( s1 == NULL ) return(s2);
941 if ( s2 == NULL ) return(s1);
942
943 s = (char *)malloc(strlen(s1)+strlen(s2)+1);
944 s = strcpy(s,s1);
945 s = strcat(s,s2);
946
947 }
948
949 /* Like strdup but changes \. into . */
950 char *strcopy(s1)
951 char *s1;
952 {
953 char *s; int i;int l; int bs; int el;
954
955 /* If string is NULL return. */
956 if ( s1 == NULL ) return(s1);
957 s = strdup(s1);
958 return(s);
959
960 l = strlen(s1)+1; bs = 0; el=0;
961 s = (char *)malloc(l);
962 if ( s == NULL ) return(s);
963 for ( i=0;i<l;++i) {
964 if ( bs == 0 ) {
965 if ( s1[i] != '\\' ) {
966 s[el]=s1[i];++el;
967 }
968 else {
969 bs = 1;
970 }
971 } else {
972 s[el]=s1[i];++el; bs=0;
973 }
974 }
975 s[el]='\0';
976 return(s);
977 }
978
979 int ParseF90Code()
980 /* Read the source code */
981 {
982 int i; FILE *file; int j;
983 char tmpFileName[MAXPATHNAM];
984 char srcFileName[MAXPATHNAM];
985 char srcDirName[MAXPATHNAM];
986
987 /* Create scratch file for loggin variable uses */
988 sprintf(tmpFileName,"%s/%s",OUTDIR,TMP1);
989 tmpfd = fopen(tmpFileName,"w");
990
991 /* Parse the list of source files */
992 if ( argList.nSFiles > 0 ) {
993 for (i=1;i<=argList.nSFiles;++i){
994 file = fopen(argList.srcFiles[i-1],"r");
995 if (!file) {
996 fprintf(stderr,"Unable to open file \"%s\"\n",argList.srcFiles[i-1]);
997 } else {
998 F90symin = file;
999 currentFile=argList.srcFiles[i-1];
1000 j=strlen(argList.srcFiles[i-1]);
1001 while ( j > 0 && *(argList.srcFiles[i-1]+j-1) != '/') --j;
1002 currentProcedure=NOPROC;
1003 Lno=1; Cno=1;
1004 currentLineHtml[0]=(char)NULL;
1005 /* Create file for writing html source */
1006 ++nSrcFile;
1007 sprintf(sHtmlName,"%s/%d%s",srcDir,nSrcFile,HTMLSUF);
1008 srcfd=fopen(sHtmlName,"w");
1009 sprintf(sHtmlName,"%d%s",nSrcFile,HTMLSUF);
1010 fprintf(srcfd,"<HTML>\n");
1011 fprintf(srcfd,"<TITLE>%s</TITLE>\n",currentFile);
1012 fprintf(srcfd,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\">\n");
1013 fprintf(srcfd,"<PRE>\n");
1014
1015 F90symparse();
1016 fprintf(srcfd,"</PRE></BODY></HTML>\n");
1017 fclose(srcfd);
1018 fclose(file);
1019 /* Write directory, file and HTML src name */
1020 strncpy(srcDirName,argList.srcFiles[i-1],MAXPATHNAM-1);
1021 srcDirName[j]='\0';
1022 if ( j == 0 ) {
1023 srcDirName[0] = '.';
1024 srcDirName[1] = '/';
1025 srcDirName[2] = '\0';
1026 }
1027 strncpy(srcFileName,argList.srcFiles[i-1]+j,MAXPATHNAM-1);
1028 srcFileName[MAXPATHNAM]='\0';
1029 printf("HTM %s %s %s\n",
1030 srcDirName, srcFileName,sHtmlName);
1031 /* Add entry to the "FileDirectory" table. */
1032 fdAdd( srcDirName, srcFileName, sHtmlName );
1033 }
1034 }
1035 fdPrint();
1036 }
1037 else
1038 {
1039 currentFile="STANDARD INPUT";currentLineHtml[0]=(char)NULL;
1040 F90symparse();
1041 }
1042
1043 fclose(tmpfd);
1044 }
1045
1046 int tblSort()
1047 {
1048 /*
1049 use system() to sort tmp1 > tmp2.
1050 Sort removes multiple entries so that if a variable appears
1051 multiple times on a single line only one table entry will
1052 be generated.
1053 */
1054 char command[500];
1055 sprintf(command,"sort %s/%s | uniq | grep -v '^ *$' > %s/%s",
1056 OUTDIR,TMP1,OUTDIR,TMP2);
1057 system(command);
1058 }
1059
1060 int GenerateVarTables()
1061 {
1062 char tmpFileName[MAXPATHNAM];
1063 char vdFileName[MAXPATHNAM];
1064 char ioBuff[currentLineHtmlSize*2];
1065 char *vNam, *vLast, *lineRef, *fileRef, *procRef, *codeRec;
1066 char *note;
1067 FILE *tabfd;
1068 ddRecord *curRec;
1069 ddRecord rec;
1070
1071 sprintf(tmpFileName,"%s/%s",OUTDIR,TMP2);
1072 tabfd = fopen(tmpFileName,"r");
1073 vLast = NULL; vdictfd = NULL;
1074
1075 while ( fscanf(tabfd,"%[^\n]%*[\n]",ioBuff) != EOF ) {
1076 /* Begin CNH debug */
1077 /* printf("ioBuff = \"%s\"\n",ioBuff); */
1078 /* exit(1); */
1079 /* End CNH debug */
1080 vNam = strtok(ioBuff,",");
1081 /* Trick here that should be fixed. */
1082 /* Testing lineRef != NULL checks to see whether the */
1083 /* there was a format error in the sorted file. The */
1084 /* file will only have an error if the parsing rules */
1085 /* are incomplete. */
1086 if ( vNam != NULL ) {
1087 lineRef = strtok(NULL,",");
1088 fileRef = strtok(NULL,",");
1089 procRef = strtok(NULL,",");
1090 codeRec = procRef+strlen(procRef)+1;
1091 if ( vLast == NULL || strcmp(vNam,vLast) != 0 ) {
1092 if ( vLast != NULL ){ free(vLast);}
1093 vLast = strdup(vNam);
1094 rec.name = vNam;
1095 curRec = ddFind(&rec);
1096 if ( curRec == NULL ) {
1097 printf("Variable %s NOT FOUND\n",vNam);
1098 exit(1);
1099 } else {
1100 printf("New variable %s key = %s\n",vNam,curRec->key);
1101 }
1102 if ( vdictfd != NULL ){
1103 /* End Table of uses */
1104 fprintf(vdictfd,"</TABLE>");
1105 /* End document */
1106 fprintf(vdictfd,"</HTML>\n");
1107 fclose(vdictfd);
1108 }
1109 sprintf(vdFileName,"%s/%s/%s%s",OUTDIR,VARSUF,curRec->key,HTMLSUF);
1110 vdictfd = fopen(vdFileName,"w");
1111 /* HTML headers */
1112 fprintf(vdictfd,"<HTML>\n");
1113 fprintf(vdictfd,"<HEAD>\n");
1114 fprintf(vdictfd,"</HEAD>\n");
1115 fprintf(vdictfd,"<TITLE>Table showing occurences of \"%s\"</TITLE>\n",curRec->name);
1116 fprintf(vdictfd,"<BODY text=\"#000000\" bgcolor=\"#FFFFFF\">\n");
1117 /* Begin table */
1118 fprintf(vdictfd,
1119 "<TABLE BORDER CELLSPACING=1 BORDERCOLOR=\"#000000\" CELLPADDING=2 >\n");
1120 html_columnHeading(vdictfd);
1121 fprintf(vdictfd,"<TR>\n");
1122 fprintf(vdictfd," <TD>\n <B><FONT FACE=\"Courier\">");
1123 fprintf(vdictfd,"%s </B></FONT>\n </TD>\n",curRec->name);
1124 fprintf(vdictfd," <TD>\n");
1125 fprintf(vdictfd," <A NAME=var.%s>",curRec->name);
1126 if ( curRec->textEntry != NULL ) {
1127 fprintf(vdictfd," %s</A>\n",curRec->textEntry);
1128 }
1129 else
1130 {
1131 fprintf(vdictfd," <B><U> </U></B></A>\n");
1132 /* fprintf(vdictfd," <B><U>%s %s %s %s</U></B></A>\n",
1133 "*** NO DEFINITION ***", "*** NO DEFINITION ***",
1134 "*** NO DEFINITION ***", "*** NO DEFINITION ***"); */
1135 }
1136 if ( curRec->unitsEntry != NULL && strlen(curRec->unitsEntry) != 0 ){
1137 fprintf(vdictfd," (<I>units</I>: %s ) \n",curRec->unitsEntry);
1138 }
1139 if ( curRec->hrefEntry != NULL && strlen(curRec->hrefEntry) != 0 ){
1140 fprintf(vdictfd," <sub><A HREF=%s><IMG SRC=\"OpenBookIcon.gif\"",curRec->hrefEntry);
1141 fprintf(vdictfd,"WIDTH=30 HEIGHT=15 ALT=\"Goto Manual\"></A></sub>\n");
1142 }
1143 if ( curRec->footNotesEntry != NULL ){
1144 fprintf(vdictfd," <sup><B>");
1145 note=strtok(curRec->footNotesEntry," ");
1146 fprintf(vdictfd,"<A HREF=#footnote_%s>%s</A>",note,note);
1147 while ( (note = strtok((char *)NULL," ")) != (char *)NULL ) {
1148 fprintf(vdictfd,"\n, <A HREF=#footnote_%s>%s</A>",note,note);
1149 }
1150 fprintf(vdictfd,"</B></sup>\n");
1151 }
1152 fprintf(vdictfd," </TD>\n");
1153 fprintf(vdictfd," <TD>\n");
1154 fprintf(vdictfd," %d\n",curRec->active);
1155 fprintf(vdictfd," </TD>\n");
1156 fprintf(vdictfd,"</TR>\n");
1157 fprintf(vdictfd,"\n");
1158 /* End header table */
1159 fprintf(vdictfd,"</TABLE>\n<BR><HR><BR>\n");
1160
1161 /* Begin table of uses */
1162 fprintf(vdictfd,
1163 "<TABLE BORDER CELLSPACING=1 BORDERCOLOR=\"#000000\" CELLPADDING=2 WIDTH=900>\n");
1164 fprintf(vdictfd,"<TR>\n<TD>File</TD>\n<TD>Line number</TD>\n<TD>Procedure</TD>\n<TD>Code</TD>\n</TR>\n");
1165 }
1166 /* Table of uses */
1167 fprintf(vdictfd,"<TR>\n");
1168 fprintf(vdictfd," <TD>\n");
1169 fprintf(vdictfd," %s",fileRef);
1170 fprintf(vdictfd," </TD>\n");
1171 fprintf(vdictfd," <TD>\n");
1172 fprintf(vdictfd," %s",lineRef);
1173 fprintf(vdictfd," </TD>\n");
1174 fprintf(vdictfd," <TD>\n");
1175 fprintf(vdictfd," %s",procRef);
1176 fprintf(vdictfd," </TD>\n");
1177 fprintf(vdictfd," <TD>\n");
1178 fprintf(vdictfd," <PRE>%s</PRE>",codeRec);
1179 fprintf(vdictfd," </TD>\n");
1180 fprintf(vdictfd,"</TR>\n");
1181 }
1182 }
1183 if ( vdictfd != NULL ){
1184 /* End last Table of uses */
1185 fprintf(vdictfd,"</TABLE>");
1186 /* End document */
1187 fprintf(vdictfd,"</BODY></HTML>\n");
1188 fclose(vdictfd);
1189 }
1190 }

  ViewVC Help
Powered by ViewVC 1.1.22