home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / tcpipsrc / h / if / Main / c / Terminal < prev    next >
Text File  |  1995-01-15  |  4KB  |  178 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 void 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 void 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.   }
  87. }
  88.  
  89. Terminal *Window_Open(struct session *Sess, char *Description, unsigned int Flags)
  90. {
  91.   int flags;
  92.   Terminal *Window;
  93. /*
  94.   for when command parser is replaced
  95.  
  96.   int i;
  97.   char *s1[1024];
  98.   char *s2[32];
  99.  
  100.   var vp;
  101.   extern varlist global_vars;
  102. */
  103.   if (term_type != -1)
  104.     return(NULL);
  105.  
  106.   if ((Window = (Terminal *) malloc(sizeof(Terminal))) == NULL)
  107.     return(NULL);
  108.  
  109.   memset(Window, 0, sizeof(Terminal));
  110.  
  111.   Window->Flags.value = Flags;
  112.  
  113.   Window_Reset(Window);
  114.  
  115.   Window->Session  = Sess;
  116.  
  117.   if (Window->Flags.flags.no_input)
  118.     flags = VTSW_VIEW|VTSW_NEWLINE;
  119.   else
  120.     flags = VTSW_LINE|VTSW_ECHO|VTSW_NEWLINE|VTSW_CMDW|VTSW_CURSOR;
  121.  
  122.   if (Sess)
  123.     Window->Session->keypad = 0; /* ??? left over from old code */
  124.   else
  125.     Window->keypad = 0; /* ??? left over from old code */
  126.  
  127.   Window->vt = vterm_create(flags);
  128.  
  129.   if (Window->Flags.flags.dont_open)
  130.     vterm_close(Window->vt);
  131.  
  132.   vterm_title(Window->vt, Description);
  133.  
  134. /*
  135.   for when command parser is replaced
  136.   do I can set default vars for each win type
  137.   UGH - I hate this parser!
  138.  
  139.   for (i = 0; Description[i]>=' '; i++)
  140.     s2[i] = tolower(Description[i]);
  141.   s2[i] = '\0';
  142.   strcat(s2, "_termopts");
  143.  
  144. */
  145.  
  146.   vterm_register_handler(Window->vt, input_handler, Window);
  147.  
  148.   return(Window);
  149. }
  150.  
  151. extern struct cmds cmds[];
  152.  
  153. static int input_handler(void *handle, char *buf, int len)
  154. {
  155.   char copybuf[VT_ICONBUF_SIZE];
  156.   Terminal *Window = (Terminal *)handle;
  157.  
  158.   if (buf==NULL && len==-1)
  159.   {
  160.     closedown(Window);
  161.   }
  162.   else
  163.   {
  164.     memcpy(copybuf, buf, len);
  165.  
  166.     if (Window->Session && Window->Session->parse)
  167.     {
  168.       (*Window->Session->parse)(Window->Session, copybuf, len);
  169.     }
  170.     else if (Window->Session == NULL)
  171.     {
  172.       cmdparse(cmds, copybuf, (void *) Window);
  173.       Window_Write(Window, "net> ", 5);
  174.     }
  175.   }
  176.   return 1;
  177. }
  178.