2.9
[glibc/nacl-glibc.git] / locale / programs / linereader.h
blobe0c844e5b2c06ad85ecfdcb0e09f342e30a1f136
1 /* Copyright (C) 1996-2001, 2002, 2003, 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.org>.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #ifndef _LINEREADER_H
20 #define _LINEREADER_H 1
22 #include <ctype.h>
23 #include <libintl.h>
24 #include <stdint.h>
25 #include <stdio.h>
27 #include "charmap.h"
28 #include "error.h"
29 #include "locfile-token.h"
30 #include "repertoire.h"
33 typedef const struct keyword_t *(*kw_hash_fct_t) (const char *, unsigned int);
34 struct charset_t;
35 struct localedef_t;
37 struct token
39 enum token_t tok;
40 union
42 struct
44 char *startmb;
45 size_t lenmb;
46 uint32_t *startwc;
47 size_t lenwc;
48 } str;
49 unsigned long int num;
50 struct
52 /* This element is sized on the safe expectation that no single
53 character in any character set uses more then 16 bytes. */
54 unsigned char bytes[16];
55 int nbytes;
56 } charcode;
57 uint32_t ucs4;
58 } val;
62 struct linereader
64 FILE *fp;
65 const char *fname;
66 char *buf;
67 size_t bufsize;
68 size_t bufact;
69 size_t lineno;
71 size_t idx;
73 char comment_char;
74 char escape_char;
76 struct token token;
78 int translate_strings;
79 int return_widestr;
81 kw_hash_fct_t hash_fct;
85 /* Functions defined in linereader.c. */
86 extern struct linereader *lr_open (const char *fname, kw_hash_fct_t hf);
87 extern struct linereader *lr_create (FILE *fp, const char *fname,
88 kw_hash_fct_t hf);
89 extern int lr_eof (struct linereader *lr);
90 extern void lr_close (struct linereader *lr);
91 extern int lr_next (struct linereader *lr);
92 extern struct token *lr_token (struct linereader *lr,
93 const struct charmap_t *charmap,
94 struct localedef_t *locale,
95 const struct repertoire_t *repertoire,
96 int verbose);
97 extern void lr_ignore_rest (struct linereader *lr, int verbose);
100 #define lr_error(lr, fmt, args...) \
101 WITH_CUR_LOCALE (error_at_line (0, 0, lr->fname, lr->lineno, fmt, ## args))
105 static inline int
106 __attribute ((always_inline))
107 lr_getc (struct linereader *lr)
109 if (lr->idx == lr->bufact)
111 if (lr->bufact != 0)
112 if (lr_next (lr) < 0)
113 return EOF;
115 if (lr->bufact == 0)
116 return EOF;
119 return lr->buf[lr->idx] == '\32' ? EOF : lr->buf[lr->idx++];
123 static inline int
124 __attribute ((always_inline))
125 lr_ungetc (struct linereader *lr, int ch)
127 if (lr->idx == 0)
128 return -1;
130 if (ch != EOF)
131 lr->buf[--lr->idx] = ch;
132 return 0;
136 static inline int
137 lr_ungetn (struct linereader *lr, size_t n)
139 if (lr->idx < n)
140 return -1;
142 lr->idx -= n;
143 return 0;
147 #endif /* linereader.h */