home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff294.lzh / DNet / amiga / server / sprint.c < prev    next >
C/C++ Source or Header  |  1989-12-11  |  1KB  |  87 lines

  1.  
  2. /*
  3.  *  SPRINT.C
  4.  *
  5.  *  DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
  6.  *
  7.  *  PRINTER SERVER
  8.  *
  9.  *  Accepting one connection at a time, dump the file to PRT:
  10.  *
  11.  *  DNET_WRITE    must be 6 or higher for this function to work.
  12.  */
  13.  
  14. #include "defs.h"
  15.  
  16. void printfile ARGS((void *));
  17.  
  18. int
  19. brk()
  20. {
  21.     return(0);
  22. }
  23.  
  24. void
  25. #ifdef LATTICE
  26. _main(str)
  27. #else
  28. _main(len,str)
  29. #endif
  30. char *str;
  31. {
  32.     PORT    *port;
  33.     PROC    *myproc = (PROC *)FindTask(NULL);
  34.     void    *chan;
  35.     long    mask, rmask;
  36.  
  37.     onbreak(brk);
  38.  
  39.     if (strncmp(str, "__dnet", 6) != 0) {
  40.     Version("SPrint", VERSION, SPRINT_VERSION);
  41.     _exit(0);
  42.     }
  43.  
  44.     port = DListen(PORT_PRINTER);
  45.     WaitPort(&myproc->pr_MsgPort);
  46.     ReplyMsg(GetMsg(&myproc->pr_MsgPort));
  47.  
  48.     mask = SIGBREAKF_CTRL_C|(1 << port->mp_SigBit);
  49.     for (;;) {
  50.     rmask = Wait(mask);
  51.     if (rmask & SIGBREAKF_CTRL_C)
  52.         break;
  53.     while (chan = DAccept(port)) {
  54.         if (GetEnvVal(DNET_WRITE) >= 6) {
  55.         DWrite(chan, "Accepted\n", 9);
  56.         printfile(chan);
  57.         } else {
  58.         DWrite(chan, "Permission Denied\n", 18);
  59.         }
  60.         DClose(chan);
  61.     }
  62.     }
  63.     DUnListen(port);
  64. }
  65.  
  66. void
  67. printfile(chan)
  68. void *chan;
  69. {
  70.     long n, fh;
  71.     char rc = 0;
  72.     char buf[256];
  73.  
  74.     if (fh = Open("PRT:", 1006)) {
  75.     rc = 1;
  76.     while ((n = DRead(chan, buf, 256)) > 0) {
  77.         if (Write(fh, buf, n) != n) {
  78.         rc = 0;
  79.         break;
  80.         }
  81.     }
  82.     Close(fh);
  83.     }
  84.     DWrite(chan, &rc, 1);
  85. }
  86.  
  87.