1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// a silly quotation utitility
#include <stdio.h>
#include <strings.h>
int skip = 0;
int empty = 1;
void pchr(int c, int indent)
{
if (skip)
{
skip = (c != '\n');
return;
}
switch(c)
{
case '\n':
if (!empty)
printf("\\n\"\n%*s\"",indent,"");
empty = 1;
break;
case '#' :
skip = 1;
break;
case '"' : case '\\':
printf("\\");
// fallthrough
default:
printf("%c",c);
empty = 0;
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");
}
|