/* ascii to atascii */ /* 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 #endif char buf1[40]; char buf2[40]; main(argc, argv) int argc; char ** argv; { char * name; char * p; FILE * inf; FILE * outf; int ch; if (argc > 1) { name = argv[1]; strcpy(buf1, name); } else { #ifdef M6502 printf("A2AT>"); if (getname(buf1) <= 0) exit(0); name = buf1; #else printf("A2AT 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) { #ifdef M6502 case 0x0D: fgetc(inf); case 0x0A: ch = '\n'; break; case 0x09: ch = '\t'; break; #else case '\n': ch = 0x9B; break; case '\t': ch = 0x7F; break; #endif } 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