1 /*
2 * html2hdml
3 *
4 * Coprygight (C) 2000-2003 Dino Co.,Ltd.
5 * http://www.dino.co.jp/
6 */
7 #ifdef HAVE_CONFIG_H
8 # include <config.h>
9 #endif
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include "strinput.h"
15 #include "html2hdml.h"
16 #include <time.h>
17
18 const char *myinput;
19 char *myinputptr;
20 char *myinputlim;
21
22 struct clientinfo gl_clientinfo;
23 struct convertopt gl_convertopt;
24
set_inputstr(const char * input,int inputlen)25 int set_inputstr(const char *input, int inputlen)
26 {
27 myinput = input;
28 myinputptr = (char *)input;
29 myinputlim = myinputptr+inputlen;
30
31 return 0;
32 }
33
func(const char * buffer,int buf_len,struct clientinfo * clientinfo,struct convertopt * convertopt)34 int func(const char *buffer, int buf_len,
35 struct clientinfo *clientinfo,
36 struct convertopt *convertopt)
37 {
38 gl_clientinfo = *clientinfo;
39 gl_convertopt = *convertopt;
40
41 set_inputstr(buffer, buf_len);
42 parse_html();
43
44 return 0;
45 }
46
set_default_opt(void)47 int set_default_opt(void)
48 {
49 gl_clientinfo.row = 10;
50 gl_clientinfo.column = 10;
51
52 gl_convertopt.a_href_html2hdml = 1;
53 gl_convertopt.img = 1;
54 gl_convertopt.img_src_gif2bmp = 1;
55 gl_convertopt.img_alt = 0;
56
57 return 0;
58 }
59
60 #ifndef ZODIAX
main(int argc,char ** argv)61 int main(int argc, char **argv)
62 {
63 char buf_stack[BUFFER_SIZE], *buf, *ptr;
64 int n;
65 int var_for_debug; /* for deadline check */
66 int need_to_close = 1;
67 int heap_used = 0;
68 FILE *fp;
69 int bufsize;
70
71 set_default_opt();
72
73 var_for_debug = 1; /* always OK */
74
75 if (argc >= 2) {
76 fp = fopen(argv[1], "rb");
77 if (fp == NULL) {
78 return 0;
79 }
80 } else {
81 fp = stdin;
82 need_to_close = 0;
83 }
84
85 n = fread(buf_stack, sizeof(char), BUFFER_SIZE-1, fp);
86 buf_stack[n] = '\0';
87
88 if (feof(fp)) {
89 buf = buf_stack;
90 bufsize = n+1;
91 } else {
92 heap_used = 1;
93
94 bufsize = n+1;
95 buf = malloc(bufsize*sizeof(char));
96 ptr = buf;
97
98 /* realloc & copy */
99 memcpy(ptr, buf_stack, n);
100
101 do {
102 n = fread(buf_stack, sizeof(char), BUFFER_SIZE-1, fp);
103 buf_stack[n] = '\0';
104 if (n) {
105 buf = realloc(buf, (bufsize+n)*sizeof(char));
106 ptr = buf+bufsize-1;
107 bufsize += n;
108
109 memcpy(ptr, buf_stack, n);
110 }
111 } while (!feof(fp));
112 buf[bufsize-1] = '\0';
113 }
114 if (need_to_close) fclose(fp);
115
116 if (bufsize > 1500) {
117 fprintf(stderr, "warning: input HTML is over 1500bytes.\n");
118 }
119
120 set_inputstr(buf, bufsize-1);
121
122 if (var_for_debug) {
123 parse_html();
124 }
125
126 if (heap_used) free(buf);
127 return 0;
128 }
129 #endif /* ZODIAX */
130