Computer Science Canada

Web Browser

Author:  DanTheMan [ Sun Jun 14, 2009 5:31 pm ]
Post subject:  Web Browser

Hi, DanTheMan here with another question... is it possible to modify Turing code to become a simple web browser? if so, could you post codes?

Just for the record, this is not a school project. This is just curiosity.

Author:  andrew. [ Sun Jun 14, 2009 5:42 pm ]
Post subject:  RE:Web Browser

A while ago I made a Turing program that goes to a web address and gets the html. I forgot what how I did it though and it's not on this computer so I can't really help. But once you figure out how to download the html, you can make your own engine to render the pages.

BTW, I wouldn't recommend doing this. It will not work properly, it's a lot of work, and it won't even compare to any real web browsers.

If you meant like embedding an IE webpage in your program, then no you can't do that.

Author:  DtY [ Sun Jun 14, 2009 6:28 pm ]
Post subject:  Re: RE:Web Browser

andrew. @ Sun Jun 14, 2009 5:42 pm wrote:
If you meant like embedding an IE webpage in your program, then no you can't do that.

I'd bet you could. IE is built right into windows, and I'm pretty sure any program can attach an IE window into any other window. You'd have to write a C# program or something though, and start it with Sys.Exec()

Author:  ecookman [ Mon Jun 15, 2009 7:15 am ]
Post subject:  RE:Web Browser

I found some turing programs that do stuff over the local network (a chatroom i forget by who)

Although it works, it is painfully slow. Trying to make a webbrowser it might work, but it will probaly be so slow you'd think you are on dialup when it first came out on a computer with 2kb or ram.

If you are trying to get rid of the (i have) Bess block or website block, a browser change won't do it.

Author:  Tony [ Mon Jun 15, 2009 12:12 pm ]
Post subject:  RE:Web Browser

as it was mentioned, you could use Net module to download web pages, and then interpret them in a way that you want. Turing's Net is known to be buggy and/or slow, so a faster alternative might be to use something like curl to fetch the content, and then read from a local file.

Author:  DanTheMan [ Tue Jun 16, 2009 8:50 am ]
Post subject:  RE:Web Browser

Well... I dunno what to say...

Author:  andrew. [ Tue Jun 16, 2009 3:45 pm ]
Post subject:  Re: RE:Web Browser

DtY @ Sun Jun 14, 2009 6:28 pm wrote:
andrew. @ Sun Jun 14, 2009 5:42 pm wrote:
If you meant like embedding an IE webpage in your program, then no you can't do that.

I'd bet you could. IE is built right into windows, and I'm pretty sure any program can attach an IE window into any other window. You'd have to write a C# program or something though, and start it with Sys.Exec()
Yeah, but then you'd be running a C# program not a Turing one. I think he wanted to have IE in his actual Turing run window.

Author:  DtY [ Tue Jun 16, 2009 6:29 pm ]
Post subject:  Re: RE:Web Browser

andrew. @ Tue Jun 16, 2009 3:45 pm wrote:
DtY @ Sun Jun 14, 2009 6:28 pm wrote:
andrew. @ Sun Jun 14, 2009 5:42 pm wrote:
If you meant like embedding an IE webpage in your program, then no you can't do that.

I'd bet you could. IE is built right into windows, and I'm pretty sure any program can attach an IE window into any other window. You'd have to write a C# program or something though, and start it with Sys.Exec()
Yeah, but then you'd be running a C# program not a Turing one. I think he wanted to have IE in his actual Turing run window.

That's what I'm talking about, I think you can make a program attach an IE frame in any window (even ones that program didn't create).

I remember a stealth program that would put one in whatever window was active, that you could hide with a quick key stroke. The name escapes me though.

Author:  DanTheMan [ Tue Jun 16, 2009 6:30 pm ]
Post subject:  RE:Web Browser

Either that, or just a turing window that has a web address bar that you can type into and open up the page in a web browser.

Author:  DtY [ Tue Jun 16, 2009 6:34 pm ]
Post subject:  Re: RE:Web Browser

DanTheMan @ Tue Jun 16, 2009 6:30 pm wrote:
Either that, or just a turing window that has a web address bar that you can type into and open up the page in a web browser.

Hmm.. To open a page in a webbrowser, try:
Turing:
Sys.Exec("URL of webpage")

That might work (Can't remember if windows associates web addresses with the browser), if not it might be:
Turing:
Sys.Exec("explorer.exe 'path to webpage'")


[edit] The first should work, that's one of the examples on the help page: http://compsci.ca/holtsoft/doc/sys_exec.html

Author:  Dan [ Tue Jun 16, 2009 9:30 pm ]
Post subject:  Re: RE:Web Browser

[quote="DtY @ 16th June 2009, 6:29 pm"][quote="andrew. @ Tue Jun 16, 2009 3:45 pm"]
DtY @ Sun Jun 14, 2009 6:28 pm wrote:

I'd bet you could. IE is built right into windows, and I'm pretty sure any program can attach an IE window into any other window.


Turing lacks any access to the windows or IE API so it can not attach an IE window only open one but thats rather pointless (as you could open it in firefox or there default browser the same way).

Turing would still have no access to any of the content or pages being viewed in the browser and by no means would it be a web browser in Turing. It could be good to spam the user into viewing your webpage but it's not very partical for anything else.

Author:  DtY [ Wed Jun 17, 2009 6:23 am ]
Post subject:  Re: RE:Web Browser

[quote="Dan @ Tue Jun 16, 2009 9:30 pm"][quote="DtY @ 16th June 2009, 6:29 pm"]
andrew. @ Tue Jun 16, 2009 3:45 pm wrote:
DtY @ Sun Jun 14, 2009 6:28 pm wrote:

I'd bet you could. IE is built right into windows, and I'm pretty sure any program can attach an IE window into any other window.


Turing lacks any access to the windows or IE API so it can not attach an IE window only open one but thats rather pointless (as you could open it in firefox or there default browser the same way).

Which is why, if you could do it, you'd have to write it in another language, and start it with Sys.Exec()

Author:  DanTheMan [ Wed Jun 17, 2009 11:33 am ]
Post subject:  RE:Web Browser

I just got an idea.

What I needed to do was just print the HTML on turing, so I have to find a way to print it. I made a program that opens the file and prints it on the screen, but I need to make it recognise the tags and print them on the screen.

code:

var fileNo : int
var ch : char

open : fileNo, "HTML.txt", get
loop
    get : fileNo, ch
    put ch ..
    if eof (fileNo) then
        exit
    end if
end loop
close : fileNo

Author:  DtY [ Wed Jun 17, 2009 11:47 am ]
Post subject:  RE:Web Browser

If you want just very basic rendering, make it read until it gets to <body>, then print every character it does not between < and >.
Then, if you feel up to it, make <br> and <br /> end the line, <em> and <strong> change foreground colour, etc.

Author:  Dan [ Wed Jun 17, 2009 12:57 pm ]
Post subject:  Re: RE:Web Browser

DtY @ 17th June 2009, 6:23 am wrote:

Which is why, if you could do it, you'd have to write it in another language, and start it with Sys.Exec()


Witch makes the turing program just a short cut for a web broswer you wrote in another langue, you might as well skip turing all togther.


DanTheMan wrote:

What I needed to do was just print the HTML on turing, so I have to find a way to print it. I made a program that opens the file and prints it on the screen, but I need to make it recognise the tags and print them on the screen.


Going from HTML to the visual rendering you get with a browser is not a trival problem and would be a masive undertaking even for a basic text based browser.

If you realy want to make your own web broswer i recomend ditching turing and going to a langue that can use permade web browser engines like WebKit.

Author:  DanTheMan [ Thu Jun 18, 2009 8:22 am ]
Post subject:  Re: RE:Web Browser

DtY @ Wed Jun 17, 2009 11:47 am wrote:
If you want just very basic rendering, make it read until it gets to <body>, then print every character it does not between < and >.
Then, if you feel up to it, make <br> and <br /> end the line, <em> and <strong> change foreground colour, etc.


I... have no idea how :\

Author:  DtY [ Thu Jun 18, 2009 9:23 am ]
Post subject:  RE:Web Browser

Hmm.. I'm sure there is a better way, but it could be done something like this:

code:
var inBody  = False (If we've made it to the body yet)
var inTag   = False (If we're inside the definition of a tag; between < and >)
var lastTag = "" (The last tag we got to)

for each character in the source as chr; do
    if chr is '<' then
        inTag = True
    else if chr is '>' then
        inTag = False
        if lastTag is "body" then
            inBody = True
        else if lastTag is "em" then
            change FG/BG colour for emphasis
        elsif lastTag is "/em" then
            change FG/BG back to normal to end emphasis
        end
        lastTag = "" (Clear last tag)
    else if inBody (Only do this if we're in the body)
        if chr is '&' then
            (this is the start of an HTML Entity, the next few character represent
            a single character, for example: &copy; means ?)
            var txt = ""
            read characters until a ';' is found, add each character to txt
            Use a switch or something to convert txt into a single character, the output
            it
        else (Just a normal character)
            if inTag then
                lastTag += chr
            else
                output the character
            end
        end
    end
done

(This is just a template, keep in mind, you'll need to add a lot more to be usable.

[edit] Fixed BBCode
[edit2] Changed [syntax] to [code]


: