f



Dose there any tcl script to translate an file with embedded tcl

Hi
I need to generate some big file, but there are rules for generate
these files
Ex .
==============================
Start
input a [0] wire
input a [1] wire
..
..
..
..
input a [1000] wire
End
=================================

Dose there any tcl script can help to translate a file with  embedded
tcl script into a new file
For example

this is a source file
========================
Start
*  set i 0
*  for { set i 0 } { $i < 1000 } { incr i } {
*  puts input a [$i] wire
* }
End
==========================

After Translate
=======================
Start
input a [0] wire
input a [1] wire
..
..
..
..
input a [1000] wire 
End
=======================

0
deanhuang (2)
7/5/2005 7:15:43 AM
comp.lang.tcl 23428 articles. 2 followers. Post Follow

3 Replies
1459 Views

Similar Articles

[PageSpeed] 20

Gogo12 wrote:
> 
> Hi
> I need to generate some big file, but there are rules for generate
> these files
> Ex .
> ==============================
> Start
> input a [0] wire
> input a [1] wire
> .
> .
> .
> .
> input a [1000] wire
> End
> =================================
> 
> Dose there any tcl script can help to translate a file with  embedded
> tcl script into a new file
> For example
> 
> this is a source file
> ========================
> Start
> *  set i 0
> *  for { set i 0 } { $i < 1000 } { incr i } {
> *  puts input a [$i] wire
> * }
> End
> ==========================
> 
> After Translate
> =======================
> Start
> input a [0] wire
> input a [1] wire
> .
> .
> .
> .
> input a [1000] wire
> End
> =======================

That ought to be easy:

set infile [open "my_file_with_embedded_scripts" "r"]
set copy 0 
while { [gets $infile line] >= 0 } { 
    if { $line == "Start" } {
        set script ""
        set copy 1 
    }
    if { $line == "End" } {
        set copy 0
        eval $script
    }
    if { $copy } {
        append script "[string range $line 1 end]\n"
    }
}
close $infile

(I have modelled this after your example, however:
change the line "puts ..." to:

   puts "input a \[$i\] wire"

to avoid Tcl errors ;)

Regards,

Arjen
0
arjen.markus (2628)
7/5/2005 8:25:13 AM
Thanks for your help Arjen ^__^

I have find a more flexible one
but it's write in Perl
it's called perl preporcessor
here is the link

It's writen by Iain McClatchie
here is the link
http://www2.killian.com/earl/download/perl/bin/perlpp

I am not so familiar with Perl
Does any one small tcl scripts can do well as the Perl scripts does?

0
deanhuang (2)
7/7/2005 2:34:03 AM
In article <1120703643.840521.156880@o13g2000cwo.googlegroups.com>,
Gogo12 <deanhuang@globalunichip.com> wrote:
>Thanks for your help Arjen ^__^
>
>I have find a more flexible one
>but it's write in Perl
>it's called perl preporcessor
>here is the link
>
>It's writen by Iain McClatchie
>here is the link
>http://www2.killian.com/earl/download/perl/bin/perlpp
>
>I am not so familiar with Perl
>Does any one small tcl scripts can do well as the Perl scripts does?
>

I don't understand the question.  I wonder whether 
<URL: http://wiki.tcl.tk/2084 > answers it.
0
claird (2363)
7/10/2005 4:08:02 PM
Reply: