Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ lesskey.man
lesskey.nro
upload
.vimrc
.vscode/
IGNORE/
157 changes: 157 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Cmake file for less
# by Pedro Oliva Rodrigues

cmake_minimum_required(VERSION 3.8)
project("gwsw-less"
VERSION 556
LANGUAGES C
)
set(PROJECT_HOMEPAGE_URL "http://www.greenwoodsoftware.com/less")

if(WIN32)
set(EDIT_PGM_ "notepad")
set(EDIT_PROTO_ "%E %g")
if(NOT SYSDIR)
set(SYSDIR "c:")
endif()
else()
set(EDIT_PGM_ "vi")
set(EDIT_PROTO_ "%E ?lm+%lm. %g")
endif()

if(MINGW)
add_compile_definitions(MINGW)
endif()


# User preferences
option(SECURE_COMPILE "If enabled, disables a bunch of features in order to be safe to run by unprivileged users." OFF)
option(CMD_HISTORY "Enable if you wish to allow keys to cycle through previous commands at prompts." ON)
option(HILITE_SEARCH "Enable if you wish to have search targets to be displayed in standout mode." ON)
set(EDIT_PGM ${EDIT_PGM_} CACHE STRING "Name of the default to be invoked by the 'v' command if EDITOR env. var. is not set")
set(EDIT_PROTO ${EDIT_PROTO_} CACHE STRING "The default editor prototype, if LESSEDIT is not set.")
option(GNU_OPTIONS "Enable if you wish to support the GNU-style command line options --help and --version." ON)
option(ONLY_RETURN "Enable if you want RETURN to be the only input which will continue past an error message. Otherwise, any key will continue past an error message." OFF)
set(LESSKEYFILE ".less" CACHE STRING "Filename of the default lesskey output file (in the HOME directory).")
set(LESSKEYFILE_SYS "sysless" CACHE STRING "Filename of the system-wide lesskey output file.")
set(DEF_LESSKEYINFILE ".lesskey" CACHE STRING "Filename of the default lesskey input (in the HOME directory).")
set(LESSHISTFILE ".lesshst" CACHE STRING "Filename of the history file (in the HOME directory).")
set(REGEX_LIBRARY regcomp-local CACHE STRING "Select what regular expression library to use ([regcomp-local],posix,pcre2,off).")

set(SECURE ${SECURE_COMPILE} CACHE INTERNAL "same as SECURE_COMPILE")

# needed for creating generated_files and making pkg releases
find_package(Perl REQUIRED)

# targets
set(SRC main.c screen.c brac.c ch.c charset.c cmdbuf.c
command.c cvt.c decode.c edit.c filename.c forwback.c
ifile.c input.c jump.c line.c linenum.c
lsystem.c mark.c optfunc.c option.c opttbl.c os.c
output.c pattern.c position.c prompt.c search.c signal.c
tags.c ttyin.c)

# we need to give the full path, else it fails to find help.c when building less
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/help.c
COMMAND ${PERL_EXECUTABLE} mkhelp.pl < "less.hlp" > help.c
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating help.c ..."
USES_TERMINAL
)
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/funcs.h
COMMAND ${PERL_EXECUTABLE} mkfuncs.pl ${SRC} > funcs.h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating funcs.h ..."
USES_TERMINAL
)

add_executable(less ${SRC} help.c)
add_executable(lesskey lesskey.c)
add_executable(lessecho lessecho.c)

# sudo lib for common settings
add_library(common INTERFACE)
target_sources(common INTERFACE ${CMAKE_SOURCE_DIR}/version.c ${CMAKE_SOURCE_DIR}/funcs.h)
target_include_directories(common INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) # for defines.h

target_link_libraries(less PRIVATE common)
target_link_libraries(lesskey PRIVATE common)
target_link_libraries(lessecho PRIVATE common)


# dependency detection
include(CheckIncludeFiles)
include(CheckTypeSize)
include(CheckSymbolExists)

# find terminal libraries
find_package(Curses) # curses or ncurses
find_library(TINFO_LIB NAMES tinfo libtinfo.so libtinfo.so.5)
find_library(TERMCAP_LIB NAMES termcap libtermcap.so)

if(WIN32)
set(TERMINAL_LIBRARY WindowsConsole)
elseif(TINFO_LIB)
set(TERMINAL_LIBRARY tinfo)
target_link_libraries(less PRIVATE ${TINFO_LIB})
elseif(CURSES_FOUND)
target_include_directories(less PRIVATE ${CURSES_INCLUDE_DIRS})
set(TERMINAL_LIBRARY curses)
target_link_libraries(less PRIVATE ${CURSES_LIBRARIES})
elseif(TERMCAP_LIB)
set(TERMINAL_LIBRARY termcap)
target_link_libraries(less PRIVATE ${TERMCAP_LIB})
else()
set(TERMINAL_LIBRARY NOTFOUND)
endif()

check_include_files("termios.h" HAVE_TERMIOS_H)
check_include_files("termio.h" HAVE_TERMIO_H)
check_include_files("termcap.h" HAVE_TERMCAP_H)

message(STATUS "terminal lib: ${TERMINAL_LIBRARY}")

if(NOT TERMINAL_LIBRARY)
message(SEND_ERROR "Cannot find terminal libraries")
endif()


# find regex library
if(REGEX_LIBRARY MATCHES regcomp-local)
target_sources(less PRIVATE ${CMAKE_SOURCE_DIR}/regexp.c)
set(HAVE_V8_REGCOMP true)
set(HAVE_REGEXEC2 true)
set(found yes)
elseif(REGEX_LIBRARY MATCHES posix)
check_include_files("regex.h" HAVE_POSIX_REGCOMP)
set(found HAVE_POSIX_REGCOMP)
elseif(REGEX_LIBRARY MATCHES pcre2)
find_library(pcre2_lib NAMES pcre2 libpcre2-8.so libpcre2-8.so.0)
if(pcre2_lib)
set(HAVE_PCRE2 true)
target_link_libraries(less PRIVATE ${pcre2_lib})
set(found yes)
endif()
elseif(NOT REGEX_LIBRARY)
set(NO_REGEX true)
set(found yes)
endif()

if(NOT found)
message("Cannot find regex lib '${REGEX_LIBRARY}'")
set(REGEX_LIBRARY NOTFOUND)
endif()

message(STATUS "regex lib: ${REGEX_LIBRARY}")


check_include_files("langinfo.h" HAVE_LANGINFO)
check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H)
check_include_files("sys/ptem.h" HAVE_SYS_PTEM_H)
check_include_files("sys/stream.h" HAVE_SYS_STREAM_H)

list(APPEND CMAKE_EXTRA_INCLUDE_FILES "signal.h")
check_type_size("(sigset_t*)0" SIGSET_T)
check_symbol_exists(sigemptyset "signal.h" HAVE_SIGEMPTYSET)

configure_file(defines.cmake.in defines.h)
1 change: 1 addition & 0 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "less.h"
#if MSDOS_COMPILER==WIN32C
#include <errno.h>
#include "os_defs.h"
#include <windows.h>
#endif

Expand Down
8 changes: 4 additions & 4 deletions charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#if HAVE_LOCALE
#include <locale.h>
#include <ctype.h>
#if HAVE_LANGINFO
#include <langinfo.h>
#endif
#endif

#include "charset.h"

#if MSDOS_COMPILER==WIN32C
#define WIN32_LEAN_AND_MEAN
#include "os_defs.h"
#include <windows.h>
#endif

Expand Down Expand Up @@ -337,16 +339,14 @@ set_charset(VOID_PARAM)
return;
}

#if HAVE_LOCALE
#ifdef CODESET
#if HAVE_LANGINFO && defined(CODESET)
/*
* Try using the codeset name as the charset name.
*/
s = nl_langinfo(CODESET);
if (icharset(s, 1))
return;
#endif
#endif

#if HAVE_STRSTR
/*
Expand Down
18 changes: 12 additions & 6 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,11 @@ histfile_modified(VOID_PARAM)
return 0;
}

#if MSDOS_COMPILER==WIN32C
#include "os_defs.h"
#include <windows.h>
#endif

/*
* Update the .lesshst file.
*/
Expand All @@ -1694,8 +1699,10 @@ save_cmdhist(VOID_PARAM)
histname = histfile_name();
if (histname == NULL)
return;

tempname = make_tempname(histname);
fout = fopen(tempname, "w");

if (fout != NULL)
{
make_file_private(fout);
Expand All @@ -1714,14 +1721,13 @@ save_cmdhist(VOID_PARAM)
read_cmdhist(&copy_hist, &ctx, skip_search, skip_shell);
save_marks(fout, HISTFILE_MARK_SECTION);
fclose(fout);

// replace the file atomically
#if MSDOS_COMPILER==WIN32C
/*
* Windows rename doesn't remove an existing file,
* making it useless for atomic operations. Sigh.
*/
remove(histname);
#endif
ReplaceFileA(histname, tempname, 0,0,0,0);
#else
rename(tempname, histname);
#endif
}
free(tempname);
free(histname);
Expand Down
1 change: 1 addition & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "less.h"
#if MSDOS_COMPILER==WIN32C
#include "os_defs.h"
#include <windows.h>
#endif
#include "position.h"
Expand Down
9 changes: 7 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,15 @@ fi

AC_MSG_CHECKING(for locale)
AC_TRY_LINK([#include <locale.h>
#include <ctype.h>
#include <langinfo.h>], [setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);],
#include <ctype.h>], [setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);],
[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LOCALE)], [AC_MSG_RESULT(no)])

AC_MSG_CHECKING(for langinfo)
AC_TRY_LINK([#include <locale.h>
#include <ctype.h>
#include <langinfo.h>], [setlocale(LC_CTYPE,""); nl_langinfo(CODESET);],
[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LANGINFO)], [AC_MSG_RESULT(no)])

AC_MSG_CHECKING(for ctype functions)
AC_TRY_LINK([
#if HAVE_CTYPE_H
Expand Down
Loading