home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 340.lha / ftek / ftek.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-26  |  6.6 KB  |  314 lines

  1.  
  2. /*
  3.  *  FTEK.C
  4.  *
  5.  *  DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
  6.  *
  7.  *  FTEK [-Nnet] [port]
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <typedefs.h>
  12. #include "/dnet/channel.h"
  13.  
  14. #include "/server/servers.h"
  15. #include "tek.h"
  16.  
  17. /* from tek */
  18. extern struct Window *TekWindow;
  19. extern struct Screen *TekScreen;
  20.  
  21. TA Ta = { (ubyte *)"topaz", 8 };
  22.  
  23. ITEXT IText[] = {
  24.     { 0, 1, JAM2, 0, 0, &Ta, (ubyte *)"Flush"          },
  25.     { 0, 1, JAM2, 0, 0, &Ta, (ubyte *)"Quit"          }
  26. };
  27.  
  28. ITEM Item[] = {
  29.     { &Item[1], 0, 0, 80, 10, ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP, 0, (APTR)&IText[0], NULL, 'o' },
  30.     { NULL,    0,10, 80, 10, ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP, 0, (APTR)&IText[1], NULL, 'q' }
  31. };
  32.  
  33. MENU Menu[] = {
  34.     { NULL, 0, 0, 80, 20, MENUENABLED, "Control", &Item[0] }
  35. };
  36.  
  37.  
  38. NW Nw = {
  39.     0, 0, 640, 200, -1, -1,
  40.     NEWSIZE|CLOSEWINDOW|MENUPICK,
  41.     WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|NOCAREREFRESH|ACTIVATE,
  42.     NULL, NULL, (UBYTE *)"FTEK  Openning, Wait", NULL, NULL,
  43.     32, 32, -1, -1, WBENCHSCREEN
  44. };
  45.  
  46. WIN *Win;
  47.  
  48. int Enable_Abort;
  49. int NotDone = 1;
  50. char Buf[512];
  51. char Term[64] = { "FTEK (UNNAMED SHELL)" };
  52. char Cc;
  53.  
  54. extern void *OpenWindow();
  55. extern void *GetMsg();
  56. extern void *CreatePort();
  57.  
  58. struct IntuitionBase *IntuitionBase;
  59. struct GfxBase *GfxBase;
  60. long chan;
  61.  
  62. main(ac,av)
  63. char *av[];
  64. {
  65.     long n;
  66.     long imask, conmask, dmask, mask;
  67.     IOCON *iocr, *iocw;
  68.     char portspec = 0;
  69.     char *host = NULL;
  70.     uword port = PORT_IALPHATERM;
  71.  
  72.     {
  73.     register short i;
  74.     for (i = 1; i < ac; ++i) {
  75.         if (strncmp(av[i], "-N", 2) == 0) {
  76.         host = av[i] + 2;
  77.         continue;
  78.         }
  79.         portspec = 1;
  80.         port = atoi(av[i]);
  81.     }
  82.     }
  83.     if (portspec)
  84.     printf("Using port %ld\n", port);
  85.     Enable_Abort = 0;
  86.     IntuitionBase = OpenLibrary("intuition.library", 0);
  87.     GfxBase = OpenLibrary("graphics.library", 0);
  88.     Win = OpenWindow(&Nw);
  89.     if (Win == NULL)
  90.     goto e1;
  91.     OpenConsole(Win, &iocr, &iocw);
  92.     if (iocr == NULL || iocw == NULL)
  93.     goto e3;
  94.  
  95.     /*
  96.      *    We delay here to allow DNET to go through its RESTART sequence
  97.      *    (when DNET automatically runs FTERM, it does so to quickly).
  98.      *    Such a hack!
  99.      */
  100.  
  101. /*    Delay(50 * 4);   */
  102.     chan = DOpen(host, port, 20, 15);
  103.  
  104.     if (!chan) {
  105.     puts("Unable to connect");
  106.     goto e3;
  107.     }
  108.     /* start tek part up */
  109.  
  110.     InitTekItems();
  111.     InitTekMenu();
  112.     InitTekDev(Win);
  113.  
  114.     DQueue(chan, 32);
  115.     SetMenuStrip(Win, Menu);
  116.     SetWindowTitles(Win, Term, -1);
  117.     imask   = 1 << Win->UserPort->mp_SigBit;
  118.     dmask   = 1 << ((PORT *)chan)->mp_SigBit;
  119.     conmask = 1 << iocr->io_Message.mn_ReplyPort->mp_SigBit;
  120.  
  121.     iocr->io_Data = (APTR)&Cc;
  122.     iocr->io_Length = 1;
  123.     SendIO(iocr);
  124.  
  125.     setsize(iocw, chan);
  126.     while (NotDone) {
  127.     mask = Wait(imask|dmask|conmask);
  128.     if (mask & imask) {
  129.         IMESS *im;
  130.         while (im = GetMsg(Win->UserPort)) {
  131.         switch(im->Class) {
  132.         case NEWSIZE:
  133.             setsize(iocw, chan);
  134.             break;
  135.         case CLOSEWINDOW:
  136.             NotDone = 0;
  137.             break;
  138.         case MENUPICK:
  139.             HandleMenu(im->Code);
  140.             break;
  141.         }
  142.         ReplyMsg(im);
  143.         }
  144.     }
  145.     if (mask & dmask) {
  146.         char buf[256];
  147.         int n, i;
  148.         if ((n = DNRead(chan, buf, 256)) > 0)
  149.         for(i = 0; i < n;i++)
  150.     /* check if tek wants the byte - if not just send it to window */
  151.             if(!Tek(buf[i])){
  152.             iocw->io_Data = (APTR)&buf[i];
  153.             iocw->io_Length = 1;
  154.             DoIO(iocw);
  155.             }
  156.         if (n < 0)
  157.         NotDone = 0;
  158.     }
  159.     if (mask & conmask)
  160.         if (CheckIO(iocr)) {
  161.         WaitIO(iocr);
  162.         DWrite(chan, &Cc, 1);
  163.         iocr->io_Data = (APTR)&Cc;
  164.         iocr->io_Length = 1;
  165.         SendIO(iocr);
  166.         }
  167.     }
  168.     AbortIO(iocr);
  169.     WaitIO(iocr);
  170.     SetWindowTitles(Win, "Closing...", -1);
  171.     DClose(chan);
  172.     CloseTek();     /* closes and releases all the tek stuff */
  173. e3: CloseConsole(iocr,iocw);
  174.     CloseWindow(Win);
  175. e1: CloseLibrary(IntuitionBase);
  176.     CloseLibrary(GfxBase);
  177. }
  178.  
  179. OpenConsole(win, piocr, piocw)
  180. IOCON **piocr, **piocw;
  181. WIN *win;
  182. {
  183.     PORT *port;
  184.     static IOCON iocr, iocw;
  185.     int error;
  186.  
  187.     port = CreatePort(NULL, 0);
  188.     iocr.io_Command = CMD_READ;
  189.     iocr.io_Data = (APTR)win;
  190.     iocr.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  191.     iocr.io_Message.mn_ReplyPort = port;
  192.     error = OpenDevice("console.device", 0, &iocr, 0);
  193.     if (!error) {
  194.     iocw = iocr;
  195.     iocw.io_Command = CMD_WRITE;
  196.     *piocr = &iocr;
  197.     *piocw = &iocw;
  198.     } else {
  199.     *piocr = *piocw = NULL;
  200.     }
  201. }
  202.  
  203. CloseConsole(iocr, iocw)
  204. IOCON *iocr;
  205. IOCON *iocw;
  206. {
  207.     IOCON *tmp = (iocr) ? iocr : iocw;
  208.     if (tmp) {
  209.     CloseDevice(tmp);
  210.     DeletePort(tmp->io_Message.mn_ReplyPort);
  211.     }
  212. }
  213.  
  214. setsize(iocw, chan)
  215. IOCON *iocw;
  216. long chan;
  217. {
  218.     struct ConUnit *cu = (struct ConUnit *)iocw->io_Unit;
  219. /*    iocw->io_Data = (APTR)"\033c\033[20l\033[t\033[u";    */
  220.  
  221.     iocw->io_Data = (APTR)"\033[20l\033[t\033[u";
  222.     iocw->io_Length = 11;
  223.     DoIO(iocw);
  224.     DIoctl(chan, CIO_SETROWS, cu->cu_YMax+1, 0);
  225.     DIoctl(chan, CIO_SETCOLS, cu->cu_XMax+1, 0);
  226.     sprintf(Term, "FTEK   %ld x %ld", cu->cu_YMax+1, cu->cu_XMax+1);
  227.     SetWindowTitles(Win, Term, -1);
  228. }
  229.  
  230. HandleMenu(code)
  231. uword code;
  232. {
  233.     switch(MENUNUM(code)){
  234.         case 0:    /*    menu 0    */
  235.         switch(ITEMNUM(code)){
  236.             case 0:    /* item 0 */
  237.             DIoctl(chan, CIO_FLUSH, 0, 0);
  238.             break;
  239.             case 1:    /* item 1 */
  240.             NotDone = 0; /* fall out of loop and quit */
  241.             break;
  242.         }
  243.         break;
  244.         case 1:    /*    menu 1    */
  245.         switch(ITEMNUM(code)){
  246.             case 0:    /* item 0 -> choose tek scale */
  247.             switch (SUBNUM(code)){
  248.                 case 0: /* choose 1020x780 resolution */
  249.                 t_scale = 0;
  250.                 break;
  251.                 case 1: /* choose 640x400 */
  252.                 t_scale = 1;
  253.                 break;
  254.             }
  255.             break;
  256.             case 1:    /* choose screen depth */
  257.             switch (SUBNUM(code)) {
  258.                 case 0:
  259.                 t_cmd_depth("1");
  260.                 break;
  261.                 case 1:
  262.                 t_cmd_depth("2");
  263.                 break;
  264.                 case 2:
  265.                 t_cmd_depth("3");
  266.                 break;
  267.                 case 3:
  268.                 t_cmd_depth("4");
  269.                 break;
  270.             }
  271.             break;
  272.             case 2:        /* choose interlace */
  273.             switch (SUBNUM(code)) {
  274.                 case 0:
  275.                 t_cmd_interlace("0");
  276.                 break;
  277.                 case 1:
  278.                 t_cmd_interlace("1");
  279.                 break;
  280.             }
  281.             break;
  282.         }
  283.         break;
  284.         case 2:    /* menu 2 */
  285.         switch(ITEMNUM(code)){
  286.             case 0:        /* tek screen on/off */
  287.             switch (SUBNUM(code)) {
  288.                 case 0:    /* tek screen off  */
  289.                 t_cmd_on("0");
  290.                 break;
  291.                 case 1:    /* tek screen on   */
  292.                 t_cmd_on("1");
  293.                 break;
  294.             }
  295.             break;
  296.             case 1:
  297.             ScreenToFront(TekScreen); /* force tek screen to front */
  298.             break;
  299.             case 2:
  300.             ScreenToBack(TekScreen);  /* force vt screen to front */
  301.             break;
  302.             case 3:        /* clear screen */
  303.             if(Tek_screen_open == 1)
  304.                 Tek(27);    /* put in escape mode */
  305.                 Tek(12);    /* clear page */
  306.             break;
  307.             case 4:        /* quit tekmode */
  308.             TekMode = FALSE;
  309.             break;
  310.         }
  311.         break;
  312.     } /* end of switch (MENUNUM(code ) */
  313. }
  314.