#!/usr/bin/sed -f
:main
# remove most of the binary garbage
1i\
$i\
/[^[:print:]]\{6,\}/d
/^[^[:print:]]\{1,\}$/d
# Structure sequences
# ^S ... ^T ... ^U is a control sequence
# where is one of
# xe chapter heading ?
# tc table of contents entry
# SEQ section numbering
# PAGE page numbers
# TOC table of contents
# *german versions also:
# PRIVAT trash
# inhalt like `tc'
# XE like `xe'
# Form feeds -> hrule
#//i\
#
s%%%g
# section/chapter heading
s%^xe "\([[:print:]]*\)"\([[:print:]]*\)$%\2
%
s%^XE "\([[:print:]]*\)"\([[:print:]]*\)$%\2
%
s%SEQ[^]*%%g
s%\([^]*\)tc[ ]\{1,\}\\l[ ]*\([0-9]\{1,\}\)[ ]*"\(\([^ ]*\) *.*\)"%\3%
s%\([^]*\)tc[ ]\{1,\}\\l[ ]*\([0-9]\{1,\}\)[ ]*"\(\([^ ]*\) *.*\)%\3%
# Table of contents
/^TOC .*/ { g
i\
Contents
:toc-loop
n
/^[ ]*$/btoc-line
/^\(.*\) [0-9ivxlcm]\{1,\}$/btoc-line
/^/d
btoc-end
:toc-line
/^[ ]*$/i\
s%^\(\([^ ]*\) *.*\) [0-9ivxlcm]\{1,\}$%\1
%
btoc-loop
:toc-end
}
# Tables
# A: ^^G^G^G^G^G^G^G^G^G$
# by row.
/$/ {
i\
:tab-loop
/$/btab-data
btab-end
:tab-data
s%\([^]*\)$%\1 |
%
s%\([^]*\)$%\1 | %
n
btab-loop
:tab-end
i\
}
# B: ^ $
# by row.
#/ / {
# i\
#
# :tabB-loop
# / /btabB-data
# /^[ ]*$/ {
# i\
#
# g
# n
# btabB-loop
# }
# btabB-end
# :tabB-data
# /$/btabB-last
# s%^\([^ ]\{1,\}\)[ ]\{1,\}%\1 | %
##s%\([^ ]\{1,\}\)[ ]\{1,\}%\1 | %g
# s% \([^ ]\{1,\}\)[ ]*$%\1 |
%g
# n
# btabB-loop
# :tabB-last
# s%\([^ ]\{1,\}\)*$%\1 | %g
# :tabB-end
# i\
#
#}
# Footnotes
# ^B footnotemarks (in the text)
# ^B footnote (beginning of line)
# footnotes match by order
s%^%$NOTE++$
%
s%%$MARK++$%
# Paragraph
s%^[ ]*$%%
#s%[^>]$%\
#
%
# end of main
n
bmain