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

Started by
17 comments, last by aftermath 21 years, 2 months ago
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.
Rate me up.
Advertisement
Why don''t you tell us exactally what you want to do so we can try to help you?

Karg
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?

Rate me up.
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.
Keys to success: Ability, ambition and opportunity.
sed.
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)
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)
Perl, that''s what it''s written for. Its not to hard to learn. We use it at work to do just what your talking about.

Cheers
Chris
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.

I second chollida''s suggestion: PERL.

Think Liberally..
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!
Rate me up.

This topic is closed to new replies.

Advertisement