home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 239.lha / amiga / src / server / sprint.c < prev    next >
C/C++ Source or Header  |  1989-05-02  |  1KB  |  84 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 <stdio.h>
  15. #include <fcntl.h>
  16. #include "servers.h"
  17.  
  18. int Enable_Abort;
  19.  
  20. typedef struct Process PROC;
  21.  
  22. extern struct MsgPort *DListen();
  23. extern PROC *FindTask();
  24.  
  25. extern void printfile();
  26.  
  27. _main()
  28. {
  29.     struct MsgPort *port;
  30.     PROC    *myproc = FindTask(NULL);
  31.     long    chan;
  32.     long    savedir;
  33.     long    mask, rmask;
  34.  
  35.     Enable_Abort = 0;
  36.  
  37.     if (myproc->pr_CLI) {
  38.     Version("SPrint", VERSION, SPRINT_VERSION);
  39.     _exit(0);
  40.     }
  41.  
  42.     port = DListen(PORT_PRINTER);
  43.     WaitPort(&myproc->pr_MsgPort);
  44.     ReplyMsg(GetMsg(&myproc->pr_MsgPort));
  45.  
  46.     mask = SIGBREAKF_CTRL_C|(1 << port->mp_SigBit);
  47.     for (;;) {
  48.     rmask = Wait(mask);
  49.     if (rmask & SIGBREAKF_CTRL_C)
  50.         break;
  51.     while (chan = DAccept(port)) {
  52.         if (GetEnvVal(DNET_WRITE) >= 6) {
  53.         DWrite(chan, "Accepted\n", 9);
  54.         printfile(chan);
  55.         } else {
  56.         DWrite(chan, "Permission Denied\n", 18);
  57.         }
  58.         DClose(chan);
  59.     }
  60.     }
  61.     DUnListen(port);
  62. }
  63.  
  64. void
  65. printfile(chan)
  66. {
  67.     long n, fh;
  68.     char rc = 0;
  69.     char buf[256];
  70.  
  71.     if (fh = Open("PRT:", 1006)) {
  72.     rc = 1;
  73.     while ((n = DRead(chan, buf, 256)) > 0) {
  74.         if (Write(fh, buf, n) != n) {
  75.         rc = 0;
  76.         break;
  77.         }
  78.     }
  79.     Close(fh);
  80.     }
  81.     DWrite(chan, &rc, 1);
  82. }
  83.  
  84.