home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sources / 3b1 / 80 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  15.9 KB

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