Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GNU Readline functionality to command prompt #48

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/Makeinc.common_linux
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ LIBAODT = $(OS_LIB)/libaodt.a
LIBGPC = $(OS_LIB)/libgpc.a
LIBNCEPBUFR = $(OS_LIB)/libncepBUFR.a

LIBREADLINE = -lreadline

BUFRFLAGS = -O

HAVEMOTIF = yes
Expand Down
3 changes: 2 additions & 1 deletion gempak/source/contrib/awc/gdmlev/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ LIBINC = \
$(CGEMLIB) \
$(ZLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
3 changes: 2 additions & 1 deletion gempak/source/contrib/awc/gpanot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ LIBINC = \
$(XMLLIB) \
$(ZLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
3 changes: 2 additions & 1 deletion gempak/source/contrib/awc/gpltln/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ LIBINC = \
$(XMLLIB) \
$(ZLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
3 changes: 2 additions & 1 deletion gempak/source/contrib/awc/gpmxplt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ LIBINC = \
$(XMLLIB) \
$(ZLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
9 changes: 6 additions & 3 deletions gempak/source/contrib/awc/gprcm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ LIBINC = \
$(ZLIB) \
$(CGEMLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

LIBINC_NC = \
$(GPLT_NC) \
Expand All @@ -55,7 +56,8 @@ LIBINC_NC = \
$(ZLIB) \
$(CGEMLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

LIBINC_GF = \
$(GPLT_NC) \
Expand All @@ -73,7 +75,8 @@ LIBINC_GF = \
$(ZLIB) \
$(CGEMLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

PROG = $(PROG.f:.f=)
PROG_NC = $(PROG.f:.f=_nc)
Expand Down
3 changes: 2 additions & 1 deletion gempak/source/contrib/cpc/cpcgstn/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ LIBINC = \
$(CGEMLIB) \
$(GPLT) \
$(DEVICE) \
$(GN)
$(GN) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
6 changes: 4 additions & 2 deletions gempak/source/gemlib/ip/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ include $(CONFIGDIR)/$(MAKEINC)
ALIB = $(GEMLIB)

FOBJS = \
$(ALIB)(rlgets.o) \
$(ALIB)(ipread.o) \
$(ALIB)(ipcwin.o) \
$(ALIB)(ipdflt.o) \
$(ALIB)(ipdynm.o) \
Expand All @@ -34,7 +36,7 @@ FOBJS = \
$(ALIB)(ipsvar.o) \
$(ALIB)(ipswin.o) \
$(ALIB)(ipvers.o)

GDIR = ip

.PRECIOUS: $(ALIB)
Expand All @@ -48,7 +50,7 @@ $(ALIB): $(FOBJS)
.c.a :
$(CC) $(CFLAGS) -c $<
.f.a :
$(FC) $(FFLAGS) -c $<
$(FC) $(FFLAGS) -J$(OS_INC) -c $<


clean:
Expand Down
11 changes: 4 additions & 7 deletions gempak/source/gemlib/ip/ipdynm.f
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ SUBROUTINE IP_DYNM ( done, iret )
C* D.W.Plummer/NCEP 6/97 Increased string lengths from 80 to 164 *
C* C. Bailey/HPC 1/05 Added GSAVE option *
C* S. Jacobs/NCEP 3/13 Allow mixed case for restoring NTS files*
C* S. Decker/Rutgers 7/20 Use GNU Readline for prompt *
C************************************************************************
USE IP_READ
INCLUDE 'ipcmn.cmn'
C*
LOGICAL done, resp
Expand Down Expand Up @@ -75,13 +77,8 @@ SUBROUTINE IP_DYNM ( done, iret )
C
more = .true.
DO WHILE ( more )
WRITE ( 6, 1000 ) tutor ( 1 : lent )
1000 FORMAT ( 1X, A, $ )
READ ( 5, 1001, IOSTAT = iostat ) input
1001 FORMAT ( A )
IF ( iostat .ne. 0 ) input = 'EXIT'

C
CALL GET_INPUT_LINE ( tutor ( 1 : lent ), input )
C
C* Check whether the user wants to exit or run program.
C
CALL ST_LDSP ( input, input, nc, ier )
Expand Down
56 changes: 56 additions & 0 deletions gempak/source/gemlib/ip/ipread.f
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
MODULE IP_READ
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_NULL_CHAR,
+ C_PTR, C_F_POINTER
IMPLICIT NONE

INTERFACE
SUBROUTINE RL_GETS(prompt, line) BIND(C, NAME="rl_get")
IMPORT :: C_CHAR, C_PTR
CHARACTER(KIND=C_CHAR), DIMENSION(*) :: prompt
TYPE(C_PTR) :: line
END SUBROUTINE RL_GETS
END INTERFACE

CONTAINS

SUBROUTINE GET_INPUT_LINE(p, c)
C**********************************************************************
C* GET_INPUT_LINE *
C* *
C* This subroutine uses the GNU Readline library to provide the *
C* GEMPAK prompt with bash/emacs-type features. The arrow keys *
C* work, for instance. *
C* *
C* GET_INPUT_LINE ( p, c ) *
C* *
C* Input parameters: *
C* p CHARACTER(*) Prompt text *
C* *
C* Output parameters: *
c* c CHARACTER(*) String input by user *
C** *
C* Log: *
C* S. Decker/Rutgers 7/20 *
C**********************************************************************
CHARACTER(*), INTENT(IN) :: p
CHARACTER(*), INTENT(OUT) :: c

CHARACTER(KIND=C_CHAR, LEN=LEN(p)+1) :: prompt
TYPE(C_PTR) :: res
CHARACTER, POINTER, DIMENSION(:) :: cp
INTEGER :: n, i
c------------------------------------------------------------------
n = LEN(c)
prompt = p // C_NULL_CHAR

CALL RL_GETS(prompt, res)
CALL C_F_POINTER(res, cp, [n])

c = ""
DO i = 1, n
IF (cp(i) == C_NULL_CHAR) EXIT
c(i:i) = cp(i)
END DO

END SUBROUTINE GET_INPUT_LINE
END MODULE IP_READ
44 changes: 44 additions & 0 deletions gempak/source/gemlib/ip/rlgets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
#include "readline/readline.h"
#include "readline/history.h"

/* A static variable for holding the line. */
static char *line_read = (char *)NULL;

void rl_get (char* prompt, char** line)
/**************************************************************
* rl_get *
* *
* This function reads a string using the GNU Readline *
* library, and returns a pointer to it. Returns NULL on *
* EOF. *
* *
* void rl_get ( prompt, line ) *
* *
* Input parameters: *
* *prompt char Prompt text *
* *
* Output parameters: *
* **line char User input *
** *
* S. Decker/Rutgers 9/19 *
*************************************************************/
{
/* If the buffer has already been allocated,
return the memory to the free pool. */
if (line_read)
{
free (line_read);
line_read = (char *)NULL;
}

/* Get a line from the user. */
line_read = readline (prompt);

/* If the line has any text in it, save it to history. */
if (line_read && *line_read)
add_history (line_read);

*line = line_read;
}
3 changes: 2 additions & 1 deletion gempak/source/programs/gd/gd2img/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ LIBINC = \
$(PNGLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

OBJS = gdptin.o gdpttm.o gdptup.o gd2img.o dgconav.o gdcnav.o gdcanl.o \
gdlgin.o writepng.o
Expand Down
3 changes: 2 additions & 1 deletion gempak/source/programs/gd/gdbiint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ LIBINC = \
$(PNGLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

all : $(ALIB) $(PROG)

Expand Down
3 changes: 2 additions & 1 deletion gempak/source/programs/gd/gdcfil/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ LIBINC = \
$(XMLLIB) \
$(ZLIB) \
$(GEMLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
9 changes: 6 additions & 3 deletions gempak/source/programs/gd/gdcntr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ LIBINC = \
$(ZLIB) \
$(CGEMLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

LIBINC_NC = \
$(GPLT_NC) \
Expand All @@ -53,7 +54,8 @@ LIBINC_NC = \
$(ZLIB) \
$(CGEMLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

LIBINC_GF = \
$(GPLT_NC) \
Expand All @@ -72,7 +74,8 @@ LIBINC_GF = \
$(ZLIB) \
$(CGEMLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

PROG_NC = $(PROG)_nc
PROG_GF = $(PROG)_gf
Expand Down
9 changes: 6 additions & 3 deletions gempak/source/programs/gd/gdcross/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ LIBINC = \
$(PNGLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

LIBINC_NC = \
$(GPLT_NC) \
Expand All @@ -65,7 +66,8 @@ LIBINC_NC = \
$(GEMLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

LIBINC_GF = \
$(GPLT_NC) \
Expand All @@ -81,7 +83,8 @@ LIBINC_GF = \
$(GEMLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

PROG_NC = $(PROG)_nc
PROG_GF = $(PROG)_gf
Expand Down
3 changes: 2 additions & 1 deletion gempak/source/programs/gd/gdcsv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ LIBINC = \
$(ZLIB) \
$(CGEMLIB) \
$(RSLLIB) \
$(LIBBZ2)
$(LIBBZ2) \
$(LIBREADLINE)

OBJS = gdptin.o gdpttm.o gdcsv.o gdpout.o dgconav.o \
cwrapgcalc.o cwrapgcalcf.o
Expand Down
3 changes: 2 additions & 1 deletion gempak/source/programs/gd/gddelt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ LIBINC = \
$(GEMLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
3 changes: 2 additions & 1 deletion gempak/source/programs/gd/gddiag/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ LIBINC = \
$(PNGLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
1 change: 1 addition & 0 deletions gempak/source/programs/gd/gdedit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ LIBINC = \
$(GEMLIB)\
$(LIBJASPER) \
$(PNGLIB) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
3 changes: 2 additions & 1 deletion gempak/source/programs/gd/gdfrzl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ LIBINC = \
$(PNGLIB) \
$(XMLLIB) \
$(ZLIB) \
$(CGEMLIB)
$(CGEMLIB) \
$(LIBREADLINE)

.PRECIOUS: $(ALIB)

Expand Down
Loading