1
0

more cleaning!!!

This commit is contained in:
dtb 2022-09-18 20:40:56 -04:00
parent 3b9ff7ddb4
commit 473cbc8123
8 changed files with 62 additions and 90 deletions

View File

@ -1,20 +1,4 @@
all: ; all: ;
clean: ; clean: ;
sane: ; sane: ;
dist: ../dist/battery.tar.gz
../dist/battery: battery
mkdir -p ../dist/battery.tmp/bin/
cp battery* ../dist/battery.tmp/bin/
mv ../dist/battery.tmp ../dist/battery
../dist/battery.tar: ../dist/battery
cd ../dist/battery && pax -w -x ustar . >../battery.tar.tmp
mv ../dist/battery.tar.tmp ../dist/battery.tar
../dist/battery.tar.gz: ../dist/battery.tar
gzip -c <../dist/battery.tar >../dist/battery.tar.gz.tmp
mv ../dist/battery.tar.gz.tmp ../dist/battery.tar.gz
.PHONY: all clean sane .PHONY: all clean sane

19
dist/Makefile vendored
View File

@ -1,19 +1,28 @@
.PHONY: dirs
dirs: bin share/man/man1
bin: bin:
mkdir -p bin mkdir -p bin
share/man/man1:
mkdir -p share/man/man1
.PHONY: battery .PHONY: battery
battery: bin/battery battery: bin/battery
bin/battery: bin ../battery/battery bin/battery: bin ../battery/battery
cp ../battery/battery* bin/ cp ../battery/battery* bin/
../battery/battery:
$(MAKE) -C ../battery sane
.PHONY: data .PHONY: data
data: bin/data battery lowercase nonzero str streq data: bin/data battery lowercase nonzero str streq
bin/data: bin ../data/data bin/data: bin ../data/data
cp ../data/data bin/ cp ../data/data bin/
../data/data:
$(MAKE) -C ../data sane .PHONY: echo
echo: bin/echo
bin/echo: dirs ../echo/echo
cp ../echo/echo bin/
share/man/man1/echo.1: dirs ../echo/echo.1
cp ../echo/echo.1 share/man/man1/
../echo/echo:
$(MAKE) -C ../echo sane
.PHONY: lowercase .PHONY: lowercase
lowercase: bin/lowercase lowercase: bin/lowercase
@ -47,5 +56,3 @@ bin/streq: bin ../streq/streq
volume: bin/volume volume: bin/volume
bin/volume: bin ../volume/volume bin/volume: bin ../volume/volume
cp ../volume/volume* bin/ cp ../volume/volume* bin/
../volume/volume:
$(MAKE) -C ../volume/volume sane

View File

@ -1,28 +1,17 @@
all: echo TARGETS = echo
all: $(TARGETS)
%: %.c
$(CC) -o $@ $@.c
clean: clean:
rm -rf ../dist/echo ../dist/echo.tar ../dist/echo.tar.gz echo rm -f $(TARGETS)
dist: ../dist/echo.tar.gz sane: echo.c ../sysexits/sysexits.h
sane: echo.c ../include/sysexits.h
$(CC) -DDONT_USE_SYSTEM_SYSEXITS -o echo echo.c $(CC) -DDONT_USE_SYSTEM_SYSEXITS -o echo echo.c
echo: echo.c ../sysexits/sysexits.h:
$(CC) -o echo echo.c $(MAKE) -C ../sysexits sysexits.h
../dist/echo: echo
mkdir -p ../dist/echo.tmp/bin/ ../dist/echo.tmp/share/man/man1/
cp echo ../dist/echo.tmp/bin/echo
cp echo.1 ../dist/echo.tmp/share/man/man1/echo.1
mv ../dist/echo.tmp ../dist/echo
../dist/echo.tar: ../dist/echo
cd ../dist/echo && pax -w -x ustar . >../echo.tar.tmp
mv ../dist/echo.tar.tmp ../dist/echo.tar
../dist/echo.tar.gz: ../dist/echo.tar
gzip -c <../dist/echo.tar >../dist/echo.tar.gz.tmp
mv ../dist/echo.tar.gz.tmp ../dist/echo.tar.gz
.PHONY: all clean sane .PHONY: all clean sane

9
lowercase/Makefile Normal file
View File

@ -0,0 +1,9 @@
all: lowercase
clean:
rm -f lowercase
sane: lowercase
lowercase: ../ascii/ascii.h lowercase.c
$(CC) -I../ascii/ -o lowercase lowercase.c
.PHONY: all clean sane

View File

@ -1,5 +1,4 @@
#include <ascii.h> /* ASCII_MAX_VALUE */ #include <ascii.h> /* ASCII_MAX_VALUE */
#include <stdbool.h> /* bool */
#include <stdio.h> /* fprintf(3), getc(3), putc(3), stderr, stdin, stdout */ #include <stdio.h> /* fprintf(3), getc(3), putc(3), stderr, stdin, stdout */
#include <stdlib.h> /* exit(3) */ #include <stdlib.h> /* exit(3) */
#include <sysexits.h> /* EX_OK, EX_USAGE, EX_SOFTWARE */ #include <sysexits.h> /* EX_OK, EX_USAGE, EX_SOFTWARE */
@ -10,16 +9,10 @@
# include <unicode/uchar.h> /* UCHAR_MAX_VALUE, u_tolower(3) */ # include <unicode/uchar.h> /* UCHAR_MAX_VALUE, u_tolower(3) */
# include <unicode/umachine.h> /* UChar32 */ # include <unicode/umachine.h> /* UChar32 */
# include <unicode/ustdio.h> /* u_fgetc(3) */ # include <unicode/ustdio.h> /* u_fgetc(3) */
#else
# include <ctype.h> /* tolower(3) */
#endif /* USE_ICU */ #endif /* USE_ICU */
#define PROGRAM_NAME "lowercase"
void
usage(char *name){
fprintf(stderr, "Usage: %s (-f)\n", name);
exit(EX_USAGE);
}
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
#ifdef USE_ICU #ifdef USE_ICU
UChar32 UChar32
@ -27,45 +20,22 @@ int main(int argc, char *argv[]){
int int
#endif #endif
c; /* iterating over character stream */ c; /* iterating over character stream */
int d; /* iterating over getopt */
bool force;
force = false;
while((d = getopt(argc, argv, "f")) != -1) if(argc > 1){
switch(d){ fprintf(stderr, "Usage: %s\n", argv[0]);
case 'f': return EX_USAGE;
force = true; }
break;
case '?':
usage(argv[0] != NULL ? argv[0] : PROGRAM_NAME);
break;
}
if(argv[optind] != NULL) /* don't accept arguments */
usage(argv[0] != NULL ? argv[0] : PROGRAM_NAME);
#ifdef USE_ICU #ifdef USE_ICU
while((c = u_fgetc(stdin)) != U_EOF){ while((c = u_fgetc(stdin)) != U_EOF){
#else if(c <= UCHAR_MAX_VALUE && c >= 0)
while((c = getc(stdin)) != EOF){
#endif
if(c <= ASCII_MAX_VALUE)
c += ('a' - 'A') * (c >= 'A' && c <= 'Z');
#ifdef USE_ICU
else if(c <= UCHAR_MAX_VALUE)
c = u_tolower(c); c = u_tolower(c);
#endif
else if(!force){ /* past supported */
fprintf(
stderr,
"%s: Sorry, extra-ASCII characters are not yet"
" supported!\n",
argv[0] != NULL ? argv[0] : PROGRAM_NAME
);
return EX_SOFTWARE;
}
#ifdef USE_ICU
u_fputc(c, stdout); u_fputc(c, stdout);
#else #else
while((c = getc(stdin)) != EOF){
if(c <= ASCII_MAX_VALUE && c >= 0)
c = tolower(c);
putc(c, stdout); putc(c, stdout);
#endif #endif
} }

View File

@ -7,6 +7,7 @@ streq \(en compare strings
.SH SYNOPSIS .SH SYNOPSIS
streq streq
.RM [ string ]
.RB [ strings... ] .RB [ strings... ]
.SH DESCRIPTION .SH DESCRIPTION

13
sysexits/Makefile Normal file
View File

@ -0,0 +1,13 @@
TARGETS = sysexits sysexits.h
CFLAGS = -I..
all: $(TARGETS)
clean:
rm -f $(TARGETS)
%: %.c
$(CC) $(CFLAGS) -o $@ $@.c
sysexits.h: sysexits
./sysexits >sysexits.h

View File

@ -1,15 +1,14 @@
#include <ascii.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include "usefulmacros.h" #include "arraylen.h"
/* Thanks to u/smcameron on Reddit. */ /* Thanks to u/smcameron on Reddit. */
#define TAB_WIDTH 8 #define TAB_WIDTH 8
/* Changing ENUM to DEFINE will make this output the traditional BSD header /* Changing ENUM to DEFINE will make this output the traditional BSD header
* verbatim, without copyright notice. I don't have any fucking idea if that's * verbatim, without copyright notice. I don't have any idea if that's a
* a copyright violation, but let's keep this as ENUM to skirt by that little * copyright violation, but let's keep this as ENUM to skirt by that little
* technicality. * technicality.
* I implemented sysexits(3) in the enum method before reading the BSD 4.0 * I implemented sysexits(3) in the enum method before reading the BSD 4.0
* source to see how they did it. */ * source to see how they did it. */
@ -17,7 +16,7 @@
static char *program_name = "sysexits"; static char *program_name = "sysexits";
//static const char comment_prefix[] = "/* "; static const char comment_prefix[] = "/* ";
static const char comment_prefix_ongoing[] = " * "; static const char comment_prefix_ongoing[] = " * ";
static const char comment_suffix[] = " */\n"; static const char comment_suffix[] = " */\n";
@ -168,7 +167,7 @@ static void output_header(void){
); );
#endif /* ifdef DEFINE */ #endif /* ifdef DEFINE */
} }
fflush(stdout); /* Fixes actual issue. */ fflush(stdout);
write(1, header_suffix, ARRAYLEN(header_suffix) - 1); write(1, header_suffix, ARRAYLEN(header_suffix) - 1);
} }