|
Igor,
Yes, that's the case, this macro does not account for C-style comments. The reason (or excuse, perhaps ) is that it's very difficult to accurately detect where such comments begin and end, and then keep track of their locations for every subsequent change. With C++ comments, it's easy. The comment goes to the end of the line. C-style comments can go for one or more lines and accounting for them is not something I thought would merit my time and effort.
On the plus side, if a block of code has been commented in C-style, it will also get reformatted, which is often a good thing.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
This line:-
;for(;; );
Gets changed to:-
; f
or (;; )
;
Strange but true...
|
|
|
|
|
Man, I don't know what's stranger, my macro not properly formatting this code or the code itself.
I took a look at why this happens and found the problem. It'll be fixed on the next version, coming up soon.
Thanks,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
The macro changes
#define CHECK(xml, hr) \
if( FAILED(hr) ) {\
addFault(xml, hr); \
}
to
#define CHECK(xml, hr) \
if (FAILED(hr))
{
\
addFault(xml, hr); \
}
which the compiler isn't nearly as happy with
Niels Harremoës
|
|
|
|
|
Yup, unfortunately the macro does not distinguish between real code and code inside multi-line #defines. I haven't given it much thought but I suppose it could account for such code by simply checking the last character in the line. If it's a backslash, then the line shouldn't be touched.
Let me look into it and I'll try to post an update sometime next week.
Thanks,
Alvaro
|
|
|
|
|
A week later.... or more like a year later.
I've just taken care of this issue and sent it to Chris for an update, so you may expect it soon.
Thanks for reporting it and being patient.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
There is still a little problem with multiline macro's
#define THEMACRO \
if (x!=y) x = y;
changes to
#define THEMACRO \
if (x != y)
x = y;
I think instead of checking the end of the current line for '\' and
checking for '#define' should be replaced with checking for '#define' in the current line and checking for '\' at the end of the previous line.
thanks for your great work
michael
|
|
|
|
|
I am new to this macro thing. Can anyone suggest how I might change this one to put the right bracket on the same line as the function definition?
Thank You
|
|
|
|
|
I just want to make a small comment on the MyFunc() { style:
IT SUCKS!
Having said that, if you still want to make it happen, the easiest way is to do it for ALL opening braces. Here are the steps I would follow:
1. Loop through every opening brace (not inside a comment or quoted string)
2. Select from the beginning of the line to the brace.
3. If the selection only contains blankspace,
- Delete it, and
- Backspace to the previous line.
4. Go back to step 2 until step 3 fails.
Remember to account for comments and quoted strings. Check the macro's code to see how I do it.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
Alvaro Mendez wrote:
I just want to make a small comment on the MyFunc() { style:
IT SUCKS!
I agree.
|
|
|
|
|
Alvaro Mendez wrote:
IT SUCKS!
I agree, it really sucs!!!
Best regards,
Alexandru Savescu
|
|
|
|
|
Hi
I read posts about deleting files. It also happened to me. However, when I reopened Visual Studio, everything worked great.
Probably this is something similar to the problem when Visual studio looses clipboard.
And also a different problem, I could not format the following code properly
#pragma warning(disable : 4786)
#pragma warning(disable : 4503)
#include <iostream.h>
int main()
{
if (abc) test();
else test3();
A test;
test.i =5;
cout << test.nick << endl;
return 0;
}
Igor Proskuriakov
|
|
|
|
|
Thanks for the excellent work.
I have found a problem in nested switch statement. It seems that lost the nesting depth.
The code bellow is my unfinished working code.
Note: notice that the spaces are lost in mail, I have replaced "tab" character to "+".
Also, If I want to keep the style as shown in original, how do I do?
Thanks,
// ====== Original ===========================================
BOOL CALLBACK
BioDataProc (HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
case WM_INITDIALOG:
PostMessage(hdlg, WM_USER, 0, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wp))
{
case IDM_BIO1:
case IDM_BIO2:
break;
}
break;
case WM_NOTIFY:
switch(((NMHDR FAR*)lp)->code)
{
case PSN_APPLY:
{
}
return TRUE;
case PSN_HELP:
DisplayHelp();
break;
}
break;
case WM_USER:
break;
case WM_ACTIVATE:
}
return FALSE;
}
// ====== After MakeSelectedCodeNicer =====================
BOOL CALLBACK
BioDataProc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
{
+switch (msg)
+{
++case WM_INITDIALOG:
+++PostMessage(hdlg, WM_USER, 0, 0);
+++return TRUE;
++case WM_COMMAND:
+++switch (LOWORD(wp))
+++{
+++case IDM_BIO1:
+++case IDM_BIO2:
++++break;
+++}
+++break;
+++case WM_NOTIFY:
++++switch (((NMHDR FAR*)lp)->code)
++++{
++++case PSN_APPLY:
+++++{
+++++}
+++++return TRUE;
++++case PSN_HELP:
+++++DisplayHelp();
+++++break;
++++}
++++break;
++++case WM_USER:
+++++break;
++++case WM_ACTIVATE:
+}
+return FALSE;
}
|
|
|
|
|
I use this macro to reformart some files,but when run to this line the marco behave unconventionally.Who can help me ?
if (ads_entsel("\nSelect baseline: ",ent1,pt) == RTNORM)
if you want test,you can new a text file and run the macro to test.In my machine ,the line is like the following(after I cancel the macro):
if (ads_entsel("\n选择基线: ",ent1 ,pt) == RTNORM)
Thanks a lot!
|
|
|
|
|
if (ads_entsel("\nselect baseline :",ent1 ,pt) == RTNORM)
there are hundreds of blanks in "ent" and ",pt)==RTNORM),but in html this not show
|
|
|
|
|
I'm a chinese,I find when the prompt is use english there is no problem...but if if I use chinese language,when I run the reformat marco,the error occur...
|
|
|
|
|
I played a bit with it, the following code is deleted instead of reformatted!
int test()
{
int s;
for (s=0;s<2;s++)
{
test();
if (t==1)
{
test = 3;
}
}
}
This is no actual code, I've just typed a few lines.
Greetings,
Thomas
|
|
|
|
|
Deleted ha? That's a new one! I took this "not actual" code, copied it to a new file inside Visual C++, ran the macro, and guess what? It got reformatted beautifully.
Have you tried recording and running your own macros to see if you see the same behavior. It seems like something that only you're experiencing.
Regards,
Alvaro
|
|
|
|
|
I propose this utility here, because I think it may be of interest for some users.
It does a similar job as this one, except it is an external program, so its aim is quite different.
Check Artistic Style at http://astyle.sourceforge.net/
It seems it still have some bugs, but it is open source, so you can make it work the way you want...
|
|
|
|
|
I did look at Artistic Style, it is quite good, but not strict enough for me, e.g. it does not remove unnecessary spaces.
If you compare code of those two utilities, you may find that VBscript is much easier to understand.
Ideal utility is GNU indent, but it does not handle C++. Under ideal, I assume that you can configure almost everything, and when you add or remove any spaces or tabs and run the program once again, you shall have the same results.
Igor Proskuriakov
|
|
|
|
|
It does not move a block to the first column if the first character of the block is not at first column. This may be useful for copy-paste -- stealing others' code.
By the way, I hardly use formatting tools. It seems that Edit->Advanced->Format Selection is quick enough for me. At least it removes the indents that should not be there.
Has some one compare this tool with Smart Format that comes with MS studio?
|
|
|
|
|
I ran this macro on a large file. Visual C++ ran out of memory.
I was prompted to open a new instance of VC for each large file. I ran the large file again. It came up with the same problem. But the worst part is that when I tried to open up VC again - it came up with an acces violation on the strart-up screen. I will need to reload Visual C++.
|
|
|
|
|
Reload Visual C++? Do you mean reinstall it?
If that's the case, then it's definetely the first one I've come across. Try just rebooting your machine or something. You shouldn't need to reinstall VC... unless its registry settings got messed up somehow. Wow, that's one nasty VC bug, ha?
I have been able to run the macro on very large files once per VC session. After that I just close VC, open up a new session, and I can run it fine on another large file. If you can't even do that on your file, then perhaps it's way to huge even for one session. Try breaking it up.
Regards,
Alvaro
|
|
|
|
|
Yes - I Had to do a clean reinstall! Not even reinstalling sp3 helped.
This is realy a great utility. We want to use it in team development where every programmer has his own style.
I think that this will maybe work better as an add -in dll.
Send me your ideas on this - maybe we can work together ?
|
|
|
|
|
Hmmm, I wonder if these problems still occur when the script is executed through an add-in instead of the VBScript interpreter...
Anyway, I've never written an add-in before but I imagine it's not difficult. The problem is time, and right now I have very little of it to put into this type of effort.
Also, I wonder if a tool already exists that allows individual programmers to reformat code to their own tastes. That would be a nice one to have.
Regards,
Alvaro
|
|
|
|