Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!hao!gatech!purdue!i.cc.purdue.edu!j.cc.purdue.edu!ahh From: ahh@j.cc.purdue.edu (Brent L. Woods) Newsgroups: comp.sources.amiga Subject: vt100 version 2.8 Message-ID: <6495@j.cc.purdue.edu> Date: 25 Feb 88 10:36:51 GMT Organization: Co-Moderators Unlimited. Lines: 2353 Keywords: tested, see notes, part 3 of 4 Approved: ahh@j.cc.purdue.edu (Brent Woods) Program Name: vt100 (version 2.8) Submitted By: acs@uts.amdahl.com (Tony Sumrall) Summary: vt100 terminal emulator. Poster Boy: Brent Woods (ahh@j.cc.purdue.edu) Tested. Part 3 of 4. NOTES: This program was tested by our Guest Moderator, Robert Tillotson. He had a couple of problems with the program at first (a couple of Guru errors, and we think that the vt100 task hung around instead of exiting properly; not certain, though), but when we (Rob, Pat, and I) tested it a few hours ago, none of us had any problems. I dunno. It seems to work okay now. Probably some fluke or other. Brent Woods, Co-Moderator, comp.{sources,binaries}.amiga USENET: ...!j.cc.purdue.edu!ahh ARPANET: ahh@j.cc.purdue.edu BITNET: PODUM@PURCCVM PHONE: +1 (317) 743-8421 USNAIL: 320 Brown St., #406 / West Lafayette, IN 47906 ====================================cut here============================ #! /bin/sh # # This is a shell archive. Save this into a file, edit it # and delete all lines above this comment. Then give this # file to sh by executing the command "sh file". The files # will be extracted into the current directory owned by # you with default permissions. # # The files contained herein are: # # -rw-r--r-- 1 acs other 10384 Feb 1 18:54 remote.c # -rw-r--r-- 1 acs other 24586 Feb 1 18:55 script.c # -rw-r--r-- 1 acs other 22122 Feb 1 18:56 vt100.c # echo 'x - remote.c' if test -f remote.c; then echo 'shar: not overwriting remote.c'; else sed 's/^X//' << '________This_Is_The_END________' > remote.c X/**************************************************** X * vt100 emulator - remote character interpretation X * X * v2.8 880117 ACS - See the README file X * v2.7 870227 ACS - No changes to this routine. X * v2.6 870227 DBW - bug fixes for all the stuff in v2.5 X * v2.5 870214 DBW - more additions (see readme file) X * v2.4 861214 DBW - lots of fixes/additions (see readme file) X * v2.3 861101 DBW - minor bug fixes X * v2.2 861012 DBW - more of the same X * v2.1 860915 DBW - new features (see README) X * 860823 DBW - Integrated and rewrote lots of code X * v2.0 860803 DRB - Rewrote the control sequence parser X * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes X * v1.0 860712 DBW - First version released X * X ****************************************************/ X X#include "vt100.h" X Xstatic int p[10]; Xstatic int numpar; Xstatic char escseq[40]; X X/************************************************ X* function to handle remote characters X*************************************************/ Xvoid doremote(c) Xchar c; X { X if (c == 24) { inesc = 0; inctrl = 0; return; } X if (c == 27 || (inesc >= 0 && c >= ' ')) { doesc(c); return; } X if (inctrl >= 0 && c >= ' ') { doctrl(c); return; } X if (c == 10 || c == 11 || c == 12) { X if (nlmode) doindex('E'); else doindex('D'); X return; X } X if (c == 13) { X if (!nlmode) emit(c); X return; X } X if (c == 15) { alt = 0; return; } X if (c == 14) { alt = 1; return; } X if (a[alt] && c > 94 && c < 127) { doalt(c); return; } X emit(c); X } X Xvoid doesc(c) Xchar c; X{ X if (inesc < 0) { inesc = 0; return; } X if (c == 27 || c == 24) { inesc = -1; return; } X if (c < ' ' || c == 127) return; /* Ignore control chars */ X X /* Collect intermediates */ X if (c < '0') {escseq[inesc++] = c; return; } X X /* by process of elimination, we have a final character. X Put it in the buffer, and dispatch on the first character X in the buffer */ X X escseq[inesc] = c; X inesc = -1; /* No longer collecting a sequence */ X switch (escseq[0]) /* Dispatch on the first received */ X { X case '[': /* Control sequence introducer */ X numpar = 0; /* No parameters yet */ X private = 0; /* Not a private sequence (yet?) */ X badseq = 0; /* Good until proven bad */ X p[0] = p[1] = 0; /* But default the first parameter */ X inctrl = 0; /* We are in a control sequence */ X return; /* All done for now ... */ X X case 'D': case 'E': case 'M': /* Some kind of index */ X doindex (c); /* Do the index */ X return; /* Return */ X X case '7': /* Save cursor position */ X savx = x; savy = y; savmode = curmode; savalt = alt; X sa[0] = a[0]; sa[1] = a[1]; X return; X X case '8': /* Restore cursor position */ X x = savx; y = savy; alt = savalt; curmode = savmode; X a[0] = sa[0]; a[1] = sa[1]; X return; X X case 'c': /* Reset */ X top = MINY; bot = MAXY; savx = MINX; savy = MINY; X curmode = FS_NORMAL; p_keyapp = 0; p_curapp = 0; X inesc = -1; X a[0] = 0; a[1] = 0; sa[0] = 0; sa[1] = 0; X redoutil(); X emit(12); X return; X X case '(': /* Change character set */ X if (c == '0' || c == '2') a[0] = 1; else a[0] = 0; X return; X X case ')': /* Change the other character set */ X if (c == '0' || c == '2') a[1] = 1; else a[1] = 0; X return; X X case '=': /* set keypad application mode */ X p_keyapp = 1; X redoutil(); X return; X X case '>': /* reset application mode */ X p_keyapp = 0; X redoutil(); X return; X X case 'Z': X sendchar(27); sendstring("[?1;7c"); return; X X /* If we didn't match anything, we can just return, happy in the X knowledge that we've at least eaten the whole sequence */ X X } /* End of switch */ X return; X} X Xvoid doctrl(c) Xchar c; X{ X int i; X X if (c == 27 || c == 24) { inctrl = -1; return; } X if (c < ' ' || c == 127) return; /* Ignore control chars */ X X /* First, look for some parameter characters. If the very first X parameter character isn't a digit, then we have a X private sequence */ X X if (c >= '0' && c < '@') X { X /* can't have parameters after intermediates */ X if (inctrl > 0) {badseq++ ; return; } X switch (c) X { X case '0': case '1': case '2': case '3': case '4': X case '5': case '6': case '7': case '8': case '9': X p[numpar] = p[numpar] * 10 + (c - '0'); X return; X X case ';': X p[++numpar] = 0; /* Start a new parameter */ X return; X X case '<': case '=': case '>': case '?': /* Can only mean private */ X X /* Only allowed BEFORE parameters */ X if (inctrl == 0) private = c; X return; X X /* if we come here, it's a bad sequence */ X } X badseq++; /* Flag the bad sequence */ X } X X if (c < '0') /* Intermediate character */ X { X escseq[inctrl++] = c; /* Save the intermediate character */ X return; X } X X /* if we get here, we have the final character. Put it in the X escape sequence buffer, then dispatch the control sequence */ X X numpar++; /* Reflect the real number of parameters */ X escseq[inctrl++] = c; /* Store the final character */ X escseq[inctrl] = '\000'; /* Tie off the buffer */ X inctrl = -1; /* End of the control sequence scan */ X X /* Don't know how to do most private sequences right now, X so just punt them */ X X if ((private != 0 && private != '?') || badseq != 0) return; X if (private == '?' && escseq[0] != 'h' && X escseq[0] != 'l') return; X X switch (escseq[0]) /* Dispatch on first intermediate or final */ X { X case 'A': if (p[0]<=0) p[0] = 1; X y -= 8*p[0]; if (ybot) y = bot; return; X case 'C': if (p[0]<=0) p[0] = 1; X x += 8*p[0]; if (x>MAXX) x = MAXX; return; X case 'D': if (p[0]<=0) p[0] = 1; X x -= 8*p[0]; if (x MAXY) y = MAXY; X if (x > MAXX) x = MAXX; X if (y < MINY) y = MINY; X if (x < MINX) x = MINX; X return; X X case 'L': /* ANSI insert line */ X case 'M': /* ANSI delete line */ X if (p[0] <= 0) p[0] = 1; X ScrollRaster(mywindow->RPort,0L, X (long)((escseq[0] == 'M' ? 8L : -8L) * p[0]), X (long)MINX,(long)y-6,(long)(MAXX+7),(long)bot+1); X return; X X case '@': /* Insert characters */ X case 'P': /* Delete characters */ X if (p[0] <= 0) p[0] = 1; X ScrollRaster(mywindow->RPort, X (long) ((escseq[0] == 'P'? 8 : -8)) * p[0], 0L, X (long) x, (long) y-6, X (long) MAXX+7, (long) y+1); X return; X X case 'r': /* Set scroll region */ X if (p[0] <= 0) p[0] = 1; X if (p[1] <= 0) p[1] = p_lines; X top = (--p[0]*8)+MINY; bot = (--p[1]*8)+MINY; X if (top < MINY) top = MINY; X if (bot > MAXY) bot = MAXY; X if (top > bot) { top = MINY; bot = MAXY; } X x = MINX; y = MINY; X return; X X case 'm': /* Set graphic rendition */ X for (i=0;iRPort,0L); X if (p[0] == 0) { X if (y < MAXY) RectFill(mywindow->RPort, X (long)MINX,(long)(y+2),(long)(MAXX+7),(long)(MAXY+1)); X } X else if (p[0] == 1) { X if (y > MINY) RectFill(mywindow->RPort, X (long)MINX,(long)(MINY-6),(long)(MAXX+7),(long)(y-7)); X } X else RectFill(mywindow->RPort, X (long)MINX,(long)(MINY-6),(long)(MAXX+7),(long)(MAXY+1)); X SetAPen(mywindow->RPort,1L); X doerase(); return; X X case 'h': /* Set parameter */ X if (private == 0 && p[0] == 20) nlmode = 1; X else if (private == '?') { X if (p[0] == 7) p_wrap = 1; X else if (p[0] == 1) p_curapp = 1; X redoutil(); X } X return; X X case 'l': /* Reset parameter */ X if (private == 0 && p[0] == 20) nlmode = 0; X else if (private == '?') { X if (p[0] == 7) p_wrap = 0; X else if (p[0] == 1) p_curapp = 0; X redoutil(); X } X return; X X case 'x': X sendchar(27); sendstring("[3;1;8;64;64;1;0x"); return; X X case 'n': X if (p[0] == 6) { X sendchar(27); X sprintf(escseq,"[%d;%dR",((y-MINY)/8)+1,((x-MINX)/8)+1); X sendstring(escseq); return; X } X sendchar(27); sendstring("[0n"); return; X X case 'c': X sendchar(27); sendstring("[?1;7c"); return; X } X X /* Don't know how to do this one, so punt it */ X} X Xvoid doindex(c) Xchar c; X { X if (c != 'M') { X if (c == 'E') x = MINX; X if (y > bot) if (y < MAXY) y += 8; X if (y == bot) X ScrollRaster(mywindow->RPort,0L,8L,(long)MINX,(long)(top-6), X (long)(MAXX+7),(long)(bot+1)); X if (y < bot) y += 8; X } X else { X if (y < top) if (y > MINY) y -= 8; X if (y == top) X ScrollRaster(mywindow->RPort,0L,-8L,(long)MINX,(long)(top-6), X (long)(MAXX+7),(long)(bot+1)); X if (y > top) y -= 8; X } X return; X } X Xdoalt(c) Xchar c; X { X int oldx,newx; X inesc = -1; X oldx = x; emit(' '); newx = x; X x = oldx; X SetAPen(mywindow->RPort,1L); X switch (c) { X case 'a': X doline(0,-6,8,1); X break; X X case 'j': X case 'm': X case 'v': doline(4,-6,4,-2); X if (c=='j') doline(0,-2,4,-2); X else if (c=='m') doline(4,-2,8,-2); X else doline(0,-2,8,-2); X break; X X case 'k': X case 'l': X case 'w': doline(4,-2,4,1); X if (c=='k') doline(0,-2,4,-2); X else if (c=='l') doline(4,-2,8,-2); X else doline(0,-2,8,-2); X break; X X case 'n': X case 'q': doline(0,-2,8,-2); X if (c=='n') doline(4,-6,4,2); X break; X X case 't': X case 'u': X case 'x': doline(4,-6,4,1); X if (c=='t') doline(4,-2,8,-2); X else if (c=='u') doline(0,-2,4,-2); X break; X } X x = newx; X } X Xdoline(x1,y1,x2,y2) { X RectFill(mywindow->RPort,(long)(x+x1),(long)(y+y1), X (long)(x+x2),(long)(y+y2)); X } X Xvoid doerase() X { X if (p[0] < 0) p[0] = 0; X SetAPen(mywindow->RPort,0L); X if (p[0] == 0) RectFill(mywindow->RPort,(long)x,(long)(y-6), X (long)(MAXX+7),(long)(y+1)); X else if (p[0] == 1) RectFill(mywindow->RPort, X (long)MINX,(long)(y-6),(long)(x+7),(long)(y+1)); X else RectFill(mywindow->RPort, X (long)MINX,(long)(y-6),(long)(MAXX+7),(long)(y+1)); X SetAPen(mywindow->RPort,1L); X return; X } X ________This_Is_The_END________ if test `wc -l < remote.c` -ne 398; then echo 'shar: remote.c was damaged during transit (should have been 398 bytes)' fi fi ; : end of overwriting check echo 'x - script.c' if test -f script.c; then echo 'shar: not overwriting script.c'; else sed 's/^X//' << '________This_Is_The_END________' > script.c X/************************************************************* X * vt100 terminal emulator - Script file support X * X * v2.8 880117 ACS - See the README file X * v2.7 870825 ACS - Wait for the reply from AbortIO(). X * Use the *InfoMsg*() routines in window.c. Provide X * for multiple script files on command line X * (companion to the changes in init.c). Add the X * ability to set shortcuts from init file. X * v2.6 870227 DBW - bug fixes for all the stuff in v2.5 X * v2.5 870214 DBW - more additions (see readme file) X * v2.4 861214 DBW - lots of fixes/additions (see readme file) X * v2.3 861101 DBW - minor bug fixes X * v2.2 861012 DBW - more of the same X * v2.1 860915 DBW - new features (see README) X * 860901 ACS - Added BAUD, PARITY and WORD commands & handling X * 860823 DBW - Integrated and rewrote lots of code X * 860815 Steve Drew: Initial version written of SCRIPT.C X * v2.0 860809 DBW - Major rewrite X * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes X * v1.0 860712 DBW - First version released X * X *************************************************************/ X X#include "vt100.h" X X#define FONTNAMESIZE 40 X#define FONTSUFFIX ".font" X#define MAXFONTVARLEN 34 /* 40 minus sizeof(".font") */ X Xchar myfontname[FONTNAMESIZE]; X Xstruct COMMAND { X void (*func)(); X char *cname; X}; X Xstruct LABEL { X struct LABEL *next; X char *name; X long pos; X}; X Xextern long atol(); X Xstruct SHORT_CUTS { X char *cname; X char *pos; X}; X X/* Following variables are set up in init.c's InitDefaults. They tell X** us if there are any other script files listed on the command line so X** that we can execute them when a prior script is done. */ X Xextern int script_files_todo; Xextern char **script_files; X X/**************** globals needed ******************/ X Xchar on_string[20]; /* string to match on for on cmd */ Xchar wait_string[20]; /* string to match of for wait cmd */ Xchar golabel[20]; /* label we are looking for in goto */ Xchar on_cmd[20]; /* command to execute when on matchs*/ Xint onsize; /* size of on_string */ Xint waitsize; /* size of wait_string */ Xint onpos; /* position in on string for search */ Xint waitpos; /* pos in wait_string for search */ Xint on_match; /* flag set while doing on_cmd */ XFILE *sf; /* file pointer for script file */ Xstruct LABEL *lbase = NULL; /* will point to first label */ Xstruct LABEL *labels; /* current label pointer */ X Xvoid cmd_short(); X X/********************** command tables *******************************/ Xstatic struct COMMAND inicmds[] = { /* initialization commands */ X cmd_bkg, "bac", /* set background color */ X cmd_bold, "bol", /* set bold color */ X cmd_buf, "buf", /* set buffer size */ X cmd_cursor, "cur", /* set cursor color */ X cmd_depth, "dep", /* set screen depth */ X cmd_fore, "for", /* set foreground color */ X cmd_font, "fon", /* set font */ X cmd_inter, "int", /* interlace ON/OFF */ X cmd_lines, "lin", /* num lines */ X cmd_screen, "scr", /* Screen WB/CUST */ X cmd_unit, "unit", /* Unit of serial.device to use */ X cmd_volume, "vol", /* set volume */ X cmd_wb, "wb", /* use WB colors */ X cmd_short, "sho", /* Set shortcuts */ X cmd_null, NULL /* mark the end of the list */ X}; Xstatic struct COMMAND scrcmds[] = { /* script only commands */ X cmd_as, "asc", /* ascii send */ X cmd_beep, "bee", /* Beep */ X cmd_cap, "cap", /* ascii capture on/off */ X cmd_cd, "cd", /* change directory */ X cmd_delay, "del", /* delay amount of seconds */ X cmd_goto, "got", /* goto label */ X cmd_kb, "kb", /* kermit bye (for server) */ X cmd_kg, "kg", /* kermit get file */ X cmd_kr, "kr", /* kermit receive file */ X cmd_ks, "ks", /* kermit send file */ X cmd_on, "on", /* on a 'string' do a cmd */ X cmd_recf, "recf", /* receive a file from host */ X cmd_sb, "sb", /* Send a break */ X cmd_send, "send", /* send string to host */ X cmd_sendf, "sendf", /* send a file to host */ X cmd_xr, "xr", /* xmodem receive file */ X cmd_xs, "xs", /* xmodem send file */ X cmd_wait, "wait", /* wait for a host string */ X cmd_null, NULL /* mark the end of the list */ X}; Xstatic struct COMMAND commands[]= { /* generally available commands */ X cmd_appcur, "app", /* turn app. cursor on/off */ X cmd_baud, "bau", /* Set Baud Rate */ X cmd_bt, "bre", /* Set Break Time */ X cmd_conv, "con", /* convert fn to lowercase */ X cmd_echo, "ech", /* turn echo on or off */ X cmd_exit, "exi", /* exit script file */ X cmd_fnc, "f", /* define function key */ X cmd_key, "key", /* keyscript character */ X cmd_kmaxpk, "kmaxpack", /* Kermit maximum packet size */ X cmd_mode, "mod", /* KERMIT transfer mode */ X cmd_numkey, "numkey", /* turn numeric kpad on/off */ X cmd_parity, "parity", /* Set Parity */ X cmd_swap, "swap", /* Swap BS and DEL */ X cmd_wrap, "wrap", /* turn wrap on or off */ X cmd_xbeep, "xbee", /* Beep at end of xfer */ X cmd_xproto, "xproto", /* Xfer Protocol */ X cmd_null, NULL /* mark the end of the list */ X}; X Xchar *xprotos[] = { /* Order *must* be same as corresponding p_xproto values */ X "ascii", "xmodem", "xmodemcrc", "kermit" }; X X/* NB: The structures referenced in the structure may be found in X** init.c */ Xextern struct filecmd { X char mo; /* Mode */ X char se; /* Send */ X char re; /* Receive */ X char kg; /* Kermit Get */ X char kb; /* Kermit Bye */ X char ca; /* Capture or Capturing */ X char nl; X} filecmd_chars; X Xextern struct mode_cmd { X char as; /* ascii mode */ X char xm; /* xmodem mode */ X char xmc; /* xmodem crc mode */ X char ke; /* kermit mode */ X char nl; X} modecmd_chars; X Xextern struct baducmd { X char b03; /* 0300 */ X char b12; /* 1200 */ X char b24; /* 2400 */ X char b48; /* 4800 */ X char b96; /* 9600 */ X char bnl; X} baudcmd_chars; X Xextern struct parcmd { X char no; /* NOne */ X char ma; /* MArk */ X char sp; /* SPace */ X char ev; /* EVen */ X char od; /* ODd */ X char nl; X} parcmd_chars; X Xextern struct modcmd { X char im; /* IMage */ X char tx; /* TeXt */ X char cn; /* CoNvert */ X char nl; X} modcmd_chars; X Xextern struct scrcmd { X char em; /* Execute Macro */ X char ab; /* Abort Macro */ X char nl; X} scrcmd_chars; X Xextern struct { X char sb; /* Send Break */ X char hu; /* Hang Up */ X char cd; /* Change Dir */ X char cs; /* Clear Screen */ X char ec; /* ECho */ X char wr; /* WRap */ X char nk; /* Num Key */ X char ac; /* App Cur */ X char bs; /* BS<->DEL */ X char xb; /* Beep at end of Xfer */ X char nl; X} utilcmd_chars; X Xstatic struct SHORT_CUTS shortkeys[] = { /* Short-cut keys */ X /* File items: */ X "se", &(filecmd_chars.se), /* Send file */ X "re", &(filecmd_chars.re), /* Receive file */ X "kb", &(filecmd_chars.kb), /* kermit bye (for server) */ X "kg", &(filecmd_chars.kg), /* kermit get (for server) */ X "cap", &(filecmd_chars.ca), /* Capture */ X /* Mode items: */ X "asc", &(modecmd_chars.as), /* ascii mode */ X "xm", &(modecmd_chars.xm), /* xmodem mode */ X "ke", &(modecmd_chars.ke), /* kermit mode */ X "xmc", &(modecmd_chars.xmc), /* xmodemcrc mode */ X /* Comm items: */ X "300", &(baudcmd_chars.b03), /* Set Baud Rate */ X "1200", &(baudcmd_chars.b12), /* Set Baud Rate */ X "2400", &(baudcmd_chars.b24), /* Set Baud Rate */ X "4800", &(baudcmd_chars.b48), /* Set Baud Rate */ X "9600", &(baudcmd_chars.b96), /* Set Baud Rate */ X "none", &(parcmd_chars.no), /* Set Parity */ X "mark", &(parcmd_chars.ma), /* Set Parity */ X "space", &(parcmd_chars.sp), /* Set Parity */ X "even", &(parcmd_chars.ev), /* Set Parity */ X "odd", &(parcmd_chars.od), /* Set Parity */ X "image", &(modcmd_chars.im), /* KERMIT transfer mode */ X "text", &(modcmd_chars.tx), /* KERMIT transfer mode */ X "convert", &(modcmd_chars.cn), /* KERMIT transfer mode */ X /* Script items: */ X "execute", &(scrcmd_chars.em), /* execute macro */ X "abort", &(scrcmd_chars.ab), /* abort macro */ X /* Util items: */ X "sb", &(utilcmd_chars.sb), /* send break */ X "hang", &(utilcmd_chars.hu), /* hang up */ X "cd", &(utilcmd_chars.cd), /* change directory */ X "clear", &(utilcmd_chars.cs), /* clear screen */ X "ech", &(utilcmd_chars.ec), /* turn echo on or off */ X "wrap", &(utilcmd_chars.wr), /* turn wrap on or off */ X "numkey", &(utilcmd_chars.nk), /* turn numeric kpad on/off */ X "app", &(utilcmd_chars.ac), /* turn app. cursor on/off */ X "con", &(utilcmd_chars.bs), /* convert bs to del */ X "swap", &(utilcmd_chars.bs), /* Swap BS and DEL */ X "xbeep", &(utilcmd_chars.xb), /* Beep at end of xfer */ X NULL, NULL X}; X X/********************************************************************/ X/* checks char to see if match with on string or wait_string */ X/* if on string match oncmd gets executed imediately, */ X/* if wait_string match script_wait is set. */ X/********************************************************************/ X Xchk_script(c) Xchar c; X{ X if (on_string[0] != '\0') { X if (on_string[onpos] == c) { X onpos++; X if (onpos == onsize) { X on_match = TRUE; X do_script_cmd(ONCOMMAND); X on_match = FALSE; X return(0); X } X } X else onpos = 0; X } X if (wait_string[0] != '\0') { X if (wait_string[waitpos] != c) { X waitpos = 0; X return(0); X } X waitpos++; X if (waitpos != waitsize) return(0); X wait_string[0] = '\0'; X script_wait = FALSE; X } X} X Xscript_start(file) Xchar *file; X{ X char *sfile = NULL; X X if (strlen(file) == 0 || *file == '#') return(0); X if ((sf = fopen(file, "r")) == NULL) { X sfile = AllocMem((LONG)(strlen(file)+3), MEMF_PUBLIC|MEMF_CLEAR); X strcpy(sfile, "S:"); X strcat(sfile, file); X if((sf = fopen(sfile, "r")) == NULL) { X InfoMsg2Line("Can't open script file",file); X return(0); X } X } X script_on = TRUE; X script_wait = FALSE; X wait_string[0] = '\0'; X on_string[0] = '\0'; X on_match = FALSE; X lbase = NULL; X if(sfile) X FreeMem(sfile, (LONG)strlen(file)+3); X} X X/* return pointer to next word. set l to size of the word */ X Xchar *next_wrd(s,l) Xchar *s; Xint *l; X{ X char *p; X X while(*s && (*s == ' ' || *s == '\t')) s++; X p = s; X while(*s && (*s != ' ' && *s != '\t')) s++; X *l = s-p; X return(p); X} X Xexe_cmd(p,l) Xchar *p; Xint l; X{ X int i,l2; X X /* downcase the command */ X for (i=0; i= l2 && strncmp(p, inicmds[i].cname, l2) == 0) { X (*inicmds[i].func)(next_wrd(p+l, &l)); X return(TRUE); X } X } X X /* or the script command list */ X else X for (i=0; scrcmds[i].func != cmd_null; ++i) { X l2 = strlen(scrcmds[i].cname); X if (l >= l2 && strncmp(p, scrcmds[i].cname, l2) == 0) { X (*scrcmds[i].func)(next_wrd(p+l, &l)); X return(TRUE); X } X } X X /* now search for it (in the standard command list) */ X for (i=0; commands[i].func != cmd_null; ++i) { X l2 = strlen(commands[i].cname); X if (l >= l2 && strncmp(p, commands[i].cname, l2) == 0) { X (*commands[i].func)(next_wrd(p+l, &l)); X return(TRUE); X } X } X if (doing_init) { X puts("Init: unknown command:"); X puts(p); X } X else InfoMsg2Line("Script - unknown command:",p); X X return(FALSE); X} X Xstruct LABEL *find_label(lname) Xchar *lname; X{ X struct LABEL *label; X X label = lbase; X while(label != NULL) { X if (strcmp(label->name, lname) == 0) return (label); X label = label->next; X } X return(NULL); X} X Xdo_script_cmd(stat) Xint stat; X{ X int len,l; X char line[256]; X char *p; X X /* if ON command is matched and we were */ X /* doing a DELAY then abort the delay timer,*/ X /* except if on_cmd was just a SEND. */ X if (stat == ONCOMMAND) { X strcpy(line,on_cmd); X p = next_wrd(line,&l); X if (*p != 's' && script_wait == WAIT_TIMER) { X if(!CheckIO(&Script_Timer)) X AbortIO((char *) &Script_Timer); X Wait (1L << Script_Timer_Port->mp_SigBit); X WaitIO(&Script_Timer); X X /* script will proceed after on command */ X script_wait = FALSE; X } X exe_cmd(p,l); X return(0); X } X script_wait = FALSE; X while(fgets(line,256,sf) != NULL) { X len = strlen(line); X line[--len] = '\0'; X p = next_wrd(&line[0], &l); X if (*(p + l - 1) == ':') { /* its a label */ X *(p + l - 1) = '\0'; X if (find_label(p) == NULL) { /* it's a new label */ X if (lbase == NULL) { /* it's the first label */ X labels = lbase = (struct LABEL *) X malloc(sizeof (struct LABEL)); X } X else { X labels->next = (struct LABEL *) X malloc(sizeof (struct LABEL)); X labels = labels->next; X } X labels->pos = ftell(sf); X labels->name = malloc(l); X labels->next = NULL; X strcpy(labels->name, p); X if (stat == GOTOLABEL && strcmp(p, golabel) == 0) X stat = NEXTCOMMAND; X } X p = next_wrd(p+l+1, &l); X } /* end of it's a label */ X if (stat == GOTOLABEL || *p == '#') continue; X if (*p) exe_cmd(p,l); X return(0); X } /* end of while */ X if (stat == GOTOLABEL) InfoMsg2Line("Script: label not found:",golabel); X exit_script(); X if(script_files_todo > 0) { X script_files_todo--; X script_start(*(script_files++)); X } X} X Xexit_script() X{ X if (script_wait == WAIT_TIMER) { /* timer not done yet */ X if(!CheckIO(&Script_Timer)) X AbortIO((char *) &Script_Timer); /* so abort it */ X Wait (1L << Script_Timer_Port->mp_SigBit); /* Wait for the sig */ X WaitIO(&Script_Timer); /* Get my reply back */ X } X InfoMsg1Line("Script: terminated"); X script_on = FALSE; X script_wait = TRUE; X fclose(sf); X if (reqwinup && ((reqwindow->Flags) & WINDOWACTIVE)) X ActivateWindow(mywindow); X} X X/* remove quotes terminate string & return pointer to start */ X Xchar *tostring(ptr) Xchar *ptr; X{ X char *s1,*s2; X X s1 = ptr; X if (*ptr == '"') { X while(*ptr++ && *ptr != '"') ; X if (*ptr == '"') { X *ptr = '\0'; X ptr = s2 = ++s1; X while(*s2) { X if (*s2 != '^') *s1++ = *s2; X else if (*(s2+1) == '^') *s1++ = *s2++; X else *s1++ = ((*++s2)|' ')-96; X s2++; X } X *s1 = '\0'; X return(ptr); X } X } X if (*s1 == '^') { X *s1 = (*(s1+1)|' ')-96; X *(s1+1) = '\0'; X return(s1); X } X *(s1+1) = '\0'; X return(s1); X} X X/***************************** SCRIPT COMMANDS ********************/ X Xvoid cmd_goto(lname) Xchar *lname; X{ X struct LABEL *label; X /* if on_cmd was a goto kill wait state */ X if (on_match) { wait_string[0] = '\0'; script_wait = FALSE; } X if ((label = find_label(lname)) == NULL) { /* is it forward */ X strcpy(golabel,lname); X do_script_cmd(GOTOLABEL); X } X else { X fseek(sf,(long)(label->pos),0); X } X} X Xvoid cmd_send(str) Xchar *str; X{ X sendstring(tostring(str)); X} X Xvoid cmd_wait(str) Xchar *str; X{ X str = tostring(str); X *(str+20) = '\0'; /* 20 characters max */ X strcpy(wait_string, str); X waitsize = strlen(str); X script_wait = WAIT_STRING; X} X Xvoid cmd_on(str) Xchar *str; X{ X char *p; X X p = tostring(str); X strcpy(on_string, p); X onsize = strlen(p); X *(p+onsize+2+20) = '\0'; /* 20 characters max */ X strcpy(on_cmd,p+onsize+2); X} X Xvoid cmd_delay(seconds) Xchar *seconds; X{ X script_wait = WAIT_TIMER; X Script_Timer.tr_time.tv_secs = atoi(seconds); X Script_Timer.tr_time.tv_micro = 0; X SendIO((char *) &Script_Timer.tr_node); X} X Xvoid cmd_exit(option) Xchar *option; X{ X char *p; X int l; X X if (doing_init) return; X X if (*option) { X p = next_wrd(option,&l); X *(p+l) = '\000'; X if (strcmp(p,"vt100") == 0 || strcmp(p,"VT100") == 0) X cleanup("Exit vt100 from script",0); X exit_script(); X script_start(p); X } X else { X exit_script(); X if(script_files_todo > 0) { X script_files_todo--; X script_start(*(script_files++)); X } X } X} X Xvoid cmd_ks(file) Xchar *file; X{ X char name[80], *p; X X name[0] = '\0'; X if(file == NULL || *file == '\0') { X req("Kermit Send:",name,1); X p = name; X } X else p = file; X multi_xfer(p, doksend, 1); X} X Xvoid cmd_kr(file) Xchar *file; X{ X char name[80]; X X name[0] = '\0'; X X multi_xfer(name, dokreceive, 0); X} X Xvoid cmd_kg(file) Xchar *file; X{ X char name[80], *p; X X name[0] = 0; X server = TRUE; X if(file == NULL || *file == '\0') { X req("Kermit GET remote file(s):", name, 1); X p = name; X } X else p = file; X multi_xfer(p, dokreceive, 0); X} X Xvoid cmd_kb() X{ X saybye(); X} X Xvoid cmd_recf(file) Xchar *file; X{ X switch(p_xproto) { X case 0: /* Ascii */ X do_capture(file); X break; X case 1: /* Xmodem */ X case 2: /* XmodemCRC */ X if(p_parity > 0) { X InfoMsg1Line("Parity setting prevents XMODEM receive."); X break; X } X cmd_xr(file); X break; X case 3: /* Kermit */ X default: X cmd_kr(file); X break; X } X} X Xvoid cmd_sendf(file) Xchar *file; X{ X switch(p_xproto) { X case 0: /* Ascii */ X do_send(file); X break; X case 1: /* Xmodem */ X case 2: /* XmodemCRC */ X if(p_parity > 0) { X InfoMsg1Line("Parity setting prevents XMODEM send."); X break; X } X cmd_xs(file); X break; X case 3: /* Kermit */ X default: X cmd_ks(file); X break; X } X} X Xvoid cmd_xs(file) Xchar *file; X{ X char name[80], *p; X X name[0] = '\0'; X if(file == NULL || *file == '\0') { X req("Xmodem Send:",name,1); X p = name; X } X else p = file; X multi_xfer(p, XMODEM_Send_File, 1); X} X Xvoid cmd_xr(file) Xchar *file; X{ X char name[80], *p; X X name[0] = '\0'; X if(file == NULL || *file == '\0') { X req("Xmodem Receive:",name,1); X p = name; X } X else p = file; X multi_xfer(p, XMODEM_Read_File, 1); X} X Xvoid cmd_cd(name) Xchar *name; X{ X set_dir(name); X} X Xvoid cmd_sb(str) Xchar *str; X{ X sendbreak(); X} X Xvoid cmd_baud(rate) Xchar *rate; X{ X int i = atoi(rate); X X switch( i ) { X case 300: X case 1200: X case 2400: X case 4800: X case 9600: X if (doing_init) p_baud = i; X else setserbaud(i, TRUE); X break; X X default: X if (doing_init) { X puts("Init: invalid baud rate:"); X puts(rate); X } X else InfoMsg2Line("Script: invalid baud rate: ",rate); X break; X } X} X Xvoid cmd_parity(par) Xchar *par; X{ X int i; X X switch( *par|' ' ) { X case 'n': i = 0; break; X case 'm': i = 1; break; X case 's': i = 2; break; X case 'e': i = 3; break; X case 'o': i = 4; break; X X default: X if (doing_init) { X puts("Init: invalid parity:"); X puts(par); X } X else InfoMsg2Line("Script: invalid parity: ",par); X return; X } X p_parity = i; X if (doing_init == 0) redocomm(); X X} X Xvoid cmd_bt(breaklength) Xchar *breaklength; X{ X p_break = atol(breaklength); X if (doing_init) return; X X AbortIO(Read_Request); X Wait(1L << Read_Request->IOSer.io_Message.mn_ReplyPort->mp_SigBit); X WaitIO(Read_Request); X Read_Request->io_BrkTime = Write_Request->io_BrkTime = p_break; X setparams(); X} X Xvoid cmd_kmaxpk(pks) Xchar *pks; X{ X int i = atoi(pks); X X if(i <= MAXLONGPKS) X p_kmaxpack = i; X else { X if(doing_init) { X puts("Init: Kermit packet size too big:"); X puts(pks); X } X else InfoMsg2Line("Script: Kermit packet size too big: ",pks); X } X} X Xvoid cmd_mode(tmode) Xchar *tmode; X{ X switch (*tmode|' ') { X case 'i': X p_mode = 0; X break; X X case 'c': X p_mode = 1; X break; X X default: X if (doing_init) { X puts("Init: invalid transfer mode:"); X puts(tmode); X } X else X InfoMsg2Line("Script: invalid transfer mode: ",tmode); X return; X } X if (doing_init == 0) redocomm(); X} X Xvoid cmd_as(file) Xchar *file; X{ X do_send(file); X} X Xvoid cmd_cap(file) Xchar *file; X{ X do_capture(file); X} X Xvoid cmd_beep(dummy) Xchar *dummy; X{ X if (p_volume == 0) DisplayBeep(NULL); X else { X BeginIO(&Audio_Request); X WaitIO(&Audio_Request); X } X} X Xvoid setvar(par,typ,var) Xchar *par; Xint typ,*var; X{ X int i; X X switch (typ) { X case 0: /* ON/OFF or YES/NO */ X case 1: /* not case */ X if ((par[1]|' ') == 'n' || (par[0]|' ') == 'y') *var = 1-typ; X else *var = typ; X break; X X case 2: /* read hex number */ X if (sscanf(par,"%x",&i) == 1) *var = i; X X break; X X case 3: /* read decimal number */ X if (sscanf(par,"%d",&i) == 1) *var = i; X break; X } X} X Xvoid cmd_echo(par) Xchar *par; X{ X setvar(par,0,&p_echo); X if (doing_init == 0) redoutil(); X} X Xvoid cmd_wrap(par) Xchar *par; X{ X setvar(par,0,&p_wrap); X if (doing_init == 0) redoutil(); X} X Xvoid cmd_xbeep(par) Xchar *par; X{ X setvar(par,0,&p_xbeep); X if (doing_init == 0) redoutil(); X} X Xvoid cmd_xproto(par) Xchar *par; X{ X int i, l = strlen(par); X char temp[40]; X X /* downcase the parameter */ X for(i=0; i= MODEMAX) { X p_xproto = MODEMAX - 1; X sprintf(temp, "XPROTO \"%.10s\" unknown, %s used", par, &(*(xprotos[p_xproto]))); X if(doing_init) { X puts("Init:"); X puts(temp); X } X else X InfoMsg2Line("Script:", temp); X } X if(doing_init == 0) redofile(); X} X Xvoid cmd_numkey(par) Xchar *par; X{ X setvar(par,1,&p_keyapp); X if (doing_init == 0) redoutil(); X} X Xvoid cmd_appcur(par) Xchar *par; X{ X setvar(par,0,&p_curapp); X if (doing_init == 0) redoutil(); X} X Xvoid cmd_swap(par) Xchar *par; X{ X setvar(par,0,&p_bs_del); X if (doing_init == 0) X redoutil(); /* Calls InitUtilItems which does swap_bs_del() */ X else { X swap_bs_del(); /* Setup keys[] properly... */ X swap_bs_del(); /* ...for new mode */ X } X} X Xvoid cmd_bkg(par) Xchar *par; X{ X setvar(par,2,&p_background); X} X Xvoid cmd_bold(par) Xchar *par; X{ X setvar(par,2,&p_bold); X} X Xvoid cmd_buf(par) Xchar *par; X{ X setvar(par,3,&p_buffer); X} X Xvoid cmd_cursor(par) Xchar *par; X{ X setvar(par,2,&p_cursor); X} X Xvoid cmd_depth(par) Xchar *par; X{ X setvar(par,3,&p_depth); X} X Xvoid cmd_fore(par) Xchar *par; X{ X setvar(par,2,&p_foreground); X} X Xvoid cmd_font(par) Xchar *par; X{ X char temp[80]; X X /* myfontname has been initialized from p_font in InitDefaults() in X ** init.c */ X X if(*par) { X if(strlen(par) < MAXFONTVARLEN) { X strcpy(myfontname, par); X strcat(myfontname,FONTSUFFIX); X } X else { X puts("Init:"); X sprintf(temp, "Font specification too long, \"%s\" used", myfontname); X puts(temp); X } X } X myattr.ta_Name = (STRPTR)myfontname; X} X Xvoid cmd_inter(par) Xchar *par; X{ X setvar(par,0,&p_interlace); X} X Xvoid cmd_lines(par) Xchar *par; X{ X setvar(par,3,&p_lines); X} X Xvoid cmd_screen(par) Xchar *par; X{ X if ((par[0]|' ') == 'w') p_screen = 0; X else p_screen = 1; X} X Xvoid cmd_unit(par) Xchar *par; X{ X setvar(par, 3, &p_unit); X} X Xvoid cmd_wb(par) Xchar *par; X{ X setvar(par,0,&p_wbcolors); X} X Xvoid cmd_short(par) /* Set keyboard shortcuts */ Xchar *par; X{ X int i, l, l2; X register char *p = par; X X /* downcase the next word */ X for (i=0; p[i] && (p[i] != ' ') && (p[i] != '\t'); i++) p[i] |= ' '; X l = i; X X /* Find the command name. If found set the shortcut key to the X ** user's value. If no value then set the key to ' ' to indicate no X ** shortcur available. */ X for(i = 0; shortkeys[i].cname != NULL; i++) { X l2 = strlen(shortkeys[i].cname); X if (l >= l2 && strncmp(p, shortkeys[i].cname, l2) == 0) { X for( ; p[l] && ((p[l] == ' ') || (p[l] == '\t')) ; l++) ; X if(p[l]) X *(shortkeys[i].pos) = p[l]; X else X *(shortkeys[i].pos) = ' '; X return; X } X } X if(doing_init) { X puts("Init: Unknown shortcut: "); X puts(par); X } X else X InfoMsg2Line("Script: Unknown shortcut:", par); X} X Xvoid cmd_key(par) Xchar *par; X{ X int i; X X if (sscanf(par,"%x",&i) == 1) p_keyscript = (char)(i & 0x7f); X} X Xvoid cmd_volume(par) Xchar *par; X{ X setvar(par,3,&p_volume); X} X Xvoid cmd_conv(par) Xchar *par; X{ X setvar(par,0,&p_convert); X if (doing_init == 0) redoutil(); X} X Xvoid cmd_fnc(par) Xchar *par; X{ X char *s; X int l; X int i = atoi(par); X X s = par; X if (*s) s = next_wrd(s,&l); /* skip key number */ X if (*s) s = next_wrd(s+l+1,&l); /* point at desired string */ X if (*s) s = tostring(s); /* convert the string */ X if (*s && i > 0 && i < 21) { X if (i > 10) { X p_F[i-11] = malloc(strlen(s)+1); X strcpy(p_F[i-11],s); X } X else { X p_f[i-1] = malloc(strlen(s)+1); X strcpy(p_f[i-1],s); X } X } X} X Xvoid cmd_null(dummy) Xchar *dummy; X{ } X ________This_Is_The_END________ if test `wc -l < script.c` -ne 1090; then echo 'shar: script.c was damaged during transit (should have been 1090 bytes)' fi fi ; : end of overwriting check echo 'x - vt100.c' if test -f vt100.c; then echo 'shar: not overwriting vt100.c'; else sed 's/^X//' << '________This_Is_The_END________' > vt100.c X/******************************************************************** X * vt100 terminal emulator with xmodem transfer capability X * X * v2.8 880117 ACS - See the README file X * v2.7 870825 ACS - Provide handling of the msgs from the X * info/status window. X * v2.6 870227 DBW - bug fixes for all the stuff in v2.5 X * v2.5 870214 DBW - more additions (see readme file) X * v2.4 861214 DBW - lots of fixes/additions (see readme file) X * v2.3 861101 DBW - minor bug fixes X * v2.2 861012 DBW - more of the same X * v2.1 860915 DBW - new features (see README) X * 860901 ACS - Added Parity and Word Length and support code X * 860823 DBW - Integrated and rewrote lots of code X * v2.0 860809 DBW - Major rewrite X * v1.1 860720 DBW - Switches, 80 cols, colors, bug fixes X * v1.0 860712 DBW - First version released X * X * use to abort xmodem or kermit transfers X * X * written by Michael Mounier X * new version by Dave Wecker X *******************************************************************/ X X/* all includes defines and globals */ X#include "vt100.h" X XAPTR OrigWindowPtr; /* Used by init.c when opening a new screen */ X X/**************************************************************/ X/* here are all the global definitions that appear in vt100.h */ X/**************************************************************/ X Xchar bufr[BufSize]; Xint fd, timeout = FALSE, ttime; Xint multi = FALSE, server; Xlong bytes_xferred; Xchar MyDir[60]; XBPTR StartLock = 0; Xstruct IntuitionBase *IntuitionBase; Xstruct GfxBase *GfxBase; X Xextern char myfontname[]; /* In script.c */ X Xstruct TextAttr myattr = { X (STRPTR)(&(myfontname[0])), X 8, X 0, X 0}; Xstruct TextFont *myfont = NULL; Xstruct NewScreen NewScreen = { X 0,0,640,200,1, /* left, top, width, height, depth */ X 0,1,HIRES, /* DetailPen, BlockPen, ViewModes */ X CUSTOMSCREEN,&myattr, /* Type, Font */ X (UBYTE *)"VT100", /* Title */ X NULL,NULL }; /* Gadgets, Bitmap */ Xstruct NewWindow NewWindow = { X 0,0,640,200, /* left, top, width, height */ X 0,1, /* detailpen, blockpen */ X MENUPICK|CLOSEWINDOW|RAWKEY|ACTIVEWINDOW|INACTIVEWINDOW, X SMART_REFRESH|ACTIVATE|BORDERLESS|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG, X NULL,NULL, /* FirstGadget, CheckMark */ X (UBYTE *)NULL, X NULL, /* set screen after open screen */ X NULL, /* bitmap */ X 640, 200, 640, 200, /* minw, minh, maxw, maxh */ X CUSTOMSCREEN /* Type */ X }; Xstruct NewWindow NewReqWindow = { X 10, 15, ((54*8)+4+18), ((4*8)+11+2), /* left, top, width, height */ X 0, 1, /* detailpen, blockpen */ X /* IDCMP Flags... */ X CLOSEWINDOW | ACTIVEWINDOW | REQCLEAR | REQSET | NEWSIZE, X /* Flags... */ X SMART_REFRESH | NOCAREREFRESH | ACTIVATE | WINDOWSIZING | SIZEBRIGHT | X WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG, X X NULL, /* First gadget */ X NULL, /* CheckMark */ X (UBYTE *)"VT100 Info & Xfer Status", /* Title */ X NULL, /* set screen after open screen */ X NULL, /* bitmap */ X ((5*8)+4+18), ((1*8)+11+2), 640, 200, /* minw, minh, maxw, maxh */ X CUSTOMSCREEN /* Type */ X }; Xstruct IntuiText MyTitle = { X 0,1,JAM2,26,0, /* front pen, back pen, mode, left, top */ X &myattr, /* font */ X (UBYTE *)VERSION, /* title */ X NULL}; /* next text */ X Xstruct Screen *myscreen = NULL; /* ptr to applications screen */ Xstruct Window *mywindow = NULL; /* ptr to applications window */ Xstruct Window *reqwindow = NULL; /* ptr to requester's window */ Xstruct ViewPort *myviewport; Xstruct RastPort *myrastport; Xstruct IntuiMessage *NewMessage; /* msg structure for GetMsg() */ Xstruct Preferences *Prefs; /* preferences from GetPrefs() */ X X/**** String requester support ******/ X Xchar InpBuf[80],UndoBuf[80],Prompt[80]; Xstruct IntuiText donetxt = { X 1,0,JAM2,0,0, /* front pen, back pen, mode, left, top */ X &myattr, /* font */ X (UBYTE *)"DONE", /* question to ask */ X NULL}; /* next text */ Xstruct Gadget mydonegad = { X &mystrgad,290,2,40,10, /* next,left,top,width,height */ X GADGHCOMP|REQGADGET, /* flags */ X RELVERIFY|ENDGADGET, /* activation */ X BOOLGADGET, /* gadget type */ X NULL,NULL,&donetxt, /* gad render, sel render, gad text */ X 0L,NULL,2,NULL}; /* mutual exclude, special, ID, user data */ Xstruct StringInfo mystrinfo = { X (UBYTE *)InpBuf, X (UBYTE *)UndoBuf, X 0,80,0,0,0,0, /* initial, max, disp, undo, #chrs, dsp chrs */ X 0,0,NULL,0L,NULL}; /* left,top,layer,longint,keymap */ Xstruct Gadget mystrgad = { X NULL,10,12,320,10, /* next,left,top,width,height */ X GADGHCOMP|REQGADGET,/* flags */ X ENDGADGET,STRGADGET,/* activation, type */ X NULL,NULL,NULL, /* gad render, sel render, gad text */ X 0L, /* mutual exclude */ X (APTR)&mystrinfo, /* special info */ X 1,NULL}; /* gadget ID, user data */ Xstruct IntuiText mystrtxt = { X 0,1,JAM2,10,2, /* front pen, back pen, mode, left, top */ X &myattr, /* font */ X (UBYTE *)Prompt, /* question to ask */ X NULL}; /* next text */ Xstruct Requester myrequest = { X NULL,5,10,340,22, /* older requester, left, top, width, height */ X 0,0,&mydonegad, /* relleft reltop, gadgets */ X NULL, /* border */ X &mystrtxt, /* text */ X NULL,1,NULL, /* flags, back fill pen, layer */ X {0,0,0,0,0,0,0,0, X 0,0,0,0,0,0,0,0, X 0,0,0,0,0,0,0,0, X 0,0,0,0,0,0,0,0}, /* pad1 */ X NULL,NULL, /* image bit map, rquest window */ X {0,0,0,0,0,0,0,0,0, X 0,0,0,0,0,0,0,0,0, X 0,0,0,0,0,0,0,0,0, X 0,0,0,0,0,0,0,0,0} /* pad2 */ X }; X Xint numreqs = 0; /* number of outstanding requestors */ Xint reqwinup = 0; /* Requester window is NOT displayed */ Xextern int reqmaxx, reqmaxy, reqmaxlen; /* Defined in window.c */ Xextern void ReqNewSize(); /* New req window size -- window.c */ Xextern void KillReq(); /* Kill requester window in window.c */ X X/***** menu structures *****/ Xstruct MenuItem FileItem[FILEMAX]; Xstruct IntuiText FileText[FILEMAX]; Xstruct MenuItem ModeItem[MODEMAX]; Xstruct IntuiText ModeText[MODEMAX]; Xstruct MenuItem CommItem[COMMAX]; Xstruct IntuiText CommText[COMMAX]; Xstruct MenuItem RSItem[RSMAX]; Xstruct IntuiText RSText[RSMAX]; Xstruct MenuItem ParItem[PARMAX]; Xstruct IntuiText ParText[PARMAX]; Xstruct MenuItem XFItem[XFMAX]; Xstruct IntuiText XFText[XFMAX]; Xstruct MenuItem ScriptItem[SCRIPTMAX]; Xstruct IntuiText ScriptText[SCRIPTMAX]; Xstruct MenuItem UtilItem[UTILMAX]; Xstruct IntuiText UtilText[UTILMAX]; Xstruct Menu menu[MAXMENU]; Xstruct IOExtSer *Read_Request; Xchar *rs_in; Xstruct IOExtSer *Write_Request; Xchar rs_out[2]; Xstruct timerequest Timer; Xstruct MsgPort *Timer_Port = NULL; Xstruct timerequest Script_Timer; Xstruct MsgPort *Script_Timer_Port = NULL; Xstruct IOAudio Audio_Request; Xstruct MsgPort *Audio_Port = NULL; XUBYTE *BeepWave; XUBYTE Audio_AllocMap[4] = { 1, 8, 2, 4 }; Xint x,y,curmode; Xint MINX = 0; Xint MAXX = 632; Xint MINY = 14; Xint MAXY = 198; Xint top = 14; Xint bot = 198; Xint savx = 0; Xint savy = 14; Xint savmode = 0; Xint nlmode = 0; Xint alt = 0; Xint savalt = 0; Xint a[2] = { 0, 0 }; Xint sa[2] = { 0, 0 }; Xint inesc = -1; Xint inctrl = -1; Xint private = 0; Xint badseq = 0; Xint maxcol = 79; X X/*************************** defaults *******************************/ Xchar *p_font = "topaz"; /* Default font. Name must be < 34 chars */ Xint p_baud = 1200; /* baud rate */ Xint p_screen = 0; /* 0 = WORKBENCH, 1 = CUSTOM */ Xint p_wbcolors = 1; /* 0 = Custom, 1 = Workbench colors */ Xint p_interlace = 0; /* 0 = no interlace, 1 = interlace */ Xint p_depth = 2; /* number of bit planes (1 or 2) */ Xint p_foreground = 0x840; /* default foreground RGB color */ Xint p_background = 0x000; /* default background RGB color */ Xint p_bold = 0x000; /* default BOLD RGB color */ Xint p_cursor = 0x00d; /* default Cursor RGB color */ Xint p_lines = 24; /* 0 == use all available (MoreRows) */ Xint p_mode = 0; /* 0 = image, 1 = CRLF (for kermit) */ Xint p_unit = 0; /* unit of serial.device to open */ Xint p_xproto = 3; /* 0=ASCII, 1=Xmodem, 2=XmodemCRC, 3 = Kermit */ Xint p_buffer = 512; /* read buffer size (>= 512 bytes) */ Xint p_parity = 0; /* 0=none,1=mark,2=space,3=even,4=odd */ Xlong p_break = 750000; /* break time (in micro seconds) */ Xint p_volume = 64; /* beep volume (0 = DisplayBeep) */ Xint p_wrap = 1; /* 0 = truncate, 1 = wrap long lines */ Xint p_keyapp = 0; /* 0 = numeric, 1 = application keypad */ Xint p_curapp = 0; /* 0 = cursor, 1 = application cursor */ Xint p_echo = 0; /* 0 = full duplex, 1 = half duplex */ Xint p_bs_del = 0; /* 0 = normal, 1 = swap bs and delete */ Xint p_convert = 0; /* 1 = convert filenames to lower case */ Xint p_kmaxpack = 1000; /* Max packet size for Kermit xfers */ X/* Must be <= 1000. <= 94 is standard, > 94 requires a kermit capable X** of long packet support. */ Xint p_xbeep = 1; /* 1 = beep at end of xfer */ Xchar p_keyscript = 0x7E; /* function key script introducer = ~ */ Xchar *p_f[10] = { /* function key defaults */ X "\033OP","\033OQ","\033OR","\033OS", X "f5","f6","f7","f8","f9","f10" }; X Xchar *p_F[10] = { /* shifted function key defaults */ X "F1","F2","F3","F4","F5", X "F6","F7","F8","F9","F10"}; X X/* for script file */ Xint script_on; Xint script_wait; Xint doing_init = 0; X X/******************************************************/ X/* Main Program */ X/* */ X/* This is the main body of the program. */ X/******************************************************/ X Xchar lookahead[80]; XFILE *tranr = NULL; XFILE *trans = NULL; Xint capture,send; Xchar name[80]; Xstruct MsgPort *mySerPort; X Xmain(argc,argv) Xint argc; Xchar **argv; X { X ULONG class, waitmask; X unsigned int code, qual; X APTR iaddr; X int KeepGoing,i,la,dola,actual, len; X char c,*ptr; X char ascstr[100]; /* Area for string returned by toasc() */ X X ptr = InitDefaults(argc,argv); X InitDevs(); X InitFileItems(); X InitCommItems(); X InitScriptItems(); X InitUtilItems(); X InitMenu(); X SetMenuStrip(mywindow,&menu[0]); X PrintIText(mywindow->RPort,&MyTitle,0L,0L); X X MyDir[0] = '\000'; X StartLock = ((struct Process *) FindTask(NULL))->pr_CurrentDir; X CurrentDir(DupLock(StartLock)); X KeepGoing = TRUE; X capture = FALSE; X send = FALSE; X maxcol = MAXX / 8; X la = 0; X x = MINX ; X y = MINY; X curmode = FS_NORMAL; X script_on = FALSE; X script_wait= TRUE; X SetAPen(mywindow->RPort,1L); X cursorflip(); X cursorflip(); X emit(12); X mySerPort = Read_Request->IOSer.io_Message.mn_ReplyPort; X SendIO(Read_Request); X X /* see if we had a startup script */ X if (ptr != NULL) script_start(ptr); X X while( KeepGoing ) X { X /* wait for window message or serial port message */ X cursorflip(); X if(reqwinup) X waitmask = (1L << mySerPort->mp_SigBit) | X (1L << mywindow->UserPort->mp_SigBit) | X (1L << Script_Timer_Port->mp_SigBit) | X (1L << reqwindow->UserPort->mp_SigBit); X else X waitmask = (1L << mySerPort->mp_SigBit) | X (1L << mywindow->UserPort->mp_SigBit) | X (1L << Script_Timer_Port->mp_SigBit); X if (script_wait) /* if script ready dont wait here */ X Wait(waitmask); X cursorflip(); X X /* do ascii file send */ X if (send) X { X if ((c=getc(trans)) != EOF) { X if (c == '\n') c = '\r'; X sendchar(c); X } X else { X fclose(trans); X InfoMsg1Line("File Sent"); X send=FALSE; X } X } X X /* see if there are any characters from the host */ X if (CheckIO(Read_Request)) { X WaitIO(Read_Request); X c = rs_in[0] & 0x7F; X doremote(c); X if (script_on) chk_script(c); X if (capture && c != 10) { X if (c == 13) c = 10; X putc(c , tranr); X } X Read_Request->IOSer.io_Command = SDCMD_QUERY; X DoIO(Read_Request); X Read_Request->IOSer.io_Command = CMD_READ; X actual = (int)Read_Request->IOSer.io_Actual; X if (actual > 0) { X if (inesc < 0 && X inctrl < 0 && X a[alt] == 0 && X capture == FALSE) dola = 1; X else dola = 0; X Read_Request->IOSer.io_Length = X Read_Request->IOSer.io_Actual; X DoIO(Read_Request); X Read_Request->IOSer.io_Length = 1; X X for (i = 0; i < actual; i++) { X c=rs_in[i] & 0x7f; X if (script_on) chk_script(c); X X if (dola == 1) { X if (c >= ' ' && c <= '~' && la < 80) X lookahead[la++] = c; X else { X if (la > 0) { X emitbatch(la,lookahead); X la = 0; X } X doremote(c); X dola = 0; X } X } X else { X doremote(c); X if (inesc < 0 && X inctrl < 0 && X a[alt] == 0 && X capture == FALSE) dola = 1; X if (capture && c != 10) { X if (c == 13) c = 10; X putc(c , tranr); X } X } X } X X /* dump anything left in the lookahead buffer */ X if (la > 0) { X emitbatch(la,lookahead); X la = 0; X } X } X SendIO(Read_Request); X } X X while((NewMessage = X (struct IntuiMessage *)GetMsg(mywindow->UserPort)) X != FALSE) { X class = NewMessage->Class; X code = NewMessage->Code; X qual = NewMessage->Qualifier; X if(class == RAWKEY) X iaddr = *((APTR *)NewMessage->IAddress); X ReplyMsg( NewMessage ); X switch( class ) X { X case CLOSEWINDOW: X KeepGoing = FALSE; X break; X X case RAWKEY: X len = toasc(&(ascstr[0]), code,qual, 100, iaddr, 0); X if (p_echo) { X ptr = &(ascstr[0]); X for(i = 0; i < len; i++) X doremote(*(ptr++)); X } X break; X X case NEWSIZE: X emit(12); X break; X X case MENUPICK: X handle_menupick(class,code); X break; X X default: X PrintIText(mywindow->RPort,&MyTitle,0L,0L); X break; X } /* end of switch (class) */ X } /* end of while ( newmessage )*/ X X if (!script_wait || X (CheckIO(&Script_Timer) && X script_wait == WAIT_TIMER)) X do_script_cmd(NEXTCOMMAND); X X while( reqwinup && X ((NewMessage = (struct IntuiMessage *) X GetMsg(reqwindow->UserPort)) != FALSE) X ) { X class = NewMessage->Class; X ReplyMsg( NewMessage ); X switch( class ) { X case REQCLEAR: X numreqs = 0; X break; X X case CLOSEWINDOW: X KillReq(); /* Kills requester window, set reqwinup = 0 */ X break; X X case NEWSIZE: X ReqNewSize(reqwindow->Height, reqwindow->Width); X break; X } /* end of switch (class) */ X } /* end while */ X } /* end while ( keepgoing ) */ X X /* It must be time to quit, so we have to clean X * up and exit. X */ X X cleanup("",0); X X} /* end of main */ X X/* cleanup code */ X Xcleanup(reason, fault) Xchar *reason; Xint fault; X { X extern struct Device *ConsoleDevice; /* In init.c */ X extern struct IOStdReq ConReq; /* In init.c */ X X switch(fault) { X case 0: /* quitting close everything */ X KillReq(); /* Kill the requester and its window */ X ClearMenuStrip( mywindow ); X CloseDevice(&Audio_Request); X UnLock(CurrentDir(StartLock)); /* back to original directory */ X X case 8: /* error opening audio */ X DeletePort(Audio_Port); X FreeMem(BeepWave,BEEPSIZE); X CloseDevice(&Timer); X X case 7: /* error opening timer */ X DeletePort(Timer_Port); X CloseDevice(&Script_Timer); X DeletePort(Script_Timer_Port); X X case 6: /* error opening write device */ X DeletePort(Write_Request->IOSer.io_Message.mn_ReplyPort); X FreeMem(Write_Request,(long)sizeof(*Write_Request)); X CloseDevice(Read_Request); X X case 5: /* error opening read device */ X DeletePort(Read_Request->IOSer.io_Message.mn_ReplyPort); X FreeMem(Read_Request,(long)sizeof(*Read_Request)); X X case 4: /* error opening window */ X if (ConsoleDevice != NULL) CloseDevice(&ConReq); X if (myfont != NULL) CloseFont( myfont ); X if (mywindow != NULL) CloseWindow( mywindow ); X if (p_screen != 0) { X struct Process *mproc; X X mproc = (struct Process *)FindTask(0L); X mproc->pr_WindowPtr = OrigWindowPtr; X CloseScreen( myscreen ); X } X X case 3: /* error opening screen */ X case 2: /* error opening graphics library */ X CloseLibrary(GfxBase); X case 1: /* error opening intuition */ X CloseLibrary(IntuitionBase); X default: X if (*reason) puts (reason); X } X exit(fault); X } X Xdo_capture(file) Xchar *file; X { X if (capture == TRUE) X { X capture=FALSE; X fclose(tranr); X InfoMsg1Line("End File Capture"); X } X else X { X if (file == NULL || *file == '\0') { X name[0] = '\000'; X req("Ascii Capture:",name,1); X } X else strcpy(name, file); X if ((tranr=fopen(name,"w")) == 0) { X capture=FALSE; X InfoMsg2Line("Error Opening File:", name); X return(FALSE); X } X capture=TRUE; X } X redofile(); X } X Xdo_send(file) Xchar *file; X { X if (send == TRUE) X { X send=FALSE; X fclose(trans); X InfoMsg1Line("File Send Cancelled"); X } X else X { X if (file == NULL || *file == '\0') { X name[0] = '\000'; X req("Ascii Send:",name,1); X } X else strcpy(name, file); X if ((trans=fopen(name,"r")) == 0) { X send=FALSE; X InfoMsg2Line("Error Opening File:", name); X return(FALSE); X } X send=TRUE; X } X } X Xvoid setparams() X { X Read_Request->IOSer.io_Command = X Write_Request->IOSer.io_Command = X SDCMD_SETPARAMS; X DoIO(Read_Request); DoIO(Write_Request); X Read_Request->IOSer.io_Command = CMD_READ; X SendIO(Read_Request); X Write_Request->IOSer.io_Command = CMD_WRITE; X } X Xvoid hangup () X { X if(!CheckIO(Read_Request)) X AbortIO(Read_Request); X Wait (1L <mp_SigBit); X WaitIO(Read_Request); X CloseDevice (Read_Request); X Timer.tr_time.tv_secs=0L; X Timer.tr_time.tv_micro=750000L; X DoIO((char *) &Timer.tr_node); X OpenDevice (SERIALNAME,(LONG)p_unit,Read_Request,NULL); X setparams(); X } X Xvoid redocomm() { X ClearMenuStrip( mywindow ); /* Remove old menu */ X InitCommItems(); /* Re-do comm menu */ X SetMenuStrip(mywindow,&menu[0]); /* Re-display the menu */ X} Xvoid redofile() { X ClearMenuStrip( mywindow ); /* Remove old menu */ X InitFileItems(); /* Re-do file menu */ X SetMenuStrip(mywindow,&menu[0]); /* Re-display the menu */ X} X Xvoid setserbaud(baud, redomenu) Xint baud; XLONG redomenu; X { X if(!CheckIO(Read_Request)) X AbortIO(Read_Request); X Wait (1L <mp_SigBit); X WaitIO(Read_Request); X Write_Request->io_Baud = Read_Request->io_Baud = baud; X setparams(); X p_baud = baud; X if (redomenu) redocomm(); X } X Xvoid redoutil() { X ClearMenuStrip(mywindow); X InitUtilItems(); X SetMenuStrip(mywindow,&menu[0]); X } X Xvoid handle_menupick(class, code) XULONG class; Xunsigned int code; X { X unsigned int menunum, itemnum, subnum, i; X X if (code == MENUNULL) return; X X menunum = MENUNUM( code ); X itemnum = ITEMNUM( code ); X subnum = SUBNUM( code ); X switch( menunum ) { X case 0: X switch( itemnum ) { X case 0: /* menunum case 0 itemnum case 0 -- Set xfer mode */ X switch( subnum ) { X case 0: /* Ascii */ X case 1: /* Xmodem */ X case 2: /* XmodemCRC */ X case 3: /* Kermit */ X i = subnum; X break; X default: X i = MODEMAX-1; X } X p_xproto = i; X redofile(); X break; X X case 1: /* menunum case 0 itemnum case 1 -- Send a file */ X name[0] = '\0'; X cmd_sendf(name); X break; X X case 2: /* menunum case 0 itemnum case 2 -- Receive a file */ X name[0] = '\000'; X cmd_recf(name); X break; X X case 3: /* menunum case 0 itemnum case 3 -- Kermit GET */ X name[0] = '\000'; X cmd_kg(name); X break; X X case 4: /* menunum case 0 itemnum case 4 -- Kermit BYE */ X saybye(); X break; X case 5: /* menunum case 0 itemnum case 5 -- ASCII capture */ X name[0] = '\0'; X do_capture(name); X break; X } /* End of itemnum switch for menunum case 0 */ X break; X X case 1: /* menunum case 1 - Comm Setup */ X switch( itemnum ) { X case 0: /* Baud */ X switch( subnum ) { X case 0: X setserbaud(300, FALSE); X break; X X case 1: X setserbaud(1200, FALSE); X break; X X case 2: X setserbaud(2400, FALSE); X break; X X case 3: X setserbaud(4800, FALSE); X break; X X case 4: X setserbaud(9600, FALSE); X break; X } /* End of subnum switch for itemnum 0 of menunum 1 */ X break; X X case 1: /* menunum case 1 itemnum 1 -- Set Parity */ X p_parity = subnum; X break; X X case 2: /* menunum case 2 itemnum 2 -- set kermit transfer mode */ X if (subnum < 2) p_mode = subnum; X else { X if (p_convert) p_convert = 0; X else p_convert = 1; X redocomm(); X } X break; X } X break; /* End of menunum case 1 */ X X case 2: /* menunum case 2 - Script */ X if (!itemnum && !script_on) { X name[0] = '\000'; X req("Script file name:",name,1); X script_start(name); X } X if (itemnum && script_on) exit_script(); X break; X X case 3: /* menunum case 3 -- Utility */ X switch( itemnum ) { X case 0: X sendbreak(); X break; X X case 1: /* menunum case 3 itemnum case 1 -- Hang Up */ X hangup(); X break; X X case 2: /* menunum case 3 itemnum case 2 -- Cd */ X strcpy(name,MyDir); X req("Directory:",name,1); X set_dir(name); X break; X X case 3: /* menunum case 3 itemnum case 3 -- Clear Screen */ X top = MINY; bot = MAXY; savx = MINX; savy = MINY; X curmode = FS_NORMAL; inesc = -1; X a[0] = 0; a[1] = 0; sa[0] = 0; sa[1] = 0; X redoutil(); X emit(12); X break; X X case 4: /* menunum case 3 itemnum case 4 -- Echo mode */ X if (p_echo) p_echo = 0; X else p_echo = 1; X redoutil(); X break; X X case 5: /* menunum case 3 itemnum case 5 -- Wrap mode */ X if (p_wrap) p_wrap = 0; X else p_wrap = 1; X redoutil(); X break; X X case 6: /* menunum case 3 itemnum case 6 -- NumKey */ X if (p_keyapp) p_keyapp = 0; X else p_keyapp = 1; X redoutil(); X break; X X case 7: /* menunum case 3 itemnum case 7 -- App Cur */ X if (p_curapp) p_curapp = 0; X else p_curapp = 1; X redoutil(); X break; X X case 8: /* menunum case 3 itemnum case 8 -- BS <-> DEL */ X swap_bs_del(); X redoutil(); X break; X X case 9: /* menunum case 3 itemnum case 9 -- Xfer Beep */ X if(p_xbeep) p_xbeep = 0; X else p_xbeep = 1; X redoutil(); X break; X } X X break; X } /* end of switch ( menunum ) */ X} ________This_Is_The_END________ if test `wc -l < vt100.c` -ne 805; then echo 'shar: vt100.c was damaged during transit (should have been 805 bytes)' fi fi ; : end of overwriting check exit 0