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 / scli.c < prev    next >
C/C++ Source or Header  |  1989-12-11  |  3KB  |  147 lines

  1.  
  2. /*
  3.  *  SCLI.C
  4.  *
  5.  *  DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
  6.  *
  7.  *  SHELL SERVER.   THIS REQUIRES MY PIPE DEVICE TO WORK!!!!!!!!!!
  8.  *
  9.  *  Port #8196
  10.  *
  11.  *  Only one connection accepted at a time in this baby.
  12.  *  HUGE CLUDGE!!!
  13.  *
  14.  *  DNET_LEVEL must be 9 or higher.
  15.  */
  16.  
  17. #include "defs.h"
  18.  
  19. char Buf[4096];
  20.  
  21. int
  22. brk()
  23. {
  24.     return(0);
  25. }
  26.  
  27. void
  28. #ifdef LATTICE
  29. _main(str)
  30. #else
  31. _main(len,str)
  32. #endif
  33. char *str;
  34. {
  35.     struct MsgPort *port;
  36.     PROC    *proc = (PROC *)FindTask(NULL);
  37.     void    *chan;
  38.     long    mask, rmask;
  39.     long    namei = (long)proc;
  40.     APTR    oldwptr;
  41.     /*short   mycis = 0, mycos = 0;*/
  42.  
  43.     onbreak(brk);
  44.  
  45.     if (strncmp(str, "__dnet", 6) != 0) {
  46.     Version("SCli", VERSION, SCLI_VERSION);
  47.     _exit(0);
  48.     }
  49.  
  50.     port = DListen(PORT_AMIGASHELL);
  51.     WaitPort(&proc->pr_MsgPort);
  52.     ReplyMsg(GetMsg(&proc->pr_MsgPort));
  53.     if (!port)
  54.     _exit(1);
  55.     mask = SIGBREAKF_CTRL_C|(1 << port->mp_SigBit);
  56.     oldwptr = proc->pr_WindowPtr;
  57.     proc->pr_WindowPtr = (APTR)-1;
  58.  
  59.     /* REMOVED
  60.     proc->pr_ConsoleTask = DeviceProc("dpipe:");
  61.     if (!proc->pr_CIS) {
  62.     mycis = 1;
  63.     proc->pr_CIS = Open("nil:", 1006);
  64.     }
  65.     if (!proc->pr_COS) {
  66.     mycos = 1;
  67.     proc->pr_COS = Open("nil:", 1006);
  68.     }
  69.     */
  70.     for (;;) {
  71.     rmask = Wait(mask);
  72.     if (rmask & SIGBREAKF_CTRL_C)
  73.         break;
  74.     if (chan = DAccept(port)) {
  75.         long fh;
  76.         long mask;
  77.         long fhmask, smask;
  78.         short sig;
  79.         char pname[16];
  80.         char buf[64];
  81.  
  82.         if (GetEnvVal(DNET_LEVEL) < 9) {
  83.         DWrite(chan, "env:DNET_LEVEL must be >= 9\n", 18);
  84.         DClose(chan);
  85.         continue;
  86.         }
  87.  
  88.         sprintf(pname, "%08lx", namei++);
  89.         sprintf(buf, "newshell <nil: >nil: dpipe:%s/St FROM s:remote-startup", pname);
  90.         DExec(chan, buf);
  91.         sig = AllocSignal(-1);
  92.         fhmask = 1 << sig;
  93.         smask = 1 << ((struct MsgPort *)chan)->mp_SigBit;
  94.         sprintf(buf, "dpipe:%s/Mctns%ld", pname, sig);
  95.         fh = (long)Open(buf, 1006);
  96.         if (fh) {
  97.         char notdone = 1;
  98.         DWrite(chan, "Amiga CLI running\n", 20);
  99.         while (notdone) {
  100.             char buf[256];
  101.             int n;
  102.             mask = Wait(fhmask | smask | SIGBREAKF_CTRL_C);
  103.             while ((n = Read(fh, buf, 256)) > 0) {
  104.             DWrite(chan, buf, n);
  105.             }
  106.             if (n < 0)
  107.             notdone = 0;
  108.             while ((n = DNRead(chan, buf, 256)) > 0) {
  109.             /* REMOVED
  110.             DWrite(chan, buf, n);
  111.             */
  112.             Write(fh, buf, n);
  113.             }
  114.             if (n == -2) {
  115.             short pv;
  116.             char pa;
  117.             DGetIoctl(chan, &pv, &pa);
  118.             } else if (n < 0)
  119.             notdone = 0;
  120.         }
  121.         Write(fh, "ENDCLI\n", 7);
  122.         Write(fh, "ENDCLI\n", 7);
  123.         Close(fh);
  124.         }
  125.         DClose(chan);
  126.         FreeSignal(sig);
  127.         puts("DONE");
  128.     }
  129.     }
  130.     proc->pr_WindowPtr = oldwptr;
  131.  
  132.     /* REMOVED
  133.     if (mycos) {
  134.     Close(proc->pr_COS);
  135.     proc->pr_COS = NULL;
  136.     }
  137.     if (mycis) {
  138.     Close(proc->pr_CIS);
  139.     proc->pr_CIS = NULL;
  140.     }
  141.     */
  142.     DUnListen(port);
  143. }
  144.  
  145.  
  146.  
  147.