jsdy@hadron.UUCP (Joseph S. D. Yao) (11/13/86)
In article <1105@cit-vax.Caltech.Edu> jon@cit-vax.UUCP (Jon Leech) writes: >In article <5058@brl-smoke.ARPA> jrv@MITRE-BEDFORD.ARPA (James R. Van Zandt) writes: >>Several times I've wanted to make a change to some C source code that >>would be minor, but requires parsing it. Some examples are: > Another example that I badly needed recently is a 'diff'-like program >driven by syntax rather than text; I had two divergent versions of a large >program with differing indentations, preprocessor usage, etc. ... What I did at one point, after a round of 'style wars' had badly trashed some otherwise good pieces of code, was to write into the 'compare' program some language-specific routines that recognised general C and assembler constructs (assuming file.[csh] was right), and transformed the files such that: all white space became a single space (trailing WS stripped); all '{'s and '}'s put on single lines, indented or not semicolons not in strings or comments introduced new lines no blank lines. Terrible format to read, but a common, comparable format. It got the job done, and was lots easier to write than a general parser. Unfortunately, it's on an 800 bpi tape that I can't read right now. But, you should be able to do this at home with some simple equipment [;-)]. Just remember to match "" '' /**/. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP} jsdy@hadron.COM (not yet domainised)