PageRenderTime 80ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/frameworks/trunk/zziplib/libzziplib/docs/mksite.sh

#
Shell | 1689 lines | 1457 code | 107 blank | 125 comment | 200 complexity | 1e4d2b0ec0665e789ed105fb2186902f MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, BSD-3-Clause, GPL-3.0, LGPL-3.0, MPL-2.0-no-copyleft-exception, Zlib, GPL-2.0
  1. #! /bin/sh
  2. # this is the sh/sed variant of the mksite script. It is largely
  3. # derived from snippets that I was using to finish doc pages for
  4. # website publishing. For the mksite project the functionaliy has
  5. # been expanded of course. Still this one does only use simple unix
  6. # commands like sed, date, and test. And it still works. :-)=)
  7. # http://zziplib.sf.net/mksite/
  8. # THE MKSITE.SH (ZLIB/LIBPNG) LICENSE
  9. # Copyright (c) 2004 Guido U. Draheim <guidod@gmx.de>
  10. # This software is provided 'as-is', without any express or implied warranty
  11. # In no event will the authors be held liable for any damages arising
  12. # from the use of this software.
  13. # Permission is granted to anyone to use this software for any purpose,
  14. # including commercial applications, and to alter it and redistribute it
  15. # freely, subject to the following restrictions:
  16. # 1. The origin of this software must not be misrepresented; you must not
  17. # claim that you wrote the original software. If you use this software
  18. # in a product, an acknowledgment in the product documentation would be
  19. # appreciated but is not required.
  20. # 2. Altered source versions must be plainly marked as such, and must not
  21. # be misrepresented as being the original software.
  22. # 3. This notice may not be removed or altered from any source distribution.
  23. # $Id: mksite.sh,v 1.5 2006-09-22 00:33:22 guidod Exp $
  24. # Zsh is not Bourne compatible without the following: (seen in autobook)
  25. if test -n "$ZSH_VERSION"; then
  26. emulate sh
  27. NULLCMD=:
  28. fi
  29. # initialize some defaults
  30. test ".$SITEFILE" = "." && test -f "site.htm" && SITEFILE="site.htm"
  31. test ".$SITEFILE" = "." && test -f "site.html" && SITEFILE="site.html"
  32. test ".$SITEFILE" = "." && SITEFILE="site.htm"
  33. MK="-mksite" # note the "-" at the start
  34. SED="sed"
  35. CAT="cat" # "sed -e n" would be okay too
  36. GREP="grep"
  37. DATE_NOW="date" # should be available on all posix systems
  38. DATE_R="date -r" # gnu date has it / solaris date not
  39. STAT_R="stat" # gnu linux
  40. LS_L="ls -l" # linux uses one less char than solaris
  41. DATA="~~" # extension for meta data files
  42. HEAD="~head~" # extension for head sed script
  43. BODY="~body~" # extension for body sed script
  44. FOOT="~foot~" # append to body text (non sed)
  45. NULL="/dev/null" # to divert stdout/stderr
  46. CATNULL="$CAT $NULL" # to create 0-byte files
  47. SED_LONGSCRIPT="$SED -f"
  48. Q='q class='
  49. QX='/q'
  50. LOWER="abcdefghijklmnopqrstuvwxyz"
  51. UPPER="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  52. az="$LOWER" # some old sed tools can not
  53. AZ="$UPPER" # use char-ranges in the
  54. NN="0123456789" # match expressions so that
  55. AA="_$NN$AZ$az" # we use their unrolled
  56. AX="$AA.+-" # definition here
  57. AP="|" # (pipe symbol in char-range)
  58. AK="[" # (open range in char-range)
  59. LANG="C" ; LANGUAGE="C" ; LC_COLLATE="C" # these are needed for proper
  60. export LANG LANGUAGE LC_COLLATE # lowercasing as some collate
  61. # treat A-Z to include a-z
  62. HTMLTAGS=" a p h1 h2 h3 h4 h5 h6 dl dd dt ul ol li pre code table tr td th"
  63. HTMLTAGS=" $HTMLTAGS b u i s q em strong strike cite big small sup sub tt"
  64. HTMLTAGS=" $HTMLTAGS thead tbody center hr br nobr wbr"
  65. HTMLTAGS=" $HTMLTAGS span div img adress blockquote"
  66. HTMLTAGS2=" html head body title meta http-equiv style link"
  67. # ==========================================================================
  68. if "${SHELL-/bin/sh}" -c 'foo () { exit 0; }; foo' 2>$NULL ; then : ; else
  69. echo "!! sorry, this shell '$SHELL' does not support shell functions" ; exit 1
  70. fi
  71. error ()
  72. {
  73. echo "ERROR:" "$@" 1>&2
  74. }
  75. warn ()
  76. {
  77. echo "WARN:" "$@" 1>&2
  78. }
  79. note ()
  80. {
  81. echo "NOTE:" "$@" 1>&2
  82. }
  83. hint=":"
  84. init ()
  85. {
  86. if test -d DEBUG
  87. then hint="note"
  88. fi
  89. if test "$SED" = "sed" ; then
  90. if gsed --version 2>$NULL | $GREP "GNU sed" >$NULL ; then
  91. SED="gsed"
  92. $hint "using 'gsed' as SED"
  93. fi
  94. fi
  95. if $SED --version 2>$NULL | $GREP "GNU sed" >$NULL ; then
  96. az="a-z" # but if we have GNU sed
  97. AZ="A-Z" # then we assume there are
  98. NN="0-9" # char-ranges available
  99. AA="_$NN$AZ$az" # that makes the resulting
  100. AX="$AA.+-" # script more readable
  101. $hint "found GNU sed - good"
  102. elif uname -s | $GREP HP-UX >$NULL ; then
  103. SED_LONGSCRIPT="sed_longscript" # due to 100 sed lines limit
  104. $hint "weird sed - hpux sed has a limit of 100 lines" \
  105. "- using sed_longscript mode"
  106. fi
  107. if echo "TEST" | sed -e "s%[:[]*TEST%OK%" | grep OK 2>&1 > $NULL
  108. then :
  109. elif echo "TEST" | sed -e "s%[:\\[]*TEST%OK%" | grep OK 2>&1 > $NULL
  110. then AK="\\[" ; $hint "AK=\\["
  111. else AK="" ; warn "buggy sed - disabled [ in char-ranges / fileref-tests"
  112. fi
  113. if echo "TEST" | sed -e "s%[:|]*TEST%OK%" | grep OK 2>&1 > $NULL
  114. then :
  115. elif echo "TEST" | sed -e "s%[:\\|]*TEST%OK%" | grep OK 2>&1 > $NULL
  116. then AP="\\[" ; $hint "AP=\\|"
  117. else AP="" ; warn "buggy sed - disabled | in char-ranges / fileref-tests"
  118. fi
  119. }
  120. init "NOW!!!"
  121. sed_debug ()
  122. {
  123. $note "sed" "$@" >&2
  124. sed "$@"
  125. }
  126. # ==========================================================================
  127. # reading options from the command line GETOPT
  128. opt_variables="files"
  129. opt_fileseparator="?"
  130. opt_files=""
  131. opt_main_file=""
  132. opt_formatter="$0"
  133. opt=""
  134. for arg in "$@" # this variant should allow to embed spaces in $arg
  135. do if test ".$opt" != "." ; then
  136. eval "export opt_$opt='$arg'"
  137. opt=""
  138. else
  139. case "$arg" in
  140. -*=*)
  141. opt=`echo "$arg" | $SED -e "s/-*\\([$AA][$AA-]*\\).*/\\1/" -e y/-/_/`
  142. if test ".$opt" = "." ; then
  143. error "invalid option $arg"
  144. else
  145. arg=`echo "$arg" | $SED -e "s/^[^=]*=//"`
  146. eval "export opt_$opt='$arg'"
  147. opt_variables="$opt_variables $opt"
  148. fi
  149. opt="" ;;
  150. -*?-*) : an option with an argument --main-file=x or --main-file x
  151. opt=`echo "$arg" | $SED -e "s/-*\\([$AA][$AA-]*\\).*/\\1/" -e y/-/_/`
  152. if test ".$opt" = "." ; then
  153. error "invalid option $arg"
  154. opt=""
  155. else :
  156. # keep the option for next round
  157. fi ;;
  158. -*) : a simple option --filelist or --debug or --verbose
  159. opt=`echo "$arg" | $SED -e "s/^-*\\([$AA][$AA-]*\\).*/\\1/" -e y/-/_/`
  160. if test ".$opt" = "." ; then
  161. error "invalid option $arg"
  162. else
  163. arg=`echo "$arg" | $SED -e "s/^[^=]*=//"`
  164. eval "export opt_$opt=' '"
  165. fi
  166. opt="" ;;
  167. *) $hint "<$arg>"
  168. if test ".$opt_main_file" = "." ; then opt_main_file="$arg" ; else
  169. test ".$opt_files" != "." && opt_files="$opt_files$opt_fileseparator"
  170. opt_files="$opt_files$arg" ; fi
  171. opt="" ;;
  172. esac
  173. fi
  174. done ; if test ".$opt" != "." ; then
  175. eval "export opt_$opt='$arg'"
  176. opt=""
  177. fi
  178. ### env | grep ^opt
  179. test ".$opt_main_file" != "." && test -f "$opt_main_file" && \
  180. SITEFILE="$opt_main_file"
  181. test ".$opt_site_file" != "." && test -f "$opt_site_file" && \
  182. SITEFILE="$opt_site_file"
  183. test "$opt_debug" && \
  184. hint="note"
  185. if test ".$opt_help" != "." ; then
  186. F="$SITEFILE"
  187. echo "$0 [sitefile]";
  188. echo " default sitefile = $F";
  189. echo "options:";
  190. echo " --filelist : show list of target files as ectracted from $F"
  191. echo " --src-dir xx : if source files are not where mksite is executed"
  192. echo " --tmp-dir xx : use temp instead of local directory"
  193. echo " --tmp : use automatic temp directory in ${TEMP-/tmp}/mksite.*"
  194. exit;
  195. echo " internal:"
  196. echo "--fileseparator=x : for building the internal filelist (default '?')"
  197. echo "--files xx : for list of additional files to be processed"
  198. echo "--main-file xx : for the main sitefile to take file list from"
  199. fi
  200. if test ".$SITEFILE" = "." ; then
  201. error "no SITEFILE found (default would be 'site.htm')"
  202. exit 1
  203. else
  204. $hint "sitefile:" `ls -s $SITEFILE`
  205. fi
  206. tmp="." ; if test ".$opt_tmp_dir" != "." ; then tmp="$opt_tmp_dir" ; fi
  207. if test ".$opt_tmp_dir" = "." && test ".$opt_tmp" != "." ; then
  208. tmp="${TEMP-/tmp}/mksite.$$" ; fi
  209. # we use external files to store mappings - kind of relational tables
  210. MK_TAGS="$tmp/$MK.tags.tmp.sed"
  211. MK_VARS="$tmp/$MK.vars.tmp.sed"
  212. MK_SPAN="$tmp/$MK.span.tmp.sed"
  213. MK_META="$tmp/$MK.meta.tmp.htm"
  214. MK_METT="$tmp/$MK.mett.tmp.htm"
  215. MK_TEST="$tmp/$MK.test.tmp.htm"
  216. MK_FAST="$tmp/$MK.fast.tmp.sed"
  217. MK_GETS="$tmp/$MK.gets.tmp.sed"
  218. MK_PUTS="$tmp/$MK.puts.tmp.sed"
  219. MK_SITE="$tmp/$MK.site.tmp.sed"
  220. MK_SECT1="$tmp/$MK.sect1.tmp.sed"
  221. MK_SECT2="$tmp/$MK.sect2.tmp.sed"
  222. MK_SECT3="$tmp/$MK.sect3.tmp.sed"
  223. MK_STYLE="$tmp/$MK.style.tmp.sed"
  224. MK_DATA="$tmp/$MK.$DATA.tmp.htm"
  225. # ========================================================================
  226. # ========================================================================
  227. # ========================================================================
  228. # MAGIC VARS
  229. # IN $SITEFILE
  230. printerfriendly=""
  231. sectionlayout="list"
  232. sitemaplayout="list"
  233. attribvars=" " # <x ref="${varname:=default}">
  234. updatevars=" " # <!--$varname:=-->default
  235. expandvars=" " # <!--$varname-->
  236. commentvars=" " # $updatevars && $expandsvars
  237. sectiontab=" " # highlight ^<td class=...>...href="$section"
  238. currenttab=" " # highlight ^<br>..<a href="$topic">
  239. headsection="no"
  240. tailsection="no"
  241. sectioninfo="no" # using <h2> title <h2> = info text
  242. emailfooter="no"
  243. if $GREP "<!--multi-->" $SITEFILE >$NULL ; then
  244. echo \
  245. "WARNING: do not use <!--multi-->, change to <!--mksite:multi--> " "$SITEFILE"
  246. echo \
  247. "warning: or <!--mksite:multisectionlayout--> <!--mksite:multisitemaplayout-->"
  248. sectionlayout="multi"
  249. sitemaplayout="multi"
  250. fi
  251. if $GREP "<!--mksite:multi-->" $SITEFILE >$NULL ; then
  252. sectionlayout="multi"
  253. sitemaplayout="multi"
  254. fi
  255. if $GREP "<!--mksite:multilayout-->" $SITEFILE >$NULL ; then
  256. sectionlayout="multi"
  257. sitemaplayout="multi"
  258. fi
  259. mksite_magic_option ()
  260. {
  261. # $1 is word/option to check for
  262. INP="$2" ; test ".$INP" = "." && INP="$SITEFILE"
  263. $SED \
  264. -e "s/\\(<!--mksite:\\)\\($1\\)-->/\\1\\2: -->/g" \
  265. -e "s/\\(<!--mksite:\\)\\([$AA][$AA]*\\)\\($1\\)-->/\\1\\3:\\2-->/g" \
  266. -e "/<!--mksite:$1:/!d" \
  267. -e "s/.*<!--mksite:$1:\\([^<>]*\\)-->.*/\\1/" \
  268. -e "s/.*<!--mksite:$1:\\([^-]*\\)-->.*/\\1/" \
  269. -e "/<!--mksite:$1:/d" -e q $INP # $++
  270. }
  271. x=`mksite_magic_option sectionlayout` ; case "$x" in
  272. "list"|"multi") sectionlayout="$x" ;; esac
  273. x=`mksite_magic_option sitemaplayout` ; case "$x" in
  274. "list"|"multi") sitemaplayout="$x" ;; esac
  275. x=`mksite_magic_option attribvars` ; case "$x" in
  276. " "|"no"|"warn") attribvars="$x" ;; esac
  277. x=`mksite_magic_option updatevars` ; case "$x" in
  278. " "|"no"|"warn") updatevars="$x" ;; esac
  279. x=`mksite_magic_option expandvars` ; case "$x" in
  280. " "|"no"|"warn") expandvars="$x" ;; esac
  281. x=`mksite_magic_option commentvars` ; case "$x" in
  282. " "|"no"|"warn") commentvars="$x" ;; esac
  283. x=`mksite_magic_option printerfriendly` ; case "$x" in
  284. " "|".*"|"-*") printerfriendly="$x" ;; esac
  285. x=`mksite_magic_option sectiontab` ; case "$x" in
  286. " "|"no"|"warn") sectiontab="$x" ;; esac
  287. x=`mksite_magic_option currenttab` ; case "$x" in
  288. " "|"no"|"warn") currenttab="$x" ;; esac
  289. x=`mksite_magic_option sectioninfo` ; case "$x" in
  290. " "|"no"|"[=:-]") sectioninfo="$x" ;; esac
  291. x=`mksite_magic_option emailfooter`
  292. test ".$x" != "." && emailfooter="$x"
  293. test ".$opt_print" != "." && printerfriendly="$opt_print"
  294. test ".$commentvars" = ".no" && updatevars="no" # duplicated into
  295. test ".$commentvars" = ".no" && expandvars="no" # info2vars_sed ()
  296. $hint "'$sectionlayout'sectionlayout '$sitemaplayout'sitemaplayout"
  297. $hint "'$attribvars'attribvars '$updatevars'updatevars"
  298. $hint "'$expandvars'expandvars '$commentvars'commentvars "
  299. $hint "'$currenttab'currenttab '$sectiontab'sectiontab"
  300. $hint "'$headsection'headsection '$tailsection'tailsection"
  301. if ($STAT_R "$SITEFILE" >$NULL) 2>$NULL ; then : ; else STAT_R=":" ; fi
  302. # ==========================================================================
  303. # init a few global variables
  304. # 0. INIT
  305. mkpathdir () {
  306. if test -n "$1" && test ! -d "$1" ; then
  307. echo "!! mkdir '$1'" ; mkdir "$1"
  308. test ! -d "$1" || mkdir -p "$1"
  309. fi
  310. }
  311. mkpathfile () {
  312. dirname=`echo "$1" | $SED -e "s:/[^/][^/]*\$::"`
  313. if test ".$1" != ".$dirname" && test ".$dirname" != "." ;
  314. then mkpathdir "$dirname"; fi
  315. }
  316. mknewfile () {
  317. mkpathfile "$1"
  318. $CATNULL > "$1"
  319. }
  320. tmp_dir_was_created="no"
  321. if test ! -d "$tmp" ; then mkpathdir "$tmp" ; tmp_dir_was_created="yes" ; fi
  322. # $MK_TAGS - originally, we would use a lambda execution on each
  323. # uppercased html tag to replace <P> with <p class="P">. Here we just
  324. # walk over all the known html tags and make an sed script that does
  325. # the very same conversion. There would be a chance to convert a single
  326. # tag via "h;y;x" or something we do want to convert all the tags on
  327. # a single line of course.
  328. mknewfile "$MK_TAGS"
  329. for M in `echo $HTMLTAGS`
  330. do P=`echo "$M" | $SED -e "y/$LOWER/$UPPER/"`
  331. echo "s|<$P>|<$M class=\"$P\">|g" >> "$MK_TAGS"
  332. echo "s|<$P |<$M class=\"$P\" |g" >> "$MK_TAGS"
  333. echo "s|</$P>|</$M>|g" >> "$MK_TAGS"
  334. done
  335. echo "s|<>|\\&nbsp\\;|g" >> "$MK_TAGS"
  336. echo "s|<->|<WBR />|g" >> "$MK_TAGS"
  337. echo "s|<c>|<code>|g" >> "$MK_TAGS"
  338. echo "s|</c>|</code>|g" >> "$MK_TAGS"
  339. echo "s|<section>||g" >> "$MK_TAGS"
  340. echo "s|</section>||g" >> "$MK_TAGS"
  341. echo "s|<\\(a [^<>]*\\) />|<\\1></a>|g" >> "$MK_TAGS"
  342. _ulink_="<a href=\"\\1\" remap=\"url\">\\1</a>"
  343. echo "s|<a>\\([$az$AZ][$az$AZ]*://[^<>]*\\)</a>|$_ulink_|g" >> "$MK_TAGS"
  344. # also make sure that some non-html entries are cleaned away that
  345. # we are generally using to inject meta information. We want to see
  346. # that meta ino in the *.htm browser view during editing but they
  347. # shall not get present in the final html page for publishing.
  348. DC_VARS="contributor date source language coverage identifier"
  349. DC_VARS="$DC_VARS rights relation creator subject description"
  350. DC_VARS="$DC_VARS publisher DCMIType"
  351. _EQUIVS="refresh expires content-type cache-control"
  352. _EQUIVS="$_EQUIVS redirect charset" # mapped to refresh / content-type
  353. _EQUIVS="$_EQUIVS content-language content-script-type content-style-type"
  354. for P in $DC_VARS $_EQUIVS ; do # dublin core embedded
  355. echo "s|<$P>[^<>]*</$P>||g" >> "$MK_TAGS"
  356. done
  357. test ".$opt_keepsect" = "." && \
  358. echo "s|<a sect=\"[$AZ$NN]\"|<a|g" >> "$MK_TAGS"
  359. echo "s|<!--[$AX]*[?]-->||g" >> "$MK_TAGS"
  360. echo "s|<!--\\\$[$AX]*[?]:-->||g" >> "$MK_TAGS"
  361. echo "s|<!--\\\$[$AX]*:[?=]-->||g" >> "$MK_TAGS"
  362. echo "s|\\(<[^<>]*\\)\\\${[$AX]*:[?=]\\([^<{}>]*\\)}\\([^<>]*>\\)|\\1\\2\\3|g" >>$MK_TAGS
  363. # see overview at www.metatab.de - http-equivs are
  364. # <refresh>5; url=target</reresh> or <redirect>target</redirect>
  365. # <content-type>text/html; charset=koi8-r</content-type> iso-8859-1/UTF-8
  366. # <content-language>de</content-language> <charset>UTF-8</charset>
  367. # <content-script-type>text/javascript</content-script-type> /jscript/vbscript
  368. # <content-style-type>text/css</content-style-type>
  369. # <cache-control>no-cache</cache-control>
  370. trimm ()
  371. {
  372. echo "$1" | $SED -e "s:^ *::" -e "s: *\$::";
  373. }
  374. trimmm ()
  375. {
  376. echo "$1" | $SED -e "s:^ *::" -e "s: *\$::" -e "s:[ ][ ]*: :g";
  377. }
  378. timezone ()
  379. {
  380. # +%z is an extension while +%Z is supposed to be posix
  381. _timezone=`$DATE_NOW +%z`
  382. case "$_timezone" in
  383. *+*) echo "$_timezone" ;;
  384. *-*) echo "$_timezone" ;;
  385. *) $DATE_NOW +%Z
  386. esac
  387. }
  388. timetoday ()
  389. {
  390. $DATE_NOW +%Y-%m-%d
  391. }
  392. timetodays ()
  393. {
  394. $DATE_NOW +%Y-%m%d
  395. }
  396. # ======================================================================
  397. # FUNCS
  398. sed_longscript ()
  399. {
  400. # hpux sed has a limit of 100 entries per sed script !
  401. $SED -e "100q" "$1" > "$1~1~"
  402. $SED -e "1,100d" -e "200q" "$1" > "$1~2~"
  403. $SED -e "1,200d" -e "300q" "$1" > "$1~3~"
  404. $SED -e "1,300d" -e "400q" "$1" > "$1~4~"
  405. $SED -e "1,400d" -e "500q" "$1" > "$1~5~"
  406. $SED -e "1,500d" -e "600q" "$1" > "$1~6~"
  407. $SED -e "1,600d" -e "700q" "$1" > "$1~7~"
  408. $SED -e "1,700d" -e "800q" "$1" > "$1~8~"
  409. $SED -e "1,800d" -e "900q" "$1" > "$1~9~"
  410. $SED -f "$1~1~" -f "$1~2~" -f "$1~3~" -f "$1~4~" -f "$1~5~" \
  411. -f "$1~6~" -f "$1~7~" -f "$1~8~" -f "$1~9~" "$2"
  412. }
  413. sed_escape_key ()
  414. {
  415. $SED -e "s|\\.|\\\\&|g" -e "s|\\[|\\\\&|g" -e "s|\\]|\\\\&|g" "$@"
  416. }
  417. sed_slash_key () # helper to escape chars special in /anchor/ regex
  418. { # currently escaping "/" "[" "]" "."
  419. echo "$1" | sed_escape_key -e "s|/|\\\\&|g"
  420. }
  421. sed_piped_key () # helper to escape chars special in s|anchor|| regex
  422. { # currently escaping "|" "[" "]" "."
  423. echo "$1" | sed_escape_key -e "s/|/\\\\&/g"
  424. }
  425. back_path () # helper to get the series of "../" for a given path
  426. {
  427. echo "$1" | $SED -e "/\\//!d" -e "s|/[^/]*\$|/|" -e "s|[^/]*/|../|g"
  428. }
  429. dir_name ()
  430. {
  431. echo "$1" | $SED -e "s:/[^/][^/]*\$::"
  432. }
  433. piped_value="s/|/\\\\|/g"
  434. amp_value="s|&|\\\\&|g"
  435. info2vars_sed () # generate <!--$vars--> substition sed addon script
  436. {
  437. INP="$1" ; test ".$INP" = "." && INP="$tmp/$F.$DATA"
  438. V8=" *\\([^ ][^ ]*\\) \\(.*\\)<$QX>"
  439. V9=" *DC[.]\\([^ ][^ ]*\\) \\(.*\\)<$QX>"
  440. N8=" *\\([^ ][^ ]*\\) \\([$NN].*\\)<$QX>"
  441. N9=" *DC[.]\\([^ ][^ ]*\\) \\([$NN].*\\)<$QX>"
  442. V0="\\\\([<]*\\\\)\\\\\\\$"
  443. V1="\\\\([^<>]*\\\\)\\\\\\\$"
  444. V2="\\\\([^{<>}]*\\\\)"
  445. V3="\\\\([^<>]*\\\\)"
  446. SS="<""<>"">" # spacer so value="2004" does not make for s|\(...\)|\12004|
  447. test ".$commentvars" = ".no" && updatevars="no" # duplicated from
  448. test ".$commentvars" = ".no" && expandvars="no" # option handling
  449. test ".$expandvars" != ".no" && \
  450. $SED -e "/^=....=formatter /d" -e "$piped_value" \
  451. -e "/^<$Q'name'>/s,<$Q'name'>$V9,s|<!--$V0\\1[?]-->|- \\2|," \
  452. -e "/^<$Q'Name'>/s,<$Q'Name'>$V9,s|<!--$V0\\1[?]-->|(\\2)|," \
  453. -e "/^<$Q'name'>/s,<$Q'name'>$V8,s|<!--$V0\\1[?]-->|- \\2|," \
  454. -e "/^<$Q'Name'>/s,<$Q'Name'>$V8,s|<!--$V0\\1[?]-->|(\\2)|," \
  455. -e "/^<$Q/d" -e "/^<!/d" -e "$amp_value" $INP # $++
  456. test ".$expandvars" != ".no" && \
  457. $SED -e "/^=....=formatter /d" -e "$piped_value" \
  458. -e "/^<$Q'text'>/s,<$Q'text'>$V9,s|<!--$V1\\1-->|\\\\1$SS\\2|," \
  459. -e "/^<$Q'Text'>/s,<$Q'Text'>$V9,s|<!--$V1\\1-->|\\\\1$SS\\2|," \
  460. -e "/^<$Q'name'>/s,<$Q'name'>$V9,s|<!--$V1\\1[?]-->|\\\\1$SS\\2|," \
  461. -e "/^<$Q'Name'>/s,<$Q'Name'>$V9,s|<!--$V1\\1[?]-->|\\\\1$SS\\2|," \
  462. -e "/^<$Q'text'>/s,<$Q'text'>$V8,s|<!--$V1\\1-->|\\\\1$SS\\2|," \
  463. -e "/^<$Q'Text'>/s,<$Q'Text'>$V8,s|<!--$V1\\1-->|\\\\1$SS\\2|," \
  464. -e "/^<$Q'name'>/s,<$Q'name'>$V8,s|<!--$V1\\1[?]-->|\\\\1$SS\\2|," \
  465. -e "/^<$Q'Name'>/s,<$Q'Name'>$V8,s|<!--$V1\\1[?]-->|\\\\1$SS\\2|," \
  466. -e "/^<$Q/d" -e "/^<!/d" -e "$amp_value" $INP # $++
  467. test ".$updatevars" != ".no" && \
  468. $SED -e "/^=....=formatter /d" -e "$piped_value" \
  469. -e "/^<$Q'name'>/s,<$Q'name'>$V9,s|<!--$V0\\1:[?]-->[^<>]*|- \\2|," \
  470. -e "/^<$Q'Name'>/s,<$Q'Name'>$V9,s|<!--$V0\\1:[?]-->[^<>]*|(\\2)|," \
  471. -e "/^<$Q'name'>/s,<$Q'name'>$V8,s|<!--$V0\\1:[?]-->[^<>]*|- \\2|," \
  472. -e "/^<$Q'Name'>/s,<$Q'Name'>$V8,s|<!--$V0\\1:[?]-->[^<>]*|(\\2)|," \
  473. -e "/^<$Q/d" -e "/^<!/d" -e "$amp_value" $INP # $++
  474. test ".$updatevars" != ".no" && \
  475. $SED -e "/^=....=formatter /d" -e "$piped_value" \
  476. -e "/^<$Q'text'>/s,<$Q'text'>$V9,s|<!--$V1\\1:[=]-->[^<>]*|\\\\1$SS\\2|," \
  477. -e "/^<$Q'Text'>/s,<$Q'Text'>$V9,s|<!--$V1\\1:[=]-->[^<>]*|\\\\1$SS\\2|," \
  478. -e "/^<$Q'name'>/s,<$Q'name'>$V9,s|<!--$V1\\1:[?]-->[^<>]*|\\\\1$SS\\2|," \
  479. -e "/^<$Q'Name'>/s,<$Q'Name'>$V9,s|<!--$V1\\1:[?]-->[^<>]*|\\\\1$SS\\2|," \
  480. -e "/^<$Q'text'>/s,<$Q'text'>$V8,s|<!--$V1\\1:[=]-->[^<>]*|\\\\1$SS\\2|," \
  481. -e "/^<$Q'Text'>/s,<$Q'Text'>$V8,s|<!--$V1\\1:[=]-->[^<>]*|\\\\1$SS\\2|," \
  482. -e "/^<$Q'name'>/s,<$Q'name'>$V8,s|<!--$V1\\1:[?]-->[^<>]*|\\\\1$SS\\2|," \
  483. -e "/^<$Q'Name'>/s,<$Q'Name'>$V8,s|<!--$V1\\1:[?]-->[^<>]*|\\\\1$SS\\2|," \
  484. -e "/^<$Q/d" -e "/^<!/d" -e "$amp_value" $INP # $++
  485. test ".$attribvars" != ".no" && \
  486. $SED -e "/^=....=formatter /d" -e "$piped_value" \
  487. -e "/^<$Q'text'>/s,<$Q'text'>$V9,s|<$V1{\\1:[=]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  488. -e "/^<$Q'Text'>/s,<$Q'Text'>$V9,s|<$V1{\\1:[=]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  489. -e "/^<$Q'name'>/s,<$Q'name'>$V9,s|<$V1{\\1:[?]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  490. -e "/^<$Q'Name'>/s,<$Q'Name'>$V9,s|<$V1{\\1:[?]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  491. -e "/^<$Q'text'>/s,<$Q'text'>$V8,s|<$V1{\\1:[=]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  492. -e "/^<$Q'Text'>/s,<$Q'Text'>$V8,s|<$V1{\\1:[=]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  493. -e "/^<$Q'name'>/s,<$Q'name'>$V8,s|<$V1{\\1:[?]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  494. -e "/^<$Q'Name'>/s,<$Q'Name'>$V8,s|<$V1{\\1:[?]$V2}$V3>|<\\\\1$SS\\2\\\\3>|," \
  495. -e "/^<$Q/d" -e "/^<!/d" -e "$amp_value" $INP # $++
  496. # if value="2004" then generated sed might be "\\12004" which is bad
  497. # instead we generate an edited value of "\\1$SS$value" and cut out
  498. # the spacer now after expanding the variable values:
  499. echo "s|$SS||g" # $++
  500. }
  501. info2meta_sed () # generate <meta name..> text portion
  502. {
  503. # http://www.metatab.de/meta_tags/DC_type.htm
  504. INP="$1" ; test ".$INP" = "." && INP="$tmp/$F.$DATA"
  505. V6=" *HTTP[.]\\([^ ][^ ]*\\) \\(.*\\)<$QX>"
  506. V7=" *DC[.]\\([^ ][^ ]*\\) \\(.*\\)<$QX>"
  507. V8=" *\\([^ ][^ ]*\\) \\(.*\\)<$QX>"
  508. DATA_META_TYPE_SCHEME="name=\"DC.type\" content=\"\\2\" scheme=\"\\1\""
  509. DATA_META_DCMI="name=\"\\1\" content=\"\\2\" scheme=\"DCMIType\""
  510. DATA_META_NAME_TZ="name=\"\\1\" content=\"\\2 `timezone`\""
  511. DATA_META_NAME="name=\"\\1\" content=\"\\2\""
  512. DATA_META_HTTP="http-equiv=\"\\1\" content=\"\\2\""
  513. $SED -e "/=....=today /d" \
  514. -e "/<$Q'meta'>HTTP[.]/s,<$Q'meta'>$V6, <meta $DATA_META_HTTP />," \
  515. -e "/<$Q'meta'>DC[.]DCMIType /s,<$Q'meta'>$V7, <meta $DATA_META_TYPE_SCHEME />," \
  516. -e "/<$Q'meta'>DC[.]type Collection$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  517. -e "/<$Q'meta'>DC[.]type Dataset$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  518. -e "/<$Q'meta'>DC[.]type Event$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  519. -e "/<$Q'meta'>DC[.]type Image$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  520. -e "/<$Q'meta'>DC[.]type Service$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  521. -e "/<$Q'meta'>DC[.]type Software$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  522. -e "/<$Q'meta'>DC[.]type Sound$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  523. -e "/<$Q'meta'>DC[.]type Text$/s,<$Q'meta'>$V8, <meta $DATA_META_DCMI />," \
  524. -e "/<$Q'meta'>DC[.]date[.].*[+]/s,<$Q'meta'>$V8, <meta $DATA_META_NAME />," \
  525. -e "/<$Q'meta'>DC[.]date[.].*[:]/s,<$Q'meta'>$V8, <meta $DATA_META_NAME_TZ />," \
  526. -e "/<$Q'meta'>/s,<$Q'meta'>$V8, <meta $DATA_META_NAME />," \
  527. -e "/<meta name=\"[^\"]*\" content=\"\" /d" \
  528. -e "/<meta http-equiv=\"[^\"]*\" content=\"\" /d" \
  529. -e "/^<$Q/d" -e "/^<!/d" $INP # $++
  530. }
  531. info_get_entry () # get the first <!--vars--> value known so far
  532. {
  533. TXT="$1" ; test ".$TXT" = "." && TXT="sect"
  534. INP="$2" ; test ".$INP" = "." && INP="$tmp/$F.$DATA"
  535. $SED -e "/<$Q'text'>$TXT /!d" \
  536. -e "s|<$Q'text'>$TXT ||" -e "s|<$QX>||" -e "q" $INP # $++
  537. }
  538. info1grep () # test for a <!--vars--> substition to be already present
  539. {
  540. TXT="$1" ; test ".$TXT" = "." && TXT="sect"
  541. INP="$2" ; test ".$INP" = "." && INP="$tmp/$F.$DATA"
  542. $GREP "^<$Q'text'>$TXT " $INP >$NULL
  543. return $?
  544. }
  545. dx_init()
  546. {
  547. mkpathdir "$tmp"
  548. dx_meta formatter `basename $opt_formatter` > "$tmp/$F.$DATA"
  549. for opt in $opt_variables ; do case "$opt" in # commandline --def=value
  550. *_*) op_=`echo "$opt" | sed -e "y/_/-/"` # makes for <!--$def-->
  551. dx_meta "$op_" `eval echo "\\\$opt_$opt"` ;;
  552. *) dx_text "$opt" `eval echo "\\\$opt_$opt"` ;;
  553. esac ; done
  554. }
  555. dx_line ()
  556. {
  557. echo "<$Q$1>$2 "`trimmm "$3"`"<$QX>" >> "$tmp/$F.$DATA"
  558. }
  559. DX_line ()
  560. {
  561. dx_val_=`echo "$3" | sed -e "s/<[^<>]*>//g"`
  562. dx_line "$1" "$2" "$dx_val_"
  563. }
  564. dx_text ()
  565. {
  566. dx_line "'text'" "$1" "$2"
  567. }
  568. DX_text () # add a <!--vars--> substition includings format variants
  569. {
  570. N=`trimm "$1"` ; T=`trimm "$2"`
  571. if test ".$N" != "." ; then
  572. if test ".$T" != "." ; then
  573. text=`echo "$T" | $SED -e "y/$UPPER/$LOWER/" -e "s/<[^<>]*>//g"`
  574. dx_line "'text'" "$N" "$T"
  575. dx_line "'name'" "$N" "$text"
  576. varname=`echo "$N" | $SED -e 's/.*[.]//'` # cut out front part
  577. if test ".$N" != ".$varname" ; then
  578. text=`echo "$varname $T" | $SED -e "y/$UPPER/$LOWER/" -e "s/<[^<>]*>//g"`
  579. dx_line "'Text'" "$varname" "$T"
  580. dx_line "'Name'" "$varname" "$text"
  581. fi
  582. fi
  583. fi
  584. }
  585. dx_meta ()
  586. {
  587. DX_line "'meta'" "$1" "$2"
  588. }
  589. DX_meta () # add simple meta entry and its <!--vars--> subsitution
  590. {
  591. DX_line "'meta'" "$1" "$2"
  592. DX_text "$1" "$2"
  593. }
  594. DC_meta () # add new DC.meta entry plus two <!--vars--> substitutions
  595. {
  596. DX_line "'meta'" "DC.$1" "$2"
  597. DX_text "DC.$1" "$2"
  598. DX_text "$1" "$2"
  599. }
  600. HTTP_meta () # add new HTTP.meta entry plus two <!--vars--> substitutions
  601. {
  602. DX_line "'meta'" "HTTP.$1" "$2"
  603. DX_text "HTTP.$1" "$2"
  604. DX_text "$1" "$2"
  605. }
  606. DC_VARS_Of () # check DC vars as listed in $DC_VARS global and generate DC_meta
  607. { # the results will be added to .meta.tmp and .vars.tmp later
  608. FILENAME="$1" ; test ".$FILENAME" = "." && FILENAME="$SOURCEFILE"
  609. for M in $DC_VARS title ; do
  610. # scan for a <markup> of this name
  611. part=`$SED -e "/<$M>/!d" -e "s|.*<$M>||" -e "s|</$M>.*||" -e q $FILENAME`
  612. part=`trimm "$part"`
  613. text=`echo "$part" | $SED -e "s|^[$AA]*:||"`
  614. text=`trimm "$text"`
  615. test ".$text" = "." && continue
  616. # <mark:part> will be <meta name="mark.part">
  617. if test ".$text" != ".$part" ; then
  618. N=`echo "$part" | $SED -e "s/:.*//"`
  619. DC_meta "$M.$N" "$text"
  620. elif test ".$M" = ".date" ; then
  621. DC_meta "$M.issued" "$text" # "<date>" -> "<date>issued:"
  622. else
  623. DC_meta "$M" "$text"
  624. fi
  625. done
  626. }
  627. HTTP_VARS_Of () # check HTTP-EQUIVs as listed in $_EQUIV global then
  628. { # generate meta tags that are http-equiv= instead of name=
  629. FILENAME="$1" ; test ".$FILENAME" = "." && FILENAME="$SOURCEFILE"
  630. for M in $_EQUIVS ; do
  631. # scan for a <markup> of this name
  632. part=`$SED -e "/<$M>/!d" -e "s|.*<$M>||" -e "s|</$M>.*||" -e q $FILENAME`
  633. part=`trimm "$part"`
  634. text=`echo "$part" | $SED -e "s|^[$AA]*:||"`
  635. text=`trimm "$text"`
  636. test ".$text" = "." && continue
  637. if test ".$M" = ".redirect" ; then
  638. HTTP_meta "refresh" "5; url=$text" ; DX_text "$M" "$text"
  639. elif test ".$M" = ".charset" ; then
  640. HTTP_meta "content-type" "text/html; charset=$text"
  641. else
  642. HTTP_meta "$M" "$text"
  643. fi
  644. done
  645. }
  646. DC_isFormatOf () # make sure there is this DC.relation.isFormatOf tag
  647. { # choose argument for a fallback (usually $SOURCEFILE)
  648. NAME="$1" ; test ".$NAME" = "." && NAME="$SOURCEFILE"
  649. info1grep DC.relation.isFormatOf || DC_meta relation.isFormatOf "$NAME"
  650. }
  651. DC_publisher () # make sure there is this DC.publisher meta tag
  652. { # choose argument for a fallback (often $USER)
  653. NAME="$1" ; test ".$NAME" = "." && NAME="$USER"
  654. info1grep DC.publisher || DC_meta publisher "$NAME"
  655. }
  656. DC_modified () # make sure there is a DC.date.modified meta tag
  657. { # maybe choose from filesystem dates if possible
  658. ZZ="$1" # target file
  659. if info1grep DC.date.modified ; then :
  660. else
  661. _42_chars="........................................."
  662. cut_42_55="s/^$_42_chars\\(.............\\).*/\\1/" # i.e.`cut -b 42-55`
  663. text=`$STAT_R $ZZ 2>$NULL | $SED -e '/odify:/!d' -e 's|.*fy:||' -e q`
  664. text=`echo "$text" | $SED -e "s/:..[.][$NN]*//"`
  665. text=`trimm "$text"`
  666. test ".$text" = "." && \
  667. text=`$DATE_R "$ZZ" +%Y-%m-%d 2>$NULL` # GNU sed
  668. test ".$text" = "." &&
  669. text=`$LS_L "$ZZ" | $SED -e "$cut_42_55" -e "s/^ *//g" -e "q"`
  670. text=`echo "$text" | $SED -e "s/[$NN]*:.*//"` # cut way seconds
  671. DC_meta date.modified `trimm "$text"`
  672. fi
  673. }
  674. DC_date () # make sure there is this DC.date meta tag
  675. { # choose from one of the available DC.date.* specials
  676. ZZ="$1" # source file
  677. if info1grep DC.date
  678. then DX_text issue "dated `info_get_entry DC.date`"
  679. DX_text updated "`info_get_entry DC.date`"
  680. else text=""
  681. for kind in available issued modified created ; do
  682. text=`info_get_entry DC.date.$kind`
  683. # test ".$text" != "." && echo "$kind = date = $text ($ZZ)"
  684. test ".$text" != "." && break
  685. done
  686. if test ".$text" = "." ; then
  687. M="date"
  688. part=`$SED -e "/<$M>/!d" -e "s|.*<$M>||" -e "s|</$M>.*||" -e q $ZZ`
  689. part=`trimm "$part"`
  690. text=`echo "$part" | $SED -e "s|^[$AA]*:||"`
  691. text=`trimm "$text"`
  692. fi
  693. if test ".$text" = "." ; then
  694. M="!--date:*=*--" # takeover updateable variable...
  695. part=`$SED -e "/<$M>/!d" -e "s|.*<$M>||" -e "s|</.*||" -e q $ZZ`
  696. part=`trimm "$part"`
  697. text=`echo "$part" | $SED -e "s|^[$AA]*:||" -e "s|\\&.*||"`
  698. text=`trimm "$text"`
  699. fi
  700. text=`echo "$text" | $SED -e "s/[$NN]*:.*//"` # cut way seconds
  701. DX_text updated "$text"
  702. text1=`echo "$text" | $SED -e "s|^.* *updated ||"`
  703. if test ".$text" != ".$text1" ; then
  704. kind="modified" ; text=`echo "$text1" | $SED -e "s|,.*||"`
  705. fi
  706. text1=`echo "$text" | $SED -e "s|^.* *modified ||"`
  707. if test ".$text" != ".$text1" ; then
  708. kind="modified" ; text=`echo "$text1" | $SED -e "s|,.*||"`
  709. fi
  710. text1=`echo "$text" | $SED -e "s|^.* *created ||"`
  711. if test ".$text" != ".$text1" ; then
  712. kind="created" ; text=`echo "$text1" | $SED -e "s|,.*||"`
  713. fi
  714. text=`echo "$text" | $SED -e "s/[$NN]*:.*//"` # cut way seconds
  715. DC_meta date `trimm "$text"`
  716. DX_text issue `trimm "$kind $text"`
  717. fi
  718. }
  719. DC_title ()
  720. {
  721. # choose a title for the document, either an explicit title-tag
  722. # or one of the section headers in the document or fallback to filename
  723. ZZ="$1" # target file
  724. if info1grep DC.title ; then :
  725. else
  726. for M in TITLE title H1 h1 H2 h2 H3 H3 H4 H4 H5 h5 H6 h6 ; do
  727. text=`$SED -e "/<$M>/!d" -e "s|.*<$M>||" -e "s|</$M>.*||" -e q $ZZ`
  728. text=`trimm "$text"` ; test ".$text" != "." && break
  729. MM="$M [^<>]*"
  730. text=`$SED -e "/<$MM>/!d" -e "s|.*<$MM>||" -e "s|</$M>.*||" -e q $ZZ`
  731. text=`trimm "$text"` ; test ".$text" != "." && break
  732. done
  733. if test ".text" = "." ; then
  734. text=`basename $ZZ .html`
  735. text=`basename $text .htm | $SED -e 'y/_/ /' -e "s/\\$/ info/"`
  736. fi
  737. term=`echo "$text" | $SED -e 's/.*[(]//' -e 's/[)].*//'`
  738. text=`echo "$text" | $SED -e 's/[(][^()]*[)]//'`
  739. if test ".$term" = "." || test ".$term" = ".$text" ; then
  740. DC_meta title "$text"
  741. else
  742. DC_meta title "$term - $text"
  743. fi
  744. fi
  745. }
  746. site_get_section () # return parent section page of given page
  747. {
  748. _F_=`sed_slash_key "$1"`
  749. $SED -e "/^<$Q'sect'>$_F_ /!d" \
  750. -e "s|^<$Q'sect'>$_F_ ||" -e "s|<$QX>||" \
  751. -e q "$MK_DATA" # $++
  752. }
  753. DC_section () # not really a DC relation (shall we use isPartOf ?)
  754. { # each document should know its section father
  755. sectn=`site_get_section "$F"`
  756. if test ".$sectn" != "." ; then
  757. DC_meta relation.section "$sectn"
  758. fi
  759. }
  760. info_get_entry_section()
  761. {
  762. info_get_entry DC.relation.section # $++
  763. }
  764. site_get_selected () # return section of given page
  765. {
  766. _F_=`sed_slash_key "$1"`
  767. $SED -e "/<$Q'use.'>$_F_ /!d" \
  768. -e "s|<$Q'use.'>[^ ]* ||" -e "s|<$QX>||" \
  769. -e q "$MK_DATA" # $++
  770. }
  771. DC_selected () # not really a DC title (shall we use alternative ?)
  772. {
  773. # each document might want to highlight the currently selected item
  774. short=`site_get_selected "$F"`
  775. if test ".$short" != "." ; then
  776. DC_meta title.selected "$short"
  777. fi
  778. }
  779. info_get_entry_selected ()
  780. {
  781. info_get_entry DC.title.selected # $++
  782. }
  783. site_get_rootsections () # return all sections from root of nav tree
  784. {
  785. $SED -e "/^<$Q'use1'>/!d" \
  786. -e "s|^<$Q'use.'>\\([^ ]*\\) .*|\\1|" "$MK_DATA" # $++
  787. }
  788. site_get_sectionpages () # return all children pages in the given section
  789. {
  790. _F_=`sed_slash_key "$1"`
  791. $SED -e "/^<$Q'sect'>[^ ]* $_F_<[^<>]*>\$/!d" \
  792. -e "s|^<$Q'sect'>||" -e "s|<$QX>||" \
  793. -e "s/ .*//" "$MK_DATA" # $++
  794. }
  795. site_get_subpages () # return all page children of given page
  796. {
  797. _F_=`sed_slash_key "$1"`
  798. $SED -e "/^<$Q'node'>[^ ]* $_F_<[^<>]*>\$/!d" \
  799. -e "s|^<$Q'node'>||" -e "s|<$QX>||" \
  800. -e "s/ .*//" "$MK_DATA"
  801. # $++
  802. }
  803. site_get_parentpage () # return parent page for given page (".." for sections)
  804. {
  805. _F_=`sed_slash_key "$1"`
  806. $SED -e "/^<$Q'node'>$_F_ /!d" \
  807. -e "s|^<$Q'node'>[^ ]* ||" -e "s|<$QX>||" \
  808. -e "q" "$MK_DATA" # $++
  809. }
  810. DX_alternative () # detect wether page asks for alternative style
  811. { # which is generally a shortpage variant
  812. x=`mksite_magic_option alternative $1 | sed -e "s/^ *//" -e "s/ .*//"`
  813. if test ".$x" != "." ; then
  814. DX_text alternative "$x"
  815. fi
  816. }
  817. info2head_sed () # append alternative handling script to $HEAD
  818. {
  819. have=`info_get_entry alternative`
  820. if test ".$have" != "." ; then
  821. echo "/<!--mksite:alternative:$have .*-->/{" # $++
  822. echo "s/<!--mksite:alternative:$have\\( .*\\)-->/\\1/" # $++
  823. echo "q" # $++
  824. echo "}" # $++
  825. fi
  826. }
  827. info2body_sed () # append alternative handling script to $BODY
  828. {
  829. have=`info_get_entry alternative`
  830. if test ".$have" != "." ; then
  831. echo "s/<!--mksite:alternative:$have\\( .*\\)-->/\\1/" # $++
  832. fi
  833. }
  834. bodymaker_for_sectioninfo ()
  835. {
  836. test ".$sectioninfo" = ".no" && return
  837. _x_="<!--mksite:sectioninfo::-->"
  838. _q_="\\([^<>]*[$AX][^<>]*\\)"
  839. test ".$sectioninfo" != ". " && _q_="[ ][ ]*$sectioninfo\\([ ]\\)"
  840. echo "s|\\(^<[hH][$NN][ >].*</[hH][$NN]>\\)$_q_|\\1$_x_\\2|" # $++
  841. echo "/$_x_/s|^|<table width=\"100%\"><tr valign=\"bottom\"><td>|" # $++
  842. echo "/$_x_/s|</[hH][$NN]>|&</td><td align=\"right\"><i>|" # $++
  843. echo "/$_x_/s|\$|</i></td></tr></table>|" # $++
  844. echo "s|$_x_||" # $++
  845. }
  846. fast_href () # args "$FILETOREFERENCE" "$FROMCURRENTFILE:$F"
  847. { # prints path to $FILETOREFERENCE href-clickable in $FROMCURRENTFILE
  848. # if no subdirectoy then output is the same as input $FILETOREFERENCE
  849. R="$2" ; test ".$R" = "." && R="$F"
  850. S=`back_path "$R"`
  851. if test ".$S" = "."
  852. then echo "$1" # $++
  853. else _1_=`echo "$1" | \
  854. $SED -e "/^ *\$/d" -e "/^\\//d" -e "/^[.][.]/d" -e "/^[$AA]*:/d" `
  855. if test ".$_1_" = "." # don't move any in the pattern above
  856. then echo "$1" # $++
  857. else echo "$S$1" # $++ prefixed with backpath
  858. fi fi
  859. }
  860. make_back_path () # "$FILE"
  861. {
  862. R="$1" ; test ".$R" = "." && R="$F"
  863. S=`back_path "$R"`
  864. if test ".$S" != "." ; then
  865. echo "s|\\(<[^<>]* href=\\\"\\)\\([$AA][^<>:]*\\\"[^<>]*>\\)|\\1$S\\2|g"
  866. echo "s|\\(<[^<>]* src=\\\"\\)\\([$AA][^<>:]*\\\"[^<>]*>\\)|\\1$S\\2|g"
  867. fi
  868. }
  869. # ============================================================== SITE MAP DATA
  870. # each entry needs atleast a list-title, a long-title, and a list-date
  871. # these are the basic information to be printed in the sitemap file
  872. # where it is bound the hierarchy of sect/subsect of the entries.
  873. site_map_list_title() # $file $text
  874. {
  875. echo "<$Q'list'>$1 $2<$QX>" >> "$MK_DATA"
  876. }
  877. info_map_list_title() # $file $text
  878. {
  879. echo "<$Q'list'>$2<$QX>" >> "$tmp/$1.$DATA"
  880. }
  881. site_map_long_title() # $file $text
  882. {
  883. echo "<$Q'long'>$1 $2<$QX>" >> "$MK_DATA"
  884. }
  885. info_map_long_title() # $file $text
  886. {
  887. echo "<$Q'long'>$2<$QX>" >> "$tmp/$1.$DATA"
  888. }
  889. site_map_list_date() # $file $text
  890. {
  891. echo "<$Q'date'>$1 $2<$QX>" >> "$MK_DATA"
  892. }
  893. info_map_list_date() # $file $text
  894. {
  895. echo "<$Q'date'>$2<$QX>" >> "$tmp/$1.$DATA"
  896. }
  897. siteinfo2sitemap () # generate <name><page><date> addon sed scriptlet
  898. { # the resulting script will act on each item/line
  899. # containing <!--"filename"--> and expand any following
  900. # reference of <!--name--> or <!--date--> or <!--long-->
  901. INP="$1" ; test ".$INP" = "." && INP="$MK_DATA"
  902. _list_="s|\\\\(<!--\"\\1\"-->.*\\\\)<name href=[^<>]*>.*</name>|\\\\1<name href=\"\\1\">\\2</name>|"
  903. _date_="s|\\\\(<!--\"\\1\"-->.*\\\\)<date>.*</date>|\\\\1<date>\\2</date>|"
  904. _long_="s|\\\\(<!--\"\\1\"-->.*\\\\)<long>.*</long>|\\\\1<long>\\2</long>|"
  905. $SED -e "s:&:\\\\&:g" \
  906. -e "s:<$Q'list'>\\([^ ]*\\) \\(.*\\)<$QX>:$_list_:" \
  907. -e "s:<$Q'date'>\\([^ ]*\\) \\(.*\\)<$QX>:$_date_:" \
  908. -e "s:<$Q'long'>\\([^ ]*\\) \\(.*\\)<$QX>:$_long_:" \
  909. -e "/^s|/!d" $INP # $++
  910. }
  911. make_multisitemap ()
  912. { # each category gets its own column along with the usual entries
  913. INPUTS="$1" ; test ".$INPUTS" = "." && INPUTS="$MK_DATA"
  914. siteinfo2sitemap > "$MK_SITE" # have <name><long><date> addon-sed
  915. _form_="<!--\"\\2\"--><!--use\\1--><long>\\3</long><!--end\\1-->"
  916. _form_="$_form_<br><name href=\"\\2\">\\3</name><date>......</date>"
  917. _tiny_="small><small><small" ; _tinyX_="small></small></small "
  918. _tabb_="<br><$_tiny_> </$_tinyX_>" ; _bigg_="<big> </big>"
  919. echo "<table width=\"100%\"><tr><td> " # $++
  920. $SED -e "/^<$Q'[Uu]se.'>/!d" \
  921. -e "/>[$AZ$az][$AZ$az][$AZ$az][$AZ$az]*:/d" \
  922. -e "s|^<$Q'[Uu]se\\(.\\)'>\\([^ ]*\\) \\(.*\\)<$QX>|$_form_|" \
  923. -f "$MK_SITE" -e "/<name/!d" \
  924. -e "s|<!--use1-->|</td><td valign=\"top\"><b>|" \
  925. -e "s|<!--end1-->|</b>|" \
  926. -e "s|<!--use2-->|<br>|" \
  927. -e "s|<!--use.-->|<br>|" -e "s/<!--[^<>]*-->/ /g" \
  928. -e "s|<name |<$_tiny_><a |" -e "s|</name>||" \
  929. -e "s|<date>|<small style=\"date\">|" \
  930. -e "s|</date>|</small></a><br></$_tinyX_>|" \
  931. -e "s|<long>|<!--long-->|" -e "s|</long>|<!--/long-->|" \
  932. $INPUTS # $++
  933. echo "</td><tr></table>" # $++
  934. }
  935. make_listsitemap ()
  936. { # traditional - the body contains a list with date and title extras
  937. INPUTS="$1" ; test ".$INPUTS" = "." && INPUTS="$MK_DATA"
  938. siteinfo2sitemap > "$MK_SITE" # have <name><long><date> addon-sed
  939. _form_="<!--\"\\2\"--><!--use\\1--><name href=\"\\2\">\\3</name>"
  940. _form_="$_form_<date>......</date><long>\\3</long>"
  941. _tabb_="<td>\\&nbsp\\;</td>"
  942. echo "<table cellspacing=\"0\" cellpadding=\"0\">" # $++
  943. $SED -e "/^<$Q'[Uu]se.'>/!d" \
  944. -e "/>[$AZ$az][$AZ$az][$AZ$az][$AZ$az]*:/d" \
  945. -e "s|^<$Q'[Uu]se\\(.\\)'>\\([^ ]*\\) \\(.*\\)<$QX>|$_form_|" \
  946. -f "$MK_SITE" -e "/<name/!d" \
  947. -e "s|<!--use\\(1\\)-->|<tr class=\"listsitemap\\1\"><td>*</td>|" \
  948. -e "s|<!--use\\(2\\)-->|<tr class=\"listsitemap\\1\"><td>-</td>|" \
  949. -e "s|<!--use\\(.\\)-->|<tr class=\"listsitemap\\1\"><td> </td>|" \
  950. -e "/<tr.class=\"listsitemap3\">/s|<name [^<>]*>|&- |" \
  951. -e "s|<!--[^<>]*-->| |g" \
  952. -e "s|<name href=\"name:sitemap:|<name href=\"|" \
  953. -e "s|<name |<td><a |" -e "s|</name>|</a></td>$_tabb_|" \
  954. -e "s|<date>|<td><small style=\"date\">|" \
  955. -e "s|</date>|</small></td>$_tabb_|" \
  956. -e "s|<long>|<td><em><!--long-->|" \
  957. -e "s|</long>|<!--/long--></em></td></tr>|" \
  958. "$INPUTS" # $++
  959. for xx in `grep "^<$Q'use.'>name:sitemap:" $INPUTS` ; do
  960. xx=`echo $xx | sed -e "s/^<$Q'use.'>name:sitemap://" -e "s|<$QX>||"`
  961. if test -f "$xx" ; then
  962. grep "<tr.class=\"listsitemap[$NN]\">" $xx # $++
  963. fi
  964. done
  965. echo "</table>" # $++
  966. }
  967. _xi_include_=`echo \
  968. "<xi:include xmlns:xi=\"http://www.w3.org/2001/XInclude\" parse=\"xml\""`
  969. make_xmlsitemap ()
  970. { # traditional - the body contains a list with date and title extras
  971. INPUTS="$1" ; test ".$INPUTS" = "." && INPUTS="$MK_DATA"
  972. siteinfo2sitemap > "$MK_SITE" # have <name><long><date> addon-sed
  973. _form_="<!--\"\\2\"--><name href=\"\\2\">\\3</name>"
  974. _sitefile_=`sed_slash_key "$SITEFILE"`
  975. $SED -e "/^<$Q'[Uu]se.'>/!d" \
  976. -e "/>[$AZ$az][$AZ$az][$AZ$az][$AZ$az]*:/d" \
  977. -e "s|^<$Q'[Uu]se\\(.\\)'>\\([^ ]*\\) \\(.*\\)<$QX>|$_form_|" \
  978. -f "$MK_SITE" -e "/<name/!d" \
  979. -e "/${_sitefile_}/d" \
  980. -e "/${_sitefile_}l/d" \
  981. -e "s|\\(href=\"[^<>]*\\)\\.html\\(\"\\)|\\1.xml\\2|g" \
  982. -e "s|.*<name|$_xi_include_\\n |" \
  983. -e "s|>.*</name>| />|" \
  984. "$INPUTS" # $++
  985. }
  986. print_extension ()
  987. {
  988. ARG="$1" ; test ".$ARG" = "." && ARG="$opt_print"
  989. case "$ARG" in
  990. -*|.*) echo "$ARG" ;; # $++
  991. *) echo ".print" ;; # $++
  992. esac
  993. }
  994. from_sourcefile ()
  995. {
  996. if test -f "$1"
  997. then echo "$1"
  998. elif test -f "$opt_srcdir/$1"
  999. then echo "$opt_srcdir/$1"
  1000. else echo "$1"
  1001. fi
  1002. }
  1003. html_sourcefile () # generally just cut away the trailing "l" (ell)
  1004. { # making "page.html" argument into "page.htm" return
  1005. # (as a new addtion the source may be in ".dbk" xml)
  1006. _SRCFILE_=`echo "$1" | $SED -e "s/l\\$//"`
  1007. _XMLFILE_=`echo "$1" | $SED -e "s/\\.html/.dbk/"`
  1008. if test -f "$_SRCFILE_"
  1009. then echo "$_SRCFILE_" # $++
  1010. elif test -f "$_XMLFILE_"
  1011. then echo "$_XMLFILE_" # $++
  1012. elif test -f "$opt_src_dir/$_SRCFILE_"
  1013. then echo "$opt_src_dir/$_SRCFILE_" # $++
  1014. elif test -f "$opt_src_dir/$_XMLFILE_"
  1015. then echo "$opt_src_dir/$_XMLFILE_" # $++
  1016. else echo ".//$_SRCFILE_" # $++ (not found?)
  1017. fi
  1018. }
  1019. html_printerfile_sourcefile ()
  1020. {
  1021. if test ".$printerfriendly" = "."
  1022. then
  1023. echo "$1" | sed -e "s/l\$//" # $++
  1024. else
  1025. _ext_=`print_extension "$printerfriendly"`
  1026. _ext_=`sed_slash_key "$_ext_"`
  1027. echo "$1" | sed -e "s/l\$//" -e "s/$_ext_\\([.][$AA]*\\)\$/\\1/" # $++
  1028. fi
  1029. }
  1030. fast_html_printerfile () {
  1031. x=`html_printerfile "$1"` ; basename "$x" # $++
  1032. # x=`html_printerfile "$1"` ; fast_href "$x" $2 # $++
  1033. }
  1034. html_printerfile () # generate the printerfile for a given normal output
  1035. {
  1036. _ext_=`print_extension "$printerfriendly" | sed -e "s/&/\\\\&/"`
  1037. echo "$1" | sed -e "s/\\([.][$AA]*\\)\$/$_ext_\\1/" # $++
  1038. }
  1039. make_printerfile_fast () # generate s/file.html/file.print.html/ for hrefs
  1040. { # we do that only for the $FILELIST
  1041. ALLPAGES="$1" ; # ="$FILELIST"
  1042. for p in $ALLPAGES ; do
  1043. a=`sed_slash_key "$p"`
  1044. b=`html_printerfile "$p"`
  1045. if test "$b" != "$p" ; then
  1046. b=`html_printerfile "$p" | sed -e "s:&:\\\\&:g" -e "s:/:\\\\\\/:g"`
  1047. echo "s/<a href=\"$a\">/<a href=\"$b\">/" # $++
  1048. echo "s/<a href=\"$a\" /<a href=\"$b\" /" # $++
  1049. fi
  1050. done
  1051. }
  1052. echo_printsitefile_style ()
  1053. {
  1054. _bold_="text-decoration : none ; font-weight : bold ; "
  1055. echo " <style>" # $+++
  1056. echo " a:link { $_bold_ color : #000060 ; }" # $+++
  1057. echo " a:visited { $_bold_ color : #000040 ; }" # $+++
  1058. echo " body { background-color : white ; }" # $+++
  1059. echo " </style>" # $+++
  1060. }
  1061. make_printsitefile_head() # $sitefile
  1062. {
  1063. echo_printsitefile_style > "$MK_STYLE"
  1064. $SED -e "/<title>/p" -e "/<title>/d" \
  1065. -e "/<head>/p" -e "/<head>/d" \
  1066. -e "/<\/head>/p" -e "/<\/head>/d" \
  1067. -e "/<body>/p" -e "/<body>/d" \
  1068. -e "/^.*<link [^<>]*rel=\"shortcut icon\"[^<>]*>.*\$/p" \
  1069. -e "d" $SITEFILE | $SED -e "/<head>/r $MK_STYLE" # $+++
  1070. }
  1071. # ------------------------------------------------------------------------
  1072. # The printsitefile is a long text containing html href markups where
  1073. # each of the href lines in the file is being prefixed with the section
  1074. # relation. During a secondary call the printsitefile can grepp'ed for
  1075. # those lines that match a given output fast-file. The result is a
  1076. # navigation header with 1...3 lines matching the nesting level
  1077. # these alt-texts will be only visible in with a text-mode browser:
  1078. printsitefile_square="width=\"8\" height=\"8\" border=\"0\""
  1079. printsitefile_img_1="<img alt=\"|go text:\" $printsitefile_square />"
  1080. printsitefile_img_2="<img alt=\"||topics:\" $printsitefile_square />"
  1081. printsitefile_img_3="<img alt=\"|||pages:\" $printsitefile_square />"
  1082. _SECT="mksite:sect:"
  1083. echo_current_line () # $sect $extra
  1084. {
  1085. echo "<!--$_SECT\"$1\"-->$2" # $++
  1086. }
  1087. make_current_entry () # $sect $file ## requires $MK_SITE
  1088. {
  1089. S="$1" ; R="$2"
  1090. SSS=`sed_slash_key "$S"`
  1091. sep=" - " ; _left_=" [ " ; _right_=" ] "
  1092. echo_current_line "$S" "<!--\"$R\"--><name href=\"$R\">$R</name>$sep" \
  1093. | $SED -f "$MK_SITE" \
  1094. -e "s|<!--[^<>]*--><name |<a |" -e "s|</name>|</a>|" \
  1095. -e "/<a href=\"$SSS\"/s/<a href/$_left_&/" \
  1096. -e "/<a href=\"$SSS\"/s/<\\/a>/&$_right_/" # $+++
  1097. }
  1098. echo_subpage_line () # $sect $extra
  1099. {
  1100. echo "<!--$_SECT*:\"$1\"-->$2" # $++
  1101. }
  1102. make_subpage_entry ()
  1103. {
  1104. S="$1" ; R="$2"
  1105. RR=`sed_slash_key "$R"`
  1106. sep=" - " ;
  1107. echo_subpage_line "$S" "<!--\"$R\"--><name href=\"$R\">$R</name>$sep" \
  1108. | $SED -f "$MK_SITE" \
  1109. -e "s|<!--[^<>]*--><name |<a |" -e "s|</name>|</a>|" # $+++
  1110. }
  1111. make_printsitefile ()
  1112. {
  1113. # building the printsitefile looks big but its really a loop over sects
  1114. INPUTS="$1" ; test ".$INPUTS" = "." && INPUTS="$MK_DATA"
  1115. siteinfo2sitemap > "$MK_SITE" # have <name><long><date> addon-sed
  1116. if test -d DEBUG && test -f "$MK_SITE"
  1117. then FFFF=`echo "$F" | sed -e "s,/,:,g"`
  1118. cp "$MK_DATA" "DEBUG/$FFFF.SITE.tmp.sed"
  1119. fi
  1120. make_printsitefile_head $SITEFILE # $++
  1121. sep=" - "
  1122. _sect1="<a href=\"#.\" title=\"section\">$printsitefile_img_1</a> ||$sep"
  1123. _sect2="<a href=\"#.\" title=\"topics\">$printsitefile_img_2</a> ||$sep"
  1124. _sect3="<a href=\"#.\" title=\"pages\">$printsitefile_img_3</a> ||$sep"
  1125. site_get_rootsections > "$MK_SECT1"
  1126. # round one - for each root section print a current menu
  1127. for r in `cat "$MK_SECT1"` ; do
  1128. echo_current_line "$r" "<!--mksite:sect1:A--><br>$_sect1" # $++
  1129. for s in `cat "$MK_SECT1"` ; do
  1130. make_current_entry "$r" "$s" # $++
  1131. done
  1132. echo_current_line "$r" "<!--mksite:sect1:Z-->" # $++
  1133. done # "$r"
  1134. # round two - for each subsection print a current and subpage menu
  1135. for r in `cat "$MK_SECT1"` ; do
  1136. site_get_subpages "$r" > "$MK_SECT2"
  1137. for s in `cat "$MK_SECT2"` ; do test "$r" = "$s" && continue
  1138. echo_current_line "$s" "<!--mksite:sect2:A--><br>$_sect2" # $++
  1139. for t in `cat "$MK_SECT2"` ; do test "$r" = "$t" && continue
  1140. make_current_entry "$s" "$t" # $++
  1141. done # "$t"
  1142. echo_current_line "$s" "<!--mksite:sect2:Z-->" # $++
  1143. done # "$s"
  1144. _have_children_="0"
  1145. for t in `cat "$MK_SECT2"` ; do test "$r" = "$t" && continue
  1146. test "$_have_children_" = "0" && _have_children_="1" && \
  1147. echo_subpage_line "$r" "<!--mksite:sect2:A--><br>$_sect2" # $++
  1148. make_subpage_entry "$r" "$t" # $++
  1149. done # "$t"
  1150. test "$_have_children_" = "1" && \
  1151. echo_subpage_line "$r" "<!--mksite:sect2:Z-->" # $++
  1152. done # "$r"
  1153. # round three - for each subsubsection print a current and subpage menu
  1154. for r in `cat "$MK_SECT1"` ; do
  1155. site_get_subpages "$r" > "$MK_SECT2"
  1156. for s in `cat "$MK_SECT2"` ; do test "$r" = "$s" && continue
  1157. site_get_subpages "$s" > "$MK_SECT3"
  1158. for t in `cat "$MK_SECT3"` ; do test "$s" = "$t" && continue
  1159. echo_current_line "$t" "<!--mksite:sect3:A--><br>$_sect3" # $++
  1160. for u in `cat "$MK_SECT3"` ; do test "$s" = "$u" && continue
  1161. make_current_entry "$t" "$u" # $++
  1162. done # "$u"
  1163. echo_current_line "$t" "<!--mksite:sect3:Z-->" # $++
  1164. done # "$t"
  1165. _have_children_="0"
  1166. for u in `cat "$MK_SECT3"` ; do test "$u" = "$s" && continue
  1167. test "$_have_children_" = "0" && _have_children_="1" && \
  1168. echo_subpage_line "$s" "<!--mksite:sect3:A--><br>$_sect3" # $++
  1169. make_subpage_entry "$s" "$u" # $++
  1170. done # "$u"
  1171. test "$_have_children_" = "1" && \
  1172. echo_subpage_line "$s" "<!--mksite:sect3:Z-->" # $++
  1173. done # "$s"
  1174. done # "$r"
  1175. echo "<a name=\".\"></a>" # $++
  1176. echo "</body></html>" # $++
  1177. }
  1178. # create a selector that can grep a printsitefile for the matching entries
  1179. select_in_printsitefile () # arg = "page" : return to stdout >> $P.$HEAD
  1180. {
  1181. _selected_="$1" ; test ".$_selected_" = "." && _selected_="$F"
  1182. _section_=`sed_slash_key "$_selected_"`
  1183. echo "s/^<!--$_SECT\"$_section_\"-->//" # sect3
  1184. echo "s/^<!--$_SECT[*]:\"$_section_\"-->//" # children
  1185. _selected_=`site_get_parentpage "$_selected_"`
  1186. _section_=`sed_slash_key "$_selected_"`
  1187. echo "s/^<!--$_SECT\"$_section_\"-->//" # sect2
  1188. _selected_=`site_get_parentpage "$_selected_"`
  1189. _section_=`sed_slash_key "$_selected_"`
  1190. echo "s/^<!--$_SECT\"$_section_\"-->//" # sect1
  1191. echo "/^<!--$_SECT\"[^\"]*\"-->/d"
  1192. echo "/^<!--$_SECT[*]:\"[^\"]*\"-->/d"
  1193. echo "s/^<!--mksite:sect[$NN]:[$AZ]-->//"
  1194. }
  1195. body_for_emailfooter ()
  1196. {
  1197. test ".$emailfooter" = ".no" && return
  1198. _email_=`echo "$emailfooter" | sed -e "s|[?].*||"`
  1199. _dated_=`info_get_entry updated`
  1200. echo "<hr><table border=\"0\" width=\"100%\"><tr><td>"
  1201. echo "<a href=\"mailto:$emailfooter\">$_email_</a>"
  1202. echo "</td><td align=\"right\">"
  1203. echo "$_dated_</td></tr></table>"
  1204. }
  1205. # =================================================================== CSS
  1206. # There was another project to support sitemap build from xml files.
  1207. # The source format was using .dbk+xml with embedded references to .css
  1208. # files for visual preview in a browser. An docbook xml file with semantic
  1209. # outlines is far better suited for quality documentation than any html
  1210. # source. It happens that the xml/css support in browsers is still not
  1211. # very portable - especially embedded css style blocks are a nightmare.
  1212. # Instead we (a) grab all non-html xml markup tags (b) grab all referenced
  1213. # css stylesheets (c) cut out css defs from [b] that are known by [a] and
  1214. # (d) append those to the <style> tag in the output html file as well as
  1215. # (e) reformatting the defs as well as markups from tags to tag classes.
  1216. # Input dbk/htm
  1217. # <?xml-stylesheet type="text/css" href="html.css" ?> <!-- dbk/xml -->
  1218. # <link rel="stylesheet" type="text/css" href="sdocbook.css" /> <!-- xhtml -->
  1219. # <article><para>
  1220. # Using some <command>exe</command>
  1221. # </para></article>
  1222. # Input css:
  1223. # article { .. ; display : block }
  1224. # para { .. ; display : block }
  1225. # command { .. ; display : inline }
  1226. # Output html:
  1227. # <html><style type="text/css">
  1228. # div .article { .. }
  1229. # div .para { .. }
  1230. # span .command { .. }
  1231. # </style>
  1232. # <div class="article"><div class="para>
  1233. # Using some <span class="command">exe</span>
  1234. # </div></div>
  1235. css_sourcefile ()
  1236. {
  1237. if test -f "$1" ; then echo "$1"
  1238. elif test -f "$opt_src_dir/$1" ; then echo "$opt_src_dir/$1"
  1239. elif echo "$1" | grep "^/" > $NULL ; then echo "$1"
  1240. else echo "./$1"
  1241. fi
  1242. }
  1243. css_xmltags () # $SOURCEFILE
  1244. {
  1245. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1246. S="$SOURCEFILE"
  1247. cat "$S" | $SED -e "s|>[^<>]*<|><|g" -e "s|^[^<>]*<|<|" \
  1248. -e "s|>[^<>]*\$|>|" -e "s|<|\\n|g" \
  1249. | $SED -e "/^\\//d" -e "/^ *\$/d" -e "/>/!d" -e "s|>.*||" \
  1250. | sort | uniq > "$tmp/$MK.$X.xmltags.tmp.txt"
  1251. }
  1252. css_xmlstyles () # $SOURCEFILE
  1253. {
  1254. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1255. S="$SOURCEFILE"
  1256. cat "$S" "$SITEFILE" \
  1257. | sed \
  1258. -e "s|<link *rel=['\"]*stylesheet|<?xml-stylesheet |" \
  1259. -e "/<.xml-stylesheet/!d" -e "/href/!N" -e "/href/!N" \
  1260. -e "s|^.*<.xml-stylesheet||" -e 's|^.*href="||' -e 's|".*||' \
  1261. | sort | uniq > "$tmp/$MK.$X.xmlstylesheets.tmp.txt"
  1262. }
  1263. css_xmlstyles_sed () # $SOURCEFILE
  1264. {
  1265. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1266. S="$tmp/$MK.$X.xmltags.tmp.txt"
  1267. R="$tmp/$MK.$X.xmltags.tmp.sed"
  1268. rm -f "$R"
  1269. {
  1270. for x in 1 2 3 4 5 6 7 8 9 ; do echo "/}/d" ; echo "/{/!N" ; done
  1271. echo "s|\\r||g"
  1272. $SED "/^[$AZ$az$NN]/!d" "$S" | { while read xmltag ; do
  1273. xmltag=`echo "$xmltag" | sed -e "s/ .*//"`
  1274. _xmltag=`sed_slash_key "$xmltag"`
  1275. if echo " title section " | grep " $xmltag " > $NULL ; then
  1276. test "$xmltag" = "section" && continue;
  1277. echo "/^ *$_xmltag *[,\\n{]/bfound" >> "$R"
  1278. echo "/[,\\n] *$_xmltag *[,\\n{]/bfound" >> "$R"
  1279. $SED "/^[$AZ$az$NN]/!d" "$S" | { while read xmlparent ; do
  1280. xmlparent=`echo "$xmlparent" | sed -e "s/ .*//"`
  1281. _xmlparent=`sed_slash_key "$xmlparent"`
  1282. echo "/^ *$_xmlparent *$_xmltag *[,\\n{]/bfound"
  1283. echo "/[ ,\\n] *$_xmlparent *$_xmltag *[,\\n{]/bfound"
  1284. done }
  1285. else
  1286. echo "/^ *$_xmltag *[ ,\\n{]/bfound"
  1287. echo "/[ ,\\n] *$_xmltag *[ ,\\n{]/bfound"
  1288. fi
  1289. done }
  1290. echo "d" ; echo ":found"
  1291. for x in 1 2 3 4 5 6 7 8 9 ; do echo "/}/!N" ; done
  1292. $SED "/^[$AZ$az$NN]/!d" "$S" | { while read xmltag ; do
  1293. xmltag=`echo "$xmltag" | sed -e "s/ .*//"`
  1294. if echo " $HTMLTAGS $HTMLTAGS2" | grep " $xmltag " > $NULL ; then
  1295. continue # keep html tags
  1296. fi
  1297. echo "s|^\\( *\\)\\($xmltag *[ ,\\n{]\\)|\\1.\\2|g"
  1298. echo "s|\\([ ,\\n] *\\)\\($xmltag *[ ,\\n{]\\)|\\1.\\2|g"
  1299. done }
  1300. } > "$R"
  1301. }
  1302. css_xmltags_css () # $SOURCEFILE
  1303. {
  1304. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1305. S="$tmp/$MK.$X.xmltags.tmp.sed"
  1306. R="$tmp/$MK.$X.xmltags.tmp.css"
  1307. {
  1308. cat "$tmp/$MK.$X.xmlstylesheets.tmp.txt" | { while read xmlstylesheet ; do
  1309. stylesheet=`css_sourcefile "$xmlstylesheet"`
  1310. if test -f "$stylesheet" ; then
  1311. echo "/* $xmlstylesheet */"
  1312. cat "$stylesheet" | $SED -f "$S"
  1313. else
  1314. error "$xmlstylesheet : ERROR, no such stylesheet"
  1315. fi
  1316. done }
  1317. } > "$R"
  1318. }
  1319. css_xmlmapping_sed () # $SOURCEFILE
  1320. {
  1321. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1322. S="$tmp/$MK.$X.xmltags.tmp.txt"
  1323. R="$tmp/$MK.$X.xmlmapping.tmp.sed"
  1324. rm -f "$R"
  1325. {
  1326. for x in 1 2 3 4 5 6 7 8 9 ; do echo "/}/d" ; echo "/{/!N" ; done
  1327. echo "s|\\r||g"
  1328. $SED "/^[$AZ$az$NN]/!d" "$S" | { while read xmltag ; do
  1329. xmltag=`echo "$xmltag" | sed -e "s/ .*//"`
  1330. xmltag=`sed_slash_key "$xmltag"`
  1331. echo "/^ *\\.$xmltag *[ ,\\n{]/bfound"
  1332. echo "/[ ,\\n] *\\.$xmltag *[,\\n{]/bfound"
  1333. done }
  1334. echo "d" ; echo ":found"
  1335. for x in 1 2 3 4 5 6 7 8 9 ; do echo "/}/!N" ; done
  1336. echo "s/^/>>/"
  1337. echo "/[\\n ]display *: *list-item/s|^.*>>|li>>|"
  1338. echo "/[\\n ]display *: *table-caption/s|^.*>>|caption>>|"
  1339. echo "/[\\n ]display *: *table-cell/s|^.*>>|td>>|"
  1340. echo "/[\\n ]display *: *table-row/s|^.*>>|tr>>|"
  1341. echo "/[\\n ]display *: *table/s|^.*>>|table>>|"
  1342. echo "/[\\n ]display *: *block/s|^.*>>|div>>|"
  1343. echo "/[\\n ]display *: *inline/s|^.*>>|span>>|"
  1344. echo "/[\\n ]display *: *none/s|^.*>>|small>>|"
  1345. echo "/^div>>.*[\\n ]list-style-type *: *disc/s|^.*>>|ul>>|"
  1346. echo "/^div>>.*[\\n ]list-style-type *: *decimal/s|^.*>>|ol>>|"
  1347. echo "/^span>>.*[\\n ]font-family *: *monospace/s|^.*>>|tt>>|"
  1348. echo "/^span>>.*[\\n ]font-style *: *italic/s|^.*>>|em>>|"
  1349. echo "/^span>>.*[\\n ]font-weight *: *bold/s|^.*>>|b>>|"
  1350. echo "/^div>>.*[\\n ]white-space *: *pre/s|^.*>>|pre>>|"
  1351. echo "/^div>>.*[\\n ]margin-left *: *[$NN]/s|^.*>>|blockquote>>|"
  1352. $SED "/^[$AZ$az$NN]/!d" "$S" | { while read xmltag ; do
  1353. xmltag=`echo "$xmltag" | sed -e "s/ .*//"`
  1354. echo "s|^\\(.*\\)>> *\\.$xmltag *[ ,\\n{].*|\\1 .$xmltag|"
  1355. echo "s|^\\(.*\\)>>.*[ ,\\n] *\\.$xmltag *[ ,\\n{].*|\\1 .$xmltag|"
  1356. done }
  1357. echo "s/^div \\.para\$/p .para/"
  1358. echo "s/^span \\.ulink\$/a .ulink/"
  1359. } > "$R"
  1360. }
  1361. css_xmlmapping () # $SOURCEFILE
  1362. {
  1363. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1364. cat "$tmp/$MK.$X.xmltags.tmp.css" | \
  1365. $SED -f "$tmp/$MK.$X.xmlmapping.tmp.sed" \
  1366. > "$tmp/$MK.$X.xmlmapping.tmp.txt"
  1367. }
  1368. css_scan() # $SOURCEFILE
  1369. {
  1370. css_xmltags
  1371. css_xmlstyles
  1372. css_xmlstyles_sed
  1373. css_xmltags_css
  1374. css_xmlmapping_sed
  1375. css_xmlmapping
  1376. }
  1377. tags2span_sed() # $SOURCEFILE > $++
  1378. {
  1379. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1380. S="$tmp/$MK.$X.xmltags.tmp.txt"
  1381. R="$tmp/$MK.$X.xmltags.tmp.css"
  1382. echo "s|<[?]xml-stylesheet[^<>]*[?]>||"
  1383. echo "s|<link *rel=['\"]*stylesheet[^<>]*>||"
  1384. echo "s|<section[^<>]*>||g"
  1385. echo "s|</section>||g"
  1386. $SED "/^[$AZ$az$NN]/!d" "$S" | { while read xmltag ; do
  1387. # note "xmltag=$xmltag"
  1388. xmltag=`echo "$xmltag" | sed -e "s/ .*//"`
  1389. if echo " $HTMLTAGS $HTMLTAGS2" | grep " $xmltag " > $NULL ; then
  1390. continue # keep html tags
  1391. fi
  1392. _xmltag=`sed_slash_key "$xmltag"`
  1393. _span_=`$SED -e "/ \\.$_xmltag\$/!d" -e "s/ .*//" -e q \
  1394. < "$tmp/$MK.$X.xmlmapping.tmp.txt"`
  1395. test ".$_span_" = "." && _span_="span"
  1396. _xmltag=`sed_piped_key "$xmltag"`
  1397. echo "s|<$xmltag\\([\\n\\t ][^<>]*\\)url=|<$_span_ class=\"$xmltag\"\\1href=|g"
  1398. echo "s|<$xmltag\\([\\n\\t >]\\)|<$_span_ class=\"$xmltag\"\\1|g"
  1399. echo "s|</$xmltag\\([\\n\\t >]\\)|</$_span_\\1|g"
  1400. done }
  1401. cat "$tmp/$MK.$X.xmlstylesheets.tmp.txt" | { while read xmlstylesheet ; do
  1402. if test -f "$xmlstylesheet" ; then
  1403. R="[^<>]*href=['"'"'"]$xmlstylesheet['"'"'"][^<>]*"
  1404. echo "s|<[?]xml-stylesheet$R>||"
  1405. echo "s|<link[^<>]* rel=['"'"'"]*stylesheet['"'"'" ]$R>||"
  1406. fi
  1407. done }
  1408. }
  1409. tags2meta_sed() # $SOURCEFILE > $++
  1410. {
  1411. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1412. S="$tmp/$MK.$X.xmlstylesheets.tmp.txt"
  1413. R="$tmp/$MK.$X.xmltags.tmp.css"
  1414. cat "$tmp/$MK.$X.xmlstylesheets.tmp.txt" | { while read xmlstylesheet ; do
  1415. if test -f "$xmlstylesheet" ; then
  1416. echo " <style type=\"text/css\"><!--"
  1417. $SED -e "s/^/ /" < "$R"
  1418. echo " --></style>"
  1419. break
  1420. fi
  1421. done }
  1422. }
  1423. # ==========================================================================
  1424. # xml/docbook support is taking an dbk input file converting any html DBK
  1425. # syntax into pure docbook tagging. Each file is being given a docbook
  1426. # doctype so that an xml/docbook viewer can render it correctly - that
  1427. # is needed atleast since docbook files do not embed stylesheet infos.
  1428. # Most of the processing is related to remap html markup and some other
  1429. # shortcut markup into correct docbook markup. The result is NOT checked
  1430. # for being well-formed or even matching the docbook schema DTD at all.
  1431. scan_xml_rootnode ()
  1432. {
  1433. rootnode=`cat "$SOURCEFILE" | \
  1434. $SED -e "/<[$AZ$az$NN]/!d" -e "s/<\\([$AZ$az$NN]*\\).*/\\1/" -e q`
  1435. echo "<$Q'root'>$F $rootnode<$QX>" >> "$MK_DATA"
  1436. }
  1437. get_xml_rootnode ()
  1438. {
  1439. _file_=`sed_slash_key "$F"`
  1440. $SED -e "/^<$Q'root'>$_file_ /!d" \
  1441. -e "s|.* ||" -e "s|<.*||" -e q "$MK_DATA" # +
  1442. }
  1443. xml_sourcefile ()
  1444. {
  1445. _XMLFILE_=`echo "$1" | $SED -e "s/\\.xml\\$/.dbk/"`
  1446. _SRCFILE_=`echo "$1" | $SED -e "s/\\.xml\\$/.htm/"`
  1447. test "$1" = "$_XMLFILE_" && _XMLFILE_="///"
  1448. test "$1" = "$_SRCFILE_" && _SRCFILE_="///"
  1449. if test -f "$_XMLFILE_"
  1450. then echo "$_XMLFILE_" # $++
  1451. elif test -f "$_SRCFILE_"
  1452. then echo "$_SRCFILE_" # $++
  1453. elif test -f "$opt_src_dir/$_XMLFILE_"
  1454. then echo "$opt_src_dir/$_XMLFILE_" # $++
  1455. elif test -f "$opt_src_dir/$_SRCFILE_"
  1456. then echo "$opt_src_dir/$_SRCFILE_" # $++
  1457. else echo ".//$_XMLFILE_" # $++ (not found?)
  1458. fi
  1459. }
  1460. scan_xmlfile()
  1461. {
  1462. SOURCEFILE=`xml_sourcefile "$F"`
  1463. $hint "'$SOURCEFILE': scanning xml -> '$F'"
  1464. scan_xml_rootnode
  1465. rootnode=`get_xml_rootnode | sed -e "/^h[$NN]/s|\$| <?section?>|"`
  1466. $hint "'$SOURCEFILE': rootnode ('$rootnode')"
  1467. }
  1468. make_xmlfile()
  1469. {
  1470. SOURCEFILE=`xml_sourcefile "$F"`
  1471. X=`echo $SOURCEFILE | sed -e "y:/:~:"`
  1472. article=`get_xml_rootnode`
  1473. test ".$article" = "." && article="article"
  1474. echo '<!DOCTYPE '$article' PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"' \
  1475. > "$F"
  1476. echo ' "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">' \
  1477. >> "$F"
  1478. cat "$tmp/$MK.$X.xmlstylesheets.tmp.txt" | { while read stylesheet ; do
  1479. echo "<?xml-stylesheet type=\"text/css\" href=\"$stylesheet\" ?>" \
  1480. >> "$F"
  1481. done }
  1482. __secinfo="\\1<sectioninfo>\\2</sectioninfo>"
  1483. cat "$SOURCEFILE" | $SED \
  1484. -e "s!<>!\&nbsp\;!g" \
  1485. -e "s!\\(&\\)\\(&\\)!\\1amp;\\2amp;!g" \
  1486. -e "s!\\(<[^<>]*\\)\\(width\\)\\(=\\)\\([$NN]*\%*\\)!\\1\\2\\3\"\\4\"!g" \
  1487. -e "s!\\(<[^<>]*\\)\\(cellpadding\\)\\(=\\)\\([$NN]*\%*\\)!\\1\\2\\3\"\\4\"!g" \
  1488. -e "s!\\(<[^<>]*\\)\\(border\\)\\(=\\)\\([$NN]*\%*\\)!\\1\\2\\3\"\\4\"!g" \
  1489. -e "s!<[?]xml-stylesheet[^<>]*>!!" \
  1490. -e "s!<link[^<>]* rel=[\'\"]*stylesheet[^<>]*>!!" \
  1491. -e "s!<[hH][$NN]!<title!g" \
  1492. -e "s!</[hH][$NN]!</title!g" \
  1493. -e "s!\\(</title> *\\)\\([^<>]*[$AZ$az$NN][^<>\r\n]*\\)\$!\\1<sub>\\2</sub>!" \
  1494. -e "s!\\(</title>.*\\)<sub>!\\1<subtitle>!g" \
  1495. -e "s!\\(</title>.*\\)</sub>!\\1</subtitle>!g" \
  1496. -e "s!\\(<section>[^<>]*\\)\\(<date>.*</date>[^<>]*\\)\$!\\1<sectioninfo>\\2</sectioninfo>!g" \
  1497. -e "s!<em>!<emphasis>!g" \
  1498. -e "s!</em>!</emphasis>!g" \
  1499. -e "s!<i>!<emphasis>!g" \
  1500. -e "s!</i>!</emphasis>!g" \
  1501. -e "s!<b>!<emphasis role=\"bold\">!g" \
  1502. -e "s!</b>!</emphasis>!g" \
  1503. -e "s!<u>!<emphasis role=\"underline\">!g" \
  1504. -e "s!</u>!</emphasis>!g" \
  1505. -e "s!<big>!<emphasis role=\"strong\">!g" \
  1506. -e "s!</big>!</emphasis>!g" \
  1507. -e "s!<\\(strike\\)>!<emphasis role=\"strikethrough\">!g" \
  1508. -e "s!<\\(s\\)>!<emphasis role=\"strikethrough\">!g" \
  1509. -e "s!</\\(strike\\)>!</emphasis>!g" \
  1510. -e "s!</\\(s\\)>!</emphasis>!g" \
  1511. -e "s!<center>!<blockquote><para>!g" \
  1512. -e "s!</center>!</para></blockquote>!g" \
  1513. -e "s!<p align=\\(\"[$AZ$az$NN]*\"\\)>!<para role=\\1>!g" \
  1514. -e "s!<[pP]>!<para>!g" \
  1515. -e "s!</[pP]>!</para>!g" \
  1516. -e "s!<\\(pre\\)>!<screen>!g" \
  1517. -e "s!<\\(PRE\\)>!<screen>!g" \
  1518. -e "s!</\\(pre\\)>!</screen>!g" \
  1519. -e "s!</\\(PRE\\)>!</screen>!g" \
  1520. -e "s!<a\\( [^<>]*\\)name=\\([^<>]*\\)/>!<anchor \\1id=\\2/>!g" \
  1521. -e "s!<a\\( [^<>]*\\)name=\\([^<>]*\\)>!<anchor \\1id=\\2/>!g" \
  1522. -e "s!<a\\( [^<>]*\\)href=!<ulink\\1url=!g" \
  1523. -e "s!</a>!</ulink>!g" \
  1524. -e "s! remap=\"url\">[^<>]*</ulink>! />!g" \
  1525. -e "s!<\\(/*\\)span\\([ ][^<>]*\\)>!<\\1phrase\\2>!g" \
  1526. -e "s!<\\(/*\\)span>!<\\1phrase>!g" \
  1527. -e "s!<small\\([ ][^<>]*\\)>!<phrase role=\"small\"\\1>!g" \
  1528. -e "s!<small>!<phrase role=\"small\">!g" \
  1529. -e "s!</small>!</phrase>!g" \
  1530. -e "s!<\\(/*\\)\\(sup\\)>!<\\1superscript>!g" \
  1531. -e "s!<\\(/*\\)\\(sub\\)>!<\\1subscript>!g" \
  1532. -e "s!\\(<\\)\\(li\\)\\(><\\)!\\1listitem\\3!g" \
  1533. -e "s!\\(></\\)\\(li\\)\\(>\\)!\\1listitem\\3!g" \
  1534. -e "s!\\(<\\)\\(li\\)\\(>\\)!\\1listitem\\3<para>!g" \
  1535. -e "s!\\(</\\)\\(li\\)\\(>\\)!</para>\\1listitem\\3!g" \
  1536. -e "s!\\(</*\\)\\(ul\\)>!\\1itemizedlist>!g" \
  1537. -e "s!\\(</*\\)\\(ol\\)>!\\1orderedlist>!g" \
  1538. -e "s!\\(</*\\)\\(dl\\)>!\\1variablelist>!g" \
  1539. -e "s!<\\(/*\\)DT>!<\\1dt>!g" \
  1540. -e "s!<\\(/*\\)DD>!<\\1dd>!g" \
  1541. -e "s!<\\(/*\\)DL>!<\\1dl>!g" \
  1542. -e "s!<BLOCKQUOTE>!<blockquote><para>!g" \
  1543. -e "s!</BLOCKQUOTE>!</para></blockquote>!g" \
  1544. -e "s!<\\(/*\\)dl>!<\\1variablelist>!g" \
  1545. -e "s!<dt\\( [^<>]*\\)>!<varlistentry\\1><term>!g" \
  1546. -e "s!<dt>!<varlistentry><term>!g" \
  1547. -e "s!</dt>!</term>!g" \
  1548. -e "s!<dd\\( [^<>]*\\)><!<listitem\\1><!g" \
  1549. -e "s!<dd><!<listitem><!g" \
  1550. -e "s!></dd>!></listitem></varlistentry>!g" \
  1551. -e "s!<dd\\( [^<>]*\\)>!<listitem\\1><para>!g" \
  1552. -e "s!<dd>!<listitem><para>!g" \
  1553. -e "s!</dd>!</para></listitem></varlistentry>!g" \
  1554. -e "s!<table[^<>]*><tr><td>\\(<table[^<>]*>\\)!\\1!" \
  1555. -e "s!\\(</table>\\)</td></tr></table>!\\1!" \
  1556. -e "s!<table\\( [^<>]*\\)>!<informaltable\\1><tgroup cols=\"2\"><tbody>!g" \
  1557. -e "s!<table>!<informaltable><tgroup cols=\"2\"><tbody>!g" \
  1558. -e "s!</table>!</tbody></tgroup></informaltable>!g" \
  1559. -e "s!\\(</*\\)tr\\([ ][^<>]*\\)>!\\1row\\2>!g" \
  1560. -e "s!\\(</*\\)tr>!\\1row>!g" \
  1561. -e "s!\\(</*\\)td\\([ ][^<>]*\\)>!\\1entry\\2>!g" \
  1562. -e "s!\\(</*\\)td>!\\1entry>!g" \
  1563. -e "s!\\(<informaltable[^<>]*[ ]width=\"100\%\"\\)!\\1 pgwide=\"1\"!g" \
  1564. -e "s!\\(<tgroup[<>]*[ ]cols=\"2\">\\)\\(<tbody>\\)!\\1<colspec colwidth=\"1*\" /><colspec colwidth=\"1*\" />\\2!g" \
  1565. -e "s!\\(<entry[^<>]*[ ]\\)width=\\(\"[$NN]*\%*\"\\)!\\1remap=\\2!g" \
  1566. -e "s!<nobr>\\([\'\`]*\\)<tt>!<cmdsynopsis><command>\\1!g" \
  1567. -e "s!</tt>\\([\'\`]*\\)</nobr>!\\1</command></cmdsynopsis>!g" \
  1568. -e "s!<nobr><\\(code\\)>\\([\`\"\']\\)!<cmdsynopsis><command>\\2!g" \
  1569. -e "s!<