home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 419b.lha / TERMLIB / cur.c < prev    next >
C/C++ Source or Header  |  1990-10-05  |  1KB  |  54 lines

  1. /* Cur: Provide cursor addressing for shell scripts.
  2.  *
  3.  * Cur performs the same functions as echo, with 2 differences:
  4.  *  1. 
  5.  *     a. Arguments of the form -xx result in the generation of the capability
  6.  *        string xx. The two special strings "cm" and "cs" are handled by
  7.  *        cur ... -cm x y ... and ... -cs lo hi ...
  8.  *     b. Arguments of the form #xx return the value of the numeric capability
  9.  *        xx.
  10.  *     c. Arguments of the form +terminal force cur to assume that as the
  11.  *        terminal type. Any number of these can be included, and will be
  12.  *        evaluated when encountered.
  13.  *  2. No newline is appended to the echoed string.
  14.  *
  15.  * Syntax: cur [string|-xx|#xx|+term]...
  16.  *
  17.  * Other notes: The code is obvious.
  18.  */
  19. #include <stdio.h>
  20. #include "termlib.h"
  21.  
  22. extern char *junkptr;
  23.  
  24. main(ac, av)
  25. int ac; char **av;
  26. {
  27.     int line, col, outch();
  28.     char *val;
  29.  
  30.     tinit(getenv("TERM"));
  31.  
  32.     while(--ac)
  33.         if(**++av=='-') {
  34.             if(val=tgetstr(*av+1, &junkptr)) {
  35.                 if(strcmp(*av+1, "cm") &&
  36.                    strcmp(*av+1, "cs"))
  37.                     tputs(val, 1, outch);
  38.                 else {
  39.                     col = atoi(*++av); --ac;
  40.                     line = atoi(*++av); --ac;
  41.                     tputs(tgoto(val, col, line), 0, outch);
  42.                 }
  43.             }
  44.         } else if(**av=='#') {
  45.             if(val = tgetstr(*av+1, &junkptr))
  46.                 fputs(val, stdout);
  47.         } else if(**av=='+') {
  48.             tinit(*av+1);
  49.         } else
  50.             fputs(*av, stdout);
  51. }
  52.  
  53. outch(c) char c; { putchar(c); }
  54.