[r7649]: incubator / DocMusings / transformxml / arguments.cls  Maximize  Restore  History

Download this file

127 lines (109 with data), 3.9 kB

  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
::requires 'string2args.cls'
::class CommonArguments public subclass Directory
::attribute argIndex -- current arg index during parsing
::attribute args -- array of arguments
::attribute errors
::method init
self~errors = .List~new
self~initEntries
-- Tokenize the arguments, if needed
use strict arg callType, arguments -- always an array
select
when callType == "COMMAND" & arguments~items == 1 then self~args = String2Args(arguments[1])
when callType == "SUBROUTINE" & arguments~items == 1 & arguments[1]~isA(.array) then self~args = arguments[1]
otherwise self~args = arguments
end
-- Use makeArray to have a non-sparse array,
-- because omitted parameters have no corresponding index,
-- and we ignore omitted parameters here.
loop i=1 to self~args~items
if self~args[i] == "" then self~args~remove(i)
end
self~args = self~args~makeArray
if self~args~items == 0 then do
self~help = .true
return
end
-- Process the options
self~argIndex = 1
do while self~argIndex <= self~args~items
option = self~args[self~argIndex]
if option~left(1) <> "-" then leave -- not an option, assume we have reached the end of the options
if self~parseOption(option) == .false then return
-- Return now if help requested
if self~help then return
end
self~verifyOptions
if \self~errors~isEmpty then return
-- Process the arguments
self~parseArguments
::method initEntries
-- Entries in the directory, no need to declare them as attributes
self~setMethod("UNKNOWN", "return ''") -- I want '' instead of .nil when accessing an unset entry
self~debug = .false
self~dsssl = .false
self~dump = .false
self~help = .false
self~reportlinks = .false
self~syntdiag = .false
self~xslt = .false
::method parseOption
use strict arg option
if "-debug"~caseLessEquals(option) then do
self~argIndex += 1
self~debug = .true
self~debugOption = option
return .true
end
if "-dsssl"~caseLessEquals(option) then do
self~argIndex += 1
self~dsssl = .true
self~dssslOption = option
return .true
end
if "-dump"~caseLessEquals(option) then do
self~argIndex += 1
self~dump = .true
self~dumpOption = option
return .true
end
if "-help"~caseLessEquals(option) then do
self~argIndex += 1
self~help = .true
self~helpOption = option
return .true
end
if "-reportlinks"~caseLessEquals(option) then do
self~argIndex += 1
self~reportlinks = .true
self~reportlinksOption = option
value = self~args[self~argIndex]
if value == .nil then value = ""
if value == "" | value~left(1) == "-" then do
self~errors~append("[error] Value expected for option "option)
return .false
end
else do
self~argIndex += 1
self~reportlinksValue = value
return .true
end
end
if "-syntdiag"~caseLessEquals(option) then do
self~argIndex += 1
self~syntdiag = .true
self~syntdiagOption = option
return .true
end
if "-xslt"~caseLessEquals(option) then do
self~argIndex += 1
self~xslt = .true
self~xsltOption = option
return .true
end
self~errors~append("[error] Unknown option" option)
return .false
::method verifyOptions
if self~dsssl & self~xslt then self~errors~append("[error] You can't specify both "self~dssslOption" and "self~xsltOption)
::method parseArguments
-- Nothing to do here, will be specialized by subclasses

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks