#!/bin/bash

version=2.01
myname=$(basename $0)

<<'DOC'
= lug - create and edit TeX Local User Group web pages

= Synopsis
lug [options] [lug-code]	

lug can be used to maintain the TeX Local User Group web pages, currently
located at www.ntg.nl/lug.
Without options, reads key=value pairs, possibly embedded in the body of a
mail as sent by a web form like U{www.ntg.nl/lug/nl.html}{here}.
You can feed the complete email (after saving it) to lug, or you can paste
its content to standard input.

For testing, you may want to make a copy and run it from there:

   $ cp -a /var/www/html/lug /var/www/html/lugtest
   $ cd /var/www/html/lugtest
   $ ./lug --help
   $ (more lug calls)

Finally look at the results in http://www.ntg.nl/lugtest

Options:
-h,--help	Print this help and exit
-H,--Help	Print full documentation via less and exit
-V,--version	Print version and exit
-f,--full	Re-create all files
-e,--extras=STR	Re-create STR, where STR can be:
		labels.pdf
		lugs.pdf
		lugs.html
		index.html
		links.inc
		pagehead.inc
		pagetail1.inc
		pagetail2.inc
-s,--sync[=STR]	Synchronize the lug page at |www.ntg.nl/STR| with the current directory
		The default for |STR| is |lug| 
-c,--clean	Remove all files that can be re-created

= Description
lug can be used to to (re-)create the web pages of the LUG database.
This script must be executed in its own directory. After the script has
been executed, this directory will contain the web site for the Electronic
LUG Database, currently: U{www.ntg.nl/lug}{www.ntg.nl/lug}.

Before execution, the directory must contain at least"
- the script (as said)
- a subdirectory containing one text file for each LUG

When people send new data by using the forms of the site, they do so by 
submitting the form, which causes an email with raw data to be sent to
the administrator(s). 

An administrator should verify the password reported in the email and then
cd to this directory, or to a copy of it on his own computer, and he should
then run:

	$ ./lug

lug waits for data, which it can be given by cut (from the email) and paste
(to standard input). By ending the input with |^D|, lug corrects the data in
the directory `lugs'

It is of course also possible to save the contents of the email into a file 
and then run:

	$ ./lug <file

The administrator can make small correction to one country by giving the
necessary input on the command line. For example, to change the email address
of the treasurer of The Netherlands he can run:

	$ ./lug
	code=nl
	femail=wybodekker@xs4all.nl
	^D

Synchronize the website (|www.ntg.nl/lug|) with the current directory:

	./lug --sync

Or, for testing purposes, synchronize |www.ntg.nl/lugtest|:

	./lug --sync=lugtest

or, shorter:

	./lug -slugtest

Remove everything that can be regenerated:

	lug --clean

Regenerate everything: 

	lug --full

= Author and copyright
Author	Wybo Dekker
Email	U{wybo@dekkerdocumenten.nl}{wybo@dekkerdocumenten.nl}
License	Released under the U{www.gnu.org/copyleft/gpl.html}{GNU General Public License}
DOC

    die() { echo -e "$myname: $Err$@$Nor" 1>&2; exit 1; }
   Warn() { echo -e "$myname: $War$@$Nor" 1>&2; }
   warn() { $verbose && Warn $@; }
   help() { sed -n '/^= Synopsis/,/^= /p' $0|sed '1s/.*/Usage:/;/^= /d'; exit; }
helpall() { sed -n '/^<<.DOC.$/,/^DOC$/p' $0|sed -n '1d;$d;p'|less; exit; }
version() { echo $version; exit; }
install() { which instscript>&/dev/null && instscript --zip --pdf --markdown $myname; exit; }

Nor='\e[0m'    # reset color	]
Err='\e[31;1m' # light red	]
War='\e[35;1m' # light magenta	]


<<'DOC' #------ function setkeys ----------------------------------------------- 
= setkeys
parameters:	1: country code
description:	Set the |keys| hash to the values taken from the file |lugs/$1|.
globals  set:	 keys
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
setkeys() { # code semicolonreplacement ampersandreplacement
   local k v
   while IFS=$'\t' read -r k v; do 
      [[ $k = '' || $k =~ ^# ]] && continue
      [[ $k =~ addr$ ]] && v=${v//;/$2}
      keys["$k"]="${v//&/$3}"
   done <lugs/$1
}

<<'DOC' #------ function clean -------------------------------------------------
= clean
parameters:	-
description:	Remove files created but not needed for the web site or for 
		lug functioning.
globals  set:	-
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
clean() {
   rm -f utf82html.c Makefile
}

<<'DOC' #------ function Clean -------------------------------------------------
= Clean
parameters:	-
description:	Remove all files that can be re-created.
globals  set:	-
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
Clean() {
   clean
   rm -f *.html labels.* lugs.{html,pdf,tex} \
	links.inc pagehead.inc pagetail1.inc pagetail2.inc utf82html
}

<<'DOC' #------ function makeMakefile ------------------------------------------
= makeMakefile
parameters:	-
description:	Create the file |Makefile|
globals  set:	-
globals used:	 db 
returns:	0
DOC
#-------------------------------------------------------------------------------
makeMakefile() {
   local i
   cat<<EOF |sed 's/\t//' > Makefile
	BASEFILES = $(for i in ${db[@]}; do echo -n lugs/$i' '; done)

	.SUFFIXES: .tex .pdf

	.tex.pdf:
		PDFLATEX='xelatex -recorder -interaction=batchmode' texi2dvi -p -q \$< 2>/tmp/\$\$ || cat /tmp/\$\$
		PDFLATEX='xelatex -interaction=batchmode' texi2dvi -p -q --mostly-clean \$< 2>/tmp/\$\$ || cat /tmp/\$\$
	all:	$(echo -n ${db[@]} |sed 's/ /.html /g').html \
		utf82html index.html lugs.html \
		links.inc pagetail1.inc pagetail2.inc pagehead.inc \
		lugs.pdf labels.pdf
	$(for i in ${db[@]}; do echo "$i.html: lugs/$i utf82html; ./lug $i"; done)
	labels.pdf: \$(BASEFILES)
		./lug --extras=labels.pdf

	lugs.pdf: \$(BASEFILES)
		./lug --extras=lugs.pdf

	lugs.html: \$(BASEFILES)
		./lug --extras=lugs.html

	index.html: \$(BASEFILES)
		./lug --extras=index.html

	links.inc: \$(BASEFILES)
		./lug --extras=links.inc

	pagehead.inc:
		./lug --extras=pagehead.inc

	pagetail1.inc:
		./lug --extras=pagetail1.inc

	pagetail2.inc:
		./lug --extras=pagetail2.inc

	clean:
		rm -rf *.html labels.* lugs.* links.inc pagehead.inc pagetail1.inc pagetail2.inc utf82html Makefile

	utf82html: utf82html.c
		cc -o utf82html utf82html.c

EOF
}

<<'DOC' #------ function makepagehead.inc --------------------------------------
= makepagehead.inc
parameters:	-
description:	Create the file |pagehead.inc|
globals  set:	-
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
makepagehead.inc() {
   cat <<-'EOF' >pagehead.inc
	<?xml version="1.0" encoding="ISO-8859-1"?>
	<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head profile="http://www.w3.org/2005/10/profile">
	<link rel="stylesheet" type="text/css" href="../ntg.css"/>
	<link rel="icon" type="image/png" href="../graphics/favicon.ico"/>
	<meta http-equiv="Content-language" content="nl"/>
	<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
	<meta name="robots" content="index, follow"/>
	<meta name="description" content="Nederlandstalige TeX Gebruikersgroep"/>
	<meta name="keywords" content="TeX LaTeX ConTeXt Metafont MetaPost typesetting NTG gebruikersgroep"/>
	<meta name="DC.Title" content="Nederlandstalige TeX Gebruikersgroep"/>
	<meta name="DC.Creator" content="Erik Frambach"/>
	<meta name="DC.Subject" content="Nederlandstalige TeX Gebruikersgroep"/>
	<meta name="DC.Description" content="Nederlandstalige TeX Gebruikersgroep"/>
	<meta name="DC.Publisher" content="Nederlandstalige TeX Gebruikersgroep"/>
	<meta name="DC.Date" content="2002-05-14"/>
	<meta name="DC.Type" content="Data"/>
	<meta name="DC.Format" content="text/html"/>
	<meta name="DC.Source" content="original"/>
	<meta name="DC.Language" content="nl"/>
	<meta name="DC.Rights" content="All rights reserved by NTG"/>
	<link rev="made" href="mailto:info@ntg.nl"/>
	<style type="text/css"> 
	textarea,input,p#copyright { font-size: x-small; vertical-align:middle }
	td,th { vertical-align:middle }
	table#luginfo { font-size: small }
	tr.mainhead, tr.mainhead * {
	font-family: Verdana, sans-serif;
	color: #fff;
	background-color: #068; }
	</style>
	<title>De Nederlandstalige TeX Gebruikersgroep</title>
	</head>
	<body>
	<div id="everything">
	<div id="header">
	<a href="../index.html" title="NTG homepage"><img
	src="../graphics/ntglogo.png" alt="NTG"/></a>
	<p>Nederlandstalige TeX Gebruikersgroep</p>
	<form method="post" action="/cgi-bin/websearch.pl">
	<p><input type="text" name="terms" size="30" value=""/>
	<input type="submit" value="Zoek"/></p>
	</form>
	</div>
	<div id="notheader">
	<div id="main">
	<h1>TeX user groups around the world</h1>
	EOF
}

<<'DOC' #------ function makepagetail1.inc --------------------------------------
= makepagetail1.inc
parameters:	-
description:	Create the file |pagetail1.inc|
globals  set:	-
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
makepagetail1.inc() {
   cat <<-'EOF' >pagetail1.inc
	</div>
	<ul id="links">
	<li><a href="../zoeken.html" title="zoeken op de NTG-site">zoeken</a></li>
	<li><a href="../voorleden.html" title="alleen voor
	NTG-leden">alleen voor leden</a></li>
	<li><a href="../nieuws.html" title="nieuws">nieuws</a></li>
	<li>over TeX
	<ul>
	 <li><a href="../watistex.html" title="wat is TeX?">wat is TeX</a></li>
	<li><a href="../watislatex.html" title="wat is LaTeX?">wat is
	LaTeX</a></li>
	 <li><a href="../watiscontext.html" title="wat is ConTeXt?">wat is
	ConTeXt</a></li>
	 <li><a href="../watismf.html" title="wat is Metafont?">wat is
	Metafont</a></li>
	 <li><a href="../watismp.html" title="wat is MetaPost?">wat is
	MetaPost</a></li>
	 <li><a href="../software.html" title="TeX-software">software</a></li>
	<li><a href="../faq.html" title="Frequently Asked
	Questions">FAQ's</a></li>
	 <li><a href="../doc/index.html" title="literatuur">literatuur</a></li>
	</ul></li>
	<li>over de NTG
	<ul> <li><a href="../doelstelling.html" title="doelstelling">doelstelling</a></li>
	 <li><a href="../activiteiten.html" title="activiteiten">activiteiten</a></li>
	 <li><a href="../bestuur.html" title="bestuur">bestuur</a></li>
	 <li><a href="../statuten.html" title="statuten">statuten</a></li>
	 <li><a href="../lidmaatschap.html" title="lidmaatschap">lidmaatschap</a></li>
	</ul></li>
	<li>internationaal
	<ul>
	<li><a
	href="../lug/index.html"
	title="local TeX user groups">local user groups</a></li>
	<li><a
	href="../conferenties.html"
	title="conferenties">conferenties</a></li>
	</ul></li>
	<li>publicaties
	<ul>
	 <li><a href="../maps.html" title="NTG tijdschift MAPS">MAPS</a></li>
	 <li><a href="../publicaties.html#internationaal" title="tijdschriften
	 wereldwijd">internationaal</a></li>
	</ul></li>
	<li>evenementen
	<ul>
	 <li><a href="../bijeen/" title="NTG-bijeenkomsten">NTG-bijeenkomsten</a></li>
	<li><a href="http://texcalendar.dante.de/year.php?lug=All&amp;month=1&amp;lang=nl"
	       title="internationale kalender">TeX-kalender</a></li>
	</ul></li>
	<li>contact
	<ul>
	 <li><a href="../lug/nl.html" title="adressen">adressen</a></li>
	 <li><a href="../mail.html" title="mailing lists">mailing lists</a></li>
	</ul></li>
	 <li><a href="../links.html" title="links">links</a></li>
	 <li><a href="../english.html" title="in English">in English</a></li>
	</ul>
	</div>

	<p id="copyright">&copy; NTG 2010; laatst gewijzigd op 
	EOF
}

<<'DOC' #------ function makepagetail2.inc --------------------------------------
= makepagetail2.inc
parameters:	-
description:	Create the file |pagetail2.inc|
globals  set:	-
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
makepagetail2.inc() {
   cat <<-'EOF' >pagetail2.inc
	</p>
	</div>
	</body>
	</html>
	EOF
}

<<'DOC' #------ function makeutf82html.c --------------------------------------
= makeutf82html.c
parameters:	-
description:	Create the file |utf82html.c|;
		it will be compiled /via/ |Makefile|
globals  set:	-
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
makeutf82html.c() {
   cat <<-'EOF' >utf82html.c
	// utf82html.c: convert UTF-8 byte sequences to numeric html entities
	// Written in 2004 by Peter Samuelson <peter@p12n.org>
	// Copyright abandoned by the author

	#include <stdio.h>
	#include <string.h>
	#include <ctype.h>

	void from_utf8 (FILE *in, FILE *out)
	{
		char buf[4096 + 17];
		size_t len = 0;

		while (!feof(in)) {
			size_t usable, i;

			len += fread(buf+len, 1, 4096, in);
			buf[len] = 0;
			if (feof(in) || len < 16)
				usable = len;
			else
				usable = len - 16;

			for (i=0; i<usable; i++) {
				int t;
				unsigned ch, len;

				/* properties of UTF-8 chars */
				static struct { unsigned minval; int len; char b0, b0mask; }
				uprop[] = {
					{ 1<<7,  2, 0xc0, 0xe0 },
					{ 1<<11, 3, 0xe0, 0xf0 },
					{ 1<<16, 4, 0xf0, 0xf8 },
					{ 1<<21, 5, 0xf8, 0xfc },
					{ 1<<26, 6, 0xfc, 0xfe },
					{ 0, }
				};

				if (!(buf[i] & 0x80)) {
					putc(buf[i], out);
					continue;
				}
				for (t = 0; uprop[t].minval; t++)
					if ((buf[i] & uprop[t].b0mask) == uprop[t].b0)
						break;
				if (!uprop[t].minval)
					goto invalid;

				ch = buf[i] & ~uprop[t].b0mask;
				for (len = uprop[t].len - 1; len; len--,i++) {
					if ((buf[i+1] & 0xc0) != 0x80)
						goto invalid;

					ch = (ch << 6) | (buf[i+1] & 0x3f);
				}
				if (ch < uprop[t].minval)
					goto invalid;

				fprintf(out, (ch > 255) ? "&#x%04x;" : "&#x%02x;", ch);
				continue;

			invalid:
				fprintf(stderr, "illegal UTF-8 sequence\n");
				fprintf(out, "&#xfffd;"); /* "REPLACEMENT CHARACTER" */
			}
			if (i < len)
				memcpy(buf, buf+i, len-i);
			len -= i;
		}
	}

	int main (int argc, char *argv[])
	{
		if (argc == 1) {
			from_utf8(stdin, stdout);
			return 0;
		}
		while (argc > 1) {
			FILE *fp = fopen(argv[1], "r");
			if (fp)
				from_utf8(fp, stdout);
			else
				perror("fopen");

			fclose(fp);
			argc--; argv++;
		}
		return 0;
	}
	EOF
}

<<'DOC' #------ function makelinks.inc -----------------------------------------
= makelinks.inc
parameters:	-
description:	Create the file |links.inc|
globals  set:	-
globals used:	-
returns:	0
DOC
#-------------------------------------------------------------------------------
makelinks.inc() {
   local i
   for i in lugs/*; do 
      i=${i#lugs/}
      echo "<a href=\"$i.html\">$i</a>"
   done
   echo '<a href="index.html">home</a>'
} >links.inc

<<'DOC' #------ function makexx.html -------------------------------------------
= makexx.html
parameters:	1: country code
description:	Create the file |lugs/$1|
globals  set:	(/via/ setkeys): |keys|
globals used:	 db keys adminemail
returns:	
DOC
#-------------------------------------------------------------------------------
makexx.html() {
   [[ -n ${db[$1]} ]] || die "Unknown country code $1"
   setkeys $1 "\n" '&amp;'
   local www
   [[ -n ${keys[www]} ]] && www='<a href="http://'${keys[www]}'">(Here is this lug'"'"'s website)</a>'
   cat <<-EOF |./utf82html >$1.html
	<!--#include virtual="pagehead.inc" -->
	<h2>${keys[full]}</h2>
	<ul>
	  <li>Changes won't be instant, but are mailed to the maintainer</li>
	  <li>Use either TeX notation or accented characters for accents.</li>
	  <li>Enter phone numbers starting with +, then the country code et cetera,<br>
	  no whitespace, hyphens or other punctuation.</li>
	</ul>
	<form id="lugform" name="reaction" method="post" action="http://www.ntg.nl/cgi-bin/lugs.pl">
	  <input size="23" type="hidden" value="${keys[code]}" name="code">
	  Links to other User Group correction forms:<p>
	  <!--#include virtual="links.inc" --><p>
	  <table id="luginfo" border="0" cellspacing="3" summary="form">
	    <tr class="mainhead">
	      <th colspan="4" align="center">${keys[code]} - ${keys[country]} $www</th>
	    </tr>
	    <tr>
	      <td align="right">full name</td>
	      <td>
	      <textarea cols="21" rows="2" name="full">
	${keys[full]}
	</textarea></td>
	      <td align="right">periodical</td>
	      <td>
	      <textarea cols="21" rows="2" name="publ">
	${keys[publ]}
	</textarea></td>
	    </tr>
	    <tr>
	      <td align="right">short name</td>
	      <td><input size="23" value="${keys[short]}" name="short"></td>
	      <td align="right">editor</td>
	      <td><input size="23" value="${keys[editor]}" name="editor"></td>
	    </tr>
	    <tr>
	      <td align="right"><a href="http://www.lingoes.net/en/translator/langcode.htm">language(s)</a></td>
	      <td><input size="23" value="${keys[lang]}" name="lang"></td>
	      <td align="right">editor email</td>
	      <td><input size="23" value="${keys[eemail]}" name="eemail"></td>
	    </tr>
	    <tr>
	      <td align="right">members</td>
	      <td><input size="23" value="${keys[members]}" name="members"></td>
	    </tr>
	    <tr>
	      <td align="right">email</td>
	      <td><input size="23" value="${keys[email]}" name="email"></td>
	      <td align="right">bank</td>
	      <td><input size="23" value="${keys[bank]}" name="bank"></td>
	    </tr>
	    <tr>
	      <td align="right">web site</td>
	      <td><input size="23" value="${keys[www]}" name="www"></td>
	      <td align="right">bank account</td>
	      <td><input size="23" value="${keys[bacc]}" name="bacc"></td>
	    </tr>
	    <tr>
	      <td align="right">mailing list</td>
	      <td><input size="23" value="${keys[list]}" name="list"></td>
	      <td align="right">swift code</td>
	      <td><input size="23" value="${keys[bcode]}" name="bcode"></td>
	    </tr>
	    <tr>
	      <td align="right">subscribe at</td>
	      <td><input size="23" value="${keys[subscr]}" name="subscr"></td>
	      <td align="right">routing no/BIC</td>
	      <td><input size="23" value="${keys[brout]}" name="brout"></td>
	    </tr>
	    <tr>
	      <td align="right">address</td>
	      <td>
	      <textarea cols="21" rows="6" name="addr">
	$(echo -e ${keys[addr]})
	</textarea></td>
	      <td align="right">bank address</td>
	      <td>
	      <textarea cols="21" rows="6" name="baddr">
	$(echo -e ${keys[baddr]})
	</textarea></td>
	    </tr>
	    <tr class="mainhead">
	      <th colspan="4" align="center">contact addresses</th>
	    </tr>
	    <tr>
	      <td>&nbsp;</td>
	      <th>policy matters</th>
	      <th>general matters</th>
	      <th>finance / member admin</th>
	    </tr>
	    <tr>
	      <td align="right">position</td>
	      <td><input size="23" value="${keys[ppos]}" name="ppos"></td>
	      <td><input size="23" value="${keys[gpos]}" name="gpos"></td>
	      <td><input size="23" value="${keys[fpos]}" name="fpos"></td>
	    </tr>
	    <tr>
	      <td align="right">name</td>
	      <td><input size="23" value="${keys[pname]}" name="pname"></td>
	      <td><input size="23" value="${keys[gname]}" name="gname"></td>
	      <td><input size="23" value="${keys[fname]}" name="fname"></td>
	    </tr>
	    <tr>
	      <td align="right">address</td>
	      <td>
	      <textarea cols="21" rows="6" name="paddr">
	$(echo -e ${keys[paddr]})
	</textarea></td>
	      <td>
	      <textarea cols="21" rows="6" name="gaddr">
	$(echo -e ${keys[gaddr]})
	</textarea></td>
	      <td>
	      <textarea cols="21" rows="6" name="faddr">
	$(echo -e ${keys[faddr]})
	</textarea></td>
	    </tr>
	    <tr>
	      <td align="right">email</td>
	      <td><input size="23" value="${keys[pemail]}" name="pemail"></td>
	      <td><input size="23" value="${keys[gemail]}" name="gemail"></td>
	      <td><input size="23" value="${keys[femail]}" name="femail"></td>
	    </tr>
	    <tr>
	      <td align="right">phone</td>
	      <td><input size="23" value="${keys[pphone]}" name="pphone"></td>
	      <td><input size="23" value="${keys[gphone]}" name="gphone"></td>
	      <td><input size="23" value="${keys[fphone]}" name="fphone"></td>
	    </tr>
	    <tr>
	      <td align="right">fax</td>
	      <td><input size="23" value="${keys[pfax]}" name="pfax"></td>
	      <td><input size="23" value="${keys[gfax]}" name="gfax"></td>
	      <td><input size="23" value="${keys[ffax]}" name="ffax"></td>
	    </tr>
	    <tr>
	      <td></td>
	      <th align="left"><a href="lugs/${keys[code]}">download data</a></th>
	    </tr>
	    <tr class="mainhead">
	      <th colspan="4" align="center">submission of corrected data; enter your email address and password first!</th>
	    </tr>
	    <tr>
	      <td></td>
	      <td align="right">password</td>
	      <td><input size="23" name="password"></td>
	      <td><font size="1">obtain from wybo@xs4all.nl</font></td>
	    </tr>
	    <tr>
	      <td></td>
	      <td align="right">your email address</td>
	      <td><input size="23" name="submitemail"></td>
	      <td><font size="1">needed in case we have questions</font></td>
	    </tr>
	    <tr>
	      <td></td>
	      <td></td>
	      <td align="left"><input type="submit" value="submit corrected data"></td>
	    </tr>
	  </table><p>
	  Links to other User Group correction forms:<p>
	  <!--#include virtual="links.inc" -->
	</form>
	<!--#include virtual="pagetail1.inc" -->
	<!--#config timefmt="%A %B %d, %Y %X:%Z" -->
	<!--#echo var="LAST_MODIFIED" -->
	by <a href="mailto:$adminemail">$adminemail</a>
	<!--#include virtual="pagetail2.inc" -->
	EOF
}

<<'DOC' #------ function makeindex.html ----------------------------------------
= makeindex.html
parameters:	-
description:	Create the file |index.html|
globals  set:	-
globals used:	 db fullname adminemail
returns:	0
DOC
#-------------------------------------------------------------------------------
makeindex.html() {
   local content=$(for i in ${db[@]}; do echo "<tr><td>$i</td><td><a href=\"$i.html\">${fullname[$i]}</a></td></tr>"; done)
   cat <<-EOF |./utf82html >index.html
	<!--#include virtual="pagehead.inc" -->
	<table border="0" cellspacing="0" cellpadding="10">
	<tr valign="top"><td width="67%">
	This page presents electronic information about TeX User Groups around 
	the world, with an automated mechanism for updating this information and 
	a download facility with which the primary database can be extracted.
	<p>
	The data for each user group is generated in a separate table. To access it,
	simply click on the name of the country.
	<p> 
	A user group representative (the secretary, usually) can send a corrected version of his
	group data by editing the data on-line and then hitting the Send
	button. This will mail the changed data to the maintainer of this page.
	<p><b>New</b> user groups can request an entry by sending an
	email to wybodekker at xs4all.nl
	<ul>
	<li>Please enter ASCII characters (decimal 32-126) only
	<li>use TeX for accents
	<li>Enter phone numbers starting with +, then the country code
	et cetera, no whitespace, hyphens or other punctuation.
	</ul>
	Anybody can obtain user group information by downloading the data from
	the green cell in a table. 
	This will generate a key=value line for  each cell in the table, starting with
	a key for that cell, followed by the contents of the cell.
	<p>
	<table border="1" cellspacing="0" cellpadding="10">
	<tr class="mainhead"><th colspan="3">
	How to obtain information about all lugs at once:
	</th>
	</tr>
	<tr><td>Obtain a LaTeX file presenting all lug information
	for publication in two-column format:
	</td>
	<td><a href="lugs.tex">LaTeX source</a>
	</td>
	<td><table>
	<tr><td><a href="lugs.pdf">PDF</a></td></tr>
	<tr><td><a href="lugs.html">HTML</a></td></tr>
	</table>
	</td>
	</tr>
	<tr><td>Obtain a LaTeX file containing labels with addresses
	of all lugs, where you can send your publication:
	</td>
	<td><a href="labels.tex">LaTeX source</a>
	</td>
	<td><a href="labels.pdf">PDF</a>
	</td>
	</tr>
	</table>
	</td>
	<td><table>
	$content
	</table></td></tr></table>
	<!--#include virtual="pagetail1.inc" -->
	<!--#config timefmt="%A %B %d %Y %X:%Z" -->
	<!--#echo var="LAST_MODIFIED" -->
	by <a href="mailto:$adminemail">$adminemail</a>
	<!--#include virtual="pagetail2.inc" -->
	EOF
}

<<'DOC' #------ function makelugs.html -----------------------------------------
= makelugs.html
parameters:	-
description:	Create the file |lugs.html|
globals  set:	(/via/ setkeys) |keys|
globals used:	 db keys fullname
returns:	0
DOC
#-------------------------------------------------------------------------------
makelugs.html() {
   local linkline=$(for l in ${db[@]}; do echo "<a href=\"#$l\">$l</a>"; done)
   local i l lug www
   {  cat <<-EOF
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	<html>
	<head>
	  <script language="Javascript" type="text/javascript">
	    <!--
	      if (top.location != location) top.location.href = location.href;
	    -->
	  </script>
	  <title>All TeX User Groups</title>
	  <style type="text/css">
	    <!--
	      body {
	        margin-top: 8pt;
	        margin-left: 8pt;
	        color: black; background: white;
	        font-family: sans-serif;
	      }
	      H1, H2, H3, H4 { color: navy; }
	      a:link      { color: navy; }
	      a:visited   { color: green; }
	      a:active    { color: red; }
	      td.label {font-size: 80%; text-align: right}
	      td.addr {font-size: 80%; text-align: right; vertical-align: top}
	      .nounderline A {text-decoration:none; font-weight:bold}
	      th.kop {background-color:#aaa; vertical-align:middle; text-align:left; font-size:150%; line-height:200%; }
	    -->
	  </style>
	</head>
	<body>
	<h1>TeX user groups around the world</h1>
	The TeX Users Group (contact info below) serves as the local user
	group (LUG) of TeX users in North America and any other area or
	language not appearing in the following list. TUG is always
	interested in fostering the formation of local TeX users groups;
	please contact the TUG board (board at tug.org) for assistance,
	such as forwarding information about others who might be
	interested, publicity, arranging joint memberships and so on.
	<p>
	See also:
	<ul>
	<li>The TeX calendar (
	      <a href="http://texcalendar.dante.de/month.php">month view</a>,
	      <a href="http://texcalendar.dante.de/year.php">year view</a>
	    ) for user group activities.
	<li>The <a href="http://www.tug.org/calendar.html">TUG Calendar</a> for general TeX and other typographic activities.
	<li>The list of <a href="http://www.tug.org/pubs.html">user group publications and journals</a>.
	<li>This same information in <a href="lugs.pdf">PDF</a> and in <a href="lugs.tex">LaTeX</a>.
	</ul>
	<p>
	This information comes from the
	<a href="http://www.ntg.nl/lug/index.html">Electronic LUG Database</a>:
	you can correct or add information there.<br>The following links
	bring you straight to the individual user group correction forms:<p>
	<strong>
	EOF
      for i in ${db[@]}; do 
         echo "    <a href=\"http://www.ntg.nl/lug/$i.html\">$i</a>"
      done
      cat <<-EOF
	</strong>
	<p>
	Below, a similar line of links just above
	every LUG header can be used to wander between the LUG info records in this document.<hr>
	<table summary="lugs">
	EOF
      for lug in ${db[@]}; do 
         setkeys $lug '<br>' '&amp;'
         www=${keys[www]}
         [[ -n $www ]] && www="<a href=\"http://$www\">$www</a>"
         cat <<-EOF
		<tr><td colspan="2"><br>$linkline</td></tr>
		<tr bgcolor="#aaa" valign="middle"><th class="kop" colspan="2">&nbsp;<img src="./images/$lug.png"/>&nbsp;<a name="$lug">$lug - ${fullname[$lug]}</a></th></tr>
		<tr><td class="label">short name:     </td><td>${keys[short]}</td></tr>
		<tr><td class="label">full name:      </td><td>${keys[full]}</td></tr>
		<tr><td class="label">language:       </td><td>${keys[lang]}</td></tr>
		<tr><td class="label">members:        </td><td>${keys[members]}</td></tr>
		<tr><td class="label">email:          </td><td>${keys[email]}</td></tr>
		<tr><td class="label">web site:       </td><td>$www</td></tr>
		<tr><td class="label">discussion list:</td><td>${keys[list]}</td></tr>
		<tr><td class="label">subscribe at:   </td><td>${keys[subscr]}</td></tr>
		<tr valign="top"><td class="addr" >address:</td><td>${keys[addr]}</td></tr>
		
		<tr valign="middle"><th align="left" colspan="2"><h3>Periodical</h3></th></tr>
		<tr><td class="label">title:          </td><td>${keys[publ]}</td></tr>
		<tr><td class="label">editor:         </td><td>${keys[editor]}</td></tr>
		<tr><td class="label">editor email:   </td><td>${keys[eemail]}</td></tr>
		
		<tr valign="middle"><th align="left" colspan="2"><h3>Banking</h3></th></tr>
		<tr><td class="label">name:           </td><td>${keys[bank]}</td></tr>
		<tr><td class="label">account:        </td><td>${keys[bacc]}</td></tr>
		<tr><td class="label">(swift) code:   </td><td>${keys[bcode]}</td></tr>
		<tr><td class="label">routing no.:    </td><td>${keys[brout]}</td></tr>
		<tr valign="top"><td class="addr" >address:</td><td>${keys[baddr]}</td></tr>
		
		<tr valign="middle"><th align="left" colspan="2"><h3>${keys[ppos]:-President}</h3></th></tr>
		<tr><td class="label">name:           </td><td>${keys[pname]}</td></tr>
		<tr valign="top"><td class="addr" >address:</td><td>${keys[paddr]}</td></tr>
		<tr><td class="label">email:          </td><td>${keys[pemail]}</td></tr>
		<tr><td class="label">phone:          </td><td>${keys[pphone]}</td></tr>
		<tr><td class="label">fax:            </td><td>${keys[pfax]}</td></tr>
		
		<tr valign="middle"><th align="left" colspan="2"><h3>${keys[gpos]:-Secretary}</h3></th></tr>
		<tr><td class="label">name:           </td><td>${keys[gname]}</td></tr>
		<tr valign="top"><td class="addr" >address:</td><td>${keys[gaddr]}</td></tr>
		<tr><td class="label">email:          </td><td>${keys[gemail]}</td></tr>
		<tr><td class="label">phone:          </td><td>${keys[gphone]}</td></tr>
		<tr><td class="label">fax:            </td><td>${keys[gfax]}</td></tr>
		
		<tr valign="middle"><th align="left" colspan="2"><h3>${keys[fpos]:-Treasurer}</h3></th></tr>
		<tr><td class="label">name:           </td><td>${keys[fname]}</td></tr>
		<tr valign="top"><td class="addr" >address:</td><td>${keys[faddr]}</td></tr>
		<tr><td class="label">email:          </td><td>${keys[femail]}</td></tr>
		<tr><td class="label">phone:          </td><td>${keys[fphone]}</td></tr>
		<tr><td class="label">fax:            </td><td>${keys[ffax]}</td></tr>
	EOF
      done
      echo "</table></body></html>" 
   } |	sed '/^$/d;/<\/td><td><\/td><\/tr>$/d' |
	tac | # reverse and go looking for <h3> headers with no content
	while read -r l; do
	   if [[ $l =~ :\ *\</td\> ]]; then		# content line?
	      keep=true					# yes, keep <h3> header
	   elif [[ $l =~ \</h3\>\</th\>\</tr\> ]]; then	# <h3> header?
	      $keep || continue				# keep it if keep was set true, skip otherwise
	      keep=false				# not a content line, so set keep false
	   else
	      keep=false				# not a content line, so set keep false
	   fi
	   echo "$l"
	done |
	tac |
	utf82html >lugs.html
}

<<'DOC' #------ function makelugs.pdf ------------------------------------------
= makelugs.pdf
parameters:	-
description:	Create the files |lug.tex| and |lugs.pdf|
globals  set:	(/via/ setkeys) |keys|
globals used:	 keys db fullname
returns:	0
DOC
#-------------------------------------------------------------------------------
makelugs.pdf() {
   local l lug
   { cat <<-'EOF'
	%!xelatex
	\documentclass[10pt]{article}
	\usepackage[a4paper,margin=25mm]{geometry}
	\usepackage{textcomp}
	\usepackage{fontspec}
	\usepackage{url}
	\setcounter{secnumdepth}{0}
	\renewcommand{\-}{\discretionary{}{}{}}
	\newenvironment{mylist}{%
	  \begin{list}{}{%
	    \itemsep0ex\parsep0pt\leftmargin25mm\labelwidth25mm
	    \renewcommand{\makelabel}[1]{\hfill\emph{##1:}}
	  }}{\end{list}
	}
	\def\head#1#2{\vfill\item[\bfseries\large\upshape #1] {\Large\bfseries\upshape
	#2}\nopagebreak}
	\def\subhead#1{\\{\bfseries\upshape #1:}}
	\begin{document}\fontspec{FreeSans}
	EOF
   for lug in ${db[@]}; do 
      setkeys $lug '\\' '\&'
      cat <<-EOF
	\begin{mylist}
	\head{$lug}{${fullname[$lug]}}
	\item[short name]     ${keys[short]}
	\item[full name]      ${keys[full]}
	\item[language]       ${keys[lang]}
	\item[members]        ${keys[members]}
	\item[email]          ${keys[email]:+$(echo "\\url{${keys[email]}}")}
	\item[web site]       ${keys[www]:+$(echo "\\url{${keys[www]}}")}
	\item[discussion list]${keys[list]}
	\item[subscribe at]   ${keys[subscr]}
	\item[address] ${keys[addr]:+$(echo "\\begin{minipage}[t]{\\hsize}${keys[addr]//;/\\\\}\\strut\\end{minipage}")}

	\subhead{Periodical}
	\item[title]          ${keys[publ]}
	\item[editor]         ${keys[editor]}
	\item[editor email]   ${keys[eemail]:+$(echo "\\url{${keys[eemail]}}")}

	\subhead{Banking}
	\item[name]           ${keys[bank]}
	\item[account]        ${keys[bacc]}
	\item[(swift) code]   ${keys[bcode]}
	\item[routing no.]    ${keys[brout]}
	\item[address] ${keys[baddr]:+$(echo "\\begin{minipage}[t]{\\hsize}${keys[baddr]//;/\\\\}\\strut\\end{minipage}")}

	\subhead{${keys[ppos]:-President}}
	\item[name]           ${keys[pname]}
	\item[address] ${keys[paddr]:+$(echo "\\begin{minipage}[t]{\\hsize}${keys[paddr]//;/\\\\}\\strut\\end{minipage}")}
	\item[email]          ${keys[pemail]:+$(echo "\\url{${keys[pemail]}}")}
	\item[phone]          ${keys[pphone]}
	\item[fax]            ${keys[pfax]}

	\subhead{${keys[gpos]:-Secretary}}
	\item[name]           ${keys[gname]}
	\item[address] ${keys[gaddr]:+$(echo "\\begin{minipage}[t]{\\hsize}${keys[gaddr]//;/\\\\}\\strut\\end{minipage}")}
	\item[email]          ${keys[gemail]:+$(echo "\\url{${keys[gemail]}}")}
	\item[phone]          ${keys[gphone]}
	\item[fax]            ${keys[gfax]}

	\subhead{${keys[fpos]:-Treasurer}}
	\item[name]           ${keys[fname]}
	\item[address] ${keys[faddr]:+$(echo "\\begin{minipage}[t]{\\hsize}${keys[faddr]//;/\\\\}\\strut\\end{minipage}")}
	\item[email]          ${keys[femail]:+$(echo "\\url{${keys[femail]}}")}
	\item[phone]          ${keys[fphone]}
	\item[fax]            ${keys[ffax]}

	\end{mylist}
	EOF
      done
      echo '\end{document}'
   } |
   sed '/^\\item\[.*\] *$/d;/^$/d' |
   tac | # reverse and go looking for \subhead headers with no content
   while read -r l; do
      if [[ $l =~ ^\\item ]]; then	# content line?
         keep=true			# yes, keep <h3> header
      elif [[ $l =~ ^\\subhead ]]; then	# \subhead header?
         $keep || continue		# keep it if keep was set true, skip otherwise
         keep=false			# not a content line, so set keep false
      else
         keep=false			# not a content line, so set keep false
      fi
      echo "$l"
   done |
   tac >lugs.tex
   mk --noprint --noview lugs.tex &&
      mk -c lugs.tex ||
      die "Problems compiling lugs.tex"
}

<<'DOC' #------ function makelabels.pdf ----------------------------------------
= makelabels.pdf
parameters:	-
description:	Create the file |labels.tex| and |labels.pdf|
globals  set:	(/via/ setkeys) |keys|
globals used:	 keys db
returns:	0
DOC
#-------------------------------------------------------------------------------
makelabels.pdf() {
   local a i lug 
   { cat <<-'EOF'
	%!xelatex
	\documentclass{article}
	\usepackage{labels,fontspec}
	\LabelRows=8\LabelCols=3
	\TopBorder=0mm\BottomBorder=0mm
	\LeftBorder=7mm\RightBorder=7mm
	\begin{document}\fontspec{FreeSans}\begin{labels}
	EOF
     for lug in ${db[@]}; do 
        setkeys $lug "\n" '\&'
        a=
        for i in addr gaddr paddr faddr; do 
           if [[ -n ${keys[$i]} ]]; then 
              a=${keys[$i]}
              break
           fi
        done 
        [[ -n $a ]] || continue
        echo -e "${keys[short]:-${keys[full]}}\n$a\n"
     done
     echo '\end{labels}\end{document}' 
   } >labels.tex
   mk --noprint --noview labels.tex &&
      mk -c labels.tex ||
      die "Problems compiling labels.tex"
}

<<'DOC' #----------- fullname -----------------------------
= fullname (hash)
Links the country codes to the full name of countries.
Also used to test the validity of country codes.
DOC
#----------------------------------------------------------
declare -A fullname=(
   [ad]='Andorra'                  [ky]='Cayman Islands'
   [ae]='United Arab Emirates'     [kz]='Kazakhstan'
   [af]='Afghanistan'              [la]='Laos'
   [ag]='Antigua and Barbuda'      [lb]='Lebanon'
   [ai]='Anguilla'                 [li]='Liechtenstein'
   [al]='Albania'                  [lk]='Sri Lanka'
   [am]='Armenia'                  [lr]='Liberia'
   [an]='Netherlands Antilles'     [ls]='Lesotho'
   [ao]='Angola'                   [lt]='Lithuania'
   [ar]='Argentina'                [lu]='Luxembourg'
   [as]='American Samoa'           [lv]='Latvia'
   [at]='Austria'                  [ly]='Libya'
   [au]='Australia'                [ma]='Morocco'
   [aw]='Aruba'                    [mc]='Monaco'
   [az]='Azerbaijan'               [md]='Moldova'
   [ba]='Bosnia and Herzegovina'   [mg]='Madagascar'
   [bb]='Barbados'                 [mh]='Marshall Islands'
   [bd]='Bangladesh'               [mk]='Macedonia'
   [be]='Belgium'                  [ml]='Mali'
   [bf]='Burkina Faso'             [mm]='Myanmar'
   [bg]='Bulgaria'                 [mn]='Mongolia'
   [bh]='Bahrain'                  [mo]='Macau'
   [bi]='Burundi'                  [mp]='Northern Marianas Islands'
   [bj]='Benin'                    [mq]='Martinique'
   [bm]='Bermuda'                  [mr]='Mauritania'
   [bn]='Brunei'                   [ms]='Montserrat'
   [bo]='Bolivia'                  [mt]='Malta'
   [br]='Brazil'                   [mu]='Mauritius'
   [bs]='Bahamas'                  [mv]='Maldives'
   [bt]='Bhutan'                   [mw]='Malawi'
   [bw]='Botswana'                 [mx]='Mexico'
   [by]='Belarus'                  [my]='Malaysia'
   [bz]='Belize'                   [mz]='Mozambique'
   [ca]='Canada'                   [na]='Namibia'
   [cf]='Central African Republic' [nc]='New Caledonia'
   [cg]='Congo'                    [ne]='Niger'
   [ch]='Switzerland'              [nf]='Norfolk Island'
   [ci]='Ivory Coast'              [ng]='Nigeria'
   [ck]='Cook Islands'             [ni]='Nicaragua'
   [cl]='Chile'                    [nl]='Netherlands'
   [cm]='Cameroon'                 [no]='Norway'
   [cn]='China'                    [nr]='Nauru'
   [co]='Colombia'                 [nu]='Niue'
   [cr]='Costa Rica'               [nz]='New Zealand'
   [cu]='Cuba'                     [om]='Oman'
   [cv]='Cape Verde Islands'       [pa]='Panama'
   [cy]='Cyprus'                   [pe]='Peru'
   [cz]='Czech Republic'           [pf]='French Polynesia'
   [de]='Germany'                  [pg]='Papua New Guinea'
   [dj]='Djibouti'                 [ph]='Philippines'
   [dk]='Denmark'                  [pk]='Pakistan'
   [dm]='Dominica'                 [pl]='Poland'
   [do]='Dominican Republic'       [pm]='St Pierre and Miquelon'
   [dz]='Algeria'                  [pr]='Puerto Rico'
   [ec]='Ecuador'                  [pt]='Portugal'
   [ee]='Estonia'                  [pw]='Palau'
   [eg]='Egypt'                    [py]='Paraguay'
   [eh]='Western Samoa'            [qa]='Qatar'
   [er]='Eritrea'                  [re]='Reunion'
   [es]='Spain'                    [ro]='Romania'
   [esc]='Spain (Catalan)'         [ru]='Russia'
   [et]='Ethiopia'                 [rw]='Rwanda'
   [fi]='Finland'                  [sa]='Saudi Arabia'
   [fj]='Fiji Islands'             [sb]='Solomon Islands'
   [fk]='Falkland Islands'         [sc]='Seychelles Islands'
   [fm]='Micronesia'               [sd]='Sudan'
   [fo]='Faroe Islands'            [se]='Sweden'
   [fr]='France'                   [sg]='Singapore'
   [ga]='Gabon'                    [si]='Slovenia'
   [gb]='United Kingdom'           [sk]='Slovak Republic'
   [gd]='Grenada'                  [sl]='Sierra Leone'
   [ge]='Georgia'                  [sm]='San Marino'
   [gf]='French Guiana'            [sn]='Senegal'
   [gh]='Ghana'                    [so]='Somalia'
   [gi]='Gibraltar'                [sr]='Suriname'
   [gl]='Greenland'                [sv]='El Salvador'
   [gm]='Gambia'                   [sy]='Syria'
   [gn]='Guinea'                   [sz]='Swaziland'
   [gp]='Guadeloupe'               [tc]='Turks and Caicos Islands'
   [gq]='Equatorial Guinea'        [td]='Chad'
   [gr]='Greece'                   [tg]='Togo'
   [gt]='Guatemala'                [th]='Thailand'
   [gu]='Guam'                     [tj]='Tajikistan'
   [gw]='Guinea-Bissau'            [tk]='Tokelau'
   [gy]='Guyana'                   [tm]='Turkmenistan'
   [hk]='Hong Kong'                [tn]='Tunisia'
   [hn]='Honduras'                 [to]='Tonga Islands'
   [hr]='Croatia'                  [tp]='East Timor'
   [ht]='Haiti'                    [tr]='Turkey'
   [hu]='Hungary'                  [tt]='Trinidad and Tobago'
   [id]='Indonesia'                [tv]='Tuvalu'
   [ie]='Ireland'                  [tw]='Taiwan'
   [il]='Israel'                   [tz]='Tanzania'
   [in]='India'                    [ua]='Ukraine'
   [iq]='Iraq'                     [ug]='Uganda'
   [ir]='Iran'                     [us]='TeX User Group (International)'
   [is]='Iceland'                  [uy]='Uruguay'
   [it]='Italy'                    [uz]='Uzbekistan'
   [jm]='Jamaica'                  [ve]='Venezuela'
   [jo]='Jordan'                   [vg]='Virgin Islands (GB)'
   [jp]='Japan'                    [vi]='Virgin Islands (US)'
   [ke]='Kenya'                    [vn]='Vietnam'
   [kg]='Kyrgyzstan'               [vu]='Vanuatu'
   [kh]='Cambodia'                 [wf]='Wallis and Futuna Islands'
   [ki]='Kiribati'                 [ye]='Yemen'
   [km]='Comoros'                  [yt]='Mayotte Island'
   [kn]='St Kitts and Nevis'       [yu]='Yugoslavia'
   [kp]='Korea (North)'            [za]='South Africa'
   [kr]='Korea (South)'            [zm]='Zambia'
   [kw]='Kuwait'                   [zw]='Zimbabwe'
)

<<'DOC' #----------- keys, inp ----------------------------
= keys, inp (hashes)
Depending on which lug is handled, |keys| will contain the
key and values defined in the files in |lugs/|. 
In an edit operation, |inp| will be filled with similar
keys and values that will replace those in keys.
DOC
#----------------------------------------------------------
declare -A keys inp

<<'DOC' #------------- db ---------------------------------
= db (string)
Contains the space-separated country codes for which data
are available in the |lugs/| directory.
DOC
#----------------------------------------------------------
db=$(test -d lugs && cd lugs && ls | tr "\n" " ")

<<'DOC' #------------- admin ------------------------------
= admin (string)
Contains the user name of the lug administrator at www.ntg.nl
DOC
#----------------------------------------------------------
admin=wybo

<<'DOC' #------------- adminemail -------------------------
= adminemail (string)
Contains the email address that should receive corrections
from the web site.
DOC
#----------------------------------------------------------
adminemail=wybo@dekkerdocumenten.nl

# =============== Program starts here =============
source=$(readlink $0 || echo ./lug)
cd ${source%/lug}
test -d lugs -a -e lug || 
  die "The lug script is part of a directory containing all LUG data;\n" \
      "    You must run (an exact copy of) it in that directory,\n" \
      "    or you must make a link to the lug script in your PATH"
diff ./lug $0 >/dev/null || die "You are running a copy of the lug script that differs from its source"

if ! options=$(getopt \
   -n $myname \
   -o hHVIcfe:s:: \
   -l help,Help,version,clean,full,extras:,sync:: \
   -- "$@"
); then exit 1; fi
eval set -- "$options"
while [ $# -gt 0 ]; do
   case $1 in
   (-h|--help)    help;;
   (-H|--Help)    helpall;;
   (-V|--version) version;;
   (-I)           install;;
   (-c|--clean)	  Clean
		  exit;;
   (-f|--full)    Clean
		  makeutf82html.c
		  makeMakefile
		  make --quiet
		  clean
		  exit;;
   (-e|--extras)  eval "make$2"
		  exit;;
   (-s|--sync)    i=${2:-lug}
		  n=$(ls -R|wc -l)
		  test $n -lt 70 && die "Only $n files here, can't sync"
		  echo syncing with www.ntg.nl/$i
		  rsync -ia --delete --exclude='.hg*' ./ $admin@www.ntg.nl:html/$i/
		  exit;;
   (--)           shift;  break;;
   (*)			  break;;
   esac
done

if [ -n "$1" ]; then 
   for i in "$@"; do
      makexx.html $i
   done
   exit 
fi

in=false
echo waiting for input...
while IFS='' read line; do
   [[ -z $line ]] && continue 		# skip empty lines
   if [[ $line =~ ^code= ]]; then	# we get here only with manual input 
      in=true				# of a few lines; those must start with code=
      inp[code]=${line#*=}
   fi
   [[ $line == 'password=kjwb' ]] && { in=true; continue; }
   $in || continue 			# look only after "password=kjwb"
   [[ $line =~ =$ ]] && continue
   if [[ $line =~ = ]]; then
      IFS='=' read k v <<<$line
      inp[$k]="$v"
   else 
      inp[$k]+=";$line"
   fi
done
code=${inp[code]}
[[ -n $code ]] || die "No code was specified"
[[ $(echo ${db[@]}) =~ $code ]] || die "Unrecognized code: $code"

setkeys $code ';' '&' # make copy of old data in keys
for i in ${!inp[@]}; do keys[$i]=${inp[$i]}; done # overwrite with new data

cat <<-EOF >new
	# General:
	code	${keys[code]}
	short	${keys[short]}
	full	${keys[full]}
	lang	${keys[lang]}
	members	${keys[members]}
	email	${keys[email]}
	www	${keys[www]}
	list	${keys[list]}
	subscr	${keys[subscr]}
	addr	${keys[addr]}

	# Periodical:
	publ	${keys[publ]}
	editor	${keys[editor]}
	eemail	${keys[eemail]}

	# Banking:
	bank	${keys[bank]}
	bacc	${keys[bacc]}
	bcode	${keys[bcode]}
	brout	${keys[brout]}
	baddr	${keys[baddr]}

	# Policy matters:
	ppos	${keys[ppos]}
	pname	${keys[pname]}
	paddr	${keys[paddr]}
	pemail	${keys[pemail]}
	pphone	${keys[pphone]}
	pfax	${keys[pfax]}

	# General matters:
	gpos	${keys[gpos]}
	gname	${keys[gname]}
	gaddr	${keys[gaddr]}
	gemail	${keys[gemail]}
	gphone	${keys[gphone]}
	gfax	${keys[gfax]}

	# Finance matters:
	fpos	${keys[fpos]}
	fname	${keys[fname]}
	faddr	${keys[faddr]}
	femail	${keys[femail]}
	fphone	${keys[fphone]}
	ffax	${keys[ffax]}
	EOF
diff -y --left-column --report-identical-files lugs/$code new && die "No changes"
while true; do
   echo -n "Save [Yn]? "
   read r 
   case $r in 
   ([yY]|'')	mv -f new lugs/$code && Warn Saved || die "Could not save"
		exit
		;;
   (n|N) 	die "Not saved, result left in file new"
		;;
   esac 
done
