2012-07-23 21:31:53 +00:00
|
|
|
/*
|
2017-04-29 06:30:21 +00:00
|
|
|
* Copyright (C) 1984-2017 Mark Nudelman
|
2012-07-23 21:31:53 +00:00
|
|
|
*
|
|
|
|
* You may distribute under the terms of either the GNU General Public
|
|
|
|
* License or the Less License, as specified in the README file.
|
|
|
|
*
|
|
|
|
* For more information, see the README file.
|
|
|
|
*/
|
2000-05-22 09:53:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prompting and other messages.
|
|
|
|
* There are three flavors of prompts, SHORT, MEDIUM and LONG,
|
|
|
|
* selected by the -m/-M options.
|
|
|
|
* There is also the "equals message", printed by the = command.
|
|
|
|
* A prompt is a message composed of various pieces, such as the
|
|
|
|
* name of the file being viewed, the percentage into the file, etc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "less.h"
|
|
|
|
#include "position.h"
|
|
|
|
|
|
|
|
extern int pr_type;
|
|
|
|
extern int new_file;
|
|
|
|
extern int sc_width;
|
|
|
|
extern int so_s_width, so_e_width;
|
|
|
|
extern int linenums;
|
|
|
|
extern int hshift;
|
|
|
|
extern int sc_height;
|
|
|
|
extern int jump_sline;
|
2007-06-04 01:42:54 +00:00
|
|
|
extern int less_is_more;
|
2000-05-22 09:53:22 +00:00
|
|
|
extern IFILE curr_ifile;
|
|
|
|
#if EDITOR
|
|
|
|
extern char *editor;
|
|
|
|
extern char *editproto;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes for the three flavors of prompts.
|
|
|
|
* These strings are expanded by pr_expand().
|
|
|
|
*/
|
|
|
|
static constant char s_proto[] =
|
2002-01-07 20:29:38 +00:00
|
|
|
"?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\\: %x..%t";
|
2000-05-22 09:53:22 +00:00
|
|
|
static constant char m_proto[] =
|
2002-01-07 20:29:38 +00:00
|
|
|
"?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t";
|
2000-05-22 09:53:22 +00:00
|
|
|
static constant char M_proto[] =
|
2002-01-07 20:29:38 +00:00
|
|
|
"?f%f .?n?m(%T %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t";
|
2000-05-22 09:53:22 +00:00
|
|
|
static constant char e_proto[] =
|
2002-01-07 20:29:38 +00:00
|
|
|
"?f%f .?m(%T %i of %m) .?ltlines %lt-%lb?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t";
|
2000-05-22 09:53:22 +00:00
|
|
|
static constant char h_proto[] =
|
|
|
|
"HELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done";
|
2002-01-07 20:29:38 +00:00
|
|
|
static constant char w_proto[] =
|
|
|
|
"Waiting for data";
|
2007-06-04 01:42:54 +00:00
|
|
|
static constant char more_proto[] =
|
|
|
|
"--More--(?eEND ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t)";
|
2000-05-22 09:53:22 +00:00
|
|
|
|
|
|
|
public char *prproto[3];
|
|
|
|
public char constant *eqproto = e_proto;
|
|
|
|
public char constant *hproto = h_proto;
|
2002-01-07 20:29:38 +00:00
|
|
|
public char constant *wproto = w_proto;
|
2000-05-22 09:53:22 +00:00
|
|
|
|
|
|
|
static char message[PROMPT_SIZE];
|
|
|
|
static char *mp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the prompt prototype strings.
|
|
|
|
*/
|
|
|
|
public void
|
2017-04-25 03:42:16 +00:00
|
|
|
init_prompt()
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
prproto[0] = save(s_proto);
|
2007-06-04 01:42:54 +00:00
|
|
|
prproto[1] = save(less_is_more ? more_proto : m_proto);
|
2000-05-22 09:53:22 +00:00
|
|
|
prproto[2] = save(M_proto);
|
|
|
|
eqproto = save(e_proto);
|
|
|
|
hproto = save(h_proto);
|
2002-01-07 20:29:38 +00:00
|
|
|
wproto = save(w_proto);
|
2000-05-22 09:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a string to the end of the message.
|
|
|
|
*/
|
|
|
|
static void
|
2017-04-25 03:42:16 +00:00
|
|
|
ap_str(s)
|
|
|
|
char *s;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2016-01-04 00:22:34 +00:00
|
|
|
len = (int) strlen(s);
|
2000-05-22 09:53:22 +00:00
|
|
|
if (mp + len >= message + PROMPT_SIZE)
|
2016-01-04 00:22:34 +00:00
|
|
|
len = (int) (message + PROMPT_SIZE - mp - 1);
|
2000-05-22 09:53:22 +00:00
|
|
|
strncpy(mp, s, len);
|
|
|
|
mp += len;
|
|
|
|
*mp = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a character to the end of the message.
|
|
|
|
*/
|
|
|
|
static void
|
2017-04-25 03:42:16 +00:00
|
|
|
ap_char(c)
|
|
|
|
char c;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
char buf[2];
|
|
|
|
|
|
|
|
buf[0] = c;
|
|
|
|
buf[1] = '\0';
|
|
|
|
ap_str(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a POSITION (as a decimal integer) to the end of the message.
|
|
|
|
*/
|
|
|
|
static void
|
2017-04-25 03:42:16 +00:00
|
|
|
ap_pos(pos)
|
|
|
|
POSITION pos;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
2004-04-17 07:16:34 +00:00
|
|
|
char buf[INT_STRLEN_BOUND(pos) + 2];
|
|
|
|
|
|
|
|
postoa(pos, buf);
|
|
|
|
ap_str(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a line number to the end of the message.
|
|
|
|
*/
|
|
|
|
static void
|
2017-04-25 03:42:16 +00:00
|
|
|
ap_linenum(linenum)
|
|
|
|
LINENUM linenum;
|
2004-04-17 07:16:34 +00:00
|
|
|
{
|
|
|
|
char buf[INT_STRLEN_BOUND(linenum) + 2];
|
|
|
|
|
|
|
|
linenumtoa(linenum, buf);
|
|
|
|
ap_str(buf);
|
2000-05-22 09:53:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append an integer to the end of the message.
|
|
|
|
*/
|
|
|
|
static void
|
2017-04-25 03:42:16 +00:00
|
|
|
ap_int(num)
|
|
|
|
int num;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
2004-04-17 07:16:34 +00:00
|
|
|
char buf[INT_STRLEN_BOUND(num) + 2];
|
2000-05-22 09:53:22 +00:00
|
|
|
|
2004-04-17 07:16:34 +00:00
|
|
|
inttoa(num, buf);
|
2000-05-22 09:53:22 +00:00
|
|
|
ap_str(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append a question mark to the end of the message.
|
|
|
|
*/
|
|
|
|
static void
|
2017-04-25 03:42:16 +00:00
|
|
|
ap_quest()
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
ap_str("?");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the "current" byte offset in the file.
|
|
|
|
*/
|
|
|
|
static POSITION
|
2017-04-25 03:42:16 +00:00
|
|
|
curr_byte(where)
|
|
|
|
int where;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
POSITION pos;
|
|
|
|
|
|
|
|
pos = position(where);
|
2006-08-20 15:49:51 +00:00
|
|
|
while (pos == NULL_POSITION && where >= 0 && where < sc_height-1)
|
2000-05-22 09:53:22 +00:00
|
|
|
pos = position(++where);
|
|
|
|
if (pos == NULL_POSITION)
|
|
|
|
pos = ch_length();
|
|
|
|
return (pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the value of a prototype conditional.
|
|
|
|
* A prototype string may include conditionals which consist of a
|
|
|
|
* question mark followed by a single letter.
|
|
|
|
* Here we decode that letter and return the appropriate boolean value.
|
|
|
|
*/
|
|
|
|
static int
|
2017-04-25 03:42:16 +00:00
|
|
|
cond(c, where)
|
|
|
|
char c;
|
|
|
|
int where;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
POSITION len;
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'a': /* Anything in the message yet? */
|
|
|
|
return (mp > message);
|
|
|
|
case 'b': /* Current byte offset known? */
|
|
|
|
return (curr_byte(where) != NULL_POSITION);
|
|
|
|
case 'c':
|
|
|
|
return (hshift != 0);
|
|
|
|
case 'e': /* At end of file? */
|
2009-05-08 23:45:27 +00:00
|
|
|
return (eof_displayed());
|
2000-05-22 09:53:22 +00:00
|
|
|
case 'f': /* Filename known? */
|
|
|
|
return (strcmp(get_filename(curr_ifile), "-") != 0);
|
|
|
|
case 'l': /* Line number known? */
|
|
|
|
case 'd': /* Same as l */
|
|
|
|
return (linenums);
|
|
|
|
case 'L': /* Final line number known? */
|
2006-08-20 15:49:51 +00:00
|
|
|
case 'D': /* Final page number known? */
|
2000-05-22 09:53:22 +00:00
|
|
|
return (linenums && ch_length() != NULL_POSITION);
|
|
|
|
case 'm': /* More than one file? */
|
2004-04-17 07:16:34 +00:00
|
|
|
#if TAGS
|
2002-01-07 20:29:38 +00:00
|
|
|
return (ntags() ? (ntags() > 1) : (nifile() > 1));
|
2004-04-17 07:16:34 +00:00
|
|
|
#else
|
|
|
|
return (nifile() > 1);
|
|
|
|
#endif
|
2000-05-22 09:53:22 +00:00
|
|
|
case 'n': /* First prompt in a new file? */
|
2004-04-17 07:16:34 +00:00
|
|
|
#if TAGS
|
2002-01-07 20:29:38 +00:00
|
|
|
return (ntags() ? 1 : new_file);
|
2004-04-17 07:16:34 +00:00
|
|
|
#else
|
|
|
|
return (new_file);
|
|
|
|
#endif
|
2000-05-22 09:53:22 +00:00
|
|
|
case 'p': /* Percent into file (bytes) known? */
|
|
|
|
return (curr_byte(where) != NULL_POSITION &&
|
|
|
|
ch_length() > 0);
|
|
|
|
case 'P': /* Percent into file (lines) known? */
|
|
|
|
return (currline(where) != 0 &&
|
|
|
|
(len = ch_length()) > 0 &&
|
|
|
|
find_linenum(len) != 0);
|
|
|
|
case 's': /* Size of file known? */
|
|
|
|
case 'B':
|
|
|
|
return (ch_length() != NULL_POSITION);
|
|
|
|
case 'x': /* Is there a "next" file? */
|
2004-04-17 07:16:34 +00:00
|
|
|
#if TAGS
|
2002-01-07 20:29:38 +00:00
|
|
|
if (ntags())
|
|
|
|
return (0);
|
2004-04-17 07:16:34 +00:00
|
|
|
#endif
|
2000-05-22 09:53:22 +00:00
|
|
|
return (next_ifile(curr_ifile) != NULL_IFILE);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a "percent" prototype character.
|
|
|
|
* A prototype string may include various "percent" escapes;
|
|
|
|
* that is, a percent sign followed by a single letter.
|
|
|
|
* Here we decode that letter and take the appropriate action,
|
|
|
|
* usually by appending something to the message being built.
|
|
|
|
*/
|
|
|
|
static void
|
2017-04-25 03:42:16 +00:00
|
|
|
protochar(c, where, iseditproto)
|
|
|
|
int c;
|
|
|
|
int where;
|
|
|
|
int iseditproto;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
POSITION pos;
|
|
|
|
POSITION len;
|
|
|
|
int n;
|
2004-04-17 07:16:34 +00:00
|
|
|
LINENUM linenum;
|
|
|
|
LINENUM last_linenum;
|
2000-05-22 09:53:22 +00:00
|
|
|
IFILE h;
|
|
|
|
|
2006-08-20 15:49:51 +00:00
|
|
|
#undef PAGE_NUM
|
|
|
|
#define PAGE_NUM(linenum) ((((linenum) - 1) / (sc_height - 1)) + 1)
|
|
|
|
|
2000-05-22 09:53:22 +00:00
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'b': /* Current byte offset */
|
|
|
|
pos = curr_byte(where);
|
|
|
|
if (pos != NULL_POSITION)
|
|
|
|
ap_pos(pos);
|
|
|
|
else
|
|
|
|
ap_quest();
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
ap_int(hshift);
|
|
|
|
break;
|
|
|
|
case 'd': /* Current page number */
|
2004-04-17 07:16:34 +00:00
|
|
|
linenum = currline(where);
|
|
|
|
if (linenum > 0 && sc_height > 1)
|
2006-08-20 15:49:51 +00:00
|
|
|
ap_linenum(PAGE_NUM(linenum));
|
2000-05-22 09:53:22 +00:00
|
|
|
else
|
|
|
|
ap_quest();
|
|
|
|
break;
|
2006-08-20 15:49:51 +00:00
|
|
|
case 'D': /* Final page number */
|
|
|
|
/* Find the page number of the last byte in the file (len-1). */
|
2000-05-22 09:53:22 +00:00
|
|
|
len = ch_length();
|
2006-08-20 15:49:51 +00:00
|
|
|
if (len == NULL_POSITION)
|
2000-05-22 09:53:22 +00:00
|
|
|
ap_quest();
|
2006-08-20 15:49:51 +00:00
|
|
|
else if (len == 0)
|
|
|
|
/* An empty file has no pages. */
|
|
|
|
ap_linenum(0);
|
2000-05-22 09:53:22 +00:00
|
|
|
else
|
2006-08-20 15:49:51 +00:00
|
|
|
{
|
|
|
|
linenum = find_linenum(len - 1);
|
|
|
|
if (linenum <= 0)
|
|
|
|
ap_quest();
|
|
|
|
else
|
|
|
|
ap_linenum(PAGE_NUM(linenum));
|
|
|
|
}
|
2000-05-22 09:53:22 +00:00
|
|
|
break;
|
|
|
|
#if EDITOR
|
|
|
|
case 'E': /* Editor name */
|
|
|
|
ap_str(editor);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'f': /* File name */
|
2004-04-17 07:16:34 +00:00
|
|
|
ap_str(get_filename(curr_ifile));
|
2000-05-22 09:53:22 +00:00
|
|
|
break;
|
2011-05-09 18:30:23 +00:00
|
|
|
case 'F': /* Last component of file name */
|
|
|
|
ap_str(last_component(get_filename(curr_ifile)));
|
|
|
|
break;
|
2000-05-22 09:53:22 +00:00
|
|
|
case 'i': /* Index into list of files */
|
2004-04-17 07:16:34 +00:00
|
|
|
#if TAGS
|
2002-01-07 20:29:38 +00:00
|
|
|
if (ntags())
|
|
|
|
ap_int(curr_tag());
|
|
|
|
else
|
2004-04-17 07:16:34 +00:00
|
|
|
#endif
|
2002-01-07 20:29:38 +00:00
|
|
|
ap_int(get_index(curr_ifile));
|
2000-05-22 09:53:22 +00:00
|
|
|
break;
|
|
|
|
case 'l': /* Current line number */
|
2004-04-17 07:16:34 +00:00
|
|
|
linenum = currline(where);
|
|
|
|
if (linenum != 0)
|
|
|
|
ap_linenum(linenum);
|
2000-05-22 09:53:22 +00:00
|
|
|
else
|
|
|
|
ap_quest();
|
|
|
|
break;
|
|
|
|
case 'L': /* Final line number */
|
|
|
|
len = ch_length();
|
|
|
|
if (len == NULL_POSITION || len == ch_zero() ||
|
2004-04-17 07:16:34 +00:00
|
|
|
(linenum = find_linenum(len)) <= 0)
|
2000-05-22 09:53:22 +00:00
|
|
|
ap_quest();
|
|
|
|
else
|
2004-04-17 07:16:34 +00:00
|
|
|
ap_linenum(linenum-1);
|
2000-05-22 09:53:22 +00:00
|
|
|
break;
|
|
|
|
case 'm': /* Number of files */
|
2004-04-17 07:16:34 +00:00
|
|
|
#if TAGS
|
2002-01-07 20:29:38 +00:00
|
|
|
n = ntags();
|
|
|
|
if (n)
|
|
|
|
ap_int(n);
|
|
|
|
else
|
2004-04-17 07:16:34 +00:00
|
|
|
#endif
|
2002-01-07 20:29:38 +00:00
|
|
|
ap_int(nifile());
|
2000-05-22 09:53:22 +00:00
|
|
|
break;
|
|
|
|
case 'p': /* Percent into file (bytes) */
|
|
|
|
pos = curr_byte(where);
|
|
|
|
len = ch_length();
|
|
|
|
if (pos != NULL_POSITION && len > 0)
|
|
|
|
ap_int(percentage(pos,len));
|
|
|
|
else
|
|
|
|
ap_quest();
|
|
|
|
break;
|
|
|
|
case 'P': /* Percent into file (lines) */
|
2004-04-17 07:16:34 +00:00
|
|
|
linenum = currline(where);
|
|
|
|
if (linenum == 0 ||
|
2000-05-22 09:53:22 +00:00
|
|
|
(len = ch_length()) == NULL_POSITION || len == ch_zero() ||
|
2004-04-17 07:16:34 +00:00
|
|
|
(last_linenum = find_linenum(len)) <= 0)
|
2000-05-22 09:53:22 +00:00
|
|
|
ap_quest();
|
|
|
|
else
|
2004-04-17 07:16:34 +00:00
|
|
|
ap_int(percentage(linenum, last_linenum));
|
2000-05-22 09:53:22 +00:00
|
|
|
break;
|
|
|
|
case 's': /* Size of file */
|
|
|
|
case 'B':
|
|
|
|
len = ch_length();
|
|
|
|
if (len != NULL_POSITION)
|
|
|
|
ap_pos(len);
|
|
|
|
else
|
|
|
|
ap_quest();
|
|
|
|
break;
|
|
|
|
case 't': /* Truncate trailing spaces in the message */
|
|
|
|
while (mp > message && mp[-1] == ' ')
|
|
|
|
mp--;
|
2011-05-09 18:30:23 +00:00
|
|
|
*mp = '\0';
|
2000-05-22 09:53:22 +00:00
|
|
|
break;
|
2002-01-07 20:29:38 +00:00
|
|
|
case 'T': /* Type of list */
|
2004-04-17 07:16:34 +00:00
|
|
|
#if TAGS
|
2002-01-07 20:29:38 +00:00
|
|
|
if (ntags())
|
|
|
|
ap_str("tag");
|
|
|
|
else
|
2004-04-17 07:16:34 +00:00
|
|
|
#endif
|
2002-01-07 20:29:38 +00:00
|
|
|
ap_str("file");
|
|
|
|
break;
|
2000-05-22 09:53:22 +00:00
|
|
|
case 'x': /* Name of next file */
|
|
|
|
h = next_ifile(curr_ifile);
|
|
|
|
if (h != NULL_IFILE)
|
2004-04-17 07:16:34 +00:00
|
|
|
ap_str(get_filename(h));
|
|
|
|
else
|
2000-05-22 09:53:22 +00:00
|
|
|
ap_quest();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip a false conditional.
|
|
|
|
* When a false condition is found (either a false IF or the ELSE part
|
|
|
|
* of a true IF), this routine scans the prototype string to decide
|
|
|
|
* where to resume parsing the string.
|
|
|
|
* We must keep track of nested IFs and skip them properly.
|
|
|
|
*/
|
2012-06-26 20:38:53 +00:00
|
|
|
static constant char *
|
2017-04-25 03:42:16 +00:00
|
|
|
skipcond(p)
|
2017-04-29 06:30:21 +00:00
|
|
|
constant char *p;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
2017-04-29 06:30:21 +00:00
|
|
|
int iflevel;
|
2000-05-22 09:53:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We came in here after processing a ? or :,
|
|
|
|
* so we start nested one level deep.
|
|
|
|
*/
|
|
|
|
iflevel = 1;
|
|
|
|
|
|
|
|
for (;;) switch (*++p)
|
|
|
|
{
|
|
|
|
case '?':
|
|
|
|
/*
|
|
|
|
* Start of a nested IF.
|
|
|
|
*/
|
|
|
|
iflevel++;
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
/*
|
|
|
|
* Else.
|
|
|
|
* If this matches the IF we came in here with,
|
|
|
|
* then we're done.
|
|
|
|
*/
|
|
|
|
if (iflevel == 1)
|
|
|
|
return (p);
|
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
/*
|
|
|
|
* Endif.
|
|
|
|
* If this matches the IF we came in here with,
|
|
|
|
* then we're done.
|
|
|
|
*/
|
|
|
|
if (--iflevel == 0)
|
|
|
|
return (p);
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
/*
|
|
|
|
* Backslash escapes the next character.
|
|
|
|
*/
|
|
|
|
++p;
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
/*
|
|
|
|
* Whoops. Hit end of string.
|
|
|
|
* This is a malformed conditional, but just treat it
|
|
|
|
* as if all active conditionals ends here.
|
|
|
|
*/
|
|
|
|
return (p-1);
|
|
|
|
}
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a char that represents a position on the screen.
|
|
|
|
*/
|
2012-06-26 20:38:53 +00:00
|
|
|
static constant char *
|
2017-04-25 03:42:16 +00:00
|
|
|
wherechar(p, wp)
|
|
|
|
char constant *p;
|
|
|
|
int *wp;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
switch (*p)
|
|
|
|
{
|
|
|
|
case 'b': case 'd': case 'l': case 'p': case 'P':
|
|
|
|
switch (*++p)
|
|
|
|
{
|
|
|
|
case 't': *wp = TOP; break;
|
|
|
|
case 'm': *wp = MIDDLE; break;
|
|
|
|
case 'b': *wp = BOTTOM; break;
|
|
|
|
case 'B': *wp = BOTTOM_PLUS_ONE; break;
|
2017-11-20 06:53:49 +00:00
|
|
|
case 'j': *wp = sindex_from_sline(jump_sline); break;
|
2000-05-22 09:53:22 +00:00
|
|
|
default: *wp = TOP; p--; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a message based on a prototype string.
|
|
|
|
*/
|
|
|
|
public char *
|
2017-04-25 03:42:16 +00:00
|
|
|
pr_expand(proto, maxwidth)
|
|
|
|
constant char *proto;
|
|
|
|
int maxwidth;
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
2017-04-29 06:30:21 +00:00
|
|
|
constant char *p;
|
|
|
|
int c;
|
2000-05-22 09:53:22 +00:00
|
|
|
int where;
|
|
|
|
|
|
|
|
mp = message;
|
|
|
|
|
|
|
|
if (*proto == '\0')
|
|
|
|
return ("");
|
|
|
|
|
|
|
|
for (p = proto; *p != '\0'; p++)
|
|
|
|
{
|
|
|
|
switch (*p)
|
|
|
|
{
|
|
|
|
default: /* Just put the character in the message */
|
|
|
|
ap_char(*p);
|
|
|
|
break;
|
|
|
|
case '\\': /* Backslash escapes the next character */
|
|
|
|
p++;
|
|
|
|
ap_char(*p);
|
|
|
|
break;
|
|
|
|
case '?': /* Conditional (IF) */
|
|
|
|
if ((c = *++p) == '\0')
|
|
|
|
--p;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
where = 0;
|
|
|
|
p = wherechar(p, &where);
|
|
|
|
if (!cond(c, where))
|
|
|
|
p = skipcond(p);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ':': /* ELSE */
|
|
|
|
p = skipcond(p);
|
|
|
|
break;
|
|
|
|
case '.': /* ENDIF */
|
|
|
|
break;
|
|
|
|
case '%': /* Percent escape */
|
|
|
|
if ((c = *++p) == '\0')
|
|
|
|
--p;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
where = 0;
|
|
|
|
p = wherechar(p, &where);
|
|
|
|
protochar(c, where,
|
|
|
|
#if EDITOR
|
|
|
|
(proto == editproto));
|
|
|
|
#else
|
|
|
|
0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mp == message)
|
2006-08-20 15:49:51 +00:00
|
|
|
return ("");
|
2000-05-22 09:53:22 +00:00
|
|
|
if (maxwidth > 0 && mp >= message + maxwidth)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Message is too long.
|
|
|
|
* Return just the final portion of it.
|
|
|
|
*/
|
|
|
|
return (mp - maxwidth);
|
|
|
|
}
|
|
|
|
return (message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a message suitable for printing by the "=" command.
|
|
|
|
*/
|
|
|
|
public char *
|
2017-04-25 03:42:16 +00:00
|
|
|
eq_message()
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
|
|
|
return (pr_expand(eqproto, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a prompt.
|
|
|
|
* This depends on the prompt type (SHORT, MEDIUM, LONG), etc.
|
|
|
|
* If we can't come up with an appropriate prompt, return NULL
|
|
|
|
* and the caller will prompt with a colon.
|
|
|
|
*/
|
|
|
|
public char *
|
2017-04-25 03:42:16 +00:00
|
|
|
pr_string()
|
2000-05-22 09:53:22 +00:00
|
|
|
{
|
2002-01-07 20:29:38 +00:00
|
|
|
char *prompt;
|
2007-06-04 01:42:54 +00:00
|
|
|
int type;
|
2002-01-07 20:29:38 +00:00
|
|
|
|
2007-06-04 01:42:54 +00:00
|
|
|
type = (!less_is_more) ? pr_type : pr_type ? 0 : 1;
|
2002-01-07 20:29:38 +00:00
|
|
|
prompt = pr_expand((ch_getflags() & CH_HELPFILE) ?
|
2007-06-04 01:42:54 +00:00
|
|
|
hproto : prproto[type],
|
2002-01-07 20:29:38 +00:00
|
|
|
sc_width-so_s_width-so_e_width-2);
|
|
|
|
new_file = 0;
|
|
|
|
return (prompt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a message suitable for printing while waiting in the F command.
|
|
|
|
*/
|
|
|
|
public char *
|
2017-04-25 03:42:16 +00:00
|
|
|
wait_message()
|
2002-01-07 20:29:38 +00:00
|
|
|
{
|
|
|
|
return (pr_expand(wproto, sc_width-so_s_width-so_e_width-2));
|
2000-05-22 09:53:22 +00:00
|
|
|
}
|