advent: support ${.OBJDIR} != ${.CURDIR}, tracker item 486

This commit is contained in:
Ben Gras 2010-06-22 21:56:38 +00:00
parent ddc3f62290
commit d78ae27865
2 changed files with 13 additions and 7 deletions

View file

@ -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}"'

View file

@ -11,28 +11,34 @@
#include <stdlib.h>
#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);