summaryrefslogtreecommitdiffstats
path: root/common/html2js.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/html2js.c')
-rw-r--r--common/html2js.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/common/html2js.c b/common/html2js.c
index 1f38a45..f6bf46c 100644
--- a/common/html2js.c
+++ b/common/html2js.c
@@ -2,8 +2,7 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include <unistd.h> 4#include <unistd.h>
5void html2js(char file_name[]) 5void html2js(char file_name[]) {
6{
7 FILE *html, *js; 6 FILE *html, *js;
8 char buf[1024]; 7 char buf[1024];
9 size_t i, len; 8 size_t i, len;
@@ -11,27 +10,22 @@ void html2js(char file_name[])
11 strcpy(tmp, file_name); 10 strcpy(tmp, file_name);
12 html = fopen(strcat(tmp, ".html"), "r"); 11 html = fopen(strcat(tmp, ".html"), "r");
13 js = fopen(strcat(file_name, ".js"), "w"); 12 js = fopen(strcat(file_name, ".js"), "w");
14 if (html == NULL || js == NULL) 13 if (html == NULL || js == NULL) {
15 {
16 printf("ERROR:Fail to open file!\n"); 14 printf("ERROR:Fail to open file!\n");
17 exit(1); 15 exit(1);
18 } 16 }
19 while (!feof(html)) 17 while (!feof(html)) {
20 {
21 memset(buf, '\0', 1024); 18 memset(buf, '\0', 1024);
22 fgets(buf, 1024, html); 19 fgets(buf, 1024, html);
23 len = strlen(buf); 20 len = strlen(buf);
24 fprintf(js, "document.writeln(\""); 21 fprintf(js, "document.writeln(\"");
25 for (i = 0; i < len - 1; i++) 22 for (i = 0; i < len - 1; i++) {
26 { 23 if (buf[i] == '\"' || buf[i] == '\'') {
27 if (buf[i] == '\"' || buf[i] == '\'')
28 {
29 fprintf(js, "\\"); 24 fprintf(js, "\\");
30 } 25 }
31 fprintf(js, "%c", buf[i]); 26 fprintf(js, "%c", buf[i]);
32 } 27 }
33 if (buf[i] != '\n') 28 if (buf[i] != '\n') {
34 {
35 fprintf(js, "%c", buf[i]); 29 fprintf(js, "%c", buf[i]);
36 } 30 }
37 fprintf(js, "\");\n"); 31 fprintf(js, "\");\n");
@@ -40,12 +34,11 @@ void html2js(char file_name[])
40 fclose(js); 34 fclose(js);
41 printf("Success!\n"); 35 printf("Success!\n");
42} 36}
43int main() 37int main() {
44{
45 char file_name[30]; 38 char file_name[30];
46 strcpy(file_name, "script4code"); 39 strcpy(file_name, "common/script4code");
47 html2js(file_name); 40 html2js(file_name);
48 strcpy(file_name, "script4works"); 41 strcpy(file_name, "common/script4works");
49 html2js(file_name); 42 html2js(file_name);
50 return 0; 43 return 0;
51} 44}