1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? generating html tables

Discussion in 'T&T - Scripting' started by Frank, Feb 3, 2012.

  1. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    I'm not a web-designer, but sometimes I wanna create html-tables with tcc.
    Here I show you how I do it.
    If anyone has a better idea or technique, please let me know.
    Also suggestions and critique is appeciated ;)

    Code:
    @echo    off
    setlocal
     
    set    fontsize=-1
    set    outfile=disk-report.html
     
    setdos    /x-6
    set    fh=%@fileopen[%outfile,write,t]
    set    rc=%@filewrite[%fh,<html>]
    set    rc=%@filewrite[%fh,<body>]
    set    rc=%@filewrite[%fh,<h2>Disk Usage on %computername</h2>]
    set    rc=%@filewrite[%fh,<h4>as of: %_isodate, %_time</h4>]
    set    rc=%@filewrite[%fh,<table border="1" cellspacing="10" cellpadding="20">]
    set    rc=%@filewrite[%fh,<tr><th>Disk</th>]
    set    rc=%@filewrite[%fh,<th>Disk Name</th>]
    set    rc=%@filewrite[%fh,<th>Capacity</th>]
    set    rc=%@filewrite[%fh,<th>Space Used</th>]
    set    rc=%@filewrite[%fh,<th>Space Free</th>]
    set    rc=%@filewrite[%fh,<th>Pct in Use</th></tr>]
    set    rc=%@filewrite[%fh,<tbody align="center">]
    setdos    /x0
     
    do    drive in /l %_drives
     
        iff    %@ready[%drive] eq 1 .and. %@remote[%drive] eq 0 then
       
            set    disklabel=%@label[%drive]
            set    disktotal=%@comma[%@disktotal[%drive,M]]
            set    diskused=%@comma[%@diskused[%drive,M]]
            set    diskfree=%@comma[%@diskfree[%drive,M]]
            set    diskpctused=%@eval[ 100-(%diskfree / %disktotal*100=0) ]
            setdos    /x-6
            set    rc=%@filewrite[%fh,<tr><td><font size="%fontsize">%drive</font></td>    %=
            <td><font size="%fontsize">%disklabel</font></td>    %=
            <td><font size="%fontsize">%disktotal</font></td>    %=
            <td><font size="%fontsize">%diskused</font></td>    %=
            <td><font size="%fontsize">%diskfree</font></td>    %=
            <td><font size="%fontsize">%[diskpctused]%%</font></td></tr>]
            setdos    /x0
        endiff
    enddo
     
    setdos    /x-6
    set    rc=%@filewrite[%fh,</tbody>]
    set    rc=%@filewrite[%fh,</table>]
    set    rc=%@filewrite[%fh,<p><br>&copy; Frank</p>]
    set    rc=%@filewrite[%fh,</body>]
    set    rc=%@filewrite[%fh,</html>]
    setdos    /x0
     
    set    rc=%@fileclose[%fh]
     
    start    %outfile
    endlocal
    quit
    
    regards
    Frank
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,307
    Likes Received:
    39
    The last time I worked on my HTags plugin, I added a command to dump a TCC array to stdout as an HTML table: http://www.unm.edu/~cdye/plugins/htags.html#arraytable

    If you'd prefer a 'pure' approach, using only internal commands, you might look into here-document redirection. You can put multiple lines of HTML in a here-document, and less-than and greater-than signs won't be an issue because those lines are never interpreted as commands. You can even use variables and functions; they will be expanded when the text is read.
     
  3. Frank

    Joined:
    Aug 2, 2011
    Messages:
    258
    Likes Received:
    4
    thank you for now, but I have to leave now. I will have a look at it later.

    ....
    Today I finally could give it a try.
    Charles, your plugin is really cool and in this case "Arraytable" would be the one.
    But if ever possible I want to keep it simple and use the buildin commands and make it work even with LE.

    So here is my new code, which is much better "human readeable" than the one before:
    Code:
    @echo    off
    setlocal
     
    set    fontsize=-1
    set    outfile=disk-report.html
     
    rem    with linux-like "Here-document" redirection
     
    type > %outfile <<- endofinput
        <html>
        <body>
        <h2>Disk Usage on %computername</h2>
        <h4>as of: %_isodate, %_time</h4>
        <table border="1" cellspacing="10" cellpadding="20">
        <tr><th>Disk</th>
        <th>Disk Name</th>
        <th>Capacity</th>
        <th>Space Used</th>
        <th>Space Free</th>
        <th>Pct in Use</th></tr>
        <tbody align="center">
    endofinput
     
    do    drive in /l %_drives
     
        iff    %@ready[%drive] eq 1 .and. %@remote[%drive] eq 0 then
     
            set    disklabel=%@label[%drive]
            set    disktotal=%@comma[%@disktotal[%drive,M]]
            set    diskused=%@comma[%@diskused[%drive,M]]
            set    diskfree=%@comma[%@diskfree[%drive,M]]
            set    diskpctused=%@eval[ 100-(%diskfree / %disktotal*100=0) ]
         
            type >> %outfile <<- endofinput
                <tr><td><font size="%fontsize">%drive</font></td>
                <td><font size="%fontsize">%disklabel</font></td>
                <td><font size="%fontsize">%disktotal</font></td>
                <td><font size="%fontsize">%diskused</font></td>
                <td><font size="%fontsize">%diskfree</font></td>
                <td><font size="%fontsize">%[diskpctused]%%</font></td></tr>
            endofinput
     
        endiff
     
    enddo
     
    type >> %outfile <<- endofinput
        </tbody>
        </table>
        <br><p>&copy; Frank</p>
        </body>
        </html>
    endofinput
     
    endlocal
    quit
    Thank's for your tipp, Charles and thank you Rex for programming such a vast amount of features and functions. It's really a gift.

    regards
    Frank

     

Share This Page