Archived

This topic is now archived and is closed to further replies.

aftermath

Code processor (not preprocessor, nompiler... POCESSOR!)

Recommended Posts

sorry if this does not belong in this forum Hey everyone! I am going to keep this short because I am writing on my PPC. Does anyone know of a C/Cpp code processor that can automatically process large amounts of code that would be hard to do by hand. For example: • Append “_T(“ to the beginning and “)” to the end of any quotes string. • Automatically cast variables. Like if I have an integer transformation to a float, I want to cast it using “(FLOAT)” or “dynamic_cast(…)” • Ect… I hope you know what I mean. The examples above aren’t exactly what I want to do, so don’t tell me how to do them, just tell me if anyone knows of such a tool. Thanks. Tell me if I need to clarify my post.

Share this post


Link to post
Share on other sites
There is a number of things that I need to do to my code.

Maybe someone knows of a source code formatter that can be changed programmatically or something like that.

There is no one thing that I want to do in particular… I just need it, ok?

Share this post


Link to post
Share on other sites
Well, you are pretty well going to have to write a program. You can use something like lex on unix, macros for an editor, a scripting language like Python or plain old C/C++. Whichever way you do it it is generally best to use several programs for a complex task rather than one huge complex one. You then write a script to run all of it. Do it in three phases. First extract the lines you want to change and the line number it was on. Then modify the extract file. Finally apply it back to the original. Also when you apply it back make sure the original line is still what it is suppose to be. Your most likely mistake after extracting the correct lines and making the correct changes is to apply it to the wrong file.

Doing it in phases and using seperate programs makes it easier to test and verify what you are about to do. Verifying that you got one in a hundred lines correctly identified and modified is a hassle and prone to error. Even successive lines with each having a differant modification made is prone to error. A file where every line is changed in the same manner makes the mistakes stand out. Simply applying the file at the end lets you stop in the middle and hand modify the odd error that would take a bunch of code to correct. A few minutes deleting a few lines or the next hour or two writing a hundred lines of code. The choice is yours.

Share this post


Link to post
Share on other sites
C++ is in general pretty hard to parse - it is context dependant. Sadly. Have luck writing your own solution (unless you are lucky and it is pretty easy because it is a special case).


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Share this post


Link to post
Share on other sites
You could try M4.

Most C preprocessors are based on a cut down version of this beauty, so the syntax shouldnt scare you.

You can also get full source code for it.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
sed.


what the hEcK does that mean?

thanks to everyone else... i will try perl then :D

dynamic sigs are fresh!

Share this post


Link to post
Share on other sites
When you see a word you don''t understand, it''s often helpful to google for it:
quote:

Sed (streams editor) isn''t really a true text editor or text processor. Instead, it is used to filter text, i.e., it takes text input and performs some operation (or set of operations) on it and outputs the modified text. Sed is typically used for extracting part of a file using pattern matching or substituting multiple occurances of a string within a file.



Think Liberally..

Share this post


Link to post
Share on other sites
Dogh!

I thought it was some underground word that says “this guy is a jerk” or something like that. You know, like “pleh” or something.

I guess the AP should have been just a BIT more descriptive… sorry, or “my bad, dog!” as they say it.

dynamic sigs are fresh!

Share this post


Link to post
Share on other sites
Perl is nice for processing text...

Do you use Visual C++? If you do, then, in the Find/Replace dialog box, you can check "Regular expressions". This is a really powerful feature which lets you do really neat text replacements. I dunno if you''re familiar with regular expressions, if not then here''s some info..

Regular expressions let you search for complex patterns. For example:

To find a capital letter, you''d say:
[A-Z]

To find a string of lowercase letters you''d say:
[a-z]+

To find an identifier (some word which could potentially be used as a variable in some programming language):
\:i

To find a character which isn''t #:
[^#]

To turn a bunch of functions which look like:
void SetAlpha(int alpha)

into:

void Graphics::SetAlpha(int alpha)

You could say:

Find:
void \(\:i\)(\(\:i\))

Replace with:
void Graphics::\1(\2)

Once you get used to it, it''s pretty easy to spit out huge expressions like the ones above, so when you have some really repetitive text editing task, it can be quite handy..

Raj

Share this post


Link to post
Share on other sites
Bump.

Perl and Python are currently on my list. I am trying to distinguish witch one to buy a book on. Any suggestions, with one is, um, better (please don’t start a war) ?

dynamic sigs are fresh!

Share this post


Link to post
Share on other sites
Python: should be plenty of introductory info on their site. However, it''s not the best at stream processing; that''s not what it was meant for. PERL, on the other hand, was originally designed for data processing and modification, and is somewhat easier to do this stuff in. Good info is available everywhere, but the O''Reilly books on Perl are by far the best.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
I was going to suggest awk, but it''s really more appropriate for files which are line-oriented -- C++ is not. You could separate by semicolons, but even that is very chancy (think about for statements). Also, awk is more useful for situations where the output does not closely resemble the input.

Still, awk is a great language to know; it''s perfect for implementing many one-off processing scripts.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
AWK -> Arranging Without Knowledge. Use ed.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m going to attempt a jump from flordia. I should end up in a pile of cheese in no time!
Please accept my radio signal!!

Share this post


Link to post
Share on other sites