1
0
Fork 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: ;
clean: ;
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

19
dist/Makefile vendored
View File

@ -1,19 +1,28 @@
.PHONY: dirs
dirs: bin share/man/man1
bin:
mkdir -p bin
share/man/man1:
mkdir -p share/man/man1
.PHONY: battery
battery: bin/battery
bin/battery: bin ../battery/battery
cp ../battery/battery* bin/
../battery/battery:
$(MAKE) -C ../battery sane
.PHONY: data
data: bin/data battery lowercase nonzero str streq
bin/data: bin ../data/data
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
lowercase: bin/lowercase
@ -47,5 +56,3 @@ bin/streq: bin ../streq/streq
volume: bin/volume
bin/volume: bin ../volume/volume
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:
rm -rf ../dist/echo ../dist/echo.tar ../dist/echo.tar.gz echo
rm -f $(TARGETS)
dist: ../dist/echo.tar.gz
sane: echo.c ../include/sysexits.h
sane: echo.c ../sysexits/sysexits.h
$(CC) -DDONT_USE_SYSTEM_SYSEXITS -o echo echo.c
echo: echo.c
$(CC) -o echo echo.c
../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
../sysexits/sysexits.h:
$(MAKE) -C ../sysexits sysexits.h
.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 <stdbool.h> /* bool */
#include <stdio.h> /* fprintf(3), getc(3), putc(3), stderr, stdin, stdout */
#include <stdlib.h> /* exit(3) */
#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/umachine.h> /* UChar32 */
# include <unicode/ustdio.h> /* u_fgetc(3) */
#else
# include <ctype.h> /* tolower(3) */
#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[]){
#ifdef USE_ICU
UChar32
@ -27,45 +20,22 @@ int main(int argc, char *argv[]){
int
#endif
c; /* iterating over character stream */
int d; /* iterating over getopt */
bool force;
force = false;
while((d = getopt(argc, argv, "f")) != -1)
switch(d){
case 'f':
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);
if(argc > 1){
fprintf(stderr, "Usage: %s\n", argv[0]);
return EX_USAGE;
}
#ifdef USE_ICU
while((c = u_fgetc(stdin)) != U_EOF){
#else
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)
if(c <= UCHAR_MAX_VALUE && c >= 0)
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);
#else
while((c = getc(stdin)) != EOF){
if(c <= ASCII_MAX_VALUE && c >= 0)
c = tolower(c);
putc(c, stdout);
#endif
}

View File

@ -7,6 +7,7 @@ streq \(en compare strings
.SH SYNOPSIS
streq
.RM [ string ]
.RB [ strings... ]
.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 <unistd.h>
#include "usefulmacros.h"
#include "arraylen.h"
/* Thanks to u/smcameron on Reddit. */
#define TAB_WIDTH 8
/* 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
* a copyright violation, but let's keep this as ENUM to skirt by that little
* verbatim, without copyright notice. I don't have any idea if that's a
* copyright violation, but let's keep this as ENUM to skirt by that little
* technicality.
* I implemented sysexits(3) in the enum method before reading the BSD 4.0
* source to see how they did it. */
@ -17,7 +16,7 @@
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_suffix[] = " */\n";
@ -168,7 +167,7 @@ static void output_header(void){
);
#endif /* ifdef DEFINE */
}
fflush(stdout); /* Fixes actual issue. */
fflush(stdout);
write(1, header_suffix, ARRAYLEN(header_suffix) - 1);
}