Added LOG. Added true implementation. Added skeleton for wc.

This commit is contained in:
Mid Favila 2021-11-23 12:21:16 -04:00
parent e3bc4a02e2
commit 1ac44c03b7
6 changed files with 113 additions and 2 deletions

1
LOG Normal file
View File

@ -0,0 +1 @@
2021/11/23 - Added true and false, as well as a skeleton for wc. Created LOG.

3
TODO
View File

@ -79,13 +79,12 @@ Write the following utilities:
touch
tput
tr
true
tsort
uname
uncompress(?)
unexpand
uniq
wc
wc [in progress]
who
write(?)
xargs

34
doc/wc.1 Normal file
View File

@ -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)

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

9
src/truefalse.c Normal file
View File

@ -0,0 +1,9 @@
#include "common.h"
int main(int argc, char **argv)
{
if(!strcmp(argv[0], "true"))
return 0;
else
return 1;
}

67
src/wc.c Normal file
View File

@ -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:
}