summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/eijkhout/DB_process.tex
blob: f43078e950eb43895ba320f7a2eeef382a8b371e (plain)
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DataBase processing macros, version 0.91, December 2000
% Copyright Victor Eijkhout 2000
% file name: DB_process.tex
%
% Author:
% Victor Eijkhout
% Department of Computer Science
% University of Tennessee, Knoxville TN 37996
%
% victor@eijkhout.net
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% For a copy of the GNU General Public License, write to the 
% Free Software Foundation, Inc.,
% 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA,
% or find it on the net, for instance at
% http://www.gnu.org/copyleft/gpl.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Use this file as follows:
%
% \input DB_process
% \def\DBPprintline#1#2#3#4#5#6#7#8#9%
%     { < do whatever you want with the argument > }
% \DBPtabfile{ <input file> }  or  \DBPcommafile{ <input file> }
%
% The user macro \DBPprintline is applied to the max 9 arguments
% of each database line. You need to define the macro with 9 arguments;
% if the database has less than 9 fields, empty arguments are passed.
%
% The input records are counted, and the counter is available as \DBPno.
% To print this, you have to do \number\DBPno or somesuch.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% revision history:
% 0.9 first release, December 1998
% 0.91 documentation update, use repeat.tex for loop macro,
%      copyright notice, better handling of 'fragile' material
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%
%% prevent multiple loading of this file
%%
\expandafter\ifx\csname DBPfile\endcsname\relax
  \message{Loading DataBase Processing macros ... }%
\else
  \message{DataBase Processing macros already loaded ... }\endinput \fi

%%
%% Allocations
%%
\newread\DBPfile \newcount\DBPitem \newtoks\DBPtoks
\def\csarg#1#2{\expandafter#1\csname#2\endcsname}
\def\cscsarg#1#2{\csname#1\expandafter\endcsname\csname#2\endcsname}
\cscsarg{newtoks}{DBPtoks1}
\cscsarg{newtoks}{DBPtoks2}
\cscsarg{newtoks}{DBPtoks3}
\cscsarg{newtoks}{DBPtoks4}
\cscsarg{newtoks}{DBPtoks5}
\cscsarg{newtoks}{DBPtoks6}
\cscsarg{newtoks}{DBPtoks7}
\cscsarg{newtoks}{DBPtoks8}
\cscsarg{newtoks}{DBPtoks9}

%%
%% Load auxiliary files: loop macro
%%
\input repeat.tex

%%
%% a default printline macro
%%
\def\DBPprintline#1#2#3#4#5#6#7#8#9{\number\DBPno: #1\par}

%%
%% general parsing macros
%%
\def\DBPparsefile{\def\DBPtestc{\par}%
    \repeat \for{DBPno} \do {\read\DBPfile to \DBPinput
      \ifx\DBPinput\DBPtestc \expandafter\breakrepeat \fi
      \DBPitem=1\relax \DBPtoks=\expandafter{\DBPinput}%
      \edef\DBPtemp{\noexpand\DBPparseline\the\DBPtoks
                    \DBPdelim DBP\DBPdelim}\DBPtemp
    }}
\def\DBPline#1#2{%
    \def\DBPtesta{#1}\def\DBPtestb{DBP}%
    \ifx\DBPtesta\DBPtestb
        \edef\DBPtemp{\noexpand\DBPprintline
            {\csarg\the{DBPtoks1}}%
            {\csarg\the{DBPtoks2}}%
            {\csarg\the{DBPtoks3}}%
            {\csarg\the{DBPtoks4}}%
            {\csarg\the{DBPtoks5}}%
            {\csarg\the{DBPtoks6}}%
            {\csarg\the{DBPtoks7}}%
            {\csarg\the{DBPtoks8}}%
            {\csarg\the{DBPtoks9}}%
            }\DBPtemp
        \csarg\relax{DBPtoks1}{}%
        \csarg\relax{DBPtoks2}{}%
        \csarg\relax{DBPtoks3}{}%
        \csarg\relax{DBPtoks4}{}%
        \csarg\relax{DBPtoks5}{}%
        \csarg\relax{DBPtoks6}{}%
        \csarg\relax{DBPtoks7}{}%
        \csarg\relax{DBPtoks8}{}%
        \csarg\relax{DBPtoks9}{}%
    \else \ifnum\DBPitem<10\relax
            \csname DBPtoks\number\DBPitem\endcsname={#1}%
            \else \message{DB Processor: can not handle >9 items/line}%
            \fi
          \advance\DBPitem by 1
          \expandafter#2\fi}

%%
%% macros for comma-delimited
%%
\def\DBPcommafile#1{%
    \openin\DBPfile=#1\relax
    \let\DBPparseline=\DBPcommaline
    \def\DBPdelim{,}%
    \DBPparsefile}
\def\DBPcommaline#1,{\DBPline{#1}\DBPcommaline}

%%
%% macros for tab-delimited
%%
\begingroup \catcode9=12
\gdef\DBPtabfile#1{%
    \openin\DBPfile=#1\relax
    \begingroup
      \catcode9=12 \let\DBPparseline=\DBPtabline
      \def\DBPdelim{^^I}%
      \DBPparsefile
    \endgroup}
\gdef\DBPtabline#1^^I{\DBPline{#1}\DBPtabline}
\endgroup

\endinput