Then just spend some time and check if PB provides similar capabilities, nothing to do. Or enum them here and someone will answerwysardry wrote:Although I prefer BASIC syntax, Perl is well known for its text processing capabilities, which is why I'm still slightly undecided.
Using PureBasic to create websites?
Re: Using PureBasic to create websites?
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Re: Using PureBasic to create websites?
Okay, one of the really handy features of Perl is being able to define strings that contain multiple lines of text. I've seen examples in the PureBasic manual that show multiple strings being assigned to one string to do this, but no examples of multiple line strings.
IIRC, in Perl, something like this would work:-
Everything between the first and second ~ (or whatever character you choose) is treated as one string including newline characters. I also vaguely remember being able to include variables in such strings.
Can PureBasic do this? If so, where is it mentioned in the online manual?
IIRC, in Perl, something like this would work:-
Code: Select all
$my_page = qq~<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<p>Welcome to My Page</p>
</body>
</html>~;
print $my_page;
Can PureBasic do this? If so, where is it mentioned in the online manual?
Re: Using PureBasic to create websites?
Though not an exact replica, here are three variations:wysardry wrote:Can PureBasic do this? If so, where is it mentioned in the online manual?
Code: Select all
;escaped string, single line format, newlines signaled with escape sequence
my_page$ = ~"<!DOCTYPE html>\n<html>\n<head>\n<title>My Page</title>\n</head>\n<body>\n<p>Welcome To My Page</p>\n</body>\n</html>"
Debug my_page$
Debug "-----------"
;escaped string, mult-line continuation format, newlines signaled with escape sequence
my_page2$= ~"<!DOCTYPE html>\n" +
~"<html>\n" +
~"<head>\n" +
~"<title>My Page</title>\n" +
~"</head>\n" +
~"<body>\n" +
~"<p>Welcome To My Page</p>\n" +
~"</body>\n" +
~"</html>"
Debug my_page2$
Debug "-----------"
;normal string, multi-line continuation with #LF$ constant for newlines
my_page3$= "<!DOCTYPE html>" + #LF$ +
"<html>" + #LF$ +
"<head>" + #LF$ +
"<title>My Page</title>" + #LF$ +
"</head>" + #LF$ +
"<body>" + #LF$ +
~"<p>Welcome To My Page</p>" + #LF$ +
"</body>" + #LF$ +
"</html>"
Debug my_page3$
Re: Using PureBasic to create websites?
That's the page I saw the examples on. I was hoping there was a less cumbersome method.
It would be even more complicated in actual use, as HTML code can include quotation marks which would need to be escaped in PureBasic (but not in my Perl example as the tilde is the string delimiter there).
I'm guessing that reading strings from a text file line by line would be the way to go, although I'm not sure if you can embed other variables in there too. Say, like this:-
If PureBasic can't replace strings inside files like that, then I would imagine that the next best thing would be to have it search for and replace certain codes, something like this:-
I made the replaceable code text uppercase so that it stands out amongst the lowercase HTML tags, but lowercase would also work.
ASP tags look similar, so most HTML editors shouldn't have a problem with them in that format. An alternative would be to use comment tags, but the program would then have to be told to ignore actual comments.
It would be even more complicated in actual use, as HTML code can include quotation marks which would need to be escaped in PureBasic (but not in my Perl example as the tilde is the string delimiter there).
I'm guessing that reading strings from a text file line by line would be the way to go, although I'm not sure if you can embed other variables in there too. Say, like this:-
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<title>$my_title</title>
</head>
<body>
<h1>$my_title</h1>
$my_page_content
</body>
</html>
Code: Select all
<!DOCTYPE html>
<html lang="en">
<head>
<title><%MY_TITLE%></title>
</head>
<body>
<h1><%MY_TITLE%></h1>
<%MY_PAGE_CONTENT%>
</body>
</html>
ASP tags look similar, so most HTML editors shouldn't have a problem with them in that format. An alternative would be to use comment tags, but the program would then have to be told to ignore actual comments.
Re: Using PureBasic to create websites?
You can use placeholders in text and then use ReplaceString()
(like s/// in Perl)
There are many functions to manipulate Strings
http://www.purebasic.com/documentation/ ... index.html
ReplaceString() eq s///
http://www.purebasic.com/documentation/ ... tring.html
String$ = ReplaceString(String$, StringToFind$, ReplacementString$ [, Mode [, StartPosition [, NbOccurrences]]])
And best of all RegularExpression (not easy to use in PB like in Perl, but work fine and faster than String)
http://www.purebasic.com/documentation/ ... index.html
You can read all bytes in a text file in one time, and whatever content (Ascii, Unicode, UTF-8)
and put it in a string
http://www.purebasic.com/documentation/ ... ddata.html
PS. HTML does not care about CR/LF except in <PRE></PRE>

(like s/// in Perl)
There are many functions to manipulate Strings
http://www.purebasic.com/documentation/ ... index.html
ReplaceString() eq s///
http://www.purebasic.com/documentation/ ... tring.html
String$ = ReplaceString(String$, StringToFind$, ReplacementString$ [, Mode [, StartPosition [, NbOccurrences]]])
And best of all RegularExpression (not easy to use in PB like in Perl, but work fine and faster than String)
http://www.purebasic.com/documentation/ ... index.html
Not the only way.... reading strings from a text file line by line would be the way to go ...
You can read all bytes in a text file in one time, and whatever content (Ascii, Unicode, UTF-8)
and put it in a string
http://www.purebasic.com/documentation/ ... ddata.html
PS. HTML does not care about CR/LF except in <PRE></PRE>

Re: Using PureBasic to create websites?
Some comments...
1. Perl has more advanced string processing built in, but PureBasic is absolutely up to this task. The code just might be more verbose.
2. You can hard-code your HTML strings into the PB code to get it up and running, but I would 100% advise you move it into external files. It would eliminate the issues of escaping quotes and linebreaks, it would be more versatile, and you wouldn't need to open/rebuild your PB program for every HTML change. You could edit these HTML templates in any editor like a regular webpage file.
3. You can read entire text files at once, instead of line by line, with ReadString(File, #PB_File_IgnoreEOL). You don't need to do ReadData() --> byte buffer --> string conversion.
4. PB doesn't automatically replace variables in strings like "$myTitle" but it's simple enough to use ReplaceString()
5. What you do need to remember is to escape characters like & < > in your text when filling in the HTML, such as & --> & . PB doesn't have built-in functions for this, but I'm sure there's plenty of example code around here.
1. Perl has more advanced string processing built in, but PureBasic is absolutely up to this task. The code just might be more verbose.
2. You can hard-code your HTML strings into the PB code to get it up and running, but I would 100% advise you move it into external files. It would eliminate the issues of escaping quotes and linebreaks, it would be more versatile, and you wouldn't need to open/rebuild your PB program for every HTML change. You could edit these HTML templates in any editor like a regular webpage file.
3. You can read entire text files at once, instead of line by line, with ReadString(File, #PB_File_IgnoreEOL). You don't need to do ReadData() --> byte buffer --> string conversion.
4. PB doesn't automatically replace variables in strings like "$myTitle" but it's simple enough to use ReplaceString()
5. What you do need to remember is to escape characters like & < > in your text when filling in the HTML, such as & --> & . PB doesn't have built-in functions for this, but I'm sure there's plenty of example code around here.
Re: Using PureBasic to create websites?
To clarify, the RegularExpression lib is many many times slower than PB code.Marc56us wrote:ReplaceString() eq s///
http://www.purebasic.com/documentation/ ... tring.html
String$ = ReplaceString(String$, StringToFind$, ReplacementString$ [, Mode [, StartPosition [, NbOccurrences]]])
And best of all RegularExpression (not easy to use in PB like in Perl, but work fine and faster than String)
http://www.purebasic.com/documentation/ ... index.html

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Using PureBasic to create websites?
Thanks guys. I'll have to experiment a little to see which commands work faster, but it's starting to look like a combination of external template files and string replacement is the way to go.
I may try a few of the XML functions too.
I'll likely avoid ReadData() as it needs an area of memory specified for storage and a length for the data to be read, which I probably won't know.
Although browsers don't care about newline characters in HTML, it would be a lot easier for me to find any errors in the created pages if they were there.
I may try a few of the XML functions too.
I'll likely avoid ReadData() as it needs an area of memory specified for storage and a length for the data to be read, which I probably won't know.
Although browsers don't care about newline characters in HTML, it would be a lot easier for me to find any errors in the created pages if they were there.
Re: Using PureBasic to create websites?
I've reached chapter 71 of the PDF version of the manual, so far. There are quite a few commands and functions that look like they would be useful. 
The more I think about this, the more likely it seems that the program could be useful to others. With that in mind, is there an obvious way to include a configuration file for the compiled program, that could be edited by users and have it contain comments (to explain what each setting is for)?

The more I think about this, the more likely it seems that the program could be useful to others. With that in mind, is there an obvious way to include a configuration file for the compiled program, that could be edited by users and have it contain comments (to explain what each setting is for)?
Re: Using PureBasic to create websites?
Hi wysardry,
http://www.purebasic.com/documentation/ ... index.html
Another way JSON files
http://www.purebasic.com/documentation/json/index.html
There are not many new users who read all the documentation from the beginning. Congratulations!wysardry wrote:I've reached chapter 71 of the PDF version of the manual, so far. There are quite a few commands and functions that look like they would be useful.
The classic and easy way: INI file with Preferencewysardry wrote:The more I think about this, the more likely it seems that the program could be useful to others. With that in mind, is there an obvious way to include a configuration file for the compiled program, that could be edited by users and have it contain comments (to explain what each setting is for)?
http://www.purebasic.com/documentation/ ... index.html
Another way JSON files
http://www.purebasic.com/documentation/json/index.html
Re: Using PureBasic to create websites?
there is a tool named jaPBdoc wich generates html documentation from purebasic source code comments:
http://www.purebasic.fr/english/viewtop ... 14&t=22605
http://www.purebasic.fr/english/viewtop ... 48#p487448 (latest version i know of)
it might be interesting for you to look at the code.
to get you started:
- there is a html template 'PBDoc.html'
- it gets included in the executable (in jaPBDoc.pb)
- it will be read into a string
- the content parts are built up using small hardcoded templates:
- and are then replaced into the final output
lexer.pbi (handles the parsing of the PB sourcecode that is to be documented) can be used for testing:
(or jaPBDoc.exe in Windows)
generates 'lexer.pbi.html'
http://www.purebasic.fr/english/viewtop ... 14&t=22605
http://www.purebasic.fr/english/viewtop ... 48#p487448 (latest version i know of)
it might be interesting for you to look at the code.
to get you started:
- there is a html template 'PBDoc.html'
- it gets included in the executable (in jaPBDoc.pb)
Code: Select all
DataSection
pbdoctemplate:
IncludeBinary "PBDoc.html"
endpbdoctemplate:
EndDataSection
Code: Select all
TemplateString = PeekS(?pbdoctemplate, ?endpbdoctemplate - ?pbdoctemplate, #PB_UTF8)
Code: Select all
Template = "<TR BGCOLOR="+#DQUOTE$+"white"+#DQUOTE$+"><TD><DL><DT>"
Template + "<code><b>%NAME%</b></code></DT><DD>%DESC%</DD><DL></TD></TR>"
...
Temp = ReplaceString(Template, "%NAME%", constant()\Name)
Temp = ReplaceString(Temp, "%DESC%", constant()\Desc)
Code: Select all
Temp = GetConstantsOverview()
Template = ReplaceString(Template, "%CONSTANTSDESCRIPTION%", Temp)
Code: Select all
./jaPBDoc lexer.pbi
generates 'lexer.pbi.html'
Re: Using PureBasic to create websites?
Marc56us: Thanks. It looks like the preferences option would be the easiest to understand (for me and other users). Being able to write comments in the file from within the program is a handy feature.
I am starting to skip parts of the manual now, if they don't seem relevant or are too advanced, but I am at least reading what each command or function does, so I know what options there are. I will probably skip the 3D engine commands when I reach them, as I can't see me using them any time soon.
#NULL: Thanks. I'll take a closer look at the code once I've read more of the manual. It will be easier for me to understand what the program is doing that way. I do have experience of other versions of BASIC, but PureBasic does some things differently.
I think flat file databases will be heavily involved.
I am starting to skip parts of the manual now, if they don't seem relevant or are too advanced, but I am at least reading what each command or function does, so I know what options there are. I will probably skip the 3D engine commands when I reach them, as I can't see me using them any time soon.
#NULL: Thanks. I'll take a closer look at the code once I've read more of the manual. It will be easier for me to understand what the program is doing that way. I do have experience of other versions of BASIC, but PureBasic does some things differently.
I think flat file databases will be heavily involved.
Re: Using PureBasic to create websites?
I've read a little more of the manual and am now thinking that using SQLite to store most of the data would be a good move.
I haven't yet decided whether to store the HTML for each post in the database too, as I'm not sure whether people would need an option to edit them in an external HTML editor. I do want the page templates to be actual files though, as creating or modifying "themes" would be easier that way.
Is it possible to create complex editor interfaces in PureBasic? I'm thinking of something along the lines of Bluefish or Thingamablog as writing posts and interacting with a database via a command line program would be a pain.
The closest thing I've done before is creating online form interfaces in Perl and HTML.
I haven't yet decided whether to store the HTML for each post in the database too, as I'm not sure whether people would need an option to edit them in an external HTML editor. I do want the page templates to be actual files though, as creating or modifying "themes" would be easier that way.
Is it possible to create complex editor interfaces in PureBasic? I'm thinking of something along the lines of Bluefish or Thingamablog as writing posts and interacting with a database via a command line program would be a pain.
The closest thing I've done before is creating online form interfaces in Perl and HTML.
Re: Using PureBasic to create websites?
Purebasic IDE itself is made in PB (with it's quite complex UI).wysardry wrote: Is it possible to create complex editor interfaces in PureBasic? I'm thinking of something along the lines of Bluefish or Thingamablog as writing posts and interacting with a database via a command line program would be a pain.
The closest thing I've done before is creating online form interfaces in Perl and HTML.
The other most complex UI I've seen on PB is example by Andre, included into this stuff ( http://www.purebasic.fr/english/viewtop ... 12&t=65330 )
Or saying shortly, surely that's possible ^^ But using for that raw built-in library and form designer probably will be painful.
At least I've quickly tired from that and created also dialogs-based stuff for myself
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Re: Using PureBasic to create websites?
Thanks. The Dynamic Dialogues module in that thread looks like it would make the process easier. I'm not sure if any of my screens will need to have quite so many different types of input areas as in Andre's example, but overall the total might well be similar.
I haven't yet decided whether to include a WYSIWYG HTML editor screen, as I've always found them to be restrictive, but buttons to insert a range of different HTML tags would be useful.
I'm guessing that PureBasic doesn't have any HTML code syntax highlighting options as standard.
I haven't yet decided whether to include a WYSIWYG HTML editor screen, as I've always found them to be restrictive, but buttons to insert a range of different HTML tags would be useful.
I'm guessing that PureBasic doesn't have any HTML code syntax highlighting options as standard.