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