home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
ucpbtm10.exe
/
UCOMPBTM.8
< prev
next >
Wrap
Text File
|
1993-12-23
|
8KB
|
440 lines
; UCOMPBTM 4dos compressed .BTM decompressor
; Copyright (C) 1933 Christopher Hall
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program, as the file COPYING.DOC; if not, write to the
; Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; I may be contacted by e-mail as cah17@phx.cam.ac.uk, or by paper mail at
; Christ's College, Cambridge, CB2 3BU, England
main:
jmp start
common_chars equ main-2
help:
mov dx,t_help
jmp error_exit
check_space:
cmp al,' '
je ret
cmp al,9
je ret
cmp al,'='
je ret
cmp al,';'
ret
parse:
mov si,081
xor bx,bx ;input filename
xor cx,cx ;output filename
xor dl,dl ;no /O found
l0:
lodsb
call check_space
je l0
cmp al,0d
je ret
cmp al,'/'
jne >l1
cmp b[si],'?'
je help
cmp b[si],'o'
je >l2
cmp b[si],'O'
jne >l1
l2:
mov al,b[si+1]
cmp al,0d
je help
call check_space
mov al,'/'
jne >l1
mov dl,1
add si,2
l0:
lodsb
call check_space
je l0
cmp al,0d
je help
l1:
lea bx,[si-1]
l0:
lodsb
cmp al,0d
je >l1
call check_space
jne l0
l1:
mov b[si-1],0
cmp al,0d
je >l9
l0:
lodsb
call check_space
je l0
cmp al,0d
je >l9
lea cx,[si-1]
l0:
lodsb
cmp al,0d
je >l1
call check_space
jne l0
l1:
mov b[si-1],0
l9:
jcxz >l1
ret
l1:
mov cx,di,si
mov si,bx
xor bp,bp ;position after dot.
l0:
lodsb
stosb
or al,al
je >l1
cmp al,'\'
if e xor bp,bp
cmp al,'.'
if e mov bp,di
jmp l0
l1:
or bp,bp
jnz >l1
dec di
mov al,'.'
stosb
jmp >l2
l1:
mov di,bp
l2:
mov ax,[di]
and ax,0dfdf
cmp ax,'AB'
jne >l1
mov al,[di+2]
and al,0df
cmp al,'T'
je same_name
l1:
mov ax,'ab'
stosw
mov ax,'t'
stosw
ret
same_name:
call print_names
mov dx,t_same_name
jmp error_exit
print_string:
push si,cx
xor cx,cx
mov si,dx
l0:
lodsb
inc cx
or al,al
jnz l0
dec cx
jcxz >l9
push ax,bx
mov ah,040
mov bx,2
int 021
pop bx,ax
l9:
pop cx,si
ret
in_handle dw 0
out_handle dw 1
do_hi:
xor bl,bl ;reset flag
xchg al,bl ;bh is always 0 here
mov bl,[common_chars+bx+16]
xchg al,bl
jmp put_byte
lit_1:
inc bh
mov dl,al
ret
lit_2:
xor bh,bh
shl al,1
shl al,1
shl al,1
shl al,1
or al,dl
jmp put_byte
do_byte:
cmp bl,1
je do_hi
cmp bh,1
je lit_1
cmp bh,2
je lit_2
or al,al
jne >l1
mov bh,1
ret
l1:
cmp al,1
jne >l1
mov bl,1
ret
l1:
xchg al,bl ;bh is always 0 here
mov bl,[common_chars+bx]
xchg al,bl
put_byte:
dec cx
l0:
stosb
cmp di,01234
outbuf_end equ w[$-2]
jne >l2
flush:
push ax,bx,cx,dx
mov ah,040
mov bx,out_handle
mov cx,di
mov dx,01234
outbuf_start equ w[$-2]
sub cx,dx
jcxz >l1
int 021
l1:
pop dx,cx,bx,ax
mov di,outbuf_start
l2:
cmp al,0d
if ne ret
mov al,0a
jmp l0
l2:
jc ret
mov ah,al
jmp get_byte
get_word:
push l2
get_byte:
cmp si,bp
je >l1
lodsb
clc
ret
l1:
push ax,bx,cx,dx
mov ah,03f
mov bx,in_handle
mov cx,01234
inbuf_len equ w[$-2]
mov dx,eop
mov bp,dx
int 021
if c xor ax,ax
add bp,ax
mov si,eop
pop dx,cx,bx,ax
lodsb
cmp bp,si ;eof=>stc
ret
l0:
mov dx,t_stdio
call print_string
ret
print_names:
push dx
mov dx,t_decompressing
call print_string
mov dx,bx
call print_string
mov dx,t_to
call print_string
mov dx,cx
call print_string
mov dx,t_crlf
call print_string
pop dx
ret
open_files:
cmp bx,cx
je l0
call print_names
or dl,dl
jne >l2
push bx,cx,dx
mov dx,cx
mov ax,03d00
int 021
jc >l1
mov bx,ax
mov ah,03e
int 021
mov dx,t_overwrite_error
jmp error_exit
l1:
pop dx,cx,bx
l2:
push cx
mov dx,bx
mov ax,03d00
int 021
jnc >l1
mov dx,t_openin_error
jmp error_exit
l1:
mov in_handle,ax
pop dx
mov ah,03c
xor cx,cx
int 021
jnc >l1
mov ah,03e
mov bx,in_handle
int 021
mov dx,t_openout_error
jmp error_exit
l1:
mov out_handle,ax
ret
close_files:
mov ah,03e
mov bx,in_handle
cmp bx,5
if ae int 021
mov in_handle,0
mov ah,03e
mov bx,out_handle
cmp bx,5
if ae int 021
mov out_handle,1
ret
error_exit:
call print_string
call close_files
mov ax,04cff
int 021
start:
mov dx,t_signon
call print_string
mov ax,sp
sub ax,0100
mov outbuf_end,ax
sub ax,eop
shr ax,1
mov inbuf_len,ax
add ax,eop
mov outbuf_start,ax
call parse
mov dx,t_howto_help
call print_string
call open_files
mov si,bp,eop
mov di,outbuf_start
call get_word
cmp ax,0ebbe ;is it compressed?
mov dx,t_not_compressed
jne error_exit
call get_word
xchg ah,al
mov cx,ax ;length of uncompressed file
push cx,di
mov cx,30
mov di,common_chars+2
l0:
call get_byte
jc >l9
stosb
loop l0
pop di,cx
xor bx,bx ;bh=1 for literal; bl=1 for second 16 chars
l0:
call get_byte
jc >l1
mov ah,al
shr al,1
shr al,1
shr al,1
shr al,1
and ah,0f
call do_byte
jcxz >l1
mov al,ah
call do_byte
inc cx
loop l0
l1:
call flush
l9:
call close_files
mov ax,04c00
int 021
t_not_compressed: db 'File is not a compressed batch file',0d,0a,0
;; We can write data over the remaining messages, as they can't be issued after
;; reading from the file.
eop:
t_decompressing: db 'Decompressing ',0
t_to: db ' to ',0
t_stdio: db 'Decompressing STDIN to STDOUT',0d,0a,0
t_overwrite_error: db 0d,0a
db 'UCOMPBTM failed: That would overwrite an existing file!',0d,0a
db 'Use the /O switch to force overwriting.',0d,0a,0
t_openin_error: db 0d,0a
db 'UCOMPBTM failed: Can''t open input file!',0d,0a,0
t_openout_error: db 0d,0a
db 'UCOMPBTM failed: Can''t open output file!',0d,0a,0
t_same_name: db 0d,0a
db 'UCOMPBTM failed: Input and output files must have different names!',0d,0a,0
t_help:
db 0d,0a
db 0d,0a
db 'UCOMPBTM comes with ABSOLUTELY NO WARRANTY; for details see the GNU',0d,0a
db 'GPL in the file COPYING.DOC which should have come with this program.',0d,0a
db 'If this file is missing, write to the Free Software Foundation, Inc.,',0d,0a
db '675 Mass Ave, Cambridge, MA 02139, USA.',0d,0a
db 0d,0a
db 'Usage: UCOMPBTM [[/O] input_file [output_file]]',0d,0a,0
t_signon: db 0d,0a
db 'UCOMPBTM 1.0 Copyright (C) 1993 Christopher Hall',0
t_howto_help:
db ' UCOMPBTM /? for help',0d,0a
t_crlf:
db 0d,0a,0