May 18, 2024, 09:06:34 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Web apps

Started by Rock Ridge Farm (Larry), October 07, 2008, 12:23:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

Has anyone built a web app using ebasic?
If so I would like to see it.

Ionic Wind Support Team

Yes, but I can't post it here.

What are you looking to do?  Here is the CGI example I posted a while ago.  Compile and stick it on a IIS server to test.


declare cdecl extern getenv alias _getenv(envtype:string),string
declare cdecl extern sscanf alias _sscanf(p1 as pointer,format as string,p2 as pointer),int
CONST STD_INPUT_HANDLE = -10
declare import,GetStdHandle(handle as INT),UINT
declare import,ReadFile(hFile as UINT,lpBuffer as POINTER,nNumberOfBytesToRead as UINT,lpNumberOfBytesRead as UINT BYREF,lpOverlapped as UINT),INT

int query_length
query_length = val(getenv("CONTENT_LENGTH"))
print "<html><head>"
print "HTTP/1.0 200 OK"
print "Content-Type: text/html\n\n"
print "<title>Home Page</title>"
print "</head><body>"

if(query_length = 0)
'show a form
print "<form method=\"POST\" name=\"example\" action=\"cgi_example.exe\">"
print "<p>Username <input type=\"text\" name=\"Username\" size=\"20\"><br>"
print "Password <input type=\"text\" name=\"Password\" size=\"20\"></p>"
print "<p>First Name <input type=\"text\" name=\"First\" size=\"20\"><br>"
print "Last Name <input type=\"text\" name=\"Last\" size=\"20\"><br>"
print "Address <input type=\"text\" name=\"Address\" size=\"57\"><br>"
print "Country <select size=\"1\" name=\"Country\">"
print "<option selected>USA</option>"
print "<option>Canada</option>"
print "</select></p>"
print "<p><input type=\"submit\" value=\"Submit\" name=\"B1\"><input type=\"reset\" value=\"Reset\" name=\"B2\"></p>"
print "</form>"
else
'show the results of the form
int stdin,bytes_read,pos
stdin = GetStdHandle(STD_INPUT_HANDLE)
istring inp[4000]
pointer pAssoc,pData
ReadFile(stdin,inp,query_length,bytes_read,0)
'terminate the string
inp[bytes_read] = NULL
pAssoc = SplitPairs(inp)
'print out the results back to the browser
print "The data entered on the form:<br>"
pos = DictGetStartAssoc(pAssoc)
WHILE pos
pData = DictGetNextAssoc(pAssoc,pos)
PRINT DictGetKey(pData),"=",DictGetValue(pData),"<br>"
ENDWHILE
'in reality you would probably want to "lookup" the data like so
'username = DictLookup(pAssoc,"Username")
DictFree(pAssoc)
endif
print "</body></html>"

'General purpose subroutines to split the name/value pairs into a dictionary (Assoc Array)

Sub SplitPairs(inp as string),pointer
pointer pInp,pStart,pRet
pInp = inp
pStart = inp
pRet = DictCreate()
while #<char>pInp <> NULL
if #<char>pInp = ASC("&")
#<char>pInp = NULL
AddNameValue(pRet, #<STRING>pStart)
pStart = pInp+1
endif
pInp++
endwhile
AddNameValue(pRet,#<STRING>pStart)
return pRet
Endsub

Sub AddNameValue(pointer pAssoc,string value)
pointer pName,pValue:pName = value
int eq:eq = instr(value,"=")
if(eq)
value[eq-1]=NULL
pValue = pName + eq
DictAdd(pAssoc,#<STRING>pName,uudecode(#<STRING>pValue))
endif
Endsub

Sub uudecode(string value),heap
pointer pReturn,pTemp,pValue
int code
pReturn = AllocHeap(len(value)+1)
pTemp = pReturn
pValue = value
while(#<CHAR>pValue <> NULL)
if #<CHAR>pValue = ASC("+")
#<CHAR>pTemp = " "
else
if #<CHAR>pValue = ASC("%")
'next two bytes are a hex code
if(sscanf(pValue+1,"%2x",&code) <> 1) then code = ASC("?")
#<CHAR>pTemp = code
pValue+=2
else
#<CHAR>pTemp = #<CHAR>pValue
endif
endif
pTemp++
pValue++
Endwhile
return #<string>pReturn
Endsub


Paul.
Ionic Wind Support Team

Rock Ridge Farm (Larry)

I have several web apps I need to do - they use cgi and html currently.
I thought it would be cool to do the new versions with ebasic.

Rock Ridge Farm (Larry)

The app will also need to run on Linux.

Ionic Wind Support Team

Don't have any Linux examples, sorry.   But on linux it should be easier.  The code will be different though so you will need two apps.

Paul.
Ionic Wind Support Team