mirror of
https://github.com/troglobit/editline.git
synced 2025-09-18 02:08:08 +08:00
Compare commits
187 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2a3575495a | ||
![]() |
8aa36184e6 | ||
![]() |
0a8f2ef420 | ||
![]() |
8078ff69cc | ||
![]() |
6db7c7d440 | ||
![]() |
e02339c3ae | ||
![]() |
f66e8cc151 | ||
![]() |
782ce4a7a9 | ||
![]() |
059d97d7a9 | ||
![]() |
edc38768ff | ||
![]() |
59a2db7217 | ||
![]() |
ba005dc0d0 | ||
![]() |
a1002f6984 | ||
![]() |
7a0c292a82 | ||
![]() |
91398ceb34 | ||
![]() |
3dbeaa0637 | ||
![]() |
2f08585884 | ||
![]() |
8a40df481b | ||
![]() |
8439f426fc | ||
![]() |
cbb5dd037e | ||
![]() |
7a9e467251 | ||
![]() |
6ad3cc1df5 | ||
![]() |
7abfadd7e6 | ||
![]() |
9fbad9dbff | ||
![]() |
474b9a6548 | ||
![]() |
9865d7fe9f | ||
![]() |
e35b8f2fd0 | ||
![]() |
c10241745c | ||
![]() |
295f901800 | ||
![]() |
a1ca0d46ac | ||
![]() |
256e288331 | ||
![]() |
9c163ff72b | ||
![]() |
6a8556733a | ||
![]() |
a2bc89db64 | ||
![]() |
256e6106c7 | ||
![]() |
426a32f771 | ||
![]() |
33ff6d5e0e | ||
![]() |
473602aa08 | ||
![]() |
bb9e5e176f | ||
![]() |
c497555bec | ||
![]() |
528581cb48 | ||
![]() |
e4b1078234 | ||
![]() |
b00453554f | ||
![]() |
98583f8d0f | ||
![]() |
01537e3bc0 | ||
![]() |
8fbc87707e | ||
![]() |
394c4f82a9 | ||
![]() |
e53ccf61f2 | ||
![]() |
cd50714e29 | ||
![]() |
7cd7fc4b61 | ||
![]() |
f7432fbfbd | ||
![]() |
9fd8e0b4d3 | ||
![]() |
26bc0716b7 | ||
![]() |
bd9c8ddda6 | ||
![]() |
85e606d093 | ||
![]() |
9cc0cc1ccd | ||
![]() |
08b7f57c98 | ||
![]() |
29b7f91165 | ||
![]() |
7330f21c28 | ||
![]() |
33ffb150f2 | ||
![]() |
4bc12834fe | ||
![]() |
c7a6ff9317 | ||
![]() |
897a98be55 | ||
![]() |
111fc5e1fb | ||
![]() |
8e81add050 | ||
![]() |
088dc1d1b2 | ||
![]() |
c59c62951f | ||
![]() |
0646b511ab | ||
![]() |
4f134f1025 | ||
![]() |
850e36f9db | ||
![]() |
d72069144e | ||
![]() |
fc08d47bce | ||
![]() |
87e69be38b | ||
![]() |
f984a48dae | ||
![]() |
d4d0c002dc | ||
![]() |
2b747467f0 | ||
![]() |
56478685d6 | ||
![]() |
916fac7cad | ||
![]() |
1c89c9886c | ||
![]() |
de6ff117bb | ||
![]() |
5e9177fd18 | ||
![]() |
27fcc878a1 | ||
![]() |
5de90af58f | ||
![]() |
0a75b182b1 | ||
![]() |
6a8ecd7e2e | ||
![]() |
bdf5384c5b | ||
![]() |
ff404e2088 | ||
![]() |
d04bdaf38f | ||
![]() |
aea0d60478 | ||
![]() |
04a0cbd902 | ||
![]() |
55aaddbc54 | ||
![]() |
dde4471eda | ||
![]() |
76ec5adba6 | ||
![]() |
80ca9e1811 | ||
![]() |
b48de203e7 | ||
![]() |
3fedfd4444 | ||
![]() |
f1edf7ae52 | ||
![]() |
2a9b087bbc | ||
![]() |
f617f84293 | ||
![]() |
bde0c0c9d6 | ||
![]() |
02acd55b2e | ||
![]() |
167059d159 | ||
![]() |
20c55a58da | ||
![]() |
0d9ce0ce06 | ||
![]() |
67e9aa3f2b | ||
![]() |
dbad0d0871 | ||
![]() |
f16cbece5a | ||
![]() |
be921400bb | ||
![]() |
83e4837f39 | ||
![]() |
a7eea67253 | ||
![]() |
8e13c7b5ae | ||
![]() |
02ea37e4de | ||
![]() |
c7b78df006 | ||
![]() |
5a8ad742d9 | ||
![]() |
522e534448 | ||
![]() |
d4aa5ac293 | ||
![]() |
a848011073 | ||
![]() |
ceb1995733 | ||
![]() |
98b846c8b1 | ||
![]() |
511a1a65a4 | ||
![]() |
64219dc1f0 | ||
![]() |
b51dad6408 | ||
![]() |
cc1fd1e9dc | ||
![]() |
536dcacb06 | ||
![]() |
009d3f0568 | ||
![]() |
60245e5e51 | ||
![]() |
576e437290 | ||
![]() |
6d2f4c99a3 | ||
![]() |
8b85bab216 | ||
![]() |
a0ec848f7b | ||
![]() |
d76ca9f1d6 | ||
![]() |
98fbc6cd41 | ||
![]() |
4c4a7e808c | ||
![]() |
7d0aff5ba3 | ||
![]() |
f874ad60ab | ||
![]() |
2d2ec7db98 | ||
![]() |
ca56b74763 | ||
![]() |
89261724d2 | ||
![]() |
885475fc49 | ||
![]() |
ad0fee03aa | ||
![]() |
da4bd00eef | ||
![]() |
3c4cf96bfc | ||
![]() |
00dd651835 | ||
![]() |
34a314c8e7 | ||
![]() |
4c9c71faae | ||
![]() |
cbf276d9ff | ||
![]() |
722dae35a2 | ||
![]() |
c52e75cb01 | ||
![]() |
e16f245672 | ||
![]() |
bc6dd1c34e | ||
![]() |
07fe826324 | ||
![]() |
9973cc2a9a | ||
![]() |
348eb97440 | ||
![]() |
e0c7e38d4e | ||
![]() |
e8fc7788aa | ||
![]() |
be016e4866 | ||
![]() |
2b8e5ef78b | ||
![]() |
87edc33897 | ||
![]() |
8ff3272698 | ||
![]() |
fc498f305b | ||
![]() |
48465835b8 | ||
![]() |
5b27b6ce4f | ||
![]() |
e828182cb0 | ||
![]() |
c1b3d17926 | ||
![]() |
69e01d11d4 | ||
![]() |
4898413730 | ||
![]() |
b1e74f3de2 | ||
![]() |
6d8d857dd4 | ||
![]() |
77d483da02 | ||
![]() |
62e900a061 | ||
![]() |
5c9f0047bb | ||
![]() |
4a3fbd9187 | ||
![]() |
05f4234310 | ||
![]() |
b935808b7d | ||
![]() |
64cc1b5325 | ||
![]() |
f7b2ea938d | ||
![]() |
9a94fc9d4d | ||
![]() |
cab8f18472 | ||
![]() |
06a7f578d5 | ||
![]() |
4f88d8d823 | ||
![]() |
c76941f24f | ||
![]() |
5ffe54c277 | ||
![]() |
afb65c0d75 | ||
![]() |
ad061041f1 | ||
![]() |
2ebc94631c | ||
![]() |
882d443045 | ||
![]() |
d661023224 |
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
*~
|
||||
*/.libs/
|
||||
*.lo
|
||||
*.o
|
||||
.deps
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
archive
|
||||
autom4te.cache
|
||||
compile
|
||||
config.guess
|
||||
config.h
|
||||
config.h.in
|
||||
config.log
|
||||
config.status
|
||||
config.sub
|
||||
configure
|
||||
depcomp
|
||||
install-sh
|
||||
libtool
|
||||
ltmain.sh
|
||||
missing
|
||||
stamp-h1
|
34
.travis.yml
Normal file
34
.travis.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
# Travis CI integration
|
||||
# Defaults to GNU GCC and autotools: ./configure && make && make test
|
||||
language: c
|
||||
|
||||
# We don't need to install packages, use dockerized build, quicker
|
||||
sudo: false
|
||||
|
||||
# Test build with both GCC and Clang (LLVM)
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
env:
|
||||
global:
|
||||
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
|
||||
# via the "travis encrypt" command using the project repo's public key
|
||||
- secure: "iFll6pD0lzVYVRUlbPBGOTB0xqoEsC0BeUdftfRQdnEssruWOEKtf3VH6gSNRu8QMPeTCNhl4fsWUJhnowZgoobi/XcsXxFv/oJQZ1sa7cQUXizeEYUmsDZxUiw/sNsWlUz6dBKPepQStYyOK/tJLQ1GfLi1ESTPt6anokMVDbk="
|
||||
|
||||
addons:
|
||||
coverity_scan:
|
||||
project:
|
||||
name: "troglobit/editline"
|
||||
description: "Minix editline"
|
||||
notification_email: troglobit@gmail.com
|
||||
build_command_prepend: "./autogen.sh && ./configure --enable-sigstop --enable-terminal-bell"
|
||||
build_command: "make -j5"
|
||||
branch_pattern: dev
|
||||
|
||||
# We don't store generated files (configure and Makefile) in GIT,
|
||||
# so we must customize the default build script to run ./autogen.sh
|
||||
script:
|
||||
- ./autogen.sh
|
||||
- ./configure --enable-sigstop --enable-terminal-bell
|
||||
- make -j5
|
177
ChangeLog.md
Normal file
177
ChangeLog.md
Normal file
@@ -0,0 +1,177 @@
|
||||
Change Log
|
||||
==========
|
||||
|
||||
All notable changes to the project are documented in this file.
|
||||
|
||||
|
||||
[1.15.2][] - 2016-06-06
|
||||
-----------------------
|
||||
|
||||
Bug fixes and minor feature creep in `pkg-config` support.
|
||||
|
||||
### Changes
|
||||
- Prevent mangling of symbols when linking with C++. Patch courtesy of
|
||||
Jakub Pawlowski
|
||||
- Add `libeditline.pc` for `pkg-config`
|
||||
|
||||
### Fixes
|
||||
- Do not assume a termcap library exists, check for `tgetent()` in
|
||||
curses, ncurses, tinfo and termcap libraries
|
||||
- Call `tty_flush()` when user calls `rl_forced_update_display()`
|
||||
to prevent screen becoming garbled. Patch by Jakub Pawlowski
|
||||
|
||||
|
||||
[1.15.1][] - 2015-11-16
|
||||
-----------------------
|
||||
|
||||
Bug fixes only.
|
||||
|
||||
### Changes
|
||||
- Update README with origin of this version of editline
|
||||
|
||||
### Fixes
|
||||
- Fix build system, don't force automake v1.11, require at least v1.11
|
||||
- Fix build problem with examples using `--enable-termcap`
|
||||
|
||||
|
||||
[1.15.0][] - 2015-09-10
|
||||
-----------------------
|
||||
|
||||
### Changes
|
||||
- Add support for `--disable-eof` and `--disable-sigint` to disable
|
||||
default Ctrl-D and Ctrl-C behavior
|
||||
- Add support for `el_no_hist` to disable access to and auto-save of history
|
||||
- GNU readline compat functions for prompt handling and redisplay
|
||||
- Refactor: replace variables named 'new' with non-reserved word
|
||||
- Add support for [Travis-CI][], continuous integration with GitHub
|
||||
- Add support for [Coverity Scan][], the best static code analyzer,
|
||||
integrated with [Travis-CI][] -- scan runs for each push to master
|
||||
- Rename NEWS.md --> ChangeLog.md, with symlinks for <kbd>make install</kbd>
|
||||
- Attempt to align with http://keepachangelog.com/ for this file
|
||||
- Cleanup and improve Markdown syntax in [README.md][]
|
||||
- Add API and example to [README.md][], inspired by [libuEv][]
|
||||
- Removed generated files from version control. Use `./autogen.sh`
|
||||
to generate the `configure` script when working from GIT. This
|
||||
does not affect distributed tarballs
|
||||
|
||||
### Fixes
|
||||
- Fix issue #2, regression in Ctrl-D (EOF) behavior. Regression
|
||||
introduced in [1.14.1][]. Fixed by @TobyGoodwin
|
||||
- Fix memory leak in completion handler. Found by [Coverity Scan][].
|
||||
- Fix suspicious use of `sizeof(char **)`, same as `sizeof(char *)` but
|
||||
non-portable. Found by [Coverity Scan][]
|
||||
- Fix out-of-bounds access in user key binding routines
|
||||
Found by [Coverity Scan][].
|
||||
- Fix invisible example code in man page
|
||||
|
||||
|
||||
[1.14.2][] - 2014-09-14
|
||||
-----------------------
|
||||
|
||||
Bug fixes only.
|
||||
|
||||
### Fixes
|
||||
- Fix `el_no_echo` bug causing secrets to leak when disabling no-echo
|
||||
- Handle `EINTR` in syscalls better
|
||||
|
||||
|
||||
[1.14.1][] - 2014-09-14
|
||||
-----------------------
|
||||
|
||||
Minor fixes and additions.
|
||||
|
||||
### Changes
|
||||
- Don't print status message on `stderr` in key binding funcions
|
||||
- Export `el_del_char()`
|
||||
- Check for and return pending signals when detected
|
||||
- Allow custom key bindings ...
|
||||
|
||||
### Fixes
|
||||
- Bug fixes ...
|
||||
|
||||
|
||||
[1.14.0][] - 2010-08-10
|
||||
-----------------------
|
||||
|
||||
Major cleanups and further merges with Debian editline package.
|
||||
|
||||
### Changes
|
||||
- Merge in changes to `debian/` from `editline_1.12-6.debian.tar.gz`
|
||||
- Migrate to use libtool
|
||||
- Make `UNIQUE_HISTORY` configurable
|
||||
- Make scrollback history (`HIST_SIZE`) configurable
|
||||
- Configure options for toggling terminal bell and `SIGSTOP` (Ctrl-Z)
|
||||
- Configure option for using termcap to read/control terminal size
|
||||
- Rename Signal to `el_intr_pending`, from Festival speech-tools
|
||||
- Merge support for capitalizing words (`M-c`) from Festival
|
||||
speech-tools by Alan W Black <mailto:awb()cstr!ed!ac!uk>
|
||||
- Fallback backspace handling, in case `tgetstr("le")` fails
|
||||
|
||||
### Fixes
|
||||
- Cleanups and fixes thanks to the Sparse static code analysis tool
|
||||
- Merge `el_no_echo` patch from Festival speech-tools
|
||||
- Merge fixes from Heimdal project
|
||||
- Completely refactor `rl_complete()` and `rl_list_possib()` with
|
||||
fixes from the Heimdal project. Use `rl_set_complete_func()` and
|
||||
`rl_set_list_possib_func()`. Default completion callbacks are now
|
||||
available as a configure option `--enable-default-complete`
|
||||
- Memory leak fixes
|
||||
- Actually fix 8-bit handling by reverting old Debian patch
|
||||
- Merge patch to improve compatibility with GNU readline, thanks to
|
||||
Steve Tell from way back in 1997 and 1998
|
||||
|
||||
|
||||
[1.13.0][] - 2010-03-09
|
||||
-----------------------
|
||||
|
||||
Adaptations to Debian editline package.
|
||||
|
||||
### Changes
|
||||
- Major version number bump, adapt to Jim Studt's v1.12
|
||||
- Import `debian/` directory and adapt it to configure et al.
|
||||
- Change library name to libeditline to distinguish it from BSD libedit
|
||||
|
||||
|
||||
[0.3.0][] - 2009-02-08
|
||||
----------------------
|
||||
|
||||
### Changes
|
||||
- Support for ANSI arrow keys using <kbd>configure --enable-arrow-keys</kbd>
|
||||
|
||||
|
||||
[0.2.3][] - 2008-12-02
|
||||
----------------------
|
||||
|
||||
### Changes
|
||||
- Patches from Debian package merged
|
||||
- Support for custom command completion
|
||||
|
||||
|
||||
[0.1.0][] - 2008-06-07
|
||||
----------------------
|
||||
|
||||
### Changes
|
||||
- First version, forked from Minix current 2008-06-06
|
||||
|
||||
|
||||
[UNRELEASED]: https://github.com/troglobit/finit/compare/1.15.1...HEAD
|
||||
[1.15.2]: https://github.com/troglobit/finit/compare/1.15.1...1.15.2
|
||||
[1.15.1]: https://github.com/troglobit/finit/compare/1.15.0...1.15.1
|
||||
[1.15.0]: https://github.com/troglobit/finit/compare/1.14.2...1.15.0
|
||||
[1.14.2]: https://github.com/troglobit/finit/compare/1.14.1...1.14.2
|
||||
[1.14.1]: https://github.com/troglobit/finit/compare/1.14.0...1.14.1
|
||||
[1.14.0]: https://github.com/troglobit/finit/compare/1.13.0...1.14.0
|
||||
[1.13.0]: https://github.com/troglobit/finit/compare/0.3.0...1.13.0
|
||||
[0.3.0]: https://github.com/troglobit/finit/compare/0.2.3...0.3.0
|
||||
[0.2.3]: https://github.com/troglobit/finit/compare/0.1.0...0.2.3
|
||||
[0.1.0]: https://github.com/troglobit/finit/compare/0.0.0...0.1.0
|
||||
[libuEv]: http://github.com/troglobit/libuev
|
||||
[Travis-CI]: https://travis-ci.org/troglobit/uftpd
|
||||
[Coverity Scan]: https://scan.coverity.com/projects/2947
|
||||
[README.md]: https://github.com/troglobit/editline/blob/master/README.md
|
||||
|
||||
<!--
|
||||
-- Local Variables:
|
||||
-- mode: markdown
|
||||
-- End:
|
||||
-->
|
46
INSTALL
Normal file
46
INSTALL
Normal file
@@ -0,0 +1,46 @@
|
||||
HowTo Build Minix Editline
|
||||
==========================
|
||||
|
||||
Minix editline use the GNU configure tools, which includes autoconf,
|
||||
automake and libtool. This enables high levels of portability and ease
|
||||
of use. In most cases all you need to do is unpack the tarball, enter
|
||||
the directory and type:
|
||||
|
||||
./configure
|
||||
|
||||
There are are, however, more options available. For instance, sometimes
|
||||
it is useful to build editline as a static library, type:
|
||||
|
||||
./configure --disable-shared
|
||||
|
||||
By default editline employs a default handler for the TAB key, pressing
|
||||
it once completes to the nearest matching filename in the current
|
||||
working directory, or it can display a listing of possible completions.
|
||||
For some uses this default is not desirable at all, type:
|
||||
|
||||
./configure --disable-default-complete
|
||||
|
||||
An even more common desire is to change the default install location.
|
||||
By default all configure scripts setup /usr/local as the install
|
||||
"prefix", to change this type:
|
||||
|
||||
./configure --prefix=/home/troglobit/tmp
|
||||
|
||||
Advanced users are encouraged to read up on --libdir, --mandir, etc. in
|
||||
the GNU Configure and Build System.
|
||||
|
||||
For more available options, type:
|
||||
|
||||
./configure --help
|
||||
|
||||
To build and install, simply type:
|
||||
|
||||
make
|
||||
|
||||
followed by
|
||||
|
||||
sudo make install
|
||||
|
||||
Good Luck!
|
||||
//Joachim
|
||||
|
17
LICENSE
Normal file
17
LICENSE
Normal file
@@ -0,0 +1,17 @@
|
||||
Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
|
||||
This software is not subject to any license of the American Telephone
|
||||
and Telegraph Company or of the Regents of the University of California.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose on
|
||||
any computer system, and to alter it and redistribute it freely, subject
|
||||
to the following restrictions:
|
||||
1. The authors are not responsible for the consequences of use of this
|
||||
software, no matter how awful, even if they arise from flaws in it.
|
||||
2. The origin of this software must not be misrepresented, either by
|
||||
explicit claim or by omission. Since few users ever read sources,
|
||||
credits must appear in the documentation.
|
||||
3. Altered versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software. Since few users
|
||||
ever read sources, credits must appear in the documentation.
|
||||
4. This notice may not be removed or altered.
|
19
Make.os9
Normal file
19
Make.os9
Normal file
@@ -0,0 +1,19 @@
|
||||
## $Revision: 1.2 $
|
||||
##
|
||||
## OS-9 makefile for editline library.
|
||||
##
|
||||
|
||||
.SUFFIXES:
|
||||
|
||||
RFILES = editline.r complete.r sysos9.r
|
||||
|
||||
%.r: %.c
|
||||
cc68 -r -Dstrchr=index -Dstrrchr=rindex -DNEED_STRDUP -DSYS_OS9 $*.c
|
||||
|
||||
testit: testit.r editline.lib
|
||||
cc68 -f=testit testit.r -l=editline.lib
|
||||
|
||||
$(RFILES): $(RFILES:%.r=%.c)
|
||||
|
||||
editline.lib: $(RFILES)
|
||||
cat $(RFILES) >$@
|
38
Makefile.am
Normal file
38
Makefile.am
Normal file
@@ -0,0 +1,38 @@
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libeditline.pc
|
||||
doc_DATA = README LICENSE CHANGELOG
|
||||
EXTRA_DIST = LICENSE CHANGELOG INSTALL
|
||||
SUBDIRS = src include man examples
|
||||
|
||||
## Generate MD5 checksum file
|
||||
MD5 = md5sum
|
||||
md5-dist:
|
||||
@for file in $(DIST_ARCHIVES); do \
|
||||
$(MD5) $$file > $$file.md5; \
|
||||
done
|
||||
|
||||
## Check if tagged in git
|
||||
release-hook:
|
||||
if [ ! `git tag | grep $(PACKAGE_VERSION)` ]; then \
|
||||
echo; \
|
||||
printf "\e[1m\e[41mCannot find release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
||||
printf "\e[1m\e[5mDo release anyway?\e[0m "; read yorn; \
|
||||
if [ "$$yorn" != "y" -a "$$yorn" != "Y" ]; then \
|
||||
printf "OK, aborting release.\n"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
echo; \
|
||||
else \
|
||||
echo; \
|
||||
printf "\e[1m\e[42mFound GIT release tag $(PACKAGE_VERSION)\e[0m\n"; \
|
||||
printf "\e[1m\e[44m>>Remember to push tags!\e[0m\n"; \
|
||||
echo; \
|
||||
fi
|
||||
|
||||
## Target to run when building a release
|
||||
release: dist release-hook md5-dist
|
||||
@for file in $(DIST_ARCHIVES); do \
|
||||
printf "$$file \tDistribution tarball\n"; \
|
||||
printf "$$file.md5\t"; cat $$file.md5 | cut -f1 -d' '; \
|
||||
mv $$file* ../; \
|
||||
done
|
44
Makefile.in
44
Makefile.in
@@ -1,44 +0,0 @@
|
||||
## $Revision: 1390 $
|
||||
##
|
||||
## Unix makefile for editline library.
|
||||
##
|
||||
|
||||
|
||||
## Set your options:
|
||||
## -DANSI_ARROWS ANSI arrows keys work like emacs.
|
||||
## -DHAVE_STDLIB Have <stdlib.h>.
|
||||
## -DHAVE_TCGETATTR Have , .
|
||||
## -DHAVE_TERMIO Have "struct termio" and <termio.h>
|
||||
## (If neither of above two, we use <sgttyb.h> and BSD ioctl's)
|
||||
## -DHIDE Make static functions static (non debug).
|
||||
## -DHIST_SIZE=n History size.
|
||||
## -DNEED_STRDUP Don't have .
|
||||
## -DUNIQUE_HISTORY Don't save command if same as last one.
|
||||
## -DUSE_DIRENT Use <dirent.h>, not <sys/dir.h>?
|
||||
## -DUSE_TERMCAP Use the termcap library for terminal size
|
||||
## see LDFLAGS, below, if you set this.
|
||||
## -DNEED_PERROR Don't have (used in testit)
|
||||
DEFS="-DANSI_ARROWS -DHAVE_STDLIB -DHAVE_TCGETATTR -DHIDE -DUSE_DIRENT \
|
||||
-DHIST_SIZE=100 -DUSE_TERMCAP -DSYS_UNIX"
|
||||
#-DNEED_STRDUP
|
||||
|
||||
CFLAGS="-O -D_MINIX -D_POSIX_SOURCE $DEFS -wo"
|
||||
#CC1 = $(CC) $(CFLAGS) -c
|
||||
|
||||
## If you have -DUSE_TERMCAP, set this as appropriate:
|
||||
#LDFLAGS = -ltermlib
|
||||
#LDFLAGS = -ltermcap
|
||||
|
||||
## End of configuration.
|
||||
|
||||
#SOURCES = editline.c complete.c sysunix.c
|
||||
#LIBRARY = ../libedit.a
|
||||
LIBRARIES=libedit
|
||||
#OBJECTS = editline.o complete.o sysunix.o
|
||||
libedit_FILES="editline.c complete.c sysunix.c"
|
||||
#SHARFILES = README Makefile editline.3 editline.h unix.h editline.c \
|
||||
|
||||
TYPE=both
|
||||
#include ../Makefile.inc
|
||||
|
||||
#$(call ADDDEPENDENCIES,$(libedit_OBJECTS),editline.h)
|
59
README
59
README
@@ -1,59 +0,0 @@
|
||||
$Revision: 5 $
|
||||
|
||||
This is a line-editing library. It can be linked into almost any
|
||||
program to provide command-line editing and recall.
|
||||
|
||||
It is call-compatible with the FSF readline library, but it is a
|
||||
fraction of the size (and offers fewer features). It does not use
|
||||
standard I/O. It is distributed under a "C News-like" copyright.
|
||||
|
||||
Configuration is done in the Makefile. Type "make testit" to get
|
||||
a small slow shell for testing.
|
||||
|
||||
An earlier version was distributed with Byron's rc. Principal
|
||||
changes over that version include:
|
||||
Faster.
|
||||
Is eight-bit clean (thanks to brendan@cs.widener.edu)
|
||||
Written in K&R C, but ANSI compliant (gcc all warnings)
|
||||
Propagates EOF properly; rc trip test now passes
|
||||
Doesn't need or use or provide memmove.
|
||||
More robust
|
||||
Calling sequence changed to be compatible with readline.
|
||||
Test program, new manpage, better configuration
|
||||
More system-independant; includes Unix and OS-9 support.
|
||||
|
||||
This contains some changes since the posting to comp.sources.misc:
|
||||
Bugfix for completion on absolute pathnames.
|
||||
Better handling of M-n versus showing raw 8bit chars.
|
||||
Better signal handling.
|
||||
Now supports termios/termio/sgttyb ioctl's.
|
||||
Add M-m command to toggle how 8bit data is displayed.
|
||||
|
||||
There is one known bug:
|
||||
History-searching redraws the line wrong if the text
|
||||
retrieved is shorter then the prompt.
|
||||
|
||||
Enjoy,
|
||||
Rich $alz
|
||||
<rsalz@osf.org>
|
||||
|
||||
Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
|
||||
This software is not subject to any license of the American Telephone
|
||||
and Telegraph Company or of the Regents of the University of California.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose on
|
||||
any computer system, and to alter it and redistribute it freely, subject
|
||||
to the following restrictions:
|
||||
1. The authors are not responsible for the consequences of use of this
|
||||
software, no matter how awful, even if they arise from flaws in it.
|
||||
2. The origin of this software must not be misrepresented, either by
|
||||
explicit claim or by omission. Since few users ever read sources,
|
||||
credits must appear in the documentation.
|
||||
3. Altered versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software. Since few users
|
||||
ever read sources, credits must appear in the documentation.
|
||||
4. This notice may not be removed or altered.
|
||||
|
||||
--
|
||||
$PchId: README,v 1.3 1996/02/22 21:18:51 philip Exp $
|
194
README.md
Normal file
194
README.md
Normal file
@@ -0,0 +1,194 @@
|
||||
Editline
|
||||
========
|
||||
[![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
|
||||
|
||||
|
||||
Table of Contents
|
||||
-----------------
|
||||
|
||||
* [Introduction](#introduction)
|
||||
* [API](#api)
|
||||
* [Example](#example)
|
||||
* [Build & Install](#build--install)
|
||||
* [Origin & References](#origin--references)
|
||||
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
This is a small [line editing][] library. It can be linked into almost
|
||||
any program to provide command line editing and history functions. It
|
||||
is call compatible with the [FSF readline][] library, but at a fraction
|
||||
of the size, and as a result fewer features. It is also distributed
|
||||
under a much more liberal [LICENSE][].
|
||||
|
||||
The small size (<30k), lack of dependencies (no ncurses needed!), and
|
||||
the free license should make this library interesting to many embedded
|
||||
developers.
|
||||
|
||||
Editline has several optional build-time features that can be enabled by
|
||||
by supplying different options to the GNU configure script. See the
|
||||
output from <kbd>configure --help</kbd> for details. In the `examples/`
|
||||
directory you can find some small code snippets used for testing.
|
||||
|
||||
Editline is maintained collaboratively at [GitHub][].
|
||||
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
Here is the interface to editline. It has a small compatibility layer
|
||||
to [FSF readline][], which may not be entirely up-to-date.
|
||||
|
||||
```C
|
||||
/* Editline specific global variables. */
|
||||
int el_no_echo; /* Do not echo input characters */
|
||||
int el_no_hist; /* Disable auto-save of and access to history,
|
||||
* e.g. for password prompts or wizards */
|
||||
int el_hist_size; /* Size of history scrollback buffer, default: 15 */
|
||||
|
||||
/* Editline specific functions. */
|
||||
char * el_find_word(void);
|
||||
void el_print_columns(int ac, char **av);
|
||||
el_status_t el_ring_bell(void);
|
||||
el_status_t el_del_char(void);
|
||||
|
||||
/* Callback function for key binding */
|
||||
typedef el_status_t el_keymap_func_t(void);
|
||||
|
||||
/* Bind key to a callback, use CTL('f') to change Ctrl-F, for example */
|
||||
el_status_t el_bind_key(int key, el_keymap_func_t function);
|
||||
el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function);
|
||||
|
||||
/* For compatibility with FSF readline. */
|
||||
int rl_point;
|
||||
int rl_mark;
|
||||
int rl_end;
|
||||
int rl_inhibit_complete;
|
||||
char *rl_line_buffer;
|
||||
const char *rl_readline_name;
|
||||
|
||||
void rl_initialize(void);
|
||||
void rl_reset_terminal(const char *terminal_name);
|
||||
|
||||
void rl_save_prompt(void);
|
||||
void rl_restore_prompt(void);
|
||||
void rl_set_prompt(const char *prompt);
|
||||
|
||||
void rl_clear_message(void);
|
||||
void rl_forced_update_display(void);
|
||||
|
||||
/* Main function to use, saves history by default */
|
||||
char *readline(const char *prompt);
|
||||
|
||||
/* Use to save a read line to history, when el_no_hist is set */
|
||||
void add_history(const char *line);
|
||||
|
||||
/* Load and save editline history from/to a file. */
|
||||
int read_history(const char *filename);
|
||||
int write_history(const char *filename);
|
||||
|
||||
/* Magic completion API, see examples/cli.c for more info */
|
||||
rl_complete_func_t *rl_set_complete_func(rl_complete_func_t *func);
|
||||
rl_list_possib_func_t *rl_set_list_possib_func(rl_list_possib_func_t *func);
|
||||
```
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
Here is a very brief example to illustrate how one can use Editline to
|
||||
create a simple CLI. More examples are availble in the source tree.
|
||||
|
||||
```C
|
||||
#include <stdlib.h>
|
||||
|
||||
extern char *readline(char *prompt);
|
||||
|
||||
int main (void)
|
||||
{
|
||||
char *p;
|
||||
|
||||
while ((p = readline("CLI> ")) != NULL) {
|
||||
puts(p);
|
||||
free(p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Build & Install
|
||||
---------------
|
||||
|
||||
Editline was originally designed for older UNIX systems and Plan 9. The
|
||||
current maintainer works exclusively on GNU/Linux systems, so it may use
|
||||
GCC and GNU Make specific extensions here and there. This is not on
|
||||
purpose and patches or pull requests to correct this are most welcome!
|
||||
|
||||
1. Configure editline with default features: <kbd>./configure</kbd>
|
||||
2. Build the library and examples: <kbd>make all</kbd>
|
||||
3. Install using <kbd>make install</kbd>
|
||||
|
||||
The `$DESTDIR` environment variable is honored at install. See
|
||||
<kbd>./configure --help</kbd> for more options.
|
||||
|
||||
Origin & References
|
||||
--------------------
|
||||
|
||||
This [line editing][] library was created by Simmule Turner and
|
||||
[Rich Salz][upstream] in in 1992. It is distributed under a “C
|
||||
News-like” license, similar to the [BSD license][]. Rich's latest
|
||||
version is however under the Apache license. For details on the
|
||||
licensing terms of this version of the software, see [LICENSE][].
|
||||
|
||||
This version of the editline library was forked from the [Minix 3][]
|
||||
source tree and is *not* related to the similarily named NetBSD version
|
||||
that [Jess Thrysøe][jess] disitributes to the world outside BSD. The
|
||||
libraries have much in common, but the latter is heavily refactored and
|
||||
also relies on libtermcap (usually supplied by ncurses), whereas this
|
||||
library only uses termios from the standard C library.
|
||||
|
||||
Patches and bug fixes from the following forks, all based on the
|
||||
original comp.sources.unix posting, have been merged:
|
||||
|
||||
* Debian [libeditline][]
|
||||
* [Heimdal][]
|
||||
* [Festival][] speech-tools
|
||||
* [Steve Tell][]'s editline patches
|
||||
|
||||
The version numbering scheme today follows that of the Debian version,
|
||||
which can be seen in the [ChangeLog.md][]. The Debian version was
|
||||
unknown to the current [maintainer][] for quite some time, so a
|
||||
different name and different versioning scheme was used. In June 2009
|
||||
this was changed to line up alongside Debian, with the intent is to
|
||||
eventually merge the efforts.
|
||||
|
||||
Outstanding issues are listed in the [TODO.md][] file.
|
||||
|
||||
[GitHub]: https://github.com/troglobit/editline
|
||||
[line editing]: https://github.com/troglobit/editline/blob/master/doc/README
|
||||
[maintainer]: http://troglobit.com
|
||||
[LICENSE]: https://github.com/troglobit/editline/blob/master/LICENSE
|
||||
[TODO.md]: https://github.com/troglobit/editline/blob/master/TODO.md
|
||||
[ChangeLog.md]: https://github.com/troglobit/editline/blob/master/ChangeLog.md
|
||||
[FSF readline]: http://www.gnu.org/software/readline/
|
||||
[upstream]: https://github.com/richsalz/editline/
|
||||
[Minix 3]: http://www.cise.ufl.edu/~cop4600/cgi-bin/lxr/http/source.cgi/lib/editline/
|
||||
[jess]: http://thrysoee.dk/editline/
|
||||
[BSD license]: http://en.wikipedia.org/wiki/BSD_licenses
|
||||
[libeditline]: http://packages.qa.debian.org/e/editline.html
|
||||
[Heimdal]: http://www.h5l.org
|
||||
[Festival]: http://festvox.org/festival/
|
||||
[Steve Tell]: http://www.cs.unc.edu/~tell/dist.html
|
||||
[Travis]: https://travis-ci.org/troglobit/editline
|
||||
[Travis Status]: https://travis-ci.org/troglobit/editline.png?branch=master
|
||||
[Coverity Scan]: https://scan.coverity.com/projects/2982
|
||||
[Coverity Status]: https://scan.coverity.com/projects/2982/badge.svg
|
||||
|
||||
<!--
|
||||
-- Local Variables:
|
||||
-- mode: markdown
|
||||
-- End:
|
||||
-->
|
49
TODO.md
Normal file
49
TODO.md
Normal file
@@ -0,0 +1,49 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
Issues in need of work. Mostly compatibility with GNU readline, BSD
|
||||
[libedit], and usability improvements.
|
||||
|
||||
Remember, the general idea is to keep this library editline small with
|
||||
no external dependencies, except a C library.
|
||||
|
||||
|
||||
Verify custom completion handlers
|
||||
---------------------------------
|
||||
|
||||
Verify for v1.14.0 that custom completion handlers still work After
|
||||
reverting a "fix" in v0.2.2 that made `rl_complete()` a function pointer
|
||||
we need to make sure the same functionality is still available with the
|
||||
new infrastructure. Which is more inspired by BSD libedit and GNU
|
||||
readline.
|
||||
|
||||
|
||||
Check what's needed to run the fileman example
|
||||
----------------------------------------------
|
||||
|
||||
The BSD libedit library has imported the GNU readline "fileman" example
|
||||
into its tree to demonstrate the abilities of that library. This would
|
||||
also be quite useful for this library!
|
||||
|
||||
The first task is to investigate the depependencies and form TODO list
|
||||
items detailing what is missing and, if possible, proposals how to
|
||||
implement including any optional configure flags.
|
||||
|
||||
|
||||
Other minor TODO's
|
||||
------------------
|
||||
|
||||
- Instead of supporting multiline input, try the Emacs approach, line
|
||||
scrolling.
|
||||
- Add support for `rl_bind_key()`, currently only en editline specific
|
||||
`el_bind_key()` exists.
|
||||
- Make `char *rl_prompt;` globally visible.
|
||||
- Add support for `rl_set_prompt()`
|
||||
- Add support for `--enable-utf8` to configure script
|
||||
- Use `strcmp(nl_langinfo(CODESET), "UTF-8")` to look for utf8 capable
|
||||
terminal
|
||||
- Implement simple UTF-8 parser according to
|
||||
http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
|
||||
|
||||
[libedit]: http://www.thrysoee.dk/editline/
|
3
autogen.sh
Executable file
3
autogen.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
autoreconf -W portability -visfm
|
254
complete.c
254
complete.c
@@ -1,254 +0,0 @@
|
||||
/* $Revision: 5 $
|
||||
**
|
||||
** History and file completion functions for editline library.
|
||||
*/
|
||||
#include "editline.h"
|
||||
|
||||
|
||||
#if defined(NEED_STRDUP)
|
||||
/*
|
||||
** Return an allocated copy of a string.
|
||||
*/
|
||||
char *
|
||||
strdup(p)
|
||||
char *p;
|
||||
{
|
||||
char *new;
|
||||
|
||||
if ((new = NEW(char, strlen(p) + 1)) != NULL)
|
||||
(void)strcpy(new, p);
|
||||
return new;
|
||||
}
|
||||
#endif /* defined(NEED_STRDUP) */
|
||||
|
||||
/*
|
||||
** strcmp-like sorting predicate for qsort.
|
||||
*/
|
||||
STATIC int
|
||||
compare(p1, p2)
|
||||
CONST void *p1;
|
||||
CONST void *p2;
|
||||
{
|
||||
CONST char **v1;
|
||||
CONST char **v2;
|
||||
|
||||
v1 = (CONST char **)p1;
|
||||
v2 = (CONST char **)p2;
|
||||
return strcmp(*v1, *v2);
|
||||
}
|
||||
|
||||
/*
|
||||
** Fill in *avp with an array of names that match file, up to its length.
|
||||
** Ignore . and .. .
|
||||
*/
|
||||
STATIC int
|
||||
FindMatches(dir, file, avp)
|
||||
char *dir;
|
||||
char *file;
|
||||
char ***avp;
|
||||
{
|
||||
char **av;
|
||||
char **new;
|
||||
char *p;
|
||||
DIR *dp;
|
||||
DIRENTRY *ep;
|
||||
SIZE_T ac;
|
||||
SIZE_T len;
|
||||
SIZE_T choices;
|
||||
SIZE_T total;
|
||||
#define MAX_TOTAL (256 << sizeof(char *))
|
||||
|
||||
if ((dp = opendir(dir)) == NULL)
|
||||
return 0;
|
||||
|
||||
av = NULL;
|
||||
ac = 0;
|
||||
len = strlen(file);
|
||||
choices = 0;
|
||||
total = 0;
|
||||
while ((ep = readdir(dp)) != NULL) {
|
||||
p = ep->d_name;
|
||||
if (p[0] == '.' && (p[1] == '\0' || (p[1] == '.' && p[2] == '\0')))
|
||||
continue;
|
||||
if (len && strncmp(p, file, len) != 0)
|
||||
continue;
|
||||
|
||||
choices++;
|
||||
if ((total += strlen(p)) > MAX_TOTAL) {
|
||||
/* This is a bit too much. */
|
||||
while (ac > 0) DISPOSE(av[--ac]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ac % MEM_INC) == 0) {
|
||||
if ((new = NEW(char*, ac + MEM_INC)) == NULL) {
|
||||
total = 0;
|
||||
break;
|
||||
}
|
||||
if (ac) {
|
||||
COPYFROMTO(new, av, ac * sizeof (char **));
|
||||
DISPOSE(av);
|
||||
}
|
||||
*avp = av = new;
|
||||
}
|
||||
|
||||
if ((av[ac] = strdup(p)) == NULL) {
|
||||
if (ac == 0)
|
||||
DISPOSE(av);
|
||||
total = 0;
|
||||
break;
|
||||
}
|
||||
ac++;
|
||||
}
|
||||
|
||||
/* Clean up and return. */
|
||||
(void)closedir(dp);
|
||||
if (total > MAX_TOTAL) {
|
||||
char many[sizeof(total) * 3];
|
||||
p = many + sizeof(many);
|
||||
*--p = '\0';
|
||||
while (choices > 0) {
|
||||
*--p = '0' + choices % 10;
|
||||
choices /= 10;
|
||||
}
|
||||
while (p > many + sizeof(many) - 8) *--p = ' ';
|
||||
if ((p = strdup(p)) != NULL) av[ac++] = p;
|
||||
if ((p = strdup("choices")) != NULL) av[ac++] = p;
|
||||
} else {
|
||||
if (ac)
|
||||
qsort(av, ac, sizeof (char **), compare);
|
||||
}
|
||||
return ac;
|
||||
}
|
||||
|
||||
/*
|
||||
** Split a pathname into allocated directory and trailing filename parts.
|
||||
*/
|
||||
STATIC int
|
||||
SplitPath(path, dirpart, filepart)
|
||||
char *path;
|
||||
char **dirpart;
|
||||
char **filepart;
|
||||
{
|
||||
static char DOT[] = ".";
|
||||
char *dpart;
|
||||
char *fpart;
|
||||
|
||||
if ((fpart = strrchr(path, '/')) == NULL) {
|
||||
if ((dpart = strdup(DOT)) == NULL)
|
||||
return -1;
|
||||
if ((fpart = strdup(path)) == NULL) {
|
||||
DISPOSE(dpart);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ((dpart = strdup(path)) == NULL)
|
||||
return -1;
|
||||
dpart[fpart - path + 1] = '\0';
|
||||
if ((fpart = strdup(++fpart)) == NULL) {
|
||||
DISPOSE(dpart);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*dirpart = dpart;
|
||||
*filepart = fpart;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to complete the pathname, returning an allocated copy.
|
||||
** Fill in *unique if we completed it, or set it to 0 if ambiguous.
|
||||
*/
|
||||
char *
|
||||
rl_complete(pathname, unique)
|
||||
char *pathname;
|
||||
int *unique;
|
||||
{
|
||||
char **av;
|
||||
char *dir;
|
||||
char *file;
|
||||
char *new;
|
||||
char *p;
|
||||
SIZE_T ac;
|
||||
SIZE_T end;
|
||||
SIZE_T i;
|
||||
SIZE_T j;
|
||||
SIZE_T len;
|
||||
|
||||
if (SplitPath(pathname, &dir, &file) < 0)
|
||||
return NULL;
|
||||
if ((ac = FindMatches(dir, file, &av)) == 0) {
|
||||
DISPOSE(dir);
|
||||
DISPOSE(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = NULL;
|
||||
len = strlen(file);
|
||||
if (ac == 1) {
|
||||
/* Exactly one match -- finish it off. */
|
||||
*unique = 1;
|
||||
j = strlen(av[0]) - len + 2;
|
||||
if ((p = NEW(char, j + 1)) != NULL) {
|
||||
COPYFROMTO(p, av[0] + len, j);
|
||||
if ((new = NEW(char, strlen(dir) + strlen(av[0]) + 2)) != NULL) {
|
||||
(void)strcpy(new, dir);
|
||||
(void)strcat(new, "/");
|
||||
(void)strcat(new, av[0]);
|
||||
rl_add_slash(new, p);
|
||||
DISPOSE(new);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
*unique = 0;
|
||||
if (len) {
|
||||
/* Find largest matching substring. */
|
||||
for (i = len, end = strlen(av[0]); i < end; i++)
|
||||
for (j = 1; j < ac; j++)
|
||||
if (av[0][i] != av[j][i])
|
||||
goto breakout;
|
||||
breakout:
|
||||
if (i > len) {
|
||||
j = i - len + 1;
|
||||
if ((p = NEW(char, j)) != NULL) {
|
||||
COPYFROMTO(p, av[0] + len, j);
|
||||
p[j - 1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up and return. */
|
||||
DISPOSE(dir);
|
||||
DISPOSE(file);
|
||||
for (i = 0; i < ac; i++)
|
||||
DISPOSE(av[i]);
|
||||
DISPOSE(av);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return all possible completions.
|
||||
*/
|
||||
int
|
||||
rl_list_possib(pathname, avp)
|
||||
char *pathname;
|
||||
char ***avp;
|
||||
{
|
||||
char *dir;
|
||||
char *file;
|
||||
int ac;
|
||||
|
||||
if (SplitPath(pathname, &dir, &file) < 0)
|
||||
return 0;
|
||||
ac = FindMatches(dir, file, avp);
|
||||
DISPOSE(dir);
|
||||
DISPOSE(file);
|
||||
return ac;
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: complete.c,v 1.3 1996/02/22 21:18:51 philip Exp $
|
||||
*/
|
82
configure.ac
Normal file
82
configure.ac
Normal file
@@ -0,0 +1,82 @@
|
||||
AC_INIT(editline, 1.15.2, https://github.com/troglobit/editline/issues)
|
||||
AM_INIT_AUTOMAKE([1.11 foreign no-dist-gzip dist-xz])
|
||||
AM_SILENT_RULES([yes])
|
||||
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_CONFIG_SRCDIR([src/editline.c])
|
||||
AC_CONFIG_HEADER([config.h])
|
||||
AC_CONFIG_FILES([Makefile libeditline.pc src/Makefile include/Makefile man/Makefile examples/Makefile])
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
|
||||
# Checks for libraries.
|
||||
LT_INIT
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_DIRENT
|
||||
AC_HEADER_STAT
|
||||
AC_HEADER_STDC
|
||||
# Check for malloc.h instead of AC_FUNC_MALLOC/REALLOC AIX and others
|
||||
# mess up the traditional malloc check.
|
||||
AC_CHECK_HEADERS([malloc.h signal.h stdlib.h string.h termcap.h termio.h termios.h sgtty.h])
|
||||
|
||||
# In termios.h or in sys/ioctl.g?
|
||||
AC_HEADER_TIOCGWINSZ
|
||||
|
||||
# Overrides and types, should be a check.
|
||||
AC_DEFINE([SYS_UNIX], [1], [Default to UNIX backend, should be detected.])
|
||||
AC_TYPE_SIZE_T
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_CLOSEDIR_VOID
|
||||
AC_PROG_GCC_TRADITIONAL
|
||||
AC_FUNC_STAT
|
||||
AC_CHECK_FUNCS([strchr strdup strrchr tcgetattr perror])
|
||||
|
||||
AC_ARG_ENABLE(unique-history,
|
||||
[AS_HELP_STRING([--disable-unique-history],
|
||||
[Disable uniqify of scrollback. Default: duplicate entries are ignored. Use this to save dupes.])],
|
||||
, AC_DEFINE(CONFIG_UNIQUE_HISTORY, 1, [Define to skip duplicate lines in the scrollback history.]))
|
||||
|
||||
AC_ARG_ENABLE(default-complete,
|
||||
[AS_HELP_STRING([--disable-default-complete], [Disable default (filename) completion handler.])],
|
||||
, AC_DEFINE(CONFIG_DEFAULT_COMPLETE, 1, [Define to enable the default completion handler.]))
|
||||
|
||||
AC_ARG_ENABLE(arrow-keys,
|
||||
[AS_HELP_STRING([--disable-arrow-keys], [Disable ANSI arrow keys.])],
|
||||
, AC_DEFINE(CONFIG_ANSI_ARROWS, 1, [Define to include ANSI arrow keys support.]))
|
||||
|
||||
AC_ARG_ENABLE(eof,
|
||||
[AS_HELP_STRING([--disable-eof], [Disable default EOF (Ctrl-D) behavior.])],
|
||||
, AC_DEFINE([CONFIG_EOF], 1, [Define to enable EOF (Ctrl-C) key.]))
|
||||
|
||||
AC_ARG_ENABLE(sigint,
|
||||
[AS_HELP_STRING([--disable-sigint], [Disable default SIGINT (Ctrl-C) behavior.])],
|
||||
, AC_DEFINE([CONFIG_SIGINT], 1, [Define to enable SIGINT (Ctrl-C) key.]))
|
||||
|
||||
AC_ARG_ENABLE(sigstop,
|
||||
[AS_HELP_STRING([--enable-sigstop], [Enable SIGSTOP (Ctrl-Z) behavior.])],
|
||||
AC_DEFINE([CONFIG_SIGSTOP], 1, [Define to enable SIGSTOP (Ctrl-Z) key.]))
|
||||
|
||||
AC_ARG_ENABLE(terminal-bell,
|
||||
[AS_HELP_STRING([--enable-terminal-bell], [Enable terminal bell on completion.])],
|
||||
AC_DEFINE([CONFIG_TERMINAL_BELL], 1, [Define to enable terminal bell on completion.]))
|
||||
|
||||
AC_ARG_ENABLE(termcap,
|
||||
[AS_HELP_STRING([--enable-termcap], [Use termcap library to query terminal size.])],
|
||||
AC_DEFINE([CONFIG_USE_TERMCAP], 1, [Define to use the termcap library for terminal size.]))
|
||||
|
||||
# Check for a termcap compatible library if enabled
|
||||
AS_IF([test "$enable_termcap" != no],
|
||||
AC_CHECK_LIB(termcap, tgetent, , [
|
||||
AC_CHECK_LIB(tinfo, tgetent, , [
|
||||
AC_CHECK_LIB(curses, tgetent, , [
|
||||
AC_CHECK_LIB(ncurses, tgetent, , [
|
||||
AC_MSG_ERROR([Cannot find a termcap capable library, try installing Ncurses.])])
|
||||
])
|
||||
])
|
||||
]))
|
||||
|
||||
AC_OUTPUT
|
9
debian/README.Debian
vendored
Normal file
9
debian/README.Debian
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
editline for Debian
|
||||
----------------------
|
||||
|
||||
This is packaged in typical Debian form with a shared library version and
|
||||
a static library version. It will be a rare package that wishes to
|
||||
use the shared library form, the static one is only adds about 12.5kb
|
||||
to your program.
|
||||
|
||||
-- Jim Studt <jim@federated.com>, Fri, 5 May 2000 13:25:51 -0500
|
81
debian/changelog
vendored
Normal file
81
debian/changelog
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
editline (1.14.2-1) unstable; urgency=low
|
||||
|
||||
* Minor bugfix release:
|
||||
+ Fix `el_no_echo` bug causing secrets to leak when disabling no-echo
|
||||
+ Handle `EINTR` in syscalls better
|
||||
|
||||
-- Joachim Nilsson <troglobit@gmail.com> Sun, 14 Sep 2014 04:27:25 +0200
|
||||
|
||||
editline (1.14.1-1) unstable; urgency=low
|
||||
|
||||
* New release.
|
||||
+ Minor fixes to key binding.
|
||||
+ Check signals and custom keys before acting on them in readline().
|
||||
+ Update maintainer email address.
|
||||
|
||||
-- Joachim Nilsson <troglobit@gmail.com> Mon, 8 Jul 2013 17:04:00 +0100
|
||||
|
||||
editline (1.14.0-1) unstable; urgency=low
|
||||
|
||||
* Update to new configure based build.
|
||||
|
||||
-- Joachim Nilsson <joachim.nilsson@vmlinux.org> Wed, 11 Aug 2010 13:28:00 +0100
|
||||
|
||||
editline (1.12-6) unstable; urgency=low
|
||||
|
||||
* Switch package format to 3.0 (quilt).
|
||||
* 200_fix-truncation-at-64-char.diff: fix invalid 64-char truncation in
|
||||
batch mode, courtesy of Mark O'Donohue. Thanks to Damyan Ivanov for
|
||||
forwarding the patch from Ubuntu (Closes: #508640).
|
||||
|
||||
-- Sam Hocevar <sho@debian.org> Sun, 03 Jan 2010 15:45:34 +0100
|
||||
|
||||
editline (1.12-5) unstable; urgency=low
|
||||
|
||||
* New maintainer (Closes: #229962).
|
||||
* debian/changelog:
|
||||
+ Removed emacs helper variables.
|
||||
* debian/control:
|
||||
+ Set policy to 3.6.1.0.
|
||||
+ Set debhelper build dependency to (>= 4.0).
|
||||
+ Use the default dh_shlibs information, since the API is rock stable
|
||||
(Closes: #131139).
|
||||
+ Removed the libc6-dev dependency in the -dev package.
|
||||
+ Rephrased the short and long descriptions.
|
||||
* debian/copyright:
|
||||
+ Replaced "Author(s)" with "Author".
|
||||
* debian/rules:
|
||||
+ Removed obsolete call to dh_suidregister.
|
||||
+ Use debian/compat instead of DH_COMPAT.
|
||||
* include_editline.h:
|
||||
+ Added a minimalist /usr/include/editline.h (Closes: #129544).
|
||||
* Makefile:
|
||||
+ Call libtool with the proper --mode flags.
|
||||
|
||||
-- Sam Hocevar (Debian packages) <sam+deb@zoy.org> Sat, 31 Jan 2004 22:32:35 +0100
|
||||
|
||||
editline (1.12-4) unstable; urgency=low
|
||||
|
||||
* Add a Build-Depends for debhelper and libtool. Thought those
|
||||
were baseline. closes: #117780
|
||||
|
||||
-- Jim Studt <jim@federated.com> Thu, 15 Nov 2001 19:00:00 -0600
|
||||
|
||||
editline (1.12-3) unstable; urgency=low
|
||||
|
||||
* Make man pages not be in the shared library package.
|
||||
|
||||
-- Jim Studt <jim@federated.com> Sat, 13 Jan 2001 00:03:53 -0600
|
||||
|
||||
editline (1.12-2) unstable; urgency=low
|
||||
|
||||
* Patch to not declare read() and write(), it fails on alphas.
|
||||
|
||||
-- Jim Studt <jim@federated.com> Tue, 12 Sep 2000 16:39:34 -0500
|
||||
|
||||
editline (1.12-1) unstable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
-- Jim Studt <jim@federated.com> Fri, 5 May 2000 13:25:51 -0500
|
||||
|
1
debian/compat
vendored
Normal file
1
debian/compat
vendored
Normal file
@@ -0,0 +1 @@
|
||||
5
|
31
debian/control
vendored
Normal file
31
debian/control
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
Source: editline
|
||||
Section: devel
|
||||
Priority: optional
|
||||
Build-Depends: debhelper (>= 5.0), libtool
|
||||
Maintainer: Sam Hocevar <sho@debian.org>
|
||||
Standards-Version: 3.8.3
|
||||
|
||||
Package: libeditline-dev
|
||||
Architecture: any
|
||||
Section: libdevel
|
||||
Depends: libeditline0 (= ${binary:Version}), ${misc:Depends}
|
||||
Description: development files for libeditline
|
||||
This is a line-editing library. It can be linked into almost any program
|
||||
to provide command-line editing and recall. It is call-compatible with a
|
||||
subset of the FSF readline library, but it is a fraction of the size (and
|
||||
offers fewer features).
|
||||
.
|
||||
This package contains the developer files: static libraries, headers,
|
||||
manpages.
|
||||
|
||||
Package: libeditline0
|
||||
Architecture: any
|
||||
Section: libs
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: line editing library similar to readline
|
||||
This is a line-editing library. It can be linked into almost any program
|
||||
to provide command-line editing and recall. It is call-compatible with a
|
||||
subset of the FSF readline library, but it is a fraction of the size (and
|
||||
offers fewer features).
|
||||
.
|
||||
This package contains the runtime library only.
|
27
debian/copyright
vendored
Normal file
27
debian/copyright
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
This package was debianized by Jim Studt <jim@federated.com> on
|
||||
Fri, 5 May 2000 13:25:51 -0500.
|
||||
|
||||
It was received from Rich Salz rsalz@shore.net
|
||||
|
||||
Upstream Author: Rich Salz rsalz@shore.net
|
||||
|
||||
Copyright:
|
||||
|
||||
Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
|
||||
This software is not subject to any license of the American Telephone
|
||||
and Telegraph Company or of the Regents of the University of California.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose on
|
||||
any computer system, and to alter it and redistribute it freely, subject
|
||||
to the following restrictions:
|
||||
1. The authors are not responsible for the consequences of use of this
|
||||
software, no matter how awful, even if they arise from flaws in it.
|
||||
2. The origin of this software must not be misrepresented, either by
|
||||
explicit claim or by omission. Since few users ever read sources,
|
||||
credits must appear in the documentation.
|
||||
3. Altered versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software. Since few users
|
||||
ever read sources, credits must appear in the documentation.
|
||||
4. This notice may not be removed or altered.
|
||||
|
2
debian/dirs
vendored
Normal file
2
debian/dirs
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
usr/lib
|
||||
usr/include
|
1
debian/docs
vendored
Normal file
1
debian/docs
vendored
Normal file
@@ -0,0 +1 @@
|
||||
README
|
4
debian/libeditline-dev.install
vendored
Normal file
4
debian/libeditline-dev.install
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
usr/include
|
||||
usr/lib/libeditline*.*a
|
||||
usr/lib/libeditline*.so
|
||||
usr/share/man/man3
|
1
debian/libeditline0.install
vendored
Normal file
1
debian/libeditline0.install
vendored
Normal file
@@ -0,0 +1 @@
|
||||
usr/lib/libeditline*.so.*
|
59
debian/rules
vendored
Executable file
59
debian/rules
vendored
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/make -f
|
||||
# debian/rules for libeditline
|
||||
# GNU copyright 1997 to 1999 by Joey Hess.
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
# shared library versions, option 1
|
||||
version=0.0.0
|
||||
major=0
|
||||
|
||||
configure: configure-stamp
|
||||
configure-stamp:
|
||||
dh_testdir
|
||||
dh_auto_configure
|
||||
touch configure-stamp
|
||||
|
||||
build: build-stamp
|
||||
build-stamp:
|
||||
dh_testdir
|
||||
dh_auto_configure
|
||||
dh_auto_build
|
||||
touch $@
|
||||
|
||||
clean:
|
||||
dh_testdir
|
||||
dh_auto_clean
|
||||
dh_clean
|
||||
@rm -f build-stamp configure-stamp
|
||||
|
||||
install: build
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
dh_auto_install
|
||||
|
||||
binary-indep: install
|
||||
|
||||
# build libeditline${major} package by moving files from editline-dev
|
||||
binary-arch: install
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_auto_install
|
||||
dh_install --sourcedir=debian/tmp
|
||||
dh_installdocs
|
||||
dh_installchangelogs
|
||||
dh_strip
|
||||
dh_compress
|
||||
dh_fixperms
|
||||
dh_makeshlibs
|
||||
dh_installdeb
|
||||
dh_shlibdeps
|
||||
dh_gencontrol
|
||||
dh_md5sums
|
||||
dh_builddeb
|
||||
|
||||
binary: binary-indep binary-arch
|
||||
.PHONY: build clean binary-indep binary-arch binary install
|
68
doc/README
Executable file
68
doc/README
Executable file
@@ -0,0 +1,68 @@
|
||||
Original Minix README
|
||||
=====================
|
||||
|
||||
Below is the original Minix editline README file. It has been
|
||||
split into a modified README and LICENSE file.
|
||||
|
||||
-- Joachim Nilsson, June 7th 2008
|
||||
|
||||
-----------------------------------------------------------------
|
||||
$Revision: 5 $
|
||||
|
||||
This is a line-editing library. It can be linked into almost any
|
||||
program to provide command-line editing and recall.
|
||||
|
||||
It is call-compatible with the FSF readline library, but it is a
|
||||
fraction of the size (and offers fewer features). It does not use
|
||||
standard I/O. It is distributed under a "C News-like" copyright.
|
||||
|
||||
Configuration is done in the Makefile. Type "make testit" to get
|
||||
a small slow shell for testing.
|
||||
|
||||
An earlier version was distributed with Byron's rc. Principal
|
||||
changes over that version include:
|
||||
Faster.
|
||||
Is eight-bit clean (thanks to brendan()cs!widener!edu)
|
||||
Written in K&R C, but ANSI compliant (gcc all warnings)
|
||||
Propagates EOF properly; rc trip test now passes
|
||||
Doesn't need or use or provide memmove.
|
||||
More robust
|
||||
Calling sequence changed to be compatible with readline.
|
||||
Test program, new manpage, better configuration
|
||||
More system-independant; includes Unix and OS-9 support.
|
||||
|
||||
This contains some changes since the posting to comp.sources.misc:
|
||||
Bugfix for completion on absolute pathnames.
|
||||
Better handling of M-n versus showing raw 8bit chars.
|
||||
Better signal handling.
|
||||
Now supports termios/termio/sgttyb ioctl's.
|
||||
Add M-m command to toggle how 8bit data is displayed.
|
||||
|
||||
There is one known bug:
|
||||
History-searching redraws the line wrong if the text
|
||||
retrieved is shorter then the prompt.
|
||||
|
||||
Enjoy,
|
||||
Rich $alz
|
||||
<rsalz()osf!org>
|
||||
|
||||
Copyright 1992,1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
|
||||
This software is not subject to any license of the American Telephone
|
||||
and Telegraph Company or of the Regents of the University of California.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose on
|
||||
any computer system, and to alter it and redistribute it freely, subject
|
||||
to the following restrictions:
|
||||
1. The authors are not responsible for the consequences of use of this
|
||||
software, no matter how awful, even if they arise from flaws in it.
|
||||
2. The origin of this software must not be misrepresented, either by
|
||||
explicit claim or by omission. Since few users ever read sources,
|
||||
credits must appear in the documentation.
|
||||
3. Altered versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software. Since few users
|
||||
ever read sources, credits must appear in the documentation.
|
||||
4. This notice may not be removed or altered.
|
||||
|
||||
--
|
||||
$PchId: README,v 1.3 1996/02/22 21:18:51 philip Exp $
|
1471
editline.c
1471
editline.c
File diff suppressed because it is too large
Load Diff
79
editline.h
79
editline.h
@@ -1,79 +0,0 @@
|
||||
/* $Revision: 5 $
|
||||
**
|
||||
** Internal header file for editline library.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#if defined(HAVE_STDLIB)
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#endif /* defined(HAVE_STDLIB) */
|
||||
#if defined(SYS_UNIX)
|
||||
#include "unix.h"
|
||||
#endif /* defined(SYS_UNIX) */
|
||||
#if defined(SYS_OS9)
|
||||
#include "os9.h"
|
||||
#endif /* defined(SYS_OS9) */
|
||||
|
||||
#if !defined(SIZE_T)
|
||||
#define SIZE_T unsigned int
|
||||
#endif /* !defined(SIZE_T) */
|
||||
|
||||
typedef unsigned char CHAR;
|
||||
|
||||
#if defined(HIDE)
|
||||
#define STATIC static
|
||||
#else
|
||||
#define STATIC /* NULL */
|
||||
#endif /* !defined(HIDE) */
|
||||
|
||||
#if !defined(CONST)
|
||||
#if defined(__STDC__)
|
||||
#define CONST const
|
||||
#else
|
||||
#define CONST
|
||||
#endif /* defined(__STDC__) */
|
||||
#endif /* !defined(CONST) */
|
||||
|
||||
|
||||
#define MEM_INC 64
|
||||
#define SCREEN_INC 256
|
||||
|
||||
#define DISPOSE(p) free((char *)(p))
|
||||
#define NEW(T, c) \
|
||||
((T *)malloc((unsigned int)(sizeof (T) * (c))))
|
||||
#define RENEW(p, T, c) \
|
||||
(p = (T *)realloc((char *)(p), (unsigned int)(sizeof (T) * (c))))
|
||||
#define COPYFROMTO(new, p, len) \
|
||||
(void)memcpy((char *)(new), (char *)(p), (int)(len))
|
||||
|
||||
|
||||
/*
|
||||
** Variables and routines internal to this package.
|
||||
*/
|
||||
extern int rl_eof;
|
||||
extern int rl_erase;
|
||||
extern int rl_intr;
|
||||
extern int rl_kill;
|
||||
extern int rl_quit;
|
||||
extern char *rl_complete();
|
||||
extern int rl_list_possib();
|
||||
extern void rl_ttyset();
|
||||
extern void rl_add_slash();
|
||||
|
||||
#if !defined(HAVE_STDLIB)
|
||||
extern char *getenv();
|
||||
extern char *malloc();
|
||||
extern char *realloc();
|
||||
extern char *memcpy();
|
||||
extern char *strcat();
|
||||
extern char *strchr();
|
||||
extern char *strrchr();
|
||||
extern char *strcpy();
|
||||
extern int strcmp();
|
||||
extern int strlen();
|
||||
extern int strncmp();
|
||||
#endif /* !defined(HAVE_STDLIB) */
|
||||
|
||||
#if defined(NEED_STRDUP)
|
||||
extern char *strdup();
|
||||
#endif
|
3
examples/.gitignore
vendored
Normal file
3
examples/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*.o
|
||||
cli
|
||||
testit
|
4
examples/Makefile.am
Normal file
4
examples/Makefile.am
Normal file
@@ -0,0 +1,4 @@
|
||||
noinst_PROGRAMS = testit cli
|
||||
LDADD = $(top_builddir)/src/libeditline.la
|
||||
AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include
|
||||
AM_LDFLAGS = -static
|
145
examples/cli.c
Normal file
145
examples/cli.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/* Custom CLI command completion.
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
#include "editline.h"
|
||||
#include <string.h>
|
||||
|
||||
#define HISTORY "/tmp/.cli-history"
|
||||
|
||||
static char *list[] = {
|
||||
"foo ", "bar ", "bsd ", "cli ", "ls ", "cd ", "malloc ", "tee ", NULL
|
||||
};
|
||||
|
||||
/* Attempt to complete the pathname, returning an allocated copy.
|
||||
* Fill in *unique if we completed it, or set it to 0 if ambiguous. */
|
||||
static char *my_rl_complete(char *token, int *match)
|
||||
{
|
||||
int i;
|
||||
int index = -1;
|
||||
int matchlen = 0;
|
||||
int count = 0;
|
||||
|
||||
for (i = 0; list[i]; i++)
|
||||
{
|
||||
int partlen = strlen (token); /* Part of token */
|
||||
|
||||
if (!strncmp (list[i], token, partlen))
|
||||
{
|
||||
index = i;
|
||||
matchlen = partlen;
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
*match = 1;
|
||||
return strdup (list[index] + matchlen);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return all possible completions. */
|
||||
static int my_rl_list_possib(char *token, char ***av)
|
||||
{
|
||||
int i, num, total = 0;
|
||||
char **copy;
|
||||
|
||||
for (num = 0; list[num]; num++)
|
||||
;
|
||||
copy = (char **) malloc (num * sizeof(char *));
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
if (!strncmp (list[i], token, strlen (token)))
|
||||
{
|
||||
copy[total] = strdup (list[i]);
|
||||
total ++;
|
||||
}
|
||||
}
|
||||
*av = copy;
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
el_status_t list_possible(void)
|
||||
{
|
||||
char **av;
|
||||
char *word;
|
||||
int ac;
|
||||
|
||||
word = el_find_word();
|
||||
ac = rl_list_possib(word, &av);
|
||||
if (word)
|
||||
free(word);
|
||||
if (ac) {
|
||||
el_print_columns(ac, av);
|
||||
while (--ac >= 0)
|
||||
free(av[ac]);
|
||||
free(av);
|
||||
|
||||
return CSmove;
|
||||
}
|
||||
|
||||
return el_ring_bell();
|
||||
}
|
||||
|
||||
el_status_t do_break(void)
|
||||
{
|
||||
puts("Breakout!");
|
||||
return CSeof;
|
||||
}
|
||||
|
||||
el_status_t do_exit(void)
|
||||
{
|
||||
puts("Bye bye!");
|
||||
return CSeof;
|
||||
}
|
||||
|
||||
el_status_t do_suspend(void)
|
||||
{
|
||||
puts("Abort!");
|
||||
return CSstay;
|
||||
}
|
||||
|
||||
int main(int ac __attribute__ ((unused)), char *av[] __attribute__ ((unused)))
|
||||
{
|
||||
char *line;
|
||||
char *prompt = "cli> ";
|
||||
|
||||
/* Setup callbacks */
|
||||
rl_set_complete_func(&my_rl_complete);
|
||||
rl_set_list_possib_func(&my_rl_list_possib);
|
||||
el_bind_key('?', list_possible);
|
||||
el_bind_key(CTL('C'), do_break);
|
||||
el_bind_key(CTL('D'), do_exit);
|
||||
el_bind_key(CTL('Z'), do_suspend);
|
||||
read_history(HISTORY);
|
||||
|
||||
while ((line = readline(prompt)) != NULL) {
|
||||
printf("\t\t\t|%s|\n", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
write_history(HISTORY);
|
||||
|
||||
return 0;
|
||||
}
|
76
examples/testit.c
Normal file
76
examples/testit.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/* A "micro-shell" to test editline library.
|
||||
* If given any arguments, commands aren't executed.
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "editline.h"
|
||||
|
||||
#ifndef HAVE_PERROR
|
||||
extern int errno;
|
||||
void perror(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: error %d\n", s, errno);
|
||||
}
|
||||
#endif /* !HAVE_PERROR */
|
||||
|
||||
int main(int argc, char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
int doit;
|
||||
char *prompt, *p;
|
||||
|
||||
doit = argc == 1;
|
||||
if ((prompt = getenv("TESTPROMPT")) == NULL)
|
||||
prompt = "testit> ";
|
||||
|
||||
while ((p = readline(prompt)) != NULL) {
|
||||
printf("\t\t\t|%s|\n", p);
|
||||
if (doit) {
|
||||
if (strncmp(p, "cd ", 3) == 0) {
|
||||
if (chdir(&p[3]) < 0)
|
||||
perror(&p[3]);
|
||||
} else if (system(p) != 0) {
|
||||
perror(p);
|
||||
}
|
||||
}
|
||||
add_history(p);
|
||||
free(p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* version-control: t
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "ellemtel"
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
2
include/Makefile.am
Normal file
2
include/Makefile.am
Normal file
@@ -0,0 +1,2 @@
|
||||
library_includedir = $(includedir)
|
||||
library_include_HEADERS = editline.h
|
111
include/editline.h
Normal file
111
include/editline.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/* Minix editline
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
#ifndef __EDITLINE_H__
|
||||
#define __EDITLINE_H__
|
||||
|
||||
/* Handy macros when binding keys. */
|
||||
#define CTL(x) ((x) & 0x1F)
|
||||
#define ISCTL(x) ((x) && (x) < ' ')
|
||||
#define UNCTL(x) ((x) + 64)
|
||||
#define META(x) ((x) | 0x80)
|
||||
#define ISMETA(x) ((x) & 0x80)
|
||||
#define UNMETA(x) ((x) & 0x7F)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Command status codes. */
|
||||
typedef enum {
|
||||
CSdone = 0, /* OK */
|
||||
CSeof, /* Error, or EOF */
|
||||
CSmove,
|
||||
CSdispatch,
|
||||
CSstay,
|
||||
CSsignal
|
||||
} el_status_t;
|
||||
|
||||
/* Editline specific types, despite rl_ prefix. From Heimdal project. */
|
||||
typedef char* rl_complete_func_t(char*, int*);
|
||||
typedef int rl_list_possib_func_t(char*, char***);
|
||||
typedef el_status_t el_keymap_func_t(void);
|
||||
typedef int rl_hook_func_t(void);
|
||||
typedef int rl_getc_func_t(void);
|
||||
typedef void rl_voidfunc_t(void);
|
||||
typedef void rl_vintfunc_t(int);
|
||||
|
||||
/* Display 8-bit chars "as-is" or as `M-x'? Toggle with M-m. (Default:0 - "as-is") */
|
||||
extern int rl_meta_chars;
|
||||
|
||||
/* Editline specific functions. */
|
||||
extern char * el_find_word(void);
|
||||
extern void el_print_columns(int ac, char **av);
|
||||
extern el_status_t el_ring_bell(void);
|
||||
extern el_status_t el_del_char(void);
|
||||
|
||||
extern el_status_t el_bind_key(int key, el_keymap_func_t function);
|
||||
extern el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function);
|
||||
|
||||
extern char *rl_complete(char *token, int *match);
|
||||
extern int rl_list_possib(char *token, char ***av);
|
||||
|
||||
/* For compatibility with FSF readline. */
|
||||
extern int rl_point;
|
||||
extern int rl_mark;
|
||||
extern int rl_end;
|
||||
extern int rl_inhibit_complete;
|
||||
extern char *rl_line_buffer;
|
||||
extern const char *rl_readline_name;
|
||||
extern FILE *rl_instream; /* The stdio stream from which input is read. Defaults to stdin if NULL - Not supported yet! */
|
||||
extern FILE *rl_outstream; /* The stdio stream to which output is flushed. Defaults to stdout if NULL - Not supported yet! */
|
||||
extern int el_no_echo; /* E.g under emacs, don't echo except prompt */
|
||||
extern int el_no_hist; /* Disable auto-save of and access to history -- e.g. for password prompts or wizards */
|
||||
extern int el_hist_size; /* size of history scrollback buffer, default: 15 */
|
||||
|
||||
extern void rl_initialize(void);
|
||||
extern void rl_reset_terminal(const char *terminal_name);
|
||||
|
||||
void rl_save_prompt(void);
|
||||
void rl_restore_prompt(void);
|
||||
void rl_set_prompt(const char *prompt);
|
||||
|
||||
void rl_clear_message(void);
|
||||
void rl_forced_update_display(void);
|
||||
|
||||
extern char *readline(const char *prompt);
|
||||
extern void add_history(const char *line);
|
||||
|
||||
extern int read_history(const char *filename);
|
||||
extern int write_history(const char *filename);
|
||||
|
||||
rl_complete_func_t *rl_set_complete_func(rl_complete_func_t *func);
|
||||
rl_list_possib_func_t *rl_set_list_possib_func(rl_list_possib_func_t *func);
|
||||
|
||||
void rl_prep_terminal(int meta_flag);
|
||||
void rl_deprep_terminal(void);
|
||||
|
||||
int rl_getc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __EDITLINE_H__ */
|
12
libeditline.pc.in
Normal file
12
libeditline.pc.in
Normal file
@@ -0,0 +1,12 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: @PACKAGE@
|
||||
Description: A small line editing library without termcap/curses
|
||||
Version: @VERSION@
|
||||
Requires:
|
||||
Libs: -L${libdir} -leditline
|
||||
Cflags: -I${includedir}
|
||||
|
1
m4/.gitignore
vendored
Normal file
1
m4/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.m4
|
3
man/Makefile.am
Normal file
3
man/Makefile.am
Normal file
@@ -0,0 +1,3 @@
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
dist_man_MANS = editline.3
|
200
man/editline.3
Normal file
200
man/editline.3
Normal file
@@ -0,0 +1,200 @@
|
||||
.TH EDITLINE 3
|
||||
.SH NAME
|
||||
editline \- command-line editing library with history
|
||||
.SH SYNOPSIS
|
||||
.nf
|
||||
.B "char *readline(char *prompt);"
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.I Editline
|
||||
is a library that provides an line-editing interface with history.
|
||||
It is intended to be functionally equivalent with the
|
||||
.I readline
|
||||
library provided by the Free Software Foundation, but much smaller.
|
||||
The bulk of this manual page describes the user interface.
|
||||
.PP
|
||||
The
|
||||
.I readline()
|
||||
function displays the given
|
||||
.I prompt
|
||||
on stdout, waits for user input on stdin and then
|
||||
returns a line of text with the trailing newline removed. The data is returned in a
|
||||
buffer allocated with
|
||||
.IR malloc (3),
|
||||
so the space should be released with
|
||||
.IR free (3)
|
||||
when the calling program is done with it.
|
||||
.PP
|
||||
Each line returned is copied to the internal history list, unless it happens
|
||||
to be equal to the previous line. This is configurable if you are building editline
|
||||
from source.
|
||||
.SS User Interface
|
||||
A program that uses this library provides a simple emacs-like editing interface to
|
||||
its users. A line may be edited before it is sent to the calling program by typing
|
||||
either control characters or escape sequences. A control character, shown as a caret
|
||||
followed by a letter, is typed by holding down the ``control'' key while the letter
|
||||
is typed. For example, ``^A'' is a control-A. An escape sequence is entered by
|
||||
typing the ``escape'' key followed by one or more characters. The escape key is
|
||||
abbreviated as ``ESC''. Note that unlike control keys, case matters in escape
|
||||
sequences; ``ESC\ F'' is not the same as ``ESC\ f''.
|
||||
.PP
|
||||
An editing command may be typed anywhere on the line, not just at the beginning. In
|
||||
addition, a return may also be typed anywhere on the line, not just at the end.
|
||||
.PP
|
||||
Most editing commands may be given a repeat count,
|
||||
.IR n ,
|
||||
where
|
||||
.I n
|
||||
is a number.
|
||||
To enter a repeat count, type the escape key, the number, and then
|
||||
the command to execute.
|
||||
For example, ``ESC\ 4\ ^f'' moves forward four characters.
|
||||
If a command may be given a repeat count then the text ``[n]'' is given at the
|
||||
end of its description.
|
||||
.PP
|
||||
The following control characters are accepted:
|
||||
.RS
|
||||
.nf
|
||||
.ta \w'ESC DEL 'u
|
||||
^A Move to the beginning of the line
|
||||
^B Move left (backwards) [n]
|
||||
^D Delete character [n]
|
||||
^E Move to end of line
|
||||
^F Move right (forwards) [n]
|
||||
^G Ring the bell
|
||||
^H Delete character before cursor (backspace key) [n]
|
||||
^I Complete filename (tab key); see below
|
||||
^J Done with line (return key)
|
||||
^K Kill to end of line (or column [n])
|
||||
^L Redisplay line
|
||||
^M Done with line (alternate return key)
|
||||
^N Get next line from history [n]
|
||||
^P Get previous line from history [n]
|
||||
^R Search backward (forward if [n]) through history for
|
||||
\& text; must start line if text begins with an uparrow
|
||||
^T Transpose characters
|
||||
^V Insert next character, even if it is an edit command
|
||||
^W Wipe to the mark
|
||||
^X^X Exchange current location and mark
|
||||
^Y Yank back last killed text
|
||||
^[ Start an escape sequence (escape key)
|
||||
^]c Move forward to next character ``c''
|
||||
^? Delete character before cursor (delete key) [n]
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
The following escape sequences are provided.
|
||||
.RS
|
||||
.nf
|
||||
.ta \w'ESC DEL 'u
|
||||
ESC\ ^H Delete previous word (backspace key) [n]
|
||||
ESC\ DEL Delete previous word (delete key) [n]
|
||||
ESC\ SP Set the mark (space key); see ^X^X and ^Y above
|
||||
ESC\ \. Get the last (or [n]'th) word from previous line
|
||||
ESC\ ? Show possible completions; see below
|
||||
ESC\ < Move to start of history
|
||||
ESC\ > Move to end of history
|
||||
ESC\ b Move backward a word [n]
|
||||
ESC\ d Delete word under cursor [n]
|
||||
ESC\ f Move forward a word [n]
|
||||
ESC\ l Make word lowercase [n]
|
||||
ESC\ m Toggle if 8bit chars display normally or with an
|
||||
\& ``M\-'' prefix
|
||||
ESC\ u Make word uppercase [n]
|
||||
ESC\ y Yank back last killed text
|
||||
ESC\ v Show library version
|
||||
ESC\ w Make area up to mark yankable
|
||||
ESC\ nn Set repeat count to the number nn
|
||||
ESC\ C Read from environment variable ``_C_'', where C is
|
||||
\& an uppercase letter
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
The
|
||||
.I editline
|
||||
library has a small macro facility.
|
||||
If you type the escape key followed by an uppercase letter,
|
||||
.IR C ,
|
||||
then the contents of the environment variable
|
||||
.I _C_
|
||||
are read in as if you had typed them at the keyboard.
|
||||
For example, if the variable
|
||||
.I _L_
|
||||
contains the following:
|
||||
.PP
|
||||
.RS
|
||||
^A^Kecho '^V^[[H^V^[[2J'^M
|
||||
.RE
|
||||
.PP
|
||||
Then typing ``ESC L'' will move to the beginning of the line, kill the
|
||||
entire line, enter the echo command needed to clear the terminal (if your
|
||||
terminal is like a VT-100), and send the line back to the shell.
|
||||
.PP
|
||||
The
|
||||
.I editline
|
||||
library also does filename completion.
|
||||
Suppose the root directory has the following files in it:
|
||||
.PP
|
||||
.RS
|
||||
.nf
|
||||
.ta \w'core 'u
|
||||
bin vmunix
|
||||
core vmunix.old
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
If you type ``rm\ /v'' and then the tab key.
|
||||
.I Editline
|
||||
will then finish off as much of the name as possible by adding ``munix''.
|
||||
Because the name is not unique, it will then beep.
|
||||
If you type the escape key and a question mark, it will display the
|
||||
two choices.
|
||||
If you then type a period and a tab, the library will finish off the filename
|
||||
for you:
|
||||
.PP
|
||||
.RS
|
||||
.nf
|
||||
.RI "rm /v[TAB]" munix ".[TAB]" old
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
The tab key is shown by ``[TAB]'' and the automatically-entered text
|
||||
is shown in italics.
|
||||
.SH USAGE
|
||||
To include
|
||||
.I readline()
|
||||
in your program, simply call it as you do any other function. Just make sure to link
|
||||
your program with libeditline.
|
||||
.SS Example
|
||||
The following brief example lets you enter a line and edit it, then displays it.
|
||||
.nf
|
||||
.B ""
|
||||
.B #include <stdlib.h>
|
||||
.B ""
|
||||
.B extern char *readline(char *prompt);
|
||||
.B ""
|
||||
.B int main (void)
|
||||
.B {
|
||||
.RS
|
||||
.B char *p;
|
||||
.B ""
|
||||
.B while ((p = readline("CLI>"))) {
|
||||
.RS
|
||||
.B puts(p);
|
||||
.B free(p);
|
||||
.RE
|
||||
.B }
|
||||
.B ""
|
||||
.B return 0;
|
||||
.RE
|
||||
.B }
|
||||
.fi
|
||||
.SH BUGS AND LIMITATIONS
|
||||
Does not handle multiple lines or unicode characters well. See the TODO
|
||||
file in the distribution if you want to help out.
|
||||
.SH AUTHORS
|
||||
The original editline library was created by Simmule R. Turner and Rich
|
||||
$alz. It now exists in several forks: Heimdal, Festival speech tools,
|
||||
Mozilla, Google Gadgets for Linux, and many other places. The original
|
||||
manual page was made by David W. Sanderson. Currently maintained by
|
||||
Joachim Nilsson at http://github.com/troglobit/editline
|
2
src/.gitignore
vendored
Normal file
2
src/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
libeditline.a
|
||||
libeditline.la
|
6
src/Makefile.am
Normal file
6
src/Makefile.am
Normal file
@@ -0,0 +1,6 @@
|
||||
lib_LTLIBRARIES = libeditline.la
|
||||
libeditline_la_SOURCES = editline.c editline.h complete.c sysunix.c unix.h
|
||||
libeditline_la_CFLAGS = -std=gnu99
|
||||
libeditline_la_CFLAGS += -W -Wall -Wundef -Wunused -Wstrict-prototypes
|
||||
libeditline_la_CFLAGS += -Werror-implicit-function-declaration -Wshadow -Wcast-qual
|
||||
libeditline_la_LDFLAGS = $(AM_LDFLAGS) -version-info 0:0:0
|
284
src/complete.c
Normal file
284
src/complete.c
Normal file
@@ -0,0 +1,284 @@
|
||||
/* History and file completion functions for editline library.
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
#include "editline.h"
|
||||
|
||||
#define MAX_TOTAL_MATCHES (256 << sizeof(char *))
|
||||
|
||||
/* Wrap strcmp() for qsort() -- weird construct to pass -Wcast-qual */
|
||||
static int compare(const void *p1, const void *p2)
|
||||
{
|
||||
char *const *v1 = (char *const *)p1;
|
||||
char *const *v2 = (char *const *)p2;
|
||||
|
||||
return strcmp(*v1, *v2);
|
||||
}
|
||||
|
||||
/* Fill in *avp with an array of names that match file, up to its length.
|
||||
* Ignore . and .. . */
|
||||
static int FindMatches(char *dir, char *file, char ***avp)
|
||||
{
|
||||
char **av;
|
||||
char **word;
|
||||
char *p;
|
||||
DIR *dp;
|
||||
DIRENTRY *ep;
|
||||
size_t ac;
|
||||
size_t len;
|
||||
size_t choices;
|
||||
size_t total;
|
||||
|
||||
if ((dp = opendir(dir)) == NULL)
|
||||
return 0;
|
||||
|
||||
av = NULL;
|
||||
ac = 0;
|
||||
len = strlen(file);
|
||||
choices = 0;
|
||||
total = 0;
|
||||
while ((ep = readdir(dp)) != NULL) {
|
||||
p = ep->d_name;
|
||||
if (p[0] == '.' && (p[1] == '\0' || (p[1] == '.' && p[2] == '\0')))
|
||||
continue;
|
||||
if (len && strncmp(p, file, len) != 0)
|
||||
continue;
|
||||
|
||||
choices++;
|
||||
if ((total += strlen(p)) > MAX_TOTAL_MATCHES) {
|
||||
/* This is a bit too much. */
|
||||
while (ac > 0) free(av[--ac]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((ac % MEM_INC) == 0) {
|
||||
word = malloc(sizeof(char *) * (ac + MEM_INC));
|
||||
if (!word) {
|
||||
total = 0;
|
||||
break;
|
||||
}
|
||||
if (ac) {
|
||||
memcpy(word, av, ac * sizeof(char *));
|
||||
free(av);
|
||||
}
|
||||
*avp = av = word;
|
||||
}
|
||||
|
||||
if ((av[ac] = strdup(p)) == NULL) {
|
||||
if (ac == 0)
|
||||
free(av);
|
||||
total = 0;
|
||||
break;
|
||||
}
|
||||
ac++;
|
||||
}
|
||||
|
||||
/* Clean up and return. */
|
||||
closedir(dp);
|
||||
if (total > MAX_TOTAL_MATCHES) {
|
||||
char many[sizeof(total) * 3];
|
||||
p = many + sizeof(many);
|
||||
*--p = '\0';
|
||||
while (choices > 0) {
|
||||
*--p = '0' + choices % 10;
|
||||
choices /= 10;
|
||||
}
|
||||
while (p > many + sizeof(many) - 8) *--p = ' ';
|
||||
if ((p = strdup(p)) != NULL) av[ac++] = p;
|
||||
if ((p = strdup("choices")) != NULL) av[ac++] = p;
|
||||
} else {
|
||||
if (ac)
|
||||
qsort(av, ac, sizeof(char *), compare);
|
||||
}
|
||||
|
||||
return ac;
|
||||
}
|
||||
|
||||
/* Split a pathname into allocated directory and trailing filename parts. */
|
||||
static int SplitPath(char *path, char **dirpart, char **filepart)
|
||||
{
|
||||
static char DOT[] = ".";
|
||||
char *dpart;
|
||||
char *fpart;
|
||||
|
||||
if ((fpart = strrchr(path, '/')) == NULL) {
|
||||
if ((dpart = strdup(DOT)) == NULL)
|
||||
return -1;
|
||||
if ((fpart = strdup(path)) == NULL) {
|
||||
free(dpart);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if ((dpart = strdup(path)) == NULL)
|
||||
return -1;
|
||||
dpart[fpart - path + 1] = '\0';
|
||||
if ((fpart = strdup(fpart + 1)) == NULL) {
|
||||
free(dpart);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*dirpart = dpart;
|
||||
*filepart = fpart;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rl_complete_func_t *el_complete_func = NULL;
|
||||
|
||||
/* For compatibility with the Heimdal project. */
|
||||
rl_complete_func_t *rl_set_complete_func(rl_complete_func_t *func)
|
||||
{
|
||||
rl_complete_func_t *old = el_complete_func;
|
||||
el_complete_func = func;
|
||||
return old;
|
||||
}
|
||||
|
||||
/* Attempt to complete the pathname, returning an allocated copy.
|
||||
* Fill in *match if we completed it, or set it to 0 if ambiguous. */
|
||||
char *el_filename_complete(char *pathname, int *match)
|
||||
{
|
||||
char **av;
|
||||
char *dir;
|
||||
char *file;
|
||||
char *path;
|
||||
char *p;
|
||||
size_t ac;
|
||||
size_t end;
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t len;
|
||||
|
||||
if (SplitPath(pathname, &dir, &file) < 0)
|
||||
return NULL;
|
||||
|
||||
if ((ac = FindMatches(dir, file, &av)) == 0) {
|
||||
free(dir);
|
||||
free(file);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = NULL;
|
||||
len = strlen(file);
|
||||
if (ac == 1) {
|
||||
/* Exactly one match -- finish it off. */
|
||||
*match = 1;
|
||||
j = strlen(av[0]) - len + 2;
|
||||
p = malloc(sizeof(char) * (j + 1));
|
||||
if (p) {
|
||||
memcpy(p, av[0] + len, j);
|
||||
len = strlen(dir) + strlen(av[0]) + 2;
|
||||
path = malloc(sizeof(char) * len);
|
||||
if (path) {
|
||||
snprintf(path, len, "%s/%s", dir, av[0]);
|
||||
rl_add_slash(path, p);
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*match = 0;
|
||||
if (len) {
|
||||
/* Find largest matching substring. */
|
||||
for (i = len, end = strlen(av[0]); i < end; i++)
|
||||
for (j = 1; j < ac; j++)
|
||||
if (av[0][i] != av[j][i])
|
||||
goto breakout;
|
||||
breakout:
|
||||
if (i > len) {
|
||||
j = i - len + 1;
|
||||
p = malloc(sizeof(char) * j);
|
||||
if (p) {
|
||||
memcpy(p, av[0] + len, j);
|
||||
p[j - 1] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up and return. */
|
||||
free(dir);
|
||||
free(file);
|
||||
for (i = 0; i < ac; i++)
|
||||
free(av[i]);
|
||||
free(av);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
char *rl_complete(char *token, int *match)
|
||||
{
|
||||
if (el_complete_func)
|
||||
return el_complete_func(token, match);
|
||||
|
||||
#ifdef CONFIG_DEFAULT_COMPLETE
|
||||
return el_filename_complete(token, match);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static rl_list_possib_func_t *el_list_possib_func = NULL;
|
||||
|
||||
/* For compatibility with the Heimdal project. */
|
||||
rl_list_possib_func_t *rl_set_list_possib_func(rl_list_possib_func_t *func)
|
||||
{
|
||||
rl_list_possib_func_t *old = el_list_possib_func;
|
||||
el_list_possib_func = func;
|
||||
return old;
|
||||
}
|
||||
|
||||
/* Default possible completions. */
|
||||
int el_filename_list_possib(char *pathname, char ***av)
|
||||
{
|
||||
char *dir;
|
||||
char *file;
|
||||
int ac;
|
||||
|
||||
if (SplitPath(pathname, &dir, &file) < 0)
|
||||
return 0;
|
||||
|
||||
ac = FindMatches(dir, file, av);
|
||||
free(dir);
|
||||
free(file);
|
||||
|
||||
return ac;
|
||||
}
|
||||
|
||||
/* Return all possible completions. */
|
||||
int rl_list_possib(char *token, char ***av)
|
||||
{
|
||||
if (el_list_possib_func)
|
||||
return el_list_possib_func(token, av);
|
||||
|
||||
#ifdef CONFIG_DEFAULT_COMPLETE
|
||||
return el_filename_list_possib(token, av);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "ellemtel"
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
1742
src/editline.c
Normal file
1742
src/editline.c
Normal file
File diff suppressed because it is too large
Load Diff
98
src/editline.h
Normal file
98
src/editline.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* Internal header file for editline library.
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
#ifndef __PRIVATE_EDITLINE_H__
|
||||
#define __PRIVATE_EDITLINE_H__
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_MALLOC_H
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_DIRENT_H
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef SYS_UNIX
|
||||
#include "unix.h"
|
||||
#endif
|
||||
#ifdef SYS_OS9
|
||||
#include "os9.h"
|
||||
#endif
|
||||
/* The following two are for TIOCGWINSZ */
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
# include <termios.h>
|
||||
#endif
|
||||
#ifdef GWINSZ_IN_SYS_IOCTL
|
||||
# include <sys/ioctl.h>
|
||||
#endif
|
||||
|
||||
#define MEM_INC 64
|
||||
#define SCREEN_INC 256
|
||||
|
||||
/* http://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827 */
|
||||
#define ARRAY_ELEMENTS(arr) ((sizeof(arr)/sizeof(0[arr])) / ((size_t)(!(sizeof(arr) % sizeof(0[arr])))))
|
||||
|
||||
/*
|
||||
** Variables and routines internal to this package.
|
||||
*/
|
||||
extern int rl_eof;
|
||||
extern int rl_erase;
|
||||
extern int rl_intr;
|
||||
extern int rl_kill;
|
||||
extern int rl_quit;
|
||||
#ifdef CONFIG_SIGSTOP
|
||||
extern int rl_susp;
|
||||
#endif
|
||||
void rl_ttyset(int Reset);
|
||||
void rl_add_slash(char *path, char *p);
|
||||
char *rl_complete(char *token, int *match);
|
||||
int rl_list_possib(char *token, char ***av);
|
||||
|
||||
#ifndef HAVE_STDLIB_H
|
||||
extern char *getenv(const char *name);
|
||||
extern char *malloc(size_t size);
|
||||
extern char *realloc(void *ptr, size_t size);
|
||||
extern char *memcpy(void *dest, const void *src, size_t n);
|
||||
extern char *strcat(char *dest, const char *src);
|
||||
extern char *strchr(const char *s, int c);
|
||||
extern char *strrchr(const char *s, int c);
|
||||
extern char *strcpy(char *dest, const char *src);
|
||||
extern char *strdup(const char *s);
|
||||
extern int strcmp(const char *s1, const char *s2);
|
||||
extern int strlen(const char *s);
|
||||
extern int strncmp(const char *s1, const char *s2, size_t n);
|
||||
#endif/* !HAVE_STDLIB_H */
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
extern char *strdup(const char *s);
|
||||
#endif
|
||||
|
||||
#include "../include/editline.h"
|
||||
#endif /* __PRIVATE_EDITLINE_H__ */
|
25
src/os9.h
Normal file
25
src/os9.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* Editline system header file for OS-9 (on 68k).
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
#define CRLF "\r\l"
|
||||
|
||||
#include <dir.h>
|
||||
typedef struct direct DIRENTRY;
|
64
src/sysos9.c
Normal file
64
src/sysos9.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* OS-9 (on 68k) system-dependant routines for editline library.
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
#include "editline.h"
|
||||
#include <sgstat.h>
|
||||
#include <modes.h>
|
||||
|
||||
void rl_ttyset(int Reset)
|
||||
{
|
||||
static struct sgbuf old;
|
||||
struct sgbuf new;
|
||||
|
||||
if (Reset == 0) {
|
||||
_gs_opt(0, &old);
|
||||
_gs_opt(0, &new);
|
||||
new.sg_backsp = 0; new.sg_delete = 0; new.sg_echo = 0;
|
||||
new.sg_alf = 0; new.sg_nulls = 0; new.sg_pause = 0;
|
||||
new.sg_page = 0; new.sg_bspch = 0; new.sg_dlnch = 0;
|
||||
new.sg_eorch = 0; new.sg_eofch = 0; new.sg_rlnch = 0;
|
||||
new.sg_dulnch = 0; new.sg_psch = 0; new.sg_kbich = 0;
|
||||
new.sg_kbach = 0; new.sg_bsech = 0; new.sg_bellch = 0;
|
||||
new.sg_xon = 0; new.sg_xoff = 0; new.sg_tabcr = 0;
|
||||
new.sg_tabsiz = 0;
|
||||
_ss_opt(0, &new);
|
||||
rl_erase = old.sg_bspch;
|
||||
rl_kill = old.sg_dlnch;
|
||||
rl_eof = old.sg_eofch;
|
||||
rl_intr = old.sg_kbich;
|
||||
rl_quit = -1;
|
||||
}
|
||||
else {
|
||||
_ss_opt(0, &old);
|
||||
}
|
||||
}
|
||||
|
||||
void rl_add_slash(char *path, char *p)
|
||||
{
|
||||
strcat(p, access(path, S_IREAD | S_IFDIR) ? " " : "/");
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "ellemtel"
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
239
src/sysunix.c
Normal file
239
src/sysunix.c
Normal file
@@ -0,0 +1,239 @@
|
||||
/* Unix system-dependant routines for editline library.
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include "editline.h"
|
||||
|
||||
#ifndef HAVE_TCGETATTR
|
||||
/* Wrapper for ioctl syscalls to restart on signal */
|
||||
static int ioctl_wrap(int fd, int req, void *arg)
|
||||
{
|
||||
int result, retries = 3;
|
||||
|
||||
while (-1 == (result = ioctl(fd, req, arg)) && retries > 0) {
|
||||
retries--;
|
||||
|
||||
if (EINTR == errno)
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Prefer termios over the others since it is likely the most portable. */
|
||||
#if defined(HAVE_TCGETATTR)
|
||||
#include <termios.h>
|
||||
|
||||
/* Wrapper for tcgetattr */
|
||||
static int getattr(int fd, struct termios *arg)
|
||||
{
|
||||
int result, retries = 3;
|
||||
|
||||
while (-1 == (result = tcgetattr(fd, arg)) && retries > 0) {
|
||||
retries--;
|
||||
|
||||
if (EINTR == errno)
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Wrapper for tcgetattr */
|
||||
static int setattr(int fd, int opt, const struct termios *arg)
|
||||
{
|
||||
int result, retries = 3;
|
||||
|
||||
while (-1 == (result = tcsetattr(fd, opt, arg)) && retries > 0) {
|
||||
retries--;
|
||||
|
||||
if (EINTR == errno)
|
||||
continue;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void rl_ttyset(int Reset)
|
||||
{
|
||||
static struct termios old;
|
||||
struct termios new;
|
||||
|
||||
if (!Reset) {
|
||||
if (-1 == getattr(0, &old))
|
||||
perror("Failed tcgetattr()");
|
||||
rl_erase = old.c_cc[VERASE];
|
||||
rl_kill = old.c_cc[VKILL];
|
||||
rl_eof = old.c_cc[VEOF];
|
||||
rl_intr = old.c_cc[VINTR];
|
||||
rl_quit = old.c_cc[VQUIT];
|
||||
#ifdef CONFIG_SIGSTOP
|
||||
rl_susp = old.c_cc[VSUSP];
|
||||
#endif
|
||||
|
||||
new = old;
|
||||
new.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
new.c_iflag &= ~INPCK;
|
||||
if (rl_meta_chars)
|
||||
new.c_iflag |= ISTRIP;
|
||||
else
|
||||
new.c_iflag &= ~ISTRIP;
|
||||
new.c_cc[VMIN] = 1;
|
||||
new.c_cc[VTIME] = 0;
|
||||
if (-1 == setattr(0, TCSADRAIN, &new))
|
||||
perror("Failed tcsetattr(TCSADRAIN)");
|
||||
} else {
|
||||
if (-1 == setattr(0, TCSADRAIN, &old))
|
||||
perror("Failed tcsetattr(TCSADRAIN)");
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(HAVE_TERMIO_H)
|
||||
#include <termio.h>
|
||||
|
||||
void rl_ttyset(int Reset)
|
||||
{
|
||||
static struct termio old;
|
||||
struct termio new;
|
||||
|
||||
if (!Reset) {
|
||||
if (-1 == ioctl_wrap(0, TCGETA, &old))
|
||||
perror("Failed ioctl(TCGETA)");
|
||||
rl_erase = old.c_cc[VERASE];
|
||||
rl_kill = old.c_cc[VKILL];
|
||||
rl_eof = old.c_cc[VEOF];
|
||||
rl_intr = old.c_cc[VINTR];
|
||||
rl_quit = old.c_cc[VQUIT];
|
||||
#ifdef CONFIG_SIGSTOP
|
||||
rl_susp = old.c_cc[VSUSP];
|
||||
#endif
|
||||
|
||||
new = old;
|
||||
new.c_lflag &= ~(ECHO | ICANON | ISIG);
|
||||
new.c_iflag &= ~INPCK;
|
||||
if (rl_meta_chars)
|
||||
new.c_iflag |= ISTRIP;
|
||||
else
|
||||
new.c_iflag &= ~ISTRIP;
|
||||
|
||||
new.c_cc[VMIN] = 1;
|
||||
new.c_cc[VTIME] = 0;
|
||||
if (-1 == ioctl_wrap(0, TCSETAW, &new))
|
||||
perror("Failed ioctl(TCSETAW)");
|
||||
} else {
|
||||
if (-1 == ioctl_wrap(0, TCSETAW, &old))
|
||||
perror("Failed ioctl(TCSETAW)");
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(HAVE_SGTTY_H)
|
||||
#include <sgtty.h>
|
||||
|
||||
void rl_ttyset(int Reset)
|
||||
{
|
||||
static struct sgttyb old_sgttyb;
|
||||
static struct tchars old_tchars;
|
||||
struct sgttyb new_sgttyb;
|
||||
struct tchars new_tchars;
|
||||
#ifdef CONFIG_SIGSTOP
|
||||
struct ltchars old_ltchars;
|
||||
#endif
|
||||
|
||||
if (!Reset) {
|
||||
if (-1 == ioctl_wrap(0, TIOCGETP, &old_sgttyb))
|
||||
perror("Failed TIOCGETP");
|
||||
rl_erase = old_sgttyb.sg_erase;
|
||||
rl_kill = old_sgttyb.sg_kill;
|
||||
|
||||
if (-1 == ioctl_wrap(0, TIOCGETC, &old_tchars))
|
||||
perror("Failed TIOCGETC");
|
||||
rl_eof = old_tchars.t_eofc;
|
||||
rl_intr = old_tchars.t_intrc;
|
||||
rl_quit = old_tchars.t_quitc;
|
||||
|
||||
#ifdef CONFIG_SIGSTOP
|
||||
if (-1 == ioctl_wrap(0, TIOCGLTC, &old_ltchars))
|
||||
perror("Failed TIOCGLTC");
|
||||
rl_susp = old_ltchars.t_suspc;
|
||||
#endif
|
||||
|
||||
new_sgttyb = old_sgttyb;
|
||||
new_sgttyb.sg_flags &= ~ECHO;
|
||||
new_sgttyb.sg_flags |= RAW;
|
||||
if (rl_meta_chars)
|
||||
new_sgttyb.sg_flags &= ~PASS8;
|
||||
else
|
||||
new_sgttyb.sg_flags |= PASS8;
|
||||
if (-1 == ioctl_wrap(0, TIOCSETP, &new_sgttyb))
|
||||
perror("Failed TIOCSETP");
|
||||
new_tchars = old_tchars;
|
||||
new_tchars.t_intrc = -1;
|
||||
new_tchars.t_quitc = -1;
|
||||
if (-1 == ioctl_wrap(0, TIOCSETC, &new_tchars))
|
||||
perror("Failed TIOCSETC");
|
||||
} else {
|
||||
if (-1 == ioctl_wrap(0, TIOCSETP, &old_sgttyb))
|
||||
perror("Failed TIOCSETP");
|
||||
if (-1 == ioctl_wrap(0, TIOCSETC, &old_tchars))
|
||||
perror("Failed TIOCSETC");
|
||||
}
|
||||
}
|
||||
#else /* Neither HAVE_SGTTY_H, HAVE_TERMIO_H or HAVE_TCGETATTR */
|
||||
#error Unsupported platform, missing tcgetattr(), termio.h and sgtty.h
|
||||
#endif /* Neither HAVE_SGTTY_H, HAVE_TERMIO_H or HAVE_TCGETATTR */
|
||||
|
||||
#ifndef HAVE_STRDUP
|
||||
/* Return an allocated copy of a string. */
|
||||
char *strdup(const char *p)
|
||||
{
|
||||
char *new = malloc(sizeof(char) * strlen(p));
|
||||
|
||||
if (new) {
|
||||
strcpy(new, p);
|
||||
return new;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
void rl_add_slash(char *path, char *p)
|
||||
{
|
||||
struct stat Sb;
|
||||
|
||||
if (stat(path, &Sb) >= 0)
|
||||
strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
* c-file-style: "ellemtel"
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
35
src/unix.h
Normal file
35
src/unix.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Editline system header file for Unix.
|
||||
*
|
||||
* Copyright (c) 1992, 1993 Simmule Turner and Rich Salz. All rights reserved.
|
||||
*
|
||||
* This software is not subject to any license of the American Telephone
|
||||
* and Telegraph Company or of the Regents of the University of California.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose on
|
||||
* any computer system, and to alter it and redistribute it freely, subject
|
||||
* to the following restrictions:
|
||||
* 1. The authors are not responsible for the consequences of use of this
|
||||
* software, no matter how awful, even if they arise from flaws in it.
|
||||
* 2. The origin of this software must not be misrepresented, either by
|
||||
* explicit claim or by omission. Since few users ever read sources,
|
||||
* credits must appear in the documentation.
|
||||
* 3. Altered versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software. Since few users
|
||||
* ever read sources, credits must appear in the documentation.
|
||||
* 4. This notice may not be removed or altered.
|
||||
*/
|
||||
|
||||
#ifndef __EDITLINE_UNIX_H__
|
||||
#define __EDITLINE_UNIX_H__
|
||||
|
||||
#define CRLF "\r\n"
|
||||
#define FORWARD STATIC
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <dirent.h>
|
||||
typedef struct dirent DIRENTRY;
|
||||
|
||||
#endif /* __EDITLINE_UNIX_H__ */
|
120
sysunix.c
120
sysunix.c
@@ -1,120 +0,0 @@
|
||||
/* $Revision: 5 $
|
||||
**
|
||||
** Unix system-dependant routines for editline library.
|
||||
*/
|
||||
#include "editline.h"
|
||||
|
||||
#if defined(HAVE_TCGETATTR)
|
||||
#include <termios.h>
|
||||
|
||||
void
|
||||
rl_ttyset(Reset)
|
||||
int Reset;
|
||||
{
|
||||
static struct termios old;
|
||||
struct termios new;
|
||||
|
||||
if (Reset == 0) {
|
||||
(void)tcgetattr(0, &old);
|
||||
rl_erase = old.c_cc[VERASE];
|
||||
rl_kill = old.c_cc[VKILL];
|
||||
rl_eof = old.c_cc[VEOF];
|
||||
rl_intr = old.c_cc[VINTR];
|
||||
rl_quit = old.c_cc[VQUIT];
|
||||
|
||||
new = old;
|
||||
new.c_lflag &= ~(ECHO | ICANON | ISIG | IEXTEN);
|
||||
new.c_iflag &= ~(ICRNL);
|
||||
new.c_cc[VMIN] = 1;
|
||||
new.c_cc[VTIME] = 0;
|
||||
(void)tcsetattr(0, TCSADRAIN, &new);
|
||||
}
|
||||
else
|
||||
(void)tcsetattr(0, TCSADRAIN, &old);
|
||||
}
|
||||
|
||||
#else
|
||||
#if defined(HAVE_TERMIO)
|
||||
#include <termio.h>
|
||||
|
||||
void
|
||||
rl_ttyset(Reset)
|
||||
int Reset;
|
||||
{
|
||||
static struct termio old;
|
||||
struct termio new;
|
||||
|
||||
if (Reset == 0) {
|
||||
(void)ioctl(0, TCGETA, &old);
|
||||
rl_erase = old.c_cc[VERASE];
|
||||
rl_kill = old.c_cc[VKILL];
|
||||
rl_eof = old.c_cc[VEOF];
|
||||
rl_intr = old.c_cc[VINTR];
|
||||
rl_quit = old.c_cc[VQUIT];
|
||||
|
||||
new = old;
|
||||
new.c_cc[VINTR] = -1;
|
||||
new.c_cc[VQUIT] = -1;
|
||||
new.c_lflag &= ~(ECHO | ICANON);
|
||||
new.c_cc[VMIN] = 1;
|
||||
new.c_cc[VTIME] = 0;
|
||||
(void)ioctl(0, TCSETAW, &new);
|
||||
}
|
||||
else
|
||||
(void)ioctl(0, TCSETAW, &old);
|
||||
}
|
||||
|
||||
#else
|
||||
#include <sgtty.h>
|
||||
|
||||
void
|
||||
rl_ttyset(Reset)
|
||||
int Reset;
|
||||
{
|
||||
static struct sgttyb old_sgttyb;
|
||||
static struct tchars old_tchars;
|
||||
struct sgttyb new_sgttyb;
|
||||
struct tchars new_tchars;
|
||||
|
||||
if (Reset == 0) {
|
||||
(void)ioctl(0, TIOCGETP, &old_sgttyb);
|
||||
rl_erase = old_sgttyb.sg_erase;
|
||||
rl_kill = old_sgttyb.sg_kill;
|
||||
|
||||
(void)ioctl(0, TIOCGETC, &old_tchars);
|
||||
rl_eof = old_tchars.t_eofc;
|
||||
rl_intr = old_tchars.t_intrc;
|
||||
rl_quit = old_tchars.t_quitc;
|
||||
|
||||
new_sgttyb = old_sgttyb;
|
||||
new_sgttyb.sg_flags &= ~ECHO;
|
||||
new_sgttyb.sg_flags |= RAW;
|
||||
(void)ioctl(0, TIOCSETP, &new_sgttyb);
|
||||
|
||||
new_tchars = old_tchars;
|
||||
new_tchars.t_intrc = -1;
|
||||
new_tchars.t_quitc = -1;
|
||||
(void)ioctl(0, TIOCSETC, &new_tchars);
|
||||
}
|
||||
else {
|
||||
(void)ioctl(0, TIOCSETP, &old_sgttyb);
|
||||
(void)ioctl(0, TIOCSETC, &old_tchars);
|
||||
}
|
||||
}
|
||||
#endif /* defined(HAVE_TERMIO) */
|
||||
#endif /* defined(HAVE_TCGETATTR) */
|
||||
|
||||
void
|
||||
rl_add_slash(path, p)
|
||||
char *path;
|
||||
char *p;
|
||||
{
|
||||
struct stat Sb;
|
||||
|
||||
if (stat(path, &Sb) >= 0)
|
||||
(void)strcat(p, S_ISDIR(Sb.st_mode) ? "/" : " ");
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: sysunix.c,v 1.4 1996/02/22 21:16:56 philip Exp $
|
||||
*/
|
68
testit.c
68
testit.c
@@ -1,68 +0,0 @@
|
||||
/* $Revision: 5 $
|
||||
**
|
||||
** A "micro-shell" to test editline library.
|
||||
** If given any arguments, commands aren't executed.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#if defined(HAVE_STDLIB)
|
||||
#include <stdlib.h>
|
||||
#endif /* defined(HAVE_STDLIB) */
|
||||
|
||||
extern char *readline();
|
||||
extern void add_history();
|
||||
|
||||
#if !defined(HAVE_STDLIB)
|
||||
extern int chdir();
|
||||
extern int free();
|
||||
extern int strncmp();
|
||||
extern int system();
|
||||
extern void exit();
|
||||
extern char *getenv();
|
||||
#endif /* !defined(HAVE_STDLIB) */
|
||||
|
||||
|
||||
#if defined(NEED_PERROR)
|
||||
void
|
||||
perror(s)
|
||||
char *s;
|
||||
{
|
||||
extern int errno;
|
||||
|
||||
(voidf)printf(stderr, "%s: error %d\n", s, errno);
|
||||
}
|
||||
#endif /* defined(NEED_PERROR) */
|
||||
|
||||
|
||||
/* ARGSUSED1 */
|
||||
int
|
||||
main(ac, av)
|
||||
int ac;
|
||||
char *av[];
|
||||
{
|
||||
char *prompt;
|
||||
char *p;
|
||||
int doit;
|
||||
|
||||
doit = ac == 1;
|
||||
if ((prompt = getenv("TESTPROMPT")) == NULL)
|
||||
prompt = "testit> ";
|
||||
|
||||
while ((p = readline(prompt)) != NULL) {
|
||||
(void)printf("\t\t\t|%s|\n", p);
|
||||
if (doit)
|
||||
if (strncmp(p, "cd ", 3) == 0) {
|
||||
if (chdir(&p[3]) < 0)
|
||||
perror(&p[3]);
|
||||
}
|
||||
else if (system(p) != 0)
|
||||
perror(p);
|
||||
add_history(p);
|
||||
free(p);
|
||||
}
|
||||
exit(0);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: testit.c,v 1.3 1996/02/22 21:18:51 philip Exp $
|
||||
*/
|
26
unix.h
26
unix.h
@@ -1,26 +0,0 @@
|
||||
/* $Revision: 5 $
|
||||
**
|
||||
** Editline system header file for Unix.
|
||||
*/
|
||||
|
||||
#define CRLF "\r\n"
|
||||
#define FORWARD STATIC
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(USE_DIRENT)
|
||||
#include <dirent.h>
|
||||
typedef struct dirent DIRENTRY;
|
||||
#else
|
||||
#include <sys/dir.h>
|
||||
typedef struct direct DIRENTRY;
|
||||
#endif /* defined(USE_DIRENT) */
|
||||
|
||||
#if !defined(S_ISDIR)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif /* !defined(S_ISDIR) */
|
||||
|
||||
/*
|
||||
* $PchId: unix.h,v 1.3 1996/02/22 21:18:51 philip Exp $
|
||||
*/
|
Reference in New Issue
Block a user