update 9-5-19

FBS (freeBASIC script) is an interpreter for FbCadCam macros and a server side script engine.

Moderators: kitty_webb, Ywsp, joanCruz03, yajra1219, Jayem, shela

Post Reply
owen
Site Admin
Posts: 642
Joined: Thu Apr 13, 2017 12:14 pm

update 9-5-19

Post by owen » Thu Sep 05, 2019 5:11 am

I compile fbs.bas using linux (ubuntu) and uploaded it to the server using filezilla.
I make sure i use binary transfer type when i upload the binary file to the server.
I then set the permissions for it to 755

With the interpreter on the server all i have to do is upload two files in order to run scripts that display in the browser.

1st file:
I use a perl cgi script to run the source code.
note: I set the server to recognize files with the extension .fbs as executable cgi files.
note: the cgi file is not really executing (it's just a text file), which opens a shell (a command prompt) to run my executable interpreter.

I saved this code as hello_world.fbs

Code: Select all

#!/usr/bin/perl
print "Content-type: text/html\n\n";
system("./fbs hello_world.bas");
2nd file:
And this code as hellow_world.bas

Code: Select all

Dim As Integer i
Dim As String s,temp
For i = 1 To 10
	temp = "<h1>" + Str(i) + ". Hello World</h1>"
	s+=temp
Next
Print s
Sleep
Then using FileZilla I uploaded both files to fbcadcam.org / fbs sub directory
Make sure to use TRANSFER TYPE ASCII

Next I set the file permissions to 755 for hello_world.fbs
note: no need to set the permissions to your bas file.

And finally I test it using a browser
http://fbcadcam.org/fbs/hello_world.fbs

owen
Site Admin
Posts: 642
Joined: Thu Apr 13, 2017 12:14 pm

Re: update 9-5-19

Post by owen » Fri Sep 06, 2019 1:06 pm

this is a test for sub routines and functions
http://fbcadcam.org/fbs/test_subs_functs.fbs

test_subs_functs.fbs

Code: Select all

#!/usr/bin/perl
print "Content-type: text/html\n\n";
system("./fbs test_subs_functs.bas");
test_subs_functs.bas

Code: Select all

Declare Sub init(document_title As String)
Declare Function build_html(document_type As UByte) As String

Dim As String html_document
Dim As UByte document_type
Dim As String document_title
Dim As String document_content
Dim Shared As String doc_type(2)
Dim Shared As String html(1)
Dim Shared As String head(1)
Dim Shared As String title(2)
Dim Shared As String body(2)

'default value is zero for html5 and 1 to 7 for other html doc types
document_type=0
document_title="My web page"

init(document_title)

'enter your web page content here
document_content="<h1> My first web page built using fbs</h1>"
document_content+="<p>This is a test</p>"
body(1)=document_content

html_document = build_html(document_type)

Print html_document
Sleep



Sub init(document_title As String)
	html(0)="<html>"
	html(1)="</html>"
	
	head(0)="<head>"
	head(1)="</head>"
	
	title(0)="<title>"
	title(1)=document_title
	title(2)="</title>"
	
	body(0)="<body>"
	body(2)="</body>"
End Sub
Function build_html(document_type As UByte) As String
	Dim As String html_document
	doc_type(0)="<!DOCTYPE "
	Select Case document_type
		Case 0
			doc_type(1)="html"'html5
		Case 1
			doc_type(1)="HTML PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/strict.dtd'"
		Case 2
			doc_type(1)="HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'"
		Case 3
			doc_type(1)="HTML PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/html4/frameset.dtd'"
		Case 4
			doc_type(1)="html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'"
		Case 5
			doc_type(1)="html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'"
		Case 6
			doc_type(1)="html PUBLIC '-//W3C//DTD XHTML 1.0 Frameset//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd'"
		Case 7
			doc_type(1)="html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'"
	End Select
	doc_type(2)=">"
	html_document=doc_type(0)
	html_document+=doc_type(1)
	html_document+=doc_type(2)
	html_document+=html(0)
	html_document+=head(0)
	html_document+=title(0)
	html_document+=title(1)
	html_document+=title(2)
	html_document+=head(1)
	html_document+=body(0)
	html_document+=body(1)
	html_document+=body(2)
	html_document+=html(1)
	Return html_document
End Function

Post Reply