Skip to content

Commit 5cc8d75

Browse files
committed
Put DEC timestamp handling in separate file.
1 parent 86ac7f1 commit 5cc8d75

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tape-dir: tape-dir.o $(OBJS) libwords.a
7171
tito: tito.o $(OBJS) libwords.a
7272
$(CC) $(CFLAGS) $^ -o $@
7373

74-
dart: dart.o $(OBJS) libwords.a
74+
dart: dart.o dec.o $(OBJS) libwords.a
7575
$(CC) $(CFLAGS) $^ -o $@
7676

7777
dumper: dumper.o $(OBJS) libwords.a

dart.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,16 @@ static int tape_frames;
5555
static int tape_bpw; /* Tape frames per word. */
5656
static int tape_bpi;
5757

58-
/* Convert a WAITS date to year, month, day. */
59-
static void
60-
compute_date (word_t date, int *year, int *month, int *day)
61-
{
62-
*day = date % 31;
63-
*month = (date / 31) % 12;
64-
*year = (date / 31 / 12) + 1964;
65-
}
66-
6758
/* Convert a WAITS date to a struct timeval. */
6859
static void
6960
unix_time (struct timeval *tv, word_t date, word_t minutes)
7061
{
7162
struct tm tm;
72-
compute_date (date, &tm.tm_year, &tm.tm_mon, &tm.tm_mday);
63+
timestamp_from_dec (&tm, date);
7364
tm.tm_sec = 0;
7465
tm.tm_min = minutes % 60;
7566
tm.tm_hour = minutes / 60;
7667
tm.tm_mday++;
77-
tm.tm_year -= 1900;
7868
tm.tm_isdst = 0;
7969
tv->tv_sec = mktime (&tm);
8070
tv->tv_usec = 0;
@@ -84,11 +74,8 @@ unix_time (struct timeval *tv, word_t date, word_t minutes)
8474
static void
8575
print_timestamp (FILE *f, word_t date, word_t minutes)
8676
{
87-
int year, month, day;
88-
compute_date (date, &year, &month, &day);
89-
fprintf (f, "%4d-%02d-%02d %02lld:%02lld",
90-
year, month + 1, day + 1,
91-
minutes / 60, minutes % 60);
77+
print_dec_timestamp (f, date);
78+
fprintf (f, " %02lld:%02lld", minutes / 60, minutes % 60);
9279
}
9380

9481
/* Convert a Unix time_t to WAITS date and time. */

dec.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <string.h>
2+
#include "dis.h"
3+
4+
/* Convert a DEC timestamp to year, month, day. */
5+
static void
6+
dec_date (word_t timestamp, int *year, int *month, int *day)
7+
{
8+
*day = timestamp % 31;
9+
*month = (timestamp / 31) % 12;
10+
*year = (timestamp / 31 / 12) + 1964;
11+
}
12+
13+
/* Print DEC timestamp. */
14+
void
15+
print_dec_timestamp (FILE *f, word_t timestamp)
16+
{
17+
int year, month, day;
18+
dec_date (timestamp, &year, &month, &day);
19+
fprintf (f, "%4d-%02d-%02d", year, month + 1, day + 1);
20+
}
21+
22+
/* Convert a DEC timesamp date to a struct tm. */
23+
void
24+
timestamp_from_dec (struct tm *tm, word_t timestamp)
25+
{
26+
memset (tm, 0, sizeof (struct tm));
27+
dec_date (timestamp, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
28+
tm->tm_year -= 1900;
29+
}

dis.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef DIS_H
1717
#define DIS_H
1818

19+
#include <time.h>
1920
#include <stdio.h>
2021
#include <stdlib.h>
2122

@@ -148,6 +149,8 @@ extern void squoze_to_ascii (word_t squoze, char *ascii);
148149
extern void print_date (FILE *, word_t t);
149150
extern void print_time (FILE *, word_t t);
150151
extern void print_datime (FILE *, word_t t);
152+
extern void print_dec_timestamp (FILE *f, word_t timestamp);
153+
extern void timestamp_from_dec (struct tm *tm, word_t timestamp);
151154
extern int byte_size (int, int *);
152155
extern void scramble (int decrypt, int verbose, word_t password,
153156
const word_t *input, word_t *output, int count);

0 commit comments

Comments
 (0)