/*   SANITIZE.C   flush tabs and convert ascii   braces to two $( $).  Aids   conversion of C code from 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 <stdio.h>#ifndef M6502#include <errno.h>#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;  if (argc > 1)    $(    name = argv[1];    strcpy(buf1, name);    $)   else    $(#ifdef M6502    printf("SANITIZE>");    if (getname(buf1) <= 0)      exit(0);    name = buf1;#else    printf("Sanitize 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 0x7B:        fputc('$', outf);        fputc('(', outf);        break;      case 0x7D:        fputc('$', outf);        fputc(')', outf);        break;      case '\t':        fputc(' ', outf);        fputc(' ', 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