Category : Word Processors
Archive   : HP22D5.ZIP
Filename : DOS.C

 
Output of file : DOS.C contained in archive : HP22D5.ZIP
/*
** DOS.C - This extension performs some commonly used DOS functions.
** It does not, however, perform any critical error checking
** like drive door open, disk write protected, etc...
**
** The low level DOS functions are handled in assembly language
** IO.ASM.
*/
#include
#include
#include

#include "extern.h"
#include "io.h"

#define COPY_BUF_SIZE 4000

union REGS near regs;
struct SREGS near sregs;

/* declare this to avoid C startup references */
_maperror() {}

pascal near doscmd(func,name)

STRING name;
BYTE func;

{
regs.h.ah = func;
sregs.ds = FP_SEG(name);
regs.x.dx = FP_OFF(name);
intdosx(®s,®s,&sregs);
return(regs.x.cflag);
}

/* returns TRUE is error, FALSE otherwise */
pascal near md(name)

STRING name;

{
return(doscmd(0x39,name));
}

/* returns TRUE if error, FALSE otherwise */
pascal near rd(name)

STRING name;

{
return(doscmd(0x3a,name));
}

/* returns TRUE if error, FALSE otherwise. drive is a letter, like 'A' */
pascal near change_disk(disk)

int disk;

{
regs.h.dl = toupper(disk) - 'A';
regs.h.ah = 0xe;
intdos(®s,®s);
return(regs.x.cflag);
}

/* returns TRUE if error, FALSE otherwise */
pascal near cd(dir)

STRING dir;

{
int RC;
int drive;

/* use DOS to change the directory... */
RC = doscmd(0x3b,dir);

/* return if wasn't able to */
if (RC) return(RC);

/* change the logged drive, if there is a drive specifier */
return(dir[1] == ':' ? change_disk(dir[0]) : FALSE);
}

pascal near rename(newname,oldname)

STRING newname,oldname;

{
regs.h.ah = 0x56;

regs.x.dx = FP_OFF(oldname);
sregs.ds = FP_SEG(oldname);

regs.x.di = FP_OFF(newname);
sregs.es = FP_SEG(newname);

intdosx(®s,®s,&sregs);
return(regs.x.cflag);
}

pascal near ReturnBoolean(bool)

BOOLEAN bool;

{
ReturnValue(stoh(bool ? "ERROR" : "OK"));
}

MakeDir(int NumArgs,...)

{
va_list args;
HANDLE hdl;

va_start(args,NumArgs);

if (NumArgs != 1) return(STOP);

hdl = va_arg(args,HANDLE);

ReturnBoolean(md(htos(hdl)));

return(STOP);
}

RemoveDir(int NumArgs,...)

{
va_list args;
HANDLE hdl;

va_start(args,NumArgs);

if (NumArgs != 1) return(STOP);

hdl = va_arg(args,HANDLE);

ReturnBoolean(rd(htos(hdl)));

return(STOP);
}

MyChangeDir(int NumArgs,...)

{
va_list args;
HANDLE hdl;

va_start(args,NumArgs);

if (NumArgs != 1) return(STOP);

hdl = va_arg(args,HANDLE);

ReturnBoolean(cd(htos(hdl)));

return(STOP);
}

DeleteFile(int NumArgs,...)

{
va_list args;
HANDLE hdl;

va_start(args,NumArgs);

if (NumArgs != 1) return(STOP);

hdl = va_arg(args,HANDLE);

ReturnBoolean(doscmd(0x41,htos(hdl)));

return(STOP);
}

ChangeDisk(int NumArgs,...)

{
va_list args;
HANDLE hdl;

va_start(args,NumArgs);

if (NumArgs != 1) return(STOP);

hdl = va_arg(args,HANDLE);

ReturnBoolean(change_disk(((PTR)deref(hdl))[0]));

return(STOP);
}

RenameFile(int NumArgs,...)

{
va_list args;
HANDLE hSource,hDest;

va_start(args,NumArgs);

if (NumArgs != 2) return(STOP);

hSource = va_arg(args,HANDLE);
hDest = va_arg(args,HANDLE);

ReturnBoolean(rename(deref(hDest),deref(hSource)));

return(STOP);
}

CopyFile(int NumArgs,...)

{
va_list args;
HANDLE hSourceName,hDestName;
HANDLE hdl = NULL;
int source = -1,dest = -1;
int NumBytes;
union REGS regs;

va_start(args,NumArgs);

if (NumArgs != 2) return(STOP);

hSourceName = va_arg(args,HANDLE);
hDestName = va_arg(args,HANDLE);

if (!(hdl = NewHandle(COPY_BUF_SIZE))) {
ReturnValue(stoh("NOT ENOUGH MEMORY"));
goto ret;
}

source = open(deref(hSourceName),READ);

if (source < 0) {
ReturnValue(stoh("CANNOT OPEN SOURCE"));
goto ret;
}

dest = create(deref(hDestName));

if (dest < 0) {
ReturnValue(stoh("CANNOT OPEN DESTINATION"));
goto ret;
}

do {
NumBytes = read(source,deref(hdl),COPY_BUF_SIZE);
if (NumBytes > 0) write(dest,deref(hdl),NumBytes);
} while (NumBytes > 0);

regs.h.ah = 0x57;
regs.h.al = 0;
regs.x.bx = source;
intdos(®s,®s);
regs.h.ah = 0x57;
regs.h.al = 1;
regs.x.bx = dest;
intdos(®s,®s);

ReturnValue(stoh("OK"));

ret:
if (source > 0) close(source);
if (dest > 0) close(dest);
FreeHandle(hdl);
return(STOP);
}

POOL pascal Pool[] = {

{ "CopyFile",
CopyFile,
0,
FUNCTION},

{ "RenameFile",
RenameFile,
0,
FUNCTION},

{ "ChangeDisk",
ChangeDisk,
0,
FUNCTION},

{ "DeleteFile",
DeleteFile,
0,
FUNCTION},


{ "ChangeDir",
MyChangeDir,
0,
FUNCTION},

{ "RenameFile",
RenameFile,
0,
FUNCTION},

{ "RemoveDir",
RemoveDir,
0,
FUNCTION},

{ "MakeDir",
MakeDir,
0,
FUNCTION},

{ NULL,
NULL,
0,
0} };


  3 Responses to “Category : Word Processors
Archive   : HP22D5.ZIP
Filename : DOS.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/