Example REMCPP.PRT
; REMCPP
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Remove "C++" remarks.
;
; Algorithm:
; - if "//" does not appear on the line, write it without modifications; otherwise,
;   create a new line PL (empty);
; - if the line begins with a remark, append characters to PL until the
;   remark is closed; then (or if the line begins outside a remark),
;   consider only the last two characters; if they are "/*", append everything
;   until the end of the line or until the token "*/" appears; if they are "//",
;   ignore them until the end of the line. Print PL if it is not empty.
;
; Note: tokens "//", "/*" and "*/" cannot appear inside strings.

; Initialization
FUNCTION ONSTART()

  IF STREQ(ARGV(3), "..")
    CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " source destination"
    CONSOLELN ""
    CONSOLELN "Purpose: remove \"C++\" remarks from source"
    ABORT 0
  FI

  _InRem = 0
RETURN

; Find token "//"
Pos = STRSTR(L, "//")

; Not found
IF EQ(Pos, 0)
  ; Write line as is
  PRINTLN L

  ; Set InRem according to C style remarks
  P = STRRSTR(L, "/*")
  M = STRRSTR(L, "*/")

  ; There is a "begin remark" token
  IF NEQ(P, 0)

    ; There is an "end remark" token
    IF NEQ(M, 0)

      ; We are inside a remark if P is greater than M
      InRem = GT(P, M)

    ELSE

      ; We are inside a remark (only begin remark was found)
      InRem = 1

    FI

  ELSE

    ; End remark: set flag
    IF NEQ(M, 0)

      InRem = 0

    FI

  FI
ELSE
  PL = ""
  P = 1
  M = STRLEN(L)
  Prev = 0
  Current = SUBSTR(L, P, 1)

  ; Line begins inside a C remark: copy until the end of line or end of remark
  IF EQ(InRem, 1)
    WHILE AND( AND(InRem, LE(P, M)), \
                  OR(STRNEQ(Prev, "*"), STRNEQ(Current, "/")) )
      PL = PL Current
      Prev = Current
      INC(@P)
      Current = SUBSTR(L, P, 1)
      IF AND(STREQ(Prev, "*"), STREQ(Current, "/"))
        InRem = 0
        BREAK
      FI
    LOOP
  FI

  ; Append characters until the token "//" is found
  WHILE AND( LE(P, M), \
                OR(STRNEQ(Prev, "/"), STRNEQ(Current, "/")) )
    ; Begin remark
    IF AND(STREQ(Prev, "/"), STREQ(Current, "*"))
      InRem = 1
      ; Copy until the end of line or the end of remark
      WHILE AND( AND(InRem, LE(P, M)), \
                    OR(STRNEQ(Prev, "*"), STRNEQ(Current, "/")) )
        PL = PL Current
        Prev = Current
        INC(@P)
        Current = SUBSTR(L, P, 1)
        IF AND(STREQ(Prev, "*"), STREQ(Current, "/"))
          InRem = 0
          BREAK
        FI
      LOOP
    ELSE
      ; Append Current if it is not a token "//"
      IF STRNEQ(SUBSTR(L, P, 2), "//")
        PL = PL Current
      FI
      Prev = Current
      INC(@P)
      Current = SUBSTR(L, P, 1)
    FI
  LOOP

  ; If the modified line is not empty, write it
  IF ISNOTEMPTY(PL)
    PRINTLN PL
  FI
FI
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