; RESREN - Rename module in RES:
; (C)1988 By Ami Bar-Yadin.
;       AMUS ID: AMI/AM
;
; Syntax:       RESREN <filename> <newname>
;       default first extension is .LIT
;       default second extension is first extension
;
;       the actual writing to RES: is done in SUPERVISOR mode
;       with JLOCK & SVLOK in effect.
;
;

VEDIT=101

;
;
; All commercial rights reserved, etc.
;
; If you want to include this program with a commercial package,
; go right ahead so long as you include the UNCHANGED source (.m68) with it.
;
; No warranties and/or guarranties of any kind, etc.
;
; Not responsible for damages resulting from the use of this program, etc.
;
; My employer (United Fashions) has nothing to do with this program and
; should not be blamed for it.
;
; I can be reached at:
;               United Fashions of Texas, Inc.
;               200 Ash Ave.
;               McAllen, TX  78501
;               (512) 631-2277/2276
;               8am-6pm
;
       SYM
       SEARCH  SYS
       SEARCH  SYSSYM
       RADIX   16.
       DEFAULT VEDIT,1
       DEFAULT $$MFLG,PV$RSM!PV$WSM
       DEFAULT $$SFLG,PH$REE!PH$REU
       DEFAULT $$SFLG,0
       DEFAULT $$LFLG,-1
       PHDR    $$LFLG,$$MFLG,$$SFLG

; some symbols

M.NAM  =        6
M.EXT  =        10.

; some macros

DEFINE IMPINI  START
       DSECT
       IF B,START,     .=0
       IF NB,START,    .=START
ENDM
                               ; define label
DEFINE IMPDEF  LBL,SIZE
       IF NB,SIZE
LBL:    BLKB    SIZE
       IFF
LBL:    BLKB    0
       ENDC
ENDM
                               ; define size label
DEFINE IMPSIZ  LBL
       IF NB,LBL
LBL:
       ENDC
       PSECT
ENDM


DEFINE  IMPGET  SIZE,IDX,NOMEM,MODNM1,MODNM2,MODEXT
       PUSH    SIZE            ;(MAC:SYS.M68:  PUSH #SIZE)
       PUSH
       GETMEM  @SP
       IF      B,NOMEM
       BEQ     10$$
       EXIT
   10$$:
       IFF
       JNE     NOMEM
       ENDC
       POP     IDX
       POP
       IF      NB,MODNM1,      MOVW    #[MODNM1],M.NAM-ZID(IDX)
       IF      NB,MODNM2,      MOVW    #[MODNM2],M.NAM+2-ZID(IDX)
       IF      NB,MODEXT,      MOVW    #[MODEXT],M.EXT-ZID(IDX)
       ENDM
                               ; allocate memory


; start of code

RESREN:
       GETIMP  SIZIMP,A5,,RES,REN,IMP  ; allocate impure storage

       BYP
       LIN
       JEQ     HELP                    ; display help if no arguments

       FSPEC   DDB(A5),LIT             ; get file spec

       CALL    FNDMOD                  ; find RES: module, abort if not found

       CLR     D6
       MOVW    D.EXT+DDB(A5),D6        ; get default extension
       FSPEC   DDB2(A5)                ; get new file spec


; lock system
       JLOCK                           ; suspend timesharing
       SUPVR                           ; enter SUPERVISOR mode
       SVLOK                           ; disable interrupts


       TST     D.FIL+DDB2(A5)
       BEQ     10$                     ; file name blank, skip it
       MOV     D.FIL+DDB2(A5),M.NAM-ZID(A0)
10$:
       TSTW    D.EXT+DDB2(A5)
       BEQ     20$                     ; file name blank, skip it
       MOVW    D.EXT+DDB2(A5),M.EXT-ZID(A0)
20$:


; unlock system
       SVUNLK                          ; enabled interrupts
       LSTS    #0                      ; exit SUPERVISOR mode
       JUNLOK                          ; resume timesharing


       TYPE    <RES:>
       OFILE   DDB(A5),OT$TRM!OT$OFN
       TYPE    < module renamed to >
       OFILE   DDB2(A5),OT$TRM
       CRLF
       EXIT


FNDMOD:
       SRCH    D.FIL+DDB(A5),A0,0      ; search for memory module
       JNE     ERR1                    ; abort if module not found
       USRBAS  A1                      ; get start of user's memory
       CMP     A0,A1
       JHIS    ERR2                    ; abort if module is in MEM:
       RTN


; ERROR MESSAGES

ERR1:   TYPE    <?Memory module >
       OFILE   DDB(A5),OT$TRM!OT$OFN
       TYPECR  < not found.>
       EXIT

ERR2:   TYPE    <?Memory module >
       OFILE   DDB(A5),OT$TRM!OT$OFN
       TYPECR  < is in MEM: instead of RES:>
       EXIT


HELP:
       TYPECR  <Syntax:        RESREN filename newname>
       TYPECR  <       default first extension is .LIT>
       TYPECR  <       default second extension is first extension>
       EXIT

;
;

       IMPINI
       IMPDEF  DDB,D.DDB               ; DDB
       IMPDEF  DDB2,D.DDB              ; DDB
       IMPSIZ  SIZIMP
;
;
       END