home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk1.iso / altsrc / articles / 11415 < prev    next >
Text File  |  1994-11-01  |  16KB  |  607 lines

  1. Newsgroups: alt.sources
  2. From: zondo@hunting2.demon.co.uk (Zondo Pillock)
  3. Path: wupost!sdd.hp.com!hpscit.sc.hp.com!news.dtc.hp.com!col.hp.com!csn!magnus.acs.ohio-state.edu!math.ohio-state.edu!caen!zip.eecs.umich.edu!panix!news.mathworks.com!udel!news.sprintlink.net!demon!hunting2.demon.co.uk!zondo
  4. Subject: a4-a5 v1.1 (bugfix release)
  5. Organization: Hunting Engineering Limited
  6. Reply-To: zondo@hunting2.demon.co.uk
  7. X-Newsreader: Demon Internet Simple News v1.29
  8. Lines: 594
  9. Date: Mon, 31 Oct 1994 09:18:20 +0000
  10. Message-ID: <783595100snz@hunting2.demon.co.uk>
  11. Sender: usenet@demon.co.uk
  12.  
  13. This is a shell archive of a4-a5, version 1.1.
  14.  
  15. a4-a5 is a perl script which converts A4 PostScript files to A5, by
  16. printing two pages per output page alongside each other.
  17.  
  18. This is a bug fix release: options now work properly, and there's a
  19. usage message with invalid options.
  20.  
  21. To install: hack the customization section of the Makefile, and just
  22. type 'make install'.
  23.  
  24. Save a tree today!  Print those massive manuals with a4-a5!
  25.  
  26.  
  27.                                                                __o
  28.                                 zondo@hunting2.demon.co.uk   _`\<,_
  29.                                 ............................(_)/ (_)
  30.  
  31.  
  32. Submitted-by: zondo@hunting2.demon.co.uk
  33. Archive-name: a4-a5/part01
  34.  
  35. ---- Cut Here and feed the following to sh ----
  36. #!/bin/sh
  37. # This is a4-a5, a shell archive (produced by GNU shar 4.0)
  38. # To extract the files from this archive, save it to some FILE, remove
  39. # everything before the `!/bin/sh' line above, then type `sh FILE'.
  40. #
  41. # Made on 1994-10-31 09:03 GMT by <zondo@hunting2.demon.co.uk>.
  42. # Source directory was `/work/utils/printing/a4-a5'.
  43. #
  44. # Existing files will *not* be overwritten unless `-c' is specified.
  45. #
  46. # This shar contains:
  47. # length mode       name
  48. # ------ ---------- ------------------------------------------
  49. #   1091 -rw-r--r-- README
  50. #   1515 -rw-r--r-- Makefile
  51. #   3085 -r--r--r-- a4-a5.pl
  52. #   1477 -r--r--r-- a4-a5.ps
  53. #   1857 -r--r--r-- a4-a5.doc
  54. #   1481 -rw-rw-r-- a4-a5.man
  55. #
  56. touch -am 1231235999 $$.touch >/dev/null 2>&1
  57. if test ! -f 1231235999 && test -f $$.touch; then
  58.   shar_touch=touch
  59. else
  60.   shar_touch=:
  61.   echo 'WARNING: not restoring timestamps'
  62. fi
  63. rm -f 1231235999 $$.touch
  64. #
  65. # ============= README ==============
  66. if test -f 'README' && test X"$1" != X"-c"; then
  67.   echo 'x - skipping README (File already exists)'
  68. else
  69.   echo 'x - extracting README (text)'
  70.   sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  71. This is a4-a5, version 1.1.
  72. X
  73. a4-a5 is a perl script which converts A4 PostScript files to A5, by
  74. printing two pages per output page alongside each other.
  75. X
  76. This is a bug fix release: options now work properly, and there's a
  77. usage message with invalid options.
  78. X
  79. To install: hack the customization section of the Makefile, and just
  80. type 'make install'.
  81. X
  82. It works on most of the PostScript files I've tried it on, with the
  83. exception of files produced by FrameMaker - the first page screws up
  84. for some weird reason.  And, to get it to work on psroff output, I had
  85. to undefine the save/restore commands, so PostScript files that rely
  86. on save/restore may screw up bad.  Best to check things out with a
  87. previewer to be sure.  If any PostScript boffin out there can tell me
  88. why (or even better, give me a fix) I'd be well chuffed.
  89. X
  90. Save a tree today!  Print those massive manuals with a4-a5!
  91. X
  92. X
  93. X                                                               __o
  94. X                                zondo@hunting2.demon.co.uk   _`\<,_
  95. X                                ............................(_)/ (_)
  96. X
  97. X
  98. SHAR_EOF
  99.   $shar_touch -am 1031085694 'README' &&
  100.   chmod 0644 'README' ||
  101.   echo 'restore of README failed'
  102.   shar_count="`wc -c < 'README'`"
  103.   test 1091 -eq "$shar_count" ||
  104.     echo "README: original size 1091, current size $shar_count"
  105. fi
  106. # ============= Makefile ==============
  107. if test -f 'Makefile' && test X"$1" != X"-c"; then
  108.   echo 'x - skipping Makefile (File already exists)'
  109. else
  110.   echo 'x - extracting Makefile (text)'
  111.   sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
  112. # ---------------- Makefile for a4-a5 PostScript converter --------------
  113. X
  114. # ------------------------- Customization section -----------------------
  115. X
  116. # Where to put the program
  117. BINDIR        = /work/bin
  118. X
  119. # Where to put the man page
  120. MANDIR        = /work/man/man1
  121. X
  122. # Where to put the PostScript header file
  123. LIBDIR        = /netdat/lib
  124. X
  125. # Pathname of your perl executable
  126. PERL        = /work/bin/perl
  127. X
  128. # ---------------------- End of customization section -------------------
  129. X
  130. CONFIG        = sed    -e 's^%%LIBDIR%%^$(LIBDIR)^' \
  131. X            -e 's^%%PERL%%^$(PERL)^'
  132. X
  133. install:    a4-a5 a4-a5.ps a4-a5.1
  134. X        install -c -m 755 a4-a5 $(BINDIR)
  135. X        install -c -m 644 a4-a5.ps $(LIBDIR)
  136. X        install -c -m 644 a4-a5.1 $(MANDIR)
  137. X
  138. a4-a5:        a4-a5.pl
  139. X        $(CONFIG) a4-a5.pl > a4-a5
  140. X
  141. a4-a5.1:    a4-a5.man
  142. X        $(CONFIG) a4-a5.man > a4-a5.1
  143. X
  144. a4-a5.man:    a4-a5.doc
  145. X        srctoman - a4-a5.doc > a4-a5.man
  146. X
  147. clean:;        rm -f a4-a5 a4-a5.1 *.a5 *.orig
  148. X
  149. # ---------------------------- Distribution -----------------------------
  150. X
  151. NETNAME        = zondo@hunting2.demon.co.uk
  152. X
  153. SHARDIR        = /work/pc
  154. SHARNAME    = ashar
  155. SHAROPTS    = -n a4-a5 -o $(SHARNAME) -l 50 -s $(NETNAME) -acT
  156. SHAR        = README Makefile a4-a5.pl a4-a5.ps a4-a5.doc a4-a5.man
  157. X
  158. shar:        $(SHAR) SHAR
  159. X        shar $(SHAROPTS) $(SHAR)
  160. X        for i in $(SHARNAME)*; do \
  161. X            cat SHAR $$i > $(SHARDIR)/$$i; \
  162. X            rm $$i; \
  163. X        done        
  164. X
  165. # ----------------------------- Test stuff ------------------------------
  166. X
  167. X.SUFFIXES:    .ps .a5 .orig .diff
  168. X
  169. X.ps.a5:;    perl a4-a5.pl -h a4-a5.ps -o $*.a5 $*.ps
  170. X
  171. X.a5.orig:;    perl a4-a5.pl -r -o $*.orig $*.a5
  172. X
  173. X.orig.diff:;    diff $*.ps $*.orig
  174. SHAR_EOF
  175.   $shar_touch -am 1027092594 'Makefile' &&
  176.   chmod 0644 'Makefile' ||
  177.   echo 'restore of Makefile failed'
  178.   shar_count="`wc -c < 'Makefile'`"
  179.   test 1515 -eq "$shar_count" ||
  180.     echo "Makefile: original size 1515, current size $shar_count"
  181. fi
  182. # ============= a4-a5.pl ==============
  183. if test -f 'a4-a5.pl' && test X"$1" != X"-c"; then
  184.   echo 'x - skipping a4-a5.pl (File already exists)'
  185. else
  186.   echo 'x - extracting a4-a5.pl (text)'
  187.   sed 's/^X//' << 'SHAR_EOF' > 'a4-a5.pl' &&
  188. #!%%PERL%%
  189. X
  190. # PostScript A4-A5 converter (by G.Hutchings)
  191. X
  192. # $Id: a4-a5.pl,v 1.5 1994/10/31 09:02:59 glen Exp $
  193. X
  194. require "getopts.pl";
  195. X
  196. # Version
  197. $version = "1.1";
  198. X
  199. # Parse arguments
  200. &usage if !&Getopts('o:h:frv');
  201. X
  202. if (defined ($opt_v)) {
  203. X    print "a4-a5 version $version, (C) G. Hutchings 1994\n";
  204. X    exit 0;
  205. }
  206. X
  207. if (defined ($opt_o)) {
  208. X    open(OUT, ">" . $opt_o) || die "$0: Error: can't open $opt_o: $!\n";
  209. X    $out = OUT;
  210. } else {
  211. X    $out = STDOUT;
  212. }
  213. X
  214. $header = "%%LIBDIR%%/a4-a5.ps";
  215. $header = $opt_h if (defined ($opt_h));
  216. X
  217. # Get list of input files
  218. @list = @ARGV;
  219. if ($list[0] eq '') {
  220. X    $files = "<stdin>";
  221. } else {
  222. X    do {
  223. X    $files = $files . $list[0];
  224. X    shift @list;
  225. X    } until ($list[0] eq '');
  226. }
  227. X
  228. # Do what's requested
  229. if (!defined($opt_r)) {
  230. X    &convert;
  231. } else {
  232. X    &unconvert;
  233. }
  234. X
  235. Xexit 0;
  236. X
  237. # Convert from a4 to a5
  238. sub convert {
  239. X    $pages = 0;
  240. X    chop ($date = `date`);
  241. X    chop ($user = `whoami`);
  242. X    chop ($host = `hostname`);
  243. X
  244. X    # Write header
  245. X    print $out "%!PS-Adobe-1.0\n";
  246. X    print $out "%%Title: $files converted to a5 format\n";
  247. X    print $out "%%Creator: a4-a5 ($user@$host)\n";
  248. X    print $out "%%CreationDate: $date\n";
  249. X    print $out "%%Pages: (atend)\n";
  250. X    print $out "%%EndComments\n";
  251. X
  252. X    open (HDR, $header) || die "$0: Error: can't open $header: $!\n";
  253. X    print $out $_ while (<HDR>);
  254. X    close HDR;
  255. X
  256. X    print $out "%%EndProlog\n";
  257. X
  258. X    # Process input
  259. X    while (<>) {
  260. X    # Check first line for PostScript
  261. X    if ($. == 1) {
  262. X        if (!/^%!/ && !defined($opt_f)) {
  263. X        die "$0: Error: input doesn't look like PostScript\n";
  264. X        }
  265. X    }
  266. X
  267. X    # Write page numbers if possible
  268. X    if (/^%%Page:.*([0-9]+)/) {
  269. X        if ($1 % 2 != 0) {
  270. X        $pages++;
  271. X        print $out "%%Page: $pages\n";
  272. X        }
  273. X    }
  274. X
  275. X    # Print trailer
  276. X    print $out "%%Trailer\n" if (/^%%Trailer/);
  277. X
  278. X    # Print no. of pages if known
  279. X    print $out "%%Pages: $pages\n" if (/^%%Pages:.*[0-9]+/);
  280. X
  281. X    # Comment out all document formatting stuff
  282. X    print $out "%|" if (/^%%/);
  283. X
  284. X    # Echo line
  285. X    print $out $_;
  286. X    }
  287. X
  288. X    # Finish up
  289. X    print $out "a5finish\n";
  290. }
  291. X
  292. # Reverse the a4-a5 operation
  293. sub unconvert {
  294. X    $body = 0;
  295. X    while (<>) {
  296. X    # Check first line for PostScript
  297. X    if ($. == 1) {
  298. X        die "$0: Error: input doesn't look like PostScript\n" if (!/^%!/);
  299. X    }
  300. X
  301. X    # Check second line for a4-a5 title
  302. X    if ($. == 2) {
  303. X        if (!/converted to a5/) {
  304. X        die "$0: Error: input hasn't been converted to a5 format\n";
  305. X        }
  306. X    }
  307. X
  308. X    # Skip header
  309. X    if ($body == 0) {
  310. X        $body = 1 if (/^%%EndProlog/);
  311. X        next;
  312. X    }
  313. X
  314. X    # Rip out document formatting comments
  315. X    next if (/^%%/);
  316. X
  317. X    # De-comment the original ones
  318. X    $_ = $1 . "\n" if (/^%\|(%%.*)/);
  319. X
  320. X    # Remove last line
  321. X    next if (/^a5finish/);
  322. X
  323. X    # Echo input
  324. X    print $out $_;
  325. X    }
  326. }
  327. X
  328. # Give a usage message and exit
  329. sub usage {
  330. X    print STDERR "Usage: a4-a5 [options] [file...]\n\n";
  331. X    print STDERR "-o file     write to specified file\n";
  332. X    print STDERR "-f          force processing\n";
  333. X    print STDERR "-r          reverse operation\n";
  334. X    print STDERR "-h file     use alternate header file\n";
  335. X    print STDERR "-v          print program version\n";
  336. X    exit 1;
  337. }
  338. SHAR_EOF
  339.   $shar_touch -am 1031090394 'a4-a5.pl' &&
  340.   chmod 0444 'a4-a5.pl' ||
  341.   echo 'restore of a4-a5.pl failed'
  342.   shar_count="`wc -c < 'a4-a5.pl'`"
  343.   test 3085 -eq "$shar_count" ||
  344.     echo "a4-a5.pl: original size 3085, current size $shar_count"
  345. fi
  346. # ============= a4-a5.ps ==============
  347. if test -f 'a4-a5.ps' && test X"$1" != X"-c"; then
  348.   echo 'x - skipping a4-a5.ps (File already exists)'
  349. else
  350.   echo 'x - extracting a4-a5.ps (text)'
  351.   sed 's/^X//' << 'SHAR_EOF' > 'a4-a5.ps' &&
  352. % PostScript header for A4-A5 converter (by G.Hutchings)
  353. X
  354. % $Id: a4-a5.ps,v 1.3 1994/09/12 10:29:01 glen Exp $
  355. X
  356. % Debugging stuff
  357. /debug false def
  358. X
  359. /msg {                % MESSAGE msg --> -
  360. X    debug { print (\n) print } { pop } ifelse
  361. } bind def
  362. X
  363. /val {                % MESSAGE VAR val --> -
  364. X    debug { exch print == } { pop pop } ifelse
  365. } bind def
  366. X
  367. % Setup
  368. /inch { 72 mul } def
  369. /a4-page-width 8.3 inch def
  370. /a4-page-height 11.7 inch def
  371. /a5-scale-factor a4-page-width a4-page-height div def
  372. /do-showpage false def
  373. X
  374. % Undefine save/restore (this gets output from psroff to work, but why
  375. % do I have to do this?)
  376. /really-save /save load def
  377. /really-restore /restore load def
  378. /save { mark } def
  379. /restore { pop } def
  380. X
  381. % Save old showpage and define new one
  382. /really-showpage /showpage load def
  383. X
  384. /showpage {
  385. X    grestore
  386. X    do-showpage {
  387. X    (Flushing page...) msg
  388. X        really-showpage
  389. X    a5first
  390. X    /do-showpage false def
  391. X    }{
  392. X    a5second
  393. X    /do-showpage true def
  394. X    } ifelse
  395. } bind def
  396. X
  397. % Translate to first a5 page
  398. /a5first {
  399. X    (Starting first A5 page...) msg
  400. X    gsave
  401. X    a4-page-width 0 translate
  402. X    a5-scale-factor dup scale
  403. X    90 rotate
  404. } bind def
  405. X
  406. % Translate to second a5 page
  407. /a5second {
  408. X    (Starting second A5 page...) msg
  409. X    gsave
  410. X    a4-page-width a4-page-height 2 div translate
  411. X    a5-scale-factor dup scale
  412. X    90 rotate
  413. } bind def
  414. X
  415. % Finish processing
  416. /a5finish {
  417. X    (Finishing up...) msg
  418. X    grestore
  419. X    do-showpage { really-showpage } if
  420. } bind def
  421. X
  422. % Start everything off
  423. a5first
  424. SHAR_EOF
  425.   $shar_touch -am 0912112994 'a4-a5.ps' &&
  426.   chmod 0444 'a4-a5.ps' ||
  427.   echo 'restore of a4-a5.ps failed'
  428.   shar_count="`wc -c < 'a4-a5.ps'`"
  429.   test 1477 -eq "$shar_count" ||
  430.     echo "a4-a5.ps: original size 1477, current size $shar_count"
  431. fi
  432. # ============= a4-a5.doc ==============
  433. if test -f 'a4-a5.doc' && test X"$1" != X"-c"; then
  434.   echo 'x - skipping a4-a5.doc (File already exists)'
  435. else
  436.   echo 'x - extracting a4-a5.doc (text)'
  437.   sed 's/^X//' << 'SHAR_EOF' > 'a4-a5.doc' &&
  438. #++
  439. # NAME
  440. #       a4-a5 1
  441. # SUMMARY
  442. #       convert PostScript from A4 to A5
  443. # SYNOPSIS
  444. #       a4-a5 [-rfv] [-o outfile] [-h header] files...
  445. # DESCRIPTION
  446. #       .I a4-a5
  447. #       converts A4 PostScript files to A5 format, so that each A4
  448. #       output page contains two input pages side by side.  If no
  449. #       files are specified,
  450. #       .I a4-a5
  451. #       takes input from stdin.
  452. # OPTIONS
  453. #       .fi
  454. #       .TP 8
  455. #       .I -o outfile
  456. #       Write output to
  457. #       .I outfile
  458. #       instead of stdout.
  459. #       .TP
  460. #       .I -f
  461. #       Normally,
  462. #       .I a4-a5
  463. #       barfs on input that doesn't look like PostScript.  This forces
  464. #       processing of the input in such a case.
  465. #       .TP
  466. #       .I -r
  467. #       Reverse the conversion.  Assume that the input has been
  468. #       converted by
  469. #       .I a4-a5
  470. #       and reconstruct the original file.
  471. #       .TP
  472. #       .I -h header
  473. #       Use the specified header file instead of the default one.  For
  474. #       those special customization moments.
  475. #       .TP
  476. #       .I -v
  477. #       Print program version.
  478. # RESTRICTIONS
  479. #       .fi
  480. #       .I
  481. #       a4-a5
  482. #       attempts to deal with special PostScript document formatting
  483. #       comments, where present, and produce output that adheres to
  484. #       them.  It's possible that files with weird comments can
  485. #       confuse it.
  486. # BUGS
  487. #       .fi
  488. #       The first page screws up for some reason when trying to deal
  489. #       with files produced by FrameMaker.  Also, to deal properly
  490. #       with
  491. #       .I psroff
  492. #       output, the save/restore commands have been disabled.
  493. #       PostScript input which relies on this construct will probably
  494. #       screw up.
  495. # FILES
  496. #       .TS
  497. #       tab(@);
  498. #       l l .
  499. #       %%LIBDIR%%/a4-a5.ps@Standard header file
  500. #       .TE
  501. # AUTHOR
  502. #       Glenn Hutchings (zondo@hunting2.demon.co.uk)
  503. #--
  504. SHAR_EOF
  505.   $shar_touch -am 1031090294 'a4-a5.doc' &&
  506.   chmod 0444 'a4-a5.doc' ||
  507.   echo 'restore of a4-a5.doc failed'
  508.   shar_count="`wc -c < 'a4-a5.doc'`"
  509.   test 1857 -eq "$shar_count" ||
  510.     echo "a4-a5.doc: original size 1857, current size $shar_count"
  511. fi
  512. # ============= a4-a5.man ==============
  513. if test -f 'a4-a5.man' && test X"$1" != X"-c"; then
  514.   echo 'x - skipping a4-a5.man (File already exists)'
  515. else
  516.   echo 'x - extracting a4-a5.man (text)'
  517.   sed 's/^X//' << 'SHAR_EOF' > 'a4-a5.man' &&
  518. X.TH A4-A5 1 
  519. X.fi
  520. X.SH NAME
  521. a4-a5
  522. \-
  523. convert PostScript from A4 to A5
  524. X.SH SYNOPSIS
  525. X.na
  526. X.nf
  527. a4-a5 [-rfv] [-o outfile] [-h header] files...
  528. X.SH DESCRIPTION
  529. X.fi
  530. X.I a4-a5
  531. converts A4 PostScript files to A5 format, so that each A4
  532. output page contains two input pages side by side.  If no
  533. files are specified,
  534. X.I a4-a5
  535. takes input from stdin.
  536. X.SH OPTIONS
  537. X.na
  538. X.nf
  539. X.fi
  540. X.TP 8
  541. X.I -o outfile
  542. Write output to
  543. X.I outfile
  544. instead of stdout.
  545. X.TP
  546. X.I -f
  547. Normally,
  548. X.I a4-a5
  549. barfs on input that doesn't look like PostScript.  This forces
  550. processing of the input in such a case.
  551. X.TP
  552. X.I -r
  553. Reverse the conversion.  Assume that the input has been
  554. converted by
  555. X.I a4-a5
  556. and reconstruct the original file.
  557. X.TP
  558. X.I -h header
  559. Use the specified header file instead of the default one.  For
  560. those special customization moments.
  561. X.TP
  562. X.I -v
  563. Print program version.
  564. X.SH RESTRICTIONS
  565. X.na
  566. X.nf
  567. X.fi
  568. X.I
  569. a4-a5
  570. attempts to deal with special PostScript document formatting
  571. comments, where present, and produce output that adheres to
  572. them.  It's possible that files with weird comments can
  573. confuse it.
  574. X.SH BUGS
  575. X.fi
  576. X.fi
  577. The first page screws up for some reason when trying to deal
  578. with files produced by FrameMaker.  Also, to deal properly
  579. with
  580. X.I psroff
  581. output, the save/restore commands have been disabled.
  582. PostScript input which relies on this construct will probably
  583. screw up.
  584. X.SH FILES
  585. X.na
  586. X.nf
  587. X.TS
  588. tab(@);
  589. l l .
  590. %%LIBDIR%%/a4-a5.ps@Standard header file
  591. X.TE
  592. X.SH AUTHOR
  593. X.na
  594. X.nf
  595. Glenn Hutchings (zondo@hunting2.demon.co.uk)
  596. SHAR_EOF
  597.   $shar_touch -am 1031090294 'a4-a5.man' &&
  598.   chmod 0664 'a4-a5.man' ||
  599.   echo 'restore of a4-a5.man failed'
  600.   shar_count="`wc -c < 'a4-a5.man'`"
  601.   test 1481 -eq "$shar_count" ||
  602.     echo "a4-a5.man: original size 1481, current size $shar_count"
  603. fi
  604. exit 0
  605.  
  606. -- 
  607.