From bc5bb95dbad5cccb1b1a1bcbea524eae0bf90e24 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 23 Oct 2007 16:06:17 +0000 Subject: [PATCH] Fixed a bug about arrays --- libcevap/cgen.c | 37 ++++++++++++++++++++++++------------- libcevap/ctyp.c | 2 +- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/libcevap/cgen.c b/libcevap/cgen.c index 1ff3bdf..81718f7 100644 --- a/libcevap/cgen.c +++ b/libcevap/cgen.c @@ -337,7 +337,10 @@ int flag; pointer_level= Ctyp_get_pointer_level(ct,0); for(i=0;iname); + fprintf(fp,"%s",ct->name); + if(ct->array_size>0) + fprintf(fp,"[%lu]",ct->array_size); + fprintf(fp,";\n"); } fprintf(fp,"\n"); fprintf(fp,"};\n"); @@ -438,7 +441,7 @@ int flag; fp= cgen->fp; fprintf(fp,"\n"); fprintf(fp,"/*\n"); - fprintf(fp," cc -g -o %s.c\n",cgen->classname); + fprintf(fp," cc -g -c %s.c\n",cgen->classname); fprintf(fp,"*/\n"); Cgen_write_datestr(cgen,0); fprintf(fp,"\n"); @@ -548,6 +551,18 @@ int flag; } fprintf(fp,"{\n"); fprintf(fp," struct %s *o;\n",cgen->structname); + + /* Is an array index i needed ? */ + for(ct= cgen->elements; ct!=NULL; ct= ct->next) { + if(ct->is_comment || ct->no_initializer) + continue; + if(ct->array_size>0) + if(strcmp(ct->dtype,"char")!=0) { + fprintf(fp," int i;\n"); + break; + } + } + fprintf(fp,"\n"); if(cgen->gen_for_stic) fprintf(fp," *objpt= o= TSOB_FELD(struct %s,1);\n",cgen->structname); @@ -568,15 +583,11 @@ int flag; if(strcmp(ct->dtype,"char")==0) { fprintf(fp," o->%s[0]= 0;\n;",ct->name); } else if(pointer_level>0) { - fprintf(fp," { int i;"); - fprintf(fp," for(i=0;i%s[i]= NULL;\n",ct->name); - fprintf(fp," }"); + fprintf(fp," for(i=0;i<%lu;i++)\n",array_size); + fprintf(fp," o->%s[i]= NULL;\n",ct->name); } else { - fprintf(fp," { int i;"); - fprintf(fp," for(i=0;i%s[i]= 0;\n",ct->name); - fprintf(fp," }"); + fprintf(fp," for(i=0;i<%lu;i++)\n",array_size); + fprintf(fp," o->%s[i]= 0;\n",ct->name); } } else if(pointer_level>0) { fprintf(fp," o->%s= NULL;\n",ct->name); @@ -882,7 +893,8 @@ int flag; fprintf(fp,"int idx;\n"); fprintf(fp,"int flag;\n"); } - fprintf(fp,"/* Note: idx==-1 fetches the last item of the list */\n"); + if(ct->management==4) + fprintf(fp,"/* Note: idx==-1 fetches the last item of the list */\n"); fprintf(fp,"{\n"); if(ct->management==4) { strcpy(funct,ct->dtype); @@ -1066,7 +1078,7 @@ after_setter:; " bit1= address from start of list */\n"); fprintf(fp,"{\n"); fprintf(fp," int i,abs_idx;\n"); - fprintf(fp,"struct %s *npt;\n",cgen->structname); + fprintf(fp," struct %s *npt;\n",cgen->structname); fprintf(fp,"\n"); fprintf(fp," if(flag&2)\n"); fprintf(fp," for(;o->prev!=NULL;o= o->prev);\n"); @@ -1082,7 +1094,6 @@ after_setter:; fprintf(fp," *pt= npt;\n"); fprintf(fp," }\n"); fprintf(fp," return(*pt!=NULL);\n"); - fprintf(fp," ;\n"); fprintf(fp,"}\n"); fprintf(fp,"\n"); } diff --git a/libcevap/ctyp.c b/libcevap/ctyp.c index 122bfc2..2b27575 100644 --- a/libcevap/ctyp.c +++ b/libcevap/ctyp.c @@ -312,7 +312,7 @@ no_name:; if(bpt!=NULL) { if(strchr(bpt,']')!=NULL) *strchr(bpt,']')= 0; - sscanf(bpt,"%lu",&(o->array_size)); + sscanf(bpt+1,"%lu",&(o->array_size)); *bpt= 0; } if(Sregex_string(&(o->name),cpt,0)<=0)