47 #include "allheaders.h" 51 static l_int32 getNextNonCommentLine(
SARRAY *sa, l_int32 start, l_int32 *pnext);
52 static l_int32 getNextNonBlankLine(
SARRAY *sa, l_int32 start, l_int32 *pnext);
53 static l_int32 getNextNonDoubleSlashLine(
SARRAY *sa, l_int32 start,
55 static l_int32 searchForProtoSignature(
SARRAY *sa, l_int32 begin,
56 l_int32 *pstart, l_int32 *pstop, l_int32 *pcharindex,
58 static char * captureProtoSignature(
SARRAY *sa, l_int32 start, l_int32 stop,
60 static char * cleanProtoSignature(
char *str);
61 static l_int32 skipToEndOfFunction(
SARRAY *sa, l_int32 start,
62 l_int32 charindex, l_int32 *pnext);
63 static l_int32 skipToMatchingBrace(
SARRAY *sa, l_int32 start,
64 l_int32 lbindex, l_int32 *prbline, l_int32 *prbindex);
65 static l_int32 skipToSemicolon(
SARRAY *sa, l_int32 start,
66 l_int32 charindex, l_int32 *pnext);
67 static l_int32 getOffsetForCharacter(
SARRAY *sa, l_int32 start,
char tchar,
68 l_int32 *psoffset, l_int32 *pboffset, l_int32 *ptoffset);
69 static l_int32 getOffsetForMatchingRP(
SARRAY *sa, l_int32 start,
70 l_int32 soffsetlp, l_int32 boffsetlp, l_int32 toffsetlp,
71 l_int32 *psoffset, l_int32 *pboffset, l_int32 *ptoffset);
141 parseForProtos(
const char *filein,
142 const char *prestring)
144 char *strdata, *str, *newstr, *parsestr, *secondword;
145 l_int32 start, next, stop, charindex, found;
147 SARRAY *sa, *saout, *satest;
149 PROCNAME(
"parseForProtos");
152 return (
char *)ERROR_PTR(
"filein not defined", procName, NULL);
162 searchForProtoSignature(sa, next, &start, &stop, &charindex, &found);
167 str = captureProtoSignature(sa, start, stop, charindex);
183 if (strcmp(secondword,
"static") &&
184 strcmp(secondword,
"extern")) {
197 skipToEndOfFunction(sa, stop, charindex, &next);
198 if (next == -1)
break;
225 getNextNonCommentLine(
SARRAY *sa,
232 PROCNAME(
"getNextNonCommentLine");
235 return ERROR_INT(
"sa not defined", procName, 1);
237 return ERROR_INT(
"&pnext not defined", procName, 1);
243 for (i = start; i < n; i++) {
245 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
271 getNextNonBlankLine(
SARRAY *sa,
276 l_int32 i, j, n, len;
278 PROCNAME(
"getNextNonBlankLine");
281 return ERROR_INT(
"sa not defined", procName, 1);
283 return ERROR_INT(
"&pnext not defined", procName, 1);
289 for (i = start; i < n; i++) {
291 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
293 for (j = 0; j < len; j++) {
294 if (str[j] !=
' ' && str[j] !=
'\t' 295 && str[j] !=
'\n' && str[j] !=
'\r') {
320 getNextNonDoubleSlashLine(
SARRAY *sa,
327 PROCNAME(
"getNextNonDoubleSlashLine");
330 return ERROR_INT(
"sa not defined", procName, 1);
332 return ERROR_INT(
"&pnext not defined", procName, 1);
339 for (i = start; i < n; i++) {
341 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
343 if (len < 2 || str[0] !=
'/' || str[1] !=
'/') {
384 searchForProtoSignature(
SARRAY *sa,
391 l_int32 next, rbline, rbindex, scline;
392 l_int32 soffsetlp, soffsetrp, soffsetlb, soffsetsc;
393 l_int32 boffsetlp, boffsetrp, boffsetlb, boffsetsc;
394 l_int32 toffsetlp, toffsetrp, toffsetlb, toffsetsc;
396 PROCNAME(
"searchForProtoSignature");
399 return ERROR_INT(
"sa not defined", procName, 1);
401 return ERROR_INT(
"&start not defined", procName, 1);
403 return ERROR_INT(
"&stop not defined", procName, 1);
405 return ERROR_INT(
"&charindex not defined", procName, 1);
407 return ERROR_INT(
"&found not defined", procName, 1);
414 getNextNonCommentLine(sa, begin, &next);
415 if (next == -1)
return 0;
422 getNextNonBlankLine(sa, begin, &next);
423 if (next == -1)
return 0;
430 getNextNonDoubleSlashLine(sa, begin, &next);
431 if (next == -1)
return 0;
440 getOffsetForCharacter(sa, next,
'(', &soffsetlp, &boffsetlp,
444 getOffsetForMatchingRP(sa, next, soffsetlp, boffsetlp, toffsetlp,
445 &soffsetrp, &boffsetrp, &toffsetrp);
446 getOffsetForCharacter(sa, next,
'{', &soffsetlb, &boffsetlb,
448 getOffsetForCharacter(sa, next,
';', &soffsetsc, &boffsetsc,
453 if (soffsetrp == -1 || soffsetlb == -1)
458 if (toffsetlb < toffsetlp) {
459 skipToMatchingBrace(sa, next + soffsetlb, boffsetlb,
461 skipToSemicolon(sa, rbline, rbindex, &scline);
468 if ((soffsetsc != -1) &&
469 (toffsetsc < toffsetlb || toffsetsc < toffsetlp)) {
470 skipToSemicolon(sa, next, 0, &scline);
481 *pstop = next + soffsetrp;
482 *pcharindex = boffsetrp;
504 captureProtoSignature(
SARRAY *sa,
509 char *str, *newstr, *protostr, *cleanstr;
513 PROCNAME(
"captureProtoSignature");
516 return (
char *)ERROR_PTR(
"sa not defined", procName, NULL);
519 for (i = start; i < stop; i++) {
524 str[charindex + 1] =
'\0';
530 cleanstr = cleanProtoSignature(protostr);
548 cleanProtoSignature(
char *instr)
550 char *str, *cleanstr;
552 char externstring[] =
"extern";
553 l_int32 i, j, nwords, nchars, index, len;
556 PROCNAME(
"cleanProtoSignature");
559 return (
char *)ERROR_PTR(
"instr not defined", procName, NULL);
565 for (i = 0; i < nwords; i++) {
567 nchars = strlen(str);
569 for (j = 0; j < nchars; j++) {
573 return (
char *)ERROR_PTR(
"token too large", procName, NULL);
579 }
else if (str[j] ==
')') {
583 buf[index++] = str[j];
593 len = strlen(cleanstr);
594 cleanstr[len - 1] =
'\0';
612 skipToEndOfFunction(
SARRAY *sa,
617 l_int32 end, rbindex;
618 l_int32 soffsetlb, boffsetlb, toffsetlb;
620 PROCNAME(
"skipToEndOfFunction");
623 return ERROR_INT(
"sa not defined", procName, 1);
625 return ERROR_INT(
"&next not defined", procName, 1);
627 getOffsetForCharacter(sa, start,
'{', &soffsetlb, &boffsetlb,
629 skipToMatchingBrace(sa, start + soffsetlb, boffsetlb, &end, &rbindex);
655 skipToMatchingBrace(
SARRAY *sa,
662 l_int32 i, j, jstart, n, sumbrace, found, instring, nchars;
664 PROCNAME(
"skipToMatchingBrace");
667 return ERROR_INT(
"sa not defined", procName, 1);
669 return ERROR_INT(
"&stop not defined", procName, 1);
671 return ERROR_INT(
"&rbindex not defined", procName, 1);
678 for (i = start; i < n; i++) {
682 jstart = lbindex + 1;
683 nchars = strlen(str);
684 for (j = jstart; j < nchars; j++) {
687 if (j == jstart && str[j] ==
'\"')
688 instring = 1 - instring;
689 if (j > jstart && str[j] ==
'\"' && str[j-1] !=
'\\')
690 instring = 1 - instring;
693 if (str[j] ==
'{' && str[j+1] !=
'\'' && !instring) {
695 }
else if (str[j] ==
'}' && str[j+1] !=
'\'' && !instring) {
710 return ERROR_INT(
"matching right brace not found", procName, 1);
730 skipToSemicolon(
SARRAY *sa,
736 l_int32 i, j, n, jstart, nchars, found;
738 PROCNAME(
"skipToSemicolon");
741 return ERROR_INT(
"sa not defined", procName, 1);
743 return ERROR_INT(
"&next not defined", procName, 1);
748 for (i = start; i < n; i++) {
752 jstart = charindex + 1;
753 nchars = strlen(str);
754 for (j = jstart; j < nchars; j++) {
766 return ERROR_INT(
"semicolon not found", procName, 1);
794 getOffsetForCharacter(
SARRAY *sa,
802 l_int32 i, j, n, nchars, totchars, found;
804 PROCNAME(
"getOffsetForCharacter");
807 return ERROR_INT(
"sa not defined", procName, 1);
809 return ERROR_INT(
"&soffset not defined", procName, 1);
811 return ERROR_INT(
"&boffset not defined", procName, 1);
813 return ERROR_INT(
"&toffset not defined", procName, 1);
816 *pboffset = 100000000;
817 *ptoffset = 100000000;
822 for (i = start; i < n; i++) {
824 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
825 nchars = strlen(str);
826 for (j = 0; j < nchars; j++) {
827 if (str[j] == tchar) {
838 *psoffset = i - start;
840 *ptoffset = totchars + j;
881 getOffsetForMatchingRP(
SARRAY *sa,
891 l_int32 i, j, n, nchars, totchars, leftmatch, firstline, jstart, found;
893 PROCNAME(
"getOffsetForMatchingRP");
896 return ERROR_INT(
"sa not defined", procName, 1);
898 return ERROR_INT(
"&soffset not defined", procName, 1);
900 return ERROR_INT(
"&boffset not defined", procName, 1);
902 return ERROR_INT(
"&toffset not defined", procName, 1);
905 *pboffset = 100000000;
906 *ptoffset = 100000000;
910 totchars = toffsetlp;
912 firstline = start + soffsetlp;
913 for (i = firstline; i < n; i++) {
915 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
916 nchars = strlen(str);
919 jstart = boffsetlp + 1;
920 for (j = jstart; j < nchars; j++) {
923 else if (str[j] ==
')')
925 if (leftmatch == 0) {
933 totchars += nchars - boffsetlp;
939 *psoffset = i - start;
941 *ptoffset = totchars + j;
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
static const l_int32 L_INSERT
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayAddString(SARRAY *sa, char *string, l_int32 copyflag)
sarrayAddString()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
char * stringJoin(const char *src1, const char *src2)
stringJoin()
SARRAY * sarrayCreateWordsFromString(const char *string)
sarrayCreateWordsFromString()
static const l_int32 L_BUF_SIZE
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()