1 /* Manage different file formats HTFormat.c
2 ** =============================
7 ** Assumes the incoming stream is ASCII, rather than a local file
8 ** format, and so ALWAYS converts from ASCII on non-ASCII machines.
9 ** Therefore, non-ASCII machines can't read local files.
20 extern HTStyleSheet * styleSheet;
25 ** The input file is read using the macro which can read from
26 ** a socket or a file.
27 ** The input buffer size, if large will give greater efficiency and
28 ** release the server faster, and if small will save space on PCs etc.
30 #define INPUT_BUFFER_SIZE 4096 /* Tradeoff */
31 PRIVATE char input_buffer[INPUT_BUFFER_SIZE];
32 PRIVATE char * input_pointer;
33 PRIVATE char * input_limit;
34 PRIVATE int input_file_number;
37 /* Set up the buffering
39 ** These routines are public because they are in fact needed by
40 ** many parsers, and on PCs and Macs we should not duplicate
41 ** the static buffer area.
43 PUBLIC void HTInitInput ARGS1 (int,file_number)
45 input_file_number = file_number;
46 input_pointer = input_limit = input_buffer;
50 PUBLIC char HTGetChararcter NOARGS
54 if (input_pointer >= input_limit) {
56 int status = cl_read_data(
57 input_file_number, input_buffer, INPUT_BUFFER_SIZE);
60 input_file_number, input_buffer, INPUT_BUFFER_SIZE);
63 if (status == 0) return (char)EOF;
64 if (TRACE) fprintf(stderr,
65 "HTFormat: File read error %d\n", status);
66 return (char)EOF; /* -1 is returned by UCX at end of HTTP link */
68 input_pointer = input_buffer;
69 input_limit = input_buffer + status;
71 ch = *input_pointer++;
72 } while (ch == (char) 13); /* Ignore ASCII carriage return */
78 /* Parse a file given format and file number
81 PUBLIC void HTParseFormat ARGS3(
83 HTParentAnchor *,anchor,
91 HTInitInput(file_number);
95 case WWW_HTML: /* Parse HTML */
98 SGML_begin(&HTML_dtd);
101 character = HTGetChararcter();
102 if (character == (char)EOF) break;
104 if (++bytecount % 1024 == 0) prompt_count(bytecount / 1024);
107 SGML_character(&HTML_dtd, character);
113 default : /* unknown format -- Parse plain text */
115 HText * text = HText_new(anchor);
116 HText_setStyle(text, HTStyleNamed(styleSheet, "Example"));
117 HText_beginAppend(text);
120 character = HTGetChararcter();
121 if (character == (char)EOF) break;
123 if (++bytecount % 1024 == 0) prompt_count(bytecount / 1024);
125 HText_appendCharacter(text, character);
127 HText_endAppend(text);
131 } /* end of switch (format) */