C Library Functions  - system_readline (3)

NAME

system_readline(3f) - [M_readline] Call readline(3c) from Fortran (LICENSE:PD)

CONTENTS

Synopsis
Description
Examples
Author
License

SYNOPSIS

character(kind=c_char,len=*),intent(in) :: prompt character(kind=c_char,len=*),intent(out) :: line

DESCRIPTION

The system_readline(3f) uses the ISO_C_BINDING module to create a binding to the GNU readline(3c) procedure from Fortran programs.

EXAMPLES

The test program is basically just a read loop that prompts for lines of input read with readline(3c). You can edit the line being read with readline(3c) per its documentation. At a minimum, you can probably move around the line with the left and right arrow keys, and insert characters by typing them wherever you moved the cursor to, and use the DEL/ RUBOUT key to delete characters and such. If you use a GNU/Linux shell with command line editing, you are probably familiar with readline(3c)’s function.

It quits if you enter ’q’ on an input line, and it dumps the history if you enter ’h’.

It is presented here as a Bourne shell script that creates the necessary files and does a "compile, load, and go"

the test program

   program demo_system_readline
   use M_readline, only : system_readline
   implicit none
   character(len=4096) :: line
   integer             :: cstat
   character(len=256)  :: sstat
      call intro()

do call system_readline(line,’readline>’) ! read editable input line if(line.eq.’q’) then stop elseif(line.eq.’?’) then call intro() else call execute_command_line(trim(line),cmdstat=cstat,cmdmsg=sstat) endif enddo

contains subroutine intro() integer :: i character(len=*),parameter :: help_text(*)=[character(len=80) :: & ’--------------------------------------------------------------------------------’ ,& ’ Your input lines are now editable using the GNU readline(3c) procedure.’ ,& ’ By default, up-arrow and down-arrow go through the history lines; left and ’ ,& ’ and right arrow keys and the delete key and just typing characters let you do’ ,& ’ simple editing. Far more input control is available. See the mon(1) page for’ ,& ’ readline(3c) for more information.’ ,& ’ --------------------------------------------------------------------------------’,& ’ "q" quits; "h" display history, "?" displays this help text’ ,& ’ Enter commands and then edit them...’ ,& ’ ’ ] write(*,’(a)’)(trim(help_text(i)),i=1,size(help_text)) end subroutine intro end program demo_system_readline

AUTHOR

John S. Urban

LICENSE

Public Domain

Although this interface to readline(3c) is released as Public Domain, note that the Readline library itself is free software, distributed under the terms of the [GNU] General Public License, version 2.


Nemo Release 3.1 system_readline (3) August 28, 2026
Generated by manServer 1.08 from 68f34036-ce15-42a2-9002-ec47238282fe using man macros.