VT220 lossage

BostonU SysMgr root%bostonu.csnet at CSNET-RELAY.ARPA
Tue Oct 22 06:30:14 AEST 1985


Here, have a ball...but you still have to hit the shift key.
Yes, the security problems should be semi-obvious.

		-Barry Shein, Boston University

---------------key220.c-------------
#include <stdio.h>
#include <ctype.h>

/*
 *	The default toupper() macro is stupid, will toupper anything
 */
#ifdef toupper(c)
#undef toupper(c)
#endif
#define toupper(c) (islower(c) ? ((c)-' ') : c)

/*
 *	Trivial program to load VT220 Function keys with strings,
 *	note that the values only get sent when the key is shifted
 *	(shoulda been an option to flip the shift set like the Z19!)
 *
 *	Typing no args gives help, basically pairs of keyname/value
 *	strings.
 *
 *	Author, Author: Barry Shein, Boston University
 */
#define ESC 033
struct keynames {
  char *name ;
  char *string ;
} keys[] = {
  "F6", "17",
  "F7", "18",
  "F8", "19",
  "F9", "20",
  "F10", "21",
  "F11", "23",
  "ESC", "23",
  "F12", "24",
  "BS", "24",
  "F13", "25",
  "LF", "25",
  "F14", "26",
  "HELP", "28",
  "DO", "29",
  "F17", "31",
  "F18", "32",
  "F19", "33",
  "F20", "34",
    NULL, NULL
} ;

char *prog ;

usage()
{
	int i ;

	fprintf(stderr,"Usage: %s keyname string [keyname string...]\n",prog) ;
	fprintf(stderr,"\tSHIFTED function key then sends that string\n") ;
	fprintf(stderr,"Where keyname is one of:\n\n\t") ;
	for(i=0 ; keys[i].name != NULL ; i++)
		fprintf(stderr,"%s ",keys[i].name) ;
	fprintf(stderr,"\n\n") ;
	fprintf(stderr,"Also, be careful about quoting to the shell\n") ;
	fprintf(stderr,"'%s -c [...]' clears keys first\n",prog) ;
	fprintf(stderr,"'%s -l [...]' [sets then] locks further setting\n",
		prog) ;
	fprintf(stderr,"\t(note that the only way to unlock is via Set-Up)\n");
	exit(1) ;
}
main(argc,argv) int argc ; char **argv ;
{
	int lockf = 0, clearf = 0  ;

        prog = *argv ;
	if(argc == 1) usage() ;
	++argv ;
	--argc ;
	for(; **argv == '-' ; ++argv, --argc)
	  switch(argv[0][1]) {
	  case 'c' :
	    ++clearf ;
	    break ;
	  case 'l' :
	    lockf++ ;
	    break ;
	  default :
	    fprintf(stderr,"Bad flag: %s\n",*argv) ;
	    usage() ;
	  }
	if(argc & 01) usage() ;
	if(clearf) clearkeys() ;
	while(argc > 0) {
	  dokey(argv[0],argv[1]) ;
	  argc -= 2 ;
	  argv += 2 ;
	}
	if(lockf) lockkeys() ;
	exit(0) ;
}
/*
 *	Load the VT220 SHIFT-FNKEY value, the basic pattern is
 *		"\EP1;1|"+KEYNAME+"/"+VAL_AS_HEX+"\E\\"
 *	that is, literally what is in quotes (w/o quotes) then the
 *	name of the key from the keytable above (a numeric string)
 *	then a slash, then the string value as hex pairs then ESC-BACKSLASH
 *
 *	Note: you can gang together key defns with semicolons but that
 *	would complicate things, especially error handling, so do it all
 *	for each pair, who cares, really.
 */
dokey(nm,val) char *nm, *val ;
{
	register char *scr ;
	register struct keynames *kp ;

	for(scr = nm ; *scr = toupper(*scr) ; scr++)
	  		;
	for(kp = keys ; kp->name != NULL; kp++)
	  if(strcmp(nm,kp->name) == 0) {
	    printf("%cP1;1|%s/",ESC,kp->string) ;
	    while(*val) printf("%02x",*val++) ;
	    printf("%c\\",ESC) ;
	    fflush(stdout) ;
	    return ;
	}
	fprintf(stderr,"'%s'? ",nm) ;
	usage() ;	/* bad key name, give up */
}
clearkeys()
{
	printf("%cP0;1|%c\\",ESC,ESC) ;
	fflush(stdout) ;
}
lockkeys()
{
 	printf("%cP1;0|%c\\",ESC,ESC) ;
	fflush(stdout) ;
}



More information about the Comp.unix.wizards mailing list