/* word count.c by Michael Hanson */
/* you may use this, but not for profit, and give me credit */ 
/* word count counts words in /* word count counts words in standard input */
/* switches are -l (lines) -w (words) -c (chars) */

#include "stdio.h"
#define BLANK ' '
#define NEWLINE '\n'
#define TAB '\t'
#define CR '\r'
#define SWITC '-'
#define SWIT2 '/'

main(argc,argv)
int argc;
char *argv[];
{
	int c;
	int wc,cc,lc,inword;

	if(ver() < 0x200){
		error("wrong DOS version",1);
#asm
	db 'by Michael Hanson v1.0',1ah
#	
	}
	cc=lc=wc=0;
	inword=NO;
	while((c=getc(STDIN)) != EOF)
		if (c==NEWLINE){
			inword=NO;
			lc++;
			}
		else if (c==CR)
			inword=NO;
		else{
			cc++;
			if (c==BLANK || c==TAB )
				inword = NO;
			else if(inword == NO) {
				inword=YES;
				wc++;
				}
			}
/* handle switches at input */

	if (argc == 1){
		printf("%d characters \n",cc);
		printf("%d words \n",wc);
		printf("%d lines \n",lc);
	}
	else if((argv[1])[0] != SWITC && (argv[1])[0] != SWIT2 ){
			fprintf(STDERR,"Usage: wc [-[l][w][c]] .\n");
			printf("%d characters \n",cc);
			printf("%d words \n",wc);
			printf("%d lines \n",lc);
		}
	else {
		if(index(argv[1],'c') > -1 || index(argv[1],'C') > -1)
			printf("%d characters \n",cc);
	    if(index(argv[1],'w') > -1 || index(argv[1],'W') > -1)
			printf("%d words \n",wc);
		if(index(argv[1],'l') > -1 || index(argv[1],'L') > -1)
			printf("%d lines \n",lc);
		}
}

#include "filps.c"
#include "version.c"
#include "err.c"
#include "index.c"
