File: t-algorithmic.tex

package info (click to toggle)
context-modules 20120611-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 14,060 kB
  • sloc: xml: 608; makefile: 49; sh: 36
file content (120 lines) | stat: -rw-r--r-- 4,178 bytes parent folder | download
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
%D \module
%D   [       file=t-algorithmic,
%D        version=2009.04.21,
%D          title=\CONTEXT\ User Module,
%D       subtitle=Algorithms,
%D         author=Wolfgang Schuster,
%D           date=\currentdate,
%D      copyright=Wolfgang Schuster,
%D          email=schuster.wolfgang@googlemail.com,
%D        license=Public Domain]

\writestatus{loading}{Context User Module / Algorithms}

\unprotect

\def\????al{@@@@al} % ALgorithmic

\def\startalgorithmic
  {\bgroup
   \dosingleempty\dostartalgorithmic}

\def\dostartalgorithmic[#1]%
  {\iffirstargument
     \setupalgorithmic[#1]%
   \fi
   \def\algorithmiccommands##1%
     {\uppercase{\expandafter\let\csname##1\expandafter\endcsname}\csname algorithmic!##1\endcsname}%
   \processcommacommand[\algorithmic!list!commands]\algorithmiccommands
   \@@@@albefore
   \setupwhitespace[\v!none]%
   \doadaptleftskip\@@@@almargin
   \doif\@@@@alnumbering\v!line
     {\setuplinenumbering
        [\c!start=\@@@@alstart,
         \c!stop=\@@@@alstop,
         \c!step=\@@@@alstep]%
      \startlinenumbering}}

\def\stopalgorithmic
  {\par
   \doif\@@@@alnumbering\v!line\stoplinenumbering
   \@@@@alafter
   \egroup}

\def\setupalgorithmic
  {\dodoubleargument\getparameters[\????al]}

% Commands

\def\algorithmic!list!commands
  {state,if,else,elsif,endif,for,forall,endfor,while,endwhile,repeat,%
   until,loop,endloop,require,ensure,return,true,false,print,comment}

\def\startsubalgorithmic
  {\par\doadaptleftskip\@@@@alwidth}

\def\stopsubalgorithmic
  {\par\doadaptleftskip{-\@@@@alwidth}}

\def\algorithmic!state   {\par}
\def\algorithmic!if    #1{\par\algorithmicif\ #1 \algorithmicthen\startsubalgorithmic}
\def\algorithmic!else    {\stopsubalgorithmic\algorithmicelse\startsubalgorithmic}
\def\algorithmic!elsif #1{\stopsubalgorithmic\algorithmicelsif\ #1 \algorithmicthen\startsubalgorithmic}
\def\algorithmic!endif   {\stopsubalgorithmic\algorithmicendif}
\def\algorithmic!for   #1{\par\algorithmicfor\ #1 \algorithmicdo\startsubalgorithmic}
\def\algorithmic!forall#1{\par\algorithmicforall\ #1 \algorithmicdo\startsubalgorithmic}
\def\algorithmic!endfor  {\stopsubalgorithmic\algorithmicendfor}
\def\algorithmic!while #1{\par\algorithmicwhile\ #1 \algorithmicdo\startsubalgorithmic}
\def\algorithmic!endwhile{\stopsubalgorithmic\algorithmicendwhile}
\def\algorithmic!repeat  {\par\algorithmicrepeat\startsubalgorithmic}
\def\algorithmic!until #1{\stopsubalgorithmic\algorithmicuntil\ #1}
\def\algorithmic!loop    {\par\algorithmicloop\startsubalgorithmic}
\def\algorithmic!endloop {\stopsubalgorithmic\algorithmicendloop}
\def\algorithmic!require {\par\algorithmicrequire\space}
\def\algorithmic!ensure  {\par\algorithmicensure\space}
\def\algorithmic!return  {\par\algorithmicreturn\space}
\def\algorithmic!true    {\algorithmictrue}
\def\algorithmic!false   {\algorithmicfalse}
\def\algorithmic!print   {\par\algorithmicprint\space}
\def\algorithmic!comment {\algorithmiccomment}

% I should make this multilingual

\def\algorithmicrequire  {{\bf Require:}}
\def\algorithmicensure   {{\bf Ensure:}}
\def\algorithmiccomment#1{\{#1\}}
\def\algorithmicend      {{\bf end}}
\def\algorithmicif       {{\bf if}}
\def\algorithmicthen     {{\bf then}}
\def\algorithmicelse     {{\bf else}}
\def\algorithmicelsif    {\algorithmicelse\ \algorithmicif}
\def\algorithmicendif    {\algorithmicend\ \algorithmicif}
\def\algorithmicfor      {{\bf for}}
\def\algorithmicforall   {{\bf for all}}
\def\algorithmicdo       {{\bf do}}
\def\algorithmicendfor   {\algorithmicend\ \algorithmicfor}
\def\algorithmicwhile    {{\bf while}}
\def\algorithmicendwhile {\algorithmicend\ \algorithmicwhile}
\def\algorithmicloop     {{\bf loop}}
\def\algorithmicendloop  {\algorithmicend\ \algorithmicloop}
\def\algorithmicrepeat   {{\bf repeat}}
\def\algorithmicuntil    {{\bf until}}
\def\algorithmicprint    {{\bf print}}
\def\algorithmicreturn   {{\bf return}}
\def\algorithmictrue     {{\bf true}}
\def\algorithmicfalse    {{\bf false}}

% Default values

\setupalgorithmic
  [\c!numbering=\v!no,
   \c!start=1,
   \c!stop=,
   \c!step=1,
   \c!width=1em,
   \c!margin=1em,
   \c!before=\blank,
   \c!after=\blank]

\protect \endinput