-1

I'm working in a fairly old yet sufficiently unproductive code base that I need to create a(some) script(s) to help me out.

For example:

  • we add a version # and timestamp at the header of the file (yes we use a CVS based sys but this is beyond my control).
  • we have duplicated layout code for different languages (this is pre-unicode era so we just duplicate things) and when a control's attribute changes in one language that change needs to be cascade to the other ones.

So, my first thoughts were a couple of perl or python scripts to do find & replace to solve those two issues. But I wanted to reach out and see if anyone else had a different approach.

  • 1
    Any half decent editor will have rexexp replace functions – jk. Jan 20 '14 at 16:09
  • true, but i'd like to script this. I'm also simplifying the issue a bit for this post. – cbrulak Jan 20 '14 at 16:18
  • Your first point is likely addressed within CVS itself: ximbiot.com/cvs/manual/cvs-1.11.6/cvs_12.html – user40980 Jan 20 '14 at 16:32
  • @MichaelT Yes, I do realize that. We're forced to add a manual time/version stamp to the file. This is out of my control. – cbrulak Jan 20 '14 at 16:36
  • 1
    What is in the manual time / version stamp that wouldn't be able to be provided by keyword substitution in CVS? – user40980 Jan 20 '14 at 16:48
1

Adding a # and timestamp at each file header could be easily done by any scripting language with good text processing capabilities, if you are going to use Perl, Python, awk or sed depends mainly of what you are used to, what you like best, and what is available in the environment your are working. Heck, I have implemented such things also in VBscript (using MS regexp) because I could safely assume that beeing already installed in our Windows environment.

Finding "attributes" in code, however, can work by textual search-and-replace, but there is always some risk that you destroy string literals or comments this way. If you think this is very unlikely in your environment,do it this way. But if you want to avoid that risk, you may have to invest more effort and build (or find) some kind of parser for the programming language your layout code is written in. For HTML, you should consider to use some kind of DOM parser like this one for Perl, or this one for Python.

  • thanks. The ui/layout language is a customized version of html. Think if as a far distant, less evolved version of erb templates in rails :) – cbrulak Jan 20 '14 at 16:37
  • @cbrulak: see my edit. – Doc Brown Jan 20 '14 at 16:42
  • thanks, just did. yeah, that might actually work. thanks again. – cbrulak Jan 20 '14 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.