Thread: colour highlighting of syntax

  1. #1
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72

    colour highlighting of syntax

    Sorry if this is misplaced, I've had a look through stickies and FAQs but can't find out how to post code that is syntax highlighted in colour.

    I assume there is a utility that understands C and C++ syntax and also vBulletin colour tags but is it standalone or an editor plug-in?

    I'm using TextPad on Windows XP and vi on Suse Linux and Ubuntu Linux and vim on Cygwin. These have their own colour syntax highlighting but do not use vBulletin [COLOR] tags.
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    I've written a painter. It is in my signature.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by siavoshkc
    I've written a painter. It is in my signature.
    Got it. Thx v much. You're a star.

    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
    
        return 0;
    }
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    There are three code colourers written by members of this board as far as I'm aware. siavoshkc's "code painter", Code Colorer v2.0 by Martin, and my codeform. (codeform's somewhat old and I'm rewriting it right now.)

    Here's a recent thread where we argue about which is the best: http://cboard.cprogramming.com/showthread.php?t=82592
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by dwks
    There are three code colourers written by members of this board
    Yes, thanks. I tried them all:

    CPP code tagger

    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
    
        return 0;
    }
    Color Coder V 2.0

    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
    
        return 0;
    }
    codeform

    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
    
        return 0;
    }
    And I do believe that codeform does have that little something extra; plus, with a little adjustment, I can use it on my Linux systems. Thanks dwks.

    Adjustment:
    - I removed the forward slash from the definition of the default dat file as forward slash is the Windows-specific directory path separator

    Note:
    - Neither Linux nor Windows liked the numbercol definition in codeform_cb_cpp.dat (the equal symbol before darkblue needs a backslash escape character)

    [numbercol]
    \[color=darkblue]=[/color]

    It says
    Quote Originally Posted by codeform
    Syntax error in data file "codeform.dat" on line 112:
    [numbercol]'s data must have 2 parts (it has 3)
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I've got my own, but it gets color happy if you use keywords in parts of your variable names... for example, int sprint would look bad.
    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
    
        return 0;
    }
    oh yeah, and it's C++ specific... or I should say C wasn't included in it's design considerations as you can see from the code above.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    try some harder cases... like

    printf("while Fooo if bar \"stuff\" foo break 'bar'....");

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I can tell you before I do it that those escapes wil break my coloring:
    Code:
    printf("while Fooo if bar \"stuff\" foo break 'bar'....");
    yep
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by major_small
    I've got my own, but it gets color happy if you use keywords in parts of your variable names... for example, int sprint would look bad.
    Code:
                printf("%0x ", ch ^ 0xaa);
    oh yeah, and it's C++ specific... or I should say C wasn't included in it's design considerations as you can see from the code above.
    It seems that the consideration that keywords should be delimited by whitespace was also not in the design.

    Have you ever thought of fixing it or would that be a completely bizarre suggestion on my part?
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by risby
    It seems that the consideration that keywords should be delimited by whitespace was also not in the design.
    I have thought of that, and at first glance it seems like a good idea... but that won't always work: static_cast<int>(12.5);
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  11. #11
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I think you'll have to introduce somehow the notion of delimiters into your keyword implementation and parse with these in mind as left-hand side delimiters.

    Delimiters will be BOF, newline, whitespace, comma, semi-colon, (, {, <... if nothing is escaping me.

    Any keyword may only be preceded by those above. Anything other than that will have another meaning.

    EDIT: actually the above will not work for situations like int introduce. So, there also needs to be a list of right hand side delimiters.
    Last edited by Mario F.; 09-19-2006 at 03:56 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #12
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Quote Originally Posted by risby
    It seems that the consideration that keywords should be delimited by whitespace was also not in the design.

    Have you ever thought of fixing it or would that be a completely bizarre suggestion on my part?
    More correctly they should be delimited by word boundaries, i.e. /\b\w+?\b/.

    I just use Vim's Convert to HTML and filter that through a Perl script to get BBCode whenever I want to get pretty. E.g.
    Code:
     1 #include <stdio.h>
     2 
     3 int main(void) {
     4     int ch;
     5 
     6     while ((ch = getchar()) != EOF)
     7         if (ch == '\n')
     8             printf("\n");
     9         else
    10             printf("%0x ", ch ^ 0xaa);
    11     printf("while Fooo if bar \"stuff\" foo break 'bar'....");
    12 
    13     return 0;
    14 }
    15 
    Last edited by zx-1; 09-19-2006 at 10:03 AM.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  13. #13
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Anyway my code painter handle it easily.
    Code:
    printf("while Fooo if bar \"stuff\" foo break 'bar'....");
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  14. #14
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by Perspective
    try some harder cases... like

    printf("while Fooo if bar \"stuff\" foo break 'bar'....");
    None of them failed the Perspective test:

    SiavoshKC's
    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
        printf("while Fooo if bar \"stuff\" foo break 'bar'....");
    
        return 0;
    }
    Martin's

    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
        printf("while Fooo if bar \"stuff\" foo break 'bar'....");
    
        return 0;
    }
    dwks'
    Code:
    #include <stdio.h>
    
    int main(void) {
        int ch;
    
        while ((ch = getchar()) != EOF)
            if (ch == '\n')
                printf("\n");
            else
                printf("%0x ", ch ^ 0xaa);
        printf("while Fooo if bar \"stuff\" foo break 'bar'....");
        return 0;
    }
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

  15. #15
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    This is thanks do dwks, I think they all pass that too -

    Code:
    printf("hi");
    
    #define /*what?*/ foo
    
    puts("\\\"");
    
    in\
    t x;
    
    printf("/*comment*/");
    
    /* int x; printf("int x;"); */
    
    // /*
    for(;;){}
    //*/
    
    /*//*/ int okay;
    Or at least they don't break upon implementation

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM