source: buchla-68k/libcio/dirfns.c@ d21fc6f

Last change on this file since d21fc6f was 33b5477, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Fixed argument order.

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