From 1ac44c03b765f3b9fea794bd5e0da64c2abba30b Mon Sep 17 00:00:00 2001 From: Mid Favila Date: Tue, 23 Nov 2021 12:21:16 -0400 Subject: [PATCH] Added LOG. Added true implementation. Added skeleton for wc. --- LOG | 1 + TODO | 3 +-- doc/wc.1 | 34 +++++++++++++++++++++++++ src/common.h | 1 + src/truefalse.c | 9 +++++++ src/wc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 LOG create mode 100644 doc/wc.1 create mode 100644 src/truefalse.c create mode 100644 src/wc.c diff --git a/LOG b/LOG new file mode 100644 index 0000000..787be80 --- /dev/null +++ b/LOG @@ -0,0 +1 @@ +2021/11/23 - Added true and false, as well as a skeleton for wc. Created LOG. \ No newline at end of file diff --git a/TODO b/TODO index 00e796a..532f5e5 100644 --- a/TODO +++ b/TODO @@ -79,13 +79,12 @@ Write the following utilities: touch tput tr - true tsort uname uncompress(?) unexpand uniq - wc + wc [in progress] who write(?) xargs diff --git a/doc/wc.1 b/doc/wc.1 new file mode 100644 index 0000000..2f603f5 --- /dev/null +++ b/doc/wc.1 @@ -0,0 +1,34 @@ +.TH wc 1 2021-11-21 mp-utils Userland + +.SH NAME +wc \- print to stdout forever +.PP +.SH SYNOPSIS +.PP +Print the provided string to stdout forever. +.SH DESCRIPTION +.PP +Yes is a standard Unix tool that accepts input from the user and prints it to stdout repeatedly, or y when no input is provided. +.SH OPTIONS +.PP +This implementation of wc accepts no arguments. +.SH ENVIRONMENT +This implementation of wc requires a C89 compiler. +.SH FILES +/usr/src/mp-utils/src/wc.c +.SH CONFORMING TO +.PP +.SM +POSIX +2017, +.SM +SUS +3 +.SH NOTES +.PP +None. +.SH BUGS +.PP +None known. +.SH SEE ALSO +wc(1p) \ No newline at end of file diff --git a/src/common.h b/src/common.h index d8fd0e4..8747a98 100644 --- a/src/common.h +++ b/src/common.h @@ -1,3 +1,4 @@ #include #include #include +#include diff --git a/src/truefalse.c b/src/truefalse.c new file mode 100644 index 0000000..dfaefc9 --- /dev/null +++ b/src/truefalse.c @@ -0,0 +1,9 @@ +#include "common.h" + +int main(int argc, char **argv) + { + if(!strcmp(argv[0], "true")) + return 0; + else + return 1; + } diff --git a/src/wc.c b/src/wc.c new file mode 100644 index 0000000..4bf16e4 --- /dev/null +++ b/src/wc.c @@ -0,0 +1,67 @@ +#include "common.h" + +enum { + LINES, + WORDS, + BYTES + }; + +int* count_values(FILE *fp) + { + static int count[3] = {0}; + char in_word, c; + in_word = c = 0; + + while((c = getc(fp)) != EOF) + if(in_word) + switch(c) + { + case '\n': + count[LINES]++, count[BYTES]++; + in_word = 0; + break; + + case ' ': + in_word = 0; + count[BYTES]++; + break; + + case '\t': + in_word = 0; + count[BYTES]++; + break; + + default: + count[BYTES]++; + break; + } + else + switch(c) + { + case '\n': + count[LINES]++, count[BYTES]++; + break; + + case ' ': + count[BYTES]++; + break; + + case '\t': + count[BYTES]++; + break; + + default: + count[WORDS]++, count[BYTES]++; + in_word = 1; + break; + } + + return count; + } + +int main(int argc, char **argv) + { + return 0; + + err: + }