source: trunk/minix/commands/yap/prompt.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 3.4 KB
Line 
1/* Copyright (c) 1985 Ceriel J.H. Jacobs */
2
3# ifndef lint
4static char rcsid[] = "$Header: /cvsup/minix/src/commands/yap/prompt.c,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $";
5# endif
6
7# define _PROMPT_
8
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"
22
23#define basename(x) x
24
25#ifndef basename
26STATIC char * basename();
27#endif
28
29static char *errorgiven; /* Set to error message, if there is one */
30
31char *
32copy(p, ep, s)
33 register char *p, *s;
34 char *ep;
35{
36 while (p < ep && *s) {
37 *p++ = *s++;
38 }
39 return p;
40}
41
42/*
43 * display the prompt and refresh the screen.
44 */
45
46VOID
47give_prompt() {
48
49 register char **name;
50 register struct scr_info *p = &scr_info;
51 char buf[256];
52 register char *pb = buf;
53
54 if (startcomm) return;
55 flush();
56 if (window()) {
57 redraw(0);
58 flush();
59 }
60 if (!stupid) {
61 /*
62 * fancy prompt
63 */
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));
72 }
73 }
74 else {
75 *pb++ = '\007'; /* Stupid terminal, stupid prompt */
76 }
77 if (errorgiven) {
78 /*
79 * display error message
80 */
81 pb = copy(pb, &buf[255], " ");
82 pb = copy(pb, &buf[255], errorgiven);
83 if (stupid) {
84 pb = copy(pb, &buf[255], "\r\n");
85 }
86 errorgiven = 0;
87 }
88 else if (!stupid && (status || maxpos)) {
89 pb = copy(pb, &buf[255], " (");
90 name = &filenames[filecount];
91 if (status) {
92 /*
93 * indicate top and/or bottom
94 */
95 if (status & START) {
96 if (!*(name - 1)) {
97 pb = copy(pb, &buf[255], "Top");
98 }
99 else {
100 pb = copy(pb, &buf[255], "Previous: ");
101 pb = copy(pb, &buf[255], basename(*(name - 1)));
102 }
103 if (status & EOFILE) {
104 pb = copy(pb, &buf[255], ", ");
105 }
106 }
107 if (status & EOFILE) {
108 if (!*(name+1)) {
109 pb = copy(pb, &buf[255], "Bottom");
110 }
111 else {
112 pb = copy(pb, &buf[255], "Next: ");
113 pb = copy(pb, &buf[255], basename(*(name + 1)));
114 }
115 }
116 }
117 else { /* display percentage */
118 pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline))/maxpos));
119 pb = copy(pb, &buf[255], "%");
120 }
121 pb = copy(pb, &buf[255], ")");
122 }
123 *pb = '\0';
124 if (!stupid) {
125 buf[COLS-1] = 0;
126 putline(buf);
127 standend();
128 }
129 else putline(buf);
130}
131
132/*
133 * Remember error message
134 */
135
136VOID
137error(str) char *str; {
138
139 errorgiven = str;
140}
141
142#ifndef basename
143STATIC char *
144basename(fn) char *fn; { /* Return name without path */
145
146 register char *s;
147
148 s = fn;
149 while (*s++) ; /* Search end of name */
150 for (;;) {
151 if (*--s == '/') {
152 /*
153 * Backwards to first '/'
154 */
155 if (*(s+1)) {
156 /*
157 * There is a name after the '/'
158 */
159 return s + 1;
160 }
161 *s = 0; /* No name after the '/' */
162 }
163 if (s == fn) return s;
164 }
165 /* NOTREACHED */
166}
167#endif
168
169VOID
170ret_to_continue() { /* Obvious */
171 int c;
172 static char buf[2];
173
174 for (;;) {
175 clrbline();
176 standout();
177 if (errorgiven) {
178 putline(errorgiven);
179 putline(" ");
180 errorgiven = 0;
181 }
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);
189 }
190 else break;
191 }
192 clrbline();
193}
Note: See TracBrowser for help on using the repository browser.