From 55c96d623dbc0043203cbdaf4dad4192efdc8e65 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 16:15:11 -0500 Subject: [PATCH 01/18] implemented cksum --- src/cksum/Makefile | 5 +++++ src/cksum/cksum | Bin 0 -> 15800 bytes src/cksum/cksum.1 | 1 + src/cksum/cksum.c | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 src/cksum/Makefile create mode 100755 src/cksum/cksum create mode 100644 src/cksum/cksum.1 create mode 100644 src/cksum/cksum.c diff --git a/src/cksum/Makefile b/src/cksum/Makefile new file mode 100644 index 0000000..f84ebce --- /dev/null +++ b/src/cksum/Makefile @@ -0,0 +1,5 @@ +OUT := cksum + +SRC := cksum.c + +include ../shared.mk diff --git a/src/cksum/cksum b/src/cksum/cksum new file mode 100755 index 0000000000000000000000000000000000000000..60f4b965d759eeaf9d16a4a0aa81533137b4beb3 GIT binary patch literal 15800 zcmeHOYj7LY6~0m|VnZxB0T)AnXdq^iwpOgzaUBvjk{`($oJWn5@Cu7!$+n6u8EKU| z8K!vZn4&SJ=?^F^bfD88X_@IvTRJI)c90!UY==S}(xK__qaLPExx7rFm}j=%*}X@W z7YCSj+UbuyGrQkC-#zEvbI;yg-IcEHYHHc)bT|ad67f|*TK|P66Oa|PHL?H*h+0vM z^A+N9aUS#ngEQ*`CZN`oGtPxrDETEo@++glB6yie3r3ERko?XiXDA>DqbMQ+q4Mj5$2*PoZ1AztI0!!j~}Fy{MFC{qYvF&Vzg^O=#cMPpthm~w1ta(O zHTcO(D=j`9_%gT3{?2tBDrNo|Wm?6$?&$uS>UG`WitcDE)mPD1TT@X}?Mude>y3^n zu1XvgW4n;65_ZG(y5LQ(m$^(hvAAvjBf(xU4*AmFJ^z>9QGHS!=7SYtewGgv~v~s zD{)wb=E7p_h)7>l6P*#QU3A2IBQc?>xRUK^QVS(CwI>uMroAtuc0^;L?&zV2=uJdp zT8AJjy1X@FTT63&gSy_g-nSuFuBsMlbK7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00001 diff --git a/src/cksum/cksum.1 b/src/cksum/cksum.1 new file mode 100644 index 0000000..fca0bf6 --- /dev/null +++ b/src/cksum/cksum.1 @@ -0,0 +1 @@ +\" TODO \ No newline at end of file diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c new file mode 100644 index 0000000..79c4500 --- /dev/null +++ b/src/cksum/cksum.c @@ -0,0 +1,26 @@ +#include +#include + +#define NAME "cksum (canoutils)" +#define VERSION "0.0.1" +#define AUTHOR "cospplredman" + +#include"../version_info.h" + +#define X(a,...) for(a)for(r=(r<<8)^(e&0xff)^__VA_ARGS__,e=0,i=31;i>23;i--)if(r&(1<>(32-i)),e^=q<<(i-24); + +uint32_t q=0x04c11db7,r,e;d,i=1,t,j,k,f=2;main(c,v)char**v;{ + if(c<2)exit(1); + for(;++k=0;t++,d)X(j=t;j;,(j&0xff),j>>=8)X(j=3;j--;,0) + if(printf("%u %d %s\n",~((r<<8)|(e&0xff)),t,v[k])<0)exit(1); + r=e=t=0; + } +} From 80d78b108177747d92bdab765aa9aaf87a91e050 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 17:50:36 -0500 Subject: [PATCH 02/18] re-implemented cksum --- src/cksum/cksum.c | 103 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 79c4500..7a135d5 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -1,26 +1,101 @@ #include #include +#include #define NAME "cksum (canoutils)" #define VERSION "0.0.1" #define AUTHOR "cospplredman" -#include"../version_info.h" +#include "../version_info.h" +#include "../getopt.h" -#define X(a,...) for(a)for(r=(r<<8)^(e&0xff)^__VA_ARGS__,e=0,i=31;i>23;i--)if(r&(1<>(32-i)),e^=q<<(i-24); +static const char usage[] = { + " -v version information\n" +}; -uint32_t q=0x04c11db7,r,e;d,i=1,t,j,k,f=2;main(c,v)char**v;{ - if(c<2)exit(1); - for(;++k 23; i--){ + if(remainder & (1 << i)){ + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + length++; + } + + *octets = length; + + /* calculate crc of file contents + length of files in bytes */ + while(length){ + cur_char = (length & 0xff); + length >>= 8; + + remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; + difference = 0; + for(int i = 31; i > 23; i--){ + if(remainder & (1 << i)){ + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + } + + + /* work through the remaining 3 bytes */ + for(int j = 0; j < 3; j++){ + remainder = (remainder << 8) ^ (difference & 0xff); + difference = 0; + for(int i = 31; i > 23; i--){ + if(remainder & (1 << i)){ + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } } - FILE*f=fopen(v[k],"r"); - if(f==NULL)exit(1); - X(;(d=getc(f))>=0;t++,d)X(j=t;j;,(j&0xff),j>>=8)X(j=3;j--;,0) - if(printf("%u %d %s\n",~((r<<8)|(e&0xff)),t,v[k])<0)exit(1); - r=e=t=0; + } + + return ~((remainder<<8)|(difference&0xff)); + +} + +int main(int argc, char ** argv) { + if(argc<2){ + printf("%s\n", usage); + exit(1); + } + + int opt; + while((opt = getopt(argc, argv, "v")) != -1){ + switch(opt){ + case 'v': + print_version(); + return EXIT_SUCCESS; + break; + } + } + + int index = optind; + for(;index < argc; index++){ + FILE*file=fopen(argv[index],"r"); + + if(file==NULL) + return EXIT_FAILURE; + + size_t octets; + uint32_t crc = crc32(file, &octets); + + printf("%u %lu %s\n", crc, octets, argv[index]); } } From 9c39b39a0e7771099a769d2ff2d41f4de8dff9f2 Mon Sep 17 00:00:00 2001 From: cospplredman <62368514+cospplredman@users.noreply.github.com> Date: Sun, 21 Apr 2024 18:21:47 -0500 Subject: [PATCH 03/18] Delete src/cksum/cksum bro i swear i did git rm --- src/cksum/cksum | Bin 15800 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 src/cksum/cksum diff --git a/src/cksum/cksum b/src/cksum/cksum deleted file mode 100755 index 60f4b965d759eeaf9d16a4a0aa81533137b4beb3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15800 zcmeHOYj7LY6~0m|VnZxB0T)AnXdq^iwpOgzaUBvjk{`($oJWn5@Cu7!$+n6u8EKU| z8K!vZn4&SJ=?^F^bfD88X_@IvTRJI)c90!UY==S}(xK__qaLPExx7rFm}j=%*}X@W z7YCSj+UbuyGrQkC-#zEvbI;yg-IcEHYHHc)bT|ad67f|*TK|P66Oa|PHL?H*h+0vM z^A+N9aUS#ngEQ*`CZN`oGtPxrDETEo@++glB6yie3r3ERko?XiXDA>DqbMQ+q4Mj5$2*PoZ1AztI0!!j~}Fy{MFC{qYvF&Vzg^O=#cMPpthm~w1ta(O zHTcO(D=j`9_%gT3{?2tBDrNo|Wm?6$?&$uS>UG`WitcDE)mPD1TT@X}?Mude>y3^n zu1XvgW4n;65_ZG(y5LQ(m$^(hvAAvjBf(xU4*AmFJ^z>9QGHS!=7SYtewGgv~v~s zD{)wb=E7p_h)7>l6P*#QU3A2IBQc?>xRUK^QVS(CwI>uMroAtuc0^;L?&zV2=uJdp zT8AJjy1X@FTT63&gSy_g-nSuFuBsMlbK7<`97#kvqe(52XxrY<9gjuYLi@WTXtJ{> z9+RD@rs<-Fh#E5iSDg+%)7Tu~Hv)OyrY?;Z(d=lD+^@d-0EX-oJINTr&lA3nducL3 z&dBEl^IplX2^iJ6`=0g87L%uZ(zRik$m8WLVpL7#@%i)cOdh|K8v#z|@f?#;9Waf^ zRz7+RqA-s)p4Xl*cq@hU}wP2fSmz519k>JBLi=HuJ}M1 zc&$(wa*eDLLK)0xPJK!l7%Mz(cEyLwUJwgP3 z=Y@}+NxQy}nvLV0`#NBEWT^NMROLZsX!G&GNo}L&*wXaqz~3uU#hzn(9aJbl!8wpM zm~D=M>;Yo7IR~Hj9NvN!1~Z<+UjeqHU&(GkK+WkB7_{eb6k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v)3n)d<(=|^z+{*WHFxhbUH+-u*Prh{av2hKhBMn z8}=9H<_GheP*`lg@D1R-Y?Ox&8+@7Y2J%Q0r*JG6mxvb0%V{k%$v0Z~HVl~T6$?-M zripK}@O|J*M48wud8mfmh4TuhNAP_rX)%bxa@bb}Oorq6Hq^z&OS>4Tee1Z6g7@OE z$}tejon?ZrKi3~8o^~sHO@{k@9%>23bwj}9`TQsfD}+1uzY^m+9&lAMKf3}@Al%LX z$~3O(0I~D@pHQZ}1p>s*^M6K}>}vzW&hsy#Oz~Lr`8V(sPp_Qk#&<^GUNd-{EOHk5 zV)^t?{KyZ-!)`0Vds)fD4dAcL)48|{{0b+Y&X)Ub5Akf2kH$B2zILHD-nb*Uy}1E< z&~YcKO^Uj;HMqS=RT^7`x~*kreXvE{xpnLHO>Jshu)d`UyVI>Z;sdSQ!o)5v;co+xM6dA0;#$Pl8B6(k6ZpqLLOYm8?N3GV7m{dLQo;J>3N6$r4D+r~ zvP<~F2V>~ML@i;~$S+zKC@Sg_k?s&V$Wm{&CVWQRJ}uIRvT;#-iMVlze334-BN6I} zs9jhvp=uT z7o;-hk zA39S362f+-Hm@`PDk^C1aR0o%&He9_1_z<}Pr`nD9p3>*ChX7uNaj>Z3UlnoI)&Kwi From 815a831571c5601fd7523888e93f262f72eb0d8d Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 18:35:01 -0500 Subject: [PATCH 04/18] formatting fix --- src/cksum/cksum.c | 172 ++++++++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 88 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 7a135d5..3014c8e 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -1,101 +1,97 @@ -#include -#include -#include +#include +#include +#include #define NAME "cksum (canoutils)" #define VERSION "0.0.1" #define AUTHOR "cospplredman" -#include "../version_info.h" #include "../getopt.h" +#include "../version_info.h" -static const char usage[] = { - " -v version information\n" -}; +static const char usage[] = {" -v version information\n"}; static const uint32_t crc32_ = 0x04c11db7; -uint32_t crc32(FILE *file, size_t *octets){ - uint32_t remainder = 0; - uint8_t difference = 0; - - size_t length = 0; - - - /* calculate crc of file contents */ - int cur_char; - while((cur_char = getc(file)) != EOF){ - remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; - difference = 0; - for(int i = 31; i > 23; i--){ - if(remainder & (1 << i)){ - remainder ^= (1 << i) | (crc32_ >> (32 - i)); - difference ^= crc32_ << (i - 24); - } - } - length++; - } - - *octets = length; - - /* calculate crc of file contents + length of files in bytes */ - while(length){ - cur_char = (length & 0xff); - length >>= 8; - - remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; - difference = 0; - for(int i = 31; i > 23; i--){ - if(remainder & (1 << i)){ - remainder ^= (1 << i) | (crc32_ >> (32 - i)); - difference ^= crc32_ << (i - 24); - } - } - } - - - /* work through the remaining 3 bytes */ - for(int j = 0; j < 3; j++){ - remainder = (remainder << 8) ^ (difference & 0xff); - difference = 0; - for(int i = 31; i > 23; i--){ - if(remainder & (1 << i)){ - remainder ^= (1 << i) | (crc32_ >> (32 - i)); - difference ^= crc32_ << (i - 24); - } - } - } - - return ~((remainder<<8)|(difference&0xff)); - +uint32_t crc32(FILE *file, size_t *octets) { + uint32_t remainder = 0; + uint8_t difference = 0; + + size_t length = 0; + + /* calculate crc of file contents */ + int cur_char; + while ((cur_char = getc(file)) != EOF) { + remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; + difference = 0; + for (int i = 31; i > 23; i--) { + if (remainder & (1 << i)) { + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + length++; + } + + *octets = length; + + /* calculate crc of file contents + length of files in bytes */ + while (length) { + cur_char = (length & 0xff); + length >>= 8; + + remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; + difference = 0; + for (int i = 31; i > 23; i--) { + if (remainder & (1 << i)) { + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + } + + /* work through the remaining 3 bytes */ + for (int j = 0; j < 3; j++) { + remainder = (remainder << 8) ^ (difference & 0xff); + difference = 0; + for (int i = 31; i > 23; i--) { + if (remainder & (1 << i)) { + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + } + + return ~((remainder << 8) | (difference & 0xff)); } -int main(int argc, char ** argv) { - if(argc<2){ - printf("%s\n", usage); - exit(1); - } - - int opt; - while((opt = getopt(argc, argv, "v")) != -1){ - switch(opt){ - case 'v': - print_version(); - return EXIT_SUCCESS; - break; - } - } - - int index = optind; - for(;index < argc; index++){ - FILE*file=fopen(argv[index],"r"); - - if(file==NULL) - return EXIT_FAILURE; - - size_t octets; - uint32_t crc = crc32(file, &octets); - - printf("%u %lu %s\n", crc, octets, argv[index]); - } +int main(int argc, char **argv) { + if (argc < 2) { + printf("%s\n", usage); + exit(1); + } + + int opt; + while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': + print_version(); + return EXIT_SUCCESS; + break; + } + } + + int index = optind; + for (; index < argc; index++) { + FILE *file = fopen(argv[index], "r"); + + if (file == NULL) + return EXIT_FAILURE; + + size_t octets; + uint32_t crc = crc32(file, &octets); + fclose(file); + + printf("%u %lu %s\n", crc, octets, argv[index]); + } } From 01ec9b945b8f7b4a7dd5d6a87d349da214e46208 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 18:50:58 -0500 Subject: [PATCH 05/18] updated makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 983cbfe..98f764e 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ BINS += mv BINS += chmod BINS += sh BINS += sleep +BINS += cksum BINARIES := $(foreach b, $(BINS), src/$b/$b) BINS-COPY := $(foreach b, $(BINS), bin/$b) From 1f1b0b36a24e8838c3539e6c09f8da4c52a0b2ac Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 19:57:19 -0500 Subject: [PATCH 06/18] updated include paths --- src/cksum/cksum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 3014c8e..f3f1333 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -6,8 +6,8 @@ #define VERSION "0.0.1" #define AUTHOR "cospplredman" -#include "../getopt.h" -#include "../version_info.h" +#include "getopt.h" +#include "version_info.h" static const char usage[] = {" -v version information\n"}; From cb008b31e70772e2bda229f426f3a1cf26af20ce Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 16:15:11 -0500 Subject: [PATCH 07/18] implemented cksum --- src/cksum/Makefile | 5 +++++ src/cksum/cksum | Bin 0 -> 15800 bytes src/cksum/cksum.1 | 1 + src/cksum/cksum.c | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 src/cksum/Makefile create mode 100755 src/cksum/cksum create mode 100644 src/cksum/cksum.1 create mode 100644 src/cksum/cksum.c diff --git a/src/cksum/Makefile b/src/cksum/Makefile new file mode 100644 index 0000000..f84ebce --- /dev/null +++ b/src/cksum/Makefile @@ -0,0 +1,5 @@ +OUT := cksum + +SRC := cksum.c + +include ../shared.mk diff --git a/src/cksum/cksum b/src/cksum/cksum new file mode 100755 index 0000000000000000000000000000000000000000..60f4b965d759eeaf9d16a4a0aa81533137b4beb3 GIT binary patch literal 15800 zcmeHOYj7LY6~0m|VnZxB0T)AnXdq^iwpOgzaUBvjk{`($oJWn5@Cu7!$+n6u8EKU| z8K!vZn4&SJ=?^F^bfD88X_@IvTRJI)c90!UY==S}(xK__qaLPExx7rFm}j=%*}X@W z7YCSj+UbuyGrQkC-#zEvbI;yg-IcEHYHHc)bT|ad67f|*TK|P66Oa|PHL?H*h+0vM z^A+N9aUS#ngEQ*`CZN`oGtPxrDETEo@++glB6yie3r3ERko?XiXDA>DqbMQ+q4Mj5$2*PoZ1AztI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HMqS=RT^7`x~*kreXvE{xpnLHO>Jshu)d`UyVI>Z;sdSQ!o)5v;co+xM6dA0;#$Pl8B6(k6ZpqLLOYm8?N3GV7m{dLQo;J>3N6$r4D+r~ zvP<~F2V>~ML@i;~$S+zKC@Sg_k?s&V$Wm{&CVWQRJ}uIRvT;#-iMVlze334-BN6I} zs9jhvp=uT z7o;-hk zA39S362f+-Hm@`PDk^C1aR0o%&He9_1_z<}Pr`nD9p3>*ChX7uNaj>Z3UlnoI)&Kwi literal 0 HcmV?d00001 diff --git a/src/cksum/cksum.1 b/src/cksum/cksum.1 new file mode 100644 index 0000000..fca0bf6 --- /dev/null +++ b/src/cksum/cksum.1 @@ -0,0 +1 @@ +\" TODO \ No newline at end of file diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c new file mode 100644 index 0000000..79c4500 --- /dev/null +++ b/src/cksum/cksum.c @@ -0,0 +1,26 @@ +#include +#include + +#define NAME "cksum (canoutils)" +#define VERSION "0.0.1" +#define AUTHOR "cospplredman" + +#include"../version_info.h" + +#define X(a,...) for(a)for(r=(r<<8)^(e&0xff)^__VA_ARGS__,e=0,i=31;i>23;i--)if(r&(1<>(32-i)),e^=q<<(i-24); + +uint32_t q=0x04c11db7,r,e;d,i=1,t,j,k,f=2;main(c,v)char**v;{ + if(c<2)exit(1); + for(;++k=0;t++,d)X(j=t;j;,(j&0xff),j>>=8)X(j=3;j--;,0) + if(printf("%u %d %s\n",~((r<<8)|(e&0xff)),t,v[k])<0)exit(1); + r=e=t=0; + } +} From e008a9311a2f781578e66ec79dc4bd6e2b1f814c Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 17:50:36 -0500 Subject: [PATCH 08/18] re-implemented cksum --- src/cksum/cksum.c | 103 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 79c4500..7a135d5 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -1,26 +1,101 @@ #include #include +#include #define NAME "cksum (canoutils)" #define VERSION "0.0.1" #define AUTHOR "cospplredman" -#include"../version_info.h" +#include "../version_info.h" +#include "../getopt.h" -#define X(a,...) for(a)for(r=(r<<8)^(e&0xff)^__VA_ARGS__,e=0,i=31;i>23;i--)if(r&(1<>(32-i)),e^=q<<(i-24); +static const char usage[] = { + " -v version information\n" +}; -uint32_t q=0x04c11db7,r,e;d,i=1,t,j,k,f=2;main(c,v)char**v;{ - if(c<2)exit(1); - for(;++k 23; i--){ + if(remainder & (1 << i)){ + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + length++; + } + + *octets = length; + + /* calculate crc of file contents + length of files in bytes */ + while(length){ + cur_char = (length & 0xff); + length >>= 8; + + remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; + difference = 0; + for(int i = 31; i > 23; i--){ + if(remainder & (1 << i)){ + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + } + + + /* work through the remaining 3 bytes */ + for(int j = 0; j < 3; j++){ + remainder = (remainder << 8) ^ (difference & 0xff); + difference = 0; + for(int i = 31; i > 23; i--){ + if(remainder & (1 << i)){ + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } } - FILE*f=fopen(v[k],"r"); - if(f==NULL)exit(1); - X(;(d=getc(f))>=0;t++,d)X(j=t;j;,(j&0xff),j>>=8)X(j=3;j--;,0) - if(printf("%u %d %s\n",~((r<<8)|(e&0xff)),t,v[k])<0)exit(1); - r=e=t=0; + } + + return ~((remainder<<8)|(difference&0xff)); + +} + +int main(int argc, char ** argv) { + if(argc<2){ + printf("%s\n", usage); + exit(1); + } + + int opt; + while((opt = getopt(argc, argv, "v")) != -1){ + switch(opt){ + case 'v': + print_version(); + return EXIT_SUCCESS; + break; + } + } + + int index = optind; + for(;index < argc; index++){ + FILE*file=fopen(argv[index],"r"); + + if(file==NULL) + return EXIT_FAILURE; + + size_t octets; + uint32_t crc = crc32(file, &octets); + + printf("%u %lu %s\n", crc, octets, argv[index]); } } From 7217e109c807bdaae8137e224fb4c922c6744a09 Mon Sep 17 00:00:00 2001 From: cospplredman <62368514+cospplredman@users.noreply.github.com> Date: Sun, 21 Apr 2024 18:21:47 -0500 Subject: [PATCH 09/18] Delete src/cksum/cksum bro i swear i did git rm --- src/cksum/cksum | Bin 15800 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100755 src/cksum/cksum diff --git a/src/cksum/cksum b/src/cksum/cksum deleted file mode 100755 index 60f4b965d759eeaf9d16a4a0aa81533137b4beb3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15800 zcmeHOYj7LY6~0m|VnZxB0T)AnXdq^iwpOgzaUBvjk{`($oJWn5@Cu7!$+n6u8EKU| z8K!vZn4&SJ=?^F^bfD88X_@IvTRJI)c90!UY==S}(xK__qaLPExx7rFm}j=%*}X@W z7YCSj+UbuyGrQkC-#zEvbI;yg-IcEHYHHc)bT|ad67f|*TK|P66Oa|PHL?H*h+0vM z^A+N9aUS#ngEQ*`CZN`oGtPxrDETEo@++glB6yie3r3ERko?XiXDA>DqbMQ+q4Mj5$2*PoZ1AztI0!!j~}Fy{MFC{qYvF&Vzg^O=#cMPpthm~w1ta(O zHTcO(D=j`9_%gT3{?2tBDrNo|Wm?6$?&$uS>UG`WitcDE)mPD1TT@X}?Mude>y3^n zu1XvgW4n;65_ZG(y5LQ(m$^(hvAAvjBf(xU4*AmFJ^z>9QGHS!=7SYtewGgv~v~s zD{)wb=E7p_h)7>l6P*#QU3A2IBQc?>xRUK^QVS(CwI>uMroAtuc0^;L?&zV2=uJdp zT8AJjy1X@FTT63&gSy_g-nSuFuBsMlbK7<`97#kvqe(52XxrY<9gjuYLi@WTXtJ{> z9+RD@rs<-Fh#E5iSDg+%)7Tu~Hv)OyrY?;Z(d=lD+^@d-0EX-oJINTr&lA3nducL3 z&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 172 ++++++++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 88 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 7a135d5..3014c8e 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -1,101 +1,97 @@ -#include -#include -#include +#include +#include +#include #define NAME "cksum (canoutils)" #define VERSION "0.0.1" #define AUTHOR "cospplredman" -#include "../version_info.h" #include "../getopt.h" +#include "../version_info.h" -static const char usage[] = { - " -v version information\n" -}; +static const char usage[] = {" -v version information\n"}; static const uint32_t crc32_ = 0x04c11db7; -uint32_t crc32(FILE *file, size_t *octets){ - uint32_t remainder = 0; - uint8_t difference = 0; - - size_t length = 0; - - - /* calculate crc of file contents */ - int cur_char; - while((cur_char = getc(file)) != EOF){ - remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; - difference = 0; - for(int i = 31; i > 23; i--){ - if(remainder & (1 << i)){ - remainder ^= (1 << i) | (crc32_ >> (32 - i)); - difference ^= crc32_ << (i - 24); - } - } - length++; - } - - *octets = length; - - /* calculate crc of file contents + length of files in bytes */ - while(length){ - cur_char = (length & 0xff); - length >>= 8; - - remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; - difference = 0; - for(int i = 31; i > 23; i--){ - if(remainder & (1 << i)){ - remainder ^= (1 << i) | (crc32_ >> (32 - i)); - difference ^= crc32_ << (i - 24); - } - } - } - - - /* work through the remaining 3 bytes */ - for(int j = 0; j < 3; j++){ - remainder = (remainder << 8) ^ (difference & 0xff); - difference = 0; - for(int i = 31; i > 23; i--){ - if(remainder & (1 << i)){ - remainder ^= (1 << i) | (crc32_ >> (32 - i)); - difference ^= crc32_ << (i - 24); - } - } - } - - return ~((remainder<<8)|(difference&0xff)); - +uint32_t crc32(FILE *file, size_t *octets) { + uint32_t remainder = 0; + uint8_t difference = 0; + + size_t length = 0; + + /* calculate crc of file contents */ + int cur_char; + while ((cur_char = getc(file)) != EOF) { + remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; + difference = 0; + for (int i = 31; i > 23; i--) { + if (remainder & (1 << i)) { + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + length++; + } + + *octets = length; + + /* calculate crc of file contents + length of files in bytes */ + while (length) { + cur_char = (length & 0xff); + length >>= 8; + + remainder = (remainder << 8) ^ (difference & 0xff) ^ cur_char; + difference = 0; + for (int i = 31; i > 23; i--) { + if (remainder & (1 << i)) { + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + } + + /* work through the remaining 3 bytes */ + for (int j = 0; j < 3; j++) { + remainder = (remainder << 8) ^ (difference & 0xff); + difference = 0; + for (int i = 31; i > 23; i--) { + if (remainder & (1 << i)) { + remainder ^= (1 << i) | (crc32_ >> (32 - i)); + difference ^= crc32_ << (i - 24); + } + } + } + + return ~((remainder << 8) | (difference & 0xff)); } -int main(int argc, char ** argv) { - if(argc<2){ - printf("%s\n", usage); - exit(1); - } - - int opt; - while((opt = getopt(argc, argv, "v")) != -1){ - switch(opt){ - case 'v': - print_version(); - return EXIT_SUCCESS; - break; - } - } - - int index = optind; - for(;index < argc; index++){ - FILE*file=fopen(argv[index],"r"); - - if(file==NULL) - return EXIT_FAILURE; - - size_t octets; - uint32_t crc = crc32(file, &octets); - - printf("%u %lu %s\n", crc, octets, argv[index]); - } +int main(int argc, char **argv) { + if (argc < 2) { + printf("%s\n", usage); + exit(1); + } + + int opt; + while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': + print_version(); + return EXIT_SUCCESS; + break; + } + } + + int index = optind; + for (; index < argc; index++) { + FILE *file = fopen(argv[index], "r"); + + if (file == NULL) + return EXIT_FAILURE; + + size_t octets; + uint32_t crc = crc32(file, &octets); + fclose(file); + + printf("%u %lu %s\n", crc, octets, argv[index]); + } } From b078275193aebb105425464a895843c98f87b200 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 18:50:58 -0500 Subject: [PATCH 11/18] updated makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 983cbfe..98f764e 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ BINS += mv BINS += chmod BINS += sh BINS += sleep +BINS += cksum BINARIES := $(foreach b, $(BINS), src/$b/$b) BINS-COPY := $(foreach b, $(BINS), bin/$b) From 0c1afeb9fa406e0cda7def8f54143ab015f3b395 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Sun, 21 Apr 2024 19:57:19 -0500 Subject: [PATCH 12/18] updated include paths --- src/cksum/cksum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 3014c8e..f3f1333 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -6,8 +6,8 @@ #define VERSION "0.0.1" #define AUTHOR "cospplredman" -#include "../getopt.h" -#include "../version_info.h" +#include "getopt.h" +#include "version_info.h" static const char usage[] = {" -v version information\n"}; From 62048505b38bf9e2d8ea6dc87d818d1238f3e14d Mon Sep 17 00:00:00 2001 From: cospplredman Date: Tue, 23 Apr 2024 08:22:51 -0500 Subject: [PATCH 13/18] added flags to cksum --- .gitignore | 1 + src/cksum/cksum.c | 81 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index ca890b5..1e0675a 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,7 @@ src/rm/rm src/rmdir/rmdir src/sh/sh src/sleep/sleep +src/sleep/cksum bin/ diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index f3f1333..4c6f8bb 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -1,15 +1,34 @@ #include #include #include +#include +#include #define NAME "cksum (canoutils)" #define VERSION "0.0.1" #define AUTHOR "cospplredman" -#include "getopt.h" +#include "cgetopt.h" #include "version_info.h" -static const char usage[] = {" -v version information\n"}; +static const char usage[] = { + "Usage: cksum [Option]... [File]...\n" + " --version version information\n" + " --help display this help and exit\n" + " --raw output raw crc\n" + " --tag default output style\n" +}; + +//flags +static int output_format = 't'; + +static struct option long_options[] = { + {"version", no_argument, NULL, 'v'}, + {"help", no_argument, NULL, 'h'}, + {"raw", no_argument, NULL, 'r'}, + {"tag", no_argument, NULL, 't'}, +}; + static const uint32_t crc32_ = 0x04c11db7; @@ -65,33 +84,65 @@ uint32_t crc32(FILE *file, size_t *octets) { return ~((remainder << 8) | (difference & 0xff)); } -int main(int argc, char **argv) { - if (argc < 2) { - printf("%s\n", usage); - exit(1); +void crc_print(char *filename, uint32_t crc, size_t octets){ + printf("%c\n", output_format); + switch(output_format){ + case 't': + if(filename == NULL) + printf("%u %lu\n", crc, octets); + else + printf("%u %lu %s\n", crc, octets, filename); + break; + case 'r': + printf("%c%c%c%c", (crc >> 24) & 255, (crc >> 16) & 255, (crc >> 8) & 255, crc & 255); + break; } +} - int opt; - while ((opt = getopt(argc, argv, "v")) != -1) { +int main(int argc, char **argv) { + + int opt, option_index; + while ((opt = getopt_long(argc, argv, "", long_options, &option_index)) != -1) { switch (opt) { + case 0: + break; case 'v': print_version(); return EXIT_SUCCESS; break; + case 'h': + printf("%s\n", usage); + return EXIT_SUCCESS; + case 'r': + output_format = 'r'; + break; + case 't': + output_format = 't'; + break; } } int index = optind; + size_t octets; + uint32_t crc; + + if (argc < 2) { + crc = crc32(stdin, &octets); + crc_print(NULL, crc, octets); + return EXIT_SUCCESS; + } + for (; index < argc; index++) { - FILE *file = fopen(argv[index], "r"); + FILE *file = fopen(argv[index], "r+"); - if (file == NULL) - return EXIT_FAILURE; + if (file == NULL){ + fprintf(stderr, "cksum: %s: %s\n", argv[index], strerror(errno)); + continue; + } - size_t octets; - uint32_t crc = crc32(file, &octets); - fclose(file); + crc = crc32(file, &octets); + crc_print(argv[index], crc, octets); - printf("%u %lu %s\n", crc, octets, argv[index]); + fclose(file); } } From e5951dbf2f24968e4cd6e262a9b7d965b8ebd088 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Tue, 23 Apr 2024 08:23:28 -0500 Subject: [PATCH 14/18] fixed typo --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1e0675a..de81bf8 100644 --- a/.gitignore +++ b/.gitignore @@ -76,7 +76,7 @@ src/rm/rm src/rmdir/rmdir src/sh/sh src/sleep/sleep -src/sleep/cksum +src/cksum/cksum bin/ From 01ce6211af445bdcb3a9468931d14f9bf4128864 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Tue, 23 Apr 2024 14:01:21 -0500 Subject: [PATCH 15/18] formatting fix --- src/cksum/cksum.c | 53 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 4c6f8bb..13ce0de 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -1,7 +1,7 @@ +#include #include #include #include -#include #include #define NAME "cksum (canoutils)" @@ -11,25 +11,22 @@ #include "cgetopt.h" #include "version_info.h" -static const char usage[] = { - "Usage: cksum [Option]... [File]...\n" - " --version version information\n" - " --help display this help and exit\n" - " --raw output raw crc\n" - " --tag default output style\n" -}; +static const char usage[] = {"Usage: cksum [Option]... [File]...\n" + " --version version information\n" + " --help display this help and exit\n" + " --raw output raw crc\n" + " --tag default output style\n"}; -//flags +// flags static int output_format = 't'; static struct option long_options[] = { - {"version", no_argument, NULL, 'v'}, - {"help", no_argument, NULL, 'h'}, - {"raw", no_argument, NULL, 'r'}, - {"tag", no_argument, NULL, 't'}, + {"version", no_argument, NULL, 'v'}, + {"help", no_argument, NULL, 'h'}, + {"raw", no_argument, NULL, 'r'}, + {"tag", no_argument, NULL, 't'}, }; - static const uint32_t crc32_ = 0x04c11db7; uint32_t crc32(FILE *file, size_t *octets) { @@ -84,25 +81,27 @@ uint32_t crc32(FILE *file, size_t *octets) { return ~((remainder << 8) | (difference & 0xff)); } -void crc_print(char *filename, uint32_t crc, size_t octets){ +void crc_print(char *filename, uint32_t crc, size_t octets) { printf("%c\n", output_format); - switch(output_format){ - case 't': - if(filename == NULL) - printf("%u %lu\n", crc, octets); - else - printf("%u %lu %s\n", crc, octets, filename); - break; - case 'r': - printf("%c%c%c%c", (crc >> 24) & 255, (crc >> 16) & 255, (crc >> 8) & 255, crc & 255); - break; + switch (output_format) { + case 't': + if (filename == NULL) + printf("%u %lu\n", crc, octets); + else + printf("%u %lu %s\n", crc, octets, filename); + break; + case 'r': + printf("%c%c%c%c", (crc >> 24) & 255, (crc >> 16) & 255, (crc >> 8) & 255, + crc & 255); + break; } } int main(int argc, char **argv) { int opt, option_index; - while ((opt = getopt_long(argc, argv, "", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "", long_options, &option_index)) != + -1) { switch (opt) { case 0: break; @@ -135,7 +134,7 @@ int main(int argc, char **argv) { for (; index < argc; index++) { FILE *file = fopen(argv[index], "r+"); - if (file == NULL){ + if (file == NULL) { fprintf(stderr, "cksum: %s: %s\n", argv[index], strerror(errno)); continue; } From 6d604950a82ca45fbed34b733b9ea847c89e6a78 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Tue, 23 Apr 2024 18:48:23 -0500 Subject: [PATCH 16/18] conformed to proh14 coding style --- src/cksum/cksum.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index 13ce0de..a21f96e 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -82,7 +82,6 @@ uint32_t crc32(FILE *file, size_t *octets) { } void crc_print(char *filename, uint32_t crc, size_t octets) { - printf("%c\n", output_format); switch (output_format) { case 't': if (filename == NULL) @@ -121,11 +120,14 @@ int main(int argc, char **argv) { } } - int index = optind; + argc -= optind; + argv += optind; + + int index = 0; size_t octets; uint32_t crc; - if (argc < 2) { + if (argc < 1) { crc = crc32(stdin, &octets); crc_print(NULL, crc, octets); return EXIT_SUCCESS; From 9a8541aa267adcaae6a5871453c9833642c02197 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Tue, 23 Apr 2024 19:00:09 -0500 Subject: [PATCH 17/18] added cksum to utils.txt --- utils.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/utils.txt b/utils.txt index 2961c53..95719e4 100644 --- a/utils.txt +++ b/utils.txt @@ -22,3 +22,4 @@ pwd rm rmdir sleep +cksum From c18649c07cdee74c7a9e45c9753548a41e6cf6c4 Mon Sep 17 00:00:00 2001 From: cospplredman Date: Tue, 23 Apr 2024 19:00:24 -0500 Subject: [PATCH 18/18] static correctness --- src/cksum/cksum.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cksum/cksum.c b/src/cksum/cksum.c index a21f96e..a683940 100644 --- a/src/cksum/cksum.c +++ b/src/cksum/cksum.c @@ -29,7 +29,7 @@ static struct option long_options[] = { static const uint32_t crc32_ = 0x04c11db7; -uint32_t crc32(FILE *file, size_t *octets) { +static uint32_t crc32(FILE *file, size_t *octets) { uint32_t remainder = 0; uint8_t difference = 0; @@ -81,7 +81,7 @@ uint32_t crc32(FILE *file, size_t *octets) { return ~((remainder << 8) | (difference & 0xff)); } -void crc_print(char *filename, uint32_t crc, size_t octets) { +static void crc_print(char *filename, uint32_t crc, size_t octets) { switch (output_format) { case 't': if (filename == NULL)