Philip Smith
2013-01-19 21:32:53 UTC
Good day everybody! I have a raspberry pi with Occidentalis ver 0.2 image on it. This is Debian Wheezy flavor of Linux. I have installed gforth via apt-get ( $ sudo apt-get install gforth ) Wanted to do some GPIO stuff with some basic web page stuff and gforth scripting. So to that end i found Bernd Paysan's PDF on Web-Server in Forth. It took me some time to find the httpd.fs but i have a fork of the gforth stuff now on git hub. So i have the system set up now with out the proxy stuff in httpd.fs used and the inetd is configured to work on port 4444 just for testing.
The code works it seems but for the scripting part. This of course was the part i wanted to use so i need some help. My thoughts are why does the code run but not the scripting part? I have no idea but following are some clues (this is output of a simple index.html file):
###########################
Computing Primes
<$ 25 Constant #prim $>
The first <$ #prim $> primes are: <$ : prim? 0 over 2 max 2 ?DO over I mod 0= or LOOP nip 0= ; : prims ( n - ) 0 swap 2 swap 0 DO dup prim? IF swap IF ." , " THEN true swap dup 0 .r 1+ 1 ELSE 1+ 0 THEN +LOOP drop ; #prim prims $> .
###########################
This is the html file:
<HTML>
<HEAD>
<TITLE>GForth <$ version-string type $> presents</TITLE>
</HEAD>
<BODY>
<H1>Computing Primes</H1> <$ 25 Constant #prim $>
<P>The first <$ #prim $> primes are: <$
: prim? 0 over 2 max 2 ?DO over I mod 0= or LOOP nip 0= ;
: prims ( n - ) 0 swap 2
swap 0 DO dup prim? IF swap IF ." , " THEN true swap
dup 0 .r 1+ 1 ELSE 1+ 0 THEN
+LOOP drop ;
#prim prims $> .</P>
</BODY>
</HTML>
#####################################
So it is clear that the script part is just echoed out to a browser. The second clue is as follows:
From sshing into the raspberry pi and then running the httpd.fs file like this: $ ./httpd.fs index.html
I get this output:
<HTML>
<HEAD>
<TITLE>GForth 0.7.0 presents</TITLE>
</HEAD>
<BODY>
<H1>Computing Primes</H1>
<P>The first primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 .</P>
</BODY>
</HTML>
This output in the ssh if it was echoed to the browser would be a working scripting webserver. No i know executing the httpd.fs file this way in a ssh viewer is not what was intended and but you can see that this told me the scripting part was executing correctly so i am stumped as to why it seems to work in one context but not the other. I just wanted a basic starting point for a scripting forth webserver and if i can not use this httpd.fs then i will just make my own. Could someone possibly give me a link for another httpd.fs file that is know to work with gforth? Or possibly could someone identify what might be the issue with these two clues? It might not be obvious but in order for the httpd.fs file to be executable i needed to run this: $ chmod +x httpd.fs This is not clearly explained in anything i could read about how to use this web server but i believe i do understand that this is necessary because of the #! /usr/bin/gforth commands at the beginning of httpd.fs file.
Sorry for being long with this question but i figure this information might give someone an idea of what i need to do to solve this. I should also say that i have commented out the proxy stuff in httpd.fs because it does not compile correctly so i will need to look at that also but i figured i do not need a proxy yet. My start to raspberry pi gpio in gforth using c wrapper functions is here on git hub: https://github.com/harrypower/Rpi_Gforth_GPIO Now it does use c code i forked from another author but again i am trying to do this stuff with out reinventing the wheel. Also i am new to Linux so i am using this stuff as a learning platform. I do have a good history with C, Forth and several microcontroller family's so the Linux stuff is the new addition. If Bernd Paysan is around this group i would like to say Thanks for sharing what you have regarding forth and i have enjoyed Gforth plenty! I cut my teeth with Tom Zimmer flavor of Forth's all the way from Vic20 and C64 days to present in many forms including win32forth. Anyways i digress ... i hope someone can direct me further to allow me to do some web stuff with forth scriping so i can do some pi GPIO stuff! Thanks again!
The code works it seems but for the scripting part. This of course was the part i wanted to use so i need some help. My thoughts are why does the code run but not the scripting part? I have no idea but following are some clues (this is output of a simple index.html file):
###########################
Computing Primes
<$ 25 Constant #prim $>
The first <$ #prim $> primes are: <$ : prim? 0 over 2 max 2 ?DO over I mod 0= or LOOP nip 0= ; : prims ( n - ) 0 swap 2 swap 0 DO dup prim? IF swap IF ." , " THEN true swap dup 0 .r 1+ 1 ELSE 1+ 0 THEN +LOOP drop ; #prim prims $> .
###########################
This is the html file:
<HTML>
<HEAD>
<TITLE>GForth <$ version-string type $> presents</TITLE>
</HEAD>
<BODY>
<H1>Computing Primes</H1> <$ 25 Constant #prim $>
<P>The first <$ #prim $> primes are: <$
: prim? 0 over 2 max 2 ?DO over I mod 0= or LOOP nip 0= ;
: prims ( n - ) 0 swap 2
swap 0 DO dup prim? IF swap IF ." , " THEN true swap
dup 0 .r 1+ 1 ELSE 1+ 0 THEN
+LOOP drop ;
#prim prims $> .</P>
</BODY>
</HTML>
#####################################
So it is clear that the script part is just echoed out to a browser. The second clue is as follows:
From sshing into the raspberry pi and then running the httpd.fs file like this: $ ./httpd.fs index.html
I get this output:
<HTML>
<HEAD>
<TITLE>GForth 0.7.0 presents</TITLE>
</HEAD>
<BODY>
<H1>Computing Primes</H1>
<P>The first primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 .</P>
</BODY>
</HTML>
This output in the ssh if it was echoed to the browser would be a working scripting webserver. No i know executing the httpd.fs file this way in a ssh viewer is not what was intended and but you can see that this told me the scripting part was executing correctly so i am stumped as to why it seems to work in one context but not the other. I just wanted a basic starting point for a scripting forth webserver and if i can not use this httpd.fs then i will just make my own. Could someone possibly give me a link for another httpd.fs file that is know to work with gforth? Or possibly could someone identify what might be the issue with these two clues? It might not be obvious but in order for the httpd.fs file to be executable i needed to run this: $ chmod +x httpd.fs This is not clearly explained in anything i could read about how to use this web server but i believe i do understand that this is necessary because of the #! /usr/bin/gforth commands at the beginning of httpd.fs file.
Sorry for being long with this question but i figure this information might give someone an idea of what i need to do to solve this. I should also say that i have commented out the proxy stuff in httpd.fs because it does not compile correctly so i will need to look at that also but i figured i do not need a proxy yet. My start to raspberry pi gpio in gforth using c wrapper functions is here on git hub: https://github.com/harrypower/Rpi_Gforth_GPIO Now it does use c code i forked from another author but again i am trying to do this stuff with out reinventing the wheel. Also i am new to Linux so i am using this stuff as a learning platform. I do have a good history with C, Forth and several microcontroller family's so the Linux stuff is the new addition. If Bernd Paysan is around this group i would like to say Thanks for sharing what you have regarding forth and i have enjoyed Gforth plenty! I cut my teeth with Tom Zimmer flavor of Forth's all the way from Vic20 and C64 days to present in many forms including win32forth. Anyways i digress ... i hope someone can direct me further to allow me to do some web stuff with forth scriping so i can do some pi GPIO stuff! Thanks again!