![]() |
04-03-2007, 11:57 AM
|
#31 |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
I've uploaded codeform again. The only changes are:
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));
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;
}
Code:
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello, World!\n");
return 0;
}
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=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]
__________________
dwk Seek and ye shall find. quaere et invenies. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! Last edited by dwks : 04-03-2007 at 12:45 PM. |
dwks is online now
|
|
04-03-2007, 12:32 PM
|
#32 |
|
The Superheterodyne
Join Date: Dec 2005
Location: Ireland
Posts: 1,542
|
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!
__________________
I've got to get a girlfriend, just for the summer, until this wears off. She'll be a summery girl. She'll have hair. She'll have summery friends who know how to be outside. She'll play tennis and wear dresses and have bare feet, and in the autumn, I'll ditch her, because she's my summer girl! |
twomers is offline
|
|
04-03-2007, 12:48 PM
|
#33 |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
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. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! |
dwks is online now
|
|
04-03-2007, 01:48 PM
|
#34 |
|
Perfect Gentleman
Join Date: Apr 2006
Location: MI
Posts: 1,256
|
> 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 < 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 citizen : 04-03-2007 at 02:02 PM. |
citizen is online now
|
|
04-03-2007, 02:12 PM
|
#35 |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
Right, see, I didn't know what the settings you were using were or anything.
Codeform actually does replace "<" with "<", as you can see from viewing the source of the output: Code:
<font color="green">#include <stdio.h></font> 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");
Code:
#exec("perl $0");
Code:
for(;;) {
system("perl pclipcf2_modified.pl");
}
__________________
dwk Seek and ye shall find. quaere et invenies. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! Last edited by dwks : 04-03-2007 at 02:17 PM. |
dwks is online now
|
|
04-03-2007, 02:23 PM
|
#36 |
|
The Superheterodyne
Join Date: Dec 2005
Location: Ireland
Posts: 1,542
|
But ... what happens if someone creates a batch file called perl and it does bad things, dwks?
__________________
I've got to get a girlfriend, just for the summer, until this wears off. She'll be a summery girl. She'll have hair. She'll have summery friends who know how to be outside. She'll play tennis and wear dresses and have bare feet, and in the autumn, I'll ditch her, because she's my summer girl! |
twomers is offline
|
|
04-04-2007, 11:29 AM
|
#37 |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
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");
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]
__________________
dwk Seek and ye shall find. quaere et invenies. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! Last edited by dwks : 04-04-2007 at 02:26 PM. |
dwks is online now
|
|
04-08-2007, 10:00 PM
|
#38 | |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
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: Quote:
![]() 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). So, here's how you run it from outside the codeform directory: Code:
C:\pclipcf4>perl pclipcf4.pl c:\codeform Code:
use Win32::Clipboard;
my $clip = Win32::Clipboard();
for(;;) {
$clip->WaitForChange();
}
![]() 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. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! |
|
dwks is online now
|
|
04-13-2007, 01:00 PM
|
#39 |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
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.
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;
}
![]() 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/showthread.php?p=633909 [/edit]
__________________
dwk Seek and ye shall find. quaere et invenies. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! Last edited by dwks : 04-13-2007 at 01:42 PM. |
dwks is online now
|
|
04-18-2007, 10:45 AM
|
#40 |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
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 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. ![]()
__________________
dwk Seek and ye shall find. quaere et invenies. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! Last edited by dwks : 04-18-2007 at 01:11 PM. |
dwks is online now
|
|
04-18-2007, 12:14 PM
|
#41 |
|
Lean Mean Coding Machine
Join Date: Mar 2007
Location: Luxembourg, Europe
Posts: 374
|
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 ? |
KONI is offline
|
|
04-18-2007, 12:26 PM
|
#42 | |
|
Registered User
Join Date: Mar 2007
Posts: 530
|
Quote:
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. |
|
brewbuck is offline
|
|
04-18-2007, 01:10 PM
|
#43 |
|
DWK
Join Date: Apr 2005
Location: Canada
Posts: 4,239
|
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. (Latin by dwks.) "Only those who will risk going too far can possibly find out how far one can go." -- TS Eliot "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison "The only real mistake is the one from which we learn nothing." -- John Powell My website: http://dwks.theprogrammingsite.com/ Other programming boards: codeform version 1.2.0 is here! |
dwks is online now
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|