Programma di esempio HTMINDEX.PRT
; HTMINDEX
;
; Programma per Proteus
;
; (C) 1998-2003 Simone Zanella Productions
;
; Crea un nuovo file contenente tutti i bookmark trovati nei
; file HTML corrispondenti alla specifica; questo programma
; è stato utilizzato per creare la prima versione dell'indice
; analitico del manuale di Proteus.

; Parametri impliciti: input e output predefiniti nulli
;!proteus -z

FUNCTION StripExtra(s)

  ; Rimuove ogni tag supplementare tra <>
  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)

  ; Trascrive il contenuto dell'AVL
  FWRITELN(_HD, s "<br>")
RETURN 0  

FUNCTION AddAvl(s)

  ; Aggiunge all'albero AVL la stringa contenuta nel 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 "Sintassi: " ARGV(1) " " ARGV(2) " \"pathname\" destinazione"
  CONSOLELN ""
  CONSOLELN "Scopo: scrive i tag di hyperlink ad ogni bookmark trovato in"
  CONSOLELN "ciascuna pagina in pathname (che puo' contenere wildcard)"
  ABORT 0
FI

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

SourceDir = STRIPQUOTES(ARGV(5))

; Isola la directory base e la specifica dei file
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 "Impossibile aprire \"" ARGV(6) "\"."
  ABORT 1
FI

RL = ""
A = AVLNEW()
WHILE GT(F, 0)
  ; File trovato - lo apre in lettura
  FH = FOPEN(BaseDir IIF(ISNOTEMPTY(BaseDir), DirSep, "") \
                 DIRLAST(H, 1), 1)
  IF EQ(FH, -1)
    CONSOLELN "Impossibile aprire \"" DIRLAST(H, 1) "\"."
  ELSE
    ; Apertura ok
    PL = ""
    ; Fino a fine file..
    WHILE NOT(FEOF(FH))
      FLine = LTRIM(FREADLN(FH), " ")
      IF STRNEQ(RL, "")
        FLine = RL FLine
        RL = ""
      FI
      ; Il bookmark è iniziato alla riga precedente?
      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
Indice esempi Prossimo esempio Esempio precedente Indice per argomenti Indice analitico
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