-
Notifications
You must be signed in to change notification settings - Fork 1
/
host2cpm.tcl
executable file
·119 lines (99 loc) · 3.56 KB
/
host2cpm.tcl
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/tclsh
# copies host directories to/from a cpm disk image file
# Note a single file can be
# moved with the yaze cdm command.
# Coded by Gary L. Howell, Jan. 2001
# uses package command line from the standard tcllib
package require cmdline 1.0
namespace import cmdline::getopt
set usage "
host2cpm \[-r\] \[-d 'dirpath\[filter\]'\] \[-cpm 'filepath'\] \[-f 'filter'\]
host2cpm -h
Moves multiple files in a dir to/from the cpm disk.
-r optional - reverse cpm->host, instead of default host->cpm
-d optional - the directory pathname of the host directory
to be copied/updated.
For host->cpm, if the path is a directory name, all the files in the
directory will be copied. If the path includes a quoted glob pattern,
only the selected files will be copied. Example '-d 'work/cpm/*.ASM'.
Glob patterns must be quoted so that the shell does not expand them
before passing the argument to the script.
For (-r) reverse mode cpm->host just the directory path should be
supplied, all files from the cpm disk will be copied to the host
directory unless the a filter is supplied ( see the -f option ).
Defaults to the current dir.
-cpm optional - the file of the cpm disk image. Default is the name of the
current dir with .dsk appended. For direction host->cpm if the file does
not exist, a new empty disk file is created.
-f optional - the CPM file glob pattern selects files to be copied.
EX -f '*.ASM' - Must be quoted from the shell.
-h help - only display this message. "
variable reverse 0
variable hostpath ""
variable cpmfile ""
variable cpmfilter ""
proc process_command_line_options {} {
set arguments_definition { h r d.arg cpm.arg f.arg }
set option ""
set option_value ""
global argc argv usage
variable reverse
variable hostpath
variable cpmfile
variable cpmfilter
while {
[set result [ cmdline::getopt argv $arguments_definition option option_value ]] != 0
} {
if { $result == -1 } then { puts "Command line $option_value. Try host2cpm -h for help." ; exit 1 }
switch $option {
r { set reverse 1 }
d { set hostpath $option_value }
cpm { set cpmfile $option_value }
f { set cpmfilter $option_value }
h { puts $usage ; exit 0 }
}
}
}
process_command_line_options
if { $cpmfile == "" } then { set cpmfile "[file tail [ pwd ]].dsk" }
if {$reverse} then {
set fcdm [ open "|cdm $cpmfile" r+ ]
puts $fcdm "dir $cpmfilter"
puts $fcdm quit
flush $fcdm
set cpm_file_directory [ read $fcdm ]
close $fcdm
set cpm_files {}
foreach word $cpm_file_directory {
if {[ string match 0:* $word ]} {
lappend cpm_files $word
}
}
set fcdm [ open "|cdm $cpmfile" w ]
foreach cpmfile $cpm_files {
puts $fcdm "cp $cpmfile u:$hostpath"
}
puts $fcdm quit
close $fcdm
} else {
if {$hostpath == ""} then {
set hostpath *
} elseif { [ string match */ $hostpath ] } then {
set hostpath "$hostpath*"
} elseif { ! [string match {*/*\**} $hostpath] } then {
set hostpath "$hostpath/*"
}
set fcdm [ open "|cdm " w ]
if { ! [ file exists $cpmfile ] } then {
puts "host2cpm: Creating a new cpm disk file $cpmfile."
puts $fcdm "create $cpmfile"
}
puts $fcdm "mount a $cpmfile"
foreach unixfile [ glob "$hostpath" ] {
if { ( [file type $unixfile ] == "file" ) && ( $unixfile != $cpmfile )} then {
puts $fcdm "cp u:$unixfile a:[file tail $unixfile ]"
}
}
puts $fcdm quit
close $fcdm
}