summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/regi-ini.mkii
blob: 538db3bcf96dc33d5976ee0a3db2cf06d81f2485 (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
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
%D \module
%D   [       file=regi-ini,
%D        version=2000.12.27, % 1998.12.03,
%D          title=\CONTEXT\ Regime Macros,
%D       subtitle=Initialization,
%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.

\unprotect

%D Plugs into the common interface.

\beginOLDTEX

    \def\mkloadregime#1%
      {\makeshortfilename[\truefilename{\f!regimeprefix#1}]%
       \startreadingfile
         \readsysfile\shortfilename
           {\showmessage\m!regimes2{#1}}
           {\showmessage\m!regimes3{#1}}%
       \stopreadingfile}

    \def\mkenableregime#1%
      {\the\executeifdefined{\@reg@#1}\emptytoks}

    \def\mkwalkregime#1%
      {\the\executeifdefined{\@reg@\currentregime}\emptytoks}

    \def\mkautosetregime#1#2%
      {\ifnum#2>127
         \expanded{\defineactivetoken #2 \@EA\noexpand\csname#1\endcsname}%
       \fi}

\endOLDTEX

\beginXETEX

    \let\mkloadregime   \gobbleoneargument
    \let\mkenableregime \gobbleoneargument
    \let\mkwalkregime   \gobbleoneargument
    \let\mkautosetregime\gobbletwoarguments

    % \def\mkenableregime#1%
    %   {\XeTeXinputencoding "#1"\relax}

    \def\mkenableregime#1%
      {\doifelse{#1}{utf}%
          {\writestatus\m!regimes{mapping utf to utf-8}%
           \XeTeXinputencoding{utf-8}}
          {\XeTeXinputencoding{#1}}}

\endXETEX

%D Remark: regimes accumulate, so there is no explicit reset in
%D mkii mode.

%D \macros
%D   {startregime}
%D
%D Sometimes it makes sense to activate the characters in the
%D upper half of the character table. Such a bundle of
%D characters can be packages in a regime. Later we will see
%D encodings (that links characters slots to glyphs) and
%D mappings (that take care of hyphenation and case changes).
%D
%D When character~231 is of category code letter, it
%D directly maps to glyph~231 (unless of course some virtual
%D font is used). By making character~231 active, we can map
%D it onto for instance the glyph in slot 233. This mapping
%D can in itself be indirect, in the sense that it is for
%D instance handled by an accent command.
%D
%D Regimes are implemented roughly the same as mappings, but
%D enabled under different circumstances. In the future, the
%D low level implementation may change.

\def\startregime[#1]%
  {\pushmacro\currentregime
   \edef\currentregime{#1}%
   \checkregimetoks}

\def\checkregimetoks
  {\doifundefined{\@reg@\currentregime}
     {\@EA\newtoks\csname\@reg@\currentregime\endcsname}}

\def\stopregime
  {\popmacro\currentregime}

\def\setregimetoks
  {\checkregimetoks
   \@EA\let\@EA\regimetoks\csname\@reg@\currentregime\endcsname}

%D \macros
%D   {defineactivedecimal, defineactivedecimals, defineactivetoken}
%D
%D The following commands are rather ugly ones. It makes a
%D character active and assigns it a value. When expanded,
%D the decimal number of the character is passed as first
%D argument.
%D
%D \starttyping
%D \def\decimalcharacter#1{\message{#1 is now active}}
%D
%D \defineactivedecimal 122 {\decimalcharacter}
%D
%D \defineactivedecimals 128 to 255 as {\decimalcharacter}
%D \stoptyping
%D
%D This command is typically used in coding definitions,
%D like the \UNICODE\ one.

\def\dodefineactivedecimal#1#2% \unexpanded ? pdfdoc encoding
  {\catcode#1\active
   \scratchcounter\uccode\activehackcode
   \uccode\activehackcode#1\relax
   \uppercase{\unexpanded\edef~{\noexpand#2{\number#1}}}%
   \uccode\activehackcode\scratchcounter}

\long\def\defineactivedecimal#1 #2 %
  {\setregimetoks
   \regimetoks\expandafter{\the\regimetoks\dodefineactivedecimal{#1}{#2}}}

\long\def\defineactivedecimals#1 to #2 as #3 %
  {\setregimetoks
   \dostepwiserecurse{#1}{#2}\plusone
     {\regimetoks\@EA\@EA\@EA{\@EA\the\@EA\regimetoks\@EA\dodefineactivedecimal\@EA{\recurselevel}{#3}}}}

\def\doexpandactivedecimal#1%
  {\ifnum#1>\scratchcounter
     \expandafter\gobbletwoarguments
   \else
     \noexpand\dodefineactivedecimal{#1}{\the\scratchtoks}%
     \expandafter\expandafter\expandafter\doexpandactivedecimal\expandafter
   \fi\expandafter{\the\numexpr#1+\plusone\relax}}

\long\def\defineactivedecimals#1 to #2 as #3 %
  {\setregimetoks
   \scratchcounter#2\relax
   \scratchtoks{#3}%
   \expanded{\regimetoks{\the\regimetoks\doexpandactivedecimal{#1}}}%
   \ignorespaces}

\long\def\defineactivetoken #1 #2% no {} after #2, else no kern
  {\setregimetoks
   \regimetoks\expandafter{\the\regimetoks\defineactivecharacter#1 {#2}}}

\long\def\defineactiveinspector #1 #2% watch the missing {}
  {\setregimetoks
   \regimetoks\expandafter{\the\regimetoks\defineactivecharacter#1 {#2}}}

% D This is kind of obsolete (replaced by previous code).
%
% \def\definetoken #1 % #1 = rawtoken or number
%   {\doifnumberelse{\string#1}
%      {\expanded{\dodefinetoken{\rawcharacter{#1}}}}
%      {\expanded{\dodefinetoken{\string#1}}}}
%
% \def\dodefinetoken#1#2%
%   {\defineactivecharacter#1 {\dohandletoken{#1}} %
%    \setvalue{\@reg@:t:\currentregime#1}{#2}}
%
% \def\dohandletoken#1%
%   {\csname\ifcsname \@reg@:t:\currentregime#1\endcsname % regi-def sets the defaults
%      \@reg@:t:\currentregime\else\defaultregime\fi#1\endcsname}

%D Preloading:

\beginOLDTEX

    \useregime[def,uni,utf] % we load the rest runtime

\endOLDTEX

\protect \endinput