[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how can I remove all the comments in my c program.

Vellingiri Arul

9/19/2007 10:20:00 AM

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-....

27 Answers

Sebastian Hungerecker

9/19/2007 10:41:00 AM

0

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

9/19/2007 10:47:00 AM

0

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-....

(Mortar)

9/19/2007 11:02:00 AM

0

"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-....
>


Daniel Lucraft

9/19/2007 12:18:00 PM

0

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...

best,
Dan
--
Posted via http://www.ruby-....

Marcin Raczkowski

9/19/2007 1:42:00 PM

0

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-....
>>
>
>
>
>
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.

ara.t.howard

9/19/2007 2:31:00 PM

0


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.
>

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://draw...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Peter Hickman

9/19/2007 2:55:00 PM

0

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.


Konrad Meyer

9/19/2007 6:21:00 PM

0

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-....
> >>
> >
> >
> >
> >
> 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.sobertil...

Marcin Raczkowski

9/19/2007 9:02:00 PM

0

Konrad Meyer wrote:
> 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-....
>>>>
>>>
>>>
>>>
>> 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.

(Mortar)

9/19/2007 11:51:00 PM

0

"Marcin Raczkowski" <mailing.mr@gmail.com> wrote in message
news:46F18F2D.6040100@gmail.com...
> Konrad Meyer wrote:
>> Quoth Marcin Raczkowski:
>>> On Web wrote:
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