| 1 |
/* |
| 2 |
* Copyright (c) 1987, 1988 by Michael J. Roberts. All Rights Reserved. |
| 3 |
* |
| 4 |
* Please see the accompanying license file, LICENSE.TXT, for information |
| 5 |
* on using and copying this software. |
| 6 |
*/ |
| 7 |
/* |
| 8 |
|
| 9 |
Name |
| 10 |
---- |
| 11 |
|
| 12 |
osatari - Operating System dependent definitions for Atari ST/TT/Falcon |
| 13 |
|
| 14 |
Notes |
| 15 |
----- |
| 16 |
|
| 17 |
This version of osatari.c is a complete rewrite of the version 1.X |
| 18 |
file. The output code has been changed from VDI to VT52, resulting in |
| 19 |
a substantial speed improvement when under running software screen |
| 20 |
accelerators, and improved portability. This version only assumes a VT52 |
| 21 |
window that is at least 80x24. |
| 22 |
|
| 23 |
This file was designed and tested with GCC 2.3.1 Patchlevel 1, but |
| 24 |
in theory should work with most Atari compilers since it uses very few |
| 25 |
OS fuctions. |
| 26 |
|
| 27 |
Dave Baggett |
| 28 |
[email protected] |
| 29 |
|
| 30 |
Worries |
| 31 |
------- |
| 32 |
|
| 33 |
o Older versions of the desktop upcase all the command line args. This will |
| 34 |
cause problems in tcd.c since it only checks for lower case args. |
| 35 |
|
| 36 |
o Should be able to disable VT52 stuff in compiler so errors can be saved |
| 37 |
to a file. |
| 38 |
|
| 39 |
o tc -p does not work for some reason, though tc -p -q does and tc -p uu2.t |
| 40 |
does as well. This is a problem with tcd.c |
| 41 |
|
| 42 |
|
| 43 |
Modifications |
| 44 |
------------- |
| 45 |
|
| 46 |
26-Jul-93 dmb First attempt at fixing monochrome problems. |
| 47 |
Updated to GCC 2.4.4 P1. (But it wouldn't |
| 48 |
build with it, so went back to 2.3.1) |
| 49 |
23-Jan-93 dmb Added file selector code. |
| 50 |
19-Jan-93 dmb Curses turned out to be too slow, so I wrote the |
| 51 |
os_ routins using VT52 codes. Even supports |
| 52 |
the DOS colors! |
| 53 |
18-Jan-93 dmb Updated for TADS 2 and GCC 2.3.1 P1 |
| 54 |
* |
| 55 |
*/ |
| 56 |
|
| 57 |
#include "os.h" /* will include osatari.h for us since -DATARI */ |
| 58 |
|
| 59 |
#include <alloc.h> |
| 60 |
#include <ctype.h> |
| 61 |
#include <osbind.h> |
| 62 |
#include <stdio.h> |
| 63 |
#include <string.h> |
| 64 |
#include <aesbind.h> /* Get shel_read */ |
| 65 |
#include <gemfast.h> /* Get graf_mouse */ |
| 66 |
|
| 67 |
/* |
| 68 |
* Use VT52 shortcuts whenever possible instead of repainting the screen |
| 69 |
* "by hand." This makes text output go much faster when a software screen |
| 70 |
* accelerator is installed. If screen output is somehow hosed, try |
| 71 |
* turning this off; when it's off, ALL screen manipulation is handled |
| 72 |
* by vt_redraw. |
| 73 |
*/ |
| 74 |
#define VT_OPTIMIZE |
| 75 |
|
| 76 |
/* |
| 77 |
* Big stack -- extra safe |
| 78 |
*/ |
| 79 |
long _stksize = 48000L; |
| 80 |
|
| 81 |
/* |
| 82 |
* Ctrl-C hit? |
| 83 |
*/ |
| 84 |
static int break_set = 0; |
| 85 |
|
| 86 |
/* |
| 87 |
* Assume medium rez, where we have four colors. |
| 88 |
* Our palette is chosen simply so that we can get the same color |
| 89 |
* combinations we have on the PC. |
| 90 |
* |
| 91 |
* A fancier implementation would read the trcolor.dat file like |
| 92 |
* the DOS version does. |
| 93 |
*/ |
| 94 |
static int drez; |
| 95 |
static int dpalette[16]; |
| 96 |
static int palette[16] = { |
| 97 |
0x000, 0x007, 0x777, 0x555, |
| 98 |
0x000, 0x000, 0x000, 0x000, |
| 99 |
0x000, 0x000, 0x000, 0x000, |
| 100 |
0x000, 0x000, 0x000, 0x000 |
| 101 |
}; |
| 102 |
#define osBLACK 0 |
| 103 |
#define osBLUE 1 |
| 104 |
#define osBRIGHTWHITE 2 |
| 105 |
#define osWHITE 3 |
| 106 |
|
| 107 |
/* |
| 108 |
* In monochrome mode, the color indices are different. |
| 109 |
*/ |
| 110 |
#define osmNORMAL 0 |
| 111 |
#define osmREVERSE 1 |
| 112 |
|
| 113 |
/* |
| 114 |
* We combine two colors into a color byte (foreground and background). |
| 115 |
*/ |
| 116 |
#define colbyte(f, b) (((f & 3) << 2) | (b & 3)) |
| 117 |
#define bytecol(byte, f, b) ((f = (byte >> 2) & 3), (b = (byte & 3))) |
| 118 |
|
| 119 |
#define VTC (drez == 2 ? 0 : 64) |
| 120 |
|
| 121 |
/* |
| 122 |
* Our own private concept of the screen and cursor. |
| 123 |
*/ |
| 124 |
#define ROWS 24 |
| 125 |
#define COLS 80 |
| 126 |
static char *screen[ROWS]; |
| 127 |
static char *colors[ROWS]; |
| 128 |
static int X, Y; |
| 129 |
|
| 130 |
static char pathbuf[70]; |
| 131 |
|
| 132 |
static void break_handler(); |
| 133 |
static char *file_select(); |
| 134 |
static char *path2fname(); |
| 135 |
static void remove_wildcard(); |
| 136 |
|
| 137 |
/* |
| 138 |
* Make sure chars get typecast to int for this function. |
| 139 |
*/ |
| 140 |
int vt_color(int c); |
| 141 |
|
| 142 |
curs_hide() |
| 143 |
{ |
| 144 |
Cursconf(0, 0); |
| 145 |
} |
| 146 |
|
| 147 |
curs_show() |
| 148 |
{ |
| 149 |
Cursconf(1, 0); |
| 150 |
} |
| 151 |
|
| 152 |
/* |
| 153 |
* Set up for VT52 screen handling. Called by os_init. |
| 154 |
*/ |
| 155 |
vt_init() |
| 156 |
{ |
| 157 |
register int row, col; |
| 158 |
|
| 159 |
/* |
| 160 |
* Init globals used by the system. |
| 161 |
*/ |
| 162 |
score_column = COLS - 10; |
| 163 |
max_line = ROWS - 1; |
| 164 |
max_column = COLS - 1; |
| 165 |
G_os_pagelength = max_line - text_line - 1; |
| 166 |
G_os_linewidth = COLS + 1; |
| 167 |
|
| 168 |
/* |
| 169 |
* Allocate our private screen data structure. |
| 170 |
*/ |
| 171 |
for (row = 0; row < ROWS; row++) { |
| 172 |
screen[row] = (char *) calloc(COLS + 1, 1); |
| 173 |
colors[row] = (char *) calloc(COLS, 1); |
| 174 |
for (col = 0; col < COLS; col++) { |
| 175 |
screen[row][col] = ' '; |
| 176 |
colors[row][col] = colbyte(osWHITE, osBLACK); |
| 177 |
} |
| 178 |
screen[row][COLS] = 0; |
| 179 |
} |
| 180 |
|
| 181 |
vt_setup(); |
| 182 |
} |
| 183 |
|
| 184 |
/* |
| 185 |
* Set up screen for VT52. |
| 186 |
* This is called by os_askfile to restore the screen to the normal |
| 187 |
* state, so it shouldn't allocate data structures. |
| 188 |
*/ |
| 189 |
vt_setup() |
| 190 |
{ |
| 191 |
int i; |
| 192 |
|
| 193 |
/* |
| 194 |
* Get rid of the mouse |
| 195 |
*/ |
| 196 |
graf_mouse(M_OFF, NULL); |
| 197 |
|
| 198 |
/* |
| 199 |
* Get desktop resolution. If monochrome, note the fact so that |
| 200 |
* we can make sure our color choices get set correctly later on. |
| 201 |
* If low resolution, change to medium resolution automagically. |
| 202 |
* |
| 203 |
* If any other resolution, don't do anything different, and hope |
| 204 |
* things work out OK. |
| 205 |
*/ |
| 206 |
drez = Getrez(); |
| 207 |
if (drez == 0) |
| 208 |
Setscreen(-1L, -1L, 1); |
| 209 |
|
| 210 |
if (drez != 2) { |
| 211 |
/* |
| 212 |
* Get desktop palette. |
| 213 |
*/ |
| 214 |
for (i = 0; i < 16; i++) |
| 215 |
dpalette[i] = Setcolor(i, -1); |
| 216 |
|
| 217 |
/* |
| 218 |
* Set our palette. |
| 219 |
*/ |
| 220 |
Setpalette(palette); |
| 221 |
|
| 222 |
/* |
| 223 |
* Tell the rest of the system what good colors |
| 224 |
* are for various things. |
| 225 |
*/ |
| 226 |
sdesc_color = colbyte(osWHITE, osBLUE); |
| 227 |
ldesc_color = colbyte(osBLACK, osWHITE); |
| 228 |
debug_color = colbyte(osBRIGHTWHITE, osBLACK); |
| 229 |
text_color = colbyte(osWHITE, osBLACK); |
| 230 |
text_bold_color = colbyte(osBRIGHTWHITE, osBLACK); |
| 231 |
text_normal_color = text_color; |
| 232 |
} |
| 233 |
else { |
| 234 |
/* |
| 235 |
* Monochrome -- note different color name constants |
| 236 |
*/ |
| 237 |
sdesc_color = colbyte(osmREVERSE, osmREVERSE); |
| 238 |
ldesc_color = colbyte(osmREVERSE, osmREVERSE); |
| 239 |
debug_color = colbyte(osmNORMAL, osmNORMAL); |
| 240 |
text_color = colbyte(osmNORMAL, osmNORMAL); |
| 241 |
text_bold_color = colbyte(osmREVERSE, osmREVERSE); |
| 242 |
text_normal_color = text_color; |
| 243 |
} |
| 244 |
|
| 245 |
/* |
| 246 |
* Set default text color |
| 247 |
*/ |
| 248 |
vt_color(text_color); |
| 249 |
|
| 250 |
/* |
| 251 |
* Clear the screen, set to no-wrap mode, and enable cursor. |
| 252 |
* Also, set drawing colors to normal. |
| 253 |
*/ |
| 254 |
Cconws("\033E\033w\033e"); |
| 255 |
X = 0; |
| 256 |
Y = 0; |
| 257 |
|
| 258 |
/* |
| 259 |
* Make the cursor not blink. |
| 260 |
*/ |
| 261 |
Cursconf(2, 0); |
| 262 |
} |
| 263 |
|
| 264 |
vt_term() |
| 265 |
{ |
| 266 |
vt_cleanup(); |
| 267 |
} |
| 268 |
|
| 269 |
/* |
| 270 |
* Cleanup -- restore palette and sane VT52 state. |
| 271 |
*/ |
| 272 |
vt_cleanup() |
| 273 |
{ |
| 274 |
/* |
| 275 |
* Restore desktop resolution (if we switched). |
| 276 |
*/ |
| 277 |
if (drez != Getrez()) |
| 278 |
Setscreen(-1L, -1L, drez); |
| 279 |
|
| 280 |
if (drez != 2) { |
| 281 |
/* |
| 282 |
* Restore desktop palette. |
| 283 |
*/ |
| 284 |
Setpalette(dpalette); |
| 285 |
|
| 286 |
Cconws("\033b"); |
| 287 |
Cconout(3 + VTC); |
| 288 |
Cconws("\033c"); |
| 289 |
Cconout(0 + VTC); |
| 290 |
} |
| 291 |
|
| 292 |
/* |
| 293 |
* Bring the mouse back |
| 294 |
*/ |
| 295 |
graf_mouse(M_ON, NULL); |
| 296 |
|
| 297 |
/* |
| 298 |
* Make the cursor visible |
| 299 |
*/ |
| 300 |
curs_show(); |
| 301 |
} |
| 302 |
|
| 303 |
vt_putcolor(buf, pos, c) |
| 304 |
char *buf; |
| 305 |
int pos; |
| 306 |
int c; |
| 307 |
{ |
| 308 |
register int f, b; |
| 309 |
|
| 310 |
bytecol(c, f, b); |
| 311 |
if (drez == 2) { |
| 312 |
if (f == osmREVERSE) { |
| 313 |
buf[pos++] = '\033'; |
| 314 |
buf[pos++] = 'p'; |
| 315 |
} |
| 316 |
else { |
| 317 |
buf[pos++] = '\033'; |
| 318 |
buf[pos++] = 'q'; |
| 319 |
} |
| 320 |
} |
| 321 |
else { |
| 322 |
buf[pos++] = '\033'; |
| 323 |
buf[pos++] = 'b'; |
| 324 |
buf[pos++] = f + VTC; |
| 325 |
buf[pos++] = '\033'; |
| 326 |
buf[pos++] = 'c'; |
| 327 |
buf[pos++] = b + VTC; |
| 328 |
} |
| 329 |
|
| 330 |
return pos; |
| 331 |
} |
| 332 |
|
| 333 |
/* |
| 334 |
* Set the color of subsequent text. |
| 335 |
*/ |
| 336 |
vt_color(c) |
| 337 |
register int c; |
| 338 |
{ |
| 339 |
register int f, b; |
| 340 |
|
| 341 |
bytecol(c, f, b); |
| 342 |
|
| 343 |
/* |
| 344 |
* In monochrome mode, we never set colors. |
| 345 |
* Instead, we turn on and off reverse video mode. |
| 346 |
*/ |
| 347 |
if (drez == 2) { |
| 348 |
if (f == osmREVERSE) |
| 349 |
Cconws("\033p"); |
| 350 |
else |
| 351 |
Cconws("\033q"); |
| 352 |
} |
| 353 |
else { |
| 354 |
Cconws("\033b"); |
| 355 |
Cconout(f + VTC); |
| 356 |
Cconws("\033c"); |
| 357 |
Cconout(b + VTC); |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
/* |
| 362 |
* Update the real screen so it matches our idea of what's on the screen. |
| 363 |
*/ |
| 364 |
vt_flush() |
| 365 |
{ |
| 366 |
vt_redraw(0, ROWS - 1); |
| 367 |
} |
| 368 |
|
| 369 |
/* |
| 370 |
* Redraw a portion of the screen. This is a bit tricky because we have |
| 371 |
* to make sure we get the colors right, but we don't want to output a |
| 372 |
* character at a time. We build a string for each line of the region |
| 373 |
* that contains all the text and the minimum necessary color change |
| 374 |
* escape sequences. |
| 375 |
*/ |
| 376 |
vt_redraw(top, bottom) |
| 377 |
int top, bottom; |
| 378 |
{ |
| 379 |
static char ds[7 * COLS + 1] = {0}; |
| 380 |
|
| 381 |
register int row, col, pos; |
| 382 |
register char **s = screen; |
| 383 |
register char **c = colors; |
| 384 |
int color; |
| 385 |
|
| 386 |
curs_hide(); |
| 387 |
|
| 388 |
/* |
| 389 |
* Position to top line, column zero. |
| 390 |
*/ |
| 391 |
vt_loc(top, 0); |
| 392 |
|
| 393 |
/* |
| 394 |
* Redraw each line between top line and bottom line. |
| 395 |
* We have to build a string from our text and color |
| 396 |
* information so we can write the output a line at a time |
| 397 |
* rather than a character at a time. |
| 398 |
*/ |
| 399 |
color = c[top][0]; |
| 400 |
vt_color(color); |
| 401 |
for (row = top; row <= bottom; row++) { |
| 402 |
Cconws("\033j"); /* save cursor position */ |
| 403 |
|
| 404 |
/* |
| 405 |
* Combine color and text information into a single |
| 406 |
* string for this line. |
| 407 |
*/ |
| 408 |
for (col = 0, pos = 0; col < COLS; col++) { |
| 409 |
/* |
| 410 |
* Do we have to change text color? |
| 411 |
* If so, add the appropriate escape sequence |
| 412 |
* to our string for this line, before the |
| 413 |
* first character to be printed in the new |
| 414 |
* color. |
| 415 |
*/ |
| 416 |
if (c[row][col] != color) { |
| 417 |
register int f, b, nc; |
| 418 |
|
| 419 |
nc = c[row][col]; |
| 420 |
pos = vt_putcolor(ds, pos, nc); |
| 421 |
color = nc; |
| 422 |
} |
| 423 |
|
| 424 |
ds[pos++] = s[row][col]; |
| 425 |
} |
| 426 |
ds[pos] = 0; |
| 427 |
|
| 428 |
Cconws(ds); /* blast the string */ |
| 429 |
Cconws("\033k"); /* restore cursor position */ |
| 430 |
Cconws("\033B"); /* down a line */ |
| 431 |
} |
| 432 |
|
| 433 |
/* |
| 434 |
* Reposition cursor to its former location |
| 435 |
*/ |
| 436 |
vt_loc(Y, X); |
| 437 |
|
| 438 |
curs_show(); |
| 439 |
} |
| 440 |
|
| 441 |
/* |
| 442 |
* Move the VT52 cursor. Note that this has nothing to do with the |
| 443 |
* virtual cursor that TADS tells us to move around -- that's updated |
| 444 |
* by ossloc. |
| 445 |
*/ |
| 446 |
vt_loc(y, x) |
| 447 |
int y, x; |
| 448 |
{ |
| 449 |
Cconws("\033Y"); |
| 450 |
Cconout(y + ' '); |
| 451 |
Cconout(x + ' '); |
| 452 |
} |
| 453 |
|
| 454 |
/* |
| 455 |
* Scroll region down a line. |
| 456 |
* This is equivalent to inserting a line at the top of the region. |
| 457 |
*/ |
| 458 |
ossscu(top, left, bottom, right, blank_color) |
| 459 |
int top, left, bottom, right; |
| 460 |
int blank_color; |
| 461 |
{ |
| 462 |
register int r1, r2, col; |
| 463 |
register char **s = screen; |
| 464 |
register char **c = colors; |
| 465 |
|
| 466 |
curs_hide(); |
| 467 |
|
| 468 |
/* |
| 469 |
* Update our internal version |
| 470 |
*/ |
| 471 |
for (r1 = bottom - 1, r2 = bottom; r1 >= top; r1--, r2--) |
| 472 |
for (col = left; col <= right; col++) { |
| 473 |
s[r2][col] = s[r1][col]; |
| 474 |
c[r2][col] = c[r1][col]; |
| 475 |
} |
| 476 |
for (col = left; col <= right; col++) { |
| 477 |
s[r2][col] = ' '; |
| 478 |
c[r2][col] = blank_color; |
| 479 |
} |
| 480 |
|
| 481 |
/* |
| 482 |
* If we can duplicate the effect of this scroll on the screen |
| 483 |
* with a simple VT52 command, do so; otherwise, refresh by |
| 484 |
* redrawing every affected line. |
| 485 |
*/ |
| 486 |
#ifdef VT_OPTIMIZE |
| 487 |
if (left == 0 && right == COLS - 1 && bottom == ROWS - 1) { |
| 488 |
vt_loc(top, 0); |
| 489 |
vt_color(blank_color); |
| 490 |
Cconws("\033L"); |
| 491 |
vt_loc(Y, X); |
| 492 |
} |
| 493 |
else { |
| 494 |
#endif |
| 495 |
vt_redraw(top, bottom); |
| 496 |
#ifdef VT_OPTIMIZE |
| 497 |
} |
| 498 |
#endif |
| 499 |
|
| 500 |
curs_show(); |
| 501 |
} |
| 502 |
|
| 503 |
/* |
| 504 |
* Scroll region up a line |
| 505 |
* This is equivalent to deleting a line at the top of the region and pulling |
| 506 |
* everything below it up. |
| 507 |
*/ |
| 508 |
ossscr(top, left, bottom, right, blank_color) |
| 509 |
int top, left, bottom, right; |
| 510 |
int blank_color; |
| 511 |
{ |
| 512 |
register int r1, r2, col; |
| 513 |
register char **s = screen; |
| 514 |
register char **c = colors; |
| 515 |
|
| 516 |
curs_hide(); |
| 517 |
|
| 518 |
/* |
| 519 |
* Update our internal version |
| 520 |
*/ |
| 521 |
for (r1 = top, r2 = top + 1; r2 <= bottom; r1++, r2++) |
| 522 |
for (col = left; col <= right; col++) { |
| 523 |
s[r1][col] = s[r2][col]; |
| 524 |
c[r1][col] = c[r2][col]; |
| 525 |
} |
| 526 |
for (col = left; col <= right; col++) { |
| 527 |
s[r1][col] = ' '; |
| 528 |
c[r1][col] = blank_color; |
| 529 |
} |
| 530 |
|
| 531 |
/* |
| 532 |
* If we can duplicate the effect of this scroll on the screen |
| 533 |
* with a simple VT52 command, do so; otherwise, refresh by |
| 534 |
* redrawing every affected line. |
| 535 |
*/ |
| 536 |
#ifdef VT_OPTIMIZE |
| 537 |
if (left == 0 && right == COLS - 1 && bottom == ROWS - 1) { |
| 538 |
vt_loc(top, 0); |
| 539 |
vt_color(blank_color); |
| 540 |
Cconws("\033M"); |
| 541 |
vt_loc(Y, X); |
| 542 |
} |
| 543 |
else { |
| 544 |
#endif |
| 545 |
vt_redraw(top, bottom); |
| 546 |
#ifdef VT_OPTIMIZE |
| 547 |
} |
| 548 |
#endif |
| 549 |
|
| 550 |
curs_show(); |
| 551 |
} |
| 552 |
|
| 553 |
/* |
| 554 |
* Clear region (fill with spaces) |
| 555 |
*/ |
| 556 |
ossclr(top, left, bottom, right, blank_color) |
| 557 |
int top, left, bottom, right; |
| 558 |
int blank_color; |
| 559 |
{ |
| 560 |
register int row, col; |
| 561 |
register char **s = screen; |
| 562 |
register char **c = colors; |
| 563 |
|
| 564 |
curs_hide(); |
| 565 |
|
| 566 |
/* |
| 567 |
* Update our internal version |
| 568 |
*/ |
| 569 |
for (row = top; row <= bottom; row++) |
| 570 |
for (col = left; col <= right; col++) { |
| 571 |
s[row][col] = ' '; |
| 572 |
c[row][col] = blank_color; |
| 573 |
} |
| 574 |
|
| 575 |
/* |
| 576 |
* If we can duplicate the effect of this scroll on the screen |
| 577 |
* with a simple VT52 command, do so; otherwise, refresh by |
| 578 |
* redrawing every affected line. |
| 579 |
*/ |
| 580 |
#ifdef VT_OPTIMIZE |
| 581 |
if (left == 0 && right == COLS - 1 && bottom == ROWS - 1) { |
| 582 |
vt_color(blank_color); |
| 583 |
if (top == 0) { |
| 584 |
Cconws("\033E"); |
| 585 |
vt_loc(Y, X); |
| 586 |
} |
| 587 |
else { |
| 588 |
vt_loc(top, 0); |
| 589 |
Cconws("\033J"); |
| 590 |
vt_loc(Y, X); |
| 591 |
} |
| 592 |
} |
| 593 |
else { |
| 594 |
#endif |
| 595 |
vt_redraw(top, bottom); |
| 596 |
#ifdef VT_OPTIMIZE |
| 597 |
} |
| 598 |
#endif |
| 599 |
|
| 600 |
curs_show(); |
| 601 |
} |
| 602 |
|
| 603 |
/* |
| 604 |
* Locate (input) cursor at given row and column. |
| 605 |
* Nore that this is never used to determine where things are drawn. |
| 606 |
* It's only used for aesthetics; i.e., showing the user where input |
| 607 |
* will be taken from next. |
| 608 |
*/ |
| 609 |
ossloc(row, col) |
| 610 |
int row, col; |
| 611 |
{ |
| 612 |
vt_loc(row, col); |
| 613 |
|
| 614 |
/* |
| 615 |
* Update internal cursor position |
| 616 |
*/ |
| 617 |
X = col; |
| 618 |
Y = row; |
| 619 |
} |
| 620 |
|
| 621 |
/* |
| 622 |
* Display msg with color at coordinates (y, x). |
| 623 |
* The color must be in the range 0 <= color <= 16, and specifies both |
| 624 |
* foreground and background colors. |
| 625 |
*/ |
| 626 |
ossdsp(y, x, color, msg) |
| 627 |
int y, x; |
| 628 |
int color; |
| 629 |
register char *msg; |
| 630 |
{ |
| 631 |
register int col; |
| 632 |
register char *s, *m = msg, *c; |
| 633 |
|
| 634 |
curs_hide(); |
| 635 |
|
| 636 |
if (y < ROWS && x < COLS) { |
| 637 |
s = &screen[y][x]; |
| 638 |
c = &colors[y][x]; |
| 639 |
} |
| 640 |
else |
| 641 |
return; |
| 642 |
|
| 643 |
/* |
| 644 |
* Update our own version of the screen. |
| 645 |
*/ |
| 646 |
for (col = x; *m && col < COLS; col++) { |
| 647 |
*s++ = *m++; |
| 648 |
*c++ = color; |
| 649 |
} |
| 650 |
|
| 651 |
#ifdef VT_OPTIMIZE |
| 652 |
/* |
| 653 |
* Now update the real screen using VT52 codes. |
| 654 |
*/ |
| 655 |
vt_loc(y, x); |
| 656 |
vt_color(color); |
| 657 |
Cconws(msg); |
| 658 |
vt_loc(Y, X); |
| 659 |
#else |
| 660 |
vt_redraw(y, y); |
| 661 |
#endif |
| 662 |
|
| 663 |
curs_show(); |
| 664 |
} |
| 665 |
|
| 666 |
/* |
| 667 |
* Show the user where we are in the compilation. |
| 668 |
*/ |
| 669 |
os_progress(fname, linenum) |
| 670 |
const char *fname; |
| 671 |
unsigned long linenum; |
| 672 |
{ |
| 673 |
static char sl[COLS - 32 + 1]; |
| 674 |
register int i; |
| 675 |
register char *s = sl; |
| 676 |
|
| 677 |
sprintf(sl, "File: %-12s Line: %-7ld", fname, linenum); |
| 678 |
ossdsp(sdesc_line, COLS - 32, sdesc_color, sl); |
| 679 |
} |
| 680 |
|
| 681 |
/* |
| 682 |
* os_init calls the windowing support function that initializes |
| 683 |
* the standard output window. |
| 684 |
*/ |
| 685 |
int |
| 686 |
os_init(argc, argv, prompt, buf, bufsiz) |
| 687 |
int *argc; |
| 688 |
char *argv[]; |
| 689 |
char *prompt; |
| 690 |
char *buf; |
| 691 |
int bufsiz; |
| 692 |
{ |
| 693 |
char *mybuf; |
| 694 |
char tail[128]; |
| 695 |
void os_remext(); |
| 696 |
void os_defext(); |
| 697 |
char *p; |
| 698 |
int l; |
| 699 |
FILE *fp; |
| 700 |
|
| 701 |
appl_init(); |
| 702 |
vt_init(); |
| 703 |
|
| 704 |
/* |
| 705 |
* Clear the screen and put an introductory message on the screen |
| 706 |
*/ |
| 707 |
ossclr(0, 0, max_line, max_column, text_color); |
| 708 |
|
| 709 |
/* |
| 710 |
* Make the status line the right color |
| 711 |
*/ |
| 712 |
ossclr(sdesc_line, 0, sdesc_line, max_column, sdesc_color); |
| 713 |
ossdsp(sdesc_line, 0, sdesc_color, |
| 714 |
"TADS: The Text Adventure Development System"); |
| 715 |
text_lastcol = text_column; |
| 716 |
|
| 717 |
/* |
| 718 |
* Initialize pathbuf with current directory |
| 719 |
*/ |
| 720 |
mybuf = pathbuf; |
| 721 |
*mybuf++ = Dgetdrv() + 'A'; |
| 722 |
*mybuf++ = ':'; |
| 723 |
Dgetpath( mybuf, 0 ); |
| 724 |
mybuf += strlen( mybuf ); |
| 725 |
if ( *( mybuf-1 ) != '\\' ) *mybuf++ = '\\'; |
| 726 |
strcpy( mybuf, "*.SAV" ); |
| 727 |
|
| 728 |
#ifdef USE_SCROLLBACK |
| 729 |
|
| 730 |
osssbini(32767); /* allocate a scrollback buffer */ |
| 731 |
|
| 732 |
#endif /* USE_SCROLLBACK */ |
| 733 |
|
| 734 |
/* |
| 735 |
* Set up the command line's first argument with the root name of |
| 736 |
* the executable, or command tail if present. This allows users to |
| 737 |
* do one of three things: |
| 738 |
* - Run from shells. If we see something in the basepage command |
| 739 |
* line, we'll use that. |
| 740 |
* - Call the run-time TR.TTP, and type the name of the game to play |
| 741 |
* into the TOS-Takes-Parameters dialogue box. |
| 742 |
* - Rename the run-time XYZ.PRG, and call the data file XYZ.GAM; |
| 743 |
* upon double-clicking, we'll try to read XYZ.GAM. |
| 744 |
* Note that the first method overrides the second; the two are |
| 745 |
* mutually exclusive. Note that this bit is skipped if we didn't |
| 746 |
* get enough valid arguments (non-null argv and buf). |
| 747 |
*/ |
| 748 |
if ( argv && buf ) |
| 749 |
{ |
| 750 |
*argc = 2; /* set the new argument count - we'll find something */ |
| 751 |
shel_read( buf, tail ); /* get the program name and argument list */ |
| 752 |
|
| 753 |
#if 0 |
| 754 |
/* |
| 755 |
* Check the basepage entry, because shells will write that. If |
| 756 |
* nothing's there, check the command tail from shel_read. If we |
| 757 |
* find nothing in either place, we'll use the program's name as |
| 758 |
* our argument. |
| 759 |
*/ |
| 760 |
if ( BP->p_cmdlin[1] ) /* use basepage command line if present */ |
| 761 |
strcpy( buf, BP->p_cmdlin+1 ); |
| 762 |
else |
| 763 |
#endif |
| 764 |
if ( tail[0] ) /* use command tail if present */ |
| 765 |
strcpy( buf, tail+1 ); |
| 766 |
/* |
| 767 |
* Clean up the argument - remove leading and trailing junk |
| 768 |
*/ |
| 769 |
for ( p=buf ; isspace( *p ) ; ++p ); |
| 770 |
while (( l=strlen( p )) && ( p[l-1] <= ' ' )) p[l-1] = '\0'; |
| 771 |
argv[1] = p; |
| 772 |
os_remext( buf ); |
| 773 |
|
| 774 |
/* |
| 775 |
* Now see if we can find a .GAM file for this game. If not, |
| 776 |
* ask for a filename in the usual manner. |
| 777 |
*/ |
| 778 |
os_defext( buf, "GAM" ); |
| 779 |
if ( fp = fopen( buf, "rb" )) |
| 780 |
{ |
| 781 |
fclose( fp ); |
| 782 |
} |
| 783 |
else |
| 784 |
{ |
| 785 |
char savpath[128]; |
| 786 |
|
| 787 |
strcpy( savpath, pathbuf ); |
| 788 |
os_remext( pathbuf ); |
| 789 |
if (!strncmp(prompt, "Debug", 5)) os_defext(pathbuf, "TD0"); |
| 790 |
else os_defext( pathbuf, "GAM" ); |
| 791 |
if ( os_askfile( (char *)0, buf, 128, OS_AFP_OPEN, OSFTGAME ) |
| 792 |
!= OS_AFE_SUCCESS ) |
| 793 |
return( 1 ); |
| 794 |
strcpy( pathbuf, savpath ); |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
return 0; |
| 799 |
} |
| 800 |
|
| 801 |
void |
| 802 |
os_uninit() |
| 803 |
{ |
| 804 |
} |
| 805 |
|
| 806 |
void |
| 807 |
os_term(rc) |
| 808 |
int rc; |
| 809 |
{ |
| 810 |
vt_term(); |
| 811 |
exit(rc); |
| 812 |
} |
| 813 |
|
| 814 |
/* |
| 815 |
* os_waitc waits for a character to be typed. It is used to allow the user |
| 816 |
* to say it's OK to continue after a "[More]" prompt. Acceptable keys are |
| 817 |
* OS dependent; ideally, any key will do. The key should not be echoed. |
| 818 |
* |
| 819 |
* Note! This routine must NOT allow scrollback mode to be entered. The |
| 820 |
* problem is that out put may be done on exiting scrollback mode, to restore |
| 821 |
* the status line, which would trash the output now in progress. Hence, |
| 822 |
* do not honor the scrollback key. |
| 823 |
*/ |
| 824 |
void |
| 825 |
os_waitc() |
| 826 |
{ |
| 827 |
int c; |
| 828 |
|
| 829 |
c = os_getc(); /* get a single character from the keyboard */ |
| 830 |
if (!c) |
| 831 |
c = os_getc(); /* if command character, fetch second part, too */ |
| 832 |
} |
| 833 |
|
| 834 |
/* |
| 835 |
* os_getc waits for a single character to be typed and returns its value. |
| 836 |
* The character should not be echoed. It should not be necessary to press |
| 837 |
* the ENTER or RETURN key to terminate the input. |
| 838 |
* |
| 839 |
* When used in RUNTIME mode, we want command line editing. To accommodate |
| 840 |
* this feature, we must return special codes when arrow keys and other |
| 841 |
* command keys are hit. When one of these special command keys is used, |
| 842 |
* os_getc() returns 0, and will return the CMD_xxx value (defined earlier |
| 843 |
* in this file) appropriate to the key on the next call. |
| 844 |
*/ |
| 845 |
int os_getc() |
| 846 |
{ |
| 847 |
static int cmdval; |
| 848 |
long d; |
| 849 |
|
| 850 |
tryAgain: |
| 851 |
if (cmdval) { |
| 852 |
int tmpcmd = cmdval; /* save command for a moment */ |
| 853 |
cmdval = 0; /* clear the flag - next call gets another key */ |
| 854 |
return(tmpcmd); /* return the command that we saved */ |
| 855 |
} |
| 856 |
else |
| 857 |
d = Bconin(2); /* no command pending - get another key */ |
| 858 |
|
| 859 |
#ifdef RUNTIME |
| 860 |
|
| 861 |
switch ((int)(d >> 16)) { |
| 862 |
case 0x4b: |
| 863 |
cmdval = CMD_LEFT; |
| 864 |
break; |
| 865 |
case 0x4d: |
| 866 |
cmdval = CMD_RIGHT; |
| 867 |
break; |
| 868 |
case 0x48: |
| 869 |
cmdval = CMD_UP; |
| 870 |
break; |
| 871 |
case 0x50: |
| 872 |
cmdval = CMD_DOWN; |
| 873 |
break; |
| 874 |
case 0x53: |
| 875 |
cmdval = CMD_DEL; |
| 876 |
break; |
| 877 |
case 0x47: |
| 878 |
cmdval = CMD_HOME; |
| 879 |
break; |
| 880 |
case 0x3b: /* F1 */ |
| 881 |
cmdval = CMD_SCR; |
| 882 |
break; |
| 883 |
case 0x43: /* F9 - page up */ |
| 884 |
cmdval = CMD_PGUP; |
| 885 |
break; |
| 886 |
case 0x44: /* F10 - page down */ |
| 887 |
cmdval = CMD_PGDN; |
| 888 |
break; |
| 889 |
|
| 890 |
default: |
| 891 |
switch ((int)(d & 0xff)) { |
| 892 |
case 1: /* ^A */ |
| 893 |
cmdval = CMD_HOME; |
| 894 |
break; |
| 895 |
case 2: /* ^B */ |
| 896 |
cmdval = CMD_LEFT; |
| 897 |
break; |
| 898 |
case 4: /* ^D */ |
| 899 |
cmdval = CMD_DEL; |
| 900 |
break; |
| 901 |
case 5: /* ^E */ |
| 902 |
cmdval = CMD_END; |
| 903 |
break; |
| 904 |
case 6: /* ^F */ |
| 905 |
cmdval = CMD_RIGHT; |
| 906 |
break; |
| 907 |
case 11: /* ^K */ |
| 908 |
cmdval = CMD_DEOL; |
| 909 |
break; |
| 910 |
case 14: /* ^N */ |
| 911 |
cmdval = CMD_DOWN; |
| 912 |
break; |
| 913 |
case 16: /* ^P */ |
| 914 |
cmdval = CMD_UP; |
| 915 |
break; |
| 916 |
case 21: /* ^U */ |
| 917 |
cmdval = CMD_KILL; |
| 918 |
break; |
| 919 |
} |
| 920 |
} |
| 921 |
|
| 922 |
#endif /* RUNTIME */ |
| 923 |
|
| 924 |
if (cmdval) |
| 925 |
return 0; |
| 926 |
else if (d & 0xff) |
| 927 |
return (int) (d & 0xff); |
| 928 |
else |
| 929 |
goto tryAgain; |
| 930 |
} |
| 931 |
|
| 932 |
/* |
| 933 |
* os_getc_raw() works like os_getc(), but doesn't translate keys to |
| 934 |
* high-level CMD_xxx codes. |
| 935 |
*/ |
| 936 |
int os_getc_raw() |
| 937 |
{ |
| 938 |
static int cmdval; |
| 939 |
long d; |
| 940 |
|
| 941 |
tryAgain: |
| 942 |
if (cmdval) { |
| 943 |
int tmpcmd = cmdval; /* save command for a moment */ |
| 944 |
cmdval = 0; /* clear the flag - next call gets another key */ |
| 945 |
return(tmpcmd); /* return the command that we saved */ |
| 946 |
} |
| 947 |
else |
| 948 |
d = Bconin(2); /* no command pending - get another key */ |
| 949 |
|
| 950 |
#ifdef RUNTIME |
| 951 |
|
| 952 |
switch ((int)(d >> 16)) { |
| 953 |
case 0x4b: |
| 954 |
cmdval = CMD_LEFT; |
| 955 |
break; |
| 956 |
case 0x4d: |
| 957 |
cmdval = CMD_RIGHT; |
| 958 |
break; |
| 959 |
case 0x48: |
| 960 |
cmdval = CMD_UP; |
| 961 |
break; |
| 962 |
case 0x50: |
| 963 |
cmdval = CMD_DOWN; |
| 964 |
break; |
| 965 |
case 0x53: |
| 966 |
cmdval = CMD_DEL; |
| 967 |
break; |
| 968 |
case 0x47: |
| 969 |
cmdval = CMD_HOME; |
| 970 |
break; |
| 971 |
case 0x3b: /* F1 */ |
| 972 |
cmdval = CMD_F1; |
| 973 |
break; |
| 974 |
case 0x3c: /* F2 */ |
| 975 |
cmdval = CMD_F2; |
| 976 |
break; |
| 977 |
case 0x3d: /* F3 */ |
| 978 |
cmdval = CMD_F3; |
| 979 |
break; |
| 980 |
case 0x3e: /* F4 */ |
| 981 |
cmdval = CMD_F4; |
| 982 |
break; |
| 983 |
case 0x3f: /* F5 */ |
| 984 |
cmdval = CMD_F5; |
| 985 |
break; |
| 986 |
case 0x40: /* F6 */ |
| 987 |
cmdval = CMD_F6; |
| 988 |
break; |
| 989 |
case 0x41: /* F7 */ |
| 990 |
cmdval = CMD_F7; |
| 991 |
break; |
| 992 |
case 0x42: /* F8 */ |
| 993 |
cmdval = CMD_F8; |
| 994 |
break; |
| 995 |
case 0x43: /* F9 */ |
| 996 |
cmdval = CMD_F9; |
| 997 |
break; |
| 998 |
case 0x44: /* F10 */ |
| 999 |
cmdval = CMD_F10; |
| 1000 |
break; |
| 1001 |
|
| 1002 |
default: |
| 1003 |
/* return other keys unchanged */ |
| 1004 |
break; |
| 1005 |
} |
| 1006 |
|
| 1007 |
#endif /* RUNTIME */ |
| 1008 |
|
| 1009 |
if (cmdval) |
| 1010 |
return 0; |
| 1011 |
else if (d & 0xff) |
| 1012 |
return (int) (d & 0xff); |
| 1013 |
else |
| 1014 |
goto tryAgain; |
| 1015 |
} |
| 1016 |
|
| 1017 |
/* |
| 1018 |
* Check for control-break. Returns status of break flag, and clears |
| 1019 |
* the flag. |
| 1020 |
*/ |
| 1021 |
int |
| 1022 |
os_break() |
| 1023 |
{ |
| 1024 |
int ret; |
| 1025 |
|
| 1026 |
ret = break_set; |
| 1027 |
break_set = 0; |
| 1028 |
return ret; |
| 1029 |
} |
| 1030 |
|
| 1031 |
/* |
| 1032 |
* Handle ^C. Currently, this doesn't do anything. |
| 1033 |
*/ |
| 1034 |
static void |
| 1035 |
break_handler() |
| 1036 |
{ |
| 1037 |
break_set = 1; |
| 1038 |
} |
| 1039 |
|
| 1040 |
int |
| 1041 |
os_paramfile(buf) |
| 1042 |
{ |
| 1043 |
return 0; |
| 1044 |
} |
| 1045 |
|
| 1046 |
/* |
| 1047 |
* os_exeseek - finds datafile at end of executable. Note that, on the |
| 1048 |
* ST, the exename will be a flag simply to tell us to use this feature. |
| 1049 |
* We actually need to find the executable's name through an OS call. |
| 1050 |
* |
| 1051 |
* This is commented out for TADS 2 because I think it may not work with |
| 1052 |
* future versions of TOS. |
| 1053 |
*/ |
| 1054 |
FILE * |
| 1055 |
os_exeseek( exename ) |
| 1056 |
char *exename; |
| 1057 |
{ |
| 1058 |
#ifdef RUNTIME |
| 1059 |
FILE *fp, *fopen(); |
| 1060 |
char cmd[128], tail[128]; |
| 1061 |
int i; |
| 1062 |
long segsiz[4]; |
| 1063 |
|
| 1064 |
shel_read( cmd, tail ); |
| 1065 |
if (!( fp = fopen( cmd, "rb" ))) return( (FILE *)0 ); |
| 1066 |
if (fseek( fp, 2L, 0 )) |
| 1067 |
{ |
| 1068 |
fclose( fp ); |
| 1069 |
return( (FILE *)0 ); |
| 1070 |
} |
| 1071 |
for ( i=0 ; i<4 ; ++i ) |
| 1072 |
{ |
| 1073 |
if ( fread( &segsiz[i], sizeof( segsiz[i] ), 1, fp ) != 1 ) |
| 1074 |
{ |
| 1075 |
fclose( fp ); |
| 1076 |
return( (FILE *)0 ); |
| 1077 |
} |
| 1078 |
} |
| 1079 |
if (fseek( fp, 10L+segsiz[0]+segsiz[1], 1 )) |
| 1080 |
{ |
| 1081 |
fclose( fp ); |
| 1082 |
return( (FILE *)0 ); |
| 1083 |
} |
| 1084 |
return( fp ); |
| 1085 |
#else /* RUNTIME */ |
| 1086 |
return( (FILE *)0 ); |
| 1087 |
#endif |
| 1088 |
} |
| 1089 |
|
| 1090 |
int (*os_exfld(fp, siz))() |
| 1091 |
FILE *fp; |
| 1092 |
unsigned siz; |
| 1093 |
{ |
| 1094 |
int (*extfn)(/*_ void _*/); |
| 1095 |
|
| 1096 |
if (!(extfn = malloc(siz))) return( (int (*)(/*_ void _*/))0 ); |
| 1097 |
fread(extfn, siz, 1, fp); |
| 1098 |
return(extfn); |
| 1099 |
} |
| 1100 |
|
| 1101 |
int (*os_exfil(name))() |
| 1102 |
char *name; |
| 1103 |
{ |
| 1104 |
FILE *fp; |
| 1105 |
unsigned len; |
| 1106 |
int (*extfn)(/*_ void _*/); |
| 1107 |
|
| 1108 |
/* open the file and see how big it is to determine our memory needs */ |
| 1109 |
if (!(fp = fopen(name, "rb"))) return( (int (*)(/*_ void _*/))0 ); |
| 1110 |
(void)fseek(fp, 0L, 2); |
| 1111 |
len = (unsigned)ftell(fp); /* get total length of file */ |
| 1112 |
|
| 1113 |
(void)fseek(fp, 0L, 0); |
| 1114 |
extfn = os_exfld(fp, len); |
| 1115 |
|
| 1116 |
fclose(fp); |
| 1117 |
return(extfn); |
| 1118 |
} |
| 1119 |
|
| 1120 |
int os_excall(extfn, ctx) |
| 1121 |
int (*extfn)(/*_ void _*/); |
| 1122 |
char *ctx; |
| 1123 |
{ |
| 1124 |
return((*extfn)(ctx)); |
| 1125 |
} |
| 1126 |
|
| 1127 |
#ifndef STD_ASKFILE |
| 1128 |
|
| 1129 |
int |
| 1130 |
os_askfile(prompt, reply, replen, prompt_type, file_type) |
| 1131 |
char *prompt; |
| 1132 |
char *reply; |
| 1133 |
int replen; |
| 1134 |
int prompt_type; |
| 1135 |
int file_type; |
| 1136 |
{ |
| 1137 |
static char *r; |
| 1138 |
static char path[255] = ".\\", filename[20] = ""; |
| 1139 |
|
| 1140 |
r = file_select(path, filename, prompt); |
| 1141 |
if (r) { |
| 1142 |
if (strlen(r) < replen) { |
| 1143 |
strcpy(reply, r); |
| 1144 |
return OS_AFE_SUCCESS; |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
return OS_AFE_CANCEL; |
| 1149 |
} |
| 1150 |
|
| 1151 |
/* |
| 1152 |
* Put up a file selector box with prompting text. |
| 1153 |
* |
| 1154 |
* A pointer to the selected pathname is returned. If no filename was |
| 1155 |
* selected (i.e., the user pressed CANCEL), a NULL is returned. |
| 1156 |
* |
| 1157 |
* The path and filename strings will be modified. |
| 1158 |
*/ |
| 1159 |
char * |
| 1160 |
file_select(path, filename, message) |
| 1161 |
char *path; |
| 1162 |
char *filename; |
| 1163 |
char *message; |
| 1164 |
{ |
| 1165 |
static char p[255]; |
| 1166 |
int button; |
| 1167 |
|
| 1168 |
if (path[0] == '.') { |
| 1169 |
/* |
| 1170 |
* Expand current working directory for brain-damaged |
| 1171 |
* GEM file selector. |
| 1172 |
*/ |
| 1173 |
p[0] = (char) Dgetdrv() + 'A'; |
| 1174 |
p[1] = ':'; |
| 1175 |
Dgetpath(&p[2], 0); |
| 1176 |
strcat(p, &path[1]); |
| 1177 |
} |
| 1178 |
else { |
| 1179 |
strcpy(p, path); |
| 1180 |
} |
| 1181 |
|
| 1182 |
vt_cleanup(); |
| 1183 |
Cconws("\033f\033E\033bC\033c@"); |
| 1184 |
if (message) { |
| 1185 |
Cconws(message); |
| 1186 |
Cconout('?'); |
| 1187 |
} |
| 1188 |
graf_mouse(M_ON, NULL); |
| 1189 |
fsel_input(p, filename, &button); |
| 1190 |
vt_setup(); |
| 1191 |
vt_flush(); |
| 1192 |
|
| 1193 |
if (button) { |
| 1194 |
strcpy(path, p); |
| 1195 |
remove_wildcard(p); |
| 1196 |
strcat(p, filename); |
| 1197 |
return p; |
| 1198 |
} |
| 1199 |
else |
| 1200 |
return NULL; |
| 1201 |
} |
| 1202 |
|
| 1203 |
/* |
| 1204 |
* Remove wildcards at the end of a pathspec returned by fsel_input |
| 1205 |
*/ |
| 1206 |
static void |
| 1207 |
remove_wildcard(p) |
| 1208 |
register char *p; |
| 1209 |
{ |
| 1210 |
register char *base = p; |
| 1211 |
|
| 1212 |
/* |
| 1213 |
* Find terminating null |
| 1214 |
*/ |
| 1215 |
while (*p) p++; |
| 1216 |
|
| 1217 |
/* |
| 1218 |
* Delete characters until either \ or : are reached. |
| 1219 |
*/ |
| 1220 |
while (p != base) { |
| 1221 |
if (*p == '\\' || *p == ':') |
| 1222 |
break; |
| 1223 |
|
| 1224 |
*p-- = '\0'; |
| 1225 |
} |
| 1226 |
} |
| 1227 |
|
| 1228 |
/* |
| 1229 |
* Return a pointer to the start of the filename (8.3) in a complete path. |
| 1230 |
*/ |
| 1231 |
char * |
| 1232 |
path2fname(path) |
| 1233 |
char *path; |
| 1234 |
{ |
| 1235 |
char *p; |
| 1236 |
|
| 1237 |
/* |
| 1238 |
* Find end of string |
| 1239 |
*/ |
| 1240 |
p = path; |
| 1241 |
while (*p) |
| 1242 |
p++; |
| 1243 |
|
| 1244 |
/* |
| 1245 |
* Search backwards until we find \, :, /, or beginning of string |
| 1246 |
*/ |
| 1247 |
while (*p != '\\' && *p != ':' && *p != '/' && p != path) |
| 1248 |
p--; |
| 1249 |
|
| 1250 |
if (*p == '\\' || *p == ':' || *p == '/') |
| 1251 |
p++; |
| 1252 |
|
| 1253 |
return p; |
| 1254 |
} |
| 1255 |
|
| 1256 |
#endif /* STD_ASKFILE */ |
| 1257 |
|
| 1258 |
/* |
| 1259 |
* Provide memicmp since it's not a standard libc routine. |
| 1260 |
*/ |
| 1261 |
memicmp(s1, s2, len) |
| 1262 |
char *s1, *s2; |
| 1263 |
int len; |
| 1264 |
{ |
| 1265 |
char *x1, *x2; |
| 1266 |
int result; |
| 1267 |
int i; |
| 1268 |
|
| 1269 |
x1 = malloc(len); |
| 1270 |
x2 = malloc(len); |
| 1271 |
|
| 1272 |
if (!x1 || !x2) { |
| 1273 |
printf("Out of memory!\n"); |
| 1274 |
exit(-1); |
| 1275 |
} |
| 1276 |
|
| 1277 |
for (i = 0; i < len; i++) { |
| 1278 |
if (isupper(s1[i])) |
| 1279 |
x1[i] = tolower(s1[i]); |
| 1280 |
else |
| 1281 |
x1[i] = s1[i]; |
| 1282 |
|
| 1283 |
if (isupper(s2[i])) |
| 1284 |
x2[i] = tolower(s2[i]); |
| 1285 |
else |
| 1286 |
x2[i] = s2[i]; |
| 1287 |
} |
| 1288 |
|
| 1289 |
result = memcmp(x1, x2, len); |
| 1290 |
free(x1); |
| 1291 |
free(x2); |
| 1292 |
return result; |
| 1293 |
} |
| 1294 |
|