1 | #include <stdio.h> |
---|
2 | #include <string.h> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <ctype.h> |
---|
5 | #include "utils.h" |
---|
6 | |
---|
7 | extern FILE *yylpin; |
---|
8 | extern char *optarg; |
---|
9 | extern int optind, opterr, optopt; |
---|
10 | extern int lpverbose, check; |
---|
11 | extern int found_version, found_info, found_oldhelp, found_proc_in_proc; |
---|
12 | warning_info = 0, warning_version = 0; |
---|
13 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
14 | void main_init(int argc, char *argv[]) |
---|
15 | { |
---|
16 | char c, *file=NULL; |
---|
17 | |
---|
18 | while(optind<argc) { |
---|
19 | switch(c=getopt(argc, argv, "d:sf:")) |
---|
20 | { |
---|
21 | case 'd': |
---|
22 | lpverbose = 1; |
---|
23 | sscanf(optarg, "%d", &lpverbose); |
---|
24 | break; |
---|
25 | case 'f': file = argv[optind-1]; |
---|
26 | // printf("opening:%d %s\n", optind, file); |
---|
27 | break; |
---|
28 | case 's': |
---|
29 | check++; |
---|
30 | break; |
---|
31 | case -1 : printf("no such option:%s\n", argv[optind]); |
---|
32 | break; |
---|
33 | default: printf("no such option.%x, %s\n", c&0xff, argv[optind]); |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | if(file!=NULL) |
---|
38 | yylpin = fopen( file, "rb" ); |
---|
39 | else |
---|
40 | yylpin = stdin; |
---|
41 | } |
---|
42 | |
---|
43 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
44 | void main_result(char *libname) |
---|
45 | { |
---|
46 | if(!found_info) printf("*** No info-string found!\n"); |
---|
47 | if(!found_version) printf("*** No version-string found!\n"); |
---|
48 | if(found_oldhelp) printf("*** Library has stil OLD library-format.\n"); |
---|
49 | if(found_info && warning_info) |
---|
50 | printf("*** INFO-string should come before every procedure definition.\n"); |
---|
51 | if(found_version && warning_version) |
---|
52 | printf("*** VERSION-string should come before every procedure definition.\n"); |
---|
53 | } |
---|
54 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
55 | |
---|
56 | procinfo *iiInitSingularProcinfo(procinfov pi, char *libname, |
---|
57 | char *procname, int line, long pos, |
---|
58 | BOOLEAN pstatic = FALSE) |
---|
59 | { |
---|
60 | pi->libname = (char *)malloc(strlen(libname)+1); |
---|
61 | memcpy(pi->libname, libname, strlen(libname)); |
---|
62 | *(pi->libname+strlen(libname)) = '\0'; |
---|
63 | |
---|
64 | pi->procname = (char *)malloc(strlen(procname)+1); |
---|
65 | strcpy(pi->procname, procname/*, strlen(procname)*/); |
---|
66 | pi->language = LANG_SINGULAR; |
---|
67 | pi->ref = 1; |
---|
68 | pi->is_static = pstatic; |
---|
69 | pi->data.s.proc_start = pos; |
---|
70 | pi->data.s.def_end = 0L; |
---|
71 | pi->data.s.help_start = 0L; |
---|
72 | pi->data.s.body_start = 0L; |
---|
73 | pi->data.s.body_end = 0L; |
---|
74 | pi->data.s.example_start = 0L; |
---|
75 | pi->data.s.proc_lineno = line; |
---|
76 | pi->data.s.body_lineno = 0; |
---|
77 | pi->data.s.example_lineno = 0; |
---|
78 | pi->data.s.body = NULL; |
---|
79 | return(pi); |
---|
80 | } |
---|
81 | |
---|
82 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
83 | pi_clear(procinfov pi) |
---|
84 | { |
---|
85 | free(pi->libname); |
---|
86 | free(pi->procname); |
---|
87 | free(pi); |
---|
88 | } |
---|
89 | |
---|
90 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
91 | printpi(procinfov pi) |
---|
92 | { |
---|
93 | FILE *fp = fopen( pi->libname, "rb"); |
---|
94 | char *buf, name[256]; |
---|
95 | int len1, len2; |
---|
96 | |
---|
97 | if(!found_info && !warning_info) warning_info++; |
---|
98 | if(!found_version && !warning_version) warning_version++; |
---|
99 | if(pi->data.s.body_end==0) |
---|
100 | pi->data.s.body_end = pi->data.s.proc_end; |
---|
101 | |
---|
102 | printf( "%c %-15s %20s ", pi->is_static ? 'l' : 'g', pi->libname, |
---|
103 | pi->procname); |
---|
104 | printf("line %4d,%5ld-%-5ld %4d,%5ld-%-5ld %4d,%5ld-%-5ld\n", |
---|
105 | pi->data.s.proc_lineno, pi->data.s.proc_start, pi->data.s.def_end, |
---|
106 | pi->data.s.body_lineno, pi->data.s.body_start, pi->data.s.body_end, |
---|
107 | pi->data.s.example_lineno, pi->data.s.example_start, |
---|
108 | pi->data.s.proc_end); |
---|
109 | if(check) { |
---|
110 | if(!pi->is_static && (pi->data.s.body_start-pi->data.s.def_end)<4) |
---|
111 | printf("*** Procedure '%s' is global and has no help-section.\n", |
---|
112 | pi->procname); |
---|
113 | if(!pi->is_static && !pi->data.s.example_start) |
---|
114 | printf("*** Procedure '%s' is global and has no example-section.\n",\ |
---|
115 | pi->procname); |
---|
116 | if(found_proc_in_proc) |
---|
117 | printf("*** found proc within procedure '%s'.\n", pi->procname); |
---|
118 | } |
---|
119 | |
---|
120 | #if 0 |
---|
121 | if( fp != NULL) { // loading body |
---|
122 | len1 = pi->data.s.def_end - pi->data.s.proc_start; |
---|
123 | if(pi->data.s.body_end==0) |
---|
124 | len2 = pi->data.s.proc_end - pi->data.s.body_start; |
---|
125 | else len2 = pi->data.s.body_end - pi->data.s.body_start; |
---|
126 | buf = (char *)malloc(len1 + len2 + 1); |
---|
127 | fseek(fp, pi->data.s.proc_start, SEEK_SET); |
---|
128 | fread( buf, len1, 1, fp); |
---|
129 | *(buf+len1) = '\n'; |
---|
130 | fseek(fp, pi->data.s.body_start, SEEK_SET); |
---|
131 | fread( buf+len1+1, len2, 1, fp); |
---|
132 | *(buf+len1+len2+1)='\0'; |
---|
133 | printf("##BODY:'%s'##\n", buf); |
---|
134 | free(buf); |
---|
135 | |
---|
136 | // loading help |
---|
137 | len1 = pi->data.s.body_start - pi->data.s.proc_start; |
---|
138 | printf("len1=%d;\n", len1); |
---|
139 | buf = (char *)malloc(len1+1); |
---|
140 | fseek(fp, pi->data.s.proc_start, SEEK_SET); |
---|
141 | fread( buf, len1, 1, fp); |
---|
142 | *(buf+len1)='\0'; |
---|
143 | printf("##HELP:'%s'##\n", buf); |
---|
144 | free(buf); |
---|
145 | |
---|
146 | if(pi->data.s.example_start>0) { // loading example |
---|
147 | fseek(fp, pi->data.s.example_start, SEEK_SET); |
---|
148 | len2 = pi->data.s.proc_end - pi->data.s.example_start; |
---|
149 | buf = (char *)malloc(len2+1); |
---|
150 | fread( buf, len2, 1, fp); |
---|
151 | *(buf+len2)='\0'; |
---|
152 | printf("##EXAMPLE:'%s'##\n", buf); |
---|
153 | free(buf); |
---|
154 | } |
---|
155 | |
---|
156 | fclose(fp); |
---|
157 | //getchar(); |
---|
158 | } |
---|
159 | #endif |
---|
160 | } |
---|
161 | |
---|
162 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|