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


Groups > comp.programming > #986 > unrolled thread

indent: convert to C-style comments

Started by"Mark" <mark_cruzNOTFORSPAM@hotmail.com>
First post2011-11-03 16:20 -0400
Last post2011-11-10 20:47 -0700
Articles 14 — 7 participants

Back to article view | Back to comp.programming


Contents

  indent: convert to C-style comments "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2011-11-03 16:20 -0400
    Re: indent: convert to C-style comments Ian Collins <ian-news@hotmail.com> - 2011-11-04 20:08 +1300
      Re: indent: convert to C-style comments scott@slp53.sl.home (Scott Lurndal) - 2011-11-04 16:46 +0000
      Re: indent: convert to C-style comments "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2011-11-05 16:00 -0500
        Re: indent: convert to C-style comments Ian Collins <ian-news@hotmail.com> - 2011-11-06 09:05 +1300
          Re: indent: convert to C-style comments "Mark" <mark_cruzNOTFORSPAM@hotmail.com> - 2011-11-05 16:12 -0500
        Re: indent: convert to C-style comments Thad Smith <ThadSmith@acm.org> - 2011-11-06 18:54 -0600
          Re: indent: convert to C-style comments jt@toerring.de (Jens Thoms Toerring) - 2011-11-09 14:29 +0000
            Re: indent: convert to C-style comments John Gordon <gordon@panix.com> - 2011-11-09 17:07 +0000
              Re: indent: convert to C-style comments jt@toerring.de (Jens Thoms Toerring) - 2011-11-09 18:36 +0000
                Re: indent: convert to C-style comments John Gordon <gordon@panix.com> - 2011-11-10 20:08 +0000
                  Re: indent: convert to C-style comments Doug McIntyre <merlyn@geeks.org> - 2011-11-10 20:21 +0000
                    Re: indent: convert to C-style comments jt@toerring.de (Jens Thoms Toerring) - 2011-11-10 21:04 +0000
            Re: indent: convert to C-style comments Thad Smith <ThadSmith@acm.org> - 2011-11-10 20:47 -0700

#986 — indent: convert to C-style comments

From"Mark" <mark_cruzNOTFORSPAM@hotmail.com>
Date2011-11-03 16:20 -0400
Subjectindent: convert to C-style comments
Message-ID<j8ut1o$psd$1@speranza.aioe.org>
Hello,

I've read through 'man indent' but have not found if it allows to enforce 
C-style comments. Am I missing any option using which would convert C++ 
comments in to C-style?

GNU indent 2.2.9

Thanks.

Mark 

[toc] | [next] | [standalone]


#987

FromIan Collins <ian-news@hotmail.com>
Date2011-11-04 20:08 +1300
Message-ID<9hhhbcF62fU1@mid.individual.net>
In reply to#986
On 11/ 4/11 09:20 AM, Mark wrote:
> Hello,
>
> I've read through 'man indent' but have not found if it allows to enforce
> C-style comments. Am I missing any option using which would convert C++
> comments in to C-style?

Since 1999, C++ comments are C comments!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#988

Fromscott@slp53.sl.home (Scott Lurndal)
Date2011-11-04 16:46 +0000
Message-ID<lFUsq.37947$Oy6.7159@news.usenetserver.com>
In reply to#987
Ian Collins <ian-news@hotmail.com> writes:
>On 11/ 4/11 09:20 AM, Mark wrote:
>> Hello,
>>
>> I've read through 'man indent' but have not found if it allows to enforce
>> C-style comments. Am I missing any option using which would convert C++
>> comments in to C-style?
>
>Since 1999, C++ comments are C comments!
>

More correctly, C++ comments were added to the 1999 C standard.   Earlier
C compilers (C89 and precedessors) likely do not support C++ comments.

A stand-alone pre-processor pass can be used with such compilers if necessary.

scott

[toc] | [prev] | [next] | [standalone]


#990

From"Mark" <mark_cruzNOTFORSPAM@hotmail.com>
Date2011-11-05 16:00 -0500
Message-ID<j944ln$ad8$1@speranza.aioe.org>
In reply to#987
"Ian Collins" <ian-news@hotmail.com> wrote in message 
news:9hhhbcF62fU1@mid.individual.net...
> On 11/ 4/11 09:20 AM, Mark wrote:
>> Hello,
>>
>> I've read through 'man indent' but have not found if it allows to enforce
>> C-style comments. Am I missing any option using which would convert C++
>> comments in to C-style?
>
> Since 1999, C++ comments are C comments!

Correct,however many internal coding guidelines require to use old-style 
comments /**/, so I wanted to know if popular tool such as 'indent' has 
ability to convert.

Mark. 

[toc] | [prev] | [next] | [standalone]


#991

FromIan Collins <ian-news@hotmail.com>
Date2011-11-06 09:05 +1300
Message-ID<9hlj81F62fU13@mid.individual.net>
In reply to#990
On 11/ 6/11 10:00 AM, Mark wrote:
> "Ian Collins"<ian-news@hotmail.com>  wrote in message
> news:9hhhbcF62fU1@mid.individual.net...
>> On 11/ 4/11 09:20 AM, Mark wrote:
>>> Hello,
>>>
>>> I've read through 'man indent' but have not found if it allows to enforce
>>> C-style comments. Am I missing any option using which would convert C++
>>> comments in to C-style?
>>
>> Since 1999, C++ comments are C comments!
>
> Correct,however many internal coding guidelines require to use old-style
> comments /**/, so I wanted to know if popular tool such as 'indent' has
> ability to convert.

That doesn't really make sense.  If the coding standard required 
old-style comments, how cones C++ style comments were used?

The best solution is to modernise the coding standard.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#992

From"Mark" <mark_cruzNOTFORSPAM@hotmail.com>
Date2011-11-05 16:12 -0500
Message-ID<j945bi$c91$1@speranza.aioe.org>
In reply to#991
"Ian Collins" <ian-news@hotmail.com> wrote in message 
news:9hlj81F62fU13@mid.individual.net...
>>> Since 1999, C++ comments are C comments!
>>
>> Correct,however many internal coding guidelines require to use old-style
>> comments /**/, so I wanted to know if popular tool such as 'indent' has
>> ability to convert.
>
> That doesn't really make sense.  If the coding standard required old-style 
> comments, how cones C++ style comments were used?

As it often happens, not everyone wants to follow the coding standards and 
leave sources unformatted.

> The best solution is to modernise the coding standard.
>
Unfortunately this is not an option.

Mark 

[toc] | [prev] | [next] | [standalone]


#1000

FromThad Smith <ThadSmith@acm.org>
Date2011-11-06 18:54 -0600
Message-ID<j97a9a$1lu$1@speranza.aioe.org>
In reply to#990
On 11/5/2011 3:00 PM, Mark wrote:

>>> I've read through 'man indent' but have not found if it allows to enforce
>>> C-style comments. Am I missing any option using which would convert C++
>>> comments in to C-style?

It's a nice programming exercise to convert the comments.  Remember to disable 
// searches in string constants and character constants.  For solid code, you 
need to also process trigraphs and line continuations.

That said, there must be such a program out there somewhere.  I must have 
written one, but can't find it.  :-(

Thad

[toc] | [prev] | [next] | [standalone]


#1009

Fromjt@toerring.de (Jens Thoms Toerring)
Date2011-11-09 14:29 +0000
Message-ID<9hvh24F8d8U1@mid.uni-berlin.de>
In reply to#1000
In comp.unix.programmer Thad Smith <ThadSmith@acm.org> wrote:
> On 11/5/2011 3:00 PM, Mark wrote:

> >>> I've read through 'man indent' but have not found if it allows to enforce
> >>> C-style comments. Am I missing any option using which would convert C++
> >>> comments in to C-style?

> It's a nice programming exercise to convert the comments.  Remember to
> disable  // searches in string constants and character constants.

>  For solid code, you 
> need to also process trigraphs and line continuations.

How could "//" appear in a character constant?

> That said, there must be such a program out there somewhere.  I must have 
> written one, but can't find it.  :-(

Here's a small filter program, using flex:

------8<--------------------------------------------
%option noyywrap noinput stack nounput noyy_top_state

%{
#include <stdio.h>
%}

%x str
%x c_cmt
%x cc_cmt

%%

\"        { putchar( '"' ); yy_push_state( str ); }
<str>{
\\\"      fputs( yytext, stdout );
\"        { putchar( '"' ); yy_pop_state( ); }
.         fputs( yytext, stdout );
}

"/*"      { fputs( yytext, stdout ); yy_push_state( c_cmt ); }
<c_cmt>{
"*/"      { fputs( "*/", stdout ); yy_pop_state( ); }
.         fputs( yytext, stdout );
}

"//"      { fputs( "/*", stdout ); yy_push_state( cc_cmt ); }
<cc_cmt>{
\n        { puts( " */" ); yy_pop_state( ); }
.         fputs( yytext, stdout );
}

.         fputs( yytext, stdout );

%%

int
main( void )
{
    yyin = stdin;
    yylex( );
    return 0;
}
------8<--------------------------------------------

Store it as ccmt.l, then use flex to convert it to a C program
with e.g.

flex -o ccmt.c ccmt.l

then compile it. Pipe the file you want to convert to it and
the converted data go to stdout. Dealing with trigraphs is
left as an exercise to the reader;-) Since I'm not sure how
contenuation lines work with C++-comments I left that out but
that shouldn't be too difficult to add support for that. And,
of course, there are no guarantees that it will work as ad-
vertised;-)
                          Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

[toc] | [prev] | [next] | [standalone]


#1010

FromJohn Gordon <gordon@panix.com>
Date2011-11-09 17:07 +0000
Message-ID<j9ec01$8j$1@reader1.panix.com>
In reply to#1009
In <9hvh24F8d8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

> How could "//" appear in a character constant?

Multibyte characters?  Character digraphs and trigraphs?

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#1011

Fromjt@toerring.de (Jens Thoms Toerring)
Date2011-11-09 18:36 +0000
Message-ID<9hvvhbFsq8U1@mid.uni-berlin.de>
In reply to#1010
In comp.unix.programmer John Gordon <gordon@panix.com> wrote:
> In <9hvh24F8d8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

> > How could "//" appear in a character constant?

> Multibyte characters?  Character digraphs and trigraphs?

Can you give me an example of a multibyte character constant
that could contain two slashes in a row? I've not much expe-
rience with multibyte characters and can't come up with one.

And, as I said in the end, I didn't with (di|tri)graphs in
this 5 minute program - I have yet to see them in the wild
after quite a bit of time programming C and thus am a bit
too lazy to bother with them;-)

                            Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

[toc] | [prev] | [next] | [standalone]


#1022

FromJohn Gordon <gordon@panix.com>
Date2011-11-10 20:08 +0000
Message-ID<j9hb0n$43i$1@reader1.panix.com>
In reply to#1011
In <9hvvhbFsq8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

> In comp.unix.programmer John Gordon <gordon@panix.com> wrote:
> > In <9hvh24F8d8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

> > > How could "//" appear in a character constant?

> > Multibyte characters?  Character digraphs and trigraphs?

> Can you give me an example of a multibyte character constant
> that could contain two slashes in a row? I've not much expe-
> rience with multibyte characters and can't come up with one.

I don't know if there are any actual multibyte characters that contain
two slashes.  I was just providing general examples of contexts where
such a thing could conceivably happen.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#1023

FromDoug McIntyre <merlyn@geeks.org>
Date2011-11-10 20:21 +0000
Message-ID<4ebc3253$0$79796$8046368a@newsreader.iphouse.net>
In reply to#1022
John Gordon <gordon@panix.com> writes:
>In <9hvvhbFsq8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

>> In comp.unix.programmer John Gordon <gordon@panix.com> wrote:
>> > In <9hvh24F8d8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

>> > > How could "//" appear in a character constant?

>> > Multibyte characters?  Character digraphs and trigraphs?

>> Can you give me an example of a multibyte character constant
>> that could contain two slashes in a row? I've not much expe-
>> rience with multibyte characters and can't come up with one.

>I don't know if there are any actual multibyte characters that contain
>two slashes.  I was just providing general examples of contexts where
>such a thing could conceivably happen.


Fairly easy to find (at least for UTF-16, but Unicode has shift
character to escape 16-bit and 32-bit chars).

http://glyphwiki.org/wiki/u2f2f

But, is it likely? Probably not. 

[toc] | [prev] | [next] | [standalone]


#1027

Fromjt@toerring.de (Jens Thoms Toerring)
Date2011-11-10 21:04 +0000
Message-ID<9i2sj9ForgU1@mid.uni-berlin.de>
In reply to#1023
In comp.unix.programmer Doug McIntyre <merlyn@geeks.org> wrote:
> John Gordon <gordon@panix.com> writes:
> >In <9hvvhbFsq8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

> >> In comp.unix.programmer John Gordon <gordon@panix.com> wrote:
> >> > In <9hvh24F8d8U1@mid.uni-berlin.de> jt@toerring.de (Jens Thoms Toerring) writes:

> >> > > How could "//" appear in a character constant?

> >> > Multibyte characters?  Character digraphs and trigraphs?

> >> Can you give me an example of a multibyte character constant
> >> that could contain two slashes in a row? I've not much expe-
> >> rience with multibyte characters and can't come up with one.

> >I don't know if there are any actual multibyte characters that contain
> >two slashes.  I was just providing general examples of contexts where
> >such a thing could conceivably happen.


> Fairly easy to find (at least for UTF-16, but Unicode has shift
> character to escape 16-bit and 32-bit chars).

> http://glyphwiki.org/wiki/u2f2f

> But, is it likely? Probably not. 

Well, maybe not likely, but for a "real" program in principle
also unlikely situation should be covered;-) Thank you and
Geoff for the explanations!
                              Best regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de

[toc] | [prev] | [next] | [standalone]


#1029

FromThad Smith <ThadSmith@acm.org>
Date2011-11-10 20:47 -0700
Message-ID<j9i5se$ssj$1@speranza.aioe.org>
In reply to#1009
On 11/9/2011 7:29 AM, Jens Thoms Toerring wrote:
> In comp.unix.programmer Thad Smith<ThadSmith@acm.org>  wrote:
>> On 11/5/2011 3:00 PM, Mark wrote:
>
>>>>> I've read through 'man indent' but have not found if it allows to enforce
>>>>> C-style comments. Am I missing any option using which would convert C++
>>>>> comments in to C-style?
>
>> It's a nice programming exercise to convert the comments.  Remember to
>> disable  // searches in string constants and character constants.
>
>>   For solid code, you
>> need to also process trigraphs and line continuations.
>
> How could "//" appear in a character constant?

6.4.4.4: An integer character constant is a sequence of one or more multibyte 
characters enclosed in single-quotes, as in 'x'.

The BNF also shows
character-constant:	' c-char-sequence '
			L' c-char-sequence '
c-char-sequence:	c-char
			c-char-sequence c-char
c-char:			any member of the source character set except
the single-quote ', backslash \, or new-line character escape-sequence

An int may hold multiple bytes.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web