SeryZone
Strange Attractor
Posts: 253
Contemplate...
|
|
« Reply #2 on: January 05, 2014, 02:30:42 PM » |
|
Thanks. I don't learn C++, please, tell me for about this code: int main(int argc,char *argv[]) { int fnarg; FILE *palettefile; FILE *textfile; char FxPal[PALMAX]; int pivlen; /* Palette index and values length */ int numindex, index, value; char textline[TXTMAX], origline[TXTMAX]; int txtlncnt; enum indextype lastindex, currindex; char *word,*nlpos; int fxpalpos, fxpallastixpos, pallength;
if (argc < 3) { /* If less than 2 arguments we call the Usage routine and exit */ Usage(argv[0]); return 1; } /* handle the program options */ fnarg=HandleOptions(argc,argv); if((textfile=fopen(argv[fnarg],"r"))==NULL) { fprintf(stderr,"Cant open %s\n",argv[fnarg]); return 2; } if((palettefile=fopen(argv[fnarg+1],"wb"))==NULL) { fprintf(stderr,"Cent open %s\n",argv[fnarg+1]); return 3; } memset(FxPal,0,PALMAX); memcpy(FxPal,FXPL_hdr,FXPL_HdrSize); memcpy(&(FxPal[FXPL_FlenHi+1]),FXPL_FlenFill,FXPL_FlenFillSize); FxPal[FXPL_ShowStripes]=1; memcpy(&(FxPal[FXPL_ShowStripes+1]),FXPL_SSFill,3); FxPal[FXPL_CyclePos]=114; memcpy(&(FxPal[FXPL_CyclePos+1]),FXPL_CPFill,3); FxPal[FXPL_CycleBackwards]=0; FxPal[FXPL_CycleSpeed]=30; memcpy(&(FxPal[FXPL_CycleSpeed+1]),FXPL_CSFill,7); FxPal[FXPL_InteriorRed]=0xFF; FxPal[FXPL_InteriorGreen]=0xFF; FxPal[FXPL_InteriorBlue]=0xFF; FxPal[FXPL_InteriorBlue+1]=FXPL_ICFill; FxPal[FXPL_EdgeFillRed]=0; FxPal[FXPL_EdgeFillGreen]=0; FxPal[FXPL_EdgeFillBlue]=0; FxPal[FXPL_EdgeFillBlue+1]=FXPL_EFFill;
fxpallastixpos=FXPL_NumRedEvenIndexes; fxpalpos=fxpallastixpos+1; FxPal[fxpalpos++]=0; numindex=0; lastindex=unset; /* 1st index should be red colour so this will trigger break */ txtlncnt=0; while(fgets(textline,TXTMAX,textfile)!=NULL) { if((nlpos=strchr(textline,'\n'))!=NULL) *nlpos=0; txtlncnt++; strncpy(origline,textline,TXTMAX); word=strtok(textline," "); if(strnicmp(word,"index",TXTMAX)==0) { if(lastindex==unset) { fprintf(stderr,"line %d error index found before colour type\n%s\n",txtlncnt,origline); exit(4); } word=strtok(NULL," "); sscanf(word,"%d",&index); word=strtok(NULL," "); if(strnicmp(word,"value",TXTMAX)!=0) { fprintf(stderr,"value doesnt follow index line %d\n%s\n",txtlncnt,origline); exit(5); } word=strtok(NULL," "); sscanf(word,"%d",&value); numindex+=1; FxPal[fxpalpos++]=(char)index; FxPal[fxpalpos++]=0; FxPal[fxpalpos++]=(char)value; FxPal[fxpalpos++]=0; } else { /* must be a colour type line RED main, Green main, red stripe etc */ if(strnicmp(word,"red",TXTMAX)==0) indexbreak(word,&lastindex,&numindex,&fxpalpos,&fxpallastixpos,FxPal,txtlncnt); else if(strnicmp(word,"green",TXTMAX)==0) indexbreak(word,&lastindex,&numindex,&fxpalpos,&fxpallastixpos,FxPal,txtlncnt); else if(strnicmp(word,"blue",TXTMAX)==0) indexbreak(word,&lastindex,&numindex,&fxpalpos,&fxpallastixpos,FxPal,txtlncnt); else { fprintf(stderr,"Unexpected %s at line %d\n",word,txtlncnt); exit(6); } } } if(lastindex!=unset) { FxPal[fxpallastixpos]=(char)numindex; } pallength=fxpalpos-FXPL_ByteB4Palette; FxPal[FXPL_FlenLo]=(char)(pallength & 0x00FF); FxPal[FXPL_FlenHi]=(char)((pallength&0xFF00)>>8); fwrite(FxPal,fxpalpos,1,palettefile); fclose(palettefile); fclose(textfile); }
Ye, I researched for sequence. Cool.
|