Home | History | Annotate | Download | only in wcstox
      1 #ifndef SHGETC_H
      2 #define SHGETC_H
      3 
      4 #include <stdio.h>
      5 #include <wchar.h>
      6 
      7 // Custom stream abstraction, replaces the Musl FILE type for
      8 // the purpose of scanning integers and floating points.
      9 // |rstart| is the start of the input string.
     10 // |rend| is the first wchar_t after it.
     11 // |rpos| is the current reading position.
     12 // |extra_eof| is a counter of positions past EOF. Needed because the
     13 // scanning routines more or less assume an infinite input string, with
     14 // EOF being returned when shgetc() is being called past the real end
     15 // of the input stream.
     16 struct fake_file_t {
     17     const wchar_t *rstart, *rpos, *rend;
     18     int extra_eof;
     19 };
     20 
     21 // Initialize fake_file_t structure from a wide-char string.
     22 void shinit_wcstring(struct fake_file_t *, const wchar_t *wcs);
     23 
     24 // Get next character from string. This convers the wide character to
     25 // an 8-bit value, which will be '@' in case of overflow. Returns EOF (-1)
     26 // in case of end-of-string.
     27 int shgetc(struct fake_file_t *);
     28 
     29 // Back-track one character, must not be called more times than shgetc()
     30 void shunget(struct fake_file_t *);
     31 
     32 // This will be called with a value of 0 for |lim| to force rewinding
     33 // to the start of the string. In Musl, this is also used in different
     34 // parts of the library to impose a local limit on the number of characters
     35 // that can be retrieved through shgetc(), but this is not necessary here.
     36 void shlim(struct fake_file_t *, off_t lim);
     37 
     38 // Return the number of input characters that were read so far.
     39 off_t shcnt(struct fake_file_t *);
     40 
     41 #endif  // SHGETC_H
     42