; 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