1837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh#ifndef SHGETC_H 2837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh#define SHGETC_H 3837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 4837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh#include <stdio.h> 5837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh#include <wchar.h> 6837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 7837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// Custom stream abstraction, replaces the Musl FILE type for 8837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// the purpose of scanning integers and floating points. 9837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// |rstart| is the start of the input string. 10837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// |rend| is the first wchar_t after it. 11837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// |rpos| is the current reading position. 12837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// |extra_eof| is a counter of positions past EOF. Needed because the 13837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// scanning routines more or less assume an infinite input string, with 14837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// EOF being returned when shgetc() is being called past the real end 15837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// of the input stream. 16837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsiehstruct fake_file_t { 17837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh const wchar_t *rstart, *rpos, *rend; 18837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh int extra_eof; 19837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh}; 20837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 21837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// Initialize fake_file_t structure from a wide-char string. 22837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsiehvoid shinit_wcstring(struct fake_file_t *, const wchar_t *wcs); 23837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 24837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// Get next character from string. This convers the wide character to 25837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// an 8-bit value, which will be '@' in case of overflow. Returns EOF (-1) 26837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// in case of end-of-string. 27837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsiehint shgetc(struct fake_file_t *); 28837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 29837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// Back-track one character, must not be called more times than shgetc() 302569ad3ea4275b371c9cccfb4fb42183838a44e1Nico Webervoid shunget(struct fake_file_t *); 31837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 32837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// This will be called with a value of 0 for |lim| to force rewinding 33837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// to the start of the string. In Musl, this is also used in different 34837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// parts of the library to impose a local limit on the number of characters 35837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// that can be retrieved through shgetc(), but this is not necessary here. 36837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsiehvoid shlim(struct fake_file_t *, off_t lim); 37837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 38837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh// Return the number of input characters that were read so far. 39837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsiehoff_t shcnt(struct fake_file_t *); 40837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh 41837ecf801d102042e63827d8e89e3213f0c90493Andrew Hsieh#endif // SHGETC_H 42