Pick.To.HTML

From Pickwiki
Jump to navigationJump to search
*
* Sample the VOC, turning items into HTML rows, and attributes into HTML
columns. Write it to NTSHARE as an .html, then launch it through Accuterm
* Writen by Will Johnson, Fast Forward Technologies, [email protected]
* Creative Commons License, this notice must be present in all derivative
 works
*
      EQUATE FALSE TO 0, TRUE TO 1
      EQUATE STX TO CHAR(2), BS TO CHAR(8), TAB TO CHAR(9)
      EQUATE CR TO CHAR(13), EM TO CHAR(25), ESC TO CHAR(27)
*
*TO.FILE = Host file directory in which to put the file
*TO.ITEM = Name of item
*MAPPED.DRIVE = Directory or mapped location that in Windows
* puts you in same directory as TO.FILE
*
      GOSUB GET.PARAMETERS
      GOSUB OPEN.FILES
      GOSUB BUILD.OUTPUT
      SCRIPT = MAPPED.DRIVE:"\":TO.ITEM
      PRINT "Opening ":SCRIPT:" file"
      PRINT ESC:STX:'<':SCRIPT:CR
      STOP
*
GET.PARAMETERS:
      USER.ID = @LOGNAME
      IF INDEX(USER.ID,'\',1) THEN USER.ID = FIELD(USER.ID,'\',2)
*
      PRINT "Press the ENTER key to accept these default locations"
      TO.FILE = "NTSHARE.TEMP"
      PRINT "Directory to write result to: ":TO.FILE:
      PRINT STR(BS,LEN(TO.FILE)):
      INPUT NEW.TO.FILE
      IF NEW.TO.FILE # '' THEN TO.FILE = NEW.TO.FILE
*
      TO.ITEM = USER.ID:"_temp.html"
      PRINT "File to write result to: ":TO.ITEM:
      PRINT STR(BS,LEN(TO.ITEM)):
      INPUT NEW.TO.ITEM
      IF NEW.TO.ITEM # '' THEN TO.ITEM = NEW.TO.ITEM
*
      MAPPED.DRIVE = "M:\temp"
      PRINT "Mapped drive to write result to: ":MAPPED.DRIVE:
      PRINT STR(BS,LEN(MAPPED.DRIVE)):
      INPUT NEW.MAPPED.DRIVE
      IF NEW.MAPPED.DRIVE # '' THEN MAPPED.DRIVE = NEW.MAPPED.DRIVE
      RETURN
*
OPEN.FILES:
      OPEN "VOC" TO F.VOC ELSE
         PRINT "Cannot open VOC file.  Hit ENTER.":
         INPUT CONT ; STOP
      END
      IF TO.FILE = "NTSHARE.TEMP" THEN
         K.VOC = "NTSHARE.TEMP"
         READ R.VOC FROM F.VOC,K.VOC ELSE
            R.VOC = "F":@AM:"D:[[/RWC/ntshare/temp]]":@AM:"[[D_VOC]]"
            WRITE R.VOC ON F.VOC,K.VOC
         END
      END
      OPEN TO.FILE TO F.TO.FILE ELSE
         PRINT "Cannot open ":TO.FILE:" file.  Hit ENTER.":
         INPUT CONT ; STOP
      END
      RETURN
*
BUILD.OUTPUT:
      CNT = 0 ; DONE = FALSE ; SELECT F.VOC
      OUTPUT = '' ; S.COL = 1
      LOOP
         CNT += 1
         READNEXT K.VOC ELSE DONE = TRUE
      UNTIL DONE OR (CNT > 14) DO
         READ R.VOC FROM F.VOC,K.VOC THEN
            T.OUTPUT = "<TR>"
            S.VOC = DCOUNT(R.VOC,@AM)
            FOR I.VOC = 1 TO S.VOC
               T.OUTPUT := "<TD>":R.VOC<I.VOC>:"</TD>"
            NEXT I.VOC
            IF S.VOC > S.COL THEN S.COL = S.VOC
            T.OUTPUT := "</TR>"
            OUTPUT := T.OUTPUT
         END
      REPEAT
*
* Now build the header as KEY FIELD 1 FIELD 2 FIELD 3...
      T.HEADER = "<TR><TH>KEY</TH>"
      FOR I.COL = 2 TO S.COL
         T.HEADER := "<TH>FIELD ":(I.COL-1):"</TH>"
      NEXT I.COL
      T.HEADER := "</TR>"
      START.TABLE = "<HTML><TABLE BORDER=2>"
      END.TABLE = "</TABLE></HTML>"
*
      OUTPUT = START.TABLE:T.HEADER:OUTPUT:END.TABLE
      WRITE OUTPUT ON F.TO.FILE,TO.ITEM
      RETURN
*
END