-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.c
72 lines (56 loc) · 1.35 KB
/
convert.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char *argv[] )
{
if (argc < 2){
printf("Please provide a file to convert.\n");
}
else{
FILE *file = fopen( argv[1], "r" );
if ( file == 0 ){
printf( "Could not open file\n" );
fclose( file );
exit(EXIT_FAILURE);
}
printf("const static char http_html[] = \"");
char c;
char last_c;
int open_h = 0;
int open_dh = 0;
while( (c = fgetc(file)) != EOF ){
switch (c){
case '\"':
printf("\\\"");
open_h == !open_h;
break;
case '\'':
printf("\\\'");
open_dh == !open_dh;
break;
case '\\':
printf("\\\\");
break;
case ' ':
if ((!open_dh || !open_h)&&(last_c != ' ')){
printf("%c", c);
}
break;
case '\n':
break;
case '\r':
break;
case '\t':
break;
case '\f':
break;
default:
printf("%c", c);
break;
}
last_c = c;
}
printf("\";\n");
fclose( file );
}
return 0;
}