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