1 #ifndef INPUT_H
2 #define INPUT_H
3 
4 #include <stdio.h>
5 #include "charset.h"
6 #include "stdio16.h"
7 #include "dtd.h"
8 
9 /* Typedefs */
10 
11 typedef struct input_source *InputSource;
12 
13 /* Input sources */
14 
15 XML_API InputSource SourceFromFILE16(const char8 *description, FILE16 *file16);
16 XML_API InputSource SourceFromStream(const char8 *description, FILE *file);
17 XML_API InputSource EntityOpen(Entity e);
18 XML_API InputSource NewInputSource(Entity e, FILE16 *f16);
19 XML_API void SourceClose(InputSource source);
20 XML_API int SourceTell(InputSource s);
21 XML_API int SourceSeek(InputSource s, int byte_offset);
22 XML_API int SourceLineAndChar(InputSource s, int *linenum, int *charnum);
23 XML_API void SourcePosition(InputSource s, Entity *entity, int *byte_offset);
24 XML_API int get_with_fill(InputSource s);
25 XML_API void determine_character_encoding(InputSource s);
26 
27 struct input_source {
28     Entity entity;		/* The entity from which the source reads */
29 
30     void (*reader)(InputSource); /* line-reading method */
31     unsigned char *map;		 /* character type map */
32 
33     FILE16 *file16;
34 
35     Char *line;
36     int line_alloc, line_length;
37     int line_is_incomplete;
38     int next;
39 
40     int seen_eoe;
41     int complicated_utf8_line;
42     int bytes_consumed;
43     int bytes_before_current_line;
44     int line_end_was_cr;
45     int expecting_low_surrogate;
46     int ignore_linefeed;
47 
48     int line_number;
49     int not_read_yet;
50     int read_carefully;		/* be sure not to read past end of XML decl */
51 
52     struct input_source *parent;
53 
54     int nextin;
55     int insize;
56     unsigned char inbuf[4096];
57 
58     int seen_error;
59     char error_msg[100];
60 
61     int cached_line_char;	/* cached data for SourceTell */
62     int cached_line_byte;
63 };
64 
65 /* EOE used to be -2, but that doesn't work if Char is signed char */
66 #define XEOE (-999)
67 
68 /* Use NUL for an illegal character (in 1.1, it's the only illegal 8-bit
69    character) */
70 #define BADCHAR 0
71 
72 #define at_eol(s) ((s)->next == (s)->line_length)
73 #define get(s)    (at_eol(s) ? get_with_fill(s) : (s)->line[(s)->next++])
74 #define unget(s)  ((s)->seen_eoe ? (s)->seen_eoe= 0 : (s)->next--)
75 
76 #endif /* INPUT_H */
77