home *** CD-ROM | disk | FTP | other *** search
- #ifndef LINT
- static char rcsid[] = "$Header: tput.c,v 1.2 86/08/22 13:39:27 badri Exp $" ;
- #endif LINT
- /*
- * Copyright (C) $Date: 86/08/22 13:39:27 $
- * by $Author: badri $
- * University of Rochester,
- * Department of Electrical Engineering.
- *
- * CoNtEnTs This file contains a program to emulate the system V
- * CoNtEnTs version of tput.
- *
- * $Locker: badri $
- * $Source: /u/users/badri/usr/src/local/tput/RCS/tput.c,v $
- * $Revision: 1.2 $
- *
- * History of this release:
- * $Log: tput.c,v $
- * Revision 1.2 86/08/22 13:39:27 badri
- * 1. Corrected a bug that would cause %d to fail after %%.
- * 2. Included XTABS handling.
- * 3. General cleanup of code.
- *
- * Revision 1.1 86/08/21 19:23:33 badri
- * Initial revision
- *
- */
- #include <sgtty.h>
-
- #ifndef XTABS
- #define XTABS 0006000
- #endif XTABS
-
- #define LARGEBUF 1024
- #define SMALLBUF 64
- #define OUTPUT 1
- #define SUCCESS 0
- #define FAILURE 1
- #define AFFLINES 1
-
- int errno;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- char bp[LARGEBUF], *getenv(), *tgetstr(), *tgoto(),
- buf[SMALLBUF], *area, *ptr;
- int outc();
- struct sgttyb ttyprm;
- short ttyflg;
-
- if (argc < 2) exit(FAILURE);
-
- switch (tgetent(bp,getenv("TERM")))
- {
- case -1:
- exit(FAILURE);
-
- case 0:
- exit(FAILURE);
-
- case 1:
- break;
- }
- area = buf;
- if (*(ptr=tgetstr(argv[1],&area)) == '\0') exit(FAILURE);
-
- /*
- * Examine if cursor movement specified. This is done
- * by looking for % followed by any but %. Since %%
- * is a single %, we have to make sure that %% followed
- * by any but % is not interpreted as a format.
- * If cursor movement is specified then tgoto needs
- * to be invoked. Else put as is.
- */
- ptr = buf;
- while (*ptr != '\0')
- {
- if (*(ptr++) != '%') continue;
- if (*ptr != '\0' && *(ptr++) != '%')
- {
- /* This string is a cm string. */
- if (argc != 4) exit(FAILURE);
-
- if (*(ptr=tgoto(buf,atoi(argv[2]),atoi(argv[3]))) == 'O'
- && *(ptr+1) == 'O' && *(ptr+2) == 'P'
- && *(ptr+3) == 'S') exit(FAILURE);
-
- /* Turn off XTABS, but save old flags first. */
- if (gtty(OUTPUT,&ttyprm) < 0) exit(errno);
- ttyflg = ttyprm.sg_flags;
-
- ttyprm.sg_flags &= ~XTABS;
- if (stty(OUTPUT,&ttyprm) < 0) exit(errno);
-
- tputs(ptr,AFFLINES,outc);
-
- /* Restore old flags. */
- ttyprm.sg_flags = ttyflg;
- if (stty(OUTPUT,&ttyprm) < 0) exit(errno);
- exit(SUCCESS);
- }
- exit(FAILURE);
- }
- tputs(buf,AFFLINES,outc);
- exit(errno);
- }
-
- outc(c)
- char c;
- {
- if (write(OUTPUT,&c,sizeof(char)) < 0) exit(errno);
- return(SUCCESS);
- }
-