// a silly quotation utitility

#include <stdio.h>
#include <strings.h>

void pchr(int c, int indent)
{
  switch(c)
  {
    case '\n':            printf("\\n\"\n%*s\"",indent,""); break;
    case '"' : case '\\': printf("\\%c",c);               break;
    default:              printf("%c",c);                 break;
  }
}

#define INDENT 2

int main(int argc, char* argv[])
{ int cc; FILE *sysin;
  if (argc < 2) { fprintf(stderr,"usage: %s filename\n",argv[0]); return 1; }
  sysin = fopen(argv[1],"r");
  if (!sysin) { fprintf(stderr,"cannot open %s\n",argv[1]); perror("reason: "); return 1; }
  printf("%*s/* generated by '%s %s' */\n\n",INDENT,"",argv[0],argv[1]);
  printf("%*s\"",INDENT,"");
  while( (cc = fgetc(sysin)) > 0)
  {
    pchr(cc,INDENT);
  }
  printf("\"\n");
}
