home *** CD-ROM | disk | FTP | other *** search
- /*
- * Novell network example of the CTSLOK.C module based on low level
- * MS-DOS calls made through the c runtime library. This sample is
- * setup for the Novell 2.1 environment and the MICROSOFT C
- * compiler. This code assumes that the low level MS-DOS calls made
- * through the c runtime library return the status flags so that the
- * carry bit can be tested for a DOS error condition.
- *
- * Compact memory model server.
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1985, 1986, 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #define LPOINTER
-
- #include "ctstdr.h" /* standard i/o header */
- #undef EXTERN
- #define EXTERN /* */
- #include "ctoptn.h" /* c-tree configuration options */
- #include "cterrc.h" /* c-tree error codes */
- #include "ctstrc.h" /* c-tree data structures */
- #include "ctgvar.h" /* c-tree global variables */
- #include "ctcomm.h"
-
- #define INFINITY 3000 /* loop termination count waiting for lock */
-
- /* DOS dependent low level function numbers */
-
- #define OS_OPEN 0x3D00 /* MS-DOS dependent */
- #define OS_CLOSE 0x3E00 /* " */
- #define OS_CREATE 0x3C00 /* " */
- #define OS_READ 0x3F00 /* " */
- #define OS_WRITE 0x4000 /* " */
- #define OS_REMOVE 0x4100 /* " */
- #define OS_LSEEK 0x4200 /* " */
- #define SH_MODE 0x0042 /* " */
- #define EX_MODE 0x0012 /* " */
- #define OS_FLUSH 0x0D00 /* " */
-
- #define GT_LOCK 1
- #define UN_LOCK 2
-
- COUNT uerr();
- extern LONG cts_wl,cts_rl,cts_ul;
- extern COUNT noverr;
-
- /* 8086 dependent register structures based on Microsoft DOS.H model */
-
- struct XREGS {
- short ax,bx,cx,dx,si,di,cflag;
- } outregs;
-
- struct SREGS {
- short es,cs,ss,ds;
- } segreg;
-
- /* parse pointer variable (used for memory models with 4 byte pointers) */
-
- struct VAL {
- int offval;
- int segval;
- };
- union PTR {
- struct VAL v;
- TEXT *p;
- } ptr;
-
- /* union to separate high and low words */
-
- union {
- LONG li;
- COUNT xi[2]; /* xi[0] = low order word */
- } ci;
-
- /* --------------------------------------------------------- */
-
- /*
- * The dos() function must be changed if you are not using the Lattice
- * C compiler. In particular, if your compiler uses different
- * structures to represent the 8086 registers, define those structures
- * local to the dos function and make the appropriate translation prior
- * to calling your compiler's version of intdos(). Likewise, if your
- * compiler does not return the status flag, change the dos return statement(s)
- * so that it returns a non-zero value in case of error, and a zero if no
- * error.
- */
-
- numdis(i)
- unsigned int i;
- {
- ltoa((long) i,ct_buf,10);
- display(ct_buf);
- display(" ");
- }
-
- lngdis(i)
- long i;
- {
- ltoa(i,ct_buf,10);
- display(ct_buf);
- display(" ");
- }
-
- COUNT dos(pr,nds) /* returns a non-zero value on an OS error */
- struct XREGS *pr; /* pointer to input register values */
- COUNT nds; /* nds != -1 implies data segment must be set */
- {
- int retval;
-
- #ifdef LPOINTER /* four byte pointers are in use */
- segread(&segreg); /* loads segreg structure with current values */
- if (nds != -1)
- segreg.ds = nds;
-
- /*
- * note that intdos & intdosx return the status flag word. we "and" it
- * with 0x0001 to see if the carry bit is set which signifies a dos error
- */
- retval = novshlx(pr,&outregs,&segreg);
- #else
- retval = novshl(pr,&outregs);
- #endif
- #ifdef VAPDEBUG
- if (retval) {
- display("\n\rOS error: ");
- numdis(pr->ax);
- numdis(noverr);
- }
- return(retval);
- #endif
- }
-
- LOCAL COUNT ctseek(ctnum,recbyt)
- PFAST CTFILE *ctnum;
- POINTER recbyt;
- {
- struct XREGS inregs;
-
- if (ctnum->sekpos == recbyt)
- return(NO_ERROR);
-
- inregs.ax = OS_LSEEK;
- ci.li = ctnum->sekpos = recbyt;
- inregs.dx = ci.xi[0];
- inregs.cx = ci.xi[1];
- inregs.bx = ctnum->fd;
- if (dos(&inregs,-1))
- return(uerr(SEEK_ERR));
- else
- return(NO_ERROR);
- }
-
- RNDFILE mbopen(ctnum,opmode)
- PFAST CTFILE *ctnum;
- COUNT opmode; /* EXCLUSIVE or SHARED */
- {
- RNDFILE retval;
- struct XREGS inregs;
- COUNT newds;
-
- COUNT vtclose();
-
- ctnum->sekpos = 0L;
- inregs.ax = (OS_OPEN | EX_MODE);
-
- if (!(opmode & PERMANENT) && ct_numvfil >= MAXVFIL)
- vtclose();
-
- ptr.p = ctnum->flname;
- inregs.dx = ptr.v.offval;
-
- #ifdef LPOINTER
- newds = ptr.v.segval;
- #endif
-
- if (dos(&inregs,newds)) { /* check for carry flag set => error */
- retval = -1;
- if (vtclose() == YES) {
- if (dos(&inregs,newds))
- retval = -1;
- else
- retval = outregs.ax;
- }
- } else
- retval = outregs.ax;
-
- if (!(opmode & PERMANENT) && retval >= 0)
- ct_numvfil++;
-
- return(retval);
- }
-
- /* ------------------------------------------------------------ */
-
- RNDFILE mbcrat(ctnum)
- PFAST CTFILE *ctnum;
- {
- RNDFILE retval;
- struct XREGS inregs;
- COUNT newds;
-
- COUNT vtclose();
-
- ctnum->sekpos = 0L;
- if (!(ctnum->flmode & PERMANENT) && ct_numvfil >= MAXVFIL)
- vtclose();
-
- inregs.ax = OS_CREATE;
- inregs.cx = 0;
- ptr.p = ctnum->flname;
- inregs.dx = ptr.v.offval;
-
- #ifdef LPOINTER
- newds = ptr.v.segval;
- #endif
-
- if (dos(&inregs,newds)) { /* check for carry flag set => error */
- retval = -1;
- if (vtclose() == YES) {
- if (dos(&inregs,newds))
- retval = -1;
- else
- retval = outregs.ax;
- }
- } else
- retval = outregs.ax;
-
-
- if (!(ctnum->flmode & PERMANENT) && retval >= 0)
- ct_numvfil++;
-
- return(retval);
- }
-
-
- /* ------------------------------------------------------------ */
-
- COUNT ctio(op_code,ctnum,recbyt,bufadr,iosize)
- COUNT op_code; /* CTREAD or CTWRITE */
- CTFILE *ctnum;
- LONG recbyt;
- TEXT *bufadr;
- unsigned int iosize;
- {
- struct XREGS inregs;
- COUNT newds;
- char tt_buf[12];
-
- #ifdef VAPDEBUG
- if (op_code == CTREAD)
- display("\n\rREAD...");
- else
- display("\n\rWRITE..");
- display(ctnum->flname);
- display("..pos=");
- itoa((int) recbyt,tt_buf,10);
- display(tt_buf);
- #endif
-
- if (ctseek(ctnum,recbyt))
- return(uerr(SEEK_ERR));
-
- if (!iosize)
- iosize = ctnum->reclen;
-
- #ifdef VAPDEBUG
- itoa(iosize,tt_buf,10);
- display("..io=");
- display(tt_buf);
- #endif
-
- inregs.bx = ctnum->fd;
- inregs.cx = iosize;
- ptr.p = bufadr;
- inregs.dx = ptr.v.offval;
- #ifdef LPOINTER
- newds = ptr.v.segval;
- #endif
-
- if (op_code == CTREAD) {
- inregs.ax = OS_READ;
- if (dos(&inregs,newds) || outregs.ax != iosize) {
- ctnum->sekpos = -1L;
- #ifdef VAPDEBUG
- display("\n\rERR..");
- itoa(outregs.ax,tt_buf,10);
- display(tt_buf);
- #endif
- return(uerr(READ_ERR));
- }
- } else {
- inregs.ax = OS_WRITE;
- if (dos(&inregs,newds) || outregs.ax != iosize) {
- ctnum->sekpos = -1L;
- #ifdef VAPDEBUG
- display("\n\rERR..");
- itoa(outregs.ax,tt_buf,10);
- display(tt_buf);
- #endif
- return(uerr(WRITE_ERR));
- }
- }
-
- #ifdef VAPDEBUG
- display("ok");
- #endif
-
- ctnum->sekpos += iosize;
- return(NO_ERROR);
- }
-
-
- /* ------------------------------------------------------------ */
-
- COUNT mbclos( ctnum,clmode)
- PFAST CTFILE *ctnum;
- COUNT clmode; /* COMPLETE or PARTIAL */
- {
- struct XREGS inregs;
-
- if (!(ctnum->flmode & PERMANENT))
- ct_numvfil--;
- inregs.ax = OS_CLOSE;
- inregs.bx = ctnum->fd;
-
- if (dos(&inregs,-1))
- return(-1);
- else
- return(0);
- }
-
-
- /* ------------------------------------------------------------ */
-
- COUNT mbsave( ctnum)
- PFAST CTFILE *ctnum;
- {
- COUNT mbclos();
- RNDFILE mbopen();
-
- if (mbclos(ctnum,ctnum->flmode))
- return(uerr(FSAV_ERR));
- else if ((ctnum->fd = mbopen(ctnum,ctnum->flmode)) < 0)
- return(uerr(FSAV_ERR));
- else
- return(NO_ERROR);
- }
-
- VOID flushdos(datno)
- COUNT datno;
- {
- }
-
- sexit(err)
- COUNT err;
- {
- itoa(err,ct_buf,10);
- display(ct_buf);
- killvap();
- }
-
- COUNT dltfil(filnam)
- TEXT *filnam;
- {
- struct XREGS inregs;
- COUNT newds;
-
- inregs.ax = OS_REMOVE;
-
- ptr.p = filnam;
- inregs.dx = ptr.v.offval;
-
- #ifdef LPOINTER
- newds = ptr.v.segval;
- #endif
-
- if (dos(&inregs,newds)) /* check for carry flag set => error */
- return(uerr_cod = DLTF_ERR);
- else
- return(NO_ERROR);
- }
-
- /* end of ctclibc.nov */
-