* Copyright (c) 1988 Mark Nudleman
* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Mark Nudleman and the University of California, Berkeley. The
* name of Mark Nudleman or the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)prompt.c 5.4 (Berkeley) %G%";
* 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.
extern int so_width
, se_width
;
extern char *current_file
;
* Prototypes for the three flavors of prompts.
* These strings are expanded by pr_expand().
"?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\\: %x..%t";
"?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t";
"?f%f .?n?m(file %i of %m) ..?ltline %lt :byte %bB?s/%s ..?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t";
"?f%f .?m(file %i of %m) .?ltline %lt .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t";
static char message
[250];
* Initialize the prompt prototype strings.
prproto
[0] = save(s_proto
);
prproto
[1] = save(m_proto
);
prproto
[2] = save(M_proto
);
* Set the message pointer to the end of the message string.
* Append a POSITION (as a decimal integer) to the end of the message.
(void)sprintf(mp
, "%ld", (long)pos
);
* Append an integer to the end of the message.
(void)sprintf(mp
, "%d", n
);
* Append a question mark to the end of the message.
* Return the "current" byte offset in the file.
if (pos
== NULL_POSITION
)
* 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.
case 'a': /* Anything in the message yet? */
case 'b': /* Current byte offset known? */
return (curr_byte(where
) != NULL_POSITION
);
case 'e': /* At end of file? */
case 'f': /* Filename known? */
case 'l': /* Line number known? */
case 'm': /* More than one file? */
case 'n': /* First prompt in a new file? */
case 'p': /* Percent into file known? */
return (curr_byte(where
) != NULL_POSITION
&&
case 's': /* Size of file known? */
return (ch_length() != NULL_POSITION
);
case 'x': /* Is there a "next" file? */
return (curr_ac
+ 1 < ac
);
* 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.
case 'b': /* Current byte offset */
if (pos
!= NULL_POSITION
)
case 'f': /* File name */
strtcpy(mp
, current_file
,
(unsigned int)(&message
[sizeof(message
)] - mp
));
case 'i': /* Index into list of files */
case 'l': /* Current line number */
case 'm': /* Number of files */
case 'p': /* Percent into file */
if (pos
!= NULL_POSITION
&& len
> 0)
ap_int((int)(100*pos
/ len
));
case 's': /* Size of file */
if (len
!= NULL_POSITION
)
case 't': /* Truncate trailing spaces in the message */
while (mp
> message
&& mp
[-1] == ' ')
case 'x': /* Name of next file */
strtcpy(mp
, av
[curr_ac
+1],
(unsigned int)(&message
[sizeof(message
)] - mp
));
* 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.
register int iflevel
= 1;
* If this matches the IF we came in here with,
* If this matches the IF we came in here with,
* Backslash escapes the next character.
* Whoops. Hit end of string.
* This is a malformed conditional, but just treat it
* as if all active conditionals ends here.
case 'b': case 'l': case 'p':
case 't': *wp
= TOP
; break;
case 'm': *wp
= MIDDLE
; break;
case 'b': *wp
= BOTTOM
; break;
case 'B': *wp
= BOTTOM_PLUS_ONE
; break;
default: *wp
= TOP
; break;
* Construct a message based on a prototype string.
pr_expand(proto
, maxwidth
)
for (p
= proto
; *p
!= '\0'; p
++)
default: /* Just put the character in the message */
case '\\': /* Backslash escapes the next character */
case '?': /* Conditional (IF) */
p
= wherechar(p
, &where
);
case '%': /* Percent escape */
p
= wherechar(p
, &where
);
if (maxwidth
> 0 && mp
>= message
+ maxwidth
)
* Return just the final portion of it.
* Return a message suitable for printing by the "=" command.
return (pr_expand(eqproto
, 0));
* 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.
return (pr_expand(prproto
[pr_type
], sc_width
-so_width
-se_width
-2));