/[cvs]/joko/ToolBox/Windows/VpnDial/src/CommandLine.cls
ViewVC logotype

Annotation of /joko/ToolBox/Windows/VpnDial/src/CommandLine.cls

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Wed Sep 28 20:36:46 2005 UTC (18 years, 9 months ago) by joko
Branch: MAIN
+ initial commit

1 joko 1.1 VERSION 1.0 CLASS
2     BEGIN
3     MultiUse = -1 'True
4     Persistable = 0 'NotPersistable
5     DataBindingBehavior = 0 'vbNone
6     DataSourceBehavior = 0 'vbNone
7     MTSTransactionMode = 0 'NotAnMTSObject
8     END
9     Attribute VB_Name = "CommandLine"
10     Attribute VB_GlobalNameSpace = False
11     Attribute VB_Creatable = True
12     Attribute VB_PredeclaredId = False
13     Attribute VB_Exposed = False
14     Option Explicit
15    
16     Dim options As New Collection
17     Dim switches As New CVector
18    
19     Public Sub parse()
20    
21     Dim args() As String
22     Dim arg As String
23     'Dim blnDebug As Boolean
24     'Dim strFilename As String
25    
26     Dim i As Integer
27     Dim key As String
28     Dim value As String
29    
30     args = Split(Command$, " ")
31     For i = LBound(args) To UBound(args)
32    
33     'Debug.Print "i: " & i
34    
35     'arg = args(i)
36     key = readSwitch(args(i))
37     value = ""
38     If (i <> UBound(args)) Then
39     value = readArgument(args(i + 1))
40     If (Left(value, 1) = Chr(34)) Then
41     i = i + 1
42     value = value & " " & readArgument(args(i + 1))
43     End If
44     End If
45    
46     If (key <> "") Then
47     'Debug.Print "key: " & key
48     switches.add key
49     'switches.item(i + 1) = key
50     If (value <> "") Then
51     options.add readValue(value), key
52     i = i + 1
53     Else
54     options.add 1, key
55     End If
56     End If
57    
58     Next i
59    
60     End Sub
61    
62     Public Function getOptions() As Collection
63     Set getOptions = options
64     End Function
65    
66     Public Function Count() As Integer
67     Count = options.Count
68     End Function
69    
70     Public Sub dump()
71     Dim i As Integer
72     Dim key As String
73     For i = 2 To switches.Last
74     key = switches.item(i)
75     Debug.Print key & ": " & options(key)
76     Next
77     End Sub
78    
79     Public Function hasSwitch(key As String) As Boolean
80    
81     Dim value As Variant
82    
83     On Error Resume Next
84     value = options.item(key)
85     On Error GoTo 0
86    
87     If (Not IsEmpty(value)) Then
88     hasSwitch = True
89     Else
90     hasSwitch = False
91     End If
92    
93     End Function
94    
95     Public Function getArgument(key As String) As String
96     If hasSwitch(key) Then
97     getArgument = options.item(key)
98     End If
99     End Function
100    
101    
102     Private Function readSwitch(arg As String) As String
103     If (Left(arg, 2) = "--") Then
104     readSwitch = LCase(Mid(arg, 3))
105     End If
106     End Function
107    
108     Private Function readArgument(arg As String) As String
109     If (Left(arg, 2) <> "--") Then
110     readArgument = LCase(arg)
111     End If
112     End Function
113    
114     Private Function readValue(value As String) As String
115     If (Left(value, 1) = Chr(34)) Then
116     value = Mid(value, 2)
117     End If
118     If (Right(value, 1) = Chr(34)) Then
119     value = Left(value, Len(value) - 1)
120     End If
121     readValue = value
122     End Function
123    
124    

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed