/* UNSANITIZE.C Opposite of sanitize. turn { } to c-style braces. Aids conversion of C code from atascii to ascii. This program is copyleft 1989 by JRD. See COPYLEFT.JRD for a detailed description of your rights and responsibilities about copying it. Give this program and its source away! Help create more free software! */ #include #ifndef M6502 #include #define delete unlink #endif char buf1[80]; char buf2[80]; main(argc, argv) int argc; char ** argv; { char * name; char * p; FILE * inf; FILE * outf; int ch, other_ch; if (argc > 1) { name = argv[1]; strcpy(buf1, name); } else { #ifdef M6502 printf("UNSANITIZE>"); if (getname(buf1) <= 0) exit(0); name = buf1; #else printf("Unsanitize what?\n"); exit(0); #endif } fn_default(name, 0, buf1); name = buf1; inf = fopen(name, "r"); /* printf("open '%s'->%x\n", name, inf); */ if ((int)inf <= 0) { printf("Can't open '%s' error %x\n", name, errno); #ifdef M6502 kbdchar(); #endif exit(0); } strcpy(buf2, buf1); p = strchr(buf2, '.'); if (!p) p = buf2 + strlen(buf2); strcpy(p, ".tmp"); outf = fopen(buf2, "w"); /* printf("open '%s'->%x\n", buf2, outf); */ while ((ch = fgetc(inf)) != EOF) { switch (ch) { case '$': other_ch = fgetc(inf); switch(other_ch) { case '(': other_ch = 0x7B; break; case ')': other_ch = 0x7D; break; default: fputc(ch, outf); } fputc(other_ch, outf); break; default: fputc(ch, outf); } } fclose(inf); fclose(outf); delete(buf1); rename(buf2, buf1); } #ifdef M6502 int getname(buf) char * buf; { int i; int ch; i = 0; /* str idx */ for (; ((ch = kbdchar()) != '\n') ; ) { if (ch == '\b') { if (i > 0) { fputc('\b', stderr); i--; } } else { fputc(ch, stderr); buf[i] = ch; i++; } } buf[i] = '\0'; return strlen(buf); } #endif