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

Discussion in 'Ruby' started by Vellingiri Arul, Sep 19, 2007.

  1. 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, Sep 19, 2007
    #1
    1. Advertising

  2. 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:
    ICQ: 205544826
     
    Sebastian Hungerecker, Sep 19, 2007
    #2
    1. Advertising

  3. 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/.
     
    Vellingiri Arul, Sep 19, 2007
    #3
  4. Vellingiri Arul

    On Web Guest

    "Vellingiri Arul" <> wrote in message
    news:...
    > 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/.
    >
     
    On Web, Sep 19, 2007
    #4
  5. 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.ht...ession-to-strip-C-style-comments-from-a-file?

    best,
    Dan
    --
    Posted via http://www.ruby-forum.com/.
     
    Daniel Lucraft, Sep 19, 2007
    #5
  6. On Web wrote:
    > "Vellingiri Arul" <> wrote in message
    > news:...
    >> 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.
     
    Marcin Raczkowski, Sep 19, 2007
    #6
  7. Vellingiri Arul

    ara.t.howard Guest

    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://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
     
    ara.t.howard, Sep 19, 2007
    #7
  8. 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.
     
    Peter Hickman, Sep 19, 2007
    #8
  9. Vellingiri Arul

    Konrad Meyer Guest

    --nextPart1709184.N4EHa9TSQk
    Content-Type: text/plain;
    charset="utf-8"
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: inline

    Quoth Marcin Raczkowski:
    > On Web wrote:
    > > "Vellingiri Arul" <> wrote in message=20
    > > news:...
    > >> 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.

    > >=20
    > > Why would anyone want to remove the comments from a program?
    > >=20
    > > Paul
    > >=20
    > >> Please any one tell me.
    > >>
    > >> By
    > >> Vellingiri.
    > >> --=20
    > >> Posted via http://www.ruby-forum.com/.
    > >>

    > >=20
    > >=20
    > >=20
    > >=20

    > becouse they have to release it as open source becouse of GPL or other=20
    > OS license and they want to make imposible to actually use that code by=20
    > 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.

    =2D-=20
    Konrad Meyer <> http://konrad.sobertillnoon.com/

    --nextPart1709184.N4EHa9TSQk
    Content-Type: application/pgp-signature; name=signature.asc
    Content-Description: This is a digitally signed message part.

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.7 (GNU/Linux)

    iD8DBQBG8WiUCHB0oCiR2cwRAnTYAJ9dcx+xWN1llFbEKcIfrdqpHUWehQCfXoN2
    HgZWPQ3T5ZZfNj0Wjsa6v94=
    =jd/C
    -----END PGP SIGNATURE-----

    --nextPart1709184.N4EHa9TSQk--
     
    Konrad Meyer, Sep 19, 2007
    #9
  10. Konrad Meyer wrote:
    > Quoth Marcin Raczkowski:
    >> On Web wrote:
    >>> "Vellingiri Arul" <> wrote in message
    >>> news:...
    >>>> 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.
     
    Marcin Raczkowski, Sep 19, 2007
    #10
  11. Vellingiri Arul

    On Web Guest

    "Marcin Raczkowski" <> wrote in message
    news:...
    > 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
     
    On Web, Sep 20, 2007
    #11
  12. Vellingiri Arul

    Todd Benson Guest

    On 9/19/07, 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 try to meet your helpers half way.

    Thanks,

    Todd
     
    Todd Benson, Sep 20, 2007
    #12
  13. Vellingiri Arul

    Chris Carter Guest

    On 9/19/07, 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.
    >
    > Paul
    >


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


    --
    Chris Carter
    concentrationstudios.com
    brynmawrcs.com
     
    Chris Carter, Sep 20, 2007
    #13
  14. Vellingiri Arul

    Phlip Guest

    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.


    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.

    --
    Phlip
     
    Phlip, Sep 20, 2007
    #14
  15. 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:
    > 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.

    >
    > 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?
     
    Marcin Raczkowski, Sep 20, 2007
    #15
  16. 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.
     
    Peter Hickman, Sep 20, 2007
    #16
  17. Vellingiri Arul

    Paul Knight Guest

    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?


    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
     
    Paul Knight, Sep 20, 2007
    #17
  18. Paul Knight wrote:
    > 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?

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

    Hello,
    What do you want?Why are you scolding me like that.
    If we are asking only doubts,If you know tell yes.otherwise you tell no.
    Don't speak nonsence others.
    ok.

    by
    velligniri.

    --
    Posted via http://www.ruby-forum.com/.
     
    Vellingiri Arul, Sep 20, 2007
    #18
  19. Vellingiri Arul

    Paul Knight Guest

    On Sep 20, 2007, at 3:15 AM, Vellingiri Arul wrote:

    > Paul Knight wrote:
    >> 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?

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

    > Hello,
    > What do you want?Why are you scolding me like that.
    > If we are asking only doubts,If you know tell yes.otherwise you
    > tell no.
    > Don't speak nonsence others.
    > ok.
    >
    > by
    > velligniri.
    >


    We're curious why you want to strip out comments, and whether it may
    or may not be a good idea. I wanted to suggest to several others that
    there are legitimate reasons, though a few of them might be slightly
    misguided. Perhaps if you explained why you want to get rid of the
    comments, it would clear up some of the messages in this thread.

    --Paulymer
     
    Paul Knight, Sep 20, 2007
    #19
  20. Paul Knight wrote:
    > On Sep 20, 2007, at 3:15 AM, Vellingiri Arul wrote:
    >
    >>> different way, by surrounding it with prose, and the comments would
    >>>

    >> by
    >> velligniri.
    >>

    >
    > We're curious why you want to strip out comments, and whether it may
    > or may not be a good idea. I wanted to suggest to several others that
    > there are legitimate reasons, though a few of them might be slightly
    > misguided. Perhaps if you explained why you want to get rid of the
    > comments, it would clear up some of the messages in this thread.
    >
    > --Paulymer


    Hello Friends,
    I am also working in software company.
    You ask know why are removing the comments in your c program.
    For needness I want to remove all the comments and also I want to align
    all the program coding lines.
    --
    Posted via http://www.ruby-forum.com/.
     
    Vellingiri Arul, Sep 20, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,149
  2. James Hu

    Program to remove C comments (long signature)

    James Hu, Nov 12, 2003, in forum: C Programming
    Replies:
    11
    Views:
    907
    CBFalconer
    Nov 14, 2003
  3. Frank Potter
    Replies:
    9
    Views:
    609
  4. Monk
    Replies:
    10
    Views:
    1,491
    Michael Wojcik
    Apr 20, 2005
  5. Replies:
    4
    Views:
    623
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page