diff options
Diffstat (limited to 'contrib/less/prompt.c')
-rw-r--r-- | contrib/less/prompt.c | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/contrib/less/prompt.c b/contrib/less/prompt.c index 14480213dff4..80fc29deee2c 100644 --- a/contrib/less/prompt.c +++ b/contrib/less/prompt.c @@ -41,19 +41,22 @@ extern char *editproto; * These strings are expanded by pr_expand(). */ static constant char s_proto[] = - "?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\\: %x..%t"; + "?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\\: %x..%t"; static constant char m_proto[] = - "?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t"; + "?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t"; static constant char M_proto[] = - "?f%f .?n?m(file %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t"; + "?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"; static constant char e_proto[] = - "?f%f .?m(file %i of %m) .?ltlines %lt-%lb?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t"; + "?f%f .?m(%T %i of %m) .?ltlines %lt-%lb?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t"; static constant char h_proto[] = "HELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done"; +static constant char w_proto[] = + "Waiting for data"; public char *prproto[3]; public char constant *eqproto = e_proto; public char constant *hproto = h_proto; +public char constant *wproto = w_proto; static char message[PROMPT_SIZE]; static char *mp; @@ -69,6 +72,7 @@ init_prompt() prproto[2] = save(M_proto); eqproto = save(e_proto); hproto = save(h_proto); + wproto = save(w_proto); } /* @@ -109,10 +113,19 @@ ap_char(c) ap_pos(pos) POSITION pos; { - char buf[MAX_PRINT_POSITION]; - - sprintf(buf, PR_POSITION, pos); - ap_str(buf); + char buf[INT_STRLEN_BOUND(pos) + 1]; + char *p = buf + sizeof(buf) - 1; + int neg = (pos < 0); + + if (neg) + pos = -pos; + *p = '\0'; + do + *--p = '0' + (pos % 10); + while ((pos /= 10) != 0); + if (neg) + *--p = '-'; + ap_str(p); } /* @@ -122,7 +135,7 @@ ap_pos(pos) ap_int(n) int n; { - char buf[MAX_PRINT_INT]; + char buf[INT_STRLEN_BOUND(n) + 1]; sprintf(buf, "%d", n); ap_str(buf); @@ -186,9 +199,9 @@ cond(c, where) case 'D': /* Same as L */ return (linenums && ch_length() != NULL_POSITION); case 'm': /* More than one file? */ - return (nifile() > 1); + return (ntags() ? (ntags() > 1) : (nifile() > 1)); case 'n': /* First prompt in a new file? */ - return (new_file); + return (ntags() ? 1 : new_file); case 'p': /* Percent into file (bytes) known? */ return (curr_byte(where) != NULL_POSITION && ch_length() > 0); @@ -200,6 +213,8 @@ cond(c, where) case 'B': return (ch_length() != NULL_POSITION); case 'x': /* Is there a "next" file? */ + if (ntags()) + return (0); return (next_ifile(curr_ifile) != NULL_IFILE); } return (0); @@ -272,7 +287,10 @@ protochar(c, where, iseditproto) free(s); break; case 'i': /* Index into list of files */ - ap_int(get_index(curr_ifile)); + if (ntags()) + ap_int(curr_tag()); + else + ap_int(get_index(curr_ifile)); break; case 'l': /* Current line number */ n = currline(where); @@ -290,7 +308,11 @@ protochar(c, where, iseditproto) ap_int(n-1); break; case 'm': /* Number of files */ - ap_int(nifile()); + n = ntags(); + if (n) + ap_int(n); + else + ap_int(nifile()); break; case 'p': /* Percent into file (bytes) */ pos = curr_byte(where); @@ -321,6 +343,12 @@ protochar(c, where, iseditproto) while (mp > message && mp[-1] == ' ') mp--; break; + case 'T': /* Type of list */ + if (ntags()) + ap_str("tag"); + else + ap_str("file"); + break; case 'x': /* Name of next file */ h = next_ifile(curr_ifile); if (h != NULL_IFILE) @@ -483,7 +511,6 @@ pr_expand(proto, maxwidth) } } - new_file = 0; if (mp == message) return (NULL); if (maxwidth > 0 && mp >= message + maxwidth) @@ -515,7 +542,20 @@ eq_message() public char * pr_string() { - if (ch_getflags() & CH_HELPFILE) - return (pr_expand(hproto, sc_width-so_s_width-so_e_width-2)); - return (pr_expand(prproto[pr_type], sc_width-so_s_width-so_e_width-2)); + char *prompt; + + prompt = pr_expand((ch_getflags() & CH_HELPFILE) ? + hproto : prproto[pr_type], + 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 * +wait_message() +{ + return (pr_expand(wproto, sc_width-so_s_width-so_e_width-2)); } |