RosettaCodeData/Task/Strip-block-comments/BBC-BASIC/strip-block-comments.basic

39 lines
1.1 KiB
Plaintext

infile$ = "C:\sample.c"
outfile$ = "C:\stripped.c"
PROCstripblockcomments(infile$, outfile$, "/*", "*/")
END
DEF PROCstripblockcomments(infile$, outfile$, start$, finish$)
LOCAL infile%, outfile%, comment%, test%, A$
infile% = OPENIN(infile$)
IF infile%=0 ERROR 100, "Could not open input file"
outfile% = OPENOUT(outfile$)
IF outfile%=0 ERROR 100, "Could not open output file"
WHILE NOT EOF#infile%
A$ = GET$#infile% TO 10
REPEAT
IF comment% THEN
test% = INSTR(A$, finish$)
IF test% THEN
A$ = MID$(A$, test% + LEN(finish$))
comment% = FALSE
ENDIF
ELSE
test% = INSTR(A$, start$)
IF test% THEN
BPUT#outfile%, LEFT$(A$, test%-1);
A$ = MID$(A$, test% + LEN(start$))
comment% = TRUE
ENDIF
ENDIF
UNTIL test%=0
IF NOT comment% BPUT#outfile%, A$
ENDWHILE
CLOSE #infile%
CLOSE #outfile%
ENDPROC