Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PARSING COMMAND LINE ARGUMENTS

Name: Anonymous 2008-01-02 15:34

optimization (desperately) welcome

example usage;
function_copy C:\file.txt "C:\program files\out.put" -x -y
should return [function_copy, C:\file.txt, C:\program files\out.put, -x, -y]




Function CommandArguments(partstr As String) As String()
Dim args() As String
ReDim args(0)

Dim k As Integer
Dim ptr As Integer
Dim withinQuotes As Boolean
withinQuotes = False

Dim command As String
command = " " & partstr & " "

For k = 1 To Len(command)
    Select Case Mid$(command, k, 1)
    Case " "
        If withinQuotes = False Then
            ReDim Preserve args(UBound(args) + 1)
            If ptr <> 0 Then args(UBound(args) - 1) = Mid$(command, ptr + 1, k - ptr - 1)
            ptr = k
        End If
    Case Chr(34)
        Select Case withinQuotes
        Case False: withinQuotes = True
        Case True: withinQuotes = False
        End Select
    End Select
Next

For k = 1 To UBound(args)
    args(k) = NoQ(args(k))
    args(k - 1) = args(k)
Next

ReDim Preserve args(UBound(args) - 2)
CommandArguments = args

End Function

Public Function NoQ(inst As String) As String
If Len(inst) > 0 Then
    If Mid$(inst, 1, 1) = Chr(34) Then
        NoQ = Mid$(inst, 2, Len(inst) - 2)
    Else
        NoQ = inst
    End If
Else
    NoQ = vbNullString
End If
End Function

Name: Anonymous 2008-01-02 15:46

man strtok

Name: Anonymous 2008-01-02 15:48

>>2
He's clearly not using UNIX.

Name: Anonymous 2008-01-02 16:04

I think that code just gave me cancer.

Name: Anonymous 2008-01-02 16:17

>>2
strtok is a piece of shit. what kind of function modifies the string you pass it?

Name: Anonymous 2008-01-02 16:26

>>1

That is VERY GROSS.

Name: Anonymous 2008-01-02 16:33

>>5
there's a reentrant version as well
man strtok_r

Name: Anonymous 2008-01-02 16:59

Why strtok? What's wrong with man getopt?

Name: Anonymous 2008-01-02 17:09

Why strtok? What's wrong with Haskell and Parsec?

Name: Anonymous 2008-01-02 18:23

>>9
Anonymous has a Ph.D. in computer science, but never sold a line of code to a customer.

Name: Anonymous 2008-01-02 19:04

>>3
is it not in the windows version of libc too?

Name: Anonymous 2008-01-02 20:12

What Sort Of Shitty Language Makes You Capitalize The First Letter Of Every Fucking Word?

...my fingers hurt from typing that.

Name: Anonymous 2008-01-02 23:00

>>12
C

Name: Anonymous 2008-01-03 1:15

>>13
no one (who isn't a fucktard) does that in C

Name: Anonymous 2008-01-03 1:20

>>10
so what?

Name: sage 2008-01-03 3:14

>>1
fagfag

Name: Anonymous 2009-03-06 5:58

Continue to seem hopelessly   contrarian and outnumbered   until the first   is some header   files which are   useful for code   more like what   to do If   you lock in   your code to   login into the   armature and burn   it so as   much as a   good idea to   keep everything a   function or a   flat file database!

Don't change these.
Name: Email:
Entire Thread Thread List