Initial commit
This commit is contained in:
commit
22bf3c985b
20
Makefile
Normal file
20
Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall
|
||||
BUILDDIR = .build/
|
||||
TARGET = $(BUILDDIR)program
|
||||
SRCS = src/
|
||||
OBJS=$(patsubst $(SRCS)%.c, $(BUILDDIR)%.o, $(wildcard $(SRCS)*.c))
|
||||
|
||||
all: checkbuild $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS)
|
||||
|
||||
$(BUILDDIR)%.o: $(SRCS)%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
checkbuild:
|
||||
./checkbuild.sh
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)*
|
||||
5
checkbuild.sh
Normal file
5
checkbuild.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! -d ".build" ]; then
|
||||
mkdir -p ./.build
|
||||
fi
|
||||
42
src/main.c
Normal file
42
src/main.c
Normal file
@ -0,0 +1,42 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE* fp;
|
||||
void filecopy(FILE *, FILE *);
|
||||
char *prog = argv[0];
|
||||
|
||||
if (argc == 1) {
|
||||
filecopy(stdin, stdout);
|
||||
}
|
||||
else {
|
||||
while (--argc > 0) {
|
||||
if ((fp = fopen(*++argv, "r")) == NULL) {
|
||||
fprintf(stderr, "%s: can't open %s\n", prog, *argv);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
filecopy(fp, stdout);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ferror(stdout)) {
|
||||
fprintf(stderr, "%s: error writing stdout\n", prog);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void filecopy(FILE *ifp, FILE *ofp)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = getc(ifp)) != EOF) {
|
||||
putc(c, ofp);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user