~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/mod/sys/doc/chapter-1.xml

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
<!-- = incidental  or special  damages arising  in any way out of the use = -->
14
14
<!-- = of this software.                                                  = -->
15
15
<!-- ====================================================================== -->
16
 
<!-- = copyright (c) 1999-2007 - amaury darsch                            = -->
 
16
<!-- = copyright (c) 1999-2011 - amaury darsch                            = -->
17
17
<!-- ====================================================================== -->
18
18
 
19
19
<chapter module="sys" number="1">
20
20
  <title>Introduction</title>
21
21
  
22
22
  <p>
23
 
  This chapter covers the system services available in the
24
 
  <afnix/> standard system service module. The basic operations that are
25
 
  embedded in the interpreter gives system information. Complex
26
 
  information, like the system time are provided via specific
27
 
  classes.
28
 
  </p>
29
 
 
30
 
  <p>
31
 
  All <afnix/> system service objects are located in the
32
 
  <code>afnix-sys</code> module. This module must be loaded prior 
33
 
  any operation. Multiple calls to the module initialization routine
34
 
  are harmless. The interpreter method <code>module</code> loads a
35
 
  specific module by name. When the module has been loaded, the
36
 
  object are available in the <code>afnix:sys</code> nameset.
37
 
  </p>
38
 
 
39
 
  <example>
40
 
  interp:library "afnix-sys"
41
 
  </example>
 
23
    This chapter covers the system services available in the
 
24
    standard system module.
 
25
  </p>
42
26
 
43
27
  <!-- interpreter information -->
44
28
  <section>
45
29
    <title>Interpreter information</title>
46
30
 
47
31
    <p>
48
 
    The <afnix/> interpreter provides a set reserved names that are
49
 
    related to the system platform. Example <file>0501.als</file>
50
 
    demonstrates the available information.
 
32
      The interpreter provides a set reserved names that are
 
33
      related to the system platform. Example <file>0501.als</file>
 
34
      demonstrates the available information.
51
35
    </p>
52
36
 
53
37
    <example>
54
 
    zsh&gt; axi 0501.als
55
 
    program name           : afnix
56
 
    operating system name  : linux
57
 
    operating system type  : unix
58
 
    afnix official uri     : http://www.afnix.org
 
38
      zsh&gt; axi 0501.als
 
39
      program name           : afnix
 
40
      operating system name  : linux
 
41
      operating system type  : unix
 
42
      afnix official uri     : http://www.afnix.org
59
43
    </example>
60
44
 
61
45
    <!-- interpreter version -->
63
47
      <title>Interpreter version</title>
64
48
 
65
49
      <p>
66
 
      The interpreter version is identified by 3 numbers called 
67
 
      <em>major</em>, <em>minor</em> and <em>patch</em> numbers. A
68
 
      change in the major number represents a major change in the
69
 
      <afnix/>language. The minor number indicates a major change in
70
 
      the interface or libraries. A change in the patch number
71
 
      indicates bug fixes. All values are accessed via the interpreter
72
 
      itself. The <code>major-version</code>,
73
 
      <code>minor-version</code>, <code>patch-version</code>
74
 
      symbols are bound to these values.
 
50
        The interpreter version is identified by 3 numbers called 
 
51
        <em>major</em>, <em>minor</em> and <em>patch</em> numbers. A
 
52
        change in the major number represents a major change in the
 
53
        writing system. The minor number indicates a major change in
 
54
        the interface or libraries. A change in the patch number
 
55
        indicates bug fixes. All values are accessed via the interpreter
 
56
        itself. The <code>major-version</code>,
 
57
        <code>minor-version</code>, <code>patch-version</code>
 
58
        symbols are bound to these values.
75
59
      </p>
76
60
 
77
61
      <example>
78
 
      println "major version number   : " interp:major-version
79
 
      println "minor version number   : " interp:minor-version
80
 
      println "patch version number   : " interp:patch-version
 
62
        println "major version number   : " interp:major-version
 
63
        println "minor version number   : " interp:minor-version
 
64
        println "patch version number   : " interp:patch-version
81
65
      </example>
82
66
    </subsect>
83
67
 
86
70
      <title>Operating system</title>
87
71
 
88
72
      <p>
89
 
      The operating system is uniquely identified by its name. The
90
 
      operating system type (or category) uniquely identifies the
91
 
      operating system flavor.
 
73
        The operating system is uniquely identified by its name. The
 
74
        operating system type (or category) uniquely identifies the
 
75
        operating system flavor.
92
76
      </p>
93
77
 
94
78
      <example>
95
 
      println "operating system name  : " interp:os-name
96
 
      println "operating system type  : " interp:os-type
 
79
        println "operating system name  : " interp:os-name
 
80
        println "operating system type  : " interp:os-type
97
81
      </example>
98
82
    </subsect>
99
83
 
102
86
      <title>Program information</title>
103
87
 
104
88
      <p>
105
 
      Program information are carried by two symbols that identifies
106
 
      the program name and the official <afnix/> url. While the first
107
 
      might be useful, the second one is mostly used by demo
108
 
      programs.
 
89
        Program information are carried by two symbols that identifies
 
90
        the program name and the official uri. While the first
 
91
        might be useful, the second one is mostly used by demo
 
92
        programs.
109
93
      </p>
110
94
 
111
95
      <example>
112
 
      println "program name           : " interp:program-name
113
 
      println "afnix official url     : " interp:afnix-url
 
96
        println "program name           : " interp:program-name
 
97
        println "afnix official uri     : " interp:afnix-uri
114
98
      </example>
115
99
    </subsect>
116
100
  </section>
120
104
    <title>System services</title>
121
105
 
122
106
    <p>
123
 
    The <em>system services</em> module provides various functions
124
 
    that cannot be classified into any particular category.
 
107
      The <em>system services</em> module provides various functions
 
108
      that cannot be classified into any particular category.
125
109
    </p>
126
110
 
127
111
    <table>
128
 
     <title>System services functions</title>
129
 
     <tr><th>Function</th><th>Description</th></tr>
130
 
     <tr><td>exit</td>            <td>terminate with an exit code</td></tr>
131
 
     <tr><td>sleep</td>           <td>pause for a certain time</td></tr>
132
 
     <tr><td>get-random</td>      <td>return a random integer number</td></tr>
133
 
     <tr><td>get-random-real</td> <td>return a random real number</td></tr>
134
 
     <tr><td>get-pid</td>         <td>get the process identifier</td></tr>
135
 
     <tr><td>get-env</td>         <td>get an environment variable</td></tr>
136
 
     <tr><td>get-host-name</td>   <td>get the host name</td></tr>
137
 
     <tr><td>get-user-name</td>   <td>get the user name</td></tr>
 
112
      <title>System services functions</title>
 
113
      <tr><th>Function</th><th>Description</th></tr>
 
114
      <tr><td>exit</td>            <td>terminate with an exit code</td></tr>
 
115
      <tr><td>sleep</td>           <td>pause for a certain time</td></tr>
 
116
      <tr><td>get-pid</td>         <td>get the process identifier</td></tr>
 
117
      <tr><td>get-env</td>         <td>get an environment variable</td></tr>
 
118
      <tr><td>get-host-name</td>   <td>get the host name</td></tr>
 
119
      <tr><td>get-user-name</td>   <td>get the user name</td></tr>
138
120
    </table>
139
121
 
140
122
    <p>
141
 
    The <code>exit</code> function terminates the program with an exit
142
 
    code specified as the argument. The <code>sleep</code> function
143
 
    pause the specific thread for a certain time. The time argument is
144
 
    expressed in milliseconds. The <code>get-random</code> function
145
 
    returns a random integer number. The <code>get-random-real</code>
146
 
    returns a random real number. The <code>get-pid</code> function
147
 
    returns the process identifier. The <code>get-env</code> function
148
 
    returns the environment variable associated with the string argument.
149
 
    The <code>get-host-name</code> function returns the host name. The
150
 
    host name can be either a simple name or a canonical name with its
151
 
    domain, depending on the system configuration. The
152
 
    <code>get-user-name</code> function returns the current user
153
 
    name.
 
123
      The <code>exit</code> function terminates the program with an exit
 
124
      code specified as the argument. The <code>sleep</code> function
 
125
      pause the specific thread for a certain time. The time argument is
 
126
      expressed in milliseconds. The <code>get-pid</code> function
 
127
      returns the process identifier. The <code>get-env</code> function
 
128
      returns the environment variable associated with the string argument.
 
129
      The <code>get-host-name</code> function returns the host name. The
 
130
      host name can be either a simple name or a canonical name with its
 
131
      domain, depending on the system configuration. The
 
132
      <code>get-user-name</code> function returns the current user
 
133
      name.
154
134
    </p>
155
135
  </section>
156
136
 
159
139
    <title>Time and date</title>
160
140
 
161
141
    <p>
162
 
    The <code>Time</code> and <code>Date</code> classes are classes
163
 
    designed to manipulate time and date. The <afnix/> system operates
164
 
    with the <afnix/> time coordinated or <em>ATC</em> which uses the
165
 
    reference of Jan 1st 0000 in a modified proleptic gregorian
166
 
    calendar. This proleptic feature means that the actual calendar
167
 
    (gregorian) is extended beyond year 1582 (its introduction year)
168
 
    and modified in order to support the year 0. This kind of calendar
169
 
    is somehow similar to the astronomical gregorian calendar except
170
 
    that the reference date is 0 for the atc system. This method
171
 
    presents the advantage to support negative time. It should be
172
 
    noted that the 0 reference does not means year 1BC since year 0 did
173
 
    not exist at that time (the concept of zero is fairly new) and more
174
 
    important, the date expressed in the form 1BC generally refers to
175
 
    the Julian calendar since the date is before 1582. Although, the class
176
 
    provides several methods to access the time and date fields, it is also
177
 
    possible to get a string representation that conforms to ISO-8601
178
 
    or to RFC-2822.
 
142
      The <code>Time</code> and <code>Date</code> classes are classes
 
143
      designed to manipulate time and date. The writing system operates
 
144
      with a special coordinated time which uses the
 
145
      reference of Jan 1st 0000 in a modified proleptic Gregorian
 
146
      calendar. This proleptic feature means that the actual calendar
 
147
      (Gregorian) is extended beyond year 1582 (its introduction year)
 
148
      and modified in order to support the year 0. This kind of calendar
 
149
      is somehow similar to the astronomical Gregorian calendar except
 
150
      that the reference date is 0 for the writing system. This method
 
151
      presents the advantage to support negative time. It should be
 
152
      noted that the 0 reference does not means year 1BC since year 0 did
 
153
      not exist at that time (the concept of zero is fairly new) and more
 
154
      important, the date expressed in the form 1BC generally refers to
 
155
      the Julian calendar since the date is before 1582. Although, the class
 
156
      provides several methods to access the time and date fields, it is also
 
157
      possible to get a string representation that conforms to ISO-8601
 
158
      or to RFC-2822.
179
159
    </p>
180
160
 
181
161
    <!-- time and date construction -->
183
163
      <title>Time and date construction</title>
184
164
 
185
165
      <p>
186
 
      By default, a time instance of current time is constructed. This
187
 
      time reference is obtained form the machine time and adjusted for
188
 
      the <afnix/> internal representation. One feature of this class
189
 
      is that the time instance does not have to be bounded with 24
190
 
      hours. The time stored is the absolute time, which should be
191
 
      considered like a temporal reference -- or date -- those origin
192
 
      is 0 in some calendar representation.
193
 
      </p>
194
 
 
195
 
      <example>
196
 
      const  time (afnix:sys:Time)
197
 
      assert true (afnxi:sys:time-p time)
198
 
      </example>
199
 
 
200
 
      <p>
201
 
      A simple time representation can also be built by hours, minutes
202
 
      and seconds. In this case, the time is a time definition at day
203
 
      0 in the reference calendar.
204
 
      </p>
205
 
 
206
 
      <example>
207
 
      const  time (afnix:sys:Time 12 23 54)
208
 
      </example>
209
 
 
210
 
      <p>
211
 
      By default a date instance of the current date is constructed. 
212
 
      The current date is computed from the machine time and expressed
213
 
      in a particular calendar. By default, the <afnix/> engine uses a
214
 
      special gregorian calendar as explained before. The important
215
 
      point here s that the date will show up like the user should
216
 
      expect.
217
 
      </p>
218
 
 
219
 
      <example>
220
 
      const  date (afnix:sys:Date)
221
 
      assert true (afnix:sys:date-p date)
222
 
      </example>
223
 
 
224
 
      <p>
225
 
      A date instance can also be built with an absolute time expressed
226
 
      in seconds or with specific elements. with one argument, the
227
 
      date is expressed in seconds since the origin. Since the
228
 
      <afnix/> internal representation is 64 bits, the date room is
229
 
      quite large. For example, the absolute time to represent Jan 1st
230
 
      1970 is 62167219200 seconds. This <em>epoch</em> is used to
231
 
      adjust the system time on some UNIX system. Another way to
232
 
      create a specific date is to use the date descriptor by year,
233
 
      month and day. With 6 arguments, the time components can also be
234
 
      given. This makes <code>Date</code> one of the constructor that
235
 
      accept the largest number of arguments.
236
 
      </p>
237
 
 
238
 
      <example>
239
 
      const  date (afnix:sys:Date 1789 7 14 16 0 0)
240
 
      assert true (afnix:sys:date-p date)
241
 
      </example>
242
 
 
243
 
      <p>
244
 
      In the previous example, at 17:00 local time, 16:00Z although
245
 
      the concept of time zone was not formalized, the Bastille
246
 
      surrenders on July 14 1789. This example shows that extreme care
247
 
      should be used when dealing with old dates. Note that a simpler
248
 
      form could have been used to set that date. With 3 argument, the
249
 
      date is set at time 00:00:00Z.
250
 
      </p>
251
 
 
252
 
      <example>
253
 
      const  date (afnix:sys:Date 1789 7 14)
254
 
      assert true (afnix:sys:date-p date)
 
166
        By default, a time instance of current time is constructed. This
 
167
        time reference is obtained form the machine time and adjusted for
 
168
        the internal representation. One feature of this class
 
169
        is that the time instance does not have to be bounded with 24
 
170
        hours. The time stored is the absolute time, which should be
 
171
        considered like a temporal reference -- or date -- those origin
 
172
        is 0 in some calendar representation.
 
173
      </p>
 
174
 
 
175
      <example>
 
176
        const  time (afnix:sys:Time)
 
177
        assert true (afnxi:sys:time-p time)
 
178
      </example>
 
179
 
 
180
      <p>
 
181
        A simple time representation can also be built by hours, minutes
 
182
        and seconds. In this case, the time is a time definition at day
 
183
        0 in the reference calendar.
 
184
      </p>
 
185
 
 
186
      <example>
 
187
        const  time (afnix:sys:Time 12 23 54)
 
188
      </example>
 
189
 
 
190
      <p>
 
191
        By default a date instance of the current date is constructed. 
 
192
        The current date is computed from the machine time and expressed
 
193
        in a particular calendar. By default, the engine uses a
 
194
        special Gregorian calendar as explained before. The important
 
195
        point here s that the date will show up like the user should
 
196
        expect.
 
197
      </p>
 
198
 
 
199
      <example>
 
200
        const  date (afnix:sys:Date)
 
201
        assert true (afnix:sys:date-p date)
 
202
      </example>
 
203
 
 
204
      <p>
 
205
        A date instance can also be built with an absolute time expressed
 
206
        in seconds or with specific elements. with one argument, the
 
207
        date is expressed in seconds since the origin. Since the
 
208
        internal representation is 64 bits, the date room is
 
209
        quite large. For example, the absolute time to represent Jan 1st
 
210
        1970 is 62167219200 seconds. This <em>epoch</em> is used to
 
211
        adjust the system time on some UNIX system. Another way to
 
212
        create a specific date is to use the date descriptor by year,
 
213
        month and day. With 6 arguments, the time components can also be
 
214
        given. This makes <code>Date</code> one of the constructor that
 
215
        accept the largest number of arguments.
 
216
      </p>
 
217
 
 
218
      <example>
 
219
        const  date (afnix:sys:Date 1789 7 14 16 0 0)
 
220
        assert true (afnix:sys:date-p date)
 
221
      </example>
 
222
 
 
223
      <p>
 
224
        In the previous example, at 17:00 local time, 16:00Z although
 
225
        the concept of time zone was not formalized, the Bastille
 
226
        surrenders on July 14 1789. This example shows that extreme care
 
227
        should be used when dealing with old dates. Note that a simpler
 
228
        form could have been used to set that date. With 3 argument, the
 
229
        date is set at time 00:00:00Z.
 
230
      </p>
 
231
 
 
232
      <example>
 
233
        const  date (afnix:sys:Date 1789 7 14)
 
234
        assert true (afnix:sys:date-p date)
255
235
      </example>      
256
236
    </subsect>
257
237
 
260
240
      <title>Time and date representation</title>
261
241
 
262
242
      <p>
263
 
      Except for some special applications -- like the cookie maximum
264
 
      age --, the date representation is quite standard and can be
265
 
      found either in the form of ISO-8601 or RFC-2822.
266
 
      </p>
267
 
 
268
 
      <example>
269
 
      const time (afnix:sys:Time 12 44 55)
270
 
      println    (time:format) # 12:44:55
271
 
      println    (time:to-iso) # 14:44:55
272
 
      println    (time:to-rfc) # 14:44:55 +0200
273
 
      </example>
274
 
 
275
 
      <p>
276
 
      in the first form, the time is represented naturally by hour,
277
 
      minutes and seconds. By default, it is the local time that is
278
 
      given. With a flag set to true, the UTC time is displayed. In
279
 
      the second form, the time is displayed in the ISO-8601 form
280
 
      which is the same as before. In the third form, the time is
281
 
      displayed in the RFC-2822 form. This form is always expressed
282
 
      locally with the timezone difference associated with it. It
283
 
      shall be noted that the ISO-8601 mandate to sue the suffix 'Z'
284
 
      for the zulu time. This is the difference when using the
285
 
      <code>true</code> flag with the <code>format</code> and
286
 
      <code>to-iso</code> methods.
287
 
      </p>
288
 
 
289
 
      <example>
290
 
      println (time:format true) # 12:44:55
291
 
      println (time:to-iso true) # 12:44:55Z
292
 
      </example>
293
 
 
294
 
      <p>
295
 
      The date representation also operates with 3 methods, namely
296
 
      <code>format</code>, <code>to-iso</code> and
297
 
      <code>to-rfc</code>. For example, if the time is 12:00 in Paris
298
 
      on July 14th 2000, the date will be displayed like below.
299
 
      </p>
300
 
 
301
 
      <example>
302
 
      const date (afnix:sys:Date 2000 7 14 12 0 0)
303
 
      println (date:format) # Fri Jul 14 07:00:00 2000
304
 
      println (date:to-iso) # 2000-07-14T07:00:00
305
 
      println (date:to-rfc) # Fri, 14 Jul 2000 07:00:00 -0500
306
 
      </example>
307
 
 
308
 
      <p>
309
 
      The example show the local time. With UTC display, only the
310
 
      first two methods can be used.
311
 
      </p>
312
 
 
313
 
      <example>
314
 
      const date (afnix:sys:Date 2000 7 14 12 0 0)
315
 
      println (date:format true) # Fri Jul 14 12:00:00 2000
316
 
      println (date:to-iso true) # 2000-07-14T12:00:00Z
 
243
        Except for some special applications -- like the cookie maximum
 
244
        age --, the date representation is quite standard and can be
 
245
        found either in the form of ISO-8601 or RFC-2822.
 
246
      </p>
 
247
 
 
248
      <example>
 
249
        const time (afnix:sys:Time 12 44 55)
 
250
        println    (time:format) # 12:44:55
 
251
        println    (time:to-iso) # 14:44:55
 
252
        println    (time:to-rfc) # 14:44:55 +0200
 
253
      </example>
 
254
 
 
255
      <p>
 
256
        in the first form, the time is represented naturally by hour,
 
257
        minutes and seconds. By default, it is the local time that is
 
258
        given. With a flag set to true, the UTC time is displayed. In
 
259
        the second form, the time is displayed in the ISO-8601 form
 
260
        which is the same as before. In the third form, the time is
 
261
        displayed in the RFC-2822 form. This form is always expressed
 
262
        locally with the timezone difference associated with it. It
 
263
        shall be noted that the ISO-8601 mandate to use the suffix 'Z'
 
264
        for the zulu time. This is the difference when using the
 
265
        <code>true</code> flag with the <code>format</code> and
 
266
        <code>to-iso</code> methods.
 
267
      </p>
 
268
 
 
269
      <example>
 
270
        println (time:format true) # 12:44:55
 
271
        println (time:to-iso true) # 12:44:55Z
 
272
      </example>
 
273
 
 
274
      <p>
 
275
        The date representation also operates with 3 methods, namely
 
276
        <code>format</code>, <code>to-iso</code> and
 
277
        <code>to-rfc</code>. For example, if the time is 12:00 in Paris
 
278
        on July 14th 2000, the date will be displayed like below.
 
279
      </p>
 
280
 
 
281
      <example>
 
282
        const date (afnix:sys:Date 2000 7 14 12 0 0)
 
283
        println (date:format) # Fri Jul 14 07:00:00 2000
 
284
        println (date:to-iso) # 2000-07-14T07:00:00
 
285
        println (date:to-rfc) # Fri, 14 Jul 2000 07:00:00 -0500
 
286
      </example>
 
287
 
 
288
      <p>
 
289
        The example show the local time. With UTC display, only the
 
290
        first two methods can be used.
 
291
      </p>
 
292
 
 
293
      <example>
 
294
        const date (afnix:sys:Date 2000 7 14 12 0 0)
 
295
        println (date:format true) # Fri Jul 14 12:00:00 2000
 
296
        println (date:to-iso true) # 2000-07-14T12:00:00Z
317
297
      </example>
318
298
    </subsect>
319
299
  </section>
323
303
    <title>Options parsing</title>
324
304
 
325
305
    <p>
326
 
    The <code>Options</code> class provides a convenient mechanism to
327
 
    define a set of options and to parse them in a simple way. The
328
 
    object is constructed by specifying which option is valid
329
 
    and how it behaves. The arguments can be passed to the object
330
 
    for subsequent analysis. An option can be either a unique option
331
 
    or a string option. In this later case, multiple value for the
332
 
    same option can be accepted. In that case, the option is said to
333
 
    be a string vector option. An option can be also an option list. I
334
 
    that case, the option is defined with a set of valid string. A
335
 
    list option is associated with a boolean flag for each string defined
336
 
    with that option.
 
306
      The <code>Options</code> class provides a convenient mechanism to
 
307
      define a set of options and to parse them in a simple way. The
 
308
      object is constructed by specifying which option is valid
 
309
      and how it behaves. The arguments can be passed to the object
 
310
      for subsequent analysis. An option can be either a unique option
 
311
      or a string option. In this later case, multiple value for the
 
312
      same option can be accepted. In that case, the option is said to
 
313
      be a string vector option. An option can be also an option list. I
 
314
      that case, the option is defined with a set of valid string. A
 
315
      list option is associated with a boolean flag for each string defined
 
316
      with that option.
337
317
    </p>
338
318
 
339
319
    <!-- option creation -->
341
321
      <title>Option creation</title>
342
322
 
343
323
      <p>
344
 
      An <code>Options</code> is created by invoking the constructor
345
 
      with or without a user message. The user message is used by the
346
 
      <code>usage</code> method which display an information message.
 
324
        An <code>Options</code> is created by invoking the constructor
 
325
        with or without a user message. The user message is used by the
 
326
        <code>usage</code> method which display an information message.
347
327
      </p>
348
328
 
349
329
      <example>
350
 
      const options (afnix:sys:Options "axi [options] [file [arguments]]")
 
330
        const options (afnix:sys:Options "axi [options] [file [arguments]]")
351
331
      </example>
352
332
 
353
333
      <p>
354
 
      Eventually, the <code>set-user-message</code> method can be used
355
 
      to set the user message.
 
334
        Eventually, the <code>set-user-message</code> method can be used
 
335
        to set the user message.
356
336
      </p>
357
337
    </subsect>
358
338
 
361
341
      <title>Options definition</title>
362
342
 
363
343
      <p>
364
 
      The process of defining options is done by specifying the option
365
 
      character, eventually an option string and an option message. 
 
344
        The process of defining options is done by specifying the option
 
345
        character, eventually an option string and an option message. 
366
346
      </p>
367
347
 
368
348
      <example>
369
 
      options:add-unique-option 'h'          "print this help message"
370
 
      options:add-unique-option 'v'          "print system version"
371
 
      options:add-vector-option 'i'          "add a resolver path"
372
 
      options:add-string-option 'e'          "force the encoding mode"
373
 
      options:add-list-option   'f' "assert" "enable assertion checks"
374
 
      options:add-list-option   'f' "nopath" "do not set initial path"
 
349
        options:add-unique-option 'h'          "print this help message"
 
350
        options:add-unique-option 'v'          "print system version"
 
351
        options:add-vector-option 'i'          "add a resolver path"
 
352
        options:add-string-option 'e'          "force the encoding mode"
 
353
        options:add-list-option   'f' "assert" "enable assertion checks"
 
354
        options:add-list-option   'f' "nopath" "do not set initial path"
375
355
      </example>
376
356
 
377
357
      <p>
378
 
      The above example shows the option descriptors for the <afnix/>
379
 
      interpreter. Since <option>i</option> is a vector option,
380
 
      multiple occurrences of that option is allowed. It shall be noted
381
 
      that the list option <option>f assert</option> is a debug option. This
382
 
      means that this option is always set when the program is
383
 
      compiled in debug mode.
 
358
        The above example shows the option descriptors for the
 
359
        interpreter. Since <option>i</option> is a vector option,
 
360
        multiple occurrences of that option is allowed. It shall be noted
 
361
        that the list option <option>f assert</option> is a debug option. This
 
362
        means that this option is always set when the program is
 
363
        compiled in debug mode.
384
364
      </p>
385
365
    </subsect>
386
366
 
389
369
      <title>Options parsing and retrieval</title>
390
370
 
391
371
      <p>
392
 
      A string vector is parsed with the <code>parse</code>
393
 
      method. Generally, the vector argument is the interpreter
394
 
      argument vector defined in the qualified name
395
 
      <code>interp:args</code>. When the vector has been successfully
396
 
      parsed, it is possible to check the option that have been set.
 
372
        A string vector is parsed with the <code>parse</code>
 
373
        method. Generally, the vector argument is the interpreter
 
374
        argument vector defined in the qualified name
 
375
        <code>interp:args</code>. When the vector has been successfully
 
376
        parsed, it is possible to check the option that have been set.
397
377
      </p>
398
378
 
399
379
      <example>
400
 
      options:parse (Vector "-h")
401
 
      if (options:get-unique-option 'h') {
 
380
        options:parse (Vector "-h")
 
381
        if (options:get-unique-option 'h') {
402
382
        options:usage
403
383
        afnix:sys:exit 0
404
 
      }
405
 
      </example>
406
 
 
407
 
      <p>
408
 
      In the above example, the option vector is parsed with the
409
 
      <code>parse</code> method. The <code>get-unique-option</code>
410
 
      method returns true for the <option>h</option> thus triggering the
411
 
      display of the usage message.
412
 
      </p>
413
 
 
414
 
      <example>
415
 
      usage: axi [options] [file [arguments]]
416
 
                 [h]           print this help message
417
 
                 [v]           print system version
418
 
                 [i   path]    add a resolver path
419
 
                 [e   mode]    force the encoding mode
420
 
                 [f assert]    enable assertion checks
421
 
                 [f nopath]    do not set initial path
422
 
      </example>
423
 
 
424
 
      <p>
425
 
      If the option is a string option, the
426
 
      <code>get-string-option</code> will return the string associated
427
 
      with that option. It shall be noted that the
428
 
      <code>get-unique-option</code> method can be used to check if
429
 
      the option has been set during the parsing process. If the
430
 
      option is a vector option, the <code>get-vector-option</code>
431
 
      method is more appropriate. In this case, a vector is returned
432
 
      with all strings matching this option.
433
 
      </p>
434
 
 
435
 
      <example>
436
 
      options:parse (Vector "-i" "../" "-i" "../.." -e "UTF-08" "hello")
 
384
        }
 
385
      </example>
 
386
 
 
387
      <p>
 
388
        In the above example, the option vector is parsed with the
 
389
        <code>parse</code> method. The <code>get-unique-option</code>
 
390
        method returns true for the <option>h</option> thus triggering the
 
391
        display of the usage message.
 
392
      </p>
 
393
 
 
394
      <example>
 
395
        usage: axi [options] [file [arguments]]
 
396
        [h]           print this help message
 
397
        [v]           print system version
 
398
        [i   path]    add a resolver path
 
399
        [e   mode]    force the encoding mode
 
400
        [f assert]    enable assertion checks
 
401
        [f nopath]    do not set initial path
 
402
      </example>
 
403
 
 
404
      <p>
 
405
        If the option is a string option, the
 
406
        <code>get-string-option</code> will return the string associated
 
407
        with that option. It shall be noted that the
 
408
        <code>get-unique-option</code> method can be used to check if
 
409
        the option has been set during the parsing process. If the
 
410
        option is a vector option, the <code>get-vector-option</code>
 
411
        method is more appropriate. In this case, a vector is returned
 
412
        with all strings matching this option.
 
413
      </p>
 
414
 
 
415
      <example>
 
416
        options:parse (Vector "-i" "../" "-i" "../.." -e "UTF-08" "hello")
437
417
      </example>
438
418
      
439
419
      <p>
440
 
      In the previous example, the vector option <option>i</option> is
441
 
      set two times. The associated vector option has therefore a
442
 
      length of 2. The string option <option>e</option> is set to
443
 
      <tt>UTF-08</tt>. For this option <option>e</option>, the
444
 
      <code>get-unique-option</code> method will return true. Finally,
445
 
      the vector argument is filled with one string argument.
 
420
        In the previous example, the vector option <option>i</option> is
 
421
        set two times. The associated vector option has therefore a
 
422
        length of 2. The string option <option>e</option> is set to
 
423
        <tt>UTF-08</tt>. For this option <option>e</option>, the
 
424
        <code>get-unique-option</code> method will return true. Finally,
 
425
        the vector argument is filled with one string argument.
446
426
      </p>
447
427
    </subsect>    
448
428
  </section>