📄 ch14.htm
字号:
Skip that blank<BR>
Do While Mid$(buf,
i, 1) = " " ' Skip
any additional whitespace<BR>
i
= i + 1<BR>
Loop<BR>
n = n + 1 '
Bump array index<BR>
Loop<BR>
<BR>
argv(n) = Trim$(Mid$(buf, i, (l - i +
1))) ' Get last arg<BR>
GetArgs = n + 1
' Return arg count<BR>
<BR>
End Function<BR>
<BR>
'--------------------------------------------------------------------------
<BR>
'<BR>
' GetExtraHeaders() - Create the array of extra
header structs<BR>
'<BR>
' Enumerate the keys in the [Extra Headers] section of the profile
file,<BR>
' then get the value for each of the keys.<BR>
'--------------------------------------------------------------------------
<BR>
Private Sub GetExtraHeaders()<BR>
Dim sList As String<BR>
Dim i As Integer, j As Integer, l As Integer,
n As Integer<BR>
<BR>
sList = GetProfile("Extra Headers",
"") ' Get key list<BR>
l = Len(sList) '
Length incl. trailing null<BR>
i = 1
' Start at 1st character<BR>
n = 0
' Index in array<BR>
Do While ((i < l) And (n < MAX_XHDR)) '
Safety stop here<BR>
j = InStr(i, sList,
Chr$(0)) ' J ->
next null<BR>
CGI_ExtraHeaders(n).key
= Mid$(sList, i, j - i) ' Get Key, then value<BR>
CGI_ExtraHeaders(n).value
= GetProfile("Extra Headers", CGI_ExtraHeaders(n).key)
<BR>
i = j + 1 '
Bump pointer<BR>
n = n + 1 '
Bump array index<BR>
Loop<BR>
CGI_NumExtraHeaders = n
' Fill in global count<BR>
<BR>
End Sub<BR>
<BR>
'--------------------------------------------------------------------------
<BR>
'<BR>
' GetFormTuples() - Create the array of POST
form input key=value pairs<BR>
'<BR>
'--------------------------------------------------------------------------
<BR>
Private Sub GetFormTuples()<BR>
Dim sList As String<BR>
Dim i As Integer, j As Integer, k As Integer
<BR>
Dim l As Integer, m As Integer, n As Integer
<BR>
Dim s As Long<BR>
Dim buf As String<BR>
Dim extName As String<BR>
Dim extFile As Integer<BR>
Dim extlen As Long<BR>
<BR>
n = 0
' Index in array<BR>
<BR>
'<BR>
' Do the easy one first: [Form Literal]
<BR>
'<BR>
sList = GetProfile("Form Literal",
"") ' Get key list<BR>
l = Len(sList) '
Length incl. trailing null<BR>
i = 1
' Start at 1st character<BR>
Do While ((i < l) And (n < MAX_FORM_TUPLES))
' Safety stop here<BR>
j = InStr(i, sList,
Chr$(0)) ' J ->
next null<BR>
CGI_FormTuples(n).key
= Mid$(sList, i, j - i) ' Get Key, then value<BR>
CGI_FormTuples(n).value
= GetProfile("Form Literal", CGI_FormTuples(n).key)
<BR>
i = j + 1 '
Bump pointer<BR>
n = n + 1 '
Bump array index<BR>
Loop<BR>
'<BR>
' Now do the external ones: [Form External]
<BR>
'<BR>
sList = GetProfile("Form External",
"") ' Get key list<BR>
l = Len(sList) '
Length incl. trailing null<BR>
i = 1
' Start at 1st character<BR>
extFile = FreeFile<BR>
Do While ((i < l) And (n < MAX_FORM_TUPLES))
' Safety stop here<BR>
j = InStr(i, sList,
Chr$(0)) ' J ->
next null<BR>
CGI_FormTuples(n).key
= Mid$(sList, i, j - i) ' Get Key, then pathname<BR>
buf = GetProfile("Form
External", CGI_FormTuples(n).key)<BR>
k = InStr(buf,
" ")
' Split file & length<BR>
extName = Mid$(buf,
1, k - 1)
' Pathname<BR>
k = k + 1<BR>
extlen = CLng(Mid$(buf,
k, Len(buf) - k + 1)) ' Length<BR>
'<BR>
' Use feature
of GET to read content in one call<BR>
'<BR>
Open extName For
Binary Access Read As #extFile<BR>
CGI_FormTuples(n).value
= String$(extlen, " ") ' Breathe in...<BR>
Get #extFile,
, CGI_FormTuples(n).value 'GULP!<BR>
Close #extFile
<BR>
i = j + 1 '
Bump pointer<BR>
n = n + 1 '
Bump array index<BR>
Loop<BR>
<BR>
CGI_NumFormTuples = n
' Number of fields decoded<BR>
n = 0
' Reset counter<BR>
'<BR>
' Next, the [Form Huge] section. Will
this ever get executed?<BR>
'<BR>
sList = GetProfile("Form Huge",
"") ' Get key list<BR>
l = Len(sList) '
Length incl. trailing null<BR>
i = 1
' Start at 1st character<BR>
Do While ((i < l) And (n < MAX_FORM_TUPLES))
' Safety stop here<BR>
j = InStr(i, sList,
Chr$(0)) ' J ->
next null<BR>
CGI_HugeTuples(n).key
= Mid$(sList, i, j - i) ' Get Key<BR>
buf = GetProfile("Form
Huge", CGI_HugeTuples(n).key) ' "offset length"
<BR>
k = InStr(buf,
" ")
' Delimiter<BR>
CGI_HugeTuples(n).offset
= CLng(Mid$(buf, 1, (k - 1)))<BR>
CGI_HugeTuples(n).length
= CLng(Mid$(buf, k, (Len(buf) - k + 1)))<BR>
i = j + 1 '
Bump pointer<BR>
n = n + 1 '
Bump array index<BR>
Loop<BR>
<BR>
CGI_NumHugeTuples = n
' Fill in global count<BR>
<BR>
n = 0
' Reset counter<BR>
'<BR>
' Finally, the [Form File] section.<BR>
'<BR>
sList = GetProfile("Form File",
"") ' Get key list<BR>
l = Len(sList) '
Length incl. trailing null<BR>
i = 1
' Start at 1st character<BR>
Do While ((i < l) And (n < MAX_FILE_TUPLES))
' Safety stop here<BR>
j = InStr(i, sList,
Chr$(0)) ' J ->
next null<BR>
CGI_FileTuples(n).key
= Mid$(sList, i, j - i) ' Get Key<BR>
buf = GetProfile("Form
File", CGI_FileTuples(n).key)<BR>
ParseFileValue
buf, CGI_FileTuples(n) ' Complicated, use Sub<BR>
i = j + 1 '
Bump pointer<BR>
n = n + 1 '
Bump array index<BR>
Loop<BR>
<BR>
CGI_NumFileTuples = n
' Fill in global count<BR>
<BR>
End Sub<BR>
<BR>
'--------------------------------------------------------------------------
<BR>
'<BR>
' GetProfile() - Get a value or enumerate keys
in CGI_Profile file<BR>
'<BR>
' Get a value given the section and key, or enumerate keys given
the<BR>
' section name and "" for the key. If enumerating, the
list of keys for<BR>
' the given section is returned as a null-separated string, with
a<BR>
' double null at the end.<BR>
'<BR>
' VB handles this with flair! I couldn't believe my eyes when
I tried this.<BR>
'--------------------------------------------------------------------------
<BR>
Private Function GetProfile(sSection As String, sKey As String)
As String<BR>
Dim retLen As Long<BR>
Dim buf As String * ENUM_BUF_SIZE<BR>
<BR>
If sKey <> "" Then<BR>
retLen = GetPrivateProfileString(sSection,
sKey, "", buf, ENUM_BUF_SIZE, CGI_ProfileFile)<BR>
Else<BR>
retLen = GetPrivateProfileString(sSection,
0&, "", buf, ENUM_BUF_SIZE, CGI_ProfileFile)<BR>
End If<BR>
If retLen = 0 Then<BR>
GetProfile = ""
<BR>
Else<BR>
GetProfile = Left$(buf,
retLen)<BR>
End If<BR>
<BR>
End Function<BR>
<BR>
'----------------------------------------------------------------------
<BR>
'<BR>
' Get the value of a "small" form field given the key
<BR>
'<BR>
' Signals an error if field does not exist<BR>
'<BR>
'----------------------------------------------------------------------
<BR>
Function GetSmallField(key As String) As String<BR>
D
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -