• TYPEHTML.SRC

    From Digital Man@VERT to All on Mon Oct 9 07:41:00 2000
    I'm converting my "working documents" for Synchronet (to-do list, FAQs, etc) to HTML and needed an easy way to "share" these files with the users on the BBS, without requiring them to download them and view them in a web browser.

    So, I spent "some time" today creating this little "diddy" in Baja and just thought I'd post the source here since it's probably the most intense Baja coding I've done since QNET.SRC (QWK networking module for SBBS v2). I'll be putting this on Vertrauen for download too.

    It only handles BASIC HTML right now, so don't be too shocked if it doesn't print your more elaborate HTML files very nicely. Obviously, things like graphics and fonts can't be well represented on a typical telnet terminal. (HTML to RIP anyone?)

    Well, here it is:

    # TypeHTML

    # Synchronet Baja Modules to Display HTML files to TTY/ANSI users

    # Created October 09, 2000 by Rob Swindell

    !include file_io.inc
    !include sbbsdefs.inc

    # Color Attributes for HTML type styles
    !define NORMAL "\1N\1H"
    !define HEADING1 "\1H\1Y"
    !define HEADING2 "\1H\1C"
    !define HEADING3 "\1H\1M"
    !define HEADING4 "\1H\1G"
    !define HEADING5 "\1H\1B"
    !define HEADING6 "\1H\1R"
    !define BOLD "\1H\1C\x014"
    !define ITALIC "\1H\1G\x012"
    !define UNDERLINE "\1H\1W\x016"
    !define STRIKE_THROUGH "\1N\1K\x017"
    !define LIST_ITEM " \1H\1Wo \1G"

    str filename
    str href
    str tmp
    int i
    int file
    int hlevel # header level
    int col # current cursor column
    int last_line_len # length of last line printed
    int lines # total lines printed
    int printing # printing on
    int newline # new line read from html file

    copy filename str

    compare_str ""
    if_true
    print "usage: *typehtml <filename>"
    return
    end_if

    fopen file O_RDONLY|O_DENYNONE filename
    if_false
    printf "!Error %d opening %s\r\n" _ERRNO filename
    return
    end_if

    set col 0 # reset column counter
    set last_line_len 0 # reset last line length
    set lines 0 # reset line counter
    set printing 1 # printing by default
    cls # clear screen
    print NORMAL # normal color

    :next_line

    # Check abort flag
    copy i _sys_status
    and i SS_ABORT
    compare i 0
    if_not_equal # user aborting listing
    return
    end_if

    # Read a line
    fread_line file str
    if_false # end of file
    crlf
    pause
    return
    end_if

    set newline 1

    # truncate whitespace
    strip_ctrl str
    :skip_whitespace
    compare_word " "
    if_false
    compare_word "\t"
    end_if
    if_true
    shift_str 1
    goto skip_whitespace
    end_if

    :next_char
    compare_str ""
    if_true
    goto next_line
    end_if
    sprintf tmp "%.1s" str
    shift_str 1
    compare tmp "<"
    if_false
    compare printing 1
    if_true
    # handle word wrap
    compare newline 1
    if_equal
    compare col 0
    if_not_equal
    print " "
    add col 1
    end_if
    end_if
    set newline 0

    # don't start lines with white-space
    compare col 0
    if_true
    compare tmp " "
    end_if
    if_false
    print tmp
    add col 1
    compare col 79
    if_greater_or_equal
    call crlf
    end_if
    end_if
    end_if
    goto next_char
    end_if

    # Title
    compare_word "TITLE>"
    if_true
    set printing 0
    call find_close_bracket
    goto next_char
    end_if
    compare_word "/TITLE>"
    if_true
    set printing 1
    call find_close_bracket
    goto next_char
    end_if


    # List item
    compare_word "LI>"
    if_false
    compare_word "LI "
    end_if
    if_true
    compare col 0
    if_not_equal
    call crlf
    end_if
    printf LIST_ITEM
    set col 6
    call find_close_bracket
    goto next_char
    end_if

    # Strike-through
    compare_word "S>"
    if_false
    compare_word "STRIKE>"
    end_if
    if_true
    printf STRIKE_THROUGH
    call find_close_bracket
    goto next_char
    end_if

    # Bold
    compare_word "B>"
    if_false
    compare_word "STONG>"
    end_if
    if_true
    printf BOLD
    call find_close_bracket
    goto next_char
    end_if

    # Italics
    compare_word "I>"
    if_false
    compare_word "EM>"
    end_if
    if_true
    printf ITALIC
    call find_close_bracket
    goto next_char
    end_if

    # Underline
    compare_word "U>"
    if_false
    compare_word "U>"
    end_if
    if_true
    printf UNDERLINE
    call find_close_bracket
    goto next_char
    end_if


    # Attribute off
    compare_word "/S>"
    if_false
    compare_word "/STRIKE>"
    end_if
    if_false
    compare_word "/B>"
    end_if
    if_false
    compare_word "/STONG>"
    end_if
    if_false
    compare_word "/I>"
    end_if
    if_false
    compare_word "/EM>"
    end_if
    if_false
    compare_word "/U>"
    end_if
    if_true
    print NORMAL
    call find_close_bracket
    goto next_char
    end_if

    # Table cell
    compare_word "TD>"
    if_false
    compare_word "TD "
    end_if
    if_true
    # visually separate cells
    compare col 0
    if_greater
    print " "
    add col 1
    end_if
    call find_close_bracket
    goto next_char
    end_if


    # Dumb CR/LF block
    compare_word "BR>"
    if_false
    compare_word "BR "
    end_if
    if_false
    compare_word "P>"
    end_if
    if_false
    compare_word "P "
    end_if
    if_false
    compare_word "TR>"
    end_if
    if_false
    compare_word "TR "
    end_if
    if_true
    call crlf
    call find_close_bracket
    goto next_char
    end_if


    # Intelligent CR/LF block (force single blank line)
    compare_word "/UL>"
    if_false
    compare_word "/OL>"
    end_if
    if_false
    compare_word "/DIR>"
    end_if
    if_false
    compare_word "/MENU>"
    end_if
    if_true
    print NORMAL
    end_if
    if_false
    compare_word "H"
    if_true
    shift_str 1
    copy hlevel str
    compare hlevel 0
    if_greater
    switch hlevel
    case 1
    print HEADING1
    end_case
    case 2
    print HEADING2
    end_case
    case 3
    print HEADING3
    end_case
    case 4
    print HEADING4
    end_case
    case 5
    print HEADING5
    end_case
    default
    print HEADING6
    end_case
    end_switch
    setlogic TRUE
    else
    setlogic FALSE
    end_if
    end_if
    end_if
    if_false
    compare_word "/H"
    if_true
    shift_str 2
    copy hlevel str
    compare hlevel 0
    if_greater
    print NORMAL
    setlogic TRUE
    else
    setlogic FALSE
    end_if
    end_if
    end_if
    if_true
    compare lines 0
    if_equal
    compare col 0
    end_if
    if_greater
    compare last_line_len 0
    if_equal
    compare col 0
    end_if
    if_not_equal
    call crlf
    call crlf
    end_if
    end_if
    call find_close_bracket
    goto next_char
    end_if

    # Hyper-link
    compare_word "A HREF="
    if_true
    shift_str 7
    set href ""
    :copy_href
    sprintf tmp "%.1s" str
    compare tmp ">"
    if_false
    shift_str 1
    strcat href tmp
    goto copy_href
    end_if
    end_if

    # Show hyper-link
    compare_word "/A>"
    if_true
    compare href ""
    if_false
    strlen i href
    add i 3
    add col i
    compare col 79
    if_equal_or_greater
    call crlf
    sub i 1
    copy col i
    else
    print " "
    end_if
    printf "<%s>" href
    end_if
    set href ""
    end_if

    call find_close_bracket
    goto next_char

    return

    # Carriage-return/Line-feed with column reset
    :crlf
    copy last_line_len col
    crlf
    set col 0
    add lines 1
    return

    # Shift str past first close bracket
    :find_close_bracket
    compare_str ""
    if_true
    return
    end_if

    sprintf tmp "%.1s" str
    shift_str 1
    compare tmp ">"
    if_false
    goto find_close_bracket
    end_if
    return

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Amcleod@VERT to Digital Man on Tue Oct 10 20:50:00 2000
    RE: TYPEHTML.SRC
    BY: Digital Man to All on Mon Oct 09 2000 06:41 pm

    So, I spent "some time" today creating this little "diddy" in Baja and just thought I'd post the source here since it's probably the most intense Baja coding I've done since QNET.SRC (QWK networking module for SBBS v2). I'll be putting this on Vertrauen for download too.

    Any reason why I can't FTP this file?

    I can't seem to get Z-Modem working on this box, and when I tried to connect to the FTP server it kept refusing to allow me online. I get "530 not logged in" as soon as I put in the password.

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Digital Man@VERT to Amcleod on Wed Oct 11 00:54:00 2000
    RE: TYPEHTML.SRC
    BY: Amcleod to Digital Man on Wed Oct 11 2000 07:50 am

    RE: TYPEHTML.SRC
    BY: Digital Man to All on Mon Oct 09 2000 06:41 pm

    So, I spent "some time" today creating this little "diddy" in Baja and ju thought I'd post the source here since it's probably the most intense Baj coding I've done since QNET.SRC (QWK networking module for SBBS v2). I'll putting this on Vertrauen for download too.

    Any reason why I can't FTP this file?

    I can't seem to get Z-Modem working on this box, and when I tried to connect the FTP server it kept refusing to allow me online. I get "530 not logged i as soon as I put in the password.

    I don't know. Other people (and myself) have been able to login just fine. Is it possible you forgot the "user" command?

    Rob

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Amcleod@VERT to Digital Man on Wed Oct 11 02:31:00 2000
    RE: TYPEHTML.SRC
    BY: Digital Man to Amcleod on Wed Oct 11 2000 11:54 am

    Any reason why I can't FTP this file?

    I don't know. Other people (and myself) have been able to login just fine. I it possible you forgot the "user" command?

    alfred:~$ ftp ftp.synchro.net
    Connected to www.synchro.net.
    220 Serv-U FTP-Server v2.5a for WinSock ready...
    Name (ftp.synchro.net:amcleod): amcleod
    331 User name okay, need password.
    Password:
    530 Not logged in.
    Login failed.
    Remote system type is UNIX.
    Using binary mode to transfer files.
    ftp> ls
    530 Not logged in.
    ftp: bind: Address already in use
    ftp> bye
    221 Goodbye!
    alfred:~$

    I don't know what to make of it. The PW is not shown because it doesn't
    echo. I am _sure_ I'm getting it right - I've tried maybe 20 times, and I've used various capitalization on the username and the password. Wait, let me try something:

    Okay! I can get onto vert.synchro.net but not ftp.synchro.net for some reason. Let me try something else:

    Hehehe! :) <-- red face! Okay, so if I use anonymous FTP then I get on
    to ftp.synchro.net without problems. Sorry about that - I guess I need more sleep or something...

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Digital Man@VERT to Amcleod on Wed Oct 11 07:33:00 2000
    RE: TYPEHTML.SRC
    BY: Amcleod to Digital Man on Wed Oct 11 2000 01:31 pm

    Any reason why I can't FTP this file?

    I don't know. Other people (and myself) have been able to login just fine it possible you forgot the "user" command?

    alfred:~$ ftp ftp.synchro.net

    Yeah, wrong hostname. :-)

    Rob

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Plunder Point@VERT/CANNONIA to Digital Man on Fri Oct 13 13:54:00 2000
    RE: TYPEHTML.SRC
    BY: Digital Man to All on Mon Oct 09 2000 06:41 pm

    I had to change line 44 of TYPEHTML.SRC to:

    fopen file O_RDONLY|O_DENYNONE filename

    to make it compile without an error. Was that a typo on your part, or do I have an outdated version of the BAJA compiler that just wouldn't accept what you had in your source code?

    ---
    þ Synchronet þ Cannonia BBS - cannonia.darktech.org:5003
  • From Amcleod@VERT to Plunder Point on Fri Oct 13 21:28:00 2000
    RE: TYPEHTML.SRC
    BY: Plunder Point to Digital Man on Sat Oct 14 2000 12:54 am

    I had to change line 44 of TYPEHTML.SRC to:

    fopen file O_RDONLY|O_DENYNONE filename

    to make it compile without an error......

    Duuuh... You changed it

    FROM: fopen file O_RDONLY|O_DENYNONE filename
    TO: fopen file O_RDONLY|O_DENYNONE filename

    And it corrected the error??? Mow THAT is a feat of debugging skill, the likes of which has not been seen for many a day.....

    How long did it take you to figure out the changes?

    Digital Man: SHAME on you for leaving such an obvious bug in your code! ;-)

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Plunder Point@VERT/CANNONIA to Amcleod on Sat Oct 14 15:53:00 2000
    RE: TYPEHTML.SRC
    BY: Amcleod to Plunder Point on Sat Oct 14 2000 08:28 am

    RE: TYPEHTML.SRC
    BY: Plunder Point to Digital Man on Sat Oct 14 2000 12:54 am

    I had to change line 44 of TYPEHTML.SRC to:

    fopen file O_RDONLY|O_DENYNONE filename

    to make it compile without an error......

    Duuuh... You changed it

    FROM: fopen file O_RDONLY|O_DENYNONE filename
    TO: fopen file O_RDONLY|O_DENYNONE filename

    And it corrected the error??? Mow THAT is a feat of debugging skill, the li of which has not been seen for many a day.....

    How long did it take you to figure out the changes?

    Digital Man: SHAME on you for leaving such an obvious bug in your code! ;-)

    Typo on my part. I had to change it to:

    fopen file O_RDONLY|O_DENYNONE filename

    to make it compile.

    ---
    þ Synchronet þ Cannonia BBS - cannonia.darktech.org:5003
  • From Plunder Point@VERT/CANNONIA to Plunder Point on Sun Oct 15 02:53:00 2000
    RE: TYPEHTML.SRC
    BY: Plunder Point to Amcleod on Sun Oct 15 2000 02:53 am

    fopen file O_RDONLY|O_DENYNONE filename

    That's O_RDONLY followed by a pipe and then O_DENYNONE. Apparently the pipe gets itself garbled when posted here? That would explain it.

    ---
    þ Synchronet þ Cannonia BBS - cannonia.darktech.org:5003
  • From Digital Man@VERT to Plunder Point on Sun Oct 15 11:58:00 2000
    RE: TYPEHTML.SRC
    BY: Plunder Point to Digital Man on Sat Oct 14 2000 12:54 am

    I had to change line 44 of TYPEHTML.SRC to:

    fopen file O_RDONLY|O_DENYNONE filename

    to make it compile without an error. Was that a typo on your part, or do I have an outdated version of the BAJA compiler that just wouldn't accept what you had in your source code?

    You probalby have Celerity or Renegade color codes enabled on your system, in which case the "pipe" symbol gets eaten.

    Rob

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Amcleod@VERT to Plunder Point on Sun Oct 15 18:06:00 2000
    RE: TYPEHTML.SRC
    BY: Plunder Point to Plunder Point on Sun Oct 15 2000 01:53 pm

    fopen file O_RDONLY|O_DENYNONE filename

    That's O_RDONLY followed by a pipe and then O_DENYNONE. Apparently the pipe gets itself garbled when posted here? That would explain it.

    I'm seeing a pipe in the original and in both your "corrections". Hmmm I wonder if those pesky colour codes (is it WWIV?) are to blame?

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Digital Man@VERT to Amcleod on Mon Oct 16 01:08:00 2000
    RE: TYPEHTML.SRC
    BY: Amcleod to Plunder Point on Mon Oct 16 2000 05:06 am

    fopen file O_RDONLY|O_DENYNONE filename

    That's O_RDONLY followed by a pipe and then O_DENYNONE. Apparently the p gets itself garbled when posted here? That would explain it.

    I'm seeing a pipe in the original and in both your "corrections". Hmmm I wonder if those pesky colour codes (is it WWIV?) are to blame?

    They're Celerity and Renegade color codes, and I have them disabled here on Vertrauen. :-)

    Rob

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Amcleod@VERT to Digital Man on Mon Oct 16 09:09:00 2000
    RE: TYPEHTML.SRC
    BY: Digital Man to Amcleod on Mon Oct 16 2000 12:08 pm

    fopen file O_RDONLY|O_DENYNONE filename

    That's O_RDONLY followed by a pipe and then O_DENYNONE. Apparently th gets itself garbled when posted here? That would explain it.

    I'm seeing a pipe in the original and in both your "corrections". Hmmm I wonder if those pesky colour codes (is it WWIV?) are to blame?

    They're Celerity and Renegade color codes, and I have them disabled here on Vertrauen. :-)

    I seem to recall doing O_RDONLY+O_DENYNONE instead of O_RDONLY|O_DENYNONE in the past to avoid this problem. It isn't exactly perfect but it _usually_ works, so long as the items you are ORing are single-bit-on values...

    Pity you can't do <code><pre>Yada Yada</pre></code> eh? At least, not YET...

    :)

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net
  • From Plunder Point@VERT/CANNONIA to Digital Man on Mon Oct 16 12:15:00 2000
    RE: TYPEHTML.SRC
    BY: Digital Man to Amcleod on Mon Oct 16 2000 12:08 pm

    They're Celerity and Renegade color codes, and I have them disabled here on Vertrauen. :-)
    And they're going to be disabled here on Cannonia in just a few minutes... Sorry to bother you with a typo that didn't really exist. :)

    ---
    þ Synchronet þ Cannonia BBS - cannonia.darktech.org:5003
  • From Reaper Man@VERT/FLAMINT to Amcleod on Wed Oct 18 07:40:00 2000
    RE: TYPEHTML.SRC
    BY: Amcleod to Plunder Point on Sat Oct 14 2000 08:28:00

    FROM: fopen file O_RDONLY|O_DENYNONE filename
    TO: fopen file O_RDONLY|O_DENYNONE filename

    And it corrected the error??? Mow THAT is a feat of debugging skill, the li of which has not been seen for many a day.....

    How long did it take you to figure out the changes?

    Digital Man: SHAME on you for leaving such an obvious bug in your code! ;-)

    agghhh, i can't see a difference, oh my god I'm going blind!!!!

    ---
    þ Synchronet þ Flamin' Torch BBS - Fired Up and ready to go flamint.dyndns.org
  • From Reaper Man@VERT/FLAMINT to Plunder Point on Wed Oct 18 07:42:00 2000
    RE: TYPEHTML.SRC
    BY: Plunder Point to Plunder Point on Sun Oct 15 2000 13:53:00

    fopen file O_RDONLY|O_DENYNONE filename

    That's O_RDONLY followed by a pipe and then O_DENYNONE. Apparently the pipe gets itself garbled when posted here? That would explain it.

    oh god, i was gettin' really worried there for a minute.

    ---
    þ Synchronet þ Flamin' Torch BBS - Fired Up and ready to go flamint.dyndns.org