Article View: mod.amiga.sources
Article #35VT100 Terminal Emulator (V2.1 DBW 860915) Part 2 of 2
From: doc
Date: Tue, 23 Sep 1986 14:58
Date: Tue, 23 Sep 1986 14:58
2554 lines
73776 bytes
73776 bytes
Reply-To: wecker%cookie.DEC@decwrl.DEC.COM (DAVE TANSTAAFL WECKER)
# This is a shell archive.
# Remove everything above and including the cut line.
# Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# expand.c
# init.c
# remote.c
# script.c
# window.c
# xmodem.c
# This archive created: Sun Sep 14 22:42:46 1986
echo shar: extracting expand.c
sed 's/^XX//' << \SHAR_EOF > expand.c
XX/*************************************************************
XX * vt100 terminal emulator - Wild card and Directory support
XX * v2.1 860915 DBW - new features (see README)
XX * 860830 Steve Drew Added Wild card support, features(expand.c)
XX * v2.0 860809 DBW - Major rewrite
XX * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
XX * v1.0 860712 DBW - First version released
XX *
XX * Much of the code from this module extracted from
XX * Matt Dillons Shell program. (Thanxs Matt.)
XX *************************************************************/
XX
XX#define MODULE_EXPAND 1
XX#include "vt100.h"
XX
XXstruct DPTR { /* Format of directory fetch pointer */
XX struct FileLock *lock; /* lock on directory */
XX struct FileInfoBlock *fib; /* mod'd fib for entry */
XX};
XX
XX/*
XX * Disk directory routines
XX *
XX *
XX * dopen() returns a struct DPTR, or NULL if the given file does not
XX * exist. stat will be set to 1 if the file is a directory. If the
XX * name is "", then the current directory is openned.
XX *
XX * dnext() returns 1 until there are no more entries. The **name and
XX * *stat are set. *stat = 1 if the file is a directory.
XX *
XX * dclose() closes a directory channel.
XX *
XX */
XX
XXstruct DPTR *
XXdopen(name, stat)
XXchar *name;
XXint *stat;
XX{
XX struct DPTR *dp;
XX int namelen, endslash = 0;
XX struct FileLock *MyLock;
XX
XX MyLock = (struct FileLock *)( (ULONG) ((struct Process *)
XX (FindTask(NULL)))->pr_CurrentDir);
XX namelen = strlen(name);
XX if (namelen && name[namelen - 1] == '/') {
XX name[namelen - 1] = '\0';
XX endslash = 1;
XX }
XX *stat = 0;
XX dp = (struct DPTR *)malloc(sizeof(struct DPTR));
XX if (*name == '\0')
XX dp->lock = (struct FileLock *)DupLock (MyLock);
XX else
XX dp->lock = (struct FileLock *)Lock (name, ACCESS_READ);
XX if (endslash)
XX name[namelen - 1] = '/';
XX if (dp->lock == NULL) {
XX free (dp);
XX return (NULL);
XX }
XX dp->fib = (struct FileInfoBlock *)
XX AllocMem((long)sizeof(struct FileInfoBlock), MEMF_PUBLIC);
XX if (!Examine (dp->lock, dp->fib)) {
XX dclose (dp);
XX return (NULL);
XX }
XX if (dp->fib->fib_DirEntryType >= 0)
XX *stat = 1;
XX return (dp);
XX}
XX
XXdnext(dp, pname, stat)
XXstruct DPTR *dp;
XXchar **pname;
XXint *stat;
XX{
XX if (dp == NULL)
XX return (0);
XX if (ExNext (dp->lock, dp->fib)) {
XX *stat = (dp->fib->fib_DirEntryType < 0) ? 0 : 1;
XX *pname = dp->fib->fib_FileName;
XX return (1);
XX }
XX return (0);
XX}
XX
XX
XXdclose(dp)
XXstruct DPTR *dp;
XX{
XX if (dp == NULL)
XX return (1);
XX if (dp->fib)
XX FreeMem (dp->fib, (long)sizeof(*dp->fib));
XX if (dp->lock)
XX UnLock (dp->lock);
XX free (dp);
XX return (1);
XX}
XX
XXfree_expand(av)
XXchar **av;
XX{
XX char **base = av;
XX
XX if (av) {
XX while (*av) {
XX free (*av);
XX ++av;
XX }
XX free (base);
XX }
XX}
XX
XX/*
XX * EXPAND(wild_name, pac)
XX * wild_name - char * (example: "df0:*.c")
XX * pac - int * will be set to # of arguments.
XX *
XX */
XX
XX
XXchar **
XXexpand(base, pac)
XXchar *base;
XXint *pac;
XX{
XX char **eav = (char **)malloc (sizeof(char *));
XX int eleft, eac;
XX
XX char *ptr, *name;
XX char *bname, *ename, *tail;
XX int stat, scr;
XX struct DPTR *dp;
XX
XX *pac = eleft = eac = 0;
XX base = strcpy(malloc(strlen(base)+1), base);
XX for (ptr = base; *ptr && *ptr != '?' && *ptr != '*'; ++ptr);
XX for (; ptr >= base && !(*ptr == '/' || *ptr == ':'); --ptr);
XX if (ptr < base) {
XX bname = strcpy (malloc(1), "");
XX } else {
XX scr = ptr[1];
XX ptr[1] = '\0';
XX bname = strcpy (malloc(strlen(base)+1), base);
XX ptr[1] = scr;
XX }
XX ename = ptr + 1;
XX for (ptr = ename; *ptr && *ptr != '/'; ++ptr);
XX scr = *ptr;
XX *ptr = '\0';
XX tail = (scr) ? ptr + 1 : NULL;
XX
XX if ((dp = dopen (bname, &stat)) == NULL || stat == 0) {
XX free (bname);
XX free (base);
XX free (eav);
XX emits ("Could not open directory");
XX return (NULL);
XX }
XX while (dnext (dp, &name, &stat)) {
XX if (compare_ok(ename, name)) {
XX if (tail) {
XX int alt_ac;
XX char *search, **alt_av, **scrav;
XX struct FileLock *lock;
XX
XX if (!stat) /* expect more dirs, but this not a dir */
XX continue;
XX lock = (struct FileLock *)CurrentDir (dp->lock);
XX search = malloc(strlen(name)+strlen(tail)+2);
XX strcpy (search, name);
XX strcat (search, "/");
XX strcat (search, tail);
XX scrav = alt_av = expand (search, &alt_ac);
XX CurrentDir (lock);
XX if (scrav) {
XX while (*scrav) {
XX if (eleft < 2) {
XX char **scrav = (char **)malloc(sizeof(char *) * (eac + 10));
XX movmem (eav, scrav, sizeof(char *) * (eac + 1));
XX free (eav);
XX eav = scrav;
XX eleft = 10;
XX }
XX eav[eac] = malloc(strlen(bname)+strlen(*scrav)+1);
XX strcpy(eav[eac], bname);
XX strcat(eav[eac], *scrav);
XX free (*scrav);
XX ++scrav;
XX --eleft, ++eac;
XX }
XX free (alt_av);
XX }
XX } else {
XX if (eleft < 2) {
XX char **scrav = (char **)malloc(sizeof(char *) * (eac + 10));
XX movmem (eav, scrav, sizeof(char *) * (eac + 1));
XX free (eav);
XX eav = scrav;
XX eleft = 10;
XX }
XX eav[eac] = malloc (strlen(bname)+strlen(name)+1);
XX eav[eac] = strcpy(eav[eac], bname);
XX strcat(eav[eac], name);
XX --eleft, ++eac;
XX }
XX }
XX }
XX dclose (dp);
XX *pac = eac;
XX eav[eac] = NULL;
XX free (bname);
XX free (base);
XX if (eac)
XX return (eav);
XX free (eav);
XX return (NULL);
XX}
XX
XX/*
XX * Compare a wild card name with a normal name
XX */
XX
XX#define MAXB 8
XX
XXcompare_ok(wild, name)
XXchar *wild, *name;
XX{
XX char *w = wild;
XX char *n = name;
XX char *back[MAXB][2];
XX int bi = 0;
XX
XX while (*n || *w) {
XX switch (*w) {
XX case '*':
XX if (bi == MAXB) {
XX emits ("Too many levels of '*'");
XX return (0);
XX }
XX back[bi][0] = w;
XX back[bi][1] = n;
XX ++bi;
XX ++w;
XX continue;
XXgoback:
XX --bi;
XX while (bi >= 0 && *back[bi][1] == '\0')
XX --bi;
XX if (bi < 0)
XX return (0);
XX w = back[bi][0] + 1;
XX n = ++back[bi][1];
XX ++bi;
XX continue;
XX case '?':
XX if (!*n) {
XX if (bi)
XX goto goback;
XX return (0);
XX }
XX break;
XX default:
XX if (toupper(*n) != toupper(*w)) {
XX if (bi)
XX goto goback;
XX return (0);
XX }
XX break;
XX }
XX if (*n) ++n;
XX if (*w) ++w;
XX }
XX return (1);
XX}
XX
XXset_dir(new)
XXchar *new;
XX{
XX register char *s;
XX int i;
XX struct FileLock *lock;
XX char temp[60];
XX struct FileInfoBlock fib;
XX
XX if (*new != '\000') {
XX strcpy(temp, MyDir);
XX s = new;
XX if (*s == '/') {
XX s++;
XX for (i=strlen(MyDir);
XX MyDir[i] != '/' && MyDir[i] != ':';
XX i--);
XX MyDir[i+1] = '\0';
XX strcat(MyDir, s);
XX }
XX else if (exists(s, ':') == 0) {
XX if (MyDir[strlen(MyDir)-1] != ':')
XX strcat(MyDir, "/");
XX strcat(MyDir, s);
XX }
XX else
XX strcpy(MyDir, s);
XX
XX if ((lock = (struct FileLock *)Lock(MyDir)) == 0) {
XX emits("Directory not found\n");
XX strcpy(MyDir, temp);
XX }
XX else {
XX if (Examine(lock, &fib)) {
XX if (fib.fib_DirEntryType > 0) {
XX if (lock = (struct FileLock *)CurrentDir(lock))
XX UnLock(lock);
XX if (MyDir[strlen(MyDir)-1] == '/')
XX MyDir[strlen(MyDir)-1] = '\0';
XX }
XX else {
XX emits("Not a Directory\n");
XX strcpy(MyDir,temp);
XX }
XX }
XX }
XX }
XX}
XX
XXexists(s,c)
XXchar *s,c;
XX {
XX while (*s != '\000')
XX if (*s++ == c) return(1);
XX return(0);
XX }
SHAR_EOF
if test 8210 -ne "`wc -c expand.c`"
then
echo shar: error transmitting expand.c '(should have been 8210 characters)'
fi
echo shar: extracting init.c
sed 's/^XX//' << \SHAR_EOF > init.c
XX/***************************************************************
XX * vt100 - terminal emulator - initialization
XX *
XX * v2.1 860915 DBW - new features (see README)
XX * 860901 ACS - Added Parity and Word Length and support code
XX * 860823 DBW - Integrated and rewrote lots of code
XX * v2.0 860809 DBW - Major rewrite
XX * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
XX * v1.0 860712 DBW - First version released
XX *
XX ***************************************************************/
XX
XX#define MODULE_INIT 1
XX#include "vt100.h"
XX
XXvoid InitDefaults(argc,argv)
XXint argc;
XXchar **argv;
XX {
XX FILE *fd;
XX char line[256],scr[32],delim,macro[256],c0,*ptr;
XX int i,j,k;
XX long li;
XX
XX if (((argc > 1) && (fd=fopen(argv[1],"r")) != 0) ||
XX (fd=fopen("vt100.init","r")) != 0 ||
XX (fd=fopen("s:vt100.init","r")) != 0) {
XX while (fgets(line,256,fd) != 0) {
XX if ((c0 = line[0]) == '#') continue;
XX if ((c0|' ') == 'e') break;
XX switch (c0|' ') {
XX case 'b':
XX if ((line[1]|' ') == 'o') {
XX /* bold color */
XX if (sscanf(line,"%s %x",scr,&i) == 2) p_bold = i;
XX break;
XX }
XX if ((line[1]|' ') == 'u') {
XX /* buffer size */
XX if (sscanf(line,"%s %d",scr,&i) == 2) p_buffer = i;
XX if (p_buffer < 512) p_buffer = 512;
XX break;
XX }
XX if ((line[1]|' ') == 'r') {
XX /* break time */
XX if (sscanf(line,"%s %ld",scr,&li) == 2) p_break = li;
XX break;
XX }
XX if ((line[1]|' ') != 'a') break;
XX switch(line[2]|' ') {
XX /* baud rate */
XX case 'u':
XX if (sscanf(line,"%s %d",scr,&i) == 2)
XX switch (i) {
XX case 300:
XX case 1200:
XX case 2400:
XX case 4800:
XX case 9600: p_baud = i; break;
XX }
XX break;
XX
XX /* background */
XX case 'c':
XX if (sscanf(line,"%s %x",scr,&i) == 2) p_background = i;
XX break;
XX }
XX break;
XX
XX /* screen type */
XX case 's':
XX if (sscanf(line,"%s %s",scr,scr) == 2) {
XX if ((scr[0]|' ') == 'w') p_screen = 0;
XX else p_screen = 1;
XX }
XX break;
XX
XX /* number of lines */
XX case 'l':
XX if (sscanf(line,"%s %d",scr,&i) == 2) p_lines = i;
XX break;
XX
XX /* screen depth */
XX case 'd':
XX if (sscanf(line,"%s %d",scr,&i) == 2) p_depth = i;
XX break;
XX
XX /* cursor color */
XX case 'c':
XX if (sscanf(line,"%s %x",scr,&i) == 2) p_cursor = i;
XX break;
XX
XX /* interlace type */
XX case 'i':
XX if (sscanf(line,"%s %s",scr,scr) == 2) {
XX if ((scr[1]|' ') == 'n') p_interlace = 1;
XX else p_interlace = 0;
XX }
XX break;
XX
XX case 'f':
XX switch (line[1]|' ') {
XX
XX /* foreground color */
XX case 'o':
XX if (sscanf(line,"%s %x",scr,&i) == 2) p_foreground = i;
XX break;
XX
XX /* function key */
XX default:
XX if (sscanf(&line[1],"%d",&i) != 1) break;
XX if (i < 1 || i > 10) break;
XX delim = 0;
XX for (j=(i==10?3:2); line[j] != 0 &&
XX (line[j] == ' ' || line[j] == '\t'); j++) ;
XX if (line[j] == 0) {
XX if (c0 == 'f') p_f[i-1] = NULL;
XX else p_F[i-1] = NULL;
XX break;
XX }
XX delim = line[j];
XX k = 0;
XX macro[0] = 0;
XX while (line[++j] != delim) {
XX if (line[j] == 0) {
XX if (fgets(line,256,fd) == 0) {
XX line[0] = delim;
XX line[1] = 0;
XX }
XX j = -1;
XX continue;
XX }
XX if (line[j] == '^' && line[++j] != '^')
XX macro[k++] = (line[j]|' ') - 0x60;
XX else if (line[j] != '\n') macro[k++] = line[j];
XX macro[k] = 0;
XX }
XX ptr = malloc(k+1);
XX if (c0 == 'f') p_f[i-1] = ptr;
XX else p_F[i-1] = ptr;
XX strcpy(ptr,macro);
XX break;
XX }
XX break;
XX
XX case 'm':
XX if (sscanf(line,"%s %s",scr,scr) == 2) {
XX if ((scr[0]|' ') == 'i') p_mode = 0;
XX else p_mode = 1;
XX }
XX break;
XX
XX case 'p': /*parity*/
XX if (sscanf(line,"%s %s",scr,scr) == 2)
XX switch(*scr|' ') {
XX case 'n': p_parity = -1; break;
XX case 'e': p_parity = 0; break;
XX case 'o': p_parity = 1; break;
XX }
XX break;
XX
XX case 'w': /*wordsize*/
XX if (sscanf(line,"%s %d",scr,&i) == 2)
XX if (i==7 || i==8) p_wordsize = i;
XX break;
XX }
XX }
XX fclose(fd);
XX }
XX /* Now set up all the screen info as necessary */
XX if (p_interlace == 0) {
XX if (p_lines > 24) p_lines = 24;
XX MINY = 14;
XX NewWindow.Height = (long)((p_lines*8)+8);
XX }
XX else {
XX if (p_lines > 48) p_lines = 48;
XX MINY = 16;
XX NewScreen.ViewModes |= LACE;
XX NewWindow.Height = (long)((p_lines*8)+10);
XX }
XX NewWindow.MinHeight = NewWindow.Height;
XX NewWindow.MaxHeight = NewWindow.Height;
XX NewWindow.TopEdge = 3L;
XX MAXY = ((p_lines-1)*8) + MINY;
XX top = MINY;
XX bot = MAXY;
XX savx = MINX;
XX savy = MINY;
XX if (p_screen == 1) {
XX if (p_depth > 2) p_depth = 2;
XX if (p_depth < 1) p_depth = 1;
XX NewScreen.Depth = (long)p_depth;
XX NewScreen.Height = (long)((p_lines*8)+15);
XX if (p_interlace == 1)
XX NewScreen.TopEdge = (long)(402 - NewScreen.Height);
XX else
XX NewScreen.TopEdge = 0L;
XX }
XX else {
XX p_depth = 2L;
XX NewWindow.TopEdge = 0L;
XX NewWindow.Screen = NULL;
XX NewWindow.Type = WBENCHSCREEN;
XX }
XX }
XX
XXvoid InitDevs()
XX{
XXUSHORT colors[4];
XXint i;
XXBYTE *b,*c;
XX
XXIntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", INTUITION_REV);
XXif( IntuitionBase == NULL )
XX cleanup("can't open intuition",1);
XX
XXGfxBase = (struct GfxBase *)OpenLibrary("graphics.library",GRAPHICS_REV);
XXif( GfxBase == NULL )
XX cleanup("can't open graphics library",2);
XX
XXif (p_screen == 1) {
XX if ((myscreen = (struct Screen *)OpenScreen(&NewScreen)) == NULL)
XX cleanup("can't open screen",3);
XX NewWindow.Screen = myscreen;
XX }
XX
XXif(( mywindow = (struct Window *)OpenWindow(&NewWindow) ) == NULL)
XX cleanup("can't open window",4);
XX
XXmyviewport = (struct ViewPort *)ViewPortAddress(mywindow);
XX
XXif (p_screen != 0) {
XX colors[0] = p_background;
XX colors[1] = p_foreground;
XX colors[2] = p_bold;
XX colors[3] = p_cursor;
XX if (p_depth == 1)
XX LoadRGB4(myviewport,(struct ColorMap *)colors,2L);
XX else
XX LoadRGB4(myviewport,(struct ColorMap *)colors,4L);
XX }
XX
XXRead_Request = (struct IOExtSer *)
XX AllocMem((long)sizeof(*Read_Request),MEMF_PUBLIC|MEMF_CLEAR);
XXRead_Request->io_SerFlags = 0L;
XXRead_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",0);
XXif(OpenDevice(SERIALNAME,NULL,Read_Request,NULL))
XX cleanup("Cant open Read device",5);
XXrs_in = malloc(p_buffer+1);
XXRead_Request->io_SerFlags = 0L;
XXswitch (p_parity) {
XX case 1:
XX Read_Request->io_SerFlags |= SERF_PARTY_ODD;
XX case 0:
XX Read_Request->io_SerFlags |= SERF_PARTY_ON;
XX p_wordsize = 7;
XX }
XXRead_Request->io_Baud = p_baud;
XXRead_Request->io_ReadLen = p_wordsize;
XXRead_Request->io_WriteLen = p_wordsize;
XXRead_Request->io_CtlChar = 0x11130000L;
XXRead_Request->io_RBufLen = p_buffer;
XXRead_Request->io_BrkTime = p_break;
XXRead_Request->IOSer.io_Command = SDCMD_SETPARAMS;
XXDoIO(Read_Request);
XXRead_Request->IOSer.io_Command = CMD_READ;
XXRead_Request->IOSer.io_Length = 1;
XXRead_Request->IOSer.io_Data = (APTR) &rs_in[0];
XX
XXWrite_Request = (struct IOExtSer *)
XX AllocMem((long)sizeof(*Write_Request),MEMF_PUBLIC|MEMF_CLEAR);
XXb = (BYTE *)Read_Request;
XXc = (BYTE *)Write_Request;
XXfor (i=0;i<sizeof(struct IOExtSer);i++) *c++ = *b++;
XXWrite_Request->IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS",0);
XXWrite_Request->IOSer.io_Command = CMD_WRITE;
XXWrite_Request->IOSer.io_Length = 1;
XXWrite_Request->IOSer.io_Data = (APTR) &rs_out[0];
XX
XX
XXTimer_Port = CreatePort("Timer Port",0);
XXScript_Timer_Port = CreatePort("Timer Port",0);
XX
XXif (OpenDevice(TIMERNAME, UNIT_VBLANK, (char *) &Timer, 0) ||
XX OpenDevice(TIMERNAME, UNIT_VBLANK, (char *) &Script_Timer, 0))
XX cleanup("can't open timer device",7);
XX
XXTimer.tr_node.io_Message.mn_ReplyPort = Timer_Port;
XXTimer.tr_node.io_Command = TR_ADDREQUEST;
XXTimer.tr_node.io_Flags = 0;
XXTimer.tr_node.io_Error = 0;
XX
XXScript_Timer.tr_node.io_Message.mn_ReplyPort = Script_Timer_Port;
XXScript_Timer.tr_node.io_Command = TR_ADDREQUEST;
XXScript_Timer.tr_node.io_Flags = 0;
XXScript_Timer.tr_node.io_Error = 0;
XX}
XX
XX/*****************************************************************/
XX/* The following function initializes the structure arrays */
XX/* needed to provide the File menu topic. */
XX/*****************************************************************/
XXvoid InitFileItems()
XX{
XXint n;
XX
XX/* initialize each menu item and IntuiText with loop */
XXfor( n=0; n<FILEMAX; n++ )
XX {
XX FileItem[n].NextItem = &FileItem[n+1];
XX FileItem[n].LeftEdge = 0;
XX FileItem[n].TopEdge = 11 * n;
XX FileItem[n].Width = 135;
XX FileItem[n].Height = 11;
XX FileItem[n].Flags = ITEMTEXT | ITEMENABLED | HIGHBOX;
XX FileItem[n].MutualExclude = 0;
XX FileItem[n].ItemFill = (APTR)&FileText[n];
XX FileItem[n].SelectFill = NULL;
XX FileItem[n].Command = 0;
XX FileItem[n].SubItem = NULL;
XX FileItem[n].NextSelect = 0;
XX
XX FileText[n].FrontPen = 0;
XX FileText[n].BackPen = 1;
XX FileText[n].DrawMode = JAM2; /* render in fore and background */
XX FileText[n].LeftEdge = 0;
XX FileText[n].TopEdge = 1;
XX FileText[n].ITextFont = NULL;
XX FileText[n].NextText = NULL;
XX }
XXFileItem[FILEMAX-1].NextItem = NULL;
XX
XX/* initialize text for specific menu items */
XXFileText[0].IText = (UBYTE *)"Ascii Capture";
XXFileText[1].IText = (UBYTE *)"Ascii Send";
XXFileText[2].IText = (UBYTE *)"Xmodem Receive";
XXFileText[3].IText = (UBYTE *)"Xmodem Send";
XXFileText[4].IText = (UBYTE *)"Kermit Get";
XXFileText[5].IText = (UBYTE *)"Kermit Receive";
XXFileText[6].IText = (UBYTE *)"Kermit Send";
XXFileText[7].IText = (UBYTE *)"Kermit BYE";
XX}
XX
XX/*****************************************************************/
XX/* The following function initializes the structure arrays */
XX/* needed to provide the BaudRate menu topic. */
XX/*****************************************************************/
XXvoid InitRSItems()
XX{
XXint n;
XX
XX/* initialize each menu item and IntuiText with loop */
XXfor( n=0; n<RSMAX; n++ )
XX {
XX RSItem[n].NextItem = &RSItem[n+1];
XX RSItem[n].LeftEdge = 0;
XX RSItem[n].TopEdge = 11 * n;
XX RSItem[n].Width = 85;
XX RSItem[n].Height = 11;
XX RSItem[n].Flags = ITEMTEXT | ITEMENABLED | HIGHBOX | CHECKIT;
XX RSItem[n].MutualExclude = (~(1 << n));
XX RSItem[n].ItemFill = (APTR)&RSText[n];
XX RSItem[n].SelectFill = NULL;
XX RSItem[n].Command = 0;
XX RSItem[n].SubItem = NULL;
XX RSItem[n].NextSelect = 0;
XX
XX RSText[n].FrontPen = 0;
XX RSText[n].BackPen = 1;
XX RSText[n].DrawMode = JAM2; /* render in fore and background */
XX RSText[n].LeftEdge = 0;
XX RSText[n].TopEdge = 1;
XX RSText[n].ITextFont = NULL;
XX RSText[n].NextText = NULL;
XX }
XXRSItem[RSMAX-1].NextItem = NULL;
XX/* select baud item chekced */
XXswitch (p_baud) {
XX case 300: n = 0; break;
XX case 1200: n = 1; break;
XX case 2400: n = 2; break;
XX case 4800: n = 3; break;
XX case 9600: n = 4; break;
XX default: n = 2; p_baud = 2400;
XX }
XXRSItem[n].Flags = ITEMTEXT | ITEMENABLED | HIGHBOX | CHECKIT | CHECKED;
XX
XX/* initialize text for specific menu items */
XXRSText[0].IText = (UBYTE *)" 300";
XXRSText[1].IText = (UBYTE *)" 1200";
XXRSText[2].IText = (UBYTE *)" 2400";
XXRSText[3].IText = (UBYTE *)" 4800";
XXRSText[4].IText = (UBYTE *)" 9600";
XX}
XX
XX/*****************************************************************/
XX/* The following function initializes the structure arrays */
XX/* needed to provide the Transfer Mode menu topic. */
XX/*****************************************************************/
XXvoid InitXFItems()
XX{
XXint n;
XX
XX/* initialize each menu item and IntuiText with loop */
XXfor( n=0; n<XFMAX; n++ )
XX {
XX XFItem[n].NextItem = &XFItem[n+1];
XX XFItem[n].LeftEdge = 0;
XX XFItem[n].TopEdge = 11 * n;
XX XFItem[n].Width = 85;
XX XFItem[n].Height = 11;
XX XFItem[n].Flags = ITEMTEXT | ITEMENABLED | HIGHBOX | CHECKIT;
XX XFItem[n].MutualExclude = (~(1 << n));
XX XFItem[n].ItemFill = (APTR)&XFText[n];
XX XFItem[n].SelectFill = NULL;
XX XFItem[n].Command = 0;
XX XFItem[n].SubItem = NULL;
XX XFItem[n].NextSelect = 0;
XX
XX XFText[n].FrontPen = 0;
XX XFText[n].BackPen = 1;
XX XFText[n].DrawMode = JAM2; /* render in fore and background */
XX XFText[n].LeftEdge = 0;
XX XFText[n].TopEdge = 1;
XX XFText[n].ITextFont = NULL;
XX XFText[n].NextText = NULL;
XX }
XXXFItem[XFMAX-1].NextItem = NULL;
XX/* mode checked */
XXXFItem[p_mode].Flags = ITEMTEXT | ITEMENABLED | HIGHBOX | CHECKIT | CHECKED;
XX
XX/* initialize text for specific menu items */
XXXFText[0].IText = (UBYTE *)" image";
XXXFText[1].IText = (UBYTE *)" CR LF";
XX}
XX
XX
XX/*****************************************************************/
XX/* The following function initializes the structure arrays */
XX/* needed to provide the Script menu topic. */
XX/*****************************************************************/
XXvoid InitScriptItems()
XX{
XXint n;
XX
XX/* initialize each menu item and IntuiText with loop */
XXfor( n=0; n<SCRIPTMAX; n++ )
XX {
XX ScriptItem[n].NextItem = &ScriptItem[n+1];
XX ScriptItem[n].LeftEdge = 0;
XX ScriptItem[n].TopEdge = 11 * n;
XX ScriptItem[n].Width = 155;
XX ScriptItem[n].Height = 11;
XX ScriptItem[n].Flags = ITEMTEXT | ITEMENABLED | HIGHBOX;
XX ScriptItem[n].MutualExclude = 0;
XX ScriptItem[n].ItemFill = (APTR)&ScriptText[n];
XX ScriptItem[n].SelectFill = NULL;
XX ScriptItem[n].Command = 0;
XX ScriptItem[n].SubItem = NULL;
XX ScriptItem[n].NextSelect = 0;
XX
XX ScriptText[n].FrontPen = 0;
XX ScriptText[n].BackPen = 1;
XX ScriptText[n].DrawMode = JAM2; /* render in fore and background */
XX ScriptText[n].LeftEdge = 0;
XX ScriptText[n].TopEdge = 1;
XX ScriptText[n].ITextFont = NULL;
XX ScriptText[n].NextText = NULL;
XX }
XXScriptItem[SCRIPTMAX-1].NextItem = NULL;
XX
XX/* initialize text for specific menu items */
XXScriptText[0].IText = (UBYTE *)"Execute file";
XXScriptText[1].IText = (UBYTE *)"Abort Execution";
XX}
XX
XX/*****************************************************************/
XX/* The following function initializes the structure arrays */
XX/* needed to provide the Util menu topic. */
XX/*****************************************************************/
XXvoid InitUtilItems()
XX{
XXint n;
XX
XX/* initialize each menu item and IntuiText with loop */
XXfor( n=0; n<UTILMAX; n++ )
XX {
XX UtilItem[n].NextItem = &UtilItem[n+1];
XX UtilItem[n].LeftEdge = 0;
XX UtilItem[n].TopEdge = 11 * n;
XX UtilItem[n].Width = 100;
XX UtilItem[n].Height = 11;
XX UtilItem[n].Flags = ITEMTEXT | ITEMENABLED | HIGHBOX;
XX if (n >= 3) UtilItem[n].Flags |= CHECKIT;
XX switch (n) {
XX case 3: UtilItem[3].MutualExclude = 0x30; break;
XX case 4: UtilItem[4].MutualExclude = 0x28; break;
XX case 5: UtilItem[5].MutualExclude = 0x18; break;
XX case 6: UtilItem[6].MutualExclude = 0x80; break;
XX case 7: UtilItem[7].MutualExclude = 0x40; break;
XX default:UtilItem[n].MutualExclude = 0; break;
XX }
XX UtilItem[n].ItemFill = (APTR)&UtilText[n];
XX UtilItem[n].SelectFill = NULL;
XX UtilItem[n].Command = 0;
XX UtilItem[n].SubItem = NULL;
XX UtilItem[n].NextSelect = 0;
XX
XX UtilText[n].FrontPen = 0;
XX UtilText[n].BackPen = 1;
XX UtilText[n].DrawMode = JAM2; /* render in fore and background */
XX UtilText[n].LeftEdge = 0;
XX UtilText[n].TopEdge = 1;
XX UtilText[n].ITextFont = NULL;
XX UtilText[n].NextText = NULL;
XX }
XX/* select parity item */
XXswitch (p_parity) {
XX case -1: n = 3; break;
XX case 0: n = 4; break;
XX case 1: n = 5; break;
XX default: n = 3; p_parity = -1; break;
XX }
XXUtilItem[n].Flags |= CHECKED;
XX
XX/* select word item */
XXswitch (p_wordsize) {
XX case 8: n = 6; break;
XX case 7: n = 7; break;
XX default: n = 6; p_wordsize = 8; break;
XX }
XXUtilItem[n].Flags |= CHECKED;
XX
XXUtilItem[UTILMAX-1].NextItem = NULL;
XX
XX/* initialize text for specific menu items */
XXUtilText[0].IText = (UBYTE *)" Send Break";
XXUtilText[1].IText = (UBYTE *)" Hang Up";
XXUtilText[2].IText = (UBYTE *)" Change Dir";
XXUtilText[3].IText = (UBYTE *)" No Parity";
XXUtilText[4].IText = (UBYTE *)" Even Parity";
XXUtilText[5].IText = (UBYTE *)" Odd Parity";
XXUtilText[6].IText = (UBYTE *)" 8 bit Words";
XXUtilText[7].IText = (UBYTE *)" 7 bit Words";
XX}
XX
XX/**********************************************************************/
XX/* The following function initializes the Menu structure array with */
XX/* appropriate values for our simple menu strip. Review the manual */
XX/* if you need to know what each value means. */
XX/**********************************************************************/
XXvoid InitMenu()
XX{
XXmenu[0].NextMenu = &menu[1];
XXmenu[0].LeftEdge = 5;
XXmenu[0].TopEdge = 0;
XXmenu[0].Width = 50;
XXmenu[0].Height = 10;
XXmenu[0].Flags = MENUENABLED;
XXmenu[0].MenuName = "File"; /* text for menu-bar display */
XXmenu[0].FirstItem = &FileItem[0]; /* pointer to first item in list */
XX
XXmenu[1].NextMenu = &menu[2];
XXmenu[1].LeftEdge = 65;
XXmenu[1].TopEdge = 0;
XXmenu[1].Width = 85;
XXmenu[1].Height = 10;
XXmenu[1].Flags = MENUENABLED;
XXmenu[1].MenuName = "BaudRate"; /* text for menu-bar display */
XXmenu[1].FirstItem = &RSItem[0]; /* pointer to first item in list */
XX
XXmenu[2].NextMenu = &menu[3];
XXmenu[2].LeftEdge = 160;
XXmenu[2].TopEdge = 0;
XXmenu[2].Width = 85;
XXmenu[2].Height = 10;
XXmenu[2].Flags = MENUENABLED;
XXmenu[2].MenuName = "Xfer Mode"; /* text for menu-bar display */
XXmenu[2].FirstItem = &XFItem[0]; /* pointer to first item in list */
XX
XXmenu[3].NextMenu = &menu[4];
XXmenu[3].LeftEdge = 255;
XXmenu[3].TopEdge = 0;
XXmenu[3].Width = 60;
XXmenu[3].Height = 10;
XXmenu[3].Flags = MENUENABLED;
XXmenu[3].MenuName = "Script"; /* text for menu-bar display */
XXmenu[3].FirstItem = &ScriptItem[0]; /* pointer to first item in list */
XX
XXmenu[4].NextMenu = NULL;
XXmenu[4].LeftEdge = 325;
XXmenu[4].TopEdge = 0;
XXmenu[4].Width = 70;
XXmenu[4].Height = 10;
XXmenu[4].Flags = MENUENABLED;
XXmenu[4].MenuName = "Utility"; /* text for menu-bar display */
XXmenu[4].FirstItem = &UtilItem[0]; /* pointer to first item in list */
XX}
XX
SHAR_EOF
if test 17694 -ne "`wc -c init.c`"
then
echo shar: error transmitting init.c '(should have been 17694 characters)'
fi
echo shar: extracting remote.c
sed 's/^XX//' << \SHAR_EOF > remote.c
XX/****************************************************
XX * vt100 emulator - remote character interpretation
XX *
XX * v2.1 860915 DBW - new features (see README)
XX * 860823 DBW - Integrated and rewrote lots of code
XX * v2.0 860803 DRB - Rewrote the control sequence parser
XX * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
XX * v1.0 860712 DBW - First version released
XX *
XX ****************************************************/
XX
XX#define MODULE_REMOTE 1
XX#include "vt100.h"
XX
XXstatic int p[10];
XXstatic int numpar;
XXstatic char escseq[40];
XX
XXvoid doctrl();
XXvoid doesc(); /* force correct denomination */
XXvoid doerase();
XXvoid doindex();
XX
XX/************************************************
XX* function to handle remote characters
XX*************************************************/
XXvoid doremote(c)
XXchar c;
XX {
XX if (c == 24) { inesc = 0; inctrl = 0; return; }
XX if (c == 27 || (inesc >= 0 && c >= ' ')) { doesc(c); return; }
XX if (inctrl >= 0 && c >= ' ') { doctrl(c); return; }
XX if (c == 10 || c == 11 || c == 12) {
XX if (nlmode) doindex('E'); else doindex('D');
XX return;
XX }
XX if (c == 13) {
XX if (!nlmode) emit(c);
XX return;
XX }
XX if (c == 15) { alt = 0; return; }
XX if (c == 14) { alt = 1; return; }
XX if (a[alt] && c > 94 && c < 127) { doalt(c); return; }
XX emit(c);
XX }
XX
XXvoid doesc(c)
XXchar c;
XX{
XX if (inesc < 0) { inesc = 0; return; }
XX if (c == 27 || c == 24) { inesc = -1; return; }
XX if (c < ' ' || c == 127) return; /* Ignore control chars */
XX if (c < '0') {escseq[inesc++] = c; return; } /* Collect intermediates */
XX
XX /* by process of elimination, we have a final character. Put it in
XX the buffer, and dispatch on the first character in the buffer */
XX
XX escseq[inesc] = c;
XX inesc = -1; /* No longer collecting a sequence */
XX switch (escseq[0]) /* Dispatch on the first received */
XX {
XX case '[': /* Control sequence introducer */
XX numpar = 0; /* No parameters yet */
XX private = 0; /* Not a private sequence (yet?) */
XX badseq = 0; /* Good until proven bad */
XX p[0] = p[1] = 0; /* But default the first parameter */
XX inctrl = 0; /* We are in a control sequence */
XX return; /* All done for now ... */
XX
XX case 'D': case 'E': case 'M': /* Some kind of index */
XX doindex (c); /* Do the index */
XX return; /* Return */
XX
XX case '7': /* Save cursor position */
XX savx = x; savy = y; savmode = curmode; savalt = alt;
XX sa[0] = a[0]; sa[1] = a[1];
XX return;
XX
XX case '8': /* Restore cursor position */
XX x = savx; y = savy; alt = savalt; curmode = savmode;
XX a[0] = sa[0]; a[1] = sa[1];
XX return;
XX
XX case 'c': /* Reset */
XX top = MINY; bot = MAXY; savx = MINX; savy = MINY;
XX curmode = FS_NORMAL; keyapp = FALSE;
XX inesc = -1;
XX a[0] = 0; a[1] = 0; sa[0] = 0; sa[1] = 0;
XX emit(12);
XX return;
XX
XX case '(': /* Change character set */
XX if (c == '0' || c == '2') a[0] = 1; else a[0] = 0;
XX return;
XX
XX case ')': /* Change the other character set */
XX if (c == '0' || c == '2') a[1] = 1; else a[1] = 0;
XX return;
XX
XX case '=': /* set keypad application mode */
XX keyapp = TRUE;
XX return;
XX
XX case '>': /* reset application mode */
XX keyapp = FALSE;
XX return;
XX
XX case 'Z':
XX sendchar(27); sendstring("[?1;7c"); return;
XX
XX /* If we didn't match anything, we can just return, happy in the
XX knowledge that we've at least eaten the whole sequence */
XX
XX } /* End of switch */
XX return;
XX}
XX
XXvoid doctrl(c)
XXchar c;
XX{
XX int i;
XX
XX if (c == 27 || c == 24) { inctrl = -1; return; }
XX if (c < ' ' || c == 127) return; /* Ignore control chars */
XX
XX /* First, look for some parameter characters. If the very first
XX parameter character isn't a digit, then we have a private sequence */
XX
XX if (c >= '0' && c < '@')
XX {
XX /* can't have parameters after intermediates */
XX if (inctrl > 0) {badseq++ ; return; }
XX switch (c)
XX {
XX case '0': case '1': case '2': case '3': case '4':
XX case '5': case '6': case '7': case '8': case '9':
XX p[numpar] = p[numpar] * 10 + (c - '0');
XX return;
XX
XX case ';':
XX p[++numpar] = 0; /* Start a new parameter */
XX return;
XX
XX case '<': case '=': case '>': case '?': /* Can only mean private */
XX if (inctrl = 0) private = c; /* Only allowed BEFORE parameters */
XX return;
XX
XX /* if we come here, it's a bad sequence */
XX }
XX badseq++; /* Flag the bad sequence */
XX }
XX
XX if (c < '0') /* Intermediate character */
XX {
XX escseq[inctrl++] = c; /* Save the intermediate character */
XX return;
XX }
XX
XX /* if we get here, we have the final character. Put it in the
XX escape sequence buffer, then dispatch the control sequence */
XX
XX numpar++; /* Reflect the real number of parameters */
XX escseq[inctrl++] = c; /* Store the final character */
XX escseq[inctrl] = '\000'; /* Tie off the buffer */
XX inctrl = -1; /* End of the control sequence scan */
XX
XX /* Don't know how to do any private sequences right now, so just punt
XX them */
XX
XX if (private != 0 || badseq != 0) return;
XX
XX switch (escseq[0]) /* Dispatch on first intermediate or final */
XX {
XX case 'A': if (p[0]<=0) p[0] = 1;
XX y -= 8*p[0]; if (y<top) y = top; return;
XX case 'B': if (p[0]<=0) p[0] = 1;
XX y += 8*p[0]; if (y>bot) y = bot; return;
XX case 'C': if (p[0]<=0) p[0] = 1;
XX x += 8*p[0]; if (x>MAXX) x = MAXX; return;
XX case 'D': if (p[0]<=0) p[0] = 1;
XX x -= 8*p[0]; if (x<MINX) x = MINX; return;
XX
XX case 'H': case 'f': /* Cursor position */
XX if (p[0] <= 0) p[0] = 1;
XX if (p[1] <= 0) p[1] = 1;
XX y = (--p[0]*8)+MINY; x = (--p[1]*8)+MINX;
XX if (y > MAXY) y = MAXY;
XX if (x > MAXX) x = MAXX;
XX if (y < MINY) y = MINY;
XX if (x < MINX) x = MINX;
XX return;
XX
XX case 'r': /* Set scroll region */
XX if (p[0] <= 0) p[0] = 1;
XX if (p[1] <= 0) p[1] = p_lines;
XX top = (--p[0]*8)+MINY; bot = (--p[1]*8)+MINY;
XX if (top < MINY) top = MINY;
XX if (bot > MAXY) bot = MAXY;
XX if (top > bot) { top = MINY; bot = MAXY; }
XX x = MINX; y = MINY;
XX return;
XX
XX case 'm': /* Set graphic rendition */
XX for (i=0;i<numpar;i++) {
XX if (p[i] < 0) p[i] = 0;
XX switch (p[i]) {
XX case 0:
XX curmode = FS_NORMAL;
XX break;
XX
XX case 1:
XX curmode |= FSF_BOLD;
XX break;
XX
XX case 4:
XX curmode |= FSF_UNDERLINED;
XX break;
XX
XX case 5:
XX curmode |= FSF_ITALIC;
XX break;
XX
XX default:
XX curmode |= FSF_REVERSE;
XX break;
XX }
XX }
XX return;
XX
XX case 'K': /* Erase in line */
XX doerase();
XX return;
XX
XX case 'J': /* Erase in display */
XX if (p[0] < 0) p[0] = 0;
XX SetAPen(mywindow->RPort,0L);
XX if (p[0] == 0) {
XX if (y < MAXY) RectFill(mywindow->RPort,
XX (long)MINX,(long)(y+2),(long)(MAXX+7),(long)(MAXY+1));
XX }
XX else if (p[0] == 1) {
XX if (y > MINY) RectFill(mywindow->RPort,
XX (long)MINX,(long)(MINY-6),(long)(MAXX+7),(long)(y-7));
XX }
XX else RectFill(mywindow->RPort,
XX (long)MINX,(long)(MINY-6),(long)(MAXX+7),(long)(MAXY+1));
XX SetAPen(mywindow->RPort,1L);
XX doerase(); return;
XX
XX case 'h': /* Set parameter */
XX if (p[0] == 20) nlmode = 1;
XX return;
XX
XX case 'l': /* Reset parameter */
XX if (p[0] == 20) nlmode = 0;
XX return;
XX
XX case 'x':
XX sendchar(27); sendstring("[3;1;8;64;64;1;0x"); return;
XX
XX case 'n':
XX if (p[0] == 6) {
XX sendchar(27);
XX sprintf(escseq,"[%d;%dR",((y-MINY)/8)+1,((x-MINX)/8)+1);
XX sendstring(escseq); return;
XX }
XX sendchar(27); sendstring("[0n"); return;
XX
XX case 'c':
XX sendchar(27); sendstring("[?1;7c"); return;
XX }
XX
XX /* Don't know how to do this one, so punt it */
XX}
XX
XXvoid doindex(c)
XXchar c;
XX {
XX if (c != 'M') {
XX if (c == 'E') x = MINX;
XX if (y > bot) if (y < MAXY) y += 8;
XX if (y == bot)
XX ScrollRaster(mywindow->RPort,0L,8L,(long)MINX,(long)(top-6),
XX (long)(MAXX+7),(long)(bot+1));
XX if (y < bot) y += 8;
XX }
XX else {
XX if (y < top) if (y > MINY) y -= 8;
XX if (y == top)
XX ScrollRaster(mywindow->RPort,0L,-8L,(long)MINX,(long)(top-6),
XX (long)(MAXX+7),(long)(bot+1));
XX if (y > top) y -= 8;
XX }
XX return;
XX }
XX
XXdoalt(c)
XXchar c;
XX {
XX int oldx,newx;
XX inesc = -1;
XX oldx = x; emit(' '); newx = x;
XX x = oldx;
XX SetAPen(mywindow->RPort,1L);
XX switch (c) {
XX case 'j':
XX case 'm':
XX case 'v': doline(4,-8,4,-4);
XX if (c=='j') doline(0,-4,4,-4);
XX else if (c=='m') doline(4,-4,8,-4);
XX else doline(0,-4,8,-4);
XX break;
XX
XX case 'k':
XX case 'l':
XX case 'w': doline(4,-4,4,0);
XX if (c=='k') doline(0,-4,4,-4);
XX else if (c=='l') doline(4,-4,8,-4);
XX else doline(0,-4,8,-4);
XX break;
XX
XX case 'n':
XX case 'q': doline(0,-4,8,-4);
XX if (c=='n') doline(4,-8,4,0);
XX break;
XX
XX case 't':
XX case 'u':
XX case 'x': doline(4,-8,4,0);
XX if (c=='t') doline(4,-4,8,-4);
XX else if (c=='u') doline(0,-4,4,-4);
XX break;
XX }
XX x = newx;
XX }
XX
XXdoline(x1,y1,x2,y2) {
XX RectFill(mywindow->RPort,(long)(x+x1),(long)(y+y1),
XX (long)(x+x2),(long)(y+y2));
XX }
XX
XXvoid doerase()
XX {
XX if (p[0] < 0) p[0] = 0;
XX SetAPen(mywindow->RPort,0L);
XX if (p[0] == 0) RectFill(mywindow->RPort,(long)x,(long)(y-6),
XX (long)(MAXX+7),(long)(y+1));
XX else if (p[0] == 1) RectFill(mywindow->RPort,
XX (long)MINX,(long)(y-6),(long)(x+7),(long)(y+1));
XX else RectFill(mywindow->RPort,
XX (long)MINX,(long)(y-6),(long)(MAXX+7),(long)(y+1));
XX SetAPen(mywindow->RPort,1L);
XX return;
XX }
XX
SHAR_EOF
if test 9213 -ne "`wc -c remote.c`"
then
echo shar: error transmitting remote.c '(should have been 9213 characters)'
fi
echo shar: extracting script.c
sed 's/^XX//' << \SHAR_EOF > script.c
XX/*************************************************************
XX * vt100 terminal emulator - Script file support
XX *
XX * v2.1 860915 DBW - new features (see README)
XX * 860901 ACS - Added BAUD, PARITY and WORD commands & handling
XX * 860823 DBW - Integrated and rewrote lots of code
XX * 860815 Steve Drew: Initial version written of SCRIPT.C
XX * v2.0 860809 DBW - Major rewrite
XX * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
XX * v1.0 860712 DBW - First version released
XX *
XX *************************************************************/
XX
XX#define MODULE_SCRIPT 1
XX
XX#include "vt100.h"
XX
XXstruct COMMAND {
XX int (*func)();
XX char *cname;
XX};
XX
XXstruct LABEL {
XX struct LABEL *next;
XX char *name;
XX long pos;
XX};
XX
XX
XX
XX/**************** globals needed ******************/
XX
XXchar on_string[20]; /* string to match on for on cmd */
XXchar wait_string[20]; /* string to match of for wait cmd */
XXchar golabel[20]; /* label we are looking for in goto */
XXchar on_cmd[20]; /* command to execute when on matchs*/
XXint onsize; /* size of on_string */
XXint waitsize; /* size of wait_string */
XXint onpos; /* position in on string for search */
XXint waitpos; /* pos in wait_string for search */
XXint on_match; /* flag set while doing on_cmd */
XXFILE *sf; /* file pointer for script file */
XXstruct LABEL *lbase = NULL; /* will point to first label */
XXstruct LABEL *labels; /* current label pointer */
XX
XXint cmd_send(), cmd_wait(), cmd_on(), cmd_goto(), cmd_delay(), cmd_done(),
XX cmd_ks(), cmd_kg(), cmd_kr(), cmd_xs(), cmd_xr(), cmd_cap(), cmd_as(),
XX cmd_null(), cmd_kb(), cmd_cd(), cmd_sb(), cmd_baud(), cmd_word(),
XX cmd_parity(), cmd_bt(), cmd_tm();
XX
XXchar *next_wrd(), *tostring();
XX
XX
XX/********************** command table **********************************/
XX
XXstatic struct COMMAND commands[]= {
XX cmd_send, "send", /* send string to host */
XX cmd_wait, "wait", /* wait for a string from host */
XX cmd_on, "on", /* on a 'string' do a cmd */
XX cmd_goto, "goto", /* goto label */
XX cmd_delay, "delay", /* delay amount of seconds */
XX cmd_done, "exit", /* exit script file */
XX cmd_ks, "ks", /* kermit send file */
XX cmd_kr, "kr", /* kermit receive file */
XX cmd_kg, "kg", /* kermit get file */
XX cmd_kb, "kb", /* kermit bye (for server) */
XX cmd_xs, "xs", /* xmodem send file */
XX cmd_xr, "xr", /* xmodem receive file */
XX cmd_cap, "capture", /* ascii capture on/off */
XX cmd_as, "ascii_send", /* ascii send */
XX cmd_cd, "cd", /* change directory */
XX cmd_sb, "sb", /* Send a break */
XX cmd_baud, "baud", /* Set Baud Rate */
XX cmd_parity, "parity", /* Set Parity */
XX cmd_word, "word", /* Set Word Length */
XX cmd_bt, "bt", /* Set Break Time */
XX cmd_tm, "tm", /* Set KERMIT transfer mode */
XX cmd_null, NULL
XX};
XX
XX/********************************************************************/
XX/* checks char to see if match with on string or wait_string */
XX/* if on string match oncmd gets executed imediately, */
XX/* if wait_string match script_wait is set. */
XX/********************************************************************/
XX
XXchk_script(c)
XXchar c;
XX{
XX if (on_string[0] != '\0') {
XX if (on_string[onpos] == c) {
XX onpos++;
XX if (onpos == onsize) {
XX on_match = TRUE;
XX do_script_cmd(ONCOMMAND);
XX on_match = FALSE;
XX return(0);
XX }
XX }
XX else onpos = 0;
XX }
XX
XX if (wait_string[0] != '\0') {
XX if (wait_string[waitpos] != c) {
XX waitpos = 0;
XX return(0);
XX }
XX waitpos++;
XX if (waitpos != waitsize) return(0);
XX wait_string[0] = '\0';
XX script_wait = FALSE;
XX }
XX}
XX
XXscript_start(file)
XXchar *file;
XX{
XX if ((sf = fopen(file, "r")) == NULL) {
XX emits("Can't open script file\n");
XX return(0);
XX }
XX script_on = TRUE;
XX script_wait = FALSE;
XX wait_string[0] = '\0';
XX on_string[0] = '\0';
XX on_match = FALSE;
XX lbase = NULL;
XX}
XX
XX/* return pointer to next word. set l to size of the word */
XX
XXchar *next_wrd(s,l)
XXchar *s;
XXint *l;
XX{
XX char *p;
XX while(*s && (*s == ' ' || *s == 9)) s++;
XX p = s;
XX while(*s && (*s != ' ' && *s != 9)) s++;
XX *l = s-p;
XX return(p);
XX}
XX
XXexe_cmd(p,l)
XXchar *p;
XXint l;
XX{
XX int i;
XX
XX /* downcase the command */
XX for (i=0; i<l; i++) p[i] |= ' ';
XX
XX /* now search for it */
XX for (i=0; commands[i].func != cmd_null; ++i)
XX if (strncmp(p, commands[i].cname, l) == 0) {
XX (*commands[i].func)(next_wrd(p+l, &l));
XX return(TRUE);
XX }
XX emits ("\nScript - unknown command: ");
XX emits (p);
XX emits ("\n");
XX}
XX
XXstruct LABEL *find_label(lname)
XXchar *lname;
XX{
XX struct LABEL *label;
XX
XX label = lbase;
XX while(label != NULL) {
XX if (strcmp(label->name, lname) == 0) return (label);
XX label = label->next;
XX }
XX return(NULL);
XX}
XX
XX
XXdo_script_cmd(stat)
XXint stat;
XX{
XX int len,l;
XX char line[256];
XX char *p;
XX
XX if (stat == ONCOMMAND) { /* if ON command is matched and we were */
XX strcpy(line,on_cmd); /* doing a DELAY then abort the delay timer,*/
XX p = next_wrd(line,&l); /* except if on_cmd was just a SEND. */
XX if (*p != 'S' && script_wait == WAIT_TIMER) {
XX AbortIO((char *) &Script_Timer);
XX Wait (1L << Script_Timer_Port->mp_SigBit);
XX script_wait = FALSE; /* script will proceed after on command */
XX }
XX exe_cmd(p,l);
XX return(0);
XX }
XX
XX script_wait = FALSE;
XX while(fgets(line,256,sf) != NULL) {
XX len = strlen(line);
XX line[--len] = '\0';
XX p = next_wrd(&line[0], &l);
XX if (*(p + l - 1) == ':') { /* its a label */
XX *(p + l - 1) = '\0';
XX if (find_label(p) == NULL) { /* it's a new label */
XX if (lbase == NULL) { /* it's the first label */
XX labels = lbase = (struct LABEL *) malloc (sizeof (struct LABEL));
XX }
XX else {
XX labels->next =
XX (struct LABEL *) malloc (sizeof (struct LABEL));
XX labels = labels->next;
XX }
XX labels->pos = ftell(sf);
XX labels->name = malloc(l);
XX labels->next = NULL;
XX strcpy(labels->name, p);
XX if (stat == GOTOLABEL && strcmp(p, golabel) == 0)
XX stat = NEXTCOMMAND;
XX }
XX p = next_wrd(p+l+1, &l);
XX } /* end of it's a label */
XX if (stat == GOTOLABEL || *p == '#') continue;
XX if (*p) exe_cmd(p,l);
XX return(0);
XX } /* end of while */
XX if (stat == GOTOLABEL) {
XX emits("\nScript - label not found: ");
XX emits(golabel);
XX emits("\n");
XX }
XX exit_script();
XX}
XX
XXexit_script()
XX{
XX if (script_wait == WAIT_TIMER) /* timer not done yet */
XX AbortIO((char *) &Script_Timer); /* so abort it */
XX emits("\nScript - terminated\n");
XX script_on = FALSE;
XX script_wait = TRUE;
XX fclose(sf);
XX}
XX
XX/* remove quotes terminate string & return pointer to start */
XX
XXchar *tostring(ptr)
XXchar *ptr;
XX{
XX char *s;
XX
XX s = ptr;
XX if (*ptr == '"') {
XX while(*ptr++ && *ptr !='"');
XX if (*ptr == '"') {
XX *ptr = '\0';
XX ptr = s+1;
XX while(*s++) if (*s == '|') *s = '\r';
XX return(ptr);
XX }
XX }
XX if (*s == '^') {
XX *s = *(s+1)-64;
XX *(s+1) = '\0';
XX return(s);
XX }
XX *(s+1) = '\0';
XX return(s);
XX}
XX
XXcmd_goto(lname)
XXchar *lname;
XX{
XX struct LABEL *label;
XX /* if on_cmd was a goto kill wait state */
XX if (on_match) { wait_string[0] = '\0'; script_wait = FALSE; }
XX if ((label = find_label(lname)) == NULL) { /* is it forward */
XX strcpy(golabel,lname);
XX do_script_cmd(GOTOLABEL);
XX }
XX else {
XX fseek(sf,(long)(label->pos),0);
XX }
XX}
XX
XXcmd_send(str)
XXchar *str;
XX{
XX sendstring(tostring(str));
XX}
XX
XX
XXcmd_wait(str)
XXchar *str;
XX{
XX str = tostring(str);
XX *(str+20) = '\0'; /* 20 characters max */
XX strcpy(wait_string, str);
XX waitsize = strlen(str);
XX script_wait = WAIT_STRING;
XX}
XX
XXcmd_on(str)
XXchar *str;
XX{
XX char *p;
XX
XX p = tostring(str);
XX strcpy(on_string, p);
XX onsize = strlen(p);
XX *(p+onsize+2+20) = '\0'; /* 20 characters max */
XX strcpy(on_cmd,p+onsize+2);
XX}
XX
XXcmd_delay(seconds)
XXchar *seconds;
XX{
XX script_wait = WAIT_TIMER;
XX Script_Timer.tr_time.tv_secs = atoi(seconds);
XX Script_Timer.tr_time.tv_micro = 0;
XX SendIO((char *) &Script_Timer.tr_node);
XX}
XX
XXcmd_done()
XX{
XX exit_script();
XX}
XX
XXcmd_ks(file)
XXchar *file;
XX{
XX multi_xfer(file, doksend, 1);
XX}
XX
XXcmd_kr(file)
XXchar *file;
XX{
XX multi_xfer(file, dokreceive, 0);
XX}
XX
XXcmd_kg(file)
XXchar *file;
XX{
XX server = TRUE;
XX multi_xfer(file, dokreceive, 0);
XX}
XX
XXcmd_kb()
XX{
XX saybye();
XX}
XX
XXcmd_xs(file)
XXchar *file;
XX{
XX multi_xfer(file, XMODEM_Send_File, 1);
XX}
XX
XXcmd_xr(file)
XXchar *file;
XX{
XX multi_xfer(file, XMODEM_Read_File, 1);
XX}
XX
XXcmd_cap(file)
XXchar *file;
XX{
XXdo_capture(file);
XX}
XX
XXcmd_as(file)
XXchar *file;
XX{
XXdo_send(file);
XX}
XX
XXcmd_cd(name)
XXchar *name;
XX {
XX set_dir(name);
XX }
XX
XXcmd_sb(str)
XXchar *str;
XX {
XX sendbreak();
XX }
XX
XXcmd_baud(rate)
XXchar *rate;
XX{
XX int i = atoi(rate);
XX
XX switch( i )
XX {
XX case 300:
XX case 1200:
XX case 2400:
XX case 4800:
XX case 9600:
XX setserbaud(i, TRUE);
XX break;
XX
XX default:
XX emits("\nScript - invalid baud rate: ");
XX emits(rate);
XX emits("\n");
XX break;
XX }
XX}
XX
XXcmd_parity(par)
XXchar *par;
XX{
XX int i;
XX
XX switch( *par|' ' )
XX {
XX case 'n': i = -1; break;
XX case 'e': i = 0; break;
XX case 'o': i = 1; break;
XX
XX default:
XX emits("\nScript - invalid parity: ");
XX emits(par);
XX emits("\n");
XX return;
XX }
XX if (i >= 0 && p_wordsize != 7) {
XX setserword(7, TRUE); /* Set 7-bit words if we have parity. */
XX emits("\nScript - ");
XX emits(i == 0 ? "Even" : "Odd");
XX emits(" parity requested, WORD forced to 7 bits\n");
XX }
XX setserpar(i, TRUE);
XX}
XX
XXcmd_word(wordlength)
XXchar *wordlength;
XX{
XX int i = atoi(wordlength);
XX
XX switch( i )
XX {
XX case 8:
XX if (p_parity >= 0) {
XX emits("\nScript - 8-bit WORD requested, parity forced from ");
XX emits(p_parity == 0 ? "Even" : "Odd");
XX emits(" to None\n");
XX setserpar(-1, TRUE);
XX }
XX /* Fall through to case 7: */
XX case 7:
XX setserword(i, TRUE);
XX break;
XX
XX default:
XX emits("\nScript - invalid word length: ");
XX emit(*wordlength);
XX emits("\n");
XX break;
XX }
XX}
XX
XXcmd_bt(breaklength)
XXchar *breaklength;
XX{
XX long i = atol(breaklength);
XX AbortIO(Read_Request);
XX Read_Request->io_BrkTime = Write_Request->io_BrkTime = i;
XX setparams();
XX}
XX
XXcmd_tm(tmode)
XXchar *tmode;
XX{
XX switch (*tmode|' ') {
XX case 'i':
XX p_mode = 0;
XX break;
XX
XX case 'c':
XX p_mode = 1;
XX break;
XX
XX default:
XX emits("\nScript - invalid transfer mode: ");
XX emits(tmode);
XX emits("\n");
XX return;
XX }
XX
XX ClearMenuStrip(mywindow);
XX InitXFItems();
XX SetMenuStrip(mywindow,&menu[0]);
XX}
XX
XXcmd_null(file)
XXchar *file;
XX{
XX}
XX
SHAR_EOF
if test 11733 -ne "`wc -c script.c`"
then
echo shar: error transmitting script.c '(should have been 11733 characters)'
fi
echo shar: extracting window.c
sed 's/^XX//' << \SHAR_EOF > window.c
XX/****************************************************
XX * vt100 emulator - window/keyboard support
XX *
XX * v2.1 860915 DBW - new features (see README)
XX * 860823 DBW - Integrated and rewrote lots of code
XX * v2.0 860809 DBW - Major rewrite
XX * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
XX * v1.0 860712 DBW - First version released
XX *
XX ****************************************************/
XX
XX#define MODULE_WINDOW 1
XX#include "vt100.h"
XX
XX/* forward declarations for LATTICE */
XXvoid filename();
XXvoid emits();
XXvoid emit();
XXvoid emitbatch();
XXvoid cursoroff();
XXvoid cursoron();
XX
XX/*************************************************
XX* function to get file name
XX*************************************************/
XXvoid filename(name)
XXchar name[];
XX {
XX char c;
XX ULONG class;
XX unsigned int code;
XX int keepgoing,i;
XX keepgoing = TRUE;
XX i=0;
XX while (keepgoing) {
XX while( NewMessage=(struct IntuiMessage *)GetMsg(mywindow->UserPort) )
XX {
XX class = NewMessage->Class;
XX code = NewMessage->Code;
XX ReplyMsg( NewMessage );
XX if (class=RAWKEY)
XX {
XX c = toasc(code,1);
XX name[i]=c;
XX if (name[i] != 0)
XX {
XX if (name[i] == 13)
XX {
XX name[i]=0;
XX keepgoing = FALSE;
XX }
XX else
XX {
XX if (name[i] == 8 || name[i] == 127)
XX {
XX i -= 2;
XX if (i < -1) i = -1;
XX else {
XX if (x == MINX) { y -= 8; x = MAXX; }
XX emit(8);
XX emit(32);
XX emit(8);
XX }
XX }
XX else
XX emit(c);
XX if (x == MAXX) emits("\n");
XX }
XX i += 1;
XX }
XX }
XX } /* end of new message loop */
XX } /* end of god knows what */
XX emit(13);
XX emit(10);
XX } /* end of function */
XX
XX
XX/*************************************************
XX* function to print a string
XX*************************************************/
XXvoid emits(string)
XXchar string[];
XX {
XX int i;
XX char c;
XX
XX i=0;
XX while (string[i] != 0)
XX {
XX c=string[i];
XX if (c == 10) emit(13);
XX emit(c);
XX i += 1;
XX }
XX }
XX
XX/*************************************************
XX* function to output ascii chars to window
XX*************************************************/
XXvoid emit(c)
XXchar c;
XX {
XX Move(mywindow->RPort,(long)x,(long)y);
XX
XX c &= 0x7F;
XX switch( c )
XX {
XX case '\t':
XX x += 64 - ((x-MINX) % 64);
XX break;
XX
XX case 10: /* lf */
XX y += 8;
XX break;
XX
XX case 13: /* cr */
XX x = MINX;
XX break;
XX
XX case 8: /* backspace */
XX x -= 8;
XX if (x < MINX) x = MINX;
XX break;
XX
XX case 12: /* page */
XX x = MINX;
XX y = MINY;
XX SetAPen(mywindow->RPort,0L);
XX RectFill(mywindow->RPort,(long)MINX,
XX (long)(MINY-7),(long)(MAXX+7),(long)(MAXY+1));
XX SetAPen(mywindow->RPort,1L);
XX break;
XX
XX case 7: /* bell */
XX DisplayBeep(NULL);
XX ClipBlit(mywindow->RPort,0L,0L,mywindow->RPort,0L,0L,
XX (long)MAXX,(long)MAXY,0x50L);
XX ClipBlit(mywindow->RPort,0L,0L,mywindow->RPort,0L,0L,
XX (long)MAXX,(long)MAXY,0x50L);
XX break;
XX
XX default:
XX if (c < ' ' || c > '~') break;
XX SetSoftStyle(mywindow->RPort,(long)curmode,255L);
XX if (curmode&FSF_REVERSE) {
XX SetDrMd(mywindow->RPort,(long)(JAM2+INVERSVID));
XX Text(mywindow->RPort,&c,1L);
XX SetDrMd(mywindow->RPort,(long)JAM2);
XX }
XX else Text(mywindow->RPort,&c,1L);
XX x += 8;
XX } /* end of switch */
XX
XX while (x > MAXX) x -= 8;
XX while (y > MAXY) {
XX y -= 8;
XX x = MINX;
XX ScrollRaster(mywindow->RPort,0L,8L,(long)MINX,
XX (long)(MINY-6),(long)(MAXX+7),(long)(MAXY+1));
XX }
XX }
XX
XX/*************************************************
XX* function to output ascii chars to window (batched)
XX*************************************************/
XXvoid emitbatch(la,lookahead)
XXint la;
XXchar *lookahead;
XX {
XX int i;
XX Move(mywindow->RPort,(long)x,(long)y);
XX i = x / 8;
XX if (i+la > maxcol) la = maxcol-i;
XX SetSoftStyle(mywindow->RPort,(long)curmode,255L);
XX if (curmode&FSF_REVERSE) {
XX SetDrMd(mywindow->RPort,(long)(JAM2+INVERSVID));
XX Text(mywindow->RPort,lookahead,(long)la);
XX SetDrMd(mywindow->RPort,(long)JAM2);
XX }
XX else Text(mywindow->RPort,lookahead,(long)la);
XX x += (8 * la);
XX }
XX
XX/******************************
XX* Manipulate cursor
XX******************************/
XXvoid cursoroff()
XX {
XX SetDrMd(mywindow->RPort,(long)COMPLEMENT);
XX SetAPen(mywindow->RPort,3L);
XX RectFill(mywindow->RPort,
XX (long)(x-1),(long)(y-6),(long)(x+8),(long)(y+1));
XX SetAPen(mywindow->RPort,1L);
XX SetDrMd(mywindow->RPort,(long)JAM2);
XX }
XX
XXvoid cursoron()
XX {
XX SetDrMd(mywindow->RPort,(long)COMPLEMENT);
XX SetAPen(mywindow->RPort,3L);
XX RectFill(mywindow->RPort,
XX (long)(x-1),(long)(y-6),(long)(x+8),(long)(y+1));
XX SetAPen(mywindow->RPort,1L);
XX SetDrMd(mywindow->RPort,(long)JAM2);
XX }
XX
XX/************************************************
XX* function to take raw key data and convert it
XX* into ascii chars
XX**************************************************/
XXint toasc(code,local)
XXunsigned int code;
XXint local;
XX {
XX static int ctrl = FALSE;
XX static int shift = FALSE;
XX static int capsl = FALSE;
XX static int amiga = FALSE;
XX char c = 0, keypad = 0;
XX static char keys[75] = {
XX '`','1','2','3','4','5','6','7','8','9','0','-' ,
XX '=','\\', 0, '0','q','w','e','r','t','y','u','i','o' ,
XX 'p','[',']', 0, '1','2','3','a','s','d','f','g','h' ,
XX 'j','k','l',';','\'', 0, 0, '4','5','6', 0, 'z','x','c','v',
XX 'b','n','m',44,'.','/', 0, '.','7','8','9',' ',8,
XX '\t',13,13,27,127,0,0,0,'-' } ;
XX
XX switch ( code )
XX {
XX case 98: capsl = TRUE; c = 0;break;
XX case 226: capsl = FALSE;c = 0;break;
XX case 99: ctrl = TRUE; c = 0;break;
XX case 227: ctrl = FALSE; c = 0;break;
XX case 96:
XX case 97: shift = TRUE; c = 0;break;
XX case 224:
XX case 225: shift = FALSE;c = 0;break;
XX case 102:
XX case 103: amiga = TRUE; c = 0; break;
XX case 230:
XX case 231: amiga = FALSE; c = 0; break;
XX case 0x50:
XX case 0x51:
XX case 0x52:
XX case 0x53:
XX case 0x54:
XX case 0x55:
XX case 0x56:
XX case 0x57:
XX case 0x58:
XX case 0x59: c = 0;
XX if (shift) sendstring(p_F[code - 0x50]);
XX else sendstring(p_f[code - 0x50]);
XX break;
XX case 0x0f: c = (keyapp) ? 'p' : '0'; keypad = TRUE; break;
XX case 0x1d: c = (keyapp) ? 'q' : '1'; keypad = TRUE; break;
XX case 0x1e: c = (keyapp) ? 'r' : '2'; keypad = TRUE; break;
XX case 0x1f: c = (keyapp) ? 's' : '3'; keypad = TRUE; break;
XX case 0x2d: c = (keyapp) ? 't' : '4'; keypad = TRUE; break;
XX case 0x2e: c = (keyapp) ? 'u' : '5'; keypad = TRUE; break;
XX case 0x2f: c = (keyapp) ? 'v' : '6'; keypad = TRUE; break;
XX case 0x3d: c = (keyapp) ? 'w' : '7'; keypad = TRUE; break;
XX case 0x3e: c = (keyapp) ? 'x' : '8'; keypad = TRUE; break;
XX case 0x3f: c = (keyapp) ? 'y' : '9'; keypad = TRUE; break;
XX case 0x43: c = (keyapp) ? 'M' : 13 ; keypad = TRUE; break;
XX case 0x4a: c = (keyapp) ? 'l' : '-'; keypad = TRUE; break;
XX case 0x5f: sendstring("\033Om") ;break;
XX case 0x3c: c = (keyapp) ? 'n' : '.'; keypad = TRUE; break;
XX case 0x4c:
XX case 0x4d:
XX case 0x4e:
XX case 0x4f: sendchar(27); /* cursor keys */
XX if (keyapp) sendchar('O');
XX else sendchar('[');
XX sendchar(code - 11);
XX break;
XX
XX default:
XX if (code < 75) c = keys[code];
XX else c = 0;
XX }
XX
XX if (keypad) {
XX if (keyapp) sendstring("\033O");
XX sendchar(c);
XX return(0);
XX }
XX
XX /* add modifiers to the keys */
XX
XX if (c != 0) {
XX if (shift) {
XX if ((c <= 'z') && (c >= 'a')) c -= 32;
XX else
XX switch( c ) {
XX case '[': c = '{'; break;
XX case ']': c = '}'; break;
XX case '\\': c = '|'; break;
XX case '\'': c = '"'; break;
XX case ';': c = ':'; break;
XX case '/': c = '?'; break;
XX case '.': c = '>'; break;
XX case ',': c = '<'; break;
XX case '`': c = '~'; break;
XX case '=': c = '+'; break;
XX case '-': c = '_'; break;
XX case '1': c = '!'; break;
XX case '2': c = '@'; break;
XX case '3': c = '#'; break;
XX case '4': c = '$'; break;
XX case '5': c = '%'; break;
XX case '6': c = '^'; break;
XX case '7': c = '&'; break;
XX case '8': c = '*'; break;
XX case '9': c = '('; break;
XX case '0': c = ')'; break;
XX default: break;
XX }
XX }
XX else if (capsl && (c <= 'z') && (c >= 'a')) c -= 32;
XX }
XX if (ctrl) {
XX if (c >= '`' && c <= 127) c -= 96;
XX else if (c >= '@' && c <= '_') c -= 64;
XX }
XX if (amiga && c == '.') { sendbreak(); return(0); }
XX if (c != 0 && (!local)) sendchar(c);
XX return((int)c);
XX }
XX
SHAR_EOF
if test 8147 -ne "`wc -c window.c`"
then
echo shar: error transmitting window.c '(should have been 8147 characters)'
fi
echo shar: extracting xmodem.c
sed 's/^XX//' << \SHAR_EOF > xmodem.c
XX/*************************************************************
XX * vt100 terminal emulator - XMODEM protocol support
XX *
XX * v2.1 860915 DBW - new features (see README)
XX * 860901 ACS - Added Parity and Word Length and support code
XX * 860823 DBW - Integrated and rewrote lots of code
XX * 860815 Steve Drew: readchar inproved with real timeouts
XX * v2.0 860809 DBW - Major rewrite
XX * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes
XX * v1.0 860712 DBW - First version released
XX *
XX *************************************************************/
XX
XX#define MODULE_XMODEM 1
XX#include "vt100.h"
XX
XXint enablexon = TRUE;
XX
XX/* forward declarations for LATTICE */
XXvoid sendstring();
XXvoid sendchar();
XXvoid sendbreak();
XXvoid No_XON();
XXvoid Do_XON();
XX
XXstatic unsigned long parity_settings[4] = {
XX 0x96696996,
XX 0x69969669,
XX 0x69969669,
XX 0x96696996 };
XX
XX/************************************************************
XX* Send a string (using sendchar below)
XX************************************************************/
XX
XXvoid sendstring(s)
XXchar *s;
XX {
XX char c;
XX
XX while ((c = *s++) != '\000') sendchar(c);
XX }
XX
XX/**************************************************************/
XX/* send char and read char functions for the xmodem function */
XX/************************************************************/
XXvoid sendchar(ch)
XXint ch;
XX {
XX int doxon,i,j,k;
XX
XX doxon = enablexon;
XX if (doxon) No_XON();
XX if (p_parity < 0) /* no parity */
XX rs_out[0] = ch & 0xFF;
XX else {
XX i = (ch >> 5) & 0x3;
XX j = ch & 0x1F;
XX k = ((parity_settings[i] >> j) & 0x1) << 7;
XX if (p_parity == 0) /* even parity */
XX rs_out[0] = (ch & 0x7F) | k;
XX else /* odd parity */
XX rs_out[0] = (ch & 0x7F) | (k ^ 0x80);
XX }
XX DoIO(Write_Request);
XX if (doxon) Do_XON();
XX }
XX
XX/* send a break to the host */
XXvoid sendbreak() {
XX AbortIO(Read_Request);
XX Read_Request->IOSer.io_Command = SDCMD_BREAK;
XX DoIO(Read_Request);
XX Read_Request->IOSer.io_Command = CMD_READ;
XX SendIO(Read_Request);
XX }
XX
XXint readchar()
XX {
XX int rd,ch;
XX
XX Timer.tr_time.tv_secs = ttime;
XX Timer.tr_time.tv_micro = 0;
XX SendIO((char *) &Timer.tr_node);
XX
XX rd = FALSE;
XX while (rd == FALSE)
XX {
XX Wait((1L << Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit) |
XX ( 1L << mywindow->UserPort->mp_SigBit) |
XX ( 1L << Timer_Port->mp_SigBit));
XX if (CheckIO(Read_Request))
XX {
XX WaitIO(Read_Request);
XX ch=rs_in[0];
XX rd = TRUE;
XX SendIO(Read_Request);
XX }
XX if (NewMessage=(struct IntuiMessage *)GetMsg(mywindow->UserPort)) {
XX if ((NewMessage->Class == RAWKEY) && (NewMessage->Code == 69))
XX {
XX AbortIO((char *) &Timer);
XX Wait (1L << Timer_Port->mp_SigBit);
XX if (want_message)
XX emits("\nUser aborted transfer\n");
XX timeout = USERABORT;
XX return('\0');
XX }
XX continue;
XX }
XX if (rd == FALSE && CheckIO(&Timer)) {
XX if (want_message)
XX emits("\nTimeout waiting for character\n");
XX timeout = TIMEOUT;
XX return('\0');
XX }
XX } /* end while */
XX AbortIO((char *) &Timer);
XX Wait (1L << Timer_Port->mp_SigBit);
XX timeout = GOODREAD;
XX return(ch & 0xFF);
XX }
XX
XXvoid No_XON() {
XX
XX /* turn off XON/XOFF processing */
XX enablexon = FALSE;
XX Write_Request->io_SerFlags |= SERF_XDISABLED;
XX Write_Request->IOSer.io_Command = SDCMD_SETPARAMS;
XX DoIO(Write_Request);
XX Write_Request->IOSer.io_Command = CMD_WRITE;
XX }
XX
XXvoid Do_XON() {
XX /* turn on XON/XOFF processing */
XX enablexon = TRUE;
XX Write_Request->io_SerFlags &= ~SERF_XDISABLED;
XX Write_Request->IOSer.io_Command = SDCMD_SETPARAMS;
XX DoIO(Write_Request);
XX Write_Request->IOSer.io_Command = CMD_WRITE;
XX }
XX
XX/**************************************/
XX/* xmodem send and recieve functions */
XX/************************************/
XX
XXint XMODEM_Read_File(file)
XXchar *file;
XX {
XX int firstchar, sectnum, sectcurr, sectcomp, errors, errorflag;
XX unsigned int checksum, j, bufptr;
XX char numb[10];
XX bytes_xferred = 0L;
XX ttime = TTIME_SHORT;
XX want_message = TRUE; /* tell readchar to print any error msgs */
XX
XX if ((fd = creat(file, 0)) < 0)
XX {
XX emits("Cannot Open File\n");
XX return FALSE;
XX }
XX else
XX emits("Receiving File\n\nType <ESC> to abort transfer\n");
XX
XX sectnum = errors = bufptr = 0;
XX sendchar(NAK);
XX firstchar = 0;
XX No_XON();
XX while (firstchar != EOT && errors != ERRORMAX)
XX {
XX errorflag = FALSE;
XX
XX do { /* get sync char */
XX firstchar = readchar();
XX if (timeout != GOODREAD) {
XX if (timeout == USERABORT || errors++ == ERRORMAX)
XX Do_XON();
XX return FALSE;
XX }
XX } while (firstchar != SOH && firstchar != EOT);
XX
XX if (firstchar == SOH)
XX {
XX emits(blanks);
XX emits("\rGetting Block ");
XX sprintf(numb, "%d", sectnum);
XX emits(numb);
XX emits("...");
XX sectcurr = readchar();
XX if (timeout != GOODREAD) { Do_XON(); return FALSE; }
XX sectcomp = readchar();
XX if (timeout != GOODREAD) { Do_XON(); return FALSE; }
XX if ((sectcurr + sectcomp) == 255)
XX {
XX if (sectcurr == ((sectnum + 1) & 0xff))
XX {
XX checksum = 0;
XX for (j = bufptr; j < (bufptr + SECSIZ); j++)
XX {
XX bufr[j] = readchar();
XX if (timeout != GOODREAD) { Do_XON(); return FALSE; }
XX checksum = (checksum + bufr[j]) & 0xff;
XX }
XX if (checksum == readchar() && timeout == GOODREAD)
XX {
XX errors = 0;
XX sectnum++;
XX bufptr += SECSIZ;
XX bytes_xferred += SECSIZ;
XX emits("verified\r");
XX if (bufptr == BufSize)
XX {
XX if (write(fd, bufr, BufSize-128) == EOF)
XX {
XX emits("\nError Writing File\n");
XX Do_XON();
XX return FALSE;
XX }
XX bufptr = 128;
XX for (j = 0; j < 128; j++)
XX bufr[j] = bufr[(BufSize-128)+j];
XX }
XX sendchar(ACK);
XX }
XX else
XX {
XX errorflag = TRUE;
XX if (timeout == USERABORT) { Do_XON(); return FALSE; }
XX }
XX }
XX else
XX {
XX /* got a duplicate sector */
XX if (sectcurr == (sectnum & 0xff))
XX {
XX /* wait until we time out for 5secs */
XX do {
XX readchar();
XX } while (timeout == GOODREAD);
XX if (timeout == USERABORT) {
XX Do_XON();
XX return FALSE;
XX }
XX emits("\nReceived Duplicate Sector\n");
XX sendchar(ACK);
XX }
XX else errorflag = TRUE;
XX }
XX }
XX else errorflag = TRUE;
XX }
XX if (errorflag == TRUE)
XX {
XX errors++;
XX emits("\nError\n");
XX sendchar(NAK);
XX }
XX } /* end while */
XX if ((firstchar == EOT) && (errors < ERRORMAX))
XX {
XX sendchar(ACK);
XX while (bufptr > 0 && (bufr[--bufptr] == 0x00 ||
XX bufr[bufptr] == 0x1A)) ;
XX write(fd, bufr, ++bufptr);
XX close(fd);
XX Do_XON();
XX return TRUE;
XX }
XX Do_XON();
XX return FALSE;
XX }
XX
XXint XMODEM_Send_File(file)
XXchar *file;
XX {
XX int sectnum, bytes_to_send, size, attempts, c;
XX unsigned checksum, j, bufptr;
XX char numb[10];
XX bytes_xferred = 0;
XX ttime = TTIME_LONG;
XX want_message = TRUE; /* tell readchar to print any error msgs */
XX
XX if ((fd = open(file, 0)) < 0) {
XX emits("Cannot Open Send File\n");
XX return FALSE;
XX }
XX else
XX emits("Sending File\n\nType <ESC> to abort transfer\n");
XX attempts = 0;
XX sectnum = 1;
XX No_XON();
XX /* wait for sync char */
XX j=1;
XX while (((c = readchar()) != NAK) && (j++ < ERRORMAX))
XX if (timeout == USERABORT) { Do_XON(); return(FALSE); }
XX if (j >= (ERRORMAX))
XX {
XX emits("\nReceiver not sending NAKs\n");
XX Do_XON();
XX return FALSE;
XX }
XX
XX while ((bytes_to_send = read(fd, bufr, BufSize)) && attempts != RETRYMAX)
XX {
XX if (bytes_to_send == EOF)
XX {
XX emits("\nError Reading File\n");
XX Do_XON();
XX return FALSE;
XX }
XX
XX bufptr = 0;
XX while (bytes_to_send > 0 && attempts != RETRYMAX)
XX {
XX attempts = 0;
XX emits(blanks);
XX emits("\rBlock ");
XX sprintf(numb, "%d ", sectnum);
XX emits(numb);
XX do {
XX emits(".");
XX sendchar(SOH);
XX sendchar(sectnum);
XX sendchar(~sectnum);
XX checksum = 0;
XX size = SECSIZ <= bytes_to_send ? SECSIZ : bytes_to_send;
XX bytes_to_send -= size;
XX for (j = bufptr; j < (bufptr + SECSIZ); j++)
XX if (j < (bufptr + size)) {
XX sendchar(bufr[j]);
XX checksum += bufr[j];
XX }
XX else sendchar(0);
XX sendchar(checksum);
XX attempts++;
XX c = readchar();
XX if (timeout == USERABORT) {
XX emits("\n");
XX Do_XON();
XX return FALSE;
XX }
XX } while ((c != ACK) && (attempts != RETRYMAX));
XX bufptr += size;
XX bytes_xferred += size;
XX emits(" sent\r");
XX sectnum++;
XX }
XX }
XX close(fd);
XX if (attempts == RETRYMAX)
XX {
XX emits("\nNo Acknowledgment Of Sector, Aborting\n");
XX Do_XON();
XX return FALSE;
XX }
XX else
XX {
XX attempts = 0;
XX do {
XX sendchar(EOT);
XX attempts++;
XX } while ((readchar() != ACK) &&
XX (attempts != RETRYMAX) &&
XX (timeout != USERABORT)) ;
XX if (attempts == RETRYMAX)
XX emits("\nNo Acknowledgment Of End Of File\n");
XX }
XX Do_XON();
XX return TRUE;
XX }
XX
SHAR_EOF
if test 9012 -ne "`wc -c xmodem.c`"
then
echo shar: error transmitting xmodem.c '(should have been 9012 characters)'
fi
# End of shell archive
exit 0
Technical Details
Message-ID:
<2119@j.cc.purdue.edu>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!qantel!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!docShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!qantel!ihnp4!inuxc!pur-ee!j.cc.purdue.edu!doc From: doc@j.cc.purdue.edu Newsgroups: mod.amiga.sources Subject: VT100 Terminal Emulator (V2.1 DBW 860915) Part 2 of 2 Message-ID: <2119@j.cc.purdue.edu> Date: Tue, 23-Sep-86 10:58:18 EDT Article-I.D.: j.2119 Posted: Tue Sep 23 10:58:18 1986 Date-Received: Wed, 24-Sep-86 00:58:53 EDT Sender: doc@j.cc.purdue.edu Organization: Purdue University Computing Center Lines: 2554 Approved: doc@j.cc.purdue.edu