UNIX Utilities for the HP-71 by Jim Walters 4171 Antler Trail Smyrna, Ga. 30080 (404) 432-0776 Recently my company purchased a Sun Engineering Workstation which comes with the UNIX Operating System. I was enormously impressed by the dozens of utilities, and how easy many programming tasks became by combining various utilities to achieve the desired result. I decided to write my own versions for the HP-71. Obviously compromises had to be made, but most of the routines are either complete versions or implement the major features of their Unix counterparts. All of the routines are written in BASIC as CALLable routines. Most should be easily portable to other dialects of BASIC such as the new QUICKBASIC and TURBOBASIC. Some routines do require lexfile support from the TEXT EDITOR Rom, the FORTH Rom or the 41 TRANSLATOR Rom. One routine, 'REV', requires either STRINGLX or REVLEX, but replacements for the lex functions could be coded directly in BASIC with the attendant speed penalty. To date over 40 utilities have been coded. Those herein are believed to be bug free although some 71 version 1BBBB bugs may rear their heads. Be sure for example that the calling program has an END statement. Brief descriptions of the utilities are given below: COLRM - removes specified columns from a file EXPAND - expands 'tab' characters to spaces REV - reverses order of chars. in each record (line) in file FOLD - fold lines to fixed length UNEXPAND - colapse spaces to 'tab' characters UNIQ - eliminate duplicate lines in a sorted file WC - counts lines, words and characters in a file TR - translate characters CRYPT - encrypt/decrypt a file CLS - clears the video display WIDEPRT - prints a text file in 24 column strips on the strip printer ( tape them together for a poor man's 80+ column printer ) DIR - list main directory ( this routine is not mine, it came from a back issue of the Journal or Chronicle.) CAL - displays a calendar for specified month and year SPLIT - splits a file into pieces, n-lines each MORE - Browse a text file ( even one on mass storage ) BSPLIT - splits a BASIC program text into multiple files each containing only one subprogram. HEAD - displays first n-lines of multiple text files ( even those on mass storage ) TAIL - like HEAD but either the last n-lines of a file or from line n to the end of the file. PAIR - checks a file for proper pairings of '()', '[]' etc. CMP - simple file comparison. Returns lll.ccc of first difference. DEROFF - removes TEXT FORMATTER formatting commands from a file PASTE - horizontally concatinate multiple files CONCAT - concatinate multiple files, output to either file or display TEE - copy file to multiple files, optional append Most of the routines are 'filters.' That is they read from one text from one file, alter it and write to another file. Input and output files are text files unless otherwise stated. Most of the input and output files may be ram based or on tape or disk and do not need to be loaded into ram. Large databases may thus be processed. The routines are compact and have little error checking. With this in mind, the detailed calling sequences are given below. 1.) CALL COLRM(F1$,F2$,C1,C2) F1$ - name of the input file F2$ - name of the output file C1, C2 - range of columns to be removed inclusive 2.) CALL EXPAND(F1$,F2$,C$,T) F1$ - name of the input file F2$ - name of the output file C$ - 'tab' character i.e. any character you want expanded into spaces. T - tabstops are n*T, n=0,1,2,3... (default 8) 3.) CALL REV(F1$,F2$) ( STRINGLX or REVLEX required) F1$ - input file F2$ - output file 4.) CALL FOLD(F1$,F2$,C) F1$ - input file F2$ - output file C - max number of characters per line you want (default 80) 5.) CALL UNEXPAND(F1$,F2$,C$,T) F1$ - input file F2$ - output file C$ - character to be inserted in place of spaces T - tabstops n*T, n=0,1,2,3... ( default 8 ) 6.) CALL UNIQ(F1$,F2$,C1,C2,N) F1$ - input file (must be sorted on columns c1 through c2) F2$ - output file C1,C2 - range of columns for comparison ( default 1, 95 ) N _ returns number of duplicate lines 7.) CALL WC(F1$,L,W,C) F1$ - input file L - returns number of lines W - returns number of words C - returns number of characters 8.) CALL TR(F1$,F2$,S$,R$) F1$ - input file F2$ - output file S$ - list of characters to be changed R$ - list of characters to be changed into TR changes a character in S$ into the character found at the same relative position in R$. IF LEN(R$)0 then display lines n through end of file(s) F$ - same as for 'HEAD' 19.) CALL PAIR(F$,C$) F$ - input filename C$ - string containing 'pairs' i.e. C$='()[]' will check that each '(' has a balancing ')'. Pair also checks for an even number of '"' and "'" . When checking a FORTH file C$=':;' is handy. 20.) CALL CMP(F1$,F2$,P) F1$ - name of first file F2$ - name of second file P - returns llll.ccc of first difference found, where llll is the line number and ccc is the column position. 21.) CALL DEROFF(F1$,F2$,C$) F1$ - input filename F2$ - output filename C$ - character formatting commands begin with ( TEXT FORMATTER rom uses '^' ) 22.) CALL PASTE(F1$,F2$,C$) F1$ - string containing names of files to be concatinated, separated by commas ( see note on HEAD above ) F2$ - output filename C$ - string containing starting column numbers in the output file for each record in the input files, entries separated by commas. e.g. CALL PASTE('file1,file2','out','5,40') will print file1 in columns 1 through 39 and file2 in columns 40 and above in the file 'out'. 23.) CALL CONCAT(F1$,F2$,N) F1$ - string containing names of files to be concatinated, separated by commas ( see note on HEAD above ) F2$ - output filename N - line numbering flag: 0 don't line number 1 line number the output 24.) CALL TEE(F1$,F2$,A) F1$ - input filename F2$ - string containing names of files to receive copies of F1$, separated by commas ( see note on HEAD above ) A - append flag: 0 - write over file 1 - append to file That's all for now, still to come are BPP a BASIC preprocessor, JAWK a report generator, JOIN a relational database operator and much more! If you have any questions concerning these routines give me a call. I'll be moving soon and will have a new address. Check with Brian Walsh if you have trouble reaching me.