Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #383849

Re: Block Comments Or Rest-Of-Line Comments?

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Block Comments Or Rest-Of-Line Comments?
Date 2024-03-21 12:48 -0700
Organization None to speak of
Message-ID <87edc31i3e.fsf@nosuchdomain.example.com> (permalink)
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>

Show all headers | View raw


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 */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Block Comments Or Rest-Of-Line Comments? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-21 06:19 +0000
  Re: Block Comments Or Rest-Of-Line Comments? bart <bc@freeuk.com> - 2024-03-21 09:39 +0000
  Re: Block Comments Or Rest-Of-Line Comments? Mikko <mikko.levanto@iki.fi> - 2024-03-21 13:37 +0200
    Re: Block Comments Or Rest-Of-Line Comments? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-21 21:16 +0000
      Re: Block Comments Or Rest-Of-Line Comments? David Brown <david.brown@hesbynett.no> - 2024-03-22 10:02 +0100
        Re: Block Comments Or Rest-Of-Line Comments? Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-03-22 16:13 +0000
        Re: Block Comments Or Rest-Of-Line Comments? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-23 02:58 +0000
          Re: Block Comments Or Rest-Of-Line Comments? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-03-22 21:15 -0700
            Re: Block Comments Or Rest-Of-Line Comments? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-23 04:44 +0000
          Re: Block Comments Or Rest-Of-Line Comments? David Brown <david.brown@hesbynett.no> - 2024-03-23 16:24 +0100
            Re: Block Comments Or Rest-Of-Line Comments? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-03-23 18:34 +0000
  Re: Block Comments Or Rest-Of-Line Comments? scott@slp53.sl.home (Scott Lurndal) - 2024-03-21 14:16 +0000
    Re: Block Comments Or Rest-Of-Line Comments? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-03-21 08:19 -0700
      Re: Block Comments Or Rest-Of-Line Comments? cross@spitfire.i.gajendra.net (Dan Cross) - 2024-03-21 17:58 +0000
        Re: Block Comments Or Rest-Of-Line Comments? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-03-22 06:27 -0700
          Re: Block Comments Or Rest-Of-Line Comments? cross@spitfire.i.gajendra.net (Dan Cross) - 2024-03-22 23:16 +0000
  Re: Block Comments Or Rest-Of-Line Comments? Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-03-21 14:19 +0000
  Re: Block Comments Or Rest-Of-Line Comments? David Brown <david.brown@hesbynett.no> - 2024-03-21 16:20 +0100
    Re: Block Comments Or Rest-Of-Line Comments? Richard Harnden <richard.nospam@gmail.invalid> - 2024-03-21 16:32 +0000
      Re: Block Comments Or Rest-Of-Line Comments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-21 12:23 -0700
        Re: Block Comments Or Rest-Of-Line Comments? Richard Harnden <richard.nospam@gmail.invalid> - 2024-03-21 19:41 +0000
          Re: Block Comments Or Rest-Of-Line Comments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-21 12:48 -0700
            Re: Block Comments Or Rest-Of-Line Comments? Richard Harnden <richard.nospam@gmail.invalid> - 2024-03-21 19:54 +0000
            Re: Block Comments Or Rest-Of-Line Comments? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-21 21:18 +0000
              Re: Block Comments Or Rest-Of-Line Comments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-21 15:50 -0700
        Re: Block Comments Or Rest-Of-Line Comments? scott@slp53.sl.home (Scott Lurndal) - 2024-03-21 20:19 +0000
          Re: Block Comments Or Rest-Of-Line Comments? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-03-21 20:35 +0000
        Re: Block Comments Or Rest-Of-Line Comments? Kaz Kylheku <433-929-6894@kylheku.com> - 2024-03-21 20:22 +0000
          Re: Block Comments Or Rest-Of-Line Comments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-21 15:41 -0700
        Re: Block Comments Or Rest-Of-Line Comments? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-03-22 12:20 -0400
          Re: Block Comments Or Rest-Of-Line Comments? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-03-22 09:33 -0700
          Re: Block Comments Or Rest-Of-Line Comments? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-22 23:42 +0000
      Re: Block Comments Or Rest-Of-Line Comments? David Brown <david.brown@hesbynett.no> - 2024-03-22 10:09 +0100
  Re: Block Comments Or Rest-Of-Line Comments? fir <fir@grunge.pl> - 2024-03-21 19:46 +0100
    Re: Block Comments Or Rest-Of-Line Comments? Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-03-21 21:14 +0000
  Re: Block Comments Or Rest-Of-Line Comments? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-03-22 22:50 +0000

csiph-web