From 4ac7dd380f1bb5eac3def440024ffb74dc75cc6d Mon Sep 17 00:00:00 2001 From: Jerome Duval Date: Thu, 29 Jun 2017 17:06:55 +0200 Subject: import fix from previous version diff --git a/cmdbuf.c b/cmdbuf.c index db5b259..671403a 100644 --- a/cmdbuf.c +++ b/cmdbuf.c @@ -74,16 +74,16 @@ struct mlist /* * These are the various command histories that exist. */ -struct mlist mlist_search = +struct mlist mlist_search = { &mlist_search, &mlist_search, &mlist_search, NULL, 0 }; public void *ml_search = (void *) &mlist_search; -struct mlist mlist_examine = +struct mlist mlist_examine = { &mlist_examine, &mlist_examine, &mlist_examine, NULL, 0 }; public void *ml_examine = (void *) &mlist_examine; #if SHELL_ESCAPE || PIPEC -struct mlist mlist_shell = +struct mlist mlist_shell = { &mlist_shell, &mlist_shell, &mlist_shell, NULL, 0 }; public void *ml_shell = (void *) &mlist_shell; #endif @@ -394,7 +394,7 @@ cmd_right() char *pr; char *ncp; int width; - + if (*cp == '\0') { /* Already at the end of the line. */ @@ -460,14 +460,14 @@ cmd_ichar(cs, clen) int clen; { char *s; - + if (strlen(cmdbuf) + clen >= sizeof(cmdbuf)-1) { /* No room in the command buffer for another char. */ bell(); return (CC_ERROR); } - + /* * Make room for the new character (shift the tail of the buffer right). */ @@ -527,7 +527,7 @@ cmd_erase() */ updown_match = -1; cmd_repaint(cp); - + /* * We say that erasing the entire command string causes us * to abort the current command, if CF_QUIT_ON_ERASE is set. @@ -664,7 +664,7 @@ cmd_updown(action) { constant char *s; struct mlist *ml; - + if (curr_mlist == NULL) { /* @@ -729,7 +729,7 @@ cmd_addhist(mlist, cmd, modified) { #if CMD_HISTORY struct mlist *ml; - + /* * Don't save a trivial command. */ @@ -801,7 +801,7 @@ cmd_edit(c) #else #define not_in_completion() #endif - + /* * See if the char is indeed a line-editing command. */ @@ -912,7 +912,7 @@ cmd_istr(str) char *s; int action; char *endline = str + strlen(str); - + for (s = str; *s != '\0'; ) { char *os = s; @@ -944,7 +944,7 @@ delimit_word() constant char *esc = get_meta_escape(); int esclen = (int) strlen(esc); #endif - + /* * Move cursor to end of word. */ @@ -1017,7 +1017,7 @@ delimit_word() /* * Set things up to enter completion mode. - * Expand the word under the cursor into a list of filenames + * Expand the word under the cursor into a list of filenames * which start with that word, and set tk_text to that list. */ static void @@ -1025,7 +1025,7 @@ init_compl() { char *word; char c; - + /* * Get rid of any previous tk_text. */ @@ -1114,8 +1114,8 @@ cmd_complete(action) if (!in_completion || action == EC_EXPAND) { /* - * Expand the word under the cursor and - * use the first word in the expansion + * Expand the word under the cursor and + * use the first word in the expansion * (or the entire expansion if we're doing EC_EXPAND). */ init_compl(); @@ -1147,13 +1147,13 @@ cmd_complete(action) */ tk_trial = next_compl(action, tk_trial); } - + /* * Remove the original word, or the previous trial completion. */ while (cp > tk_ipoint) (void) cmd_erase(); - + if (tk_trial == NULL) { /* @@ -1184,9 +1184,9 @@ cmd_complete(action) goto fail; } } - + return (CC_OK); - + fail: in_completion = 0; bell(); @@ -1274,7 +1274,7 @@ cmd_char(c) literal = 0; return (cmd_ichar(cmd_mbc_buf, len)); } - + /* * See if it is a line-editing character. */ @@ -1290,7 +1290,7 @@ cmd_char(c) break; } } - + /* * Insert the char into the command buffer. */ @@ -1360,10 +1360,14 @@ mlist_size(ml) static char * histfile_name() { +#ifdef __HAIKU__ + char home[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; +#else char *home; +#endif char *name; int len; - + /* See if filename is explicitly specified by $LESSHISTFILE. */ name = lgetenv("LESSHISTFILE"); if (name != NULL && *name != '\0') @@ -1378,6 +1382,13 @@ histfile_name() if (strcmp(LESSHISTFILE, "") == 0 || strcmp(LESSHISTFILE, "-") == 0) return (NULL); +#ifdef __HAIKU__ + { + dev_t volume = dev_for_path("/boot"); + if (find_directory(B_USER_SETTINGS_DIRECTORY, volume, true, home, sizeof(home)) != B_OK) + return (NULL); + } +#else /* Otherwise, file is in $HOME. */ home = lgetenv("HOME"); if (home == NULL || *home == '\0') @@ -1388,6 +1399,7 @@ histfile_name() #endif return (NULL); } +#endif len = (int) (strlen(home) + strlen(LESSHISTFILE) + 2); name = (char *) ecalloc(len, sizeof(char)); SNPRINTF2(name, len, "%s/%s", home, LESSHISTFILE); diff --git a/configure.ac b/configure.ac index 3616ef0..144a8be 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ # 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 about less, or for information on how to +# For more information about less, or for information on how to # contact the author, see the README file. # Autoconf initialization. @@ -237,10 +237,10 @@ AH_TEMPLATE([SECURE_COMPILE], # Checks for identifiers. AC_TYPE_OFF_T AC_MSG_CHECKING(for void) -AC_TRY_COMPILE(, [void *foo = 0;], +AC_TRY_COMPILE(, [void *foo = 0;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_VOID)], [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(for const) -AC_TRY_COMPILE(, [const int foo = 0;], +AC_TRY_COMPILE(, [const int foo = 0;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_CONST)], [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(for time_t) AC_TRY_COMPILE([#include ], [time_t t = 0;], @@ -306,7 +306,7 @@ AC_TRY_LINK([ [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STRERROR)], [AC_MSG_RESULT(no)]) AC_MSG_CHECKING(for sys_errlist) -AC_TRY_LINK(, [extern char *sys_errlist[]; static char **x; x = sys_errlist;], +AC_TRY_LINK(, [extern char *sys_errlist[]; static char **x; x = sys_errlist;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYS_ERRLIST)], [AC_MSG_RESULT(no)]) AC_CHECK_TYPES([sigset_t],,,[#include ]) @@ -322,13 +322,13 @@ AC_MSG_CHECKING(for errno) AC_TRY_LINK([ #if HAVE_ERRNO_H #include -#endif], [static int x; x = errno;], +#endif], [static int x; x = errno;], [AC_MSG_RESULT(yes - in errno.h); AC_DEFINE(HAVE_ERRNO) have_errno=yes]) if test $have_errno = no; then AC_TRY_LINK([ #if HAVE_ERRNO_H #include -#endif], [extern int errno; static int x; x = errno;], +#endif], [extern int errno; static int x; x = errno;], [AC_MSG_RESULT(yes - must define); AC_DEFINE(HAVE_ERRNO) AC_DEFINE(MUST_DEFINE_ERRNO)], [AC_MSG_RESULT(no)]) fi @@ -363,7 +363,7 @@ AC_TRY_LINK([ #endif], [ospeed = 0;], [AC_MSG_RESULT(yes - in termcap.h); AC_DEFINE(HAVE_OSPEED) have_ospeed=yes]) if test $have_ospeed = no; then -AC_TRY_LINK(, [extern short ospeed; ospeed = 0;], +AC_TRY_LINK(, [extern short ospeed; ospeed = 0;], [AC_MSG_RESULT(yes - must define); AC_DEFINE(HAVE_OSPEED) AC_DEFINE(MUST_DEFINE_OSPEED)], [AC_MSG_RESULT(no)]) fi @@ -379,7 +379,7 @@ AC_ARG_WITH(no-float, [ --with-no-float Do not use floating point], WANT_NO_FLOAT=1, WANT_NO_FLOAT=0) if test $WANT_NO_FLOAT = 0; then - AC_TRY_LINK(, [double f1 = 12.5; double f2 = f1*f1/2.5;], + AC_TRY_LINK(, [double f1 = 12.5; double f2 = f1*f1/2.5;], [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FLOAT)], [AC_MSG_RESULT(no)]) else AC_MSG_RESULT(disabled by user) @@ -433,21 +433,21 @@ fi if test $have_regex = no; then if test $WANT_REGEX = auto -o $WANT_REGEX = pcre; then -AC_CHECK_LIB(pcre, pcre_compile, +AC_CHECK_LIB(pcre, pcre_compile, [AC_DEFINE(HAVE_PCRE) LIBS="$LIBS -lpcre" have_regex=yes; supported_regex="$supported_regex pcre"], []) fi fi if test $have_regex = no; then if test $WANT_REGEX = auto -o $WANT_REGEX = gnu; then -AC_CHECK_LIB(c, re_compile_pattern, +AC_CHECK_LIB(c, re_compile_pattern, [AC_DEFINE(HAVE_GNU_REGEX) have_regex=yes; supported_regex="$supported_regex gnu"], []) fi fi if test $have_regex = no; then if test $WANT_REGEX = auto -o $WANT_REGEX = regcmp; then -AC_CHECK_FUNC(regcmp, +AC_CHECK_FUNC(regcmp, [AC_DEFINE(HAVE_REGCMP) have_regex=yes; supported_regex="$supported_regex regcmp"],[]) fi fi @@ -463,7 +463,7 @@ fi if test $have_regex = no && test -f ${srcdir}/regexp.c; then if test $WANT_REGEX = auto -o $WANT_REGEX = regcomp-local; then -AC_MSG_RESULT(using V8 regcomp -- local source); AC_DEFINE(HAVE_V8_REGCOMP) +AC_MSG_RESULT(using V8 regcomp -- local source); AC_DEFINE(HAVE_V8_REGCOMP) supported_regex="$supported_regex regcomp-local" AC_DEFINE(HAVE_REGEXEC2) REGEX_O='regexp.$(O)' AC_SUBST(REGEX_O) have_regex=yes fi @@ -538,7 +538,7 @@ AH_TOP([ #define CMD_HISTORY 1 /* - * HILITE_SEARCH is 1 if you wish to have search targets to be + * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ #define HILITE_SEARCH 1 @@ -556,7 +556,7 @@ AH_TOP([ #define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .less file to specify * user-defined key bindings. */ #define USERFILE (!SECURE) @@ -593,19 +593,25 @@ AH_TOP([ #define ONLY_RETURN 0 /* - * LESSKEYFILE is the filename of the default lesskey output file + * LESSKEYFILE is the filename of the default lesskey output file * (in the HOME directory). * LESSKEYFILE_SYS is the filename of the system-wide lesskey output file. - * DEF_LESSKEYINFILE is the filename of the default lesskey input + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ +#ifdef __HAIKU__ +# define LESSKEYFILE "less" +# define LESSKEYFILE_SYS SYSDIR "/sysless" +# define DEF_LESSKEYINFILE "lesskey" +# define LESSHISTFILE "lesshst" +#else #define LESSKEYFILE ".less" #define LESSKEYFILE_SYS SYSDIR "/sysless" #define DEF_LESSKEYINFILE ".lesskey" #define LESSHISTFILE ".lesshst" - +#endif /* Settings always true on Unix. */ @@ -662,7 +668,7 @@ AH_TOP([ #define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\$%=~{}," #define DEF_METAESCAPE "\\" -/* +/* * HAVE_DUP is 1 if your system has the dup() call. */ #define HAVE_DUP 1 diff --git a/filename.c b/filename.c index 1c0ae42..b9d322a 100644 --- a/filename.c +++ b/filename.c @@ -164,7 +164,7 @@ shell_quote(s) if (esclen == 0) { /* - * We've got a metachar, but this shell + * We've got a metachar, but this shell * doesn't support escape chars. Use quotes. */ use_quotes = 1; @@ -259,12 +259,23 @@ homefile(filename) { char *pathname; +#ifdef __HAIKU__ + char path[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; + dev_t volume = dev_for_path("/boot"); + if (find_directory(B_USER_SETTINGS_DIRECTORY, volume, true, path, sizeof(path)) != B_OK) + return (NULL); + + pathname = dirfile(&path, filename); + if (pathname != NULL) + return (pathname); +#else /* * Try $HOME/filename. */ pathname = dirfile(lgetenv("HOME"), filename); if (pathname != NULL) return (pathname); +#endif #if OS2 /* * Try $INIT/filename. @@ -317,7 +328,7 @@ fexpand(s) (c) == '#' ? old_ifile : NULL_IFILE) /* - * Make one pass to see how big a buffer we + * Make one pass to see how big a buffer we * need to allocate for the expanded string. */ n = 0; @@ -415,8 +426,8 @@ fcomplete(s) /* * But in DOS, we have to glob "s*.*". * But if the final component of the filename already has - * a dot in it, just do "s*". - * (Thus, "FILE" is globbed as "FILE*.*", + * a dot in it, just do "s*". + * (Thus, "FILE" is globbed as "FILE*.*", * but "FILE.A" is globbed as "FILE.A*"). */ { @@ -528,8 +539,8 @@ readfd(fd) int ch; char *buf; char *p; - - /* + + /* * Make a guess about how many chars in the string * and allocate a buffer to hold it. */ @@ -585,7 +596,7 @@ shellcmd(cmd) char *esccmd; /* - * Read the output of <$SHELL -c cmd>. + * Read the output of <$SHELL -c cmd>. * Escape any metacharacters in the command. */ esccmd = shell_quote(cmd); @@ -686,7 +697,7 @@ lglob(filename) char *pfilename; char *qfilename; DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle) - + GLOB_FIRST_NAME(filename, &fnd, handle); if (GLOB_FIRST_FAILED(handle)) { @@ -825,7 +836,7 @@ num_pct_s(lessopen) } /* - * See if we should open a "replacement file" + * See if we should open a "replacement file" * instead of the file we're about to open. */ public char * @@ -845,7 +856,7 @@ open_altfile(filename, pf, pfd) #if HAVE_FILENO int returnfd = 0; #endif - + if (!use_lessopen || secure) return (NULL); ch_ungetchar(-1); @@ -854,7 +865,7 @@ open_altfile(filename, pf, pfd) while (*lessopen == '|') { /* - * If LESSOPEN starts with a |, it indicates + * If LESSOPEN starts with a |, it indicates * a "pipe preprocessor". */ #if !HAVE_FILENO @@ -914,7 +925,7 @@ open_altfile(filename, pf, pfd) /* * Pipe is empty. * If more than 1 pipe char was specified, - * the exit status tells whether the file itself + * the exit status tells whether the file itself * is empty, or if there is no alt file. * If only one pipe char, just assume no alt file. */ @@ -956,13 +967,13 @@ close_altfile(altfilename, filename) FILE *fd; char *cmd; int len; - + if (secure) return; ch_ungetchar(-1); if ((lessclose = lgetenv("LESSCLOSE")) == NULL) return; - if (num_pct_s(lessclose) > 2) + if (num_pct_s(lessclose) > 2) { error("LESSCLOSE ignored; must contain no more than 2 %%s", NULL_PARG); return; @@ -976,7 +987,7 @@ close_altfile(altfilename, filename) pclose(fd); #endif } - + /* * Is the specified file a directory? */ @@ -1024,7 +1035,7 @@ bad_file(filename) { static char is_a_dir[] = " is a directory"; - m = (char *) ecalloc(strlen(filename) + sizeof(is_a_dir), + m = (char *) ecalloc(strlen(filename) + sizeof(is_a_dir), sizeof(char)); strcpy(m, filename); strcat(m, is_a_dir); @@ -1079,7 +1090,7 @@ filesize(f) } /* - * + * */ public char * shell_coption() diff --git a/less.h b/less.h index 39ca65e..203d620 100644 --- a/less.h +++ b/less.h @@ -100,6 +100,11 @@ #include #endif +#ifdef __HAIKU__ +#include +#include +#endif + #if MSDOS_COMPILER==WIN32C || OS2 #include #endif @@ -305,7 +310,7 @@ struct scrpos /* * A mark is an ifile (input file) plus a position within the file. */ -struct mark +struct mark { IFILE m_ifile; struct scrpos m_scrpos; @@ -331,7 +336,7 @@ struct wchar_range LWCHAR first, last; }; -struct wchar_range_table +struct wchar_range_table { struct wchar_range *table; int count; diff --git a/lesskey.c b/lesskey.c index 9fd0a9f..f7b065b 100644 --- a/lesskey.c +++ b/lesskey.c @@ -11,7 +11,7 @@ /* * lesskey [-o output] [input] * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Make a .less file. * If no input file is specified, standard input is used. @@ -21,9 +21,9 @@ * key bindings. Basically any sequence of 1 to MAX_CMDLEN * keystrokes may be bound to an existing less function. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * The input file is an ascii file consisting of a + * The input file is an ascii file consisting of a * sequence of lines of the form: * string action [chars] * @@ -37,14 +37,14 @@ * to specify a character by its octal value. * 4. A backslash followed by b, e, n, r or t * to specify \b, ESC, \n, \r or \t, respectively. - * 5. Any character (other than those mentioned above) preceded + * 5. Any character (other than those mentioned above) preceded * by a \ to specify the character itself (characters which * must be preceded by \ include ^, \, and whitespace. * "action" is the name of a "less" action, from the table below. * "chars" is an optional sequence of characters which is treated * as keyboard input after the command is executed. * - * Blank lines and lines which start with # are ignored, + * Blank lines and lines which start with # are ignored, * except for the special control lines: * #command Signals the beginning of the command * keys section. @@ -55,7 +55,7 @@ * #stop Stops command parsing in less; * causes all default keys to be disabled. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * The output file is a non-ascii file, consisting of a header, * one or more sections, and a trailer. @@ -63,7 +63,7 @@ * and the section data. Normally there are three sections: * CMD_SECTION Definition of command keys. * EDIT_SECTION Definition of editing keys. - * END_SECTION A special section header, with no + * END_SECTION A special section header, with no * length word or section data. * * Section data consists of zero or more byte sequences of the form: @@ -77,7 +77,7 @@ * If action is ORed with A_EXTRA, the action byte is followed * by the null-terminated "chars" string. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "less.h" @@ -90,7 +90,7 @@ struct cmdname int cn_action; }; -struct cmdname cmdnames[] = +struct cmdname cmdnames[] = { { "back-bracket", A_B_BRACKET }, { "back-line", A_B_LINE }, @@ -158,7 +158,7 @@ struct cmdname cmdnames[] = { NULL, 0 } }; -struct cmdname editnames[] = +struct cmdname editnames[] = { { "back-complete", EC_B_COMPLETE }, { "backspace", EC_BACKSPACE }, @@ -196,14 +196,14 @@ struct table vartable; struct table *currtable = &cmdtable; char fileheader[] = { - C0_LESSKEY_MAGIC, - C1_LESSKEY_MAGIC, - C2_LESSKEY_MAGIC, + C0_LESSKEY_MAGIC, + C1_LESSKEY_MAGIC, + C2_LESSKEY_MAGIC, C3_LESSKEY_MAGIC }; char filetrailer[] = { - C0_END_LESSKEY_MAGIC, - C1_END_LESSKEY_MAGIC, + C0_END_LESSKEY_MAGIC, + C1_END_LESSKEY_MAGIC, C2_END_LESSKEY_MAGIC }; char cmdsection[1] = { CMD_SECTION }; @@ -250,8 +250,19 @@ homefile(filename) char *p; char *pathname; +#ifdef __HAIKU__ + char path[B_PATH_NAME_LENGTH+B_FILE_NAME_LENGTH]; + dev_t volume = dev_for_path("/boot"); + if (find_directory(B_USER_SETTINGS_DIRECTORY, volume, true, path, sizeof(path)) != B_OK) + return (NULL); + + pathname = mkpathname(&path, filename); + if (pathname != NULL) + return (pathname); +#else if ((p = getenv("HOME")) != NULL && *p != '\0') pathname = mkpathname(p, filename); +#endif #if OS2 else if ((p = getenv("INIT")) != NULL && *p != '\0') pathname = mkpathname(p, filename); @@ -442,7 +453,7 @@ tstr(pp, xlate) /* FALLTHRU */ default: /* - * Backslash followed by any other char + * Backslash followed by any other char * just means that char. */ *pp = p+1; @@ -478,7 +489,7 @@ tstr(pp, xlate) skipsp(s) char *s; { - while (*s == ' ' || *s == '\t') + while (*s == ' ' || *s == '\t') s++; return (s); } @@ -600,7 +611,7 @@ fputint(fd, val) if (val >= KRADIX*KRADIX) { - fprintf(stderr, "error: integer too big (%d > %d)\n", + fprintf(stderr, "error: integer too big (%d > %d)\n", val, KRADIX*KRADIX); exit(1); } @@ -790,7 +801,7 @@ main(argc, argv) char *path = getenv("HOMEPATH"); if (drive != NULL && path != NULL) { - char *env = (char *) calloc(strlen(drive) + + char *env = (char *) calloc(strlen(drive) + strlen(path) + 6, sizeof(char)); strcpy(env, "HOME="); strcat(env, drive); @@ -869,7 +880,7 @@ main(argc, argv) fputbytes(out, (char *)edittable.buffer, edittable.pbuffer-edittable.buffer); /* Environment variable section */ - fputbytes(out, varsection, sizeof(varsection)); + fputbytes(out, varsection, sizeof(varsection)); fputint(out, vartable.pbuffer - vartable.buffer); fputbytes(out, (char *)vartable.buffer, vartable.pbuffer-vartable.buffer); -- 2.14.2