49 #include <config_auto.h> 53 #include "allheaders.h" 55 #define L_BUF_SIZE 2048 57 static l_int32 getNextNonCommentLine(
SARRAY *sa, l_int32 start, l_int32 *pnext);
58 static l_int32 getNextNonBlankLine(
SARRAY *sa, l_int32 start, l_int32 *pnext);
59 static l_int32 getNextNonDoubleSlashLine(
SARRAY *sa, l_int32 start,
61 static l_int32 searchForProtoSignature(
SARRAY *sa, l_int32 begin,
62 l_int32 *pstart, l_int32 *pstop, l_int32 *pcharindex,
64 static char * captureProtoSignature(
SARRAY *sa, l_int32 start, l_int32 stop,
66 static char * cleanProtoSignature(
char *str);
67 static l_int32 skipToEndOfFunction(
SARRAY *sa, l_int32 start,
68 l_int32 charindex, l_int32 *pnext);
69 static l_int32 skipToMatchingBrace(
SARRAY *sa, l_int32 start,
70 l_int32 lbindex, l_int32 *prbline, l_int32 *prbindex);
71 static l_int32 skipToSemicolon(
SARRAY *sa, l_int32 start,
72 l_int32 charindex, l_int32 *pnext);
73 static l_int32 getOffsetForCharacter(
SARRAY *sa, l_int32 start,
char tchar,
74 l_int32 *psoffset, l_int32 *pboffset, l_int32 *ptoffset);
75 static l_int32 getOffsetForMatchingRP(
SARRAY *sa, l_int32 start,
76 l_int32 soffsetlp, l_int32 boffsetlp, l_int32 toffsetlp,
77 l_int32 *psoffset, l_int32 *pboffset, l_int32 *ptoffset);
150 parseForProtos(
const char *filein,
151 const char *prestring)
153 char *strdata, *str, *newstr, *parsestr, *secondword;
154 l_int32 start, next, stop, charindex, found;
156 SARRAY *sa, *saout, *satest;
158 PROCNAME(
"parseForProtos");
161 return (
char *)ERROR_PTR(
"filein not defined", procName, NULL);
171 searchForProtoSignature(sa, next, &start, &stop, &charindex, &found);
176 str = captureProtoSignature(sa, start, stop, charindex);
196 if (strcmp(secondword,
"static") &&
197 strcmp(secondword,
"extern") &&
198 strcmp(secondword,
"typedef")) {
211 skipToEndOfFunction(sa, stop, charindex, &next);
212 if (next == -1)
break;
240 getNextNonCommentLine(
SARRAY *sa,
247 PROCNAME(
"getNextNonCommentLine");
250 return ERROR_INT(
"sa not defined", procName, 1);
252 return ERROR_INT(
"&pnext not defined", procName, 1);
258 for (i = start; i < n; i++) {
260 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
287 getNextNonBlankLine(
SARRAY *sa,
292 l_int32 i, j, n, len;
294 PROCNAME(
"getNextNonBlankLine");
297 return ERROR_INT(
"sa not defined", procName, 1);
299 return ERROR_INT(
"&pnext not defined", procName, 1);
305 for (i = start; i < n; i++) {
307 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
309 for (j = 0; j < len; j++) {
310 if (str[j] !=
' ' && str[j] !=
'\t' 311 && str[j] !=
'\n' && str[j] !=
'\r') {
337 getNextNonDoubleSlashLine(
SARRAY *sa,
344 PROCNAME(
"getNextNonDoubleSlashLine");
347 return ERROR_INT(
"sa not defined", procName, 1);
349 return ERROR_INT(
"&pnext not defined", procName, 1);
356 for (i = start; i < n; i++) {
358 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
360 if (len < 2 || str[0] !=
'/' || str[1] !=
'/') {
403 searchForProtoSignature(
SARRAY *sa,
410 l_int32 next, rbline, rbindex, scline;
411 l_int32 soffsetlp, soffsetrp, soffsetlb, soffsetsc;
412 l_int32 boffsetlp, boffsetrp, boffsetlb, boffsetsc;
413 l_int32 toffsetlp, toffsetrp, toffsetlb, toffsetsc;
415 PROCNAME(
"searchForProtoSignature");
418 return ERROR_INT(
"sa not defined", procName, 1);
420 return ERROR_INT(
"&start not defined", procName, 1);
422 return ERROR_INT(
"&stop not defined", procName, 1);
424 return ERROR_INT(
"&charindex not defined", procName, 1);
426 return ERROR_INT(
"&found not defined", procName, 1);
433 getNextNonCommentLine(sa, begin, &next);
434 if (next == -1)
return 0;
441 getNextNonBlankLine(sa, begin, &next);
442 if (next == -1)
return 0;
449 getNextNonDoubleSlashLine(sa, begin, &next);
450 if (next == -1)
return 0;
459 getOffsetForCharacter(sa, next,
'(', &soffsetlp, &boffsetlp,
463 getOffsetForMatchingRP(sa, next, soffsetlp, boffsetlp, toffsetlp,
464 &soffsetrp, &boffsetrp, &toffsetrp);
465 getOffsetForCharacter(sa, next,
'{', &soffsetlb, &boffsetlb,
467 getOffsetForCharacter(sa, next,
';', &soffsetsc, &boffsetsc,
472 if (soffsetrp == -1 || soffsetlb == -1)
477 if (toffsetlb < toffsetlp) {
478 skipToMatchingBrace(sa, next + soffsetlb, boffsetlb,
480 skipToSemicolon(sa, rbline, rbindex, &scline);
487 if ((soffsetsc != -1) &&
488 (toffsetsc < toffsetlb || toffsetsc < toffsetlp)) {
489 skipToSemicolon(sa, next, 0, &scline);
500 *pstop = next + soffsetrp;
501 *pcharindex = boffsetrp;
525 captureProtoSignature(
SARRAY *sa,
530 char *str, *newstr, *protostr, *cleanstr;
534 PROCNAME(
"captureProtoSignature");
537 return (
char *)ERROR_PTR(
"sa not defined", procName, NULL);
540 for (i = start; i < stop; i++) {
545 str[charindex + 1] =
'\0';
551 cleanstr = cleanProtoSignature(protostr);
571 cleanProtoSignature(
char *instr)
573 char *str, *cleanstr;
575 char externstring[] =
"extern";
576 l_int32 i, j, nwords, nchars, index, len;
579 PROCNAME(
"cleanProtoSignature");
582 return (
char *)ERROR_PTR(
"instr not defined", procName, NULL);
588 for (i = 0; i < nwords; i++) {
590 nchars = strlen(str);
592 for (j = 0; j < nchars; j++) {
596 return (
char *)ERROR_PTR(
"token too large", procName, NULL);
602 }
else if (str[j] ==
')') {
606 buf[index++] = str[j];
616 len = strlen(cleanstr);
617 cleanstr[len - 1] =
'\0';
635 skipToEndOfFunction(
SARRAY *sa,
640 l_int32 end, rbindex;
641 l_int32 soffsetlb, boffsetlb, toffsetlb;
643 PROCNAME(
"skipToEndOfFunction");
646 return ERROR_INT(
"sa not defined", procName, 1);
648 return ERROR_INT(
"&next not defined", procName, 1);
650 getOffsetForCharacter(sa, start,
'{', &soffsetlb, &boffsetlb,
652 skipToMatchingBrace(sa, start + soffsetlb, boffsetlb, &end, &rbindex);
680 skipToMatchingBrace(
SARRAY *sa,
687 l_int32 i, j, jstart, n, sumbrace, found, instring, nchars;
689 PROCNAME(
"skipToMatchingBrace");
692 return ERROR_INT(
"sa not defined", procName, 1);
694 return ERROR_INT(
"&stop not defined", procName, 1);
696 return ERROR_INT(
"&rbindex not defined", procName, 1);
703 for (i = start; i < n; i++) {
707 jstart = lbindex + 1;
708 nchars = strlen(str);
709 for (j = jstart; j < nchars; j++) {
712 if (j == jstart && str[j] ==
'\"')
713 instring = 1 - instring;
714 if (j > jstart && str[j] ==
'\"' && str[j-1] !=
'\\')
715 instring = 1 - instring;
718 if (str[j] ==
'{' && str[j+1] !=
'\'' && !instring) {
720 }
else if (str[j] ==
'}' && str[j+1] !=
'\'' && !instring) {
735 return ERROR_INT(
"matching right brace not found", procName, 1);
757 skipToSemicolon(
SARRAY *sa,
763 l_int32 i, j, n, jstart, nchars, found;
765 PROCNAME(
"skipToSemicolon");
768 return ERROR_INT(
"sa not defined", procName, 1);
770 return ERROR_INT(
"&next not defined", procName, 1);
775 for (i = start; i < n; i++) {
779 jstart = charindex + 1;
780 nchars = strlen(str);
781 for (j = jstart; j < nchars; j++) {
793 return ERROR_INT(
"semicolon not found", procName, 1);
824 getOffsetForCharacter(
SARRAY *sa,
832 l_int32 i, j, n, nchars, totchars, found;
834 PROCNAME(
"getOffsetForCharacter");
837 return ERROR_INT(
"sa not defined", procName, 1);
839 return ERROR_INT(
"&soffset not defined", procName, 1);
841 return ERROR_INT(
"&boffset not defined", procName, 1);
843 return ERROR_INT(
"&toffset not defined", procName, 1);
846 *pboffset = 100000000;
847 *ptoffset = 100000000;
852 for (i = start; i < n; i++) {
854 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
855 nchars = strlen(str);
856 for (j = 0; j < nchars; j++) {
857 if (str[j] == tchar) {
868 *psoffset = i - start;
870 *ptoffset = totchars + j;
914 getOffsetForMatchingRP(
SARRAY *sa,
924 l_int32 i, j, n, nchars, totchars, leftmatch, firstline, jstart, found;
926 PROCNAME(
"getOffsetForMatchingRP");
929 return ERROR_INT(
"sa not defined", procName, 1);
931 return ERROR_INT(
"&soffset not defined", procName, 1);
933 return ERROR_INT(
"&boffset not defined", procName, 1);
935 return ERROR_INT(
"&toffset not defined", procName, 1);
938 *pboffset = 100000000;
939 *ptoffset = 100000000;
943 totchars = toffsetlp;
945 firstline = start + soffsetlp;
946 for (i = firstline; i < n; i++) {
948 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
949 nchars = strlen(str);
952 jstart = boffsetlp + 1;
953 for (j = jstart; j < nchars; j++) {
956 else if (str[j] ==
')')
958 if (leftmatch == 0) {
966 totchars += nchars - boffsetlp;
972 *psoffset = i - start;
974 *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()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
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()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()