GNU Readline

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書
GNU Readline
原作者布萊恩·福克斯
開發者Chet Ramey
首次釋出1989年,​35年前​(1989
目前版本
  • 8.2 (2022年9月26日;穩定版本)[1]
編輯維基數據連結
原始碼庫 編輯維基數據連結
程式語言C
類型
特許條款GNU通用公眾特許條款
網站tiswww.case.edu/php/chet/readline/rltop.html

GNU Readline是一個軟件庫,可為具有命令列介面(例如Bash)的互動式程式英語interactive program提供行編輯器和歷史記錄功能。是GNU計劃的一部分,目前由Chet Ramey維護。

用戶可以移動文字游標,搜尋命令歷史,控制kill ring(一個更靈活的剪貼簿),並在文字終端上使用Tab鍵自動完成。作為一個跨平臺的庫,readline允許不同系統上的應用程式展現相同的行編輯行為。

GPL特許條款

GNU Readline是一個著名的自由軟件庫,它是通過GNU通用公眾特許條款(GPL)進行授權的。而其他的自由軟件庫通常是通過GNU寬公用特許條款(LGPL)進行授權,例如GNU C庫GNU GettextFLTK[2]但其它軟件在分發時,如果連結到像GNU Readline這種GPL協定的庫,必須將與之相連的整個軟件以GPL協定進行授權,以符合GPL第5章的規定。[3][4]自由軟件基金會為GNU Readline選用了這個授權協定,以鼓勵其它軟件選用GPL協定。[5]

範例代碼

下面的代碼是C語言的,必須通過向編譯器傳遞-lreadline標誌來連結到readline庫:

#include <stdlib.h>
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>

int main()
{
    // Configure readline to auto-complete paths when the tab key is hit.
    rl_bind_key('\t', rl_complete);

    while (1) {
        // Display prompt and read input
        char* input = readline("prompt> ");

        // Check for EOF.
        if (!input)
            break;

        // Add input to readline history.
        add_history(input);

        // Do stuff...

        // Free buffer that was allocated by readline
        free(input);
    }
    return 0;
}

外部連結

  1. ^ Readline-8.2 Release available. 2022年9月26日 [2022年9月26日] (英語). 
  2. ^ GNU Lesser General Public License. The GNU Lesser General Public License v3.0 - GNU Project. Free Software Foundation. 2007 [2011-09-03]. (原始內容存檔於2018-04-04). 
  3. ^ GNU General Public License. The GNU General Public License v3.0 - GNU Project. Free Software Foundation. 2007 [2011-09-03]. (原始內容存檔於2021-02-05). 
  4. ^ Frequently Asked Questions about the GNU licenses. Frequently Asked Questions about the GNU Licenses - GNU Project. Free Software Foundation. 2010 [2011-09-03]. (原始內容存檔於2016-12-29). 
  5. ^ Why you shouldn't use the Lesser GPL for your next library. Why you shouldn't use the Lesser GPL for your next library - GNU Project - Free Software Foundation. Free Software Foundation. 2016 [2019-10-15]. (原始內容存檔於2020-12-09).