summaryrefslogtreecommitdiffstats
path: root/perl-install/printer.pm
blob: f780963afe0afd53f972ede19f6e85218d700b83 (plain)
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
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1
  'pl'  => [ 'Polish',			'iso-8859-2', 'pl', 'pl' ],
#-'pp'	=> [ 'Papiamento',		'iso-8859-1', 'pp', 'pp' ],
'pt_BR' => [ 'Portuguese|Brazil',	'iso-8859-1', 'pt_BR', 'pt_BR:pt_PT:pt' ],
'pt_PT' => [ 'Portuguese|Portugal', 'iso-8859-15', 'pt', 'pt_PT:pt:pt_BR' ],
  'ro'  => [ 'Romanian',  		'iso-8859-2', 'ro', 'ro' ],
'ru_RU.KOI8-R' => [ 'Russian|KOI8-R',	'koi8-r',     'ru', 'ru_RU:ru' ],
'ru_RU.CP1251' => [ 'Russian|CP1251',	'cp1251',     'ru', 'ru_RU:ru' ],
'ru_RU.UTF-8' => [ 'Russian|UTF-8',	'cp1251',   'ru', 'ru_RU:ru', 'UTF-8' ],
  'sk'  => [ 'Slovak',    		'iso-8859-2', 'sk', 'sk' ],
  'sl'  => [ 'Slovenian',		'iso-8859-2', 'sl', 'sl' ],
#-  'sp'  => [ 'Serbian|Cyrillic (ISO-8859-5)','iso-8859-5', 'sp', 'sp:sr' ],
#'sp_YU.CP1251' => [ 'Serbian|Cyrillic (CP1251)','cp1251',    'sp', 'sp:sr' ],
'sp_YU.UTF-8' => [ 'Serbian|Cyrillic', 'cp1251',   'sp', 'sp:sr', 'UTF-8' ],
  'sr'  => [ 'Serbian|Latin (ISO-8859-2)', 'iso-8859-2', 'sr', 'sr' ],
'sr_YU.UTF-8' => [ 'Serbian|Latin (UTF-8)',	'iso-8859-2',      'sr', 'sr', 'UTF-8' ],
  'sv'  => [ 'Swedish',			'iso-8859-1', 'sv', 'sv' ],
#- there is no tamil font curently; so set DrakX encoding to utf_1
#- note: most of the gnome translations for tamil are broken (using bad
#- encoding)
#-
#- Tamil currently works only with TSCII encoding; which identifies
#- itself as a fake iso-8859-1
#'ta_IN.UTF-8' => [ 'Tamil (UTF-8)',	'iso-8859-1',      'ta', 'ta', 'UTF-8' ],
'ta_IN' => [ 'Tamil (TSCII)',		'tscii',      'ta', 'ta' ],
'tg_TJ.UTF-8' => [ 'Tajik',		'utf_koi8-k',    'tg', 'tg', 'UTF-8' ],
  'th'  => [ 'Thai|TIS-620',            'tis620',     'th', 'th' ],
'th_TH.UTF-8' => [ 'Thai (UTF-8)',         'tis620',     'th', 'th', 'UTF-8' ],
  'tr'  => [ 'Turkish',	 		'iso-8859-9', 'tr', 'tr' ],
#-'tt_RU.UTF-8' => [ 'Tatar',		'koi8-k',  'tt', 'tt' ],
#-'ur'	=> [ 'Urdu',			'cp1256',     'ur', 'ur' ],  
'uk_UA' => [ 'Ukrainian|KOI8-U', 	'koi8-u',     'uk', 'uk_UA:uk' ],
'uk_UA.CP1251' => [ 'Ukrainian|CP1251',	'cp1251',     'uk', 'uk_UA:uk' ],
'uk_UA.UTF-8' => [ 'Ukrainian|UTF-8',	'cp1251',   'uk', 'uk_UA:uk', 'UTF-8' ],
  'uz'  => [ 'Uzbek',			'iso-8859-1', 'uz', 'uz' ],
#'vi_VN.TCVN'  => [ 'Vietnamese|TCVN',   'tcvn',     'vi', 'vi' ],
#'vi_VN.VISCII' => [ 'Vietnamese|VISCII','viscii',   'vi', 'vi' ],
'vi_VN.UTF-8' => [ 'Vietnamese',  'viscii',   'vi', 'vi', 'UTF-8' ],
  'wa'  => [ 'Walon',     		'iso-8859-15', 'wa', 'wa:fr_BE:fr' ],
#-'yi'	=> [ 'Yiddish',			'cp1255',     'yi', 'yi' ],
#- NOTE: 'zh' must be in the LANGUAGE list, it is not used for translations
#- themselves but is needed for our selection of locales-xx packages
#- and the language dependent packages resolution
#'zh_HK.Big5' => [ 'Chinese|Traditional|Hong Kong|Big5', 'Big5', 'zh_TW.Big5', 'zh_TW.Big5:zh_TW:zh_HK:zh' ],
#'zh_HK.UTF-8' => [ 'Chinese|Traditional|Hong Kong|UTF-8','Big5','zh_HK', 'zh_HK:zh_TW.Big5:zh_TW:zh', 'UTF-8' ],
'zh_TW.Big5'  => [ 'Chinese|Traditional|Big5',   'Big5',   'zh_TW.Big5', 'zh_TW.Big5:zh_TW:zh_HK:zh' ],
'zh_TW.UTF-8' => [ 'Chinese|Traditional|UTF-8',  'Big5', 'zh_TW',      'zh_TW.Big5:zh_TW.big5:zh_TW:zh_HK:zh', 'UTF-8' ],
'zh_CN.GB2312' => [ 'Chinese|Simplified|GB2312', 'gb2312', 'zh_CN.GB2312', 'zh_CN.GB2312:zh_CN:zh' ],
'zh_CN.UTF-8'  => [ 'Chinese|Simplified|UTF-8',  'gb2312', 'zh_CN',        'zh_CN.GB2312:zh_CN:zh', 'UTF-8' ],
#- does this one works? 
#'zh_CN.GB18030' => [ 'Chinese|Simplified|GB18030','gb2312','zh_CN', 'zh_CN.GB2312:zh_CN:zh' ],
);
@languages = map { $_->[0] } group_by2(@languages);

my %xim = (
  'zh_TW.Big5' => { 
 	ENC => 'big5',
 	XIM => 'xcin',
 	XIM_PROGRAM => 'xcin',
 	XMODIFIERS => '"@im=xcin"',
 	CONSOLE_NOT_LOCALIZED => 'yes',
  },
  'zh_TW.Big5@chinput' => {
	ENC => 'big5',
	XIM => 'Chinput',
	XIM_PROGRAM => 'chinput',
	XMODIFIERS => '"@im=Chinput"',
	CONSOLE_NOT_LOCALIZED => 'yes',
  },
  'zh_TW.UTF-8' => {
	ENC => 'utf8',
	XIM => 'Chinput',
	XIM_PROGRAM => 'chinput',
	XMODIFIERS => '"@im=Chinput"',
	CONSOLE_NOT_LOCALIZED => 'yes',
  },
  'zh_CN.GB2312' => {
	ENC => 'gb',
	XIM => 'Chinput',
	XIM_PROGRAM => 'chinput',
	XMODIFIERS => '"@im=Chinput"',
	CONSOLE_NOT_LOCALIZED => 'yes',
  },
  'zh_CN.UTF-8' => {
	ENC => 'utf8',
	XIM => 'Chinput',
	XIM_PROGRAM => 'chinput',
	XMODIFIERS => '"@im=Chinput"',
	CONSOLE_NOT_LOCALIZED => 'yes',
  },
  'ko' => {
	ENC => 'kr',
	XIM => 'Ami',
	#- NOTE: there are several possible versions of ami, for the different
	#- desktops (kde, gnome, etc). So XIM_PROGRAM isn't defined; it will
	#- be the xinitrc script, XIM section, that will choose the right one 
	#- XIM_PROGRAM => 'ami',
	XMODIFIERS => '"@im=Ami"',
	CONSOLE_NOT_LOCALIZED => 'yes',
  },
  'ko_KR.UTF-8' => {
	ENC => 'utf8',
	XIM => 'Ami',
	#- NOTE: there are several possible versions of ami, for the different
	#- desktops (kde, gnome, etc). So XIM_PROGRAM isn't defined; it will
	#- be the xinitrc script, XIM section, that will choose the right one 
	#- XIM_PROGRAM => 'ami',
	XMODIFIERS => '"@im=Ami"',
	CONSOLE_NOT_LOCALIZED => 'yes',
  },
  'ja' => {
	ENC => 'eucj',
	XIM => 'kinput2',
	XIM_PROGRAM => 'kinput2',
	XMODIFIERS => '"@im=kinput2"',
  },
  'ja_JP.UTF-8' => {
	ENC => 'utf8',
	XIM => 'kinput2',
	XIM_PROGRAM => 'kinput2',
	XMODIFIERS => '"@im=kinput2"',
  },
  #- XFree86 has an internal XIM for Thai that enables syntax checking etc.
  #- 'Passthroug' is no check at all, 'BasicCheck' accepts bad sequences
  #- and convert them to right ones, 'Strict' refuses bad sequences
  'th' => {
	XIM_PROGRAM => '/bin/true', #- it's an internal module
	XMODIFIERS => '"@im=BasicCheck"',
  },
  #- xvnkb is not an XIM input method; but an input method of another
  #- kind, only XIM_PROGRAM needs to be defined
  #- ! xvnkb doesn't work in UTF-8 !
#-  'vi_VN.VISCII' => {
#-	XIM_PROGRAM => 'xvnkb',
#-  },
);

sub std2 { "-*-*-medium-r-normal-*-$_[1]-*-*-*-*-*-$_[0]" }
sub std_ { std2($_[0], 10), std2($_[0], 10) }
sub std  { std2($_[0], $_[1] || 10), std2($_[0],  8) }

#- [0]: console font name
#- [1]: sfm map for console font (if needed)
#- [2]: acm file for console font (none if utf8)
#- [3]: iocharset param for mount (utf8 if utf8)
#- [4]: codepage parameter for mount (none if utf8)
#- [5]: X11 fontset (for DrakX)
my %charsets = (
  "armscii-8"  => [ "arm8",		undef,	"armscii-8",
	 undef,	undef, std_("armscii-8") ],
#- chinese needs special console driver for text mode
  "Big5"       => [ undef,		undef,		undef,
	"big5", "950", "-*-*-*-*-*-*-*-*-*-*-*-*-big5-0" ],
  "gb2312"     => [ undef,		undef,		undef,
	"gb2312", "936", "-*-*-*-*-*-*-*-*-*-*-*-*-gb2312.1980-0" ],
  "C" => [ "lat1-16",	undef,		"iso15",
	"iso8859-1", "850", sub { std("iso8859-1", @_) } ],
  "iso-8859-1" => [ "lat1-16",	undef,		"iso1",
	"iso8859-1", "850", sub { std("iso8859-15", @_) } ],
  "iso-8859-2" => [ "lat2-sun16",	undef,		"iso02",
	"iso8859-2", "852", sub { std("iso8859-2", @_) } ],
  "iso-8859-3" => [ "iso03.f16",	undef,		"iso03",
	"iso8859-3", undef, std_("iso8859-3") ],
#-  "iso-8859-4" => [ "lat4u-16",		undef,		"iso04",
#-	"iso8859-4", "775", std_("iso8859-4") ],
#-  "iso-8859-5" => [ "UniCyr_8x16",	undef,	"iso05",
#-  	"iso8859-5", "855", sub { std("microsoft-cp1251", @_) } ],
#-#- arabic needs special console driver for text mode [acon]
#-#- (and gtk support isn't done yet)
  "iso-8859-6" => [ "iso06.f16",	undef,	"iso06",
	"iso8859-6", "864", std_("iso8859-6") ],
  "iso-8859-7" => [ "iso07.f16",	undef,	"iso07",
	"iso8859-7", "869", std_("iso8859-7") ],
#-#- hebrew needs special console driver for text mode [acon]
#-#- (and gtk support isn't done yet)
   "iso-8859-8" => [ "iso08.f16",	undef,	"iso08",
#-	std_("iso8859-8") ],
	"iso8859-8", "862", std_("microsoft-cp1255") ],
  "iso-8859-9" => [ "lat5u-16",	undef,	"iso09",
	"iso8859-9", "857", sub { std("iso8859-9", @_) } ],
  "iso-8859-13" => [ "tlat7",		undef,	"iso13",
	"iso8859-13", "775", std_("iso8859-13") ],
  "iso-8859-14" => [ "iso14.f16",	undef,		"iso14",
	"iso8859-14", "850", std_("iso8859-14") ],
  "iso-8859-15" => [ "lat0-16",	undef,		"iso15",
	"iso8859-15", "850", sub { std("iso8859-15", @_) } ],
  "iso-8859-9e"      => [ "tiso09e",		undef,	"iso09e",
	undef, undef, std2("iso8859-9e",10) ],
#- japanese needs special console driver for text mode [kon2]
  "jisx0208"   => [ undef,		undef,		"trivial.trans",
	"euc-jp", "932", "-*-*-*-*-*-*-*-*-*-*-*-*-jisx*.*-0" ],
  "koi8-r"     => [ "UniCyr_8x16",	undef,		"koi8-r",
	"koi8-r", "866", sub { std("microsoft-cp1251", @_) } ],
  "koi8-u"     => [ "UniCyr_8x16",	undef,		"koi8-u",
	"koi8-u", "866", sub { std("microsoft-cp1251", @_) } ],
  "utf_ka"      => [ "t_geors",		undef,	undef,
	"utf8",  undef, "-*-*-*-*-*-*-*-*-*-*-*-*-georgian-academy" ],
  "utf_koi8-k"     => [ "koi8-k",		undef,	undef,
	"utf8", undef, std("koi8-k") ],
  "cp1251"     => [ "UniCyr_8x16",	undef,		"cp1251",
	"cp1251", "866", sub { std("microsoft-cp1251", @_) } ],
#- Yiddish needs special console driver for text mode [acon]
#- (and gtk support isn't done yet)
#-  "cp1255"     => [ "iso08.f16",        "iso08",        "trivial.trans",
#-	"cp1255", "862", std_("microsoft-cp1255") ],
#- Urdu needs special console driver for text mode [acon]
#- (and gtk support isn't done yet)
#-  "cp1256"     => [ undef,              undef,          "trivial.trans",
#-	undef, "864", std_("microsoft-cp1255") ],
#- korean needs special console driver for text mode
  "ksc5601"    => [ undef,		undef,		undef,
	"euc-kr", "949", "-*-*-*-*-*-*-*-*-*-*-*-*-ksc5601.1987-*" ],
#- I have no console font for Thai...
  "tis620"     => [ undef,		undef,		"trivial.trans",
	"tis-620", "874", std2("tis620.2533-1",12) ],
#-  "tcvn"       => [ "tcvn8x16",		undef,		"tcvn",
#-	undef, undef, std2("tcvn-5712", 13), std2("tcvn-5712", 10) ],
  "viscii"     => [ "tcvn8x16",	undef,	"viscii",
	undef, undef, std2("tcvn-5712", 13), std2("tcvn-5712", 10) ],
#- Tamil uses pseudo iso-8859-1 fonts
  "tscii" => [ "tamil",		undef,		"tscii-0",
	undef, undef, "-tamil-tscakaram-medium-r-normal--12-120-75-75-p-92-tscii-0" ],
  "unicode" => [ undef,			undef,		undef,
	"utf8", undef, "-*-*-*-*-*-*-*-*-*-*-*-*-iso10646-1" ],
);

my %bigfonts = (
    Big5     => 'taipei16.pcf.gz',
    gb2312   => 'gb16fs.pcf.gz',
    jisx0208 => 'k14.pcf.gz',
    ksc5601  => 'baekmuk_gulim_h_14.pcf.gz',
    unicode  => 'cu12.pcf.gz',
);

#- for special cases not handled magically
my %charset2kde_charset = (
    gb2312 => 'gb2312.1980-0',
    jisx0208 => 'jisx0208.1983-0',
    ksc5601 => 'ksc5601.1987-0',
    Big5 => 'big5-0',
    cp1251 => 'microsoft-cp1251',
    utf8 => 'iso10646-1',
    tis620 => 'tis620-0',
    #- TSCII works using a pseudo iso-8859-1 encoding
    tscii => 'iso8859-1',
);

#- for special cases not handled magically
my %lang2country = (
  ar => 'eg',
  be => 'by',
  bs => 'bh',
  cs => 'cz',
  da => 'dk',
  el => 'gr',
  et => 'ee',
  ko => 'kr',
  mi => 'nz',
  ms => 'my',
  nn => 'no',
  sl => 'si',
  sp => 'sr',
  sv => 'se',
  ta => 'in',
);


my @during_install__lang_having_their_LC_CTYPE = qw(ja ko th vi);

#-######################################################################################
#- Functions
#-######################################################################################

sub list { 
    my (%options) = @_;
    my @l = @languages;
    if ($options{exclude_non_necessary_utf8}) {
	my %LANGs_non_utf8 = map { lang2LANG($_) => 1 } grep { !/UTF-8/ } @languages;
	@l = grep { !/UTF-8/ || !$LANGs_non_utf8{lang2LANG($_)} } @l;
    }
    if ($options{exclude_non_installed_langs}) {
	@l = grep { -e "/usr/share/locale/" . lang2LANG($_) . "/LC_CTYPE" } @l;
    }
    @l;
}
sub lang2text     { exists $languages{$_[0]} && $languages{$_[0]}[0] }
sub lang2charset  { exists $languages{$_[0]} && $languages{$_[0]}[1] }
sub lang2LANG     { exists $languages{$_[0]} && $languages{$_[0]}[2] }
sub lang2LANGUAGE { exists $languages{$_[0]} && $languages{$_[0]}[3] }
sub lang2UTF8     { exists $languages{$_[0]} && $languages{$_[0]}[4] }
sub getxim { $xim{$_[0]} }

sub lang2console_font {
    my ($lang) = @_;
    my $c = $charsets{lang2charset($lang) || return} or return;
    my ($name, $sfm, $acm) = @$c;
    undef $acm if lang2UTF8($lang);
    ($name, $sfm, $acm);
}

sub lang2country {
    my ($lang, $prefix) = @_;

    my $dir = "$prefix/usr/share/locale/l10n";
    my @countries = grep { -d "$dir/$_" } all($dir);
    my %countries; @countries{@countries} = ();

    my $valid_country = sub {
	my ($country) = @_;
	#- fast & dirty solution to ensure bad entries do not happen
	exists $countries{$country} && $country;
    };

    my $country;
    if ($country ||= $lang2country{$lang}) {
	return $valid_country->($country) ? $country : 'C';
    }
    $country ||= $valid_country->(lc($1)) if $lang =~ /([A-Z]+)/;
    $country ||= $valid_country->(lc($1)) if lang2LANGUAGE($lang) =~ /([A-Z]+)/;
    $country ||= $valid_country->(substr($lang, 0, 2));
    $country ||= first(grep { $valid_country->($_) } map { substr($_, 0, 2) } split(':', lang2LANGUAGE($lang)));
    $country || 'C';
}


sub country2lang {
    my ($country, $default) = @_;

    my $uc_country = uc $country;
    my %country2lang = reverse %lang2country;
    
    my ($lang1, $lang2);
    $lang1 ||= $country2lang{$country};
    $lang1 ||= first(grep { /^$country/    } list());
    $lang1 ||= first(grep { /_$uc_country/ } list());
    $lang2 ||= first(grep { int grep { /^$country/    } split(':', lang2LANGUAGE($_)) } list());
    $lang2 ||= first(grep { int grep { /_$uc_country/ } split(':', lang2LANGUAGE($_)) } list());
    ($lang1 =~ /UTF-8/ && $lang2 !~ /UTF-8/ ? $lang2 || $lang1 : $lang1 || $lang2) || $default || 'en_US';
}

sub lang2kde_lang {
    my ($lang, $default) = @_;

    #- get it using 
    #- echo C $(rpm -qp --qf "%{name}\n" /RPMS/kde-i18n-*  | sed 's/kde-i18n-//')
    my @valid_kde_langs = qw(C af az bg ca cs da de el en_GB eo es et fi fr he hu is it ja ko lt lv mt nl no no_NY pl pt pt_BR ro ru sl sk sr sv ta th tr uk xh zh_CN.GB2312 zh_TW.Big5);
    my %valid_kde_langs; @valid_kde_langs{@valid_kde_langs} = ();

    my $valid_lang = sub {
	my ($lang) = @_;
	#- fast & dirty solution to ensure bad entries do not happen
	$lang eq 'en' ? 'C' :
	  exists $valid_kde_langs{$lang} ? $lang :
	  exists $valid_kde_langs{substr($lang, 0, 2)} ? substr($lang, 0, 2) : '';
    };

    my $r;
    $r ||= $valid_lang->(lang2LANG($lang));
    $r ||= first(grep { $valid_lang->($_) } split(':', lang2LANGUAGE($lang)));
    $r || $default || 'C';
}

sub kde_lang2lang {
    my ($klang, $default) = @_;
    first(grep { /^$klang/ } list()) || $default || 'en_US';
}

sub kde_lang_country2lang {
    my ($klang, $country, $default) = @_;
    my $uc_country = uc $country;
    #- country is used to precise the lang
    my @choices = grep { /^$klang/ } list();
    my @sorted = 
      @choices == 2 && length $choices[0] !~ /[._]/ && $choices[1] =~ /UTF-8/ ? @choices :
      map { $_->[0] } sort { $b->[1] <=> $a->[1] } map { [ $_ => /_$uc_country/ ] } @choices;
    
    $sorted[0] || $default || 'en_US';
}

sub charset2kde_charset {
    my ($charset, $default) = @_;
    my $iocharset = ($charsets{$charset} || [])->[3];

    my @valid_kde_charsets = qw(big5-0 gb2312.1980-0 iso10646-1 iso8859-1 iso8859-4 iso8859-6 iso8859-8 iso8859-13 iso8859-14 iso8859-15 iso8859-2 iso8859-3 iso8859-5 iso8859-7 iso8859-9 koi8-r koi8-u ksc5601.1987-0 jisx0208.1983-0 microsoft-cp1251 tis620-0);
    my %valid_kde_charsets; @valid_kde_charsets{@valid_kde_charsets} = ();

    my $valid_charset = sub {
	my ($charset) = @_;
	#- fast & dirty solution to ensure bad entries do not happen
	exists $valid_kde_charsets{$charset} && $charset;
    };

    my $r;
    $r ||= $valid_charset->($charset2kde_charset{$charset});
    $r ||= $valid_charset->($charset2kde_charset{$iocharset});
    $r ||= $valid_charset->($iocharset);
    $r || $default || 'iso10646-1';
}

#- font+size for different charsets; the field [0] is the default,
#- others are overrridens for fixed(1), toolbar(2), menu(3) and taskbar(4)
my %charset2kde_font = (
  'C' => [ "adobe-helvetica,12", "courier,10", "adobe-helvetica,11" ],
  'iso-8859-1'  => [ "adobe-helvetica,12", "courier,10", "adobe-helvetica,11" ],
  'iso-8859-2'  => [ "adobe-helvetica,12", "courier,10", "adobe-helvetica,11" ],
  'iso-8859-9'  => [ "adobe-helvetica,12", "courier,10", "adobe-helvetica,11" ],
  'iso-8859-15' => [ "adobe-helvetica,12", "courier,10", "adobe-helvetica,11" ],
  'jisx0208' => [ "misc-fixed,14", "wadalab-gothic,13" ],
  'ksc5601' => [ "daewoo-gothic,16" ],
  'gb2312' => [ "default-ming,16" ],
  'Big5' => [ "taipei-fixed,16" ],
  'tis620' => [ "misc-norasi,17", ],
  'viscii' => [ "misc-fixed,13", "misc-fixed,13", "misc-fixed,10", ],
  #- TSCII uses pseudo iso-8859-1 fonts, it is important to choose them
  #- correctly
  'tscii' => [ "tsc_avarangal,14", "tsc_avarangalfxd,10", "tsc_avarangal,12", ],
  #- the following should be changed to better defaults when better fonts
  #- get available
  'armscii-8' => [ "clearlyu,17" ],
  'utf_ka' => [ "clearlyu,17" ],
  'default' => [ "misc-fixed,13", "misc-fixed,13", "misc-fixed,10", ],
);

sub charset2kde_font {
    my ($charset, $type) = @_;
    my $kdecharset = charset2kde_charset($charset);
    
    my $font = $charset2kde_font{$charset} || $charset2kde_font{default};
    my $r = $font->[$type] || $font->[0];

    #- the format is "font-name,size,5,kdecharset,0,0" I have no idea of the
    #- meaning of that "5"...
    "$r,5,$kdecharset,0,0";
}

sub set { 
    my ($lang, $translate_for_console) = @_;

    if ($lang && !exists $languages{$lang}) {
	#- try to find the best lang
	my ($lang2) = grep { /^\Q$lang/ } list(); #- $lang is not precise enough, choose the first complete
	my ($lang3) = grep { $lang =~ /^\Q$_/ } list(); #- $lang is too precise, choose the first substring matching
	log::l("lang::set: fixing $lang with ", $lang2 || $lang3);
	$lang = $lang2 || $lang3;
    }

    if ($lang && exists $languages{$lang}) {
	my ($dir, $LANG) = ("$ENV{SHARE_PATH}/locale", lang2LANG($lang));
	if (! -e "$dir/$LANG" && common::usingRamdisk()) {
	    @ENV{qw(LANG LC_ALL LANGUAGE LINGUAS)} = ();

	    my @LCs = qw(LC_ADDRESS LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME);

	    my $charset = during_install__lang2charset($lang) || $LANG;

	    #- there are 3 main charsets containing everything for all locales, except LC_CTYPE
	    #- by default, there is UTF-8.
	    #- when asked for GB2312 or BIG5, removing the other main charsets
	    my $main_charset = member($charset, 'GB2312', 'BIG5') ? $charset : 'UTF-8';

	    #- removing everything
	    #- except in main charset: only removing LC_CTYPE if it is there
	    eval { rm_rf($_ eq $main_charset ? "$dir/$_/LC_CTYPE" : "$dir/$_") } foreach all($dir);

	    if (! -e "$dir/$main_charset") {
		#- getting the main charset
		mkdir "$dir/$main_charset";
		mkdir "$dir/$main_charset/LC_MESSAGES";
		install_any::getAndSaveFile("$dir/$main_charset/$_") foreach @LCs, 'LC_MESSAGES/SYS_LC_MESSAGES';
	    }
	    mkdir "$dir/$LANG";

	    #- linking to the main charset
	    symlink "../$main_charset/$_", "$dir/$LANG/$_" foreach @LCs, 'LC_MESSAGES';	    

	    #- getting LC_CTYPE (putting it directly in $LANG)
	    install_any::getAndSaveFile ("Mandrake/mdkinst$dir/$charset/LC_CTYPE", "$dir/$LANG/LC_CTYPE");
	}

#- set all LC_* variables to a unique locale ("C"), and only redefine
#- LC_CTYPE (for X11 choosing the fontset) and LANGUAGE (for the po files)
	$ENV{$_} = 'C' foreach qw(LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT LC_IDENTIFICATION);

#- use lang2LANG() to define LC_CTYPE, so DrakX will use a same encoding
#- for all variations of a same language, eg both 'ru_RU.KOI8-R' and
#- 'ru_RU.UTF-8' will be handled the same (as 'ru') by DrakX.
#- that way DrakX only needs a reduced set of locale and fonts support.
#- of course on the installed system they will be different.
	$ENV{LC_CTYPE}  = lang2LANG($lang);
	$ENV{LC_MESSAGES} = lang2LANG($lang);
	$ENV{LANG}      = lang2LANG($lang);

	if ($translate_for_console && $lang =~ /^(ko|ja|zh|th)/) {
	    log::l("not translating in console");
	    $ENV{LANGUAGE}  = 'C';
	} else {
	    $ENV{LANGUAGE}  = lang2LANGUAGE($lang);
	}
	load_mo();
    } else {
	#- stick with the default (English) */
	delete $ENV{LANG};
	delete $ENV{LC_ALL};
	delete $ENV{LANGUAGE};
	delete $ENV{LINGUAS};
    }
    $lang;
}

sub langs {
    my ($l) = @_;
    grep { $l->{$_} } keys %$l;
}

sub langsLANGUAGE {
    my ($l) = @_;
    my @l = $l->{all} ? list() : langs($l);
    uniq(map { split ':', lang2LANGUAGE($_) } @l);
}

sub pack_langs { 
    my ($l) = @_; 
    my $s = $l->{all} ? 'all' : join ':', uniq(map { lang2LANGUAGE($_) } langs($l));
    $ENV{RPM_INSTALL_LANG} = $s;
    $s;
}

sub unpack_langs {
    my ($s) = @_;
    my @l = uniq(map { split ':', lang2LANGUAGE($_) } split(':', $s));
    my @l2 = intersection(\@l, [ keys %languages ]);
    +{ map { $_ => 1 } @l2 };
}

sub read {
    my ($prefix, $user_only) = @_;
    my ($f1, $f2) = ("$prefix$ENV{HOME}/.i18n", "$prefix/etc/sysconfig/i18n");
    my %h = getVarsFromSh($user_only && -e $f1 ? $f1 : $f2);
    my $lang = $h{LC_MESSAGES} || 'en_US';
    $lang = bestMatchSentence($lang, list()) if !exists $languages{$lang};
    my $langs = $user_only ? () :
      cat_("$prefix/etc/rpm/macros") =~ /%_install_langs (.*)/ ? unpack_langs($1) : { $lang => 1 };
    $lang, $langs;
}

sub write_langs {
    my ($prefix, $langs) = @_;
    my $s = pack_langs($langs);
    symlink "$prefix/etc/rpm", "/etc/rpm" if $prefix;
    substInFile { s/%_install_langs.*//; $_ .= "%_install_langs $s\n" if eof && $s } "$prefix/etc/rpm/macros";
}

sub write { 
    my ($prefix, $lang, $user_only, $dont_touch_kde_files) = @_;

    $lang or return;

    my $h = {
	XKB_IN_USE => '',
	(map { $_ => $lang } qw(LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LC_MONETARY LC_TIME)),
    };
    if ($lang && exists $languages{$lang}) {
##- note: KDE is unable to use the keyboard if LC_* and LANG values differ...
#-	add2hash $h, { LANG => lang2LANG($lang), LANGUAGE => lang2LANGUAGE($lang) };
	add2hash $h, { LANG => $lang, LANGUAGE => lang2LANGUAGE($lang) };

	my ($name, $sfm, $acm) = lang2console_font($lang);
	if ($name && !$user_only) {
	    my $p = "$prefix/usr/lib/kbd";
	    if ($name) {
		eval {
		    cp_af("$p/consolefonts/$name.psf.gz", "$prefix/etc/sysconfig/console/consolefonts");
		    add2hash $h, { SYSFONT => $name };
		};
		$@ and log::l("missing console font $name");
	    }
	    if ($sfm) {
		eval {
		    cp_af(glob_("$p/consoletrans/$sfm*"), "$prefix/etc/sysconfig/console/consoletrans");
		    add2hash $h, { UNIMAP => $sfm };
		};
		$@ and log::l("missing console unimap file $sfm");
	    }
	    if ($acm) {
		eval {
		    cp_af(glob_("$p/consoletrans/$acm*"), "$prefix/etc/sysconfig/console/consoletrans");
		    add2hash $h, { SYSFONTACM => $acm };
		};
		$@ and log::l("missing console acm file $acm");
	    }

	}
	add2hash $h, $xim{$lang};
    }
    setVarsInSh($prefix . ($user_only ? "$ENV{HOME}/.i18n" : '/etc/sysconfig/i18n'), $h);

    eval {
	my $charset = lang2charset($lang);
	my $confdir = $prefix . ($user_only ? "$ENV{HOME}/.kde" : '/usr') . '/share/config';
	my ($prev_kde_charset) = cat_("$confdir/kdeglobals") =~ /^Charset=(.*)/mi;

	mkdir_p($confdir);

	update_gnomekderc("$confdir/kdeglobals", Locale => (
			      Charset => charset2kde_charset($charset),
			      Country => lang2country($lang, $prefix),
			      Language => lang2kde_lang($lang),
			  ));

        if ($prev_kde_charset ne charset2kde_charset($charset)) {
	    update_gnomekderc("$confdir/kdeglobals", WM => (
	    		      activeFont => charset2kde_font($charset,0),
	    		  ));
	    update_gnomekderc("$confdir/kdeglobals", General => (
	    		      fixed => charset2kde_font($charset, 1),
	    		      font => charset2kde_font($charset, 0),
	    		      menuFont => charset2kde_font($charset, 3),
	    		      taskbarFont => charset2kde_font($charset, 4),
	    		      toolBarFont => charset2kde_font($charset, 2),
	    	          ));
	    update_gnomekderc("$confdir/konquerorrc", FMSettings => (
	    		      StandardFont => charset2kde_font($charset, 0),
	    		  ));
	    update_gnomekderc("$confdir/kdesktoprc", FMSettings => (
	    		      StandardFont => charset2kde_font($charset, 0),
	    		  ));
	}
    } if !$dont_touch_kde_files;
}

sub bindtextdomain() {
    my $localedir = "$ENV{SHARE_PATH}/locale";
    $localedir .= "_special" if $::isInstall;

    c::setlocale();
    c::bindtextdomain('libDrakX', $localedir);

    $localedir;
}

sub load_mo {
    my ($lang) = @_;

    my $localedir = bindtextdomain();
    my $suffix = 'LC_MESSAGES/libDrakX.mo';

    $lang ||= $ENV{LANGUAGE} || $ENV{LC_ALL} || $ENV{LC_MESSAGES} || $ENV{LANG};

    foreach (split ':', $lang) {
	my $f = "$localedir/$_/$suffix";
	-s $f and return $_;

	if ($::isInstall && common::usingRamdisk()) {
	    #- cleanup
	    eval { rm_rf($localedir) };
	    eval { mkdir_p(dirname("$localedir/$_/$suffix")) };
	    install_any::getAndSaveFile("$localedir/$_/$suffix");

	    -s $f and return $_;
	}
    }
    '';
}


#- used in Makefile during "make get_needed_files"
sub console_font_files {
    map { -e $_ ? $_ : "$_.gz" }
      (map { "/usr/lib/kbd/consolefonts/$_.psf" } uniq grep { $_ } map { $_->[0] } values %charsets),
      (map { -e $_ ? $_ : "$_.sfm" } map { "/usr/lib/kbd/consoletrans/$_" } uniq grep { $_ } map { $_->[1] } values %charsets),
      (map { -e $_ ? $_ : "$_.acm" } map { "/usr/lib/kbd/consoletrans/$_" } uniq grep { $_ } map { $_->[2] } values %charsets),
}

sub load_console_font {
    my ($lang) = @_;
    my ($name, $sfm, $acm) = lang2console_font($lang);

    require run_program;
    run_program::run(if_($ENV{LD_LOADER}, $ENV{LD_LOADER}), 
		     'consolechars', '-v', '-f', $name || 'lat0-sun16',
		     if_($sfm, '-u', $sfm), if_($acm, '-m', $acm));
}

sub get_x_fontset {
    my ($lang, $size) = @_;

    my $charset = lang2charset($lang) or return;
    my $c = $charsets{$charset} or return;
    if (my $f = $bigfonts{$charset}) {
	my $dir = "/usr/X11R6/lib/X11/fonts";
	if (! -e "$dir/$f" && $::isInstall && common::usingRamdisk()) {
	    unlink "$dir/$_" foreach values %bigfonts;
	    install_any::remove_bigseldom_used ();
	    install_any::getAndSaveFile("$dir/$f");
	}
    }
    my ($big, $small) = @$c[5..6];
    ($big, $small) = $big->($size) if ref $big;
    ($big, $small);
}

sub fs_options {
    my ($lang) = @_;
    if (lang2UTF8($lang)) {
	('utf8', undef);
    } else {
	my $c = $charsets{lang2charset($lang) || return} or return;
	my ($iocharset, $codepage) = @$c[3..4];
	$iocharset, $codepage;
    }
}

sub charset {
    my ($lang, $prefix) = @_;
    my $l = lang2LANG($lang);
    foreach (cat_("$prefix/usr/X11R6/lib/X11/locale/locale.alias")) {
	/$l:\s+.*\.(\S+)/ and return $1;
    }
    $l =~ /.*\.(\S+)/ and return $1;
}

sub during_install__lang2charset {
    my ($lang) = @_;
    return if member(lang2LANG($lang), @during_install__lang_having_their_LC_CTYPE);

    my ($c) = lang2charset($lang) or die "bad lang $lang\n";
    $c = 'cp1251' if $c =~ /koi8-/;
    $c = 'iso-8859-15' if member($c, 'iso-8859-1', 'C');
    $c = 'UTF-8' if member($c, 'unicode', 'utf_ka');
    $c = 'UTF-8' if member($c, 'armscii-8', 'iso-8859-9e', 'iso-8859-8', 'iso-8859-6'); #- BAD, need fixing
    uc($c);
}

sub check {
    $^W = 0;
    my $ok = 1;
    my $warn = sub {
	print STDERR "$_[0]\n";
    };
    my $err = sub {
	&$warn;
	$ok = 0;
    };
    
    my @wanted_charsets = uniq map { lang2charset($_) } list();
    $err->("invalid charset $_ ($_ does not exist in \%charsets)") foreach difference2(\@wanted_charsets, [ keys %charsets ]);
    $err->("invalid charset $_ in \%charset2kde_font ($_ does not exist in \%charsets)") foreach difference2([ keys %charset2kde_font ], [ 'default', keys %charsets ]);
    $warn->("unused charset $_ (given in \%charsets, but not used in \%languages)") foreach difference2([ keys %charsets ], \@wanted_charsets);

    $warn->("unused entry $_ in \%xim") foreach difference2([ keys %xim ], [ list() ]);

    #- consolefonts are checked during build via console_font_files()

    if (my @l = difference2([ 'default', keys %charsets ], [ keys %charset2kde_font ])) {
	$warn->("no kde font for charset " . join(" ", @l));
    }

    if (my @l = grep { lang2country($_) eq 'C' } list()) {
	$warn->("no country for langs " . join(" ", @l));
    }
    if (my @l = grep { lang2kde_lang($_, 'err') eq 'err' } list()) {
	$warn->("no KDE lang for langs " . join(" ", @l));
    }
    if (my @l = grep { charset2kde_charset($_, 'err') eq 'err' } keys %charsets) {
	$warn->("no KDE charset for charsets " . join(" ", @l));
    }
    exit($ok ? 0 : 1);
}

1;
ss="hl str">]{type} = 'int'; # } else { # $args[$i]{type} = 'float'; # } # $innumerical = 1; } } } else { if ($line =~ /^\s*([^\s:][^:]*):\s+-o\s+([^\s=]+)=<choice>\s*$/) { # if ($line =~ /^\s*([^\s:][^:]*):\s+-o\s+([^\s=]+)=<.*>\s*$/) { $inoption = 1; push(@args, {}); $i = $#args; $args[$i]{comment} = $1; $args[$i]{name} = $2; $args[$i]{type} = 'enum'; @{$args[$i]{vals}} = (); } } } close F; # Return the arguments field return \@args; } #------------------------------------------------------------------------------ sub read_cups_printer_list { my ($printer) = $_[0]; # This function reads in a list of all printers which the local CUPS # daemon currently knows, including remote ones. local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "lpstat -v |" || return (); my @printerlist; my $line; while ($line = <F>) { if ($line =~ m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) { my $queuename = $1; my $comment = ""; if (($2 =~ m!^ipp://([^/:]+)[:/]!) && (!$printer->{configured}{$queuename})) { $comment = _("(on %s)", $1); } else { $comment = _("(on this machine)"); } push (@printerlist, "$queuename $comment"); } } close F; return @printerlist; } sub get_cups_remote_queues { my ($printer) = $_[0]; # This function reads in a list of all remote printers which the local # CUPS daemon knows due to broadcasting of remote servers or # "BrowsePoll" entries in the local /etc/cups/cupsd.conf/ local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "lpstat -v |" || return (); my @printerlist; my $line; while ($line = <F>) { if ($line =~ m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) { my $queuename = $1; my $comment = ""; if (($2 =~ m!^ipp://([^/:]+)[:/]!) && (!$printer->{configured}{$queuename})) { $comment = _("On CUPS server \"%s\"", $1); my $sep = "!"; push (@printerlist, ($::expert ? _("CUPS") . $sep : "") . _("Remote Printers") . "$sep$queuename: $comment" . ($queuename eq $printer->{DEFAULT} ? _(" (Default)") : (""))); } } } close F; return @printerlist; } sub set_cups_autoconf { my $autoconf = $_[0]; # Read config file local *F; my $file = "$prefix/etc/sysconfig/printing"; if (!(-f $file)) { @file_content = (); } else { open F, "< $file" or die "Cannot open $file!"; @file_content = <F>; close F; } # Remove all valid "CUPS_CONFIG" lines (/^\s*CUPS_CONFIG/ and $_ = "") foreach @file_content; # Insert the new "Printcap" line if ($autoconf) { push @file_content, "CUPS_CONFIG=automatic\n"; } else { push @file_content, "CUPS_CONFIG=manual\n"; } # Write back modified file open F, "> $file" or die "Cannot open $file!"; print F @file_content; close F; # Restart CUPS restart_service("cups"); return 1; } sub get_cups_autoconf { local *F; open F, ("< $prefix/etc/sysconfig/printing") || return 1; my $line; while ($line = <F>) { if ($line =~ m!^[^\#]*CUPS_CONFIG=manual!) { return 0; } } return 1; } sub set_default_printer { my ($printer) = $_[0]; run_program::rooted($prefix, "foomatic-configure", "-D", "-q", "-s", $printer->{SPOOLER}, "-n", $printer->{DEFAULT}) || return 0; return 1; } sub get_default_printer { my $printer = $_[0]; local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "foomatic-configure -Q -q -s $printer->{SPOOLER} |" || return undef; my $line; while ($line = <F>) { if ($line =~ m!^\s*<defaultqueue>(.*)</defaultqueue>\s*$!) { return $1; } } return undef; } sub read_cupsd_conf { my @cupsd_conf; local *F; open F, "$prefix/etc/cups/cupsd.conf"; @cupsd_conf = <F>; close F; @cupsd_conf; } sub write_cupsd_conf { my (@cupsd_conf) = @_; local *F; open F, ">$prefix/etc/cups/cupsd.conf"; print F @cupsd_conf; close F; #- restart cups after updating configuration. restart_service("cups"); } sub read_printers_conf { my ($printer) = @_; my $current; #- read /etc/cups/printers.conf file. #- according to this code, we are now using the following keys for each queues. #- DeviceURI > lpd://printer6/lp #- Info > Info Text #- Location > Location Text #- State > Idle|Stopped #- Accepting > Yes|No local *PRINTERS; open PRINTERS, "$prefix/etc/cups/printers.conf" or return; local $_; while (<PRINTERS>) { chomp; /^\s*#/ and next; if (/^\s*<(?:DefaultPrinter|Printer)\s+([^>]*)>/) { $current = { mode => 'cups', QUEUE => $1, } } elsif (/\s*<\/Printer>/) { $current->{QUEUE} && $current->{DeviceURI} or next; #- minimal check of synthax. add2hash($printer->{configured}{$current->{QUEUE}} ||= {}, $current); $current = undef } elsif (/\s*(\S*)\s+(.*)/) { $current->{$1} = $2 } } close PRINTERS; #- assume this printing system. $printer->{SPOOLER} ||= 'cups'; } sub get_direct_uri { #- get the local printer to access via a Device URI. my @direct_uri; local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/sbin/lpinfo -v |"; local $_; while (<F>) { /^(direct|usb|serial)\s+(\S*)/ and push @direct_uri, $2; } close F; @direct_uri; } sub get_descr_from_ppd { my ($printer) = @_; my %ppd; #- if there is no ppd, this means this is a raw queue. local *F; open F, "$prefix/etc/cups/ppd/$printer->{OLD_QUEUE}.ppd" or return "|" . _("Unknown model"); # "OTHERS|Generic PostScript printer|PostScript (en)"; local $_; while (<F>) { /^\*([^\s:]*)\s*:\s*\"([^\"]*)\"/ and do { $ppd{$1} = $2; next }; /^\*([^\s:]*)\s*:\s*([^\s\"]*)/ and do { $ppd{$1} = $2; next }; } close F; my $descr = ($ppd{NickName} || $ppd{ShortNickName} || $ppd{ModelName}); # Apply the beautifying rules of poll_ppd_base if ($descr =~ /Foomatic \+ Postscript/) { $descr =~ s/Foomatic \+ Postscript/PostScript/; } elsif ($descr =~ /Foomatic/) { $descr =~ s/Foomatic/GhostScript/; } elsif ($descr =~ /CUPS\+GIMP-print/) { $descr =~ s/CUPS\+GIMP-print/CUPS \+ GIMP-Print/; } elsif ($descr =~ /Series CUPS/) { $descr =~ s/Series CUPS/Series, CUPS/; } elsif (!(uc($descr) =~ /POSTSCRIPT/)) { $descr .= ", PostScript"; } # Split the $descr into model and driver my $model; my $driver; if ($descr =~ /^([^,]+), (.*)$/) { $model = $1; $driver = $2; } else { # Some PPDs do not have the ", <driver>" part. $model = $descr; $driver = "PostScript"; } my $make = $ppd{Manufacturer}; my $lang = $ppd{LanguageVersion}; # Remove manufacturer's name from the beginning of the model name if (($make) && ($model =~ /^$make[\s\-]+([^\s\-].*)$/)) { $model = $1; } # Put out the resulting description string uc($make) . '|' . $model . '|' . $driver . ($lang && (" (" . lc(substr($lang, 0, 2)) . ")")); } sub poll_ppd_base { #- before trying to poll the ppd database available to cups, we have to make sure #- the file /etc/cups/ppds.dat is no more modified. #- if cups continue to modify it (because it reads the ppd files available), the #- poll_ppd_base program simply cores :-) run_program::rooted($prefix, "ifconfig lo 127.0.0.1"); #- else cups will not be happy! and ifup lo don't run ? start_not_running_service("cups"); my $driversthere = scalar(keys %thedb); foreach (1..60) { local *PPDS; open PPDS, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/poll_ppd_base -a |"; local $_; while (<PPDS>) { chomp; my ($ppd, $mf, $descr, $lang) = split /\|/; if ($ppd eq "raw") { next } my ($model, $driver); if ($descr) { if ($descr =~ /^([^,]+), (.*)$/) { $model = $1; $driver = $2; } else { # Some PPDs do not have the ", <driver>" part. $model = $descr; $driver = "PostScript"; } } # Rename Canon "BJC XXXX" models into "BJC-XXXX" so that the models # do not appear twice if ($mf eq "CANON") { $model =~ s/BJC\s+/BJC-/; } $ppd && $mf && $descr and do { my $key = "$mf|$model|$driver" . ($lang && " ($lang)"); $thedb{$key}{ppd} = $ppd; $thedb{$key}{driver} = $driver; $thedb{$key}{make} = $mf; $thedb{$key}{model} = $model; } } close PPDS; scalar(keys %thedb) - $driversthere > 5 and last; #- we have to try again running the program, wait here a little before. sleep 1; } #scalar(keys %descr_to_ppd) > 5 or die "unable to connect to cups server"; } #-****************************************************************************** #- write functions #-****************************************************************************** sub configure_queue($) { my ($printer) = @_; local *F; if ($printer->{currentqueue}{foomatic}) { #- Create the queue with "foomatic-configure", in case of queue #- renaming copy the old queue run_program::rooted($prefix, "foomatic-configure", "-q", "-s", $printer->{currentqueue}{spooler}, "-n", $printer->{currentqueue}{queue}, (($printer->{currentqueue}{queue} ne $printer->{OLD_QUEUE}) && ($printer->{configured}{$printer->{OLD_QUEUE}}) ? ("-C", $printer->{OLD_QUEUE}) : ()), "-c", $printer->{currentqueue}{connect}, "-p", $printer->{currentqueue}{printer}, "-d", $printer->{currentqueue}{driver}, "-N", $printer->{currentqueue}{desc}, "-L", $printer->{currentqueue}{loc}, @{$printer->{currentqueue}{options}} ) or die "foomatic-configure failed"; } elsif ($printer->{currentqueue}{ppd}) { #- If the chosen driver is a PPD file from /usr/share/cups/model, #- we use lpadmin to set up the queue run_program::rooted($prefix, "lpadmin", "-p", $printer->{currentqueue}{queue}, # $printer->{State} eq 'Idle' && # $printer->{Accepting} eq 'Yes' ? ("-E") : (), "-E", "-v", $printer->{currentqueue}{connect}, ($printer->{currentqueue}{ppd} ne '1') ? ("-m", $printer->{currentqueue}{ppd}) : (), $printer->{currentqueue}{desc} ? ("-D", $printer->{currentqueue}{desc}) : (), $printer->{currentqueue}{loc} ? ("-L", $printer->{currentqueue}{loc}) : (), @{$printer->{currentqueue}{options}} ) or die "lpadmin failed"; # Add a comment line containing the path of the used PPD file to the # end of the PPD file if ($printer->{currentqueue}{ppd} ne '1') { open F, ">> $prefix/etc/cups/ppd/$printer->{currentqueue}{queue}.ppd"; print F "*%MDKMODELCHOICE:$printer->{currentqueue}{ppd}\n"; close F; } # Copy the old queue's PPD file to the new queue when it is renamed, # to conserve the option settings if (($printer->{currentqueue}{queue} ne $printer->{OLD_QUEUE}) && ($printer->{configured}{$printer->{OLD_QUEUE}})) { system("cp -f $prefix/etc/cups/ppd/$printer->{OLD_QUEUE}.ppd $prefix/etc/cups/ppd/$printer->{currentqueue}{queue}.ppd"); } } else { # Raw queue run_program::rooted($prefix, "foomatic-configure", "-q", "-s", $printer->{currentqueue}{spooler}, "-n", $printer->{currentqueue}{queue}, "-c", $printer->{currentqueue}{connect}, "-d", $printer->{currentqueue}{driver}, "-N", $printer->{currentqueue}{desc}, "-L", $printer->{currentqueue}{loc} ) or die "foomatic-configure failed"; } # Make sure that queue is active if ($printer->{SPOOLER} ne "pdq") { run_program::rooted($prefix, "foomatic-printjob", "-s", $printer->{currentqueue}{spooler}, "-C", "up", $printer->{currentqueue}{queue}); } # Check whether a USB printer is configured and activate USB printing if so my $useUSB = 0; foreach (values %{$printer->{configured}}) { $useUSB ||= $_->{queuedata}{connect} =~ /usb/ || $_->{DeviceURI} =~ /usb/; } $useUSB ||= ($printer->{currentqueue}{queue}{queuedata}{connect} =~ /usb/); if ($useUSB) { my $f = "$prefix/etc/sysconfig/usb"; my %usb = getVarsFromSh($f); $usb{PRINTER} = "yes"; setVarsInSh($f, \%usb); } # Open permissions for device file when PDQ is chosen as spooler # so normal users can print. if ($printer->{SPOOLER} eq 'pdq') { if ($printer->{currentqueue}{connect} =~ m!^\s*file:(\S*)\s*$!) { set_permissions($1,"666"); } } # Make a new printer entry in the $printer structure $printer->{configured}{$printer->{currentqueue}{queue}}{queuedata} = {}; copy_printer_params($printer->{currentqueue}, $printer->{configured}{$printer->{currentqueue}{queue}}{queuedata}); # Construct an entry line for tree view in main window of # printerdrake make_menuentry($printer, $printer->{currentqueue}{queue}); # Store the default option settings $printer->{configured}{$printer->{currentqueue}{queue}}{args} = {}; if ($printer->{currentqueue}{foomatic}) { my $tmp = $printer->{OLD_QUEUE}; $printer->{OLD_QUEUE} = $printer->{currentqueue}{queue}; $printer->{configured}{$printer->{currentqueue}{queue}}{args} = read_foomatic_options($printer); $printer->{OLD_QUEUE} = $tmp; } elsif ($printer->{currentqueue}{ppd}) { $printer->{configured}{$printer->{currentqueue}{queue}}{args} = read_cups_options($printer->{currentqueue}{queue}); } # Clean up delete($printer->{ARGS}); $printer->{OLD_CHOICE} = ""; $printer->{ARGS} = {}; $printer->{DBENTRY} = ""; $printer->{currentqueue} = {}; } sub remove_queue($$) { my ($printer) = $_[0]; my ($queue) = $_[1]; run_program::rooted($prefix, "foomatic-configure", "-R", "-q", "-s", $printer->{SPOOLER}, "-n", $queue); # Delete old stuff from data structure delete $printer->{configured}{$queue}; delete($printer->{currentqueue}); delete($printer->{ARGS}); $printer->{OLD_CHOICE} = ""; $printer->{ARGS} = {}; $printer->{DBENTRY} = ""; $printer->{currentqueue} = {}; removeprinterfromapplications($printer, $queue); } sub restart_queue($) { my ($printer) = @_; my $queue = $printer->{QUEUE}; # Restart the daemon(s) for ($printer->{SPOOLER}) { /cups/ && do { #- restart cups. restart_service("cups"); last }; /lpr|lprng/ && do { #- restart lpd. foreach (("/var/spool/lpd/$queue/lock", "/var/spool/lpd/lpd.lock")) { my $pidlpd = (cat_("$prefix$_"))[0]; kill 'TERM', $pidlpd if $pidlpd; unlink "$prefix$_"; } restart_service("lpd"); sleep 1; last }; } # Kill the jobs run_program::rooted($prefix, "foomatic-printjob", "-R", "-s", $printer->{SPOOLER}, "-P", $queue, "-"); } sub print_pages($@) { my ($printer, @pages) = @_; my $queue = $printer->{QUEUE}; my $lpr = "/usr/bin/foomatic-printjob"; my $lpq = "$lpr -Q"; # Print the pages foreach (@pages) { my $page = $_; # Only text and PostScript can be printed directly with all spoolers, # images must be treated seperately if ($page =~ /\.jpg$/) { system(($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/convert $page -page 427x654+100+65 PS:- | " . ($::testing ? $prefix : "chroot $prefix/ ") . "$lpr -s $printer->{SPOOLER} -P $queue"); } else { run_program::rooted($prefix, $lpr, "-s", $printer->{SPOOLER}, "-P", $queue, $page); } } sleep 5; #- allow lpr to send pages. # Check whether the job is queued local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "$lpq -s $printer->{SPOOLER} -P $queue |"; my @lpq_output = grep { !/^no entries/ && !(/^Rank\s+Owner/ .. /^\s*$/) } <F>; close F; @lpq_output; } sub lphelp_output { my ($printer) = @_; my $queue = $printer->{QUEUE}; my $lphelp = "/usr/bin/lphelp"; local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "$lphelp $queue |"; $helptext = join("", <F>); close F; if (!$helptext || ($helptext eq "")) { $helptext = "Option list not available!\n"; } return $helptext; } sub pdqhelp_output { my ($printer) = @_; my $queue = $printer->{QUEUE}; my $pdq = "/usr/bin/pdq"; local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "$pdq -h -P $queue 2>&1 |"; $helptext = join("", <F>); close F; return $helptext; } sub print_optionlist { my ($printer) = @_; my $queue = $printer->{QUEUE}; my $lpr = "/usr/bin/foomatic-printjob"; # Print the option list pages if ($printer->{configured}{$queue}{queuedata}{foomatic}) { run_program::rooted($prefix, $lpr, "-s", $printer->{SPOOLER}, "-P", $queue, "-o", "docs", "/etc/bashrc"); } elsif ($printer->{configured}{$queue}{queuedata}{ppd}) { system(($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/lphelp $queue | " . ($::testing ? $prefix : "chroot $prefix/ ") . "$lpr -s $printer->{SPOOLER} -P $queue"); } } # --------------------------------------------------------------- # # Spooler config stuff # # --------------------------------------------------------------- sub get_copiable_queues { my ($oldspooler, $newspooler) = @_; local $_; #- use of while (<... local *QUEUEOUTPUT; #- don't have to do close ... and don't modify globals #- at least my @queuelist; #- here we will list all Foomatic-generated queues # Get queue list with foomatic-configure open QUEUEOUTPUT, ($::testing ? $prefix : "chroot $prefix/ ") . "foomatic-configure -Q -q -s $oldspooler |" || die "Could not run foomatic-configure"; my $entry = {}; my $inentry = 0; while (<QUEUEOUTPUT>) { chomp; if ($inentry) { # We are inside a queue entry if (m!^\s*</queue>\s*$!) { # entry completed $inentry = 0; if (($entry->{foomatic}) && ($entry->{spooler} eq $oldspooler)) { # Is the connection type supported by the new # spooler? if ((($newspooler eq "cups") && (($entry->{connect} =~ /^file:/) || ($entry->{connect} =~ /^ptal:/) || ($entry->{connect} =~ /^lpd:/) || ($entry->{connect} =~ /^socket:/) || ($entry->{connect} =~ /^smb:/) || ($entry->{connect} =~ /^ipp:/))) || ((($newspooler eq "lpd") || ($newspooler eq "lprng")) && (($entry->{connect} =~ /^file:/) || ($entry->{connect} =~ /^ptal:/) || ($entry->{connect} =~ /^lpd:/) || ($entry->{connect} =~ /^socket:/) || ($entry->{connect} =~ /^smb:/) || ($entry->{connect} =~ /^ncp:/) || ($entry->{connect} =~ /^postpipe:/))) || (($newspooler eq "pdq") && (($entry->{connect} =~ /^file:/) || ($entry->{connect} =~ /^ptal:/) || ($entry->{connect} =~ /^lpd:/) || ($entry->{connect} =~ /^socket:/)))) { push(@queuelist, $entry->{name}); } } $entry = {}; } elsif (m!^\s*<name>(.+)</name>\s*$!) { # queue name $entry->{name} = $1; } elsif (m!^\s*<connect>(.+)</connect>\s*$!) { # connection type (URI) $entry->{connect} = $1; } } else { if (m!^\s*<queue\s+foomatic\s*=\s*\"?(\d+)\"?\s*spooler\s*=\s*\"?(\w+)\"?\s*>\s*$!) { # new entry $inentry = 1; $entry->{foomatic} = $1; $entry->{spooler} = $2; } } } close QUEUEOUTPUT; return @queuelist; } sub copy_foomatic_queue { my ($printer, $oldqueue, $oldspooler, $newqueue) = @_; run_program::rooted($prefix, "foomatic-configure", "-q", "-s", $printer->{SPOOLER}, "-n", $newqueue, "-C", $oldspooler, $oldqueue); } # ------------------------------------------------------------------ # # Configuration of HP multi-function devices # # ------------------------------------------------------------------ sub configure_hpoj { my ($device, @autodetected) = @_; # Make the subroutines of /usr/sbin/ptal-init available # It's only necessary to read it at the first call of this subroutine, # the subroutine definitions stay valid after leaving this subroutine. if (!$ptalinitread) { local *PTALINIT; open PTALINIT, "$prefix/usr/sbin/ptal-init" || do { die "unable to open $prefix/usr/sbin/ptal-init"; }; my @ptalinitfunctions; # subroutine definitions in /usr/sbin/ptal-init while (<PTALINIT>) { if (m!sub main!) { last; } elsif (m!^[^\#]!) { push (@ptalinitfunctions, $_); } } close PTALINIT; eval "@ptalinitfunctions sub getDevnames { return (%devnames) } sub getConfigInfo { return (%configInfo) }"; $ptalinitread = 1; } # Read the HPOJ config file and check whether this device is already # configured setupVariables (); readDeviceInfo (); # Get the model ID as auto-detected $device =~ m!^/dev/\S*lp(\d+)$!; my $model = $1; my $model_long = $1; my $serialnumber = ""; my $serialnumber_long = ""; my $cardreader = 0; my $device_ok = 1; my $bus; my $address_arg = ""; my $base_address = ""; if ($device =~ /usb/) { $bus = "usb"; } else { $bus = "par"; $address_arg = parport_addr($device); $address_arg =~ /^\s*-base\s+(\S+)/; eval ("$base_address = $1"); } my $devdata; foreach (@autodetected) { $device eq $_->{port} or next; $devdata = $_; $model = $_->{val}{MODEL}; $serialnumber = $_->{val}{SERIALNUMBER}; # Check if the device is really an HP multi-function device stop_service("hpoj"); run_program::rooted($prefix, "ptal-mlcd", "$bus:probe", "-device", $device, split(' ',$address_arg)); $device_ok = 0; local *F; if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/ptal-devid mlc:$bus:probe |") { my $devid = join("", <F>); close F; if ($devid) { $device_ok = 1; if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/ptal-devid mlc:$bus:probe -long -mdl 2>/dev/null |") { $model_long = join("", <F>); close F; chomp $model_long; } if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "/usr/bin/ptal-devid mlc:$bus:probe -long -sern 2>/dev/null |") { $serialnumber_long = join("", <F>); close F; chomp $serialnumber_long; } if (cardReaderDetected ("mlc:$bus:probe")) { $cardreader = 1; } } } if (open F, ($::testing ? $prefix : "chroot $prefix/ ") . "ps auxwww | grep \"ptal-mlcd $bus:probe\" | grep -v grep | ") { my $line = <F>; if ($line =~ /^\s*\S+\s+(\d+)\s+/) { my $pid = $1; kill (15, $pid); } close F; } start_service("hpoj"); last; } # No, it is not an HP multi-function device. return "" if (!$device_ok); # Determine the ptal device name from already existing config files my $ptaldevice = lookupDevname ("mlc:$bus:", $model_long, $serialnumber_long, $base_address); # It's all done for us, the device is already configured return $ptaldevice if defined($ptaldevice); # Determine the ptal name for a new device $ptaldevice = $model; $ptaldevice =~ s![\s/]+!_!g; $ptaldevice = "mlc:$bus:$ptaldevice"; # Delete any old/conflicting devices deleteDevice ($ptaldevice); if ($bus eq "par") { while (1) { my $oldDevname = lookupDevname ("mlc:par:",undef,undef, $base_address); if (!defined($oldDevname)) { last; } deleteDevice ($oldDevname); } } # Configure the device # Open configuration file local *CONFIG; open(CONFIG,"> /etc/ptal/$ptaldevice") || die "Could not open /etc/ptal/$ptaldevice for writing!\n"; # Write file header. $_ = `date`; chomp; print CONFIG "# Added $_ by \"printerdrake\".\n". "\n". "# The basic format for this file is \"key[+]=value\".\n". "# If you say \"+=\" instead of \"=\", then the value is appended to any\n". "# value already defined for this key, rather than replacing it.\n". "\n". "# Comments must start at the beginning of the line. Otherwise, they may\n". "# be interpreted as being part of the value.\n". "\n". "# If you have multiple devices and want to define options that apply to\n". "# all of them, then put them in the file /etc/ptal/defaults, which is read\n". "# in before this file.\n". "\n". "# The format version of this file:\n". "# ptal-init ignores devices with incorrect/missing versions.\n". "init.version=1\n"; # Write model string. if ($model_long !~ /\S/) { print CONFIG "\n". "# \"printerdrake\" couldn't read the model but added this device anyway:\n". "# "; } else { print CONFIG "\n". "# The device model that was originally detected on this port:\n". "# If this ever changes, then you should re-run \"printerdrake\"\n". "# to delete and re-configure this device.\n"; if ($bus eq "par") { print CONFIG "# Comment out if you don't care what model is really connected to this\n". "# parallel port.\n"; } } print CONFIG "init.mlcd.append+=-devidmatch \"$model_long\"\n"; # Write serial-number string. if ($serialnumber_long!~/\S/) { print CONFIG "\n". "# The device's serial number is unknown.\n". "# "; } else { print CONFIG "\n". "# The serial number of the device that was originally detected on this port:\n" ; if ($bus=~/^[pu]/) { print CONFIG "# Comment out if you want to disable serial-number matching.\n"; } } print CONFIG "init.mlcd.append+=-devidmatch \"$serialnumber_long\"\n"; if ($bus=~/^[pu]/) { print CONFIG "\n". "# Standard options passed to ptal-mlcd:\n". "init.mlcd.append+="; if ($bus eq "usb") { # Important: don't put more quotes around /dev/usb/lp[0-9]*, # because ptal-mlcd currently does no globbing: print CONFIG "-device /dev/usb/lp[0-9]*"; } elsif ($bus eq "par") { print CONFIG "$address_arg -device $device"; } print CONFIG "\n". "\n". "# ptal-mlcd's remote console can be useful for debugging, but may be a\n". "# security/DoS risk otherwise. In any case, it's accessible with the\n". "# command \"ptal-connect mlc:<XXX>:<YYY> -service PTAL-MLCD-CONSOLE\".\n". "# Uncomment the following line if you want to enable this feature for\n". "# this device:\n". "# init.mlcd.append+=-remconsole\n". "\n". "# If you need to pass any other command-line options to ptal-mlcd, then\n". "# add them to the following line and uncomment the line:\n". "# init.mlcd.append+=\n". "\n". "# By default ptal-printd is started for mlc: devices. If you use CUPS,\n". "# then you may not be able to use ptal-printd, and you can uncomment the\n". "# following line to disable ptal-printd for this device:\n". "# init.printd.start=0\n"; } else { print CONFIG "\n". "# By default ptal-printd isn't started for hpjd: devices.\n". "# If for some reason you want to start it for this device, then\n". "# uncomment the following line:\n". "# init.printd.start=1\n"; } print CONFIG "\n". "# If you need to pass any additional command-line options to ptal-printd,\n". "# then add them to the following line and uncomment the line:\n". "# init.printd.append+=\n"; if ($cardreader) { print CONFIG "\n". "# Uncomment the following line to enable ptal-photod for this device:\n". "init.photod.start=1\n". "\n". "# If you have more than one photo-card-capable peripheral and you want to\n". "# assign particular TCP port numbers and mtools drive letters to each one,\n". "# then change the line below to use the \"-portoffset <n>\" option.\n". "init.photod.append+=-maxaltports 26\n"; } close(CONFIG); readOneDevice ($ptaldevice); # Restart HPOJ restart_service("hpoj"); # Return HPOJ device name to form the URI return $ptaldevice; } sub parport_addr{ # auto-detect the parallel port addresses my ($device) = @_; $device =~ m!^/dev/lp(\d+)$!; my $portnumber = $1; my $parport_addresses = `cat /proc/sys/dev/parport/parport$portnumber/base-addr`; my $address_arg; if ($parport_addresses =~ /^\s*(\d+)\s+(\d+)\s*$/) { $address_arg = sprintf(" -base 0x%x -basehigh 0x%x", $1, $2); } elsif ($parport_addresses =~ /^\s*(\d+)\s*$/) { $address_arg = sprintf(" -base 0x%x", $1); } else { $address_arg = ""; } return $address_arg; } sub config_sane { # Add HPOJ backend to /etc/sane.d/dll.conf if needed (no individual # config file /etc/sane.d/hpoj.conf necessary, the HPOJ driver finds the # scanner automatically) return if member("hpoj", chomp_(cat_("$prefix/etc/sane.d/dll.conf"))); local *F; open F, ">> $prefix/etc/sane.d/dll.conf" or die "can't write SANE config in /etc/sane.d/dll.conf: $!"; print F "hpoj\n"; close F; } sub config_photocard { # Add definitions for the drives p:. q:, r:, and s: to /etc/mtools.conf my $mtoolsconf = join("", cat_("$prefix/etc/mtools.conf")); return if $mtoolsconf =~ m/^\s*drive\s+p:/m; my $mtoolsconf_append = " # Drive definitions added for the photo card readers in HP multi-function # devices driven by HPOJ drive p: file=\":0\" remote drive q: file=\":1\" remote drive r: file=\":2\" remote drive s: file=\":3\" remote # This turns off some file system integrity checks of mtools, it is needed # for some photo cards. mtools_skip_check=1 "; open F, ">> $prefix/etc/mtools.conf" or die "can't write mtools config in /etc/mtools.conf: $!"; print F $mtoolsconf_append; close F; # Generate a config file for the graphical mtools frontend MToolsFM or # modify the existing one my $mtoolsfmconf; if (-f "$prefix/etc/mtoolsfm.conf") { open F, "< $prefix/etc/mtoolsfm.conf" or die "can't read MToolsFM config in $prefix/etc/mtoolsfm.conf: $!"; $mtoolsfmconf = join("", <F>); close F; $mtoolsfmconf =~ m/^\s*DRIVES\s*=\s*\"([A-Za-z ]*)\"/m; my $alloweddrives = lc($1); foreach my $letter ("p", "q", "r", "s") { if ($alloweddrives !~ /$letter/) { $alloweddrives .= $letter; } } $mtoolsfmconf =~ s/^\s*DRIVES\s*=\s*\"[A-Za-z ]*\"/DRIVES=\"$alloweddrives\"/m; $mtoolsfmconf =~ s/^\s*LEFTDRIVE\s*=\s*\"[^\"]*\"/LEFTDRIVE=\"p\"/m; } else { $mtoolsfmconf = "\# MToolsFM config file. comments start with a hash sign. \# \# This variable sets the allowed driveletters (all lowercase). Example: \# DRIVES=\"ab\" DRIVES=\"apqrs\" \# \# This variable sets the driveletter upon startup in the left window. \# An empty string or space is for the hardisk. Example: \# LEFTDRIVE=\"a\" LEFTDRIVE=\"p\" \# \# This variable sets the driveletter upon startup in the right window. \# An empty string or space is for the hardisk. Example: \# RIGHTDRIVE=\"a\" RIGHTDRIVE=\" \" "; } open F, "> $prefix/etc/mtoolsfm.conf" or die "can't write mtools config in /etc/mtools.conf: $!"; print F $mtoolsfmconf; close F; } # ------------------------------------------------------------------ # # Configuration of printers in Applications # # ------------------------------------------------------------------ sub configureapplications { my ($printer) = @_; configurestaroffice($printer); configureopenoffice($printer); } sub addcupsremotetoapplications { my ($printer, $queue) = @_; return (addcupsremotetostaroffice($printer, $queue) && addcupsremotetoopenoffice($printer, $queue)); } sub removeprinterfromapplications { my ($printer, $queue) = @_; return (removeprinterfromstaroffice($printer, $queue) && removeprinterfromopenoffice($printer, $queue)); } sub removelocalprintersfromapplications { my ($printer) = @_; removelocalprintersfromstaroffice($printer); removelocalprintersfromopenoffice($printer); } sub configurestaroffice { my ($printer) = @_; # Do we have Star Office installed? my $configfilename = findsofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/xp3/Xpdefaults$!; my $configprefix = $1; # Load Star Office printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Update remote CUPS queues if (0 && ($printer->{SPOOLER} eq "cups") && (-x "$prefix/usr/bin/curl")) { my @printerlist = getcupsremotequeues(); for my $listentry (@printerlist) { next if !($listentry =~ /^([^\|]+)\|([^\|]+)$/); my $queue = $1; my $server = $2; eval(run_program::rooted ($prefix, "curl", "-o", "/etc/foomatic/$queue.ppd", "http://$server:631/printers/$queue.ppd")); if (-r "$prefix/etc/foomatic/$queue.ppd") { $configfilecontent = makestarofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } } } # Update local printer queues for my $queue (keys(%{$printer->{configured}})) { # Check if we have a PPD file if (! -r "$prefix/etc/foomatic/$queue.ppd") { if (-r "$prefix/etc/cups/ppd/$queue.ppd") { # If we have a PPD file in the CUPS config dir, link to it run_program::rooted($prefix, "ln", "-sf", "/etc/cups/ppd/$queue.ppd", "/etc/foomatic/$queue.ppd"); } elsif (-r "$prefix/usr/share/postscript/ppd/$queue.ppd") { # Check PPD directory of GPR, too run_program::rooted($prefix, "ln", "-sf", "/usr/share/postscript/ppd/$queue.ppd", "/etc/foomatic/$queue.ppd"); } else { # No PPD file at all? We cannot set up this printer next; } } $configfilecontent = makestarofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } # Patch PostScript output to print Euro symbol correctly also for # the "Generic Printer" $configfilecontent = removeentry ("ports", "default_queue=", $configfilecontent); $configfilecontent = addentry ("ports", "default_queue=/usr/bin/perl -p -e \"s=16#80 /euro=16#80 /Euro=\" | /usr/bin/$lprcommand{$printer->{SPOOLER}}", $configfilecontent); # Write back Star Office configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub configureopenoffice { my ($printer) = @_; # Do we have OpenOffice.org installed? my $configfilename = findopenofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/psprint/psprint.conf$!; my $configprefix = $1; # Load OpenOffice.org printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Update remote CUPS queues if (0 && ($printer->{SPOOLER} eq "cups") && (-x "$prefix/usr/bin/curl")) { my @printerlist = getcupsremotequeues(); for my $listentry (@printerlist) { next if !($listentry =~ /^([^\|]+)\|([^\|]+)$/); my $queue = $1; my $server = $2; eval(run_program::rooted ($prefix, "curl", "-o", "/etc/foomatic/$queue.ppd", "http://$server:631/printers/$queue.ppd")); if (-r "$prefix/etc/foomatic/$queue.ppd") { $configfilecontent = makeopenofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } } } # Update local printer queues for my $queue (keys(%{$printer->{configured}})) { # Check if we have a PPD file if (! -r "$prefix/etc/foomatic/$queue.ppd") { if (-r "$prefix/etc/cups/ppd/$queue.ppd") { # If we have a PPD file in the CUPS config dir, link to it run_program::rooted($prefix, "ln", "-sf", "/etc/cups/ppd/$queue.ppd", "/etc/foomatic/$queue.ppd"); } elsif (-r "$prefix/usr/share/postscript/ppd/$queue.ppd") { # Check PPD directory of GPR, too run_program::rooted($prefix, "ln", "-sf", "/usr/share/postscript/ppd/$queue.ppd", "/etc/foomatic/$queue.ppd"); } else { # No PPD file at all? We cannot set up this printer next; } } $configfilecontent = makeopenofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } # Patch PostScript output to print Euro symbol correctly also for # the "Generic Printer" $configfilecontent = removeentry ("Generic Printer", "Command=", $configfilecontent); $configfilecontent = addentry ("Generic Printer", "Command=/usr/bin/perl -p -e \"s=/euro /unused=/Euro /unused=\" | /usr/bin/$lprcommand{$printer->{SPOOLER}}", $configfilecontent); # Write back OpenOffice.org configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub addcupsremotetostaroffice { my ($printer, $queue) = @_; # Do we have Star Office installed? my $configfilename = findsofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/xp3/Xpdefaults$!; my $configprefix = $1; # Load Star Office printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Update remote CUPS queues if (($printer->{SPOOLER} eq "cups") && (-x "$prefix/usr/bin/curl")) { my @printerlist = getcupsremotequeues(); for my $listentry (@printerlist) { next if !($listentry =~ /^([^\|]+)\|([^\|]+)$/); my $q = $1; next if ($q ne $queue); my $server = $2; # Remove server name from queue name $q =~ s/^([^@]*)@.*$/$1/; eval(run_program::rooted ($prefix, "/usr/bin/curl", "-o", "/etc/foomatic/$queue.ppd", "http://$server:631/printers/$q.ppd")); # Does the file exist and is it not an error message? if ((-r "$prefix/etc/foomatic/$queue.ppd") && (cat_("$prefix/etc/foomatic/$queue.ppd") =~ /^\*PPD-Adobe/)) { $configfilecontent = makestarofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } else { return 0; } last; } } # Write back Star Office configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub addcupsremotetoopenoffice { my ($printer, $queue) = @_; # Do we have OpenOffice.org installed? my $configfilename = findopenofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/psprint/psprint.conf$!; my $configprefix = $1; # Load OpenOffice.org printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Update remote CUPS queues if (($printer->{SPOOLER} eq "cups") && (-x "$prefix/usr/bin/curl")) { my @printerlist = getcupsremotequeues(); for my $listentry (@printerlist) { next if !($listentry =~ /^([^\|]+)\|([^\|]+)$/); my $q = $1; next if ($q ne $queue); my $server = $2; # Remove server name from queue name $q =~ s/^([^@]*)@.*$/$1/; eval(run_program::rooted ($prefix, "/usr/bin/curl", "-o", "/etc/foomatic/$queue.ppd", "http://$server:631/printers/$q.ppd")); # Does the file exist and is it not an error message? if ((-r "$prefix/etc/foomatic/$queue.ppd") && (cat_("$prefix/etc/foomatic/$queue.ppd") =~ /^\*PPD-Adobe/)) { $configfilecontent = makeopenofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } else { return 0; } } } # Write back OpenOffice.org configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub removeprinterfromstaroffice { my ($printer, $queue) = @_; # Do we have Star Office installed? my $configfilename = findsofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/xp3/Xpdefaults$!; my $configprefix = $1; # Load Star Office printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Remove the printer entry $configfilecontent = removestarofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); # Write back Star Office configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub removeprinterfromopenoffice { my ($printer, $queue) = @_; # Do we have OpenOffice.org installed? my $configfilename = findopenofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/psprint/psprint.conf$!; my $configprefix = $1; # Load OpenOffice.org printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Remove the printer entry $configfilecontent = removeopenofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); # Write back OpenOffice.org configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub removelocalprintersfromstaroffice { my ($printer) = @_; # Do we have Star Office installed? my $configfilename = findsofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/xp3/Xpdefaults$!; my $configprefix = $1; # Load Star Office printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Remove the printer entries for my $queue (keys(%{$printer->{configured}})) { $configfilecontent = removestarofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } # Write back Star Office configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub removelocalprintersfromopenoffice { my ($printer) = @_; # Do we have OpenOffice.org installed? my $configfilename = findopenofficeconfigfile(); return 1 if !$configfilename; $configfilename =~ m!^(.*)/share/psprint/psprint.conf$!; my $configprefix = $1; # Load OpenOffice.org printer config file my $configfilecontent = readsofficeconfigfile($configfilename); # Remove the printer entries for my $queue (keys(%{$printer->{configured}})) { $configfilecontent = removeopenofficeprinterentry($printer, $queue, $configprefix, $configfilecontent); } # Write back OpenOffice.org configuration file return writesofficeconfigfile($configfilename, $configfilecontent); } sub makestarofficeprinterentry { my ($printer, $queue, $configprefix, $configfile) = @_; # Set default printer if ($queue eq $printer->{DEFAULT}) { $configfile = removeentry("windows", "device=", $configfile); $configfile = addentry("windows", "device=$queue,$queue PostScript,$queue", $configfile); } # Make an entry in the "[devices]" section $configfile = removeentry("devices", "$queue=", $configfile); $configfile = addentry("devices", "$queue=$queue PostScript,$queue", $configfile); # Make an entry in the "[ports]" section # The "perl" command patches the PostScript output to print the Euro # symbol correctly. $configfile = removeentry("ports", "$queue=", $configfile); $configfile = addentry("ports", "$queue=/usr/bin/perl -p -e \"s=16#80 /euro=16#80 /Euro=\" | /usr/bin/$lprcommand{$printer->{SPOOLER}} -P $queue", $configfile); # Make printer's section $configfile = addsection("$queue,PostScript,$queue", $configfile); # Load PPD file my $ppd = cat_("$prefix/etc/foomatic/$queue.ppd"); # Set the PostScript level my $pslevel; if ($ppd =~ /^\s*\*LanguageLevel:\s*\"?([^\s\"]+)\"?\s*$/m) { $pslevel = $1; $pslevel = "2" if $pslevel eq "3"; } else { $pslevel = "2"; } $configfile = removeentry("$queue.PostScript.$queue", "Level=", $configfile); $configfile = addentry("$queue.PostScript.$queue", "Level=$pslevel", $configfile); # Set Color/BW my $color; if ($ppd =~ /^\s*\*ColorDevice:\s*\"?([Tt]rue)\"?\s*$/m) { $color = "1"; } else { $color = "0"; } $configfile = removeentry("$queue.PostScript.$queue", "BitmapColor=", $configfile); $configfile = addentry("$queue.PostScript.$queue", "BitmapColor=$color", $configfile); # Set the default paper size if ($ppd =~ /^\s*\*DefaultPageSize:\s*(\S+)\s*$/m) { my $papersize = $1; $configfile = removeentry("$queue.PostScript.$queue", "PageSize=", $configfile); $configfile = removeentry("$queue.PostScript.$queue", "PPD_PageSize=", $configfile); $configfile = addentry("$queue.PostScript.$queue", "PageSize=$papersize", $configfile); $configfile = addentry("$queue.PostScript.$queue", "PPD_PageSize=$papersize", $configfile); } # Link the PPD file run_program::rooted($prefix, "ln", "-sf", "/etc/foomatic/$queue.ppd", "$configprefix/share/xp3/ppds/$queue.PS"); return $configfile; } sub makeopenofficeprinterentry { my ($printer, $queue, $configprefix, $configfile) = @_; # Make printer's section $configfile = addsection($queue, $configfile); # Load PPD file my $ppd = cat_("$prefix/etc/foomatic/$queue.ppd"); # "PPD_PageSize" line if ($ppd =~ /^\s*\*DefaultPageSize:\s*(\S+)\s*$/m) { my $papersize = $1; $configfile = removeentry($queue, "PPD_PageSize=", $configfile); $configfile = addentry($queue, "PPD_PageSize=$papersize", $configfile); } # "Command" line # The "perl" command patches the PostScript output to print the Euro # symbol correctly. $configfile = removeentry($queue, "Command=", $configfile); $configfile = addentry($queue, "Command=/usr/bin/perl -p -e \"s=/euro /unused=/Euro /unused=\" | /usr/bin/$lprcommand{$printer->{SPOOLER}} -P $queue", $configfile); # "Comment" line $configfile = removeentry($queue, "Comment=", $configfile); if (($printer->{configured}{$queue}) && ($printer->{configured}{$queue}{queuedata}{desc})) { $configfile = addentry ($queue, "Comment=$printer->{configured}{$queue}{queuedata}{desc}", $configfile); } else { $configfile = addentry($queue, "Comment=", $configfile); } # "Location" line $configfile = removeentry($queue, "Location=", $configfile); if (($printer->{configured}{$queue}) && ($printer->{configured}{$queue}{queuedata}{loc})) { $configfile = addentry ($queue, "Location=$printer->{configured}{$queue}{queuedata}{loc}", $configfile); } else { $configfile = addentry($queue, "Location=", $configfile); } # "DefaultPrinter" line $configfile = removeentry($queue, "DefaultPrinter=", $configfile); my $default = "0"; if ($queue eq $printer->{DEFAULT}) { $default = "1"; } $configfile = addentry($queue, "DefaultPrinter=$default", $configfile); # "Printer" line $configfile = removeentry($queue, "Printer=", $configfile); $configfile = addentry($queue, "Printer=$queue/$queue", $configfile); # Link the PPD file run_program::rooted($prefix, "ln", "-sf", "/etc/foomatic/$queue.ppd", "$configprefix/share/psprint/driver/$queue.PS"); return $configfile; } sub removestarofficeprinterentry { my ($printer, $queue, $configprefix, $configfile) = @_; # Remove default printer entry $configfile = removeentry("windows", "device=$queue,", $configfile); # Remove entry in the "[devices]" section $configfile = removeentry("devices", "$queue=", $configfile); # Remove entry in the "[ports]" section $configfile = removeentry("ports", "$queue=", $configfile); # Remove "[$queue,PostScript,$queue]" section $configfile = removesection("$queue,PostScript,$queue", $configfile); # Remove Link of PPD file run_program::rooted($prefix, "rm", "-f", "$configprefix/share/xp3/ppds/$queue.PS"); return $configfile; } sub removeopenofficeprinterentry { my ($printer, $queue, $configprefix, $configfile) = @_; # Remove printer's section $configfile = removesection($queue, $configfile); # Remove Link of PPD file run_program::rooted($prefix, "rm", "-f", "$configprefix/share/psprint/driver/$queue.PS"); return $configfile; } sub findsofficeconfigfile { my @configfilenames = ("/usr/lib/*/share/xp3/Xpdefaults", "/usr/local/lib/*/share/xp3/Xpdefaults", "/usr/local/*/share/xp3/Xpdefaults", "/opt/*/share/xp3/Xpdefaults"); my $configfilename = ""; for $configfilename (@configfilenames) { local *F; if (open F, "ls -r $prefix$configfilename 2> /dev/null |") { my $filename = <F>; close F; if ($filename) { if ($prefix ne "") { $filename =~ s:^$prefix::; } return $filename; } } } return ""; } sub findopenofficeconfigfile { my @configfilenames = ("/usr/lib/*/share/psprint/psprint.conf", "/usr/local/lib/*/share/psprint/psprint.conf", "/usr/local/*/share/psprint/psprint.conf", "/opt/*/share/psprint/psprint.conf"); my $configfilename = ""; for $configfilename (@configfilenames) { local *F; if (open F, "ls -r $prefix$configfilename 2> /dev/null |") { my $filename = <F>; close F; if ($filename) { if ($prefix ne "") { $filename =~ s:^$prefix::; } return $filename; } } } return ""; } sub readsofficeconfigfile { my ($file) = @_; local *F; open F, "< $prefix$file" || return ""; my $filecontent = join("", <F>); close F; return $filecontent; } sub writesofficeconfigfile { my ($file, $filecontent) = @_; local *F; open F, "> $prefix$file" || return 0; print F $filecontent; close F; return 1; } sub getcupsremotequeues { # The following code reads in a list of all remote printers which the # local CUPS daemon knows due to broadcasting of remote servers or # "BrowsePoll" entries in the local /etc/cups/cupsd.conf local *F; open F, ($::testing ? $prefix : "chroot $prefix/ ") . "lpstat -v |" || return (); my @printerlist; my $line; while ($line = <F>) { if ($line =~ m/^\s*device\s+for\s+([^:\s]+):\s*(\S+)\s*$/) { my $queuename = $1; if (($2 =~ m!^ipp://([^/:]+)[:/]!) && (!$printer->{configured}{$queuename})) { my $server = $1; push (@printerlist, "$queuename|$server"); } } } close F; return @printerlist; } sub addentry { my ($section, $entry, $filecontent) = @_; my $sectionfound = 0; my $entryinserted = 0; my @lines = split("\n", $filecontent); local $_; for (@lines) { if (!$sectionfound) { if (/^\s*\[\s*$section\s*\]\s*$/) { $sectionfound = 1; } } else { if (!/^\s*$/ && !/^\s*;/) { #-# $_ = "$entry\n$_"; $entryinserted = 1; last; } } } if ($sectionfound && !$entryinserted) { push(@lines, $entry); } return join ("\n", @lines); } sub addsection { my ($section, $filecontent) = @_; my $entryinserted = 0; my @lines = split("\n", $filecontent); local $_; for (@lines) { if (/^\s*\[\s*$section\s*\]\s*$/) { # section already there, nothing to be done return $filecontent; } } return $filecontent . "\n[$section]"; } sub removeentry { my ($section, $entry, $filecontent) = @_; my $sectionfound = 0; my $done = 0; my @lines = split("\n", $filecontent); local $_; for (@lines) { $_ = "$_\n"; next if ($done); if (!$sectionfound) { if (/^\s*\[\s*$section\s*\]\s*$/) { $sectionfound = 1; } } else { if (/^\s*\[.*\]\s*$/) { # Next section $done = 1; } elsif (/^\s*$entry/) { $_ = ""; $done = 1; } } } return join ("", @lines); } sub removesection { my ($section, $filecontent) = @_; my $sectionfound = 0; my $done = 0; my @lines = split("\n", $filecontent); local $_; for (@lines) { $_ = "$_\n"; next if ($done); if (!$sectionfound) { if (/^\s*\[\s*$section\s*\]\s*$/) { $_ = ""; $sectionfound = 1; } } else { if (/^\s*\[.*\]\s*$/) { # Next section $done = 1; } else { $_ = ""; } } } return join ("", @lines); } #-###################################################################################### #- Wonderful perl :( #-###################################################################################### 1;