2 * locate `procname` in lib `libname` and find the part `part`: * part=0: help, between, but excluding the line "proc ..." and "{...": * => return * part=1: body, between "{ ..." and "}", including the 1. line, w/o "{" * => set pi->data.s.body, return NULL * part=2: example, between, but excluding the line "exapmle {..." and "}": * => return */
| 195 | * => return |
| 196 | */ |
| 197 | char* iiGetLibProcBuffer(procinfo *pi, int part ) |
| 198 | { |
| 199 | char buf[SINGULAR_PATH_LENGTH], *s = NULL, *p; |
| 200 | long procbuflen; |
| 201 | |
| 202 | FILE * fp = feFopen( pi->libname, "rb", NULL, TRUE ); |
| 203 | if (fp==NULL) |
| 204 | { |
| 205 | return NULL; |
| 206 | } |
| 207 | |
| 208 | int res=fseek(fp, pi->data.s.proc_start, SEEK_SET); |
| 209 | if (res==1) return NULL; |
| 210 | if(part==0) |
| 211 | { // load help string |
| 212 | int i, offset=0; |
| 213 | long head = pi->data.s.def_end - pi->data.s.proc_start; |
| 214 | procbuflen = pi->data.s.help_end - pi->data.s.help_start; |
| 215 | if (procbuflen<5) |
| 216 | { |
| 217 | fclose(fp); |
| 218 | return NULL; // help part does not exist |
| 219 | } |
| 220 | //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start, |
| 221 | // pi->data.s.proc_start, procbuflen); |
| 222 | s = (char *)omAlloc(procbuflen+head+3); |
| 223 | res=myfread(s, head, 1, fp); |
| 224 | if (res<=0) /* error*/ { omFree(s); return NULL; } |
| 225 | s[head] = '\n'; |
| 226 | int res=fseek(fp, pi->data.s.help_start, SEEK_SET); |
| 227 | if (res==-1) /*error*/ { omFree(s); return NULL; } |
| 228 | res=myfread(s+head+1, procbuflen, 1, fp); |
| 229 | if (res<=0) /* error*/ { omFree(s); return NULL; } |
| 230 | fclose(fp); |
| 231 | s[procbuflen+head+1] = '\n'; |
| 232 | s[procbuflen+head+2] = '\0'; |
| 233 | offset=0; |
| 234 | for(i=0;i<=procbuflen+head+2; i++) |
| 235 | { |
| 236 | if(s[i]=='\\' && |
| 237 | (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\')) |
| 238 | { |
| 239 | i++; |
| 240 | offset++; |
| 241 | } |
| 242 | if(offset>0) s[i-offset] = s[i]; |
| 243 | } |
| 244 | return(s); |
| 245 | } |
| 246 | else if(part==1) |
| 247 | { // load proc part - must exist |
| 248 | procbuflen = pi->data.s.def_end - pi->data.s.proc_start; |
| 249 | char *ss=(char *)omAlloc(procbuflen+2); |
| 250 | //fgets(buf, sizeof(buf), fp); |
| 251 | myfread( ss, procbuflen, 1, fp); |
| 252 | char ct; |
| 253 | char *e; |
| 254 | s=iiProcName(ss,ct,e); |
no test coverage detected