#include #include #include char buff[1000]; int instr(char *b) // returns 0 if comment // return instr type otherwise { if ( b[1] == '/' ) return 1; if ( b[2] == '/' ) return 1; return 0; } main(int argc, char **argv) { FILE *fin = fopen(argv[1], "r"); FILE *fin2 = NULL; char *msg = NULL; int n0 = -1; // previous value of n, enables test for special variants if ( argc >=3 ) // template file specified as first param { while ( *fgets(buff, 999, fin) != '*' ) // look for * in column 1 fputs(buff, stdout); fin2 = fin; fin = fopen(argv[2], "r"); } fgets(buff, 999, fin); // skip title line while ( fgets(buff, 999, fin) != NULL ) if ( strlen(buff) >=3 ) // not just a page number if ( instr(buff) == 0 ) // more comment printf(" // %s", buff); else { int i = 4; int f = atoi(buff); int n = f<<3; if ( msg != NULL ) { printf(" notImplemented(\"%s\");\n", msg); free(msg); printf(" break;\n"); printf(" /* --------------- */\n"); } while ( buff[++i] != ' ' ) ; buff[i++] = 0; if ( strcmp(buff+i-5, "/d/m") == 0 ) // standard form instruction { printf(" case 0%03o: case 0%03o: case 0%03o:\n", n + 5, n + 6, n + 7); printf(" m = store[groupref + m + m];\n"); printf(" case 0%03o:\n", n + 4); printf(" notImplemented(\"Long form\");\n"); printf(" case 0%03o: case 0%03o: case 0%03o:\n", n + 1, n + 2, n + 3); printf(" m = store[groupref + m + m];\n"); } else if ( buff[i-4] == 'd' ) // variable d but fixed m { n += atoi(buff+i-2); printf(" case 0%03o:\n", n + 4); // need to accommodate both variants } else if ( buff[i-2] == 'm' ) // fixed d but variable m { n += atoi(buff+i-4) * 4; printf(" case 0%03o: case 0%03o: case 0%03o:\n", n + 1, n + 2, n + 3); } else // fixed d and m { n += atoi(buff+i-4) * 4; n += atoi(buff+i-2); } if ( n == n0 ) // instruction with multiply specified variants printf(" // 0%03o: // %s - %s", n, buff, buff+i); else printf(" case 0%03o: // %s - %s", n, buff, buff+i); n0 = n; n = i; while ( buff[++n] != 0 && buff[n] < 'a' ) ; while ( buff[--n] > 'Z' || buff[n] < 'A' ) ; buff[n] = 0; msg = strdup(buff+i); } printf(" notImplemented(\"%s\");\n", msg); printf(" break;\n"); printf(" /* --------------- */\n"); if ( fin2 != NULL ) while ( fgets(buff, 999, fin2) != NULL ) fputs(buff, stdout); }