Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Having programmed in C all my life, I googled usage of the perl constructs below and wrote a C like program. This works flawlessly for me. :-) </p> <p>Edit : This is to clarify why I must skip a line in the algo below. The pattern which is retrieved and later searched for in the second file occurs on two consecutive lines. It therefore suffices that its first occurence is reliably detected. Also a nitpick, It is always guaranteed that the substring containing the pattern is always the second substring on the line.</p> <p>e.g #define Something_Pos (Some Value)</p> <pre><code>#!/usr/bin/perl use strict; use warnings; my $OriginalHeader=$ARGV[0]; my $GeneratedHeader=$ARGV[1]; my $DeltaHeader=$ARGV[2]; my $MatchingPattern="_Pos"; my $FoundPattern; open FILE1, $OriginalHeader or die $!; open FILE2, $GeneratedHeader or die $!; open (FILE3, "&gt;$DeltaHeader") or die $!; my $lineFromOriginalHeader; my $lineFromGeneratedHeader; my $TotalMacrosExamined = 0; my $TotalMacrosMissed = 0; while($lineFromOriginalHeader=&lt;FILE1&gt;) { if($lineFromOriginalHeader =~ /$MatchingPattern/) { my $index = index($lineFromOriginalHeader,$MatchingPattern); my $BackIndex = $index; my $BackIndexStart = $index; $BackIndex = $BackIndex - 1; ## Use this while loop to extract the substring. while (1) { my $ExtractedChar = substr($lineFromOriginalHeader,$BackIndex,1); if ($ExtractedChar =~ / /) { $FoundPattern = substr($lineFromOriginalHeader,$BackIndex + 1,$BackIndexStart + 3 - $BackIndex); print "Identified $FoundPattern \n"; $TotalMacrosExamined = $TotalMacrosExamined + 1; ##Skip the next line $lineFromOriginalHeader = &lt;FILE1&gt;; last; } else { $BackIndex = $BackIndex - 1; } } ##while(1) ## We now look for $FoundPattern in FILE2 while ($lineFromGeneratedHeader = &lt;FILE2&gt;) { ##print "Read the following line from FILE2: $lineFromGeneratedHeader\n"; if (index($lineFromGeneratedHeader,$FoundPattern)!= -1) { ##Pattern found. Close the file and break out of while loop seek FILE2,0,0; last; } else { if (eof(FILE2) == 1) { print FILE3 "Generated header misses $FoundPattern\n"; $TotalMacrosMissed = $TotalMacrosMissed + 1; seek FILE2,0,0; last; } } } ##while(1) } else { } } ##while (linefromoriginalheader) close FILE1; close FILE2; close FILE3; print "Total number of bitfields examined = $TotalMacrosExamined\n"; print "Number of macros obsolete = $TotalMacrosMissed\n"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload