home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Workbench / Misc / NULLHNDL.LHA / Null / src / null.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-05  |  3.9 KB  |  146 lines

  1. /****************************************************************************
  2.  *
  3.  *  null driver V0.0 (c)CopyRight 1988, Gunnar Nordmark.  All Rights Reserved.
  4.  *  
  5.  *  null-handler Ver. 0.0  20-Jul-1988
  6.  *
  7.  *  Gunnar Nordmark
  8.  *  Nora strand 5
  9.  *  182 34 DANDERYD
  10.  *  SWEDEN
  11.  *
  12.  *  |You may freely distribute this source as long as |
  13.  *  |the Copyright notice is left intact.          |
  14.  *
  15.  *  Remark by Reinhard Katzmann: Added some SAS/C Options, so it will compile
  16.  *  with SAS/C 6.51 
  17.  *  Changed Version Number to 0.1 because of
  18.  *  - Adding DOS-OpenLibrary (and checking if Version >= V37)
  19.  *  - Changed SysBase Definition (should work with execbase.h)
  20.  ***************************************************************************/
  21.  
  22. #include <functions.h>
  23. #include <stdio.h>
  24. #include <exec/types.h>
  25. #include <exec/nodes.h>
  26. #include <exec/lists.h>
  27. #include <exec/ports.h>
  28. #include <exec/libraries.h>
  29. #include <exec/devices.h>
  30. #include <exec/io.h>
  31. #include <exec/memory.h>
  32. #include <exec/execbase.h>
  33. #include <devices/console.h>
  34. #include <libraries/dos.h>
  35. #include <libraries/dosextens.h>
  36. #include <libraries/filehandler.h>
  37. #include <proto/exec.h>
  38. #include <proto/dos.h>
  39.  
  40. #undef  BADDR
  41. #define BADDR(x)   ((APTR)((long)x << 2))
  42.  
  43. #ifndef LATTICE
  44. #define ACTION_FINDINPUT    1005L
  45. #define ACTION_FINDOUTPUT    1006L
  46. #define ACTION_END         1007L
  47. #else
  48. extern void returnpkt(struct DosPacket *, struct Process *, ULONG, ULONG);
  49. extern void returnpktplain(struct DosPacket *, struct Process *);
  50. extern struct DosPacket *taskwait(struct Process *);
  51. __saveds _main(void);
  52. #endif
  53.  
  54. #define DOS_FALSE            0L
  55. #define DOS_TRUE                -1L
  56. #define DOSVER    37L            /* We require AT LEAST V37 of OS */
  57. #define DOSLIB    "dos.library"
  58.  
  59. /* My Globals */
  60.  
  61. struct Process      *myproc;
  62. struct ExecBase *SysBase;
  63. struct DosLibrary *DOSBase;
  64. #ifdef LATTICE
  65. __saveds _main()
  66. #else
  67. _main()
  68. #endif
  69. {
  70.     if ((DOSBase = (struct DosLibrary *)OpenLibrary(DOSLIB, DOSVER))) {
  71.     extern void returnpkt();        /* sends back the packet          */
  72.     extern void returnpktplain();    /* use args in Res1               */
  73.     extern struct DosPacket *taskwait();
  74.  
  75. #ifdef LATTICE
  76.     const char Version[] = "$VER: Version 0.1 (c) Gunnar Nordmark 1988";
  77. #else
  78.            char       *version =     "Ver 0.0 (c) Gunnar Nordmark 1988";
  79. #endif
  80.     struct DosPacket  *mypkt;          /* a pointer to the dos packet    */
  81.     struct DeviceNode *mynode;         /* our device node (parmpkt Arg3) */
  82.     struct FileHandle *fh;         /* a pointer to our file handle      */
  83.     long          run = TRUE;    /* handler main loop flag      */
  84.     int              null_open = 0;    /* null open count          */
  85.  
  86.  
  87.     /* Initializing the handler */
  88.  
  89.     myproc      = (struct Process *)FindTask(0L);
  90.     mypkt       = taskwait(myproc);      /* Wait for my startup message */
  91.  
  92.     /* I don't need the name or extra info passed in Arg1/2 */
  93.  
  94.     mynode          = (struct DeviceNode *)BADDR(mypkt->dp_Arg3);
  95.     mynode->dn_Task     = &myproc->pr_MsgPort; 
  96.     returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2); 
  97.  
  98.     /* done initial stuff, now for some work */
  99.  
  100.     while(run) {
  101.     mypkt = taskwait(myproc);
  102.  
  103.     switch(mypkt->dp_Type) {    /* find what action to perform */
  104.  
  105.     case ACTION_FINDINPUT:
  106.     case ACTION_FINDOUTPUT:
  107.  
  108.         null_open++;
  109.  
  110.         fh = (struct FileHandle  *)BADDR(mypkt->dp_Arg1);
  111.         fh->fh_Arg1 = mypkt->dp_Type;
  112.         fh->fh_Port = (struct MsgPort *)DOS_FALSE; /* not interactive */
  113.  
  114.         returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
  115.         break;
  116.  
  117.     case ACTION_READ:
  118.  
  119.         returnpkt(mypkt, myproc, 0, mypkt->dp_Res2); /* zero-length=EOF */
  120.         break;
  121.  
  122.     case ACTION_WRITE:
  123.         
  124.         mypkt->dp_Res1 = mypkt->dp_Arg3;  /* tell em we wrote them all */
  125.         returnpktplain(mypkt, myproc);
  126.         break;
  127.  
  128.     case ACTION_END:
  129.  
  130.         if (--null_open == 0)
  131.         run = 0;
  132.  
  133.         returnpkt(mypkt, myproc, DOS_TRUE, mypkt->dp_Res2);
  134.         break;
  135.  
  136.     default:
  137.  
  138.         returnpkt(mypkt, myproc, DOS_FALSE, ERROR_ACTION_NOT_KNOWN);
  139.         break;
  140.     }
  141.     } /* end while */
  142.     mynode->dn_Task = FALSE; 
  143.    }
  144.    return(RETURN_FAIL);
  145. }
  146.