Browse Source

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

master
Mid Favila 2 months ago
parent
commit
1ac44c03b7
  1. 1
      LOG
  2. 3
      TODO
  3. 34
      doc/wc.1
  4. 1
      src/common.h
  5. 9
      src/truefalse.c
  6. 67
      src/wc.c

1
LOG

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

3
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

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

1
src/common.h

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

9
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;
}

67
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:
}
Loading…
Cancel
Save