Update syscall lists for Linux 6.6
[glibc.git] / locale / programs / linereader.h
blob13bc5ccd339899b7f41d353ef024aa1be411d2a0
1 /* Copyright (C) 1996-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation; version 2 of the License, or
7 (at your option) any later version.
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, see <https://www.gnu.org/licenses/>. */
17 #ifndef _LINEREADER_H
18 #define _LINEREADER_H 1
20 #include <ctype.h>
21 #include <libintl.h>
22 #include <stdint.h>
23 #include <stdio.h>
25 #include "charmap.h"
26 #include "error.h"
27 #include "locfile-token.h"
28 #include "repertoire.h"
29 #include "record-status.h"
31 typedef const struct keyword_t *(*kw_hash_fct_t) (const char *, size_t);
32 struct charset_t;
33 struct localedef_t;
35 struct token
37 enum token_t tok;
38 union
40 struct
42 char *startmb;
43 size_t lenmb;
44 uint32_t *startwc;
45 size_t lenwc;
46 } str;
47 unsigned long int num;
48 struct
50 /* This element is sized on the safe expectation that no single
51 character in any character set uses more than 16 bytes. */
52 unsigned char bytes[16];
53 int nbytes;
54 } charcode;
55 uint32_t ucs4;
56 } val;
60 struct linereader
62 FILE *fp;
63 const char *fname;
64 char *buf;
65 size_t bufsize;
66 size_t bufact;
67 size_t lineno;
69 size_t idx;
71 char comment_char;
72 char escape_char;
74 struct token token;
76 int translate_strings;
77 int return_widestr;
79 kw_hash_fct_t hash_fct;
83 /* Functions defined in linereader.c. */
84 extern struct linereader *lr_open (const char *fname, kw_hash_fct_t hf);
85 extern struct linereader *lr_create (FILE *fp, const char *fname,
86 kw_hash_fct_t hf);
87 extern int lr_eof (struct linereader *lr);
88 extern void lr_close (struct linereader *lr);
89 extern int lr_next (struct linereader *lr);
90 extern struct token *lr_token (struct linereader *lr,
91 const struct charmap_t *charmap,
92 struct localedef_t *locale,
93 const struct repertoire_t *repertoire,
94 int verbose);
95 extern void lr_ignore_rest (struct linereader *lr, int verbose);
98 static inline void
99 __attribute__ ((__format__ (__printf__, 2, 3), nonnull (1, 2)))
100 lr_error (struct linereader *lr, const char *fmt, ...)
102 char *str;
103 va_list arg;
104 struct locale_state ls;
105 int ret;
107 va_start (arg, fmt);
108 ls = push_locale ();
110 ret = vasprintf (&str, fmt, arg);
111 if (ret == -1)
112 abort ();
114 pop_locale (ls);
115 va_end (arg);
117 error_at_line (0, 0, lr->fname, lr->lineno, "%s", str);
119 free (str);
123 static inline int
124 __attribute ((always_inline))
125 lr_getc (struct linereader *lr)
127 if (lr->idx == lr->bufact)
129 if (lr->bufact != 0)
130 if (lr_next (lr) < 0)
131 return EOF;
133 if (lr->bufact == 0)
134 return EOF;
137 return lr->buf[lr->idx++] & 0xff;
141 static inline int
142 __attribute ((always_inline))
143 lr_ungetc (struct linereader *lr, int ch)
145 if (lr->idx == 0)
146 return -1;
148 if (ch != EOF)
149 lr->buf[--lr->idx] = ch;
150 return 0;
154 static inline int
155 lr_ungetn (struct linereader *lr, size_t n)
157 if (lr->idx < n)
158 return -1;
160 lr->idx -= n;
161 return 0;
165 #endif /* linereader.h */