added error checking on various file open operations in xschem.tcl
This commit is contained in:
parent
32d18b5a94
commit
c565a363b0
|
|
@ -7044,21 +7044,24 @@ proc symbolParse {file} {
|
||||||
}
|
}
|
||||||
|
|
||||||
proc read_data_nonewline {f} {
|
proc read_data_nonewline {f} {
|
||||||
set fid [open $f r]
|
set res [catch {open $f r} fid]
|
||||||
|
if {$res} { puts "read_data_nonewline: $fid"; return {}}
|
||||||
set data [read -nonewline $fid]
|
set data [read -nonewline $fid]
|
||||||
close $fid
|
close $fid
|
||||||
return $data
|
return $data
|
||||||
}
|
}
|
||||||
|
|
||||||
proc read_data {f} {
|
proc read_data {f} {
|
||||||
set fid [open $f r]
|
set res [catch {open $f r} fid]
|
||||||
|
if {$res} { puts "read_data: $fid"; return {}}
|
||||||
set data [read $fid]
|
set data [read $fid]
|
||||||
close $fid
|
close $fid
|
||||||
return $data
|
return $data
|
||||||
}
|
}
|
||||||
|
|
||||||
proc read_data_window {w f} {
|
proc read_data_window {w f} {
|
||||||
set fid [open $f r]
|
set res [catch {open $f r} fid]
|
||||||
|
if {$res} { puts "read_data_window: $fid"; return {}}
|
||||||
set t [read $fid]
|
set t [read $fid]
|
||||||
# $w delete 0.0 end
|
# $w delete 0.0 end
|
||||||
## 20171103 insert text at cursor position instead of at beginning (insert index tag)
|
## 20171103 insert text at cursor position instead of at beginning (insert index tag)
|
||||||
|
|
@ -7067,7 +7070,9 @@ proc read_data_window {w f} {
|
||||||
}
|
}
|
||||||
|
|
||||||
proc write_data {data f} {
|
proc write_data {data f} {
|
||||||
set fid [open $f w]
|
|
||||||
|
set res [catch {open $f w} fid]
|
||||||
|
if {$res} { puts "write_data: $fid"; return {}}
|
||||||
puts -nonewline $fid $data
|
puts -nonewline $fid $data
|
||||||
close $fid
|
close $fid
|
||||||
return {}
|
return {}
|
||||||
|
|
@ -7497,11 +7502,14 @@ proc editdata {{data {}} {title {Edit data}} {wrap {none}} {ro 1}} {
|
||||||
set editdata_filename [tk_getSaveFile -initialdir [pwd] ]
|
set editdata_filename [tk_getSaveFile -initialdir [pwd] ]
|
||||||
}
|
}
|
||||||
if { $editdata_filename != "" } {
|
if { $editdata_filename != "" } {
|
||||||
set editdata_fileid [open $editdata_filename w]
|
if {[catch {open $editdata_filename w} editdata_fileid]} {
|
||||||
|
puts "editdata: $editdata_fileid"
|
||||||
|
} else {
|
||||||
puts -nonewline $editdata_fileid [.editdata.text get 1.0 {end - 1 chars}]
|
puts -nonewline $editdata_fileid [.editdata.text get 1.0 {end - 1 chars}]
|
||||||
close $editdata_fileid
|
close $editdata_fileid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
editdata_save
|
editdata_save
|
||||||
}
|
}
|
||||||
pack $window.buttons.saveas -side left -expand 1
|
pack $window.buttons.saveas -side left -expand 1
|
||||||
|
|
@ -7546,9 +7554,12 @@ proc textwindow {filename {ro {}}} {
|
||||||
if { $ro eq {} } {
|
if { $ro eq {} } {
|
||||||
button $textwindow_w.buttons.save -text "Save" -command \
|
button $textwindow_w.buttons.save -text "Save" -command \
|
||||||
{
|
{
|
||||||
set textwindow_fileid [open $textwindow_filename w]
|
if {[catch {open $textwindow_filename w} textwindow_fileid]} {
|
||||||
|
puts "textwindow: $textwindow_fileid"
|
||||||
|
} else {
|
||||||
puts -nonewline $textwindow_fileid [$textwindow_w.text get 1.0 {end - 1 chars}]
|
puts -nonewline $textwindow_fileid [$textwindow_w.text get 1.0 {end - 1 chars}]
|
||||||
close $textwindow_fileid
|
close $textwindow_fileid
|
||||||
|
}
|
||||||
destroy $textwindow_w
|
destroy $textwindow_w
|
||||||
}
|
}
|
||||||
pack $textwindow_w.buttons.save -side left -expand 1
|
pack $textwindow_w.buttons.save -side left -expand 1
|
||||||
|
|
@ -7563,10 +7574,12 @@ proc textwindow {filename {ro {}}} {
|
||||||
pack $textwindow_w.xscroll -side bottom -fill x
|
pack $textwindow_w.xscroll -side bottom -fill x
|
||||||
bind $textwindow_w <Escape> "$textwindow_w.buttons.dismiss invoke"
|
bind $textwindow_w <Escape> "$textwindow_w.buttons.dismiss invoke"
|
||||||
set textwindow_fileid [open $filename r]
|
set textwindow_fileid [open $filename r]
|
||||||
|
if {[catch {open $filename r} textwindow_fileid]} {
|
||||||
# 20171103 insert at insertion cursor(insert tag) instead of 0.0
|
puts "textwindow: $textwindow_fileid"
|
||||||
|
} else {
|
||||||
$textwindow_w.text insert insert [read $textwindow_fileid]
|
$textwindow_w.text insert insert [read $textwindow_fileid]
|
||||||
close $textwindow_fileid
|
close $textwindow_fileid
|
||||||
|
}
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7600,11 +7613,14 @@ proc viewdata {data {ro {}} {win .view} {wrap none}} {
|
||||||
set viewdata_filename [tk_getSaveFile -initialdir [pwd] ]
|
set viewdata_filename [tk_getSaveFile -initialdir [pwd] ]
|
||||||
}
|
}
|
||||||
if { $viewdata_filename != "" } {
|
if { $viewdata_filename != "" } {
|
||||||
set viewdata_fileid [open $viewdata_filename w]
|
if {[catch {open $viewdata_filename w} viewdata_fileid]} {
|
||||||
|
puts "viewdata: $viewdata_fileid"
|
||||||
|
} else {
|
||||||
puts -nonewline $viewdata_fileid [$viewdata_w.text get 1.0 {end - 1 chars}]
|
puts -nonewline $viewdata_fileid [$viewdata_w.text get 1.0 {end - 1 chars}]
|
||||||
close $viewdata_fileid
|
close $viewdata_fileid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pack $viewdata_w.buttons.saveas -side left -expand 1
|
pack $viewdata_w.buttons.saveas -side left -expand 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue