1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
%D \module
%D [ file=core-dat, % was core-02a,
%D version=1999.08.10, % 1997.03.31,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Database Support, % 2A
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
% THIS WILL DISAPPEAR, I.E. BE MOVED TO A MODULE
\writestatus{loading}{Context Database Support}
\startmessages dutch library: databases
title: database
1: --
2: lokaal bestand --
3: globaal bestand --
4: onbekend bestand --
\stopmessages
\startmessages english library: databases
title: databases
1: --
2: local file --
3: global file --
4: unknown file --
\stopmessages
\startmessages german library: databases
title: Datenbank
1: --
2: lokale Datei --
3: globale Datei --
4: unbekannte Datei --
\stopmessages
% TOM :
\startmessages czech library: databases
title: databases
1: --
2: local file --
3: global file --
4: unknown file --
\stopmessages
\startmessages italian library: databases
title: database
1: --
2: file locale --
3: file globale --
4: file sconosciuto --
\stopmessages
\startmessages norwegian library: databases
title: databaser
1: --
2: lokal fil --
3: global fil --
4: ukjent fil --
\stopmessages
\startmessages romanian library: databases
title: baze de date
1: --
2: fisier local --
3: fisier global --
4: fisier necunoscut --
\stopmessages
\unprotect
%D This module is a (limited) rewrite of the original \type
%D {core-02a} module, the module that dealt with managing a
%D database of addresses. The principles and methods have not
%D changed; they are only generalized.
%D
%D A database file |<|in most cases such a base is generated
%D from another one|>| is structured as follows:
%D
%D \starttyping
%D \startrecord{tag}
%D \memberofgroup{grouplist}
%D \setrecordentry{name}{...}
%D ....
%D \stoprecord
%D \stoptyping
%D
%D The interface to such a database is defined as follows:
%D
%D \starttyping
%D \definerecord[class][settings]
%D \setuprecord[class][settings]
%D \definerecordentry[class][name]
%D \stoptyping
%D
%D and processed by
%D
%D \starttyping
%D \processrecords[file list][tag and/or group list]
%D \stoptyping
%D
%D The actual processing is done by a macro assigned to \type
%D {command}:
%D
%D \starttyping
%D \setuprecord[class][command=\DoWithRecord]
%D \stoptyping
%D
%D Given that one can ask for a field with
%D
%D \starttyping
%D \getrecordentry{name}
%D \stoptyping
%D
%D such a command can look like:
%D
%D \starttyping
%D \def\DoWithRecord#1%
%D {\startpacked
%D \let\\=\quad
%D name: \getrecordentry{name}~\getrecordentry{family name}\par
%D address: \getrecordentry{postal address}\par
%D \stoppacked}
%D \stoptyping
%D
%D The argument passed is the tag. The database can look like:
%D
%D \starttyping
%D \startrecord{hagenj}
%D \memberofgroup{a,b}
%D \setrecordentry{naam}{Hans}
%D \setrecordentry{family name}{Hagen}
%D \setrecordentry{postal address}{J. Hagen\\Ridderstraat 29\\Hasselt NL}
%D \stoprecord
%D
%D \startrecord{ottenaf}
%D \memberofgroup{a}
%D \setrecordentry{name}{Ton}
%D \setrecordentry{family name}{Otten}
%D \setrecordentry{postal address}{A.F. Otten\\Prinsengracht 17\\Hasselt NL}
%D \stoprecord
%D \stoptyping
%D
%D The definition of this database looks like:
%D
%D \starttyping
%D \definerecord[address][command=\DoWithRecord]
%D
%D \definerecordentry[address][name]
%D \definerecordentry[address][family name]
%D \definerecordentry[address][postal address]
%D \stoptyping
%D
%D The actual processing is now done by (for instance):
%D
%D \starttyping
%D \processrecords[datafile][hagenj]
%D \processrecords[datafile][hagenj,offenaf]
%D \processrecords[datafile][all]
%D \processrecords[datafile][a]
%D \processrecords[datafile][b]
%D \stoptyping
%D
%D Of course one can reassign the command used to handle the
%D records in between.
% \??kt ->
% \??kw ->
\def\??db {@@db}
\def\c!velden{velden}
%\newevery \everyrecord \EveryRecord
\def\definerecord
{\dodoubleempty\dodefinerecord}
\def\dodefinerecord[#1][#2]%
{\getparameters
[\??db#1]
[\c!velden=,
\c!command=\gobbleoneargument,
#2]}
\def\setuprecord
{\dodoubleargument\dosetuprecord}
\def\dosetuprecord[#1][#2]%
{\getparameters[\??db#1][#2]}%
\def\definerecordentry[#1][#2]%
{\edef\recordentries{\getvalue{\??db#1\c!velden}}%
\addtocommalist{#2}\recordentries
\letvalue{\??db#1\c!velden}\recordentries}
%D Watch out: the entries are defined global! While
%D processing a record, no grouping is applied.
\def\getrecordentry #1{\getvalue {\??db:#1}}
\def\resetrecordentry #1{\letgvalueempty{\??db:#1}}
\def\assignrecordentry#1{\setgvalue {\??db:#1}}
\long\def\skiprecord#1\stoprecord
{\egroup}
\newif\ifrecordok
\newtoks\resetrecordlist
\def\processrecords
{\dotripleargument\doprocessrecords}
\def\doprocessrecords[#1][#2][#3]%
{\bgroup
\ifx\\\undefined\let\\\relax\fi
\def\docommando##1%
{\resetrecordentry{##1}%
\appendtoks\resetrecordentry{##1}\to\resetrecordlist}%
\processcommacommand[\getvalue{\??db#1\c!velden}]\docommando
\let\setrecordentry\skiprecord
\the\resetrecordlist
\doifelse{#2}\v!all % 't Is nu eenmaal alles
\recordoktrue
{\doifelsenothing{#2} % of niets
\recordoktrue
\recordokfalse}% % zullen we maar zeggen.
\ifrecordok
\let\askedrecords\v!all
\else
\makerawcommalist[#2]\askedrecords
\fi
\def\checkrecord##1%
{\rawdoifinsetelse{##1}{\askedrecords}{\recordoktrue}{}}%
\def\presetrecord##1%
{\let\setrecordentry\assignrecordentry
\let\memberofgroup\gobbleoneargument
\the\resetrecordlist
\def\stoprecord{\dostoprecord{##1}}}%
\def\memberofgroup##1%
{\doifsomething{##1}
{\rawprocesscommalist[##1]\checkrecord}%
\ifrecordok
\presetrecord{##1}%
\else
\expandafter\skiprecord
\fi}%
\def\startrecord##1%
{\bgroup
\ifrecordok
\presetrecord{##1}%
\else
\checkrecord{##1}%
\ifrecordok
\presetrecord{##1}%
\fi
\fi}%
\def\dostoprecord##1%
{\relax
\egroup
%\the\everyrecord
\getvalue{\??db#1\c!command}{##1}}%
\showmessage\m!databases1\askedrecords
\def\doprocessrecords##1%
{\readjobfile{##1}
{\showmessage\m!databases2{(job)}}
{\readsysfile{##1}
{\showmessage\m!databases3{(sys)}}
{\showmessage\m!databases4{}}}}%
\processcommalist[#3]\doprocessrecords
\egroup}
%D While writing the original implementation, I did some
%D experiments with \type {%} before each entry and changing
%D the category code of the comment char. Because \TEX\ scans
%D the line anyway |<|this is needed because the end of line
%D character can be non standard|>| this is not faster.
%D
%D Although this mechanism could have been combined with the
%D block moving mechaism, the current implementation is
%D prefered out of speed reasons.
\protect \endinput
|