Index: tool/lemon.c ================================================================== --- tool/lemon.c +++ tool/lemon.c @@ -34,10 +34,17 @@ #define MAXRHS 1000 #endif static char *msort(char*,char**,int(*)(const char*,const char*)); +/* +** Compilers are getting increasingly pedantic about type conversions +** as C evolves ever closer to Ada.... To work around the latest problems +** we have to define the following variant of strlen(). +*/ +#define lemonStrlen(X) ((int)strlen(X)) + static struct action *Action_new(void); static struct action *Action_sort(struct action *); /********** From the file "build.h" ************************************/ void FindRulePrecedences(); @@ -1319,17 +1326,17 @@ if( lineno>0 ){ sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno); }else{ sprintf(prefix,"%.*s: ",PREFIXLIMIT-10,filename); } - prefixsize = strlen(prefix); + prefixsize = lemonStrlen(prefix); availablewidth = LINEWIDTH - prefixsize; /* Generate the error message */ vsprintf(errmsg,format,ap); va_end(ap); - errmsgsize = strlen(errmsg); + errmsgsize = lemonStrlen(errmsg); /* Remove trailing '\n's from the error message. */ while( errmsgsize>0 && errmsg[errmsgsize-1]=='\n' ){ errmsg[--errmsgsize] = 0; } @@ -1369,11 +1376,11 @@ if( azDefine==0 ){ fprintf(stderr,"out of memory\n"); exit(1); } paz = &azDefine[nDefine-1]; - *paz = malloc( strlen(z)+1 ); + *paz = malloc( lemonStrlen(z)+1 ); if( *paz==0 ){ fprintf(stderr,"out of memory\n"); exit(1); } strcpy(*paz, z); @@ -1647,14 +1654,14 @@ int k; FILE *err; { int spcnt, i; if( argv[0] ) fprintf(err,"%s",argv[0]); - spcnt = strlen(argv[0]) + 1; + spcnt = lemonStrlen(argv[0]) + 1; for(i=1; i%*s %s\n",op[i].label, - (int)(max-strlen(op[i].label)-9),"",op[i].message); + (int)(max-lemonStrlen(op[i].label)-9),"",op[i].message); break; case OPT_DBL: case OPT_FDBL: fprintf(errstream," %s=%*s %s\n",op[i].label, - (int)(max-strlen(op[i].label)-6),"",op[i].message); + (int)(max-lemonStrlen(op[i].label)-6),"",op[i].message); break; case OPT_STR: case OPT_FSTR: fprintf(errstream," %s=%*s %s\n",op[i].label, - (int)(max-strlen(op[i].label)-8),"",op[i].message); + (int)(max-lemonStrlen(op[i].label)-8),"",op[i].message); break; } } } /*********************** From the file "parse.c" ****************************/ @@ -2323,27 +2330,27 @@ int nOld, n, nLine, nNew, nBack; int addLineMacro; char zLine[50]; zNew = x; if( zNew[0]=='"' || zNew[0]=='{' ) zNew++; - nNew = strlen(zNew); + nNew = lemonStrlen(zNew); if( *psp->declargslot ){ zOld = *psp->declargslot; }else{ zOld = ""; } - nOld = strlen(zOld); + nOld = lemonStrlen(zOld); n = nOld + nNew + 20; addLineMacro = psp->insertLineMacro && (psp->decllinenoslot==0 || psp->decllinenoslot[0]!=0); if( addLineMacro ){ for(z=psp->filename, nBack=0; *z; z++){ if( *z=='\\' ) nBack++; } sprintf(zLine, "#line %d ", psp->tokenlineno); - nLine = strlen(zLine); - n += nLine + strlen(psp->filename) + nBack; + nLine = lemonStrlen(zLine); + n += nLine + lemonStrlen(psp->filename) + nBack; } *psp->declargslot = zBuf = realloc(*psp->declargslot, n); zBuf += nOld; if( addLineMacro ){ if( nOld && zBuf[-1]!='\n' ){ @@ -2453,11 +2460,11 @@ }else{ for(j=i+7; isspace(z[j]); j++){} for(n=0; z[j+n] && !isspace(z[j+n]); n++){} exclude = 1; for(k=0; kfilename) + strlen(suffix) + 5 ); + name = malloc( lemonStrlen(lemp->filename) + lemonStrlen(suffix) + 5 ); if( name==0 ){ fprintf(stderr,"Can't allocate space for a filename.\n"); exit(1); } strcpy(name,lemp->filename); @@ -2752,11 +2759,11 @@ int i, j, maxlen, len, ncolumns, skip; printf("// Reprint of input file \"%s\".\n// Symbols:\n",lemp->filename); maxlen = 10; for(i=0; insymbol; i++){ sp = lemp->symbols[i]; - len = strlen(sp->name); + len = lemonStrlen(sp->name); if( len>maxlen ) maxlen = len; } ncolumns = 76/(maxlen+5); if( ncolumns<1 ) ncolumns = 1; skip = (lemp->nsymbol + ncolumns - 1)/ncolumns; @@ -2967,22 +2974,22 @@ cp = strrchr(argv0,'/'); #endif if( cp ){ c = *cp; *cp = 0; - path = (char *)malloc( strlen(argv0) + strlen(name) + 2 ); + path = (char *)malloc( lemonStrlen(argv0) + lemonStrlen(name) + 2 ); if( path ) sprintf(path,"%s/%s",argv0,name); *cp = c; }else{ extern char *getenv(); pathlist = getenv("PATH"); if( pathlist==0 ) pathlist = ".:/bin:/usr/bin"; - path = (char *)malloc( strlen(pathlist)+strlen(name)+2 ); + path = (char *)malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2 ); if( path!=0 ){ while( *pathlist ){ cp = strchr(pathlist,':'); - if( cp==0 ) cp = &pathlist[strlen(pathlist)]; + if( cp==0 ) cp = &pathlist[lemonStrlen(pathlist)]; c = *cp; *cp = 0; sprintf(path,"%s/%s",pathlist,name); *cp = c; if( c==0 ) pathlist = ""; @@ -3213,11 +3220,11 @@ if( n<=0 ){ if( n<0 ){ used += n; assert( used>=0 ); } - n = strlen(zText); + n = lemonStrlen(zText); } if( n+sizeof(zInt)*2+used >= alloced ){ alloced = n + sizeof(zInt)*2 + used + 200; z = realloc(z, alloced); } @@ -3226,11 +3233,11 @@ c = *(zText++); if( c=='%' && n>0 && zText[0]=='d' ){ sprintf(zInt, "%d", p1); p1 = p2; strcpy(&z[used], zInt); - used += strlen(&z[used]); + used += lemonStrlen(&z[used]); zText++; n--; }else{ z[used++] = c; } @@ -3382,17 +3389,17 @@ arraysize = lemp->nsymbol * 2; types = (char**)calloc( arraysize, sizeof(char*) ); for(i=0; ivartype ){ - maxdtlength = strlen(lemp->vartype); + maxdtlength = lemonStrlen(lemp->vartype); } for(i=0; insymbol; i++){ int len; struct symbol *sp = lemp->symbols[i]; if( sp->datatype==0 ) continue; - len = strlen(sp->datatype); + len = lemonStrlen(sp->datatype); if( len>maxdtlength ) maxdtlength = len; } stddt = (char*)malloc( maxdtlength*2 + 1 ); if( types==0 || stddt==0 ){ fprintf(stderr,"Out of memory.\n"); @@ -3440,11 +3447,11 @@ hash++; if( hash>=arraysize ) hash = 0; } if( types[hash]==0 ){ sp->dtnum = hash + 1; - types[hash] = (char*)malloc( strlen(stddt)+1 ); + types[hash] = (char*)malloc( lemonStrlen(stddt)+1 ); if( types[hash]==0 ){ fprintf(stderr,"Out of memory.\n"); exit(1); } strcpy(types[hash],stddt); @@ -3609,11 +3616,11 @@ fprintf(out,"#if INTERFACE\n"); lineno++; } name = lemp->name ? lemp->name : "Parse"; if( lemp->arg && lemp->arg[0] ){ int i; - i = strlen(lemp->arg); + i = lemonStrlen(lemp->arg); while( i>=1 && isspace(lemp->arg[i-1]) ) i--; while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--; fprintf(out,"#define %sARG_SDECL %s;\n",name,lemp->arg); lineno++; fprintf(out,"#define %sARG_PDECL ,%s\n",name,lemp->arg); lineno++; fprintf(out,"#define %sARG_FETCH %s = yypParser->%s\n", @@ -4207,11 +4214,11 @@ { char *z; if( y==0 ) return 0; z = Strsafe_find(y); - if( z==0 && (z=malloc( strlen(y)+1 ))!=0 ){ + if( z==0 && (z=malloc( lemonStrlen(y)+1 ))!=0 ){ strcpy(z,y); Strsafe_insert(z); } MemoryCheck(z); return z;