From a94b5bcd943ff91c90d04000d6896fdaf5070392 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Fri, 28 Apr 2023 20:32:18 -0400 Subject: added tail and head --- src/shared.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/shared.c') diff --git a/src/shared.c b/src/shared.c index 8d0dcca..240e364 100644 --- a/src/shared.c +++ b/src/shared.c @@ -34,6 +34,7 @@ FILE* get_file_s(const char* path, const char* type) { } FILE* get_file(const char* path, const char* type) { + if (streql("-", path)) return stdin; FILE* file = get_file_s(path, type); if (file == NULL) exit(EXIT_FAILURE); return file; @@ -48,6 +49,30 @@ long int get_number(const char* text) { return n; } +long int get_blkm(const char* text) { + char* end; + long int n = strtol(text, &end, 10); + if (text == end) { + error("error: %s is not a valid bkm", text); + } + if (*end == '\0') return n; + switch (*end) { + case 'K': + case 'k': + return n * 1024; + case 'B': + case 'b': + return n * 512; + case 'M': + case 'm': + return n * 1024 * 1204; + default: + error("error: invalid bkm type %c", *end); + } + // shouldnt get here anyways + return 0; +} + bool streql(const char* a, const char* b) { if (*a != *b) return false; int n = 0; -- cgit v1.2.3-freya