Repository navigation
Expand file tree
/
Copy pathprompt.c
More file actions
executable file
·193 lines (174 loc) · 3.31 KB
/
Copy pathprompt.c
File metadata and controls
executable file
·193 lines (174 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/* Copyright (c) 1985 Ceriel J.H. Jacobs */
# ifndef lint
static char rcsid[] = "$Header$";
# endif
# define _PROMPT_
# include "in_all.h"
# include "prompt.h"
# include "term.h"
# include "output.h"
# include "options.h"
# include "display.h"
# include "process.h"
# include "getline.h"
# include "main.h"
# include "getcomm.h"
# include "keys.h"
# include "assert.h"
# include "commands.h"
#define basename(x) x
#ifndef basename
STATIC char * basename();
#endif
static char *errorgiven; /* Set to error message, if there is one */
char *
copy(p, ep, s)
register char *p, *s;
char *ep;
{
while (p < ep && *s) {
*p++ = *s++;
}
return p;
}
/*
* display the prompt and refresh the screen.
*/
VOID
give_prompt() {
register char **name;
register struct scr_info *p = &scr_info;
char buf[256];
register char *pb = buf;
if (startcomm) return;
flush();
if (window()) {
redraw(0);
flush();
}
if (!stupid) {
/*
* fancy prompt
*/
clrbline();
standout();
pb = copy(pb, &buf[255], basename(currentfile));
if (stdf >= 0) {
pb = copy(pb, &buf[255], ", ");
pb = copy(pb, &buf[255], getnum(p->firstline));
pb = copy(pb, &buf[255], "-");
pb = copy(pb, &buf[255], getnum(p->lastline));
}
}
else {
*pb++ = '\007'; /* Stupid terminal, stupid prompt */
}
if (errorgiven) {
/*
* display error message
*/
pb = copy(pb, &buf[255], " ");
pb = copy(pb, &buf[255], errorgiven);
if (stupid) {
pb = copy(pb, &buf[255], "\r\n");
}
errorgiven = 0;
}
else if (!stupid && (status || maxpos)) {
pb = copy(pb, &buf[255], " (");
name = &filenames[filecount];
if (status) {
/*
* indicate top and/or bottom
*/
if (status & START) {
if (!*(name - 1)) {
pb = copy(pb, &buf[255], "Top");
}
else {
pb = copy(pb, &buf[255], "Previous: ");
pb = copy(pb, &buf[255], basename(*(name - 1)));
}
if (status & EOFILE) {
pb = copy(pb, &buf[255], ", ");
}
}
if (status & EOFILE) {
if (!*(name+1)) {
pb = copy(pb, &buf[255], "Bottom");
}
else {
pb = copy(pb, &buf[255], "Next: ");
pb = copy(pb, &buf[255], basename(*(name + 1)));
}
}
}
else { /* display percentage */
pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline))/maxpos));
pb = copy(pb, &buf[255], "%");
}
pb = copy(pb, &buf[255], ")");
}
*pb = '\0';
if (!stupid) {
buf[COLS-1] = 0;
putline(buf);
standend();
}
else putline(buf);
}
/*
* Remember error message
*/
VOID
error(str) char *str; {
errorgiven = str;
}
#ifndef basename
STATIC char *
basename(fn) char *fn; { /* Return name without path */
register char *s;
s = fn;
while (*s++) ; /* Search end of name */
for (;;) {
if (*--s == '/') {
/*
* Backwards to first '/'
*/
if (*(s+1)) {
/*
* There is a name after the '/'
*/
return s + 1;
}
*s = 0; /* No name after the '/' */
}
if (s == fn) return s;
}
/* NOTREACHED */
}
#endif
VOID
ret_to_continue() { /* Obvious */
int c;
static char buf[2];
for (;;) {
clrbline();
standout();
if (errorgiven) {
putline(errorgiven);
putline(" ");
errorgiven = 0;
}
putline("[Type anything to
3832
continue]");
standend();
if (is_escape(c = getch())) {
buf[0] = c;
(VOID) match(buf, &c, currmap->k_mach);
assert(c > 0);
do_comm(c, -1L);
}
else break;
}
clrbline();
}