home *** CD-ROM | disk | FTP | other *** search
- Path: comp-sources-3b1
- From: dave@galaxia.network23.com (David H. Brierley)
- Subject: v02i027: echo command with termcap escape sequences, Part01/01
- Newsgroups: comp.sources.3b1
- Approved: dave@galaxia.network23.com
- X-Checksum-Snefru: bf87c992 86988075 ba669022 cbcab398
-
- Submitted-by: dave@galaxia.network23.com (David H. Brierley)
- Posting-number: Volume 2, Issue 27
- Archive-name: techo/part01
-
- This is the README file for the Dave Brierley collection of miscellaneous
- source programs. The collection is posted in seven separate pieces but
- all of the source came from the "misc" directory on my machine. As a result
- of this, there is only one README file and only one Makefile, although each
- of the seven postings will contain a copy of these two files. I suggest
- that you obtain (or save) as many of these postings as you are interested
- in, unpack them all in a single directory, and then compile the sources.
- Note that some of the programs are actually shell scripts and therefore do
- not need compilation.
-
- techo.c
- A version of echo that allows direct access to termcap capabilities. A lot
- easier to use than intermixing calls to echo with calls to tput.
-
- techo.1
- Hey, I actually wrote a man page for this one!
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 1)."
- # Contents: MANIFEST Makefile README techo.1 techo.c
- # Wrapped by dave@galaxia on Tue Jul 21 10:44:42 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(251 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1
- X Makefile 1
- X README 1
- X techo.1 1
- X techo.c 1
- END_OF_FILE
- if test 251 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'Makefile' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'Makefile'\"
- else
- echo shar: Extracting \"'Makefile'\" \(374 characters\)
- sed "s/^X//" >'Makefile' <<'END_OF_FILE'
- XCFLAGS = -O
- X
- Xall: bsdln disktest email ndf techo wclipper
- X
- Xbsdln: bsdln.o
- X $(CC) bsdln.o
- X mv a.out bsdln
- X
- Xdisktest: disktest.o
- X $(CC) disktest.o
- X mv a.out disktest
- X
- Xemail: email.o
- X $(CC) email.o
- X mv a.out email
- X
- Xndf: ndf.o
- X $(CC) ndf.o
- X mv a.out ndf
- X
- Xtecho: techo.o
- X $(CC) techo.o
- X mv a.out techo
- X
- Xwclipper: wclipper.o
- X $(CC) wclipper.o
- X mv a.out wclipper
- X
- END_OF_FILE
- if test 374 -ne `wc -c <'Makefile'`; then
- echo shar: \"'Makefile'\" unpacked with wrong size!
- fi
- # end of 'Makefile'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(4280 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XThis is the README file for the Dave Brierley collection of miscellaneous
- Xsource programs. The collection is posted in seven separate pieces but
- Xall of the source came from the "misc" directory on my machine. As a result
- Xof this, there is only one README file and only one Makefile, although each
- Xof the seven postings will contain a copy of these two files. I suggest
- Xthat you obtain (or save) as many of these postings as you are interested
- Xin, unpack them all in a single directory, and then compile the sources.
- XNote that some of the programs are actually shell scripts and therefore do
- Xnot need compilation.
- X
- XINSTALLATION INSTRUCTIONS:
- X1. Compile all the source programs by typing "make all". Edit the Makefile
- X if you did not unpack all seven of the pieces. Note that the Makefile
- X does not contain explicit commands for using the shared library. I always
- X depend on "ccc" to do this for me.
- X2. Copy the resultant executables to your favorite bin directory. I always
- X use "/usr/local/bin".
- X3. Copy the various shell scripts to the bin directory and make then executable
- X using the chmod command. The shell scripts are all distributed with a
- X suffix of ".sh". I suggest you remove this suffix when you install it, but
- X that is entirely up to you.
- X
- X
- XDescription of programs included in this package. There is a line of dashes
- Xseparating each of the seven pieces.
- X
- Xbsdln.c
- X A version of the ln command that follows the BSD behaviour. I.e. if the
- X target file exists, the command will fail. The standard 3b1 version will
- X remove the target.
- X
- X--------------------------------------------------------------------------
- X
- Xinstall.sh
- X A shell script version of the BSD install command.
- X
- Xnull.sh
- X Zero out one or more files.
- X
- Xtolower.sh
- X Convert file names to lower case. Requires ksh.
- X
- Xtoupper.sh
- X Convert file names to upper case. Requires ksh.
- X
- X--------------------------------------------------------------------------
- X
- Xndf.c
- X Almost emulates the BSD df command. I say "almost" because I chose to
- X display the numbers in terms of blocks instead of kbytes since everything
- X else on the machine displays sizes in blocks. Supports the "-i" option
- X to displays inode information. Also supports specifying any random
- X directory as an argument and it will figure out what file system it is.
- X
- X--------------------------------------------------------------------------
- X
- Xdisktest.c
- X A program used by the format script to test the floppy disk to be doubly
- X sure that it is usable.
- X
- Xformat.sh
- X Format a floppy disk. Asks questions to determine desired parameters, such
- X as number of cylinders and number of sectors. Will optionally run an
- X intensive surface test of the floppy (see disktest.c), build a file system
- X structure, and make the floppy bootable. The main processing is done in a
- X loop so you can format multiple floppies easily.
- X
- Xnewfs.sh
- X Reads the VHB from the floppy and then builds a file system structure on it.
- X
- X--------------------------------------------------------------------------
- X
- Xtecho.c
- X A version of echo that allows direct access to termcap capabilities. A lot
- X easier to use than intermixing calls to echo with calls to tput.
- X
- Xtecho.1
- X Hey, I actually wrote a man page for this one!
- X
- X--------------------------------------------------------------------------
- X
- Xwclipper.c
- X A program to read in the wtmp file and output the tail end of it. Useful
- X if you want to maintain an N-day history of who has been using your system.
- X The output size can be specified in terms of days or kbytes.
- X
- Xwtmp.fix.sh
- X A shell script to control the operation of wclipper.
- X
- X--------------------------------------------------------------------------
- X
- Xemail.c
- X A version of the "email" program. This program should be installed as
- X /usr/bin/email and it will be used by pcmgr (or by smgr) when you click
- X on the envelope icon. It provides a safe interface to the mail program
- X by making sure the uid is set correctly and by doing a chdir to the
- X users home directory (both of which are already being done by pcmgr).
- X This version also provides a unique feature of reading an "rc" file
- X from the users home directory (~/.email.rc), which can be used to specify
- X what mail program to use. See the sample provided.
- X
- Xemail.rc
- X Sample .email.rc file.
- END_OF_FILE
- if test 4280 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'techo.1' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'techo.1'\"
- else
- echo shar: Extracting \"'techo.1'\" \(1909 characters\)
- sed "s/^X//" >'techo.1' <<'END_OF_FILE'
- X.TH TECHO LOCAL "SSD-SGF UNIX Manual"
- X.UC
- X.SH NAME
- Xtecho \- echo program with termcap capabilities
- X.SH SYNOPSIS
- X.nf
- Xtecho [-n] arguments ...
- X.fi
- X.SH DESCRIPTION
- XThe
- X.I techo
- Xprogram is very similar to the
- X.I echo
- Xprogram, with the added capability of being able to print strings
- Xfrom the termcap data base. This capability makes it possible to
- Xwrite a shell script which includes screen oriented functions in a
- Xterminal independant manner. Some of the more common termcap items
- Xthat can be selected include: clear screen, cursor motion, standout
- Xmode, and underline mode. It is also possible to print the value
- Xof the various boolean flags and numeric variables defined in the
- Xtermcap data base.
- X.SH "SUMMARY OF ARGUMENT FORMAT"
- XArguments that begin and end with a colon are interpreted as requests for
- Xtermcap variables, subject to the following rules.
- X.TP 15
- X:xx:
- XPrint the value of the boolean flag xx.
- X.TP
- X:xx#:
- XPrint the value of the numeric variable xx.
- X.TP
- X:xx=:
- XPrint the value of the string variable xx.
- X.TP
- X:xx=a,b:
- XTreat the string variable xx as a cursor motion string with arguments
- Xof a and b.
- X.SH NOTES
- XArguments that are not in one of the above formats are treated as simple
- Xstrings and are just printed out. Selecting a string item which is not
- Xdefined for your terminal causes nothing to be printed. Selecting a
- Xnumeric item which is not defined for your terminal causes a zero to
- Xbe printed. Selecting a boolean flag will cause a one to be printed
- Xif the flag is defined and a zero otherwise.
- X.SH EXAMPLES
- X.sp
- Xtecho :so=: "this will be printed in standout mode" :se=:
- X.sp
- Xtecho :cl=: "clear the screen before printing this"
- X.sp
- Xtecho :cm=10,25: "print at row 10, column 25"
- X.sp
- XRefer to the manual page for termcap(5) for a complete list of the
- Xitems that are normally defined.
- X.SH FILES
- X/etc/termcap termcap data base
- X.SH "SEE ALSO"
- Xecho(1), termcap(5)
- X.SH "AUTHOR"
- XD.H. Brierley
- END_OF_FILE
- if test 1909 -ne `wc -c <'techo.1'`; then
- echo shar: \"'techo.1'\" unpacked with wrong size!
- fi
- # end of 'techo.1'
- fi
- if test -f 'techo.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'techo.c'\"
- else
- echo shar: Extracting \"'techo.c'\" \(4827 characters\)
- sed "s/^X//" >'techo.c' <<'END_OF_FILE'
- X/*----------------------------------------------------------------------*
- X *
- X * Program: techo
- X *
- X * Function:
- X * This program is an echo program that allows items from the
- X * termcap data base to be included in the output. Termcap
- X * items are selected using the following format:
- X *
- X * :xx: print the value of the boolean flag
- X * :xx#: print the value of the numeric variable xx
- X * :xx=: print the value of the string variable xx
- X * :xx=a:
- X * :xx=a,b:
- X * :xx=,b: treat the variable xx as a cursor motion string with
- X * values of a and b. if only one number is given, the
- X * other one defaults to zero.
- X *
- X * Arguments that are not in one of the above formats are treated
- X * as simple strings and are just printed out. Selecting a string
- X * item which is not defined for your terminal causes nothing to
- X * be printed. Selecting a numeric variable which is not defined
- X * for your terminal causes a zero to be printed. Selecting a
- X * boolean flag will cause a one to be printed if the flag is
- X * defined and a zero otherwise.
- X *
- X *----------------------------------------------------------------------*/
- X
- X/***********************************************************************
- X *
- X * Copyright 1986 David H. Brierley
- 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 * 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 * 2. The origin of this software must not be misrepresented, either
- X * by explicit claim or by omission.
- X * 3. Altered versions must be plainly marked as such, and must not
- X * be misrepresented as being the original software.
- X *
- X ***********************************************************************/
- X
- X#ifndef lint
- Xstatic char *SccsId = "@(#) techo.c version 1.1 9/28/86 (rayssd!dhb)";
- X#endif
- X
- X#include <stdio.h>
- X#include <sgtty.h>
- X
- Xextern int tgetent ();
- Xextern int tgetnum ();
- Xextern int tgetflag ();
- Xextern char *tgetstr ();
- Xextern char *tgoto ();
- Xextern char *getenv ();
- Xextern char *strcpy ();
- Xextern char *strchr ();
- Xextern short ospeed;
- X
- Xmain (argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int argx;
- X int nlflag = 1;
- X int spflag = 0;
- X
- X argx = 0;
- X if (argc >= 2) {
- X if (strcmp (argv[1], "-n") == 0) {
- X nlflag = 0;
- X argx++;
- X }
- X }
- X while (++argx < argc) {
- X if (tcheck (argv[argx]) == 1) {
- X spflag = 0;
- X continue;
- X }
- X if (spflag) {
- X printf (" ");
- X }
- X printf ("%s", argv[argx]);
- X spflag++;
- X }
- X if (nlflag) {
- X printf ("\n");
- X }
- X (void) fflush (stdout);
- X exit (0);
- X
- X}
- X
- Xtcheck (arg)
- Xchar *arg;
- X{
- X auto int n;
- X auto int x;
- X auto int y;
- X static char tcapbuff[1024];
- X static char tstring[1024];
- X auto char *tptr;
- X auto char *aoft;
- X auto int tvalue;
- X auto char colon;
- X static char ttype[64];
- X static char option[32];
- X static int tvalid = 0;
- X static int need_init = 1;
- X static struct sgttyb tty_buf;
- X extern int outc ();
- X
- X if (*arg != ':') {
- X return (0);
- X }
- X if (need_init) {
- X need_init = 0;
- X if ((tptr = getenv ("TERM")) == NULL) {
- X return (0);
- X }
- X (void) strcpy (ttype, tptr);
- X if (tgetent (tcapbuff, ttype) != 1) {
- X return (0);
- X }
- X if (ioctl (1, TIOCGETP, (char *) &tty_buf) != -1) {
- X ospeed = tty_buf.sg_ospeed;
- X }
- X tvalid = 1;
- X }
- X
- X if (tvalid == 0) {
- X return (0);
- X }
- X
- X tptr = strchr (arg + 1, ':');
- X if ((tptr == NULL) || (*++tptr != '\0')) {
- X return (0);
- X }
- X
- X tptr = arg + 1;
- X n = 0;
- X while (*tptr) {
- X if ((*tptr == '=') || (*tptr == '#') || (*tptr == ':')) {
- X break;
- X }
- X option[n++] = *tptr++;
- X }
- X option[n] = '\0';
- X
- X switch (*tptr) {
- X case '#':
- X if (*++tptr != ':') {
- X return (0);
- X }
- X if (*++tptr != '\0') {
- X return (0);
- X }
- X tvalue = tgetnum (option);
- X if (tvalue < 0) {
- X tvalue = 0;
- X }
- X printf ("%d", tvalue);
- X return (1);
- X case ':':
- X if (*++tptr != '\0') {
- X return (0);
- X }
- X tvalue = tgetflag (option);
- X printf ("%d", tvalue);
- X return (1);
- X case '=':
- X aoft = tstring;
- X if (tgetstr (option, &aoft) == NULL) {
- X return (1);
- X }
- X n = 0;
- X if ((colon = *++tptr) != ':') {
- X n = sscanf (tptr, "%d,%d%c", &x, &y, &colon);
- X if (n != 3) {
- X y = 0;
- X n = sscanf (tptr, "%d%c", &x, &colon);
- X if (n != 2) {
- X x = 0;
- X n = sscanf (tptr, ",%d%c", &y, &colon);
- X }
- X }
- X }
- X if (colon != ':') {
- X return (0);
- X }
- X if (n != 0) {
- X tptr = tgoto (tstring, y, x);
- X }
- X else {
- X tptr = tstring;
- X }
- X tputs (tptr, 1, outc);
- X return (1);
- X default:
- X return (0);
- X }
- X
- X}
- X
- Xoutc (ch)
- Xint ch;
- X{
- X
- X (void) fputc (ch, stdout);
- X
- X}
- END_OF_FILE
- if test 4827 -ne `wc -c <'techo.c'`; then
- echo shar: \"'techo.c'\" unpacked with wrong size!
- fi
- # end of 'techo.c'
- fi
- echo shar: End of archive 1 \(of 1\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have the archive.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
- --
- David H. Brierley
- Home: dave@galaxia.network23.com; Work: dhb@quahog.ssd.ray.com
- Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.network23.com
- %% Can I be excused, my brain is full. **
-