Interpreting/parsing a command line type of argument 
Author Message
 Interpreting/parsing a command line type of argument

Hi all-

I've got an interesting question, and I can't seem to find an
answer for it.  Maybe I'm looking in the wrong place.  Does anyone
have a reference for how to parse a command line efficiently, and
without errors; that is, given a
line in a file one might supply to a VB program:

foobar -fCourier -tlandscape -m10.7 -vScript.txt

how does one parse out the little pieces of information on the
command line?  This may be trivial for simple situations, but
what is the best way to go about doing this?  If I know I have a
certain number of command line switches, I guess I can just
look for the - sign, look for the next one, and then chop up
the line based on this, and then check which switch I am turning on with
a case statement.

I'm wondering if there is a more global view I should be taking of
the process of parsing this line.  I'm looking for either good
examples of how to process something in VB, or reference I can look
at.  I'm NOT asking for someone to write code, that's for sure.

I have checked out nice programs like 'a2ps' and the like, which
are for Unix systems, and do processing of command line arguments,
but I thought there might be more information on this.  For example;
should I use the '-' as a flag to tell what options are desired,
or is there something better that that.

Just wondering,

A.

--
Andrew P. Anselmo



Thu, 04 Mar 1999 03:00:00 GMT  
 Interpreting/parsing a command line type of argument

Quote:
>I've got an interesting question, and I can't seem to find an
>answer for it.  Maybe I'm looking in the wrong place.  Does anyone
>have a reference for how to parse a command line efficiently, and
>without errors; that is, given a
>line in a file one might supply to a VB program:

Think this will help you on your way... It's not beautiful, excellent,
genius... but it works... it's really coded like basic should be coded
a mess :)

lineraw.text is the command-line
param(x) is an array of strings so param(0) will refer to the first
parameter after starting this sub. debug it, change it... sleep with
it.. do anything you want.

Dim temp() As Byte
    For i = 0 To 7
    param(i).Text = ""
    Next i

lineraw.Text = LTrim(RTrim(lineraw.Text))
temp() = lineraw.Text
snum = 0: cparam = 0: cnt = 0: i = ""
For cnt = 0 To (Len(lineraw.Text) * 2 - 1)
    i = Chr(temp(cnt))
    If i = " " Then
        If cparam = 7 Then
        'if too many parameters give expected syntax and option te dit
            temp2 = "Too many parameters on line" + Chr(10) + Chr(13)
+ "expected: " + Chr(10) + Chr(13) + "Gold xp" + Chr(10) + Chr(13) +
"found: "

            temp2 = temp2 + Chr(10) + Chr(13) + lineraw.Text
            MsgBox (temp2)
            End If
        If param(cparam).Text <> "" And cparam < 7 Then cparam =
cparam + 1
    Else
        param(cparam).Text = Trim(param(cparam).Text + i)
        End If
    Next cnt
    lineraw.Text = ""

Greetings,
  Venice



Fri, 05 Mar 1999 03:00:00 GMT  
 Interpreting/parsing a command line type of argument

Quote:
>I've got an interesting question, and I can't seem to find an
>answer for it.  Maybe I'm looking in the wrong place.  Does anyone
>have a reference for how to parse a command line efficiently, and
>without errors; that is, given a
>line in a file one might supply to a VB program:

Think this will help you on your way... It's not beautiful, excellent,
genius... but it works... it's really coded like basic should be coded
a mess :)

lineraw.text is the command-line
param(x) is an array of strings so param(0) will refer to the first
parameter after starting this sub. debug it, change it... sleep with
it.. do anything you want.

Dim temp() As Byte
    For i = 0 To 7
    param(i).Text = ""
    Next i

lineraw.Text = LTrim(RTrim(lineraw.Text))
temp() = lineraw.Text
snum = 0: cparam = 0: cnt = 0: i = ""
For cnt = 0 To (Len(lineraw.Text) * 2 - 1)
    i = Chr(temp(cnt))
    If i = " " Then
        If cparam = 7 Then
        'if too many parameters give expected syntax and option te dit
            temp2 = "Too many parameters on line" + Chr(10) + Chr(13)
+ "expected: " + Chr(10) + Chr(13) + "Gold xp" + Chr(10) + Chr(13) +
"found: "

            temp2 = temp2 + Chr(10) + Chr(13) + lineraw.Text
            MsgBox (temp2)
            End If
        If param(cparam).Text <> "" And cparam < 7 Then cparam =
cparam + 1
    Else
        param(cparam).Text = Trim(param(cparam).Text + i)
        End If
    Next cnt
    lineraw.Text = ""

Greetings,
  Venice



Fri, 05 Mar 1999 03:00:00 GMT  
 Interpreting/parsing a command line type of argument


Quote:
>Hi all-
>I've got an interesting question, and I can't seem to find an
>answer for it.  Maybe I'm looking in the wrong place.  Does anyone
>have a reference for how to parse a command line efficiently, and
>have a reference for how to parse a command line efficiently, and
>without errors; that is, given a
>line in a file one might supply to a VB program:

Think this will help you on your way... It's not beautiful, excellent,
genius... but it works... it's really coded like basic should be coded
a mess :)

lineraw.text is the command-line
param(x) is an array of strings so param(0) will refer to the first
parameter after starting this sub. debug it, change it... sleep with
it.. do anything you want.

Dim temp() As Byte
    For i = 0 To 7
    param(i).Text = ""
    Next i

lineraw.Text = LTrim(RTrim(lineraw.Text))
temp() = lineraw.Text
snum = 0: cparam = 0: cnt = 0: i = ""
For cnt = 0 To (Len(lineraw.Text) * 2 - 1)
    i = Chr(temp(cnt))
    If i = " " Then
        If cparam = 7 Then
        'if too many parameters give expected syntax and option te dit
            temp2 = "Too many parameters on line" + Chr(10) + Chr(13)
+ "expected: " + Chr(10) + Chr(13) + "Gold xp" + Chr(10) + Chr(13) +
"found: "

            temp2 = temp2 + Chr(10) + Chr(13) + lineraw.Text
            MsgBox (temp2)
            End If
        If param(cparam).Text <> "" And cparam < 7 Then cparam =
cparam + 1
    Else
        param(cparam).Text = Trim(param(cparam).Text + i)
        End If
    Next cnt
    lineraw.Text = ""

Greetings,
  Venice



Fri, 05 Mar 1999 03:00:00 GMT  
 Interpreting/parsing a command line type of argument

Quote:
>I've got an interesting question, and I can't seem to find an
>answer for it.  Maybe I'm looking in the wrong place.  Does anyone
>have a reference for how to parse a command line efficiently, and
>without errors; that is, given a
>line in a file one might supply to a VB program:

Think this will help you on your way... It's not beautiful, excellent,
genius... but it works... it's really coded like basic should be coded
a mess :)

lineraw.text is the command-line
param(x) is an array of strings so param(0) will refer to the first
parameter after starting this sub. debug it, change it... sleep with
it.. do anything you want.

Dim temp() As Byte
    For i = 0 To 7
    param(i).Text = ""
    Next i

lineraw.Text = LTrim(RTrim(lineraw.Text))
temp() = lineraw.Text
snum = 0: cparam = 0: cnt = 0: i = ""
For cnt = 0 To (Len(lineraw.Text) * 2 - 1)
    i = Chr(temp(cnt))
    If i = " " Then
        If cparam = 7 Then
        'if too many parameters give expected syntax and option te dit
            temp2 = "Too many parameters on line" + Chr(10) + Chr(13)
+ "expected: " + Chr(10) + Chr(13) + "Gold xp" + Chr(10) + Chr(13) +
"found: "

            temp2 = temp2 + Chr(10) + Chr(13) + lineraw.Text
            MsgBox (temp2)
            End If
        If param(cparam).Text <> "" And cparam < 7 Then cparam =
cparam + 1
    Else
        param(cparam).Text = Trim(param(cparam).Text + i)
        End If
    Next cnt
    lineraw.Text = ""

Greetings,
  Venice



Fri, 05 Mar 1999 03:00:00 GMT  
 Interpreting/parsing a command line type of argument

a$ = trim(command$)
gets the command line except for the name of the program called.  That is,
ALL the arguments.
Then, all you have to do is loop over looking for a space (with suitable
intermediate t{*filter*}) and keep extracting the left part.  This gives each
piece.  Then discard the "-" and you have it.

Shelly



Quote:
> Andrew P. Anselmo



Sat, 06 Mar 1999 03:00:00 GMT  
 Interpreting/parsing a command line type of argument


Quote:
>I've got an interesting question, and I can't seem to find an
>answer for it.  Maybe I'm looking in the wrong place.  Does anyone
>have a reference for how to parse a command line efficiently, and
>without errors; that is, given a
>line in a file one might supply to a VB program:

I'll make available on my site, PARSE.ZIP, this is a routine I used in
QB and should work with minor changes in VB.

http://hom.rica.net/wmingee
-------------------------------------------------------------



Sat, 06 Mar 1999 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Command Line Argument Parsing

2. Parsing Command line Arguments in VB Script

3. reading/parsing command line arguments AND return codes from vbs's

4. Command-Line arguments using Command()

5. WScript.Arguments won't parse double-quotes within arguments

6. Code to parse the command line

7. Command Line Parsing

8. Looking for robust command line parse algorithm

9. parsing command line

10. Help: Command line parsing

11. getopt / command line parsing

12. Help Parsing Command Line Parms

 

 
Powered by phpBB® Forum Software