summaryrefslogtreecommitdiff
path: root/Master/bin/x86_64-darwin/texconfig-dialog
blob: 8ccda930dd740752060e2308a043c0ca90c1b054 (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
#!/bin/sh

# TeX-Config version 3.0
# Thomas Esser, te@dbs.uni-hannover.de. Public domain.

# invoke the right shell:

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=1184605103 # seconds since `00:00:00 1970-01-01 UTC'
                   # date '+%s' (with GNU date)

: ${PAGER=more}
progname=texconfig-dialog
tmpdir=${TMPDIR-${TEMP-${TMP-/tmp}}}/tcdtmp.$$
log=$tmpdir/log
tmpmenu=$tmpdir/tmpmenu
needsCleanup=false

###############################################################################
# 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"; }
  termCtl reset
  (exit $rc); exit $rc
}

###############################################################################
# setupTmpDir()
#   set up a temp directory and a trap to remove it
###############################################################################
setupTmpDir()
{
  case $needsCleanup in
    true) return;;
  esac

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

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

logexec()
{
  (echo; echo ">>> Executing \`$@' <<<") >> $log
  "$@" 2>&1 | tee -a $log
}

###############################################################################
# runDialog(args, ...)
#   execute the right dialog program with the right default parameters
###############################################################################
runDialog()
{
  termCtl clear
  if test -n "$DIALOG_PROG"; then
    $DIALOG_PROG --title "TeX setup utility" ${1+"$@"}
    runDialogRc=$?
  else
    TERM=$DIALOG_TERM TERMINFO=$DIALOG_TERMINFO \
      tcdialog --title "TeX setup utility" ${1+"$@"}
    runDialogRc=$?
  fi
  termCtl clear
  (exit $runDialogRc)
  return $runDialogRc
}

###############################################################################
# findDialog(void)
#   Some systems have their own dialog. Use it then and do not use
#   faked TERM and TERMINFO variables when calling that dialog.
###############################################################################
findDialog()
{
  for bin in whiptail dialog
  do
    binLoc=`texconfig findprog $bin`
    case $binLoc in
      "") DIALOG_PROG="";;
      *)  DIALOG_PROG=$binLoc; break;;
    esac
  done
  case $DIALOG_PROG in
    "") 
      : ${DIALOG_TERMINFO=$TEXMFMAIN/texconfig}
      : ${DIALOG_TERM=generic}
  esac
}

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

###############################################################################
# termCtl(arg)
#   some convenience utilities for terminal control
###############################################################################
termCtl()
{
  case $1 in
    clear)
      test -n "$NO_CLEAR" && return
      tty >/dev/null 2>&1 && clear
      ;;
    reset)
      test -n "$NO_CLEAR" && return
      reset 2>/dev/null
      stty sane 2>/dev/null
      reset 2>/dev/null
      termCtl clear
      ;;
    readln)
      echo
      echo "press return to continue..."
      read a
      ;;
  esac
}

###############################################################################
# menuMain(void)
#   the main menu
###############################################################################
menuMain()
{
  cat <<-'eof'
	The interactive texconfig utility will be started now. Make sure
	your screen has at least 24 rows and 80 columns. If texconfig
	crashes now, you can still set up your teTeX system using the
	batch mode of texconfig.  Try 'texconfig help' to get a list
	of options.

	The interactive mode works best with a real vt100 terminal or
	inside an xterm window.
eof
  termCtl readln

  while :; do
    logMessage='view logfile'

    runDialog \
      --menu "
Hint: all output of external commands (e.g. tex) is logged into
a file. You can look at this file using "LOG". If cursor keys make
trouble, you may have more luck with +/- and TAB.
" \
      23 80 14 \
      EXIT      'exit' \
      PAPER     'default paper: A4 or letter (us)' \
      MODE      'default metafont mode and resolution' \
      REHASH    'rebuild filename databases' \
      FORMATS   'edit format definitions' \
      HYPHENATION   'customize hyphenation' \
      DVIPS     'dvips configuration' \
      FAQ       'view frequently asked questions + answers' \
      CONF      'show configuration' \
      LOG       "$logMessage" \
      2>"$tmpmenu" || break
    
    case `cat "$tmpmenu"` in
      EXIT)
        break
        ;;
      PAPER)
        menuPaper
        ;;
      MODE)
        menuMode
        ;;
      REHASH)
        logexec texconfig rehash
        termCtl readln
        ;;
      FORMATS)
        texconfig formats
        termCtl readln
        ;;
      HYPHENATION)
        menuHyphenation
        ;;
      DVIPS)
        menuDvips
        ;;
      FAQ)
        texconfig faq
        termCtl readln
        ;;
      CONF)
        logexec texconfig conf
        termCtl readln
        ;;
      LOG)
        <"$log" eval $PAGER
        termCtl readln
        ;;
    esac
  done
}

menuGetMode()
{
  # we need eval to get the command line right... :-(
  eval \
    runDialog \
      --menu \""
Chosse a mode to be used when metafont generates font bitmaps. The resolution is the most important point, but there might
be differences between modes of the same resolution. See the comments in the file modes.mf for more details.
\"" \
      23 80 14 \
      `texconfig mode-list` 2>"$tmpmenu"
}

menuMode()
{
  menuGetMode
  mode=`cat "$tmpmenu"`

  if test -n "$mode"; then
    logexec texconfig mode "$mode"
    termCtl readln
  fi
}

menuDvips()
{
  menuDvipsDest=ps

  while :; do
    case $menuDvipsDest in
      ps)
        menuDvipsPrinterOpt=
        menuDvipsMsg="
dvips GLOBAL section. Define the most common default settings (config.ps).
To define settings for a specific printer, first ADD a printer definition,
then CHANGE it.
"
        ;;
      *)
        menuDvipsPrinterOpt="-P $menuDvipsDest"
        menuDvipsMsg="
dvips settings for printer $menuDvipsDest (config.$menuDvipsDest). Define
local settings for this printer. To switch back to global settings mode,
select GLOBAL.
"
        ;;
    esac

    runDialog \
      --menu "$menuDvipsMsg
You can use dvips for non PostScript printers, if you can setup your
printing system to convert PostScript to a format that your printer can
handle. Maybe, you can use GhostScript to do the conversion (if your
printer is supported)." \
      23 80 9 \
      RETURN	'back to the main menu' \
      DEST      'define default destination of the generated Postscript' \
      MODE      'change metafont mode/resolution' \
      OFFSET    'shift output by some offset' \
      PAPER     'define the default paper' \
      GLOBAL	'change global settings (config.ps)' \
      CHANGE	'change printer settings (config.$PRINTER)' \
      ADD	'add a printer configuration' \
      DEL	'remove a printer configuration' \
        2>"$tmpmenu" || break

    menuDvipsAns=`cat "$tmpmenu"`
    case $menuDvipsAns in
      RETURN)
        break
        ;;
      DEST)
        runDialog --inputbox "Enter the command to print.

In general, you need a command like 'lpr' or 'lpr -Pfoo'.

NOTE: If you just press return, printing will be disabled and the output saved to a file by default.
" 23 80 2>"$tmpmenu"
        if test $? = 0; then
          menuDvipsAns=`cat "$tmpmenu"`
          case $menuDvipsAns in
            "")
              menuDvipsPrintOpt=-
              ;;
            *)
              menuDvipsPrintOpt=$menuDvipsAns
              ;;
          esac
          logexec texconfig dvips $menuDvipsPrinterOpt printcmd "$menuDvipsPrintOpt"
          termCtl readln
        fi
        ;;
      MODE)
        menuGetMode
        mode=`cat "$tmpmenu"`
  
        if test -n "$mode"; then
          logexec texconfig dvips $menuDvipsPrinterOpt mode "$mode"
          termCtl readln
        fi
        ;;
      OFFSET)
        runDialog --inputbox "Enter a dimension pair (a rightwards offset and a downwards
offset), e.g. 2mm,-0.5in (right 2mm and up .5in):" 23 80 2>"$tmpmenu"; menuDvipsAns=`cat "$tmpmenu"`
        case $menuDvipsAns in
          "") : ;;
          *)
            logexec texconfig dvips $menuDvipsPrinterOpt offset "$menuDvipsAns"
            termCtl readln
            ;;
        esac
        ;;
      PAPER)
        eval runDialog \
          --menu \'\\n\\nChoose the default papersize definition for dvips.\\n\\n\' \
          23 80 8 `texconfig dvips paper-list` \
          2>"$tmpmenu"
        paper=`cat "$tmpmenu"`
        if test -n "$paper"; then
          logexec texconfig dvips paper "$paper"
          termCtl readln
        fi
        ;;
      GLOBAL)
        menuDvipsDest=ps
        ;;
      CHANGE)
        runDialog --inputbox "Printer name (for future settings of DEST / MODE / OFFSET)" 23 80 2>"$tmpmenu"
        menuDvipsAns=`cat $tmpmenu`
        case $menuDvipsAns in
          "") : ;;
          *)  menuDvipsDest=$menuDvipsAns;;
        esac
        ;;
      ADD)
        runDialog --inputbox "Printer name (for printer to add)" 23 80 2>"$tmpmenu"
        menuDvipsAns=`cat $tmpmenu`
        case $menuDvipsAns in
          "") : ;;
          *)
            logexec texconfig dvips add $menuDvipsAns
            termCtl readln
            ;;
        esac
        ;;
      DEL)
        runDialog --inputbox "Printer name (for printer to delete)" 23 80 2>"$tmpmenu"
        menuDvipsAns=`cat $tmpmenu`
        case $menuDvipsAns in
          "") : ;;
          *)
	    logexec texconfig dvips del $menuDvipsAns
            termCtl readln
            ;;
        esac
        ;;
    esac
  done
}

menuPaper()
{
  runDialog \
    --menu "
Select your default paper format.
" \
    23 80 14 \
    RETURN 'return to the main menu' \
    A4	'ISO A4 (210x297mm)' \
    LETTER 'US (8.5x11in)' 2>"$tmpmenu"

  p=`cat "$tmpmenu"`
  case $p in
    A4)
      logexec texconfig paper a4
      termCtl readln
      ;;
    LETTER)
      logexec texconfig paper letter
      termCtl readln
      ;;
  esac
}

menuHyphenation()
{
  runDialog \
    --menu "
Choose format to set up hyphenation for.
" \
    23 80 14 \
    `texconfig hyphen-list | sed 's@\(.*\)@\1 \1@'`  2>"$tmpmenu"
  p=`cat "$tmpmenu"`
  case $p in
    "")
      return
      ;;
    *)
      texconfig hyphen "$p"
      termCtl readln
  esac
}

# main()

case $1 in
  help|--help)
    cat <<-eof
	Usage: $progname [--help|--version]
eof
    exit 0
    ;;
  --version)
    cat <<-eof
	$progname version $version.
eof
    exit 0
    ;;
esac


: ${TEXMFCONFIG=`kpsewhich -var-value=TEXMFCONFIG`}
: ${TEXMFVAR=`kpsewhich -var-value=TEXMFVAR`}
: ${TEXMFMAIN=`kpsewhich -var-value=TEXMFMAIN`}
export TEXMFCONFIG TEXMFVAR TEXMFMAIN

setupTmpDir
echo "$progname: started `date`" > $log
findDialog

test -d "$TEXMFCONFIG" \
  || mktexdir "$TEXMFCONFIG" >/dev/null 2>&1 \
  || echo "$progname: directory \`$TEXMFCONFIG' (from TEXMFCONFIG variable) does not exist and cannot be created" >&2

canWriteConfig=false
if test -d "$TEXMFCONFIG"; then
  if test -w "$TEXMFCONFIG"; then
    canWriteConfig=true
  else
    echo "$progname: directory \`$TEXMFCONFIG' (from TEXMFCONFIG variable) is not writable."
    echo "$progname: configuration data cannot be changed." >&2
  fi
fi

test -d "$TEXMFVAR" \
  || mktexdir "$TEXMFVAR" >/dev/null 2>&1 \
  || echo "$progname: directory \`$TEXMFVAR' (from TEXMFVAR variable) does not exist and cannot be created" >&2

canWriteVardata=false
if test -d "$TEXMFVAR"; then
  if test -w "$TEXMFVAR"; then
    canWriteVardata=true
  else
    echo "$progname: directory \`$TEXMFVAR' (from TEXMFVAR variable) is not writable."
    echo "$progname: cached variable runtime data files cannot be written." >&2
  fi
fi

menuMain
cleanup 0