Test of cancellation after cond_signal.
[glibc/history.git] / locale / programs / linereader.h
blobd4d7e830a6ec831c7071011d809ba336c24f1602
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 version 2 as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 #ifndef _LINEREADER_H
19 #define _LINEREADER_H 1
21 #include <ctype.h>
22 #include <libintl.h>
23 #include <stdint.h>
24 #include <stdio.h>
26 #include "charmap.h"
27 #include "error.h"
28 #include "locfile-token.h"
29 #include "repertoire.h"
32 typedef const struct keyword_t *(*kw_hash_fct_t) (const char *, unsigned int);
33 struct charset_t;
34 struct localedef_t;
36 struct token
38 enum token_t tok;
39 union
41 struct
43 char *startmb;
44 size_t lenmb;
45 uint32_t *startwc;
46 size_t lenwc;
47 } str;
48 unsigned long int num;
49 struct
51 /* This element is sized on the safe expectation that no single
52 character in any character set uses more then 16 bytes. */
53 unsigned char bytes[16];
54 int nbytes;
55 } charcode;
56 uint32_t ucs4;
57 } val;
61 struct linereader
63 FILE *fp;
64 const char *fname;
65 char *buf;
66 size_t bufsize;
67 size_t bufact;
68 size_t lineno;
70 size_t idx;
72 char comment_char;
73 char escape_char;
75 struct token token;
77 int translate_strings;
78 int return_widestr;
80 kw_hash_fct_t hash_fct;
84 /* Functions defined in linereader.c. */
85 extern struct linereader *lr_open (const char *fname, kw_hash_fct_t hf);
86 extern struct linereader *lr_create (FILE *fp, const char *fname,
87 kw_hash_fct_t hf);
88 extern int lr_eof (struct linereader *lr);
89 extern void lr_close (struct linereader *lr);
90 extern int lr_next (struct linereader *lr);
91 extern struct token *lr_token (struct linereader *lr,
92 const struct charmap_t *charmap,
93 struct localedef_t *locale,
94 const struct repertoire_t *repertoire,
95 int verbose);
96 extern void lr_ignore_rest (struct linereader *lr, int verbose);
99 #define lr_error(lr, fmt, args...) \
100 WITH_CUR_LOCALE (error_at_line (0, 0, lr->fname, lr->lineno, fmt, ## args))
104 static inline int
105 __attribute ((always_inline))
106 lr_getc (struct linereader *lr)
108 if (lr->idx == lr->bufact)
110 if (lr->bufact != 0)
111 if (lr_next (lr) < 0)
112 return EOF;
114 if (lr->bufact == 0)
115 return EOF;
118 return lr->buf[lr->idx] == '\32' ? EOF : lr->buf[lr->idx++];
122 static inline int
123 __attribute ((always_inline))
124 lr_ungetc (struct linereader *lr, int ch)
126 if (lr->idx == 0)
127 return -1;
129 if (ch != EOF)
130 lr->buf[--lr->idx] = ch;
131 return 0;
135 static inline int
136 lr_ungetn (struct linereader *lr, size_t n)
138 if (lr->idx < n)
139 return -1;
141 lr->idx -= n;
142 return 0;
146 #endif /* linereader.h */