summaryrefslogtreecommitdiff
path: root/Master/bin/x86_64-linux/updmap
blob: e09c817451bd682b1953467ebc8aabefd78f2c9f (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
#!/bin/sh
# updmap: utility to maintain map files for outline fonts.
# Thomas Esser. Public domain.
# Run with --help for usage.

###############################################################################
# program history:
#   Sun May 25 21:05:32 CEST 2008 (Reinhard Kotucha)
#      add function symlink_or_copy needed by tl-portable.
#   Post-te retirement, now maintained in TeX Live; see
#     Build/texk/tetex/ChangeLog for further changes.
#   Fr Jul 22 07:22:38 CEST 2005
#      write hint about log file into output files
#   Fr Apr  8 19:15:05 CEST 2005
#      cleanup now has an argument for the return code
#   So Mär 27 18:52:06 CEST 2005
#      honor $TMPDIR, $TEMP and $TMP, not just $TMP
#   Do Mär 10 19:31:39 CET 2005
#      add a few quotes for $cnfFile with whitespace
#   Sa Jan 15 18:13:46 CET 2005
#      avoid multiple variable assignments in one statement
#   Sa Dez 25 12:44:23 CET 2004
#      implementaion adopted for teTeX-3.0 (tcfmgr)
#   Mi Nov  3 16:33:22 CET 2004
#      add "--setoption option=value" syntax
#   Fr Okt 29 21:05:53 CEST 2004
#      add --enable Map=... / --enable MixedMap=...
#   Mi Okt 20 19:17:19 CEST 2004
#      transcript added; even better warnings / error messages
#   So Okt 17 19:07:17 CEST 2004
#      improved warnings / error messages
#      added --syncwithtrees
#      added --listavailablemaps
#   Mi Okt  6 16:37:49 CEST 2004
#      commenty may start with any of *#;%
#   Sun Aug  1 11:42:14 CEST 2004, te
#      remove pdftex related hacks; pdftex no longer needs them!
#   Thu May 13 22:04:23 CEST 2004, te
#      support user with new map file locations
#   Fri Mar 19 15:22:55 CET 2004, te
#      output "xxx yyy" instead of " xxx yyy " (less blanks)
#   Fri Jan  2 22:41:11 CET 2004, te:
#      add version string
#   Wed Aug 20 18:51:47 CEST 2003
#      store map files to fonts/map, add options for dvipsoutputdir,
#      pdftexoutputdir, dvipdfmoutputdir
#   Mon Mar 24 13:40:55 CET 2003
#      fix fmex[789] for dvipdfm (no -r option)
#   Sun Mar 23 18:58:00 CET 2003
#      make the script robust against whitespace in filenames
#   Mon Jan 27 22:38:44 CET 2003
#      don't call a function before processOptions; we may loose our
#      argument list with some broken shells
#   Mon Jan 27 06:55:28 CET 2003
#      fix unportable egrep / sed
#   Sat Jan 18 10:10:26 CET 2003
#      use $tmp8 in dvips2dvipdfm()
#   Thu Jan  2 23:14:34 CET 2003
#      add umask 022, so generated files are always world-readable
#   Sun Oct 27 11:33:04 CET 2002
#      write output in normalized format
#      add support for dvipdfm
#   Mon Sep 22 19:18:57 CEST 2002
#      fix typo: buildin -> builtin
#   Mon Sep  2 19:18:57 CEST 2002
#      fix condensed <-> narrow mapping
#   Sun Sep  1 15:02:28 CEST 2002
#      add dvipsDownloadBase35 / pdftexDownloadBase14 options
#   Wed May 22 20:00:13 CEST 2002
#      listmaps option added by Gerben Wierda
#   Tue May 21 05:27:37 CEST 2002
#      now removing map files before rewriting them; fixes permission problems
#   Tue May 21 05:05:34 CEST 2002:
#      cli options added: showoptions, setoption, enable, disable, nomkmap
#      now even more verbose; now reporting non-existing map files
#      fixing trap for MAC OS/X compatibility
#   Fri May 17 22:38:37 CEST 2002:
#      rewritten from teTeX-1.0 version; Completely new designed.
###############################################################################

test -f /bin/ksh && test -z "$RUNNING_KSH" \
  && { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \
  && { RUNNING_KSH=true; export RUNNING_KSH; exec /bin/ksh $0 ${1+"$@"}; }
unset RUNNING_KSH

test -f /bin/bsh && test -z "$RUNNING_BSH" \
  && { UNAMES=`uname -s`; test "x$UNAMES" = xAIX; } 2>/dev/null \
  && { RUNNING_BSH=true; export RUNNING_BSH; exec /bin/bsh $0 ${1+"$@"}; }
unset RUNNING_BSH

export PATH

# hack around a bug in zsh:
test -n "${ZSH_VERSION+set}" && alias -g '${1+"$@"}'='"$@"'

# the version string
version=1211742332 # seconds since `00:00:00 1970-01-01 UTC'
                   # date '+%s' (with GNU date)

# 
###############################################################################
# help()
#   display help message and exit
###############################################################################
help()
{
  cat <<eof
Usage: updmap [OPTION]...  [COMMAND]...

Update the default font map files used by pdftex, dvips, and dvipdfm, as
determined by updmap.cfg.  Among other things, these font map files are
used to determine which fonts should be found as bitmaps and which as
outlines, and to determine which fonts are included in the output.

By default, the filename database is also rebuilt (with mktexlsr).

Valid options:
  --cnffile FILE            read FILE for the updmap configuration
  --pdftexoutputdir DIR     specify output directory (pdftex syntax)
  --dvipsoutputdir DIR      specify output directory (dvips syntax)
  --dvipdfmoutputdir DIR    specify output directory (dvipdfm syntax)
  --outputdir DIR           specify output directory (for all files)
  --copy                    cp generic files rather than using symlinks
  --nomkmap                 do not recreate map files
  --nohash                  do not run texhash
  -n, --dry-run             only show the configuration, no output
  --quiet                   reduce verbosity

Valid commands:
  --help                    show this message
  --edit                    edit $cnfFileShort file
  --showoptions ITEM        show alternatives for options
  --setoption OPTION VALUE  set option, where OPTION is one of:
                             dvipsPreferOutline LW35 dvipsDownloadBase35
                             pdftexDownloadBase14 dvipdfmDownloadBase14
  --setoption OPTION=VALUE  see above, just different syntax
  --enable MAPTYPE MAPFILE  add MAPFILE as a MAPTYPE, one of: Map MixedMap
  --enable Map=MAPFILE      add MAPFILE as a Map
  --enable MixedMap=MAPFILE add or enable MAPFILE as a MixedMap
  --disable MAPFILE         disable MAPFILE, whether Map or MixedMap
  --syncwithtrees           entries with unavailable map files will be
                             disabled in the config file
  --listmaps                list all active and inactive maps
  --listavailablemaps       same as --listmaps, but without
                             unavailable map files

Explanation of the map types: the (only) difference between Map and
MixedMap is that MixedMap entries are not added to psfonts_pk.map.  The
purpose is to help users with printers that render Type 1 outline fonts
worse than mode-tuned Type 1 bitmap fonts.  So MixedMap is used for
fonts that are available as both Type 1 and Metafont.

To see the precise locations of the various files that will be read and
written, run updmap -n.

Report bugs to <tex-k@tug.org>.
eof
  (exit 0); exit
}

###############################################################################
# verboseMsg(msg)
#   print `msg' to stderr is $verbose is true
###############################################################################
verboseMsg() {
  test -n "$log" && echo ${1+"$@"} >> "$log"
  $verbose && echo ${1+"$@"} >&2
}

###############################################################################
# verboseCat()
#   cat to stderr is $verbose is true
###############################################################################
verboseCat() {
  if $verbose; then
    if test -n "$log"; then
      cat ${1+"$@"} | tee -a "$log" >&2
    else
      cat ${1+"$@"} >&2
    fi
  else
    test -n "$log" && cat ${1+"$@"} >> "$log"
  fi
}

###############################################################################
# warn(msg)
#   print `msg' to stderr
###############################################################################
warn()
{
  test -n "$log" && echo ${1+"$@"} >> "$log"
  echo ${1+"$@"} >&2
}

###############################################################################
# abort(errmsg)
#   print `errmsg' to stderr and exit with error code 1
###############################################################################
abort()
{
  warn "$progname: $1."
  cleanup 1
}

###############################################################################
# cfgval(variable)
#   read variable ($1) from config file, first match wins
###############################################################################
cfgval()
{
  cat "$cnfFile" | sed -n 's/^'"$1"'[	 =][	 =]*//p' | sed q
}

###############################################################################
# symlink_or_copy()
#   if --copy is not set, try to create a symlink.  If this fails, write 
#   a message to stderr and copy the file instead.
###############################################################################
symlink_or_copy()
{
  if $copy; then
    $copy_cmd "$1" "$2"
  else
    $link_cmd "$1" "$2" ||
    {
    echo "Creating symbolic link failed, the file is copied instead." 1>&2 &&
    $copy_cmd "$1" "$2"
    }
  fi
}

###############################################################################
# setupSymlinks()
#   set symlink (or copy)
#    for psfonts.map according to dvipsPreferOutline variable,
#    and for pdftex.map and dvipdfm.map according to pdftexDownloadBase14.
###############################################################################
setupSymlinks()
{
  (
  cd "$dvipsoutputdir" || exit 1
  rm -f psfonts.map
  if test "x$dvipsPreferOutline" = xtrue; then
    symlink_or_copy psfonts_t1.map psfonts.map
  else
    symlink_or_copy psfonts_pk.map psfonts.map
  fi

  cd "$pdftexoutputdir" || exit 1
  rm -f pdftex.map
  if test "x$pdftexDownloadBase14" = xtrue; then
    symlink_or_copy pdftex_dl14.map pdftex.map
  else
    symlink_or_copy pdftex_ndl14.map pdftex.map
  fi

  cd "$dvipdfmoutputdir" || exit 1
  rm -f dvipdfm.map
  if test "x$dvipdfmDownloadBase14" = xtrue; then
    symlink_or_copy dvipdfm_dl14.map dvipdfm.map
  else
    symlink_or_copy dvipdfm_ndl14.map dvipdfm.map
  fi
  )
}

###############################################################################
# transLW35(args ...)
#   transform fontname and filenames according to transformation specified
#   by mode
###############################################################################
transLW35()
{
  case $mode in
    ""|URWkb)
      cat ${1+"$@"}
      ;;
    URW)
      fileURW ${1+"$@"}
      ;;
    ADOBE|ADOBEkb)
      psADOBE ${1+"$@"} | file$mode
      ;;
  esac
}

###############################################################################
# catMaps(regex)
#   filter config file by regex for map lines and extract the map filenames.
#   These are then looked up (by kpsewhich in locateMap) and the content of
#   all map files is send to stdout.
###############################################################################
catMaps()
{
  rm -f $catMapsFailed
  egrep "$1" "$cnfFile" \
    | sed 's@#.*@@' \
       | awk '{print $2}' \
       | sort \
       | uniq \
       | grep . > $tmp4

  while read map; do
    file=`locateMap "$map"` || { touch $catMapsFailed; break; }

    # output the file; also output a newline, because the final newline
    # might be missing in the map file; Empty lines are filtered out later,
    # so it does not really hurt do do this here.
    test -n "$file" && { cat "$file"; echo; }
  done < $tmp4
  if test -f $catMapsFailed; then
    false; return 1
  else
    true; return 0
  fi
}

###############################################################################
# configReplace(file, pattern, line)
#   The first line in file that matches pattern gets replaced by line.
#   line will be added at the end of the file if pattern does not match.
###############################################################################
configReplace()
{
  file=$1; pat=$2; line=$3

  if grep "$pat" "$file" >/dev/null; then
    ed "$file" >/dev/null 2>&1 <<-eof
	/$pat/
	c
	$line
	.
	w
	q
eof
  else
    echo "$line" >> "$file"
  fi
}

###############################################################################
# setOption (option, value)
#   sets option to value in the config file (replacing the existing setting
#   or by adding a new line to the config file).
###############################################################################
setOption()
{
  opt=$1
  val=$2
  case "$opt" in
    LW35)
      case "$val" in
        URWkb|URW|ADOBE|ADOBEkb)
          ;;
        *)
          abort "invalid value $val for option $opt"
          ;;
      esac
      ;;
    dvipsPreferOutline|dvipsDownloadBase35|pdftexDownloadBase14|dvipdfmDownloadBase14)
      case "$val" in
        true|false)
          ;;
        *)
          abort "invalid value $val for option $opt"
      esac
      ;;
    *)
      abort "unsupported option $opt"
      ;;
  esac

  configReplace "$cnfFile" "^$opt[ 	]" "$opt $val"
}

###############################################################################
# enableMap (type, map)
#   enables an entry in the config file for map with a given type.
###############################################################################
enableMap()
{
  case $1 in
    Map|MixedMap)
      ;;
    *)
      abort "invalid mapType $1"
      ;;
  esac

  # a map can only have one type, so we carefully disable everything
  # about map here:
  disableMap "$2"

  # now enable with the right type:
  configReplace "$cnfFile" "^#![ 	]*$1[ 	]*$2" "$1 $2"
}

###############################################################################
# disableMap (map)
#   disables map in config file (any type)
###############################################################################
disableMap()
{
  #mapType=`awk '($1 == "MixedMap" || $1 == "Map") && $2 == map { print $1 }' \
  #           map=$1 <"$cnfFile" | sort | uniq`
  map=$1
  mapType=`egrep "^(MixedMap|Map)[ 	]*$map( |	|$)" "$cnfFile" | awk '{print $1}' | sort | uniq`
  for type in $mapType; do
    configReplace "$cnfFile" "^$type[ 	]*$1" "#! $type $1"
  done
}

###############################################################################
# psADOBE()
#   transform fontnames from URW to Adobe
###############################################################################
psADOBE()
{
  sed \
    -e 's/ URWGothicL-Demi / AvantGarde-Demi /' \
    -e 's/ URWGothicL-DemiObli / AvantGarde-DemiOblique /' \
    -e 's/ URWGothicL-Book / AvantGarde-Book /' \
    -e 's/ URWGothicL-BookObli / AvantGarde-BookOblique /' \
    -e 's/ URWBookmanL-DemiBold / Bookman-Demi /' \
    -e 's/ URWBookmanL-DemiBoldItal / Bookman-DemiItalic /' \
    -e 's/ URWBookmanL-Ligh / Bookman-Light /' \
    -e 's/ URWBookmanL-LighItal / Bookman-LightItalic /' \
    -e 's/ NimbusMonL-Bold / Courier-Bold /' \
    -e 's/ NimbusMonL-BoldObli / Courier-BoldOblique /' \
    -e 's/ NimbusMonL-Regu / Courier /' \
    -e 's/ NimbusMonL-ReguObli / Courier-Oblique /' \
    -e 's/ NimbusSanL-Bold / Helvetica-Bold /' \
    -e 's/ NimbusSanL-BoldCond / Helvetica-Narrow-Bold /' \
    -e 's/ NimbusSanL-BoldItal / Helvetica-BoldOblique /' \
    -e 's/ NimbusSanL-BoldCondItal / Helvetica-Narrow-BoldOblique /' \
    -e 's/ NimbusSanL-Regu / Helvetica /' \
    -e 's/ NimbusSanL-ReguCond / Helvetica-Narrow /' \
    -e 's/ NimbusSanL-ReguItal / Helvetica-Oblique /' \
    -e 's/ NimbusSanL-ReguCondItal / Helvetica-Narrow-Oblique /' \
    -e 's/ CenturySchL-Bold / NewCenturySchlbk-Bold /' \
    -e 's/ CenturySchL-BoldItal / NewCenturySchlbk-BoldItalic /' \
    -e 's/ CenturySchL-Roma / NewCenturySchlbk-Roman /' \
    -e 's/ CenturySchL-Ital / NewCenturySchlbk-Italic /' \
    -e 's/ URWPalladioL-Bold / Palatino-Bold /' \
    -e 's/ URWPalladioL-BoldItal / Palatino-BoldItalic /' \
    -e 's/ URWPalladioL-Roma / Palatino-Roman /' \
    -e 's/ URWPalladioL-Ital / Palatino-Italic /' \
    -e 's/ StandardSymL / Symbol /' \
    -e 's/ NimbusRomNo9L-Medi / Times-Bold /' \
    -e 's/ NimbusRomNo9L-MediItal / Times-BoldItalic /' \
    -e 's/ NimbusRomNo9L-Regu / Times-Roman /' \
    -e 's/ NimbusRomNo9L-ReguItal / Times-Italic /' \
    -e 's/ URWChanceryL-MediItal / ZapfChancery-MediumItalic /' \
    -e 's/ Dingbats / ZapfDingbats /' \
    ${1+"$@"}
}

###############################################################################
# fileADOBEkb()
#   transform filenames from URW to ADOBE (both berry names)
###############################################################################
fileADOBEkb()
{
  sed \
    -e 's/\([^A-Za-z]\)uagd8a.pfb/\1pagd8a.pfb/' \
    -e 's/\([^A-Za-z]\)uagdo8a.pfb/\1pagdo8a.pfb/' \
    -e 's/\([^A-Za-z]\)uagk8a.pfb/\1pagk8a.pfb/' \
    -e 's/\([^A-Za-z]\)uagko8a.pfb/\1pagko8a.pfb/' \
    -e 's/\([^A-Za-z]\)ubkd8a.pfb/\1pbkd8a.pfb/' \
    -e 's/\([^A-Za-z]\)ubkdi8a.pfb/\1pbkdi8a.pfb/' \
    -e 's/\([^A-Za-z]\)ubkl8a.pfb/\1pbkl8a.pfb/' \
    -e 's/\([^A-Za-z]\)ubkli8a.pfb/\1pbkli8a.pfb/' \
    -e 's/\([^A-Za-z]\)ucrb8a.pfb/\1pcrb8a.pfb/' \
    -e 's/\([^A-Za-z]\)ucrbo8a.pfb/\1pcrbo8a.pfb/' \
    -e 's/\([^A-Za-z]\)ucrr8a.pfb/\1pcrr8a.pfb/' \
    -e 's/\([^A-Za-z]\)ucrro8a.pfb/\1pcrro8a.pfb/' \
    -e 's/\([^A-Za-z]\)uhvb8a.pfb/\1phvb8a.pfb/' \
    -e 's/\([^A-Za-z]\)uhvb8ac.pfb/\1phvb8an.pfb/' \
    -e 's/\([^A-Za-z]\)uhvbo8a.pfb/\1phvbo8a.pfb/' \
    -e 's/\([^A-Za-z]\)uhvbo8ac.pfb/\1phvbo8an.pfb/' \
    -e 's/\([^A-Za-z]\)uhvr8a.pfb/\1phvr8a.pfb/' \
    -e 's/\([^A-Za-z]\)uhvr8ac.pfb/\1phvr8an.pfb/' \
    -e 's/\([^A-Za-z]\)uhvro8a.pfb/\1phvro8a.pfb/' \
    -e 's/\([^A-Za-z]\)uhvro8ac.pfb/\1phvro8an.pfb/' \
    -e 's/\([^A-Za-z]\)uncb8a.pfb/\1pncb8a.pfb/' \
    -e 's/\([^A-Za-z]\)uncbi8a.pfb/\1pncbi8a.pfb/' \
    -e 's/\([^A-Za-z]\)uncr8a.pfb/\1pncr8a.pfb/' \
    -e 's/\([^A-Za-z]\)uncri8a.pfb/\1pncri8a.pfb/' \
    -e 's/\([^A-Za-z]\)uplb8a.pfb/\1pplb8a.pfb/' \
    -e 's/\([^A-Za-z]\)uplbi8a.pfb/\1pplbi8a.pfb/' \
    -e 's/\([^A-Za-z]\)uplr8a.pfb/\1pplr8a.pfb/' \
    -e 's/\([^A-Za-z]\)uplri8a.pfb/\1pplri8a.pfb/' \
    -e 's/\([^A-Za-z]\)usyr.pfb/\1psyr.pfb/' \
    -e 's/\([^A-Za-z]\)utmb8a.pfb/\1ptmb8a.pfb/' \
    -e 's/\([^A-Za-z]\)utmbi8a.pfb/\1ptmbi8a.pfb/' \
    -e 's/\([^A-Za-z]\)utmr8a.pfb/\1ptmr8a.pfb/' \
    -e 's/\([^A-Za-z]\)utmri8a.pfb/\1ptmri8a.pfb/' \
    -e 's/\([^A-Za-z]\)uzcmi8a.pfb/\1pzcmi8a.pfb/' \
    -e 's/\([^A-Za-z]\)uzdr.pfb/\1pzdr.pfb/' \
    ${1+"$@"}
}

###############################################################################
# fileURW()
#   transform filenames from URWkb (berry names) to URW (vendor names)
###############################################################################
fileURW()
{
  sed \
    -e 's/\([^A-Za-z]\)uagd8a.pfb/\1a010015l.pfb/' \
    -e 's/\([^A-Za-z]\)uagdo8a.pfb/\1a010035l.pfb/' \
    -e 's/\([^A-Za-z]\)uagk8a.pfb/\1a010013l.pfb/' \
    -e 's/\([^A-Za-z]\)uagko8a.pfb/\1a010033l.pfb/' \
    -e 's/\([^A-Za-z]\)ubkd8a.pfb/\1b018015l.pfb/' \
    -e 's/\([^A-Za-z]\)ubkdi8a.pfb/\1b018035l.pfb/' \
    -e 's/\([^A-Za-z]\)ubkl8a.pfb/\1b018012l.pfb/' \
    -e 's/\([^A-Za-z]\)ubkli8a.pfb/\1b018032l.pfb/' \
    -e 's/\([^A-Za-z]\)ucrb8a.pfb/\1n022004l.pfb/' \
    -e 's/\([^A-Za-z]\)ucrbo8a.pfb/\1n022024l.pfb/' \
    -e 's/\([^A-Za-z]\)ucrr8a.pfb/\1n022003l.pfb/' \
    -e 's/\([^A-Za-z]\)ucrro8a.pfb/\1n022023l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvb8a.pfb/\1n019004l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvb8ac.pfb/\1n019044l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvbo8a.pfb/\1n019024l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvbo8ac.pfb/\1n019064l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvr8a.pfb/\1n019003l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvr8ac.pfb/\1n019043l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvro8a.pfb/\1n019023l.pfb/' \
    -e 's/\([^A-Za-z]\)uhvro8ac.pfb/\1n019063l.pfb/' \
    -e 's/\([^A-Za-z]\)uncb8a.pfb/\1c059016l.pfb/' \
    -e 's/\([^A-Za-z]\)uncbi8a.pfb/\1c059036l.pfb/' \
    -e 's/\([^A-Za-z]\)uncr8a.pfb/\1c059013l.pfb/' \
    -e 's/\([^A-Za-z]\)uncri8a.pfb/\1c059033l.pfb/' \
    -e 's/\([^A-Za-z]\)uplb8a.pfb/\1p052004l.pfb/' \
    -e 's/\([^A-Za-z]\)uplbi8a.pfb/\1p052024l.pfb/' \
    -e 's/\([^A-Za-z]\)uplr8a.pfb/\1p052003l.pfb/' \
    -e 's/\([^A-Za-z]\)uplri8a.pfb/\1p052023l.pfb/' \
    -e 's/\([^A-Za-z]\)usyr.pfb/\1s050000l.pfb/' \
    -e 's/\([^A-Za-z]\)utmb8a.pfb/\1n021004l.pfb/' \
    -e 's/\([^A-Za-z]\)utmbi8a.pfb/\1n021024l.pfb/' \
    -e 's/\([^A-Za-z]\)utmr8a.pfb/\1n021003l.pfb/' \
    -e 's/\([^A-Za-z]\)utmri8a.pfb/\1n021023l.pfb/' \
    -e 's/\([^A-Za-z]\)uzcmi8a.pfb/\1z003034l.pfb/' \
    -e 's/\([^A-Za-z]\)uzdr.pfb/\1d050000l.pfb/' \
    ${1+"$@"}
}

###############################################################################
# fileADOBE()
#   transform filenames from URWkb (berry names) to ADOBE (vendor names)
###############################################################################
fileADOBE()
{
  sed \
    -e 's/\([^A-Za-z]\)uagd8a.pfb/\1agd_____.pfb/' \
    -e 's/\([^A-Za-z]\)uagdo8a.pfb/\1agdo____.pfb/' \
    -e 's/\([^A-Za-z]\)uagk8a.pfb/\1agw_____.pfb/' \
    -e 's/\([^A-Za-z]\)uagko8a.pfb/\1agwo____.pfb/' \
    -e 's/\([^A-Za-z]\)ubkd8a.pfb/\1bkd_____.pfb/' \
    -e 's/\([^A-Za-z]\)ubkdi8a.pfb/\1bkdi____.pfb/' \
    -e 's/\([^A-Za-z]\)ubkl8a.pfb/\1bkl_____.pfb/' \
    -e 's/\([^A-Za-z]\)ubkli8a.pfb/\1bkli____.pfb/' \
    -e 's/\([^A-Za-z]\)ucrb8a.pfb/\1cob_____.pfb/' \
    -e 's/\([^A-Za-z]\)ucrbo8a.pfb/\1cobo____.pfb/' \
    -e 's/\([^A-Za-z]\)ucrr8a.pfb/\1com_____.pfb/' \
    -e 's/\([^A-Za-z]\)ucrro8a.pfb/\1coo_____.pfb/' \
    -e 's/\([^A-Za-z]\)uhvb8a.pfb/\1hvb_____.pfb/' \
    -e 's/\([^A-Za-z]\)uhvb8ac.pfb/\1hvnb____.pfb/' \
    -e 's/\([^A-Za-z]\)uhvbo8a.pfb/\1hvbo____.pfb/' \
    -e 's/\([^A-Za-z]\)uhvbo8ac.pfb/\1hvnbo___.pfb/' \
    -e 's/\([^A-Za-z]\)uhvr8a.pfb/\1hv______.pfb/' \
    -e 's/\([^A-Za-z]\)uhvr8ac.pfb/\1hvn_____.pfb/' \
    -e 's/\([^A-Za-z]\)uhvro8a.pfb/\1hvo_____.pfb/' \
    -e 's/\([^A-Za-z]\)uhvro8ac.pfb/\1hvno____.pfb/' \
    -e 's/\([^A-Za-z]\)uncb8a.pfb/\1ncb_____.pfb/' \
    -e 's/\([^A-Za-z]\)uncbi8a.pfb/\1ncbi____.pfb/' \
    -e 's/\([^A-Za-z]\)uncr8a.pfb/\1ncr_____.pfb/' \
    -e 's/\([^A-Za-z]\)uncri8a.pfb/\1nci_____.pfb/' \
    -e 's/\([^A-Za-z]\)uplb8a.pfb/\1pob_____.pfb/' \
    -e 's/\([^A-Za-z]\)uplbi8a.pfb/\1pobi____.pfb/' \
    -e 's/\([^A-Za-z]\)uplr8a.pfb/\1por_____.pfb/' \
    -e 's/\([^A-Za-z]\)uplri8a.pfb/\1poi_____.pfb/' \
    -e 's/\([^A-Za-z]\)usyr.pfb/\1sy______.pfb/' \
    -e 's/\([^A-Za-z]\)utmb8a.pfb/\1tib_____.pfb/' \
    -e 's/\([^A-Za-z]\)utmbi8a.pfb/\1tibi____.pfb/' \
    -e 's/\([^A-Za-z]\)utmr8a.pfb/\1tir_____.pfb/' \
    -e 's/\([^A-Za-z]\)utmri8a.pfb/\1tii_____.pfb/' \
    -e 's/\([^A-Za-z]\)uzcmi8a.pfb/\1zcmi____.pfb/' \
    -e 's/\([^A-Za-z]\)uzdr.pfb/\1zd______.pfb/' \
    ${1+"$@"}
}

###############################################################################
# locateWeb2c (file ...)
#   apply kpsewhich with format 'web2c files'
###############################################################################
locateWeb2c()
{
  kpsewhich --format='web2c files' ${1+"$@"}
}

###############################################################################
# locateMap (file ...)
#   apply kpsewhich with format 'map'
###############################################################################
locateMap()
{

  # Always use the "migration checking version". This might become
  # consigurable, but for now, we always want to check.
  if :; then
    locateMapMigrate "$@"
    return $?
  fi

  # The old version of the code; not used at the moment.
  for map
  do
    file=`kpsewhich --format=map "$map"`
    if test -f "$file"; then
      verboseMsg "$progname: using map file \`$file'"
      echo "$file"
    else
      warn "map file \`$map' not found."
    fi
  done
}

###############################################################################
# locateMapMigrate (file ...)
#   look for map file; assist user with possibly files in wrong locations;
#   also watch out for possibly hidden conflicts
###############################################################################
locateMapMigrate()
{
  for map
  do
    # look up using the new search path
    file=`kpsewhich --format=map "$map"`

    # look up using the old search path
    file2=`kpsewhich --format='dvips config' "$map"`

    # Well, the search paths should not overlap. If they do, and if
    # file1 = file2, we don't want to complain about file2, so:
    test "x$file" = "x$file2" && file2=

    if test -f "$file"; then

      verboseMsg "$progname: using map file \`$file'"
      echo "$file"

      # we have found the file where we should. If we have additional
      # ones: complain!
      if test -f "$file2"; then
        mapCmp "$file" "$file2" \
          && mapWarn obsoleteCopy "$map" "$file2" \
          || mapWarn manualResolve "$map" "$file" "$file2"
      fi

    else
      if test -f "$file2"; then
        # bad: map file exists in the wrong location only
        mapWarn badLocation "$map" "$file2"
      else
        # bad: map file does not exist at all
        mapWarn notFound "$map"
      fi
      false; return 1
    fi
  done
  true; return 0
}

###############################################################################
# mapCmp(file, file2)
#   compare two map files like cmp; but less strict, so changes regarding
#   whitespaces, comments etc. are tolerated. Important is only the
#   return value here.
###############################################################################
mapCmp()
{
  file=$1; file2=$2

  # For reasons of speed only. Avoid normalizeLines if files are 100%
  # the same.
  cmp "$file" "$file2" >/dev/null 2>&1 && return 0

  normalizeLines <"$file" >"$tmpdir/mapCmp-1"
  normalizeLines <"$file2" >"$tmpdir/mapCmp-2"
  cmp "$tmpdir/mapCmp-1" "$tmpdir/mapCmp-2" >/dev/null 2>&1
}

###############################################################################
# mapWarn()
###############################################################################
mapWarn()
{

  case $1 in
  obsoleteCopy)
    warn "
!!! WARNING: Identical copy of used file for \`$2'
    exists in obsolete location
      $3
    Please, consider removing this file.
"
    touch $mapWarnCalled
    ;;
  manualResolve)
    warn "
!!! WARNING: While searching for the right map file for \`$2', we have
    found the file
      $3
    in the right location and we are using this
    file. However, a map file with different content has been found in
    the obsolete location
      $4
    Please, see which version you want to use and eventually update the
    content of the used map file. Additionally, consider removing the
    obsolete file.
"
    touch $mapWarnCalled
    ;;
  badLocation)
    map=$2
    location=$3

    m="
!!! ERROR: The right location for map files has been
    changed for this release and the map file \`$map' has
    not been found in the right location, but in the obsolete
    location
      $location
    instead.

    To fix this, please move this file into an appropriate
    subdirectory of fonts/map in one of your texmf trees.

    For more information about the changed search paths, see
    the release notes section in the teTeX manual. You probably
    can read this document by executing the command
      texdoc TETEXDOC
    else visit the web page
      http://tug.org/texlive/mapenc.html
"
    warn "$m"
    false; return 1
    ;;
  notFound)
    warn "
!!! ERROR! The map file \`$2' has not been found at all.

    Either put this file into the right place or remove the
    reference from the configuration file. An automatic way
    to disable unavailable map files is to call
      $progname --syncwithtrees

    For manual editing, call
      $progname --edit
"

    false; return 1
    ;;
  esac
}

###############################################################################
# cleanup()
#   clean up the temp area and exit with proper exit status
###############################################################################
cleanup()
{
  rc=$1
  $needsCleanup && test -n "$tmpdir" && test -d "$tmpdir" \
    && { cd / && rm -rf "$tmpdir"; }
  (exit $rc); exit $rc
}

###############################################################################
# setupTmpDir()
#   set up a temp directory and a trap to remove it
###############################################################################
setupTmpDir()
{
  $needsCleanup && return

  trap 'cleanup 1' 1 2 3 7 13 15
  needsCleanup=true
  mkdir "$tmpdir" || abort "could not create directory \`$tmpdir'"
}

###############################################################################
# showOptions(item)
#   show Options for an item
###############################################################################
showOptions()
{
  item=$1

  case "$item" in
    LW35)
      echo "URWkb URW ADOBE ADOBEkb"
      ;;
    dvipsPreferOutline|pdftexDownloadBase14|dvipdfmDownloadBase14|dvipsDownloadBase35)
      echo "true false"
      ;;
    *)
      abort "Unknown item \"$item\". Choose one of LW35, dvipsPreferOutline, dvipsDownloadBase35, pdftexDownloadBase14 or dvipdfmDownloadBase14"
      ;;
  esac

  (exit 0); exit 0
}

###############################################################################
# mktexdir(args)
#   call mktexdir script, disable all features (to prevent sticky directories)
###############################################################################
mktexdir()
{
  MT_FEATURES=none "$TEXMFMAIN/web2c/mktexdir" "$@" >&2
}

###############################################################################
# setupDestDir()
#   Assign output directories which are not yet assigned. Always use
#   the TEXMFVAR for this.
###############################################################################
setupDestDir()
{
  vartexmf=`kpsewhich -var-value=TEXMFVAR`

  # dvips
  if test -z "$dvipsoutputdir"; then
    dvipsoutputdir=$vartexmf/fonts/map/dvips/updmap
  fi

  # pdftex
  if test -z "$pdftexoutputdir"; then
    pdftexoutputdir=$vartexmf/fonts/map/pdftex/updmap
  fi

  # dvipdfm
  if test -z "$dvipdfmoutputdir"; then
    dvipdfmoutputdir=$vartexmf/fonts/map/dvipdfm/updmap
  fi

  mktexdir "$dvipsoutputdir" "$pdftexoutputdir" "$dvipdfmoutputdir" >/dev/null 2>&1
  for d in "$dvipsoutputdir" "$pdftexoutputdir" "$dvipdfmoutputdir"; do
    test -d "$d" || abort "output directory \`$d' does not exist"
    test -w "$d" || abort "output directory \`$d' is not writable"
  done

}

###############################################################################
# setupLog(cfgFile)
#   try to set up a log file in $TEXMFVAR/web2c
###############################################################################
setupLog()
{
  vartexmf=`kpsewhich -var-value=TEXMFVAR`
  dir=$vartexmf/web2c
  mktexdir "$dir" >/dev/null 2>&1
  log="$dir/$progname.log"
  if test -d "$dir" && test -w "$dir"; then
    rm -f "$log"
    > "$log"
  fi
  if test -w "$log"; then
    if $chicken_mode; then
      log=
    else
      date > "$log"
      verboseMsg "$progname: This is $progname, version $version"
      verboseMsg "$progname: using transcript file \`$log'"
    fi
  else
    log=
    verboseMsg "$progname: This is $progname, version $version"
    verboseMsg "$progname: no permissions for writing $dir/$progname.log', so no transcript"
  fi
}

###############################################################################
# setupCfgFile()
#   find config file if none specified on cmd line.
###############################################################################
setupCfgFile()
{
  case "$cnfFile" in
    "") cnfFile=`locateWeb2c $cnfFileShort`
        case "$cnfFile" in
          "") abort "config file $cnfFileShort not found"
        esac;;
  esac
  setupLog
}

###############################################################################
# processOptions()
#   process cmd line options
###############################################################################
processOptions()
{
  while
    case $1 in
      --quiet|-q)
          verbose=false;;
      --cnffile)
          cfgparam=1; cnfFile=$2; shift;;
      --cnffile=*)
          cfgparam=1; cnfFile=`echo "$1" | sed 's/--cnffile=//'`;;
      --copy)
          copy=true;;
      --dry-run|-n)
          chicken_mode=true;;
      --dvipsoutputdir)
          dvipsoutputdirparam=1; dvipsoutputdir=$2; shift;;
      --dvipsoutputdir=*)
          dvipsoutputdirparam=1; dvipsoutputdir=`echo "$1" | sed 's/--dvipsoutputdir=//'`;;
      --pdftexoutputdir)
          pdftexoutputdirparam=1; pdftexoutputdir=$2; shift;;
      --pdftexoutputdir=*)
          pdftexoutputdirparam=1; pdftexoutputdir=`echo "$1" | sed 's/--pdftexoutputdir=//'`;;
      --dvipdfmoutputdir)
          dvipdfmoutputdirparam=1; dvipdfmoutputdir=$2; shift;;
      --dvipdfmoutputdir=*)
          dvipdfmoutputdirparam=1; dvipdfmoutputdir=`echo "$1" | sed 's/--dvipdfmoutputdir=//'`;;
      --outputdir)
          dvipsoutputdirparam=1; dvipsoutputdir=$2
          pdftexoutputdirparam=1; pdftexoutputdir=$2
          dvipdfmoutputdirparam=1; dvipdfmoutputdir=$2
          shift
          ;;
      --outputdir=*)
          outputdir=`echo "$1" | sed 's/--outputdir=//'`
          dvipsoutputdirparam=1; dvipsoutputdir=$outputdir
          pdftexoutputdirparam=1; pdftexoutputdir=$outputdir
          dvipdfmoutputdirparam=1; dvipdfmoutputdir=$outputdir
          ;;
      --setoption)
          cfgmaint=1
          cmd=setoption
          case $2 in
            *=*)
              setoptionOpt=`echo $2 | sed 's@=.*@@'`
              setoptionVal=`echo $2 | sed 's@[^=]*=@@'`
              shift
            ;;
            *)
              test $# -ge 3 || { abort "--setoption needs two parameters: option value"; }
              setoptionOpt=$2; setoptionVal=$3; shift; shift
            ;;
          esac
          ;;
      --enable)
          cfgmaint=1
          cmd=enable
          case $2 in 
            Map=*)
              enableMapType=Map; enableMapFile=`echo "$2" | sed 's/Map=//'`; shift;;
            MixedMap=*)
              enableMapType=MixedMap; enableMapFile=`echo "$2" | sed 's/MixedMap=//'`; shift;;
            Map|MixedMap)
              test $# -ge 3 || { abort "--enable needs two parameters: mapType mapFile"; }
              enableMapType=$2; enableMapFile=$3; shift; shift;;
            *)
              abort "--enable needs two parameters mapType mapFile";;
          esac
          ;;
      --syncwithtrees)
          cfgmaint=1
          cmd=syncwithtrees;;
      --disable)
          cfgmaint=1
          cmd=disable; disableMapFile=$2; shift
          ;;
      --disable=*)
          cfgmaint=1
          disableMapFile=`echo "$1" | sed 's/--disable=//'`
          cmd=disable
          ;;
      --edit|-e)
          cfgmaint=1
          cmd=edit;;
      --listmaps|-l)
          cmd=listmaps;;
      --listavailablemaps)
          cmd=listavailablemaps;;
      --showoptions)
          cmd=showoptions; showoptionsItem=$2; shift;;
      --showoptions=*)
          cmd=showoptions; showoptionsItem=`echo "$1" | sed 's/--showoptions=//'`;;
     
      --nohash)
          texhashEnabled=false;;
      --nomkmap)
          mkmapEnabled=false;;
      --help|-help|-h)
          help;;
      --version)
          echo "$progname version $version."; (exit 0); exit 0;;
      "") break;;
      *) abort "$progname: unknown option \`$1'. Try $progname --help for help";;
    esac
  do test $# -gt 0 && shift; done

  if test -n "$cfgparam"; then
    if test -z "$cnfFile" || test ! -f "$cnfFile"; then
      abort "config file \`$cnfFileShort' not found"
    fi
  fi

  if test -n "$dvipdoutputdirparam"; then
    if test -z "$dvipdoutputdir" || test ! -d "$dvipdoutputdir"; then
      abort "dvips output directory \`$1' not found"
    fi
  fi
  if test -n "$pdftexoutputdirparam"; then
    if test -z "$pdftexoutputdir" || test ! -d "$pdftexoutputdir"; then
      abort "pdftex output directory \`$1' not found"
    fi
  fi
  if test -n "$dvipdfmoutputdirparam"; then
    if test -z "$dvipdfmoutputdir" || test ! -d "$dvipdfmoutputdir"; then
      abort "dvipdfm output directory \`$1' not found"
    fi
  fi

}

###############################################################################
# listMaps()
#   list all maps mentioned in the config file
###############################################################################
listMaps()
{
  egrep '^(#! *)?(Mixed)?Map' "$cnfFile"
}

###############################################################################
# listAvailableMaps()
#   list maps mentioned in the config file if they are available
###############################################################################
listAvailableMaps()
{
  # loop over each possible line in the config file (-> $line)
  # extract the name of the map file (-> $m)
  # check if the map file exists and in that case echo the line
  OLDIFS=$IFS
  IFS='
'
  for line in `egrep '^(#! *)?(Mixed)?Map' "$cnfFile"`; do
    m=`echo "$line" | sed 's@[ 	]*$@@; s@.*[ 	]@@'`
    kpsewhich --format=map "$m" >/dev/null && echo "$line"
  done
  IFS=$OLDIFS
}

###############################################################################
# syncWithTrees()
#   update the config file: uncomment all lines which refer to map files that
#   are unavailabe in the texmf trees
###############################################################################
syncWithTrees()
{
  for i in `egrep '^(Mixed)?Map' "$cnfFile" | sed 's@.* @@'`; do
    kpsewhich --format=map "$i" >/dev/null || echo "$i"
  done > $tmp1
  {
    sed 's@/@\\/@g; s@^@/^MixedMap[ 	]*@; s@$@$/s/^/#! /@' <$tmp1
    sed 's@/@\\/@g; s@^@/^Map[ 	]*@; s@$@$/s/^/#! /@' <$tmp1
  } > $tmp2
  sed -f $tmp2 "$cnfFile" > $tmp3 && cat $tmp3 > "$cnfFile"
}

###############################################################################
# normalizeLines()
#   remove comments, whitespace is exactly one space, no empty lines,
#   no whitespace at end of line, one space before and after ",
#   no CR's (as in skaknew).
###############################################################################
normalizeLines()
{
  sed \
      -e '/^[*#;%]/d' \
      -e 's@[ 	][ 	]*@ @g' \
      -e '/^ *$/d' \
      -e 's@ $@@' \
      -e 's@ *" *@ " @g' \
      -e 's@" \([^"]*\) "@"\1"@g' \
   | tr -d '\r' \
   | sort | uniq
}

###############################################################################
# dvips2dvipdfm()
#   reads from stdin, writes to stdout. It transforms "dvips"-like syntax into
#   "dvipdfm"-like syntax. It is a very ugly hack.
###############################################################################
dvips2dvipdfm()
{
  sed -e 's@$@ %@' \
      -e 's@^\(\([^ ]*\).*\)@\1\2@' \
      -e 's@\(.*<\[* *\([^ ]*\)\.enc\(.*\)\)@\1 \2@' \
      -e '/%[^ ]*$/s@$@ default@' \
      -e 's@\(.*<<* *\([^ ]*\)\.pf[ab].*\)@\1 \2@' \
      -e '/%[^ ]* [^ ]*$/s@\( \([^ ]*\).*\)$@\1 \2@' \
      -e 's@\(.*[" ]\([.0-9-][.0-9-]*\) *ExtendFont.*\)@\1 -e \2@' \
      -e 's@\(.*[" ]\([.0-9-][.0-9-]*\) *SlantFont.*\)@\1 -s \2@' \
      -e 's@.*%@@' |
  awk '$1 == $3 && $2 == "default" {$2=""; $3=""} {print}' > $tmp8

  egrep '^(cm|eu|la|lc|line|msam|xy)' $tmp8 \
    | sed 's@$@ -r@; s@\(fmex[789]\) -r$@\1@'
  egrep -v '^(cm|eu|la|lc|line|msam|xy)' $tmp8
}


###############################################################################
# mkMaps()
#   the main task of this script: create the output files
###############################################################################
mkMaps()
{
  newline='
'
  mode=`cfgval LW35`
  dvipsPreferOutline=`cfgval dvipsPreferOutline`
  dvipsDownloadBase35=`cfgval dvipsDownloadBase35`
  pdftexDownloadBase14=`cfgval pdftexDownloadBase14`
  dvipdfmDownloadBase14=`cfgval dvipdfmDownloadBase14`

  # defaults
  test -z "$mode" && mode=URWkb
  test -z "$dvipsPreferOutline" && dvipsPreferOutline=true
  test -z "$dvipsDownloadBase35" && dvipsDownloadBase35=false
  test -z "$pdftexDownloadBase14" && pdftexDownloadBase14=false
  test -z "$dvipdfmDownloadBase14" && dvipdfmDownloadBase14=false

  outputFiles="$dvipsoutputdir/download35.map
$dvipsoutputdir/builtin35.map
$dvipsoutputdir/psfonts_t1.map
$dvipsoutputdir/psfonts_pk.map
$pdftexoutputdir/pdftex_dl14.map
$pdftexoutputdir/pdftex_ndl14.map
$dvipdfmoutputdir/dvipdfm_dl14.map
$dvipdfmoutputdir/dvipdfm_ndl14.map
$dvipsoutputdir/ps2pk.map"

  outputLinks="$dvipsoutputdir/psfonts.map
$pdftexoutputdir/pdftex.map
$dvipdfmoutputdir/dvipdfm.map"

  allOutput="$outputFiles
$outputLinks"

  notfound=false
  OLDIFS=$IFS; IFS=$newline
  for o in $allOutput; do
    test -f "$o" || notfound=true
  done
  IFS=$OLDIFS
  $notfound || texhashEnabled=false

  verboseCat <<-eof
	updmap is creating new map files using the following configuration:

	  config file: \`$cnfFile'
	  dvips output directory: \`$dvipsoutputdir'
	  pdftex output directory: \`$pdftexoutputdir'
	  dvipdfm output directory: \`$dvipdfmoutputdir'

	  prefer outlines: \`$dvipsPreferOutline'
	  texhash enabled: \`$texhashEnabled'
	  download standard fonts (dvips): \`$dvipsDownloadBase35'
	  download standard fonts (pdftex): \`$pdftexDownloadBase14'
	  download standard fonts (dvipdfm): \`$dvipdfmDownloadBase14'
eof

  verboseMsg
  verboseMsg "$progname: scanning for LW35 support files"
  dvips35=`locateMap dvips35.map` || cleanup 1
  pdftex35=`locateMap pdftex35.map` || cleanup 1
  dvipdfm35=`locateMap dvipdfm35.map` || cleanup 1
  ps2pk35=`locateMap ps2pk35.map` || cleanup 1

  if $chicken_mode; then
    echo
    echo "$progname: chicken mode, skipping all output generation, goodbye."
    exit 0
  fi
  
  verboseMsg
  verboseMsg "$progname: Scanning for MixedMap entries:"
  catMaps '^MixedMap' > $tmp1 || cleanup 1

  verboseMsg
  verboseMsg "$progname: Scanning for Map entries:"
  catMaps '^Map' > $tmp2 || cleanup 1
  verboseMsg

  # files should be world-readable
  umask 022

  OLDIFS=$IFS; IFS=$newline
  for file in $allOutput; do
    rm -f "$file"
    cat > "$file" <<-eof
	% $file: maintained by the script updmap.
	%   Don't change this file directly. Edit texmf/web2c/$cnfFileShort
	%   and run updmap to recreate this file.
eof
    if test -n "$log"; then
    cat >> "$file" <<-eof
	% A log of the updmap run that has created this file is available here:
	%   $log
eof
    fi
  done
  IFS=$OLDIFS

  verboseMsg "$progname: Generating output for ps2pk..."
  { transLW35 "$ps2pk35"; cat $tmp1 $tmp2; } \
    | normalizeLines >> "$dvipsoutputdir/ps2pk.map"

  verboseMsg "$progname: Generating output for dvips..."
  { transLW35 "$ps2pk35"; } \
    | normalizeLines >> "$dvipsoutputdir/download35.map"
  { transLW35 "$dvips35"; } \
    | normalizeLines >> "$dvipsoutputdir/builtin35.map"

  if test "x$dvipsDownloadBase35" = xtrue; then
    dftdvips=$ps2pk35
  else
    dftdvips=$dvips35
  fi
  { transLW35 "$dftdvips"; cat $tmp1 $tmp2; } \
    | normalizeLines >> "$dvipsoutputdir/psfonts_t1.map"
  { transLW35 "$dftdvips"; cat $tmp2; } \
    | normalizeLines >> "$dvipsoutputdir/psfonts_pk.map"

  verboseMsg "$progname: Generating output for pdftex..."
  # remove PaintType due to Sebastian's request
  { transLW35 "$pdftex35"; cat $tmp1 $tmp2; } \
    | grep -v PaintType | grep . > $tmp3
  { transLW35 "$dvipdfm35"; cat $tmp1 $tmp2; } \
    | grep -v PaintType | grep . > $tmp6
  { transLW35 "$ps2pk35"; cat $tmp1 $tmp2; } \
    | grep -v PaintType | grep . > $tmp7

  <$tmp3 normalizeLines >> "$pdftexoutputdir/pdftex_ndl14.map"
  <$tmp7 normalizeLines >> "$pdftexoutputdir/pdftex_dl14.map"

  verboseMsg "$progname: Generating output for dvipdfm..."
  <$tmp7 normalizeLines | dvips2dvipdfm | normalizeLines >> "$dvipdfmoutputdir/dvipdfm_dl14.map"
  <$tmp6 normalizeLines | dvips2dvipdfm | normalizeLines >> "$dvipdfmoutputdir/dvipdfm_ndl14.map"
  verboseMsg "$progname: All output generated."
  verboseMsg

  setupSymlinks
  $texhashEnabled && { $verbose && texhash || texhash >/dev/null 2>&1; }

  verboseMsg
  verboseMsg "$progname: Files generated:"
  OLDIFS=$IFS; IFS=$newline
  ls -l $outputFiles | verboseCat
  IFS=$OLDIFS
  verboseMsg

  verboseMsg "$progname: Map file links or copies:"
  ls -l "$dvipsoutputdir"/psfonts.map \
         "$pdftexoutputdir"/pdftex.map \
         "$dvipdfmoutputdir"/dvipdfm.map | verboseCat

  if test -f $mapWarnCalled; then
    m="

!!! NOTICE:

    With this release, the search paths for map files have been changed
    and we have found that some files exist in the new path as well as
    in the obsolete path.

    This is not an error per se, but please consider removing duplicates
    from the old location and search the above output"

    test -n "$log" && m="$m or the transcript file
      $log
   "

    m="$m for warnings.

    For more information about the changed search paths, see
    the release notes section in the teTeX manual. You probably
    can read this document by executing the command
      texdoc TETEXDOC
    else visit the web page
      http://tug.org/texlive/mapenc.html
"
    warn "$m"
  fi

  verboseMsg
  verboseMsg "$progname: Done."
  return 0
}

###############################################################################
# main()
#   execution starts here
###############################################################################
main()
{
  # initialize global variables
  progname=updmap
  cmd=
  log=
  chicken_mode=false
  link_cmd="ln -s"
  copy_cmd="cp"
  copy=false

  cfgparam=
  outputdirparam=
  cfgmaint=
  texhashEnabled=true
  mkmapEnabled=true
  verbose=true
  needsCleanup=false

  cnfFileShort=updmap.cfg
  cnfFile=
  dvipsoutputdir=; pdftexoutputdir=; dvipdfmoutputdir=
  : ${TEXMFMAIN=`kpsewhich -var-value=TEXMFMAIN`}

  tmpdir=${TMPDIR-${TEMP-${TMP-/tmp}}}/$progname.$$
  tmp1=$tmpdir/a
  tmp2=$tmpdir/b
  tmp3=$tmpdir/c
  tmp4=$tmpdir/d
  tmp5=$tmpdir/e
  tmp6=$tmpdir/f
  tmp7=$tmpdir/g
  tmp8=$tmpdir/h
  mapWarnCalled=$tmpdir/mapWarnCalled
  catMapsFailed=$tmpdir/catMapsFailed

  processOptions ${1+"$@"}

  case "$cmd" in
    showoptions) showOptions "$showoptionsItem"; (exit 0); exit;;
    help)        help; (exit 0); exit;;
  esac

  setupCfgFile
  case "$cmd" in
    listmaps) listMaps; (exit 0); exit;;
    listavailablemaps) listAvailableMaps; (exit 0); exit;;
  esac

  # keep a copy of config file, so that we can see if the file was modified
  setupTmpDir

  if test -n "$cfgmaint"; then
    if test -z "$cfgparam"; then
      co=`"$TEXMFMAIN/texconfig/tcfmgr" --tmp $tmpdir --cmd co --file $cnfFileShort`
      test $? = 0 || cleanup 1
      set x $co; shift
      id=$1; cnfFile=$3; orig=$4
      verboseMsg "$progname: initial config file is \`$orig'"
    else
      verboseMsg "$progname: config file is \`$cnfFile'"
      cp "$cnfFile" $tmp5
    fi

    case "$cmd" in
      edit)
        ${VISUAL-${EDITOR-vi}} "$cnfFile";;
      setoption)
        setOption "$setoptionOpt" "$setoptionVal";;
      enable)
        enableMap "$enableMapType" "$enableMapFile";;
      disable)
        disableMap "$disableMapFile";;
      syncwithtrees)
        syncWithTrees;;
    esac

    unchanged=true
    if test -z "$cfgparam"; then
      ci=`"$TEXMFMAIN/texconfig/tcfmgr" --tmp $tmpdir --cmd ci --id $id`
      test $? = 0 || cleanup 1
      case "$ci" in
        "") : ;;
        *) unchanged=false
           cnfFile=$ci
           ;;
      esac
    else
      cmp "$cnfFile" $tmp5 >/dev/null 2>&1 || unchanged=false
    fi
    case $unchanged in
      true) if $mkmapEnabled; then
              verboseMsg "$progname: configuration (updmap.cfg) unchanged. Map files will not be recreated."
              mkmapEnabled=false
            else
              verboseMsg "$progname: configuration (updmap.cfg) unchanged."
            fi;;
      *)
           verboseMsg "$progname: configuration file updated: \`$cnfFile'";;
    esac
  fi

  $mkmapEnabled || return
  setupDestDir
  mkMaps
}

main ${1+"$@"}
cleanup 0