65 lines
1.3 KiB
C
65 lines
1.3 KiB
C
|
/*
|
|||
|
* Copyright (C) 1995 Sebastien Carlier
|
|||
|
*/
|
|||
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
|
|||
|
#define BUFSIZE 256
|
|||
|
#define NEXTFIELD {s=p; while ((p<BUFSIZE)&&(ptr[p]!='\t')) p++; ptr[p] = 0; p++;}
|
|||
|
|
|||
|
char buffer[BUFSIZE];
|
|||
|
int icnt, lcnt;
|
|||
|
|
|||
|
int main() {
|
|||
|
char *ptr, array;
|
|||
|
int s, p, ticks;
|
|||
|
|
|||
|
while (!feof(stdin)) {
|
|||
|
lcnt++;
|
|||
|
|
|||
|
if (gets(buffer)==NULL) break;
|
|||
|
if (buffer[0]==0) break;
|
|||
|
if (buffer[0]=='#') {
|
|||
|
if (buffer[1])
|
|||
|
printf("/* %s */\n", buffer+1);
|
|||
|
else
|
|||
|
putchar('\n');
|
|||
|
continue;
|
|||
|
}
|
|||
|
ptr = buffer; p = 0;
|
|||
|
|
|||
|
NEXTFIELD;
|
|||
|
printf("o%s: ", ptr+s);
|
|||
|
|
|||
|
NEXTFIELD;
|
|||
|
if (ptr[s+3]) {
|
|||
|
array = ptr[s+3];
|
|||
|
ptr[s+3] = 0;
|
|||
|
ticks = atoi(ptr+s);
|
|||
|
ptr[s+3] = array;
|
|||
|
array = ptr[s+6];
|
|||
|
ptr[s+6] = 0;
|
|||
|
if (ticks)
|
|||
|
printf("ticks-=%i+%s[(int)I[%i]];", ticks, ptr+s+3, array-'0');
|
|||
|
else
|
|||
|
printf("ticks-=%s[(int)I[%i]];", ptr+s+3, array-'0');
|
|||
|
ptr[s+6] = array;
|
|||
|
} else {
|
|||
|
ticks = atoi(ptr+s);
|
|||
|
printf("ticks-=%i; ", ticks);
|
|||
|
}
|
|||
|
|
|||
|
NEXTFIELD;
|
|||
|
NEXTFIELD;
|
|||
|
NEXTFIELD;
|
|||
|
printf("%s goto o_done;\n", ptr+s);
|
|||
|
|
|||
|
icnt++;
|
|||
|
}
|
|||
|
if (feof(stdin))
|
|||
|
printf("/* %i lines, %i instructions */\n", lcnt, icnt);
|
|||
|
else
|
|||
|
fprintf(stderr, "Error at line %i\n", lcnt+1);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|