summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/prop-ini.tex
blob: 084842fdd37fe951016ae4bf022a3ac335f4743e (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
%D \module
%D   [       file=prop-ini,
%D        version=2003.04.20,
%D          title=\CONTEXT\ Property 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.

\writestatus{loading}{Context Property Macros / initialization}

%D Welcome to the third alternative of this yet undocumented module,
%D which means that there is no public interface yet!

\unprotect

\newcount\propertylevel

\def\currentpropertylevel {\csname\??py:l:\currentpropertytype\endcsname} % counter
\def\previouspropertylevel{\csname\??py:p:\currentpropertytype\endcsname} % counter

\def\currentproperty      {\csname\??py:c:\number\currentpropertylevel \endcsname} % string
\def\previousproperty     {\csname\??py:c:\number\previouspropertylevel\endcsname} % string

% more efficient:

\def\currentproperty      {\csname\??py:c:\number\propertylevel\endcsname} % string
\def\currentpropertytype {\csname\??py\currentproperty\c!type\endcsname}

\def\docheckproperty % watch the s instead of e
  {\csname\s!check\currentpropertytype property\endcsname
   \global\expandafter\let\csname\??py\s!check\currentproperty\endcsname\empty}

\def\checkproperty[#1]%
  {\bgroup
   \def\currentproperty{#1}%
   \csname\??py\s!check\currentproperty\endcsname
   \egroup}

\unexpanded\def\property[#1]%
  {\groupedcommand{\dostartproperty{#1}}\dostopproperty}

\unexpanded\def\startproperty[#1]%
  {\dostartproperty{#1}}

\unexpanded\def\stopproperty
  {\dostopproperty}

\def\dostartgproperty
  {\begingroup\dostartproperty}

\def\dostopgproperty
  {\dostopproperty\endgroup}

\def\dostartproperty#1% evt pack: {current}{level}{
  {\global\advance\propertylevel\plusone
   \@EAEAEA\xdef\currentproperty{#1}%
   \global\advance\previouspropertylevel\plusone
   \global\advance\currentpropertylevel\plusone
   \csname\??py\s!check\currentproperty\endcsname
   \csname\s!start\currentpropertytype\s!property\endcsname}

\def\dostopproperty
  {\csname\s!stop\currentpropertytype\s!property\endcsname
   \global\advance\currentpropertylevel\minusone
   \global\advance\previouspropertylevel\minusone
   \global\advance\propertylevel\minusone}

\def\defineproperty
  {\dotripleempty\dodefineproperty}

\def\defineproperty
  {\dotripleempty\dodefineproperty}

\def\dodefineproperty[#1]%
  {\ifundefined{\??py#1\c!global}%
     \expandafter\dododefineproperty
   \else
     \expandafter\nododefineproperty
   \fi[#1]}

% due to initializations/counters, definitions are always global
%
% global : yes     : ungrouped
%          no      : grouped
% method : command : define commands
%          none    : no commands

\def\dododefineproperty[#1][#2][#3]% global ! ! !
  {\getgparameters[\??py#1][\c!global=\v!no,\c!type=#2,\c!method=\v!none,#3]% global ! ! ! !
   \expandafter\newcount\csname\??py:l:#2\endcsname % current level
   \expandafter\newcount\csname\??py:p:#2\endcsname % previous level
   \global\csname\??py:p:#2\endcsname\minusone
   \global\expandafter\expandafter\let\csname\??py:c:0\endcsname\empty
   \letgvalue{\??py\s!check#1}\docheckproperty
   \doifelsevalue{\??py#1\c!method}\v!command
     {\doifelsevalue{\??py#1\c!global}\v!yes
        {\setgvalue{\e!start#1}{\dostartproperty{#1}}%
         \letgvalue{\e!stop #1}\dostopproperty}%
        {\setgvalue{\e!start#1}{\dostartgproperty{#1}}%
         \letgvalue{\e!stop #1}\dostopgproperty}}%
     {\doifelsevalue{\??py#1\c!global}\v!yes
        {\setgvalue{\e!start#2}[##1]{\dostartproperty{##1}}%
         \letgvalue{\e!stop #2}\dostopproperty}%
        {\setgvalue{\e!start#2}[##1]{\dostartgproperty{##1}}%
         \letgvalue{\e!stop #2}\dostopgproperty}}}

\def\nododefineproperty[#1][#2][#3]%
  {}

\def\doifelseproperty#1{\doifdefinedelse{\??py#1\c!global}}

\def\setupproperty
  {\dodoubleempty\dosetupproperty}

\def\dosetupproperty[#1][#2]% local
  {\ifsecondargument
     \getparameters[\??py#1][#2]%
   \else
     \getparameters[\??py][#1]%
   \fi}

\letvalue{\??py\s!empty}\empty

% beware, normally \*parameter concerns the current one

\def\propertyparameter#1#2% expands to #1 when not defined (see \define...)
  {\csname\??py
     \ifcsname\??py#1#2\endcsname
       #1#2%
     \else\ifcsname\??py\csname\??py#1\c!type\endcsname#2\endcsname
       \csname\??py#1\c!type\endcsname#2%
     \else
       \s!empty
     \fi\fi
   \endcsname}

\def\currentpropertyparameter % self and class
  {\propertyparameter\currentproperty}

\def\checkedpropertyparameter#1% only self
  {\executeifdefined{\??py\currentproperty#1}}

\def\definepropertyhandler#1{\setvalue{\??py*#1}}
\def\propertyhandler      #1{\getvalue{\??py*#1}}

\protect \endinput