1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#use strict; use constant SCRIPT_NAME => "patch_mapping.pl"; use constant SCRIPT_VERSION => "1.0.1"; #use Log4TA #Log_Info("USAGE: " . SCRIPT_NAME . <Frame Report Folder> <FRAME_NAME>,<FRAME_NAME> [<output directory>]"); #Log_SetOutDir("."); #Log_SetOutFile("log_patch_mapping.log"); my $ScrDIR = $ARGV[0]; my $FrameName = $ARGV[1]; my $out_dir = $ARGV[2]; my $frame; my $emptyFrame; my @added_frames; my $Count = 0; my $line; my @array; #-----Open source file------------------ my $FrameReport = $ScrDIR."\\test.txt"; #Source document: Frame report list my $fhR; open ($fhR, $FrameReport) or die "Unable to open the file $FrameReport\n"; #---------------------------------------- #-----add signal to mapping file-------- my $fhWrite = $out_dir."\\mapping".".txt";# Created document: mapping INCA Signal name - Internal signal name open ($out_dir, '>>', $fhWrite) or die "Unable to open the file $fhWrite\n"; #---------------------------------------- # check for valid input parameter if(! defined $FrameReport or ! -f $FrameReport) { Log_Error("No frame report file given!"); die; } if(!defined $FrameName) { Log_Error("No frame name given!"); die; } else { #$FrameName =~ s/^frame=//i; #@added_frames = split("[\,\;]",$FrameName); @added_frames = split(/,/,$FrameName); } if(defined $out_dir) { if(! -d $out_dir) { mkdir $out_dir; } } else { $out_dir = "."; } #my $read_state; #local $/ = q||; while ($line = <$fhR>) #As long as the file fhR contains data, we read the data { $Count++; foreach $frame(@added_frames) { if($line=~ /$frame/ .. $line =~ /^$/) { print"my frame: $frame\n"; print"my line: $Count\n"; if($line =~ /::::0x/ and $line =~ /\_FA,/ and $line =~ /\(/) { if($line =~ /FREI/ or $line =~ /ID2\)/) #ignore lines with "FREI" or "(ID2)" {} else { ( $_, $line) = split(/\(/,$line); #selects string after the opened bracket ( $_, $line) = split(/\)/,$line); #from the selected string, selects the one before the closed bracket @array = split(/, /,$line); print $out_dir $_, ";", "$array[1]\n"; #$countPar = $countPar +1; #count the number of mapping <internal variables> to <INCA variables> } } } } #print"my total lines: $Count\n"; }
if($line=~ /$frame/ .. $line =~ /^$/)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $file = 'test.txt';
{
open my $fh, '<', $file or die "$file: $!";
# change block separator to have one complete frame
# read per iteration
local $/ = "\nFRAME NAME:";
# read the blocks
while ( my $frame = <$fh> ) {
next if $. == 1; # skip the "header"
chomp $frame; # remove block separator
# print the frame
print "This is a frame:\n",
'=' x 30, "\n",
$frame, "\n",
'=' x 30;
}
close $fh;
}
($frame_name) = $line =~ /^FRAME\s+NAME:\s+.*?[\(|\[]([A-Z]+_[A-Z]+(?:[_ A-Z 0-9]+)?)[\)|\]|\,]/;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $file = 'test.txt'; my @added_frames; my $line; { open my $fh, '<', $file or die "$file: $!"; # change block separator to have one complete frame # read per iteration local $/ = "\nFRAME NAME:"; # read the blocks while ( my $frame = <$fh> ) { next if $. == 1; # skip the "header" chomp $frame; # remove block separator (my $frame_name) = $line =~ /\s+([A-Z]+_[A-Z]+(?:[_ A-Z 0-9]+)?)[\)|\]|\,]/; print"\nmy frame name: $frame_name\n\n"; foreach $AddedFrame(@added_frames) { if($frame_name eq $AddedFrame) { if(($line =~ /::::0x/ and $line =~ /\(/) and ($line =~ /\_FA,/ or $line =~ /\_A,/)) { if($line =~ /FREI/ or $line =~ /ID2\)/) #ignore lines with "FREI" or "(ID2)" {} else { ( $_, $line) = split(/\(/,$line); #selects string after the opened bracket ( $_, $line) = split(/\)/,$line); #from the selected string, selects the one before the closed bracket @array = split(/, /,$line); print $out_dir $_, ";", "$array[1]\n"; #$countPar = $countPar +1; #count the number of mapping <internal variables> to <INCA variables> } } } } # print the frame print "This is a frame:\n", '=' x 30, "\n", $frame, "\n", '=' x 30; } close $fh; }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use List::Util qw(first);
my $file = 'test.txt';
my %frames_found;
{
open my $fh, '<', $file or die "$file: $!";
# change block separator to have one complete frame
# read per iteration
local $/ = "\nFRAME NAME:";
# read the blocks
while ( my $frame = <$fh> ) {
next if $. == 1; # skip the "header"
chomp $frame; # remove block separator
# get frame name
my ($name) = $frame =~ m{\A [^\(\[]* [\(\[] (\w+) [\)\]] }x;
# skip the frame when no name is given
next if !$name;
# check if user wants to get info about frame. Skip the frame if the
# user didn't mentioned it
next if !first{ $name eq $_ }@ARGV;
# get all signals
my @signals = grep{ $_ }$frame =~ m{^ \s* :+ 0x\d+ (.*?) \r?\n? $}xmg;
my @found;
for my $signal ( @signals ) {
# skip signals that contains "FREI" or "(ID2)"
next if index( $signal, 'FREI' ) != -1;
next if index( $signal, '(ID2)' ) != -1;
# skip signal if it does not contain _FA, or _A,
next if $signal !~ m{ _F?A, }x;
my ($value) = $signal =~ m{ \( ([^\)]+) \) }x;
push @found, $value if $value;
}
$frames_found{$name} = @found ? \@found : 1;
}
close $fh;
}
print Dumper \%frames_found;
@signals = grep{ $_ }$frame =~ m{^ \s+ :+ 0x\d+ (.*?) \r?\n? $}xmg;
@signals = grep{ $_ }$frame =~ m{^ \s+ :+ 0x\w+\d+ (.*?) \r?\n? $}xmg;
1
2
3
4
5
6
7
8
9
10
11
12
my $file = '174621_testdb2_CanA.txt';
# slurp all the content into the scalar
my $content = do { local ( @ARGV, $/ ) = $file; <> };
# needed as $VAR1 is used in the dump
my $VAR1;
# eval the content to get the Perl datastructure
eval $content;
print $VAR1->[0]->{SDOM_REFERENCE};