Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
input.h
1 /*************************************************************************/
2 /* */
3 /* Copyright (c) 1997-98 Richard Tobin, Language Technology Group, HCRC, */
4 /* University of Edinburgh. */
5 /* */
6 /* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, */
7 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
8 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
9 /* IN NO EVENT SHALL THE AUTHOR OR THE UNIVERSITY OF EDINBURGH BE LIABLE */
10 /* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF */
11 /* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION */
12 /* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
13 /* */
14 /*************************************************************************/
15 #ifndef INPUT_H
16 #define INPUT_H
17 
18 #ifndef FOR_LT
19 #define XML_API
20 #endif
21 
22 #include <stdio.h>
23 #include "charset.h"
24 #include "stdio16.h"
25 #include "dtd.h"
26 
27 /* Typedefs */
28 
29 typedef struct input_source *InputSource;
30 typedef struct stream_ops *StreamOps;
31 typedef int ReadProc(StreamOps ops, unsigned char *buf, int max_count);
32 typedef int WriteProc(StreamOps ops, unsigned char *buf, int count);
33 typedef void CloseProc(StreamOps ops);
34 typedef int SeekProc(StreamOps ops, int offset);
35 
36 /* Input sources */
37 
38 XML_API InputSource SourceFromStream(const char8 *description, FILE *file);
39 XML_API InputSource EntityOpen(Entity e);
40 XML_API InputSource NewInputSource(Entity e, FILE16 *f16);
41 XML_API int SourceTell(InputSource s);
42 XML_API int SourceSeek(InputSource s, int offset);
43 XML_API int SourceLineAndChar(InputSource s, int *linenum, int *charnum);
44 XML_API void SourcePosition(InputSource s, Entity *entity, int *char_number);
45 XML_API int get_with_fill(InputSource s);
46 XML_API void determine_character_encoding(InputSource s);
47 
48 struct input_source {
49  Entity entity; /* The entity from which the source reads */
50 
51  FILE16 *file16;
52 
53  Char *line;
54  int line_alloc, line_length;
55  int next;
56 
57  int seen_eoe;
58  int complicated_utf8_line;
59  int bytes_consumed;
60  int bytes_before_current_line;
61  int line_end_was_cr;
62 
63  int line_number;
64  int not_read_yet;
65 
66  struct input_source *parent;
67 
68  int nextin;
69  int insize;
70  unsigned char inbuf[4096];
71 };
72 
73 /* EOE used to be -2, but that doesn't work if Char is signed char */
74 #define XEOE (-999)
75 
76 #define at_eol(s) ((s)->next == (s)->line_length)
77 #define get(s) (at_eol(s) ? get_with_fill(s) : (s)->line[(s)->next++])
78 #define unget(s) ((s)->seen_eoe ? (s)->seen_eoe= 0 : (s)->next--)
79 
80 #endif /* INPUT_H */