PROGRAM macprint; { This program prints the output files produced by Digital Research's MAC assembler. The program command line must be of form: PRMAC NAME The program will first search for the file NAME.PRN, print it with page numbers, then erase NAME.PRN. It will then look for NAME.SYM, print it and then erase it also. J.A. Koehler Saskatoon 3 October, 1982 } CONST page_size = 66; upper_border = 10; lower_border = 10; ff = $0C; {form-feed} TYPE longstr = string[128]; VAR infile, outfile: text; result, page_no, line_no: integer; headprint: boolean; filename: string; EXTERNAL PROCEDURE @hlt; EXTERNAL PROCEDURE getarg(VAR n:integer;VAR a,b:string); { GETARG is a routine similar to those described in "Software Tools in Pascal" ... it returns the arguments written on the command line and the number of them (up to 2). 'n' is the number; 'a' is the first and 'b' is the second. If the program were invoked by, for example, the command: PRINT NAME1 NAME2 NAME3 TEXT the returned values would be: n 2 a NAME1 b NAME2 NAME3 TEXT } PROCEDURE initialize; VAR temp1, temp2: string; ch: char; narg: integer; PROCEDURE err_chk(name:string); BEGIN IF ioresult = 255 THEN BEGIN writeln('Unable to open file: ',name); @hlt; END; END; BEGIN headprint := TRUE; getarg(narg,temp1,temp2); IF narg = 0 THEN BEGIN writeln('What !!!'); @hlt; END; IF pos('.',temp1) <> 0 THEN @hlt; temp1:=concat(temp1,'.PRN'); filename:=temp1; temp2:='LST:'; assign(infile,temp1); reset(infile); err_chk(temp1); assign(outfile,temp2); rewrite(outfile); err_chk(temp2); END; { INITIALIZE } PROCEDURE list; VAR line: longstr; PROCEDURE dofooter; BEGIN write(outfile,chr(ff)); END; PROCEDURE doheader; VAR i,part1,part2: integer; BEGIN IF NOT headprint THEN FOR i:=1 TO upper_border DO writeln(outfile) ELSE BEGIN part1:=upper_border DIV 2; part2:=upper_border - (part1+1); FOR i:=1 TO part1 DO writeln(outfile); write(outfile,filename); FOR i:=1 TO 40 DO write(outfile,' '); writeln(outfile,'Page ',page_no); FOR i:=1 TO part2 DO writeln(outfile); END; line_no:=upper_border+1; END; PROCEDURE sift(VAR line:longstr); { Remove all form feeds from input file } VAR i,len: integer; temp: longstr; BEGIN len:=length(line); temp:=''; FOR i:=1 TO len DO IF line[i] <> chr(ff) THEN temp:=concat(temp,line[i]); line:=temp; END; BEGIN doheader; readln(infile,line); sift(line); WHILE NOT eof(infile) DO BEGIN writeln(outfile,line); line_no:=line_no+1; IF line_no > (page_size-lower_border) THEN BEGIN page_no:=page_no+1; dofooter; doheader; END; readln(infile,line); sift(line); END; writeln(outfile,line); END; { LIST } BEGIN page_no:=1; initialize; list; write(outfile,chr(ff)); {form feed} page_no:=page_no+1; closedel(infile,result); delete(filename,pos('.',filename),4); filename:=concat(filename,'.SYM'); assign(infile,filename); reset(infile); IF ioresult = 255 THEN @hlt; list; closedel(infile,result); END.