aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile7
-rw-r--r--src/alf.c48
-rw-r--r--src/unalf.h5
3 files changed, 41 insertions, 19 deletions
diff --git a/src/Makefile b/src/Makefile
index d09d8dc..0106dc7 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -41,7 +41,7 @@ CFLAGS=-DVERSION='"$(VERSION)"' -Wall -I../f65 $(COPT)
UNALF_OBJS=unalf.o io.o listalf.o extract.o f65.o glob.o opts.o usage.o self.o asmcode.o
ALFSUM_OBJS=alfsum.o self.o
-ALF_OBJS=alf.o
+ALF_OBJS=alf.o self.o
.PHONY: all clean install crosswin windows windows-upload realclean
@@ -53,9 +53,12 @@ all: unalf unalf.1 alfsum alfsum.1 alf alf.1
unalf: $(UNALF_OBJS)
$(CC) $(LDFLAGS) -o $@ $(UNALF_OBJS)
-alfsum: alfsum.o self.o
+alfsum: $(ALFSUM_OBJS)
$(CC) $(LDFLAGS) -o $@ $(ALFSUM_OBJS)
+alf: $(ALF_OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(ALF_OBJS)
+
usage.o: usage.c
f65.o: ../f65/f65.c ../f65/f65.h
diff --git a/src/alf.c b/src/alf.c
index 0dd8d88..63b1d05 100644
--- a/src/alf.c
+++ b/src/alf.c
@@ -1,17 +1,13 @@
-/* eventual options:
- -a append
- -o overwrite (instead of backup~)
- -v verbose
- */
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <limits.h>
+#include <sys/stat.h>
+#include <time.h>
-#define self "unalf"
+#include "self.h"
#ifndef u8
#define u8 unsigned char
@@ -35,6 +31,8 @@ int input_len, output_len, out_bitpos;
int opt_append = 0;
int opt_overwrite = 0;
+struct stat in_file_stat;
+
typedef struct s_token {
u8 *start;
u16 length;
@@ -127,6 +125,22 @@ void atarify_filename(char *result) {
*p = toupper(*p);
}
+/* see Arcinfo for the gory details. */
+unsigned long get_msdos_date_time(void) {
+ time_t t = in_file_stat.st_mtim.tv_sec;
+ struct tm *tm;
+ int msdos_year;
+ u16 ms_date, ms_time;
+
+ tm = gmtime(&t);
+
+ msdos_year = tm->tm_year + 1900 - 1980;
+
+ ms_date = tm->tm_mday | (tm->tm_mon << 5) | (msdos_year << 9);
+ ms_time = (tm->tm_min << 5) | (tm->tm_hour << 11);
+ return ms_date | (ms_time << 16);
+}
+
void create_header(void) {
char hdr_filename[13];
@@ -137,7 +151,7 @@ void create_header(void) {
strncat((char *)&output_buf[2], hdr_filename, 13);
output_buf[14] = 0x00;
store_quad(15, 0); /* compressed size, fill in later */
- store_quad(19, 0); /* date/time (TODO: real timestamp) */
+ store_quad(19, get_msdos_date_time());
store_cksum();
store_quad(25, input_len);
output_len = 29;
@@ -243,6 +257,7 @@ void crunch_file(const char *filename) {
/* read in entire input, couldn't do it this way on the Atari */
input_len = fread(input_buf, 1, MAX_INPUT_SIZE - 1, in_file);
output_len = 0;
+ fstat(fileno(in_file), &in_file_stat); /* for timestamp */
fclose(in_file);
memset(output_buf, 0, sizeof(output_buf));
@@ -262,15 +277,22 @@ void make_backup(void) {
rename(out_filename, bak);
}
+void usage(void) {
+ puts("alf (ALF compressor) v" VERSION " by B. Watson, WTFPL.");
+ printf("Usage: %s [-a|-o] archive.alf file [file ...]\n", self);
+ puts("Options:");
+ puts(" -a: append to archive");
+ puts(" -o: overwrite archive (don't make backup with ~)");
+ exit(0);
+}
+
int main(int argc, char **argv) {
int opt;
+ set_self(argv[0]);
+
if(argc < 2 || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) {
- fprintf(stderr, "Usage: %s [-a|-o] archive.alf file [file ...]\n", self);
- fprintf(stderr, "Options:\n");
- fprintf(stderr, " -a: append to archive\n");
- fprintf(stderr, " -o: overwrite archive (don't make backup with ~)\n");
- exit(1);
+ usage();
}
while((opt = getopt(argc, argv, "ao")) != -1) {
diff --git a/src/unalf.h b/src/unalf.h
index cab319f..1cb71bf 100644
--- a/src/unalf.h
+++ b/src/unalf.h
@@ -6,6 +6,7 @@
#include <ctype.h>
#include <sys/stat.h>
#include <f65.h>
+#include "self.h"
#ifndef VERSION
#define VERSION "???"
@@ -64,10 +65,6 @@ void fix_filename(void);
/* opts.c */
void parse_opts(int argc, char * const *argv);
-/* self.c */
-extern char *self;
-void set_self(char *argv0);
-
/* unalf.c */
extern char *self;
extern FILE *out_file;