Skip to content

Commit cdf08a6

Browse files
authored
Merge pull request #66 from cginternals/convertUTF
Convert utf
2 parents 0f5b974 + 7af41c2 commit cdf08a6

File tree

15 files changed

+5277
-77
lines changed

15 files changed

+5277
-77
lines changed

3rdparty/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# External libraries
3+
set(IDE_FOLDER "3rdparty")
4+
add_subdirectory(linenoise-ng)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
2+
#
3+
# External dependencies
4+
#
5+
6+
7+
#
8+
# Library name and options
9+
#
10+
11+
# Target name
12+
set(target linenoise-ng)
13+
14+
# Exit here if required dependencies are not met
15+
message(STATUS "External ${target}")
16+
17+
18+
#
19+
# Sources
20+
#
21+
22+
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
23+
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
24+
25+
set(headers
26+
${include_path}/linenoise.h
27+
${include_path}/ConvertUTF.h
28+
)
29+
30+
set(sources
31+
${source_path}/linenoise.cpp
32+
${source_path}/ConvertUTF.cpp
33+
${source_path}/wcwidth.cpp
34+
)
35+
36+
37+
#
38+
# Create library
39+
#
40+
41+
# Build library
42+
add_library(${target} STATIC
43+
${sources}
44+
${headers}
45+
)
46+
47+
# Create namespaced alias
48+
add_library(externals::${target} ALIAS ${target})
49+
50+
51+
#
52+
# Project options
53+
#
54+
55+
set_target_properties(${target}
56+
PROPERTIES
57+
${DEFAULT_PROJECT_OPTIONS}
58+
FOLDER "${IDE_FOLDER}"
59+
)
60+
61+
62+
#
63+
# Include directories
64+
#
65+
66+
target_include_directories(${target}
67+
PRIVATE
68+
${DEFAULT_INCLUDE_DIRECTORIES}
69+
${PROJECT_BINARY_DIR}/source/include
70+
71+
PUBLIC
72+
${CMAKE_CURRENT_SOURCE_DIR}/include
73+
74+
INTERFACE
75+
)
76+
77+
78+
#
79+
# Libraries
80+
#
81+
82+
target_link_libraries(${target}
83+
PRIVATE
84+
85+
PUBLIC
86+
${DEFAULT_LIBRARIES}
87+
88+
INTERFACE
89+
)
90+
91+
92+
#
93+
# Compile definitions
94+
#
95+
96+
target_compile_definitions(${target}
97+
PRIVATE
98+
99+
PUBLIC
100+
${target_upper}_STATIC_DEFINE
101+
${DEFAULT_COMPILE_DEFINITIONS}
102+
103+
INTERFACE
104+
)
105+
106+
107+
#
108+
# Compile options
109+
#
110+
111+
target_compile_options(${target}
112+
PRIVATE
113+
114+
PUBLIC
115+
# ${DEFAULT_COMPILE_OPTIONS}
116+
117+
INTERFACE
118+
)
119+
120+
121+
#
122+
# Linker options
123+
#
124+
125+
target_link_libraries(${target}
126+
PRIVATE
127+
128+
PUBLIC
129+
${DEFAULT_LINKER_OPTIONS}
130+
131+
INTERFACE
132+
)
133+
134+
135+
#
136+
# Target Health
137+
#
138+
139+
perform_health_checks(
140+
${target}
141+
${sources}
142+
)

3rdparty/linenoise-ng/LICENSE

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
linenoise.cpp
2+
=============
3+
4+
Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
5+
Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
6+
7+
All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
* Redistributions of source code must retain the above copyright notice,
13+
this list of conditions and the following disclaimer.
14+
* Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
* Neither the name of Redis nor the names of its contributors may be used
18+
to endorse or promote products derived from this software without
19+
specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
POSSIBILITY OF SUCH DAMAGE.
32+
33+
34+
wcwidth.cpp
35+
===========
36+
37+
Markus Kuhn -- 2007-05-26 (Unicode 5.0)
38+
39+
Permission to use, copy, modify, and distribute this software
40+
for any purpose and without fee is hereby granted. The author
41+
disclaims all warranties with regard to this software.
42+
43+
44+
45+
ConvertUTF.cpp
46+
==============
47+
48+
Copyright 2001-2004 Unicode, Inc.
49+
50+
Disclaimer
51+
52+
This source code is provided as is by Unicode, Inc. No claims are
53+
made as to fitness for any particular purpose. No warranties of any
54+
kind are expressed or implied. The recipient agrees to determine
55+
applicability of information provided. If this file has been
56+
purchased on magnetic or optical media from Unicode, Inc., the
57+
sole remedy for any claim will be exchange of defective media
58+
within 90 days of receipt.
59+
60+
Limitations on Rights to Redistribute This Code
61+
62+
Unicode, Inc. hereby grants the right to freely use the information
63+
supplied in this file in the creation of products supporting the
64+
Unicode Standard, and to make copies of this file in any form
65+
for internal or external distribution as long as this notice
66+
remains attached.

3rdparty/linenoise-ng/README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Linenoise Next Generation
2+
3+
A small, portable GNU readline replacement for Linux, Windows and
4+
MacOS which is capable of handling UTF-8 characters. Unlike GNU
5+
readline, which is GPL, this library uses a BSD license and can be
6+
used in any kind of program.
7+
8+
## Origin
9+
10+
This linenoise implementation is based on the work by
11+
[Salvatore Sanfilippo](https://github.com/antirez/linenoise) and
12+
10gen Inc. The goal is to create a zero-config, BSD
13+
licensed, readline replacement usable in Apache2 or BSD licensed
14+
programs.
15+
16+
## Features
17+
18+
* single-line and multi-line editing mode with the usual key bindings implemented
19+
* history handling
20+
* completion
21+
* BSD license source code
22+
* Only uses a subset of VT100 escapes (ANSI.SYS compatible)
23+
* UTF8 aware
24+
* support for Linux, MacOS and Windows
25+
26+
It deviates from Salvatore's original goal to have a minimal readline
27+
replacement for the sake of supporting UTF8 and Windows. It deviates
28+
from 10gen Inc.'s goal to create a C++ interface to linenoise. This
29+
library uses C++ internally, but to the user it provides a pure C
30+
interface that is compatible with the original linenoise API.
31+
C interface.
32+
33+
## Requirements
34+
35+
To build this library, you will need a C++11-enabled compiler and
36+
some recent version of CMake.
37+
38+
## Build instructions
39+
40+
To build this library on Linux, first create a build directory
41+
42+
```bash
43+
mkdir -p build
44+
```
45+
46+
and then build the library:
47+
48+
```bash
49+
(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make)
50+
```
51+
52+
To build and install the library at the default target location, use
53+
54+
```bash
55+
(cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make && sudo make install)
56+
```
57+
58+
The default installation location can be adjusted by setting the `DESTDIR`
59+
variable when invoking `make install`:
60+
61+
```bash
62+
(cd build && make DESTDIR=/tmp install)
63+
```
64+
65+
To build the library on Windows, use these commands in an MS-DOS command
66+
prompt:
67+
68+
```
69+
md build
70+
cd build
71+
```
72+
73+
After that, invoke the appropriate command to create the files for your
74+
target environment:
75+
76+
* 32 bit: `cmake -G "Visual Studio 12 2013" -DCMAKE_BUILD_TYPE=Release ..`
77+
* 64 bit: `cmake -G "Visual Studio 12 2013 Win64" -DCMAKE_BUILD_TYPE=Release ..`
78+
79+
After that, open the generated file `linenoise.sln` from the `build`
80+
subdirectory with Visual Studio.
81+
82+
83+
*note: the following sections of the README.md are from the original
84+
linenoise repository and are partly outdated*
85+
86+
## Can a line editing library be 20k lines of code?
87+
88+
Line editing with some support for history is a really important
89+
feature for command line utilities. Instead of retyping almost the
90+
same stuff again and again it's just much better to hit the up arrow
91+
and edit on syntax errors, or in order to try a slightly different
92+
command. But apparently code dealing with terminals is some sort of
93+
Black Magic: readline is 30k lines of code, libedit 20k. Is it
94+
reasonable to link small utilities to huge libraries just to get a
95+
minimal support for line editing?
96+
97+
So what usually happens is either:
98+
99+
* Large programs with configure scripts disabling line editing if
100+
readline is not present in the system, or not supporting it at all
101+
since readline is GPL licensed and libedit (the BSD clone) is not
102+
as known and available as readline is (Real world example of this
103+
problem: Tclsh).
104+
105+
* Smaller programs not using a configure script not supporting line
106+
editing at all (A problem we had with Redis-cli for instance).
107+
108+
The result is a pollution of binaries without line editing support.
109+
110+
So Salvatore spent more or less two hours doing a reality check
111+
resulting in this little library: is it *really* needed for a line
112+
editing library to be 20k lines of code? Apparently not, it is possibe
113+
to get a very small, zero configuration, trivial to embed library,
114+
that solves the problem. Smaller programs will just include this,
115+
supporing line editing out of the box. Larger programs may use this
116+
little library or just checking with configure if readline/libedit is
117+
available and resorting to linenoise if not.
118+
119+
## Terminals, in 2010.
120+
121+
Apparently almost every terminal you can happen to use today has some
122+
kind of support for basic VT100 escape sequences. So Salvatore tried
123+
to write a lib using just very basic VT100 features. The resulting
124+
library appears to work everywhere Salvatore tried to use it, and now
125+
can work even on ANSI.SYS compatible terminals, since no VT220
126+
specific sequences are used anymore.
127+
128+
The original library has currently about 1100 lines of code. In order
129+
to use it in your project just look at the *example.c* file in the
130+
source distribution, it is trivial. Linenoise is BSD code, so you can
131+
use both in free software and commercial software.
132+
133+
## Tested with...
134+
135+
* Linux text only console ($TERM = linux)
136+
* Linux KDE terminal application ($TERM = xterm)
137+
* Linux xterm ($TERM = xterm)
138+
* Linux Buildroot ($TERM = vt100)
139+
* Mac OS X iTerm ($TERM = xterm)
140+
* Mac OS X default Terminal.app ($TERM = xterm)
141+
* OpenBSD 4.5 through an OSX Terminal.app ($TERM = screen)
142+
* IBM AIX 6.1
143+
* FreeBSD xterm ($TERM = xterm)
144+
* ANSI.SYS
145+
* Emacs comint mode ($TERM = dumb)
146+
* Windows
147+
148+
Please test it everywhere you can and report back!
149+
150+
## Let's push this forward!
151+
152+
Patches should be provided in the respect of linenoise sensibility for
153+
small and easy to understand code that and the license
154+
restrictions. Extensions must be submitted under a BSD license-style.
155+
A contributor license is required for contributions.
156+

0 commit comments

Comments
 (0)