Correctly handle m68k long double format.
[glibc/pb-stable.git] / locale / programs / linereader.h
blob27ea124037614587e660c6a1c78831c7eb36c21d
1 /* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.org>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #ifndef _LINEREADER_H
21 #define _LINEREADER_H 1
23 #include <ctype.h>
24 #include <libintl.h>
25 #include <stdint.h>
26 #include <stdio.h>
28 #include "charmap.h"
29 #include "error.h"
30 #include "locfile-token.h"
31 #include "repertoire.h"
34 typedef const struct keyword_t *(*kw_hash_fct_t) (const char *, unsigned int);
35 struct charset_t;
38 struct token
40 enum token_t tok;
41 union
43 struct
45 char *startmb;
46 size_t lenmb;
47 uint32_t *startwc;
48 size_t lenwc;
49 } str;
50 unsigned long int num;
51 struct
53 /* This element is sized on the safe expectation that no single
54 character in any character set uses more then 16 bytes. */
55 unsigned char bytes[16];
56 int nbytes;
57 } charcode;
58 uint32_t ucs4;
59 } val;
63 struct linereader
65 FILE *fp;
66 const char *fname;
67 char *buf;
68 size_t bufsize;
69 size_t bufact;
70 size_t lineno;
72 size_t idx;
74 char comment_char;
75 char escape_char;
77 struct token token;
79 int translate_strings;
80 int return_widestr;
82 kw_hash_fct_t hash_fct;
86 /* Functions defined in linereader.c. */
87 extern struct linereader *lr_open (const char *fname, kw_hash_fct_t hf);
88 extern struct linereader *lr_create (FILE *fp, const char *fname, 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 const struct repertoire_t *repertoire,
95 int verbose);
98 #define lr_error(lr, fmt, args...) \
99 error_at_line (0, 0, lr->fname, lr->lineno, fmt, ## args)
103 static inline int
104 lr_getc (struct linereader *lr)
106 if (lr->idx == lr->bufact)
108 if (lr->bufact != 0)
109 if (lr_next (lr) < 0)
110 return EOF;
112 if (lr->bufact == 0)
113 return EOF;
116 return lr->buf[lr->idx] == '\32' ? EOF : lr->buf[lr->idx++];
120 static inline int
121 lr_ungetc (struct linereader *lr, int ch)
123 if (lr->idx == 0)
124 return -1;
126 if (ch != EOF)
127 lr->buf[--lr->idx] = ch;
128 return 0;
132 static inline int
133 lr_ungetn (struct linereader *lr, size_t n)
135 if (lr->idx < n)
136 return -1;
138 lr->idx -= n;
139 return 0;
143 static inline void
144 lr_ignore_rest (struct linereader *lr, int verbose)
146 if (verbose)
148 while (isspace (lr->buf[lr->idx]) && lr->buf[lr->idx] != '\n'
149 && lr->buf[lr->idx] != lr->comment_char)
150 if (lr->buf[lr->idx] == '\0')
152 if (lr_next (lr) < 0)
153 return;
155 else
156 ++lr->idx;
158 if (lr->buf[lr->idx] != '\n' && ! feof (lr->fp)
159 && lr->buf[lr->idx] != lr->comment_char)
160 lr_error (lr, _("trailing garbage at end of line"));
163 /* Ignore continued line. */
164 while (lr->bufact > 0 && lr->buf[lr->bufact - 1] != '\n')
165 if (lr_next (lr) < 0)
166 break;
168 lr->idx = lr->bufact;
172 #endif /* linereader.h */