Test program to read all whitespace delimited tokens in a text file
This commit is contained in:
19
main.c
19
main.c
@@ -18,12 +18,25 @@
|
|||||||
|
|
||||||
#include "./alisp.h"
|
#include "./alisp.h"
|
||||||
|
|
||||||
|
const char *TOKEN_DELIM = "\n ";
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
char filename[] = "./lorem.txt";
|
||||||
|
FILE *fp = fopen(filename, "r");
|
||||||
stream_t stream = {0};
|
stream_t stream = {0};
|
||||||
stream_init_pipe(&stream, "<stdin>", stdin);
|
stream_init_file(&stream, filename, fp);
|
||||||
sv_t sv = stream_substr(&stream, 10);
|
|
||||||
printf("=> `" PR_SV "`\n", SV_FMT(sv));
|
for (u64 token_no = 1; !stream_eoc(&stream); ++token_no)
|
||||||
|
{
|
||||||
|
// Skip forward any delimiters
|
||||||
|
stream_while(&stream, TOKEN_DELIM);
|
||||||
|
// Get the token (up until delimiter)
|
||||||
|
sv_t token = stream_till(&stream, TOKEN_DELIM);
|
||||||
|
printf("%s[%lu] => `" PR_SV "`\n", stream.name, token_no, SV_FMT(token));
|
||||||
|
}
|
||||||
|
|
||||||
stream_stop(&stream);
|
stream_stop(&stream);
|
||||||
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user