Printing Utility
Dimitrios P. Bouras
dbouras at hol.gr
Tue Aug 19 12:09:19 EEST 1997
Costas wrote:
>
> Gia xara linux-users,
>
> Mipos kserei kaneis apo esas an yparxei utility me to opoio na mporo na
> typoso ena keimeno prota tis mones kai ystera tis ziges selides. Den me
> endiaferei h platforma poy tha doylevei (Linux/Dos)
Costa,
To parakatw sh/awk script einai gia na xwrizei PostScript files pou
exoun "%%Header", "%%Page:" kai "%%Trailer" comments, se dyo arxeia,
to ena me tis mones selides, kai to allo me tis zyges se antistrofh
seira. Etsi mporei na fortw0ei to idio xarti twn typwmenwn monwn
selidwn gia na typw0oun sthn apo pisw pleura kai oi zyges. Einai
arketa eukolo na to alla3eis gia na bgainoun oi zyges kanonika kai oxi
antistrofa, ean o printer sou bgazei/pairnei to xarti me tropo pou na
apaitei kati tetoio.
Me xairetismous,
Dhmhtrhs
--
| Dimitrios P. Bouras | Tel.: +30 1 894-1320 or 968-0554 |
| 41 Pandora Str. | FAX: +30 1 382-7900 "Attention: Dimitri" |
| 166 74 Athens | E-mail: dbouras at hol.gr, dimitri at ee.ubc.ca |
| GREECE | Web: http://users.hol.gr/~dbouras |
"There is hopeful symbolism in the fact that flags do not wave
in a vacuum." -- Arthur C. Clarke
-------------- next part --------------
#! /bin/sh
#
# Script to invoke the AWK SplitPS program
# DB, July 1994, last update November 1996
if [ "$1" = "" -o "$1" = "-h" ]; then
echo "SplitPS V1.0d. Usage splitps <PostScript file name>"
exit 0
fi
awk -f - $1 << 'AWKPROGEND'
# And AWK script for splitting PostScript files in
# even-odd pages, the even in reverse order.
#
# DB, July 1994, last update November 1996
# Do some initialization
BEGIN {
print "SplitPS V1.0d, PostScript file even/odd page splitter"
efname = "ep_" FILENAME
ofname = "op_" FILENAME
print "Output files: " efname ", " ofname
printf("") > efname; printf("") > ofname
print "Reading file: " FILENAME
}
# Read in the entire file
{
line[NR] = $0
}
# And then process it
END {
dq = sprintf("%c", 34);
for ( lc=1; lc<=NR; lc++ ) {
nle = split( line[lc], le )
if ( le[1] == "%%Trailer" ) {
TL = lc
break
}
if ( le[1] != "%%Page:" ) {
print line[lc] >> efname
print line[lc] >> ofname
} else {
FPFL = lc
print "First line of first page: " FPFL
break
}
}
opc = 0
while ( lc<=NR ) {
if ( le[1] == "%%Trailer" ) {
TL = lc
printf("\nTrailer first line: %d\n", TL)
break
}
if ( le[1] == "%%Page:" ) {
dqi = index(le[2], dq)
if ( dqi != 0 ) {
nle = split(line[lc], ale, dq)
cp = ale[2]
} else {
cp = le[2]
}
odd = 0
if ( (cp%2)>0 ) odd = 1
if ( odd ) {
printf("[%d] ",cp)
print "%%Page:",int(cp/2),int(cp/2)+1 >> ofname
++opc
}
} else {
if ( odd ) print line[lc] >> ofname
}
++lc
if ( lc<=NR ) nle = split( line[lc], le )
}
printf("Finished odd pages\n")
for ( lc=TL; lc<=NR; lc++ ) {
print line[lc] >> ofname
}
epc = 0
for ( lc=TL-1; lc>=FPFL; lc-- ) {
nle = split( line[lc], le )
if ( le[1] == "%%Page:" ) {
dqi = index(le[2], dq)
if ( dqi != 0 ) {
nle = split(line[lc], ale, dq)
cp = ale[2]
} else {
cp = le[2]
}
if ( (cp%2)<1 ) {
EPFL = lc
++lc
printf("[%d] ",cp)
print "%%Page:",epc,epc+1 >> efname
++epc
break
}
}
}
while ( lc>=FPFL ) {
while ( lc<TL ) {
nle = split( line[lc], le )
if ( le[1] == "%%Page:" ) break
print line[lc] >> efname
++lc
}
for ( lc=EPFL-1; lc>=FPFL; lc-- ) {
nle = split( line[lc], le )
if ( le[1] == "%%Page:" ) {
dqi = index(le[2], dq)
if ( dqi != 0 ) {
nle = split(line[lc], ale, dq)
cp = ale[2]
} else {
cp = le[2]
}
if ( (cp%2)<1 ) {
EPFL = lc
++lc
printf("[%d] ",cp)
print "%%Page:",epc,epc+1 >> efname
++epc
break
}
}
}
}
printf("\nFinished even pages\n")
for ( lc=TL; lc<=NR; lc++ ) {
print line[lc] >> efname
}
print epc,"even and",opc,"odd pages processed"
print "Done."
print "Send ",efname,"to the printer first, then reload"
print "the output pages in the tray and send",ofname
}
AWKPROGEND
More information about the Linux-greek-users
mailing list