tcl : [exec bash-function] returning 0 leads to 'port install' crashing

Bjarne D Mathiesen macintosh at mathiesen.info
Tue Jun 21 11:58:36 PDT 2011


I'm modifying a Portfile, and am trying to see if a setting exists in a
*.conf-file. These :

set found [exec -ignorestderr -- grep -c "${string}" ${file} 2>@1 ]
set found [exec -ignorestderr -- grep "${string}" ${file} 2>@1 ]
set found [string length ### manual break for readability in email
          [exec -ignorestderr -- grep "${string}" ${file} 2>@1 ]]

all ought to give me some kind of measure as to whether the string is in
the *.conf-file

It works _perfectly_ if [exec ...] returns > 1 ,
but if [exec grep ...] == 0 the Portfile crashes.

I've tried this :

try {
   set fundet [exec ...]
}

which ought to ignore any errors, but it still crashes :-(

Incidentialy, this is exactly one of the examples given for
try ... catch on http://tmml.sourceforge.net/doc/tcl/exec.html

I had to resort to scanning the file line-by-line thus :

=== scrip start
set dylibFile   ${prefix}/${apachever}/conf/standard/00000-dylib.conf

set xmllib [ exec find ${prefix}/lib -type f -iname "libxml2*.dylib" ]
set lualib [ exec find ${prefix}/lib -type f -iname "liblua*.dylib" ]

set chan [open ${dylibFile}]
foreach libFile [list ${xmllib} ${lualib}]  {
    seek ${chan} 0 start
    set fundet 0
    while {[gets ${chan} line] >= 0} {
        if { [ string first ${libFile} ${line} ] > 0 } {
            set fundet [ incr ${fundet} ]
        }
    }
    if { ${fundet} == 0 } {
        exec echo "LoadFile ${libFile}" >> ${dylibFile}
    }
}
close ${chan}
=== script end

Now, can anyone point me in a direction that can get my original idea to
work ???

====== EXERCISE for the asture reader ======
consider the following piece of a Portfile,
=== script start
set confFile ${prefix}/${apachever}/conf/extra/httpd-modsecurity2.conf

if { ![ file exists ${confFile} ] } {
    exec echo "\\<IfModule security2_module\\>" > ${confFile}
    exec cat ${worksrcpath}/modsecurity.conf-recommended >> ${confFile}
    exec echo "\\</IfModule\\>" >> ${confFile}
    reinplace -E -- "s|^\\\\||" ${confFile}
    reinplace -E -- "s|(.)\\\\(.)|\\1\\2|" ${confFile}
}
=== script end
and tell me what's happening, and why ;-)

-- 
Bjarne D Mathiesen
København N ; Danmark ; Europa
----------------------------------------------------------------------
denne besked er skrevet i et totalt M$-frit miljø
MacOS X 10.6.7 Snow Leopard ; 2.8GHz Intel Core i7 ; 16GB 1067MHz DDR3
                                       http://webadmin.mathiesen.info/


More information about the macports-users mailing list