edward@ukecc.UUCP (Edward C. Bennett) (05/23/86)
Ever go to the trouble to set the pf keys on a terminal to just how you want them only to have them be changed by the next guy that comes along? Well this program was written to overcome that. We have lots of Teletype 4425s and everybody has their own preference on function keys. I use this to reset the pf keys to my layout when I log in. This was written with 4425s in mind but it should be easily modifiable for other terminal types. #! /bin/sh : This is a shell archive, meaning: : 1. Remove everything above the '#! /bin/sh' line. : 2. Save the resulting text in a file. : 3. Execute the file with /bin/sh '(not csh)' to create the files: : 'pfset.1' : 'pfset.c' : This archive created: 'Fri May 23 15:21:28 1986' : By: 'Edward C. Bennett' export PATH; PATH=/bin:$PATH echo shar: extracting "'pfset.1'" '(1469 characters)' if test -f 'pfset.1' then echo shar: will not over-write existing file "'pfset.1'" else sed 's/^X//' >'pfset.1' <<\SHAR_EOF X.TH PFSET 1 X.SH NAME Xpfset \- set programable function keys X.SH SYNOPSIS X.B pfset X.SH DESCRIPTION X.I Pfset Xis used to easily configure a terminal's programable function keys. X.PP X.I Pfset Xlooks at the file X.I .pf${TERM} Xin the user's HOME directory for key definitions. XThe environmental variable TERM is used to build the actual name of the file. Xe.g. if TERM=4425 then the definition file .pf4425 will be used. XEach line of the definition file is composed of four fields, Xseperated by colons, corresponding to the elements described in Xthe following structure. X.sp 1 X.RS X.nf Xstruct pfent { X char *pf_key; X int pf_action; X char *pf_label; X char *pf_command; X}; X.ad X.fi X.RE X.PP XThe X.I pf_key Xfield defines the key to be set. XFor 4425 terminals, Xthe keys avialable are f1-f8, the USER PF keys, Xand s1-s8, the SYS PF keys. X.PP XThe X.I pf_action Xfield defines the action of the key. XOn 4425 terminals the recognized values are X.I Xkeyed, local Xand X.I Xsend. X.PP XThe X.I pf_label Xfield contains the label to appear the screen. X.PP XThe X.I pf_command Xfield contains the actual string to be sent by the function key. XEmbedded newlines in the command are represented in the Xusual fashion by `\\n's. XA \\n must be included if a NL is desired at the end of the command. X.SH FILES X~/.pf${TERM} function definition file X.SH AUTHOR XEdward C. Bennett X.SH BUGS XThis program was written to be used with Teletype 4425 terminals. XModification for other terminal types should be fairly easy. SHAR_EOF if test 1469 -ne "`wc -c < 'pfset.1'`" then echo shar: error transmitting "'pfset.1'" '(should have been 1469 characters)' fi fi echo shar: extracting "'pfset.c'" '(3072 characters)' if test -f 'pfset.c' then echo shar: will not over-write existing file "'pfset.c'" else sed 's/^X//' >'pfset.c' <<\SHAR_EOF X/* X * pfset - set programable function keys X * X * Pfset reads the file .pf${TERM} in a users HOME directory for X * definitions on setting the function keys to the user's preference. X * This was written to work on Teletype 4425 terminals but should be X * easily modifiable for other terminal types. X * X * Compile with: X * cc -O -o pfset pfset.c X * X * AUTHOR X * Edward C. Bennett (edward@ukecc) X * X * Copyright 1985 by Edward C. Bennett X * X * Permission is given to alter this code as needed to adapt it to forign X * systems provided that this header is included and that the original X * author's name is preserved. X */ X#include <stdio.h> X X#define SYS_PF 0 X#define USER_PF 1 X X#define KEYED 0 X#define LOCAL 1 X#define SEND 2 X Xstruct pfent { X char *pf_key; X char *pf_action; X char *pf_label; X char *pf_command; X} pfent; X Xchar buf[BUFSIZ]; X X/*ARGSUSED*/ Xmain(argc, argv) Xint argc; Xchar **argv; X{ X register char *p; X FILE *fp; X char *getenv(), *pfskip(), *strcat(); X int i; X void exit(); X X if ((p = getenv("HOME")) == NULL) { X fprintf(stderr, "%s: HOME variable not found\n", argv[0]); X exit(1); X } X sprintf(buf, "%s/.pf", p); X X if ((p = getenv("TERM")) == NULL || *p == NULL) { X fprintf(stderr, "%s: TERM variable not found\n", argv[0]); X exit(1); X } X strcat(buf, p); X X if ((fp = fopen(buf, "r")) == NULL) X exit(0); X X while (fgets(buf, BUFSIZ, fp)) { X p = buf; X X pfent.pf_key = p; X p = pfskip(p); X pfent.pf_action = p; X p = pfskip(p); X pfent.pf_label = p; X p = pfskip(p); X pfent.pf_command = p; X while (*p && *p != '\n') X p++; X *p = '\0'; X X De_escape(pfent.pf_command); X X /* X * Print the key number X */ X printf("\033[%d;", *(pfent.pf_key+1)-'0'); X X /* X * Print the command length X */ X printf("%d;", strlen(pfent.pf_command)); X X /* X * Print the key action X */ X if (!strcmp(pfent.pf_action, "keyed")) X i = KEYED; X else if (!strcmp(pfent.pf_action, "local")) X i = LOCAL; X else X i = SEND; X printf("%d;", i); X X /* X * Print the key type X */ X printf("%dq", (*p == 's' ? SYS_PF : USER_PF)); X X /* X * Print the label X */ X printf(" f%d %-8.8s", *(pfent.pf_key+1)-'0', pfent.pf_label); X X /* X * Print the command X */ X printf("%s", pfent.pf_command); X X i++; X } X /* X * Show the USER PF labels X */ X printf("\033}"); X X return(0); X} X X/* X * pfskip - isolate and skip a field X * X * q = pfskip(p); X * p is a pointer to a character string X * q is a ponter to the next field in p X * X * pfskip advances along the given string watching for NULLs and ':'s. X * If it sees a ':', it changes it to a NULL and returns the NEXT X * character position. If it finds a NULL, it stops. X */ Xchar * Xpfskip(p) Xregister char *p; X{ X while (*p && *p != ':') X ++p; X X if (*p) X *p++ = '\0'; X X return(p); X} X X/* X * X * De_escape - reduce things like '\n' X * X * De_escape(p) X * p is a pointer to the string to be worked on X * X * Escapes like '\n' are converted to their real characters. X */ XDe_escape(s) Xchar *s; X{ X char *t; X X t = s; X do { X if (*s == '\\') { X switch (*++s) { X case 'n': X *s = '\015'; X break; X } X } X } while (*t++ = *s++); X} SHAR_EOF if test 3072 -ne "`wc -c < 'pfset.c'`" then echo shar: error transmitting "'pfset.c'" '(should have been 3072 characters)' fi fi : End of shell archive exit 0 -- Edward C. Bennett UUCP: ihnp4!cbosgd!ukma!ukecc!edward Kentucky: The state that needs Japan to bring it into the 20th century. "Goodnight M.A."