Skip to content

Commit

Permalink
Macros return to initial directory upon error
Browse files Browse the repository at this point in the history
  • Loading branch information
rneder committed Jan 16, 2025
1 parent a61f4f3 commit 02a614f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
8 changes: 4 additions & 4 deletions lib_f90/dkdo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SUBROUTINE do_loop (line, lend, length)
lblock = .false.
IF (ier_num.ne.0) THEN
IF(lmakro .AND. lmacro_close) THEN
CALL macro_close
CALL macro_close(-1)
ENDIF
ENDIF
do_macro = ' '
Expand Down Expand Up @@ -139,7 +139,7 @@ SUBROUTINE do_do_init(line, length)
lblock_read = .FALSE.
lblock = .FALSE.
IF(lmakro .AND. lmacro_close) THEN
CALL macro_close
CALL macro_close(-1)
ENDIF
do_macro = ' '
ENDIF
Expand Down Expand Up @@ -441,7 +441,7 @@ SUBROUTINE do_insert_line!(jlevel)
WRITE (ier_msg (1), 3000)
WRITE (ier_msg (2), 3100) line (1:41)
IF(lmakro .AND. lmacro_close) THEN
CALL macro_close
CALL macro_close(-1)
ENDIF
ENDIF
3000 FORMAT ('Erroneous line in block structure')
Expand Down Expand Up @@ -580,7 +580,7 @@ SUBROUTINE do_execute_block(lend)
! ier_num = -5
! ier_typ = ER_FORT
IF(lmakro .AND. lmacro_close) THEN
CALL macro_close
CALL macro_close(-1)
ENDIF
ENDIF
!
Expand Down
1 change: 1 addition & 0 deletions lib_f90/envir_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ MODULE envir_mod
CHARACTER(LEN=PREC_STRING) :: win_dir
CHARACTER(LEN=PREC_STRING) :: start_line
CHARACTER(LEN=PREC_STRING) :: current_dir
CHARACTER(LEN=PREC_STRING) :: macro_s_dir
CHARACTER(LEN=PREC_STRING) :: terminal_emu = ' '
CHARACTER(LEN=PREC_STRING) :: terminal_exe = ' '
CHARACTER(LEN=PREC_STRING) :: terminal_wrp = '/tmp/terminal_wrapper.sh'
Expand Down
2 changes: 1 addition & 1 deletion lib_f90/lib_trans.f90
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ subroutine lib_trans_menu(idata, value, laver, outfile, old_inc, old_eck, old_vi
RETURN
ELSE
IF(lmacro_close) THEN
CALL macro_close
CALL macro_close(-1)
prompt_status = PROMPT_ON
ENDIF
ENDIF
Expand Down
45 changes: 32 additions & 13 deletions lib_f90/macro.f90
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SUBROUTINE file_kdo(line, ilen)
is_stored = .false. ! assume macro does not exist in storage
IF(macro_level==0 .AND. .NOT.lmakro) THEN
sprompt = prompt ! Store prompt at top macro level start
macro_s_dir = current_dir ! Store starting directory
ENDIF
macro_level = macro_level + 1
CALL build_macro_name(line, ilen, filename, MAXW, ianz, cpara, lpara, werte)
Expand Down Expand Up @@ -153,7 +154,7 @@ SUBROUTINE file_kdo(line, ilen)
ier_num = - 12
ier_typ = ER_MAC
oprompt = prompt
CALL macro_close
CALL macro_close(-1)
IF(lblock) THEN ! If inside do/if terminate the block
lblock_dbg = .false.
lblock = .false.
Expand Down Expand Up @@ -198,7 +199,7 @@ SUBROUTINE file_kdo(line, ilen)
ier_num = - 12
ier_typ = ER_MAC
oprompt = prompt
CALL macro_close
CALL macro_close(-1)
IF(lblock) THEN ! If inside do/if terminate the block
lblock_dbg = .false.
lblock = .false.
Expand Down Expand Up @@ -317,9 +318,12 @@ SUBROUTINE build_macro_name(line, ilen, filename, MAXW, &
! --Get filename from command line and string for parameters
!
string = line
ip = INDEX (string, ' ')
string (ip:ip) = ','
if(string(1:1)/='"') then
ip = INDEX (string, ' ')
string (ip:ip) = ','
endif
length = -IABS(ilen)
!
CALL get_params (string, ianz, cpara, lpara, maxw, length)
!
! --Try to build filename
Expand Down Expand Up @@ -523,7 +527,7 @@ SUBROUTINE macro_read (line, laenge)
lmakro = .false.
lmakro_disp = .FALSE. ! Macro display error off
macro_level = 0
CALL macro_close
CALL macro_close( 0)
ELSE
mac_tree_active => mac_tree_active%parent
! DEALLOCATE(mac_tree_active%kid)
Expand Down Expand Up @@ -553,7 +557,7 @@ SUBROUTINE macro_read (line, laenge)
lmakro = .false.
lmakro_disp = .FALSE. ! Macro display error off
macro_level = 0
CALL macro_close
CALL macro_close( 0)
ELSE
mac_tree_active => mac_tree_active%parent
! DEALLOCATE(mac_tree_active%kid)
Expand Down Expand Up @@ -741,7 +745,7 @@ SUBROUTINE macro_terminate
lmakro = .false.
lmakro_disp = .FALSE. ! Macro display error off
macro_level = 0
CALL macro_close
CALL macro_close( 0)
ELSE
mac_tree_active => mac_tree_active%parent
macro_level = macro_level - 1
Expand All @@ -753,26 +757,41 @@ END SUBROUTINE macro_terminate
!
!*****7****************************************************************
!
SUBROUTINE macro_close
SUBROUTINE macro_close(ierror)
!-
! Closes the macro file, switches macro status off and sets the
! macro level back to zero.
! The macro tree is deallocated.
! In an interactive session (promot /= redirect ) the stored
! In an interactive session (prompt /= redirect ) the stored
! macros are deallocated. This allows the user to modify a macro
! and run the modified version
!+
USE class_macro_internal
use envir_mod
USE macro_mod
USE mpi_slave_mod
USE errlist_mod
USE prompt_mod
use support_mod
!
IMPLICIT none
!
integer, intent(in) :: ierror ! Macro closure du to error
!
character(len=PREC_STRING) :: line
integer :: length
!
IF(mpi_is_slave) THEN
RETURN
ENDIF
!
if(ierror<0) then
write(output_io,*) ' '
line = macro_s_dir
length = len_trim(line)
call do_chdir(line, length, .true.)
endif
!
IF(prompt_status/=PROMPT_OFF) THEN
WRITE(output_io,*) ' '
ENDIF
Expand Down Expand Up @@ -929,14 +948,14 @@ SUBROUTINE macro_continue (zeile, lcomm)
IF(str_comp(cpara(1), pname, 3, lpara(1), len_str(pname))) THEN
cprompt = prompt ! Remember current prompt, as macro close
! goes all the way back....
CALL macro_close
CALL macro_close( 0)
lmakro_dbg = .false.
prompt = cprompt ! Set current prompt as active prompt
lblock_dbg = .false.
lblock = .false.
ELSEIF(str_comp(cpara(1), 'suite', 3, lpara (1), 5)) THEN
lmakro_dbg = .false.
CALL macro_close
CALL macro_close( 0)
lblock_dbg = .false.
lblock = .false.
IF(pname /= 'suite') THEN
Expand All @@ -947,13 +966,13 @@ SUBROUTINE macro_continue (zeile, lcomm)
ier_num = - 6
ier_typ = ER_COMM
lmakro_dbg = .false.
CALL macro_close
CALL macro_close(-1)
ENDIF
ELSE
ier_num = - 6
ier_typ = ER_COMM
lmakro_dbg = .false.
CALL macro_close
CALL macro_close(-1)
ENDIF
!
END SUBROUTINE macro_continue
Expand Down

0 comments on commit 02a614f

Please sign in to comment.