Make sourcer's main program execute in X mode.

o Make the dos emulation treat c: and C: the same way.  Sourcer was doing
  a chdir("c:\\") rather than a chdir("C:\\");
o use drlton() in all places where we used to use -'A' so that we're always
  case independent.
o use drntol() in all places where we used to use + 'A' for similar reasons
This commit is contained in:
Warner Losh 1998-07-01 19:56:17 +00:00
parent 7f591b7e4b
commit 39a1ad8654
7 changed files with 49 additions and 61 deletions

View File

@ -29,7 +29,7 @@
* *
* BSDI config.c,v 2.2 1996/04/08 19:32:22 bostic Exp * BSDI config.c,v 2.2 1996/04/08 19:32:22 bostic Exp
* *
* $Id: config.c,v 1.2 1996/09/18 16:12:24 miff Exp $ * $Id: config.c,v 1.1 1997/08/09 01:42:35 dyson Exp $
*/ */
#include <stdio.h> #include <stdio.h>
@ -135,10 +135,8 @@ read_config(FILE *fp)
if (isdigit(av[1][4])) { if (isdigit(av[1][4])) {
drive = atoi(&av[1][4]) - 1; drive = atoi(&av[1][4]) - 1;
} else if (islower(av[1][4]) && av[1][5] == ':' && !av[1][6]) { } else if (isalpha(av[1][4]) && av[1][5] == ':' && !av[1][6]) {
drive = av[1][4] - 'a'; drive = drlton(av[1][4]);
} else if (isupper(av[1][4]) && av[1][5] == ':' && !av[1][6]) {
drive = av[1][4] - 'A';
} }
init_soft: init_soft:
drive = init_floppy(drive, atoi(av[3]), av[2]); drive = init_floppy(drive, atoi(av[3]), av[2]);
@ -149,10 +147,8 @@ read_config(FILE *fp)
if (isdigit(av[1][4])) { if (isdigit(av[1][4])) {
drive = atoi(&av[1][4]) + 1; drive = atoi(&av[1][4]) + 1;
} else if (islower(av[1][4]) && av[1][5] == ':' && !av[1][6]) { } else if (isalpha(av[1][4]) && av[1][5] == ':' && !av[1][6]) {
drive = av[1][4] - 'a'; drive = drlton(av[1][4]);
} else if (isupper(av[1][4]) && av[1][5] == ':' && !av[1][6]) {
drive = av[1][4] - 'A';
} }
init_hard: init_hard:
@ -185,10 +181,7 @@ read_config(FILE *fp)
fprintf(stderr, "Usage: assign [A-Z]: ...\n"); fprintf(stderr, "Usage: assign [A-Z]: ...\n");
quit(1); quit(1);
} }
if (isupper(av[1][0])) drive = drlton(av[1][0]);
drive = av[1][0] - 'A';
else
drive = av[1][0] - 'a';
if (ac == 3) { if (ac == 3) {
init_path(drive, (u_char *)av[2], 0); init_path(drive, (u_char *)av[2], 0);
@ -240,10 +233,7 @@ read_config(FILE *fp)
fprintf(stderr, "Usage: boot [A: | C:]\n"); fprintf(stderr, "Usage: boot [A: | C:]\n");
quit(1); quit(1);
} }
if (isupper(av[1][0])) bootdrive = drlton(av[1][0]);
bootdrive = av[1][0] - 'A';
else
bootdrive = av[1][0] - 'a';
if (bootdrive != 0 && bootdrive != 2) { if (bootdrive != 0 && bootdrive != 2) {
fprintf(stderr, "Boot drive must be either A: or C:\n"); fprintf(stderr, "Boot drive must be either A: or C:\n");
quit(1); quit(1);

View File

@ -29,7 +29,7 @@
* *
* BSDI cwd.c,v 2.2 1996/04/08 19:32:25 bostic Exp * BSDI cwd.c,v 2.2 1996/04/08 19:32:25 bostic Exp
* *
* $Id: cwd.c,v 1.6 1996/09/23 09:59:23 miff Exp $ * $Id: cwd.c,v 1.1 1997/08/09 01:42:38 dyson Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -89,13 +89,13 @@ init_path(int drive, u_char *base, u_char *dir)
free(d->path); free(d->path);
if ((d->path = ustrdup(base)) == NULL) if ((d->path = ustrdup(base)) == NULL)
fatal("strdup in init_path for %c:%s: %s", drive + 'A', base, fatal("strdup in init_path for %c:%s: %s", drntol(drive), base,
strerror(errno)); strerror(errno));
if (d->maxlen < 2) { if (d->maxlen < 2) {
d->maxlen = 128; d->maxlen = 128;
if ((d->cwd = (u_char *)malloc(d->maxlen)) == NULL) if ((d->cwd = (u_char *)malloc(d->maxlen)) == NULL)
fatal("malloc in init_path for %c:%s: %s", drive + 'A', base, fatal("malloc in init_path for %c:%s: %s", drntol(drive), base,
strerror(errno)); strerror(errno));
} }
@ -120,7 +120,7 @@ init_path(int drive, u_char *base, u_char *dir)
while (*dir == '/') while (*dir == '/')
++dir; ++dir;
dosname[0] = drive + 'A'; dosname[0] = drntol(drive);
dosname[1] = ':'; dosname[1] = ':';
real_to_dos(realname, &dosname[2]); real_to_dos(realname, &dosname[2]);
@ -200,23 +200,25 @@ dos_makepath(u_char *where, u_char *newpath)
u_char tmppath[1024]; u_char tmppath[1024];
if (where[0] != '\0' && where[1] == ':') { if (where[0] != '\0' && where[1] == ':') {
drive = *where - 'A'; drive = drlton(*where);
*newpath++ = *where++; *newpath++ = *where++;
*newpath++ = *where++; *newpath++ = *where++;
} else { } else {
drive = diskdrive; drive = diskdrive;
*newpath++ = diskdrive + 'A'; *newpath++ = drntol(diskdrive);
*newpath++ = ':'; *newpath++ = ':';
} }
printf("dos_makepath: Drive = %d\n", drive);
if (drive < 0 || drive >= MAX_DRIVE) { if (drive < 0 || drive >= MAX_DRIVE) {
debug(D_REDIR,"drive %c invalid\n",drive + 'A'); debug(D_REDIR,"drive %c invalid\n", drntol(drive));
return (DISK_DRIVE_INVALID); return (DISK_DRIVE_INVALID);
} }
d = &paths[drive]; d = &paths[drive];
if (d->cwd == NULL) { if (d->cwd == NULL) {
debug(D_REDIR,"no cwd for drive %c\n",drive + 'A'); debug(D_REDIR,"no cwd for drive %c\n",drntol(drive));
return (DISK_DRIVE_INVALID); return (DISK_DRIVE_INVALID);
} }
@ -298,8 +300,8 @@ dos_setcwd(u_char *where)
d->maxlen = d->len + 1 + 32; d->maxlen = d->len + 1 + 32;
d->cwd = (u_char *)malloc(d->maxlen); d->cwd = (u_char *)malloc(d->maxlen);
if (d->cwd == NULL) if (d->cwd == NULL)
fatal("malloc in dos_setcwd for %c:%s: %s", fatal("malloc in dos_setcwd for %c:%s: %s", drntol(drive),
drive + 'A', newpath, strerror(errno)); newpath, strerror(errno));
} }
ustrcpy(d->cwd, newpath + 2); ustrcpy(d->cwd, newpath + 2);
return (0); return (0);
@ -324,7 +326,7 @@ dos_to_real_path(u_char *dospath, u_char *realpath, int *drivep)
debug(D_REDIR, "dos_to_real_path(%s)\n", dospath); debug(D_REDIR, "dos_to_real_path(%s)\n", dospath);
if (dospath[0] != '\0' && dospath[1] == ':') { if (dospath[0] != '\0' && dospath[1] == ':') {
drive = *dospath - 'A'; drive = drlton(*dospath);
dospath++; dospath++;
dospath++; dospath++;
} else { } else {

View File

@ -31,7 +31,7 @@
* *
* BSDI int21.c,v 2.2 1996/04/08 19:32:51 bostic Exp * BSDI int21.c,v 2.2 1996/04/08 19:32:51 bostic Exp
* *
* $Id: dos.c,v 1.8 1996/09/23 09:59:24 miff Exp $ * $Id: dos.c,v 1.1 1997/08/09 01:42:40 dyson Exp $
*/ */
#include "doscmd.h" #include "doscmd.h"
@ -2007,7 +2007,7 @@ fcb_to_string(fcbp, buf)
{ {
if (fcbp->fcbDriveID != 0x00) { if (fcbp->fcbDriveID != 0x00) {
*buf++ = fcbp->fcbDriveID - 1 + 'A'; *buf++ = drntol(fcbp->fcbDriveID - 1);
*buf++ = ':'; *buf++ = ':';
} }
pack_name(fcbp->fcbFileName, buf); pack_name(fcbp->fcbFileName, buf);

View File

@ -29,7 +29,7 @@
* *
* BSDI doscmd.c,v 2.3 1996/04/08 19:32:30 bostic Exp * BSDI doscmd.c,v 2.3 1996/04/08 19:32:30 bostic Exp
* *
* $Id: doscmd.c,v 1.3 1997/09/30 22:03:40 jlemon Exp $ * $Id: doscmd.c,v 1.4 1998/02/28 16:02:23 jraynard Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -312,16 +312,12 @@ setup_boot(regcontext_t *REGS)
} }
if (fd < 0) { /* can we boot it? */ if (fd < 0) { /* can we boot it? */
fprintf(stderr, "Cannot boot from %c: (can't open)\n", errx(1, "Cannot boot from %c", drntol(booting));
booting + 'A');
quit(1);
} }
/* read bootblock */ /* read bootblock */
if (read(fd, (char *)0x7c00, 512) != 512) { if (read(fd, (char *)0x7c00, 512) != 512) {
fprintf(stderr, "Short read on boot block from %c:\n", errx(1, "Short read on boot block from %c:", drntol(booting));
booting + 'A');
quit(1);
} }
/* initialise registers for entry to bootblock */ /* initialise registers for entry to bootblock */
@ -370,13 +366,13 @@ setup_command(int argc, char *argv[], regcontext_t *REGS)
usage(); usage();
/* look for a working directory XXX ??? */ /* look for a working directory XXX ??? */
if (dos_getcwd('C' - 'A') == NULL) { if (dos_getcwd(drlton('C')) == NULL) {
/* try to get our current directory, use '/' if desperate */ /* try to get our current directory, use '/' if desperate */
p = getcwd(buffer, sizeof(buffer)); p = getcwd(buffer, sizeof(buffer));
if (!p || !*p) p = getenv("PWD"); if (!p || !*p) p = getenv("PWD");
if (!p || !*p) p = "/"; if (!p || !*p) p = "/";
init_path('C' - 'A', (u_char *)"/", (u_char *)p); init_path(drlton('C'), (u_char *)"/", (u_char *)p);
/* look for PATH= already set, learn from it if possible */ /* look for PATH= already set, learn from it if possible */
for (i = 0; i < ecnt; ++i) { for (i = 0; i < ecnt; ++i) {
@ -388,8 +384,7 @@ setup_command(int argc, char *argv[], regcontext_t *REGS)
/* no PATH in DOS environment? put current directory there*/ /* no PATH in DOS environment? put current directory there*/
if (i >= ecnt) { if (i >= ecnt) {
static char path[256]; static char path[256];
sprintf(path, "PATH=C:%s", sprintf(path, "PATH=C:%s", dos_getcwd(drlton('C')));
dos_getcwd('C' - 'A'));
put_dosenv(path); put_dosenv(path);
dos_path = envs[ecnt-1] + 5; dos_path = envs[ecnt-1] + 5;
} }
@ -428,8 +423,8 @@ setup_command(int argc, char *argv[], regcontext_t *REGS)
envs[ecnt] = 0; envs[ecnt] = 0;
/* XXX ??? */ /* XXX ??? */
if (dos_getcwd('R' - 'A') == NULL) if (dos_getcwd(drlton('R')) == NULL)
init_path('R' - 'A', (u_char *)"/", 0); init_path(drlton('R'), (u_char *)"/", 0);
/* get program name */ /* get program name */
strncpy(prog, *argv++, sizeof(prog) -1); strncpy(prog, *argv++, sizeof(prog) -1);

View File

@ -29,7 +29,7 @@
* *
* BSDI doscmd.h,v 2.3 1996/04/08 19:32:32 bostic Exp * BSDI doscmd.h,v 2.3 1996/04/08 19:32:32 bostic Exp
* *
* $Id: doscmd.h,v 1.2 1997/08/15 23:41:24 jlemon Exp $ * $Id: doscmd.h,v 1.3 1997/09/30 22:03:41 jlemon Exp $
*/ */
@ -61,6 +61,8 @@
#include "callback.h" #include "callback.h"
#include "cwd.h" #include "cwd.h"
#define drlton(a) ((islower((a)) ? toupper((a)) : (a)) - 'A')
#define drntol(a) ((a) + 'A')
/* /*
** assorted hardware/scope constants ** assorted hardware/scope constants

View File

@ -29,7 +29,7 @@
* *
* BSDI int13.c,v 2.3 1996/04/08 19:32:43 bostic Exp * BSDI int13.c,v 2.3 1996/04/08 19:32:43 bostic Exp
* *
* $Id: int13.c,v 1.3 1996/09/22 15:42:53 miff Exp $ * $Id: int13.c,v 1.1 1997/08/09 01:42:46 dyson Exp $
*/ */
#include "doscmd.h" #include "doscmd.h"
@ -200,8 +200,8 @@ init_hdisk(int drive, int cyl, int head, int tracksize, char *file, char *fake_p
di = &diskinfo[drive]; di = &diskinfo[drive];
if (di->path) { if (di->path) {
fprintf(stderr, "Drive %c: already assigned to %s\n", fprintf(stderr, "Drive %c: already assigned to %s\n", drntol(drive),
drive + 'A', di->path); di->path);
return(-1); return(-1);
} }
di->fd = -1; di->fd = -1;
@ -377,20 +377,19 @@ init_floppy(int drive, int type, char *file)
di = &diskinfo[drive]; di = &diskinfo[drive];
if (stat(file, &sb) < 0) { if (stat(file, &sb) < 0) {
fprintf(stderr, "Drive %c: Could not stat %s\n", fprintf(stderr, "Drive %c: Could not stat %s\n", drntol(drive), file);
drive + 'A', file);
return(-1); return(-1);
} }
if (drive < 2 && (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode))) { if (drive < 2 && (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode))) {
if (di->path && !di->removeable) { if (di->path && !di->removeable) {
fprintf(stderr, "Drive %c: is not removeable and hence can only have one assignment\n", drive + 'A'); fprintf(stderr, "Drive %c: is not removeable and hence can only have one assignment\n", drntol(drive));
return(-1); return(-1);
} }
di->removeable = 1; di->removeable = 1;
} else if (di->removeable) { } else if (di->removeable) {
fprintf(stderr, "Drive %c: already assigned to %s\n", fprintf(stderr, "Drive %c: already assigned to %s\n", drntol(drive),
drive + 'A', di->path); di->path);
return(-1); return(-1);
} }
@ -398,7 +397,7 @@ init_floppy(int drive, int type, char *file)
#if 0 /*XXXXX*/ #if 0 /*XXXXX*/
if (di->multi == 4) { if (di->multi == 4) {
fprintf(stderr, "Drive %c: already assigned 4 devices\n", fprintf(stderr, "Drive %c: already assigned 4 devices\n",
drive + 'A'); drntol(drive));
return(-1); return(-1);
} }
#endif #endif
@ -406,7 +405,7 @@ init_floppy(int drive, int type, char *file)
} else { } else {
if (di->path) { if (di->path) {
fprintf(stderr, "Drive %c: already assigned to %s\n", fprintf(stderr, "Drive %c: already assigned to %s\n",
drive + 'A', di->path); drntol(drive), di->path);
return(-1); return(-1);
} }

View File

@ -29,7 +29,7 @@
* *
* BSDI intff.c,v 2.2 1996/04/08 19:32:56 bostic Exp * BSDI intff.c,v 2.2 1996/04/08 19:32:56 bostic Exp
* *
* $Id: intff.c,v 1.1 1997/08/09 01:42:51 dyson Exp $ * $Id: intff.c,v 1.2 1997/09/30 22:03:57 jlemon Exp $
*/ */
#include "doscmd.h" #include "doscmd.h"
@ -673,7 +673,7 @@ int2f11_validate(regcontext_t *REGS)
} }
/* translate letter to drive number */ /* translate letter to drive number */
r_drive = toupper(path[0]) - 'A'; r_drive = drlton(path[0]);
} else { } else {
path = "(no path)"; path = "(no path)";
} }
@ -685,7 +685,7 @@ int2f11_validate(regcontext_t *REGS)
} }
debug(D_REDIR,"%s -> drive %c func %x (%sus)\n", debug(D_REDIR,"%s -> drive %c func %x (%sus)\n",
path, 'A'+r_drive, func, doit?"":"not "); path, drntol(r_drive), func, doit?"":"not ");
/* so do we deal with this one? */ /* so do we deal with this one? */
return(doit); return(doit);
@ -749,7 +749,7 @@ install_drive(int drive, u_char *path)
/* check that DOS considers this a valid drive */ /* check that DOS considers this a valid drive */
if (drive < 0 || drive >= lol->lastdrive) { if (drive < 0 || drive >= lol->lastdrive) {
debug(D_REDIR, "Drive %c beyond limit of %c)\n", debug(D_REDIR, "Drive %c beyond limit of %c)\n",
drive + 'A', lol->lastdrive - 1 + 'A'); drntol(drive), drntol(lol->lastdrive - 1));
return; return;
} }
@ -759,15 +759,15 @@ install_drive(int drive, u_char *path)
#if 0 /* XXX looks OK to me - mjs */ #if 0 /* XXX looks OK to me - mjs */
if (cds->flag & (CDS_remote | CDS_ready)) { if (cds->flag & (CDS_remote | CDS_ready)) {
debug(D_REDIR, "Drive %c already installed\n", drive + 'A'); debug(D_REDIR, "Drive %c already installed\n", drntol(drive));
return; return;
} }
#endif #endif
debug(D_REDIR, "Installing %c: as %s\n", drive + 'A', path); debug(D_REDIR, "Installing %c: as %s\n", drntol(drive), path);
cds->flag |= CDS_remote | CDS_ready | CDS_notnet; cds->flag |= CDS_remote | CDS_ready | CDS_notnet;
cds->path[0] = drive + 'A'; cds->path[0] = drntol(drive);
cds->path[1] = ':'; cds->path[1] = ':';
cds->path[2] = '\\'; cds->path[2] = '\\';
cds->path[3] = '\0'; cds->path[3] = '\0';