| View previous topic :: View next topic |
| Author |
Message |
sma Voice
Joined: 12 Sep 2006 Posts: 2
|
Posted: Tue Sep 12, 2006 11:42 am Post subject: regexp doesn't identify what it should |
|
|
Hi all,
i have the following file part:
0000 00 14 a8 ff 32 24 00 18 18 8f a6 8e 08 00 45 88 ....2$........E.
0010 00 83 eb 36 00 00 40 11 63 6b ac 14 e9 ae ac 14 ...6..@.ck......
0020 e9 68 40 00 40 00 00 6f 0f 81 80 60 00 7a 00 00 .h@.@..o...`.z..
0030 e4 c0 71 72 0a 32 00 10 02 b8 09 00 75 65 86 31 ..qr.2......ue.1
0040 74 48 1d 23 e3 ce fa 92 a4 dd a1 2a a2 9d b9 55 tH.#.......*...U
0050 2a 86 64 e4 ce 1d b2 a9 3a 4a 92 de d1 94 81 ad *.d.....:J......
0060 17 2a 67 d6 d5 66 7d 0c 6f a5 9d 4e 55 8d fa 8c .*g..f}.o..NU...
0070 14 e9 61 a3 68 92 16 36 bf ad 19 d8 6e 3e 91 22 ..a.h..6....n>."
0080 4d 86 70 18 f3 c5 72 92 1b b2 f2 30 8e 3a 3c 76 M.p...r....0.:<v
0090 20
i am using the following code on it (trimStr is ofcourse a line from the above):
| Code: |
if {[regexp -- {^\w+\s\s((\w+\s){1,16}).*$} $trimStr matchStr binaryLine]} {
# Skipping headers
if {[llength $binaryLine] < $newByteSkip} {
set newByteSkip [expr $newByteSkip - [llength $binaryLine]]
continue
} elseif {$newByteSkip > 0} {
# skipping last part of headers and printing raw data
# including the first part of rtp header
#removing the last of the unrelevant header bytes.
set binaryLine [lreplace $binaryLine 0 [expr $newByteSkip - 1]]
# getting length of the rest of the line
set len [llength $binaryLine]
# setting size
set line [binary format s $Size]
append line [eval "binary format [string repeat "H2" $len] $binaryLine"]
set newByteSkip 0
set rtpHdrSkip [expr $rtpHdrSkip - $len]
puts -nonewline $outFileBinNew $line
} elseif {$rtpHdrSkip > 0} {
# Printing the second part of the rtp header
# and printing the raw data to new format
set len [llength $binaryLine]
# checking if last line
if { $len < 16 } {
set mode $PL_MODE
}
set line [ eval "binary format [string repeat "H2" $rtpHdrSkip] $binaryLine"]
puts -nonewline $outFileBinNew $line
# Skipping the rest of the rtp header and printing raw data
set binaryLine [lreplace $binaryLine 0 [expr $rtpHdrSkip - 1]]
# from here printing the rest of the payload to both new and old files
set len [llength $binaryLine]
if {$len > $payloadLen} {
set len $payloadLen
} else {
set payloadLen [expr $payloadLen - $len]
}
if {$len == 0} {
set mode $PL_MODE
continue
}
set line [ eval "binary format [string repeat "H2" $len] $binaryLine"]
puts -nonewline $outFileBinOld $line
puts -nonewline $outFileBinNew $line
set rtpHdrSkip 0
} else {
# print raw data
set len [llength $binaryLine]
if {$len > $payloadLen} {
set len $payloadLen
} else {
set payloadLen [expr $payloadLen - $len]
}
if {$len == 0} {
set mode $PL_MODE
continue
}
set line [ eval "binary format [string repeat "H2" $len] $binaryLine"]
puts -nonewline $outFileBinNew $line
puts -nonewline $outFileBinOld $line
if { $len < 16 } {
set mode $PL_MODE
}
}
} elseif {[regexp -- {^Frame.*bytes\scaptured\)$} $trimStr]} {
set mode $PL_MODE
} else {
continue
}
|
the problem is the last line is not identified by the regexp although it should. when i add a non-space character among the spaces of the last line, it is identified but i get the following error message:
invalid command name "0"
while executing
"0"
("while" body line 204)
invoked from within
"while {[gets $inFile readBuff] !=
incr progBar
if {$progBar == 100} {
set progBar 0
puts -nonewline ".
flush stdout
}
set trimStr ..."
(file "ether2mf.tcl" line 136)
Help please!!!
Last edited by sma on Tue Sep 12, 2006 12:38 pm; edited 3 times in total |
|
| Back to top |
|
 |
deadite66 Halfop
Joined: 30 May 2005 Posts: 74 Location: Great Yarmouth, UK
|
Posted: Tue Sep 12, 2006 12:32 pm Post subject: |
|
|
best to wrap that in , you might not get any help until you do. _________________ <- tcl newb |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Tue Sep 12, 2006 12:44 pm Post subject: |
|
|
the lines making the error arent pasted, must be another part of it.
my gues is still:
you try to execute the content of a variable or boolan expression, maybe too many [] or $ _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
sma Voice
Joined: 12 Sep 2006 Posts: 2
|
Posted: Tue Sep 12, 2006 12:47 pm Post subject: but this error is dependent on input |
|
|
i think that if the error is somewhere in the code and is unrelated to the input then the error would appear when any input is given. but it doesn't.
it appears only sometimes and is somehow connected to the last line of the input. |
|
| Back to top |
|
 |
stdragon Owner

Joined: 23 Sep 2001 Posts: 959
|
Posted: Fri Sep 22, 2006 9:19 pm Post subject: |
|
|
| Code: |
if {[regexp -- {^\w+\s\s((\w+\s){1,16}).*$} $trimStr matchStr binaryLine]} {
# Skipping headers
if {[llength $binaryLine] < $newByteSkip} {
... cut ...
set line [ eval "binary format [string repeat "H2" $rtpHdrSkip] $binaryLine"]
|
There are some problems with this script. Up at the top where you initialize binaryLine, it's just a string (the 1-16 bytes matched by regexp). But then you start treating it as a list (llength) which can cause errors. The biggest problem is you're passing it to "eval" which causes it to be executed. If $binaryline contains [0 ... ...] or something, then it will try to execute that. The data you posted contains a $, so that's already a potential problem.
Another overall problem is using regular expressions with binary data. I'm surprised it's even working at all.
It's hard to identify the exact problem because you haven't posted the full script. The error identifies a line number but without the full code there's no way to tell which line it's talking about. |
|
| Back to top |
|
 |
|