then depending on the contents of the line, it may get processed before
being written to a file or wriiten out as 'raw' info - using 'puts
$outfile $in_line'
I'm hitting problems with the contents of the line, when I try to write
it out to file, if it contains '{' or '}' the script complains - I
suspect it is reading it has a special character, rather than pure text
- just something to write out to file.
How do I get puts to treat every thing as 'pure text' ?
Regards
Steve
Hi Steve,
You should have no problems at all!
Are you using [eval] at some point?
post your script here for further comments?
uwe
if {$open_comment != -1} {
set comment_flag 1
}
if {!$comment_flag} {
set title [lindex [split $in_line :] 0] ; #split line at :
set text [lindex [split $in_line :] 1]
switch -glob -- $title {
"TMS ID" {
puts $error_log "writing out TMS ID..."
gets $template out_line
set temp_title [lindex [split $out_line :] 0]
set out_line [concat $temp_title : $text]
puts $outfile $out_line
}
"Test Title" {
puts $error_log "writing out Title..."
gets $template out_line
puts $error_log "Read from template $out_line"
set temp_title [lindex [split $out_line :] 0]
puts $error_log "temp title...$temp_title"
set out_line [concat $temp_title : $text]
puts $outfile $out_line
}
"Reference(s)" {
puts $error_log "Adding Livelink No. $livelink"
puts $error_log "Adding Test Case udoc mr $udoc_mr "
puts $outfile $in_line
puts $outfile "Test Plan Livelink Number $livelink."
puts $outfile "Test Case udoc mr $udoc_mr. "
}
"Dependances" {
puts $error_log "removing dependances as not required..."
}
"Included Test I.D" {
puts $error_log "removing included test id as not required..."
}
default
{
puts $outfile "$in_line"
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
I've found that if the $in_line contains an unmatched '{' the script
errors with 'unmatched open brace in list'
The line being processed falls into the 'default' switch
> I've found that if the $in_line contains an unmatched '{' the script
> errors with 'unmatched open brace in list'
Well yes, you're using [lsearch on in_line, which requires it to be
parsed as a list first.
For arbitrary strings, better use [string first] or [string match]...
is this the error you get:
#############################
missing close-brace
while executing
"while { [gets $infile in_line] >=0 } {
set open_comment [lsearch -exact $in_line "/*"]
set close_comment [lsearch -exact $in_line "*/"]
if {$op..."
(file "bracing.tcl" line 2)
#################################################
as input tested the next 3 lines:
ljslfs {
{
}
now: $in_line is a string and _not_ a proper list
the way to find your comments would be better served by
string first $in_line "/*"
which would return the index of the first found incidence, or -1 ...
<man n string>
string first string1 string2 ?startIndex?
Search string2 for a sequence of characters that exactly match
the characters in string1. If found, return the index of the
first character in the first such match within string2. If not
found, return -1. If startIndex is specified (in any of the
forms accepted by the index method), then the search is con-
strained to start with the character in string2 specified by the
index. For example,
string first a 0a23456789abcdef 5
will return 10, but
string first a 0123456789abcdef 11
will return -1.
uwe
I find it very difficult to believe your code makes it that far. It
should choke on the lines where you try to do an lsearch command. Read
the man page on lsearch and you'll see it requires a list on input. If
your data has unbalanced braces as you say it does, they are decidedly
not lists.
The cardinal rule is "never use list commands on strings", which is
exactly what you are doing.
Use string first or regexp or something, or use split to convert the
string to a list before using list commands.
--
Bryan Oakley
http://www.tclscripting.com
Cheers for that - after a little bit of rework to script logic due to
string match verses lsearch everything is working fine
Steve