source code for a website, in shell (except a C and a PHP helper)
[shellsnippets/shellsnippets.git] / mksh / website.shar
1 # This is a shell archive.  Save it in a file, remove anything before
2 # this line, and then unpack it by entering "sh file".  Note, it may
3 # create directories; files and directories will be owned by you and
4 # have default permissions.
5 #
6 # This archive contains:
7 #
8 #       LICENCE
9 #       Makefile
10 #       mk/common
11 #       mk/htsconv
12 #       mk/inc2htm
13 #       mk/inc2rss
14 #       mk/mkdepend
15 #       mk/parser
16 #       mk/strftm.c
17 #       mk/ttf2png
18 #
19 echo x - LICENCE
20 sed 's/^X//' >LICENCE << 'END-of-LICENCE'
21 X$MirOS: www/LICENCE,v 1.20 2011/02/18 22:37:29 tg Exp $
22 X
23 X[…]
24 XThe MirOS Project web site source code is
25 XCopyright © 2007, 2008, 2009, 2011
26 X       Thorsten “mirabilos” Glaser <tg@mirbsd.de>
27 XCopyright © 2006, 2008
28 X       Benny Siegert <bsiegert@mirbsd.org>
29 XThis source code is available under the terms of the stan-
30 Xdard MirOS licence, see […] mk/common
31 END-of-LICENCE
32 echo x - Makefile
33 sed 's/^X//' >Makefile << 'END-of-Makefile'
34 X# $MirOS: www/Makefile,v 1.73 2011/02/12 23:00:00 bsiegert Exp $
35 X#-
36 X# This file is part of the website of The MirOS Project, which is
37 X# copyrighted material, please read the LICENCE file for details.
38 X
39 X.ifndef TOP
40 XTOP!=          realpath ${.CURDIR:Q}
41 XDST!=          realpath ${.OBJDIR:Q}
42 X.MAKEFLAGS:=   ${.MAKEFLAGS} TOP=${TOP:Q} DST=${DST:Q}
43 X.endif
44 X
45 Xall:
46 X
47 X.include <bsd.own.mk>
48 XBSDSRCDIR?=/nonexistant
49 X.if exists(${DST}/.depend)
50 X.  include "${DST}/.depend"
51 X.endif
52 X
53 XU_ENV+=                TOP=${TOP:Q} DST=${DST:Q} MKSH=${MKSH:Q} SHELL=${MKSH:Q} TZ=UTC
54 X
55 XSRCS+=         a4rcontrb.hts a4rp5bsd.hts
56 XSRCS+=         about.hts
57 XSRCS+=         anargeek.hts
58 XSRCS+=         ann-10.hts
59 XSRCS+=         bt.hts
60 XSRCS+=         clog11.hts
61 XSRCS+=         danke.hts
62 XSRCS+=         devel.hts
63 XSRCS+=         errata10.hts
64 XSRCS+=         getting.hts
65 XSRCS+=         irc.hts
66 XSRCS+=         jupp.hts
67 XSRCS+=         ksh-chan.hts
68 XSRCS+=         kwalletcli.hts
69 XSRCS+=         main.hts
70 XSRCS+=         makefs.hts
71 XSRCS+=         mksh.hts mksh_bld.hts mksh_old.hts
72 XSRCS+=         oldnews.hts
73 XSRCS+=         pkgsrc.hts
74 XSRCS+=         ports.hts
75 XSRCS+=         projects.hts
76 XSRCS+=         randex.hts
77 XSRCS+=         rss.hts
78 XSRCS+=         tags.hts
79 XCLEANFILES+=   tags.lst tags.out
80 XTAGCLOUD+=     debian
81 XTAGCLOUD+=     event
82 XTAGCLOUD+=     mksh
83 XWLOGS=         9 10
84 X
85 X# legacy content
86 XSRCS+=         ann-7.hts ann-8.hts anoncvs.hts bsd-intro.hts clog-2004.hts \
87 X               clog-2005.hts clog-2006.hts cvsweb.hts docs.hts errata8.hts \
88 X               faq.es.hts faq.hts history.hts ipv6-sixxs.hts \
89 X               isdn.hts mirrors.hts mirwarum.hts
90 XSRCS+=         wlog-0.hts wlog-1.hts wlog-2.hts wlog-3.hts wlog-4.hts \
91 X               wlog-5.hts wlog-6.hts wlog-7.hts wlog-8.hts
92 X
93 XINCSRCS+=      datatest
94 X
95 XINCSRCS+=      news
96 Xnews.cut: stamp_htm_news
97 XCLEANFILES+=   news.cut
98 X
99 X.PATH: ${TOP}/src
100 X
101 X_htm_2xhtml=   (tr '\n' '﷐' | \
102 X               sed 's\ 1^.*<html\ 1'${_xhtmlbeg:Q}'\ 1' | \
103 X               tr '﷐' '\n')
104 X_xhtmldtd=     ${TOP}/mk/xhtml11.dtd
105 X_xhtmlbeg=     <?xml version="1.0"?> \
106 X               <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" \
107 X                "file://${_xhtmldtd}"> \
108 X               <html
109 X
110 Xall:
111 Xinstall: site.tgz.stamp
112 X
113 XSTRFTM_MAKE=   cd ${.CURDIR:Q} && ${MAKE} -f ${.SYSMK}/bsd.prog.mk NOMAN=Yes \
114 X                   VPATH=${.CURDIR:Q}/mk PROG=strftm
115 X
116 XOBJS+=         ${SRCS:M*.hts:S/hts$/htm~/}
117 XVOBJS+=                ${SRCS:M*.hts:S/hts$/val/}
118 XCLEANFILES+=   ${SRCS:M*.hts:S/hts$/htm~/}
119 X
120 XDEPSRCS+=      ${SRCS:S,^,src/,}
121 XINCSRCS+=      ${WLOGS:S/^/wlog-/}
122 XINCSRCS+=      ${TAGCLOUD:S/^/tag_/}
123 X
124 X.for _i in ${INCSRCS}
125 XDEPSRCS+=      data/${_i}.cfg
126 XGENSRCS+=      stamp_htm_${_i} stamp_rss_${_i}
127 XCLEANFILES+=   stamp_tag_${_i}
128 X
129 Xstamp_htm_${_i}: ${DEPS_mk_inc2htm} ${DEPS_data_${_i}_cfg}
130 X       ${U_ENV} ${MKSH} ${TOP}/mk/inc2htm ${_i} >$@ || (rm -f $@; exit 1)
131 X
132 Xstamp_rss_${_i}: ${DEPS_mk_inc2rss} strftm ${DEPS_data_${_i}_cfg}
133 X       ${U_ENV} PATH=.:$$PATH ${MKSH} ${TOP}/mk/inc2rss ${_i} >$@ || \
134 X           (rm -f $@; exit 1)
135 X.endfor
136 X
137 XDEPSRCS+=      mk/inc2htm mk/inc2rss
138 XOBJS+=         ${GENSRCS}
139 XCLEANFILES+=   ${GENSRCS}
140 X
141 Xclean:
142 X       -${STRFTM_MAKE} clean
143 X.for _i in ${GENSRCS}
144 X       -rm -rf $$(<${_i})
145 X.endfor
146 X       -rm -rf dst permalinks
147 X       -rm -f ${CLEANFILES} site.tgz* *.tmp *~
148 X
149 Xcleandir: clean
150 X       -rm -rf hashed
151 X       -rm -f .depend ${CLEANFILES:M*~:S/~$//}
152 X
153 Xdeinstall:
154 X       -rm -rf dst site.tgz*
155 X
156 Xreinstall: deinstall .WAIT install
157 X
158 Xall: ${OBJS}
159 X
160 Xstrftm: mk/strftm.c
161 X       ${STRFTM_MAKE} $@
162 X
163 Xsite.tgz.stamp: _reinstall
164 X#      find dst | sort | sed -e '/^dst$$/d' -e 's,^dst/,,' | \
165 X#          (cd dst && cpio -voC512 -Hustar -Mdist) | gzip -n9 >site.tgz.tmp
166 X#      mv site.tgz.tmp site.tgz
167 X       :>$@
168 X
169 X.for _i in ${WLOGS}
170 XWLOG_LATEST:=${_i}
171 X.endfor
172 X
173 X_reinstall:
174 X       -rm -rf dst
175 X       mkdir dst dst/permalinks
176 X       pax -rw -pe -v hashed dst/
177 X       pax -rw -pe -dv ${OBJS:Nstamp_*:S/htm~$/htm/} dst/
178 X.for _i in ${GENSRCS}
179 X       pax -rw -pe -dv $$(<${_i}) dst/
180 X.endfor
181 X       cd ${TOP}/files && pax -rw -pe -v . ${DST}/dst/
182 X       cd ${TOP} && pax -rw -pe -v pics ${DST}/dst/
183 X       cd dst && \
184 X           ln -sf wlog-${WLOG_LATEST}.htm wlog.htm && \
185 X           ln -sf wlog-${WLOG_LATEST}.rss wlog.rss && \
186 X           rm -rf $$(find . -name CVS -o -name .cvsignore)
187 X       chgrp -R miros-cvswww dst
188 X       chmod -R ug=rwX,o=rX dst
189 X       chmod a+x dst/cvs.cgi
190 X
191 X.SUFFIXES: .val .htm~ .hts
192 X
193 X.hts.htm~:
194 X       @dstd='$@'; dstf=$${dstd%~}; rm -f $@; \
195 X        print -r "(. mk/htsconv; mws_basepath $$dstf; mws__do $<) >$$dstf"; \
196 X        export ${U_ENV}; if (cd ${DST}; . ${TOP}/mk/htsconv; \
197 X           mws_basepath $$dstf; mws__do $<) >$@; then \
198 X               (. ${TOP}/mk/htsconv; mws_moveifchange -k $$dstd $$dstf); \
199 X        else \
200 X               rm -f $@; \
201 X               exit 1; \
202 X       fi
203 X
204 X.htm~.val:
205 X       @print -r Creating ${@:Q} from ${<:Q} ...
206 X       @${_htm_2xhtml} <$< >$@
207 X
208 X.ifdef validate
209 XVOBJS:=                ${validate:=.val}
210 X
211 X.MAIN: validation
212 X.endif
213 X
214 Xvalidation: .PHONY ${VOBJS}
215 X       @print -r Validating ${.ALLSRC:Q} ...
216 X       @xmlstarlet val -d ${_xhtmldtd} ${.ALLSRC}
217 X       @print '\nValidation complete.'
218 X
219 X.PHONY: clean cleandir depend install deinstall reinstall _reinstall \
220 X       cp-herc cp-heph rs-heph rs-eurynome
221 X
222 X#cp-herc: site.tgz.stamp
223 X#      ssh hercs 'cd /var/www/oldsite; tar xzvf -' <site.tgz
224 X#
225 X#cp-heph: site.tgz.stamp
226 X#      ssh hephaistos 'cd Web; tar xzvpf -' <site.tgz
227 X
228 Xrs-heph:
229 X       rsync -rxlztpgavPHK dst/ hephaistos:Web/
230 X
231 Xrs-eurynome:
232 X       rsync -rxlztpgavPHK --rsh='ssh -4' dst/ eurynome:/var/anoncvs/anoncvs/www/
233 X
234 Xdepend: .depend
235 X
236 X.depend: ${TOP}/mk/mkdepend ${DEPSRCS}
237 X       -rm -f $@
238 X       ${STRFTM_MAKE} depend
239 X       ${U_ENV} ${MKSH} ${TOP}/mk/mkdepend ${DEPSRCS}
240 X
241 Xlazy: .PHONY
242 X       cd ${.CURDIR} && make depend && make && \
243 X           make _reinstall && exec make rs-eurynome rs-heph tagslst
244 X
245 Xtagslst: .PHONY
246 X       @(echo === TAGS USED/UNUSED/ACCOUNTED FOR ==; cat stamp_tag_* | \
247 X           sort -u | comm - tags.out) | tee tags.lst
248 X
249 X.include <bsd.obj.mk>
250 END-of-Makefile
251 echo x - mk/common
252 sed 's/^X//' >mk/common << 'END-of-mk/common'
253 Xrcsid_common='$MirOS: www/mk/common,v 1.3 2009/10/31 17:02:38 tg Exp $'
254 X#-
255 X# Copyright (c) 2007, 2008
256 X#      Thorsten Glaser <tg@mirbsd.de>
257 X#
258 X# Provided that these terms and disclaimer and all copyright notices
259 X# are retained or reproduced in an accompanying document, permission
260 X# is granted to deal in this work without restriction, including un-
261 X# limited rights to use, publicly perform, distribute, sell, modify,
262 X# merge, give away, or sublicence.
263 X#
264 X# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
265 X# the utmost extent permitted by applicable law, neither express nor
266 X# implied; without malicious intent or gross negligence. In no event
267 X# may a licensor, author or contributor be held liable for indirect,
268 X# direct, other damage, loss, or other issues arising in any way out
269 X# of dealing in the work, even if advised of the possibility of such
270 X# damage or existence of a defect, except proven that it results out
271 X# of said person's immediate fault when using the work as intended.
272 X
273 X# RFC 2396 and some optional characters _plus_ apostrophe
274 X# -> escapes all shell meta-characters as well
275 Xfunction uri_escape {
276 X       if (( $# )); then
277 X               print -nr -- "$@"
278 X       else
279 X               cat
280 X       fi | sed -e '
281 X           s.%.%25.g
282 X           s.;.%3B.g
283 X           s./.%2F.g
284 X           s.?.%3F.g
285 X           s.:.%3A.g
286 X           s.@.%40.g
287 X           s.&.%26.g
288 X           s.=.%3D.g
289 X           s.+.%2B.g
290 X           s.\$.%24.g
291 X           s.,.%2C.g
292 X           s.  .%09.g
293 X           s. .%20.g
294 X           s.<.%3C.g
295 X           s.>.%3E.g
296 X           s.#.%23.g
297 X           s.".%22.g
298 X           s.{.%7B.g
299 X           s.}.%7D.g
300 X           s.|.%7C.g
301 X           s.\\.%5C.g
302 X           s.\^.%5E.g
303 X           s.\[.%5B.g
304 X           s.\].%5D.g
305 X           s.`.%60.g
306 X           s.'\''.%27.g
307 X       '
308 X}
309 X
310 X# escape XHTML characters (three mandatory XML ones plus double quotes,
311 X# the latter in an XML safe fashion numerically though)
312 Xfunction xhtml_escape {
313 X       if (( $# )); then
314 X               print -nr -- "$@"
315 X       else
316 X               cat
317 X       fi | sed \
318 X           -e 's\ 1&\ 1\&amp;\ 1g' \
319 X           -e 's\ 1<\ 1\&lt;\ 1g' \
320 X           -e 's\ 1>\ 1\&gt;\ 1g' \
321 X           -e 's\ 1"\ 1\&#34;\ 1g'
322 X}
323 X
324 X# escape ampersands for sed (pipe only: post-processing)
325 Xfunction sed_escape {
326 X       sed -e 's\ 1&\ 1\\\&\ 1g'
327 X}
328 END-of-mk/common
329 echo x - mk/htsconv
330 sed 's/^X//' >mk/htsconv << 'END-of-mk/htsconv'
331 Xrcsid_htsconv='$MirOS: www/mk/htsconv,v 1.58 2011/02/18 22:37:28 tg Exp $'
332 X#-
333 X# This file is part of the website of The MirOS Project, which is
334 X# copyrighted material, please read the LICENCE file for details.
335 X
336 X#DEPEND mk/common
337 X. "$TOP"/mk/common
338 X
339 Xmws__pagename=
340 Xmws__header=
341 Xmws__rss=
342 Xmws__difftag=MBSD_HTSCONV_GENDATE_TAG_14701
343 Xunset mws__srcfile
344 Xunset mws__abspath
345 Xunset mws__relpath
346 Xunset mws__canonpath
347 Xunset mws__headline
348 Xunset mws__fontsize
349 Xmws__canonsite=https://www.mirbsd.org
350 Xnl='
351 X'
352 X
353 Xfunction mws__do {
354 X       mws__srcfile=$1
355 X
356 X       set +e
357 X       . "$1"
358 X}
359 X
360 Xfunction mws_setname {
361 X       mws__pagename=$2
362 X       # change index to mark $1
363 X}
364 X
365 Xfunction mws_setheadline {
366 X       mws__headline=$*
367 X}
368 X
369 Xfunction mws_setheadsize {
370 X       mws__fontsize=$1
371 X       (( mws__fontsize > 2 && mws__fontsize < 255 )) || unset mws__fontsize
372 X}
373 X
374 Xfunction mws_setrss {
375 X       mws__rss="\\
376 X <link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"$1\" />"
377 X       # this is for not doing the newline when no RSS is applicable
378 X}
379 X
380 Xfunction mws_subdir {
381 X       if [[ $1 = - ]]; then
382 X               mws__relpath=$mws__abspath/
383 X               return
384 X       fi
385 X       integer i=$1
386 X       mws__relpath=
387 X       while (( i-- )); do
388 X               mws__relpath=../$mws__relpath
389 X       done
390 X}
391 X
392 Xfunction mws_basepath {
393 X       mws__canonpath=$mws__canonsite/$1
394 X}
395 X
396 X# this only matches lines like this:
397 X# ^<h[23456] id="…id…">…content…</h[23456]>$
398 Xfunction mws_maketoc {
399 X       local level=0 sps='       ' line lna llv lid
400 X
401 X       if [[ -z $mws__srcfile ]]; then
402 X               print -u2 Internal error: not called via mws__do!
403 X               exit 1
404 X       fi
405 X       (grep '^<h[2-6] id="[^">]*">.*</h[2-6]>$' "$mws__srcfile"
406 X        print '<h1') |&
407 X       while IFS= read -pr line; do
408 X               set -A lna -- $line
409 X               (( llv = ${lna[0]#\<h} - 1 ))
410 X               while (( level < llv )); do
411 X                       if (( level )); then
412 X                               print "${sps::level}<li><ul>"
413 X                       else
414 X                               print "<ul>"
415 X                       fi
416 X                       let ++level
417 X               done
418 X               while (( level > llv )); do
419 X                       let --level
420 X                       if (( level )); then
421 X                               print "${sps::level}</ul></li>"
422 X                       else
423 X                               print "</ul>"
424 X                       fi
425 X               done
426 X               (( level )) || break
427 X               lid=${line#\<h? id=\"}
428 X               lid=${lid%%\"*}
429 X               line=${line#*\>}
430 X               line=${line%\</h?\>}
431 X               print "${sps::level}<li><a href=\"#$lid\">$line</a></li>"
432 X       done
433 X}
434 X
435 Xfunction mws_makepic {
436 X       local hpic htit fsiz hmag
437 X
438 X       htit=$1
439 X       fsiz=${2:-0}
440 X       hmag=${3:-u}
441 X
442 X       (( fsiz > 2 && fsiz < 255 )) || unset fsiz
443 X
444 X       hpic=$(cksum -a oaat <<<"$hmag,$fsiz,$htit").png
445 X       if [[ ! -s hashed/$hpic ]] && whence -p php >/dev/null; then
446 X               mkdir -p hashed
447 X               php "$TOP"/mk/ttf2png "$htit" $fsiz >hashed/$hpic
448 X       fi
449 X       print $hpic
450 X}
451 X
452 Xfunction mws_makepiclink {
453 X       local ptext pfile
454 X
455 X       pfile=$(mws_makepic "$@")
456 X       ptext=$(xhtml_escape "$1")
457 X
458 X       print "<img src=\"@@RELPATH@@hashed/$pfile\" alt=\"$ptext\" />"
459 X}
460 X
461 Xfunction mws_putheader {
462 X       local rcsid=$1 hpic
463 X
464 X       if [[ -z $mws__canonpath ]]; then
465 X               print -u2 Internal error: mws_basepath not called!
466 X               exit 1
467 X       fi
468 X       [[ -n $mws__headline ]] && mws__headline="$nl<h1>$(mws_makepiclink \
469 X           "$mws__headline" "$mws__fontsize" s)</h1>"
470 X       mws__content <<-EOF
471 X               <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
472 X                "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
473 X               <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
474 X                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
475 X                <meta http-equiv="Content-Style-Type" content="text/css" />
476 X                <meta name="MSSmartTagsPreventParsing" content="TRUE" />
477 X                <link rel="stylesheet" type="text/css" href="@@RELPATH@@vstyle.css" />
478 X                <link rel="apple-touch-icon" href="@@RELPATH@@pics/blumenkohl.png" />
479 X                <link rel="canonical" href="$mws__canonpath" />
480 X                <meta name="author" content="Thorsten Glaser" />
481 X                <meta name="copyright" content="All rights reserved. Redistribution except for scientific and educational uses strictly prohibited. Unmodified redistribution with no endorsement permitted." />
482 X                <meta name="owner" content="The MirOS Project and The MirPorts Framework" />
483 X                <meta name="licence" content="see the source files in CVSWEB for details" />
484 X                <title>MirOS: $mws__pagename</title>
485 X                <meta name="robots" content="index, follow" />@@RSS@@
486 X                <!--
487 X                 This is copyrighted material. For the full licence text, see the file
488 X                 LICENCE in the current directory. In no event may text from this page
489 X                 be simply copied into another work covered by an unfree (or otherwise
490 X                 mismatching) licence, such as the GNU Free Documentation License.
491 X                -->
492 X               </head><body>$mws__headline
493 X               <div class="trailing">
494 X               <div class="index">
495 X                <ul class="lv1">
496 X               <li><a href="@@RELPATH@@main.htm">Main</a><ul class="lv2">
497 X               <li><a href="@@RELPATH@@wlog-10.htm">Weblog</a> for #10</li>
498 X               <li><a href="@@RELPATH@@tags.htm">Tag Cloud</a></li>
499 X               <li><a href="@@RELPATH@@news.htm">Old News</a> &amp;
500 X                <a href="@@RELPATH@@oldnews.htm#owlog">WLog</a></li>
501 X               </ul></li>
502 X               <li><a href="@@RELPATH@@about.htm">About</a></li>
503 X               <!-- these are not in a usable state
504 X               <li><a href="@@RELPATH@@docs.htm">Documentation</a></li>
505 X               <li><a href="@@RELPATH@@faq.htm">FAQ</a></li>
506 X               -->
507 X               <li class="spacer"><a href="@@RELPATH@@getting.htm">Download</a></li>
508 X               <li><a href="@@RELPATH@@rss.htm">RSS &amp; Mailing Lists</a></li>
509 X               <li><a href="@@RELPATH@@irc.htm">IRC</a></li>
510 X               <li><a href="@@RELPATH@@projects.htm">Project Ideas</a></li>
511 X               <li><a href="@@RELPATH@@danke.htm">Donate</a></li>
512 X               <li>Manpages<ul class="lv2">
513 X               <li><a href="@@RELPATH@@htman/i386/">i386</a></li>
514 X               <li><a href="@@RELPATH@@htman/sparc/">sparc</a></li>
515 X               </ul></li>
516 X               <li><a href="@@RELPATH@@ports.htm">MirPorts</a> Framework</li>
517 X               <li><a href="@@RELPATH@@pkgsrc.htm">pkgsrc®</a> integration</li>
518 X               <li>Subprojects<ul class="lv2">
519 X               <li><a href="@@RELPATH@@jupp.htm">jupp</a> Editor</li>
520 X               <li><a href="@@RELPATH@@kwalletcli.htm">KWalletCLI</a></li>
521 X               <!-- li><a href="@@RELPATH@@makefs.htm">makefs</a></li -->
522 X               <li><a href="@@RELPATH@@mksh.htm">mksh</a> Shell</li>
523 X               </ul></li>
524 X                </ul>
525 X               <div style="margin-top:18px; margin-left:6px;">Sponsored
526 X                by<br /><a href="http://www.speedpartner.de/"
527 X                 style="border:none; text-decoration:none;"><img
528 X                 style="border:none; text-decoration:none;"
529 X                 src="@@RELPATH@@pics/speedpartner.png"
530 X                 alt="SpeedPartner logo" width="130" height="31"
531 X                 /></a>
532 X               </div>
533 X               </div>
534 X               <div class="content">
535 X       EOF
536 X       mws__header="<p class=\"rcsdiv\">Generated <!-- $mws__difftag --> on"
537 X       mws__header="$mws__header <span class=\"rcsid\">$(date +'%F %T')</span>"
538 X       mws__header="$mws__header by <span class=\"rcsid\">$rcsid_htsconv</span>"
539 X       for x in "$rcsid_parser" "$rcsid_inc2htm" "$rcsid_inc2rss"; do
540 X               [[ -n $x ]] || continue
541 X               mws__header="$mws__header and <span class=\"rcsid\">$x</span>"
542 X       done
543 X       for x in "$rcsid_cfg" "$rcsid"; do
544 X               [[ -n $x ]] || continue
545 X               mws__header="$mws__header from <span class=\"rcsid\">$x</span>"
546 X       done
547 X       for x in "${rcsid_db[@]}"; do
548 X               [[ -n $x ]] || continue
549 X               mws__header="$mws__header and <span class=\"rcsid\">$x</span>"
550 X       done
551 X       mws__header="$mws__header</p>"
552 X}
553 X
554 Xfunction mws_moveifchange {
555 X       if [[ $1 = -k ]]; then
556 X               keep=1
557 X               shift
558 X       else
559 X               keep=0
560 X       fi
561 X       [[ -e $1 && -e $2 ]] || ls -l "$1" "$2" 2>&1 | sed 's/^/!/' >&2
562 X       [[ -e $1 ]] && if [[ -e $2 ]] && \
563 X           diff -waqI "$mws__difftag" "$1" "$2" >/dev/null 2>&1; then
564 X               [[ $keep = 1 ]] || rm -f "$1"
565 X       else
566 X               if [[ $keep = 1 ]]; then
567 X                       cp -f "$1" "$2"
568 X               else
569 X                       mv -f "$1" "$2"
570 X               fi
571 X       fi
572 X       #touch "$2"
573 X       return 0
574 X}
575 X
576 Xfunction mws_putfooter {
577 X       mws_content <<-'EOF'
578 X               </div>
579 X               <div class="footer">
580 X               <p style="display: none;">Do <em>not</em> send any eMail to <a
581 X                href="mailto:junk@mirbsd.de">junk@mirbsd.de</a>, <a
582 X                href="mailto:junk@mirbsd.org">junk@mirbsd.org</a>, or <a
583 X                href="mailto:junk@mirsolutions.de">junk@mirsolutions.de</a> –
584 X                it won’t do any good to you.</p>
585 X               <p>• <a
586 X                href="mailto:miros-discuss@mirbsd.org">eMail</a> contact to
587 X                The MirOS Project • This website is (supposed to be) <a
588 X                href="http://validator.w3.org/check/referer">Valid HTML</a>! •
589 X               </p>
590 X               @@HEADER@@
591 X               </div></div>
592 X               <div class="heading">
593 X                <img class="hdrlnks" alt="MirOS Logo"
594 X                 src="@@RELPATH@@pics/logo-grey.png" />
595 X               </div>
596 X               </body></html>
597 X       EOF
598 X}
599 X
600 Xfunction mws_content {
601 X       if [[ -z $mws__header ]]; then
602 X               print -u2 Internal error: mws_putheader not called!
603 X               exit 1
604 X       fi
605 X       mws__content "$@"
606 X}
607 X
608 Xfunction mws__content {
609 X       sed \
610 X           -e 's\ 1\([0-9A-z][-.,0-9A-z]*\)(\(DOCS\))\ 1<a href="@@RELPATH@@htman/i386/man\2/\1.htm" class="manlink">&</a>\ 1g' \
611 X           -e 's\ 1\([0-9A-z][-.,0-9A-z]*\)(\(PAPERS\))\ 1<a href="@@RELPATH@@htman/i386/man\2/\1.htm" class="manlink">&</a>\ 1g' \
612 X           -e 's\ 1\([0-9A-z][-.,0-9A-z]*\)(GNU)\ 1<a href="@@RELPATH@@htman/i386/manINFO/\1.html" class="manlink">&</a>\ 1g' \
613 X           -e 's\ 1\([0-9A-z][-.,0-9A-z]*\)(\([PSU][MS][DM]\))\ 1<a href="@@RELPATH@@htman/i386/man\2/\1.htm" class="manlink">&</a>\ 1g' \
614 X           -e 's\ 1\([0-9A-z][-.,0-9A-z]*\)(\([1-9]\)/[Ss][Pp][Aa][Rr][Cc])\ 1<a href="@@RELPATH@@htman/sparc/man\2/\1.htm" class="manlink">&</a>\ 1g' \
615 X           -e 's\ 1\([0-9A-z][-.,0-9A-z]*\)(\([1-9]\)/[Ii]386)\ 1<a href="@@RELPATH@@htman/i386/man\2/\1.htm" class="manlink">&</a>\ 1g' \
616 X           -e 's\ 1\([0-9A-z][-.,0-9A-z]*\)(\([1-9]\))\ 1<a href="@@RELPATH@@htman/i386/man\2/\1.htm" class="manlink">&</a>\ 1g' \
617 X           -e "s\ 1@@ABSPATH@@\ 1$mws__abspath\ 1g" \
618 X           -e "s\ 1@@RELPATH@@\ 1$mws__relpath\ 1g" \
619 X           -e "s\ 1@@HEADER@@\ 1$mws__header\ 1g" \
620 X           -e "s\ 1@@RSS@@\ 1$mws__rss\ 1g"
621 X}
622 X
623 Xfunction mws_push {
624 X       for param in _pagename _relpath; do
625 X               eval mws__push_$param=\$mws_$param
626 X       done
627 X}
628 X
629 Xfunction mws_pop {
630 X       for param in _pagename _relpath; do
631 X               eval mws_$param=\$mws__push_$param
632 X       done
633 X}
634 END-of-mk/htsconv
635 echo x - mk/inc2htm
636 sed 's/^X//' >mk/inc2htm << 'END-of-mk/inc2htm'
637 Xrcsid_inc2htm='$MirOS: www/mk/inc2htm,v 1.26 2009/10/31 17:02:39 tg Exp $'
638 X#-
639 X# This file is part of the website of The MirOS Project, which is
640 X# copyrighted material, please read the LICENCE file for details.
641 X
642 Xinteger perpage=12
643 Xname=$1
644 X
645 X. "$TOP/data/$name.cfg"
646 X
647 X#DEPEND mk/parser
648 X. "$TOP"/mk/parser
649 X
650 X#DEPEND mk/htsconv
651 X. "$TOP"/mk/htsconv
652 X
653 Xwd=$(pwd)
654 Xcd "$TOP/data"
655 Xfor x in *.cfg; do
656 X       x=${x%.cfg}
657 X       t=$(grep '^targets=' $x.cfg || :)
658 X       typeset -l targets=
659 X       [[ -z $t ]] || eval $t
660 X       for t in $targets; do
661 X               if [[ $t != +([0-9a-z_]) ]]; then
662 X                       print -u2 "Invalid tag '$t' in data/$x.cfg"
663 X                       continue
664 X               fi
665 X               eval linktarget_$t=$x
666 X       done
667 Xdone
668 Xcd "$wd"
669 X
670 Xfunction output {
671 X       local rcmd i j x
672 X
673 X       rpath=$1
674 X       efe="${rpath}${ei_srcf[ent]}_${eid}.htm#${eid}_${ei_srcf[ent]}"
675 X       title="${e_date[ent]}${e_author[ent]+ by }${e_author[ent]}"
676 X       subtitle=
677 X       if [[ ${e_language[ent]} = +([A-Za-z0-9-]) ]]; then
678 X               xmllang=" xml:lang=\"${e_language[ent]}\""
679 X       else
680 X               xmllang=
681 X       fi
682 X       print "<div class=\"wlentry\"$xmllang>"
683 X       if [[ -n ${e_title[ent]} ]]; then
684 X               subtitle='<div class="wlsubtitle">'"${title}</div>$nl"
685 X               title="${e_title[ent]}"
686 X       fi
687 X       if [[ -n ${e_tag[ent]} ]]; then
688 X               subtitle=$subtitle'<div class="wltagtitle">Tags:'
689 X               for x in ${e_tag[ent]}; do
690 X                       eval t=\$linktarget_$x
691 X                       [[ -z $t ]] || x="<a href=\"@@RELPATH@@${t}_all.htm#${eid}_${ei_srcf[ent]}\">$x</a>"
692 X                       subtitle="$subtitle $x"
693 X               done
694 X               subtitle="$subtitle</div>$nl"
695 X       fi
696 X       if [[ -n ${e_pictures[ent]} ]]; then
697 X               set -A rcmd -- sed
698 X               for i in ${e_pictures[ent]}; do
699 X                       case $i {
700 X                       (*:*)   j=${i#*:}; i=${i%%:*} ;;
701 X                       (*)     j= ;;
702 X                       }
703 X                       eval x='${e_picture'$i'[ent]}'
704 X                       rcmd[${#rcmd[*]}]=-e
705 X                       rcmd[${#rcmd[*]}]="s\ 1@!PICTURE${i}!@\ 1$(mws_makepiclink \
706 X                           "$x" "$j" d | sed_escape)\ 1g"
707 X               done
708 X       else
709 X               rcmd=cat
710 X       fi
711 X       cat <<-EOF
712 X               <div class="wltitle">
713 X               <h2 class="wlentry" id="${e_id[ent]}_${ei_srcf[ent]}"><a href="${efe}">${title}</a></h2>
714 X               ${subtitle}</div>
715 X       EOF
716 X       "${rcmd[@]}" <<-EOF
717 X               ${ei_body[ent]/'<!-- RSS stop -->'}
718 X               </div>
719 X       EOF
720 X}
721 X
722 Xfunction mopen {
723 X       integer number=$1
724 X       if (( number == 1 )); then
725 X               fn=$name.htm
726 X       else
727 X               fn=${name}_${number}.htm
728 X       fi
729 X       print -r -- "$fn"
730 X       mws_setname $whoami "$pname – Page $number"
731 X       mws_subdir 0
732 X       mws_setheadline "$ptitle"
733 X       mws_putheader >$fn~
734 X       print -r -- "<p>${plinks}" >>$fn~
735 X}
736 X
737 Xfunction mclose {
738 X       mws_putfooter >>$1~
739 X       mws_moveifchange $1~ $1
740 X}
741 X
742 X
743 X#rm -f ${name}.{cut,htm} ${name}_*.htm permalinks/${name}_*.htm
744 X(( cutoff )) && cat >${name}.cut~ <<-EOF
745 X       : ${mws__relpath=/}
746 XEOF
747 Xmws_basepath ${name}_all.htm
748 Xprint -r -- ${name}_all.htm
749 Xmws_setname $whoami "$pname – All in One Page"
750 Xmws_setrss "${mws__relpath}${name}.rss"
751 Xmws_subdir 0
752 Xmws_setheadline "$ptitle"
753 Xmws_putheader >${name}_all.htm~
754 Xplinks="<a href=\"${name}_all.htm\">All</a> <a href=\"${name}.htm\">1</a>"
755 Xplinksr="<a href=\"../${name}_all.htm\">All</a> <a href=\"../${name}.htm\">1</a>"
756 Xinteger i=2
757 Xwhile (( i <= ((entries - cutoff) / perpage + 1) )); do
758 X       plinks="$plinks <a href=\"${name}_${i}.htm\">${i}</a>"
759 X       plinksr="$plinksr <a href=\"../${name}_${i}.htm\">${i}</a>"
760 X       let ++i
761 Xdone
762 Xplinks="${plinks}</p>"
763 Xplinksr="${plinksr}</p>"
764 Xprint -r -- "<p>${plinks}" >>${name}_all.htm~
765 Xmopen 1
766 Xmkdir -p permalinks
767 Xinteger entryc=0
768 Xinteger entryp='entries - 1'
769 Xinteger ent
770 Xwhile (( entryp >= 0 )); do
771 X       ent=${ei_indir[entryp]}
772 X       eid=$(uri_escape "${e_id[ent]}")
773 X       do_permalink=1
774 X       for f in "${nopermalinks[@]}"; do
775 X               [[ $f = ${ei_srcf[ent]} ]] || continue
776 X               do_permalink=0
777 X               break
778 X       done
779 X       if (( do_permalink )); then
780 X               fe=permalinks/${ei_srcf[ent]}_${eid}.htm
781 X               print -r -- "$fe"
782 X               mws_push
783 X               mws_setname $whoami "$pname"
784 X               mws_subdir 1
785 X               mws_setheadline "$ptitle"
786 X               mws_putheader >$fe~
787 X               print -r -- "<p>${plinksr}" >>$fe~
788 X               output | mws_content >>$fe~
789 X               mclose $fe
790 X               mws_pop
791 X       fi
792 X       if (( entryc < cutoff )); then
793 X               print "mws_content <<'EOF_cutoff_$name'" >>${name}.cut~
794 X               output @@RELPATH@@permalinks/ >>${name}.cut~
795 X               print EOF_cutoff_$name >>${name}.cut~
796 X       else
797 X               output permalinks/ | mws_content >>$fn~
798 X       fi
799 X       output permalinks/ | mws_content >>${name}_all.htm~
800 X       let entryp--
801 X       let entryc++
802 X       if (( ((entryc - cutoff) % perpage) == 0 )); then
803 X               print -r -- "<p class=\"linkbot\">$plinks" >>$fn~
804 X               mclose $fn
805 X               mopen $(((entryc - cutoff) / perpage + 1))
806 X       fi
807 Xdone
808 Xprint -r -- "<p class=\"linkbot\">$plinks" >>$fn~
809 Xprint -r -- "<p class=\"linkbot\">$plinks" >>${name}_all.htm~
810 Xmclose $fn
811 Xmclose ${name}_all.htm
812 X[[ -e ${name}.cut~ ]] && mws_moveifchange ${name}.cut~ ${name}.cut
813 Xexit 0
814 END-of-mk/inc2htm
815 echo x - mk/inc2rss
816 sed 's/^X//' >mk/inc2rss << 'END-of-mk/inc2rss'
817 Xrcsid_inc2rss='$MirOS: www/mk/inc2rss,v 1.30 2009/10/31 17:02:39 tg Exp $'
818 X#-
819 X# This file is part of the website of The MirOS Project, which is
820 X# copyrighted material, please read the LICENCE file for details.
821 X
822 Xinteger maxentries=25
823 XDATE_RSS="%a, %d %b %Y %H:%M:%S %z"
824 Xname=$1
825 X
826 X. "$TOP/data/$name.cfg"
827 X
828 X#DEPEND mk/parser
829 X. "$TOP"/mk/parser
830 X
831 X#DEPEND mk/htsconv
832 X. "$TOP"/mk/htsconv
833 X
834 Xmws__header="<!-- RSS mode -->"
835 Xmws__abspath=$mws__canonsite
836 X
837 Xfunction rss_putheader {
838 X       #lastchanged=$(date -r $(stat -f "%m" "$TOP/data/$name.inc") +"$DATE_RSS")
839 X       lastchanged=$(date +"$DATE_RSS")
840 X       cat <<-EOF
841 X               <rss
842 X                xmlns:atom="http://www.w3.org/2005/Atom"
843 X                xmlns:dc="http://purl.org/dc/elements/1.1/"
844 X                version="2.0">
845 X               <channel xml:lang="en">
846 X                <title>$ptitle</title>
847 X                <description>$pname - the MirOS Project</description>
848 X                <atom:link href="$mws__abspath/$1" rel="self" type="application/rss+xml" />
849 X                <lastBuildDate>$lastchanged</lastBuildDate>
850 X                <link>http://mirbsd.de/</link>
851 X                <managingEditor>tg@mirbsd.org (The MirOS Project)</managingEditor>
852 X                <webMaster>bsiegert@mirbsd.org (The MirOS Project)</webMaster>
853 X                <copyright>All content Copyright © by The MirOS Project or its respective
854 X                 writers. Permission to reproduce wlog entries in unmodified form without
855 X                 notice is granted provided they are not used to endorse or promote any
856 X                 products or opinions. For everything else you need to obtain written
857 X                 permission from the copyright owner.</copyright>
858 X                <dc:language>en</dc:language>
859 X                <ttl>${rssttl:-1440}</ttl>
860 X                <generator>MirOS Website, written in mksh; RCS IDs:
861 X                   $rcsid_parser
862 X                   $rcsid_common
863 X                   $rcsid_htsconv
864 X                   $rcsid_inc2rss
865 X                 RCS IDs of the content database:
866 X                   $rcsid_cfg
867 X       EOF
868 X       for x in "${rcsid_db[@]}"; do
869 X               [[ -z $x ]] && continue
870 X               print "    $x"
871 X       done
872 X       print " </generator>"
873 X}
874 X
875 Xfunction rss_putfooter {
876 X       print "</channel></rss>"
877 X}
878 X
879 Xfunction rss_output {
880 X       local rcmd i x
881 X       integer ent=$1
882 X       rpath=$2
883 X       eid=$(uri_escape "${e_id[ent]}")
884 X       efe="${mws__abspath}${rpath}${ei_srcf[ent]}_${eid}.htm#${eid}_${ei_srcf[ent]}"
885 X       pubdate=$(strftm "$DATE_RSS" ${ei_time[ent]})
886 X       if [[ -n ${e_title[ent]} ]]; then
887 X               title="${e_title[ent]}"
888 X       else
889 X               title="${e_date[ent]}${e_author[ent]+ by }${e_author[ent]}"
890 X       fi
891 X       if [[ ${e_language[ent]} = +([A-Za-z0-9-]) ]]; then
892 X               xmllang=" xml:lang=\"${e_language[ent]}\""
893 X               rss3lang="<language>${e_language[ent]}</language>"
894 X       else
895 X               xmllang=
896 X               rss3lang=
897 X       fi
898 X       # we use $xmllang: RSS 2.0 doesn’t allow the language tag inside
899 X       # items, just as channel tag (and Benny’s template doesn’t even
900 X       # use it but dc:language instead)
901 X       cat <<-EOF
902 X               <item$xmllang>
903 X               <title>$title</title>
904 X               <pubDate>$pubdate</pubDate>
905 X               <link>$efe</link>
906 X               <guid isPermaLink="true">$mws__canonsite/permalinks/${ei_srcf[ent]}_${eid}.htm</guid>
907 X       EOF
908 X       for x in ${e_tag[ent]}; do
909 X               print "<category>$x</category>"
910 X               print $x >>stamp_tag_$name
911 X       done
912 X       if [[ -n ${e_author[ent]} ]]; then
913 X               eauthor=${e_author[ent]}
914 X               mauthor=
915 X               if [[ $eauthor = *@ ]]; then
916 X                       uauthor=" ${eauthor%%@*}"
917 X                       eauthor="${eauthor}mirbsd.org"
918 X               fi
919 X               [[ $eauthor = *\(*\)* ]] || eauthor="$eauthor (MirOS Developer$uauthor)"
920 X               print "<author>${eauthor}</author>\n"
921 X       fi
922 X       print "<description>"
923 X       if [[ -n ${e_pictures[ent]} ]]; then
924 X               set -A rcmd -- sed
925 X               for i in ${e_pictures[ent]}; do
926 X                       i=${i%%:*}
927 X                       eval x='${e_picture'$i'[ent]}'
928 X                       rcmd[${#rcmd[*]}]=-e
929 X                       rcmd[${#rcmd[*]}]="s\ 1@!PICTURE${i}!@\ 1$(xhtml_escape \
930 X                           "$x" | sed_escape)\ 1g"
931 X               done
932 X       else
933 X               rcmd=cat
934 X       fi
935 X       "${rcmd[@]}" <<<"${ei_body[ent]%%@(<!-- RSS stop -->)*}" | \
936 X           mws_content | xhtml_escape
937 X       print "</description></item>"
938 X}
939 X
940 Xrm -f stamp_tag_$name
941 Xprint -r -- ${name}.rss
942 Xmws_setname $whoami "$pname"
943 Xmws_subdir -
944 Xrss_putheader "${name}.rss" >${name}.rss~
945 X
946 Xinteger i='entries - 1'
947 Xinteger last='entries < maxentries ? 0 : entries - maxentries'
948 Xwhile (( i >= last )); do
949 X       rss_output ${ei_indir[i]} "/permalinks/" >>${name}.rss~
950 X       let i--
951 Xdone
952 X
953 Xrss_putfooter >>${name}.rss~
954 Xmws_moveifchange ${name}.rss~ ${name}.rss
955 X[[ -e stamp_tag_$name ]] && sort -u -o stamp_tag_$name stamp_tag_$name
956 Xexit 0
957 END-of-mk/inc2rss
958 echo x - mk/mkdepend
959 sed 's/^X//' >mk/mkdepend << 'END-of-mk/mkdepend'
960 X# $MirOS: www/mk/mkdepend,v 1.5 2008/12/04 20:03:27 tg Exp $
961 X#-
962 X# This file is part of the website of The MirOS Project, which is
963 X# copyrighted material, please read the LICENCE file for details.
964 X
965 Xfunction tofn {
966 X       print -nr -- "$*" | tr '/. ' ___
967 X}
968 X
969 Xrm -rf "$DST"/{.depend.tmp{,2},.dep}
970 Xd="$DST/.dep"
971 Xmkdir "$d"
972 Xcd "$TOP"
973 X
974 Xset -A files
975 Xfor f in "$@"; do
976 X       files[${#files[*]}]=$f
977 X       print "\${TOP}/$f" >>"$d/$(tofn "$f")"
978 X       if [[ $f = *.hts ]]; then
979 X               g=${f##*/}
980 X               print "${g%s}m~: .NOTMAIN \${DEPS_$(tofn "$f")}" >>"$DST/.depend.tmp2"
981 X       fi
982 X       [[ $debug = 1 ]] && print "D: input file $f"
983 Xdone
984 Xinteger p=0
985 Xwhile (( p < ${#files[*]} )); do
986 X       integer q=p
987 X       integer r=${#files[*]}
988 X       while (( q < r )); do
989 X               [[ $debug = 1 ]] && print "D: depending ${files[q]}"
990 X               (
991 X                       [[ ${files[q]} = *.hts ]] && print mk/htsconv
992 X                       grep -e '^#DEPEND ' -e '^//DEPEND ' ${files[q]}
993 X               ) |&
994 X               dp=$d/$(tofn "${files[q]}")
995 X               while IFS= read -pr line; do
996 X                       line=${line##*DEPEND }
997 X                       [[ $debug = 1 ]] && print "D:        on -> $line"
998 X                       if [[ $line = OBJ:* ]]; then
999 X                               print "${line#OBJ:}" >>"$dp"
1000 X                               continue
1001 X                       fi
1002 X                       for tfn in $line; do
1003 X                               print "\${TOP}/$tfn" >>"$d/$(tofn "$tfn")"
1004 X                               files[${#files[*]}]=$tfn
1005 X                               print "\${DEPS_$(tofn "$tfn")}" >>"$dp"
1006 X                       done
1007 X               done
1008 X               let q++
1009 X       done
1010 X       let p=r
1011 Xdone
1012 X
1013 Xcd "$DST/.dep"
1014 Xfor file in *; do
1015 X       sort -u "$file" | while IFS= read -r name; do
1016 X               print "DEPS_$file+=\t$name"
1017 X       done
1018 Xdone >"$DST/.depend.tmp"
1019 Xcd "$DST"
1020 Xcat .depend.tmp2 >>.depend.tmp
1021 Xcat .depend.tmp >>.depend
1022 Xrm -rf .dep .depend.tmp{,2}
1023 Xexit 0
1024 END-of-mk/mkdepend
1025 echo x - mk/parser
1026 sed 's/^X//' >mk/parser << 'END-of-mk/parser'
1027 Xrcsid_parser='$MirOS: www/mk/parser,v 1.20 2008/12/04 20:55:12 tg Exp $'
1028 X#-
1029 X# This file is part of the website of The MirOS Project, which is
1030 X# copyrighted material, please read the LICENCE file for details.
1031 X
1032 Xset -A e_author
1033 Xset -A e_id
1034 Xset -A ei_body
1035 Xset -A ei_indir
1036 Xset -A ei_srcf
1037 Xset -A ei_skip
1038 Xset -A ei_time
1039 X
1040 Xnl='
1041 X'
1042 Xsave_IFS=$IFS
1043 Xinteger entry=0
1044 Xinteger guid
1045 Xinteger state
1046 Xtypeset -l parser_lctmp
1047 X
1048 Xfor srcf in $sources; do
1049 X       eval parser_lctmp=\$tags_${srcf//\-/_}
1050 X       tags=:
1051 X       for x in $parser_lctmp; do
1052 X               tags=$tags$x:
1053 X       done
1054 X       guid=10000
1055 X       ids=:
1056 X       state=1
1057 X       rcsid_parsed=
1058 X       while IFS= read -r line; do
1059 X               if [[ $line = RCSID:* && -z $rcsid_parsed ]]; then
1060 X                       rcsid_parsed=${line##RCSID:*([   ])}
1061 X               elif [[ $line = ---- ]]; then
1062 X                       if [[ -z ${e_id[entry]} ]]; then
1063 X                               if [[ -n ${e_date[entry]} ]]; then
1064 X                                       id=${e_date[entry]}
1065 X                                       id=e${id:6:4}${id:3:2}${id::2}
1066 X                               else
1067 X                                       id=g$((guid++))
1068 X                               fi
1069 X                               if [[ -n ${e_author[entry]} ]]; then
1070 X                                       id=${id}-${e_author[entry]%%@(@)*}
1071 X                               else
1072 X                                       id=${id}-nn
1073 X                               fi
1074 X                               e_id[entry]=$id
1075 X                       fi
1076 X                       while [[ :$ids = *:${e_id[entry]}:* ]]; do
1077 X                               e_id[entry]=${e_id[entry]}-g$guid
1078 X                               let guid++
1079 X                       done
1080 X                       ei_srcf[entry]=$srcf
1081 X                       ids=$ids${e_id[entry]}:
1082 X                       if [[ $tags != : ]]; then
1083 X                               ei_skip[entry]=1
1084 X                               for x in ${e_tag[entry]}; do
1085 X                                       [[ $tags = *:$x:* ]] || continue
1086 X                                       unset ei_skip[entry]
1087 X                                       break
1088 X                               done
1089 X                       fi
1090 X                       let ++entry
1091 X                       state=2
1092 X               elif (( state > 0 )); then
1093 X                       if [[ $line = @([A-Za-z]*([A-Za-z0-9_]):\ *) ]]; then
1094 X                               x=${line##+([A-Za-z0-9_]):+([    ])}    # value
1095 X                               parser_lctmp=${line/%:+([        ])$x}  # key
1096 X                               eval e_$parser_lctmp[entry]=\$x
1097 X                       elif [[ -z $line ]]; then
1098 X                               state=0
1099 X                               continue
1100 X                       elif [[ $line = \#* ]]; then
1101 X                               continue        # ignore comment
1102 X                       else
1103 X                               print -u2 "Unknown header in data/$srcf.inc:" \
1104 X                                   "$line"
1105 X                               exit 1
1106 X                       fi
1107 X                       state=1
1108 X                       if [[ $parser_lctmp = date ]]; then
1109 X                               # split up german format (d.m.yyyy [H:M:S])
1110 X                               # date, then pad to dd.mm.yyyy and store as
1111 X                               # y m d H M S for strftm
1112 X                               IFS=$IFS:.
1113 X                               set -A e_tmp ${e_date[entry]}
1114 X                               IFS=$save_IFS
1115 X                               typeset -i -Z2 e_tmpd=10#0${e_tmp[0]}
1116 X                               typeset -i -Z2 e_tmpm=10#0${e_tmp[1]}
1117 X                               typeset -i -Z4 e_tmpy=10#0${e_tmp[2]}
1118 X                               e_date[entry]=$e_tmpd.$e_tmpm.$e_tmpy
1119 X                               # make sure there are no leading zeroes
1120 X                               ei_time[entry]="$((e_tmpy)) $((e_tmpm)) $((e_tmpd)) $((10#0${e_tmp[3]})) $((10#0${e_tmp[4]})) $((10#0${e_tmp[5]}))"
1121 X                       elif [[ $parser_lctmp = tag ]]; then
1122 X                               parser_lctmp=${e_tag[entry]}
1123 X                               unset e_tag[entry]
1124 X                               for x in $parser_lctmp; do
1125 X                                       if [[ $x != +([0-9a-z_]) ]]; then
1126 X                                               print -u2 "Invalid tag '$x' in" \
1127 X                                                   "data/$srcf.inc: $line"
1128 X                                               continue
1129 X                                       fi
1130 X                                       e_tag[entry]=${e_tag[entry]}${e_tag[entry]+ }$x
1131 X                               done
1132 X                       fi
1133 X               else
1134 X                       ei_body[entry]=${ei_body[entry]}${ei_body[entry]+$nl}$line
1135 X               fi
1136 X       done <"$TOP/data/$srcf.inc"
1137 X       if (( state != 2 )); then
1138 X               print -u2 "Last line of data/$srcf.inc not a separator!"
1139 X               exit 1
1140 X       fi
1141 X       [[ -z $rcsid_parsed ]] || rcsid_db[${#rcsid_db[*]}]=$rcsid_parsed
1142 Xdone
1143 Xinteger entries=entry
1144 Xif [[ -n $notimesort ]]; then
1145 X       entry=-1
1146 X       state=0
1147 X       while (( ++entry < entries )); do
1148 X               [[ ${ei_skip[entry]} = 1 ]] || ei_indir[state++]=$entry
1149 X       done
1150 Xelse
1151 X       ( integer e=-1; while (( ++e < entries )); do
1152 X               [[ ${ei_skip[e]} = 1 ]] || print ${ei_time[e]} $e
1153 X         done | sort -nbk1,1 -k2,2 -k3,3 -k4,4 -k5,5 -k6,6 ) |&
1154 X       state=0
1155 X       while read -p y m d H M S entry; do
1156 X               ei_indir[state++]=$entry
1157 X       done
1158 Xfi
1159 Xentries=$state
1160 Xreturn 0
1161 END-of-mk/parser
1162 echo x - mk/strftm.c
1163 sed 's/^X//' >mk/strftm.c << 'END-of-mk/strftm.c'
1164 X/*-
1165 X * Copyright (c) 2008
1166 X *     Thorsten Glaser <tg@mirbsd.org>
1167 X *
1168 X * Provided that these terms and disclaimer and all copyright notices
1169 X * are retained or reproduced in an accompanying document, permission
1170 X * is granted to deal in this work without restriction, including un-
1171 X * limited rights to use, publicly perform, distribute, sell, modify,
1172 X * merge, give away, or sublicence.
1173 X *
1174 X * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
1175 X * the utmost extent permitted by applicable law, neither express nor
1176 X * implied; without malicious intent or gross negligence. In no event
1177 X * may a licensor, author or contributor be held liable for indirect,
1178 X * direct, other damage, loss, or other issues arising in any way out
1179 X * of dealing in the work, even if advised of the possibility of such
1180 X * damage or existence of a defect, except proven that it results out
1181 X * of said person's immediate fault when using the work as intended.
1182 X */
1183 X
1184 X#include <sys/param.h>
1185 X#include <err.h>
1186 X#include <errno.h>
1187 X#include <limits.h>
1188 X#include <stdio.h>
1189 X#include <stdlib.h>
1190 X#include <string.h>
1191 X#include <time.h>
1192 X
1193 X__RCSID("$MirOS: www/mk/strftm.c,v 1.2 2008/12/07 17:19:03 tg Exp $");
1194 X
1195 Xextern const char *__progname;
1196 X
1197 Xchar buf[4096];
1198 X
1199 X#define CONVERT(num, elem, name, minval, maxval) do {                  \
1200 X       const char *e = NULL;                                           \
1201 X       char *ep;                                                       \
1202 X       long long res;                                                  \
1203 X                                                                       \
1204 X       tm.elem = res = strtoll(argv[num], &ep, 0);                     \
1205 X       if (ep == argv[num] || *ep != '\0')                             \
1206 X               e = "invalid";                                          \
1207 X       else if ((res == LLONG_MIN && errno == ERANGE) ||               \
1208 X           res < (minval))                                             \
1209 X               e = "too small";                                        \
1210 X       else if ((res == LLONG_MAX && errno == ERANGE) ||               \
1211 X           res > (maxval))                                             \
1212 X               e = "too large";                                        \
1213 X       if (e != NULL)                                                  \
1214 X               errx(2, "%s value 「%s」 is %s", (name), argv[num], e);       \
1215 X} while (/* CONSTCOND */ 0)
1216 X
1217 Xint
1218 Xmain(int argc, char *argv[])
1219 X{
1220 X       struct tm tm;
1221 X       time_t t;
1222 X
1223 X       if (argc != 8)
1224 X               errx(1, "syntax: %s fmtstr y m d h m s\n", __progname);
1225 X
1226 X       memset(&tm, '\0', sizeof (struct tm));
1227 X
1228 X       CONVERT(2, tm_year, "year", LONG_MIN, LONG_MAX - 1900);
1229 X       CONVERT(3, tm_mon, "month", 1, 12);
1230 X       CONVERT(4, tm_mday, "day", 1, 31);
1231 X       CONVERT(5, tm_hour, "hour", 0, 23);
1232 X       CONVERT(6, tm_min, "minute", 0, 59);
1233 X       CONVERT(7, tm_sec, "second", 0, 60);
1234 X
1235 X       tm.tm_year -= 1900;
1236 X       --tm.tm_mon;
1237 X
1238 X       if ((t = mktime(&tm)) == (time_t)-1)
1239 X               errx(2, "invalid calendar time %04lld-%02d-%02d %02d:%02d:%02d",
1240 X                   (long long)tm.tm_year + 1900LL, tm.tm_mon + 1, tm.tm_mday,
1241 X                   tm.tm_hour, tm.tm_min, tm.tm_sec);
1242 X
1243 X       localtime_r(&t, &tm);
1244 X
1245 X       if (!strftime(buf, sizeof (buf), argv[1], &tm))
1246 X               errx(3, "format string 「%s」 too large", argv[1]);
1247 X
1248 X       puts(buf);
1249 X       return (0);
1250 X}
1251 END-of-mk/strftm.c
1252 echo x - mk/ttf2png
1253 sed 's/^X//' >mk/ttf2png << 'END-of-mk/ttf2png'
1254 X<?php
1255 X// $MirOS: www/mk/ttf2png,v 1.6 2009/09/25 19:10:45 tg Exp $
1256 X
1257 X/*-
1258 X * Copyright (c) 2009
1259 X *     Thorsten Glaser <tg@mirbsd.org>
1260 X *
1261 X * Provided that these terms and disclaimer and all copyright notices
1262 X * are retained or reproduced in an accompanying document, permission
1263 X * is granted to deal in this work without restriction, including un-
1264 X * limited rights to use, publicly perform, distribute, sell, modify,
1265 X * merge, give away, or sublicence.
1266 X *
1267 X * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
1268 X * the utmost extent permitted by applicable law, neither express nor
1269 X * implied; without malicious intent or gross negligence. In no event
1270 X * may a licensor, author or contributor be held liable for indirect,
1271 X * direct, other damage, loss, or other issues arising in any way out
1272 X * of dealing in the work, even if advised of the possibility of such
1273 X * damage or existence of a defect, except proven that it results out
1274 X * of said person's immediate fault when using the work as intended.
1275 X *-
1276 X * Syntax:
1277 X *     php ttf2png [text [size [/path/to/font.ttf]]] >out.png
1278 X */
1279 X
1280 X
1281 X/* if 0
1282 Xif (!function_exists('gd_info'))
1283 X       die("Install php5-gd first.");
1284 X$gd = gd_info();
1285 Xif ($gd["FreeType Support"] == false)
1286 X       die("Compile php5-gd with FreeType 2 support.");
1287 X * endif */
1288 X
1289 X
1290 X$font = "/usr/src/www/files/FNT/GenI102.ttf";
1291 X$fontsize = 30;
1292 X$text = "EINVAL";
1293 X
1294 Xif (isset($argv[1]))
1295 X       $text = $argv[1];
1296 Xif (isset($argv[2]))
1297 X       $fontsize = $argv[2];
1298 Xif (isset($argv[3]))
1299 X       $font = $argv[3];
1300 X
1301 X
1302 X// Get bounding box
1303 X$bbox = imageftbbox($fontsize, 0, $font, $text);
1304 X// Transform coordinates into width+height and position
1305 X$size_w = abs($bbox[2] - $bbox[0]);    // right - left
1306 X$size_h = abs($bbox[7] - $bbox[1]);    // top - bottom
1307 X$x = -$bbox[0];                                // left (offset)
1308 X$y = $size_h - abs($bbox[1]);          // lower
1309 X
1310 X// Create image
1311 X$im = imagecreatetruecolor($size_w, $size_h);
1312 X// Allocate colours
1313 X$bgcol = imagecolorallocate($im, 0x24, 0x24, 0x24);
1314 X$fgcol = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
1315 X
1316 X// Fill image with background colour
1317 Ximagefilledrectangle($im, 0, 0, $size_w - 1, $size_h - 1, $bgcol);
1318 X// Render text into image
1319 Ximagefttext($im, $fontsize, 0, $x, $y, $fgcol, $font, $text);
1320 X
1321 X// Convert true colour image (needed for above) to palette image
1322 Ximagetruecolortopalette($im, FALSE, 256);
1323 X
1324 X// Output created image
1325 Ximagepng($im, NULL, 9);
1326 Xexit;
1327 X?>
1328 END-of-mk/ttf2png
1329 exit