How can I remove all the comments in my c program

Dear Friends,
     using The Ruby how can I remove all the comments in my c program.
      For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
     I have tried to do using the regular expression.
     But I was unable to find the anser for this.

Please any one tell me.

By
Vellingiri.

···

--
Posted via http://www.ruby-forum.com/.

Vellingiri Arul wrote:

Dear Friends,
     using The Ruby how can I remove all the comments in my c program.
      For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
     I have tried to do using the regular expression.
     But I was unable to find the anser for this.

The most simple regexen would be %r(//.*$) to match single line comments
and %r(/\*.*?\*/)m to match multiline comments, but these will give you some
false positives - for example, when you use // or /* inside a string.
If you want something that works reliably, you would need to use a C-parser
rather than regular expressions.

HTH,
Sebastian

···

--
NP: Porcupine Tree - Open Car
Jabber: sepp2k@jabber.org
ICQ: 205544826

"Vellingiri Arul" <hariharan.spc@rediffmail.com> wrote in message
news:7c7bc7fff388569ccf579f1c079d6760@ruby-forum.com...

Dear Friends,
    using The Ruby how can I remove all the comments in my c program.
     For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
    I have tried to do using the regular expression.
    But I was unable to find the anser for this.

Why would anyone want to remove the comments from a program?

Paul

···

Please any one tell me.

By
Vellingiri.
--
Posted via http://www.ruby-forum.com/\.

i'd start with c's own preprocessor and go from there:

cfp:~ > cat a.c
/* comment be gone */
main(){ printf("%i\n", (int)(0.55 * 100)); }

cfp:~ > cpp a.c
# 1 "a.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "a.c"

main(){ printf("%i\n", (int)(0.55 * 100)); }

cfp:~ > cpp -P a.c
main(){ printf("%i\n", (int)(0.55 * 100)); }

it already knows how to strip comments.

a @ http://drawohara.com/

···

On Sep 19, 2007, at 4:20 AM, Vellingiri Arul wrote:

Dear Friends,
     using The Ruby how can I remove all the comments in my c program.
      For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
     I have tried to do using the regular expression.
     But I was unable to find the anser for this.

Please any one tell me.

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

Please try to meet your helpers half way.

Thanks,

Todd

···

On 9/19/07, Vellingiri Arul <hariharan.spc@rediffmail.com> wrote:

Dear Friends,
     using The Ruby how can I remove all the comments in my c program.
      For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
     I have tried to do using the regular expression.
     But I was unable to find the anser for this.

Sebastian Hungerecker wrote:

Vellingiri Arul wrote:

Dear Friends,
     using The Ruby how can I remove all the comments in my c program.
      For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
     I have tried to do using the regular expression.
     But I was unable to find the anser for this.

The most simple regexen would be %r(//.*$) to match single line comments
and %r(/\*.*?\*/)m to match multiline comments, but these will give you
some
false positives - for example, when you use // or /* inside a string.
If you want something that works reliably, you would need to use a
C-parser
rather than regular expressions.

HTH,
Sebastian

Hai,
very very thank you.
I wil try to implement.

by
vellingiri.

···

--
Posted via http://www.ruby-forum.com/\.

Sebastian Hungerecker wrote:

Vellingiri Arul wrote:

Dear Friends,
     using The Ruby how can I remove all the comments in my c program.
     I have tried to do using the regular expression.

If you want something that works reliably, you would need to use a
C-parser
rather than regular expressions.

It is actually possible to do this reliably using regular expressions,
but it's not straightforward.

Try translating this into Ruby regexp:
http://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file%3F

best,
Dan

···

--
Posted via http://www.ruby-forum.com/\.

becouse they have to release it as open source becouse of GPL or other OS license and they want to make imposible to actually use that code by striping comments and obscuring code.

···

On Web wrote:

"Vellingiri Arul" <hariharan.spc@rediffmail.com> wrote in message news:7c7bc7fff388569ccf579f1c079d6760@ruby-forum.com...

Dear Friends,
    using The Ruby how can I remove all the comments in my c program.
     For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
    I have tried to do using the regular expression.
    But I was unable to find the anser for this.

Why would anyone want to remove the comments from a program?

Paul

Please any one tell me.

By
Vellingiri.
--
Posted via http://www.ruby-forum.com/\.

Marcin Raczkowski wrote:

becouse they have to release it as open source becouse of GPL or other OS license and they want to make imposible to actually use that code by striping comments and obscuring code.

Can we have the name of the company / project please. I wish to add it to my list of things to avoid.

Quoth Marcin Raczkowski:

···

On Web wrote:
> "Vellingiri Arul" <hariharan.spc@rediffmail.com> wrote in message
> news:7c7bc7fff388569ccf579f1c079d6760@ruby-forum.com...
>> Dear Friends,
>> using The Ruby how can I remove all the comments in my c program.
>> For example I have mentioned c program ,that may be ruby program
>> for your purpose you assume.
>> I have tried to do using the regular expression.
>> But I was unable to find the anser for this.
>
> Why would anyone want to remove the comments from a program?
>
> Paul
>
>> Please any one tell me.
>>
>> By
>> Vellingiri.
>> --
>> Posted via http://www.ruby-forum.com/\.
>>
>
>
>
>
becouse they have to release it as open source becouse of GPL or other
OS license and they want to make imposible to actually use that code by
striping comments and obscuring code.

Umm... That's illegal, by terms of the GPL. The GPL defines source code as
the preferred form for modification. Intentionally obfuscated code isn't
the preferred form for modification. So while it's technically "source
code", it isn't according to the definition in the GPL, and thus they're
violating the license by doing that.

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertillnoon.com/

Konrad Meyer wrote:

Quoth Marcin Raczkowski:

"Vellingiri Arul" <hariharan.spc@rediffmail.com> wrote in message news:7c7bc7fff388569ccf579f1c079d6760@ruby-forum.com...

Dear Friends,
    using The Ruby how can I remove all the comments in my c program.
     For example I have mentioned c program ,that may be ruby program
for your purpose you assume.
    I have tried to do using the regular expression.
    But I was unable to find the anser for this.

Why would anyone want to remove the comments from a program?

Paul

Please any one tell me.

By
Vellingiri.
--
Posted via http://www.ruby-forum.com/\.

becouse they have to release it as open source becouse of GPL or other OS license and they want to make imposible to actually use that code by striping comments and obscuring code.

Umm... That's illegal, by terms of the GPL. The GPL defines source code as
the preferred form for modification. Intentionally obfuscated code isn't
the preferred form for modification. So while it's technically "source
code", it isn't according to the definition in the GPL, and thus they're
violating the license by doing that.

well, i had "pleasure" of having internship in company which policy was - use only MIT/BSD or LGPL as liblary, we won't pay for any licenses.
If you HAVE to use GPL make sure your changes are not documented, and you use variable names like a,b,c and function names like fa fb etc.

while it's illegal to obscure code that's covered by gpl, if you write code that extends it, you can argue it's your programming style, code like this even not technically obfuscated is useless.

GPL can't force you to write documentation or make sefl-documenting code.

···

On Web wrote:

"Marcin Raczkowski" <mailing.mr@gmail.com> wrote in message
news:46F18F2D.6040100@gmail.com...

Konrad Meyer wrote:

Quoth Marcin Raczkowski:

snip

Why would anyone want to remove the comments from a program?

Paul

snip

becouse they have to release it as open source becouse of GPL or other
OS license and they want to make imposible to actually use that code by
striping comments and obscuring code.

Umm... That's illegal, by terms of the GPL. The GPL defines source code
as
the preferred form for modification. Intentionally obfuscated code isn't
the preferred form for modification. So while it's technically "source
code", it isn't according to the definition in the GPL, and thus they're
violating the license by doing that.

well, i had "pleasure" of having internship in company which policy was -
use only MIT/BSD or LGPL as liblary, we won't pay for any licenses.
If you HAVE to use GPL make sure your changes are not documented, and you
use variable names like a,b,c and function names like fa fb etc.

while it's illegal to obscure code that's covered by gpl, if you write
code that extends it, you can argue it's your programming style, code like
this even not technically obfuscated is useless.

GPL can't force you to write documentation or make sefl-documenting code.

Not quite the same thing as taking out what's already there. I really hope
the name of this company comes to light so they can get the negative
response they deserve.

Paul

···

On Web wrote:

Nowhere did the OP state that this is the reason. Someone else threw
that out. There may be a legitimate reason for this.

···

On 9/19/07, On Web <a@b.com> wrote:

Not quite the same thing as taking out what's already there. I really hope
the name of this company comes to light so they can get the negative
response they deserve.

Paul

--
Chris Carter
concentrationstudios.com
brynmawrcs.com

Worshipping comments is an intermediate, not advanced, behavior.

Comments have plenty of legitimate reasons to disappear, not least of which is comments written only to satisfy some perverse mandated code rules.

···

On Web wrote:

Not quite the same thing as taking out what's already there. I really hope
the name of this company comes to light so they can get the negative
response they deserve.

--
  Phlip

"Chris Carter" <cdcarter@gmail.com> wrote in message
news:86987bdf0709191705s6f9f170se3d9d61d4223f5d0@mail.gmail.com...

Not quite the same thing as taking out what's already there. I really
hope
the name of this company comes to light so they can get the negative
response they deserve.

Paul

Nowhere did the OP state that this is the reason. Someone else threw
that out. There may be a legitimate reason for this.

I was referring to the GPL comment dodge.

Still, stripping comments in a compiled language seems a bizarre idea to me,
apart from deliberately making it more difficullt for others to follow, or
to hide the origin of the code.

The OP has stated in another post that the intention (if I understand the
post correctly) is to neaten the code and to allow alignment of the program
lines.

Most companies would slap my wrists if I deliberately removed comments from
a source file and as for alignment, try and do it as you go along, or at
least try and not have huges source files so it's not too difficullt a
proposition.

Paul

···

On 9/19/07, On Web <a@b.com> wrote:

--
Chris Carter
concentrationstudios.com
brynmawrcs.com

well, i guess this flamewar is becouse of me, so... it's of course possible that someone want to remove all the comments from code for some strange reason (i don't understand why tho), i might have biased view becouse of my internship ... but tell me seriously ...

Phlip wrote:

Not quite the same thing as taking out what's already there. I really hope
the name of this company comes to light so they can get the negative
response they deserve.

Worshipping comments is an intermediate, not advanced, behavior.

i don't understand this statement... but if it means what i think it means you are seriously wrong, comments are more important the better you are becouse more advenced programmers tend to use lots of idioms and write optimized but not easilly readable code

Comments have plenty of legitimate reasons to disappear, not least of which is comments written only to satisfy some perverse mandated code rules.

i understand NOT writing comments, i do it myself often ... but if you already have them in C code ... then why remove them?
if you compile code the'lll disapear anyway.. i doubt he works on project that's source code is larger then 10mb compresed (and source files compress with 90% ratio) so size is probably not the problem euther...

Philip could you tell me one legitimate reason to remove comments from c code?

···

On Web wrote:

On Sep 21, 2007, at 8:10 AM, On Web wrote:

I was referring to the GPL comment dodge.

Still, stripping comments in a compiled language seems a bizarre idea to me,
apart from deliberately making it more difficullt for others to follow, or
to hide the origin of the code.

The OP has stated in another post that the intention (if I understand the
post correctly) is to neaten the code and to allow alignment of the program
lines.

Most companies would slap my wrists if I deliberately removed comments from
a source file and as for alignment, try and do it as you go along, or at
least try and not have huges source files so it's not too difficullt a
proposition.

people need to step back and realize that this is a religious issue not really related to ruby itself.

i happen to think comments are a crutch in in any language. here is an excerpt from the last program i wrote:

#! /dmsp/reference/bin/ruby

require 'time'
require 'ostruct'
require 'alib'
require 'lockfile'
require 'dmsp'
require 'nrtlib'
require 'stpjob'

Main {

   synopsis "gen_night_file_from_dawn_dusk_orbit_pairs [options]+ descending_olspath [ascending_olspath]"

   default "destination" => "/dmsp/nrt/data/incoming/night_files_dawn_dusk"
   default "window" => (42.minutes .. 62.minutes)

   option "--link" , "-l" ,
     "link files to operate on - default(copy)"

   option "--destination=destination" , "-d" ,
     "specify output destination - default(#{ default 'destination' })"

   option "--clobber" , "-c" ,
     "force output to be clobbered iff it exists - default(false)"

   option "--window=window" , "-w" ,
     "specify time window in which to look for ascending mate - default(#{ default('window').to_a.join ',' }s)"

   option "--turd" , "-t" ,
     "leave your things lying around default(false)"

   argument "descending_olspath"

   optional_argument "ascending_olspath"

   def main
     setup

     tmpdir do |tmp|
       atomically_download_input
       generate_night_files
       atomically_upload_output
       exit! 42 if turd?
     end

     exit 0
   end

   ...

i do not think comment can add any clarity to code that's written like this and, yes, you can do the same in C. that being said i'm (literally) on crutches now and everyone needs them sometimes - they are not evil - just crutches. compilers are crutches for not being able to write assembly code quickly enough.

regards.

a @ http://drawohara.com/

···

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

Marcin Raczkowski wrote:

Worshipping comments is an intermediate, not advanced, behavior.

i don't understand this statement... but if it means what i think it means you are seriously wrong, comments are more important the better you are becouse more advenced programmers tend to use lots of idioms and write optimized but not easilly readable code

Some programmers seem to think that comments are an excuse for badly written code. Well written code should be readable to a programmer proficient in the language in question, this means that the need for comments is reduced. People who insist on comments for everything tend not to be good programmers. People who do not write any comments are idiots no matter how advanced they are. There is always a need for comments, it just depends on the degree.

As to idiomatic code, if you are an X programmer you should be familiar with the idioms, if not learn some more. Also what is called idiomatic depends on you background, ++x could be considered an idiom if your background was perhaps COBOL, FORTRAN or LISP. Do you really expect such code to be commented just in case someone isn't familiar with the 'idiom'?

Comments have plenty of legitimate reasons to disappear, not least of which is comments written only to satisfy some perverse mandated code rules.

i understand NOT writing comments, i do it myself often ... but if you already have them in C code ... then why remove them?
if you compile code the'lll disapear anyway.. i doubt he works on project that's source code is larger then 10mb compresed (and source files compress with 90% ratio) so size is probably not the problem euther...

Philip could you tell me one legitimate reason to remove comments from c code?

The comments might be wrong! Comments tend not to be updated with the same rigour as the code. It is sometimes better to throw the comments out and make the programmer read the code to determine what it is doing than be led astray by badly written comments. The code is the authority as to what the program is doing, the comments are just commentary and cannot affect the execution of the code. Of course the *best* course of action is to completely rewrite the comments but if you can't do that then I would recommend removing comments that serve only to confuse the programmer.

Perhaps the original poster is going to run some custom code metrics or code analysis, but wants to get rid of comments first.

Perhaps the original poster is going to annotate the code in a different way, by surrounding it with prose, and the comments would obfuscate rather than illuminate.

Perhaps it's for golfing.

Perhaps it's for an art project. Or an illustration for an argument.

Perhaps the original poster hasn't thought it all the way through.

Perhaps it's something dark, sinister, and nefarious. But perhaps not.

Perhaps the original poster could respond?

--Paulymer

···

On Sep 20, 2007, at 2:08 AM, Marcin Raczkowski wrote:

[C]ould you tell me one legitimate reason to remove comments from c code?

"ara.t.howard" <ara.t.howard@gmail.com> wrote in message
news:1B5A85AE-42A1-4FFE-B0A9-26D46AB735CD@gmail.com...

On Sep 21, 2007, at 8:10 AM, On Web wrote:

snip

Still, stripping comments in a compiled language seems a bizarre idea to
me,
apart from deliberately making it more difficullt for others to follow,
or
to hide the origin of the code.

The OP has stated in another post that the intention (if I understand
the
post correctly) is to neaten the code and to allow alignment of the
program
lines.

Most companies would slap my wrists if I deliberately removed comments
from
a source file and as for alignment, try and do it as you go along, or at
least try and not have huges source files so it's not too difficullt a
proposition.

people need to step back and realize that this is a religious issue not
really related to ruby itself.

Yes, it's nothing to do with ruby, religious issue? I don't think so.

i happen to think comments are a crutch in in any language. here is an
excerpt from the last program i wrote:

snip

i do not think comment can add any clarity to code that's written like
this and, yes, you can do the same in C. that being said i'm (literally)
on crutches now and everyone needs them sometimes - they are not evil -
just crutches. compilers are crutches for not being able to write
assembly code quickly enough.

Well, I don't think the HLL compiler/LLL assembler analogy is right or
elevant here.

I understand that well written code can really reduce the need for comments
and comments can sometimes get in the way of reading the flow of code. The
real judge of whether comments are useful is when someone else who hasn't
written the code has to read it. They may even be new to the problem domain
and programming so what seems obvious to those 'in the zone' might be a
complete mystery to someone else, so comments are helpful in those
circumstances. Then we consider the environment where the code is written.
You might be writing the code, but two years down the line, Sarah will be
trying to make sense of it. Sarah has been told to add some feature to the
code if it's not there already. She's been told it's probably there, but
feature 'x' didn't go live when it should have, so it may already have been
coded, or not. It may just need testing to make sure that feature works. Of
course, you've left the company and changed address and phone number. Worse
still, you quarrelled with your old project manager so aren't minded to
co-operate in helping Sarah know what state the code's in.

If nothing else comments can provide a way of tracing the history of code, a
way of identifying who did what and a way of annotation so that you know
that a particular section of code has been altered to suit a particular
change request or bugfix ("Sarah, we've changed the database and object
model, please alter any code that was introduced for change request 66.9 to
reflect the new changes. Please check with whoever made those changes if you
can.").

So, I agree comments should be kept to a minimum. I don't agree that they
are a crutch - they are important for the working dynamic in an environment
where programmers aren't just developing for themselves. If you were working
in my team, you would be including comments - like it or not.

Paul

···

regards.

a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama