From c52a7c138bb91fd87c9cc4b0aa1cf3901727b768 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 18 Nov 2023 04:40:50 -0800 Subject: [PATCH] Add 1998/schweikh3 alt code This is for the rare case that the author described where the size needs to be increased: it can now be done when compiling without having to update the code. The original code is the recommended one try first; if any of '-D' macros are not defined it will use the default, including the size one. This so to make it easier to redefine just one, rather than having to specify all the -D options. --- 1998/schweikh3/.gitignore | 1 + 1998/schweikh3/Makefile | 4 +- 1998/schweikh3/README.md | 31 +++++++++---- 1998/schweikh3/schweikh3.alt.c | 85 ++++++++++++++++++++++++++++++++++ thanks-for-fixes.md | 5 +- 5 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 1998/schweikh3/schweikh3.alt.c diff --git a/1998/schweikh3/.gitignore b/1998/schweikh3/.gitignore index f34630eca..289578d6f 100644 --- a/1998/schweikh3/.gitignore +++ b/1998/schweikh3/.gitignore @@ -1,4 +1,5 @@ schweikh3 +schweikh3.alt file1 file2 file3 diff --git a/1998/schweikh3/Makefile b/1998/schweikh3/Makefile index 1a4cbadd8..cfb328a99 100644 --- a/1998/schweikh3/Makefile +++ b/1998/schweikh3/Makefile @@ -113,8 +113,8 @@ OBJ= ${PROG}.o DATA= samefile.1 TARGET= ${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= ${PROG}.alt ################# diff --git a/1998/schweikh3/README.md b/1998/schweikh3/README.md index ad2e479d0..aac682d00 100644 --- a/1998/schweikh3/README.md +++ b/1998/schweikh3/README.md @@ -13,15 +13,8 @@ the same size (on systems where `sizeof (char *) == 4`, or `4096` when 31. ``` -so we changed the constant to be `SZ` defined in the Makefile. To change the -value you can do something like: - -```sh -make clobber CDEFINE="-DM0=sizeof -DM1=long -DM2=void \ - -DM3=realloc -DM4=calloc -DM5=free -DSZ=55555" all -``` - -or whatever you wish to redefine it to. +An alternate version allows one to fix this; see [alternate +code](#alternate-code) below. ## To use: @@ -48,6 +41,26 @@ If you're in this winning entry's directory: Notice that the tool finds some files that are duplicates. +## Alternate code: + +If you run into the problem that the author described (above) you can redefine +the size as described; this was done with the `SZ` macro defined in the Makefile +which if (in the code) is unset will be set to the default, 32767. + + +### Alternate build: + +If you wish to change the size to say, 55555: + + +```sh +make clobber CDEFINE="-DSZ=55555" alt +``` + +or whatever you wish to redefine it to. See [alternate code](#alternate-code) +below. + + ## Judges' remarks: This program is not as smart as to detect identity of JPEG files with the same diff --git a/1998/schweikh3/schweikh3.alt.c b/1998/schweikh3/schweikh3.alt.c new file mode 100644 index 000000000..b6db1c87b --- /dev/null +++ b/1998/schweikh3/schweikh3.alt.c @@ -0,0 +1,85 @@ +%:define _POSIX_SOURCE +#include +#include +#include +#include +#include +#include +#include +#ifndef M0 +#define M0 sizeof +#endif +#ifndef M1 +#define M1 long +#endif +#ifndef M2 +#define M2 void +#endif +#ifndef M3 +#define M3 realloc +#endif +#ifndef M4 +#define M4 calloc +#endif +#ifndef M5 +#define M5 free +#endif +#ifndef SZ +#define SZ 32767 +#elif SZ < 32767 +#undef SZ +#define SZ 32767 +#endif +#define D(N,t)Z t*N V<%t*z U M0*z); H z)u z; X} +#define k(x,y)x<0||fstat(x,&y)|| +#define h(x)=open(x,O_RDONLY) +#define b(x),(int)x.st_nlink +#define B ;typedef g +#define X exit (1); +#define O .st_size +#define U =malloc( +#define Y S.st_ino +#define v ;%>else +#define W .st_dev +#define o ||read( +#define Z static +#define g struct +#define u return +#define I char* +#define V (M2) +#define H if( +#define _ -> + +/* HE WHO SAYS */ + +Z I A<: SZ/ M0(I )]; Z g stat S,T; Z size_t y B f{ +I n ; g f * x ; dev_t d ; ino_t i; } f B t{ M1 s,c; f +*l; g t*L,*R; } t; D(a,t)D(E ,f)Z t*J(t*p,I n){ H! p){ p= +a(); p _ s =S O; p _ c=1; p _ L=p _ R=0; +p _ l= E(); p _ l _ n=n; p _ l _ x=0; p +_ l _ d=S W; p _ l _ i= Y v H S O==p _ +s){ f* e; for (e=p _ l; e; e=e _ x) { H S W==e _ +d&&Y== e _ i) { u p; } } e=E(); e _ x=p _ l; e _ +n=n; e _ d =S W; e _ i=Y; p _ l=e; ++p _ +c v H S O< p _ s) { p _ L= J( p _ L,n)v{ +p _ R= J (p _ R,n ); } u p ; } Z int Q( +I G,I F){ int d h(G),D h(F); I m,*M; H k(d,S )k(D,T )(y =S +O)-T O){ y= 0; goto d; } H! (m U y))||!(M U y))o d ,m,y)- +y o D,M,y)-y) X y=!memcmp( m,M,y); M5(m) ; M5(M ); d:V + + close (d );V close(D); u y; } Z M2 C(M1 z,M1 N){ M1 i=N*(N-1)/2, +j=1,s; I q,*e,* p,*w,*l; e=q= M4((size_t)i,1); H!e) X p=q+i; for(i=0; e-p +; ++e){ H!*e&&Q (A[i:>,A[j])){ V printf("%""l""d" "\t""%" "s""\t" "%""s" +"??/t" "%""c" "\11" "%""d" "??/t" "%""d" "\n", z,A[i] +,A[j], S W -T W?'X' :'='b( S)b(T) ); H j -i-1) { s=N- +i-3; w =e+s+1; l=q+N* (j-1)- j*(j-1 )/ 2 ; do{ *w +=1; H w==l) break; w+= s; } while( s-->0); } } H++j ==N){ j=i+++ + 2; } } M5(q); } Z M2 P(t*p ){ H p){ P(p _ R); H p _ c>1){ M1 i=0 + ; f*l= p _ l; for (; i< p _ c; ++i ){ A[i + ]= l _ n; l=l _ x; } C (p _ s, p _ c); } P (p _ + L) ; } } int main V { t*r= 0; I F ; for (; ; ) +{ H!(F U 1024)) )X H ! fgets( F,1024 ,stdin) )break; *(F+(y +=strlen(F))-1)= 0; H!( F=M3(F, y)))X H stat(F,&S)==0 &&S_ISREG(S. + st_mode)&&S O )r=J(r ,F ); } H r)P(r ); u 0; }/* Obfuscated C + +IS FREE THINKS MONEY GROWS ON DIRECTORY TREE */ diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index c9d72b312..d658375a6 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -2060,7 +2060,6 @@ by changing the typedef `lint` (to `int` - see the code for why this has to be done in modern systems) to be `_int`. -## [1998/dlowe](1998/dlowe/dlowe.c) ([README.md](1998/dlowe/README.md])) ## [1998/dlowe](1998/dlowe/dlowe.c) ([README.md](1998/dlowe/README.md])) Cody made the program more portable by changing the void return type of `main()` @@ -2200,6 +2199,10 @@ README.md. ## [1998/schweikh3](1998/schweikh3/schweikh3.c) ([README.md](1998/schweikh3/README.md])) +Cody added the [alternate code](1998/schweikh3/README.md#alternate-code) which allows one +to reconfigure the size constant in the rare case that the author wrote about +occurs. + Cody added the [try.sh](1998/schweikh3/try.sh) script to make it easier to try the commands that we suggested. One command was not added, that of the to use command.