home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / 3b1 / volume02 / techo / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-07-20  |  15.7 KB

  1. Path: comp-sources-3b1
  2. From: dave@galaxia.network23.com (David H. Brierley)
  3. Subject:  v02i027:  echo command with termcap escape sequences, Part01/01
  4. Newsgroups: comp.sources.3b1
  5. Approved: dave@galaxia.network23.com
  6. X-Checksum-Snefru: bf87c992 86988075 ba669022 cbcab398
  7.  
  8. Submitted-by: dave@galaxia.network23.com (David H. Brierley)
  9. Posting-number: Volume 2, Issue 27
  10. Archive-name: techo/part01
  11.  
  12. This is the README file for the Dave Brierley collection of miscellaneous
  13. source programs.  The collection is posted in seven separate pieces but
  14. all of the source came from the "misc" directory on my machine.  As a result
  15. of this, there is only one README file and only one Makefile, although each
  16. of the seven postings will contain a copy of these two files.  I suggest
  17. that you obtain (or save) as many of these postings as you are interested
  18. in, unpack them all in a single directory, and then compile the sources.
  19. Note that some of the programs are actually shell scripts and therefore do
  20. not need compilation.
  21.  
  22. techo.c
  23.  A version of echo that allows direct access to termcap capabilities.  A lot
  24.  easier to use than intermixing calls to echo with calls to tput.
  25.  
  26. techo.1
  27.  Hey, I actually wrote a man page for this one!
  28.  
  29. #! /bin/sh
  30. # This is a shell archive.  Remove anything before this line, then unpack
  31. # it by saving it into a file and typing "sh file".  To overwrite existing
  32. # files, type "sh file -c".  You can also feed this as standard input via
  33. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  34. # will see the following message at the end:
  35. #        "End of archive 1 (of 1)."
  36. # Contents:  MANIFEST Makefile README techo.1 techo.c
  37. # Wrapped by dave@galaxia on Tue Jul 21 10:44:42 1992
  38. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  39. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  41. else
  42. echo shar: Extracting \"'MANIFEST'\" \(251 characters\)
  43. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  44. X   File Name        Archive #    Description
  45. X-----------------------------------------------------------
  46. X MANIFEST                   1    
  47. X Makefile                   1    
  48. X README                     1    
  49. X techo.1                    1    
  50. X techo.c                    1    
  51. END_OF_FILE
  52. if test 251 -ne `wc -c <'MANIFEST'`; then
  53.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  54. fi
  55. # end of 'MANIFEST'
  56. fi
  57. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  58.   echo shar: Will not clobber existing file \"'Makefile'\"
  59. else
  60. echo shar: Extracting \"'Makefile'\" \(374 characters\)
  61. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  62. XCFLAGS    = -O
  63. X
  64. Xall:        bsdln disktest email ndf techo wclipper
  65. X
  66. Xbsdln:        bsdln.o
  67. X        $(CC) bsdln.o
  68. X        mv a.out bsdln
  69. X
  70. Xdisktest:    disktest.o
  71. X        $(CC) disktest.o
  72. X        mv a.out disktest
  73. X
  74. Xemail:        email.o
  75. X        $(CC) email.o
  76. X        mv a.out email
  77. X
  78. Xndf:        ndf.o
  79. X        $(CC) ndf.o
  80. X        mv a.out ndf
  81. X
  82. Xtecho:        techo.o
  83. X        $(CC) techo.o
  84. X        mv a.out techo
  85. X
  86. Xwclipper:    wclipper.o
  87. X        $(CC) wclipper.o
  88. X        mv a.out wclipper
  89. X
  90. END_OF_FILE
  91. if test 374 -ne `wc -c <'Makefile'`; then
  92.     echo shar: \"'Makefile'\" unpacked with wrong size!
  93. fi
  94. # end of 'Makefile'
  95. fi
  96. if test -f 'README' -a "${1}" != "-c" ; then 
  97.   echo shar: Will not clobber existing file \"'README'\"
  98. else
  99. echo shar: Extracting \"'README'\" \(4280 characters\)
  100. sed "s/^X//" >'README' <<'END_OF_FILE'
  101. XThis is the README file for the Dave Brierley collection of miscellaneous
  102. Xsource programs.  The collection is posted in seven separate pieces but
  103. Xall of the source came from the "misc" directory on my machine.  As a result
  104. Xof this, there is only one README file and only one Makefile, although each
  105. Xof the seven postings will contain a copy of these two files.  I suggest
  106. Xthat you obtain (or save) as many of these postings as you are interested
  107. Xin, unpack them all in a single directory, and then compile the sources.
  108. XNote that some of the programs are actually shell scripts and therefore do
  109. Xnot need compilation.
  110. X
  111. XINSTALLATION INSTRUCTIONS:
  112. X1. Compile all the source programs by typing "make all".  Edit the Makefile
  113. X   if you did not unpack all seven of the pieces.  Note that the Makefile
  114. X   does not contain explicit commands for using the shared library.  I always
  115. X   depend on "ccc" to do this for me.
  116. X2. Copy the resultant executables to your favorite bin directory.  I always
  117. X   use "/usr/local/bin".
  118. X3. Copy the various shell scripts to the bin directory and make then executable
  119. X   using the chmod command.  The shell scripts are all distributed with a
  120. X   suffix of ".sh".  I suggest you remove this suffix when you install it, but
  121. X   that is entirely up to you.
  122. X
  123. X
  124. XDescription of programs included in this package.  There is a line of dashes
  125. Xseparating each of the seven pieces.
  126. X
  127. Xbsdln.c
  128. X A version of the ln command that follows the BSD behaviour.  I.e. if the
  129. X target file exists, the command will fail.  The standard 3b1 version will
  130. X remove the target.
  131. X
  132. X--------------------------------------------------------------------------
  133. X
  134. Xinstall.sh
  135. X A shell script version of the BSD install command.
  136. X
  137. Xnull.sh
  138. X Zero out one or more files.
  139. X
  140. Xtolower.sh
  141. X Convert file names to lower case.  Requires ksh.
  142. X
  143. Xtoupper.sh
  144. X Convert file names to upper case.  Requires ksh.
  145. X
  146. X--------------------------------------------------------------------------
  147. X
  148. Xndf.c
  149. X Almost emulates the BSD df command.  I say "almost" because I chose to
  150. X display the numbers in terms of blocks instead of kbytes since everything
  151. X else on the machine displays sizes in blocks.  Supports the "-i" option
  152. X to displays inode information.  Also supports specifying any random
  153. X directory as an argument and it will figure out what file system it is.
  154. X
  155. X--------------------------------------------------------------------------
  156. X
  157. Xdisktest.c
  158. X A program used by the format script to test the floppy disk to be doubly
  159. X sure that it is usable.
  160. X
  161. Xformat.sh
  162. X Format a floppy disk.  Asks questions to determine desired parameters, such
  163. X as number of cylinders and number of sectors.  Will optionally run an
  164. X intensive surface test of the floppy (see disktest.c), build a file system
  165. X structure, and make the floppy bootable.  The main processing is done in a
  166. X loop so you can format multiple floppies easily.
  167. X
  168. Xnewfs.sh
  169. X Reads the VHB from the floppy and then builds a file system structure on it.
  170. X
  171. X--------------------------------------------------------------------------
  172. X
  173. Xtecho.c
  174. X A version of echo that allows direct access to termcap capabilities.  A lot
  175. X easier to use than intermixing calls to echo with calls to tput.
  176. X
  177. Xtecho.1
  178. X Hey, I actually wrote a man page for this one!
  179. X
  180. X--------------------------------------------------------------------------
  181. X
  182. Xwclipper.c
  183. X A program to read in the wtmp file and output the tail end of it.  Useful
  184. X if you want to maintain an N-day history of who has been using your system.
  185. X The output size can be specified in terms of days or kbytes.
  186. X
  187. Xwtmp.fix.sh
  188. X A shell script to control the operation of wclipper.
  189. X
  190. X--------------------------------------------------------------------------
  191. X
  192. Xemail.c
  193. X A version of the "email" program.  This program should be installed as
  194. X /usr/bin/email and it will be used by pcmgr (or by smgr) when you click
  195. X on the envelope icon.  It provides a safe interface to the mail program
  196. X by making sure the uid is set correctly and by doing a chdir to the
  197. X users home directory (both of which are already being done by pcmgr).
  198. X This version also provides a unique feature of reading an "rc" file
  199. X from the users home directory (~/.email.rc), which can be used to specify
  200. X what mail program to use.  See the sample provided.
  201. X
  202. Xemail.rc
  203. X Sample .email.rc file.
  204. END_OF_FILE
  205. if test 4280 -ne `wc -c <'README'`; then
  206.     echo shar: \"'README'\" unpacked with wrong size!
  207. fi
  208. # end of 'README'
  209. fi
  210. if test -f 'techo.1' -a "${1}" != "-c" ; then 
  211.   echo shar: Will not clobber existing file \"'techo.1'\"
  212. else
  213. echo shar: Extracting \"'techo.1'\" \(1909 characters\)
  214. sed "s/^X//" >'techo.1' <<'END_OF_FILE'
  215. X.TH TECHO LOCAL "SSD-SGF UNIX Manual"
  216. X.UC
  217. X.SH NAME
  218. Xtecho \- echo program with termcap capabilities
  219. X.SH SYNOPSIS
  220. X.nf
  221. Xtecho [-n] arguments ...
  222. X.fi 
  223. X.SH DESCRIPTION
  224. XThe
  225. X.I techo
  226. Xprogram is very similar to the
  227. X.I echo
  228. Xprogram, with the added capability of being able to print strings
  229. Xfrom the termcap data base.  This capability makes it possible to
  230. Xwrite a shell script which includes screen oriented functions in a
  231. Xterminal independant manner.  Some of the more common termcap items
  232. Xthat can be selected include: clear screen, cursor motion, standout
  233. Xmode, and underline mode.  It is also possible to print the value
  234. Xof the various boolean flags and numeric variables defined in the
  235. Xtermcap data base.
  236. X.SH "SUMMARY OF ARGUMENT FORMAT"
  237. XArguments that begin and end with a colon are interpreted as requests for
  238. Xtermcap variables, subject to the following rules.
  239. X.TP 15
  240. X:xx:
  241. XPrint the value of the boolean flag xx.
  242. X.TP
  243. X:xx#:
  244. XPrint the value of the numeric variable xx.
  245. X.TP
  246. X:xx=:
  247. XPrint the value of the string variable xx.
  248. X.TP
  249. X:xx=a,b:
  250. XTreat the string variable xx as a cursor motion string with arguments
  251. Xof a and b.
  252. X.SH NOTES
  253. XArguments that are not in one of the above formats are treated as simple
  254. Xstrings and are just printed out.  Selecting a string item which is not
  255. Xdefined for your terminal causes nothing to be printed.  Selecting a
  256. Xnumeric item which is not defined for your terminal causes a zero to
  257. Xbe printed.  Selecting a boolean flag will cause a one to be printed
  258. Xif the flag is defined and a zero otherwise.
  259. X.SH EXAMPLES
  260. X.sp
  261. Xtecho :so=: "this will be printed in standout mode" :se=:
  262. X.sp
  263. Xtecho :cl=: "clear the screen before printing this"
  264. X.sp
  265. Xtecho :cm=10,25: "print at row 10, column 25"
  266. X.sp
  267. XRefer to the manual page for termcap(5) for a complete list of the
  268. Xitems that are normally defined.
  269. X.SH FILES
  270. X/etc/termcap  termcap data base
  271. X.SH "SEE ALSO"
  272. Xecho(1), termcap(5)
  273. X.SH "AUTHOR"
  274. XD.H. Brierley 
  275. END_OF_FILE
  276. if test 1909 -ne `wc -c <'techo.1'`; then
  277.     echo shar: \"'techo.1'\" unpacked with wrong size!
  278. fi
  279. # end of 'techo.1'
  280. fi
  281. if test -f 'techo.c' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'techo.c'\"
  283. else
  284. echo shar: Extracting \"'techo.c'\" \(4827 characters\)
  285. sed "s/^X//" >'techo.c' <<'END_OF_FILE'
  286. X/*----------------------------------------------------------------------*
  287. X *
  288. X * Program: techo
  289. X *
  290. X * Function:
  291. X *     This program is an echo program that allows items from the
  292. X *    termcap data base to be included in the output.  Termcap
  293. X *    items are selected using the following format:
  294. X *
  295. X *    :xx:    print the value of the boolean flag
  296. X *    :xx#:    print the value of the numeric variable xx
  297. X *    :xx=:    print the value of the string variable xx
  298. X *    :xx=a:
  299. X *    :xx=a,b:
  300. X *    :xx=,b: treat the variable xx as a cursor motion string with
  301. X *        values of a and b.  if only one number is given, the
  302. X *        other one defaults to zero.
  303. X *
  304. X *    Arguments that are not in one of the above formats are treated
  305. X *    as simple strings and are just printed out.  Selecting a string
  306. X *    item which is not defined for your terminal causes nothing to
  307. X *    be printed.  Selecting a numeric variable which is not defined
  308. X *    for your terminal causes a zero to be printed.  Selecting a
  309. X *    boolean flag will cause a one to be printed if the flag is 
  310. X *    defined and a zero otherwise.
  311. X *
  312. X *----------------------------------------------------------------------*/
  313. X
  314. X/***********************************************************************
  315. X *
  316. X *  Copyright 1986 David H. Brierley
  317. X *  
  318. X *  Permission is granted to anyone to use this software for any
  319. X *  purpose on any computer system, and to redistribute it freely,
  320. X *  subject to the following restrictions:
  321. X *  1. The author is not responsible for the consequences of use of
  322. X *      this software, no matter how awful, even if they arise
  323. X *      from defects in it.
  324. X *  2. The origin of this software must not be misrepresented, either
  325. X *      by explicit claim or by omission.
  326. X *  3. Altered versions must be plainly marked as such, and must not
  327. X *      be misrepresented as being the original software.
  328. X *
  329. X ***********************************************************************/
  330. X
  331. X#ifndef lint
  332. Xstatic  char   *SccsId = "@(#) techo.c version 1.1 9/28/86 (rayssd!dhb)";
  333. X#endif
  334. X
  335. X#include <stdio.h>
  336. X#include <sgtty.h>
  337. X
  338. Xextern  int     tgetent ();
  339. Xextern  int     tgetnum ();
  340. Xextern  int     tgetflag ();
  341. Xextern  char   *tgetstr ();
  342. Xextern  char   *tgoto ();
  343. Xextern  char   *getenv ();
  344. Xextern  char   *strcpy ();
  345. Xextern  char   *strchr ();
  346. Xextern  short   ospeed;
  347. X
  348. Xmain (argc, argv)
  349. Xint     argc;
  350. Xchar   *argv[];
  351. X{
  352. X    int     argx;
  353. X    int     nlflag = 1;
  354. X    int     spflag = 0;
  355. X
  356. X    argx = 0;
  357. X    if (argc >= 2) {
  358. X    if (strcmp (argv[1], "-n") == 0) {
  359. X        nlflag = 0;
  360. X        argx++;
  361. X    }
  362. X    }
  363. X    while (++argx < argc) {
  364. X    if (tcheck (argv[argx]) == 1) {
  365. X        spflag = 0;
  366. X        continue;
  367. X    }
  368. X    if (spflag) {
  369. X        printf (" ");
  370. X    }
  371. X    printf ("%s", argv[argx]);
  372. X    spflag++;
  373. X    }
  374. X    if (nlflag) {
  375. X    printf ("\n");
  376. X    }
  377. X    (void) fflush (stdout);
  378. X    exit (0);
  379. X
  380. X}
  381. X
  382. Xtcheck (arg)
  383. Xchar   *arg;
  384. X{
  385. X    auto    int     n;
  386. X    auto    int     x;
  387. X    auto    int     y;
  388. X    static  char    tcapbuff[1024];
  389. X    static  char    tstring[1024];
  390. X    auto    char   *tptr;
  391. X    auto    char   *aoft;
  392. X    auto    int     tvalue;
  393. X    auto    char    colon;
  394. X    static  char    ttype[64];
  395. X    static  char    option[32];
  396. X    static  int     tvalid = 0;
  397. X    static  int     need_init = 1;
  398. X    static  struct  sgttyb   tty_buf;
  399. X    extern  int     outc ();
  400. X
  401. X    if (*arg != ':') {
  402. X    return (0);
  403. X    }
  404. X    if (need_init) {
  405. X    need_init = 0;
  406. X    if ((tptr = getenv ("TERM")) == NULL) {
  407. X        return (0);
  408. X    }
  409. X    (void) strcpy (ttype, tptr);
  410. X    if (tgetent (tcapbuff, ttype) != 1) {
  411. X        return (0);
  412. X    }
  413. X    if (ioctl (1, TIOCGETP, (char *) &tty_buf) != -1) {
  414. X        ospeed = tty_buf.sg_ospeed;
  415. X    }
  416. X    tvalid = 1;
  417. X    }
  418. X
  419. X    if (tvalid == 0) {
  420. X    return (0);
  421. X    }
  422. X
  423. X    tptr = strchr (arg + 1, ':');
  424. X    if ((tptr == NULL) || (*++tptr != '\0')) {
  425. X    return (0);
  426. X    }
  427. X
  428. X    tptr = arg + 1;
  429. X    n = 0;
  430. X    while (*tptr) {
  431. X    if ((*tptr == '=') || (*tptr == '#') || (*tptr == ':')) {
  432. X        break;
  433. X    }
  434. X    option[n++] = *tptr++;
  435. X    }
  436. X    option[n] = '\0';
  437. X
  438. X    switch (*tptr) {
  439. X    case '#': 
  440. X    if (*++tptr != ':') {
  441. X        return (0);
  442. X    }
  443. X    if (*++tptr != '\0') {
  444. X        return (0);
  445. X    }
  446. X    tvalue = tgetnum (option);
  447. X    if (tvalue < 0) {
  448. X        tvalue = 0;
  449. X    }
  450. X    printf ("%d", tvalue);
  451. X    return (1);
  452. X    case ':': 
  453. X    if (*++tptr != '\0') {
  454. X        return (0);
  455. X    }
  456. X    tvalue = tgetflag (option);
  457. X    printf ("%d", tvalue);
  458. X    return (1);
  459. X    case '=': 
  460. X    aoft = tstring;
  461. X    if (tgetstr (option, &aoft) == NULL) {
  462. X        return (1);
  463. X    }
  464. X    n = 0;
  465. X    if ((colon = *++tptr) != ':') {
  466. X        n = sscanf (tptr, "%d,%d%c", &x, &y, &colon);
  467. X        if (n != 3) {
  468. X        y = 0;
  469. X        n = sscanf (tptr, "%d%c", &x, &colon);
  470. X        if (n != 2) {
  471. X            x = 0;
  472. X            n = sscanf (tptr, ",%d%c", &y, &colon);
  473. X        }
  474. X        }
  475. X    }
  476. X    if (colon != ':') {
  477. X        return (0);
  478. X    }
  479. X    if (n != 0) {
  480. X        tptr = tgoto (tstring, y, x);
  481. X    }
  482. X    else {
  483. X        tptr = tstring;
  484. X    }
  485. X    tputs (tptr, 1, outc);
  486. X    return (1);
  487. X    default: 
  488. X    return (0);
  489. X    }
  490. X
  491. X}
  492. X
  493. Xoutc (ch)
  494. Xint     ch;
  495. X{
  496. X
  497. X    (void) fputc (ch, stdout);
  498. X
  499. X}
  500. END_OF_FILE
  501. if test 4827 -ne `wc -c <'techo.c'`; then
  502.     echo shar: \"'techo.c'\" unpacked with wrong size!
  503. fi
  504. # end of 'techo.c'
  505. fi
  506. echo shar: End of archive 1 \(of 1\).
  507. cp /dev/null ark1isdone
  508. MISSING=""
  509. for I in 1 ; do
  510.     if test ! -f ark${I}isdone ; then
  511.     MISSING="${MISSING} ${I}"
  512.     fi
  513. done
  514. if test "${MISSING}" = "" ; then
  515.     echo You have the archive.
  516.     rm -f ark[1-9]isdone
  517. else
  518.     echo You still need to unpack the following archives:
  519.     echo "        " ${MISSING}
  520. fi
  521. ##  End of shell archive.
  522. exit 0
  523. -- 
  524. David H. Brierley
  525. Home: dave@galaxia.network23.com; Work: dhb@quahog.ssd.ray.com
  526. Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.network23.com
  527. %% Can I be excused, my brain is full. **
  528.