in reply to extract comments from source code.
See: tutorial on Flip/Flop operator: Flipin good, or a total flop?#!/usr/bin/perl -w use strict; while (<DATA>) { if (m|^\s*<DTC>| ... m|^\s*</DTC>|) { print; } } __DATA__ ...is your data consisting of the C program...
Lines extracted:
There are a number of Perl XML parsers that can deal with these lines after they have been extracted from the C code.<DTC> <TroubleCode>1101</TroubleCode> <ShortDescription>The reductant pump needs to run slower than expect +ed to keep the pressure.</ShortDescription> <Classification>FAULT</Classification> <SelfHealing>No selfhealing</SelfHealing> <Erasability>erasable</Erasability> <RedetectedDegradation>No Degradation</RedetectedDegradation> <WarningLamp>No Warning Lamp</WarningLamp> <DirectDegradation>No Action</DirectDegradation> <Order>PRIMARY</Order> </DTC>
Update:
I looked again at the post and I think that the "C" code will not compile because the <DTC>...</DTC> stuff does not look like a comment block to the C compiler. I guess the blocks could be like:
So that the C compiler will see the whole XML doc as a single comment block./*XML doc start <DTC> <TroubleCode>1101</TroubleCode> <Classification>FAULT</Classification> <SelfHealing>No selfhealing</SelfHealing> <Erasability>erasable</Erasability> </DTC> XML doc end */
An alternate that is worth considering is Perl POD (Perl Plain Old Documentation) Perl POD. If you organize the "comments" in the C code right, the C compiler will be happy. And the Perl documentation generator will also be happy processing the raw C input file (a "=" as the first character on a line has special meaning). The Perl POD generators will make HTML web pages or man pages directly from the C source file, if the comments /*....*/ are done right.
/*Perl doc start =some heading in Perl POD ... lines =some other heading tag in Perl POD ..... lines =cut Perl doc end */
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: extract comments from source code.
by veerubiji (Sexton) on Sep 26, 2011 at 15:53 UTC | |
by veerubiji (Sexton) on Oct 03, 2011 at 14:05 UTC |