1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
Put in this directory your conversion filters.
For example, create for your format "myf" the following file:
myf.tcl
containing:
namespace eval myf {
# A short string describing your format for use within file chooser
variable msg "My format"
# A list of authorized extensions (can use globbing syntax)
# The first one is used as default extension for output
variable ext ".myf .my2"
# The optional 'guess' proc returns 1 if the filename is of the format
# else 0.
# If this proc is not provided, default behaviour is to match one of
# the extensions given in the variable ext as follows:
proc guess {filename} {
variable ext
set filext [string tolower [file extension $name]]
if {[expr [lsearch $ext $filext]>=0]} {
# Can also try to look at file header/magic number
return 1
}
return 0
}
# The 'import' proc allows to read a fully structured transcription
# in a rather complex way - see typ.tcl for a complete example
proc import {filename} {
global v
# First read content of file
set content [ReadFile $name]
# Then create an XML structure following the imported file
set v(trans,root) [::xml::element "Trans"]
...
}
# The 'readSegmt' proc can be provided instead of 'import' for simple
# segmentations (only give one of them, not both!)
# If 'readSegmt' is provided, the 'import' proc defaults to:
# proc import {name} {SegmtToTrans [readSegmt [ReadFile $name]]}
# 'readSegmt' gets the content of the file as input
# and returns a list of segments: {start stop label}
proc readSegmt {content} {
set segmt {}
foreach line [split $content "\n"] {
if {[llength $line] == 3} {
lappend segmt $line
}
}
return $segmt
}
# The 'export' proc can be used to dump the file to the format
# - see stm.tcl for an example
proc export {filename} {
global v
set channel [open $filename w]
set episode [$v(trans,root) getChilds "element" "Episode"]
foreach sec [$episode getChilds "element" "Section"] {
foreach tur [$sec getChilds "element" "Turn"] {
foreach chn [$tur getChilds] {
switch [$chn getType] {
"#PCDATA" { ... } }
"Sync" { ... }
"Event" { ... }
...
}
}
}
}
close $channel
}
}
|