HELP: Strip or extract comments from UTF-8 text records TYPE: OBJECT SYNTAX: CMT(PRESET[=ALL/NONE/HASH/SLASH/STAR/BLOCK/DASHDASH/REM/SEMI],ADD,CUSTOM[()...],MODE=INBETWEEN/BEHIND/BEFORE/STRIP,WHITESPACE=PRESERVE/REPLACE/COLLAPSE/REMOVE/TRAILING/LEADING/BOTH/NUMBER,SKIPROWS=num,BLANKLINES=STRIP/KEEP,SIDEFILE='str'/STDOUT/STDERR)
This component strips comments from UTF-8 text records on the read side, and re-inserts previously saved comments into a text stream on the write side.
CNVCMT operates exclusively in record mode. The upstream pipeline must have already split the raw byte stream into individual records (use CNV.REC() or equivalent before CNV.CMT()). CNVCMT does not process block-oriented input; passing an unsplit block returns immediately with no error (SKIP).
CNVCMT requires UTF-8 input. Place CNV.CHR() before CNV.CMT() in the pipeline to ensure the correct character set.
On the read side CNVCMT inspects every incoming record and detects comment lines, inline comments, and optionally blank lines. The built-in patterns cover the most common comment styles:
HASH (#) -- Shell, Python, Ruby, INI, YAML, ... SLASH (//) -- C++, Java, JavaScript, C99, ... STAR (*) -- leading asterisk, common in PL/I, COBOL BLOCK (/* ... */) -- C-style block comment spanning records DASHDASH (--) -- SQL, Ada, Lua, VHDL REM (REM) -- DOS batch, BASIC (case-sensitive match)
All patterns are active by default (PRESET=ALL). Custom patterns can be added or used exclusively via the CUSTOM parameter, which accepts an arbitrary number of begin/end marker pairs. A custom line comment is specified by leaving CE empty (CE='').
An inline comment divides a record into a data part before the marker and a possible data part after the end marker. The MODE parameter controls how CNVCMT handles the two data fragments:
Some files use the OPPOSITE convention from classic line comments: by default the file is comment-only, and a SECTION-BEGIN marker (SB) switches into the data region. A SECTION-END marker (SE) switches back to comment mode. This is useful for SWIFT-MT files ('{1:' ... '-}'), PEM blocks ('-----BEGIN ...-----' ... '-----END ...-----'), banner-style dumps, and Perl 'DATA'-style files.
A CUSTOM(...) entry is in section mode when SB is set. SB and CB are mutually exclusive; specifying both is an error (FLMRTC_ITF).
The section-mode parameters are:
Examples of section-mode usage are listed at the end of this manual page (see EXAMPLES).
Sidefile roundtrip: section-mode COMMENT regions (header banner, between-section trailers, footer) are written to the SIDEFILE as CL(ROW=N CB='' CS='...comment bytes...' CE='') entries with the comment region's bytes stored verbatim in CS (newlines preserved). The write side splits CS at 'n' boundaries and emits one output record per piece, dropping the trailing empty piece if CS ends with 'n' (cnv.blk adds the record terminator).
Note: If the input file does not end with 'n', the write-side reconstruction will append one because cnv.blk always emits record terminators. This is a 1-byte difference at EOF only.
When SIDEFILE is given, CNVCMT writes a CLP parameter file containing one CL(...) entry for every detected comment. This file can be passed directly to the CNV.CMT write-side to reconstruct the original comment positions in the output stream.
The sidefile format is a valid CLP parameter file:
CL(ROW=0 CB='#' CS=' Generated by tool v2' CE='') CL(ROW=3 CB='/*' CS='block line1\nline2' CE='*/') CL(ROW=5 IB CB=' #' CS=' trailing remark' CE='')
Newlines inside a comment body are escaped as n; single quotes are escaped as '. This ensures the file can be parsed back by CLP without special handling.
The read side writes the sidefile incrementally during the pipeline run and closes it only after the last record has been processed (at the end of the converter close phase). The write side parameter comment='...' is a CLP file-to-string parameter: CLP reads and expands the file content at command-parse time, before the pipeline is opened.
This ordering creates a constraint: both actions cannot be combined in a single flcl command invocation. If the read side (sidefile='sf.clp') and the write side (comment='sf.clp') are specified in the same call, CLP expands comment='sf.clp' first -- at that point the file is either absent or empty, so the write side receives no CL entries and inserts no comments. The output contains only the stripped data.
The correct approach is always two separate calls:
Step 1 -- strip comments, write sidefile (sf.clp written at close):
flcl conv read.text(file='in.txt' comment(sidefile='sf.clp')) \
write.text(file='stripped.txt')
Step 2 -- re-insert from sidefile (sf.clp fully written by now):
flcl conv read.text(file='stripped.txt') \
write.text(file='out.txt' comment='sf.clp')
The same constraint applies to flcl xcnv: even when both converters appear in a single xcnv command string, the cnv.cmt='sf.clp' parameter on the write side is expanded at parse time. Use two separate flcl xcnv calls for sidefile-based round-trips.
On the write side CNVCMT re-inserts comments from an explicit CL array (typically the sidefile produced by the read side). Each CL entry specifies the target row, the comment markers, the comment body, and the inline attachment flags IB and IE:
Multiple CL entries with the same ROW are processed in definition order. Entries with IB=NO are written as complete lines before record ROW+1. Entries with IB=YES are appended to record ROW itself.
Strip all comment lines from a Python script, keep the data:
flcl xcnv "inp(sav.fil(fio.txt(name='script.py') cnv.chr(to=UTF-8) cnv.cmt())) out(sav.fil(fio.txt(name='stripped.py')))"
Strip comments and save them to a sidefile, then re-insert in a second call (two calls are required; see SIDEFILE ROUND-TRIP above):
Step 1 -- strip and save sidefile:
flcl xcnv "inp(sav.fil(fio.txt(name='in.py') cnv.chr(to=UTF-8) cnv.cmt(sidefile='comments.clp'))) out(sav.fil(fio.txt(name='stripped.py')))"
Step 2 -- re-insert from the fully-written sidefile:
flcl xcnv "inp(sav.fil(fio.txt(name='stripped.py'))) out(sav.fil(cnv.cmt='comments.clp' fio.txt(name='out.py')))"
The same two-step pattern using flcl conv (star-comment preset, block size 8 KB for efficiency with large files):
Step 1 -- strip:
flcl conv read.text(file='source.asm' comment(preset=star sidefile='sf.clp')) \
write.text(file='stripped.asm')
Step 2 -- re-insert:
flcl conv read.text(file='stripped.asm') \
write.text(file='restored.asm' comment='sf.clp')
Use only custom comment markers (PRESET=NONE ADD CUSTOM(CB='!' CE='')):
flcl xcnv "inp(sav.fil(fio.txt(name='in.txt') cnv.chr(to=UTF-8) cnv.cmt(preset=none add custom(cb='!' ce='')))) out(sav.fil(fio.txt(name='out.txt')))"
Always skip the first two records (header rows), strip hash comments:
flcl xcnv "inp(sav.fil(fio.txt(name='data.csv') cnv.chr(to=UTF-8) cnv.cmt(pattern=hash skiprows=2))) out(sav.fil(fio.txt(name='data_clean.csv')))"
SWIFT-MT103, one transaction per '{1:'...'-}nn' block:
CNV.CMT(
PRESET=NONE
CUSTOM(SB='{1:' SE='-}\n\n' SBCMT=0 SECMT=2 STRICT)
)
PEM-style certificates, full marker lines as comment:
CNV.CMT(
PRESET=NONE
CUSTOM(SB='-----BEGIN CERTIFICATE-----\n'
SE='\n-----END CERTIFICATE-----'
SBCMT=29 SECMT=27)
)
Perl 'DATA' style -- header is comment, marker is comment, rest is data to EOF:
CNV.CMT(
PRESET=NONE
CUSTOM(SB='__DATA__\n' SBCMT=9)
)
Mixed: PEM blocks plus classic '#' comments inside the data:
CNV.CMT(
PRESET=NONE
CUSTOM(SB='-----BEGIN ...-----\n' SE='\n-----END ...-----'
SBCMT=22 SECMT=22)
CUSTOM(CB='#')
)
NUMBER: PRESET=ALL/NONE/HASH/SLASH/STAR/BLOCK/DASHDASH/REM/SEMI - Built-in comment patterns to detect [HASH|SLASH|DASHDASH]
ALL - All built-in comment patterns (Tier-1 + SEMI)NONE - No built-in patterns (use PAT for custom patterns)HASH - Hash '#' line comment (CSV, Python, YAML, ...)SLASH - Double-slash '//' line comment (C99, Java, Go, ...)STAR - Star '*' line comment (COBOL, HLASM)BLOCK - Slash-star block comment (C, Java, SQL, ...)DASHDASH - Double-dash '--' line comment (SQL, Ada, Lua, ...)REM - REM keyword line comment, word-boundary (Batch, BASIC)SEMI - Semicolon ';' line comment (INI, NASM, Lisp, CLP)SWITCH: ADD - Add CUSTOM entries to PRESET; without: CUSTOM replaces PRESET [NO]NUMBER: MODE=INBETWEEN/BEHIND/BEFORE/STRIP - Inline comment handling [INBETWEEN]
INBETWEEN - Split record at inline comment: emit rec_before, comment, rec_after [default]BEHIND - Merge split parts; place comment entry after merged recordBEFORE - Merge split parts; place comment entry before merged recordSTRIP - Merge split parts; silently discard inline commentNUMBER: WHITESPACE=PRESERVE/REPLACE/COLLAPSE/REMOVE/TRAILING/LEADING/BOTH/NUMBER - Whitespace handling at split-record join site [PRESERVE]
PRESERVE - Don't touch any whitespaceREPLACE - Replace all control characters with whitespace charactersCOLLAPSE - Remove leading/trailing whitespace and control characters and collapse multiple whitespaces intoREMOVE - Remove all whitespace and control characters from the stringTRAILING - Remove trailing whitespace and control characters from the stringLEADING - Remove leading whitespace and control characters from the stringBOTH - Remove leading and trailing whitespace and control charactersNUMBER - Remove leading/trailing whitespace and control characters as well as leading zerosNUMBER: SKIPROWS=num - Always strip first N records without comment detection [0]NUMBER: BLANKLINES=STRIP/KEEP - Blank line handling [STRIP]
STRIP - Remove blank lines [default]KEEP - Keep blank lines as-isSTRING: SIDEFILE='str'/STDOUT/STDERR - Write CLP parameter file for write-side reuse
STDOUT - Write output to stdoutSTDERR - Write output to stderr