Deutsch   English   Français   Italiano  
<87edc31i3e.fsf@nosuchdomain.example.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: Block Comments Or Rest-Of-Line Comments?
Date: Thu, 21 Mar 2024 12:48:53 -0700
Organization: None to speak of
Lines: 65
Message-ID: <87edc31i3e.fsf@nosuchdomain.example.com>
References: <utgjh0$21nsq$2@dont-email.me> <uthj7e$29aoc$2@dont-email.me>
	<uthne5$2ad1b$1@dont-email.me>
	<87msqr1j8x.fsf@nosuchdomain.example.com>
	<uti2gj$2d5i5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="0bf58c5e3e50115de10475b5e7b86fc1";
	logging-data="2532317"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18oc0Pau8x1jkkdT9rpHFre"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:gvyWLrroMgAzmyjh8FjVuy/KB6g=
	sha1:0beu3Ns2jEqFyBadOt+iMzPqlRA=
Bytes: 2872

Richard Harnden <richard.nospam@gmail.invalid> writes:
> On 21/03/2024 19:23, Keith Thompson wrote:
>> Richard Harnden <richard.nospam@gmail.invalid> writes:
>> [...]
>>> And sometimes, when it's not a really a comment, but rather a block of
>>> code I don't want right now:
>>>
>>> #ifdef 0
>>> ...
>>> #endif
>> I think you mean "#if 0".
>
> Yes I did :)
>
>> I use that sometimes, but one disadvantage is that if you're viewing
>> the
>> middle of a very large block of code, it can be hard to tell that it's
>> been "commented" out.
>> I have a script that applies "#if 0" and "#endif" to a block of code
>> *and* prepends "* " to each line in the block.
>
> That's a good ideo.  Can you share it?

Sure.  It's a Perl script called "if0".  It tries to deal with
variations in line endings (I sometimes work with code with LF and/or
CRLF line endings) and with tabs vs. spaces as indentation.

I don't have a script that undoes what if0 does.  I might write one
one of these days, but usually I can just revert the change in source
control or change it back manually.

Complaints about Perl being write-only will be cheerfully ignored.

```
#!/usr/bin/perl

use strict;
use warnings;

my @lines = <>;
my $newline = "\n";
if (defined $lines[0] and $lines[0] =~ /\r$/) {
    $newline = "\r\n";
}

print "#if 0$newline";
foreach my $line (@lines) {
    if ($line =~ /^ /) {
        $line =~ s/ /*/;
    }
    elsif ($line =~ /^\r?$/) {
        $line =~ s/^/*/;
    }
    else {
        $line =~ s/^/* /;
    }
    print $line;
}
print "#endif /* 0 */$newline";
```

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */