1: /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.00/RCS/sh.print.c,v 3.0 1991/07/04 21:49:28 christos Exp $ */
   2: /*
   3:  * sh.print.c: Primitive Output routines.
   4:  */
   5: /*-
   6:  * Copyright (c) 1980, 1991 The Regents of the University of California.
   7:  * All rights reserved.
   8:  *
   9:  * Redistribution and use in source and binary forms, with or without
  10:  * modification, are permitted provided that the following conditions
  11:  * are met:
  12:  * 1. Redistributions of source code must retain the above copyright
  13:  *    notice, this list of conditions and the following disclaimer.
  14:  * 2. Redistributions in binary form must reproduce the above copyright
  15:  *    notice, this list of conditions and the following disclaimer in the
  16:  *    documentation and/or other materials provided with the distribution.
  17:  * 3. All advertising materials mentioning features or use of this software
  18:  *    must display the following acknowledgement:
  19:  *	This product includes software developed by the University of
  20:  *	California, Berkeley and its contributors.
  21:  * 4. Neither the name of the University nor the names of its contributors
  22:  *    may be used to endorse or promote products derived from this software
  23:  *    without specific prior written permission.
  24:  *
  25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35:  * SUCH DAMAGE.
  36:  */
  37: #include "config.h"
  38: #if !defined(lint) && !defined(pdp11)
  39: static char *rcsid()
  40:     { return "$Id: sh.print.c,v 3.0 1991/07/04 21:49:28 christos Exp $"; }
  41: #endif
  42: 
  43: #include "sh.h"
  44: #include "ed.h"
  45: 
  46: extern int Tty_eight_bit;
  47: extern int Tty_raw_mode;
  48: extern Char GettingInput;
  49: 
  50: int     lbuffed = 1;        /* true if line buffered */
  51: 
  52: static  void    p2dig   __P((int));
  53: 
  54: /*
  55:  * C Shell
  56:  */
  57: 
  58: #ifdef RLIMIT_CPU
  59: void
  60: psecs(l)
  61:     long    l;
  62: {
  63:     register int i;
  64: 
  65:     i = l / 3600;
  66:     if (i) {
  67:     xprintf("%d:", i);
  68:     i = l % 3600;
  69:     p2dig(i / 60);
  70:     goto minsec;
  71:     }
  72:     i = l;
  73:     xprintf("%d", i / 60);
  74: minsec:
  75:     i %= 60;
  76:     xprintf(":");
  77:     p2dig(i);
  78: }
  79: 
  80: #endif
  81: 
  82: void
  83: pcsecs(l)           /* PWP: print mm:ss.dd, l is in sec*100 */
  84: #ifdef BSDTIMES
  85:     long    l;
  86: 
  87: #else               /* BSDTIMES */
  88: #ifndef POSIX
  89:     time_t  l;
  90: 
  91: #else               /* POSIX */
  92:     clock_t l;
  93: 
  94: #endif				/* POSIX */
  95: #endif				/* BSDTIMES */
  96: {
  97:     register int i;
  98: 
  99:     i = l / 360000L;
 100:     if (i) {
 101:     xprintf("%d:", i);
 102:     i = (l % 360000L) / 100;
 103:     p2dig(i / 60);
 104:     goto minsec;
 105:     }
 106:     i = l / 100;
 107:     xprintf("%d", i / 60);
 108: minsec:
 109:     i %= 60;
 110:     xprintf(":");
 111:     p2dig(i);
 112:     xprintf(".");
 113:     p2dig((int) (l % 100));
 114: }
 115: 
 116: static void
 117: p2dig(i)
 118:     register int i;
 119: {
 120: 
 121:     xprintf("%d%d", i / 10, i % 10);
 122: }
 123: 
 124: char    linbuf[BUFSIZ];     /* was 128 */
 125: char   *linp = linbuf;
 126: bool    output_raw = 0;     /* PWP */
 127: 
 128: void
 129: xputchar(c)
 130:     register int c;
 131: {
 132:     int     atr = 0;
 133: 
 134:     atr |= c & ATTRIBUTES & TRIM;
 135:     c &= CHAR | QUOTE;
 136:     if (!output_raw && (c & QUOTE) == 0) {
 137:     if (Iscntrl(c)) {
 138:         if (c != '\t' && c != '\n' && c != '\r') {
 139:         xputchar('^' | atr);
 140:         if (c == ASCII)
 141:             c = '?';
 142:         else
 143:             c |= 0100;
 144:         }
 145:     }
 146:     else if (!Isprint(c)) {
 147:         xputchar('\\' | atr);
 148:         xputchar((((c >> 6) & 7) + '0') | atr);
 149:         xputchar((((c >> 3) & 7) + '0') | atr);
 150:         c = (c & 7) + '0';
 151:     }
 152:     (void) putraw(c | atr);
 153:     }
 154:     else {
 155:     c &= TRIM;
 156:     if (haderr ? (didfds ? is2atty : isdiagatty) :
 157:         (didfds ? is1atty : isoutatty))
 158:         SetAttributes(c | atr);
 159:     (void) putpure(c);
 160:     }
 161:     if (lbuffed && (c & CHAR) == '\n')
 162:     flush();
 163: }
 164: 
 165: int
 166: putraw(c)
 167:     register int c;
 168: {
 169:     if (haderr ? (didfds ? is2atty : isdiagatty) :
 170:     (didfds ? is1atty : isoutatty)) {
 171:     if (Tty_eight_bit == -1)
 172:         ed_set_tty_eight_bit();
 173:     if (!Tty_eight_bit && (c & META)) {
 174:         c = (c & ~META) | STANDOUT;
 175:     }
 176:     SetAttributes(c);
 177:     }
 178:     return putpure(c);
 179: }
 180: 
 181: int
 182: putpure(c)
 183:     register int c;
 184: {
 185:     c &= CHAR;
 186: 
 187:     *linp++ = c;
 188:     if (linp >= &linbuf[sizeof linbuf - 10])
 189:     flush();
 190:     return (1);
 191: }
 192: 
 193: void
 194: draino()
 195: {
 196:     linp = linbuf;
 197: }
 198: 
 199: void
 200: flush()
 201: {
 202:     register int unit;
 203: 
 204:     /* int lmode; */
 205: 
 206:     if (linp == linbuf)
 207:     return;
 208:     if (GettingInput && !Tty_raw_mode && linp < &linbuf[sizeof linbuf - 10])
 209:     return;
 210:     if (haderr)
 211:     unit = didfds ? 2 : SHDIAG;
 212:     else
 213:     unit = didfds ? 1 : SHOUT;
 214: #ifdef COMMENT
 215: #ifdef TIOCLGET
 216:     if (didfds == 0 && ioctl(unit, TIOCLGET, (ioctl_t) & lmode) == 0 &&
 217:     lmode & LFLUSHO) {
 218:     lmode = LFLUSHO;
 219:     (void) ioctl(unit, TIOCLBIC, (ioclt_t) & lmode);
 220:     (void) write(unit, "\n", 1);
 221:     }
 222: #endif
 223: #endif
 224:     (void) write(unit, linbuf, (size_t) (linp - linbuf));
 225:     linp = linbuf;
 226: }

Defined functions

draino defined in line 193; never used
p2dig defined in line 116; used 5 times
pcsecs defined in line 82; used 2 times
psecs defined in line 59; used 1 times
putpure defined in line 181; used 4 times
putraw defined in line 165; used 11 times
rcsid defined in line 39; never used

Defined variables

lbuffed defined in line 50; used 3 times
linbuf defined in line 124; used 10 times
linp defined in line 125; used 7 times
output_raw defined in line 126; used 1 times
Last modified: 1991-08-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2947
Valid CSS Valid XHTML 1.0 Strict