Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : VMIXUTL.ZIP
Filename : VSETUP.C

 
Output of file : VSETUP.C contained in archive : VMIXUTL.ZIP
/*****************************************************************************
* ComSoft Library -- vsetup.c
*
* DATE: Dec. 02, 1991 12-18-91
*
* NAME: vsetup - VMiX 386 configurator
*
* SYNOPSIS:
*
* FUNCTION:
*
* RETURNS:
* N/A
*
*****************************************************************************/

#define SYS_DISKIO 1

#include "c_bios.h"
#include "$_kernel.h"
#include "$_config.h"
#include "$_mem.h"
#include "$_proc.h"
#include "io_chan.h"
#include "io_irp.h"
#include "io_obj.h"


#define NUMFILES 2


/* Local variables */

LOCAL char digits[16] = "0123456789ABCDEF";


/* Global variables */

char line[SYS_SHLBUF]; /* command line buffer */
int numfcb = NUMFILES; /* number of files open */
unsigned int currpid;
struct CCB *cptr;
struct MEMINFO *mptr;
struct PCB *pptr;
struct FIRP fcbt[NUMFILES]; /* I/O file control blocks */
SYSCALL (*fpin)(void);


main(void)

{
register int i = NUMFILES;
register int fh;
char src[80], dest[80], *cmdbuf, *newbuf, nextcmd[SYS_SHLBUF];
char *buffer, *lptr = NULLPTR, *aptr = NULLPTR;
int rtop, tq = 3, count = 100;
unsigned int pid, type, fpos, envsiz;
long version;
struct MCB *mcbptr;
struct PCB *nptr;
struct OCB *optr;
union ADDRESS addr32, *ptr32;
void filestat(int);
char *parse_cmd(char *, char *);
char *strnloci(char *, char *, unsigned int);
int copyfile(char *, char *);
int fork(char *);
SYSCALL vm_close(int);
SYSCALL vm_open(char *, int);
SYSCALL vm_rline(int, char *, unsigned int);
SYSCALL vm_write(int, char *, unsigned int);
long vm_lseek(int, long, int);

version = sys_version();
if ((int)(version >> 16) != 1944) return(1);

ptr32 = &addr32; /* pointer component union */


currpid = (unsigned int)sys_getpid(); /* get ourselves first */
pptr = sys_getpcb(currpid); /* our process block */
cptr = sys_getccb(pptr->chan); /* stdio channel */
io0ps_stdirp = cptr->irptr; /* dummy extern in sysgate */
type = sys_getqkey(tq, cptr->uid); /* need object type to get */
optr = sys_getocb(type); /* the object control blk */
fpin = optr->obj_read; /* input function for chan */
mptr = (struct MEMINFO *)sys_memreq(currpid, "info");

while (i--) { /* init all file blocks */
fcbt[i].count = 0;
fcbt[i].index = 0;
fcbt[i].dirty = 0;
fcbt[i].pos = 0L;
fcbt[i].fpos = 0L;
fcbt[i].handle = EMPTY; /* handle (not open) */
}

buffer = &dest[0];
ptr32->fp.segment = mptr->code - 0x10; /* VMiX PSP */
ptr32->fp.offset = 0x2C; /* VMiX environment */
ptr32->fp.segment = *ptr32->fptr;
--ptr32->fp.segment;
ptr32->fp.offset = 3; /* environment size */
envsiz = *ptr32->fptr << 4;
++ptr32->fp.segment;
ptr32->fp.offset = 0; /* VMiX environment */

dest[0] = 1;
dest[1] = src[0] = EOS;

if (lptr = strnloci(dest, (char *)ptr32->fptr, envsiz))
if (*(++lptr) == EOS) {
++lptr;
if (aptr = strnloci("vm_boot", lptr, 80)) {
*aptr = EOS;
strcpy(src, lptr);
strcpy(dest, lptr);
*aptr = 'V';
}
}

if (!strlen(src)) dest[0] = EOS;

strcat(src, "VMIX.INI");
strcat(dest, "VMIX.BAK");

if ((fh = vm_open(src, O_RDWR | O_BINARY)) != SYS_ERROR) {
while ((fpos = vm_rline(fh, line, 80)) != EMPTY) {
if (lptr = strnloci(";", line, strlen(line)))
*lptr = EOS; /* strip comments */
if (lptr = strnloci("[access", line, strlen(line))) break;
}

if (lptr) {
vm_close(fh);
copyfile(src, dest);
fh = vm_open(src, O_RDWR | O_BINARY);
vm_lseek(fh, fpos, 0);
vm_write(fh, "[encrpt", 7);
vm_lseek(fh, fpos, 0);
vm_rline(fh, line, 80);

while ((fpos = vm_rline(fh, line, 80)) != EMPTY) {
if (strnloci("[", line, strlen(line))) break;

for (i = 0; line[i]; i++) {
if (line[i] == ';') break;
if (line[i] != BLANK &&
line[i] != '\r' && line[i] != '\n') {
line[i] ^= 0x8F;
line[i] &= 0x7F;
}
}

vm_lseek(fh, fpos, 0);
vm_write(fh, line, strlen(line));
vm_lseek(fh, fpos, 0);
vm_rline(fh, line, 80);
}

vm_close(fh);
}
vm_close(fh);
}

if (!strcmp(pptr->uname, "root")) {
if ((fh = vm_open(src, O_RDONLY | O_BINARY)) != SYS_ERROR) {
while (vm_rline(fh, line, 80) != EMPTY)
if (lptr = strnloci("[startup", line, strlen(line)))
break;

rtop = io0ps_stdirp->wintop;
io0ps_stdirp->wintop = 0x0100;

if (lptr)
while (vm_rline(fh, line, 80) != EMPTY) {
if (lptr = strnloci(";", line, strlen(line)))
*lptr = EOS; /* strip comments */
if (strnloci("[", line, strlen(line))) break;
if (!strlen(line)) continue;

if (strnloci("do", line, strlen(line)) ||
strnloci("sp", line, strlen(line))) {

cmdbuf = &line[0];
newbuf = parse_cmd(cmdbuf, nextcmd);

while (*nextcmd) {
if (strnloci("do", nextcmd, 2) ||
strnloci("sp", nextcmd, 2)) {
strcat(nextcmd, "/");
strcat(nextcmd, newbuf);
*newbuf = EOS;
sys_system(nextcmd);
}
else {
if (fork(nextcmd) == SYS_ERROR)
break;

if ((pid =
(int)sys_spawn(nextcmd)) ==
SYS_ERROR) break;
nptr = sys_getpcb(pid);

while (nptr->pstate !=
PSTATE_FREE) ;
}
newbuf = parse_cmd(newbuf, nextcmd);
}
}
else {
if (fork(line) == SYS_ERROR) continue;

if ((pid = (int)sys_spawn(line)) ==
SYS_ERROR) break;
nptr = sys_getpcb(pid);

while (nptr->pstate != PSTATE_FREE) ;
}
}
sys_system("se vi -W"); /* fix the console window */
io0ps_stdirp->wintop = rtop;
vm_close(fh);

return(0);
}
else {
sys_vprintf("VM$ERR_vsetup: %s not found\r\n", src);
return(1);
}
}

sys_clrwindow(io0ps_stdirp->wintop, io0ps_stdirp->winbot);

while ((*fpin)() && count-- > 0) ;

count = 0;
while (count++ < 3) {
while ((i = sys_pinput("access password:", BLANK, SYS_PNMLEN,
&buffer)) == 0) ;

buffer[i] = EOS;

if ((fh = vm_open(src, O_RDONLY | O_BINARY)) != SYS_ERROR) {
while (vm_rline(fh, line, 80) != EMPTY) {
if (lptr = strnloci(";", line, strlen(line)))
*lptr = EOS; /* strip comments */
if (lptr = strnloci("[encrpt", line, strlen(line)))
break;
}

if (lptr)
while (vm_rline(fh, line, 80) != EMPTY) {
for (i = 0; line[i]; i++)
if (line[i] != BLANK &&
line[i] != '\r' && line[i] != '\n') {
line[i] |= 0x80;
line[i] ^= 0x8F;
}

if (strnloci("[", line, strlen(line))) break;

if (aptr = strnloci(dest, line, SYS_PNMLEN)) {
count = 3;
break;
}
}

vm_lseek(fh, 0, 0);

while ((fpos = vm_rline(fh, line, 80)) != EMPTY) {
if (lptr = strnloci(";", line, strlen(line)))
*lptr = EOS; /* strip comments */
if (strnloci("[remote", line, strlen(line))) break;
}

if (fpos == EMPTY) line[0] = EOS;
else while (vm_rline(fh, line, 80) != EMPTY) {
if (lptr = strnloci(";", line, strlen(line)))
*lptr = EOS;/* strip comments */
if (strnloci("[", line, strlen(line))) {
line[0] = EOS;
break;
}
if (strlen(line)) break;
}

vm_close(fh);
}
}

if (!aptr) {
sys_vprintf("VM$ERR_vsetup: invalid password\r\n");
return(1);
}

itoa(pptr->chan, nextcmd, 10);

i = 0;
while (nextcmd[i]) ++i;

nextcmd[i++] = BLANK;
nextcmd[i++] = 'e';
nextcmd[i++] = 'x';
nextcmd[i++] = BLANK;
nextcmd[i++] = '/';
nextcmd[i++] = 'k';
nextcmd[i++] = 'i';
nextcmd[i++] = BLANK;

itoa(currpid, nextcmd + i, 10); /* kill ourselves first */
while (nextcmd[i]) ++i;

nextcmd[i++] = '/';
strcpy(nextcmd + i, line); /* then start remote task */

pptr->psl |= PSL_VSETUP;

/* dispatch remote command line */
if ((pid = (int)sys_spawn(nextcmd)) == SYS_ERROR) return(1);

return(0);
}


int copyfile(src, dest)

char *src, *dest;

{
int fd1, fd2, num;
char buffer[SYS_FILEBUF];
SYSCALL vm_close(int);
SYSCALL vm_creat(char *, int);
SYSCALL vm_open(char *, int);
SYSCALL vm_read(int, char *, unsigned int);
SYSCALL vm_write(int, char *, unsigned int);

if ((fd1 = vm_open(src, O_RDONLY | O_BINARY)) == EOF) return(-1);

if ((fd2 = vm_creat(dest, S_IWRITE)) == EOF) return(-2);

while ((num = vm_read(fd1, buffer, 1024)) > 0)
if (num != vm_write(fd2, buffer, num)) return( -3 );

vm_close(fd2);
vm_close(fd1);

return(0);
}


int fork(request)

char *request;

{
register int n = 0;
char buf[SYS_SHLBUF];
int chan;
struct IRP *packet;

strcpy(buf, request);
if ((packet = (struct IRP *)sys_chanreq(currpid, "assign", cptr->uid,
currpid, cptr->csl)) == NULLPTR)
return(SYS_ERROR);

chan = packet->chan; /* new channel */
itoa(chan, request, 10);

while (request[n]) ++n;

request[n++] = BLANK;

if (io0ps_stdirp->winbot != make_int(COL_VMAX, ROW_VMAX)) {
request[n++] = 's';
request[n++] = 'e';
request[n++] = BLANK;
request[n++] = 'v';
request[n++] = 'i';
request[n++] = BLANK;
request[n++] = '-';
request[n++] = 'W';
request[n++] = '/';
}

request[n++] = 'e';
request[n++] = 'x';
request[n++] = BLANK;
request[n++] = '/';

strcpy(request + n, buf);

return(SYS_OK);
}


/*----------------------------------------------------------------------------
| NAME: itoa -- converts integer to ASCII hex/dec
|
| SYNOPSIS:
| itoa(num, cp, base);
|
| int num; integer (+ - 32767)
| char *cp; pointer to numeric string
| 0x hexadecimal
| int base; conversion radix
|
| FUNCTION:
|
| RETURNS:
| = (char *)str
|
|---------------------------------------------------------------------------*/

char *itoa(num, cp, base)

int num; /* number to convert */
char *cp; /* the storage string */
int base; /* the conversion radix */

{
register int n; /* number of characters in result */
char temp[18], *tcp;
int sign = 0;
unsigned int unum; /* unsigned value */

*(tcp = temp + 17) = 0;

if (base == 10 && num < 0) { /* needs signed conversion */
sign = 1;
do {*--tcp = digits[-(num % base)]; } while((num /= -base));
}
else {
unum=num;
do {*--tcp = digits[unum % base]; } while(unum /= base);
}

if (base == 16) {
*--tcp = 'x';
*--tcp = '0';
}
else if (sign) *--tcp = '-';

n = (int)(temp + 17 - tcp);
strncpy(cp, tcp, n);
*(cp + n) = 0;

return(cp);
}


/*----------------------------------------------------------------------------
| NAME: strnloci -- locates string1 in string2 first n characters
|
| SYNOPSIS:
| strnloci(s, t, n));
|
| char *s; pointer to search string1
| char *t; pointer to target string2
| unsigned int n; number of characters to search
|
| FUNCTION:
| String2 can be multiple ASCIIZ strings.
| strnloci is case insensitive.
|
| RETURNS:
| = (char *)loc
| or = NULLPTR
|
|---------------------------------------------------------------------------*/

char *strnloci(s, t, n)

char *s, *t;
unsigned int n;

{
char *c = s;
char *p = NULLPTR;

while (n-- && *c) {
if (tolower(*c) == tolower(*t)) {
++c;
if (!p) p = t;
}
else {
p = NULLPTR;
c = s;
}
++t;
}

if (*c) p = NULLPTR;

return(p);
}


/*----------------------------------------------------------------------------
| NAME: skip_white -- strips whitespace
|
| SYNOPSIS:
| skip_white(cp);
|
| char *cp; pointer to string
|
| FUNCTION:
| Function strips whitespace from a string
|
| RETURNS:
| = (char *)cp
|
|---------------------------------------------------------------------------*/

char *skip_white(cp)

char *cp;

{
while (is_white(*cp)) ++cp; /* skip white space */
return(cp);
}


/*----------------------------------------------------------------------------
| NAME: parse_cmd -- parses next command from input buffer
|
| SYNOPSIS:
| parse_cmd(inbuf, outbuf);
|
| char *inbuf input buffer
| char *outbuf output buffer
|
| FUNCTION:
| Function stores command in outbuf and returns pointer to
| next non-blank inbuf character.
|
| RETURNS:
| = (char *)cptr
|
|---------------------------------------------------------------------------*/

char *parse_cmd(inbuf, outbuf)

char *inbuf, *outbuf;

{
register int i = 0;
char *skip_white(char *);

while (*inbuf && (is_white(*inbuf) || *inbuf == '/')) ++inbuf;

while ((i <= SYS_SHLBUF) && *inbuf && !(*inbuf == '/'))
outbuf[i++] = *inbuf++;

outbuf[i] = EOS;
inbuf = skip_white(*inbuf ? ++inbuf : inbuf);

return(inbuf);
}

#include "$_dsk.c"

#ifdef SYS_DEBUG
void filestat(fhandle)

int fhandle;

{
struct FIRP *t;

sys_vprintf("\r\nFile Number: %4d\r\n",fhandle);

if (fhandle >= numfcb || fhandle < 0)
sys_vprintf("invalid handle\r\n");

else if (fcbt[fhandle].handle < 0) {
sys_vprintf("handle not open\r\n");
return;
}
else {
t = &fcbt[fhandle];
sys_vprintf("File Handle: %4d\r\n",t->handle);
sys_vprintf("Dirty Flag: %4d\r\n",t->dirty);
sys_vprintf("Count: %4d\r\n",t->count);
sys_vprintf("Index: %4d\r\n",t->index);
sys_vprintf("Position: %4ld\r\n",t->pos);
sys_vprintf("File Pos: %4ld\r\n",t->fpos);
}

sys_vprintf("Press any key to exit");
getch();
sys_vprintf("\r\n");
}
#endif



  3 Responses to “Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : VMIXUTL.ZIP
Filename : VSETUP.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/