Advertisement

[PERL]Text Wrapping etc...

Started by October 21, 2003 11:03 PM
0 comments, last by hehenoobhehe 21 years, 1 month ago
Hey All! I made a code generator that works like this: 1) Read from a header file and produce an intermediate file (named File A) that has tags(inserted by me) that facilitates sorting out the information that is read from the header by me for: Function declaration Actual code for functions with arguments/params etc everything. 2) Read this intermediate file i.e File A and process the information for making another intermediate file (named File B) that I use for another purpose later on. File B uses File A and the result is an intermediate code file that has the following: -Class Declaration -Function Definitions i.e Actual code for functions with arguments/params etc everything (whatever is dictated by the requirements is output to this intermediate file B) along with some information that I need later, 3) Read File B and use a config file named Input.config and use the information from the config file to alter the contents of the File B to produce the final processed file named File C(quite appropriate, isn¡¦t it? ) The input config file has stuff that I need to replace in File B for example Class Name etc. What is the problem: -Formatting is handled as desired by me in File B to get the results I¡¦m looking for and HERE IS THE PROBLEM: 1)What I need in File C is formatted code that wraps after 78 characters and the length of lines SHOULD NOT exceed 78 characters 2)Indented code inside if/for loops etc etc etc etc For Example: File B

class Class_Name:public BaseClass
{
	blah blah blah
public:
	blah blah blah
}	


I CAN in File B control the formatting to some degree. ļ
What I want is this in File C:
File B
   
class ClassMyClassNameNoMatterHowLongItIsName:public BaseClass
{
	blah blah blah
public:
	blah blah blah
}	
MyClassNameNoMatterHowLongItIs is read from the config file and right now I use pattern matching and whenever I encounter Class_Name, I replace it with the information read from the input config file , Here in lies the problem, if I just use pattern matching and just *replace* the stuff , then , I have no control on the wrapping etc and in all likelihood, I lose most of the formatting information that I preserved in File B. My questions are: 1) How and what do I do in order to preserve some sort of formatting in File C (my FINAL processed output file) after all the tags etc have been replaced? A possible solution could be tokenizing an entire line that is read from File B (while producing File C) and then priting out each token while keeping in mind that only 78 characters are to be printed out BUT even this solution does not preserve the tab information etc that can no longer be preserved while using this. 2) Should I use a C++ program instead of a PERL script to generate the code in File C instead? Any suggestions are welcome, I must add here: 1) I¡¦m a C++ Programmer ) I don¡¦t know PERL and all that I have managed to accomplish here has been rather painstakingly after debugging with print statements, so please reserve any comments on my illiteracy , I do know that I DON¡¦T know PERL. 3) I don¡¦t have nay other experience in PERL or scripting and this really is my first attempt and it works so some degree Thanks in advance for your time and my apologies for the length of the post. [edited by - hehenoobhehe on October 21, 2003 12:12:09 AM]
If you dont mind another stage you could pipe it through an indentation program e.g Indent.

I suspect I am completely misunderstanding what you are trying to do here though

This topic is closed to new replies.

Advertisement