0% found this document useful (0 votes)
339 views20 pages

1

The document contains examples of TCL scripts that perform various tasks like counting odd numbers in a list, guessing a random number, sorting a list, reversing a list, reading input from user, comparing files, calling subroutines, and more. It also contains examples of using loops, conditions, variables, arrays and other basic programming constructs in TCL.

Uploaded by

subash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
339 views20 pages

1

The document contains examples of TCL scripts that perform various tasks like counting odd numbers in a list, guessing a random number, sorting a list, reversing a list, reading input from user, comparing files, calling subroutines, and more. It also contains examples of using loops, conditions, variables, arrays and other basic programming constructs in TCL.

Uploaded by

subash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

1.

while {$i<=$list_size} {
#count odd numbers from a list puts [lindex $list $i]
incr i
set list "1 3 4 5 6 2 59 20 34 33 45 65 66 21 3" }
foreach data $list {
set i 0 puts $data
foreach number $list { }
if {$number%2 != 0} {
lappend odd_nums
$number
incr i 4. #Write a TCL script to sort a list without using
} the lsort function.
}
puts "Total Odd numbers: $i" set list "80 90 100 10 50 3"
puts "Odd numbers are: $odd_nums"; puts "The list is: $list"

2. set temp {}
#Make a program that will repeatedly ask the user set temp1 {}
to guess a secret number from 1 to 100 until the set list1 $list
user guesses the secret number. set list_size [llength $list]
#Your program should pick the number at random set list_size_1 [expr {$list_size - 1}]
by using the magical formula int(1 + rand 100). for {set i 0} { $i <$list_size} {incr i} {
When the user guesses wrong, for {set j 0} { $j <$list_size_1} {incr j} {
#the program should respond “Too high” or “Too set x [expr {$j + 1}]
low.” If the user enters the word quit or exit, or if if {[lindex $list $j] > [lindex $list
the user enters a blank line, $x]} {
#the program should quit. Of course, if the user set temp [lindex $list
guesses correctly, the program should quit then as $x]
well! lset list $x [lindex $list
$j]
while {1} { lset list $j $temp
puts "Guess a secret number from 1 to 100: " set list_ascending $list
gets stdin user_ip }
}
set random [expr {1+ int(rand()*100)}] for {set k 0} { $k <$list_size_1} {incr k}
if {[regexp -nocase {quit|exit} $user_ip]|[regexp {
{^$} $user_ip]} { set y [expr {$k + 1}]
exit; if {[lindex $list1 $k] < [lindex
} elseif {$user_ip>=0 & $user_ip<=100} { $list1 $y]} {
if {$user_ip==$random} { set temp1 [lindex $list1
puts "You guessed it $y]
right." lset list1 $y [lindex
exit; $list1 $k]
} elseif {$user_ip<$random} { lset list1 $k $temp1
puts "Input is Too Low." set list_descending
} else { $list1
puts "Input is Too High." }
} }
} else { }
puts "Wrong input!" puts "Ascending order: $list_ascending";
} puts "Descending order: $list_descending";
}

3. #Write a TCL script to print every element of a 5.


list using foreach and while loop. #Write a TCL script to reverse a list without using
the lreverse function.
set list "Arka Dk Nikki Tathagata"
set list "Arka Dk Nikki Tathagata"
set i 0 puts $list
set list_size [llength $list] set size [expr {[llength $list] - 1}]
set rev_list {} set result [expr {$value * 10}]
for {set i $size} {$i>=0} {incr i -1} { return $result
lappend rev_list [lindex $list $i] }
}
puts $rev_list proc div {value} {
set result [expr {$value / 2}]
6. return $result
#Write a TCL script to create a list by reading one }
item at a time from the standard input.
puts "Enter a number: "
puts "How many items do you want to add to the gets stdin num
Array: "
gets stdin no puts "\n$num multiply by 10 is: [mul $num]"
puts "$num divide by 2 is: [div $num]"
set list {}
for {set i 0} {$i<$no} {incr i} { 9.
puts "Enter one item at a time to add to the #Write a subroutine that expects three numbers
Array: " passed as arguments, and multiply the three
gets stdin ip_no together, returning the result from the subroutine.
lappend list $ip_no #Call the subroutines from inside a TCL script that
} asks the user for all three numbers. Use names for
puts $list each argument inside the subroutine itself.
7.
#Write a TCL script to compare two files and proc mul {a b c} {
identify that those two files are equivalent or not. set result [expr {$a * $b * $c}]
return $result
puts "Enter the 1st files path: " }
gets stdin path_1
puts "Enter the 2nd files path: " puts "Enter 3 numbers one by one:"
gets stdin path_2 puts "Enter 1st number:"
gets stdin x
set fh1 [open $path_1 r] puts "Enter 2nd number:"
while { [gets $fh1 files] >= 0 } { gets stdin y
lappend file_1_content $files puts "Enter 3rd number:"
} gets stdin z
close $fh1
puts "The multiplication of $x, $y & $z is: [mul $x
set fh2 [open $path_2 r] $y $z]"
while { [gets $fh2 files] >= 0 } {
lappend file_2_content $files
}
close $fh2 #proc sum {arg1 arg2} {
# set x [expr {$arg1 + $arg2}];
if {$file_1_content eq $file_2_content} { # return $x
puts "Both Files are Identical." #}
} else {
puts "Both Files are not Identical." #puts " The sum of 2 + 3 is: [sum 2 3]\n\n"
}
#proc for {a b c} {
# puts "The for command has been replaced by a
8. puts";
#Write two subroutines. Both use a variable # puts "The arguments were: $a\n$b\n$c\n"
defined in the body of the program. #}
#The first sub multiplies the variable by ten, while
the second sub divides the number by two. #for {set i 1} {$i < 10} {incr i}
#Prompt the user for the number, and then call both
subs and display the results from the main script
(not the subs). 10.

proc mul {value} {


#Write a TCL script to read the contents of a file 11.
and using sbroutine check wheather each word ot #Find no of lines, words, chars in a input file
the file is palindrome or nor.
#If any palindrome is identified then print the puts "Enter the file name along with the path:"
palindrome to a output file. gets stdin in

puts "Enter the file name along with the path:" set fh [open $in r]
gets stdin path while {[gets $fh data]>=0} {
lappend content $data
set out_path "d:/palindromes.txt" }

set fi [open $path r] set lines [llength $content]


while { [gets $fi files] >= 0 } { puts "Total no of Lines in the file is: $lines"
lappend content $files
} set string [join $content " "]
close $fi set words [llength $string]
puts "Total no of Words in the file is: $words"
set new_content [regsub -all "," $content " " ]
#set new_content [regsub -all "." $content " " ] set string1 [regexp -all -inline {\S+} $string]
#set new_content [regsub -all "?" $content " " ] set list1 [split $string1 " "]
#set new_content [regsub -all "!" $content " " ] set string2 [join $list1 ""]
set characters [string length $string2]
set string [join $new_content " "] puts "Total no of Characters in the file is:
puts $string $characters"
set list [regexp -all -inline {\S+} $string]

set fo [open $out_path w] 12.


puts $fo "Planidromes in the file $path" #Convert decimal into binary
puts "Planidromes in the file $path"
puts "Enter any Decimal nunber to be converted
set j 0 into Binary:"
set palindrome {} gets stdin ip
set size [string length $list]
for {set i 0} {$i<=$size} {incr i} { set in_hex [format %x $ip]
set temp [lindex $list $i] puts "In Hex: $ip=$in_hex"
set rev_temp [string reverse $temp]
if {[regexp -all {\w+} $temp]} { set in_dec [expr 0x$in_hex]
if {$rev_temp eq $temp} { puts "In Dec: $ip=$in_dec"
lappend palindrome
$temp set in_binary [format %b $ip]
puts $fo $temp puts "In Binary: $ip=$in_binary"
puts -nonewline $temp
puts "\n" 13.
incr $j #Write a perl script which has two subroutines
} defined asv 'avg' and 'factorial'. Prompt the user to
} enter '1' to calculate factorual and '2' to calculate
} avarage.
close $fo #Invoke the corrosponding subroutine and print the
output based on the user input.
if {$j>0} {
puts "No palindromes found!!" #Iterative version
} else { proc fact {n} {
puts "File with palindrome names is set facto 1
created at $out_path" for {set i $n} {$i>0} {incr i -1} {
} set facto [expr {$facto * $i}]
}
return $facto
#[string reverse $temp] string rwvwese syntax }

#Recursive implementation
#proc fact {n} { set dirs [glob -type d $in/*]
# if { $n == 0 } { set file_names [glob -type f $in/*.v]
# return 1
# } else { puts "Name of the Directories are:"
# return [expr {$n*[fact [expr {$n-1}]]}] foreach data_dir $dirs {
# } puts $data_dir
#} }
puts "\nName of the Files are:"
foreach data_file $file_names {
proc avg {} { puts $data_file
puts "How many numbers you want to }
add:"
gets stdin no 15.
set result 0 #Write a TCL script so that when it is executed, it
for {set i 1} {$i<=$no} {incr i} { should get the information like names and marks of
puts "Enter a number:" "N" number of students from the user through
gets stdin value standard input.
set result [expr {$result + #Value of N should be accessed through command
$value}] line argument. Make an associative array in TCL
set average [expr {$result/$no}] that has a list of all the names of the students and
} their marks.
puts "Result= $average" #Also write a subroutine so that it calculates the
} avg marks of all entire associative array.

puts "Enter '1' for Factorial of a number and '2' for proc average {array} {
calculate avg of numbers:" set avg 0
gets stdin in upvar $array a
set x [array size a]
if {$in==1} { foreach key [array names a] {
puts "Enter a number:" puts "Name:${key}
gets stdin fact_in Marks:$a($key)"
set result [fact $fact_in] set avg [expr {($avg +
puts "Factorial of $fact_in is $result." $a($key))}]
} elseif {$in==2} { }
avg puts "Avg marks of $x students: [expr
} else { {$avg/$x}]"
puts "Wrong Input!!" }
}
set n [lindex $argv 0]
for {set i 0} {$i<$n} {incr i} {
set x [expr {$i + 1}]
#fact puts "Enter no.$x student's name:"
gets stdin name_ip
#set result [expr {$a * $b * $c}] puts "Enter no.$x student's marks:"
#for {set i $size} {$i>=0} {incr i -1} { gets stdin msrks_ip
set names($name_ip) $msrks_ip
14. }
#Write a script which when executed will check array set mynewarr [average names]
wheather each file in a particular directory is a file
or directory.
#Also sort the files as well as directories in separate 16.
list and finally display the list of files as well as the #Write a subroutine which can take numeric value
#list of directories available in that directory to the from 1 to 9 as an argument and return its number
user. such 'one', 'two' etc. as it returns value.
#If the value is out of range, then return the original
#argv Syntax example: tclsh d:/sort_files_dir.tcl number as its return value.
d:/new
proc numeric {value} {
set in [lindex $argv 0] switch "$value" {
"1" {[return "ONE"]}
"2" {[return "TWO"]} #functions on lists. Display the output on the screen
"3" {[return "THREE"]} after every operation.
"4" {[return "FOUR"]}
"5" {[return "FIVE"]} set list {Arka Nikki Dk}
"6" {[return "SIX"]} set list1 {80 20 67}
"7" {[return "SEVEN"]} set list2 {Vellore TN}
"8" {[return "EIGHT"]} puts "$list"
"9" {[return "NINE"]} #o/p: Arka Nikki Dk
"default" {[return $value]}
} lappend list "Tathagata"
} puts "$list"
#o/p: Arka Nikki Dk Tathagata
puts "Please enter any Number between 1-9: "
gets stdin in lset list 2 "VIT"
puts "$list"
puts "$in = [numeric $in]" #o/p: Arka Nikki VIT Tathagata

17. set list [lreplace $list 2 2]


#Write a script to copy a data from one file to puts "$list"
another file using file handling. Also display #This will delete a element
appropriate error messagews to the user if the file is #Syntax: lreplace list first last ?element element ...
not accessible. #o/p: Arka Nikki Tathagata

puts "Please enter the Source File path: " set list [lreplace $list 0 2 80 20 67]
gets stdin in puts "$list"
puts "Please enter the Output File's Name (With #o/p: 80 20 67
Extension): "
gets stdin out_name set list [linsert $list 3 90]
puts "$list"
set fo [open $out_name w] #Syntax: linsert list index element1 ?element2
set fi [open $in r] element3 ...
while { [gets $fi data] >= 0 } { #o/p: 80 20 67 90
puts $fo $data
} set length [llength $list]
close $fo puts "$length"
close $fi #Syntax: llength list
puts "$out_name is created successfuly."; #o/p: 4

18. set result [lsearch $list "90"]


#Write a TCL script to generate 10 random test puts "$result"
vectors A and B within the limits specified by the #Syntax: lsearch ?options? list pattern
user. #o/p: 3 (index no "90")

puts "Enter the upper limit: " set result [lsearch -inline $list "90"]
gets stdin max puts "$result"
puts "Enter the lower limit: " #o/p: 90 (True- The value, False- an empty string)
gets stdin min
#[-all, -ascii, -decreasing, -increasing, -exact, -glob,
for {set i 0} {$i<=10} {incr i} { -increasing, -integer, -not, -real, -regexp, -sorted, -
set random_number [expr {$min + start index]
int(rand()*($max - $min))}]
puts "Random number is: puts $list
$random_number"
} set list [lset list 1 Nikki]
puts "$list"
19. #This will change an element in a list
#Write a TCL script to show the operations of #Syntax: lset varName ?index...? newValue..
lappend, lset, lreplace, linsert, #o/p: 80 Nikki 67 90
#llength, lsearch, lset, lrepeat, lsort, lreverse, split,
join, concat, range puts [lrepeat 3 a]
# Build a list by repeating elements
#Syntax: lrepeat count ?element ...
#o/p: a a a 20.
#Write a TCL program that reads the list of RTL
set a [lrepeat 3 [lrepeat 3 a b c]] and test bench files (Verilog files) in a design and
#o/p: a b c a b c a b c then compiles all the files
#using modelsim simulator and if compilation is
set list [lsort $list] successful for a design, then simulate the design
puts $list using the same simulator.
#Syntax: lsort ?options? list #Print messages such as “TEST PASSED― on
#o/p: 67 80 90 Nikki successful simulation and “TEST FAILED― if
#[-ascii, -dictionary, -integer, -real, -increasing, - the simulation is unsuccessful also if
decreasing, -indices, -index indexList] #compilation is unsuccessful, then print the
message as “check the log file for compilation
set list [lreverse $list] errors―.
puts $list
#Syntax: lreverse list puts "Enter the directory path containing .v files: ";
#o/p: Nikki 67 80 90 gets stdin in

set string [join $list " "] set v_files [glob -type f $in/*.v]
puts $string set v_size [llength $v_files]
#list to string puts $v_size
#o/p: Nikki 67 80 90 (string) set log_path "d:/log.txt"

set list [split $string " "] if {$v_size>0} {


puts $list file delete $log_path
#string to list exec vlib rtl_work
#o/p: Nikki 67 80 90 (list) exec vmap work rtl_work
for {set i 0} {$i<$v_size} {incr i} {
set list [concat $list $list2] exec {vlog [lindex $v_files $i]
puts $list >> $log_path};
#Join lists together }
#Syntax: concat ?arg arg ... set fi [open $log_path r]
#o/p: Nikki 67 80 90 Vellore TN while { [gets $fi data] >= 0 } {
lappend content $data
puts [string range "abcdefgh" 3 5] }
#Returns a range of consecutive characters from close $fi
string set count 0
#Syntax: string range string first last set count_err 0
#o/p: def set complied {}
set error {}
puts [string index "abcdefgh" 5] set content_size [llength $content]
#Returns the charIndex 'th character of the string for {set j 0} {$j<$content_size} {incr j} {
argument set temp [lindex $content $j]
#Syntax: string index string charIndex if {[regexp {^\s+(\w+)$} $temp _
#o/p: f a]} {
lappend complied $a
incr count
set comp1 "My name is Tathagata." }
set comp2 "My name is Tathagata." if {[regexp -nocase [subst -
puts [string compare comp1 comp2] nocommands -nobackslashes
if {[string compare comp1 comp2] == 0 } { {\*\*\sError:\s$in\s?(\w+)}] $temp _ b]} {
puts "Matched" lappend error $b
} else { incr count_err
puts "Not Matched" }
} }
#Compare two strings
#Syntax: string compare ?-nocase? ?-length int? set out "log_detail.txt"
string1 string2 set out_file [concat $in $out]
#o/p: Nikki 67 80 90 Vellore TN set fo [open $out_file w]
regsub -all {,} $content_string " " content_string
if {$count>0} { regsub -all {\.} $content_string " " content_string
set size_complied [llength regsub -all {\?} $content_string " " content_string
$complied] regsub -all {\!} $content_string " " content_string
puts "\nTEST
PASSED::\nSuccessfully complied files:" set content [split $content_string " "]
puts $fo "TEST set word [lsort -command {apply {{a b} {expr
PASSED::\nSuccessfully complied files:" {[string length $a] - [string length $b]}}}}
for {set k 0} $content]
{$k<$size_complied} {incr k} { set word [lreverse $word]
set no_com [expr {$k + puts "The longest word in the file \"$in\" is: [lindex
1}] $word 0]"
puts $fo "$no_com>
[lindex $complied $k]" 22.
puts "$no_com> [lindex #Write a Perl script that recursively checks a
$complied $k]" directory and displays only the .v files in an output
} file. The output file name
} #should be passed through the command line while
if {$count_err>0} { executing the Perl script.
set size_error [llength $error]
puts "\nTEST puts "Please enter the Directory path: "
FAILED::\nCompilation failed files:" gets stdin path
puts $fo "\nTEST
FAILED::\nCompilation failed files:" while {1} {
for {set l 0} {$l<$size_error} set v_files [glob -type f $path/*.v]
{incr l} { set size [llength $v_files]
set no_err [expr {$l + if {$size==0} {
1}] puts "No .v files found in $in"
puts $fo "$no_err> } else {
[lindex $error $l]" set fo [open [lindex $argv 0] w]
puts "$no_err> [lindex foreach temp $v_files {
$error $l]" puts $fo $temp
} }
} puts "[lindex $argv 0] is created
if {$count==0 && $count_err==0} { successfuly."
puts "Something is wrong! Check close $fo
your files." puts "Do you want to check the
} Directory again?: "
gets stdin user_ip
} else { if {[regexp -nocase {YES|y}
puts "\nNo .v files found for compilation." $user_ip]} {
} continue
close $fo } elseif { [regexp -nocase {NO|n}
$user_ip] } {
exit
} else {
21. puts "Wrong Choise."
#Write a TCL script to find and print the longest }
word in a text file. }
}
puts "Please enter Input Filename with loction: "
gets stdin in
23.
set fi [open $in r] #Write down the regular expressions that are
while { [gets $fi data] >= 0 } { matched by the following and execute the script
lappend content $data with simple examples.
} # a) A sentence (something that begins with a
capital letter and ends with a full stop)
set content_string [join $content " "]
set text1 "My name is Tathagata."
puts "String: $text1" puts "$text5 is not a number in Roman
numerals."
if {[regexp {^[A-Z]} $text1] && [regexp {\.$} }
$text1]} {
puts "\"$text1\" is begin with a capital # f) Any 'word character' except Q (try to make
letter and ends with a full stop." your regular expression as short as possible).
} else {
puts "\"$text1\" is not begin with a capital set text6 "My name is QTathagata"
letter and ends with a full stop." puts "String: $text6"
}
if {[regexp {[Q]} $text6]} {
# b) Any number that is a multiple of 5 puts "It has 'Q' along with words
characters."
set text2 "30" } else {
puts "\nGiven Number: $text2" puts "It has words characters except 'Q'."
}
if {[regexp {[05]$} $text2]} {
puts "$text2 is a multiple of 5" # g) Match any floating-point number.
} else {
puts "$text2 is not a multiple of 5" set text7 "5.9745"
}
if {[regexp {^\d*\.\d*} $text7]} {
# c) Any string whose length is a multiple of 5 puts "$text7 is a floating point number."
} else {
set text3 "My name is Tathagata" puts "$text7 is not a floating point
puts "\nString: $text3" number."
set length [string length $text3] }

if {[regexp {[05]$} $length]} { # h) Swap the two words of the following string
puts "Length of \"$text3\" is $length, and "45 67".
its multiple of 5."
} else { set text8 "45 67"
puts "Length of \"$text3\" is $length, and regexp {^(\d+)(\s)(\d+)} $text8 _ a b c
its not multiple of 5." set temp [concat $c$b$a]
}
puts "Old String: $text8, Reversed String: $temp"
# d) Any four digit number that reads the same
backwards as forwards (like 4114)
# i) http://www.beedub.com:80/index.html
set text4 "4114"
regexp {(\d)(\d)(\d)(\d)} $text4 _ a b c d set url http://www.beedub.com:80/index.html
set temp [concat $a$b$c$d]
if {[regexp
if {$text4 eq $temp} { {^(\w+\://\w+\.\w+\.\w+\:\d+\/\w+\.\w+)$} $url _
puts "$text4 is a palindrome number." a]} {
} else { puts "$a."
puts "$text4 is not a palindrome number." } else {
} puts "URL is not matching."
}
# e) A number in Roman numerals regexp {^(\w+)\:} $url _ b
regexp {^\w+\://(\w+\.\w+\.\w+)\:\d+\/\w+\.\w+$}
set text5 "XC" $url _ c
puts "Roman numeral: $text5" regexp {^\w+\://\w+\.\w+\.\w+(\:\d+)\/\w+\.\w+$}
$url _ d
if {[regexp regexp {^\w+\://\w+\.\w+\.\w+\:\d+\/(\w+\.\w+)$}
{^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(I $url _ e
X|IV|V?I{0,3})$} $text5]} { puts $b
puts "$text5 is a number in Roman puts $c
numerals." puts $d
} else { puts $e
puts "Check \"$in2\" for Reversed file."
# j) match the following words a507, b702, c334.

set text9 a509


25.
if {[regexp {\w\d+} $text9]} { #Assume you need to generate sufficient data to
puts "Matched" test your design. Write a data generator in TCL.
} else { #It should take the description of the desired data
puts "Not matching" format as its input and generate a set of random
} data conforming to that format.

puts "How many inputs does your code have?"


# Swap 30 & 40 in IP address 192.30.40.1 gets stdin in_no
puts "How many set of data you want to generate?"
set text10 192.30.40.1 gets stdin in_set
regexp {^(\d+)\.(\d+)\.(\d+)\.(\d+)} $text10 _ a b c
d for {set i 1} {$i<=$in_no} {incr i} {
set temp [concat $a.$c.$b.$d] puts "Enter no. $i input's name:"
puts "Old String: $text10, Reversed String: $temp" gets stdin in_name
lappend names $in_name
puts "Enter $in_name's size (In Bits):"
gets stdin in_size
lappend size $in_size
}

24. puts "\nRandom value are:"


#Develop a TCL script that sorts lines of the given for {set j 0} {$j<$in_no} {incr j} {
file in reverse order, so the last line becomes first set temp [expr {pow(2,[lindex $size $j])}]
and vice-versa. for {set k 1} {$k<=$in_set} {incr k} {
#The script must have two command line set random [expr {int (rand
arguments, the first is an input file name and the ()*$temp)}]
second is an output file name. set in_binary [format %b
#For input file check to have existing and readable $random]
file, otherwise print error and exit program. For puts "[lindex $names $j]:
output file check to have non existing file, $in_binary"
otherwise print error and exit. }
}
#set in1 [lindex $argv 0]
#set in2 [lindex $argv 1]
26.
set in1 "d:/temp.txt" #Develop a TCL script that deletes all empty lines
set in2 "d:/one.txt" of the given file. Lines are considered empty if one
can’t see anything, but it may contain spaces.
set fi [open $in1 r] #The script must have two command line
while { [gets $fi data] >=0 } { arguments, the first is an input file name and the
lappend content $data second is an output file name.
} #For input file check to have existing and readable
close $fi file, otherwise print error and exit program. For
output file check to have non existing file,
set fo [open $in2 w] otherwise print error and exit.

set size [expr {[llength $content] - 1 }] set in [lindex $argv 0]


for {set i $size} {$i>=0} {incr i -1} { set out [lindex $argv 1]
lappend rev_content [lindex $content $i]
puts -nonewline $fo "[lindex $content set fi [open $in r]
$i]\n" while { [gets $fi data] >=0} {
#puts $fo "\n" lappend content $data
} }
close $fo close $fi
set count 0 set data_clean [del $list]
set size [llength $content] puts "New list: $data_clean"
for {set i 0} {$i<=$size} {incr i} {
set temp [lindex $content $i]
if {[regexp -all {^s*$} $temp]} { 28.
incr count #Write a TCL script that prints the count of all the
} else { cells used in the given module of a netlist in a
lappend new_content [lindex report file.
$content $i] #The script must get two arguments. First is the
} name of the netlist and the second is the name of
} module for which to determine the cell counts.
#Script must generate a log file named
set fo [open $out w] "netlist_report.log"
for {set i 0} {$i<=[expr {$size - $count}]} {incr i}
{ set module [lindex $argv 0]
puts $fo [lindex $new_content $i] set netlist [lindex $argv 1]
}
close $fo set fi [open $netlist r]
while {[gets $fi content]>=0} {
puts "Check $out for the clean file." lappend text $content
}
27. close $fi
#Develop two perl functions. The first function
must take a list of elements as an argument and set cell_count 0
check if there are any duplicate elements in the list. set size [llength $text]
#And the second must delete duplicate elements for {set i 0} {$i<=$size} {incr i} {
from the list. set temp [lindex $text $i]
if {[regexp -nocase [subst -nocommands -
proc dup {data} { nobackslashes {^module\s*$module\s*\(}] $temp]}
set size [llength $data] {
set k 0 set x [expr {$i + 1}]
for {set i 0} {$i<$size} {incr i} { for {set j $x} {$j<=$size} {incr
for {set j [expr {$i+1}]} j} {
{$j<$size} {incr j} { set temp1 [lindex $text
if {[lindex $data $i] eq $j]
[lindex $data $j]} { if {[regexp
lappend {^\s*(\w+)\s\w+\s\(\s*\.} $temp1 _ b]} {
duplicate [lindex $data $i] lappend cells
lappend $b
location $i incr cell_count
} }
} if {[regexp
} {^endmodule} $temp1]} {
return [list $duplicate $location] break
} }
}
proc del {content} { }
set uniqueList [lsort -unique $content] }
return $uniqueList set unique_cell [lsort -unique $cells]
}
set out "d:/one.txt"
set fo [open $out w]
puts $fo "Total Cell count in the Module
\"$module\": $cell_count\nThe Cells are:"
set list "2 3 4 6 4 2" puts "Total Cell count in the Module \"$module\":
set data [dup $list] $cell_count\nThe Cells are:"
set duplicate [lindex $data 0]
set location [lindex $data 1] set count 0
puts "Duplicate elements are: $duplicate" set new_size [llength $cells]
set unique_size [llength $unique_cell] file copy -force $source_path2
for {set k 0} {$k<$unique_size} {incr k} { $target_path
for {set l 0} {$l<$new_size} {incr l} { }
if {[lindex $unique_cell $k] eq puts "Check $dir"
[lindex $cells $l]} {
incr count
} 30.
} #Write a TCL script to create a list that contains the
puts "[lindex $unique_cell $k]: $count" names of 10 students of a class. Print the list.
puts $fo "[lindex $unique_cell $k]: #Add that names at the end and beginning of list.
$count" Print the list. Ask user to input a number. Print the
set count 0 name that has that number as index.
} #Remove last and starting element of list. Print the
close $fo list in alphabetical and in reverse order.

set students {A B C D E F G H I J}
puts $students
29.
#Write a TCL programme that creates the skeleton set students_new [linsert $students 0 $students]
of a test suite such taht the directory steucture puts $students_new
should be as in fig. 1. Also assume you need to
copy two different #.v files lappend students_new $students
#residing in the current working directory to test puts $students_new
each test directory. Prompt the user to enter the
number of test directories to be created through the puts "Enter a number(0-10): "
standard input. gets stdin no
#Pass the names of the #.v files that need to be
copied to each test directory as the command line if {$no<10 && $no>=0} {
argument. puts "Value at $no index no: [lindex
$students $no]"
set cur_dir [pwd] } else {
puts "Wrong ip"
set temp "/" }
set in_file_1 [concat $cur_dir$temp[lindex $argv
0]] set students [lreplace $students [expr {[llength
set in_file_2 [concat $cur_dir$temp[lindex $argv $students]-1}] [expr {[llength $students]-1}]]
1]]
puts "Removed last element: $students"
set temp1 "/Testcases/"
set dir [concat $cur_dir$temp1] set students [lreplace $students 0 0]
file mkdir $dir puts "Removed starting element: $students"

cd $dir set students [lsort $students]


puts "Sorted list: $students"
puts "How many test directories you want to create:
" set students [lreverse $students]
gets stdin dir_no puts "Reversed list: $students"
for {set i 1} {$i<=$dir_no} {incr i} {
set temp2 "Test"
set dir_name [concat $temp2$i] 31.
file mkdir $dir_name #Write a TCL script which reads the provided
set source_path1 [concat $cur_dir/[lindex netlist and identifies the different number of cells
$argv 0]] instantiations and the number
set source_path2 [concat $cur_dir/[lindex #of occurrences of each cell. Prompt the user to
$argv 1]] modify the netlist such that any one cell name can
set target_path [concat be replaced with the cell name
$cur_dir$temp1$dir_name] #of user wish.
file copy -force $source_path1
$target_path
#####argv Syntax example: tclsh d:/task_3.pl gets stdin patched_new_name
d:/risk_netlist.v d:/patched_v_file_name.v set new [regsub -all $patched_data $text
d:/file_contains_instance_name.txt##### $patched_new_name ]
set fo1 [open $patched_netlist w]
set v_name [lindex $argv 0] set text_size [llength $text]
set patched_netlist [lindex $argv 1] for {set k 0} { $k <=$text_size} {incr k} {
set netlist_name [lindex $argv 2] set temp [lindex $new $k]
puts $fo1 $temp
puts $patched_netlist }
puts $netlist_name close $fo1
#set v_name "d:/top.v" puts "\n$patched_netlist is created
#set patched_netlist "d:/patched_netlist.v" successfully.\n"
#set netlist_name "d:/netlist_report.txt" } elseif {[regexp {NO|no|No|N|n} $user_ip]} {
exit
set fp [open $v_name r] } else {
while { [gets $fp data] >= 0 } { puts "Wrong Option chosen."
lappend text $data }
if {[regexp {^\s*(\w+)\s\w+\s?\(\s?\.\w+} $data
_ a]} {
lappend instance_names $a 32.
} #Write a TCL script to identify the number of
} occurrence of each cell in the given netlist. Also
close $fp display the number of
#occurrence of each cell along with its cell name.
set uniqueList [lsort -unique $instance_names] Identify the cell which is occurring for maximum
number of times and
set uniqueList_size [llength $uniqueList] #replace that cell with the cell name entered by the
set instance_size [llength $instance_names] user.

set fo [open $netlist_name w] set v_name [lindex $argv 0]

puts "List of the Cell instances of the given verilog set fp [open $v_name r]
netlist code:" while { [gets $fp data] >= 0 } {
puts $fo "List of the Cell instances of the given lappend text $data
verilog netlist code:" if {[regexp {^\s*(\w+)\s\w+\s?\(\s?\.\w+} $data
for {set j 0} { $j <$uniqueList_size} {incr j} { _ a]} {
set count 0 lappend instance_names $a
for {set i 0} { $i <$instance_size} {incr i} }
{ }
if {[lindex $uniqueList $j] eq close $fp
[lindex $instance_names $i]} {
incr count set uniqueList [lsort -unique $instance_names]
}
} set uniqueList_size [llength $uniqueList]
puts "[lindex $uniqueList $j]: $count" set instance_size [llength $instance_names]
puts $fo "[lindex $uniqueList $j]: $count"
} puts "List of the Cell instances of the given verilog
close $fo netlist code:"
set no 0
puts "$netlist_name is created successfully.\n" for {set j 0} { $j <$uniqueList_size} {incr j} {
set count 0
puts "Patching work is required or not 'yes' or 'no':
" for {set i 0} { $i <$instance_size} {incr i}
gets stdin user_ip {
if {[lindex $uniqueList $j] eq
if {[regexp {YES|yes|Yes|Y|y} $user_ip]} { [lindex $instance_names $i]} {
puts "Enter the name of the cell instance incr count
which you want to patch: "
gets stdin patched_data }
puts "Enter New name of cell instance: " }
lappend no $count
puts "[lindex $uniqueList $j]: $count" set error_mgs {}
} set count_error 0
set content_size [llength $content]
set sorted [lsort -integer $no] for {set j 0} { $j <$content_size} {incr j}
set length [expr {[llength $sorted]-1}] {
set max_location [lsearch $no [lindex $sorted set content_line [lindex $content
$length]] $j]
set max_value [lindex $uniqueList [expr if {[regexp {TEST PASSED}
{$max_location - 1}]] $content_line]} {
set status "PASS"
puts "\nCell that occur for maximun number of }
times i.e. [lindex $no $max_location] is \"[lindex if {[regexp {TEST FAILED}
$uniqueList [expr {$max_location - 1}]]\"\n"; $content_line]} {
puts "Enter a new cell ame to replace with set status "FAIL"
\"$max_value\": " }
gets stdin new_name if {[regexp {^\s*ERROR\s-
set uniqueList [lreplace $uniqueList [expr \s(.*)} $content_line _ a]} {
{$max_location - 1}] [expr {$max_location - 1}] lappend error_mgs $a
$new_name] incr count_error
set size_list [llength $uniqueList] }
for {set k 0} {$k<=[expr {$size_list}]} {incr k} { }
puts "[lindex $uniqueList [expr {$k -2}]]: set content {}
[lindex $no [expr {$k-1}]]" set count_error 0
} puts $fo "$x\t$name\t$status\t[lindex
$error_mgs 0]";
set error_mgs_size [llength $error_mgs]
33. if {$error_mgs_size>1} {
for {set k 1} { $k
#Write a TCL script that reads the given set of log <$error_mgs_size} {incr k} {
files from different simulations and generates a puts $fo "\t\t\t[lindex
consolidated report in .xls $error_mgs $k]";
#format which should contain the information as }
below. If the test is successful, the log file has the }
status as “TEST PASSED― and }
#if the test is unsuccessful, then the log file has the puts "Please check \"report.xls\" for report."
status as “TEST FAILED―. close $fo

set in [lindex $argv 0]


34.
set fp [open $in r]
while { [gets $fp files] >= 0 } { #Write a TCL script that reads in a file form a
lappend file_name $files specified and display the contents of that file, line
} by line. Make sure the file is handled properly,
close $fp #and remember to close the file after you finish.
Prompt the user with the list of file names in the
set fo [open "d:/Task_6/report.xls" w] directory and to enter any of the file name to be
puts $fo "Sl. No.\tTestcase Name\tStatus\tError read.
Messages"
puts "Please enter the Directory path: "
set no_of_file [llength $file_name] gets stdin path

for {set i 0} { $i <$no_of_file} {incr i} { set str_len [string length $path]


set x [expr $i+1]
set name [lindex $file_name $i] set files [glob -type f $path/*]
set fp1 [open $name r] set size [llength $files]
while { [gets $fp1 files1] >= 0 } {
lappend content $files1 foreach temp $files {
} set str_len2 [string length $temp]
close $fp1
set temp [string range $temp $str_len
$str_len2] if {$temp_f> 80} {
puts $temp puts "Avoid Sunburn!!"
} } elseif {$temp_f< 40} {
puts "Take a Coat!!"
puts "Please type any file's name to open:" } else {
gets stdin name puts "It will be a great Day!!"
set file_path [concat $path$name] }
puts "Content of the file is:\n"
37.
set fp [open $file_path r]
while { [gets $fp files] >= 0 } { #Create a new TCL command called "lincrement"
puts $files which takes two arguments a list and a value,
} #list contains N number of integers, all integers
close $fp should be incremented by the value given
#in the argument. The default increament value
should be 1 if the value is not mentioned in the
35. argument.

#!/usr/bin/tclsh proc lincreament {list {value 1}} {


set sub_file_names [glob *] set new_list {}
if {[lsearch $sub_file_names log] != -1} { if {$value>1} {
set sub_file_index [lsearch foreach data $list {
$sub_file_names log] lappend new_list [expr
cd [lindex $sub_file_names {$data + $value}]
$sub_file_index] }
#exec cd [lindex } else {
$sub_file_names $sub_file_index] foreach data $list {
file delete [glob *] lappend new_list [expr
cd .. {$data + $value}]
} else { }
puts [exec mkdir log] }
} return $new_list
}
set LOG_DIR log
puts [exec vcs -v -R [lindex $argv 0] [lindex $argv set ip "3 4 5"
1] -full64 -debug_all >$LOG_DIR/compile.log] set inc [lincreament $ip 20]
puts [exec ./simv >$LOG_DIR/sim.log] puts "Old List: $ip\nIncremented List: $inc"
puts [exec dc_shell -f ./synth.tcl
>$LOG_DIR/synth.log] puts "\n"

set ip "6 12 55"


36. set inc [lincreament $ip]
puts "Old List: $ip\nIncremented List: $inc"
#Write a program that asks the user for the outside
temperature in degrees Celsius. Display the
equivalent in degrees Celsius.
#The conversion formula is: F=32+9C/5 where F is proc unshift {list value} {
degrees Fahrenheit and C is degrees Celsius. Then, set list [lset list 0 $value]
if the temperature is going return $list
#to be below 40F tell the user to take a coat. If the }
temperature is above 80F tell them to avoid
sunburn. If it’s in between, set ip "I love India"
#tell them it will be a great day! set string [unshift $ip "We"]
puts "Old List: $ip\nIncremented List: $string"
puts "Enter the outside temperature in C:"
gets stdin temp_c 38.

set temp_f [expr {32 + (9 * $temp_c)/5}] #Write a program that creates a file called
puts "Temperature in Fahrenheit: $temp_f\F" "data.dat" in the current directory. Prompt the user
for five numbers, and write them, one at a time, on
both the foreach i {one two three} item {car coins rocks} {
#screen and into the file. Close the file, then open it puts "$i $item"
again for reading only, and display the contents on }
the screen.
#o/p
set cur_dir [pwd] #one car
#two coins
set temp "/" #three rocks
set file_name "data.dat"
set path [concat $cur_dir$temp$file_name]
set s1 "Hello"
set fo [open $path w] set s2 "World"
puts "Enter 5 numbers:" set s3 "World"
for {set i 1} {$i<=5} {incr i} {
puts "Enter no. $i number:" puts [string compare $s1 $s2]
gets stdin no if {[string compare $s2 $s3] == 0} {
puts $fo $no puts "String \'s1\' and \'s2\' are same.";
puts "Entered number: $no" }
}
close $fo if {[string compare $s1 $s2] == -1} {
puts "String \'s1\' comes before \'s2\'";
set fi [open $path r] }
while { [gets $fi data] >= 0 } {
lappend content $data if {[string compare $s2 $s1] == 1} {
} puts "String \'s2\' comes before \'s1\'";
puts "The contents of the file:" }
puts "$content"
close $fi #o/p
#String 's1' and 's2' are same. [s1 should be s3]
39. #String 's1' comes before 's2'
#String 's2' comes before 's1'
puts [linsert {1 2} 0 new stuff]
set x [list a {b c} e d]
puts $x proc parray name {
upvar $name a
#o/p
#new stuff 1 2 foreach el [lsort [array names a]] {
#a {b c} e d puts "$el = $a($el)"
}
puts [lreplace $x 1 2 B C] }

#o/p set info(name) "John"


#a B C d set info(age) 37
set info(position) "Vice President"

puts [lrange $x 1 3] parray info

#o/p #o/p
#{b c} e d #age = 37
#name = John
puts [lsearch {here is a list} 1*] #position = Vice President

#o/p set list {Perl C Java C++ Tcl}


#-1 set new {}
foreach el $list {
puts [lindex {ab {c d e} f} 2] if [string match Tcl* $el] {
lappend new $el
#o/p }
#f }
puts $new #set files [glob -type f $in/*]
set files [glob -type {f} $in*]
#o/p #puts "Name of the Directories are:"
#Tcl [Match a string with the list and #foreach data_dir $dirs {
create a new list with the matched value] # puts $data_dir
#}
puts "\nName of the Files are:"
40. foreach data_file $files {
puts $data_file
#Develop a TCL script that sorts lines of the given }
file in reverse order, so the last line becomes first
and vice-versa. 42.
#The script must have two command line
arguments, the first is an input file name and the #Write a TCL script to read a first name, last name
second is an output file name. and phone number from the
#For input file check to have existing and readable #from the console. If the user does not type at least
file, otherwise print error and exit program. For some characters for each
output file check to have non existing file, #of these, print "Do not leave any fields empty"
otherwise print error and exit. otherwise print "Thank You".

#set in1 [lindex $argv 0] while {1} {


#set in2 [lindex $argv 1] puts "Enter your first name:"
gets stdin first_name
set in1 "d:/temp.txt" puts "Enter your last name:"
set in2 "d:/one.txt" gets stdin last_name
puts "Enter your phone number:"
set fi [open $in1 r] gets stdin ph_number
while { [gets $fi data] >=0 } {
lappend content $data if {$first_name == "" | $last_name == "" |
} $ph_number == ""} {
close $fi puts "\nDo not leave any fields empty"
} else {
set fo [open $in2 w] puts "\nThank You"
exit
set size [expr {[llength $content] - 1 }] }
for {set i $size} {$i>=0} {incr i -1} { }
lappend rev_content [lindex $content $i]
puts -nonewline $fo "[lindex $content 43.
$i]\n"
#puts $fo "\n" #Write a TCL program that reads a list of
} numbers(on separate lines) until
close $fo #the number 999 is read, and then prints the total of
all the numbers added
puts "Check \"$in2\" for Reversed file." #together. (Be sure not to add in the 999!) For
example, if you enter 1, 2,
#3 and 999, the program should reply with the
41. answer of 6(1+2+3).

#Develop a TCL script that recursively searches all set added 0


files and directories of the puts "Enter some number:"
#given directory and returns the list of the files that while {1} {
contains the given word. gets stdin number
#The script must have two command line if {$number == 999} {
arguments, the first is a directory name puts "Result = $added"
#and the second is a search string. exit
} else {
set in [lindex $argv 0] set added [expr {$added + $number}]
set word [lindex $argv 1] }
}
#set dirs [glob -type d $in/*]
44. proc ldelete {list value} {
set value [expr {$value - 1}]
#Create a TCL command called "unshift" which set list [lreplace $list $value $value]
takes a list and an element as an argument return $list
#it deletes the first element in the list and adds the }
new element in place of that.
set ip "I love India"
proc unshift {list value} { set value [lindex $argv 0]
set list [lset list 0 $value] set list [ldelete $ip $value]
return $list puts "Old List: $ip\nNew List: $list"
}
48.
set ip "I love India"
set string [unshift $ip "We"] #Create a new command called "Fibonacci" which
puts "Old List: $ip\nNew List: $string" generates Fibonacci series
#but the no. of elements generated is limited by an
45, integer value specified
#Write a TCL script to reverse the elements of a list #as argument to the command.
using While and FOR loop.
proc fibonacci {value} {
set list "Tathagata DK Arka Nikki" set t1 0
set size [llength $list] set t2 1
set i 0 set nextTerm 0
while {$i<$size} {
lappend rev_list [lindex $list [expr {$size for {set i 1} {$i<=$value} {incr i} {
- $i - 1}]] puts $t1
incr i set nextTerm [expr {$t1 + $t2}]
} set t1 $t2
puts $rev_list set t2 $nextTerm
}
set new_rev_list {} }
for {set j [expr {$size - 1}]} {$j>=0} {incr j -1} {
lappend new_rev_list [lindex $rev_list $j] fibonacci 10
}
puts $new_rev_list
49.

46. #Write a TCL script to extract the word


"information" from the variable
#Write a TCL program that reads a number and #$a =
then a list of string (all separate "ccccccccaaabbbbaaaabbinformationbcaaaaaabbbb
#lines), and then prints one of the lines from the list bbbccbb" and display
as selected by the number. #the word in the standard output.

set list "My name is Tathagata. \nThis is VIT. \nI set data
am doing m.Tech." "ccccccccaaabbbbaaaabbinformationbcaaaaaabbbb
bbbccbb"
puts "Enter a number:"
gets stdin in regsub -all {[a-c]*} $data "" data

puts [lindex $list $in] puts $data

47. 50.
#Assume a file named a.txt contains a sequence of
#Create a new TCL command called "ldelete" numbers separated by comma
which deletes a particular element #as 12 / 12 / 29 / 30 / 20. Write a TCL script so that
#in a list, It takes two arguments a list and a value, the file a.txt should
it deletes the element #be modified as,
#specified by the value.
#12
set new [expr {$new + $no}]
#13 set final [format %c $new]
puts $final
#29
53.
#30
#A directory named "test" contains 100
#20 subdirectories of different tests.
#Each testcase has 5 files and one of these files,
named "monitor_cmd.v"
set fi [open "d:/new.txt" r] #needs to be deleted. Wrote a TCL script to
while {[gets $fi data]>=0} { perform the above said task.
lappend content $data
} set path "d:/new"
close $fi
set dirs [glob -type d $path/*]
set fo [open "d:/new.txt" w] set size [llength $dirs]
set list [split $content "/"] for {set i 0} {$i<$size} {incr i} {
foreach temp $list { set temp [lindex $dirs $i]
puts "$temp\n" cd $temp
puts $fo "$temp\n" set file_names [glob -type f $temp/*]
} set result [lsearch -all $file_names
close $fo *monitor_cmd.v*]
puts $file_names
puts $result
51. file delete [lindex $file_names $result]
}
#Write a TCL script to find the number of
occurrence of a cell named "DFFRX1"
#in a netlist. The netlist file should be passed as 54.
command line argument while
#executing the script. #Write a TCL script so that when it is executed, it
prompts the user to
set v_name [lindex $argv 0] #enter the names of two files and then identifies
whether those files
set fp [open $v_name r] #are identical or not. Display the appropriate
while { [gets $fp data] >= 0 } { messages to the user.
lappend text $data
} puts "Enter 1st file's name:"
close $fp gets stdin path1
puts "Enter 2nd file's name:"
set count 0 gets stdin path2
foreach temp $text {
if {[regexp set fp1 [open $path1 r]
{^\s*ad01d0\s\w+\s?\(\s?\.\w+} $temp]} { while {[gets $fp1 content1]>=0} {
incr count lappend data1 $content1
} }
} close $fp1
puts $count
set fp2 [open $path2 r]
52. while {[gets $fp2 content2]>=0} {
lappend data2 $content2
#Write a script to increment charter. }
close $fp2
puts "Enter a Charter:"
gets stdin in if {$data1 eq $data2} {
puts "Enter a integer to increment:" puts "Both files are identical"
gets stdin no } else {
puts "Both files are not identical"
set new [scan $in %c] }
array set names [list delhi 110004 chennai 600001
55. mumbai 400011 kolkata 700001 bangalore 530068]

#Write a TCL script to generate all the possible foreach {key value} [array get names] {
random input data patterns puts "$key => $value"
#to verify a 16 bit adder. }

puts "How many set of data you want to generate?" puts "Enter any one place name for pin code:"
gets stdin in_set gets stdin place
set names {A B}
set in_no [llength $names] set count 0
set bit 16 foreach {key value} [array get names] {
if {$key == $place} {
puts "\nRandom value are:" puts "$key => $value"
for {set i 0} {$i<$in_set} {incr i} { } else {
set temp [expr {pow(2,$bit)}] incr count
for {set j 0} {$j<$in_no} {incr j} { }
set random [expr {int (rand }
()*$temp)}]
set in_binary [format %b if {$count > 0} {
$random] puts "ERROR: Pin code of $place is not
puts "[lindex $names $j]: available."
$in_binary" }
}
} 58.

56. #write a TCL script that takes a dir name as its


argument, creates a new sub-dir called
#Write a TCL script to find the length of a string #executable within it. The script then scans the dir
without using the string length command. and all its sub-dirs looking for
#executable files and moves the executables into
set string abcdefghijk the new sub-dir. Assume there can be
#identically named executables also.
set temp [split $string ""]
set count 0 set path [lindex $argv 0]
foreach value $temp { set sub_dir "/executable"
incr count set sub_path [concat $path$sub_dir]
} puts $sub_path
puts "Length of the string $string is: $count"
set dirs [glob -type d $path/*]
57. set size [llength $dirs]

#Set up an associative array that contains a few city file mkdir $sub_path
names and their corresponding zip for {set i 0} {$i<$size} {incr i} {
#codes. Make at-least 5 elements in the array. set temp [lindex $dirs $i]
Display the names of the cities and ask cd $temp
#the user to enter one. Display the corresponding set file_names [glob -type f $temp/*.txt]
zip code if a city entered by the user set size1 [llength $file_names]
#is in the array. If the city is not in the array then for {set j 0} {$j<$size1} {incr j} {
generate an error message and print set temp1 [lindex $file_names $j]
#the error message file copy -force $temp1
$sub_path
#set names(110004) delhi }
#set names(600001) chennai }
#set names(400011) mumbai puts "Files copied successfully."
#set names(700001) kolkata
#set names(530068) bangalore

#parray names 59.


#Assume a project named as ABC has four }
subdirectories, rtl, tb, sim, and testsuite.
#The testsuite directory has "N" number of testcase while { [gets $fp data] >= 0 } {
directories and each testcase lappend content $data
#directory has three .v files to perform functional }
verification. You need to perform
#regression with the given testsuite. To do the puts $content
regression, for each test you need
#to go to a particular test directory copy all the .v 61.
files and past it in the sim #Scan command
#directory.Perform the simulation for that
particular test and once the simulation scan 12a34 {%d%[abc]%d} x - y
#is done, copy all the, log files and past it to the test puts $x
directory. Write a TCL script puts $y
#to perform the above said task.
#o/p
set path "d:/ABC/testsuite" #12
set v_path "d:/ABC/sim" #34

set dirs [glob -type d $path/*] foreach character {a A b B c} {


set size [llength $dirs] scan $character %c numeric
for {set i 0} {$i<$size} {incr i} { puts "ASCII character '$numeric' displays as
set temp [lindex $dirs $i] '$character'."
cd $temp }
set file_names [glob -type f $temp/*]
set size1 [llength $file_names] #o/p
exec vlib rtl_work #ASCII character '97' displays as 'a'.
exec vmap work rtl_work #ASCII character '65' displays as 'A'.
for {set j 0} {$j<$size1} {incr j} { #ASCII character '98' displays as 'b'.
set temp1 [lindex $file_names $j] #ASCII character '66' displays as 'B'.
file copy -force $temp1 $v_path #ASCII character '99' displays as 'c'.
}
}

set v_files [glob -type f $v_path/*.v]


set v_size [llength $v_files]
set log_path "d:/ABC/tb/report.log"
puts $v_files

if {$v_size>0} {
exec vlib rtl_work
exec vmap work rtl_work
for {set j 0} {$j<$v_size} {incr j} {
exec {vlog [lindex $v_files $i]
>> $log_path};
}
}

60.
#Error Command

set file "d:/new111.txt"

if [catch {open $file r} result] {


error "Warning: $result"
} else {
set fp $result

You might also like