home *** CD-ROM | disk | FTP | other *** search
- From: marty@wuphys.wustl.edu (Marty Olevitch)
- Newsgroups: comp.sources.misc
- Subject: v17i066: shmed - shell form editor, Part01/01
- Message-ID: <1991Mar22.222546.18556@sparky.IMD.Sterling.COM>
- Date: 22 Mar 91 22:25:46 GMT
- Approved: kent@sparky.imd.sterling.com
- X-Checksum-Snefru: d84230e9 0a11fd70 1378afa5 9db8f30a
-
- Submitted-by: Marty Olevitch <marty@wuphys.wustl.edu>
- Posting-number: Volume 17, Issue 66
- Archive-name: shmed/part01
-
- This is shmed, version 1.0, a simple editor that gives a shell or perl
- program form editing capabilities for user input. After reading in a
- file specifying the form, it is displayed on the screen and the user can
- edit it. Upon exit, shmed writes out the variable assignment statements
- to another file which can then be source'd (or .'d or do'd) by the
- shell. See the manual page for the details.
-
- Marty Olevitch Internet: marty@wuphys.wustl.edu
- Washington University UUCP: uunet!wugate!wuphys!marty
- Physics Department, Campus Box 1105 Bitnet: marty@wuphys.WUSTL
- St Louis MO 63130 USA Tel: (314) 889-6285
-
- ------
- : This is a shar archive. Extract with sh, not csh.
- : This archive ends with exit, so do not worry about trailing junk.
- echo 'Extracting README'
- sed 's/^X//' > README << '+ END-OF-FILE README'
- XMarch, 1991
- X
- XThis is shmed, version 1.0, a simple editor that gives a shell or perl
- Xprogram form editing capabilities for user input. After reading in a
- Xfile specifying the form, it is displayed on the screen and the user can
- Xedit it. Upon exit, shmed writes out the variable assignment statements
- Xto another file which can then be source'd (or .'d or do'd) by the
- Xshell. See the manual page for the details.
- X
- X Copyright (c) 1991 by Marty Olevitch.
- X Not derived from licensed software.
- X
- X Permission is granted to anyone to use this software for any
- X purpose on any computer system, and to redistribute it freely,
- X subject to the following restrictions:
- X
- X 1. The author is not responsible for the consequences of use of
- X this software, no matter how awful, even if they arise
- X from defects in it.
- X
- X 2. The origin of this software must not be misrepresented, either
- X by explicit claim or by omission.
- X
- X 3. Altered versions must be plainly marked as such, and must not
- X be misrepresented as being the original software.
- X
- XInstallation:
- X
- X1) Edit the Makefile and change the options at the top of the file if
- Xyou don't like them.
- X
- X2) Run "make". This should produce the executable "shmed".
- X
- X3) Run "shmed -f testform -o outfile" to try it out. Check the outfile to
- Xsee what is produced. A trivial perl example is in the file perldemo and one
- Xfor the shell is in shdemo. Roff is a more complex and possibly even useful
- Xsh program.
- X
- X4) Run "make install" to put the binary and man page in the correct place.
- X
- XShmed uses the curses library (the BSD version). It has been tested under
- XSunOS 4.1, BSD 4.3 (actually mt Xinu MORE/BSD), and the Next machine,
- Xalthough not a whole lot (this IS version 1.0).
- X
- XPlease report any bugs or improvements to me.
- X
- XMarty Olevitch Internet: marty@wuphys.wustl.edu
- XWashington University UUCP: uunet!wugate!wuphys!marty
- XPhysics Department, Campus Box 1105 Bitnet: marty@wuphys.WUSTL
- XSt Louis MO 63130 USA Tel: (314) 889-6285
- X
- X
- XNote: There was another shell form editor, "sf" by Paul Lew, which came out
- Xon the net a few years ago. I used it for a while, but found that it did
- Xbizarre things with reverse video mode on some of our terminals. After a
- Xnot-too-lengthy look at the sf code I decided that it would be easier to
- Xwrite my own than try to find the problem and fix it. Although, sf inspired
- Xthe writing of it, shmed is completely different and of course, the code and
- Xinternal structure are not the same. Ditto for the format of the form
- Xdefintion file. If you're interested, sf can be found in the archives of
- Xcomp.sources.unix, volume 14 under the name "shellforms".
- X
- + END-OF-FILE README
- chmod 'u=rw,g=r,o=r' 'README'
- echo ' -rw-r--r-- 1 marty 2681 Mar 7 15:23 README (as sent)'
- echo -n ' '
- /bin/ls -l README
- echo 'Extracting Makefile'
- sed 's/^X//' > Makefile << '+ END-OF-FILE Makefile'
- X# shmed makefile
- X
- XDESTDIR = /usr/local
- XMANSUFFIX = l
- XMANDIR = /usr/man/man$(MANSUFFIX)
- XOWNER = bin
- XGROUP = bin
- X
- XCC = cc
- X# CFLAGS = -g -Bstatic
- XLIBS = -lcurses -ltermcap
- XFILES = README Makefile shmed.man shmed.c util.c formfile.doc \
- X Roff perldemo shdemo testform
- X
- Xshmed: shmed.o util.o
- X $(CC) -o shmed shmed.o util.o $(LIBS)
- X
- Xclean:
- X rm *.o
- X
- Xinstall: shmed
- X strip shmed
- X mv shmed $(DESTDIR)
- X chmod 755 $(DESTDIR)/shmed
- X chown $(OWNER) $(DESTDIR)/shmed
- X chown $(GROUP) $(DESTDIR)/shmed
- X cp shmed.man $(MANDIR)/shmed.$(MANSUFFIX)
- X
- Xshar: shmed.shar
- X
- Xshmed.shar: $(FILES)
- X shar -o shmed.shar $(FILES)
- + END-OF-FILE Makefile
- chmod 'u=rw,g=r,o=r' 'Makefile'
- echo ' -rw-r--r-- 1 marty 598 Mar 7 15:23 Makefile (as sent)'
- echo -n ' '
- /bin/ls -l Makefile
- echo 'Extracting shmed.man'
- sed 's/^X//' > shmed.man << '+ END-OF-FILE shmed.man'
- X.TH shmed L "March 7, 1991" "WU Cosmic Ray Lab"
- X.SH NAME
- Xshmed - simple shell form editor
- X.SH USAGE
- X.nf
- Xshmed [-pbc] [-f formfile] -o outfile
- X-p perl output (default)
- X-b Bourne shell output
- X-c csh output
- X-f file form template file (default stdin)
- X-o file name of output file (no default)
- X.SH DIAGNOSTICS
- Xshmed returns non-zero if there are startup
- Xproblems or if it is interrupted, else 0.
- X.SH FILES
- XFormat of the form template file
- X.RS
- XNormal text lines are printed as they appear.
- XEditable lines should begin with a '.' (dot), and
- Xcontain 2 or 3 fields separated by a '~' (tilde).
- X.RS
- X1st field: label to be printed in the editor.
- X.br
- X2nd field: name of variable to assign the value to
- X.br
- X3rd field: (optional) default value for variable
- X.RE
- X.RE
- X.RS
- XOutput file
- X.RS
- XThe output file contains a bunch of variable assignments
- Xin the language you selected (perl, sh, or csh). It should
- Xbe do'd, .'d, or source'd after shmed is run.
- X.RE
- X.SH AUTHOR
- X.nf
- XMarty Olevitch
- XPhysics Dept.
- XWashington University
- XSt. Louis, MO 63130
- X
- Xmarty@wuphys.wustl.edu
- X
- XMarch, 1991
- + END-OF-FILE shmed.man
- chmod 'u=rw,g=r,o=r' 'shmed.man'
- echo ' -rw-r--r-- 1 marty 1066 Mar 7 15:23 shmed.man (as sent)'
- echo -n ' '
- /bin/ls -l shmed.man
- echo 'Extracting shmed.c'
- sed 's/^X//' > shmed.c << '+ END-OF-FILE shmed.c'
- X/* shmed - simple shell form editor
- X *
- X * USAGE:
- X * shmed [-pbc] [-f formfile] -o outfile
- X * -p perl output (default)
- X * -b Bourne shell output
- X * -c csh output
- X * -f formfile name of file containing form (default stdin)
- X * -o outfile name of output file (no default)
- X *
- X * DIAGNOSTICS:
- X * shmed returns non-zero if there are startup
- X * problems or if it is interrupted, else 0.
- X *
- X * FILES:
- X * format of the form file
- X * Normal text lines are printed as they appear.
- X * Editable lines should begin with a '.' (dot), and
- X * contain 2 or 3 fields separated by a '~' (tilde).
- X * 1st field: label to be printed in the editor.
- X * 2nd field: name of variable to assign the value to
- X * 3rd field: (optional) default value for the variable
- X *
- X * output file
- X * The output file contains a bunch of variable assignments
- X * in the language you selected (perl, sh, or csh). It should
- X * be require'd, .'d, or source'd after shmed is run.
- X *
- X * AUTHOR
- X *
- X * Marty Olevitch
- X * Physics Dept.
- X * Washington University
- X * St. Louis, MO 63130
- X *
- X * marty@wuphys.wustl.edu
- X *
- X * March, 1991
- X */
- X
- X#define VERSION "1.0"
- X
- X#include <curses.h>
- X#include <ctype.h>
- X#include <signal.h>
- X
- X#define CTL(x) ((x) & 0x3f)
- X#define ESC 0x1b
- X#define DEL 0x7f
- X
- X#define MAXSTR 500 /* For sizing strings -- DON'T use BUFSIZ! */
- X#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
- X#define BEEP putchar(CTL('G'))
- X
- X/* CHOP - replace last character of a string */
- X#define CHOP(s, c) ((s)[strlen(s)-1] = (c))
- X
- X#define FIELDSEP "~" /* form file field separator string */
- X#define PERLFMT "$%s = '%s';\n"
- X#define BOURNEFMT "%s='%s'\n"
- X#define CSHFMT "set %s='%s'\n"
- X
- X#define MAXFORMROWS 24 /* max. no. of rows in a form */
- Xchar answer[MAXFORMROWS][MAXSTR]; /* response lines */
- Xint editable[MAXFORMROWS]; /* tells if form line is editable */
- Xchar label[MAXFORMROWS][MAXSTR]; /* labels for editable lines */
- Xchar variable[MAXFORMROWS][MAXSTR]; /* variable names for editable lines */
- Xint longval; /* length of longest formrow string */
- Xint nrows; /* number of rows in our form */
- X
- XWINDOW *helpwin; /* help screen */
- XWINDOW *altwin; /* for saving real screen when help is displayed */
- X
- Xchar *progname;
- XFILE *efopen();
- X
- X/*
- X - usage - print usage message
- X */
- Xusage()
- X{
- X fprintf(stderr,"USAGE: %s [-pbc] [-f formfile] -o outfile\n",
- X progname);
- X}
- X
- X/*
- X - main
- X */
- Xmain(argc, argv)
- X int argc;
- X char *argv[];
- X{
- X int bourneout = 0; /* bourne shell output */
- X int cshout = 0; /* csh shell output */
- X int done;
- X char filename[MAXSTR]; /* form file */
- X char fmt[MAXSTR]; /* printf format for output */
- X int i;
- X FILE *outfp;
- X char outputfile[MAXSTR]; /* output file name */
- X int outputflag = 0; /* 1 if we have a valid -o argument */
- X int perlout = 0; /* perl output */
- X int sighandle();
- X
- X int c;
- X int errflg = 0;
- X extern int optind;
- X extern char *optarg;
- X
- X progname = argv[0];
- X strcpy(filename, "-");
- X
- X while ((c = getopt(argc, argv, "pcbf:o:")) != EOF) {
- X switch (c) {
- X case 'p': /* perl output */
- X if(bourneout || cshout) {
- X fprintf(stderr,"Use only one of -c, -b and -p flags\n");
- X errflg++;
- X } else
- X perlout = 1;
- X break;
- X case 'b': /* bourne shell output */
- X if(perlout || cshout) {
- X fprintf(stderr,"Use only one of -c, -b and -p flags\n");
- X errflg++;
- X } else
- X bourneout = 1;
- X break;
- X case 'c': /* csh output */
- X if(perlout || bourneout) {
- X fprintf(stderr,"Use only one of -c, -b and -p flags\n");
- X errflg++;
- X } else
- X cshout = 1;
- X break;
- X case 'f': /* form file name */
- X strcpy(filename, optarg);
- X break;
- X case 'o': /* output file name */
- X outputflag++;
- X strcpy(outputfile, optarg);
- X break;
- X case '?':
- X default:
- X errflg++;
- X break;
- X }
- X }
- X
- X if (errflg) {
- X usage();
- X exit(2);
- X }
- X
- X if(outputflag == 0) {
- X fprintf(stderr,"No output file specified\n");
- X usage();
- X exit(2);
- X }
- X
- X if(perlout == 0 && bourneout == 0 && cshout == 0)
- X perlout = 1;
- X
- X outfp = efopen(outputfile, "w");
- X
- X for(i=0; i<MAXFORMROWS; i++)
- X answer[i][0] = '\0';
- X
- X /* readform fills in the editable, label, variable, and answer arrays */
- X if((nrows = readform(filename)) == 0) {
- X fprintf(stderr,"%s: empty form file.\n", progname);
- X exit(1);
- X }
- X
- X startcurses();
- X signal(SIGQUIT, sighandle);
- X signal(SIGINT, sighandle);
- X
- X /* initial update of the editing screen */
- X for(i=0; i<nrows; i++) {
- X move(i,0);
- X addstr(label[i]);
- X if(editable[i]) {
- X addch(':');
- X move(i, longval); /* longval was determined by readform() */
- X addstr(answer[i]);
- X }
- X }
- X refresh();
- X
- X /* edit each of the editable lines in turn */
- X i = 0;
- X while(1) {
- X if(editable[i] == 1) {
- X done = edit_line(i, longval, answer[i]);
- X refresh();
- X if(done == 1) /* ESC was pressed */
- X break;
- X }
- X if(done == 0) { /* next line */
- X if(++i == nrows)
- X i = 0;
- X } else if(done == -1) { /* previous line */
- X if(--i < 0)
- X i = nrows - 1;
- X }
- X }
- X
- X /* output time */
- X if(perlout)
- X strcpy(fmt, PERLFMT);
- X else if(bourneout)
- X strcpy(fmt, BOURNEFMT);
- X else if(cshout)
- X strcpy(fmt, CSHFMT);
- X else { /* can't happen */
- X fprintf(stderr,"neither perl, csh, nor bourne output specified.\n");
- X exit(1);
- X }
- X
- X for(i=0; i<nrows; i++) {
- X if(editable[i] == 1)
- X fprintf(outfp, fmt, variable[i], answer[i]);
- X }
- X
- X finish_up();
- X return(0);
- X}
- X
- X/*
- X - edit_line - perform edit operations on a single line
- X * The edited string is returned in the str argument.
- X * returns 1 if ESC typed, else 0 if RET typed
- X */
- Xedit_line(r, startc, str)
- X int r; /* row that we're editing */
- X int startc; /* starting column for editable string */
- X char *str; /* pointer to editable string */
- X{
- X int k;
- X int c; /* current column */
- X int endc; /* ending column */
- X int slen; /* length of editable strings */
- X int retcode;
- X
- X slen = strlen(str);
- X c = endc = startc + slen;
- X move(r, c);
- X refresh();
- X
- X while(k = getch()) {
- X switch(k) {
- X case CTL('A'):
- X move(r, startc);
- X c = startc;
- X break;
- X case CTL('F'):
- X c = ( c+1 <= endc ) ? c + 1 : c;
- X move(r, c);
- X break;
- X case CTL('B'):
- X c = ( c-1 >= startc ) ? c - 1 : c;
- X move(r, c);
- X break;
- X case CTL('E'):
- X if(endc < COLS-2)
- X c = endc;
- X move(r, c);
- X break;
- X case CTL('D'):
- X delch();
- X endc--;
- X break;
- X case CTL('G'):
- X help();
- X move(r, c);
- X break;
- X case CTL('H'):
- X case DEL:
- X if(c != startc) {
- X c--;
- X move(r, c);
- X delch();
- X endc--;
- X }
- X break;
- X case CTL('K'): /* delete to end of line */
- X clrtoeol();
- X endc = c;
- X break;
- X case CTL('L'):
- X wrefresh(curscr);
- X break;
- X case CTL('I'):
- X case CTL('N'): /* next line */
- X case '\n':
- X case '\r':
- X retcode = 0;
- X goto finito;
- X break;
- X case CTL('P'):
- X retcode = -1;
- X goto finito;
- X break;
- X case ESC: /* done with form */
- X retcode = 1;
- X goto finito;
- X break;
- X default:
- X if(isprint(k)) {
- X addch(k);
- X if(c++ >= COLS-2) {
- X c = COLS-2;
- X move(r, c);
- X }
- X if(c > endc)
- X endc++;
- X } else {
- X BEEP;
- X }
- X break;
- X }
- X refresh();
- X }
- Xfinito:
- X instr(r, longval, endc, str);
- X return(retcode);
- X}
- X
- X/*
- X - instr - get the characters between startc and endc on a line
- X */
- Xinstr(row, startc, endc, str)
- X int row;
- X int startc;
- X int endc;
- X char *str;
- X{
- X int i;
- X char *cp;
- X
- X if(row < 0 || row > LINES - 1)
- X return(-1);
- X if(startc < 0 || startc > COLS - 1)
- X return(-2);
- X if(endc < 0 || endc > COLS - 1)
- X return(-3);
- X
- X if(startc < endc) {
- X for(cp=str,i=startc; i<endc; i++) {
- X move(row, i);
- X *cp++ = inch();
- X }
- X *cp = '\0';
- X } else { /* endc < startc */
- X for(cp=str,i=startc; i>endc; i--) {
- X move(row, i);
- X *cp++ = inch();
- X }
- X *cp = '\0';
- X }
- X return(0);
- X}
- X
- X/*
- X - readform - read the lines from the formfile
- X *
- X * format of the form file:
- X * normal text lines - printed as they appear
- X * . lines - begin with a dot; editable lines
- X * .<label>~variable name~default value
- X *
- X * example:
- X * .Name of Dog~dogname~Fido
- X * .Date of Vaccination~vacdate~9/17/91
- X *
- X * Read only up to MAXFORMROWS rows. Return the number of rows read.
- X */
- Xreadform(file)
- X char *file;
- X{
- X char formrow[MAXFORMROWS][MAXSTR]; /* input form lines */
- X FILE *formfp; /* formfile file pointer */
- X int i;
- X
- X if(STREQ(file, "-"))
- X formfp = stdin;
- X else
- X formfp = efopen(file, "r");
- X
- X for(i=0; i<MAXFORMROWS; i++) {
- X if(fgets(formrow[i], MAXSTR, formfp) == NULL)
- X break;
- X CHOP(formrow[i], '\0');
- X if(formrow[i][0] == '.') {
- X editable[i] = 1;
- X split(formrow[i]+1, FIELDSEP, 3, label[i], variable[i], answer[i]);
- X if(strlen(label[i]) + 2 > longval) /* find longest label */
- X longval = strlen(label[i]) + 2;
- X } else {
- X strcpy(label[i], formrow[i]);
- X }
- X }
- X fclose(formfp);
- X if(formfp == stdin) {
- X if(freopen("/dev/tty", "r+", stdin) != stdin) {
- X fprintf(stderr,"%s: can't reopen stdin\n", progname);
- X exit(2);
- X }
- X }
- X
- X return(i);
- X}
- X
- X/*
- X - finish_up - clean up before exit
- X */
- Xfinish_up()
- X{
- X move(nrows, 0);
- X refresh();
- X nocbreak();
- X echo();
- X endwin();
- X}
- X
- X/*
- X - sighandle - catches SIGQUIT and SIGINT
- X */
- Xsighandle()
- X{
- X signal(SIGQUIT, SIG_IGN);
- X signal(SIGINT, SIG_IGN);
- X finish_up();
- X exit(1);
- X}
- X
- Xstartcurses()
- X{
- X if(initscr() == ERR) {
- X fprintf(stderr,"%s: can't start curses!\n", progname);
- X exit(1);
- X }
- X noecho();
- X cbreak();
- X clear();
- X
- X altwin = newwin(LINES, COLS, 0, 0);
- X helpwin = newwin(LINES, COLS, 0, 0);
- X inithelp();
- X}
- X
- Xinithelp()
- X{
- X mvwprintw(helpwin, 1, 12, "%s %s", progname, VERSION);
- X mvwprintw(helpwin, 3, 0, "ctrl-N go to next line (same as pressing RET)");
- X mvwprintw(helpwin, 4, 0, "ctrl-P go to previous line");
- X mvwprintw(helpwin, 5, 0, "esc form completed");
- X
- X mvwprintw(helpwin, 7, 0, "ctrl-A go to beginning of line");
- X mvwprintw(helpwin, 8, 0, "ctrl-E go to end of line");
- X mvwprintw(helpwin, 9, 0, "ctrl-F go forward one space");
- X mvwprintw(helpwin, 10, 0, "ctrl-B go back one space");
- X
- X mvwprintw(helpwin, 12, 0, "ctrl-D delete character at cursor");
- X mvwprintw(helpwin, 13, 0, "backspace delete character before cursor");
- X mvwprintw(helpwin, 14,0, "ctrl-K delete all characters to end of line");
- X
- X mvwprintw(helpwin, 16, 0, "ctrl-L redraw screen");
- X mvwprintw(helpwin, 17, 0, "ctrl-G show help screen");
- X mvwprintw(helpwin, 20, 10, "Hit any key to continue...");
- X}
- X
- Xhelp()
- X{
- X overwrite(stdscr, altwin);
- X overwrite(helpwin, stdscr);
- X move(20, 36);
- X refresh();
- X wgetch(helpwin);
- X overwrite(altwin, stdscr);
- X refresh();
- X}
- + END-OF-FILE shmed.c
- chmod 'u=rw,g=r,o=r' 'shmed.c'
- echo ' -rw-r--r-- 1 marty 10327 Mar 7 15:23 shmed.c (as sent)'
- echo -n ' '
- /bin/ls -l shmed.c
- echo 'Extracting util.c'
- sed 's/^X//' > util.c << '+ END-OF-FILE util.c'
- X/*
- X * util.c - utility routines used in shmed
- X *
- X * (should eventually become local library routines)
- X *
- X * Marty Olevitch, March 1991
- X */
- X
- X#include <stdio.h>
- X#include <varargs.h>
- X#include <strings.h>
- X#include <errno.h>
- X
- Xextern int sys_nerr;
- Xextern char *sys_errlist[];
- Xextern int errno;
- X
- X/*
- X - efopen - fopen() with error handling
- X */
- XFILE *
- Xefopen(filename, mode)
- X char *filename;
- X char *mode;
- X{
- X FILE *fp;
- X if((fp = fopen(filename, mode)) == NULL) {
- X fprintf(stderr,"Can't open file '%s' mode '%s' (%s)\n",
- X filename, mode, sys_errlist[errno]);
- X exit(1);
- X }
- X return(fp);
- X}
- X
- X/*
- X - split - split a string into substrings
- X *
- X * usage is split(str, sep, n, str1, str2, ...)
- X *
- X * split string str on separator sep into the n substrings
- X * str1, str2, etc.
- X *
- X * returns number of substrings extracted
- X */
- Xsplit(va_alist)
- X va_dcl
- X{
- X va_list ap;
- X char *srcp; /* source string */
- X char *sep; /* separator */
- X int n; /* number of strings to split into */
- X int i;
- X char *destp;/* destination strings */
- X char *cp, *strtok();
- X
- X va_start(ap);
- X srcp = va_arg(ap, char *);
- X sep = va_arg(ap, char *);
- X n = va_arg(ap, int);
- X
- X for(i=0; i<n; i++) {
- X destp = va_arg(ap, char *);
- X if(i == 0)
- X cp = strtok(srcp, sep);
- X else
- X cp = strtok(NULL, sep);
- X
- X if(cp != NULL) {
- X strcpy(destp, cp);
- X } else {
- X strcpy(destp, ""); /* not enough fields */
- X break;
- X }
- X }
- X return(i);
- X}
- + END-OF-FILE util.c
- chmod 'u=rw,g=r,o=r' 'util.c'
- echo ' -rw-r--r-- 1 marty 1382 Mar 7 15:24 util.c (as sent)'
- echo -n ' '
- /bin/ls -l util.c
- echo 'Extracting formfile.doc'
- sed 's/^X//' > formfile.doc << '+ END-OF-FILE formfile.doc'
- XThe Shmed Form Template
- X
- XA form template consists of up to 24 lines of text (actually you
- Xcan have more than 24 lines in the file, but anything beyond 24
- Xwill be ignored). Ordinary text lines will be printed on the screen
- Xjust as they are. However, a line which begins with a dot (.) denotes
- Xan editable line. This line consists of either 2 or 3 fields separated
- Xby a tilde (~). The first field is the label that will be printed
- Xon the line; the second field is the name of the variable that will
- Xbe assigned to; and the third field, if present, is a default string
- Xthat will be printed.
- X
- XFor example, the file containing
- X
- X.Your name~nombre~Albert Q. Shmurdwell
- X
- Xwill produce a line on the editor that looks like
- X
- XYour name: Albert Q. Shmurdwell
- X ^------- (cursor will be here)
- X
- XThe user can then edit the line and change it if their name is not
- XAlbert Q. Shmurdwell. After they have exited the editor, an assignment
- Xstatement such as
- X
- Xnombre='Albert Q. Shmurdwell'
- X
- Xwill be written into the output file (if you are using the -b option
- Xfor Bourne shell output).
- X
- XLook at the sample files provided for more elaborate examples
- Xof template files.
- + END-OF-FILE formfile.doc
- chmod 'u=rw,g=r,o=r' 'formfile.doc'
- echo ' -rw-r--r-- 1 marty 1174 Mar 7 15:24 formfile.doc (as sent)'
- echo -n ' '
- /bin/ls -l formfile.doc
- echo 'Extracting Roff'
- sed 's/^X//' > Roff << '+ END-OF-FILE Roff'
- X#! /bin/sh
- X# Roff - menu driven ditroffing
- X#
- X# Usage: Roff [file]
- X#
- X# Marty Olevitch, Aug 1989
- X# March, 1991 - uses shmed
- X
- XVersion="Roff 1.3"
- X
- XFiles=$* # files, if any, to print
- X
- XTMP=/usr/tmp/shmed$$.out # shmed output file
- XRCfile=$HOME/.Roffrc # user's default-set-up file
- X
- Xtrap "if [ -f $TMP ]; then /bin/rm -f $TMP; fi" 0 1 2 3 15
- X
- X# Set up defaults. Users may put their own defaults in the $RCfile file.
- X# Otherwise we use a set of more or less reasonable defaults.
- X
- Xif [ -r $RCfile ]; then
- X . $RCfile
- Xelse
- X do_eqn=yes
- X do_tbl=yes
- X do_pic=no
- X do_grap=no
- X do_psfig=no
- X macro_pkg=ms
- X additional_opts=
- X output_dev=lw5
- X backgnd=foreground
- Xfi
- Xnew_rc=no # 'yes' if we want to create new RCfile
- X
- Xshmed -b -o $TMP << sfEOF
- X $Version
- X INSTRUCTIONS: To move to the next field, press RET.
- X When this form is completed to your satisfaction, press ESC.
- X (press ctrl-G for editing help)
- X
- X.Files to print~menu_files~$Files
- X
- X.eqn?~do_eqn~$do_eqn
- X.tbl?~do_tbl~$do_tbl
- X.pic?~do_pic~$do_pic
- X.grap?~do_grap~$do_grap
- X.psfig?~do_psfig~$do_psfig
- X.macro pkg~macro_pkg~$macro_pkg
- X.other troff options~additional_opts~$additional_opts
- X.output to~output_dev~$output_dev
- X
- Xbackground or foreground
- X.execution~backgnd~$backgnd
- X
- XDon't print anything, just make a new setup
- Xfile so Roff will remember your choices
- X.next time~new_rc~$new_rc
- XsfEOF
- X
- Xif [ $? -ne 0 ]; then
- X echo "Aborted."
- X exit # unnatural exit from sf
- Xfi
- X
- X. $TMP
- X
- Xif [ $new_rc = 'yes' ]; then # just create a new rc file, don't print
- X echo -n "Writing new .Roffrc file..."
- X cat > $RCfile <<-RoffEOF
- X do_eqn=$do_eqn
- X do_tbl=$do_tbl
- X do_pic=$do_pic
- X do_grap=$do_grap
- X do_psfig=$do_psfig
- X macro_pkg=$macro_pkg
- X additional_opts="$additional_opts"
- X output_dev=$output_dev
- X backgnd=$backgnd
- XRoffEOF
- X echo
- X exit
- Xfi
- X
- XEQN=
- XTBL=
- XPIC=
- XGRAP=
- XPSFIG=
- X
- XP="-P$output_dev"
- X
- Xif [ -n "$menu_files" ]; then # files selected in menu override cmd line
- X Files=$menu_files
- Xfi
- Xif [ -z "$Files" ]; then
- X echo "Roff: No file to print! Quitting."
- X exit
- Xfi
- X
- Xif [ $do_eqn = 'yes' ]; then
- X EQN="deqn |"
- Xfi
- Xif [ $do_tbl = 'yes' ]; then
- X TBL="dtbl |"
- Xfi
- Xif [ $do_pic = 'yes' ]; then
- X PIC="pic |"
- Xfi
- Xif [ $do_grap = 'yes' ]; then
- X GRAP="grap |"
- X PIC="pic |" # if grap, then pic
- Xfi
- Xif [ $do_psfig = 'yes' ]; then
- X PSFIG="/usr/new/psfig |"
- X DIT="rpr \"ditroff -mpsfig -Tpsc -$macro_pkg $additional_opts\" | psdit"
- X ROFFLINE="$GRAP $PIC $TBL $EQN $PSFIG $DIT | lpr $P"
- Xelse
- X if [ $output_dev = "imagen" ]; then
- X DIT="iroff -$macro_pkg $additional_opts -D'pagereversal on'"
- X else
- X EQN=${EQN+"eqn -m2 |"}
- X DIT="psroff -$macro_pkg $additional_opts $P"
- X fi
- X ROFFLINE="$GRAP $PIC $TBL $EQN rpr \"$DIT\""
- Xfi
- X
- Xecho -n "Running " "cat $Files | $ROFFLINE "
- Xif [ $backgnd = "background" ]; then
- X echo " in the background"
- X cat $Files | eval $ROFFLINE &
- Xelse
- X echo -n "..."
- X cat $Files | eval $ROFFLINE
- X echo "done"
- Xfi
- X
- + END-OF-FILE Roff
- chmod 'u=rwx,g=rx,o=rx' 'Roff'
- echo ' -rwxr-xr-x 1 marty 2862 Mar 7 15:24 Roff (as sent)'
- echo -n ' '
- /bin/ls -l Roff
- echo 'Extracting perldemo'
- sed 's/^X//' > perldemo << '+ END-OF-FILE perldemo'
- X#!/usr/bin/perl
- X
- Xsystem "shmed -o foo <<Eof
- X Shmed Demo
- X
- X Press RET to go to the next line.
- X Press ESC when the form is complete.
- X Press ^G for help.
- X
- X.Name~name~Marty Olevitch
- X.Address~addr
- X.City~city
- X.State~state
- X.Zip~zip
- X.Phone~phone
- XEof";
- X
- X
- Xdie "Bad system() call\n" if($? != 0);
- X
- Xdo 'foo';
- Xunlink 'foo';
- Xprint "\n";
- Xif($name eq "Marty Olevitch") {
- X print "I doubt if your name is really Marty Olevitch.\n";
- X print "Unless you are my cousin who has my same name.\n\n";
- X}
- Xprint "The information you gave me is:\n";
- Xprint "Name: ", $name, "\n", "Address: ", $addr, "\n",
- X "City: ", $city, "\n", "State: ", $state, "\n",
- X "Zip: ", $zip, "\n", "Phone: ", $phone, "\n";
- X
- + END-OF-FILE perldemo
- chmod 'u=rwx,g=rx,o=rx' 'perldemo'
- echo ' -rwxr-xr-x 1 marty 699 Mar 7 15:24 perldemo (as sent)'
- echo -n ' '
- /bin/ls -l perldemo
- echo 'Extracting shdemo'
- sed 's/^X//' > shdemo << '+ END-OF-FILE shdemo'
- X#!/bin/sh
- X
- XHOST=
- X
- Xif test -f /bin/hostname ; then
- X HOST=`/bin/hostname`
- Xfi
- X
- Xshmed -b -o foo$$ << ShmedInput
- X Yet Another Shmed Demo
- X
- X.Host name~hostname~$HOST
- X.IP number~ipno~$IPNO
- X
- X.Technical Contact~tech
- X.Office~office
- X.Telephone~phone
- X
- X Press RET to go to the next field, ESC when form is done.
- X Press ^G for help.
- X
- XShmedInput
- X
- Xif test $? -ne 0; then
- X exit
- Xfi
- X
- X. foo$$
- X
- Xecho "Host machine is $hostname"
- Xecho "IP address is $ipno"
- Xecho "Technical contact is $tech"
- Xecho "Office is $office"
- Xecho "Telephone $phone"
- X
- Xrm foo$$
- + END-OF-FILE shdemo
- chmod 'u=rwx,g=rx,o=rx' 'shdemo'
- echo ' -rwxr-xr-x 1 marty 580 Mar 7 15:24 shdemo (as sent)'
- echo -n ' '
- /bin/ls -l shdemo
- echo 'Extracting testform'
- sed 's/^X//' > testform << '+ END-OF-FILE testform'
- X Shmed Form Editor Demo
- X
- X Press RET to go to the next line.
- X Press ESC when the form is completed.
- X
- X.Name~name
- X.Occupation~occupation
- X.Religion~religion
- X.Favorite Animal~animal~aardvark
- X.Favorite Color~color~blue
- X.Opinion of President~opinion
- X
- X Press ctl-G for help.
- X
- X
- + END-OF-FILE testform
- chmod 'u=rw,g=r,o=r' 'testform'
- echo ' -rw-r--r-- 1 marty 315 Mar 7 15:24 testform (as sent)'
- echo -n ' '
- /bin/ls -l testform
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-