home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
newc_dev
/
rename12.lha
/
Rename.asm
< prev
next >
Wrap
Assembly Source File
|
1990-11-19
|
3KB
|
191 lines
OPTION NL
*\
** Noerrebro, 19.XI.90
** Rename V1.2:
** ¯¯¯¯¯¯¯¯¯¯¯¯
** Written mostly for the pleasure, this program does the same as the Amiga-
** DOS command by the same name and is fully re-entrant using the 'Resident'
** command.
**
** SYNTAX: Rename <oldName [AS] newName>
**
** 'Rename' is written for the Asm68K Macro Assembler and placed in Public
** Domain as FREEWARE. Please leave this header intact and let the source go
** along with ANY distribution - thanks!
**
** Keep shinin'! _
** - Klaus. _ //
** \X/ (FidoNet 2:230/114.15)
**
**
** # -= Rename V1.2 =-
** # Written in November '90 by
** # Klaus Alexander Seistrup 01.X.90 - 31.III.91:
** # H/F 1. Maj, Have #14 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
** # Islevdalvej 162 Sct Hansgades Passage 9, 4.th.
** # DK-2610 Roedovre DK-2200 Koebenhavn N
** # D E N M A R K D E N M A R K
**
*/
AbsExecBase EQU $0004
OldOpenLibrary EQU -$0198 ; A1
CloseLibrary EQU -$019E ; A1
RawDoFmt EQU -$020A ; A0/A1/A2/A3
Output EQU -$003C ; VOID
Write EQU -$0030 ; D1/D2/D3
Rename EQU -$004E ; D1/D2
MAXARGS EQU 3
TAB EQU $09
LINEFEED EQU $0A
SPACE EQU $20
QUOTE EQU $22
LINKSIZE EQU -256
oldName EQU LINKSIZE
newName EQU oldName + $04
Dummy EQU newName + $04
outBuf EQU Dummy + $04
DOSBase EQUR A4
ExecBase EQUR A6
SAVEREGS REG D2-D3/D6-D7/A2-A4/A6
*----- Macros
CALLSYS MACRO
JSR \1(ExecBase)
ENDM
CALLDOS MACRO
JSR \1(DOSBase)
ENDM
STRING MACRO
DC.B \1
DC.B 0
CNOP 0, 2
ENDM
*----- Code
OPTION L
Main LINK A5, #LINKSIZE
MOVEM.L SAVEREGS, -(SP)
CLR.B -1(A0, D0.W)
LEA LINKSIZE(A5), A3
MOVEA.L A3, A1
Parse MOVEQ #TAB, D0
MOVEQ #LINEFEED, D1
MOVEQ #SPACE, D2
MOVEQ #QUOTE, D3
MOVEQ #0, D6
MOVEQ #MAXARGS, D7 ; argc = NULL
BRA.S 2$
1$ ADDQ.W #1, A0 ; cmd++
2$ CMP.B (A0), D0 ; TAB?
BEQ.S 1$
CMP.B (A0), D1 ; SPACE?
BEQ.S 1$
CMP.B (A0), D2 ; LINEFEED?
BEQ.S 1$
TST.B (A0) ; EOS?
BEQ.S GetDOS(PC)
ADDQ.W #1, D6 ; argc++
CMP.B (A0), D3 ; QUOTE?
BNE.S 5$
ADDQ.W #1, A0 ; Point inside quoted string:
MOVE.L A0, (A1)+ ; *argv++ = ++cmd
BRA.S 4$
3$ ADDQ.W #1, A0
4$ TST.B (A0) ; EOS?
BEQ.S Done(PC) ; Unbalanced quotes
CMP.B (A0), D3 ; QUOTE?
BNE.S 3$
BRA.S 8$
5$ MOVE.L A0, (A1)+ ; *argv++ = cmd
BRA.S 7$
6$ ADDQ.W #1, A0
7$ TST.B (A0) ; EOS?
BEQ.S GetDOS(PC)
CMP.B (A0), D0 ; TAB?
BEQ.S 8$
CMP.B (A0), D1 ; LINEFEED?
BEQ.S 8$
CMP.B (A0), D2 ; SPACE?
BNE.S 6$
8$ CLR.B (A0)+ ; Terminated arg
CMP.B D7, D6
BLT.S 2$
GetDOS LEA DOSName(PC), A1
MOVEA.L AbsExecBase, A6
CALLSYS OldOpenLibrary
BEQ.S Done(PC)
MOVEA.L D0, DOSBase
Test CMPI.B #2, D6
BEQ.S DoIt(PC)
BGT.S ReArr(PC)
Info LEA Usage(PC), A3
BRA.S Puts(PC)
ReArr MOVE.L 8(A3), 4(A3)
DoIt MOVE.L (A3)+, D1
MOVE.L (A3)+, D2
CALLDOS Rename
BNE.S ExDOS(PC)
Error LEA ErrFmt(PC), A0
MOVEA.L A3, A1
SUBQ.W #8, A1
LEA PrBuf(PC), A2
CALLSYS RawDoFmt
Puts MOVE.L A3, D2
MOVEQ #-1, D3
1$ TST.B (A3)+ ; while (*str++)
DBEQ D3, 1$ ; len--
NOT.L D3 ; ~(-len) == len-1
CALLDOS Output
CALLDOS Write ; Flush it
ExDOS MOVEA.L DOSBase, A1
CALLSYS CloseLibrary
Done MOVEQ #0, D0
MOVEM.L (SP)+, SAVEREGS
UNLK A5
RTS
PrBuf MOVE.B D0, (A3)+
RTS
*----- Data
DOSName STRING 'dos.library'
Usage DC.B $9B
DC.B '33mUSAGE:'
DC.B $9B
STRING '0m Rename <oldName [AS] newName>\10'
ErrFmt STRING 'Couldn\39t rename %s as %s\10'
PgmID DC.L $536C55C8 ; V1.2, 19.XI.90
END