.title headtail ; ; Written by Jim Wolfe for Project #6, Fall '99 ; ; Program to display the head (first five lines) and tail (last five lines) ; of a file on the screen. Color output is used to highlight the elements ; that are being displayed. This program relies on the availability of ; several macros in order to work. These macros must be contained in the ; iopack and p6macs libraries. ; .library /project:iopack/ easyio .library /p6macs/ ; cr=13 lf=10 prompt: .ascii /What is the file name/ plen=.-prompt heading: .ascii / / .ascii /Head and tail for file: / hlen=.-heading five: .ascii / five records:/ flen=.-five newline: .ascii fspec: .blkb 30 ; File name fdescr: .blkw 1 ; Descriptor for file .byte 14,1 .address fspec records: .blkb 500 ; Storage for five records current: .blkw 1 ; Descriptor for a record .byte 14,1 .address records length: .blkl 5 ; Array of record lengths .entry start,^m<> .show meb colorshow green, prompt, #plen ; Prompt for file getstr fspec, #30 ; Get file name cvtlw r1, fdescr ; Make descriptor openin input, fdescr ; Open the file blbs r0, continue brw error ; Handle errors continue: colorshow cyan, heading, #hlen ; Output headings colorshow yellow, fdescr showc newline, #3 colorshow MAGENTA, <"First"> showc five, #flen clrl r6 top: getline input, current ; Read a record blbs r0, valid brw short ; Handle error valid: colorshow blue, current ; Display record in blue showc newline, #2 cvtwl current, length[r6] ; Save record length addl2 #100, current+4 ; Adjust descriptor acbl #4, #1, r6, top colorshow MAGENTA, <"Last"> showc five, #flen round: clrl r6 ; Loop to read rest movab records, current+4 ; of the records into again: getline input, current ; five record area blbc r0, finish ; Handle end of file cvtwl current, length[r6] ; Save record length addl2 #100, current+4 ; Adjust descriptor acbl #4, #1, r6, again brw round finish: close input ; Close the file movl #5, r8 movl current+4, r9 ; Set record location final: colorshow red, (r9), length[r6] ; Diplay one of last five showc newline, #2 ; in red incl r6 ; Adjust length index addl2 #100, r9 ; Adjust location cmpl r6, #5 bneq ok clrl r6 ; Wrap around end of array movab records, r9 ok: acbl #1, #-1, r8, final $exit_s short: showc newline, #3 ; Handle short files colorshow YELLOW, <"WARNING: FILE TOO SHORT TO CONTINUE"> $exit_s error: showc newline, #3 ; Handle non-existent file colorshow RED, <"ERROR: PROBLEM OPENING THE FILE"> $exit_s .end start