rendered paste body
#include <tigcclib.h>
char screen_buffer[LCD_SIZE];
HSym hsym; //reusable
HANDLE handle; //reusable
char *cptr; // pointer to MLC source code
char *pptr; // pointer to tokenized program
SYM_ENTRY *SymPtr; //reusable
void error(const char* bad){
memcpy(LCD_MEM, screen_buffer, LCD_SIZE);
ST_helpMsg(bad);
exit(0);
}
void _main(void)
{
memcpy(screen_buffer, LCD_MEM, LCD_SIZE);
ESI argptr;
int argtype;
short num;
unsigned long a = 0;
unsigned short size;
short b;
const char* filename;
InitArgPtr (argptr);
while ((argtype = GetArgType (argptr)) != END_TAG)
{
if (argtype == STR_TAG && !a){
filename = GetStrnArg(argptr);
hsym = SymFind (SYMSTR (filename));
if(hsym.folder == 0){
error("Can't find MLC source code file");
}
SymPtr = (DerefSym (hsym));
cptr = HeapDeref (SymPtr->handle);
size=*(unsigned short *)cptr;
cptr+=5;
if((*cptr)!='M' || *(cptr+1)!='L' || *(cptr+2)!='C' || *(cptr+3)!=':' || *(cptr+4)!=0x0d)
error("Not an MLC file");
error("Not an MLC file");
cptr+=5;
a=1;
}
else if (argtype == STR_TAG && a){
filename = GetStrnArg(argptr);
hsym = SymFind (SYMSTR (filename));
if(hsym.folder != 0){
clrscr();
printf("MLC program file already exists\n\n");
printf("1. Overwrite\n2. Abort");
b=ngetchx();
if(b=='1'){
goto cont;
}
else if(b=='2'){
error("Tokenization aborted");
}
}
cont:;
hsym = SymAdd (SYMSTR (filename));
// HeapAlloc must be executed before DerefSym
// because of possible garbage collection.
handle = HeapAlloc ((unsigned short)((size/2+6)));
SymPtr = (DerefSym (hsym));
pptr = HeapDeref (SymPtr->handle = handle);
*((unsigned short*)pptr)=(unsigned short)((size/2+4));
pptr+=2;
*pptr = 'M'; // actual data
*(pptr+1) = 'L';
*(pptr+2) = 'C';
*(pptr+3) = ':';
*(pptr+4) = 0x0d;
pptr+=5;
unsigned long line;
char text[44][4]={
{'D','A','T','A'},
{'D','E','N','D'},
{'B','I','T','M'},
{'A','R','R','Y'},
{'S','I','Z','E'},
{'C','L','R','S'},
{'T','E','X','T'},
{'L','I','N','E'},
{'P','I','X','L'},
{'P','I','X','T'},
{'S','P','R','T'},
{'D','I','S','P'},
{'D','B','M','P'},
{'C','L','S','M'},
{'R','E','C','T'},
{'D','R','A','W'},
{'S','T','O','P'},
{'R','C','L','P'},
{'S','H','F','T'},
{'G','K','E','Y'},
{'W','K','E','Y'},
{'P','A','U','S'},
{'F','N','C','T'},
{'F','R','U','N'},
{'F','G','O','B'},
{'F','E','N','D'},
{'I','I','F','F'},
{'R','N','D','M'},
{'H','A','L','T'},
{'W','A','I','T'},
{'W','R','T','E'},
{'R','E','A','D'},
{'P','O','L','R'},
{'S','U','B','S'},
{'R','S','E','T'},
{'C','I','N','T'},
{'A','B','S','L'},
{'I','N','P','T'},
{'N','M','A','P'},
{'T','I','L','E'},
{'C','M','A','P'},
{'T','C','H','K'},
{'D','M','A','P'}};
short counter, counter2;
for(line=0;line<size-10;line++){
/*
for(counter=0;counter<=43;counter++){
for(counter2=0;counter2<=3;counter2++){
if(text[counter][counter2]!=*(cptr+counter2))goto tok;
}
*pptr=counter;
cptr+=4;
goto tokend;
tok:
*pptr=*cptr;
tokend;
}
*/
if(*cptr!=0x20)*pptr=*cptr;
pptr++;
cptr++;
}
*(pptr+1) = 0;
*(pptr+2) = 'M';
*(pptr+3) = 'L';
*(pptr+4) = 'C';
*(pptr+5) = 0;
*(pptr+6) = OTH_TAG; //224?
// ADD STUFF NEEDED TO BE A VALID TEXT FILE
// memcpy(header,VarPtr,4);
// if(strcmp(header,"MLC:")!=0)
// error("Not an MLC file");
//VarPtr+=4;
a=2;
}
else
{
//for(e=0;e<=4;e++){
//free(sbufs[e].lplane);
//free(sbufs[e].dplane);
//}
error("Invalid argument");
}
}
if(!a){
error("No MLC source file selected");
}
else if(a==1){
error("No MLC post-tokenized file selected");
}
memcpy(LCD_MEM, screen_buffer, LCD_SIZE);
error("MLC source file successfully tokenized");
}