diff options
author | Serge V Shistarev <s.shistarev@i-wire.net> | 2014-03-21 18:05:09 +0900 |
---|---|---|
committer | Serge V Shistarev <s.shistarev@i-wire.net> | 2014-03-21 18:05:09 +0900 |
commit | a45bb470ad006008f1e939fd5293773f2f8ede0a (patch) | |
tree | bca32e6252041141e9ad0de2802e47047399f2a1 | |
parent | dcf4680d1a2f979b4e422fcb9a31b3094c49baaf (diff) | |
download | ricoh-sp100-a45bb470ad006008f1e939fd5293773f2f8ede0a.tar.gz |
Modified for systems without inotify (e.g. OS X, *BSD, etc)
-rwxr-xr-x | pstoricohddst-gdi | 180 |
1 files changed, 120 insertions, 60 deletions
diff --git a/pstoricohddst-gdi b/pstoricohddst-gdi index 2913dd3..122d19e 100755 --- a/pstoricohddst-gdi +++ b/pstoricohddst-gdi @@ -30,74 +30,134 @@ ddate="`LC_ALL=en_US.UTF-8 date '+%Y/%m/%d %H:%M:%S'`" uid="/tmp/pstoricohddst-gdi-`uuidgen`" mkdir -p $uid -( -stage="empty" -inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do - # page submitted - [ "$stage" = "empty" ] && { - # Flushing PJL header - cat <<EOF -%-12345X@PJL
-@PJL SET TIMESTAMP=$ddate
-@PJL SET FILENAME=Document
-@PJL SET COMPRESS=JBIG
-@PJL SET USERNAME=$user
-@PJL SET COVER=OFF
-@PJL SET HOLD=OFF
+[ -x "/usr/bin/inotifywait" ] && { + + ( + stage="empty" + inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do + # page submitted + [ "$stage" = "empty" ] && { + # Flushing PJL header + cat <<EOF +%-12345X@PJL +@PJL SET TIMESTAMP=$ddate +@PJL SET FILENAME=Document +@PJL SET COMPRESS=JBIG +@PJL SET USERNAME=$user +@PJL SET COVER=OFF +@PJL SET HOLD=OFF EOF - stage="printing" - } - [ "$page" = "999999999-page.pbm" ] && { - # Flushing PJL footer + stage="printing" + } + [ "$page" = "999999999-page.pbm" ] && { + # Flushing PJL footer + cat <<EOF +@PJL EOJ +%-12345X +EOF + pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '` + [ ! "x$pid" = "x" ] && kill $pid + break + } + [ "$stage" = "printing" ] && { + # Converting page to JBIG format (parameters are very special for this printer!) + pbmtojbg -p 72 -o 3 -m 0 -q < $uid/$page > $uid/raster.jbig + + # Taking image size + jsize=`wc -c < $uid/raster.jbig` + + # Taking image dimensions + read fn ft xs ys garb < <(identify $uid/$page | tr "x" " ") + + # Flushing page header + cat <<EOF +@PJL SET PAGESTATUS=START +@PJL SET COPIES=1 +@PJL SET MEDIASOURCE=AUTO +@PJL SET MEDIATYPE=PLAINRECYCLE +@PJL SET PAPER=A4 +@PJL SET PAPERWIDTH=$xs +@PJL SET PAPERLENGTH=$ys +@PJL SET RESOLUTION=600 +@PJL SET IMAGELEN=$jsize +EOF + + # Flushing image + cat $uid/raster.jbig + + # Flushing page footer + # TODO: pixelcount for toner estimate + cat <<EOF +@PJL SET DOTCOUNT=1132782 +@PJL SET PAGESTATUS=END +EOF + } + done + ) & + + # Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) + gs -sDEVICE=ps2write -sOutputFile=- -r600 -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r600 -dQUIET -dBATCH -dNOPAUSE - + + stop + wait + + trapINT +} || { + + # Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) + gs -sDEVICE=ps2write -sOutputFile=- -r600 -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r600 -dQUIET -dBATCH -dNOPAUSE - + cat <<EOF -@PJL EOJ
-%-12345X
+%-12345X@PJL +@PJL SET TIMESTAMP=$ddate +@PJL SET FILENAME=Document +@PJL SET COMPRESS=JBIG +@PJL SET USERNAME=$user +@PJL SET COVER=OFF +@PJL SET HOLD=OFF EOF - pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '` - [ ! "x$pid" = "x" ] && kill $pid - break - } - [ "$stage" = "printing" ] && { - # Converting page to JBIG format (parameters are very special for this printer!) - pbmtojbg -p 72 -o 3 -m 0 -q < $uid/$page > $uid/raster.jbig - - # Taking image size - jsize=`wc -c < $uid/raster.jbig` - - # Taking image dimensions - read fn ft xs ys garb < <(identify $uid/$page | tr "x" " ") - - # Flushing page header - cat <<EOF -@PJL SET PAGESTATUS=START
-@PJL SET COPIES=1
-@PJL SET MEDIASOURCE=AUTO
-@PJL SET MEDIATYPE=PLAINRECYCLE
-@PJL SET PAPER=A4
-@PJL SET PAPERWIDTH=$xs
-@PJL SET PAPERLENGTH=$ys
-@PJL SET RESOLUTION=600
-@PJL SET IMAGELEN=$jsize
+ + for page in ${uid}/*-page.pbm; do + + # Converting page to JBIG format (parameters are very special for this printer!) + pbmtojbg -p 72 -o 3 -m 0 -q < $page > $uid/raster.jbig + + # Taking image size + jsize=`wc -c < $uid/raster.jbig` + + # Taking image dimensions + read fn ft xs ys garb < <(identify $page | tr "x" " ") + + # Flushing page header + cat <<EOF +@PJL SET PAGESTATUS=START +@PJL SET COPIES=1 +@PJL SET MEDIASOURCE=AUTO +@PJL SET MEDIATYPE=PLAINRECYCLE +@PJL SET PAPER=A4 +@PJL SET PAPERWIDTH=$xs +@PJL SET PAPERLENGTH=$ys +@PJL SET RESOLUTION=600 +@PJL SET IMAGELEN=$jsize EOF - # Flushing image - cat $uid/raster.jbig + # Flushing image + cat $uid/raster.jbig - # Flushing page footer - # TODO: pixelcount for toner estimate - cat <<EOF -@PJL SET DOTCOUNT=1132782
-@PJL SET PAGESTATUS=END
+ # Flushing page footer + # TODO: pixelcount for toner estimate + cat <<EOF +@PJL SET DOTCOUNT=1132782 +@PJL SET PAGESTATUS=END EOF - } -done -) & + done -# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page) -gs -sDEVICE=psmono -sOutputFile=- -r600 -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%d-page.pbm -r600 -dQUIET -dBATCH -dNOPAUSE - + # Flushing PJL footer + cat <<EOF +@PJL EOJ +%-12345X +EOF -stop -wait +} -trapINT |