| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/msdos/Osdos.c,v 1.3 1999/07/11 00:46:37 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
#include <stdio.h> |
| 91 |
#include <stddef.h> |
| 92 |
#include <stdlib.h> |
| 93 |
#include <ctype.h> |
| 94 |
#include <string.h> |
| 95 |
#include <stdarg.h> |
| 96 |
|
| 97 |
#include <time.h> |
| 98 |
|
| 99 |
#ifdef TURBO |
| 100 |
# include <sys/stat.h> |
| 101 |
# include <dir.h> |
| 102 |
# include <dos.h> |
| 103 |
# define _getch getch |
| 104 |
# define _fileno fileno |
| 105 |
# define _fstat fstat |
| 106 |
#endif |
| 107 |
|
| 108 |
#ifdef DJGPP |
| 109 |
# include <signal.h> |
| 110 |
# include <dpmi.h> |
| 111 |
# include <fcntl.h> |
| 112 |
# include <conio.h> |
| 113 |
# include <sys/stat.h> |
| 114 |
# define _getch getch |
| 115 |
# define _fileno fileno |
| 116 |
# define _fstat fstat |
| 117 |
#endif |
| 118 |
|
| 119 |
#ifndef DJGPP |
| 120 |
# include <share.h> |
| 121 |
# include <dos.h> |
| 122 |
#endif |
| 123 |
|
| 124 |
#ifdef MICROSOFT |
| 125 |
# ifdef T_WIN32 |
| 126 |
# include <conio.h> |
| 127 |
# include <sys/stat.h> |
| 128 |
# include <io.h> |
| 129 |
# include <fcntl.h> |
| 130 |
# include <Windows.h> |
| 131 |
# endif |
| 132 |
# ifdef RUNTIME |
| 133 |
# include <dos.h> |
| 134 |
# endif |
| 135 |
|
| 136 |
|
| 137 |
# if _MSC_VER >= 700 |
| 138 |
# define interrupt __interrupt |
| 139 |
# define asm __asm |
| 140 |
# else |
| 141 |
# define interrupt _interrupt |
| 142 |
# define asm _asm |
| 143 |
# endif |
| 144 |
# define getvect _dos_getvect |
| 145 |
# define setvect _dos_setvect |
| 146 |
|
| 147 |
#endif |
| 148 |
|
| 149 |
#include "os.h" |
| 150 |
#include "osgen.h" |
| 151 |
#include "tio.h" |
| 152 |
|
| 153 |
#ifdef __DPMI32__ |
| 154 |
# define interrupt _interrupt |
| 155 |
#endif |
| 156 |
|
| 157 |
#ifdef MSOS2 |
| 158 |
# define INCL_DOSMODULEMGR |
| 159 |
# define INCL_DOSFILEMGR |
| 160 |
# define INCL_KBD |
| 161 |
# include <os2.h> |
| 162 |
|
| 163 |
# ifdef RUNTIME |
| 164 |
# ifdef __EMX__ |
| 165 |
# include <stdlib.h> |
| 166 |
# endif |
| 167 |
# ifdef MICROSOFT |
| 168 |
# include <direct.h> |
| 169 |
# endif |
| 170 |
# ifdef __IBMC__ |
| 171 |
# include <direct.h> |
| 172 |
# endif |
| 173 |
# endif |
| 174 |
|
| 175 |
# ifdef __EMX__ |
| 176 |
# define getch() _read_kbd(0, 1, 0) |
| 177 |
# endif |
| 178 |
# ifdef __32BIT__ |
| 179 |
# define DosGetProcAddr(a,b,c) DosQueryProcAddr(a,0L,b,c) |
| 180 |
# endif |
| 181 |
|
| 182 |
#endif |
| 183 |
|
| 184 |
#include "tadsexit.h" |
| 185 |
|
| 186 |
#ifndef DJGPP |
| 187 |
#ifdef __DPMI16__ |
| 188 |
# include <windows.h> |
| 189 |
# define SCRBASE_COLOR_PTR ((char *)MK_FP(__SegB800, 0)) |
| 190 |
# define SCRBASE_MONO_PTR ((char *)MK_FP(__SegB000, 0)) |
| 191 |
#else |
| 192 |
# define SCRBASE_COLOR_PTR ((char *)0xb8000000L) |
| 193 |
# define SCRBASE_MONO_PTR ((char *)0xb0000000L) |
| 194 |
#endif |
| 195 |
#endif |
| 196 |
|
| 197 |
|
| 198 |
int G_stdin_is_kb = TRUE; |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
static osfar_t int S_keep_cursor_pos = FALSE; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
static osfar_t int S_os_win95_kb_fix = FALSE; |
| 214 |
|
| 215 |
|
| 216 |
#ifdef USEDOSCOMMON |
| 217 |
# ifdef RUNTIME |
| 218 |
# if !defined(MSOS2) && !defined(DJGPP) |
| 219 |
char *scrbase; |
| 220 |
# endif |
| 221 |
|
| 222 |
|
| 223 |
static osfar_t int oldvmode; |
| 224 |
extern int os_f_plain; |
| 225 |
extern void osnoui_init(); |
| 226 |
extern void osnoui_uninit(); |
| 227 |
|
| 228 |
|
| 229 |
void os_scrini(void) |
| 230 |
{ |
| 231 |
int xmax, ymax; |
| 232 |
|
| 233 |
|
| 234 |
ossgmx(&ymax, &xmax); |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
G_oss_screen_width = xmax + 1; |
| 242 |
G_oss_screen_height = ymax + 1; |
| 243 |
|
| 244 |
|
| 245 |
if (!os_f_plain) |
| 246 |
{ |
| 247 |
|
| 248 |
ossclr(0, 0, ymax, xmax, text_color); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
#if defined(DJGPP) || defined(TURBO) |
| 253 |
#define OSDOS_INIT_USEBIOS 0 |
| 254 |
#define _stat stat |
| 255 |
#define _S_IFREG S_IFREG |
| 256 |
#define _S_IFIFO S_IFIFO |
| 257 |
#endif |
| 258 |
|
| 259 |
#ifndef OSDOS_INIT_USEBIOS |
| 260 |
#define OSDOS_INIT_USEBIOS 1 |
| 261 |
#endif |
| 262 |
|
| 263 |
|
| 264 |
int usebios = OSDOS_INIT_USEBIOS; |
| 265 |
|
| 266 |
|
| 267 |
static osfar_t int use_std_askfile = 0; |
| 268 |
|
| 269 |
int os_init(int *argc, char *argv[], const char *prompt, |
| 270 |
char *buf, int bufsiz) |
| 271 |
{ |
| 272 |
int i; |
| 273 |
FILE *fp; |
| 274 |
char nbuf[128]; |
| 275 |
int found_arg; |
| 276 |
struct _stat statbuf; |
| 277 |
|
| 278 |
|
| 279 |
osnoui_init(); |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
for (i = 0 ; i < *argc ; ++i) |
| 286 |
{ |
| 287 |
|
| 288 |
if (!stricmp(argv[i], "-kbfix95")) |
| 289 |
{ |
| 290 |
|
| 291 |
S_os_win95_kb_fix = TRUE; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
for ( ; i + 1 < *argc ; ++i) |
| 299 |
argv[i] = argv[i + 1]; |
| 300 |
|
| 301 |
|
| 302 |
--(*argc); |
| 303 |
|
| 304 |
|
| 305 |
break; |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
#ifndef DJGPP |
| 310 |
scrbase = SCRBASE_COLOR_PTR; |
| 311 |
#endif |
| 312 |
|
| 313 |
for (i = *argc - 1, found_arg = TRUE ; i != 0 && found_arg ; ) |
| 314 |
{ |
| 315 |
|
| 316 |
if (argv[i][0] != '-' && argv[i][0] != '/') |
| 317 |
break; |
| 318 |
|
| 319 |
|
| 320 |
switch(argv[i][1]) |
| 321 |
{ |
| 322 |
case 'b': |
| 323 |
case 'B': |
| 324 |
|
| 325 |
usebios = 1; |
| 326 |
#if !defined(MSOS2) && !defined(DJGPP) |
| 327 |
scrbase = (char *)0xf0000000L; |
| 328 |
#endif |
| 329 |
break; |
| 330 |
|
| 331 |
case 'a': |
| 332 |
case 'A': |
| 333 |
|
| 334 |
use_std_askfile = TRUE; |
| 335 |
break; |
| 336 |
|
| 337 |
default: |
| 338 |
|
| 339 |
found_arg = FALSE; |
| 340 |
break; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
if (found_arg) |
| 345 |
{ |
| 346 |
--i; |
| 347 |
--(*argc); |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
oss_con_init(); |
| 353 |
|
| 354 |
|
| 355 |
if (!_fstat(_fileno(stdout), &statbuf)) |
| 356 |
{ |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
if ((statbuf.st_mode & _S_IFREG) != 0) |
| 362 |
{ |
| 363 |
os_plain(); |
| 364 |
G_os_moremode = FALSE; |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
if (os_f_plain) |
| 370 |
{ |
| 371 |
|
| 372 |
if (!_fstat(_fileno(stdin), &statbuf)) |
| 373 |
{ |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
if ((statbuf.st_mode & _S_IFREG) != 0) |
| 379 |
G_os_moremode = FALSE; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
if ((statbuf.st_mode & (_S_IFREG | _S_IFIFO)) != 0) |
| 387 |
G_stdin_is_kb = FALSE; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
if (ossmon()) |
| 396 |
{ |
| 397 |
#if !defined(MSOS2) && !defined(DJGPP) |
| 398 |
scrbase = SCRBASE_MONO_PTR; |
| 399 |
#endif |
| 400 |
sdesc_color = 0x70; |
| 401 |
text_color = 7; |
| 402 |
ldesc_color = 0x70; |
| 403 |
debug_color = 7; |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
if (os_locate("trcolor.dat", 11, argv[0], nbuf, sizeof(nbuf)) |
| 408 |
&& (fp = fopen(nbuf, "r")) != 0) |
| 409 |
{ |
| 410 |
int i; |
| 411 |
static osfar_t int *colorptr[] = |
| 412 |
{ &text_normal_color, &text_bold_color, &sdesc_color }; |
| 413 |
|
| 414 |
for (i = 0 ; i < sizeof(colorptr)/sizeof(colorptr[0]) ; ++i) |
| 415 |
{ |
| 416 |
fgets(nbuf, sizeof(nbuf), fp); |
| 417 |
*colorptr[i] = atoi(nbuf); |
| 418 |
} |
| 419 |
fclose(fp); |
| 420 |
} |
| 421 |
text_color = text_normal_color; |
| 422 |
|
| 423 |
|
| 424 |
os_scrini(); |
| 425 |
|
| 426 |
|
| 427 |
status_mode = 1; |
| 428 |
os_printz(""); |
| 429 |
status_mode = 0; |
| 430 |
|
| 431 |
# ifdef USE_SCROLLBACK |
| 432 |
osssbini(16*1024); |
| 433 |
# endif |
| 434 |
|
| 435 |
return( 0 ); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
void os_uninit(void) |
| 442 |
{ |
| 443 |
|
| 444 |
osnoui_uninit(); |
| 445 |
|
| 446 |
|
| 447 |
oss_con_uninit(); |
| 448 |
} |
| 449 |
|
| 450 |
void os_term(int rc) |
| 451 |
{ |
| 452 |
# ifdef USE_SCROLLBACK |
| 453 |
osssbdel(); |
| 454 |
# endif |
| 455 |
|
| 456 |
exit(rc); |
| 457 |
} |
| 458 |
# endif |
| 459 |
|
| 460 |
#ifdef TURBO |
| 461 |
# define os_getch getch |
| 462 |
#endif |
| 463 |
|
| 464 |
#ifdef MICROSOFT |
| 465 |
# ifdef MSDOS |
| 466 |
# ifndef MSOS2 |
| 467 |
# ifndef T_WIN32 |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
char os_getch(void) |
| 474 |
{ |
| 475 |
char retval; |
| 476 |
|
| 477 |
|
| 478 |
if (!S_keep_cursor_pos) |
| 479 |
osssb_cursor_to_default_pos(); |
| 480 |
|
| 481 |
|
| 482 |
asm { |
| 483 |
mov ah, 07h |
| 484 |
int 21h |
| 485 |
mov retval, al |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
return retval; |
| 490 |
} |
| 491 |
|
| 492 |
# endif |
| 493 |
# endif |
| 494 |
# endif |
| 495 |
#endif |
| 496 |
|
| 497 |
|
| 498 |
#ifndef T_WIN32 |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
void os_sleep_ms(long delay_in_milliseconds) |
| 505 |
{ |
| 506 |
long done_time; |
| 507 |
|
| 508 |
|
| 509 |
osssb_redraw_if_needed(); |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
done_time = os_get_sys_clock_ms() + delay_in_milliseconds; |
| 516 |
|
| 517 |
|
| 518 |
while (os_get_sys_clock_ms() < done_time) |
| 519 |
; |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
static int oss_getc_internal(unsigned char *ch, |
| 534 |
unsigned long timeout, int use_timeout) |
| 535 |
{ |
| 536 |
unsigned long abs_timeout; |
| 537 |
char retval; |
| 538 |
#ifdef DJGPP |
| 539 |
__dpmi_regs regs; |
| 540 |
#endif |
| 541 |
|
| 542 |
#ifdef RUNTIME |
| 543 |
|
| 544 |
if (os_f_plain) |
| 545 |
{ |
| 546 |
|
| 547 |
if (use_timeout) |
| 548 |
return OS_GETS_EOF; |
| 549 |
|
| 550 |
|
| 551 |
fflush(stdout); |
| 552 |
|
| 553 |
|
| 554 |
*ch = (G_stdin_is_kb ? _getch() : getchar()); |
| 555 |
|
| 556 |
|
| 557 |
return OS_GETS_OK; |
| 558 |
} |
| 559 |
#endif |
| 560 |
|
| 561 |
|
| 562 |
osssb_redraw_if_needed(); |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
if (!use_timeout) |
| 569 |
{ |
| 570 |
|
| 571 |
#ifdef DJGPP |
| 572 |
regs.h.ah = 7; |
| 573 |
__dpmi_int(0x21, ®s); |
| 574 |
retval = regs.h.al; |
| 575 |
#else |
| 576 |
asm { |
| 577 |
mov ah, 07h |
| 578 |
int 21h |
| 579 |
mov retval, al |
| 580 |
} |
| 581 |
#endif |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
if ((unsigned char)retval == 0340) |
| 591 |
retval = 0; |
| 592 |
|
| 593 |
|
| 594 |
*ch = retval; |
| 595 |
return OS_GETS_OK; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
abs_timeout = (unsigned long)os_get_sys_clock_ms() + timeout; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
for (;;) |
| 609 |
{ |
| 610 |
|
| 611 |
#ifdef DJGPP |
| 612 |
regs.h.ah = 6; |
| 613 |
regs.h.dl = 0xff; |
| 614 |
__dpmi_int(0x21, ®s); |
| 615 |
if (regs.x.flags & 0x40) |
| 616 |
goto no_key_available; |
| 617 |
retval = regs.h.al; |
| 618 |
#else |
| 619 |
asm { |
| 620 |
mov ah, 06h |
| 621 |
mov dl, 0ffh |
| 622 |
int 21h |
| 623 |
jz no_key_available |
| 624 |
|
| 625 |
mov retval, al |
| 626 |
} |
| 627 |
#endif |
| 628 |
|
| 629 |
|
| 630 |
if ((unsigned char)retval == 0340) |
| 631 |
retval = 0; |
| 632 |
|
| 633 |
|
| 634 |
*ch = retval; |
| 635 |
return OS_GETS_OK; |
| 636 |
|
| 637 |
no_key_available: |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
if ((unsigned long)os_get_sys_clock_ms() >= abs_timeout) |
| 643 |
return OS_GETS_TIMEOUT; |
| 644 |
} |
| 645 |
} |
| 646 |
|
| 647 |
#ifdef DJGPP |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
char os_getch(void) |
| 652 |
{ |
| 653 |
unsigned char ch; |
| 654 |
|
| 655 |
|
| 656 |
if (oss_getc_internal(&ch, 0, FALSE) == OS_GETS_OK) |
| 657 |
return ch; |
| 658 |
else |
| 659 |
return EOF; |
| 660 |
} |
| 661 |
#endif |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
int oss_getc_timeout(unsigned char *ch, unsigned long timeout) |
| 668 |
{ |
| 669 |
return oss_getc_internal(ch, timeout, TRUE); |
| 670 |
} |
| 671 |
|
| 672 |
#endif |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
#ifdef T_WIN32 |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
static unsigned char xlat_keypad(int vkey) |
| 691 |
{ |
| 692 |
switch(vkey) |
| 693 |
{ |
| 694 |
case VK_HOME: |
| 695 |
return 7; |
| 696 |
|
| 697 |
case VK_UP: |
| 698 |
return 8; |
| 699 |
|
| 700 |
case VK_PRIOR: |
| 701 |
return 9; |
| 702 |
|
| 703 |
case VK_LEFT: |
| 704 |
return 4; |
| 705 |
|
| 706 |
case VK_CLEAR: |
| 707 |
return 5; |
| 708 |
|
| 709 |
case VK_RIGHT: |
| 710 |
return 6; |
| 711 |
|
| 712 |
case VK_END: |
| 713 |
return 1; |
| 714 |
|
| 715 |
case VK_DOWN: |
| 716 |
return 2; |
| 717 |
|
| 718 |
case VK_NEXT: |
| 719 |
return 3; |
| 720 |
|
| 721 |
case VK_INSERT: |
| 722 |
return 0; |
| 723 |
|
| 724 |
default: |
| 725 |
|
| 726 |
return 100; |
| 727 |
} |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
static int oss_getc_internal(unsigned char *ch, |
| 735 |
unsigned long timeout, int use_timeout) |
| 736 |
{ |
| 737 |
static osfar_t HANDLE hcon = INVALID_HANDLE_VALUE; |
| 738 |
DWORD oldmode; |
| 739 |
static osfar_t unsigned char nxt_ret = 0; |
| 740 |
DWORD abs_timeout; |
| 741 |
int status_code; |
| 742 |
extern int os_f_plain; |
| 743 |
|
| 744 |
|
| 745 |
if (os_f_plain) |
| 746 |
{ |
| 747 |
|
| 748 |
if (use_timeout) |
| 749 |
return OS_GETS_EOF; |
| 750 |
|
| 751 |
|
| 752 |
fflush(stdout); |
| 753 |
|
| 754 |
|
| 755 |
if (feof(stdin)) |
| 756 |
return OS_GETS_EOF; |
| 757 |
|
| 758 |
|
| 759 |
*ch = (G_stdin_is_kb ? _getch() : getchar()); |
| 760 |
|
| 761 |
|
| 762 |
return OS_GETS_OK; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
if (use_timeout) |
| 770 |
abs_timeout = GetTickCount() + timeout; |
| 771 |
|
| 772 |
|
| 773 |
if (nxt_ret != 0) |
| 774 |
{ |
| 775 |
*ch = nxt_ret; |
| 776 |
nxt_ret = 0; |
| 777 |
return OS_GETS_OK; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
if (hcon == INVALID_HANDLE_VALUE) |
| 782 |
{ |
| 783 |
hcon = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, |
| 784 |
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, |
| 785 |
OPEN_EXISTING, 0, 0); |
| 786 |
if (hcon == INVALID_HANDLE_VALUE) |
| 787 |
{ |
| 788 |
*ch = _getch(); |
| 789 |
return OS_GETS_OK; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
GetConsoleMode(hcon, &oldmode); |
| 795 |
|
| 796 |
|
| 797 |
SetConsoleMode(hcon, ENABLE_WINDOW_INPUT); |
| 798 |
|
| 799 |
|
| 800 |
for (;;) |
| 801 |
{ |
| 802 |
INPUT_RECORD inrec; |
| 803 |
DWORD reccnt; |
| 804 |
KEY_EVENT_RECORD *keyevt; |
| 805 |
int alt, ctl, shift, extended; |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
if (use_timeout) |
| 812 |
{ |
| 813 |
DWORD cur_time; |
| 814 |
DWORD interval; |
| 815 |
|
| 816 |
|
| 817 |
cur_time = GetTickCount(); |
| 818 |
if (cur_time >= abs_timeout) |
| 819 |
{ |
| 820 |
|
| 821 |
status_code = OS_GETS_TIMEOUT; |
| 822 |
goto done; |
| 823 |
} |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
interval = (DWORD)(abs_timeout - cur_time); |
| 830 |
if (WaitForSingleObject(hcon, interval) == WAIT_TIMEOUT) |
| 831 |
{ |
| 832 |
|
| 833 |
status_code = OS_GETS_TIMEOUT; |
| 834 |
goto done; |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
if (S_os_win95_kb_fix) |
| 882 |
{ |
| 883 |
int evt_ch; |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
WaitForSingleObject(hcon, INFINITE); |
| 890 |
|
| 891 |
|
| 892 |
PeekConsoleInput(hcon, &inrec, 1, &reccnt); |
| 893 |
|
| 894 |
|
| 895 |
keyevt = &inrec.Event.KeyEvent; |
| 896 |
|
| 897 |
|
| 898 |
alt = ((keyevt->dwControlKeyState |
| 899 |
& (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) != 0); |
| 900 |
|
| 901 |
|
| 902 |
evt_ch = keyevt->uChar.AsciiChar; |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
if (inrec.EventType == KEY_EVENT |
| 914 |
&& keyevt->bKeyDown |
| 915 |
&& evt_ch != '\0' |
| 916 |
&& (!alt || (alt && evt_ch > 127))) |
| 917 |
{ |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
ReadConsole(hcon, ch, 1, &reccnt, 0); |
| 923 |
|
| 924 |
|
| 925 |
status_code = OS_GETS_OK; |
| 926 |
goto done; |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
if (!ReadConsoleInput(hcon, &inrec, 1, &reccnt)) |
| 932 |
{ |
| 933 |
*ch = _getch(); |
| 934 |
status_code = OS_GETS_OK; |
| 935 |
goto done; |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
switch(inrec.EventType) |
| 940 |
{ |
| 941 |
#ifdef RUNTIME |
| 942 |
case WINDOW_BUFFER_SIZE_EVENT: |
| 943 |
|
| 944 |
oss_win_resize_event(); |
| 945 |
break; |
| 946 |
#endif |
| 947 |
|
| 948 |
case KEY_EVENT: |
| 949 |
|
| 950 |
status_code = OS_GETS_OK; |
| 951 |
|
| 952 |
|
| 953 |
keyevt = &inrec.Event.KeyEvent; |
| 954 |
|
| 955 |
|
| 956 |
if (!keyevt->bKeyDown) |
| 957 |
continue; |
| 958 |
|
| 959 |
|
| 960 |
switch(keyevt->wVirtualKeyCode) |
| 961 |
{ |
| 962 |
case VK_SHIFT: |
| 963 |
case VK_CONTROL: |
| 964 |
case VK_MENU: |
| 965 |
case VK_PAUSE: |
| 966 |
case VK_CAPITAL: |
| 967 |
case VK_NUMLOCK: |
| 968 |
case VK_SCROLL: |
| 969 |
continue; |
| 970 |
} |
| 971 |
|
| 972 |
|
| 973 |
alt = ((keyevt->dwControlKeyState |
| 974 |
& (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) != 0); |
| 975 |
ctl = ((keyevt->dwControlKeyState |
| 976 |
& (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED)) != 0); |
| 977 |
shift = ((keyevt->dwControlKeyState & SHIFT_PRESSED) != 0); |
| 978 |
extended = ((keyevt->dwControlKeyState & ENHANCED_KEY) != 0); |
| 979 |
|
| 980 |
|
| 981 |
if (keyevt->uChar.AsciiChar != 0) |
| 982 |
{ |
| 983 |
unsigned char evtch = keyevt->uChar.AsciiChar; |
| 984 |
|
| 985 |
|
| 986 |
if (alt) |
| 987 |
{ |
| 988 |
|
| 989 |
if (evtch >= 'a' && evtch <= 'z') |
| 990 |
evtch -= 'a' - 'A'; |
| 991 |
if (evtch >= 'A' && evtch <= 'Z') |
| 992 |
{ |
| 993 |
static osfar_t char alt_alpha[] = |
| 994 |
{ |
| 995 |
30, 48, 46, 32, 18, 33, 34, 35, 23, 36, |
| 996 |
37, 38, 50, 49, 24, 25, 16, 19, 31, 20, |
| 997 |
22, 47, 17, 45, 21, 44 |
| 998 |
}; |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
nxt_ret = alt_alpha[evtch - 'A']; |
| 1006 |
*ch = 0; |
| 1007 |
status_code = OS_GETS_OK; |
| 1008 |
goto done; |
| 1009 |
} |
| 1010 |
|
| 1011 |
|
| 1012 |
break; |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
*ch = evtch; |
| 1017 |
status_code = OS_GETS_OK; |
| 1018 |
goto done; |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
if (alt && !ctl && !shift && !extended) |
| 1030 |
{ |
| 1031 |
|
| 1032 |
*ch = xlat_keypad(keyevt->wVirtualKeyCode); |
| 1033 |
if (*ch < 10) |
| 1034 |
{ |
| 1035 |
unsigned ignore_vkey; |
| 1036 |
int ansi_key_seq; |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
ansi_key_seq = (*ch == 0); |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
if (S_os_win95_kb_fix) |
| 1063 |
{ |
| 1064 |
|
| 1065 |
ReadConsole(hcon, ch, 1, &reccnt, 0); |
| 1066 |
|
| 1067 |
|
| 1068 |
status_code = OS_GETS_OK; |
| 1069 |
goto done; |
| 1070 |
} |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
ignore_vkey = keyevt->wVirtualKeyCode; |
| 1077 |
|
| 1078 |
|
| 1079 |
for (;;) |
| 1080 |
{ |
| 1081 |
unsigned char nxt; |
| 1082 |
|
| 1083 |
|
| 1084 |
WaitForSingleObject(hcon, INFINITE); |
| 1085 |
if (!PeekConsoleInput(hcon, &inrec, 1, &reccnt) |
| 1086 |
|| reccnt == 0) |
| 1087 |
break; |
| 1088 |
|
| 1089 |
|
| 1090 |
if (inrec.EventType != KEY_EVENT) |
| 1091 |
break; |
| 1092 |
|
| 1093 |
|
| 1094 |
if (!keyevt->bKeyDown |
| 1095 |
&& keyevt->wVirtualKeyCode == VK_MENU) |
| 1096 |
{ |
| 1097 |
|
| 1098 |
break; |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
if (!keyevt->bKeyDown |
| 1106 |
&& keyevt->wVirtualKeyCode == ignore_vkey) |
| 1107 |
ignore_vkey = 0; |
| 1108 |
|
| 1109 |
|
| 1110 |
if (!keyevt->bKeyDown) |
| 1111 |
goto skip_event; |
| 1112 |
|
| 1113 |
|
| 1114 |
alt = ((keyevt->dwControlKeyState |
| 1115 |
& (RIGHT_ALT_PRESSED |
| 1116 |
| LEFT_ALT_PRESSED)) != 0); |
| 1117 |
ctl = ((keyevt->dwControlKeyState |
| 1118 |
& (RIGHT_CTRL_PRESSED |
| 1119 |
| LEFT_CTRL_PRESSED)) != 0); |
| 1120 |
shift = ((keyevt->dwControlKeyState |
| 1121 |
& SHIFT_PRESSED) != 0); |
| 1122 |
extended = ((keyevt->dwControlKeyState |
| 1123 |
& ENHANCED_KEY) != 0); |
| 1124 |
|
| 1125 |
|
| 1126 |
if (!alt || ctl || shift || extended) |
| 1127 |
break; |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
if (keyevt->wVirtualKeyCode == ignore_vkey) |
| 1135 |
goto skip_event; |
| 1136 |
|
| 1137 |
|
| 1138 |
ignore_vkey = keyevt->wVirtualKeyCode; |
| 1139 |
|
| 1140 |
|
| 1141 |
nxt = xlat_keypad(keyevt->wVirtualKeyCode); |
| 1142 |
if (nxt > 9) |
| 1143 |
break; |
| 1144 |
|
| 1145 |
|
| 1146 |
*ch *= 10; |
| 1147 |
*ch += nxt; |
| 1148 |
|
| 1149 |
skip_event: |
| 1150 |
|
| 1151 |
ReadConsoleInput(hcon, &inrec, 1, &reccnt); |
| 1152 |
} |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
if (ansi_key_seq) |
| 1159 |
{ |
| 1160 |
char buf[2]; |
| 1161 |
|
| 1162 |
|
| 1163 |
buf[0] = *ch; |
| 1164 |
buf[1] = '\0'; |
| 1165 |
|
| 1166 |
|
| 1167 |
CharToOem(buf, buf); |
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
if (buf[0] == '\0') |
| 1175 |
break; |
| 1176 |
|
| 1177 |
|
| 1178 |
*ch = buf[0]; |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
status_code = OS_GETS_OK; |
| 1183 |
goto done; |
| 1184 |
} |
| 1185 |
} |
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
if (!alt && !shift && !ctl) |
| 1192 |
{ |
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
*ch = 0; |
| 1200 |
nxt_ret = (unsigned char)keyevt->wVirtualScanCode; |
| 1201 |
status_code = OS_GETS_OK; |
| 1202 |
goto done; |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
if (shift && !ctl && !alt) |
| 1207 |
{ |
| 1208 |
|
| 1209 |
*ch = 0; |
| 1210 |
|
| 1211 |
|
| 1212 |
switch(keyevt->wVirtualKeyCode) |
| 1213 |
{ |
| 1214 |
case VK_F1: |
| 1215 |
case VK_F2: |
| 1216 |
case VK_F3: |
| 1217 |
case VK_F4: |
| 1218 |
case VK_F5: |
| 1219 |
case VK_F6: |
| 1220 |
case VK_F7: |
| 1221 |
case VK_F8: |
| 1222 |
case VK_F9: |
| 1223 |
case VK_F10: |
| 1224 |
case VK_F11: |
| 1225 |
case VK_F12: |
| 1226 |
nxt_ret = 84 + keyevt->wVirtualKeyCode - VK_F1; |
| 1227 |
goto done; |
| 1228 |
|
| 1229 |
default: |
| 1230 |
break; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
if (ctl && !alt && !shift) |
| 1236 |
{ |
| 1237 |
|
| 1238 |
*ch = 0; |
| 1239 |
|
| 1240 |
|
| 1241 |
switch(keyevt->wVirtualKeyCode) |
| 1242 |
{ |
| 1243 |
case VK_PRIOR: |
| 1244 |
nxt_ret = 132; |
| 1245 |
goto done; |
| 1246 |
|
| 1247 |
case VK_NEXT: |
| 1248 |
nxt_ret = 118; |
| 1249 |
goto done; |
| 1250 |
|
| 1251 |
case VK_LEFT: |
| 1252 |
nxt_ret = 115; |
| 1253 |
goto done; |
| 1254 |
|
| 1255 |
case VK_RIGHT: |
| 1256 |
nxt_ret = 116; |
| 1257 |
goto done; |
| 1258 |
|
| 1259 |
case VK_HOME: |
| 1260 |
nxt_ret = 119; |
| 1261 |
goto done; |
| 1262 |
|
| 1263 |
case VK_END: |
| 1264 |
nxt_ret = 0165; |
| 1265 |
goto done; |
| 1266 |
|
| 1267 |
default: |
| 1268 |
break; |
| 1269 |
} |
| 1270 |
} |
| 1271 |
|
| 1272 |
break; |
| 1273 |
|
| 1274 |
default: |
| 1275 |
|
| 1276 |
break; |
| 1277 |
} |
| 1278 |
} |
| 1279 |
|
| 1280 |
done: |
| 1281 |
|
| 1282 |
SetConsoleMode(hcon, oldmode); |
| 1283 |
|
| 1284 |
|
| 1285 |
return status_code; |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
char os_getch(void) |
| 1292 |
{ |
| 1293 |
unsigned char ch; |
| 1294 |
|
| 1295 |
|
| 1296 |
if (oss_getc_internal(&ch, 0, FALSE) == OS_GETS_OK) |
| 1297 |
return ch; |
| 1298 |
else |
| 1299 |
return EOF; |
| 1300 |
} |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
int oss_getc_timeout(unsigned char *ch, unsigned long timeout) |
| 1307 |
{ |
| 1308 |
|
| 1309 |
return oss_getc_internal(ch, timeout, TRUE); |
| 1310 |
} |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
void os_sleep_ms(long delay_in_milliseconds) |
| 1319 |
{ |
| 1320 |
|
| 1321 |
osssb_redraw_if_needed(); |
| 1322 |
|
| 1323 |
|
| 1324 |
if (!S_keep_cursor_pos) |
| 1325 |
osssb_cursor_to_default_pos(); |
| 1326 |
|
| 1327 |
|
| 1328 |
Sleep(delay_in_milliseconds); |
| 1329 |
} |
| 1330 |
|
| 1331 |
|
| 1332 |
#endif |
| 1333 |
|
| 1334 |
|
| 1335 |
#ifndef USE_DOOR |
| 1336 |
# ifndef WINDOWS |
| 1337 |
void os_waitc(void) |
| 1338 |
{ |
| 1339 |
int c; |
| 1340 |
|
| 1341 |
|
| 1342 |
c = os_getch(); |
| 1343 |
|
| 1344 |
|
| 1345 |
if ((c == 0 || (unsigned char)c == 0340)) |
| 1346 |
os_getch(); |
| 1347 |
} |
| 1348 |
# endif |
| 1349 |
#endif |
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
#ifndef USE_DOOR |
| 1354 |
# ifndef WINDOWS |
| 1355 |
# ifndef DJGPP |
| 1356 |
int os_kbhit(void) |
| 1357 |
{ |
| 1358 |
# ifdef MSOS2 |
| 1359 |
KBDKEYINFO ki; |
| 1360 |
|
| 1361 |
return( KbdPeek(&ki, (HKBD)0) == 0 && (ki.fbStatus & 0x40) ); |
| 1362 |
# else |
| 1363 |
int ret = 0; |
| 1364 |
|
| 1365 |
#ifndef __DPMI32__ |
| 1366 |
#ifndef T_WIN32 |
| 1367 |
asm { |
| 1368 |
push bp |
| 1369 |
push di |
| 1370 |
push si |
| 1371 |
push ds |
| 1372 |
push es |
| 1373 |
|
| 1374 |
mov ah, 1 |
| 1375 |
int 16h |
| 1376 |
jz no_key_ready |
| 1377 |
} |
| 1378 |
ret = 1; |
| 1379 |
no_key_ready: |
| 1380 |
asm { |
| 1381 |
pop es |
| 1382 |
pop ds |
| 1383 |
pop si |
| 1384 |
pop di |
| 1385 |
pop bp |
| 1386 |
} |
| 1387 |
#endif |
| 1388 |
#endif |
| 1389 |
return(ret); |
| 1390 |
# endif |
| 1391 |
} |
| 1392 |
# endif |
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
#ifdef RUNTIME |
| 1400 |
|
| 1401 |
char osfar_t altkeys[] = |
| 1402 |
{ |
| 1403 |
30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, |
| 1404 |
49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44 |
| 1405 |
}; |
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
static osfar_t int oss_command_pending; |
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
#define OSS_ICK_NORMAL 0 |
| 1448 |
#define OSS_ICK_CMD 1 |
| 1449 |
#define OSS_ICK_NEED_2ND 2 |
| 1450 |
#define OSS_ICK_BAD 3 |
| 1451 |
static int oss_interpret_command_key(int c, int translated) |
| 1452 |
{ |
| 1453 |
|
| 1454 |
oss_command_pending = 0; |
| 1455 |
|
| 1456 |
|
| 1457 |
if (c == 0) |
| 1458 |
{ |
| 1459 |
|
| 1460 |
return OSS_ICK_NEED_2ND; |
| 1461 |
} |
| 1462 |
else if (c >= 32 && c <= 255) |
| 1463 |
{ |
| 1464 |
|
| 1465 |
return OSS_ICK_NORMAL; |
| 1466 |
} |
| 1467 |
else if (translated) |
| 1468 |
{ |
| 1469 |
|
| 1470 |
switch(c) |
| 1471 |
{ |
| 1472 |
case 1: |
| 1473 |
oss_command_pending = CMD_HOME; |
| 1474 |
break; |
| 1475 |
case 2: |
| 1476 |
oss_command_pending = CMD_LEFT; |
| 1477 |
break; |
| 1478 |
case 4: |
| 1479 |
oss_command_pending = CMD_DEL; |
| 1480 |
break; |
| 1481 |
case 5: |
| 1482 |
oss_command_pending = CMD_END; |
| 1483 |
break; |
| 1484 |
case 6: |
| 1485 |
oss_command_pending = CMD_RIGHT; |
| 1486 |
break; |
| 1487 |
case '\t': |
| 1488 |
oss_command_pending = CMD_TAB; |
| 1489 |
break; |
| 1490 |
case 11: |
| 1491 |
oss_command_pending = CMD_DEOL; |
| 1492 |
break; |
| 1493 |
case 14: |
| 1494 |
oss_command_pending = CMD_DOWN; |
| 1495 |
break; |
| 1496 |
case 16: |
| 1497 |
oss_command_pending = CMD_UP; |
| 1498 |
break; |
| 1499 |
case 21: |
| 1500 |
case 27: |
| 1501 |
oss_command_pending = CMD_KILL; |
| 1502 |
break; |
| 1503 |
|
| 1504 |
case 13: |
| 1505 |
case 8: |
| 1506 |
|
| 1507 |
return OSS_ICK_NORMAL; |
| 1508 |
} |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
if (oss_command_pending != 0) |
| 1515 |
return OSS_ICK_CMD; |
| 1516 |
else |
| 1517 |
return OSS_ICK_BAD; |
| 1518 |
} |
| 1519 |
else |
| 1520 |
{ |
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
return OSS_ICK_NORMAL; |
| 1526 |
} |
| 1527 |
} |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
static int oss_interpret_2nd_key(int c, int translated) |
| 1544 |
{ |
| 1545 |
int i; |
| 1546 |
char *p; |
| 1547 |
|
| 1548 |
|
| 1549 |
for (i = 0, p = altkeys ; i < 26 ; ++p, ++i) |
| 1550 |
{ |
| 1551 |
if (c == *p) |
| 1552 |
{ |
| 1553 |
|
| 1554 |
oss_command_pending = CMD_ALT + i; |
| 1555 |
|
| 1556 |
|
| 1557 |
return OSS_ICK_CMD; |
| 1558 |
} |
| 1559 |
} |
| 1560 |
|
| 1561 |
|
| 1562 |
switch(c) |
| 1563 |
{ |
| 1564 |
case 0110: |
| 1565 |
oss_command_pending = CMD_UP; |
| 1566 |
break; |
| 1567 |
case 0120: |
| 1568 |
oss_command_pending = CMD_DOWN; |
| 1569 |
break; |
| 1570 |
case 0115: |
| 1571 |
oss_command_pending = CMD_RIGHT; |
| 1572 |
break; |
| 1573 |
case 0113: |
| 1574 |
oss_command_pending = CMD_LEFT; |
| 1575 |
break; |
| 1576 |
case 0117: |
| 1577 |
oss_command_pending = CMD_END; |
| 1578 |
break; |
| 1579 |
case 0107: |
| 1580 |
oss_command_pending = CMD_HOME; |
| 1581 |
break; |
| 1582 |
case 0165: |
| 1583 |
oss_command_pending = CMD_DEOL; |
| 1584 |
break; |
| 1585 |
case 0123: |
| 1586 |
oss_command_pending = CMD_DEL; |
| 1587 |
break; |
| 1588 |
case 073: |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
if (translated) |
| 1594 |
oss_command_pending = CMD_SCR; |
| 1595 |
else |
| 1596 |
oss_command_pending = CMD_F1; |
| 1597 |
break; |
| 1598 |
case 0111: |
| 1599 |
oss_command_pending = CMD_PGUP; |
| 1600 |
break; |
| 1601 |
case 0121: |
| 1602 |
oss_command_pending = CMD_PGDN; |
| 1603 |
break; |
| 1604 |
case 0122: |
| 1605 |
oss_command_pending = CMD_INS; |
| 1606 |
break; |
| 1607 |
case 132: |
| 1608 |
oss_command_pending = CMD_TOP; |
| 1609 |
break; |
| 1610 |
case 118: |
| 1611 |
oss_command_pending = CMD_BOT; |
| 1612 |
break; |
| 1613 |
case 119: |
| 1614 |
oss_command_pending = CMD_CHOME; |
| 1615 |
break; |
| 1616 |
case 115: |
| 1617 |
oss_command_pending = CMD_WORD_LEFT; |
| 1618 |
break; |
| 1619 |
case 116: |
| 1620 |
oss_command_pending = CMD_WORD_RIGHT; |
| 1621 |
break; |
| 1622 |
|
| 1623 |
case 60: oss_command_pending = CMD_F2; break; |
| 1624 |
case 61: oss_command_pending = CMD_F3; break; |
| 1625 |
case 62: oss_command_pending = CMD_F4; break; |
| 1626 |
case 63: oss_command_pending = CMD_F5; break; |
| 1627 |
case 64: oss_command_pending = CMD_F6; break; |
| 1628 |
case 65: oss_command_pending = CMD_F7; break; |
| 1629 |
case 66: oss_command_pending = CMD_F8; break; |
| 1630 |
case 67: oss_command_pending = CMD_F9; break; |
| 1631 |
case 68: oss_command_pending = CMD_F10; break; |
| 1632 |
|
| 1633 |
case 85: oss_command_pending = CMD_SF2; break; |
| 1634 |
|
| 1635 |
default: |
| 1636 |
oss_command_pending = 0; |
| 1637 |
break; |
| 1638 |
} |
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
if (oss_command_pending != 0) |
| 1645 |
return OSS_ICK_CMD; |
| 1646 |
else |
| 1647 |
return OSS_ICK_BAD; |
| 1648 |
} |
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
int oss_get_pending_command() |
| 1657 |
{ |
| 1658 |
int ret; |
| 1659 |
|
| 1660 |
|
| 1661 |
ret = oss_command_pending; |
| 1662 |
|
| 1663 |
|
| 1664 |
oss_command_pending = 0; |
| 1665 |
|
| 1666 |
|
| 1667 |
return ret; |
| 1668 |
} |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
static int os_getc_internal(unsigned char *ch, |
| 1677 |
unsigned long timeout, int use_timeout, |
| 1678 |
int translated) |
| 1679 |
{ |
| 1680 |
int status; |
| 1681 |
|
| 1682 |
|
| 1683 |
osssb_redraw_if_needed(); |
| 1684 |
|
| 1685 |
|
| 1686 |
if (!S_keep_cursor_pos) |
| 1687 |
osssb_cursor_to_default_pos(); |
| 1688 |
|
| 1689 |
|
| 1690 |
if (oss_command_pending != 0) |
| 1691 |
{ |
| 1692 |
*ch = oss_get_pending_command(); |
| 1693 |
return OS_GETS_OK; |
| 1694 |
} |
| 1695 |
|
| 1696 |
|
| 1697 |
for (;;) |
| 1698 |
{ |
| 1699 |
|
| 1700 |
status = oss_getc_internal(ch, timeout, use_timeout); |
| 1701 |
|
| 1702 |
|
| 1703 |
switch(status) |
| 1704 |
{ |
| 1705 |
case OS_GETS_OK: |
| 1706 |
|
| 1707 |
break; |
| 1708 |
|
| 1709 |
default: |
| 1710 |
|
| 1711 |
return status; |
| 1712 |
} |
| 1713 |
|
| 1714 |
|
| 1715 |
switch(oss_interpret_command_key(*ch, translated)) |
| 1716 |
{ |
| 1717 |
case OSS_ICK_BAD: |
| 1718 |
|
| 1719 |
break; |
| 1720 |
|
| 1721 |
case OSS_ICK_NORMAL: |
| 1722 |
|
| 1723 |
return OS_GETS_OK; |
| 1724 |
|
| 1725 |
case OSS_ICK_CMD: |
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
*ch = 0; |
| 1731 |
return OS_GETS_OK; |
| 1732 |
|
| 1733 |
case OSS_ICK_NEED_2ND: |
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
oss_getc_internal(ch, 0, FALSE); |
| 1741 |
switch(oss_interpret_2nd_key(*ch, translated)) |
| 1742 |
{ |
| 1743 |
case OSS_ICK_BAD: |
| 1744 |
|
| 1745 |
break; |
| 1746 |
|
| 1747 |
case OSS_ICK_CMD: |
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
*ch = 0; |
| 1753 |
return OS_GETS_OK; |
| 1754 |
} |
| 1755 |
} |
| 1756 |
} |
| 1757 |
} |
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
int os_getc_timeout(unsigned char *ch, unsigned long timeout) |
| 1763 |
{ |
| 1764 |
|
| 1765 |
return os_getc_internal(ch, timeout, TRUE, TRUE); |
| 1766 |
} |
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
int os_getc(void) |
| 1772 |
{ |
| 1773 |
unsigned char ch; |
| 1774 |
|
| 1775 |
|
| 1776 |
os_getc_internal(&ch, 0, FALSE, TRUE); |
| 1777 |
|
| 1778 |
|
| 1779 |
return ch; |
| 1780 |
} |
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
int os_getc_raw(void) |
| 1786 |
{ |
| 1787 |
unsigned char ch; |
| 1788 |
|
| 1789 |
|
| 1790 |
os_getc_internal(&ch, 0, FALSE, FALSE); |
| 1791 |
|
| 1792 |
|
| 1793 |
return ch; |
| 1794 |
} |
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
int os_get_event(unsigned long timeout_in_milliseconds, int use_timeout, |
| 1801 |
os_event_info_t *info) |
| 1802 |
{ |
| 1803 |
int kbstat; |
| 1804 |
unsigned char ch; |
| 1805 |
|
| 1806 |
|
| 1807 |
kbstat = os_getc_internal(&ch, timeout_in_milliseconds, use_timeout, |
| 1808 |
FALSE); |
| 1809 |
|
| 1810 |
|
| 1811 |
if (kbstat == OS_GETS_TIMEOUT) |
| 1812 |
return OS_EVT_TIMEOUT; |
| 1813 |
|
| 1814 |
|
| 1815 |
if (kbstat == OS_GETS_OK) |
| 1816 |
{ |
| 1817 |
|
| 1818 |
info->key[0] = (int)ch; |
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
if (ch == 0) |
| 1827 |
info->key[1] = os_getc(); |
| 1828 |
|
| 1829 |
|
| 1830 |
return OS_EVT_KEY; |
| 1831 |
} |
| 1832 |
|
| 1833 |
|
| 1834 |
return OS_EVT_EOF; |
| 1835 |
} |
| 1836 |
|
| 1837 |
|
| 1838 |
#else |
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
int os_init(int *argc, char **argv, const char *prompt, char *buf, int bufsiz) |
| 1844 |
{ |
| 1845 |
return 0; |
| 1846 |
} |
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
void os_uninit() |
| 1852 |
{ |
| 1853 |
} |
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
int os_getc(void) |
| 1859 |
{ |
| 1860 |
int c; |
| 1861 |
|
| 1862 |
|
| 1863 |
for (;;) |
| 1864 |
{ |
| 1865 |
|
| 1866 |
c = os_getch(); |
| 1867 |
|
| 1868 |
|
| 1869 |
if ((c & 0xff) != 0) |
| 1870 |
return c; |
| 1871 |
} |
| 1872 |
} |
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
int os_getc_raw(void) |
| 1879 |
{ |
| 1880 |
|
| 1881 |
return os_getc(); |
| 1882 |
} |
| 1883 |
|
| 1884 |
#endif |
| 1885 |
|
| 1886 |
# endif |
| 1887 |
#endif |
| 1888 |
|
| 1889 |
extern unsigned long ossgetdisks(void); |
| 1890 |
# ifdef RUNTIME |
| 1891 |
# if (!defined(WINDOWS) && !defined(_Windows)) || defined(__DPMI16__) |
| 1892 |
# if defined(TURBO) || defined(DJGPP) |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
# define OSS_MAXPATH MAXPATH |
| 1900 |
|
| 1901 |
|
| 1902 |
# ifdef TURBO |
| 1903 |
# define osspwd(buf, buflen) ((void)getcwd(buf, buflen)) |
| 1904 |
# endif |
| 1905 |
|
| 1906 |
|
| 1907 |
# define osscd(path) ((void)chdir(path)) |
| 1908 |
|
| 1909 |
|
| 1910 |
# define osssetdisk(drivenum) ((void)setdisk(drivenum)) |
| 1911 |
|
| 1912 |
|
| 1913 |
# define ossgetdisk() getdisk() |
| 1914 |
|
| 1915 |
|
| 1916 |
# define OSSFNAMELEN 14 |
| 1917 |
|
| 1918 |
# ifdef DJGPP |
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
static void osspwd(char *buf, int buflen) |
| 1923 |
{ |
| 1924 |
char *p; |
| 1925 |
|
| 1926 |
getcwd(buf, buflen); |
| 1927 |
for (p = buf; *p; p++) |
| 1928 |
if (*p == '/') *p = '\\'; |
| 1929 |
} |
| 1930 |
# endif |
| 1931 |
# endif |
| 1932 |
|
| 1933 |
# ifdef MSOS2 |
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
# define OSS_MAXPATH 128 |
| 1941 |
|
| 1942 |
|
| 1943 |
# define osspwd(buf, buflen) ((void)getcwd(buf, buflen)) |
| 1944 |
|
| 1945 |
#ifdef __32BIT__ |
| 1946 |
# ifndef __IBMC__ |
| 1947 |
# define DosSelectDisk(a) DosSetDefaultDisk(a) |
| 1948 |
# define DosQCurDisk(a,b) DosQueryCurrentDisk(a,b) |
| 1949 |
# endif |
| 1950 |
typedef ULONG drive_t; |
| 1951 |
#else |
| 1952 |
# define DosFindFirst(a,b,c,d,e,f) DosFindFirst(a,b,c,d,e,f,0L) |
| 1953 |
typedef USHORT drive_t; |
| 1954 |
#endif |
| 1955 |
|
| 1956 |
|
| 1957 |
# define osscd(path) ((void)chdir(path)) |
| 1958 |
|
| 1959 |
|
| 1960 |
static void osssetdisk(int drv) |
| 1961 |
{ |
| 1962 |
DosSelectDisk((drive_t)(drv+1)); |
| 1963 |
} |
| 1964 |
|
| 1965 |
|
| 1966 |
static int ossgetdisk(void) |
| 1967 |
{ |
| 1968 |
drive_t drv; |
| 1969 |
ULONG map; |
| 1970 |
|
| 1971 |
return( DosQCurDisk(&drv, &map) ? -1 : (int)(drv-1) ); |
| 1972 |
} |
| 1973 |
|
| 1974 |
|
| 1975 |
# define OSSFNAMELEN 14 |
| 1976 |
|
| 1977 |
# else |
| 1978 |
# ifdef MICROSOFT |
| 1979 |
|
| 1980 |
# ifdef T_WIN32 |
| 1981 |
|
| 1982 |
#include <io.h> |
| 1983 |
#include <direct.h> |
| 1984 |
|
| 1985 |
#define OSS_MAXPATH _MAX_PATH |
| 1986 |
#define OSSFNAMELEN _MAX_FNAME |
| 1987 |
#define osspwd(buf, buflen) ((void)_getcwd(buf, buflen)) |
| 1988 |
|
| 1989 |
#define ossgetdisk() (_getdrive() - 1) |
| 1990 |
#define osssetdisk(disk) _chdrive((disk) + 1) |
| 1991 |
#define osscd(path) _chdir(path) |
| 1992 |
|
| 1993 |
# else |
| 1994 |
|
| 1995 |
|
| 1996 |
# define OSS_MAXPATH 128 |
| 1997 |
|
| 1998 |
|
| 1999 |
# define osspwd(buf, buflen) ((void)getcwd(buf, buflen)) |
| 2000 |
|
| 2001 |
|
| 2002 |
# define osscd(path) ((void)chdir(path)) |
| 2003 |
|
| 2004 |
static int ossgetdisk(void) |
| 2005 |
{ |
| 2006 |
unsigned int drive; |
| 2007 |
_dos_getdrive(&drive); |
| 2008 |
return(drive + 1); |
| 2009 |
} |
| 2010 |
|
| 2011 |
static void osssetdisk(int drivenum) |
| 2012 |
{ |
| 2013 |
unsigned int maxdrives; |
| 2014 |
_dos_setdrive(drivenum + 1, &maxdrives); |
| 2015 |
} |
| 2016 |
|
| 2017 |
|
| 2018 |
# define OSSFNAMELEN 14 |
| 2019 |
|
| 2020 |
# endif |
| 2021 |
# endif |
| 2022 |
# endif |
| 2023 |
|
| 2024 |
|
| 2025 |
static char *fwd_file(char *cur) |
| 2026 |
{ |
| 2027 |
return(cur + OSSFNAMELEN); |
| 2028 |
} |
| 2029 |
|
| 2030 |
|
| 2031 |
static char *backup_file(char *cur, char *first) |
| 2032 |
{ |
| 2033 |
if (cur == first) |
| 2034 |
return cur; |
| 2035 |
else |
| 2036 |
return cur - OSSFNAMELEN; |
| 2037 |
} |
| 2038 |
|
| 2039 |
|
| 2040 |
static int fnamecmp(const void *a0, const void *b0) |
| 2041 |
{ |
| 2042 |
char *a = (char *)a0; |
| 2043 |
char *b = (char *)b0; |
| 2044 |
int atyp, btyp; |
| 2045 |
char c; |
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
c = a[strlen(a) - 1]; |
| 2054 |
atyp = (c == ':' ? 0 : c == '\\' ? 1 : 2); |
| 2055 |
|
| 2056 |
|
| 2057 |
c = b[strlen(b) - 1]; |
| 2058 |
btyp = (c == ':' ? 0 : c == '\\' ? 1 : 2); |
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
if (atyp != btyp) |
| 2066 |
return atyp - btyp; |
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
if (atyp == 1) |
| 2073 |
{ |
| 2074 |
if (a[0] == '.' && b[0] != '.') |
| 2075 |
return -1; |
| 2076 |
else if (a[0] != '.' && b[0] == '.') |
| 2077 |
return 1; |
| 2078 |
} |
| 2079 |
|
| 2080 |
|
| 2081 |
return stricmp(a, b); |
| 2082 |
} |
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
int os_askfile(const char *prompt, char *reply, int replen, |
| 2088 |
int prompt_type, os_filetype_t file_type) |
| 2089 |
{ |
| 2090 |
static osfar_t char *curdir; |
| 2091 |
static osfar_t int curdirl; |
| 2092 |
static osfar_t char curdisk; |
| 2093 |
static osfar_t int gotdir; |
| 2094 |
static osfar_t char *namebuf; |
| 2095 |
static osfar_t int namebufl; |
| 2096 |
int old_keep_cursor_pos; |
| 2097 |
int rem; |
| 2098 |
int newfile; |
| 2099 |
char lbuf[80]; |
| 2100 |
char *p; |
| 2101 |
char *curpage; |
| 2102 |
char *curfile; |
| 2103 |
int curofs; |
| 2104 |
int pageofs; |
| 2105 |
int filecnt; |
| 2106 |
int ent_x, ent_y; |
| 2107 |
int min_ent_x; |
| 2108 |
char *newp; |
| 2109 |
int insel; |
| 2110 |
int lastofs; |
| 2111 |
int retval; |
| 2112 |
int bottom; |
| 2113 |
int instruct_y; |
| 2114 |
int list_top, list_bottom; |
| 2115 |
int top; |
| 2116 |
int left; |
| 2117 |
int right; |
| 2118 |
int y; |
| 2119 |
int i; |
| 2120 |
static osfar_t char *lastfile; |
| 2121 |
static osfar_t char filebuf[256]; |
| 2122 |
char runpwd[OSS_MAXPATH]; |
| 2123 |
char rundisk; |
| 2124 |
osdirhdl_t dirhdl; |
| 2125 |
unsigned long fmode; |
| 2126 |
unsigned long fattr; |
| 2127 |
char *ext; |
| 2128 |
size_t extlen; |
| 2129 |
unsigned long drives; |
| 2130 |
static osfar_t char *ext_list[] = |
| 2131 |
{ |
| 2132 |
".GAM", |
| 2133 |
".SAV", |
| 2134 |
".LOG", |
| 2135 |
".DAT", |
| 2136 |
".DAT", |
| 2137 |
".CMD", |
| 2138 |
".MSG", |
| 2139 |
".TXT", |
| 2140 |
".DAT", |
| 2141 |
".TCP", |
| 2142 |
".DAT", |
| 2143 |
"", |
| 2144 |
".t3", |
| 2145 |
".t3o", |
| 2146 |
".t3s", |
| 2147 |
".t3v" |
| 2148 |
}; |
| 2149 |
|
| 2150 |
|
| 2151 |
osssb_redraw_if_needed(); |
| 2152 |
|
| 2153 |
|
| 2154 |
if (namebuf == 0) |
| 2155 |
{ |
| 2156 |
namebuf = (char *)calloc(namebufl = (256 * OSSFNAMELEN), 1); |
| 2157 |
curdir = (char *)calloc(curdirl = OSS_MAXPATH, 1); |
| 2158 |
lastfile = (char *)calloc(OSS_MAXPATH, 1); |
| 2159 |
} |
| 2160 |
|
| 2161 |
|
| 2162 |
if (!namebuf || !curdir || !lastfile || os_f_plain || use_std_askfile) |
| 2163 |
{ |
| 2164 |
|
| 2165 |
os_printz(prompt); |
| 2166 |
os_printz(" >"); |
| 2167 |
os_gets((uchar *)reply, replen); |
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
return (prompt[0] == '\0' ? OS_AFE_CANCEL : OS_AFE_SUCCESS); |
| 2174 |
} |
| 2175 |
|
| 2176 |
|
| 2177 |
old_keep_cursor_pos = S_keep_cursor_pos; |
| 2178 |
S_keep_cursor_pos = TRUE; |
| 2179 |
|
| 2180 |
|
| 2181 |
newfile = (prompt_type == OS_AFP_SAVE); |
| 2182 |
insel = !newfile; |
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
filebuf[0] = '\0'; |
| 2189 |
if (lastfile[0] != '\0') |
| 2190 |
{ |
| 2191 |
char c = lastfile[strlen(lastfile) - 1]; |
| 2192 |
|
| 2193 |
if (c != ':' && c != '\\') |
| 2194 |
strcpy(filebuf, lastfile); |
| 2195 |
} |
| 2196 |
|
| 2197 |
|
| 2198 |
if (file_type != OSFTUNK |
| 2199 |
&& (int)file_type >= 0 |
| 2200 |
&& (int)file_type < sizeof(ext_list)/sizeof(ext_list[0])) |
| 2201 |
{ |
| 2202 |
ext = ext_list[(int)file_type]; |
| 2203 |
extlen = strlen(ext); |
| 2204 |
} |
| 2205 |
else |
| 2206 |
{ |
| 2207 |
ext = 0; |
| 2208 |
extlen = 0; |
| 2209 |
} |
| 2210 |
|
| 2211 |
|
| 2212 |
rundisk = ossgetdisk(); |
| 2213 |
|
| 2214 |
|
| 2215 |
if (!gotdir) |
| 2216 |
{ |
| 2217 |
osspwd(curdir, curdirl); |
| 2218 |
curdisk = ossgetdisk(); |
| 2219 |
gotdir = 1; |
| 2220 |
} |
| 2221 |
else |
| 2222 |
osssetdisk(curdisk); |
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
top = 3; |
| 2230 |
bottom = G_oss_screen_height - 4; |
| 2231 |
left = 10; |
| 2232 |
right = G_oss_screen_width - 11; |
| 2233 |
ossclr(top, left, bottom, right, ldesc_color); |
| 2234 |
|
| 2235 |
|
| 2236 |
lbuf[0] = (char)218; |
| 2237 |
for (p = lbuf+1, i = right - left - 1 ; i ; --i) |
| 2238 |
*p++ = (uchar)196; |
| 2239 |
*p++ = (char)191; |
| 2240 |
*p++ = (char)0; |
| 2241 |
ossdsp(top, left, ldesc_color, lbuf); |
| 2242 |
|
| 2243 |
|
| 2244 |
instruct_y = bottom - 1; |
| 2245 |
|
| 2246 |
|
| 2247 |
if (newfile) |
| 2248 |
instruct_y -= 2; |
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
if (ossgetdisks() == 0) |
| 2255 |
instruct_y -= 1; |
| 2256 |
|
| 2257 |
|
| 2258 |
lbuf[0] = (char)179; |
| 2259 |
for (p = lbuf+1, i = right - left - 3 ; i ; --i) |
| 2260 |
*p++ = ' '; |
| 2261 |
*p++ = (char)179; |
| 2262 |
*p++ = ' '; |
| 2263 |
*p++ = (char)179; |
| 2264 |
*p++ = (char)0; |
| 2265 |
for (y = top+3 ; y < instruct_y - 1 ; ++y) |
| 2266 |
ossdsp(y, left, ldesc_color, lbuf); |
| 2267 |
|
| 2268 |
|
| 2269 |
*(p - 4) = ' '; |
| 2270 |
ossdsp(top + 1, left, ldesc_color, lbuf); |
| 2271 |
for (y = instruct_y ; y < bottom ; ++y) |
| 2272 |
ossdsp(y, left, ldesc_color, lbuf); |
| 2273 |
|
| 2274 |
|
| 2275 |
lbuf[0] = (char)195; |
| 2276 |
for (p = lbuf+1, i = right - left - 3 ; i ; --i) |
| 2277 |
*p++ = (char)196; |
| 2278 |
*p++ = (char)194; |
| 2279 |
*p++ = (char)196; |
| 2280 |
*p++ = (char)180; |
| 2281 |
*p++ = (char)0; |
| 2282 |
ossdsp(top+2, left, ldesc_color, lbuf); |
| 2283 |
|
| 2284 |
|
| 2285 |
*(p - 4) = (char)193; |
| 2286 |
ossdsp(instruct_y - 1, left, ldesc_color, lbuf); |
| 2287 |
|
| 2288 |
|
| 2289 |
lbuf[0] = (char)192; |
| 2290 |
for (p = lbuf+1, i = right - left - 1 ; i ; --i) |
| 2291 |
*p++ = (char)196; |
| 2292 |
*p++ = (char)217; |
| 2293 |
*p++ = (char)0; |
| 2294 |
ossdsp(bottom, left, ldesc_color, lbuf); |
| 2295 |
|
| 2296 |
|
| 2297 |
y = instruct_y; |
| 2298 |
if (newfile) |
| 2299 |
{ |
| 2300 |
|
| 2301 |
ossdsp(y, left + 1, ldesc_color, "Filename:"); |
| 2302 |
|
| 2303 |
|
| 2304 |
ent_y = y; |
| 2305 |
ent_x = min_ent_x = left + 1 + 11; |
| 2306 |
|
| 2307 |
|
| 2308 |
y += 2; |
| 2309 |
} |
| 2310 |
|
| 2311 |
|
| 2312 |
ossdsp(y, left + 1, ldesc_color, |
| 2313 |
newfile |
| 2314 |
? "<Return>=OK, <Esc>=Cancel, <Tab>=List/Filename" |
| 2315 |
: "<Return>=OK, <Esc>=Cancel"); |
| 2316 |
++y; |
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
if (ossgetdisks() == 0) |
| 2323 |
ossdsp(y, left + 1, ldesc_color, |
| 2324 |
"<Alt+A>=go to drive A:, <Alt+B>=B:, etc."); |
| 2325 |
|
| 2326 |
|
| 2327 |
list_top = top + 3; |
| 2328 |
list_bottom = instruct_y - 2; |
| 2329 |
|
| 2330 |
reread_directory: |
| 2331 |
|
| 2332 |
osspwd(runpwd, sizeof(runpwd)); |
| 2333 |
osscd(curdir); |
| 2334 |
|
| 2335 |
|
| 2336 |
p = namebuf; |
| 2337 |
rem = namebufl - 2; |
| 2338 |
filecnt = 0; |
| 2339 |
lastofs = -1; |
| 2340 |
if (os_open_dir(curdir, &dirhdl)) |
| 2341 |
{ |
| 2342 |
while (rem >= OSSFNAMELEN + 2 && os_read_dir(dirhdl, p, rem)) |
| 2343 |
{ |
| 2344 |
|
| 2345 |
size_t len = strlen(p); |
| 2346 |
if (osfmode(p, TRUE, &fmode, &fattr) |
| 2347 |
&& (fmode & OSFMODE_FILE) != 0 |
| 2348 |
&& (fattr & (OSFATTR_HIDDEN | OSFATTR_SYSTEM)) == 0 |
| 2349 |
&& (ext == 0 |
| 2350 |
|| (len >= extlen |
| 2351 |
&& memicmp(p + len - extlen, ext, extlen) == 0))) |
| 2352 |
{ |
| 2353 |
++filecnt; |
| 2354 |
rem -= OSSFNAMELEN; |
| 2355 |
p += OSSFNAMELEN; |
| 2356 |
} |
| 2357 |
} |
| 2358 |
os_close_dir(dirhdl); |
| 2359 |
} |
| 2360 |
|
| 2361 |
|
| 2362 |
if (os_open_dir(curdir, &dirhdl)) |
| 2363 |
{ |
| 2364 |
while (rem >= OSSFNAMELEN + 2 && os_read_dir(dirhdl, p, rem)) |
| 2365 |
{ |
| 2366 |
|
| 2367 |
if (osfmode(p, TRUE, &fmode, &fattr) |
| 2368 |
&& (fmode & OSFMODE_DIR) != 0 |
| 2369 |
&& (fattr & (OSFATTR_HIDDEN | OSFATTR_SYSTEM)) == 0 |
| 2370 |
&& strcmp(p, ".") != 0) |
| 2371 |
{ |
| 2372 |
char *pend; |
| 2373 |
|
| 2374 |
++filecnt; |
| 2375 |
pend = p + strlen(p); |
| 2376 |
*pend++ = '\\'; |
| 2377 |
*pend++ = '\0'; |
| 2378 |
rem -= OSSFNAMELEN; |
| 2379 |
p += OSSFNAMELEN; |
| 2380 |
} |
| 2381 |
} |
| 2382 |
os_close_dir(dirhdl); |
| 2383 |
} |
| 2384 |
|
| 2385 |
|
| 2386 |
if ((drives = ossgetdisks()) != 0) |
| 2387 |
{ |
| 2388 |
int bit; |
| 2389 |
unsigned long mask; |
| 2390 |
char drive_letter; |
| 2391 |
|
| 2392 |
|
| 2393 |
for (bit = 0, mask = 1, drive_letter = 'A' ; bit < 32 ; |
| 2394 |
++bit, ++drive_letter, mask <<= 1) |
| 2395 |
{ |
| 2396 |
|
| 2397 |
if ((drives & mask) != 0 && rem >= OSSFNAMELEN + 2) |
| 2398 |
{ |
| 2399 |
char *pend = p; |
| 2400 |
|
| 2401 |
|
| 2402 |
*pend++ = drive_letter; |
| 2403 |
*pend++ = ':'; |
| 2404 |
*pend++ = '\0'; |
| 2405 |
rem -= OSSFNAMELEN; |
| 2406 |
p += OSSFNAMELEN; |
| 2407 |
|
| 2408 |
|
| 2409 |
++filecnt; |
| 2410 |
} |
| 2411 |
} |
| 2412 |
} |
| 2413 |
|
| 2414 |
|
| 2415 |
*p++ = '\0'; |
| 2416 |
*p++ = '\0'; |
| 2417 |
|
| 2418 |
|
| 2419 |
osscd(runpwd); |
| 2420 |
|
| 2421 |
|
| 2422 |
qsort(namebuf, (size_t)filecnt, (size_t)OSSFNAMELEN, fnamecmp); |
| 2423 |
|
| 2424 |
|
| 2425 |
ossclr(list_top, left+1, list_bottom, right - 3, ldesc_color); |
| 2426 |
|
| 2427 |
|
| 2428 |
ossclr(top+1, left+1, top+1, right-1, ldesc_color); |
| 2429 |
|
| 2430 |
|
| 2431 |
ossdsp(top+1, left+1, ldesc_color, curdir); |
| 2432 |
|
| 2433 |
|
| 2434 |
if (newfile) |
| 2435 |
{ |
| 2436 |
|
| 2437 |
ossclr(ent_y, ent_x, ent_y, right - 2, text_color); |
| 2438 |
|
| 2439 |
|
| 2440 |
ossdsp(ent_y, ent_x, text_color, filebuf); |
| 2441 |
|
| 2442 |
|
| 2443 |
newp = filebuf; |
| 2444 |
} |
| 2445 |
|
| 2446 |
|
| 2447 |
for (i = 0, p = namebuf ; i < filecnt ; p = fwd_file(p), ++i) |
| 2448 |
{ |
| 2449 |
|
| 2450 |
if (strcmp(lastfile, p) == 0) |
| 2451 |
lastofs = i; |
| 2452 |
} |
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
|
| 2458 |
|
| 2459 |
if (lastofs == -1) |
| 2460 |
{ |
| 2461 |
|
| 2462 |
for (i = 0, p = namebuf ; i < filecnt ; p = fwd_file(p), ++i) |
| 2463 |
{ |
| 2464 |
char c; |
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
c = p[strlen(p) - 1]; |
| 2472 |
if ((c == ':' || (p[0] == '.' && p[1] == '.' && p[2] == '\\')) |
| 2473 |
&& i + 1 < filecnt) |
| 2474 |
{ |
| 2475 |
|
| 2476 |
lastofs = i + 1; |
| 2477 |
} |
| 2478 |
} |
| 2479 |
} |
| 2480 |
|
| 2481 |
|
| 2482 |
curpage = curfile = namebuf; |
| 2483 |
curofs = 0; |
| 2484 |
pageofs = 0; |
| 2485 |
if (lastofs != -1) |
| 2486 |
{ |
| 2487 |
for (i = 0 ; i < lastofs ; ++i) |
| 2488 |
{ |
| 2489 |
curfile = fwd_file(curfile); |
| 2490 |
if (curofs >= list_bottom - list_top) |
| 2491 |
{ |
| 2492 |
++pageofs; |
| 2493 |
curpage = fwd_file(curpage); |
| 2494 |
} |
| 2495 |
else |
| 2496 |
++curofs; |
| 2497 |
} |
| 2498 |
} |
| 2499 |
lastofs = -1; |
| 2500 |
|
| 2501 |
|
| 2502 |
for (p = curpage, y = list_top ; |
| 2503 |
*p != '\0' && y <= list_bottom && filecnt != 0 ; ++y) |
| 2504 |
{ |
| 2505 |
ossdsp(y, left+2, ldesc_color, p); |
| 2506 |
p = fwd_file(p); |
| 2507 |
} |
| 2508 |
|
| 2509 |
|
| 2510 |
for (;;) |
| 2511 |
{ |
| 2512 |
unsigned char c; |
| 2513 |
int thumb_y; |
| 2514 |
|
| 2515 |
if (filecnt - (list_bottom - list_top + 1) > 0) |
| 2516 |
thumb_y = (pageofs * (list_bottom - list_top)) / |
| 2517 |
(filecnt - (list_bottom - list_top)); |
| 2518 |
else |
| 2519 |
thumb_y = 0; |
| 2520 |
|
| 2521 |
|
| 2522 |
if (insel) |
| 2523 |
{ |
| 2524 |
ossdsp(list_top + curofs, left + 2, text_color, curfile); |
| 2525 |
ossdsp(list_top + thumb_y, right - 1, text_color, "\260"); |
| 2526 |
ossdsp(list_top + thumb_y + 1, right - 1, text_color, "\260"); |
| 2527 |
} |
| 2528 |
|
| 2529 |
|
| 2530 |
if (newfile && !insel) |
| 2531 |
ossloc(ent_y, ent_x); |
| 2532 |
else |
| 2533 |
ossloc(list_top + curofs, left + 2); |
| 2534 |
|
| 2535 |
|
| 2536 |
c = os_getc(); |
| 2537 |
|
| 2538 |
if (insel) |
| 2539 |
{ |
| 2540 |
ossdsp(list_top + curofs, left+2, ldesc_color, curfile); |
| 2541 |
ossdsp(list_top + thumb_y, right - 1, ldesc_color, " "); |
| 2542 |
ossdsp(list_top + thumb_y + 1, right - 1, ldesc_color, " "); |
| 2543 |
} |
| 2544 |
|
| 2545 |
|
| 2546 |
if (c == '\0') |
| 2547 |
{ |
| 2548 |
|
| 2549 |
c = os_getc(); |
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
if (drives == 0 && c >= CMD_ALT) |
| 2558 |
{ |
| 2559 |
|
| 2560 |
osssetdisk(c - CMD_ALT); |
| 2561 |
if (ossgetdisk() == c - CMD_ALT) |
| 2562 |
{ |
| 2563 |
curdisk = ossgetdisk(); |
| 2564 |
osspwd(curdir, curdirl); |
| 2565 |
goto reread_directory; |
| 2566 |
} |
| 2567 |
} |
| 2568 |
|
| 2569 |
|
| 2570 |
switch(c) |
| 2571 |
{ |
| 2572 |
case CMD_UP: |
| 2573 |
|
| 2574 |
if (curofs == 0 && pageofs == 0) |
| 2575 |
break; |
| 2576 |
|
| 2577 |
|
| 2578 |
if (curofs == 0) |
| 2579 |
{ |
| 2580 |
|
| 2581 |
--pageofs; |
| 2582 |
curpage = backup_file(curpage, namebuf); |
| 2583 |
ossscu(list_top, left + 1, list_bottom, right - 3, |
| 2584 |
ldesc_color); |
| 2585 |
} |
| 2586 |
else |
| 2587 |
{ |
| 2588 |
|
| 2589 |
--curofs; |
| 2590 |
} |
| 2591 |
|
| 2592 |
|
| 2593 |
curfile = backup_file(curfile, namebuf); |
| 2594 |
break; |
| 2595 |
|
| 2596 |
case CMD_DOWN: |
| 2597 |
if (!*fwd_file(curfile)) break; |
| 2598 |
if (curofs >= list_bottom - list_top) |
| 2599 |
{ |
| 2600 |
++pageofs; |
| 2601 |
curpage = fwd_file(curpage); |
| 2602 |
ossscr(list_top, left + 1, |
| 2603 |
list_bottom, right - 3, ldesc_color); |
| 2604 |
} |
| 2605 |
else |
| 2606 |
++curofs; |
| 2607 |
|
| 2608 |
curfile = fwd_file(curfile); |
| 2609 |
break; |
| 2610 |
|
| 2611 |
case CMD_KILL: |
| 2612 |
|
| 2613 |
retval = OS_AFE_CANCEL; |
| 2614 |
goto done; |
| 2615 |
|
| 2616 |
case CMD_EOF: |
| 2617 |
retval = OS_AFE_CANCEL; |
| 2618 |
goto done; |
| 2619 |
|
| 2620 |
case CMD_TAB: |
| 2621 |
if (!newfile) break; |
| 2622 |
insel = !insel; |
| 2623 |
break; |
| 2624 |
|
| 2625 |
default: |
| 2626 |
break; |
| 2627 |
} |
| 2628 |
} |
| 2629 |
else if (c == '\r') |
| 2630 |
{ |
| 2631 |
|
| 2632 |
strcpy(reply, curfile); |
| 2633 |
if (insel && strlen(reply) && reply[strlen(reply) - 1] == '\\') |
| 2634 |
{ |
| 2635 |
char *root; |
| 2636 |
|
| 2637 |
|
| 2638 |
osspwd(runpwd, sizeof(runpwd)); |
| 2639 |
osscd(curdir); |
| 2640 |
|
| 2641 |
|
| 2642 |
root = os_get_root_name(curdir); |
| 2643 |
|
| 2644 |
|
| 2645 |
if (strlen(curdir) && curdir[strlen(curdir)-1] != '\\') |
| 2646 |
strcat(curdir, "\\"); |
| 2647 |
reply[strlen(reply) - 1] = '\0'; |
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
if (strcmp(curfile, "..\\") == 0) |
| 2658 |
{ |
| 2659 |
|
| 2660 |
strcpy(lastfile, root); |
| 2661 |
} |
| 2662 |
else |
| 2663 |
{ |
| 2664 |
|
| 2665 |
strcpy(lastfile, "..\\"); |
| 2666 |
} |
| 2667 |
|
| 2668 |
|
| 2669 |
osscd(reply); |
| 2670 |
osspwd(curdir, curdirl); |
| 2671 |
|
| 2672 |
|
| 2673 |
osscd(runpwd); |
| 2674 |
goto reread_directory; |
| 2675 |
} |
| 2676 |
|
| 2677 |
|
| 2678 |
if (insel && strlen(reply) && reply[strlen(reply) - 1] == ':') |
| 2679 |
{ |
| 2680 |
|
| 2681 |
osssetdisk(reply[0] - 'A'); |
| 2682 |
if (ossgetdisk() == reply[0] - 'A') |
| 2683 |
{ |
| 2684 |
curdisk = ossgetdisk(); |
| 2685 |
osspwd(curdir, curdirl); |
| 2686 |
goto reread_directory; |
| 2687 |
} |
| 2688 |
} |
| 2689 |
|
| 2690 |
|
| 2691 |
if (newfile && insel) |
| 2692 |
{ |
| 2693 |
newp = filebuf; |
| 2694 |
strcpy(filebuf, reply); |
| 2695 |
ent_x = min_ent_x; |
| 2696 |
insel = 0; |
| 2697 |
ossclr(ent_y, ent_x, ent_y, right - 2, text_color); |
| 2698 |
ossdsp(ent_y, ent_x, text_color, filebuf); |
| 2699 |
} |
| 2700 |
else |
| 2701 |
{ |
| 2702 |
int l; |
| 2703 |
|
| 2704 |
strcpy(reply, curdir); |
| 2705 |
l = strlen(reply); |
| 2706 |
if (!l || reply[l-1] != '\\') reply[l++] = '\\'; |
| 2707 |
strcpy(reply+l, newfile ? filebuf : curfile); |
| 2708 |
retval = OS_AFE_SUCCESS; |
| 2709 |
strcpy(lastfile, filebuf); |
| 2710 |
if (!strchr(lastfile, '.')) |
| 2711 |
strcat(lastfile, ext); |
| 2712 |
if (!strchr(reply + l, '.')) |
| 2713 |
strcat(reply, ext); |
| 2714 |
|
| 2715 |
|
| 2716 |
if (!lastfile[0]) |
| 2717 |
retval = OS_AFE_CANCEL; |
| 2718 |
|
| 2719 |
|
| 2720 |
goto done; |
| 2721 |
} |
| 2722 |
} |
| 2723 |
else if (c >= ' ' && c < 127 |
| 2724 |
&& !insel |
| 2725 |
&& newp - filebuf < sizeof(filebuf) - 2 |
| 2726 |
&& newp - filebuf < replen - 2 |
| 2727 |
&& ent_x < right - 2) |
| 2728 |
{ |
| 2729 |
|
| 2730 |
if (*newp != '\0') |
| 2731 |
{ |
| 2732 |
ossclr(ent_y, min_ent_x, ent_y, right - 2, text_color); |
| 2733 |
*newp = '\0'; |
| 2734 |
} |
| 2735 |
|
| 2736 |
|
| 2737 |
*newp++ = c; |
| 2738 |
*newp = '\0'; |
| 2739 |
ossdsp(ent_y, ent_x, text_color, newp-1); |
| 2740 |
++ent_x; |
| 2741 |
} |
| 2742 |
else if (c == 8 && ent_x > min_ent_x) |
| 2743 |
{ |
| 2744 |
|
| 2745 |
--ent_x; |
| 2746 |
ossdsp(ent_y, ent_x, text_color, " "); |
| 2747 |
*(--newp) = '\0'; |
| 2748 |
} |
| 2749 |
else if (c == 9 && newfile) |
| 2750 |
{ |
| 2751 |
|
| 2752 |
insel = !insel; |
| 2753 |
} |
| 2754 |
} |
| 2755 |
|
| 2756 |
done: |
| 2757 |
|
| 2758 |
osssetdisk(rundisk); |
| 2759 |
|
| 2760 |
|
| 2761 |
ossclr(top, left, bottom, right, ldesc_color); |
| 2762 |
os_redraw(); |
| 2763 |
|
| 2764 |
|
| 2765 |
S_keep_cursor_pos = old_keep_cursor_pos; |
| 2766 |
|
| 2767 |
|
| 2768 |
return retval; |
| 2769 |
} |
| 2770 |
|
| 2771 |
# endif |
| 2772 |
# endif |
| 2773 |
#endif |
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
void os_set_title(const char *ttl) |
| 2779 |
{ |
| 2780 |
|
| 2781 |
} |
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
int os_paramfile(char *buf) |
| 2791 |
{ |
| 2792 |
return(0); |
| 2793 |
} |
| 2794 |
|
| 2795 |
#ifndef __DPMI32__ |
| 2796 |
#ifndef WINDOWS |
| 2797 |
#ifndef T_WIN32 |
| 2798 |
# ifdef MSOS2 |
| 2799 |
int os_break() { return(0); } |
| 2800 |
void os_instbrk(int install) {} |
| 2801 |
# else |
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
static osfar_t int break_set; |
| 2807 |
int os_break(void) |
| 2808 |
{ |
| 2809 |
int ret = break_set; |
| 2810 |
break_set = 0; |
| 2811 |
return(ret); |
| 2812 |
} |
| 2813 |
|
| 2814 |
# ifdef DJGPP |
| 2815 |
|
| 2816 |
|
| 2817 |
static void break_handler(int sig) |
| 2818 |
{ |
| 2819 |
break_set = 1; |
| 2820 |
} |
| 2821 |
|
| 2822 |
|
| 2823 |
void os_instbrk(int install) |
| 2824 |
{ |
| 2825 |
if (install) |
| 2826 |
signal(SIGINT, break_handler); |
| 2827 |
else |
| 2828 |
signal(SIGINT, SIG_DFL); |
| 2829 |
} |
| 2830 |
|
| 2831 |
# else |
| 2832 |
|
| 2833 |
|
| 2834 |
static interrupt void break_handler(void) |
| 2835 |
{ |
| 2836 |
break_set = 1; |
| 2837 |
} |
| 2838 |
|
| 2839 |
|
| 2840 |
void os_instbrk(int install) |
| 2841 |
{ |
| 2842 |
static void (interrupt *old)(); |
| 2843 |
|
| 2844 |
if (install) |
| 2845 |
{ |
| 2846 |
old = getvect((unsigned)0x1b); |
| 2847 |
setvect(0x1b, break_handler); |
| 2848 |
} |
| 2849 |
else |
| 2850 |
setvect(0x1b, old); |
| 2851 |
} |
| 2852 |
# endif |
| 2853 |
# endif |
| 2854 |
#endif |
| 2855 |
#endif |
| 2856 |
#endif |
| 2857 |
|
| 2858 |
|
| 2859 |
#ifdef __DPMI32__ |
| 2860 |
int os_break() |
| 2861 |
{ |
| 2862 |
return 0; |
| 2863 |
} |
| 2864 |
#endif |
| 2865 |
|
| 2866 |
|
| 2867 |
#ifndef WINDOWS |
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
void os_xlat_html4(unsigned int html4_char, char *result, size_t result_len) |
| 2874 |
{ |
| 2875 |
|
| 2876 |
#define INV_CHAR "\372" |
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
static osfar_t const char *xlat_tbl[] = |
| 2896 |
{ |
| 2897 |
INV_CHAR, |
| 2898 |
INV_CHAR, |
| 2899 |
"'", |
| 2900 |
INV_CHAR, |
| 2901 |
"\"", |
| 2902 |
INV_CHAR, |
| 2903 |
INV_CHAR, |
| 2904 |
INV_CHAR, |
| 2905 |
INV_CHAR, |
| 2906 |
INV_CHAR, |
| 2907 |
INV_CHAR, |
| 2908 |
"<", |
| 2909 |
INV_CHAR, |
| 2910 |
INV_CHAR, |
| 2911 |
INV_CHAR, |
| 2912 |
INV_CHAR, |
| 2913 |
INV_CHAR, |
| 2914 |
"'", |
| 2915 |
"'", |
| 2916 |
"\"", |
| 2917 |
"\"", |
| 2918 |
INV_CHAR, |
| 2919 |
"\304", |
| 2920 |
"--", |
| 2921 |
INV_CHAR, |
| 2922 |
"(tm)", |
| 2923 |
INV_CHAR, |
| 2924 |
">", |
| 2925 |
INV_CHAR, |
| 2926 |
INV_CHAR, |
| 2927 |
INV_CHAR, |
| 2928 |
"Y", |
| 2929 |
INV_CHAR, |
| 2930 |
"\255", |
| 2931 |
"\233", |
| 2932 |
"\234", |
| 2933 |
INV_CHAR, |
| 2934 |
"\235", |
| 2935 |
"\263", |
| 2936 |
INV_CHAR, |
| 2937 |
INV_CHAR, |
| 2938 |
"(c)", |
| 2939 |
"\246", |
| 2940 |
"\256", |
| 2941 |
"\252", |
| 2942 |
" ", |
| 2943 |
"(R)", |
| 2944 |
INV_CHAR, |
| 2945 |
"\370", |
| 2946 |
"\361", |
| 2947 |
"\375", |
| 2948 |
INV_CHAR, |
| 2949 |
"'", |
| 2950 |
"\346", |
| 2951 |
INV_CHAR, |
| 2952 |
"\371", |
| 2953 |
",", |
| 2954 |
INV_CHAR, |
| 2955 |
"\247", |
| 2956 |
"\257", |
| 2957 |
"\254", |
| 2958 |
"\253", |
| 2959 |
"3/4", |
| 2960 |
"\250", |
| 2961 |
"A", |
| 2962 |
"A", |
| 2963 |
"A", |
| 2964 |
"A", |
| 2965 |
"\216", |
| 2966 |
"\217", |
| 2967 |
"\222", |
| 2968 |
"\200", |
| 2969 |
"E", |
| 2970 |
"\220", |
| 2971 |
"E", |
| 2972 |
"E", |
| 2973 |
"I", |
| 2974 |
"I", |
| 2975 |
"I", |
| 2976 |
"I", |
| 2977 |
INV_CHAR, |
| 2978 |
"\245", |
| 2979 |
"O", |
| 2980 |
"O", |
| 2981 |
"O", |
| 2982 |
"O", |
| 2983 |
"\231", |
| 2984 |
"x", |
| 2985 |
"O", |
| 2986 |
"U", |
| 2987 |
"U", |
| 2988 |
"U", |
| 2989 |
"\232", |
| 2990 |
"Y", |
| 2991 |
INV_CHAR, |
| 2992 |
"\341", |
| 2993 |
"\205", |
| 2994 |
"\240", |
| 2995 |
"\203", |
| 2996 |
"a", |
| 2997 |
"\204", |
| 2998 |
"\206", |
| 2999 |
"\221", |
| 3000 |
"\207", |
| 3001 |
"\212", |
| 3002 |
"\202", |
| 3003 |
"\210", |
| 3004 |
"\211", |
| 3005 |
"\215", |
| 3006 |
"\241", |
| 3007 |
"\214", |
| 3008 |
"\213", |
| 3009 |
INV_CHAR, |
| 3010 |
"\244", |
| 3011 |
"\225", |
| 3012 |
"\242", |
| 3013 |
"\223", |
| 3014 |
"o", |
| 3015 |
"\224", |
| 3016 |
"\366", |
| 3017 |
"o", |
| 3018 |
"\227", |
| 3019 |
"\243", |
| 3020 |
"\226", |
| 3021 |
"\201", |
| 3022 |
"y", |
| 3023 |
INV_CHAR, |
| 3024 |
"\230" |
| 3025 |
}; |
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
if (html4_char > 255) |
| 3033 |
{ |
| 3034 |
switch(html4_char) |
| 3035 |
{ |
| 3036 |
case 338: html4_char = 140; break; |
| 3037 |
case 339: html4_char = 156; break; |
| 3038 |
case 376: html4_char = 159; break; |
| 3039 |
case 352: html4_char = 154; break; |
| 3040 |
case 353: html4_char = 138; break; |
| 3041 |
case 8211: html4_char = 150; break; |
| 3042 |
case 8212: html4_char = 151; break; |
| 3043 |
case 8216: html4_char = 145; break; |
| 3044 |
case 8217: html4_char = 146; break; |
| 3045 |
case 8218: html4_char = 130; break; |
| 3046 |
case 8220: html4_char = 147; break; |
| 3047 |
case 8221: html4_char = 148; break; |
| 3048 |
case 8222: html4_char = 132; break; |
| 3049 |
case 8224: html4_char = 134; break; |
| 3050 |
case 8225: html4_char = 135; break; |
| 3051 |
case 8240: html4_char = 137; break; |
| 3052 |
case 8249: html4_char = 139; break; |
| 3053 |
case 8250: html4_char = 155; break; |
| 3054 |
case 8482: html4_char = 153; break; |
| 3055 |
|
| 3056 |
default: |
| 3057 |
|
| 3058 |
result[0] = (unsigned char)250; |
| 3059 |
result[1] = 0; |
| 3060 |
return; |
| 3061 |
} |
| 3062 |
} |
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
if (html4_char < 128) |
| 3069 |
{ |
| 3070 |
result[0] = (unsigned char)html4_char; |
| 3071 |
result[1] = '\0'; |
| 3072 |
return; |
| 3073 |
} |
| 3074 |
|
| 3075 |
|
| 3076 |
strcpy(result, xlat_tbl[html4_char - 128]); |
| 3077 |
} |
| 3078 |
|
| 3079 |
#endif |
| 3080 |
|
| 3081 |
#ifdef DJGPP |
| 3082 |
#if DJGPP < 2 || (DJGPP == 2 && DJGPP_MINOR <= 1) |
| 3083 |
|
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
memicmp(char *s1, char *s2, int len) |
| 3088 |
{ |
| 3089 |
int i; |
| 3090 |
|
| 3091 |
for (i = 0; i < len; i++) |
| 3092 |
{ |
| 3093 |
if (tolower(s1[i]) != tolower(s2[i])) |
| 3094 |
return (int)tolower(s1[i]) - (int)tolower(s2[i]); |
| 3095 |
} |
| 3096 |
return 0; |
| 3097 |
} |
| 3098 |
|
| 3099 |
#endif |
| 3100 |
#endif |
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
char *os_strlwr(char *s) |
| 3106 |
{ |
| 3107 |
return strlwr(s); |
| 3108 |
} |
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
#ifdef T_WIN32 |
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
static int oss_get_dos_codepage(void) |
| 3122 |
{ |
| 3123 |
return GetConsoleOutputCP(); |
| 3124 |
} |
| 3125 |
|
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
|
| 3130 |
|
| 3131 |
|
| 3132 |
|
| 3133 |
|
| 3134 |
|
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
void os_get_charmap(char *mapname, int charmap_id) |
| 3139 |
{ |
| 3140 |
int cp; |
| 3141 |
HANDLE h; |
| 3142 |
|
| 3143 |
|
| 3144 |
switch(charmap_id) |
| 3145 |
{ |
| 3146 |
case OS_CHARMAP_DISPLAY: |
| 3147 |
|
| 3148 |
|
| 3149 |
|
| 3150 |
|
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
if ((h = CreateFile("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, |
| 3156 |
0, OPEN_EXISTING, 0, 0)) != INVALID_HANDLE_VALUE) |
| 3157 |
{ |
| 3158 |
|
| 3159 |
cp = GetOEMCP(); |
| 3160 |
CloseHandle(h); |
| 3161 |
} |
| 3162 |
else |
| 3163 |
{ |
| 3164 |
|
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
cp = GetACP(); |
| 3169 |
} |
| 3170 |
break; |
| 3171 |
|
| 3172 |
case OS_CHARMAP_CMDLINE: |
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
cp = GetACP(); |
| 3179 |
break; |
| 3180 |
|
| 3181 |
case OS_CHARMAP_FILENAME: |
| 3182 |
case OS_CHARMAP_FILECONTENTS: |
| 3183 |
|
| 3184 |
cp = GetACP(); |
| 3185 |
break; |
| 3186 |
|
| 3187 |
default: |
| 3188 |
|
| 3189 |
cp = GetACP(); |
| 3190 |
break; |
| 3191 |
} |
| 3192 |
|
| 3193 |
|
| 3194 |
sprintf(mapname, "CP%d", cp); |
| 3195 |
} |
| 3196 |
|
| 3197 |
#else |
| 3198 |
|
| 3199 |
|
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
static int oss_get_dos_codepage(void) |
| 3204 |
{ |
| 3205 |
int codepage; |
| 3206 |
|
| 3207 |
#ifdef DJGPP |
| 3208 |
__dpmi_regs regs; |
| 3209 |
|
| 3210 |
regs.x.ax = 0x6601; |
| 3211 |
__dpmi_int(0x21, ®s); |
| 3212 |
codepage = regs.x.bx; |
| 3213 |
|
| 3214 |
#else |
| 3215 |
__asm { |
| 3216 |
mov ax, 6601h |
| 3217 |
int 21h |
| 3218 |
mov [codepage], bx |
| 3219 |
} |
| 3220 |
#endif |
| 3221 |
return codepage; |
| 3222 |
} |
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
void os_get_charmap(char *mapname, int charmap_id) |
| 3229 |
{ |
| 3230 |
int codepage; |
| 3231 |
|
| 3232 |
|
| 3233 |
codepage = oss_get_dos_codepage(); |
| 3234 |
|
| 3235 |
|
| 3236 |
sprintf(mapname, "CP%d", codepage); |
| 3237 |
} |
| 3238 |
|
| 3239 |
#endif |
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
void os_gen_charmap_filename(char *filename, char *internal_id, |
| 3251 |
char *argv0) |
| 3252 |
{ |
| 3253 |
char *p; |
| 3254 |
char *rootname; |
| 3255 |
size_t pathlen; |
| 3256 |
int codepage; |
| 3257 |
|
| 3258 |
|
| 3259 |
codepage = oss_get_dos_codepage(); |
| 3260 |
|
| 3261 |
|
| 3262 |
for (p = rootname = argv0 ; *p != '\0' ; ++p) |
| 3263 |
{ |
| 3264 |
if (*p == '/' || *p == '\\' || *p == ':') |
| 3265 |
rootname = p + 1; |
| 3266 |
} |
| 3267 |
|
| 3268 |
|
| 3269 |
pathlen = rootname - argv0; |
| 3270 |
memcpy(filename, argv0, pathlen); |
| 3271 |
|
| 3272 |
|
| 3273 |
if (pathlen == 0 || filename[pathlen - 1] != '\\') |
| 3274 |
filename[pathlen++] = '\\'; |
| 3275 |
|
| 3276 |
|
| 3277 |
sprintf(filename + pathlen, "%u", codepage); |
| 3278 |
strcat(filename + pathlen, internal_id); |
| 3279 |
strcat(filename + pathlen, ".tcp"); |
| 3280 |
} |
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
void os_advise_load_charmap(char *id, char *ldesc, char *sysinfo) |
| 3288 |
{ |
| 3289 |
|
| 3290 |
} |
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
void oss_raw_key_to_cmd(os_event_info_t *evt) |
| 3298 |
{ |
| 3299 |
|
| 3300 |
switch(evt->key[0]) |
| 3301 |
{ |
| 3302 |
case 0: |
| 3303 |
|
| 3304 |
switch(evt->key[1]) |
| 3305 |
{ |
| 3306 |
case CMD_F1: |
| 3307 |
|
| 3308 |
evt->key[1] = CMD_SCR; |
| 3309 |
break; |
| 3310 |
} |
| 3311 |
break; |
| 3312 |
|
| 3313 |
case 1: |
| 3314 |
|
| 3315 |
evt->key[0] = 0; |
| 3316 |
evt->key[1] = CMD_HOME; |
| 3317 |
break; |
| 3318 |
|
| 3319 |
case 2: |
| 3320 |
|
| 3321 |
evt->key[0] = 0; |
| 3322 |
evt->key[1] = CMD_LEFT; |
| 3323 |
break; |
| 3324 |
|
| 3325 |
case 4: |
| 3326 |
|
| 3327 |
evt->key[0] = 0; |
| 3328 |
evt->key[1] = CMD_DEL; |
| 3329 |
break; |
| 3330 |
|
| 3331 |
case 5: |
| 3332 |
|
| 3333 |
evt->key[0] = 0; |
| 3334 |
evt->key[1] = CMD_END; |
| 3335 |
break; |
| 3336 |
|
| 3337 |
case 6: |
| 3338 |
|
| 3339 |
evt->key[0] = 0; |
| 3340 |
evt->key[1] = CMD_RIGHT; |
| 3341 |
break; |
| 3342 |
|
| 3343 |
case 11: |
| 3344 |
|
| 3345 |
evt->key[0] = 0; |
| 3346 |
evt->key[1] = CMD_DEOL; |
| 3347 |
break; |
| 3348 |
|
| 3349 |
case 21: |
| 3350 |
case 27: |
| 3351 |
|
| 3352 |
evt->key[0] = 0; |
| 3353 |
evt->key[1] = CMD_KILL; |
| 3354 |
break; |
| 3355 |
} |
| 3356 |
} |
| 3357 |
|
| 3358 |
#ifndef DJGPP |
| 3359 |
#ifdef __TURBOC__ |
| 3360 |
# define _eof(handle) eof(handle) |
| 3361 |
# define _fileno(stream) fileno(stream) |
| 3362 |
#endif |
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
|
| 3368 |
|
| 3369 |
|
| 3370 |
int oss_eof_on_stdin() |
| 3371 |
{ |
| 3372 |
return _eof(_fileno(stdin)) > 0; |
| 3373 |
} |
| 3374 |
#endif |
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
#if defined(TURBO) || defined(DJGPP) |
| 3385 |
int os_asprintf(char **bufptr, const char *fmt, ...) |
| 3386 |
{ |
| 3387 |
va_list argp; |
| 3388 |
int ret; |
| 3389 |
|
| 3390 |
va_start(argp, fmt); |
| 3391 |
ret = os_vasprintf(bufptr, fmt, argp); |
| 3392 |
va_end(argp); |
| 3393 |
|
| 3394 |
return ret; |
| 3395 |
} |
| 3396 |
|
| 3397 |
int os_vasprintf(char **bufptr, const char *fmt, va_list argp) |
| 3398 |
{ |
| 3399 |
int len; |
| 3400 |
FILE *fp; |
| 3401 |
|
| 3402 |
|
| 3403 |
fp = fopen("NUL", "w"); |
| 3404 |
if (fp == 0) |
| 3405 |
return -1; |
| 3406 |
|
| 3407 |
|
| 3408 |
len = fprintf(fp, fmt, argp); |
| 3409 |
|
| 3410 |
|
| 3411 |
fclose(fp); |
| 3412 |
|
| 3413 |
|
| 3414 |
if (len < 0) |
| 3415 |
return -1; |
| 3416 |
|
| 3417 |
|
| 3418 |
if ((*bufptr = (char *)osmalloc(len + 1)) == 0) |
| 3419 |
return -1; |
| 3420 |
|
| 3421 |
|
| 3422 |
return vsprintf(*bufptr, fmt, argp); |
| 3423 |
} |
| 3424 |
#endif |
| 3425 |
|