• Stars
    star
    254
  • Rank 160,264 (Top 4 %)
  • Language
    C
  • License
    Other
  • Created over 14 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A small replacement for GNU readline() for UNIX

Editline

License Badge Travis Status Coverity Status

Table of Contents

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 (ncurses not 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 supplying different options to the GNU configure script. See the output from configure --help for details. Some useful hints on how to use the library is available in the examples/ directory.

Editline is maintained collaboratively at GitHub.

Note: Windows is not a supported target for editline.

Example

Below is a very brief example to illustrate how one can use Editline to create a simple CLI, Ctrl-D exits the program. A slightly more advanced example is Jush, https://github.com/troglobit/jush/, a small and very simplistic UNIX shell. The Editline sources also include an examples/ sub-directory.

  1. Build and install the library, preferably using a release tarball The configure script defaults to a /usr/local prefix.

     tar xf editline-1.15.3.tar.xz
     cd editline-1.15.3/
     ./configure --prefix=/usr
     make all
     sudo make install
    
  2. Place the below source code in a separate project directory, e.g. ~/src/example.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <editline.h>

    int main(void)
    {
        char *p;

        while ((p = readline("CLI> ")) != NULL) {
            puts(p);
            free(p);
        }

        return 0;
    }
  1. Compile the example:

     cd ~/src/
     make LDLIBS=-leditline example
    

Here I use make and rely on its implicit (built-in) rules to handle all the compiler magic, but you may want to create your own Makefile for the project. In particular if you don't change the default prefix (above), because then you need to specify the search path for the include file(s) and the library manually.

A simple ~/src/Makefile could look like this:

CFLAGS    = -I/usr/local/include
LDFLAGS   = -L/usr/local/lib
LDLIBS    = -leditline
EXEC      = example
OBJS      = example.o

all: $(EXEC)

$(EXEC): $(OBJS)

clean:
        $(RM) $(OBJS) $(EXEC)

distclean: clean
        $(RM) *.o *~ *.bak

Then simply type make from your ~/src/ directory. You can also use pkg-config for your ~/src/Makefile, replace the following lines:

CFLAGS    = $(shell pkg-config --cflags libeditline)
LDFLAGS   = $(shell pkg-config --libs-only-L libeditline)
LDLIBS    = $(shell pkg-config --libs-only-l libeditline)

Then simply type make, like above.

However, most .rpm based distributions pkg-config doesn't search in /usr/local anymore, so you need to call make like this:

PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig make

Debian/Ubuntu based systems do not have this problem.

API

Here is the libeditline interfaces. It has a small compatibility layer to FSF readline, which may not be entirely up-to-date.

    /* 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_deprep_term_function)(void);
    void rl_deprep_terminal (void);
    void rl_reset_terminal  (const char *terminal_name);

    void rl_initialize   (void);
    void rl_uninitialize (void);                         /* Free all internal memory */

    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);
    
    /* Alternate interface to plain readline(), for event loops */
    void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler);
    void rl_callback_read_char       (void);
    void rl_callback_handler_remove  (void);

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. Call ./autogen.sh if you build from git
  2. Configure editline with default features: ./configure
  3. Build the library and examples: make all
  4. Install using make install

The $DESTDIR environment variable is honored at install. For more options, see ./configure --help

Remember to run ldconfig after install to update the linker cache. If you've installed to a non-standard location (--prefix) you may also have to update your /etc/ld.so.conf, or use pkg-confg to build your application (above).

NOTE: RedHat/Fedora/CentOS and other .rpm-based distributions do not consider /usr/local as standard path anymore. So make sure to ./configure --prefix=/usr, otherwise the build system use the GNU default, which is /usr/local. The Debian based distributions, like Ubuntu, do not have this problem.

Origin & References

This line editing library was created by Rich Salz and Simmule Turner and in 1992. It is distributed with a “C News-like” license, similar to the BSD license. Rich's current 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 2 source tree and is not related to the similarily named NetBSD version that Jess Thrysøe 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, based on the original comp.sources.unix posting, have been merged:

The version numbering scheme today follows that of the Debian version, details available in the ChangeLog.md. The current maintainer was unaware of the Debian version for quite some time, so a different name and 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.

More Repositories

1

inadyn

In-a-Dyn is a dynamic DNS client with multiple SSL/TLS library support
C
782
star
2

finit

Fast init for Linux. Cookies included
C
576
star
3

redir

A TCP port redirector for UNIX
C
349
star
4

mg

Micro (GNU) Emacs-like text editor ❤️ public-domain
C
293
star
5

libuev

Lightweight event loop library for Linux epoll() family APIs
C
218
star
6

smcroute

Static multicast routing for UNIX
C
216
star
7

pimd

PIM-SM/SSM multicast routing for UNIX and Linux
C
194
star
8

watchdogd

Advanced system monitor & process supervisor for Linux
C
193
star
9

uftpd

FTP/TFTP server for Linux that just works™
C
162
star
10

mcjoin

Simple multicast testing application
C
130
star
11

merecat

Small and made-easy HTTP/HTTPS server based on Jef Poskanzer's thttpd
C
129
star
12

tetris

Micro Tetris™, based on the 1989 IOCCC Obfuscated Tetris by John Tromp
C
107
star
13

uredir

A UDP port redirector for UNIX
C
87
star
14

myLinux

myLinux is an embedded operating system based on Buildroot and Finit
Shell
73
star
15

sysklogd

BSD syslog daemon with syslog()/syslogp() API replacement for Linux, RFC3164 + RFC5424
C
71
star
16

mtools

Tools for multicast testing (msend and mreceive). I do however recommend you try out mcjoin(!) or mping instead.
C
69
star
17

mrouted

The original DVMRP (dynamic multicast routing) implementation for UNIX
C
65
star
18

mini-snmpd

A minimal SNMP agent implementation
C
63
star
19

netcalc

Simplified clone of sipcalc with ipcalc looks
C
60
star
20

xplugd

Monitor, keyboard, and mouse plug/unplug helper for X
C
59
star
21

libite

That missing frog DNA you've been looking for
C
58
star
22

ssdp-responder

SSDP responder for UNIX systems that gives you an InternetGatewayDevice icon in Windows :)
C
53
star
23

mdnsd

Jeremie Miller's original mdnsd
C
49
star
24

sntpd

sntpd is a fork of Larry Doolittle's ntpclient with added daemon, syslog, and IPv6 support
C
42
star
25

adventure

Classic Colossal Cave Adventure
C
42
star
26

omping

Open Multicast Ping (omping) is a tool for testing IPv4/IPv6 multicast connectivity on a LAN.
C
33
star
27

snake

Micro Snake, based on Simon Huggins snake game.
C
30
star
28

pok3r-layouts

Vortex POK3R keyboard layouts for Linux, Windows and OS X/macOS. Based on:
28
star
29

rfctl

Linux driver and control tool for 433 MHz communication on Raspberry Pi
C
25
star
30

sun

Simple library and application that shows sunset and sunrise based on your latitude,longitude
C
23
star
31

jush

just give me a unix shell
C
22
star
32

lipify

C API for http://ipify.org
C
19
star
33

pim6sd

PIM for IPv6 sparse mode daemon
C
19
star
34

tinyroot

Small busybox based embedded Linux root file system
Makefile
17
star
35

mping

A simple multicast ping program
C
17
star
36

pimd-dense

Continuation of the original pimd-dense from 1998-1999, gaps filled with frog DNA from pimd
C
14
star
37

pev

Portable Event Library
C
14
star
38

libicmp

Very simple library for sending and receiving ICMP datagrams.
C
13
star
39

backlight

Very simple program to control the backlight brightness of a laptop
C
13
star
40

getty

Minix getty
C
10
star
41

pacman

UNIX pacman game by Dave Nixon, AGS Computers Inc. (1981) with curses support by Mark Horton (1982)
C
10
star
42

uget

Really stupid get-file-over-http program/function
Shell
10
star
43

toolbox

Misc. home brewed code, free to use under GPL/MIT/ISC, see each snippet for license.
C
9
star
44

mrdisc

Stand alone UNIX implementation of RFC4286 Multicast Router Discovery Protocol
C
9
star
45

uemacs

MicroEMACS by Dave Conroy
C
8
star
46

aliens

UNIX aliens game by Jude Miller, Cambridge (1979) with curses support by Mark Horton (1981)
C
7
star
47

nlmon

Simple example of how to use libnl and libev to monitor kernel netlink events
C
7
star
48

quagga

Westermo Quagga. See security/0.99.17 branch for ported CVE fixes and westermo/0.99.17 for patches on top of that. For more information, see the Wiki.
C
7
star
49

keepalived

Health-checking for LVS and high availability
C
6
star
50

ttinfo

Display information about a process, group or tty
C
6
star
51

awesome-config

My awesome window manager configuration
Lua
5
star
52

finit-plugins

Plugin Repository for Finit
C
5
star
53

zoo

public domain zoo archive tool
C
5
star
54

logit

tiny log helper
C
5
star
55

MicroEMACS

MicroEMACS v3.6 by Dave Conroy and Daniel Lawrence from 1986. Free in the public domain.
C
5
star
56

cx

Small wrapper for basic lxc tasks
Shell
5
star
57

awesome-redshift

Ryan Young's small, simple lua library for interfacing the Awesome window manager with redshift
Lua
5
star
58

crobots

CROBOTS is a programming game, for (aspiring) programmers
C
5
star
59

gul

The one true GUL editor!
C
5
star
60

awesome-plain

Plain barebones AwesomeWM setup
Lua
4
star
61

usbctl

A user space tool to operate on USB devices.
C
4
star
62

mctools

Collection of (old) multicast tools
C
4
star
63

deb

Signing key(s) for .deb repository
3
star
64

booz

Zoo Extractor/Lister by Rahul Dhesi
C
3
star
65

sniffer

sniff packets from interface store in db for analysis
C
3
star
66

zroute

Very simple command line client for managing Zebra static routes from the command line. Useful if Zebra is your route manager and you want your DHCP client, or PPPoE client, to set default gateway dynamically via Zebra instead of as kernel routes.
C
3
star
67

libc-chaos

Emit random errors when calling libc functions to emulate an unstable underlying system
C
3
star
68

misc

Misc. helpers, in the public domain
Makefile
2
star
69

alpine-qemu-image

Create bootable Qemu images fro Alpine Linux ISO
Shell
2
star
70

ns

Example of how to use getaddrinfo()
C
2
star
71

awesome-light

Lua library for controlling screen and keyboard brightness from Awesome WM
Lua
2
star
72

plotty

Library for text terminal plotter
C
2
star
73

klish-plugin-sysrepo

Mirror of Serj Kalichev's klish plugins for sysrepo
C
2
star
74

faux

Mirror of Serj Kalichev's auxillary functions library
C
2
star
75

troglobit.github.io

Personal website and blog
CSS
2
star
76

demo

Collection of ASCII art demos
C
1
star
77

ubot

very small and stupid irc bot
C
1
star
78

awesome

My awesome-copycats adaptions
Lua
1
star
79

logrun

An event-based, regexp-triggered, job runner ...
Perl
1
star
80

klish

Mirror of Serj Kalichev's klish
C
1
star
81

br2-finit-demo

Demo of Finit (FastInit) in Buildroot
Makefile
1
star
82

zephyr-uart-test

Playground for the Zephyr UART
C
1
star
83

busybox-builder

busybox defconfig++ binaries
Shell
1
star
84

bridged

Linux bridge helper daemon
C
1
star
85

weatherd

Hackish weather data logger for my homemade Raspberry Pi based weather station
C
1
star