;Build index to disk of first non-blank line of group of files ; Copyright 1987 by Barry A. Cole 870413 ; Non-commercial free usage encouraged ; Please send suggestions and enhancements to me via betaline (213)-313-2549 ; Usage: TITLES *.TXT MYFILE.LST builds list of .TXT files into MYFILE.LST ; TITLES A.B builds list of 1 file into TITLES.INX ; You can build a nice alphabetized index, such as my song lyrics index, by: ; TITLES *.SON ; SORTV TITLES.INX @.SON ; ; Build the .COM file for this by: ; A>asm titles ; A>load titles ;memory locations BDOS EQU 5 ;DOS ENTRY POINT cmdsiz equ 80h ;size of command line FCB EQU 5CH ;FILE CONTROL BLOCK ADDRESS FCBCR EQU FCB+32 ;CURRENT (NEXT) RECORD NUMBER (0 TO 127) OPENF EQU 15 ;FILE OPEN SEARCHF equ 17 ;Search directory for file spec SEARCHN equ 18 ;Search for next match READF EQU 20 ;READ FUNCTION WRITEF equ 21 ;write to file SETDMA equ 26 ;Set DMA address ORG 100H start: lxi d,idmsg mvi c,9 call bdos ;print signon message lxi d,usage ;help message- just in case lda cmdsiz ora a jz help ;Suggest parms if omitted lxi h,fcb+11h ;output file fcb mov a,m dcx h cpi ' '+1 jnc outok ;user specified output file lxi h,default ; or I specify outok: xchg lxi h,dfcb ;destination fcb call movfcb lxi d,dfcb mvi c,19 ;delete destination file call bdos lxi d,dfcb mvi c,22 ;make output file call bdos inr a jz nodest ;couldn't create destination lxi h,dfcb+1 lxi d,fname mvi b,8 ;max characters in filename call move mvi a,'.' stax d inx d mvi b,3 call move lxi d,outmsg mvi c,9 call bdos ;print output file message lxi h,outbuf shld obufp lxi h,fcbs shld fptr ; Output file ready so search for all matching input files mvi c,searchf match: push b lxi d,dirbuf mvi c,setdma call bdos ;set dma address lxi d,fcb pop b ;search for first/next matching filename call bdos cpi 255 jz names add a add a add a add a add a mov e,a mvi d,0 lxi h,dirbuf dad d ;hl points to matching entry xchg lhld fptr call movfcb shld fptr mvi c,searchn ;search for next file match jmp match names: lhld fptr shld endptr lxi h,fcbs-33 shld fptr more: lhld fptr lxi b,33 dad b shld fptr call cmpend jz nomore mvi b,8 namout: inx h mov a,m call chrout dcr b jnz namout mvi a,'.' call chrout mvi b,3 extout: inx h mov a,m call chrout dcr b jnz extout mvi a,' ' call chrout lhld fptr mvi m,0 ;default drive and user xchg ; fix for large file bug 880501 BAC lxi h,12 ;offset to ex byte dad d mvi m,0 ; mvi c,openf call bdos ;open file for reading inr a jz eof ;badopen is like EOF lxi d,rdbuf mvi c,setdma call bdos ;set dma address lhld fptr xchg mvi c,readf call bdos ;read first block of file jnz eof lxi h,rdbuf ;find nonblank line findlp: mov a,m cpi ' '+1 jnc putout inx h jmp findlp putout: call chrout ;hl points to first non-blank line inx h mov a,m cpi ' ' jnc putout eof: mvi a,0dh ;cr call chrout mvi a,0ah ;lf call chrout jmp more nomore: mvi a,1ah ;end of file marker call chrout jnz nomore ;until block written lxi d,dfcb mvi c,16 call bdos ;close file lxi d,done mvi c,9 jmp bdos ;print message and back to system move: mov a,m stax d inx h inx d dcr b rz jmp move movfcb: mvi b,16 ;count of half an fcb xchg call move xchg mvi b,17 clrlp: mvi m,0 inx h dcr b jnz clrlp ret nodest: lxi d,badmake help: mvi c,9 jmp bdos ;print message and back to system cmpend: lda endptr cmp l rnz lda endptr+1 cmp h ret chrout: push h lhld obufp mov m,a inx h shld obufp mvi a,(outbuf+128) and 0ffh sub l pop h rnz push h push d push b lxi h,outbuf shld obufp xchg mvi c,setdma call bdos ;set dma address lxi d,dfcb mvi c,writef call bdos ;write file xra a pop b pop d pop h ret idmsg: db 'Build index to disk of first non-blank line of a group ' db 'of files' db 0dh,0ah,' by Barry A. Cole 870413',0dh,0ah,'$' usage: db 'Usage: TITLES *.TXT MYFILE.LST ' db ' builds list of .TXT files into MYFILE.LST',0dh,0ah db ' TITLES A.B builds list of 1 file ' db 'into TITLES.INX',0dh,0ah,'$' badmake:db 'Couldn''t create output file',0dh,0ah,'$' outmsg: db 'Output file is ' fname: ds 12 db 0dh,0ah,'$' done: db 'Output complete.',0dh,0ah,'$' default:db 0,'TITLES INX',0,0,0,0 db 0 rdbuf: ds 128 db '>> dummy <<',0dh,0ah outbuf: ds 128 dirbuf: ds 128 obufp: ds 2 dfcb: ds 33 endptr: ds 2 fptr: ds 2 fcbs: ds 0 ;file control blocks build from here on end start