rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

text_reader.h (2643B)


      1 /* Copyright (C) 2013-2023, 2025 Vincent Forest (vaplv@free.fr)
      2  *
      3  * The RSys library is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published
      5  * by the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * The RSys library is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #ifndef TEXT_READER_H
     17 #define TEXT_READER_H
     18 
     19 #include "rsys.h"
     20 
     21 struct txtrdr;
     22 struct mem_allocator;
     23 
     24 BEGIN_DECLS
     25 
     26 RSYS_API res_T
     27 txtrdr_file
     28   (struct mem_allocator* allocator, /* May be NULL <=> default allocator */
     29    const char* filename,
     30    const char comment, /* Char preceeding a comment. 0 <=> no comment char */
     31    struct txtrdr** txtrdr);
     32 
     33 RSYS_API res_T
     34 txtrdr_stream
     35   (struct mem_allocator* allocator, /* May be NULL <=> default allocator */
     36    FILE* stream,
     37    const char* name, /* Stream name. May be NULL */
     38    const char comment, /* Char preceeding a comment. 0 <=> no comment char */
     39    struct txtrdr** txtrdr);
     40 
     41 RSYS_API void
     42 txtrdr_ref_get
     43   (struct txtrdr* txtrdr);
     44 
     45 RSYS_API void
     46 txtrdr_ref_put
     47   (struct txtrdr* txtrdr);
     48 
     49 /* Read a non empty line, i.e. line with text that is not a comment. The new
     50  * line character as well as the comments are skipped from the reading. A
     51  * returned value different of RES_OK means than an error occurs while reading
     52  * the stream. Note that reaching the end of file is not an error and thus that
     53  * no error is returned if the end of file is reached, even though nothing was
     54  * read. In this case the returned line is simply NULL. */
     55 RSYS_API res_T
     56 txtrdr_read_line
     57   (struct txtrdr* txtrdr);
     58 
     59 RSYS_API char*
     60 txtrdr_get_line
     61   (struct txtrdr* txtrdr);
     62 
     63 RSYS_API const char*
     64 txtrdr_get_cline
     65   (const struct txtrdr* txtrdr);
     66 
     67 /* Return the number of read lines */
     68 RSYS_API size_t
     69 txtrdr_get_line_num
     70   (const struct txtrdr* txtrdr);
     71 
     72 /* Overwrite the internal line number */
     73 RSYS_API void
     74 txtrdr_set_line_num
     75   (struct txtrdr* txtrdr,
     76    const size_t nlines);
     77 
     78 RSYS_API const char*
     79 txtrdr_get_name
     80   (const struct txtrdr* txtrdr);
     81 
     82 /* Return the stream currently read. Note that any modification of the returned
     83  * stream will affect the text reader */
     84 RSYS_API FILE*
     85 txtrdr_get_stream
     86   (const struct txtrdr* txtrdr);
     87 
     88 END_DECLS
     89 
     90 #endif /* TEXT_READER_H */