Example REMC.PRT
; REMC
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Remove "C" remarks.
;
; Algorithm:
; - if we are NOT inside a remark, check if there is a remark on the line;
;   YES: find where it ends (if on the line), write the part outside the remark,
;        skip to end of remark; at the end, set InRem to 1 if we are still inside
;        a remark;
;   NO:  write the line as is;
; - if we are inside a remark, write only the part outside (if it exists),
;   setting InRem to 0 at the end if we are outside the remark.
;
; Note: the tokens "/*" and "*/" must not appear inside strings.

; Initialization
FUNCTION ONSTART()

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

  _InRem = 0
RETURN


IF EQ(InRem, 0)

  ; Find the start of the remark
  Pos = STRSTR(L, "/*")

  ; Create a copy of the line
  PL = STRDUP(L)

  ; New remark?
  IF NEQ(Pos, 0)

    ; Flag: did we write something?
    W = 0

    REPEAT

      ; Pos is where the part to transcribe ends
      DEC(@Pos)

      ; PL2 is the substring to transcribe
      PL2 = LEFT(PL, Pos)

      ; Write PL2 if not empty
      IF ISNOTEMPTY(PL2)
        PRINT PL2
        W = 1
      FI

      ; Pos2 is where remark ends (if on the line)
      Pos2 = STRSTR(PL, "*/")

      ; Set flag: we are inside a remark
      InRem = 1

      ; Does remark end on the line?
      IF NEQ(Pos2, 0)

        ; Reset flag
        InRem = 0

        ; Pos2 is where the part to transcribe begins
        ADD(@Pos2, 2)

        ; Anything else to transcribe?
        IF NEQ(Pos2, 0)

          PL = SUBSTR(PL, Pos2, STRLEN(PL))

        ELSE

          BREAK

        FI

      ELSE

        BREAK

      FI

      Pos = STRSTR(PL, "/*")

    UNTIL EQ(Pos, 0)

    ; Something was written: add CR+LF
    IF W
      PRINTLN ""
    FI

  ELSE

    PRINTLN L

  FI

ELSE
  ; Find the end of the remark
  Pos = STRSTR(L, "*/")

  ; Create a copy of the line
  PL = STRDUP(L)

  ; Found
  IF NEQ(Pos, 0)

    ; Flag: did we write something?
    W = 0

    REPEAT

      ; Pos is where the part to transcribe begins
      ADD(@Pos, 2)

      ; PL is the substring to transcribe
      PL = SUBSTR(PL, Pos, STRLEN(PL))

      ; Find the start of the remark in PL
      Pos2 = STRSTR(PL, "/*")

      ; Set to 0 the flag 'inside remark'
      InRem = 0

      ; New remark found?
      IF NEQ(Pos2, 0)

        ; Pos2 is where the part to transcribe ends
        DEC(@Pos2)

        ; PL2 is the substring to transcribe
        PL2 = LEFT(PL, Pos2)

        ; Write PL2
        IF ISNOTEMPTY(PL2)
          PRINT PL2
          W = 1
        FI

        ; Find next remark
        Pos = STRSTR(PL, "*/")

        ; Found: update PL
        IF NEQ(Pos, 0)
          DEC(@Pos)
          PL = SUBSTR(PL, Pos, STRLEN(PL))

        ELSE
          ; We are again inside a remark
          InRem = 1
        FI

      ELSE

        ; The rest of the line is outside a remark
        IF ISNOTEMPTY(PL)
          PRINT PL
          W = 1
        FI

      FI

      Pos = STRSTR(PL, "*/")

    UNTIL EQ(Pos, 0)

    ; Something was written: add CR+LF
    IF W
      PRINTLN ""
    FI
  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