home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
internet
/
tcpipsrc
/
h
/
if
/
Main
/
c
/
Terminal
< prev
next >
Wrap
Text File
|
1995-01-15
|
4KB
|
178 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bbc.h"
#include "global.h"
#include "menu.h"
#include "os.h"
#include "misc.h"
#include "session.h"
#include "sprite.h"
#include "wimp.h"
#include "wimpt.h"
#include "win.h"
#include "dbox.h"
#include "template.h"
#include "cmdparse.h"
#include "Terminal.h"
#include "xferrecv.h"
#include "akbd.h"
#include "werr.h"
extern Terminal *MWin;
static int input_handler(void *handle, char *buf, int len);
static void closedown(Terminal *Window);
void Update_Window(Terminal *Window, wimp_redrawstr r)
{
}
void Window_Reset(Terminal *Window)
{
}
void Window_Write(Terminal *Window, char *s, int n)
{
if (Window == NULL)
Window = MWin;
if (Window == NULL)
return;
vterm_write(Window->vt, -1, s, n);
}
/* Called from seesion upcall handlers to say
all is finished */
void Window_CloseDown(Terminal *Window)
{
if (Window->Flags.flags.closing)
Window_Close(Window);
else
{
/* Prevent further input from user */
vterm_setflags(Window->vt, VTSW_VIEW, VTSW_VIEW);
/* display closedown message */
vterm_printf(Window->vt,ATTRIB_REVERSE | ATTRIB_BOLD,
"\r\n This session has closed, please close the window \r\n");
Window->Flags.flags.closed = TRUE;
}
}
/* This should now be closed once everything
related to it hash been shutdown as well */
void Window_Close(Terminal *Window)
{
vterm_destroy(Window->vt);
free(Window);
}
/* Called when user requests that session be closed
*/
static void closedown(Terminal *Window)
{
if (Window->Session != NULL)
{
close_sess(Window->Session);
Window->Session = NULL;
Window->Flags.flags.closing = TRUE;
}
if (Window->Flags.flags.closed)
{
vterm_destroy(Window->vt);
free(Window);
}
}
Terminal *Window_Open(struct session *Sess, char *Description, unsigned int Flags)
{
int flags;
Terminal *Window;
/*
for when command parser is replaced
int i;
char *s1[1024];
char *s2[32];
var vp;
extern varlist global_vars;
*/
if (term_type != -1)
return(NULL);
if ((Window = (Terminal *) malloc(sizeof(Terminal))) == NULL)
return(NULL);
memset(Window, 0, sizeof(Terminal));
Window->Flags.value = Flags;
Window_Reset(Window);
Window->Session = Sess;
if (Window->Flags.flags.no_input)
flags = VTSW_VIEW|VTSW_NEWLINE;
else
flags = VTSW_LINE|VTSW_ECHO|VTSW_NEWLINE|VTSW_CMDW|VTSW_CURSOR;
if (Sess)
Window->Session->keypad = 0; /* ??? left over from old code */
else
Window->keypad = 0; /* ??? left over from old code */
Window->vt = vterm_create(flags);
if (Window->Flags.flags.dont_open)
vterm_close(Window->vt);
vterm_title(Window->vt, Description);
/*
for when command parser is replaced
do I can set default vars for each win type
UGH - I hate this parser!
for (i = 0; Description[i]>=' '; i++)
s2[i] = tolower(Description[i]);
s2[i] = '\0';
strcat(s2, "_termopts");
*/
vterm_register_handler(Window->vt, input_handler, Window);
return(Window);
}
extern struct cmds cmds[];
static int input_handler(void *handle, char *buf, int len)
{
char copybuf[VT_ICONBUF_SIZE];
Terminal *Window = (Terminal *)handle;
if (buf==NULL && len==-1)
{
closedown(Window);
}
else
{
memcpy(copybuf, buf, len);
if (Window->Session && Window->Session->parse)
{
(*Window->Session->parse)(Window->Session, copybuf, len);
}
else if (Window->Session == NULL)
{
cmdparse(cmds, copybuf, (void *) Window);
Window_Write(Window, "net> ", 5);
}
}
return 1;
}