Line | |
---|
1 | /* Copyright (c) 1985 Ceriel J.H. Jacobs */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Handle output to screen
|
---|
5 | */
|
---|
6 |
|
---|
7 | # ifndef lint
|
---|
8 | static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/output.c,v 1.1.1.1 2005/04/21 14:55:40 beng Exp $";
|
---|
9 | # endif
|
---|
10 |
|
---|
11 | # define _OUTPUT_
|
---|
12 |
|
---|
13 | # include "in_all.h"
|
---|
14 | # include "output.h"
|
---|
15 | # include "main.h"
|
---|
16 |
|
---|
17 | # define OBUFSIZ 64*128
|
---|
18 |
|
---|
19 | static char _outbuf[OBUFSIZ];
|
---|
20 |
|
---|
21 | VOID
|
---|
22 | flush() { /* Flush output buffer, by writing it */
|
---|
23 | register char *p = _outbuf;
|
---|
24 |
|
---|
25 | _ocnt = OBUFSIZ;
|
---|
26 | if (_optr) (VOID) write(1, p, _optr - p);
|
---|
27 | _optr = p;
|
---|
28 | }
|
---|
29 |
|
---|
30 | VOID
|
---|
31 | nflush() { /* Flush output buffer, ignoring it */
|
---|
32 |
|
---|
33 | _ocnt = OBUFSIZ;
|
---|
34 | _optr = _outbuf;
|
---|
35 | }
|
---|
36 |
|
---|
37 | int
|
---|
38 | fputch(ch) char ch; { /* print a character */
|
---|
39 | putch(ch);
|
---|
40 | }
|
---|
41 |
|
---|
42 | VOID
|
---|
43 | putline(s) register char *s; { /* Print string s */
|
---|
44 |
|
---|
45 | if (!s) return;
|
---|
46 | while (*s) {
|
---|
47 | putch(*s++);
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | /*
|
---|
52 | * A safe version of putline. All control characters are echoed as ^X
|
---|
53 | */
|
---|
54 |
|
---|
55 | VOID
|
---|
56 | cputline(s) char *s; {
|
---|
57 | register c;
|
---|
58 |
|
---|
59 | while (c = *s++) {
|
---|
60 | if ((unsigned) c > 0177) c &= 0177;
|
---|
61 | if (c < ' ' || c == 0177) {
|
---|
62 | putch('^');
|
---|
63 | c ^= 0100;
|
---|
64 | }
|
---|
65 | putch(c);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * Simple minded routine to print a number
|
---|
71 | */
|
---|
72 |
|
---|
73 | VOID
|
---|
74 | prnum(n) long n; {
|
---|
75 |
|
---|
76 | putline(getnum(n));
|
---|
77 | }
|
---|
78 |
|
---|
79 | static char *
|
---|
80 | fillnum(n, p)
|
---|
81 | long n;
|
---|
82 | char *p;
|
---|
83 | {
|
---|
84 | if (n >= 10) {
|
---|
85 | p = fillnum(n / 10, p);
|
---|
86 | }
|
---|
87 | *p++ = (int) (n % 10) + '0';
|
---|
88 | *p = '\0';
|
---|
89 | return p;
|
---|
90 | }
|
---|
91 |
|
---|
92 | char *
|
---|
93 | getnum(n)
|
---|
94 | long n;
|
---|
95 | {
|
---|
96 | static char buf[20];
|
---|
97 |
|
---|
98 | fillnum(n, buf);
|
---|
99 | return buf;
|
---|
100 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.