Applications/Readline

From HPC
Revision as of 14:07, 27 March 2017 by Pysdlb (talk | contribs) (Created page with "__TOC__ ==Application Details== *Description: *Version: readline *Module: readline/6.3 *Licence: GNU ==Usage Examples== ===Module=== <pre style="background-color: #000000;...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation , search

Application Details

  • Description:
  • Version: readline
  • Module: readline/6.3
  • Licence: GNU

Usage Examples

Module

[username@login01 ~]$ module add readline/6.3

Compilation

readline is a library for use either with a compiled binary that requires it, or it could be required at compilation time also.

The following code is in C and must be linked against the readline library by passing a -lreadline flag to the compiler:


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

int main()
{
    char* input, shell_prompt[100];

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

    for(;;) {
        // Create prompt string from user name and current working directory.
        snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));

        // Display prompt and read input (NB: input must be freed after use)...
        input = readline(shell_prompt);

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

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

        // Do stuff...

        // Free input.
        free(input);
    }
    return 0;
}

Compilation

Further Information

http://www.boost.org/