home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / internet / tcpip / src205 / TCPIP_Src / Main / c / Terminal < prev    next >
Encoding:
Text File  |  1995-03-01  |  3.6 KB  |  183 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "bbc.h"
  6. #include "global.h"
  7. #include "menu.h"
  8. #include "os.h"
  9. #include "misc.h"
  10. #include "session.h"
  11. #include "sprite.h"
  12. #include "wimp.h"
  13. #include "wimpt.h"
  14. #include "win.h"
  15. #include "dbox.h"
  16. #include "template.h"
  17. #include "cmdparse.h"
  18. #include "Terminal.h"
  19.  
  20. #include "xferrecv.h"
  21. #include "akbd.h"
  22. #include "werr.h"
  23.  
  24. extern Terminal *MWin;
  25. static int input_handler(void *handle, char *buf, int len);
  26. static int closedown(Terminal *Window);
  27.  
  28.  
  29. void Update_Window(Terminal *Window, wimp_redrawstr r)
  30. {
  31. }
  32.  
  33. void Window_Reset(Terminal *Window)
  34. {
  35. }
  36.  
  37. void Window_Write(Terminal *Window, char *s, int n)
  38. {
  39.   if (Window == NULL)
  40.     Window = MWin;
  41.   if (Window == NULL)
  42.     return;
  43.  
  44.   vterm_write(Window->vt, -1, s, n);
  45. }
  46.  
  47. /* Called from seesion upcall handlers to say
  48.    all is finished */
  49. void Window_CloseDown(Terminal *Window)
  50. {
  51.   if (Window->Flags.flags.closing)
  52.     Window_Close(Window);
  53.   else
  54.   {
  55.     /* Prevent further input from user */
  56.     vterm_setflags(Window->vt, VTSW_VIEW, VTSW_VIEW);
  57.     /* display closedown message */
  58.     vterm_printf(Window->vt,ATTRIB_REVERSE | ATTRIB_BOLD,
  59.                  "\r\n This session has closed, please close the window \r\n");
  60.     Window->Flags.flags.closed = TRUE;
  61.   }
  62. }
  63.  
  64. /* This should now be closed once everything
  65.    related to it hash been shutdown as well */
  66. void Window_Close(Terminal *Window)
  67. {
  68.   vterm_destroy(Window->vt);
  69.   free(Window);
  70. }
  71.  
  72. /* Called when user requests that session be closed
  73.  */
  74. static int closedown(Terminal *Window)
  75. {
  76.   if (Window->Session != NULL)
  77.   {
  78.     close_sess(Window->Session);
  79.     Window->Session = NULL;
  80.     Window->Flags.flags.closing = TRUE;
  81.   }
  82.   if (Window->Flags.flags.closed)
  83.   {
  84.     vterm_destroy(Window->vt);
  85.     free(Window);
  86.     return 0;
  87.   }
  88.   return 1;
  89. }
  90.  
  91. Terminal *Window_Open(struct session *Sess, char *Description, unsigned int Flags)
  92. {
  93.   int flags;
  94.   Terminal *Window;
  95. /*
  96.   for when command parser is replaced
  97.  
  98.   int i;
  99.   char *s1[1024];
  100.   char *s2[32];
  101.  
  102.   var vp;
  103.   extern varlist global_vars;
  104. */
  105.   if (term_type != -1)
  106.     return(NULL);
  107.  
  108.   if ((Window = (Terminal *) malloc(sizeof(Terminal))) == NULL)
  109.     return(NULL);
  110.  
  111.   memset(Window, 0, sizeof(Terminal));
  112.  
  113.   Window->Flags.value = Flags;
  114.  
  115.   Window_Reset(Window);
  116.  
  117.   Window->Session  = Sess;
  118.  
  119.   if (Window->Flags.flags.no_input)
  120.     flags = VTSW_VIEW|VTSW_NEWLINE;
  121.   else
  122.     flags = VTSW_LINE|VTSW_ECHO|VTSW_NEWLINE|VTSW_CMDW|VTSW_CURSOR;
  123.  
  124.   if (MWin!=NULL)
  125.   {
  126.     if ((flags & VTSW_CMDW) && (MWin->vt->switches & VTSW_CMDWB))
  127.       flags |= VTSW_CMDWB;
  128.   }
  129.  
  130.   if (Sess)
  131.     Window->Session->keypad = 0; /* ??? left over from old code */
  132.   else
  133.     Window->keypad = 0; /* ??? left over from old code */
  134.  
  135.   Window->vt = vterm_create(flags);
  136.  
  137.   if (Window->Flags.flags.dont_open)
  138.     vterm_close(Window->vt);
  139.  
  140.   vterm_title(Window->vt, Description);
  141.  
  142. /*
  143.   for when command parser is replaced
  144.   do I can set default vars for each win type
  145.   UGH - I hate this parser!
  146.  
  147.   for (i = 0; Description[i]>=' '; i++)
  148.     s2[i] = tolower(Description[i]);
  149.   s2[i] = '\0';
  150.   strcat(s2, "_termopts");
  151.  
  152. */
  153.  
  154.   vterm_register_handler(Window->vt, input_handler, Window);
  155.  
  156.   return(Window);
  157. }
  158.  
  159. extern struct cmds cmds[];
  160.  
  161. static int input_handler(void *handle, char *buf, int len)
  162. {
  163.   Terminal *Window = (Terminal *)handle;
  164.  
  165.   if (buf==NULL && len==-1)
  166.   {
  167.     return closedown(Window);
  168.   }
  169.   else
  170.   {
  171.     if (Window->Session && Window->Session->parse)
  172.     {
  173.       (*Window->Session->parse)(Window->Session, buf, len);
  174.     }
  175.     else if (Window->Session == NULL)
  176.     {
  177.       cmdparse(cmds, buf, (void *) Window);
  178.       Window_Write(Window, "net> ", 5);
  179.     }
  180.   }
  181.   return 1;
  182. }
  183.