1 /* A string or file based input stream, that keeps track of a line number.
2 Copyright (C) 2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation, either version 3 of the
7 License, or (at your option) any later version.
9 This file 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2024. */
22 #include "sfl-istream.h"
25 sfl_istream_init_from_file (sfl_istream_t
*stream
, FILE *fp
)
27 sf_istream_init_from_file (&stream
->istream
, fp
);
28 stream
->line_number
= 1;
32 sfl_istream_init_from_string (sfl_istream_t
*stream
, const char *input
)
34 sf_istream_init_from_string (&stream
->istream
, input
);
35 stream
->line_number
= 1;
39 sfl_istream_init_from_string_desc (sfl_istream_t
*stream
, string_desc_t input
)
41 sf_istream_init_from_string_desc (&stream
->istream
, input
);
42 stream
->line_number
= 1;
46 sfl_set_line_number (sfl_istream_t
*stream
, size_t line_number
)
48 stream
->line_number
= line_number
;
52 sfl_get_line_number (sfl_istream_t
*stream
)
54 return stream
->line_number
;
58 sfl_getc (sfl_istream_t
*stream
)
60 int c
= sf_getc (&stream
->istream
);
62 stream
->line_number
++;
67 sfl_ferror (sfl_istream_t
*stream
)
69 return sf_ferror (&stream
->istream
);
73 sfl_ungetc (sfl_istream_t
*stream
, int c
)
76 stream
->line_number
--;
77 sf_ungetc (&stream
->istream
, c
);
81 sfl_free (sfl_istream_t
*stream
)
83 sf_free (&stream
->istream
);