Mid's Portable Utilities are a set of (hopefully) POSIX and SUS-compliant Unix userland tools that are portable across many Unices.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
mp-utils/src/wc.c

67 lines
862 B

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