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);
142 parseForProtos(
const char *filein,
143 const char *prestring)
145 char *strdata, *str, *newstr, *parsestr, *secondword;
146 l_int32 start, next, stop, charindex, found;
148 SARRAY *sa, *saout, *satest;
150 PROCNAME(
"parseForProtos");
153 return (
char *)ERROR_PTR(
"filein not defined", procName, NULL);
163 searchForProtoSignature(sa, next, &start, &stop, &charindex, &found);
168 str = captureProtoSignature(sa, start, stop, charindex);
188 if (strcmp(secondword,
"static") &&
189 strcmp(secondword,
"extern") &&
190 strcmp(secondword,
"typedef")) {
203 skipToEndOfFunction(sa, stop, charindex, &next);
204 if (next == -1)
break;
231 getNextNonCommentLine(
SARRAY *sa,
238 PROCNAME(
"getNextNonCommentLine");
241 return ERROR_INT(
"sa not defined", procName, 1);
243 return ERROR_INT(
"&pnext not defined", procName, 1);
249 for (i = start; i < n; i++) {
251 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
277 getNextNonBlankLine(
SARRAY *sa,
282 l_int32 i, j, n, len;
284 PROCNAME(
"getNextNonBlankLine");
287 return ERROR_INT(
"sa not defined", procName, 1);
289 return ERROR_INT(
"&pnext not defined", procName, 1);
295 for (i = start; i < n; i++) {
297 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
299 for (j = 0; j < len; j++) {
300 if (str[j] !=
' ' && str[j] !=
'\t' 301 && str[j] !=
'\n' && str[j] !=
'\r') {
326 getNextNonDoubleSlashLine(
SARRAY *sa,
333 PROCNAME(
"getNextNonDoubleSlashLine");
336 return ERROR_INT(
"sa not defined", procName, 1);
338 return ERROR_INT(
"&pnext not defined", procName, 1);
345 for (i = start; i < n; i++) {
347 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
349 if (len < 2 || str[0] !=
'/' || str[1] !=
'/') {
390 searchForProtoSignature(
SARRAY *sa,
397 l_int32 next, rbline, rbindex, scline;
398 l_int32 soffsetlp, soffsetrp, soffsetlb, soffsetsc;
399 l_int32 boffsetlp, boffsetrp, boffsetlb, boffsetsc;
400 l_int32 toffsetlp, toffsetrp, toffsetlb, toffsetsc;
402 PROCNAME(
"searchForProtoSignature");
405 return ERROR_INT(
"sa not defined", procName, 1);
407 return ERROR_INT(
"&start not defined", procName, 1);
409 return ERROR_INT(
"&stop not defined", procName, 1);
411 return ERROR_INT(
"&charindex not defined", procName, 1);
413 return ERROR_INT(
"&found not defined", procName, 1);
420 getNextNonCommentLine(sa, begin, &next);
421 if (next == -1)
return 0;
428 getNextNonBlankLine(sa, begin, &next);
429 if (next == -1)
return 0;
436 getNextNonDoubleSlashLine(sa, begin, &next);
437 if (next == -1)
return 0;
446 getOffsetForCharacter(sa, next,
'(', &soffsetlp, &boffsetlp,
450 getOffsetForMatchingRP(sa, next, soffsetlp, boffsetlp, toffsetlp,
451 &soffsetrp, &boffsetrp, &toffsetrp);
452 getOffsetForCharacter(sa, next,
'{', &soffsetlb, &boffsetlb,
454 getOffsetForCharacter(sa, next,
';', &soffsetsc, &boffsetsc,
459 if (soffsetrp == -1 || soffsetlb == -1)
464 if (toffsetlb < toffsetlp) {
465 skipToMatchingBrace(sa, next + soffsetlb, boffsetlb,
467 skipToSemicolon(sa, rbline, rbindex, &scline);
474 if ((soffsetsc != -1) &&
475 (toffsetsc < toffsetlb || toffsetsc < toffsetlp)) {
476 skipToSemicolon(sa, next, 0, &scline);
487 *pstop = next + soffsetrp;
488 *pcharindex = boffsetrp;
510 captureProtoSignature(
SARRAY *sa,
515 char *str, *newstr, *protostr, *cleanstr;
519 PROCNAME(
"captureProtoSignature");
522 return (
char *)ERROR_PTR(
"sa not defined", procName, NULL);
525 for (i = start; i < stop; i++) {
530 str[charindex + 1] =
'\0';
536 cleanstr = cleanProtoSignature(protostr);
554 cleanProtoSignature(
char *instr)
556 char *str, *cleanstr;
558 char externstring[] =
"extern";
559 l_int32 i, j, nwords, nchars, index, len;
562 PROCNAME(
"cleanProtoSignature");
565 return (
char *)ERROR_PTR(
"instr not defined", procName, NULL);
571 for (i = 0; i < nwords; i++) {
573 nchars = strlen(str);
575 for (j = 0; j < nchars; j++) {
579 return (
char *)ERROR_PTR(
"token too large", procName, NULL);
585 }
else if (str[j] ==
')') {
589 buf[index++] = str[j];
599 len = strlen(cleanstr);
600 cleanstr[len - 1] =
'\0';
618 skipToEndOfFunction(
SARRAY *sa,
623 l_int32 end, rbindex;
624 l_int32 soffsetlb, boffsetlb, toffsetlb;
626 PROCNAME(
"skipToEndOfFunction");
629 return ERROR_INT(
"sa not defined", procName, 1);
631 return ERROR_INT(
"&next not defined", procName, 1);
633 getOffsetForCharacter(sa, start,
'{', &soffsetlb, &boffsetlb,
635 skipToMatchingBrace(sa, start + soffsetlb, boffsetlb, &end, &rbindex);
661 skipToMatchingBrace(
SARRAY *sa,
668 l_int32 i, j, jstart, n, sumbrace, found, instring, nchars;
670 PROCNAME(
"skipToMatchingBrace");
673 return ERROR_INT(
"sa not defined", procName, 1);
675 return ERROR_INT(
"&stop not defined", procName, 1);
677 return ERROR_INT(
"&rbindex not defined", procName, 1);
684 for (i = start; i < n; i++) {
688 jstart = lbindex + 1;
689 nchars = strlen(str);
690 for (j = jstart; j < nchars; j++) {
693 if (j == jstart && str[j] ==
'\"')
694 instring = 1 - instring;
695 if (j > jstart && str[j] ==
'\"' && str[j-1] !=
'\\')
696 instring = 1 - instring;
699 if (str[j] ==
'{' && str[j+1] !=
'\'' && !instring) {
701 }
else if (str[j] ==
'}' && str[j+1] !=
'\'' && !instring) {
716 return ERROR_INT(
"matching right brace not found", procName, 1);
736 skipToSemicolon(
SARRAY *sa,
742 l_int32 i, j, n, jstart, nchars, found;
744 PROCNAME(
"skipToSemicolon");
747 return ERROR_INT(
"sa not defined", procName, 1);
749 return ERROR_INT(
"&next not defined", procName, 1);
754 for (i = start; i < n; i++) {
758 jstart = charindex + 1;
759 nchars = strlen(str);
760 for (j = jstart; j < nchars; j++) {
772 return ERROR_INT(
"semicolon not found", procName, 1);
800 getOffsetForCharacter(
SARRAY *sa,
808 l_int32 i, j, n, nchars, totchars, found;
810 PROCNAME(
"getOffsetForCharacter");
813 return ERROR_INT(
"sa not defined", procName, 1);
815 return ERROR_INT(
"&soffset not defined", procName, 1);
817 return ERROR_INT(
"&boffset not defined", procName, 1);
819 return ERROR_INT(
"&toffset not defined", procName, 1);
822 *pboffset = 100000000;
823 *ptoffset = 100000000;
828 for (i = start; i < n; i++) {
830 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
831 nchars = strlen(str);
832 for (j = 0; j < nchars; j++) {
833 if (str[j] == tchar) {
844 *psoffset = i - start;
846 *ptoffset = totchars + j;
887 getOffsetForMatchingRP(
SARRAY *sa,
897 l_int32 i, j, n, nchars, totchars, leftmatch, firstline, jstart, found;
899 PROCNAME(
"getOffsetForMatchingRP");
902 return ERROR_INT(
"sa not defined", procName, 1);
904 return ERROR_INT(
"&soffset not defined", procName, 1);
906 return ERROR_INT(
"&boffset not defined", procName, 1);
908 return ERROR_INT(
"&toffset not defined", procName, 1);
911 *pboffset = 100000000;
912 *ptoffset = 100000000;
916 totchars = toffsetlp;
918 firstline = start + soffsetlp;
919 for (i = firstline; i < n; i++) {
921 return ERROR_INT(
"str not returned; shouldn't happen", procName, 1);
922 nchars = strlen(str);
925 jstart = boffsetlp + 1;
926 for (j = jstart; j < nchars; j++) {
929 else if (str[j] ==
')')
931 if (leftmatch == 0) {
939 totchars += nchars - boffsetlp;
945 *psoffset = i - start;
947 *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()
static const l_int32 L_BUF_SIZE
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()