Example HTMINDEX.PRT
; HTMINDEX
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Create a new file including all bookmarks found inside HTML files
; matching specifications; this program was used to create
; an early version of the index ad the end of the Proteus Manual.

; Implicit parameters: input and output NULL
;!proteus -z

FUNCTION StripExtra(s)

  ; Remove any extra tag between < and >
  nl = RESTFROM(s, 2)
  nl = LEFT(nl, SUB(STRLEN(nl), 4))
  k = STRSTR(nl, "<")
  WHILE k
    nk = INC(k)
    WHILE STRNEQ(SUBSTR(nl, nk, 1), ">")
      INC(@nk)
    LOOP
    INC(@nk)
    nl = DELETE(nl, k, SUB(nk, k))
    k = STRSTR(nl, "<")
  LOOP
RETURN "<" nl RIGHT(s, 4)

FUNCTION WriteAvl(label, s)

  ; Transcribe the contents of the AVL
  FWRITELN(_HD, s "<br>")
RETURN 0  

FUNCTION AddAvl(s)

  ; Add to the AVL tree the string corresponding to bookmark s
  p = STRSTR(s, ">")
  s2 = RESTFROM(s, INC(p))
  p = STRSTR(s2, "<")
  s2 = LEFT(s2, DEC(p))
  AVLSET(_A, ALLTRIM(UPPER(s2), " "), s)
RETURN


IF OR(ISEMPTY(ARGV(5)), ISEMPTY(ARGV(6)))
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " \"pathname\" destination"
  CONSOLELN ""
  CONSOLELN "Purpose: write hyperlink tags for every bookmark found in each"
  CONSOLELN "page matching pathname (which can include wildcards)"
  ABORT 0
FI

!ifdef UNIX
  DirSep = "/"
!else
  DirSep = "\\"
!endif

SourceDir = STRIPQUOTES(ARGV(5))

; Isolate base directory and file specification
X = STRRSTR(SourceDir, DirSep)
IF X
  BaseDir = LEFT(SourceDir, X)
  Spec = RESTFROM(SourceDir, INC(X))
ELSE
  BaseDir = ""
  Spec = SourceDir
FI

H = DIROPEN(SourceDir, 1)
F = IIF(NEQ(H, -1), 1, 0)
HD = FOPEN(ARGV(6), 26)
IF EQ(HD, -1)
  CONSOLELN "Could not open \"" ARGV(6) "\"."
  ABORT 1
FI

RL = ""
A = AVLNEW()
WHILE GT(F, 0)
  ; File found - open for reading
  FH = FOPEN(BaseDir IIF(ISNOTEMPTY(BaseDir), DirSep, "") \
                 DIRLAST(H, 1), 1)
  IF EQ(FH, -1)
    CONSOLELN "Could not open \"" DIRLAST(H, 1) "\"."
  ELSE
    ; Open succesfull
    PL = ""
    ; Until the end of file..
    WHILE NOT(FEOF(FH))
      FLine = LTRIM(FREADLN(FH), " ")
      IF STRNEQ(RL, "")
        FLine = RL FLine
        RL = ""
      FI
      ; Bookmark started on the previous line?
      IF AND(STRLEN(FLine), STRLEN(PL))
        IF REXMATCH(FLine, "</a>")
          ADD(@R_START, 4)
          CL = PL SUBSTR(FLine, 1, SUB(R_START, 1))
          CL = "<a href=\"" DIRLAST(H, 1) "#" RESTFROM(CL, 10)
          FLine = RESTFROM(FLine, R_START)
          AddAvl(StripExtra(CL))
          PL = ""
        ELSE
          PL = PL FLine
          CONTINUE
        FI
      FI
      WHILE STRLEN(FLine)
        PBook = STRISTR(FLine, "<a name=")
        IF PBook
          IF REXMATCH(FLine, "</a>")
            Found = 1
            WHILE AND(LT(R_START, PBook), Found)
              FLine = RESTFROM(FLine, ADD(R_START, 4))
              PBook = STRISTR(FLine, "<a name=")
              Found = REXMATCH(FLine, "</a>")
            LOOP
            IF Found
              ADD(@R_START, 4)
              CL = SUBSTR(FLine, PBook, SUB(R_START, PBook))
              CL = "<a href=\"" DIRLAST(H, 1) "#" RESTFROM(CL, 10)
              FLine = RESTFROM(FLine, R_START)
              AddAvl(StripExtra(CL))
            ELSE
              PL = RESTFROM(FLine, PBook) " "
              BREAK
            FI
          ELSE
            PL = RESTFROM(FLine, PBook) " "
            BREAK
          FI
        ELSE
          FLine = RIGHT(RTRIM(FLine, " "), 2)
          IF STREQ(FLine, "<a")
            RL = FLine " "
          FI
          BREAK
        FI
      LOOP
    LOOP
    FCLOSE(FH)
  FI
  F = DIRNEXT(H)
LOOP
DIRCLOSE(H)
AVLTRAVERSE(A, WriteAvl)
FCLOSE(HD)
ABORT 0
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell