/wc.c (7c05702000203c8061b07e7238dc0b5049b91ca6) (2084 bytes) (mode 100644) (type blob)
/*
Copyright (c) 2019 Matthew Graham
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
void wcout(char *wd, int lines, int words, int bytes, char name[])
{
while (*wd) switch(*wd++) {
case 'l':
printf("%7i", lines);
break;
case 'w':
printf("%7i", words);
break;
case 'c':
printf("%8i", bytes);
break;
}
printf("%12s\n", name);
}
int main(int argc, char *argv[])
{
int character;
int linec=0, wordc=0, bytec=0, i = 1;
int tlinec=0, twordc=0, tbytec=0;
unsigned int spaceflag, lineflag, tabflag;
char *wd = "lwc";
FILE *filep = stdin;
if (argc > 1 && argv[1][0]=='-') {
wd = ++argv[1];
argc--;
argv++;
}
do {
lineflag=1;
if (argc > 1 && (filep = fopen(argv[i], "r"))==NULL) {
fprintf(stderr, "wc: unable to open %s\n", argv[i]);
continue;
}
while ((character = fgetc(filep)) != EOF) {
bytec++;
if (character>='A' && character<='z' && (spaceflag==1||lineflag==1||tabflag==1)) {
wordc++;
spaceflag=0;
lineflag=0;
tabflag=0;
}
switch(character) {
case '\n': linec++;
lineflag=1;
break;
case ' ': spaceflag=1;
break;
case '\t': tabflag=1;
break;
}
} fclose(filep);
if (argc > 2) {
tlinec += linec;
twordc += wordc;
tbytec += bytec;
}
if (argc > 1)
wcout(wd, linec, wordc, bytec, argv[i]);
else
wcout(wd, linec, wordc, bytec, "");
linec = 0;
wordc = 0;
bytec = 0;
} while (++i<argc);
if (argc > 2)
wcout(wd, tlinec, twordc, tbytec, "total");
}
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
35149 |
f288702d2fa16d3cdf0035b15a9fcbc552cd88e7 |
COPYING |
100755 |
blob |
539 |
46ffe64a2d057e0fd677d658f8dd29ce0cfde470 |
INSTALL |
100644 |
blob |
2429 |
d98741b40437761e17e1fa301e70952d8ff98387 |
README |
100755 |
blob |
2450 |
485c68016e02fea586279112654aaddb0acc3def |
c |
100644 |
blob |
4161 |
d3c21fdd338bf33819184988562e3961f7883484 |
clp.c |
100644 |
blob |
807 |
59c452396f94f50dbe567bc19530fd386a52b652 |
echo.c |
100755 |
blob |
695 |
a6ca102f88d4643c962a52dc416f1e7a159962b9 |
exho |
100755 |
blob |
783 |
5a9e33def49890e1fbbb5af04d35a39e078f17dd |
ins |
100644 |
blob |
979 |
89b230aabe515c66e967be21a4d9dff3ac5248da |
nl.l |
100644 |
blob |
1932 |
d59401d46002608d4563dd4afdac5ff394ed8df4 |
sc.c |
100644 |
blob |
1127 |
c105483de17bc09fe24e3b0fecfbce024fa380b0 |
spng.c |
100644 |
blob |
1178 |
1433a0105fd7a07e7ede04214e26552241f36b64 |
tee.c |
100644 |
blob |
2084 |
7c05702000203c8061b07e7238dc0b5049b91ca6 |
wc.c |
100644 |
blob |
796 |
7359238b347bc985adc97e744cde0f8aa2ee6fbc |
yes.c |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/spicylord/clutils
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/spicylord/clutils
Clone this repository using git:
git clone git://git.rocketgit.com/user/spicylord/clutils
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main