Skip to content

Commit 468dfa1

Browse files
committed
fix command line input
1 parent 7a7839d commit 468dfa1

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_library(funcs funcs.f90)
1414
target_link_libraries(funcs PRIVATE assert reg)
1515
target_compile_options(funcs PRIVATE ${FFLAGS})
1616

17-
#------- tests
17+
#--- tests
1818
add_executable(testcalc tests/test.f90)
1919
target_link_libraries(testcalc assert funcs)
2020
target_compile_options(testcalc PRIVATE ${FFLAGS})
@@ -23,8 +23,11 @@ add_test(NAME RPNfunc COMMAND testcalc)
2323
add_library(assert tests/assert.f90 tests/error2008.f90)
2424
target_compile_options(assert PRIVATE ${FFLAGS})
2525

26+
if(UNIX)
27+
add_test(NAME UIrpn COMMAND bash -c "echo -e '2 5 * \n q' | ./rpncalc ")
28+
endif()
2629

27-
#----------------------------------
30+
#--- install
2831
if(UNIX AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
2932
set(CMAKE_INSTALL_PREFIX "~/.local/bin" CACHE PATH "..." FORCE)
3033
endif()

calc.f90

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,42 @@ PROGRAM RPN
2727
INTEGER :: I, IDX, IERR, DEL, PTR, RN, RD
2828
real(wp) :: X
2929
COMPLEX(wp) :: CX
30-
CHARACTER(LEN=300) :: LINE, SUBSTR
31-
CHARACTER(LEN=100) :: FMTSTR, NUMSTR
30+
CHARACTER(300) :: LINE, SUBSTR
31+
CHARACTER(100) :: FMTSTR, NUMSTR
3232
LOGICAL :: NUM_FLAG
3333

3434

3535
!-----------------------------------------------------------------------------------------------------------------------------------
3636

37-
print *, ' RPN Version '//VERSION
37+
print *, 'Fortran 2008 RPN Calculator, Version '//VERSION
3838

3939
!
4040
! Initialize data.
4141
!
4242

4343
DEL = IACHAR('a') - IACHAR('A') ! find ASCII position diff between 'A' and 'a'
4444

45-
STACK = 0.0D0 ! clear the REAL stack
46-
REG = 0.0D0 ! clear the REAL registers
47-
LASTX = 0.0D0 ! clear the REAL LAST X register
45+
STACK = 0._wp ! clear the REAL stack
46+
REG = 0._wp ! clear the REAL registers
47+
LASTX = 0._wp ! clear the REAL LAST X register
4848

49-
NN = 0.0D0 ! clear the REAL summation registers
50-
SUMX = 0.0D0
51-
SUMX2 = 0.0D0
52-
SUMY = 0.0D0
53-
SUMY2 = 0.0D0
54-
SUMXY = 0.0D0
49+
NN = 0._wp ! clear the REAL summation registers
50+
SUMX = 0._wp
51+
SUMX2 = 0._wp
52+
SUMY = 0._wp
53+
SUMY2 = 0._wp
54+
SUMXY = 0._wp
5555

56-
CSTACK = (0.0D0,0.0D0) ! clear the COMPLEX stack
57-
CREG = (0.0D0,0.0D0) ! clear the COMPLEX registers
58-
CLASTX = (0.0D0,0.0D0) ! clear the COMPLEX LAST X register
56+
CSTACK = (0._wp,0._wp) ! clear the COMPLEX stack
57+
CREG = (0._wp,0._wp) ! clear the COMPLEX registers
58+
CLASTX = (0._wp,0._wp) ! clear the COMPLEX LAST X register
5959

60-
CNN = (0.0D0,0.0D0) ! clear the COMPLEX summation registers
61-
CSUMX = (0.0D0,0.0D0)
62-
CSUMX2 = (0.0D0,0.0D0)
63-
CSUMY = (0.0D0,0.0D0)
64-
CSUMY2 = (0.0D0,0.0D0)
65-
CSUMXY = (0.0D0,0.0D0)
60+
CNN = (0._wp,0._wp) ! clear the COMPLEX summation registers
61+
CSUMX = (0._wp,0._wp)
62+
CSUMX2 = (0._wp,0._wp)
63+
CSUMY = (0._wp,0._wp)
64+
CSUMY2 = (0._wp,0._wp)
65+
CSUMXY = (0._wp,0._wp)
6666

6767
RNSTACK = 0; RDSTACK = 1 ! clear the RATIONAL stack
6868
RNREG = 0; RDREG = 1 ! clear the RATIONAL registers
@@ -79,11 +79,11 @@ PROGRAM RPN
7979

8080
SELECT CASE (ANGLE_MODE)
8181
CASE (1) ! deg
82-
ANGLE_FACTOR = PI/180.0D0
82+
ANGLE_FACTOR = PI/180._wp
8383
CASE (2) ! rad
84-
ANGLE_FACTOR = 1.0D0
84+
ANGLE_FACTOR = 1._wp
8585
CASE (3) ! grad
86-
ANGLE_FACTOR = PI/200.0D0
86+
ANGLE_FACTOR = PI/200._wp
8787
CASE (4) ! rev
8888
ANGLE_FACTOR = TWOPI
8989
END SELECT
@@ -105,8 +105,8 @@ PROGRAM RPN
105105
DO ! loop once for each input line
106106

107107
WRITE(stdout,'(A)', ADVANCE='NO') ' ? '
108-
READ (stdin,*, iostat=ierr) LINE
109-
if (ierr<0) stop
108+
READ (stdin,'(A132)', iostat=ierr) LINE
109+
if (ierr<0) stop ! Ctrl D was pressed
110110

111111
!
112112
! Convert the input line to all uppercase.
@@ -118,18 +118,9 @@ PROGRAM RPN
118118
LINE(I:I) = ACHAR(IACHAR(LINE(I:I)) - DEL) ! ..then convert to uppercase
119119
END IF
120120
END DO
121+
! Search for QUIT 'Q'
121122

122-
!
123-
! Search for QUIT or its equivalent.
124-
!
125-
126-
IF (TRIM(LINE) .EQ. 'QUIT') EXIT
127123
IF (TRIM(LINE) .EQ. 'Q') EXIT
128-
IF (TRIM(LINE) .EQ. 'EXIT') EXIT
129-
IF (TRIM(LINE) .EQ. 'OFF') EXIT
130-
IF (TRIM(LINE) .EQ. 'BYE') EXIT
131-
IF (TRIM(LINE) .EQ. 'STOP') EXIT
132-
IF (TRIM(LINE) .EQ. 'END') EXIT
133124

134125
PTR = 1
135126

0 commit comments

Comments
 (0)