1 | /*
|
---|
2 | =============================================================================
|
---|
3 | dirfns.c -- miscellaneous directory functions
|
---|
4 | Version 4 -- 1987-06-04 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "all.h"
|
---|
9 |
|
---|
10 | extern int32_t sprintf(int8_t *str, int8_t *fmt, ...);
|
---|
11 |
|
---|
12 | static int8_t atrcons[] = "ADVSHR";
|
---|
13 |
|
---|
14 | /*
|
---|
15 | =============================================================================
|
---|
16 | atrstr(atr, s) -- convert attributes to character string
|
---|
17 | =============================================================================
|
---|
18 | */
|
---|
19 |
|
---|
20 | int8_t *atrstr(int16_t atr, int8_t s[])
|
---|
21 | {
|
---|
22 | register int16_t i, j;
|
---|
23 |
|
---|
24 | i = 0x20;
|
---|
25 |
|
---|
26 | for (j = 0; j < 6; j++) {
|
---|
27 |
|
---|
28 | if (atr & i)
|
---|
29 | s[j] = atrcons[j];
|
---|
30 | else
|
---|
31 | s[j] = '-';
|
---|
32 |
|
---|
33 | i >>= 1;
|
---|
34 | }
|
---|
35 |
|
---|
36 | s[j] = '\0';
|
---|
37 | return(s);
|
---|
38 | }
|
---|
39 |
|
---|
40 | /* |
---|
41 | */
|
---|
42 |
|
---|
43 | static int8_t *mnames[] = {
|
---|
44 |
|
---|
45 | "???",
|
---|
46 | "Jan",
|
---|
47 | "Feb",
|
---|
48 | "Mar",
|
---|
49 | "Apr",
|
---|
50 | "May",
|
---|
51 | "Jun",
|
---|
52 | "Jul",
|
---|
53 | "Aug",
|
---|
54 | "Sep",
|
---|
55 | "Oct",
|
---|
56 | "Nov",
|
---|
57 | "Dec"
|
---|
58 | };
|
---|
59 |
|
---|
60 | /*
|
---|
61 | =============================================================================
|
---|
62 | mname - convert month number to month name
|
---|
63 | =============================================================================
|
---|
64 | */
|
---|
65 |
|
---|
66 | int8_t *mname(int16_t n)
|
---|
67 | {
|
---|
68 | return((n < 1 || n > 12) ? mnames[0] : mnames[n]);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /* |
---|
72 | */
|
---|
73 |
|
---|
74 | /*
|
---|
75 | =============================================================================
|
---|
76 | dtunpk(din, tin, s, fmt) -- unpack the date and time from DOS format
|
---|
77 | into "yyyy-mm-dd hh:mm", "yyyy mmm dd hh:mm", or "mmm dd yyyy hh:mm"
|
---|
78 | format.
|
---|
79 | =============================================================================
|
---|
80 | */
|
---|
81 |
|
---|
82 | int8_t *dtunpk(int16_t din, int16_t tin, int16_t fmt, int8_t *s)
|
---|
83 | {
|
---|
84 | register int16_t ftm, fdt;
|
---|
85 |
|
---|
86 | ftm = ((tin << 8) & 0xFF00) | ((tin >> 8) & 0x00FF);
|
---|
87 | fdt = ((din << 8) & 0xFF00) | ((din >> 8) & 0x00FF);
|
---|
88 |
|
---|
89 | switch (fmt) {
|
---|
90 |
|
---|
91 | case 0: /* yyyy-mm-dd hh:mm format */
|
---|
92 |
|
---|
93 | sprintf(s, "%04d-%02d-%02d %02d:%02d",
|
---|
94 | 1980 + ((fdt >> 9) & 0x7F),
|
---|
95 | (fdt >> 5) & 0xF,
|
---|
96 | fdt & 0x1F,
|
---|
97 | (ftm >> 11) & 0x1F,
|
---|
98 | (ftm >> 5) & 0x3F
|
---|
99 | );
|
---|
100 |
|
---|
101 | s[16] = '\0';
|
---|
102 | break;
|
---|
103 |
|
---|
104 | case 1: /* yyyy mmm dd hh:mm format */
|
---|
105 | default:
|
---|
106 |
|
---|
107 | sprintf(s, "%04d %s %-2d %02d:%02d",
|
---|
108 | 1980 + ((fdt >> 9) & 0x7F),
|
---|
109 | mname((fdt >> 5) & 0xF),
|
---|
110 | fdt & 0x1F,
|
---|
111 | (ftm >> 11) & 0x1F,
|
---|
112 | (ftm >> 5) & 0x3F
|
---|
113 | );
|
---|
114 |
|
---|
115 | s[17] = '\0';
|
---|
116 | break;
|
---|
117 |
|
---|
118 | /* |
---|
119 | */
|
---|
120 |
|
---|
121 | case 2: /* mmm dd yyyy hh:mm format */
|
---|
122 |
|
---|
123 | sprintf(s, "%s %2d %04d %02d:%02d",
|
---|
124 | mname((fdt >> 5) & 0xF),
|
---|
125 | fdt & 0x1F,
|
---|
126 | 1980 + ((fdt >> 9) & 0x7F),
|
---|
127 | (ftm >> 11) & 0x1F,
|
---|
128 | (ftm >> 5) & 0x3F
|
---|
129 | );
|
---|
130 |
|
---|
131 | s[17] = '\0';
|
---|
132 | break;
|
---|
133 | }
|
---|
134 |
|
---|
135 | return(s);
|
---|
136 | }
|
---|
137 |
|
---|