home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / ps / psnup / psnup.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1991-02-26  |  2.0 KB  |  114 lines

  1. : use /bin/sh
  2. #    Copyright 1991, Chris Lewis, All Rights Reserved.
  3. #
  4. #    Permission to copy and further distribute is freely given provided
  5. #    this copyright notice remains intact and that this software is not
  6. #    sold for profit.
  7. #
  8. trap "rm -f /tmp/?$$" 0
  9. rm -f /tmp/?$$
  10.  
  11. pages=2
  12. #    Default is reversed for use with psroff with psxlate in the
  13. #    pipeline to reverse pages.
  14. reverse=true
  15. start=1
  16.  
  17. for i
  18. do
  19.     case $i in
  20.     -p2 | -p4 | -p8 | -p16)
  21.         pages=`echo $i | sed -e 's/^..//'`
  22.         if [ -z "$pages" -o -n "`echo $pages | sed -e 's/[0-9]*//'`" ]
  23.         then
  24.         echo "$0: Non-numeric pages per sheet option $i" >&2
  25.         exit 1
  26.         fi
  27.         ;;
  28.     -p*)
  29.         echo "$0: -p option ($i) must be 2, 4, 8 or 16" >&2
  30.         exit 1
  31.         ;;
  32.     -r)
  33.         reverse=false
  34.         ;;
  35.     -R)
  36.         reverse=true
  37.         ;;
  38.     -s*)
  39.         start=`echo $i | sed -e 's/^..//'`
  40.         if [ -z "$start" -o -n "`echo $start | sed -e 's/[0-9]*//'`" ]
  41.         then
  42.         echo "$0: Non-numeric start spot option $i" >&2
  43.         exit 1
  44.         fi
  45.         ;;
  46.     -*)
  47.         echo "$0: invalid option $i" >&2
  48.         echo "usage: $0 [-pn] [-r | -t] [-sn] files" >&2
  49.         exit 1
  50.         ;;
  51.     *)
  52.         files="$files $i"
  53.         ;;
  54.     esac
  55.     shift
  56. done
  57. if [ $start -gt $pages ]
  58. then
  59.     echo "$0: start option (-s$start) must be <= pages/sheet (-p$pages)" \
  60.     >&2
  61.     exit 1
  62. fi
  63. #echo pages $pages
  64. #echo rev $reverse
  65. #echo start $start
  66.  
  67. eof=`echo X | tr 'X' '\004'`
  68.  
  69. if [ -z "$files" ]
  70. then
  71.     files=-
  72. fi
  73.  
  74. touch /tmp/A$$ /tmp/B$$
  75.  
  76. (
  77.     cat $files
  78.     echo
  79. ) | sed -e '1w /tmp/A'$$ \
  80.     -e '1d' \
  81.     -e '/^'$eof'$/w /tmp/B'$$ \
  82.     -e '/^'$eof'$/d' > /tmp/C$$
  83.  
  84. if grep '^%' /tmp/A$$ > /dev/null
  85. then
  86.     cat /tmp/A$$
  87.     > /tmp/A$$
  88. else
  89.     echo "%!"
  90. fi
  91.  
  92. sed -e '/@#@Pages@#@/s//'$pages'/' \
  93.     -e '/@#@Rev@#@/s//'$reverse'/' \
  94.     -e '/@#@Start@#@/s//'$start'/' <<\!ENDPRO
  95. @@@nup.pro@@@
  96. !ENDPRO
  97.  
  98. cat /tmp/A$$
  99. cat /tmp/C$$
  100.  
  101. cat <<\!ENDEPI
  102. @@@nup.epi@@@
  103. !ENDEPI
  104. if [ -s /tmp/B$$ ]
  105. then
  106.     echo "\c" > /tmp/A$$
  107.     if [ -s /tmp/A$$ ]
  108.     then
  109.     echo -n "$eof"
  110.     else
  111.     echo "$eof\c"
  112.     fi
  113. fi
  114.