1 | #include <stdio.h> |
---|
2 | #include <string.h> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <ctype.h> |
---|
5 | #include "utils.h" |
---|
6 | |
---|
7 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
8 | |
---|
9 | procinfo *iiInitSingularProcinfo(procinfov pi, char *libname, |
---|
10 | char *procname, int line, long pos, |
---|
11 | BOOLEAN pstatic = FALSE) |
---|
12 | { |
---|
13 | pi->libname = (char *)malloc(strlen(libname)+1); |
---|
14 | memcpy(pi->libname, libname, strlen(libname)); |
---|
15 | *(pi->libname+strlen(libname)) = '\0'; |
---|
16 | |
---|
17 | pi->procname = (char *)malloc(strlen(procname)+1); |
---|
18 | strcpy(pi->procname, procname/*, strlen(procname)*/); |
---|
19 | pi->language = LANG_SINGULAR; |
---|
20 | pi->ref = 1; |
---|
21 | pi->is_static = pstatic; |
---|
22 | pi->data.s.proc_start = pos; |
---|
23 | pi->data.s.def_end = 0L; |
---|
24 | pi->data.s.help_start = 0L; |
---|
25 | pi->data.s.body_start = 0L; |
---|
26 | pi->data.s.body_end = 0L; |
---|
27 | pi->data.s.example_start = 0L; |
---|
28 | pi->data.s.proc_lineno = line; |
---|
29 | pi->data.s.body_lineno = 0; |
---|
30 | pi->data.s.example_lineno = 0; |
---|
31 | pi->data.s.body = NULL; |
---|
32 | return(pi); |
---|
33 | } |
---|
34 | |
---|
35 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
36 | pi_clear(procinfov pi) |
---|
37 | { |
---|
38 | free(pi->libname); |
---|
39 | free(pi->procname); |
---|
40 | free(pi); |
---|
41 | } |
---|
42 | |
---|
43 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
44 | printpi(procinfov pi) |
---|
45 | { |
---|
46 | FILE *fp = mfopen( pi->libname, "rb"); |
---|
47 | char *buf, name[256]; |
---|
48 | int len1, len2; |
---|
49 | |
---|
50 | if(pi->data.s.body_end==0) |
---|
51 | pi->data.s.body_end = pi->data.s.proc_end; |
---|
52 | |
---|
53 | printf( "%c %-15s %20s ", pi->is_static ? 'l' : 'g', pi->libname, |
---|
54 | pi->procname); |
---|
55 | printf("line %4d,%5ld-%-5ld %4d,%5ld-%-5ld %4d,%5ld-%-5ld\n", |
---|
56 | pi->data.s.proc_lineno, pi->data.s.proc_start, pi->data.s.def_end, |
---|
57 | pi->data.s.body_lineno, pi->data.s.body_start, pi->data.s.body_end, |
---|
58 | pi->data.s.example_lineno, pi->data.s.example_start, |
---|
59 | pi->data.s.proc_end); |
---|
60 | |
---|
61 | #if 0 |
---|
62 | if( fp != NULL) { // loading body |
---|
63 | len1 = pi->data.s.def_end - pi->data.s.proc_start; |
---|
64 | if(pi->data.s.body_end==0) |
---|
65 | len2 = pi->data.s.proc_end - pi->data.s.body_start; |
---|
66 | else len2 = pi->data.s.body_end - pi->data.s.body_start; |
---|
67 | buf = (char *)malloc(len1 + len2 + 1); |
---|
68 | fseek(fp, pi->data.s.proc_start, SEEK_SET); |
---|
69 | mfread( buf, len1, 1, fp); |
---|
70 | *(buf+len1) = '\n'; |
---|
71 | fseek(fp, pi->data.s.body_start, SEEK_SET); |
---|
72 | mfread( buf+len1+1, len2, 1, fp); |
---|
73 | *(buf+len1+len2+1)='\0'; |
---|
74 | printf("##BODY:'%s'##\n", buf); |
---|
75 | free(buf); |
---|
76 | |
---|
77 | // loading help |
---|
78 | len1 = pi->data.s.body_start - pi->data.s.proc_start; |
---|
79 | printf("len1=%d;\n", len1); |
---|
80 | buf = (char *)malloc(len1+1); |
---|
81 | fseek(fp, pi->data.s.proc_start, SEEK_SET); |
---|
82 | mfread( buf, len1, 1, fp); |
---|
83 | *(buf+len1)='\0'; |
---|
84 | printf("##HELP:'%s'##\n", buf); |
---|
85 | free(buf); |
---|
86 | |
---|
87 | if(pi->data.s.example_start>0) { // loading example |
---|
88 | fseek(fp, pi->data.s.example_start, SEEK_SET); |
---|
89 | len2 = pi->data.s.proc_end - pi->data.s.example_start; |
---|
90 | buf = (char *)malloc(len2+1); |
---|
91 | fread( buf, len2, 1, fp); |
---|
92 | *(buf+len2)='\0'; |
---|
93 | printf("##EXAMPLE:'%s'##\n", buf); |
---|
94 | free(buf); |
---|
95 | } |
---|
96 | |
---|
97 | fclose(fp); |
---|
98 | //getchar(); |
---|
99 | } |
---|
100 | #endif |
---|
101 | } |
---|
102 | |
---|
103 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|