File: cdrtoaster

package info (click to toggle)
cdrtoaster 1.12-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 76 kB
  • ctags: 4
  • sloc: tcl: 1,243; makefile: 40
file content (1565 lines) | stat: -rwxr-xr-x 43,968 bytes parent folder | download | duplicates (2)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
#!/bin/sh
# the next line restarts using wish (Emacs clue: -*- tcl -*- ) \
    exec wish "$0" "$@"

proc interface {} {

wm title . "CDR Toaster - [version]"

label .title -text {CDR Toaster} -font -*-times-bold-r-*-*-30-*-*-*-*-*-*-*

frame .b -border 3 -relief raised
button .b.burn -text {Have a Cook-Off}

set m .b.trick.m
menubutton .b.trick -text {Do Tricks} -menu $m -relief raised -border 2
menu $m -tearoff 0
$m add command -label "Read CDROM to create ISO image" -command read_iso
$m add command -label "Read audio tracks from CDROM" -command read_audio
$m add command -label "Blank a CDRW Media" -command blank_cdrw

button .b.quit -text {Never Mind}

set m .b.help.m
menubutton .b.help -text {Get Help!} -menu $m -relief raised -border 2
menu $m -tearoff 0
$m add command -label "About" -command help
$m add command -label "Clarifications" -command help_clarify

frame .audio
label .audio.la -text {Audio Track List} 
frame .audio.f -border 3 -relief sunken 
listbox .audio.f.lb -height 16 -width 30 -selectmode browse  -yscrollcommand {.audio.f.sb set}
scrollbar .audio.f.sb -orient v -command {.audio.f.lb yview}
frame .audio.m
button .audio.m.up -text {Move up} -command {
 set num [.audio.f.lb curselection]
 if {""==$num} return
 if {$num==0} return
 flip $num
 incr num -1
 .audio.f.lb selection set $num
 .audio.f.lb see $num
}
button .audio.m.dn -text {Move Down} -command {
 set num [.audio.f.lb curselection]
 if {""==$num} return
 incr num 1
 if {$num==[.audio.f.lb index end]} return
 flip $num
 .audio.f.lb selection set $num
 .audio.f.lb see $num
}
frame .audio.ar -relief flat 
button .audio.ar.add -text {Add} -command {
audio_add
}
button .audio.ar.rem -text {Remove} -command {
audio_remove
}
button .audio.remall -text {Remove All} -command audio_removeall

label .lds -text "Data Track Source"

frame .ds -border 3 -relief sunken 
radiobutton .ds.none -text {Make audio-only disk} -variable {ds} -value none
radiobutton .ds.mk -text {Make data track on the fly} -variable {ds} -value mkisofs
radiobutton .ds.pre -text {Use pre-made data track} -variable {ds} -value premade
entry .ds.tname -width 20 -font 7x14
.ds.tname insert 0 "image.iso"

## Andrew found the missing code, so now TK8 users (of which I have become)
## can reap the benefits of a standard dialog.

# Lets make the selection button if you have tk8.0 +
if {[info tclversion] >= 8.0} {
  button .ds.select -text {Select} -command {my_image}
} else {
  button .ds.select -text {Select} -command {
    perusefile
    .ds.tname delete 0 end
    .ds.tname insert 0 $perusedfile
  }
}


label .lm -text {Data Track Creation Options}
frame .m -border 3 -relief sunken

frame .m.scan
checkbutton .m.scan.all -text {Keep all files (backups etc.)} -variable {all}
checkbutton .m.scan.links -text {Follow SymLinks} -variable {follow}

frame .m.file
checkbutton .m.file.joliet -text {Joliet support} -variable {joliet}
checkbutton .m.file.trans -text {Translation Tables (old)} -variable {trans}

frame .m.rock -border 0 -relief flat 
label .m.rock.l -text {Rock Ridge:}
radiobutton .m.rock.none -text {None} -variable {rock} -value none
radiobutton .m.rock.rational -text {Rationalized} -variable {rock} -value rat
radiobutton .m.rock.literal -text {Literal} -variable {rock} -value lit

frame .m.volid -border 0
label .m.volid.l -text {Volume ID (name)}
entry .m.volid.e -width 32 -font 7x14
frame .m.root -border 0 -relief flat
label .m.root.l -text {Root of Tree}
entry .m.root.e -width 24 -font 7x14
button .m.root.p -text "Peruse" -command {
 peruse
 .m.root.e delete 0 end
 .m.root.e insert 0 $perused
}

frame .m.custom -border 0
checkbutton .m.custom.use -text "Use Custom Layout" -variable custom(use)
button .m.custom.b -text {Set Custom Layout} -command custom_layout

frame .m.boot
checkbutton .m.boot.check -text "El Torito Bootable CD" -variable boot
button .m.boot.opts -text "Boot Setup" -command boot_setup

label .lc -text {cdrecord options} 
frame .c -border 3 -relief sunken
frame .c.flag
checkbutton .c.flag.dummy -text {Dummy Burn} -variable {dummy}
checkbutton .c.flag.eject -text {Eject when done} -variable {eject}
button .c.flag.pad -text "Padding..." -command padbox
frame .c.dev -border 0 -relief flat 
label .c.dev.l -text {Device} 
entry .c.dev.e -width 20 -font 7x14 -textvariable device
frame .c.speed
label .c.speed.l -text "Speed:"
radiobutton .c.speed.1 -text "1x" -variable speed -value 1
radiobutton .c.speed.2 -text "2x" -variable speed -value 2
radiobutton .c.speed.4 -text "4x" -variable speed -value 4
radiobutton .c.speed.6 -text "6x" -variable speed -value 6
radiobutton .c.speed.8 -text "8x" -variable speed -value 8
radiobutton .c.speed.10 -text "10x" -variable speed -value 10  
radiobutton .c.speed.12 -text "12x" -variable speed -value 12  


pack .title -side top
pack .b -side top -ipadx 30 -ipady 10
pack .b.burn -side left -expand 1
pack .b.trick -side left -expand 1 -ipady 1 -ipadx 1
pack .b.quit -side left -expand 1
pack .b.help -side left -expand 1
pack .audio -side right -anchor n
pack .audio.la -side top
pack .audio.f -side top
pack .audio.f.lb -side left
pack .audio.f.sb -side left -fill y
pack .audio.m -side top
pack .audio.m.up -side left
pack .audio.m.dn -side left
pack .audio.ar -side top
pack .audio.ar.add -side left
pack .audio.ar.rem -side left
pack .audio.remall -side top
pack .lds -side top
pack .ds -side top -padx 5
pack .ds.none -side bottom -anchor w
pack .ds.mk -side bottom -anchor w
pack .ds.pre -side left -anchor w
pack .ds.tname -side left -anchor w
pack .ds.select -side right -anchor n
pack .lm -side top
pack .m -side top
pack .m.scan -side top -fill x
pack .m.scan.all -side left
pack .m.scan.links -side right
pack .m.file -side top -fill x
pack .m.file.joliet -side left
pack .m.file.trans -side right
pack .m.rock -side top -anchor w
pack .m.rock.l -side left
pack .m.rock.none -side left
pack .m.rock.rational -side left
pack .m.rock.literal -side left
pack .m.volid -side top -anchor w
pack .m.volid.l -side left
pack .m.volid.e -side left
pack .m.root -side top -anchor w -fill x
pack .m.root.l -side left
pack .m.root.e .m.root.p -side left
pack .m.custom -side top -fill x
pack .m.custom.use -side left
pack .m.custom.b -side right
pack .m.boot -side top -anchor w -fill x
pack .m.boot.check -side left
pack .m.boot.opts -side left -expand 1
pack .lc -side top
pack .c -side top
pack .c.flag -side top
pack .c.flag.dummy -side left
pack .c.flag.eject -side left
pack .c.flag.pad -side left
pack .c.dev -side top
pack .c.dev.l -side left
pack .c.dev.e -side left
pack .c.speed -side top
pack .c.speed.l .c.speed.1 .c.speed.2 .c.speed.4 .c.speed.6 .c.speed.8 .c.speed.10 .c.speed.12 -side left

frame .spacer -height 10
pack .spacer -side top


}
proc toast {} {
global apad dpad ds

if {$ds == "none"} {
set source ""
}

if {$ds == "premade"} {
 set source [.ds.tname get]
 if {![file isfile $source]} {
 alert "Premade data track must be a regular file."
 return
 }
}

if {$ds == "mkisofs"} {
 set source -
 set mk [make_mkisofs_cmd]
 if {$mk == ""} {
  return
 }
}

set cd [base_cdrec]

set nuke ""
set convlist ""

if {$source != ""} {
 lappend cd -data
 if $dpad {lappend cd "-pad"}
 lappend cd $source
}
set tmp [.audio.f.lb get 0 end]
if {$tmp == ""} {
 if {$ds == "none"} {
  alert "No audio tracks were specified for an audio-only disk. This makes no sense."
  return
 }
} else {
 lappend cd -audio
 if $apad {lappend cd "-pad"} else {
  if $dpad {lappend cd "-nopad"}
 }
 set warned 0
 foreach i $tmp {
  ## Have to validate audio track type
  switch [file extension $i] {
   .mp2 -
   .mpg -
   .mp3 {
    if {$warned == 0} {
     # Give use opportunity to opt out. Also collect info for conversion.
     set tempdir [get_mp3_burn_info]
     if {$tempdir==""} {
      alert "An understandable choice."
      return
     }
     set warned 1
    }
    # Queue for conversion burning, and nuking.
    # Yes, there are race conditions. No, I don't care too much. If
    # you have a fix for the race conditions which is not too complicated,
    # tell me and I'll probably add your fix. Thanks.
    set tail [file tail $i]
    set tempfile [file join $tempdir "###${tail}.wav"]
    if [file exists $tempfile] {
     alert "$tempfile already exists. I will cancel the burn and let you decide what to do."
     return
    }
    lappend convlist $i
    lappend nuke $tempfile
    lappend cd $tempfile
   }
   
   .wav -
   .raw -
   .pcm {
    # queue for burning
    lappend cd $i
   }
   
   default {
    # Note the offending file for the user.
    alert "I don't recognize the file extention on '$i'. For safety reasons, I won't burn that file as an audio track.\n\nI'd suggest removing it and others like it from the audio track list."
    return
   }
  }
 }
}

if {$ds == "mkisofs"} { set cd [concat $mk $cd] }

set shellCommand $cd
regsub -all {///PIPE///} $shellCommand "|" shellCommand

if {[sure "About to run command:\n\n$shellCommand\n\nAre you sure?"]} {
 set err 0
 set err [catch {
  # Run necessary conversions
  if [llength $convlist] {
    
    toplevel .conv
    wm title .conv "Converting MP3s"
    text .conv.t -width 80 -height [llength $convlist]
    pack .conv.t
    
    foreach orig $convlist tempfile $nuke {
      .conv.t insert end "$orig --> $tempfile ..."
      update
      exec mpg123 -s $orig | sox -t raw -w -s -c 2 -r 44100 - -t wav $tempfile >&/dev/null
      .conv.t insert end " Done.\n"
    }
    
    destroy .conv
  }
 }]
 
 set cmd_list [list $cd]
 
 if $err {
  alert "Some error occured during the MPEG conversion process. You probably ran out of space or don't have the mpg123 and sox tools installed."
 } else {
  # Remove temp files when done...
  foreach tempfile $nuke {
    lappend cmd_list [list rm $tempfile]
  }
  
  dispatch $cmd_list {CD Burn Progress}
 }

}

}
proc audio_add {} {
catch {destroy .add}
toplevel .add
wm title .add {Add Audio Tracks}


label .add.l -text {Track Name (Globals OK)} 
entry .add.e -width 32 -font 7x14 
button .add.ok -text {OK} -command {
set tmp [glob -nocomplain [.add.e get]]
foreach i $tmp {.audio.f.lb insert end $i}
destroy .add
}
button .add.cancel -text {Cancel} -command {
destroy .add
}

pack .add.l -side top
pack .add.e -side top
pack .add.ok -side left
pack .add.cancel -side right


}
proc audio_remove {} {
set victim [.audio.f.lb curselection]
catch {.audio.f.lb delete $victim}
}
proc audio_removeall {} {
.audio.f.lb delete 0 end
}
proc flip n {
.audio.f.lb selection clear 0 end
set above [expr $n - 1]
set tmp [.audio.f.lb get $n]
.audio.f.lb insert $above $tmp
.audio.f.lb delete [expr $n + 1]
}
proc alert msg {
tk_dialog .alert Alert $msg info 0 "So it goes."
}
proc help {} {
catch {destroy .help}
toplevel .help
wm title .help {Help!}

button .help.ok -text {This Rules!} -command {destroy .help}
text .help.t -width 60 -height 18 -yscrollcommand {.help.sb set} -wrap word
scrollbar .help.sb -orient v -command {.help.t yview}

pack .help.ok -side bottom
pack .help.t -side left
pack .help.sb -side left -fill y

.help.t insert 1.0 "About CDR-Toaster version [version]"
.help.t insert end {

This is a graphical front-end for the excellent programs 'mkisofs', 'cdrecord', and 'cdparanoia'.

It's good for:
 o Avoiding coasters due to command-line mistakes
 o Eliminating the tedium of consulting documentation
 o Feeling more secure in a correct set of options
 o Being lazy

As you can guess, I wrote it for what it's good for.

CDR-Toaster is copyright 1999 Ian Kjos <brooke@jump.net>

CDR-Toaster contains some code contributed by:
  Daniel Caujolle-Bert <lobadia@club-internet.fr>
  Andrew Williams <woodchuk@bellatlantic.net>
  Claus Brunzema <chb@ossi.fho-emden.de>
  Aaron Sherman <ajs@ajs.com>
  Fred D. Feirtag <fdfeirt@valinor.sandia.gov>
  And a cast of thousands!
  
  If you don't see your name here and you should,
  please send me some e-mail about it. Preferably
  with a diff.

CDR-Toaster is availible under the GNU General
Public License version 2.0 or later (at your option).
This license can be found at 
http://www.gnu.org/copyleft/gpl.html

}

.help.t config -state disabled

}
proc sure msg {
return [expr ![tk_dialog .alert Confirmation $msg questhead -1 yes no]]
}
proc read_iso {} {
catch {destroy .top}
toplevel .top
wm title .top "Read ISO image"

frame .top.dev -border 0 -relief flat 
frame .top.file -border 0 -relief flat 
frame .top.b -border 0 -relief flat 
label .top.dev.l -text {device to read:} 
label .top.file.l -text {file to write:} 
entry .top.dev.e -width 20 -font 7x14 
entry .top.file.e -width 20 -font 7x14 
button .top.b.ok -text {Do it} -command {
if {![file readable [.top.dev.e get]]} {
 alert "You do not have read permissions on '[.top.dev.e get]'. You should probably be running this as root."
 return
}
set cmd_echo [list echo "This takes a good while."]
set cmd_dd [list dd if=[.top.dev.e get] of=[.top.file.e get] bs=1024k]
set cmd_eject [list eject [.top.dev.e get]]
dispatch [list $cmd_echo $cmd_dd $cmd_eject] "Reading ISO Image"
destroy .top
}
button .top.b.dis -text {Forget it} -command {
destroy .top
}

pack .top.dev -side top
pack .top.file -side top
pack .top.b -side top -fill x
pack .top.dev.l -side left
pack .top.file.l -side left
pack .top.dev.e -side left
pack .top.file.e -side left
pack .top.b.ok -side left -expand 1
pack .top.b.dis -side left -expand 1

.top.dev.e insert 0 [detect_cdrom_device]
.top.file.e insert 0 "image.iso"

}
proc read_audio {} {
catch {destroy .top}
toplevel .top
wm title .top "Read audio tracks"

frame .top.path1
label .top.path1.l -text "(optional) Rip Source: "
entry .top.path1.source -width 15
button .top.path1.peruse -text "Peruse" -command {
peruse_block
.top.path1.source delete 0 end
.top.path1.source insert 0 $perusedfile
}

frame .top.path2
label .top.path2.l -text "Rip Destination: "
entry .top.path2.dest
button .top.path2.peruse -text "Peruse" -command {
peruse
.top.path2.dest delete 0 end
.top.path2.dest insert 0 $perused
}

frame .top.1 -border 0 -relief flat 
frame .top.2 -border 0 -relief flat 
frame .top.3 -border 0 -relief flat 
frame .top.4 -border 0 -relief flat 
radiobutton .top.1.entire -text {Rip Entire Disk} -variable {rip} -value {all}
radiobutton .top.2.track -text {Tracks:} -variable {rip} -value {track}
radiobutton .top.3.custom -text {Custom Options} -variable {rip} -value {custom}
button .top.4.ok -text {Do it} -command {
 set tmp "Ripping Audio"
 switch $rip {
  all {
    if {[.top.path1.source get] != ""} {
      set dp [list "cdparanoia -d [.top.path1.source get] -w -B 1-"]
    } else {
      set dp [list "cdparanoia -s -w -B 1-"]
    }
  }
  track {
   if {[.top.path1.source get] != ""} {
    set dp [list "cdparanoia -d [.top.path1.source get] -w -B [.top.2.from get]-[.top.2.to get]"]
   } else {
    set dp [list "cdparanoia -s -w -B [.top.2.from get]-[.top.2.to get]"]
   }
  }
  custom {
   set dp [list "cdparanoia [.top.3.opt get]"]
  }
 }
 if {[.top.path2.dest get] != ""} {
  set dp [concat [list "cd [.top.path2.dest get]"] $dp]
 }
 dispatch $dp $tmp
 destroy .top
}
button .top.4.dis -text {Not now.} -command {
 destroy .top
}
label .top.2.lfr -text {From:} 
entry .top.2.from -width 4 -font 7x14 
label .top.2.lto -text {To:} 
entry .top.2.to -width 4 -font 7x14 
entry .top.3.opt -width 20 -font 7x14 

pack .top.path1 -side top -fill x
pack .top.path1.l .top.path1.source .top.path1.peruse -side left
pack .top.path2 -side top -fill x
pack .top.path2.l .top.path2.dest .top.path2.peruse -side left
pack .top.1 -side top -fill x
pack .top.2 -side top -fill x
pack .top.3 -side top -fill x
pack .top.4 -side top -fill x
pack .top.1.entire -side left -anchor w
pack .top.2.track -side left -anchor w
pack .top.3.custom -side left -anchor w
pack .top.4.ok -side left -expand 1
pack .top.4.dis -side left -expand 1
pack .top.2.lfr -side left -anchor e
pack .top.2.from -side left -anchor e
pack .top.2.lto -side left -anchor e
pack .top.2.to -side left -anchor e
pack .top.3.opt -side left -anchor e

global rip
set rip all


}
proc blank_cdrw {} {
global blank

catch {destroy .top}
toplevel .top
wm title .top "Blank CDRW Media"

frame .top.type -border 0 -relief flat 
frame .top.b -border 0 -relief flat 
label .top.type.l -text {Blank Type} 
frame .top.type.r
radiobutton .top.type.all -text {Entire Disk} -variable {blank} -value {all}
radiobutton .top.type.session -text {Session} -variable {blank} -value {session}
radiobutton .top.type.track -text {Track} -variable {blank} -value {track}
radiobutton .top.type.fast -text {Fast} -variable {blank} -value {fast}
radiobutton .top.type.r.unreserve -text {Unreserve} -variable {blank} -value {unreserve}
radiobutton .top.type.r.trtail -text {Track Tail} -variable {blank} -value {trtail}
radiobutton .top.type.r.unclose -text {Unclose} -variable {blank} -value {unclose}
button .top.b.ok -text {Do it} -command {
 set cmd [base_cdrec]
 lappend cmd "blank=${blank}"
 dispatch [list $cmd] "Blanking CDRW: ${blank}"
 destroy .top
}
button .top.b.dis -text {Let's not.} -command {
 destroy .top
}

pack .top.type -side top
pack .top.b -side top -fill x
pack .top.type.l -side left
pack .top.type.r -side right -fill y
pack .top.type.all -side top -anchor w
pack .top.type.session -side top -anchor w
pack .top.type.track -side top -anchor w
pack .top.type.fast -side top -anchor w
pack .top.type.r.unreserve -side top -anchor w
pack .top.type.r.trtail -side top -anchor w
pack .top.type.r.unclose -side top -anchor w
pack .top.b.ok -side left -expand 1
pack .top.b.dis -side left -expand 1

set blank session

}

proc dispatch {cmdList title} {
 
 set shellCommand ""
 set systype [exec /bin/uname -s]
 
 switch $systype {
 	"SunOS" { set xdir "/usr/openwin/bin" }
 	default { set xdir "/usr/X11R6/bin" }
 }
 
 foreach cmd $cmdList {
   set tmp [join $cmd "' '"]
   append shellCommand "'$tmp'; "
 }
 
 regsub -all {\'///PIPE///\'} $shellCommand "|" shellCommand

 append shellCommand "echo Done. Press Enter; read"
 
 puts $shellCommand
 
 exec $xdir/xterm -geometry 80x6 -title $title -e sh -c $shellCommand &
 
}

proc base_cdrec {} {
global dummy eject speed
set cd [list cdrecord -v]
if {$dummy} {lappend cd -dummy}
if {$eject} {lappend cd -eject}
set dev [.c.dev.e get]
if {![check_device $dev]} {
 alert "You don't have write permission to the device you selected. You should probably be running this as root. If that is not an option, get the system administrator to give you write privileges for the cd-writer."
 return -code return
}
lappend cd "dev=$dev" "speed=$speed"
return $cd
}
proc help_clarify {} {
catch {destroy .help}
toplevel .help
wm title .help {Help!}

set helpstuff {
 {All Files}
{   Ordinarily files with names containing '#' or '~'
   are backup files on Linux. CDR-Toaster will instruct
   mkisofs to skip these files in the creation of a
   CD. If you DON'T want to skip them, click this box.
}
 {Joliet support}
{   This stores long filenames on a CD so Windows 9x/NT
   machines can read them. Unlike the Joliet CDs produced
   on MS-Windows, you can still see the 8.3 filenames on
   MS-Dos and other systems that don't support Joliet.
   Linux kernels 2.2 and up can also read Joliet names.
}
 {Rock Ridge}
{   This is another way to store long filenames on a CD.
   It works with all Un*x-like systems that also support
   CDs. It allows file permissions, ownership info, and
   symbolic links to be stored and appear as such on the
   CD. If you choose "Literal", the final CD will look in
   all respects identical to the directory hierarchy it
   was created from, except for some reason you can't
   write to it. This could be good for system backups.
   If you choose "Rationalized", you get a more generally
   useful CD. It sets the user and group of all files to
   root, removes SUID and SGID bits, makes all files and
   folders readable globally, sets all execute bits for
   anything that has any execute bits, and clears all
   write bits.
}
 {Follow SymLinks}
{   Normally symbolic links are ignored, unless you use
   Rock Ridge, when they are copied literally. If you
   want the actual files and folders pointed to by the
   symbolic links to show up on the CD, check this box.
}
 {Translation Tables}
{   Puts a file called "TRANS.TBL" in every directory on
   the CD which maps 8.3 files to their long equivalents.
   Very simple, very old.
}
 {MPEG Compressed Audio}
{   CDR-Toaster will extract MPEG Compressed audio (mp3)
   if you have mpg123 and sox installed. This way you
   can burn an audio CD from mp3 files. The sound will
   not be as good quality as the original uncompressed
   audio, but that's the trade off that a lossy compression
   like MPEG makes to attain the high ratios that it does.
   For more information, point your web browser at these:
   http://www.mpeg.org/MPEG/
   http://drogo.cselt.stet.it/mpeg/
}
 {PCM vs. WAV}
{   WAV is a format composed of 44 bytes of header data,
   then raw PCM data. PCM means only pulse code modulation,
   which is to say a digitial audio format made of numbers
   to signify each sample. There is no attempt made to
   compress the signals beyond the decisions of sample rate
   and dynamic range.

   For CDR-Toaster to burn audio, you can feed it either a
   raw PCM file or a WAV file. WAV files are better because
   they contain enough information in the header to ensure
   that the audio format is correct. To get an audio track
   to burn properly, the PCM data needs to be composed of
   exactly the same structure as on a CD - that is 41.1 khz
   16 bit stereo. Anything else and you get an unusable
   audio track.

   When using WAV files ripped from a CD, (as CDPARANOIA
   does) you will get files that are already correct. If
   you want to use a WAV file you recorded yourself, it is
   wise to ensure you recorded cd-quality (16 bit stereo
   44.1khz) uncompressed audio. If you did otherwise, there
   are many format converters available which can convert to
   this format without any signal loss. The other issue with
   audio files you record yourself is that they must be a
   precise multiple of 1/75th of a second. This is where
   audio padding comes into play. If you do not have the
   right number of samples, the Pad Audio option can round
   up using absolute silence.
}
 {Burning Bootable CDs}
{   When your computer boots from a CD, it treats part of
   the CD as a floppy drive. The emulation is at the BIOS
   level, so programs like the Linux Kernel operate
   normally but programs like LILO or SYSLINUX are fooled.
   All attempts to access the (primary) floppy drive are
   mapped to the "BOOT" extent on the CD.

   Step by step, the easiest way to make a bootable CD
   is as follows:

   1. Make a real live floppy disk that boots your computer
      ok. There are many rescue disk packages which are
      good for this purpose, or you can use your operating
      system install disk. Make sure the floppy actually
      boots properly.

   2. Copy this floppy disk to an image file. Under Linux
      you can type:
         dd if=/dev/fd0 of=bootimage.bin bs=18k

   3. Put this file in the directory you are going to make
      your CD from:
         mv bootimage.bin /tmp/my_cdrom/

   4. Bring up CDR-Toaster. Put a check in the "El Torito
      Bootable CD" box, and click the "Boot Setup" button.

   5. For "Boot Image Path" type "bootimage.bin"

   6. For "Boot Catalog Path" type "bootcat.bin"

   7. Click OK, and set the "Root of Tree" appropriately.
      From the example above, it would be "/tmp/my_cdrom"

   8. Finish burning your CD as you would normally.

   9. Set your bios to boot from CD, and things should
      be happy.

   The Boot Catalog is a place for information about the
   Boot Image. It is generated automatically. It need not
   exist beforehand. In fact, if it does exist, it will
   be overwritten.

   Both paths are interpretted relative to the root
   of the CD.

   For more information, see "man mkisofs". It should be on
   your system for CDR-Toaster to operate properly.
}
 {Using ATAPI CDR(W) Devices}
{   ATAPI CDR(W)s are special. The Linux kernel needs to be 
   compiled specially for them to work properly.

   Basically, you must TURN OFF IDE CDROM support and 
   instead use both "SCSI emulation" and "SCSI generic 
   support".

   If you have never compiled a kernel before, you are wise 
   to read the Kernel Howto.

   I tend to use "make menuconfig" to configure the kernel, 
   and these are the things I did:

   Under "Block devices", I set "Include IDE/ATAPI CDROM 
   support" to "n" and I set "SCSI emulation support" to 
   "Y".

   Under "SCSI support", I make sure there is "SCSI CD-ROM 
   support" and "SCSI generic support" turned on. Since I 
   have no true SCSI cards, I need nothing from the "SCSI 
   low-level drivers" section.

   I built and installed this kernel. As a result, my 
   CD-ROM detected as a scsi device (/dev/scd0 in my case) 
   during bootup and I have been able to burn to /dev/sg0 
   as is the default in CDR-Toaster.

   For more information on the special needs of your 
   CDR(W), see the documentation for "cdrecord" which is 
   the burn program that CDR-Toaster calls out to.
}
}

frame .help.b

set m .help.b.topic.m
menubutton .help.b.topic -menu $m -text Topic -relief raised
menu $m

button .help.b.ok -text {This Rules!} -command {destroy .help}
text .help.t -width 60 -height 18 -yscrollcommand {.help.sb set} -wrap word
scrollbar .help.sb -orient v -command {.help.t yview}

pack .help.b -side bottom -fill x
pack .help.b.topic -side left
pack .help.b.ok -side bottom
pack .help.t -side left
pack .help.sb -side left -fill y

.help.t insert 1.0 {Clarifications:

}

foreach {topic body} $helpstuff {
 set end [.help.t index end]
 set line [expr $end - 1]
 $m add command -label $topic -command ".help.t yview $line"
 .help.t insert end " o $topic\n"
 .help.t insert end "$body\n"
 .help.t tag add head $line $end
}

.help.t tag configure head -foreground white -background blue -font 8x16

.help.t tag add top 1.0 2.0
.help.t tag config top -foreground white -background blue -font 10x20

.help.t config -state disabled

}
proc padbox {} {

catch {destroy .pad}
toplevel .pad
wm title .pad {Padding Options}

frame .pad.audio
checkbutton .pad.audio.cb -text {Pad Audio Tracks} -variable {apad}
message .pad.audio.amesg -text {This option will pad audio track data to be a multiple of 2352 bytes. The padding is done with all zeroes which means complete silence. See also PCM vs. WAV in help.
}
frame .pad.data
checkbutton .pad.data.cb -text {Pad Data Track} -variable {dpad}
message .pad.data.dmesg -text {This option appends 15 sectors of zeroes to each data track. This works around a bug in very old Linux kernels.}
button .pad.ok -text Dismiss -command {destroy .pad}

pack .pad.audio -fill x
pack .pad.audio.cb -side left -anchor n
pack .pad.audio.amesg
pack .pad.data -fill x
pack .pad.data.cb -side left -anchor n
pack .pad.data.dmesg
pack .pad.ok

}
proc peruse {} {
# Just browse directories

global perused

set perused ""

catch {destroy .peruse}
toplevel .peruse
wm title .peruse {Peruse Folders}

frame .peruse.dir -border 0 -relief flat 
frame .peruse.mod -border 0 -relief flat 
frame .peruse.control -border 0 -relief flat
menubutton .peruse.dir.up -menu .peruse.dir.up.m -relief raised -border 2
button .peruse.dir.ok -text {<-- Accept} -command {}
listbox .peruse.mod.lb -height 10 -width 20 -selectmode browse -yscrollcommand {.peruse.mod.sb set}
scrollbar .peruse.mod.sb -orient v -command {.peruse.mod.lb yview}
button .peruse.control.go -text {Delve} -command {}
button .peruse.control.cancel -text {Cancel} -command {}

pack .peruse.dir -side top -fill x
pack .peruse.mod -side top -fill x
pack .peruse.control -side top -fill x
pack .peruse.dir.up -side left
pack .peruse.dir.ok -side right
pack .peruse.mod.lb -side left -fill y -anchor w
pack .peruse.mod.sb -side left -fill y -anchor w
pack .peruse.control.go -side left -expand 1
pack .peruse.control.cancel -side left -expand 1

peruse_populate [pwd]
tkwait window .peruse

}
proc perusefile {} {
# Just browse files

global perusedfile

set perusedfile ""

catch {destroy .perusefile}
toplevel .perusefile
wm title .perusefile {Peruse Files}

frame .perusefile.dir -border 0 -relief flat 
frame .perusefile.mod -border 0 -relief flat 
frame .perusefile.control -border 0 -relief flat
menubutton .perusefile.dir.up -menu .perusefile.dir.up.m -relief raised -border 2
button .perusefile.dir.ok -text {<-- Accept} -command {
}
listbox .perusefile.mod.lb -height 10 -width 20 -selectmode browse -yscrollcommand {.perusefile.mod.sb set}
scrollbar .perusefile.mod.sb -orient v -command {.perusefile.mod.lb yview}
button .perusefile.control.go -text {Delve} -command {
}
button .perusefile.control.cancel -text {Cancel} -command {
}

pack .perusefile.dir -side top -fill x
pack .perusefile.mod -side top -fill x
pack .perusefile.control -side top -fill x
pack .perusefile.dir.up -side left
pack .perusefile.dir.ok -side right
pack .perusefile.mod.lb -side left -fill y -anchor w
pack .perusefile.mod.sb -side left -fill y -anchor w
pack .perusefile.control.go -side left -expand 1
pack .perusefile.control.cancel -side left -expand 1

perusefile_populate [pwd]
tkwait window .perusefile

}
proc peruse_populate dir {

set tmp [file tail $dir]
if {$tmp == ""} {set tmp /}
.peruse.dir.up configure -text $tmp

set m .peruse.dir.up.m
catch {
destroy $m
}
menu $m -tearoff 0

set up /
foreach dcomp [file split $dir] {
 set up [file join $up $dcomp]
 $m add command -label $dcomp -command "peruse_populate \"$up\""
}

.peruse.mod.lb delete 0 end
set tmp [lsort [glob $dir/.* $dir/*]]
foreach dcan $tmp {
 if [file isdirectory $dcan] {
  set tail [file tail $dcan]
  if {$tail != "." && $tail != ".."} {
   .peruse.mod.lb insert end $tail
  }
 }
}

## Bindings

.peruse.control.cancel config -command {
 set perused ""
 destroy .peruse
}
.peruse.dir.ok config -command [subst {
 set perused "$dir"
 destroy .peruse
}]

set go [subst -nocommands {
 if {[.peruse.mod.lb get active] != ""} {
  peruse_populate [file join "$dir" [.peruse.mod.lb get active]]
 } else bell
}]

bind .peruse.mod.lb <Double-1> $go
.peruse.control.go config -command $go

}
proc perusefile_populate dir {

set tmp [file tail $dir]
if {$tmp == ""} {set tmp /}
.perusefile.dir.up configure -text $tmp

set m .perusefile.dir.up.m
catch {
destroy $m
}
menu $m -tearoff 0

set up /
foreach dcomp [file split $dir] {
 set up [file join $up $dcomp]
 $m add command -label $dcomp -command "perusefile_populate \"$up\""
}

.perusefile.mod.lb delete 0 end
if {[catch {lsort [glob $dir/.* $dir/*]} catchvar]} {
  set tmp ""
} else {
  set tmp $catchvar
}

foreach dcan $tmp {
  set tail [file tail $dcan]
  if {$tail != "." && $tail != ".."} {
   .perusefile.mod.lb insert end $tail
  }
}

## Bindings

.perusefile.control.cancel config -command {
 set perusedfile ""
 destroy .perusefile
}
.perusefile.dir.ok config -command [subst {
 set perusedfile "$dir"
 destroy .perusefile
}]

set go [subst -nocommands {
 if {[.perusefile.mod.lb get active] != ""} {
  perusefile_populate [file join "$dir" [.perusefile.mod.lb get active]]
 } else bell
}]

bind .perusefile.mod.lb <Double-1> $go
.perusefile.control.go config -command $go

}
proc boot_setup {} {
global bootimg bootcat

catch {destroy .boot}
toplevel .boot
wm title .boot {Bootable CD Setup}


frame .boot.img -border 0 -relief flat 
frame .boot.cat -border 0 -relief flat 
frame .boot.cmd -border 0 -relief flat 
label .boot.img.l -text {Boot Image Path} 
label .boot.cat.l -text {Boot Catalog Path} 
entry .boot.img.e -width 20 -font 7x14 
entry .boot.cat.e -width 20 -font 7x14 

# Got TK8? You get a pretty button.
if {[info tclversion] >= 8.0} {
  button .boot.img.b -text {Select} -command open_bootfile
  button .boot.cat.c -text {Select} -command open_catfile
}

button .boot.cmd.ok -text {OK} -command {
 set bootimg [.boot.img.e get]
 set bootcat [.boot.cat.e get]
 destroy .boot
}
button .boot.cmd.cancel -text {Cancel} -command {
 destroy .boot
}
button .boot.cmd.revert -text {Revert} -command {
 .boot.img.e delete 0 end
 .boot.cat.e delete 0 end
 .boot.img.e insert 0 $bootimg
 .boot.cat.e insert 0 $bootcat
}

# Populate Data Fields
.boot.img.e insert 0 $bootimg
.boot.cat.e insert 0 $bootcat

pack .boot.img -side top -fill x
pack .boot.cat -side top -fill x
pack .boot.cmd -side top -fill x
pack .boot.img.l -side left
pack .boot.cat.l -side left
pack .boot.img.e -side right
pack .boot.cat.e -side right
pack .boot.cmd.ok -side left -expand 1
pack .boot.cmd.cancel -side left -expand 1
pack .boot.cmd.revert -side left -expand 1

# Got TK8? You get a pretty button.
if {[info tclversion] >= 8.0} {
  pack .boot.img.b -side right
  pack .boot.cat.c -side right
}

# frame .m.img
# label .m.img.l -text "Boot Image Path"
# entry .m.img.e
# frame .m.cat
# label .m.cat.l -text "Boot Catalog Path"
# entry .m.cat.e
}
proc get_mp3_burn_info {} {
# Returns either the empty list, indicating a cancelation,
# or the temp directory.

global perused

set warn {\
You have chosen to burn an MPEG compressed file as an audio track. This will not be the same quality as the original from which it was made. However, the burn can proceed if given a space to uncompress the audio files.

Do you wish to proceed?}

set go [sure $warn]
if {!$go} {
 return {}
}

set df [exec -keepnewline df]

catch {destroy .df}
toplevel .df
wm title .df {Free Disk Space}

text .df.t -width 80 -height 10 -setgrid 1 -yscrollcommand {.df.sb set}
scrollbar .df.sb -orient v -command {.df.t yview}

.df.t insert end "Please browse to a directory with sufficient free space.\n\n"
.df.t insert end $df
.df.t config -state disabled

pack .df.sb -side right -fill y
pack .df.t -side left

peruse
destroy .df

alert "Be aware that the MP3 conversion process typically takes some time."

return $perused
}
proc custom_layout {} {

global custom

catch {destroy .custom}
toplevel .custom
wm title .custom {Custom CD Layout}


frame .custom.dirs -border 0 -relief flat 
frame .custom.table -border 0 -relief flat 
frame .custom.cmds -border 0 -relief flat 
frame .custom.help -border 0 -relief flat 
label .custom.dirs.a -text {Make contents of:} 
label .custom.dirs.b -text {Show up on CD within:} 

foreach x {0 1 2 3 4 5 6 7 8 9} {
 frame .custom.table.$x -border 0 -relief flat 
 button .custom.table.$x.peruse -text {Peruse} -command "custom_peruse $x"
 entry .custom.table.$x.from -width 25 -font 7x14 
 entry .custom.table.$x.to -width 25 -font 7x14 
 
 button .custom.table.$x.clear -text {Clear} -command [subst {
 .custom.table.$x.from delete 0 end
 .custom.table.$x.to delete 0 end
 }]
 
 pack .custom.table.$x -side top -fill x
 pack .custom.table.$x.peruse -side left -anchor w
 pack .custom.table.$x.from -side left -anchor w
 pack .custom.table.$x.clear -side right -anchor e
 pack .custom.table.$x.to -side right -anchor e
 
}

scrollbar .custom.help.sb -orient v -command {} -command {.custom.help.t yview}
text .custom.help.t -width 70 -height 10 -setgrid 1 -yscrollcommand {.custom.help.sb set}
button .custom.cmds.ok -text {OK} -command {
 set from {}
 set to {}
 foreach s [pack slaves .custom.table] {
  lappend from [$s.from get]
  lappend to [$s.to get]
 }
 set custom(from) $from
 set custom(to) $to
 set custom(use) 1
 destroy .custom
}
button .custom.cmds.revert -text {Revert} -command {
 foreach s [pack slaves .custom.table] from $custom(from) to $custom(to) {
  $s.from delete 0 end
  $s.to delete 0 end
  $s.from insert 0 $from
  $s.to insert 0 $to
 }
}
button .custom.cmds.cancel -text {Cancel} -command {
destroy .custom
}

pack .custom.dirs -side top -fill x
pack .custom.table -side top -fill x
pack .custom.cmds -side top -fill x
pack .custom.help -side top -fill both -expand 1
pack .custom.dirs.a -side left -anchor w
pack .custom.dirs.b -side right -anchor e
pack .custom.help.sb -side right -fill y -anchor e
pack .custom.help.t -side right -fill both -anchor w
pack .custom.cmds.ok -side left -expand 1
pack .custom.cmds.revert -side left -expand 1
pack .custom.cmds.cancel -side left -expand 1

.custom.cmds.revert invoke

.custom.help.t insert 1.0 {              Custom CD Layout Help

This was always the biggest pain for me. I want stuff from the hard
drive from arbitrary places to show up on the final CD in (other)
arbitrary places.

I've tried to make this fairly general. Name what you want on the
left, and where to put it on the right. The one thing to remember
is that if you put a directory on the left, you have to give it
a name on the right unless you want a whole bunch of files sprayed
all over the root of the CD.

The names you give on the right do not have to exist anywhere
except your imagination. If they don't exist within other parts of
what you burn, the directories will be automatically created to
exist on the CD. Directories created in this way will be owned by
root.root and have permissions 555 (read/exec for all).

I'm not yet sure how these custom layouts interact with bootable
CD creation. I think that you specify the boot paths relative to
the final CD image. I know it works that way in the simple case.

}

.custom.help.t tag add cool 1.0 2.0
.custom.help.t tag config cool -font 10x20
.custom.help.t tag config cool -background blue
.custom.help.t tag config cool -foreground white

.custom.help.t config -state disabled
}
proc custom_peruse x {
global perused
peruse
if {$perused != ""} {
  .custom.table.$x.from delete 0 end
  .custom.table.$x.from insert 0 $perused
}}
proc make_mkisofs_cmd {} {
 global all joliet follow trans ds rock
 global boot bootimg bootcat custom
 
 set vol [.m.volid.e get]
 set root [.m.root.e get]

 # Presumably this is not necessary if there is a custom layout.
 
 if {![file isdirectory $root]} {
 alert "For on-the-fly ISO image creation, the root of tree must be a directory."
 return
 }
 
 set mk mkisofs
 if {$all} {lappend mk -all-files}
 if {$joliet} {lappend mk -joliet}
 switch -exact $rock {
  none {}
  rat {lappend mk -r}
  lit {lappend mk -R}
 }
 if {$follow} {lappend mk -follow-links}
 if {$trans} {lappend mk -translation-table}
 if {$boot} {
  if {($bootimg == "") || ($bootcat == "")} {
   alert "You selected 'Bootable CD' but either the boot image or boot catalog entries are blank. This will not work."
   return
  }
  if {![file exists [file join $root $bootimg]]} {
   alert "[file join $root $bootimg] is not there. You can't make a bootable CD without a bootimage."
   return
  }
  if {[file exists [file join $root $bootcat]]} {
   if {![sure "[file join $root $bootcat] will be overwritten if you continue. Is this ok?"]} {return}
  }
  lappend mk -b $bootimg -c $bootcat
 } else {
  if {$bootimg != ""} {
   set ok [sure "You have stuff in the bootimage entry, but have not chosen the 'Bootable CD' option. Do you want a standard non-bootable cd?"]
   if {!$ok} {return}
  }
 }
 if {$vol != ""} {lappend mk -volid $vol}
 
 ## Here we need to (maybe) process the custom layout entries.
 lappend mk $root
 
 if {$custom(use)} {
  foreach dir $custom(from) graftpoint $custom(to) {
   if {$dir == ""} continue
   set isdir [file isdirectory $dir]
   if {$isdir} {set dir "$dir/"}
   lappend mk "$graftpoint/=$dir"
  }
 }
 
 ## Last gasp.
 # use a illegal filename as symbol for the pipe so it can be recognized later
 lappend mk "///PIPE///"
 return $mk
 }
proc open_bootfile {} {
set types {
    {{Disk Images}      {.img}        }
    {{All Files}        *             }
}
set boot_img [tk_getOpenFile -filetypes $types -initialdir ~/ -title {Choose Image}]
.boot.img.e delete 0 250
.boot.img.e insert 0 $boot_img
}
proc open_catfile {} {
set types {
    {{All Files}        *             }
}
set boot_cat [tk_getOpenFile -filetypes $types -initialdir ~/ -title {Choose File}]
.boot.cat.e delete 0 250
.boot.cat.e insert 0 $boot_cat
}
proc check_device dev {

if {[file writable $dev]} {
  return 1
}

# Now gotta test for numeric device specification

set len [string length $dev]
set field {0123456789,}

for {set i 0} {$i < $len} {incr i} {
  set try [string index $dev $i]
  if {![string match *$try* $field]} {return 0}
}

return 1
}
proc version {} {
# Just return the version of this CDR-Toaster copy.
# Keeps everything in one place.

return "1.12"
}
proc detect_cdrom_device {} {
# Try some likely prospects:

set prospects [list "/dev/cdrom" "/dev/cdroms/cdrom0"]
foreach try $prospects {
  if {[file exists $try] && ! [file isdirectory $try]} {
    return $try
  }
}

# Give up and hope for user input.
return "/dev/"
}
proc my_image {} {
## TK8.0+ Dialog for file selection

set types {
    {{ISO9660 Images}   {.iso}        }
    {{XCD-Roast Images} {.raw}        }
    {{All Files}        *             }
}
set image [tk_getOpenFile -filetypes $types -defaultextension *.raw -initialdir /iso -title {Choose Image}]
.ds.tname delete 0 250
.ds.tname insert 0 $image

}
proc peruse_block args {
# This procedure should use the "peruse" strategy to let
# the user select a block-special file.
# Also, I'm going to re-write the layout so it looks better.
#

global perusedfile
set perusedfile ""

set w ".perusefile"

catch {destroy $w} 
toplevel $w
wm title $w {Peruse Block Devices}

frame $w.up
frame $w.dir
frame $w.file
frame $w.ctl

menubutton $w.up.mb -menu $w.up.mb.m -relief raised -border 2

listbox $w.dir.lb  -yscrollcommand [list $w.dir.sb set]
listbox $w.file.lb -yscrollcommand [list $w.file.sb set]

scrollbar $w.dir.sb  -orient v -command [list $w.dir.lb yview]
scrollbar $w.file.sb -orient v -command [list $w.file.lb yview]

button $w.ctl.accept -text accept -command {}
button $w.ctl.cancel -text cancel -command {}

pack $w.up -side top -fill x
pack $w.dir $w.file $w.ctl -side left -fill y
pack $w.dir.sb $w.file.sb -side right -fill y
pack $w.dir.lb $w.file.lb $w.up.mb -side left
pack $w.ctl.accept $w.ctl.cancel -side top


peruse_block_populate "/dev"         
tkwait window $w

return $perusedfile

}
proc peruse_block_populate dir {
# Here we fill in the info for the peruse window and
# configure up the bindings.

set w ".perusefile"

# Configure the menu button
set tmp [file tail $dir]
if {$tmp == ""} {set tmp /}
$w.up.mb configure -text $tmp

# Replace the menu
set m $w.up.mb.m
catch {destroy $m}
menu $m -tearoff 0

set up /
foreach dcomp [file split $dir] {
 set up [file join $up $dcomp]
 $m add command -label $dcomp -command "peruse_block_populate \"$up\""
}


### Populate the list boxes:

# empty them
$w.dir.lb delete 0 end
$w.file.lb delete 0 end

# enumerate the interesting files
set file_list [lsort [glob -nocomplain -- $dir/.* $dir/*]]

# place them in the correct box
foreach file $file_list {
  set tail [file tail $file]
  if {$tail != "." && $tail != ".."} {
    file stat $file stat
    set type $stat(type)
    
    if {$type == "directory"} {
      $w.dir.lb insert end [file tail $file]
    } elseif {$type == "blockSpecial"} {
      $w.file.lb insert end [file tail $file]
    }
  }
}

## Bindings

$w.ctl.cancel config -command {
 set perusedfile ""
 destroy .perusefile
}
$w.ctl.accept config -command [list peruse_block_accept $dir]

set go [subst -nocommands {
 if {[$w.dir.lb get active] != ""} {
  peruse_block_populate [file join "$dir" [$w.dir.lb get active]]
 } else bell
}]

bind $w.dir.lb <Double-1> $go
# .perusefile.control.go config -command $go


}
proc peruse_block_accept dir {

# If appropriate, pluck the currently selected file name from the file
# list and set it into the return global.

global perusedfile

set w ".perusefile"

set chosen [$w.file.lb get active]

if {$chosen != ""} {
  set perusedfile [file join $dir $chosen]
  destroy $w
}

}




# This is CDR-Toaster

set device "/dev/sg0"
set speed 2
set joliet 1
set rock none
set dummy 1
set eject 1
set ds mkisofs
set apad 1
set dpad 0
set bootimg ""
set bootcat ""

set custom(from) {}
set custom(to) {}
set custom(use) 0

interface

.b.quit configure -command {destroy .}
.b.burn configure -command {toast}