GNU Readline

軟件庫,通過命令行界面為交互式程序提供行編輯和歷史記錄功能

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

GNU Readline
原作者布萊恩·福克斯
開發者Chet Ramey
首次發布1989年,​35年前​(1989
當前版本
  • 8.2 (2022年9月26日;穩定版本)[1]
編輯維基數據鏈接
源代碼庫 編輯維基數據鏈接
編程語言C
類型
許可協議GNU通用公共許可證
網站tiswww.case.edu/php/chet/readline/rltop.html

用戶可以移動文本光標,搜索命令歷史,控制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).