=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/prompt.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- src/usr.bin/less/prompt.c 2010/08/09 20:40:08 1.11 +++ src/usr.bin/less/prompt.c 2011/09/16 18:12:09 1.12 @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2002 Mark Nudelman + * Copyright (C) 1984-2011 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -22,7 +22,6 @@ #include "position.h" extern int pr_type; -extern int hit_eof; extern int new_file; extern int sc_width; extern int so_s_width, so_e_width; @@ -30,6 +29,7 @@ extern int hshift; extern int sc_height; extern int jump_sline; +extern int less_is_more; extern IFILE curr_ifile; #if EDITOR extern char *editor; @@ -164,7 +164,7 @@ POSITION pos; pos = position(where); - while (pos == NULL_POSITION && where >= 0 && where < sc_height) + while (pos == NULL_POSITION && where >= 0 && where < sc_height-1) pos = position(++where); if (pos == NULL_POSITION) pos = ch_length(); @@ -193,14 +193,14 @@ case 'c': return (hshift != 0); case 'e': /* At end of file? */ - return (hit_eof); + return (eof_displayed()); 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? */ - case 'D': /* Same as L */ + case 'D': /* Final page number known? */ return (linenums && ch_length() != NULL_POSITION); case 'm': /* More than one file? */ #if TAGS @@ -254,6 +254,9 @@ LINENUM last_linenum; IFILE h; +#undef PAGE_NUM +#define PAGE_NUM(linenum) ((((linenum) - 1) / (sc_height - 1)) + 1) + switch (c) { case 'b': /* Current byte offset */ @@ -269,17 +272,26 @@ case 'd': /* Current page number */ linenum = currline(where); if (linenum > 0 && sc_height > 1) - ap_linenum(((linenum - 1) / (sc_height - 1)) + 1); + ap_linenum(PAGE_NUM(linenum)); else ap_quest(); break; - case 'D': /* Last page number */ + case 'D': /* Final page number */ + /* Find the page number of the last byte in the file (len-1). */ len = ch_length(); - if (len == NULL_POSITION || len == ch_zero() || - (linenum = find_linenum(len)) <= 0) + if (len == NULL_POSITION) ap_quest(); + else if (len == 0) + /* An empty file has no pages. */ + ap_linenum(0); else - ap_linenum(((linenum - 1) / (sc_height - 1)) + 1); + { + linenum = find_linenum(len - 1); + if (linenum <= 0) + ap_quest(); + else + ap_linenum(PAGE_NUM(linenum)); + } break; #if EDITOR case 'E': /* Editor name */ @@ -289,6 +301,9 @@ case 'f': /* File name */ ap_str(get_filename(curr_ifile)); break; + case 'F': /* Last component of file name */ + ap_str(last_component(get_filename(curr_ifile))); + break; case 'i': /* Index into list of files */ #if TAGS if (ntags()) @@ -519,7 +534,7 @@ } if (mp == message) - return (NULL); + return (""); if (maxwidth > 0 && mp >= message + maxwidth) { /* @@ -550,8 +565,12 @@ pr_string() { char *prompt; + int type; - prompt = pr_expand(prproto[pr_type], sc_width-so_s_width-so_e_width-2); + type = (!less_is_more) ? pr_type : pr_type ? 0 : 1; + prompt = pr_expand((ch_getflags() & CH_HELPFILE) ? + hproto : prproto[type], + sc_width-so_s_width-so_e_width-2); new_file = 0; return (prompt); }