Skip to content

Instantly share code, notes, and snippets.

@mjf
Created October 11, 2012 10:49
Show Gist options
  • Save mjf/3871606 to your computer and use it in GitHub Desktop.
Save mjf/3871606 to your computer and use it in GitHub Desktop.
ASCIIPS - ASCII file to PostScript Converter
#! /bin/sh
# ASCIIPS - ASCII file to PostScript Converter
# Copyright (C) 2012 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
ASCIIPS_CREATOR=${ASCIIPS_CREATOR:-ASCIIPS}
ASCIIPS_FONT=${ASCIIPS_FONT:-Courier}
ASCIIPS_FONTSIZE=${ASCIIPS_FONTSIZE:-12}
cat << .
%!-Adobe-1.0
%%Title: ${1:-Standard Input}
%%Creator: $ASCIIPS_CREATOR
/$ASCIIPS_FONT findfont $ASCIIPS_FONTSIZE scalefont setfont
/colwid (m) stringwidth pop def
36 756 moveto
256 string
{ %exec
{ %loop over file
dup currentfile exch readstring exch
{ %loop FF
(\f) search exch
{ %loop LF
(\n) search exch
{ %loop CR
(\r) search exch
{ %loop TAB
(\t) search exch
{ %loop BS
(\b) search exch
show
not { exit } if
pop currentpoint exch colwid sub exch moveto
} loop %BS
not { exit } if
pop currentpoint exch 36 sub colwid div .49 add cvi
8 add dup 8 mod sub colwid mul 36 add exch moveto
} loop %TAB
not { exit } if
pop 36 currentpoint exch pop moveto
} loop %CR
not { exit } if
pop 36 currentpoint exch pop
11 sub dup 25 le { %if
pop showpage 756
} if
moveto
} loop %LF
not { exit } if
pop showpage 36 756 moveto
} loop %FF
not { exit } if
} loop %over file
pop showpage
} bind exec
.
cat $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment