Category : Word Perfect
Archive   : EQUALIZE.ZIP
Filename : EQUALIZE.PAS

 
Output of file : EQUALIZE.PAS contained in archive : EQUALIZE.ZIP

uses
dos,crt,strings;
{
....reads and resets table column widths
}
type
buffer_ptr=^buffer;
buffer=array[1..64000] of byte;
wp_margin_type=record
l1:word; {length}
olm,orm:word; {old left right margins}
nlm,nrm:word; {new left/right margins}
l2:word; {length}
c2,c1:byte; {codes}
end;
wp_table_header_type=record {record header}
c1:byte; {begin function code}
c2:byte; {sub function code}
l1:word; {length of function}
end;
wp_table_body_type=record {record body}
f:byte; {flags}
s:byte; {shading}
n:word; {# of columns}
t:word; {table box #}
le:word; {left edge}
lg:word; {left gutter}
rg:word; {right gutter}
tg:word; {top gutter}
bg:word; {bottom gutter}
rn_after_header_rows:word; {row number after header}
fl_at_start:word; {formatter lines at start}
pn_at_start:word; {page # at start}
left_offset:word; {of table if positioned}
end;
wp_data_type=record {one of each per column}
width:word;
attribute:word;
alignement:byte;
end;
wp_table_tail_type=record {record tail}
gg:word; {null}
l2:word; {length}
c3:byte; {sub function code}
c4:byte; {function code}
end;

var
ifile,ofile:file;
i,io,iy,j,n:integer;
ib:buffer_ptr;
istart,ipointer,ilength,olength:word;
param1,param2,iflname,oflname:string;
b1,b2:byte;
thead:wp_table_header_type;
tbody:wp_table_body_type;
tdata:wp_data_type;
ttail:wp_table_tail_type;
margins:wp_margin_type;
total,width,attribute:word;
widths:array[1..32] of word;
alignement:byte;
new_width:real;

label
start,restart,problem,ending;

procedure get(var x; n:integer);
begin move(ib^[ipointer],x,n); ipointer:=ipointer+n; end;

begin
if (paramcount=0) then begin
problem:
textcolor(lightgreen);
writeln('-----------------------------------------------------');
writeln('EQUALIZE Inputfile Outputfile [*][,][value,value] etc');
writeln('-----------------------------------------------------');
writeln('With no values, all columns are set to EQUAL widths -- to fill the margins.');
writeln('If a value is provided for column i then column i width is reset');
writeln('and the others are set to EQUAL width -- to fill the margins.');
writeln('Columns may be skipped with a ,, notation and * denotes an existing');
writeln('unspecified width value that should not be changed. e.g:');
writeln;
writeln('equalize infile.wp outfile.wp *,,*,0.32');
writeln;
writeln('takes the column widths in infile.wp leaving column 1 & 3 unchanged');
writeln('but setting column 4 to 0.32" and all others are set to equal widths.');
writeln('The tables are reset to "no-shade/full width/auto-adjust".');
writeln;
writeln('The maximum file length is 64k!, the page width is 8.5"!');
exit;
end;
ClrScr;
textcolor(yellow);
iflname:=paramstr(1);
oflname:=paramstr(2);
{
....obvious checking
}
if (iflname=oflname)
or (oflname='')
then begin writeln('!!duplicate or null file!!'#7); goto problem; end;
assign(ifile,iflname);
reset(ifile,1);
if (filesize(ifile)>sizeof(buffer))
then begin writeln('!!File bigger than 64k bytes!!'#7); goto problem; end;
{
....allocate buffer and read in file
}
new(ib);
if (ib=NIL) then exit;
blockread(ifile,ib^,sizeof(buffer),ilength);
writeln('EQUALIZE reading: ',iflname,' length: ',ilength:1,' bytes');
{
....find table start code/page width codes
....using single byte reads
}
ipointer:=1;
restart:
get(b2,1);
while (ipointer b1:=b2; get(b2,1);
if (b1=$d2) and (b2=$b) then goto start;
if (b1=$d0) and (b2=$1) then get(margins,14);
end;
writeln('No further tables found in this file');
goto ending;
start:
writeln('-- table found at offset: ',ipointer:1,' bytes');
{
....skip table size
}
get(width,2);
{
....skip previous data settings
}
get(tbody,sizeof(tbody));
for i:=1 to tbody.n do get(tdata,sizeof(tdata));
{
....mark start of new columns
....reset flags/shading
}
istart:=ipointer;
get(tbody,sizeof(tbody));
writeln('-- has ',tbody.n:1,' columns,'
,' with margins:',(margins.nlm)/1200.0:8:4,(margins.nrm)/1200.0:8:4);
with tbody do begin
f:=3+64+128; {full/auto adjust/expand to margins}
s:=0; {no shading}
end;
move(tbody,ib^[istart],sizeof(tbody));
{
....get current column data
}
total:=0;
istart:=ipointer;
iy:=whereY;
for i:=1 to tbody.n do begin
get(width,2);
writeln('Column:',i:2 ,' width: ',(width)/1200.0:8:4,'"');
widths[i]:=width;
total:=total+width;
end;
write('End of widths, total:'+r2str((total)/1200.0,1,4)+'"'+#10#13);
{
....pick up any width revisions
}
total:=0;
n:=0;
param1:=paramstr(3);
for i:=1 to tbody.n do begin
param2:=parse(param1,param1); {remove 1 parameter}
new_width:=str2r(param2,io);
if (io=0) and (new_width>0) then widths[i]:=round(1200*new_width)
else
if (param2='*') then {leave it}
else widths[i]:=0; {clear it}
if (widths[i]>0)
then begin inc(n); total:=total+widths[i]; end;
end;
width:=(round(8.5*1200)-(margins.nlm+margins.nrm)-total);
if (width<0) then goto problem;
width:=width div (tbody.n-n);
total:=0;
gotoXY(40,iy);
for i:=1 to tbody.n do begin
if (widths[i]=0) then widths[i]:=width;
gotoXY(40,whereY);
writeln('Column:',i:2 ,' width: ',(widths[i])/1200.0:8:4,'"');
total:=total+widths[i];
end;
gotoXY(40,whereY);
write('Widths reset, total:'+r2str((total)/1200.0,1,4)+'"'+#10#13);
{
....put back edited widths
}
move(widths,ib^[istart],tbody.n*sizeof(word));
goto restart;
ending:
assign(ofile,oflname);
rewrite(ofile,1);
blockwrite(ofile,ib^,ilength,olength);
writeln('--- all tables reset to Full/Noshade/Auto adjust');
writeln('EQUALIZE output: ',oflname,' length: ',olength:1,' bytes');
end.