00001
00002
00003 # ifndef lint
00004 static char rcsid[] = "$Header: /opt/proj/minix/cvsroot/src/commands/yap/prompt.c,v 1.1.1.1 2005/04/21 14:55:41 beng Exp $";
00005 # endif
00006
00007 # define _PROMPT_
00008
00009 # include "in_all.h"
00010 # include "prompt.h"
00011 # include "term.h"
00012 # include "output.h"
00013 # include "options.h"
00014 # include "display.h"
00015 # include "process.h"
00016 # include "getline.h"
00017 # include "main.h"
00018 # include "getcomm.h"
00019 # include "keys.h"
00020 # include "assert.h"
00021 # include "commands.h"
00022
00023 #define basename(x) x
00024
00025 #ifndef basename
00026 STATIC char * basename();
00027 #endif
00028
00029 static char *errorgiven;
00030
00031 char *
00032 copy(p, ep, s)
00033 register char *p, *s;
00034 char *ep;
00035 {
00036 while (p < ep && *s) {
00037 *p++ = *s++;
00038 }
00039 return p;
00040 }
00041
00042
00043
00044
00045
00046 VOID
00047 give_prompt() {
00048
00049 register char **name;
00050 register struct scr_info *p = &scr_info;
00051 char buf[256];
00052 register char *pb = buf;
00053
00054 if (startcomm) return;
00055 flush();
00056 if (window()) {
00057 redraw(0);
00058 flush();
00059 }
00060 if (!stupid) {
00061
00062
00063
00064 clrbline();
00065 standout();
00066 pb = copy(pb, &buf[255], basename(currentfile));
00067 if (stdf >= 0) {
00068 pb = copy(pb, &buf[255], ", ");
00069 pb = copy(pb, &buf[255], getnum(p->firstline));
00070 pb = copy(pb, &buf[255], "-");
00071 pb = copy(pb, &buf[255], getnum(p->lastline));
00072 }
00073 }
00074 else {
00075 *pb++ = '\007';
00076 }
00077 if (errorgiven) {
00078
00079
00080
00081 pb = copy(pb, &buf[255], " ");
00082 pb = copy(pb, &buf[255], errorgiven);
00083 if (stupid) {
00084 pb = copy(pb, &buf[255], "\r\n");
00085 }
00086 errorgiven = 0;
00087 }
00088 else if (!stupid && (status || maxpos)) {
00089 pb = copy(pb, &buf[255], " (");
00090 name = &filenames[filecount];
00091 if (status) {
00092
00093
00094
00095 if (status & START) {
00096 if (!*(name - 1)) {
00097 pb = copy(pb, &buf[255], "Top");
00098 }
00099 else {
00100 pb = copy(pb, &buf[255], "Previous: ");
00101 pb = copy(pb, &buf[255], basename(*(name - 1)));
00102 }
00103 if (status & EOFILE) {
00104 pb = copy(pb, &buf[255], ", ");
00105 }
00106 }
00107 if (status & EOFILE) {
00108 if (!*(name+1)) {
00109 pb = copy(pb, &buf[255], "Bottom");
00110 }
00111 else {
00112 pb = copy(pb, &buf[255], "Next: ");
00113 pb = copy(pb, &buf[255], basename(*(name + 1)));
00114 }
00115 }
00116 }
00117 else {
00118 pb = copy(pb, &buf[255], getnum((100 * getpos(p->lastline))/maxpos));
00119 pb = copy(pb, &buf[255], "%");
00120 }
00121 pb = copy(pb, &buf[255], ")");
00122 }
00123 *pb = '\0';
00124 if (!stupid) {
00125 buf[COLS-1] = 0;
00126 putline(buf);
00127 standend();
00128 }
00129 else putline(buf);
00130 }
00131
00132
00133
00134
00135
00136 VOID
00137 error(str) char *str; {
00138
00139 errorgiven = str;
00140 }
00141
00142 #ifndef basename
00143 STATIC char *
00144 basename(fn) char *fn; {
00145
00146 register char *s;
00147
00148 s = fn;
00149 while (*s++) ;
00150 for (;;) {
00151 if (*--s == '/') {
00152
00153
00154
00155 if (*(s+1)) {
00156
00157
00158
00159 return s + 1;
00160 }
00161 *s = 0;
00162 }
00163 if (s == fn) return s;
00164 }
00165
00166 }
00167 #endif
00168
00169 VOID
00170 ret_to_continue() {
00171 int c;
00172 static char buf[2];
00173
00174 for (;;) {
00175 clrbline();
00176 standout();
00177 if (errorgiven) {
00178 putline(errorgiven);
00179 putline(" ");
00180 errorgiven = 0;
00181 }
00182 putline("[Type anything to continue]");
00183 standend();
00184 if (is_escape(c = getch())) {
00185 buf[0] = c;
00186 (VOID) match(buf, &c, currmap->k_mach);
00187 assert(c > 0);
00188 do_comm(c, -1L);
00189 }
00190 else break;
00191 }
00192 clrbline();
00193 }