codeform version 1.2.0 #2

This is a discussion on codeform version 1.2.0 #2 within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I've uploaded codeform again. The only changes are: get_string() doubles the allocated memory when it runs out of space, speeding ...

  1. #31
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I've uploaded codeform again. The only changes are:
    1. get_string() doubles the allocated memory when it runs out of space, speeding up codeform for very long source code lines.
    2. clinkfunc, cdescfunc, and cdesclinkfunc rules files have been added. They only work with HTML so far like so:
      Code:
      C:\>codeform -f rules\c_1_css -f rules\cdesclinkfunc codeform.c
      But you can easily modify them for use with BBCode. Just change the top ten lines where variables are initialized.


    I've also created Perl versions of my clipboard programs. The first package is pclip.zip: http://dwks.theprogrammingsite.com/m...down/pclip.zip

    It contains pclipset.pl, pclipget.pl, and pclipclr.pl, which set, get, and clear the clipboard. The whole archive is 510 bytes and this is the most complicated of the three:
    Code:
    use Win32::Clipboard;
    
    my $CLIP = Win32::Clipboard();
    
    my @data = <STDIN>;
    
    $CLIP->Set(join('', @data));
    They work better than my C ones; they never add mysterious characters to the end or chop off the last character.

    There's also pclipcf2.zip: http://dwks.theprogrammingsite.com/m...n/pclipcf2.zip

    It's really neat. You run it in the background from codeform's install directory. Then whenever you put something into the clipboard that starts with "//cf", it runs codeform on the clipboard (after removing the "//cf") and puts the results in the clipboard. So you just write some code like
    Code:
    //cf
    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
        printf("Hello, World!\n");
        return 0;
    }
    (without code tags), copy it into the clipboard, and viola! your clipboard contains this (with code tags):
    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
        printf("Hello, World!\n");
        return 0;
    }
    It's amazing. Sort of annoying if you need to copy text starting with "//cf", but that shouldn't happen too often. It takes virtually no CPU time, except when you modify the clipboard. It must be run from codeform's install directory -- i.e. the same directory as codeform.exe. It only works on Windows. And don't worry, if the clipboard doesn't start with //cf, it leaves it alone. Let me know how it works. [edit=2] It doesn't seem to work too well with Windows XP . . . [/edit]

    [edit] For non-Perl gurus:
    Code:
    C:\whatever\codeform>perl pclipcf.pl
    [/edit]

    [edit=3] pclipcf update
    There's a new version of pclipcf, version 3. It works with Windows XP even.
    http://dwks.theprogrammingsite.com/m...n/pclipcf3.zip [/edit]
    Last edited by dwks; 04-03-2007 at 12:45 PM.
    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.

  2. #32
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    That's pretty neat! so \\cf your code, copy it and paste it and it should work without me having to encode it manually? You're a king of being nice to lazy people!

  3. #33
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Yeah, well, I fall into that category too you know.

    The latest version of pclipcf, version 3, works on Windows XP. See my edit.

    In case anyone wants to get the Perl interpreter for Windows, here's where: http://www.activestate.com/Products/ActivePerl/
    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.

  4. #34
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    > Post the code you messed it up with.
    No.

    > It works pretty well for me.
    That's because you're still spitting out BB code. HTML treats < and > very differently, and that's what I mean. You see, before posting BB code, the scripts that this board works with will replace all those < > with some &#60 special character jargon. So you don't need to worry about it. But in a web page, #include <header> will be parsed by browsers as #include ; template<class T> will also probably just be template .

    Try it yourself and see.
    Last edited by whiteflags; 04-03-2007 at 02:02 PM.

  5. #35
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Right, see, I didn't know what the settings you were using were or anything.

    Codeform actually does replace "<" with "&lt;", as you can see from viewing the source of the output:
    Code:
    <font color="green">#include &lt;stdio.h&gt;</font>
    But I guess I have to replace "<" with "&amp;lt;" for HTML. Thanks for the bug report. I'll fix it as soon as I can.

    I never really thought the online version would be used for anything but BBCode so I guess when I tacked on HTML support I forgot about that.

    [edit] It looks like I haven't uploaded the right pclipcf3.zip . . . rats, it's not on this computer. I'll upload it as soon as I can. Or you can modify pclipcf2.pl; just comment out the line
    Code:
    exec("perl $0");
    changing it into
    Code:
    #exec("perl $0");
    and create a new script to run the other one in an infinite loop:
    Code:
    for(;;) {
        system("perl pclipcf2_modified.pl");
    }
    [/edit]
    Last edited by dwks; 04-03-2007 at 02:17 PM.
    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.

  6. #36
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    But ... what happens if someone creates a batch file called perl and it does bad things, dwks?

  7. #37
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I would put the full path in, but it's not standard on Windows systems and the Windows version of perl doesn't support shebangs (#!/usr/bin/perl). Perhaps there's a variable that contains the path to the Perl interpreter, like $(MAKE) in Makefiles. I'll look into it. [edit=2] It's $^X. So you could use
    Code:
    exec("$^X $0");
    Looks really cryptic, eh? Maybe put a comment in too. [/edit]

    Besides, I just wrote that program in half an hour.

    Version 2 (with the exec) works on Windows 98. For Windows XP, just remove the exec line and it should work. I'll try to make a platform-independent version soon.

    But just think of the possibilities for that code! If you've ever used KDE, you know the value of kclip, which holds previous clipboard values. You can copy something, copy something else, and then click on kclip and choose some previous content of the clipboard to store in the clipboard. I could write something like that for Windows. [edit] Not that it hasn't already been done: http://ditto-cp.sourceforge.net/ [/edit]

    Or I could write a version that, whenever a file (image) is put into the clipboard, the image is resized to 800x600 . . . useful for digital cameras that have really bad reading software (like mine). I could even make something like this:
    Code:
    /b: bold
    /c: code
    /blue: [color=blue]
    for use on CBoard, or RTF; I could make a backup program -- copy the files you want backed up, tell this program to do something, and it will copy them . . . the possibilities are endless.
    Last edited by dwks; 04-04-2007 at 02:26 PM.
    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.

  8. #38
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I have not done much with codeform proper, but I've rewritten pclipcf again; this version is called pclipcf4. I've tested it on Windows 98 and XP and it works on both. Here's the download link (it's 1172 bytes): http://dwks.theprogrammingsite.com/m...n/pclipcf4.zip

    See the post 7 posts up for details about pclipcf:
    It's really neat. You run it in the background [...] Then whenever you put something into the clipboard that starts with ["[cf]"], it runs codeform on the clipboard (after removing the ["[cf]"]) and puts the results in the clipboard.
    pclipcf4 is broken up into functions. It exists in one script, so there's no problems with exec. And it even has a comment at the top explaining what it does.
    Code:
    # pclipcf4.pl by DWK
    # Perl script to run codeform with the clipboard for input and output
    #
    # Usage: pclipcf4.pl [-s start-sequence] [path-to-codeform [arguments]]
    #
    # If the clipboard starts with the start sequence, executes codeform on the
    # clipboard's contents and puts the output back into the clipboard.
    # Otherwise, does nothing.
    #
    # The start sequence is by default "[cf]".
    #
    # This script is Windows-only and not thread-safe!
    # In other words, don't run multiple instances of it.
    # It takes no CPU except when the clipboard is changed (on the OSes tested).
    As you can see, the default starting sequence has been changed to "[cf]", but you can change it with a command-line argument. As well, this script can be run from anywhere -- you just pass it the location of codeform's install directory. Finally, you can tell it what arguments to pass codeform. (The default is "rules/cpp_1_vbb".)

    So, here's how you run it from outside the codeform directory:
    Code:
    C:\pclipcf4>perl pclipcf4.pl c:\codeform
    Note that you have to quit it with CTRL-C. Under Windows XP this causes an illegal operation. However, this is beyond my control as it happens even with this simple script:
    Code:
    use Win32::Clipboard;
    
    my $clip = Win32::Clipboard();
    
    for(;;) {
        $clip->WaitForChange();
    }
    Just ignore it. It's supposed to be quitting anyway.

    Also, while codeform is executing, pclipcf4 clears the clipboard. So if you've highlighting a really large chunk of code (like codeform's source, over 2000 lines), and you press CTRL-C-V and nothing happens (that's what happens with an empty clipboard), wait a few milliseconds and press CTRL-V again.
    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.

  9. #39
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I've uploaded codeform again. There are no changes to the actual program, but I added a subdirectory called exts/ which contains 50KB (>25 files) of extensions to codeform. (The .ZIP is now 227208 bytes, 222KB.)

    I'll copy exts/README.txt here:
    Code:
    This directory, exts/, contains several extensions to codeform. Perl is
    required to run many of them. You can get Perl for Windows at:
        http://activestate.com/
    
    codeform.pl is used to host codeform online at
    http://dwks.theprogrammingsite.com/myprogs/down/codeform_online/cfonline.htm
    
    The rest of the files are related to clipboard extensions. You can run them by
    executing the batch files or directly from the command line, with your own
    options.
    
    Here are the files in exts/ and a brief description:
    asyncdown.c         C source code for asyncdown
    asyncdown.exe       Returns true if a given key is held down
    clip_inout_any.bat  Codeforms the data from and to the clipboard
    clip_inout_vbb.bat  The same, but rules\cpp_1_vbb is added to the args
    clip_shift.bat*     Codeforms the clipboard when CTRL-SHIFT-C is pressed
    clip_start.bat*     Codeforms the clipboard when it starts with "[cf]"
    clip_start_any.bat* The same, but when it starts with the first argument
    clipclr.c           C source code for clipclr
    clipclr.exe         Clears the clipboard
    clipget.c           C source code for clipget
    clipget.exe         Prints the contents of the clipboard (like pclipget.pl)
    clipset.c           C source code for clipset
    clipset.exe         Stores its input into the clipboard (like pclipset.pl)
    cliptee.c           C source code for cliptee
    cliptee.exe         Stores input into the clipboard, but also prints the data
    codeform.pl*        Perl script for codeform online
    pclipcf.pl*         Codeforms the clipboard for multiple conditions
    pclipcf4.pl*        (old) Codeforms the clipboard when it starts with a string
    pclipclr.pl*        Clears the clipboard
    pclipget.pl*        Prints the contents of the clipboard to the screen
    pclipset.pl*        Sets the clipboard to the data it is passed (from stdin)
    pcliptee.pl*        Stores input into the clipboard, but also prints the data
    presdir.exe         CDs somewhere, executes a command, then CDs back
    presdir.c           C source code for presdir
    README.txt          This readme file
    shiftdown.c         C source code for shiftdown
    shiftdown.exe       Returns true if either shift key is currently held down
    
    Programs marked with an asterisk (*) require Perl to run.
    Usually, unless you want something unusual, you execute one of the batch files.

    clip_inout_any.bat: This uses the clipboard for input and output to codeform, but you need to pass it some arguments because it doesn't add any. Execute this from the command line only.
    clip_inout_vbb.bat: The same, but rules\cpp_1_vbb is added to the arguments. You can run this from Windows. I have a shortcut to it.
    clip_shift.bat: [perl] *NEW* When you press CTRL-SHIFT-C, the clipboard is codeformed; CTRL-C, it isn't. See below.
    clip_start.bat: Codeforms the clipboard when it starts with "[cf]". Identical to pclipcf4.pl (which is still included if you want to use it). Run this from Windows.
    clip_start_any.bat: The same, but you specify what to use instead of "[cf]" for the first argument. Run this from a command line.

    What's really neat is clip_shift.bat. When it is running, if you press CTRL-SHIFT-C instead of CTRL-C, the clipboard is codeformed. No more typing an extra four characters for "[cf]"! We're lazier than that! Just press shift! Unfortunately it doesn't work on Windows 98, though it does work on Windows XP. I can't imagine why; here's its code:
    Code:
    #include <windows.h>
    
    int main(void) {
        return GetAsyncKeyState(VK_SHIFT) & 0x8000 ? 1 : 0;
    }
    Also, some programs trap CTRL-SHIFT-C. If that is the case, you could modify that code, or use asyncshift to trap both shifts, or use notepad.

    I also fixed a bug in the C clipboard programs. They now work just as well as the Perl ones.

    I also added cliptee, which is like clipset but it also prints the clipboard contents to the screen.

    [edit] I posted that exactly on the hour! That doesn't happen too often . . . 1/60 of the time in fact. [/edit]

    [edit=2] Vote for code colouring! http://cboard.cprogramming.com/brief-history-cprogramming-com/88629-proposal-code-colouring.html#post633909 [/edit]
    Last edited by dwks; 04-13-2007 at 01:42 PM.
    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.

  10. #40
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Codeform online has moved. The new location of cfonline.htm is at this shorter address: http://dwks.theprogrammingsite.com/myprogs/cfonline.htm

    The same file at the old location can still be accessed, but I may get rid of it soon.

    I don't suppose anyone really cares, but I've fixed citizen's bug. I've also created C versions of all of the Perl scripts included in codeform.zip (except for the codeform online script, codeform.pl), but I haven't added them to the .ZIP because right now you have to do something like this:
    Code:
    whenkey -p "clipget | startseq -p "clipget | stripchars 4 |\
    presdir .. codeform rules\cpp_1_vbb exts\clipset" [cf]" ctrl c
    Except you can't have double quotes inside double quotes on Windows, of course; you need multiple batch files. But if someone wants them, let me know. I'll add them to the .ZIP once they work properly (well, almost anyway).

    I've also enabled cdescfunc, clinkfunc, and cdesclinkfunc, though since you can't specify codeform's arguments, they only work with HTML and CSS. Also, don't try checking more than one of those cfunc checkboxes.
    Last edited by dwks; 04-18-2007 at 01:11 PM.
    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.

  11. #41
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Could I ask where you got your grammars from? I intend to write a real-time code colorer and syntax analyzer with JavaScript but I had problems finding the lexical and syntactical grammar.

    So I was wondering if there was an official grammar somewhere ?

  12. #42
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by KONI View Post
    Could I ask where you got your grammars from? I intend to write a real-time code colorer and syntax analyzer with JavaScript but I had problems finding the lexical and syntactical grammar.
    There are grammars out there, but they're old. Obviously, there is an official grammar of the C language, but it varies between language levels (pre-C90, C90, C99, etc.)

    I think implementing a complete grammar for the C language would be overkill. It might even work against you, since people edit code in real-time and the code goes through intermediate states where it is not even valid C. You wouldn't want your code colorer to oscillate wildly as people type stuff.

    Most code coloring software is based on heuristics. There is some basic grammar processing going on, but it's mostly at a lexical level. So really, all you need is a lexer, not a full blown parser. You wouldn't have to code it to standard -- just code it so that it highlights things how you want them highlighted.

  13. #43
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I didn't use any grammer at all, believe it or not. Codeform just looks for keywords based on whether the characters before and after the keyword are non-alphanumeric or not. It works reasonably well, but of course I can't easily tell the difference between parentheses for function calls and parentheses for expressions.
    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.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. No Version info tab in file properties?
    By cpjust in forum Windows Programming
    Replies: 2
    Last Post: 06-03-2008, 03:42 PM
  3. How to set File Version of VC++ 6 dll
    By mercury529 in forum Windows Programming
    Replies: 3
    Last Post: 12-08-2006, 01:49 PM
  4. Finding the windows version...
    By The_Muffin_Man in forum Windows Programming
    Replies: 1
    Last Post: 06-10-2004, 11:39 PM
  5. Dev C++ Version 5
    By Zoalord in forum C++ Programming
    Replies: 3
    Last Post: 08-30-2003, 01:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21