PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/src/lib/cli/command_line_context.e

http://github.com/tybor/Liberty
Specman e | 117 lines | 73 code | 13 blank | 31 comment | 3 complexity | 2a1f22c87b192c1f052cc1c47d74ca3d MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4expanded class COMMAND_LINE_CONTEXT
  5--
  6-- Internal command-line parsing context.
  7--
  8
  9insert
 10   HASHABLE
 11   COMPARABLE
 12
 13feature {ANY}
 14   hash_code: INTEGER
 15      do
 16         if is_short then
 17            Result := short_index #+ (short_option_index #* 4096)
 18            if Result < 0 then
 19               Result := ~Result
 20            end
 21         else
 22            Result := index
 23         end
 24      end
 25
 26   infix "<" (other: like Current): BOOLEAN
 27      do
 28         if index = other.index then
 29            Result := short_option_index < other.short_option_index
 30         else
 31            Result := index < other.index
 32         end
 33      end
 34
 35feature {ANY}
 36   index: INTEGER
 37         -- set to the next argument to read
 38
 39   short_index: INTEGER
 40         -- set to the next option parameter position when parsing a short parameters sequence
 41
 42   short_option_index: INTEGER
 43         -- position of the short option in the short option sequence
 44
 45   is_parsed: BOOLEAN
 46         -- True if the parsing may continue. False if a grave parsing error occurs (such as an option present
 47         -- but with invalid data)
 48      do
 49         Result := index > 0
 50      end
 51
 52   is_short: BOOLEAN
 53      do
 54         Result := short_option_index > 1
 55      end
 56
 57feature {COMMAND_LINE_ARGUMENTS}
 58   init
 59      do
 60         index := 1
 61         short_index := 2
 62         short_option_index := 1
 63      ensure
 64         index = 1
 65         is_parsed
 66      end
 67
 68feature {COMMAND_LINE_ARGUMENT, CLARG_PARSER}
 69   set_short (a_short_index: like short_index; a_short_option_index: like short_option_index)
 70      require
 71         a_short_index > index
 72      do
 73         short_index := a_short_index
 74         short_option_index := a_short_option_index
 75      ensure
 76         short_index = a_short_index
 77         short_option_index = a_short_option_index
 78         is_short
 79      end
 80
 81   set_index (a_index: like index)
 82      require
 83         a_index > 0
 84      do
 85         index := a_index
 86         short_index := a_index + 1
 87         short_option_index := 1
 88      ensure
 89         index = a_index
 90         not is_short
 91      end
 92
 93invariant
 94   index > 0 implies short_index > index
 95   index > 0 implies short_option_index >= 1
 96
 97end -- class COMMAND_LINE_CONTEXT
 98--
 99-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
100--
101-- Permission is hereby granted, free of charge, to any person obtaining a copy
102-- of this software and associated documentation files (the "Software"), to deal
103-- in the Software without restriction, including without limitation the rights
104-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
105-- copies of the Software, and to permit persons to whom the Software is
106-- furnished to do so, subject to the following conditions:
107--
108-- The above copyright notice and this permission notice shall be included in
109-- all copies or substantial portions of the Software.
110--
111-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
112-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
113-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
114-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
115-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
116-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
117-- THE SOFTWARE.