Research V5 development
authorJoe Ossanna <jfo@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
committerJoe Ossanna <jfo@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
Work on file usr/source/s2/wc.c

Synthesized-from: v5

usr/source/s2/wc.c [new file with mode: 0644]

diff --git a/usr/source/s2/wc.c b/usr/source/s2/wc.c
new file mode 100644 (file)
index 0000000..b18cb81
--- /dev/null
@@ -0,0 +1,53 @@
+/* wc line and word count */
+
+char buf[518];
+int wordct[2];
+int linect[2];
+
+main(argc,argv)
+char **argv;
+{
+       int i;
+       register int c;
+       int token;
+
+       i = 1;
+       do {
+               if(argc<=1) buf[0] = 0;
+               else if(fopen(argv[i],buf)<0) {
+                       diag(argv[i]);
+                       diag(": cannot open\n");
+                       continue;
+               }
+               linect[0] = linect[1] = 0;
+               wordct[0] = wordct[1] = 0;
+               token = 0;
+               while((c=getc(buf))>=0) {
+                       if(' '<c&&c<0177) {
+                               if(!token++) {
+                                       if(++wordct[0]==0)
+                                               wordct[1]++;
+                               }
+                       } else {
+                               if(c=='\n') {
+                                       if(++linect[0]==0)
+                                               linect[1]++;
+                               }
+                               else if(c!=' '&&c!='\t')
+                                       continue;
+                               token = 0;
+                       }
+               }
+               printf("%7s ",locv(linect[1],linect[0]));
+               printf("%7s ",locv(wordct[1],wordct[0]));
+               printf("%s\n", argc<=1?"":argv[i]);
+               close(buf[0]);
+       } while(++i<argc);
+}
+
+diag(s)
+char *s;
+{
+       while(*s)
+               write(2,s++,1);
+}