[3] | 1 | # |
---|
| 2 | # Copyright (c) 2004-2007 - Consultas, PKG.fr |
---|
| 3 | # |
---|
| 4 | # This file is part of A2P. |
---|
| 5 | # |
---|
| 6 | # A2P is free software; you can redistribute it and/or modify |
---|
| 7 | # it under the terms of the GNU General Public License as published by |
---|
| 8 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | # (at your option) any later version. |
---|
| 10 | # |
---|
| 11 | # A2P is distributed in the hope that it will be useful, |
---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | # GNU General Public License for more details. |
---|
| 15 | # |
---|
| 16 | # You should have received a copy of the GNU General Public License |
---|
| 17 | # along with A2P; if not, write to the Free Software |
---|
| 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 19 | # |
---|
| 20 | # $Id: ControlRecordDef.pm 3 2007-10-18 16:20:19Z root $ |
---|
| 21 | # |
---|
| 22 | # Module to initialize Control Record definitions |
---|
| 23 | |
---|
| 24 | package AFPDS::ControlRecordDef; |
---|
| 25 | |
---|
| 26 | use strict; |
---|
| 27 | use A2P::Globals ; |
---|
| 28 | use A2P::Syslog ; |
---|
| 29 | |
---|
| 30 | BEGIN { |
---|
| 31 | use Exporter (); |
---|
| 32 | our ( $VERSION , @ISA , @EXPORT ); |
---|
| 33 | |
---|
| 34 | $VERSION = sprintf "%s", q$Rev: 717 $ =~ /(\d[0-9.]+)\s+/ ; |
---|
| 35 | |
---|
| 36 | @ISA = qw(Exporter); |
---|
| 37 | @EXPORT = qw( %RCDEF %SIZE ); |
---|
| 38 | } |
---|
| 39 | our $VERSION ; |
---|
| 40 | |
---|
| 41 | # Exported Variables |
---|
| 42 | our %RCDEF = () ; |
---|
| 43 | our %SIZE = () ; |
---|
| 44 | |
---|
| 45 | #======================================================================= |
---|
| 46 | # initialisation code - stuff the DATA into the RCDEF hash |
---|
| 47 | #======================================================================= |
---|
| 48 | my $T = "" ; |
---|
| 49 | my $index = 0 ; |
---|
| 50 | my %data = (); |
---|
| 51 | |
---|
| 52 | &Debug("Loading RCDEF..."); |
---|
| 53 | while (<DATA>) |
---|
| 54 | { |
---|
| 55 | chomp ; |
---|
| 56 | next if /^\s*$/ ; # Skip empty lines |
---|
| 57 | next if /^#/ ; # Skip comment line |
---|
| 58 | |
---|
| 59 | my ( $rec , $tag , $comment ) = |
---|
| 60 | /^\s*(\w+)\s+=>\s+(.*)\s*#\s+(\w+.*)\s*$/i ; |
---|
| 61 | |
---|
| 62 | die "Bad line $_ found in Record Control definitions" |
---|
| 63 | unless (defined($rec)); |
---|
| 64 | |
---|
| 65 | if ( $rec =~ /^type$/i ) { |
---|
| 66 | ( $tag ) = $tag =~ /^(\w+)/ ; |
---|
| 67 | &Debug("Loading new Record Control definition type '$tag'"); |
---|
| 68 | $T = "$tag" ; |
---|
| 69 | $index = 1 ; |
---|
| 70 | next ; |
---|
| 71 | |
---|
| 72 | } elsif ( $rec =~ /^__SPLIT__$/i |
---|
| 73 | and $tag =~ /^<code\s*name=["'](\w+)["']\s*>\s*$/i ) { |
---|
| 74 | my $name = $1 ; |
---|
| 75 | |
---|
| 76 | &Debug("Loading afpds splitter '$name' with RC type $tag"); |
---|
| 77 | my $splitter = "" ; |
---|
| 78 | while (my $line = <DATA>) { |
---|
| 79 | last if ( $line =~ /^\s*<\/code>\s*$/ ); |
---|
| 80 | $splitter .= $line ; |
---|
| 81 | } |
---|
| 82 | &Debug("Loaded splitter is ".length($splitter)." long"); |
---|
| 83 | my $code = eval( "sub { $splitter }" ); |
---|
| 84 | |
---|
| 85 | die "Can't load '$name' splitter with invalid code\n" |
---|
| 86 | unless (defined($code) and ref($code) =~ /^CODE$/); |
---|
| 87 | |
---|
| 88 | $RCDEF{$T}->{'__A2P_SPLITTER__'} = $code ; |
---|
| 89 | &Debug("Splitter $name loaded"); |
---|
| 90 | next ; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | die "No Record Control type defined for line $_" |
---|
| 94 | unless ( $T ); |
---|
| 95 | |
---|
| 96 | # Extract now the pos and the id |
---|
| 97 | my ( $pos, $id ) = |
---|
| 98 | $tag =~ /^Pos:\s+([-+0-9*]+)\s+:\s+(\w+)\s*$/i ; |
---|
| 99 | |
---|
| 100 | die "Bad format in $_ line found in Record Control type $T definition with". |
---|
| 101 | "'$tag' field definition" |
---|
| 102 | unless ( $rec and $pos and $id and $comment ); |
---|
| 103 | |
---|
| 104 | #&Debug("Type=$T ; Index=$index ; Rec=$rec ; Pos=$pos ; Id=$id ; Comment=<$comment>"); |
---|
| 105 | |
---|
| 106 | $data{$T}->[$index++] = [ $rec => $pos ]; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | close(DATA); |
---|
| 110 | |
---|
| 111 | &Debug("Analysing RCDEF..."); |
---|
| 112 | |
---|
| 113 | foreach $T (keys(%data)) { |
---|
| 114 | my ( $key , $pos , $curpos , $size ) = ( "" , 0 , 0 , 0 ); |
---|
| 115 | $index = 1 ; |
---|
| 116 | while (defined($data{$T}->[$index])) { |
---|
| 117 | ( $key , $pos ) = @{$data{$T}->[$index++]} ; |
---|
| 118 | if ( $pos =~ /-/ ) { |
---|
| 119 | # First position must be in x-y style |
---|
| 120 | ( $curpos , $size ) = split( "-" , $pos ); |
---|
| 121 | |
---|
| 122 | die "Bad POS format in Control Record def ($index)" |
---|
| 123 | unless (defined($curpos) and defined($size)); |
---|
| 124 | |
---|
| 125 | $size -= $curpos - 1 if ( $size ne '*' ); |
---|
| 126 | |
---|
| 127 | die "Bad SIZE $size found in Control Record def ($index)" |
---|
| 128 | unless ( $size > 0 or $size eq '*'); |
---|
| 129 | |
---|
| 130 | } elsif ( $pos =~ /\+(\d+)/ ) { |
---|
| 131 | $size = $1 ; |
---|
| 132 | |
---|
| 133 | die "Bad $pos size definition found in Control Record def ($index)" |
---|
| 134 | unless $size ; |
---|
| 135 | |
---|
| 136 | } else { |
---|
| 137 | die "$pos is not a POS definition in Control Record def ($index)"; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | #&Debug("T$T: RC{$key} def = pos $curpos ( $size long )"); |
---|
| 141 | if ( $size eq '*' ) { |
---|
| 142 | $RCDEF{$T}->{$key} = [ $curpos , -1 ]; |
---|
| 143 | $SIZE{$T} = -1 ; |
---|
| 144 | |
---|
| 145 | } else { |
---|
| 146 | $RCDEF{$T}->{$key} = [ $curpos , $size ]; |
---|
| 147 | $curpos += $size ; |
---|
| 148 | $SIZE{$T} = $curpos - 1 |
---|
| 149 | if ( !defined($SIZE{$T}) or $SIZE{$T} < $curpos - 1 ); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | #&Debug("RC type $T is $SIZE{$T} bytes long"); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | &Debug("Module " . __PACKAGE__ . " v$VERSION loaded"); |
---|
| 156 | |
---|
| 157 | 1; |
---|
| 158 | |
---|
| 159 | __DATA__ |
---|
| 160 | |
---|
| 161 | ################################################################################ |
---|
| 162 | TYPE => 001 # RC001 |
---|
| 163 | UTIPRJ => Pos: 6-7 : UTIPRJ # Code projet 'RS' |
---|
| 164 | UTISTE3 => Pos: +3 : UTISTE3 # Code société 'P10' |
---|
| 165 | UTICPR => Pos: +3 : UTICPR # Centre de profit '036' |
---|
| 166 | IMPDOCA => Pos: +2 : IMPDOCA # Code application '20' |
---|
| 167 | IMPDOCN => Pos: +2 : IMPDOCN # Numéro de document '01' |
---|
| 168 | TRTDAT => Pos: +8 : TRTDAT # Date de formatage 'yyyymmdd' |
---|
| 169 | IMPHEU => Pos: +7 : IMPHEU # Heure de formatage 'hhmmssc' |
---|
| 170 | COPIES => Pos: +3 : IMPCOPN # Number of copies to add |
---|
| 171 | FORM => Pos: +4 : IMPFORN # Sheet number (Numéro de formulaire) |
---|
| 172 | DESTID => Pos: +8 : IMPLU # printer (Terminal ID) |
---|
| 173 | IMPCLAS => Pos: +1 : IMPCLAS # printing class |
---|
| 174 | BURST => Pos: +1 : IMPBURS # burst |
---|
| 175 | FLASH => Pos: +4 : IMPFLAS # flash |
---|
| 176 | CHARS => Pos: +16 : IMPCHAR # chars (4x4 pos.) |
---|
| 177 | PAGEDEF => Pos: +6 : IMPPAGD # PageDef |
---|
| 178 | FORMDEF => Pos: +6 : IMPPAGD # Formdef |
---|
| 179 | HOLD => Pos: +1 : IMPHOLD # hold |
---|
| 180 | PRIORITY => Pos: +2 : IMPPRIO # priority |
---|
| 181 | __SPLIT__ => <code name='DESTID_Splitter'> # Perl code to split AFPDS |
---|
| 182 | # We just want to split AFPDS when DESTID has changed, so just return it |
---|
| 183 | my $RC = shift ; |
---|
| 184 | return $RC->{DESTID} ; |
---|
| 185 | </code> |
---|
| 186 | |
---|
| 187 | ################################################################################ |
---|
| 188 | TYPE => 100 # RC100 |
---|
| 189 | UTIPRJ => Pos: 6-7 : UTIPRJ # Code projet 'RS' |
---|
| 190 | UTISTE3 => Pos: +3 : UTISTE3 # Code société 'P10' |
---|
| 191 | UTICPR => Pos: +3 : UTICPR # Centre de profit '036' |
---|
| 192 | IMPDOCA => Pos: +2 : IMPDOCA # Code application '20' |
---|
| 193 | IMPDOCN => Pos: +2 : IMPDOCN # Numéro de document '01' |
---|
| 194 | TRTDAT => Pos: +8 : TRTDAT # Date de formatage 'yyyymmdd' |
---|
| 195 | IMPHEU => Pos: +7 : IMPHEU # Heure de formatage 'hhmmssc' |
---|
| 196 | CHARS => Pos: +16 : IMPCHAR # chars (4x4 pos.) |
---|
| 197 | PAGEDEF => Pos: +6 : IMPPAGD # PageDef |
---|
| 198 | FORMDEF => Pos: +6 : IMPPAGD # Formdef |
---|
| 199 | RECORD => Pos: 6-60 : RECORD # To put in Arch file |
---|
| 200 | |
---|
| 201 | ################################################################################ |
---|
| 202 | TYPE => 101 # RC101 |
---|
| 203 | RECORD => Pos: 6-114 : RECORD # brut transcrit |
---|
| 204 | |
---|
| 205 | ################################################################################ |
---|
| 206 | TYPE => 102 # RC102 |
---|
| 207 | RECORD => Pos: 6-135 : RECORD # brut transcrit |
---|
| 208 | |
---|
| 209 | ################################################################################ |
---|
| 210 | TYPE => 103 # RC103 |
---|
| 211 | RECORD => Pos: 6-35 : RECORD # brut transcrit |
---|
| 212 | |
---|
| 213 | ################################################################################ |
---|
| 214 | ################### Control Record in 200-299 are not sized ################### |
---|
| 215 | ################### But need a RECORD definition ################### |
---|
| 216 | ################################################################################ |
---|
| 217 | TYPE => 200 # RC200 |
---|
| 218 | RECORD => Pos: 6-* : XML # as <a2p><service name='xxx'/></a2p> |
---|
| 219 | |
---|
| 220 | ################################################################################ |
---|
| 221 | TYPE => 201 # RC201 |
---|
| 222 | RECORD => Pos: 6-* : START # empty start record |
---|
| 223 | |
---|
| 224 | ################################################################################ |
---|
| 225 | TYPE => 202 # RC202 |
---|
| 226 | RECORD => Pos: 6-* : STOP # empty stop record |
---|
| 227 | |
---|
| 228 | ################################################################################ |
---|