From 88efa1bd6591b9f81b0ed6776e059ac1b765c24b Mon Sep 17 00:00:00 2001 From: "Guillermo J. Rozas" Date: Tue, 15 Sep 1992 20:35:55 +0000 Subject: [PATCH] Make FILE-EQ? work correctly under DOS. --- v7/src/microcode/dosfs.c | 53 +++---- v7/src/microcode/dosint10.c | 24 +-- v7/src/microcode/dossys.c | 302 +++++++++++++++++++++++------------- v7/src/microcode/dostop.c | 4 +- v7/src/microcode/prdosfs.c | 21 ++- 5 files changed, 237 insertions(+), 167 deletions(-) diff --git a/v7/src/microcode/dosfs.c b/v7/src/microcode/dosfs.c index 6bc353c18..2ae4f1cfd 100644 --- a/v7/src/microcode/dosfs.c +++ b/v7/src/microcode/dosfs.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/dosfs.c,v 1.2 1992/07/06 23:42:01 jinx Exp $ +$Id: dosfs.c,v 1.3 1992/09/15 20:35:55 jinx Exp $ Copyright (c) 1992 Massachusetts Institute of Technology @@ -35,32 +35,13 @@ MIT in each case. */ #include "msdos.h" #include "osfs.h" -int -DEFUN (DOS_read_file_status, (name, s), - CONST char * name AND - struct stat * s) -{ char filename[128]; - - dos_pathname_as_filename(name, filename); - - while ((stat (filename, s)) < 0) - { - if (errno == EINTR) - continue; - if ((errno == ENOENT) || (errno == ENOTDIR)) - return (0); - error_system_call (errno, syscall_lstat); - } - return (1); -} - enum file_existence DEFUN (OS_file_existence_test, (name), char * name) { struct stat s; char filename[128]; - dos_pathname_as_filename(name, filename); + dos_pathname_as_filename (name, filename); return (((DOS_stat (filename, (&s))) < 0) @@ -72,7 +53,7 @@ DEFUN (OS_file_access, (name, mode), CONST char * name AND unsigned int mode) { char filename[128]; - dos_pathname_as_filename(name, filename); + dos_pathname_as_filename (name, filename); return ((DOS_access (filename, mode)) == 0); } @@ -82,7 +63,7 @@ DEFUN (OS_file_directory_p, (name), char * name) struct stat s; char filename[128]; - dos_pathname_as_filename(name, filename); + dos_pathname_as_filename (name, filename); return (((DOS_stat (filename, (&s))) == 0) && (((s . st_mode) & S_IFMT) == S_IFDIR)); } @@ -115,6 +96,7 @@ DEFUN (OS_file_link_hard, (from_name, to_name), CONST char * to_name) { error_unimplemented_primitive (); + /*NOTREACHED*/ } void @@ -123,6 +105,7 @@ DEFUN (OS_file_link_soft, (from_name, to_name), CONST char * to_name) { error_unimplemented_primitive (); + /*NOTREACHED*/ } void @@ -241,7 +224,7 @@ DEFUN (OS_directory_open, (name), CONST char * name) if (pointer == 0) error_system_call (ENOMEM, syscall_malloc); - if (dos_pathname_as_filename(name, filename)) + if (dos_pathname_as_filename (name, filename)) sprintf(searchname, "%s*.*", filename); else sprintf(searchname, "%s\\*.*", filename); @@ -270,7 +253,7 @@ DEFUN (OS_directory_read_matching, (index, prefix), CONST char * prefix) { error_unimplemented_primitive (); - return (0); + /*NOTREACHED*/ } void @@ -280,5 +263,23 @@ DEFUN (OS_directory_close, (index), unsigned int index) free(pointer); DEALLOCATE_DIRECTORY (index); } + +int +DEFUN (DOS_read_file_status, (name, s), + CONST char * name AND + struct stat * s) +{ + char filename[128]; - + dos_pathname_as_filename (name, filename); + + while ((stat (filename, s)) < 0) + { + if (errno == EINTR) + continue; + if ((errno == ENOENT) || (errno == ENOTDIR)) + return (0); + error_system_call (errno, syscall_lstat); + } + return (1); +} diff --git a/v7/src/microcode/dosint10.c b/v7/src/microcode/dosint10.c index 8a4bef726..feb7dbac7 100644 --- a/v7/src/microcode/dosint10.c +++ b/v7/src/microcode/dosint10.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/dosint10.c,v 1.1 1992/07/28 18:15:43 jinx Exp $ +$Id: dosint10.c,v 1.2 1992/09/15 20:35:42 jinx Exp $ Copyright (c) 1992 Massachusetts Institute of Technology @@ -111,10 +111,11 @@ int BACKGROUND_ATTRIBUTE = UNINITIALIZED; int NORMAL_VIDEO = UNINITIALIZED; int REVERSE_VIDEO = UNINITIALIZED; -unsigned long RealModeBufferParagraph = 0; -char *pRealModeBuffer = NULL; +extern unsigned long RealModeBufferParagraph; +extern char *pRealModeBuffer; -void bios_initialize_variables(void) +void +bios_initialize_variables (void) /* If valid environment variables exist, use values. Otherwise queries BIOS for parameters. @@ -162,18 +163,7 @@ void bios_initialize_variables(void) NORMAL_VIDEO = (FOREGROUND_ATTRIBUTE | BACKGROUND_ATTRIBUTE); REVERSE_VIDEO = ((FOREGROUND_ATTRIBUTE << 4) | (BACKGROUND_ATTRIBUTE >> 4)); - - { - union REGS rIn; - union REGS rOut; - - rIn.h.ah = 0x48; - rIn.x.bx = 256; - int86(0x21,&rIn,&rOut); - /* Ought to check for success, carry flag cleared if successful */ - pRealModeBuffer = (char *) rOut.e.ebx; - RealModeBufferParagraph = rOut.x.ax; - } + return; } void bios_uninitialize_variables(void) @@ -443,7 +433,7 @@ DEFINE_PRIMITIVE("BIOS:DISCARD!", Prim_bios_discard, 0, 0, 0) DEFINE_PRIMITIVE("BIOS:ENTER!", Prim_bios_enter, 0, 0, 0) { PRIMITIVE_HEADER(0); - bios_initialize_variables(); + bios_initialize_variables (); bios_clear_screen(); bios__set_cursor_position(0,0,DISPLAY_ROWS); PRIMITIVE_RETURN(SHARP_T); diff --git a/v7/src/microcode/dossys.c b/v7/src/microcode/dossys.c index 5f0f19f79..8e63a0751 100644 --- a/v7/src/microcode/dossys.c +++ b/v7/src/microcode/dossys.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/dossys.c,v 1.1 1992/05/05 06:55:13 jinx Exp $ +$Id: dossys.c,v 1.2 1992/09/15 20:35:37 jinx Exp $ Copyright (c) 1992 Massachusetts Institute of Technology @@ -36,108 +36,108 @@ MIT in each case. */ #include #include "dossys.h" -int dos_keyboard_input_available_p(void) +int +dos_keyboard_input_available_p (void) { union REGS inregs, outregs; inregs.h.ah = 0x0B; - intdos(&inregs, &outregs); - + intdos (&inregs, &outregs); return (outregs.h.al != 0); } -unsigned char dos_get_keyboard_character(void) +unsigned char +dos_get_keyboard_character (void) { union REGS inregs, outregs; inregs.h.ah = 0x07; - intdos(&inregs, &outregs); - - return (unsigned char) (outregs.h.al); + intdos (&inregs, &outregs); + return ((unsigned char) (outregs.h.al)); } -int dos_poll_keyboard_character(unsigned char *result) +int +dos_poll_keyboard_character (unsigned char * result) { union REGS inregs, outregs; inregs.h.ah = 0x06; inregs.h.dl = 0xFF; - intdos(&inregs, &outregs); - - *result = (unsigned char) (outregs.h.al); + intdos (&inregs, &outregs); + *result = ((unsigned char) (outregs.h.al)); return ((outregs.x.flags & 0x40) == 0); } -void dos_console_write_character(unsigned char character) +void +dos_console_write_character (unsigned char character) { union REGS inregs, outregs; inregs.h.ah = 0x06; inregs.h.dl = character; - - intdos(&inregs, &outregs); + intdos (&inregs, &outregs); return; } -int dos_console_write(void * vbuffer, size_t nsize) -{ union REGS inregs, outregs; - unsigned char *buffer = vbuffer; +int +dos_console_write (void * vbuffer, size_t nsize) +{ + union REGS inregs, outregs; + unsigned char * buffer = vbuffer; int i; for (inregs.h.ah = 0x06, i=0; i < nsize; i++) - { inregs.h.dl = buffer[i]; - intdos(&inregs, &outregs); + { + inregs.h.dl = buffer[i]; + intdos (&inregs, &outregs); } - return nsize; + return (nsize); } - /* DOS I/O functions using handles */ -handle_t dos_open_file_with_handle(unsigned char * name, int mode) +handle_t +dos_open_file_with_handle (unsigned char * name, int mode) { union REGS inregs, outregs; struct SREGS segregs; - inregs.e.edx = (unsigned long) name; - segread(&segregs); - + inregs.e.edx = ((unsigned long) name); + segread (&segregs); inregs.h.ah = 0x3D; inregs.h.al = mode; - intdosx(&inregs, &outregs, &segregs); - printf("Returning from DOS\n"); - return (outregs.x.cflag) ? DOS_FAILURE : (unsigned int) outregs.x.ax; + intdosx (&inregs, &outregs, &segregs); + return ((outregs.x.cflag) ? DOS_FAILURE : ((unsigned int) outregs.x.ax)); } -int dos_close_file_with_handle(handle_t handle) +int +dos_close_file_with_handle (handle_t handle) { union REGS inregs, outregs; inregs.x.bx = handle; inregs.h.al = 0x3E; - intdos(&inregs, &outregs); - - return (outregs.x.cflag) ? DOS_FAILURE : DOS_SUCCESS; + intdos (&inregs, &outregs); + return ((outregs.x.cflag) ? DOS_FAILURE : DOS_SUCCESS); } -int dos_read_file_with_handle(handle_t handle, void * buffer, size_t nbytes) +int +dos_read_file_with_handle (handle_t handle, void * buffer, size_t nbytes) { union REGS inregs, outregs; struct SREGS segregs; inregs.x.bx = handle; - inregs.e.edx = (unsigned long) buffer; + inregs.e.edx = ((unsigned long) buffer); inregs.e.ecx = nbytes; - - segread(&segregs); - + segread (&segregs); inregs.h.ah = 0x3F; - intdosx(&inregs, &outregs, &segregs); - - return (outregs.x.cflag) ? DOS_FAILURE : outregs.e.eax; + intdosx (&inregs, &outregs, &segregs); + return ((outregs.x.cflag) ? DOS_FAILURE : outregs.e.eax); } -int dos_write_file_with_handle(handle_t handle, void * buffer, size_t nbytes) +int +dos_write_file_with_handle (handle_t handle, void * buffer, size_t nbytes) { union REGS inregs, outregs; struct SREGS segregs; @@ -145,104 +145,102 @@ int dos_write_file_with_handle(handle_t handle, void * buffer, size_t nbytes) inregs.x.bx = handle; inregs.e.edx = (unsigned long) buffer; inregs.e.ecx = nbytes; - - segread(&segregs); - + segread (&segregs); inregs.h.ah = 0x40; - intdosx(&inregs, &outregs, &segregs); - - return (outregs.x.cflag) ? DOS_FAILURE : outregs.e.eax; + intdosx (&inregs, &outregs, &segregs); + return ((outregs.x.cflag) ? DOS_FAILURE : outregs.e.eax); } -int dos_get_device_status_with_handle(handle_t handle) +int +dos_get_device_status_with_handle (handle_t handle) { union REGS inregs, outregs; inregs.x.bx = handle; inregs.x.ax = 0x4400; - intdos(&inregs, &outregs); - - return (outregs.x.cflag) ? DOS_FAILURE : (unsigned int) outregs.x.dx; + intdos (&inregs, &outregs); + return ((outregs.x.cflag) ? DOS_FAILURE : ((unsigned int) outregs.x.dx)); } -int dos_set_device_status_with_handle(handle_t handle, int mode) -{ int original_mode; +int +dos_set_device_status_with_handle (handle_t handle, int mode) +{ + int original_mode; union REGS inregs, outregs; original_mode = dos_get_device_status_with_handle(handle); - if (original_mode == DOS_FAILURE) return DOS_FAILURE; - + if (original_mode == DOS_FAILURE) + return (DOS_FAILURE); inregs.x.dx = mode; inregs.x.bx = handle; inregs.x.ax = 0x4401; - intdos(&inregs, &outregs); - return (outregs.x.cflag) ? DOS_FAILURE : original_mode; + intdos (&inregs, &outregs); + return ((outregs.x.cflag) ? DOS_FAILURE : original_mode); } - - -void dos_get_version(version_t *version_number) +void +dos_get_version (version_t *version_number) { union REGS inregs, outregs; /* Use old style version number because we may be running below DOS 5.0 */ inregs.h.al = 0x01; inregs.h.ah = 0x30; - intdos(&inregs, &outregs); + intdos (&inregs, &outregs); version_number -> major = outregs.h.al; version_number -> minor = outregs.h.ah; - if ((version_number -> major) >= 5) { /* Get the real version. */ inregs.x.ax = 0x3306; - intdos(&inregs, &outregs); + intdos (&inregs, &outregs); version_number -> major = outregs.h.bl; version_number -> minor = outregs.h.bh; } return; } -void dos_reset_drive(void) +void +dos_reset_drive (void) { union REGS inregs, outregs; inregs.h.al = 0x0d; - intdos(&inregs, &outregs); - + intdos (&inregs, &outregs); return; } -int dos_set_verify_flag(int verify_p) -{ union REGS inregs, outregs; +int +dos_set_verify_flag (int verify_p) +{ + union REGS inregs, outregs; int old_flag; inregs.h.ah = 0x54; intdos(&inregs, &outregs); old_flag = outregs.h.al; - inregs.h.al = (verify_p) ? 1 : 0; inregs.h.ah = 0x2E; intdos(&inregs, &outregs); - - return old_flag; + return (old_flag); } -int dos_set_ctrl_c_check_flag(int check_p) -{ union REGS inregs, outregs; +int +dos_set_ctrl_c_check_flag (int check_p) +{ + union REGS inregs, outregs; int old_flag; inregs.x.ax = 0x3300; intdos(&inregs, &outregs); old_flag = outregs.h.dl; - inregs.h.dl = (check_p) ? 1 : 0; inregs.x.ax = 0x3301; intdos(&inregs, &outregs); - - return old_flag; + return (old_flag); } -int dos_rename_file(const char *old, const char *new) +int +dos_rename_file (const char * old, const char * new) { union REGS inregs, outregs; struct SREGS segregs; @@ -251,34 +249,32 @@ int dos_rename_file(const char *old, const char *new) inregs.e.edi = (unsigned long) new; segread(&segregs); segregs.es = segregs.ds; - inregs.h.ah = 0x56; intdosx(&inregs, &outregs, &segregs); - if (outregs.x.cflag) - return DOS_FAILURE; + return (DOS_FAILURE); else - return DOS_SUCCESS; + return (DOS_SUCCESS); } -int dos_get_machine_name(char *name) +int +dos_get_machine_name (char * name) { union REGS inregs, outregs; struct SREGS segregs; - inregs.e.edx = (unsigned long) name; + inregs.e.edx = ((unsigned long) name); segregs.ds = getDS(); - inregs.x.ax = 0x5E00; intdosx(&inregs, &outregs, &segregs); - if ((outregs.x.cflag) || (outregs.h.ch == 0)) - return DOS_FAILURE; + return (DOS_FAILURE); else - return outregs.h.cl; + return (outregs.h.cl); } -int dos_drive_letter_to_number(char letter) +int +dos_drive_letter_to_number (char letter) { if (letter == '\0') return 0; @@ -287,18 +283,20 @@ int dos_drive_letter_to_number(char letter) else if ((letter >= 'A')&&(letter <= 'Z')) return ((letter - 'A') + 1); else - return -1; + return (-1); } -char dos_drive_number_to_letter(int number) +char +dos_drive_number_to_letter (int number) { if ((number >= 1)&&(number <= 26)) return ('A' + (number - 1)); else - return '\0'; + return ('\0'); } -int dos_set_default_drive(int drive_number) +int +dos_set_default_drive (int drive_number) { union REGS inregs, outregs; @@ -308,61 +306,141 @@ int dos_set_default_drive(int drive_number) inregs.h.ah = 0x0E; intdos(&inregs, &outregs); } - return DOS_SUCCESS; + return (DOS_SUCCESS); } -int dos_get_default_drive(int drive_number) +int +dos_get_default_drive (int drive_number) { union REGS inregs, outregs; inregs.h.ah = 0x19; - intdos(&inregs, &outregs); - - return outregs.h.al + 1; + intdos (&inregs, &outregs); + return (outregs.h.al + 1); } - dos_boolean -dos_pathname_as_filename(char * name, char * buffer) +dos_pathname_as_filename (char * name, char * buffer) { /* Returns whether directory encountered is top level */ unsigned int end_index = strlen(name) - 1; /* The runtime system comes down with a name that has a back slash at the end. This will choke DOS. */ - strcpy(buffer, name); + strcpy (buffer, name); if ((end_index >= 0) && (buffer[end_index] == '\\')) { /* Name is indeed a directory */ if (end_index == 0) /* if only one char, name is top */ - return dos_true; + return (dos_true); else - { if (buffer[end_index-1] == ':') /* Preceded by drive letter, top */ - { return dos_true; } + { + if (buffer[end_index-1] == ':') /* Preceded by drive letter, top */ + return (dos_true); else - { buffer[end_index] = '\0'; - return dos_false; + { + buffer[end_index] = '\0'; + return (dos_false); } } } else - { return dos_false; } + return (dos_false); } -int dos_split_filename(char * name, char * device, char * filename) +int +dos_split_filename (char * name, char * device, char * filename) { unsigned start; int drive_number; if ((strlen(name) >= 2) && (name[1] == ':')) - { device[0] = name[0], device[1] = name[1], device[2] = '\0'; + { + device[0] = name[0], device[1] = name[1], device[2] = '\0'; drive_number = dos_drive_letter_to_number(name[0]); start = 2; } else - { device[0] = '\0'; + { + device[0] = '\0'; drive_number = 0; start = 0; } - dos_pathname_as_filename(&name[start], filename); - return drive_number; + dos_pathname_as_filename (&name[start], filename); + return (drive_number); +} + +/* The following code should work at least under X32, Zortech's DOSX, + and Phar Lap 386/DOSX. +*/ + +extern int DOS_canonicalize_filename (char *, char *); +extern unsigned long RealModeBufferParagraph; +extern char *pRealModeBuffer; + +#pragma ZTC align 1 + +struct rm_interrupt +{ + unsigned short intno; + unsigned short ds; + unsigned short es; + unsigned short fs; + unsigned short gs; + unsigned long eax; + unsigned long edx; +}; + +#pragma ZTC align + +/* It only needs 128! */ + +#define RETURN_BUFFER_SIZE 256 + +int +DOS_canonicalize_filename (char * aliased, char * direct) +{ + struct rm_interrupt intrpt; + struct SREGS sregs; + union REGS regs; + + if (pRealModeBuffer == NULL) + return (-1); + strcpy ((pRealModeBuffer + RETURN_BUFFER_SIZE), aliased); + segread (&sregs); + /* Int 21h, ah = 60h: Canonicalize filename or path. */ + intrpt.intno = 0x21; + intrpt.eax = 0x6000; + intrpt.ds = (RealModeBufferParagraph + (RETURN_BUFFER_SIZE >> 4)); + intrpt.es = RealModeBufferParagraph; + regs.e.esi = 0; + regs.e.edi = 0; + regs.e.edx = ((unsigned) &intrpt); + /* Int 21h, ax = 2511h: Issue real mode interrupt. */ + regs.x.ax = 0x2511; + int86x (0x21, ®s, ®s, &sregs); + if (regs.e.cflag != 0) + return (-1); + strncpy (direct, pRealModeBuffer, RETURN_BUFFER_SIZE); + return (0); +} + +extern void DOS_initialize_real_mode (void); +unsigned long RealModeBufferParagraph = 0; +char *pRealModeBuffer = NULL; + +void +DOS_initialize_real_mode (void) +{ + union REGS rIn; + union REGS rOut; + + rIn.h.ah = 0x48; + rIn.x.bx = 256; + int86 (0x21, &rIn, &rOut); + if (rOut.e.cflag == 0) + { + pRealModeBuffer = ((char *) rOut.e.ebx); + RealModeBufferParagraph = rOut.x.ax; + } + return; } diff --git a/v7/src/microcode/dostop.c b/v7/src/microcode/dostop.c index 8310543da..a27a3468f 100644 --- a/v7/src/microcode/dostop.c +++ b/v7/src/microcode/dostop.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/dostop.c,v 1.4 1992/08/22 19:33:10 jinx Exp $ +$Id: dostop.c,v 1.5 1992/09/15 20:35:49 jinx Exp $ Copyright (c) 1992 Massachusetts Institute of Technology @@ -50,6 +50,7 @@ extern void EXFUN (DOS_initialize_trap_recovery, (void)); extern void EXFUN (DOS_initialize_conio, (void)); extern void EXFUN (DOS_initialize_tty, (void)); extern void EXFUN (DOS_initialize_userio, (void)); +extern void EXFUN (DOS_initialize_real_mode, (void)); extern void EXFUN (DOS_reset_channels, (void)); extern void EXFUN (DOS_reset_processes, (void)); @@ -88,6 +89,7 @@ DEFUN_VOID (OS_initialize) DOS_initialize_signals (); DOS_initialize_directory_reader (); DOS_initialize_conio(); + DOS_initialize_real_mode (); OS_Name = SYSTEM_NAME; OS_Variant = SYSTEM_VARIANT; diff --git a/v7/src/microcode/prdosfs.c b/v7/src/microcode/prdosfs.c index 83b95560c..cd4ffc9d5 100644 --- a/v7/src/microcode/prdosfs.c +++ b/v7/src/microcode/prdosfs.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/prdosfs.c,v 1.1 1992/05/05 06:55:13 jinx Exp $ +$Id: prdosfs.c,v 1.2 1992/09/15 20:35:31 jinx Exp $ Copyright (c) 1992 Massachusetts Institute of Technology @@ -382,15 +382,14 @@ The file must exist and you must be the owner (or superuser).") DEFINE_PRIMITIVE ("FILE-EQ?", Prim_file_eq_p, 2, 2, "True iff the two file arguments are the same file.") { + extern int EXFUN (DOS_canonicalize_filename, (char *, char *)); + static char buf1[128], buf2[128]; PRIMITIVE_HEADER (2); - { - struct stat s1; - struct stat s2; - PRIMITIVE_RETURN - (BOOLEAN_TO_OBJECT - ((DOS_read_file_status ((STRING_ARG (1)), (&s1))) - && (DOS_read_file_status ((STRING_ARG (2)), (&s2))) - && ((s1 . st_dev) == (s2 . st_dev)) - && ((s1 . st_ino) == (s2 . st_ino)))); - } + + if (((DOS_canonicalize_filename ((STRING_ARG (1)), &buf1[0])) + == -1) + || ((DOS_canonicalize_filename ((STRING_ARG (2)), &buf2[0])) + == -1)) + error_external_return (); + PRIMITIVE_RETURN (BOOLEAN_TO_OBJECT ((strcmp (&buf1[0], &buf2[0])) == 0)); } -- 2.25.1