home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / system / unixwind.zoo / uw.1of1 < prev    next >
Encoding:
Text File  |  1988-06-23  |  11.2 KB  |  404 lines

  1. #!/bin/sh
  2. # shar:    Shell Archiver
  3. #    Run the following text with /bin/sh to create:
  4. #    README
  5. #    amterm
  6. #    terminal.c
  7. #    terminal.diff
  8. # This archive created: Mon Jan 25 09:25:07 1988
  9. # By:    Patrick White (PUCC Land, USA)
  10. echo shar: extracting README '(1376 characters)'
  11. cat << \SHAR_EOF > README
  12. Enclosed here are the following files:
  13.    <amterm> contains a termcap entry for the UW program's default window size.
  14.       If you resize the window it won't work!
  15.    <terminal.diff> contains the differences to 'terminal.c' to fix a bug
  16.    <terminal.c> is the new version of the file
  17.    <uw.uue> is an executable with the fix
  18.  
  19. To use 'amterm', put it in a file in your home directory. After you log in,
  20. type:
  21. . amterm
  22.  
  23. THEN run the uw-server on UNIX and carry on from there. [HOWEVER, comma, that
  24. worked just now with our current version of ULTRIX. When I was messing with
  25. this last summer, I had to run it with each window after it had been opened,
  26. when we were using a previous version of ULTRIX. Give it a try and check to
  27. see if it got exported and inherited correctly before you believe anything.]
  28.  
  29. The original released version of UW has a bug in handling received linefeeds.
  30. On the screen, they show up as newlines, but certain programs which use CURSES
  31. try to use a linefeed to move the cursor straight down. As a result, the
  32. unmodified UW couldn't be used with VI or anything else that was screen
  33. oriented.
  34.  
  35. This change fixes that, but unfortunately I don't remember precisely how,
  36. since I fixed it about 5 months ago. I seem to remember something about
  37. sending a special character sequence to the terminal handler to make a
  38. line-feed no longer treated as a newline.
  39. SHAR_EOF
  40. if test 1376 -ne "`wc -c README`"
  41. then
  42. echo shar: error transmitting README '(should have been 1376 characters)'
  43. fi
  44. echo shar: extracting amterm '(501 characters)'
  45. cat << \SHAR_EOF > amterm
  46. TERMCAP="sz|amiga|amiga-ansi:\
  47.     :ae=\017:as=\016:bw:mi:ms:sf=\E[S:sr=\E[T:te=\E[S\E23;H:vb=\007:\
  48.     :cr=^M:do=\ED:nl=^J:bl=^G:co#77:li#23:cl=\014:\
  49.     :le=^H:bs:am:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:\
  50.     :ce=\E[K:cd=\E[J:so=\E[3;7m:se=\E[m:us=\E[4m:ue=\E[m:\
  51.     :md=\E[1m:mr=\E[7m:mb=\E[2m:me=\E[m:is=\E[23t\E[79u\E[23;H:\
  52.     :ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:kh=\E?~\
  53.     :ho=\E[H:k1=\E0~:k2=\E1~:k3=\E2~:k4=\E3~:ta=^I:pt:sr=\EM:\
  54.     :al=\E[L:dl=\E[M:dc=\E[P:ic=\E[@:im=:ei=:ed=:xn:"
  55. TERM="amiga"
  56. export TERM TERMCAP
  57. SHAR_EOF
  58. if test 501 -ne "`wc -c amterm`"
  59. then
  60. echo shar: error transmitting amterm '(should have been 501 characters)'
  61. fi
  62. echo shar: extracting terminal.c '(8109 characters)'
  63. cat << \SHAR_EOF > terminal.c
  64.  
  65. /*  Unix Windows Client for the Amiga (ANSI Terminal Emulation only)
  66.  
  67.     ) 1987 by  Michael J. McInerny   12-May-87 version 1.00
  68.  
  69. */
  70.  
  71. #define INTUITION_MESSAGE(x) (1<<uw[x].winsig)
  72. #define TYPED_CHARACTER(x) (1<<uw[x].consig)
  73. #define INPUT_CHARACTER (1<<serReadBit)
  74.  
  75. #define CloseConsole(x) CloseDevice(x)
  76.  
  77. #include "term.h"
  78. #include "devices/serial.h"
  79.  
  80. /* GLOBALS ****************************************************** */
  81. extern long IntuitionBase;
  82. extern long GfxBase;
  83.  
  84. extern UWwrite();
  85.  
  86. struct uw_struct uw[8];
  87. int uw_read, uw_write, uw_count = 0;
  88.  
  89. extern struct Window *NewTermWin();
  90. extern struct Menu *MenuHead;
  91.  
  92. int waitmask;    /* what are we waiting for? */
  93. struct MsgPort *serReadPort = NULL;
  94. struct MsgPort *serWritePort = NULL;
  95. struct IOExtSer *SerReadReq = NULL;
  96. struct IOExtSer *SerWriteReq = NULL;
  97.  
  98. char letter[8];            /* one letter at a time from console */
  99. char serin;             /* one letter at a time from serial  */
  100. char serbuf[4096]; /* as much as we can get! */
  101. int sercount;    /* how many to get */
  102. int FullDuplex = TRUE;  /* flag for local echo  */
  103.  
  104. static   char reset_mode[] = {0x9B, 0x32, 0x30, 0x6C};
  105.  
  106. AllocTerm(slot)
  107. int slot;
  108. {
  109.    char *s = "xxuw.con";
  110.  
  111.    uw_count += 1;
  112.    uw[slot].free = FALSE;
  113.    uw[slot].win = NewTermWin();
  114.    SetMenuStrip(uw[slot].win, MenuHead);
  115.    *s = (char)slot + 'a';
  116.    *(s+1) = 'w';
  117.    uw[slot].ConWritePort = CreatePort(s,0);
  118.     if(uw[slot].ConWritePort == 0) Cleanup();
  119.    uw[slot].ConWriteReq = CreateStdIO(uw[slot].ConWritePort);
  120.     if(uw[slot].ConWriteReq == 0) Cleanup();
  121.    *(s+1) = 'r';
  122.    uw[slot].ConReadPort = CreatePort(s,0);
  123.     if(uw[slot].ConReadPort == 0) Cleanup();
  124.    uw[slot].ConReadReq =  CreateStdIO(uw[slot].ConReadPort);
  125.     if(uw[slot].ConReadReq == 0) Cleanup();
  126.    if((OpenConsole(uw[slot].ConWriteReq,
  127.    uw[slot].ConReadReq,
  128.    uw[slot].win)) != 0)
  129.       Cleanup();
  130.    uw[slot].consig = uw[slot].ConReadReq->io_Message.mn_ReplyPort->mp_SigBit;
  131.    uw[slot].winsig = uw[slot].win->UserPort->mp_SigBit;
  132.    waitmask |= INTUITION_MESSAGE(slot) | TYPED_CHARACTER(slot) ;
  133.    QueueRead(uw[slot].ConReadReq, &letter[slot]);
  134.  
  135.    uw[slot].ConWriteReq->io_Command = CMD_WRITE;
  136.    uw[slot].ConWriteReq->io_Length = sizeof(reset_mode);
  137.    uw[slot].ConWriteReq->io_Data = (APTR)(reset_mode);
  138.  
  139.    if(DoIO(uw[slot].ConWriteReq) != 0) {
  140.       Notify(uw[uw_write].win, "Console write error.");
  141.    }
  142. } /* end of AllocTerm */
  143.  
  144. ZeroTerm(slot)
  145. int slot;
  146. {
  147.  uw[slot].free = TRUE;
  148.  uw[slot].ConReadPort = NULL;
  149.  uw[slot].ConWritePort = NULL;
  150.  uw[slot].ConReadReq = NULL;
  151.  uw[slot].ConWriteReq = NULL;
  152.  uw[slot].win = NULL;
  153.  uw[slot].winsig = 0;
  154.  uw[slot].consig = 0;
  155. } /* end of ZeroTerm */
  156.  
  157. DeallocTerm(slot)
  158. int slot;
  159. {
  160.    waitmask &= ~(INTUITION_MESSAGE(slot) | TYPED_CHARACTER(slot)) ;
  161.    if (uw[slot].free == FALSE) {
  162.  AbortIO(uw[slot].ConReadReq);  /* cancel the last queued read */
  163.  uw_count -= 1;
  164.  if (uw[slot].ConWriteReq) CloseConsole(uw[slot].ConWriteReq);
  165.  if (uw[slot].ConReadReq) DeleteStdIO(uw[slot].ConReadReq);
  166.  if (uw[slot].ConReadPort) DeletePort(uw[slot].ConReadPort);
  167.  if (uw[slot].ConWriteReq) DeleteStdIO(uw[slot].ConWriteReq);
  168.  if (uw[slot].ConWritePort) DeletePort(uw[slot].ConWritePort);
  169.  if (uw[slot].win) {
  170.     ClearMenuStrip(uw[slot].win);
  171.     CloseWindow(uw[slot].win);
  172.  }
  173.  ZeroTerm(slot);
  174.    } /* end if uw.free */
  175. } /* end of DeallocTerm */
  176.  
  177. InitSerReqs()
  178. {
  179.    serReadPort = CreatePort("uw.ser.read",0);
  180.    if (serReadPort == NULL) Cleanup();
  181.    SerReadReq = (struct IOExtSer *)CreateExtIO(serReadPort,
  182.                                                sizeof(struct IOExtSer));
  183.    if (SerReadReq == NULL) Cleanup();
  184.    serWritePort = CreatePort("uw.ser.write",0);
  185.    if (serWritePort == NULL) Cleanup();
  186.    SerWriteReq = (struct IOExtSer *)CreateExtIO(serWritePort,
  187.                                                sizeof(struct IOExtSer));
  188.    if (SerWriteReq == NULL) Cleanup();
  189.    if ((OpenSerial(SerReadReq, SerWriteReq)) != 0) Cleanup();
  190.    if ((SetParams( SerReadReq, 4096, 0x07, 0x07, 750000,
  191.                            9600, 0x00, 
  192.       0x51040303, 0x03030303)) != 0)
  193.       Cleanup();
  194. }
  195.  
  196. main()
  197. {
  198.    USHORT class, code, qualifier;
  199.    int problem, i, serReadBit;
  200.    struct IntuiMessage *message; /* the message the IDCMP sends us */
  201.  
  202.    IntuitionBase = 0L;
  203.    GfxBase = 0L;
  204.    MenuHead = NULL;
  205.  
  206.    for(i = 0; i < 8; ++i) ZeroTerm(i);
  207.  
  208.    InitLibs();
  209.    InitSerReqs();
  210.    serReadBit = SerReadReq->IOSer.io_Message.mn_ReplyPort->mp_SigBit;
  211.    waitmask = INPUT_CHARACTER;
  212.  
  213.    if (!InitMenus()) Cleanup();
  214.  
  215.    AllocTerm(1);
  216.    uw_read = 1;
  217.    uw_write = 1;
  218.  
  219.    sercount = 1;
  220.    ReadSer(serbuf, sercount);
  221.  
  222. /*   UWExit(); */
  223.  
  224.    problem = TRUE;
  225.    do {
  226.  Wait(waitmask);
  227.  if(CheckIO(SerReadReq))
  228.  {
  229.   WaitIO(SerReadReq);
  230.   UWwrite(serbuf, sercount);
  231.   sercount = QuerySer(SerReadReq);
  232.   if (sercount < 1) sercount = 1;
  233.   ReadSer(serbuf, sercount);
  234.  } /* end if(CheckIO(SerRead)) */
  235.       for (i = 0; i < 8; ++i) {
  236.  if (!uw[i].free) {
  237.   while((!uw[i].free) &&
  238.    ((message = (struct IntuiMessage *)
  239.     GetMsg(uw[i].win->UserPort) ) != NULL)) {
  240.     class     = message->Class;
  241.     code      = message->Code;
  242.     qualifier = message->Qualifier;
  243.     ReplyMsg(message);
  244.     problem &= HandleEvent(i,class,code,qualifier);
  245. /*    if(problem == FALSE) break; */
  246.    } /* end while(mess... */
  247.  
  248.   if((!uw[i].free) && CheckIO(uw[i].ConReadReq))
  249.   {
  250.    WaitIO(uw[i].ConReadReq);
  251.    if (uw_read != i) SelInput(i);
  252.  /* is this is current input window?  if not, send note off ... */
  253.    UWWriteChar(letter[i]);
  254. /*   SerPutChar(SerWriteReq, letter[i]); */
  255.    if (!FullDuplex)
  256.     ConPutChar(uw[uw_write].ConWriteReq, letter[i]);
  257.    QueueRead(uw[i].ConReadReq, &letter[i]);
  258.   } /* end if(CheckIO(ConRead)) */
  259.  } /* end if(!uw[i].free) */
  260.       } /* end for i */
  261.    } while (problem); /* keep going as long as HandleEvent returns nonzero */
  262.  
  263.    AbortIO(SerReadReq);
  264.    Cleanup();
  265. }
  266.  
  267. Cleanup()
  268. {
  269.    int i;
  270.  
  271.    for (i = 0; i < 8; ++i)
  272.  if (!uw[i].free) DeallocTerm(i);
  273.    if (SerReadReq) CloseDevice(SerReadReq);
  274.    if (SerWriteReq) DeleteExtIO(SerWriteReq,sizeof(struct IOExtSer));
  275.    if (serWritePort) DeletePort(serWritePort);
  276.    if (SerReadReq) DeleteExtIO(SerReadReq,sizeof(struct IOExtSer));
  277.    if (serReadPort) DeletePort(serReadPort);
  278.    if (MenuHead) DisposeMenus(MenuHead);
  279.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  280.    if (GfxBase) CloseLibrary(GfxBase);
  281.    exit(0);
  282. } /* end of Cleanup */
  283.  
  284. HandleEvent(term,class,code,qualifier)
  285. int term;
  286. USHORT class;
  287. USHORT code;
  288. USHORT qualifier;
  289. {
  290.       switch( class ) {
  291.   case CLOSEWINDOW:
  292.      return(CloseWin(term));
  293.      break;
  294.          case MENUPICK:
  295.             return(MenuSwitch(code));
  296.             break;
  297.       } /* end of switch( class ) */
  298.       return(TRUE);
  299. } /* end of HandleEvent */
  300.  
  301. /*      R e a d S e r
  302.  *
  303.  *      Read characters from the serial.device
  304.  *
  305.  */
  306.  
  307. ReadSer(data,length)
  308. char *data;
  309. int length;
  310. {
  311.   SerReadReq->IOSer.io_Command = CMD_READ;
  312.   SerReadReq->IOSer.io_Length = length;
  313.   SerReadReq->IOSer.io_Data = (APTR)(data);
  314.  
  315.    BeginIO(SerReadReq);
  316. }
  317.  
  318. /*      W r i t e S e r
  319.  *
  320.  *      Write characters to the serial.device
  321.  *
  322.  */
  323.  
  324. WriteSer(data,length)
  325. char *data;
  326. int length;
  327. {
  328. /*  int i; */
  329.  
  330.   SerWriteReq->IOSer.io_Command = CMD_WRITE;
  331.   SerWriteReq->IOSer.io_Length = length;
  332. /*  SerWriteReq->IOSer.io_Length = 1; 
  333.   for(i = 0; i < length; ++i) {
  334.  SerWriteReq->IOSer.io_Data = (APTR)(data + i);
  335.  DoIO(SerWriteReq);
  336.   }
  337. */
  338.   SerWriteReq->IOSer.io_Data = (APTR)(data);
  339.  
  340.   if(DoIO(SerWriteReq) != 0)
  341.   {
  342.       Notify(uw[uw_write].win, "Serial write error.");
  343.   }
  344. }
  345.  
  346. extern int uwflag;
  347. sputc(c)
  348. char c;
  349. {
  350. /* printf(">0%o ",c); */
  351.  if (uwflag) Delay(1); /* Why is this necessary????? */
  352.  SerPutChar(SerWriteReq, c);
  353. }
  354.  
  355. /*      W r i t e C o n
  356.  *
  357.  *      Write characters to the console.device
  358.  *
  359.  */
  360.  
  361. WriteCon(data,length)
  362. char *data;
  363. int length;
  364. {
  365.   uw[uw_write].ConWriteReq->io_Command = CMD_WRITE;
  366.   uw[uw_write].ConWriteReq->io_Length = length;
  367.   uw[uw_write].ConWriteReq->io_Data = (APTR)(data);
  368.  
  369. if(!uw[uw_write].free)
  370.   if(DoIO(uw[uw_write].ConWriteReq) != 0)
  371.   {
  372.       Notify(uw[uw_write].win, "Console write error.");
  373.   }
  374. }
  375.  
  376. SHAR_EOF
  377. if test 8109 -ne "`wc -c terminal.c`"
  378. then
  379. echo shar: error transmitting terminal.c '(should have been 8109 characters)'
  380. fi
  381. echo shar: extracting terminal.diff '(359 characters)'
  382. cat << \SHAR_EOF > terminal.diff
  383. 40a41,42
  384. > static   char reset_mode[] = {0x9B, 0x32, 0x30, 0x6C};
  385. 68a71,78
  386. >    uw[slot].ConWriteReq->io_Command = CMD_WRITE;
  387. >    uw[slot].ConWriteReq->io_Length = sizeof(reset_mode);
  388. >    uw[slot].ConWriteReq->io_Data = (APTR)(reset_mode);
  389. >    if(DoIO(uw[slot].ConWriteReq) != 0) {
  390. >       Notify(uw[uw_write].win, "Console write error.");
  391. >    }
  392. SHAR_EOF
  393. if test 359 -ne "`wc -c terminal.diff`"
  394. then
  395. echo shar: error transmitting terminal.diff '(should have been 359 characters)'
  396. fi
  397. #    End of shell archive
  398. exit 0
  399.  
  400.  
  401.