version 1.30, 2005/03/10 16:58:57 |
version 1.31, 2005/04/03 02:09:28 |
|
|
#include <stdarg.h> |
#include <stdarg.h> |
|
|
static char *veread(const char *, char *, size_t, int, va_list); |
static char *veread(const char *, char *, size_t, int, va_list); |
static int complt(int, int, char *, size_t, int); |
static int complt(int, int, char *, size_t, int); |
static int complt_list(int, int, char *, int); |
static int complt_list(int, int, char *, int); |
static void eformat(const char *, va_list); |
static void eformat(const char *, va_list); |
static void eputi(int, int); |
static void eputi(int, int); |
static void eputl(long, int); |
static void eputl(long, int); |
static void eputs(const char *); |
static void eputs(const char *); |
static void eputc(char); |
static void eputc(char); |
static LIST *copy_list(LIST *); |
static LIST *copy_list(LIST *); |
|
|
int epresf = FALSE; /* stuff in echo line flag */ |
int epresf = FALSE; /* stuff in echo line flag */ |
|
|
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (inmacro) |
if (inmacro) |
return TRUE; |
return (TRUE); |
#endif /* !NO_MACRO */ |
#endif /* !NO_MACRO */ |
ewprintf("%s? (y or n) ", sp); |
ewprintf("%s? (y or n) ", sp); |
for (;;) { |
for (;;) { |
s = getkey(FALSE); |
s = getkey(FALSE); |
if (s == 'y' || s == 'Y') |
if (s == 'y' || s == 'Y') |
return TRUE; |
return (TRUE); |
if (s == 'n' || s == 'N') |
if (s == 'n' || s == 'N') |
return FALSE; |
return (FALSE); |
if (s == CCHR('G')) |
if (s == CCHR('G')) |
return ctrlg(FFRAND, 1); |
return (ctrlg(FFRAND, 1)); |
ewprintf("Please answer y or n. %s? (y or n) ", sp); |
ewprintf("Please answer y or n. %s? (y or n) ", sp); |
} |
} |
/* NOTREACHED */ |
/* NOTREACHED */ |
|
|
|
|
/* |
/* |
* Like eyorn, but for more important questions. User must type all of |
* Like eyorn, but for more important questions. User must type all of |
* "yes" or "no" and the trainling newline. |
* "yes" or "no" and the trailing newline. |
*/ |
*/ |
int |
int |
eyesno(const char *sp) |
eyesno(const char *sp) |
|
|
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (inmacro) |
if (inmacro) |
return TRUE; |
return (TRUE); |
#endif /* !NO_MACRO */ |
#endif /* !NO_MACRO */ |
rep = ereply("%s? (yes or no) ", buf, sizeof(buf), sp); |
rep = ereply("%s? (yes or no) ", buf, sizeof(buf), sp); |
for (;;) { |
for (;;) { |
if (rep == NULL) |
if (rep == NULL) |
return ABORT; |
return (ABORT); |
if (rep[0] != '\0') { |
if (rep[0] != '\0') { |
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (macrodef) { |
if (macrodef) { |
|
|
(rep[1] == 'e' || rep[1] == 'E') && |
(rep[1] == 'e' || rep[1] == 'E') && |
(rep[2] == 's' || rep[2] == 'S') && |
(rep[2] == 's' || rep[2] == 'S') && |
(rep[3] == '\0')) |
(rep[3] == '\0')) |
return TRUE; |
return (TRUE); |
if ((rep[0] == 'n' || rep[0] == 'N') && |
if ((rep[0] == 'n' || rep[0] == 'N') && |
(rep[1] == 'o' || rep[0] == 'O') && |
(rep[1] == 'o' || rep[0] == 'O') && |
(rep[2] == '\0')) |
(rep[2] == '\0')) |
return FALSE; |
return (FALSE); |
} |
} |
rep = ereply("Please answer yes or no. %s? (yes or no) ", |
rep = ereply("Please answer yes or no. %s? (yes or no) ", |
buf, sizeof(buf), sp); |
buf, sizeof(buf), sp); |
|
|
va_start(ap, nbuf); |
va_start(ap, nbuf); |
rep = veread(fmt, buf, nbuf, EFNEW | EFCR, ap); |
rep = veread(fmt, buf, nbuf, EFNEW | EFCR, ap); |
va_end(ap); |
va_end(ap); |
return rep; |
return (rep); |
} |
} |
|
|
/* |
/* |
|
|
eread(const char *fmt, char *buf, size_t nbuf, int flag, ...) |
eread(const char *fmt, char *buf, size_t nbuf, int flag, ...) |
{ |
{ |
va_list ap; |
va_list ap; |
char *rep; |
char *rep; |
|
|
va_start(ap, flag); |
va_start(ap, flag); |
rep = veread(fmt, buf, nbuf, flag, ap); |
rep = veread(fmt, buf, nbuf, flag, ap); |
va_end(ap); |
va_end(ap); |
return rep; |
return (rep); |
} |
} |
|
|
static char * |
static char * |
veread(const char *fp, char *buf, size_t nbuf, int flag, va_list ap) |
veread(const char *fp, char *buf, size_t nbuf, int flag, va_list ap) |
{ |
{ |
int cpos, dynbuf = (buf == NULL); |
int cpos, dynbuf = (buf == NULL); |
int i; |
int c, i; |
int c; |
|
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (inmacro) { |
if (inmacro) { |
if (dynbuf) { |
if (dynbuf) { |
if ((buf = malloc(maclcur->l_used + 1)) == NULL) |
if ((buf = malloc(maclcur->l_used + 1)) == NULL) |
return NULL; |
return (NULL); |
} else if (maclcur->l_used >= nbuf) |
} else if (maclcur->l_used >= nbuf) |
return NULL; |
return (NULL); |
bcopy(maclcur->l_text, buf, maclcur->l_used); |
bcopy(maclcur->l_text, buf, maclcur->l_used); |
buf[maclcur->l_used] = '\0'; |
buf[maclcur->l_used] = '\0'; |
maclcur = maclcur->l_fp; |
maclcur = maclcur->l_fp; |
return buf; |
return (buf); |
} |
} |
#endif /* !NO_MACRO */ |
#endif /* !NO_MACRO */ |
cpos = 0; |
cpos = 0; |
|
|
eformat(fp, ap); |
eformat(fp, ap); |
if ((flag & EFDEF) != 0) { |
if ((flag & EFDEF) != 0) { |
if (buf == NULL) |
if (buf == NULL) |
return NULL; |
return (NULL); |
eputs(buf); |
eputs(buf); |
cpos += strlen(buf); |
cpos += strlen(buf); |
} |
} |
|
|
/* XXX hackish */ |
/* XXX hackish */ |
if (dynbuf && buf != NULL) |
if (dynbuf && buf != NULL) |
free(buf); |
free(buf); |
return falseval; |
return (falseval); |
} |
} |
lp->l_fp = maclcur->l_fp; |
lp->l_fp = maclcur->l_fp; |
maclcur->l_fp = lp; |
maclcur->l_fp = lp; |
|
|
eputc(CCHR('G')); |
eputc(CCHR('G')); |
(void)ctrlg(FFRAND, 0); |
(void)ctrlg(FFRAND, 0); |
ttflush(); |
ttflush(); |
return NULL; |
return (NULL); |
case CCHR('H'): /* rubout, erase */ |
case CCHR('H'): /* rubout, erase */ |
case CCHR('?'): |
case CCHR('?'): |
if (cpos != 0) { |
if (cpos != 0) { |
|
|
if ((newp = realloc(buf, newsize)) == NULL) { |
if ((newp = realloc(buf, newsize)) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
free(buf); |
free(buf); |
return NULL; |
return (NULL); |
} |
} |
buf = newp; |
buf = newp; |
nbuf = newsize; |
nbuf = newsize; |
|
|
} |
} |
} |
} |
done: |
done: |
return buf; |
return (buf); |
} |
} |
|
|
/* |
/* |
* do completion on a list of objects. |
* Do completion on a list of objects. |
*/ |
*/ |
static int |
static int |
complt(int flags, int c, char *buf, size_t nbuf, int cpos) |
complt(int flags, int c, char *buf, size_t nbuf, int cpos) |
|
|
ttflush(); |
ttflush(); |
free_file_list(wholelist); |
free_file_list(wholelist); |
if (nxtra < 0 && c != CCHR('M')) |
if (nxtra < 0 && c != CCHR('M')) |
return 0; |
return (0); |
return nxtra; |
return (nxtra); |
} |
} |
|
|
/* |
/* |
* wholelist is null if we are doing buffers. want to free lists |
* wholelist is NULL if we are doing buffers. Want to free lists |
* that were created for us, but not the buffer list! |
* that were created for us, but not the buffer list! |
*/ |
*/ |
free_file_list(wholelist); |
free_file_list(wholelist); |
|
|
/* Set up backspaces, etc., being mindful of echo line limit */ |
/* Set up backspaces, etc., being mindful of echo line limit. */ |
msglen = strlen(msg); |
msglen = strlen(msg); |
nshown = (ttcol + msglen + 2 > ncol) ? |
nshown = (ttcol + msglen + 2 > ncol) ? |
ncol - ttcol - 2 : msglen; |
ncol - ttcol - 2 : msglen; |
|
|
ttcol -= (i = nshown); /* update ttcol on BS's */ |
ttcol -= (i = nshown); /* update ttcol on BS's */ |
while (i--) |
while (i--) |
ttputc('\b'); /* update ttcol again! */ |
ttputc('\b'); /* update ttcol again! */ |
return 0; |
return (0); |
} |
} |
|
|
/* |
/* |
* do completion on a list of objects, listing instead of completing |
* Do completion on a list of objects, listing instead of completing. |
*/ |
*/ |
static int |
static int |
complt_list(int flags, int c, char *buf, int cpos) |
complt_list(int flags, int c, char *buf, int cpos) |
|
|
|
|
ttflush(); |
ttflush(); |
|
|
/* the results are put into a help buffer */ |
/* The results are put into a help buffer. */ |
bp = bfind("*help*", TRUE); |
bp = bfind("*help*", TRUE); |
if (bclear(bp) == FALSE) |
if (bclear(bp) == FALSE) |
return FALSE; |
return (FALSE); |
|
|
/* |
/* |
* first get the list of objects. This list may contain only |
* First get the list of objects. This list may contain only |
* the ones that complete what has been typed, or may be the |
* the ones that complete what has been typed, or may be the |
* whole list of all objects of this type. They are filtered |
* whole list of all objects of this type. They are filtered |
* later in any case. Set wholelist if the list has been |
* later in any case. Set wholelist if the list has been |
|
|
} else |
} else |
panic("broken complt call: flags"); |
panic("broken complt call: flags"); |
|
|
|
|
/* |
/* |
* Sort the list, since users expect to see it in alphabetic |
* Sort the list, since users expect to see it in alphabetic |
* order. |
* order. |
|
|
maxwidth += 1 - preflen; |
maxwidth += 1 - preflen; |
|
|
/* |
/* |
* Now do the display. objects are written into linebuf until |
* Now do the display. Objects are written into linebuf until |
* it fills, and then put into the help buffer. |
* it fills, and then put into the help buffer. |
*/ |
*/ |
linesize = MAX(ncol, maxwidth) + 1; |
linesize = MAX(ncol, maxwidth) + 1; |
if ((linebuf = malloc(linesize)) == NULL) |
if ((linebuf = malloc(linesize)) == NULL) |
return FALSE; |
return (FALSE); |
width = 0; |
width = 0; |
|
|
/* |
/* |
* We're going to strlcat() into the buffer, so it has to be |
* We're going to strlcat() into the buffer, so it has to be |
* NUL terminated |
* NUL terminated. |
*/ |
*/ |
linebuf[0] = '\0'; |
linebuf[0] = '\0'; |
for (lh2 = lh; lh2 != NULL; lh2 = lh2->l_next) { |
for (lh2 = lh; lh2 != NULL; lh2 = lh2->l_next) { |
|
|
ttmove(oldrow, oldcol); /* update leaves cursor in arbitrary place */ |
ttmove(oldrow, oldcol); /* update leaves cursor in arbitrary place */ |
ttcolor(oldhue); /* with arbitrary color */ |
ttcolor(oldhue); /* with arbitrary color */ |
ttflush(); |
ttflush(); |
return 0; |
return (0); |
} |
} |
|
|
/* |
/* |
|
|
break; |
break; |
|
|
case 'p': |
case 'p': |
snprintf(tmp, sizeof tmp, "%p", |
snprintf(tmp, sizeof(tmp), "%p", |
va_arg(ap, void *)); |
va_arg(ap, void *)); |
eputs(tmp); |
eputs(tmp); |
break; |
break; |