From 824a88bbba654121cac7ca08a3c38a4a435dcdb3 Mon Sep 17 00:00:00 2001 From: tron Date: Sun, 3 Jul 2011 20:14:12 +0000 Subject: [PATCH] Apply NetBSD specific patches, mostly related to behaviour of less(1) as more(1). --- external/bsd/less/dist/brac.c | 6 ++-- external/bsd/less/dist/ch.c | 6 ++-- external/bsd/less/dist/charset.c | 5 +++- external/bsd/less/dist/cmdbuf.c | 39 ++++++++++++++++++++++---- external/bsd/less/dist/command.c | 46 +++++++++++++++++++++---------- external/bsd/less/dist/decode.c | 9 ++++-- external/bsd/less/dist/edit.c | 16 +++++++---- external/bsd/less/dist/filename.c | 8 +++++- external/bsd/less/dist/forwback.c | 9 ++++-- external/bsd/less/dist/funcs.h | 4 +-- external/bsd/less/dist/help.c | 6 +++- external/bsd/less/dist/ifile.c | 8 +++++- external/bsd/less/dist/less.h | 4 +-- external/bsd/less/dist/lessecho.c | 9 ++++-- external/bsd/less/dist/lesskey.c | 18 ++++++------ external/bsd/less/dist/lglob.h | 4 +-- external/bsd/less/dist/line.c | 9 +++--- external/bsd/less/dist/linenum.c | 6 +++- external/bsd/less/dist/lsystem.c | 3 +- external/bsd/less/dist/main.c | 8 ++++-- external/bsd/less/dist/option.c | 9 ++++-- external/bsd/less/dist/option.h | 5 ++-- external/bsd/less/dist/opttbl.c | 11 +++++++- external/bsd/less/dist/os.c | 8 ++++-- external/bsd/less/dist/output.c | 4 +-- external/bsd/less/dist/pattern.h | 5 ++-- external/bsd/less/dist/position.c | 3 +- external/bsd/less/dist/prompt.c | 32 ++++++++++++++------- external/bsd/less/dist/screen.c | 22 ++++++++++++--- external/bsd/less/dist/search.c | 4 +-- external/bsd/less/dist/signal.c | 8 +++++- external/bsd/less/dist/tags.c | 16 +++++------ 32 files changed, 248 insertions(+), 102 deletions(-) diff --git a/external/bsd/less/dist/brac.c b/external/bsd/less/dist/brac.c index 8437b2dceedd..d8c31606a14a 100644 --- a/external/bsd/less/dist/brac.c +++ b/external/bsd/less/dist/brac.c @@ -1,4 +1,4 @@ -/* $NetBSD: brac.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: brac.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -36,9 +36,7 @@ match_brac(obrac, cbrac, forwdir, n) register int c; register int nest; POSITION pos; - int (*chget)(); - - extern int ch_forw_get(), ch_back_get(); + int (*chget) __P((void)); /* * Seek to the line containing the open bracket. diff --git a/external/bsd/less/dist/ch.c b/external/bsd/less/dist/ch.c index 386f2de2ff31..d4f1f1a36752 100644 --- a/external/bsd/less/dist/ch.c +++ b/external/bsd/less/dist/ch.c @@ -1,4 +1,4 @@ -/* $NetBSD: ch.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: ch.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -140,7 +140,9 @@ extern int logfile; extern char *namelogfile; #endif -static int ch_addbuf(); +static int ch_addbuf __P((void)); +static int buffered __P((BLOCKNUM)); +static void ch_delbufs __P((void)); /* diff --git a/external/bsd/less/dist/charset.c b/external/bsd/less/dist/charset.c index b90b3d2fa3b6..d4cba65e7562 100644 --- a/external/bsd/less/dist/charset.c +++ b/external/bsd/less/dist/charset.c @@ -1,4 +1,4 @@ -/* $NetBSD: charset.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: charset.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -117,6 +117,9 @@ static char *binfmt = NULL; static char *utfbinfmt = NULL; public int binattr = AT_STANDOUT; +static void ichardef __P((char *)); +static int icharset __P((char *, int)); +static void ilocale __P((void)); /* * Define a charset, given a description string. diff --git a/external/bsd/less/dist/cmdbuf.c b/external/bsd/less/dist/cmdbuf.c index 888f2e09a864..f51c17eb9f30 100644 --- a/external/bsd/less/dist/cmdbuf.c +++ b/external/bsd/less/dist/cmdbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: cmdbuf.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: cmdbuf.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -22,6 +22,9 @@ #if HAVE_STAT #include #endif +#if HAVE_ERRNO_H +#include +#endif extern int sc_width; extern int utf_mode; @@ -34,7 +37,7 @@ static int cmd_offset; /* Index into cmdbuf of first displayed char */ static int literal; /* Next input char should not be interpreted */ #if TAB_COMPLETE_FILENAME -static int cmd_complete(); +static int cmd_complete __P((int)); /* * These variables are statics used by cmd_complete. */ @@ -46,8 +49,24 @@ static char *tk_trial; static struct textlist tk_tlist; #endif -static int cmd_left(); -static int cmd_right(); +static void cmd_repaint __P((char *)); +static void cmd_home __P((void)); +static void cmd_lshift __P((void)); +static void cmd_rshift __P((void)); +static int cmd_right __P((void)); +static int cmd_left __P((void)); +static int cmd_ichar __P((char *, int)); +static int cmd_erase __P((void)); +static int cmd_delete __P((void)); +static int cmd_werase __P((void)); +static int cmd_wdelete __P((void)); +static int cmd_kill __P((void)); +static int cmd_updown __P((int)); +static int cmd_edit __P((int)); +static int cmd_istr __P((char *)); +static char *delimit_word __P((void)); +static void init_compl __P((void)); +static char *next_compl __P((int, char *)); #if SPACES_IN_FILENAMES public char openquote = '"'; @@ -930,7 +949,7 @@ cmd_istr(str) static char * delimit_word() { - char *word; + char *word = NULL; #if SPACES_IN_FILENAMES char *p; int delim_quoted = 0; @@ -1374,10 +1393,20 @@ init_cmdhist() char *filename; FILE *f; char *p; +#ifdef HAVE_STAT + struct stat st; +#endif filename = histfile_name(); if (filename == NULL) return; +#ifdef HAVE_STAT + /* ignore devices/fifos; allow symlinks */ + if (stat(filename, &st) < 0) + return; + if (!S_ISREG(st.st_mode)) + return; +#endif f = fopen(filename, "r"); free(filename); if (f == NULL) diff --git a/external/bsd/less/dist/command.c b/external/bsd/less/dist/command.c index 0508e8d34e5d..4120f1b67d08 100644 --- a/external/bsd/less/dist/command.c +++ b/external/bsd/less/dist/command.c @@ -1,4 +1,4 @@ -/* $NetBSD: command.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: command.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -56,6 +56,10 @@ extern int screen_trashed; /* The screen has been overwritten */ extern int shift_count; extern int oldbot; extern int forw_prompt; +extern int be_helpful; +extern int more_mode; + +static int helpprompt; #if SHELL_ESCAPE static char *shellcmd = NULL; /* For holding last shell command for "!!" */ @@ -478,21 +482,25 @@ mca_search_char(c) * Certain characters as the first char of * the pattern have special meaning: * ! Toggle the NO_MATCH flag - * * Toggle the PAST_EOF flag - * @ Toggle the FIRST_FILE flag + * * Toggle the PAST_EOF flag (less extension) + * @ Toggle the FIRST_FILE flag (less extension) */ if (len_cmdbuf() > 0) return (NO_MCA); switch (c) { - case CONTROL('E'): /* ignore END of file */ case '*': + if (more_mode) + break; + case CONTROL('E'): /* ignore END of file */ if (mca != A_FILTER) flag = SRCH_PAST_EOF; break; - case CONTROL('F'): /* FIRST file */ case '@': + if (more_mode) + break; + case CONTROL('F'): /* FIRST file */ if (mca != A_FILTER) flag = SRCH_FIRST_FILE; break; @@ -739,16 +747,23 @@ prompt() clear_bot(); clear_cmd(); forw_prompt = 0; - p = pr_string(); - if (is_filtering()) - putstr("& "); - if (p == NULL || *p == '\0') - putchr(':'); - else - { + if (helpprompt) { at_enter(AT_STANDOUT); - putstr(p); + putstr("[Press 'h' for instructions.]"); at_exit(); + helpprompt = 0; + } else { + p = pr_string(); + if (is_filtering()) + putstr("& "); + if (p == NULL || *p == '\0') + putchr(':'); + else + { + at_enter(AT_STANDOUT); + putstr(p); + at_exit(); + } } clear_eol(); } @@ -1758,7 +1773,10 @@ commands() break; default: - bell(); + if (be_helpful) + helpprompt = 1; + else + bell(); break; } } diff --git a/external/bsd/less/dist/decode.c b/external/bsd/less/dist/decode.c index 13911e18d7b2..b6e585d47497 100644 --- a/external/bsd/less/dist/decode.c +++ b/external/bsd/less/dist/decode.c @@ -1,4 +1,4 @@ -/* $NetBSD: decode.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: decode.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -225,6 +225,11 @@ static struct tablelist *list_ecmd_tables = NULL; static struct tablelist *list_var_tables = NULL; static struct tablelist *list_sysvar_tables = NULL; +static int add_cmd_table __P((struct tablelist **, char *, int)); +static int cmd_decode __P((struct tablelist *, char *, char **)); +static int gint __P((char **)); +static int old_lesskey __P((char *, int)); +static int new_lesskey __P((char *, int, int)); /* * Expand special key abbreviations in a command table. @@ -749,7 +754,7 @@ editchar(c, flags) { int action; int nch; - char *s; + char *s = NULL; /* XXX: GCC */ char usercmd[MAX_CMDLEN+1]; /* diff --git a/external/bsd/less/dist/edit.c b/external/bsd/less/dist/edit.c index 991a8fdd525d..20f1230e3101 100644 --- a/external/bsd/less/dist/edit.c +++ b/external/bsd/less/dist/edit.c @@ -1,4 +1,4 @@ -/* $NetBSD: edit.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: edit.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -29,7 +29,7 @@ extern int sigs; extern IFILE curr_ifile; extern IFILE old_ifile; extern struct scrpos initial_scrpos; -extern void constant *ml_examine; +extern void *constant ml_examine; #if SPACES_IN_FILENAMES extern char openquote; extern char closequote; @@ -50,6 +50,11 @@ char *curr_altfilename = NULL; static void *curr_altpipe; +static void close_file __P((void)); +static int edit_istep __P((IFILE, int, int)); +static int edit_inext __P((IFILE, int)); +static int edit_iprev __P((IFILE, int)); + /* * Textlist functions deal with a list of words separated by spaces. * init_textlist sets up a textlist structure. @@ -322,7 +327,7 @@ edit_ifile(ifile) * It looks like a bad file. Don't try to open it. */ error("%s", &parg); - free(parg.p_string); + free((void *)parg.p_string); err1: if (alt_filename != NULL) { @@ -352,7 +357,7 @@ edit_ifile(ifile) */ parg.p_string = errno_message(filename); error("%s", &parg); - free(parg.p_string); + free((void *)parg.p_string); goto err1; } else { @@ -744,7 +749,8 @@ use_logfile(filename) */ filename = shell_unquote(filename); exists = open(filename, OPEN_READ); - close(exists); + if (exists >= 0) + close(exists); exists = (exists >= 0); /* diff --git a/external/bsd/less/dist/filename.c b/external/bsd/less/dist/filename.c index ceb2910ebfe3..de4decbe9d66 100644 --- a/external/bsd/less/dist/filename.c +++ b/external/bsd/less/dist/filename.c @@ -1,4 +1,4 @@ -/* $NetBSD: filename.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: filename.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -62,6 +62,12 @@ extern char openquote; extern char closequote; #endif +static char *dirfile __P((char *, char *)); +static POSITION seek_filesize __P((int)); +static char *readfd __P((FILE *)); +static int metachar __P((int)); +static FILE *shellcmd __P((char *)); + /* * Remove quotes around a filename. */ diff --git a/external/bsd/less/dist/forwback.c b/external/bsd/less/dist/forwback.c index 42955d3fdda6..82e290140838 100644 --- a/external/bsd/less/dist/forwback.c +++ b/external/bsd/less/dist/forwback.c @@ -1,4 +1,4 @@ -/* $NetBSD: forwback.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: forwback.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -28,6 +28,7 @@ extern int sigs; extern int top_scroll; extern int quiet; extern int sc_width, sc_height; +extern int more_mode; extern int plusoption; extern int forw_scroll; extern int back_scroll; @@ -39,6 +40,9 @@ extern int oldbot; extern char *tagoption; #endif +static void eof_bell __P((void)); +static void eof_check __P((void)); + /* * Sound the bell to indicate user is trying to move past end of file. */ @@ -240,7 +244,8 @@ forw(n, pos, force, only_last, nblank) * start the display after the beginning of the file, * and it is not appropriate to squish in that case. */ - if (first_time && pos == NULL_POSITION && !top_scroll && + if ((first_time || more_mode) && + pos == NULL_POSITION && !top_scroll && #if TAGS tagoption == NULL && #endif diff --git a/external/bsd/less/dist/funcs.h b/external/bsd/less/dist/funcs.h index ce969d404937..def617e11a80 100644 --- a/external/bsd/less/dist/funcs.h +++ b/external/bsd/less/dist/funcs.h @@ -1,10 +1,10 @@ -/* $NetBSD: funcs.h,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: funcs.h,v 1.3 2011/07/03 20:14:12 tron Exp $ */ public char * save (); public VOID_POINTER ecalloc (); public char * skipsp (); public int sprefix (); - public void quit (); + public void quit () __attribute__((__noreturn__)); public void raw_mode (); public void scrsize (); public char * special_key_str (); diff --git a/external/bsd/less/dist/help.c b/external/bsd/less/dist/help.c index 698e28c51115..4f5f9833f98c 100644 --- a/external/bsd/less/dist/help.c +++ b/external/bsd/less/dist/help.c @@ -1,7 +1,10 @@ -/* $NetBSD: help.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: help.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* This file was generated by mkhelp from less.hlp */ #include "less.h" +#ifdef SMALL +constant char helpdata[] = "\nNo help available\n"; +#else constant char helpdata[] = { '\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','\b','S','U','\b','U','M','\b','M','M','\b','M','A','\b','A','R','\b','R','Y','\b','Y',' ','O','\b','O','F','\b','F',' ','L','\b','L','E','\b','E','S','\b','S','S','\b','S',' ','C','\b','C','O','\b','O','M','\b','M','M','\b','M','A','\b','A','N','\b','N','D','\b','D','S','\b','S','\n', @@ -235,4 +238,5 @@ constant char helpdata[] = { '\n', '\n', 0 }; +#endif constant int size_helpdata = sizeof(helpdata) - 1; diff --git a/external/bsd/less/dist/ifile.c b/external/bsd/less/dist/ifile.c index f1c6bd545339..60ccd48b9c0f 100644 --- a/external/bsd/less/dist/ifile.c +++ b/external/bsd/less/dist/ifile.c @@ -1,4 +1,4 @@ -/* $NetBSD: ifile.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: ifile.c,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -51,6 +51,12 @@ static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0', { NULL_POSITION, 0 } }; static int ifiles = 0; +static void incr_index __P((struct ifile *, int)); +static void link_ifile __P((struct ifile *, struct ifile *)); +static void unlink_ifile __P((struct ifile *)); +static struct ifile *new_ifile __P((char *, struct ifile *)); +static struct ifile *find_ifile __P((char *)); + static void incr_index(p, incr) register struct ifile *p; diff --git a/external/bsd/less/dist/less.h b/external/bsd/less/dist/less.h index 7f5fc54f4915..6116626dac90 100644 --- a/external/bsd/less/dist/less.h +++ b/external/bsd/less/dist/less.h @@ -1,4 +1,4 @@ -/* $NetBSD: less.h,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: less.h,v 1.3 2011/07/03 20:14:12 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -300,7 +300,7 @@ struct scrpos typedef union parg { - char *p_string; + constant char *p_string; int p_int; LINENUM p_linenum; } PARG; diff --git a/external/bsd/less/dist/lessecho.c b/external/bsd/less/dist/lessecho.c index b9b0098d0a3e..9faddd74faf6 100644 --- a/external/bsd/less/dist/lessecho.c +++ b/external/bsd/less/dist/lessecho.c @@ -1,4 +1,4 @@ -/* $NetBSD: lessecho.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: lessecho.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -30,7 +30,7 @@ #include "less.h" -static char *version = "$Revision: 1.2 $"; +static char *version = "$Revision: 1.3 $"; static int quote_all = 0; static char openquote = '"'; @@ -40,6 +40,11 @@ static char meta_escape_buf[2]; static char metachars[64] = ""; static int num_metachars = 0; +static void pr_usage __P((void)); +static void pr_version __P((void)); +static void pr_error __P((char *)); +static long lstrtol __P((char *, int, char **)); + static void pr_usage() { diff --git a/external/bsd/less/dist/lesskey.c b/external/bsd/less/dist/lesskey.c index 16d81a369e2e..8a0c23c5a7fb 100644 --- a/external/bsd/less/dist/lesskey.c +++ b/external/bsd/less/dist/lesskey.c @@ -1,4 +1,4 @@ -/* $NetBSD: lesskey.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: lesskey.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -214,6 +214,8 @@ char *outfile = NULL ; int linenum; int errors; +void terror(char *); + extern char version[]; void @@ -422,7 +424,7 @@ tstr(pp, xlate) case 'e': ch = SK_END; break; case 'x': ch = SK_DELETE; break; default: - error("illegal char after \\k"); + terror("illegal char after \\k"); *pp = p+1; return (""); } @@ -519,7 +521,7 @@ add_cmd_char(c) { if (currtable->pbuffer >= currtable->buffer + MAX_USERCMD) { - error("too many commands"); + terror("too many commands"); exit(1); } *(currtable->pbuffer)++ = c; @@ -619,12 +621,12 @@ findaction(actname) for (i = 0; currtable->names[i].cn_name != NULL; i++) if (strcmp(currtable->names[i].cn_name, actname) == 0) return (currtable->names[i].cn_action); - error("unknown action"); + terror("unknown action"); return (A_INVALID); } void -error(s) +terror(s) char *s; { fprintf(stderr, "line %d: %s\n", linenum, s); @@ -651,7 +653,7 @@ parse_cmdline(p) s = tstr(&p, 1); cmdlen += strlen(s); if (cmdlen > MAX_CMDLEN) - error("command too long"); + terror("command too long"); else add_cmd_str(s); } while (*p != ' ' && *p != '\t' && *p != '\0'); @@ -668,7 +670,7 @@ parse_cmdline(p) p = skipsp(p); if (*p == '\0') { - error("missing action"); + terror("missing action"); return; } actname = p; @@ -721,7 +723,7 @@ parse_varline(p) p = skipsp(p); if (*p++ != '=') { - error("missing ="); + terror("missing ="); return; } diff --git a/external/bsd/less/dist/lglob.h b/external/bsd/less/dist/lglob.h index 85155bb79a8f..8507e266edd9 100644 --- a/external/bsd/less/dist/lglob.h +++ b/external/bsd/less/dist/lglob.h @@ -1,4 +1,4 @@ -/* $NetBSD: lglob.h,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: lglob.h,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -36,7 +36,7 @@ #else #if MSDOS_COMPILER==DJGPPC -#define DECL_GLOB_LIST(list) glob_t list; int i; +#define DECL_GLOB_LIST(list) glob_t list; size_t i; #define GLOB_LIST(filename,list) glob(filename,GLOB_NOCHECK,0,&list) #define GLOB_LIST_FAILED(list) 0 #define SCAN_GLOB_LIST(list,p) i = 0; i < list.gl_pathc; i++ diff --git a/external/bsd/less/dist/line.c b/external/bsd/less/dist/line.c index 3a05a739271e..be766a6485c8 100644 --- a/external/bsd/less/dist/line.c +++ b/external/bsd/less/dist/line.c @@ -1,4 +1,4 @@ -/* $NetBSD: line.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: line.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -42,10 +42,9 @@ static POSITION pendpos; static char *end_ansi_chars; static char *mid_ansi_chars; -static int attr_swidth(); -static int attr_ewidth(); -static int do_append(); - +static int attr_swidth(int); +static int attr_ewidth(int); +static int do_append(LWCHAR, char *, POSITION); extern int sigs; extern int bs_mode; extern int linenums; diff --git a/external/bsd/less/dist/linenum.c b/external/bsd/less/dist/linenum.c index d80b7b60b0cd..ce0823b67e70 100644 --- a/external/bsd/less/dist/linenum.c +++ b/external/bsd/less/dist/linenum.c @@ -1,4 +1,4 @@ -/* $NetBSD: linenum.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: linenum.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -72,6 +72,10 @@ extern int sigs; extern int sc_height; extern int screen_trashed; +static void calcgap __P((struct linenum_info *)); +static void longloopmessage __P((void)); +static void longish __P((void)); + /* * Initialize the line number structures. */ diff --git a/external/bsd/less/dist/lsystem.c b/external/bsd/less/dist/lsystem.c index 5d091d1f2c47..de476a348514 100644 --- a/external/bsd/less/dist/lsystem.c +++ b/external/bsd/less/dist/lsystem.c @@ -1,4 +1,4 @@ -/* $NetBSD: lsystem.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: lsystem.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -294,7 +294,6 @@ pipe_data(cmd, spos, epos) { register FILE *f; register int c; - extern FILE *popen(); /* * This is structured much like lsystem(). diff --git a/external/bsd/less/dist/main.c b/external/bsd/less/dist/main.c index 021a7da06490..be5b1976de11 100644 --- a/external/bsd/less/dist/main.c +++ b/external/bsd/less/dist/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: main.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -34,6 +34,7 @@ public char * progname; public int quitting; public int secure; public int dohelp; +public int more_mode = 0; #if LOGFILE public int logfile = -1; @@ -113,6 +114,9 @@ main(argc, argv) * Process command line arguments and LESS environment arguments. * Command line arguments override environment arguments. */ + if (strcmp(getprogname(), "more") == 0) + more_mode = 1; + is_tty = isatty(1); get_term(); init_cmds(); @@ -238,7 +242,7 @@ main(argc, argv) quit(QUIT_OK); } - if (missing_cap && !know_dumb) + if (missing_cap && !know_dumb && !more_mode) error("WARNING: terminal is not fully functional", NULL_PARG); init_mark(); open_getchr(); diff --git a/external/bsd/less/dist/option.c b/external/bsd/less/dist/option.c index 9403a0472f84..7e94da9a7d00 100644 --- a/external/bsd/less/dist/option.c +++ b/external/bsd/less/dist/option.c @@ -1,4 +1,4 @@ -/* $NetBSD: option.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: option.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -26,8 +26,9 @@ static struct loption *pendopt; public int plusoption = FALSE; -static char *optstring(); -static int flip_triple(); +static char *optstring __P((char *, char **, char *, char *)); +static int flip_triple __P((int, int)); +static void nostring __P((char *)); extern int screen_trashed; extern int less_is_more; @@ -448,6 +449,8 @@ toggle_option(o, lower, s, how_toggle) { case BOOL: case TRIPLE: + if (*(o->ovar) < 0) + error("Negative option is invalid", NULL_PARG); /* * Print the odesc message. */ diff --git a/external/bsd/less/dist/option.h b/external/bsd/less/dist/option.h index cdd7e1b58612..2ce552a34bf6 100644 --- a/external/bsd/less/dist/option.h +++ b/external/bsd/less/dist/option.h @@ -1,4 +1,4 @@ -/* $NetBSD: option.h,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: option.h,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -63,7 +63,8 @@ struct loption int otype; /* Type of the option */ int odefault; /* Default value */ int *ovar; /* Pointer to the associated variable */ - void (*ofunc)(); /* Pointer to special handling function */ + void (*ofunc) /* Pointer to special handling function */ + __P((int, char *)); char *odesc[3]; /* Description of each value */ }; diff --git a/external/bsd/less/dist/opttbl.c b/external/bsd/less/dist/opttbl.c index 2d4825908682..c3444822c4ba 100644 --- a/external/bsd/less/dist/opttbl.c +++ b/external/bsd/less/dist/opttbl.c @@ -1,4 +1,4 @@ -/* $NetBSD: opttbl.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: opttbl.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -30,6 +30,7 @@ public int bs_mode; /* How to process backspaces */ public int know_dumb; /* Don't complain about dumb terminals */ public int quit_at_eof; /* Quit after hitting end of file twice */ public int quit_if_one_screen; /* Quit if EOF on first screen */ +public int be_helpful; /* more(1) style -d */ public int squeeze; /* Squeeze multiple blank lines into one */ public int tabstop; /* Tab settings */ public int back_scroll; /* Repaint screen on backwards movement */ @@ -167,7 +168,15 @@ static struct loption option[] = "Repaint by painting from top of screen" } }, +#if 1 { 'd', &d_optname, + BOOL, OPT_OFF, &be_helpful, NULL, + { "Be less helpful in prompts", + "Be helpful in prompts", + NULL } + }, +#endif + { -1, &d_optname, BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL, { "Assume intelligent terminal", diff --git a/external/bsd/less/dist/os.c b/external/bsd/less/dist/os.c index a1728e0de58b..59fcc23e0706 100644 --- a/external/bsd/less/dist/os.c +++ b/external/bsd/less/dist/os.c @@ -1,4 +1,4 @@ -/* $NetBSD: os.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: os.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -63,6 +63,10 @@ static jmp_buf read_label; extern int sigs; +#if !HAVE_STRERROR +static char *strerror __P((int)); +#endif + /* * Like read() system call, but is deliberately interruptible. * A call to intread() from a signal handler will interrupt @@ -235,7 +239,7 @@ strerror(err) errno_message(filename) char *filename; { - register char *p; + register const char *p; register char *m; int len; #if HAVE_ERRNO diff --git a/external/bsd/less/dist/output.c b/external/bsd/less/dist/output.c index ad511e54574d..27587af65d75 100644 --- a/external/bsd/less/dist/output.c +++ b/external/bsd/less/dist/output.c @@ -1,4 +1,4 @@ -/* $NetBSD: output.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: output.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -438,7 +438,7 @@ less_printf(fmt, parg) register char *fmt; PARG *parg; { - register char *s; + register constant char *s; register int col; col = 0; diff --git a/external/bsd/less/dist/pattern.h b/external/bsd/less/dist/pattern.h index 7576a98dd555..4930e641ef7b 100644 --- a/external/bsd/less/dist/pattern.h +++ b/external/bsd/less/dist/pattern.h @@ -1,4 +1,4 @@ -/* $NetBSD: pattern.h,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: pattern.h,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -13,7 +13,8 @@ #if HAVE_POSIX_REGCOMP #include #ifdef REG_EXTENDED -#define REGCOMP_FLAG REG_EXTENDED +extern int more_mode; +#define REGCOMP_FLAG (more_mode ? 0 : REG_EXTENDED) #else #define REGCOMP_FLAG 0 #endif diff --git a/external/bsd/less/dist/position.c b/external/bsd/less/dist/position.c index d8a39dded6a7..94a5545235bc 100644 --- a/external/bsd/less/dist/position.c +++ b/external/bsd/less/dist/position.c @@ -1,4 +1,4 @@ -/* $NetBSD: position.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: position.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -109,6 +109,7 @@ pos_clear() pos_init() { struct scrpos scrpos; + scrpos.pos = scrpos.ln = 0; /* XXX: GCC */ if (sc_height <= table_size) return; diff --git a/external/bsd/less/dist/prompt.c b/external/bsd/less/dist/prompt.c index d33fa7c1f29e..de265a17e8b8 100644 --- a/external/bsd/less/dist/prompt.c +++ b/external/bsd/less/dist/prompt.c @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: prompt.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -57,7 +57,7 @@ static constant char w_proto[] = static constant char more_proto[] = "--More--(?eEND ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t)"; -public char *prproto[3]; +public char constant *prproto[3]; public char constant *eqproto = e_proto; public char constant *hproto = h_proto; public char constant *wproto = w_proto; @@ -65,6 +65,17 @@ public char constant *wproto = w_proto; static char message[PROMPT_SIZE]; static char *mp; +static void ap_pos __P((POSITION)); +static void ap_int __P((int)); +static void ap_str __P((char *)); +static void ap_char __P((int)); +static void ap_quest __P((void)); +static POSITION curr_byte __P((int)); +static int cond __P((int, int)); +static void protochar __P((int, int, int)); +static const char *skipcond __P((const char *)); +static const char *wherechar __P((const char *, int *)); + /* * Initialize the prompt prototype strings. */ @@ -100,10 +111,11 @@ ap_str(s) * Append a character to the end of the message. */ static void -ap_char(c) - char c; +ap_char(i) + int i; { char buf[2]; + char c = (char)i; buf[0] = c; buf[1] = '\0'; @@ -395,9 +407,9 @@ protochar(c, where, iseditproto) * where to resume parsing the string. * We must keep track of nested IFs and skip them properly. */ - static char * + static const char * skipcond(p) - register char *p; + register const char *p; { register int iflevel; @@ -453,9 +465,9 @@ skipcond(p) /* * Decode a char that represents a position on the screen. */ - static char * + static const char * wherechar(p, wp) - char *p; + const char *p; int *wp; { switch (*p) @@ -479,10 +491,10 @@ wherechar(p, wp) */ public char * pr_expand(proto, maxwidth) - char *proto; + const char *proto; int maxwidth; { - register char *p; + register const char *p; register int c; int where; diff --git a/external/bsd/less/dist/screen.c b/external/bsd/less/dist/screen.c index c36ed1128b68..e323a3b9875f 100644 --- a/external/bsd/less/dist/screen.c +++ b/external/bsd/less/dist/screen.c @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: screen.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -229,6 +229,8 @@ extern int quiet; /* If VERY_QUIET, use visual bell for bell */ extern int no_back_scroll; extern int swindow; extern int no_init; +extern int quit_at_eof; +extern int more_mode; extern int no_keypad; extern int sigs; extern int wscroll; @@ -240,8 +242,10 @@ extern int oldbot; extern int hilite_search; #endif +#ifndef HAVE_TERMCAP_H extern char *tgetstr(); extern char *tgoto(); +#endif /* @@ -1210,11 +1214,21 @@ get_term() if (sc_e_keypad == NULL) sc_e_keypad = ""; - sc_init = ltgetstr("ti", &sp); + /* + * This loses for terminals with termcap entries with ti/te strings + * that switch to/from an alternate screen, and we're in quit_at_eof + * (eg, more(1)). + */ + if (quit_at_eof != OPT_ONPLUS && !more_mode) { + sc_init = ltgetstr("ti", &sp); + sc_deinit = ltgetstr("te", &sp); + } else { + sc_init = NULL; + sc_deinit = NULL; + } + if (sc_init == NULL) sc_init = ""; - - sc_deinit= ltgetstr("te", &sp); if (sc_deinit == NULL) sc_deinit = ""; diff --git a/external/bsd/less/dist/search.c b/external/bsd/less/dist/search.c index 799c12b4247b..6e65240f33e4 100644 --- a/external/bsd/less/dist/search.c +++ b/external/bsd/less/dist/search.c @@ -1,4 +1,4 @@ -/* $NetBSD: search.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: search.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -701,7 +701,7 @@ search_range(pos, endpos, search_type, matches, maxlines, plinepos, pendpos) char *cline; int line_len; LINENUM linenum; - char *sp, *ep; + char *sp = NULL, *ep = NULL; /* XXX: GCC */ int line_match; int cvt_ops; int cvt_len; diff --git a/external/bsd/less/dist/signal.c b/external/bsd/less/dist/signal.c index b445b83373ed..d6b81b6e1309 100644 --- a/external/bsd/less/dist/signal.c +++ b/external/bsd/less/dist/signal.c @@ -1,4 +1,4 @@ -/* $NetBSD: signal.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: signal.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -29,6 +29,12 @@ */ public int sigs; +static RETSIGTYPE u_interrupt __P((int)); +static RETSIGTYPE stop __P((int)); +#if MSDOS_COMPILER==WIN32C +static BOOL WINAPI wbreak_handler __P((DWORD)); +#endif + extern int sc_width, sc_height; extern int screen_trashed; extern int lnloop; diff --git a/external/bsd/less/dist/tags.c b/external/bsd/less/dist/tags.c index eb5e08d336ee..e827b3b0dfac 100644 --- a/external/bsd/less/dist/tags.c +++ b/external/bsd/less/dist/tags.c @@ -1,4 +1,4 @@ -/* $NetBSD: tags.c,v 1.2 2011/07/03 19:51:26 tron Exp $ */ +/* $NetBSD: tags.c,v 1.3 2011/07/03 20:14:13 tron Exp $ */ /* * Copyright (C) 1984-2011 Mark Nudelman @@ -61,12 +61,6 @@ static int getentry(); * findctag() uses either pattern (in which case line number is 0), * or line number (in which case pattern is NULL). */ -struct taglist { - struct tag *tl_first; - struct tag *tl_last; -}; -#define TAG_END ((struct tag *) &taglist) -static struct taglist taglist = { TAG_END, TAG_END }; struct tag { struct tag *next, *prev; /* List links */ char *tag_file; /* Source file containing the tag */ @@ -74,6 +68,12 @@ struct tag { char *tag_pattern; /* Pattern used to find the tag */ char tag_endline; /* True if the pattern includes '$' */ }; +struct taglist { + struct tag *tl_first; + struct tag *tl_last; +}; +#define TAG_END ((struct tag *) &taglist) +static struct taglist taglist = { TAG_END, TAG_END }; static struct tag *curtag; #define TAG_INS(tp) \ @@ -544,7 +544,7 @@ findgtag(tag, type) while (fgets(buf, sizeof(buf), fp)) { char *name, *file, *line; - int len; + size_t len; if (sigs) {