home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.shrubbery.net
/
2015-02-07.ftp.shrubbery.net.tar
/
ftp.shrubbery.net
/
pub
/
pc
/
unix
/
unx.arc
/
LINE1.ASM
< prev
next >
Wrap
Assembly Source File
|
1985-06-10
|
3KB
|
207 lines
page 66, 132
page
;---------- line?.com ------------
; Copies the [initial..final] lines of the named files to stdout.
; If no files named, uses stdout.
;
; uses args
extrn _args:near, _shift:near
extrn argc:word, argv:word
; uses ffind
extrn ffirst:near, fnext:near
extrn fnam:byte
; uses fio
extrn f_io_init:near
extrn f_ihand:word, f_ohand:word
extrn f_ibuf:word, f_obuf:word
extrn f_ilen:word, f_olen:word
extrn f_ibufend:word, f_obufend:word
extrn f_imore:near, f_omore:near
extrn f_getc:near, f_putc:near
dos macro fn
mov ah, fn
int 21h
endm
stdin equ 0
stdout equ 1
stderr equ 2
; Set the range of lines to print; 0 is the first line.
initial equ 0
final equ 0
code segment para public 'CODE'
assume cs:code,ds:code
org 100h
main proc
jmp linex
main endp
;----------------------------------------------
db 27
db '[2J Line1 (C) 1984 Yoyodyne, Inc- a growing excited company', 26
errs dw null ; error zero- no error
dw null, filenotfound, pathnotfound, nohand, access
dw null, null, null, null, null
dw null, null, null, null, baddrive
dw null, null
null db '?Dos err', 0
filenotfound db 'File not found', 0
pathnotfound db 'Path not found', 0
nohand db 'No handles left', 0
access db 'Access denied', 0
baddrive db 'Invalid drive specification', 0
lfs dw 0
trueargc dw ?
;--- strlen ---
; Returns length of ES:DI in CX, points to null with DI.
strlen proc near
cld
push ax
mov cx, -1
mov al, 0
repnz scasb
not cx
pop ax
ret
strlen endp
dos_err proc near
mov bx, ax
add bx, ax
mov di, errs[bx]
push di
call strlen
pop dx
mov bx, stderr
DOS 40h
ret
dos_err endp
open_err proc near
call dos_err
mov al, 1
DOS 4ch
open_err endp
;-------------------------------------------------
linex proc near
call _args
; Initialize the buffers...
mov f_ilen, 512
mov f_olen, 512
call f_io_init
; Get them args...
mov ax, argc
mov trueargc, ax
or ax, ax
jnz while_loop
; If no arguments, use stdin.
mov argc, 1
mov f_ihand, stdin
jmp short gothandle
;----- Main Loop -------
; do {
; find_first_matching(argv[2]);
; repeat
; line2;
; until not find_next;
; shift;
; } while (argc > 0);
while_loop:
mov dx, argv[2]
mov cx, 0
call ffirst
jnc rept_loop
jmp while_done
rept_loop:
mov dx, offset fnam
mov al, 0 ; open for read access
dos 3dh
jc open_err
gothandle:
mov f_ihand, ax
mov f_ohand, stdout
; SI & DI are used by getc & putc.
mov si, f_ibuf
mov f_ibufend, si
mov di, f_obuf
mov lfs, 0 ; initialize CRLF counter.
moreclp:
call f_getc
jz morecx
cmp al, 26
jz morecx
cmp lfs, initial
jb not_yet
call f_putc
not_yet:
cmp al, 10
jnz moreclp
inc lfs
cmp lfs, final
jbe moreclp
morecx:
call f_omore ; flush output buffer
mov bx, f_ihand
DOS 3Eh ; close input file
; until (not find_next);
cmp trueargc, 0
jz while_done
call fnext
jc rept_done
jmp rept_loop
rept_done:
; shift;
call _shift
dec argc
cmp argc, 0
jz while_done
jmp while_loop
while_done:
mov di, f_obuf ; put an EOF, please (DOS won't).
mov al, 26
call f_putc
call f_omore
mov al, 0 ; no error
exit:
mov ah, 4ch
int 21h ; terminate process, return status in AL.
linex endp
code ends
end main