From d78ae27865a215be06268449f4ab6ab016e85f6e Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Tue, 22 Jun 2010 21:56:38 +0000 Subject: [PATCH] advent: support ${.OBJDIR} != ${.CURDIR}, tracker item 486 --- commands/advent/Makefile | 4 ++-- commands/advent/setup.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/commands/advent/Makefile b/commands/advent/Makefile index 399acbebd..84cf2b622 100644 --- a/commands/advent/Makefile +++ b/commands/advent/Makefile @@ -15,11 +15,11 @@ MAN= database.o: advtext.h setup: setup.c advent.h - ${CC} ${CPPFLAGS} ${LDFLAGS} -o setup setup.c + ${CC} ${CPPFLAGS} ${LDFLAGS} -o $@ ${.CURDIR}/setup.c advtext.h advent1.dat advent2.dat advent3.dat advent4.dat: \ setup advent1.txt advent2.txt advent3.txt advent4.txt - ./setup + ./setup ${.CURDIR} CPPFLAGS.advent.c= -DTEXTDIR='"${TEXTDIR}"' diff --git a/commands/advent/setup.c b/commands/advent/setup.c index c983da9e4..dc15f37f6 100644 --- a/commands/advent/setup.c +++ b/commands/advent/setup.c @@ -11,28 +11,34 @@ #include #include "advent.h" -_PROTOTYPE(int main, (void)); _PROTOTYPE(void file_error, (char *)); _PROTOTYPE(void encode, (unsigned char *)); -int main() +int main(int argc, char *argv[]) { FILE *isam, *src, *dest; char itxt[255]; int cnt, i; long llen; - char filename[12]; + char filename[100]; + char *inputprefix = "."; static char *headername[] = { "idx1[MAXLOC]", "idx2[MAXLOC]", "idx3[MAXOBJ]", "idx4[MAXMSG]", }; long x29 = (1L << 29), x30 = (1L << 30); + + if(argc > 1) { + inputprefix=argv[1]; + } + if (!(x30 / 2 == x29 && 0L < x30 && x29 < x30)) { fprintf(stderr, "Sorry, advent needs 32-bit `long int's.\n"); exit(EXIT_FAILURE); } - isam = fopen("advtext.h", "w"); + sprintf(filename, "%s/advtext.h", inputprefix); + isam = fopen(filename, "w"); if (!isam) { fprintf(stderr, "Sorry, I can't open advtext.h...\n"); exit(EXIT_FAILURE); @@ -42,7 +48,7 @@ int main() for (i = 1; i <= 4; i++) { cnt = -1; llen = 0L; - sprintf(filename, "advent%d.txt", i); + sprintf(filename, "%s/advent%d.txt", inputprefix, i); src = fopen(filename, "r"); if (!src) file_error(filename); -- 2.44.0