simplify
This commit is contained in:
parent
f85bb632e2
commit
d8fa412f3b
@ -2,19 +2,10 @@ TARGETS = echo prompt
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
echo: echo.c
|
||||
%: %.c
|
||||
$(CC) -o $@ $@.c
|
||||
|
||||
prompt: echo.c
|
||||
$(CC) -DPROMPT -o $@ echo.c
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
|
||||
sane: echo.c ../sysexits/sysexits.h
|
||||
$(CC) -DDONT_USE_SYSTEM_SYSEXITS -o echo echo.c
|
||||
|
||||
../sysexits/sysexits.h:
|
||||
$(MAKE) -C ../sysexits sysexits.h
|
||||
|
||||
.PHONY: all clean sane
|
||||
.PHONY: all clean
|
||||
|
25
echo/echo.c
25
echo/echo.c
@ -1,25 +1,16 @@
|
||||
#include <stdio.h> /* NULL, fprintf(3), putc(3) */
|
||||
#include <stdlib.h> /* stdout */
|
||||
#include <sysexits.h> /* EX_OK */
|
||||
#include <stddef.h> /* NULL */
|
||||
#include <unistd.h> /* write(2) */
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int i;
|
||||
|
||||
if(*argv == NULL)
|
||||
goto blank;
|
||||
|
||||
++argv;
|
||||
|
||||
while(--argc){
|
||||
for(i = 0; argv[0][i] != '\0'; ++i);
|
||||
write(1, *(argv++), i);
|
||||
if(argc > 1)
|
||||
write(1, " ", 1);
|
||||
if(*argv == NULL || *++argv == NULL){
|
||||
argc = 1;
|
||||
putc('\n', stdout);
|
||||
}
|
||||
|
||||
blank:
|
||||
#ifndef PROMPT
|
||||
write(1, "\n", 1);
|
||||
#endif
|
||||
while(--argc)
|
||||
fprintf(stdout, "%s%c", *(argv++), argc > 1 ? ' ' : '\n');
|
||||
|
||||
return EX_OK;
|
||||
}
|
||||
|
17
echo/prompt.c
Normal file
17
echo/prompt.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h> /* NULL, fprintf(3), putc(3) */
|
||||
#include <stdlib.h> /* stdout */
|
||||
#include <sysexits.h> /* EX_OK */
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
if(*argv == NULL || *++argv == NULL)
|
||||
argc = 1;
|
||||
|
||||
while(--argc){
|
||||
fprintf(stdout, "%s", *(argv++));
|
||||
if(argc > 1)
|
||||
putc(' ', stdout);
|
||||
}
|
||||
|
||||
return EX_OK;
|
||||
}
|
Loading…
Reference in New Issue
Block a user