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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Fri Nov 18 18:57:46 2005 UTC (18 years, 7 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines
fixed LCase problems

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
51 On Error Resume Next
52 If (value <> "") Then
53 options.add readValue(value), key
54 i = i + 1
55 Else
56 options.add 1, key
57 End If
58 On Error GoTo 0
59
60 End If
61
62 Next i
63
64 End Sub
65
66 Public Function getOptions() As Collection
67 Set getOptions = options
68 End Function
69
70 Public Function Count() As Integer
71 Count = options.Count
72 End Function
73
74 Public Sub dump()
75 Dim i As Integer
76 Dim key As String
77 For i = 2 To switches.Last
78 key = switches.item(i)
79 Debug.Print key & ": " & options(key)
80 Next
81 End Sub
82
83 Public Function hasSwitch(key As String) As Boolean
84
85 Dim value As Variant
86
87 On Error Resume Next
88 value = options.item(key)
89 On Error GoTo 0
90
91 If (Not IsEmpty(value)) Then
92 hasSwitch = True
93 Else
94 hasSwitch = False
95 End If
96
97 End Function
98
99 Public Function getArgument(key As String) As String
100 If hasSwitch(key) Then
101 getArgument = options.item(key)
102 End If
103 End Function
104
105
106 Private Function readSwitch(arg As String) As String
107 If (Left(arg, 2) = "--") Then
108 readSwitch = Mid(arg, 3)
109 End If
110 End Function
111
112 Private Function readArgument(arg As String) As String
113 If (Left(arg, 2) <> "--") Then
114 readArgument = arg
115 End If
116 End Function
117
118 Private Function readValue(value As String) As String
119 If (Left(value, 1) = Chr(34)) Then
120 value = Mid(value, 2)
121 End If
122 If (Right(value, 1) = Chr(34)) Then
123 value = Left(value, Len(value) - 1)
124 End If
125 readValue = value
126 End Function
127
128

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