#### Archived

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

# [PERL]Text Wrapping etc...

This topic is 5452 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

##### Share on other sites
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

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 25
• 9
• 57
• ### Forum Statistics

• Total Topics
632640
• Total Posts
3007617
• ### Who's Online (See full list)

There are no registered users currently online

×