Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing data out of files

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
US
I have some custom scripts for a print system we use that have been modified over and over for years leading to a point where there is a lot of obsolete code fragments within each script that I want to clean up.

I am hoping to find an easy way to search through a file and find the variable declarations then one by one search for any lines elsewhere in the same file where that variable is in use.
Variables are declared like this.
[VAR_VARIABLE_X] VARIABLE [STORETYPE_ARRAY16];
When used the variables are referenced by the name only as [VAR_VARIABLE_X].
My goal would be to have find the variable declarations as anything beginning with the left bracket, having a closing bracket, a space and then the word VARIABLE. Then search the rest of the same file for any lines in which the name within the brackets is used, write the variable name and matching lines out then go to the next variable declaration...

The script has object blocks which contain calls to tests and actions. The tests and action code is declared similarly to the variables and I may find instances of the variables being used in a test or an action but ultimately if the test or action is not actually called from an object then that code is no longer actually in use in the script and should be cleaned out.
The same type of search will work for search each type of test or each type of action. I would search tests to see if they are referenced anywhere else and if not eliminate them. Then I would search each type of action the same way eliminating ones not referenced. I would search the variables last as any obsolete tests or calls referencing them would already be removed so I would not have to run the variable test again after eliminating other code blocks.

Sorry if I made it sound complicated but it is as simple as my example with variables above.
Find a line like "[xxxxxxxxxx] VARIABLE"
Separate out the section [xxxxxxxxxx] and look for other lines that contain it without being followed by the text VARIABLE and write those lines to a file I can use to know what to eliminate. Then go to the next variable declaration and do it again.

I have hundreds of these scripts to go through so anything that can help me identify the orphaned code will be a huge time saver.

Thanks.
Trent

At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top