From d7229970f8910aa756d299f8bdceee7f4d1fbfbc Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 8 Feb 2023 13:19:56 +0100 Subject: add env and make smash be able to parse files with comments --- lib/io/Makefile | 2 +- lib/io/io.c | 22 +++++++++++++++++----- lib/io/io.h | 7 +++++++ lib/io/test | Bin 0 -> 36104 bytes 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100755 lib/io/test (limited to 'lib/io') diff --git a/lib/io/Makefile b/lib/io/Makefile index 73aa785..46d1d43 100644 --- a/lib/io/Makefile +++ b/lib/io/Makefile @@ -1,3 +1,3 @@ unit_test: - gcc io.c ../aec/aec.c ../cstr/cstr.c ../env/env.c ../sys/start.S -o test -static -nostdlib -fno-stack-protector -Wno-implicit-function-declaration -DIO_LIB_UNIT_TEST -g + gcc io.c ../malloc/malloc.c ../aec/aec.c ../cstr/cstr.c ../env/env.c ../sys/start.S -o test -static -nostdlib -fno-stack-protector -Wno-implicit-function-declaration -DIO_LIB_UNIT_TEST -g ./test diff --git a/lib/io/io.c b/lib/io/io.c index e8384f3..7dee314 100644 --- a/lib/io/io.c +++ b/lib/io/io.c @@ -20,7 +20,19 @@ void rstd(char *buf, unsigned long count) read(STDIN_FD, buf, count); } + +void wf(unsigned int fd, char *buf) +{ + write(fd, buf, cstr_length(buf)); +} + void wstdf__(const char *buf, const void **args) +{ + wff__(STDOUT_FD, buf, args); +} + + +void wff__(unsigned int fd, const char *buf, const void **args) { const char *start = buf; char stoi_buf[32] = ""; @@ -28,28 +40,28 @@ void wstdf__(const char *buf, const void **args) for (; *buf; ++buf) { if (*buf == '%') { if (buf - start > 0) - __wstdn(start, buf - start); + write(fd, start, buf - start); ++buf; switch (*buf) { case '%': __wstdn("%", 1); break; case 's': - __wstdn(((const char **)args)[0], cstr_length(((const char**)args)[0])); + write(fd, ((const char **)args)[0], cstr_length(((const char**)args)[0])); ++args; break; case 'i': for (i = 0; i < 32; ++i) stoi_buf[i] = 0; i64_to_cstr(((u64 *)args)[0], stoi_buf, 32); - __wstdn(stoi_buf, cstr_length(stoi_buf)); + write(fd, stoi_buf, cstr_length(stoi_buf)); ++args; break; case 'u': for (i = 0; i < 32; ++i) stoi_buf[i] = 0; u64_to_cstr(((u64 *)args)[0], stoi_buf, 32); - __wstdn(stoi_buf, cstr_length(stoi_buf)); + write(fd, stoi_buf, cstr_length(stoi_buf)); ++args; break; case 'S': @@ -71,7 +83,7 @@ void wstdf__(const char *buf, const void **args) } if (buf - start > 0) - __wstdn(start, buf - start); + write(fd, start, buf - start); } #ifdef IO_LIB_UNIT_TEST diff --git a/lib/io/io.h b/lib/io/io.h index 06cc541..c373cd0 100644 --- a/lib/io/io.h +++ b/lib/io/io.h @@ -5,13 +5,20 @@ void wstd(const char *buf); void rstd(char *buf, unsigned long count); +void wf(unsigned int fd, char *buf); void wstdf__(const char *buf, const void **args); +void wff__(unsigned int fd, const char *buf, const void **args); #define wstdf(buf, ...) { \ const void *__wstdf__args__[] = { __VA_ARGS__ }; \ wstdf__(buf, __wstdf__args__); \ } +#define wff(fd, buf, ...) { \ + const void *__wstdf__args__[] = { __VA_ARGS__ }; \ + wff__(fd, buf, __wstdf__args__); \ +} + #endif diff --git a/lib/io/test b/lib/io/test new file mode 100755 index 0000000..ce7db41 Binary files /dev/null and b/lib/io/test differ -- cgit v1.2.3-70-g09d2