void GenHexByte(FILE *gDstFile, char ch) { __DEBUG1(">GenHexByte\n"); printf("%c",ch); char digs[3]; sprintf(digs,"%02X",ch); strcat(gGenHexData,digs); gGenHexSum-=ch; gGenHexAddress++; if(gGenHexAddress%25==0) printf("\n"); if((gGenHexAddress&0xf)==0) { // need to generate a new record. EndIHexLine(gDstFile,gGenHexAddress-16,16); } __DEBUG1("<GenHexByte\n"); }
void GenHexByte(FILE *dstFile, char ch) { char digs[3]; if(ch<31) { __DEBUG2("#%02x",ch); } else { __DEBUG2("#%c",ch); } sprintf(digs,"%02X",ch); strcat(gGenHexData,digs); gGenHexSum-=ch; gGenHexAddress++; if(gGenHexAddress%gScreenLineLen==0) __DEBUG2("| %d\n", gGenHexAddress); if((gGenHexAddress&0xf)==0) { // need to generate a new record. EndIHexLine(dstFile,gGenHexAddress-16,16); } }
int ConvertBuff(char *buff, int len) { int ix; static char buffCopy[512],*buffPr; strncpy((buffPr=buffCopy),buff,len); buffCopy[len]='\0'; // terminate it. while(*buffPr!='\0') { // convert back for printing purposes. if(*buffPr=='\015') *buffPr='\012'; // convert to LF, not Windows or Classic Mac compatible! buffPr++; } __DEBUG1("Block Contents:\n"); printf("\"%s\n\"\n",buffCopy); gGenHexAddress=gGenHexSum=0; strcpy(gGenHexData,""); // reset the data. fprintf(gDstFile,":02000004008179\n"); // initialisation record. for(ix=0;ix<len /* want to add '\0' too */ ;ix++) { GenHexByte(gDstFile,buff[ix]); // generate a hex byte for this character. } GenHexByte(gDstFile,0); // terminate with a 0. if((gGenHexAddress&0xf)!=0) // need to generate a new record. EndIHexLine(gDstFile,gGenHexAddress&~15,gGenHexAddress&15); // finish off the block! fprintf(gDstFile,":00000001FF\n"); // termination record. }
int T2E2PaddedOneScreen(FILE *srcFile, int firstChar) { int parseState=kParseInBlank; int ch=0; tBool crShouldPad=kFalse; fprintf(gDstFile,":02000004008179\n"); // initialisation record. __DEBUG1(">T2E2 a\n"); gGenHexAddress=gGenHexSum=0; strcpy(gGenHexData,""); // reset the data. while(gGenHexAddress<=kFIGnitionBlockLen && ch!=EOF) { ch= gGenHexAddress==0 ? firstChar : gGenHexAddress==kFIGnitionBlockLen ? EOF : fgetc(srcFile); __DEBUG1(">T2E2 b\n"); if(parseState&kParseInBlank) { if(ch=='\n' || ch==EOF) { // need to pad out to 25 chars. __DEBUG1(">T2E2 d\n"); while((gGenHexAddress%kFIGnitionScreenLineLen)!=0 || crShouldPad) { GenHexByte(gDstFile,' '); // Pad with a space. crShouldPad=kFalse; } if (gGenHexAddress<kFIGnitionBlockLen) crShouldPad=kTrue; } else { if(ch!=' ') { // start processing a word. parseState=(parseState&~kParseInBlank)|kParseInWord; crShouldPad=kFalse; gT2E2CatCh[0]=(char)ch; strcat(gT2E2CurrentWord,gT2E2CatCh); // cat the new char. } GenHexByte(gDstFile,(char)ch); // generate the hex char. } } else if(parseState&kParseInWord) { // @TODO, need to check for combinations of states. __DEBUG1(">T2E2 c\n"); if(ch=='\n' || ch==EOF) { // need to pad out to 25 chars. __DEBUG1(">T2E2 d\n"); while((gGenHexAddress%kFIGnitionScreenLineLen)!=0 || crShouldPad) { GenHexByte(gDstFile,' '); // Pad with a space. crShouldPad=kFalse; } if (gGenHexAddress<kFIGnitionBlockLen) crShouldPad=kTrue; } else { __DEBUG2(">T2E2 e %d\n",ch); GenHexByte(gDstFile,(char)ch); // generate the hex char. __DEBUG1("<T2E2 e\n"); crShouldPad=kFalse; } if(ch!=' ' && ch!='\n' && ch!=EOF) { __DEBUG1(">T2E2 f\n"); gT2E2CatCh[0]=(char)ch; strcat(gT2E2CurrentWord,gT2E2CatCh); // cat the new char. } if(ch==' ' || ch=='\n' || ch==EOF) { // space terminates a word, so process it. char lastCh; __DEBUG1(">T2E2 g\n"); lastCh=gT2E2CurrentWord[strlen(gT2E2CurrentWord)-1]; if(strcmp(gT2E2CurrentWord,":")==0) { // colon def. __DEBUG1("In Colon!"); parseState |= kParseInColon; // we're in a colon def now. } if(strcmp(gT2E2CurrentWord,";")==0 ) { if((parseState&(kParseInColon|kParseInQuote| kParseInComment))==kParseInColon) { // finished colon def if it's not in a comment or quote. __DEBUG1("Parse State is OK!"); parseState &= ~kParseInColon; // we're out of a colon def. } else __DEBUG2("Parse State was:%d",parseState); } if(strcmp(gT2E2CurrentWord,".\"")==0) { // dot quote. parseState |= kParseInQuote; // we're in quotes. } if(strcmp(gT2E2CurrentWord,"(")==0) { // Comment. parseState |= kParseInComment; // we're in a comment. //printf("Start Comment %d",parseState); } parseState=(parseState&~kParseInWord)|kParseInBlank; // done word. strcpy(gT2E2CurrentWord,""); // reset current word. } } if((parseState&kParseInComment) && ch==')') { // end of comment parseState &= ~kParseInComment; parseState=(parseState&~kParseInWord)|kParseInBlank; // done word. strcpy(gT2E2CurrentWord,""); // reset current word. //printf("End Comment %d",parseState); } if((parseState&kParseInQuote) && ch=='\"') { // done quote. parseState &= ~kParseInQuote; // we've finished quotes. parseState=(parseState&~kParseInWord)|kParseInBlank; // done word. strcpy(gT2E2CurrentWord,""); // reset current word. __DEBUG2("End Comment %d",parseState); } } __DEBUG1(">T2E2 x\n"); if(parseState & kParseInColon) { printf("In Colon Def at end of screen!!!"); } __DEBUG1(">T2E2 y\n"); while(gGenHexAddress<500) GenHexByte(gDstFile,' '); // Pad with a space. EndIHexLine(gDstFile,gGenHexAddress&~0xf,gGenHexAddress&0xf); // finish record. fprintf(gDstFile,":00000001FF\n"); // termination record. }