| 1 |
# ---------------------------------------------------------------------------- |
| 2 |
# - exp-amd-optdb - |
| 3 |
# - afnix:amd option database module - |
| 4 |
# ---------------------------------------------------------------------------- |
| 5 |
# - This program is free software; you can redistribute it and/or modify - |
| 6 |
# - it provided that this copyright notice is kept intact. - |
| 7 |
# - - |
| 8 |
# - This program is distributed in the hope that it will be useful, but - |
| 9 |
# - without any warranty; without even the implied warranty of - |
| 10 |
# - merchantability or fitness for a particular purpose. In not event shall - |
| 11 |
# - the copyright holder be liable for any direct, indirect, incidental or - |
| 12 |
# - special damages arising in any way out of the use of this software. - |
| 13 |
# ---------------------------------------------------------------------------- |
| 14 |
# - copyright (c) 1999-2023 amaury darsch - |
| 15 |
# ---------------------------------------------------------------------------- |
| 16 |
|
| 17 |
# ---------------------------------------------------------------------------- |
| 18 |
# - global section - |
| 19 |
# ---------------------------------------------------------------------------- |
| 20 |
|
| 21 |
# the option database class |
| 22 |
const afnix:amd:optdb (class) |
| 23 |
|
| 24 |
# ---------------------------------------------------------------------------- |
| 25 |
# - private section - |
| 26 |
# ---------------------------------------------------------------------------- |
| 27 |
|
| 28 |
# the option messages |
| 29 |
const AFNIX:AMD:U-CLS-MSG "axi [i afnix-amd] amd-start [options] uri" |
| 30 |
const AFNIX:AMD:H-LCO-MSG " [h] print this help message" |
| 31 |
const AFNIX:AMD:V-LCO-MSG " [v] print system version" |
| 32 |
const AFNIX:AMD:O-LCO-MSG " [o] set output file name" |
| 33 |
|
| 34 |
# ---------------------------------------------------------------------------- |
| 35 |
# - initial section - |
| 36 |
# ---------------------------------------------------------------------------- |
| 37 |
|
| 38 |
# initialize the option descriptors |
| 39 |
trans afnix:amd:optdb:preset (argv) { |
| 40 |
# create an option class and bind it |
| 41 |
trans this:super (afnix:sys:Options AFNIX:AMD:U-CLS-MSG) |
| 42 |
|
| 43 |
# register the options |
| 44 |
this:add-string-option 'o' AFNIX:AMD:O-LCO-MSG |
| 45 |
this:add-unique-option 'v' AFNIX:AMD:V-LCO-MSG |
| 46 |
this:add-unique-option 'h' AFNIX:AMD:H-LCO-MSG |
| 47 |
|
| 48 |
# parse the options |
| 49 |
try (this:parse argv) { |
| 50 |
this:usage (interp:get-error-stream) |
| 51 |
afnix:sys:exit 1 |
| 52 |
} |
| 53 |
# check for the help option |
| 54 |
if (this:get-unique-option 'h') { |
| 55 |
this:usage (interp:get-output-stream) |
| 56 |
afnix:sys:exit 0 |
| 57 |
} |
| 58 |
# check for the version option |
| 59 |
if (this:get-unique-option 'v') { |
| 60 |
println (afnix:amd:get-copyright-message) |
| 61 |
println (afnix:amd:get-revision-message) |
| 62 |
afnix:sys:exit 0 |
| 63 |
} |
| 64 |
# check for the output file name |
| 65 |
if (this:get-unique-option 'o') { |
| 66 |
trans afnix:amd:system-oflg true |
| 67 |
trans afnix:amd:system-onam (this:get-string-option 'o') |
| 68 |
} |
| 69 |
# get the requested uri argument |
| 70 |
const varg (this:get-vector-arguments) |
| 71 |
if (!= (varg:length) 1) { |
| 72 |
this:usage (interp:get-error-stream) |
| 73 |
afnix:sys:exit 1 |
| 74 |
} |
| 75 |
const this:uri (afnix:amd:get-uri-name (varg:get 0)) |
| 76 |
} |
| 77 |
|
| 78 |
# ---------------------------------------------------------------------------- |
| 79 |
# - methods section - |
| 80 |
# ---------------------------------------------------------------------------- |
| 81 |
|
| 82 |
# @return the requested uri |
| 83 |
|
| 84 |
trans afnix:amd:optdb:get-uri nil { |
| 85 |
afnix:nwg:Uri this:uri |
| 86 |
} |