home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * null driver V0.0 (c)CopyRight 1988, Gunnar Nordmark. All Rights Reserved.
- *
- * null-handler Ver. 0.0 20-Jul-1988
- *
- * Gunnar Nordmark
- * Nora strand 5
- * 182 34 DANDERYD
- * SWEDEN
- *
- * |You may freely distribute this source as long as |
- * |the Copyright notice is left intact. |
- *
- * Remark by Reinhard Katzmann: Added some SAS/C Options, so it will compile
- * with SAS/C 6.51
- * Changed Version Number to 0.1 because of
- * - Adding DOS-OpenLibrary (and checking if Version >= V37)
- * - Changed SysBase Definition (should work with execbase.h)
- ***************************************************************************/
-
- #include <functions.h>
- #include <stdio.h>
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <exec/ports.h>
- #include <exec/libraries.h>
- #include <exec/devices.h>
- #include <exec/io.h>
- #include <exec/memory.h>
- #include <exec/execbase.h>
- #include <devices/console.h>
- #include <libraries/dos.h>
- #include <libraries/dosextens.h>
- #include <libraries/filehandler.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
-
- #undef BADDR
- #define BADDR(x) ((APTR)((long)x << 2))
-
- #ifndef LATTICE
- #define ACTION_FINDINPUT 1005L
- #define ACTION_FINDOUTPUT 1006L
- #define ACTION_END 1007L
- #else
- extern void returnpkt(struct DosPacket *, struct Process *, ULONG, ULONG);
- extern void returnpktplain(struct DosPacket *, struct Process *);
- extern struct DosPacket *taskwait(struct Process *);
- __saveds _main(void);
- #endif
-
- #define DOS_FALSE 0L
- #define DOS_TRUE -1L
- #define DOSVER 37L /* We require AT LEAST V37 of OS */
- #define DOSLIB "dos.library"
-
- /* My Globals */
-
- struct Process *myproc;
- struct ExecBase *SysBase;
- struct DosLibrary *DOSBase;
- #ifdef LATTICE
- __saveds _main()
- #else
- _main()
- #endif
- {
- if ((DOSBase = (struct DosLibrary *)OpenLibrary(DOSLIB, DOSVER))) {
- extern void returnpkt(); /* sends back the packet */
- extern void returnpktplain(); /* use args in Res1 */
- extern struct DosPacket *taskwait();
-
- #ifdef LATTICE
- const char Version[] = "$VER: Version 0.1 (c) Gunnar Nordmark 1988";
- #else
- char *version = "Ver 0.0 (c) Gunnar Nordmark 1988";
- #endif
- struct DosPacket *mypkt; /* a pointer to the dos packet */
- struct DeviceNode *mynode; /* our device node (parmpkt Arg3) */
- struct FileHandle *fh; /* a pointer to our file handle */
- long run = TRUE; /* handler main loop flag */
- int null_open = 0; /* null open count */
-
-
- /* Initializing the handler */
-
- myproc = (struct Process *)FindTask(0L);
- mypkt = taskwait(myproc); /* Wait for my startup message */
-
- /* I don't need the name or extra info passed in Arg1/2 */
-
- mynode = (struct DeviceNode *)BADDR(mypkt->dp_Arg3);
- mynode->dn_Task = &myproc->pr_MsgPort;
- returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
-
- /* done initial stuff, now for some work */
-
- while(run) {
- mypkt = taskwait(myproc);
-
- switch(mypkt->dp_Type) { /* find what action to perform */
-
- case ACTION_FINDINPUT:
- case ACTION_FINDOUTPUT:
-
- null_open++;
-
- fh = (struct FileHandle *)BADDR(mypkt->dp_Arg1);
- fh->fh_Arg1 = mypkt->dp_Type;
- fh->fh_Port = (struct MsgPort *)DOS_FALSE; /* not interactive */
-
- returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
- break;
-
- case ACTION_READ:
-
- returnpkt(mypkt, myproc, 0, mypkt->dp_Res2); /* zero-length=EOF */
- break;
-
- case ACTION_WRITE:
-
- mypkt->dp_Res1 = mypkt->dp_Arg3; /* tell em we wrote them all */
- returnpktplain(mypkt, myproc);
- break;
-
- case ACTION_END:
-
- if (--null_open == 0)
- run = 0;
-
- returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
- break;
-
- default:
-
- returnpkt(mypkt, myproc, DOS_FALSE, ERROR_ACTION_NOT_KNOWN);
- break;
- }
- } /* end while */
- mynode->dn_Task = FALSE;
- }
- return(RETURN_FAIL);
- }
-