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

Last change on this file since e15f784 was 8973acd, checked in by Thomas Lopatic <thomas@…>, 7 years ago

No more warnings in libcio.

  • Property mode set to 100644
File size: 2.3 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
38static int8_t *mnames[] = {
39
40 "???",
41 "Jan",
42 "Feb",
43 "Mar",
44 "Apr",
45 "May",
46 "Jun",
47 "Jul",
48 "Aug",
49 "Sep",
50 "Oct",
51 "Nov",
52 "Dec"
53 };
54
55/*
56 =============================================================================
57 mname - convert month number to month name
58 =============================================================================
59*/
60
61int8_t *mname(int16_t n)
62{
63 return((n < 1 || n > 12) ? mnames[0] : mnames[n]);
64}
65
66/*
67 =============================================================================
68 dtunpk(din, tin, s, fmt) -- unpack the date and time from DOS format
69 into "yyyy-mm-dd hh:mm", "yyyy mmm dd hh:mm", or "mmm dd yyyy hh:mm"
70 format.
71 =============================================================================
72*/
73
74int8_t *dtunpk(uint16_t din, uint16_t tin, int8_t *s, int16_t fmt)
75{
76 register uint16_t ftm, fdt;
77
78 ftm = micon16(tin);
79 fdt = micon16(din);
80
81 switch (fmt) {
82
83 case 0: /* yyyy-mm-dd hh:mm format */
84
85 sprintf(s, "%04d-%02d-%02d %02d:%02d",
86 1980 + ((fdt >> 9) & 0x7F),
87 (fdt >> 5) & 0xF,
88 fdt & 0x1F,
89 (ftm >> 11) & 0x1F,
90 (ftm >> 5) & 0x3F
91 );
92
93 s[16] = '\0';
94 break;
95
96 case 1: /* yyyy mmm dd hh:mm format */
97 default:
98
99 sprintf(s, "%04d %s %-2d %02d:%02d",
100 1980 + ((fdt >> 9) & 0x7F),
101 mname((fdt >> 5) & 0xF),
102 fdt & 0x1F,
103 (ftm >> 11) & 0x1F,
104 (ftm >> 5) & 0x3F
105 );
106
107 s[17] = '\0';
108 break;
109
110 case 2: /* mmm dd yyyy hh:mm format */
111
112 sprintf(s, "%s %2d %04d %02d:%02d",
113 mname((fdt >> 5) & 0xF),
114 fdt & 0x1F,
115 1980 + ((fdt >> 9) & 0x7F),
116 (ftm >> 11) & 0x1F,
117 (ftm >> 5) & 0x3F
118 );
119
120 s[17] = '\0';
121 break;
122 }
123
124 return(s);
125}
126
Note: See TracBrowser for help on using the repository browser.