|
| 1 | +/* |
| 2 | + * t1204.c -- INT 2Fh / AX=1204h NORMALIZE PATH SEPARATOR |
| 3 | + * |
| 4 | + * RBIL (https://fd.lod.bz/rbil/interrup/dos_kernel/2f1204.html): |
| 5 | + * AX = 1204h |
| 6 | + * STACK: WORD character to normalize |
| 7 | + * Return: AL = normalized character ('/' -> '\', others unchanged) |
| 8 | + * ZF set if character is a path separator ('\', '/', or SWITCHAR) |
| 9 | + * STACK unchanged |
| 10 | + * |
| 11 | + * NOTE ON CALLING CONVENTION: |
| 12 | + * This function is unique among INT 2Fh/12xx subfunctions: the input |
| 13 | + * character is passed as a WORD pushed onto the stack BEFORE the INT 2Fh, |
| 14 | + * not in any register. |
| 15 | + * |
| 16 | + * Care registers: |
| 17 | + * AL -- normalized character (CARE_AL) |
| 18 | + * ZF -- set iff path separator (CARE_ZF) |
| 19 | + * All other output registers are don't-cares. |
| 20 | + * |
| 21 | + * Two modes (see testlib.h): |
| 22 | + * ref REFERENCE: run all cases, write 1204.ref, verbose stdout |
| 23 | + * default / test TEST: read 1204.ref, run all cases, write 1204.tst |
| 24 | + * |
| 25 | + * Build: |
| 26 | + * wcl -zq -q -ms -i=.. t1204.c ..\testlib.c |
| 27 | + * |
| 28 | + * Usage: |
| 29 | + * T1204 ref (reference mode, writes 1204.ref) |
| 30 | + * T1204 test (test mode, reads 1204.ref, writes 1204.tst) |
| 31 | + */ |
| 32 | + |
| 33 | +#include "../greatest.h" |
| 34 | +#include "../testlib.h" |
| 35 | + |
| 36 | +#include <dos.h> |
| 37 | +#include <stdio.h> |
| 38 | +#include <string.h> |
| 39 | + |
| 40 | + |
| 41 | +const char *g_tbasename = "1204"; /* declared by test e.g. "1204" */ |
| 42 | + |
| 43 | + |
| 44 | +/* ---- |
| 45 | + * We care about AL (normalized char) and ZF (separator flag). |
| 46 | + * All other output registers are don't-cares. |
| 47 | + * ---- */ |
| 48 | +#define CARE_1204 (CARE_AL | CARE_FLAGS) |
| 49 | + |
| 50 | + |
| 51 | +/* ------------------------------------------------------------------ */ |
| 52 | +/* Helper: fill a PROBE for recording purposes. */ |
| 53 | +/* after.ax low byte = AL result; after.flags = FLAGS result. */ |
| 54 | +/* ------------------------------------------------------------------ */ |
| 55 | +static void setup_1204(PROBE *p, unsigned char ch) |
| 56 | +{ |
| 57 | + memset(p, 0, sizeof(*p)); |
| 58 | + p->before.ax = 0x1204; |
| 59 | + p->before.cx = (unsigned short)ch; /* input char stored in CX for log */ |
| 60 | + p->value = (unsigned short)ch; |
| 61 | +} |
| 62 | + |
| 63 | +/* ------------------------------------------------------------------ */ |
| 64 | +/* Core test runner for one character. */ |
| 65 | +/* ------------------------------------------------------------------ */ |
| 66 | +static int run_char_case(const char *name, unsigned char ch) |
| 67 | +{ |
| 68 | + PROBE p; |
| 69 | + |
| 70 | + setup_1204(&p, ch); |
| 71 | + |
| 72 | + if (g_ref_mode) { |
| 73 | + printf("INPUT: ch=0x%02X ('%c')\n", |
| 74 | + (unsigned)ch, |
| 75 | + (ch >= 0x20 && ch < 0x7F) ? (char)ch : '.' |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + return run_case(name, &p, CARE_1204, NULL); |
| 80 | +} |
| 81 | + |
| 82 | +/* ------------------------------------------------------------------ */ |
| 83 | +/* Test suites */ |
| 84 | +/* ------------------------------------------------------------------ */ |
| 85 | + |
| 86 | +/* |
| 87 | + * Path separator characters: '/', '\', and the default SWITCHAR '/'. |
| 88 | + * All must return AL='\' (5Ch) and ZF=1. |
| 89 | + */ |
| 90 | +TEST test_separators(void) |
| 91 | +{ |
| 92 | + char name[TC_NAME_MAX]; |
| 93 | + |
| 94 | + /* Forward slash -- must be converted to backslash, ZF=1 */ |
| 95 | + sprintf(name, "1204_fwdslash"); |
| 96 | + ASSERT(run_char_case(name, '/')); |
| 97 | + |
| 98 | + /* Backslash -- already canonical, ZF=1 */ |
| 99 | + sprintf(name, "1204_backslash"); |
| 100 | + ASSERT(run_char_case(name, '\\')); |
| 101 | + |
| 102 | + PASS(); |
| 103 | +} |
| 104 | + |
| 105 | +/* |
| 106 | + * Non-separator printable ASCII characters: AL unchanged, ZF=0. |
| 107 | + */ |
| 108 | +TEST test_non_separators(void) |
| 109 | +{ |
| 110 | + char name[TC_NAME_MAX]; |
| 111 | + unsigned int ch; |
| 112 | + |
| 113 | + /* Letters */ |
| 114 | + sprintf(name, "1204_letter_A"); |
| 115 | + ASSERT(run_char_case(name, 'A')); |
| 116 | + sprintf(name, "1204_letter_a"); |
| 117 | + ASSERT(run_char_case(name, 'a')); |
| 118 | + sprintf(name, "1204_letter_Z"); |
| 119 | + ASSERT(run_char_case(name, 'Z')); |
| 120 | + sprintf(name, "1204_letter_z"); |
| 121 | + ASSERT(run_char_case(name, 'z')); |
| 122 | + |
| 123 | + /* Digits */ |
| 124 | + sprintf(name, "1204_digit_0"); |
| 125 | + ASSERT(run_char_case(name, '0')); |
| 126 | + sprintf(name, "1204_digit_9"); |
| 127 | + ASSERT(run_char_case(name, '9')); |
| 128 | + |
| 129 | + /* Common filename chars */ |
| 130 | + sprintf(name, "1204_dot"); |
| 131 | + ASSERT(run_char_case(name, '.')); |
| 132 | + sprintf(name, "1204_colon"); |
| 133 | + ASSERT(run_char_case(name, ':')); |
| 134 | + sprintf(name, "1204_space"); |
| 135 | + ASSERT(run_char_case(name, ' ')); |
| 136 | + sprintf(name, "1204_underscore"); |
| 137 | + ASSERT(run_char_case(name, '_')); |
| 138 | + sprintf(name, "1204_dash"); |
| 139 | + ASSERT(run_char_case(name, '-')); |
| 140 | + sprintf(name, "1204_tilde"); |
| 141 | + ASSERT(run_char_case(name, '~')); |
| 142 | + sprintf(name, "1204_bang"); |
| 143 | + ASSERT(run_char_case(name, '!')); |
| 144 | + sprintf(name, "1204_hash"); |
| 145 | + ASSERT(run_char_case(name, '#')); |
| 146 | + sprintf(name, "1204_dollar"); |
| 147 | + ASSERT(run_char_case(name, '$')); |
| 148 | + sprintf(name, "1204_percent"); |
| 149 | + ASSERT(run_char_case(name, '%')); |
| 150 | + sprintf(name, "1204_ampersand"); |
| 151 | + ASSERT(run_char_case(name, '&')); |
| 152 | + sprintf(name, "1204_at"); |
| 153 | + ASSERT(run_char_case(name, '@')); |
| 154 | + |
| 155 | + /* -All- printable ASCII except '/' and '\' */ |
| 156 | + /* *** we only print some to avoid excessive tests */ |
| 157 | + for (ch = 0x20; ch <= 0x7E; ch+=3) { |
| 158 | + if (ch == '/' || ch == '\\') |
| 159 | + continue; |
| 160 | + sprintf(name, "1204_ascii_0x%02X", ch); |
| 161 | + ASSERT(run_char_case(name, (unsigned char)ch)); |
| 162 | + } |
| 163 | + |
| 164 | + PASS(); |
| 165 | +} |
| 166 | + |
| 167 | +/* |
| 168 | + * Control characters and NUL: AL unchanged, ZF=0. |
| 169 | + */ |
| 170 | +TEST test_control_chars(void) |
| 171 | +{ |
| 172 | + char name[TC_NAME_MAX]; |
| 173 | + |
| 174 | + sprintf(name, "1204_nul"); |
| 175 | + ASSERT(run_char_case(name, 0x00)); |
| 176 | + |
| 177 | + sprintf(name, "1204_ctrl_01"); |
| 178 | + ASSERT(run_char_case(name, 0x01)); |
| 179 | + |
| 180 | + sprintf(name, "1204_ctrl_1A_EOF"); /* Ctrl-Z / EOF */ |
| 181 | + ASSERT(run_char_case(name, 0x1A)); |
| 182 | + |
| 183 | + sprintf(name, "1204_ctrl_1B_ESC"); /* ESC */ |
| 184 | + ASSERT(run_char_case(name, 0x1B)); |
| 185 | + |
| 186 | + sprintf(name, "1204_ctrl_1F"); |
| 187 | + ASSERT(run_char_case(name, 0x1F)); |
| 188 | + |
| 189 | + sprintf(name, "1204_del_7F"); |
| 190 | + ASSERT(run_char_case(name, 0x7F)); |
| 191 | + |
| 192 | + PASS(); |
| 193 | +} |
| 194 | + |
| 195 | +/* |
| 196 | + * High-byte characters (0x80..0xFF): AL unchanged, ZF=0. |
| 197 | + * These are DOS codepage characters; none are path separators. |
| 198 | + */ |
| 199 | +TEST test_high_bytes(void) |
| 200 | +{ |
| 201 | + char name[TC_NAME_MAX]; |
| 202 | + unsigned int ch; |
| 203 | + |
| 204 | + /* Spot-check a few */ |
| 205 | + sprintf(name, "1204_high_80"); |
| 206 | + ASSERT(run_char_case(name, 0x80)); |
| 207 | + |
| 208 | + sprintf(name, "1204_high_FE"); |
| 209 | + ASSERT(run_char_case(name, 0xFE)); |
| 210 | + |
| 211 | + sprintf(name, "1204_high_FF"); |
| 212 | + ASSERT(run_char_case(name, 0xFF)); |
| 213 | + |
| 214 | + /* Sweep 0x80..0xFF */ |
| 215 | + /* *** we only print some to avoid excess tests */ |
| 216 | + for (ch = 0x80; ch <= 0xFF; ch+=3) { |
| 217 | + sprintf(name, "1204_high_0x%02X", ch); |
| 218 | + ASSERT(run_char_case(name, (unsigned char)ch)); |
| 219 | + } |
| 220 | + |
| 221 | + PASS(); |
| 222 | +} |
| 223 | + |
| 224 | +/* |
| 225 | + * Boundary: characters immediately adjacent to '/' (0x2F) and '\' (0x5C). |
| 226 | + */ |
| 227 | +TEST test_adjacent_to_separators(void) |
| 228 | +{ |
| 229 | + char name[TC_NAME_MAX]; |
| 230 | + |
| 231 | + sprintf(name, "1204_before_fwdslash"); /* 0x2E = '.' */ |
| 232 | + ASSERT(run_char_case(name, 0x2E)); |
| 233 | + |
| 234 | + sprintf(name, "1204_after_fwdslash"); /* 0x30 = '0' */ |
| 235 | + ASSERT(run_char_case(name, 0x30)); |
| 236 | + |
| 237 | + sprintf(name, "1204_before_backslash"); /* 0x5B = '[' */ |
| 238 | + ASSERT(run_char_case(name, 0x5B)); |
| 239 | + |
| 240 | + sprintf(name, "1204_after_backslash"); /* 0x5D = ']' */ |
| 241 | + ASSERT(run_char_case(name, 0x5D)); |
| 242 | + |
| 243 | + PASS(); |
| 244 | +} |
| 245 | + |
| 246 | +/* ------------------------------------------------------------------ */ |
| 247 | +/* Suite -- called in main to run tests */ |
| 248 | +/* ------------------------------------------------------------------ */ |
| 249 | + |
| 250 | +SUITE(suite) |
| 251 | +{ |
| 252 | + RUN_TEST(test_separators); |
| 253 | + RUN_TEST(test_non_separators); |
| 254 | + RUN_TEST(test_control_chars); |
| 255 | + RUN_TEST(test_high_bytes); |
| 256 | + RUN_TEST(test_adjacent_to_separators); |
| 257 | +} |
0 commit comments