Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / apps / konsole / tests / quote.c
blob7377d86161f9cf26fc450f0fd45b73a4a7c6a64c
1 // a silly quotation utitility
3 /*
4 This code was written by Lars Doelle <lars.doelle@on-line.de>.
5 This code is in the public domain.
6 */
8 #include <stdio.h>
9 #include <strings.h>
11 int skip = 0;
12 int empty = 1;
14 void pchr(int c, int indent)
16 if (skip)
18 skip = (c != '\n');
19 return;
21 switch(c)
23 case '\n':
24 if (!empty)
25 printf("\\n\"\n%*s\"",indent,"");
26 empty = 1;
27 break;
28 case '#' :
29 skip = 1;
30 break;
31 case '"' : case '\\':
32 printf("\\");
33 // fallthrough
34 default:
35 printf("%c",c);
36 empty = 0;
37 break;
41 #define INDENT 2
43 int main(int argc, char* argv[])
44 { int cc; FILE *sysin;
45 if (argc < 2) { fprintf(stderr,"usage: %s filename\n",argv[0]); return 1; }
46 sysin = fopen(argv[1],"r");
47 if (!sysin) { fprintf(stderr,"cannot open %s\n",argv[1]); perror("reason: "); return 1; }
48 printf("%*s/* generated by '%s %s' */\n\n",INDENT,"",argv[0],argv[1]);
49 printf("%*s\"",INDENT,"");
50 while( (cc = fgetc(sysin)) > 0)
52 pchr(cc,INDENT);
54 printf("\"\n");