tty: don't use custom kputc; this fixes tty printf()s.
[minix.git] / commands / yap / prompt.c
blobc31c809b523b188c99923667f125459a61328326
1 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
3 # ifndef lint
4 static char rcsid[] = "$Header$";
5 # endif
7 # define _PROMPT_
9 # include "in_all.h"
10 # include "prompt.h"
11 # include "term.h"
12 # include "output.h"
13 # include "options.h"
14 # include "display.h"
15 # include "process.h"
16 # include "getline.h"
17 # include "main.h"
18 # include "getcomm.h"
19 # include "keys.h"
20 # include "assert.h"
21 # include "commands.h"
23 #define basename(x) x
25 #ifndef basename
26 STATIC char * basename();
27 #endif
29 static char *errorgiven; /* Set to error message, if there is one */
31 char *
32 copy(p, ep, s)
33 register char *p, *s;
34 char *ep;
36 while (p < ep && *s) {
37 *p++ = *s++;
39 return p;
43 * display the prompt and refresh the screen.
46 VOID
47 give_prompt() {
49 register char **name;
50 register struct scr_info *p = &scr_info;
51 char buf[256];
52 register char *pb = buf;
54 if (startcomm) return;
55 flush();
56 if (window()) {
57 redraw(0);
58 flush();
60 if (!stupid) {
62 * fancy prompt
64 clrbline();
65 standout();
66 pb = copy(pb, &buf[255], basename(currentfile));
67 if (stdf >= 0) {
68 pb = copy(pb, &buf[255], ", ");
69 pb = copy(pb, &buf[255], getnum(p->firstline));
70 pb = copy(pb, &buf[255], "-");
71 pb = copy(pb, &buf[255], getnum(p->lastline));
74 else {
75 *pb++ = '\007'; /* Stupid terminal, stupid prompt */
77 if (errorgiven) {
79 * display error message
81 pb = copy(pb, &buf[255], " ");
82 pb = copy(pb, &buf[255], errorgiven);
83 if (stupid) {
84 pb = copy(pb, &buf[255], "\r\n");
86 errorgiven = 0;
88 else if (!stupid && (status || maxpos)) {
89 pb = copy(pb, &buf[255], " (");
90 name = &filenames[filecount];
91 if (status) {
93 * indicate top and/or bottom
95 if (status & START) {
96 if (!*(name - 1)) {
97 pb = copy(pb, &buf[255], "Top");
99 else {
100 pb = copy(pb, &buf[255], "Previous: ");
101 pb = copy(pb, &buf[255], basename(*(name - 1)));
103 if (status & EOFILE) {
104 pb = copy(pb, &buf[255], ", ");
107 if (status & EOFILE) {
108 if (!*(name+1)) {
109 pb = copy(pb, &buf[255], "Bottom");
111 else {
112 pb = copy(pb, &buf[255], "Next: ");
113 pb = copy(pb, &buf[255], basename(*(name + 1)));
117 else { /* display percentage */
118 pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline))/maxpos));
119 pb = copy(pb, &buf[255], "%");
121 pb = copy(pb, &buf[255], ")");
123 *pb = '\0';
124 if (!stupid) {
125 buf[COLS-1] = 0;
126 putline(buf);
127 standend();
129 else putline(buf);
133 * Remember error message
136 VOID
137 error(str) char *str; {
139 errorgiven = str;
142 #ifndef basename
143 STATIC char *
144 basename(fn) char *fn; { /* Return name without path */
146 register char *s;
148 s = fn;
149 while (*s++) ; /* Search end of name */
150 for (;;) {
151 if (*--s == '/') {
153 * Backwards to first '/'
155 if (*(s+1)) {
157 * There is a name after the '/'
159 return s + 1;
161 *s = 0; /* No name after the '/' */
163 if (s == fn) return s;
165 /* NOTREACHED */
167 #endif
169 VOID
170 ret_to_continue() { /* Obvious */
171 int c;
172 static char buf[2];
174 for (;;) {
175 clrbline();
176 standout();
177 if (errorgiven) {
178 putline(errorgiven);
179 putline(" ");
180 errorgiven = 0;
182 putline("[Type anything to continue]");
183 standend();
184 if (is_escape(c = getch())) {
185 buf[0] = c;
186 (VOID) match(buf, &c, currmap->k_mach);
187 assert(c > 0);
188 do_comm(c, -1L);
190 else break;
192 clrbline();