summaryrefslogtreecommitdiffstats
path: root/help.inc
blob: 1ece9b0dff7b5d708d988e11e0ded5578d5c7125 (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
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%
% help system
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

% global vars used by help system


/help.context "main" def

/help.light white def
/help.dark black def
/help.font font.normal def
/help.normal.bg lightgray def
/help.normal.fg black def
/help.highlight.fg green def
/help.link.fg blue def
/help.link.selected.fg white def
/help.link.selected.bg blue def

/help.x 80 def
/help.y 50 def
/help.width 480 def
/help.height 322 def

clip.size pop 800 eq {
  /help.x 120 def
  /help.y  90 def
  /help.width 560 def
  /help.height 359 def
} if

/help.text.x help.x 10 add def
/help.text.y help.y 30 add def

/help.text.width help.width 20 sub def
/help.text.height help.height help.text.y sub help.y add 4 sub def
/help.text.rightmargin help.text.x help.text.width add def

/help.title.x help.x 10 add def
/help.title.y help.y 3 add def
/help.title.height 20 def
/help.title.font font.normal def

/help.hist.page 16 array def
/help.hist.startrow help.hist.page length array def
/help.hist.selectedlink help.hist.page length array def


% for boot option lookup
/bo.opt.max 32 def
/bo.opt bo.opt.max 3 add string def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Map help context.
%
% ( context ) ==> ( new_context )
%
/help.mapcontext {
  dup "o_vncpassword" eq { pop "o_vnc" } if
  dup "o_hostip" eq { pop "network" } if
  dup "o_netmask" eq { pop "network" } if
  dup "o_gateway" eq { pop "network" } if
  dup "o_pci" eq { pop "o_acpi" } if

  syslinux {
    % only help, startup, keytable and option pages
    dup "o_" strstr 1 ne {
      dup "help" ne
      over "startup" ne and
      over "keytable" ne and
      over "profile" ne and { pop "opt" } if
    } if
  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Set help context.
%
% ( context ) ==> ( )
%
/help.setcontext {
  help.mapcontext /help.context exch def
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Find boot option the cursor is positioned at.
%
% ( ) ==> ( option )
%
/findbootoption {
  /bo.buf boot.ed 3 get def
  /bo.len boot.ed 4 get def
  /bo.pos boot.ed 5 get def

  {
    bo.pos 0 eq { exit } if
    bo.buf bo.pos 1 sub get ' ' le  { exit } if
    /bo.pos bo.pos 1 sub def
  } loop

  /bo.buf bo.buf bo.pos add def

  bo.buf 0 get ' ' le { "" return } if

  % "o_" + option name is the help text label
  "o_" 3 bo.opt snprintf

  0 1 bo.opt.max 1 sub {
    dup
    bo.buf exch get
    dup ' ' le over '=' eq or { pop pop exit } if
    over bo.opt 2 add exch rot put
    bo.opt 3 add exch 0 put
  } for

  bo.opt

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Find help page.
%
% returns help page or empty string if no page was found
%
% ( label ) ==> ( help_text )
%
/help.findpage {
  dup length 3 add dup string
  "\x12%s\x14"
  3 1 roll dup 5 1 roll snprintf
  help.getmessages over strstr
  dup { help.getmessages exch 1 sub add } { pop "" } ifelse
  exch free
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Find help page.
%
% returns n-th help page or empty string if no page was found
%
% ( n ) ==> ( help_text )
%
/help.findpagebyindex {
  help.getmessages exch
  {
    dup "\x04" strstr
    dup { add } { pop pop "" exit } ifelse
  } repeat
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Init & display help page.
%
% ( help_text start_row selected_link ) ==> ( )
%
/help.initpage {
  /help.selectedlink exch def
  /help.startrow exch def

  /help.currenttext over def

  title.bg setcolor
  help.x 1 add help.y 1 add moveto
  help.width 2 sub help.title.height 1 sub fillrect

  help.text.x help.text.y moveto
  currentmaxrows 0 setmaxrows exch formattext setmaxrows

  white setcolor
  currenteotchar 16 seteotchar
  help.title.x help.title.y moveto currenttitle
  currentfont help.title.font setfont exch show setfont
  seteotchar

  getlinks { help.selectedlink setlink } if

  help.updatepage

  % 500 0 moveto gettextrows print
  % 400 0 moveto getlinks print

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Redraw help page.
%
% ( ) ==> ( )
%
/help.updatepage {
  help.normal.bg setcolor
  help.text.x help.text.y moveto
  help.text.width help.text.height fillrect

  help.normal.fg help.highlight.fg help.link.fg help.link.selected.fg settextcolors

  help.startrow setstartrow

  help.text.x help.text.y moveto
  help.currenttext show

  0 setstartrow

  true help.selectedlink help.redrawlink

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Used to iterate over all help pages (for debugging).
%
% get the n-th page starting from current pos
%
% ( n ) ==> ( help_text )
%
/help.test {
  help.test.cnt add
  dup 1 lt { pop 1 } if
  /help.test.cnt over def
  help.findpagebyindex
  dup "" eq {
    % one page back
    pop help.test.cnt 1 sub /help.test.cnt over def
    help.findpagebyindex
  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Redraw link.
%
% selected: true or false.
%
% ( selected n ) ==> ( )
%
%
/help.redrawlink {
  getlinks 0 eq { pop pop return } if
  getlink
  dup help.startrow lt
  over help.startrow help.text.rows add ge or {
    5 { pop } repeat return
  } if
  help.startrow sub lineheight mul help.text.y add
  moveto
  rot

  16 seteotchar

  {
    currenttextcolors 4 1 roll pop pop pop
    help.link.selected.bg
  } {
    currenttextcolors 4 2 roll pop pop pop
    help.normal.bg
  } ifelse

  setcolor over currentpoint rot strsize fillrect moveto

  setcolor show

  4 seteotchar

  pop
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Select n-th link.
%
% ( n ) ==> ( )
%
/help.selectlink {
  help.selectedlink over eq {
    pop
  } {
    % deselect old link
    false help.selectedlink help.redrawlink

    /help.selectedlink over dup setlink def

    % select link
    true exch help.redrawlink
  } ifelse
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Select first visible link.
%
% No screen update if 'update' is false.
%
% ( update ) ==> ( )
%
/help.sel.firstlink {
  getlinks {
    0 1 getlinks 1 sub {
      dup
      getlink 4 1 roll pop pop pop
      dup help.startrow help.text.rows add ge {
        pop pop exit
      } if
      dup help.startrow ge {
        pop
        over { help.selectlink } { /help.selectedlink exch dup setlink def } ifelse
        exit
      } if
      pop pop
    } for
  } if
  pop
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Select last visible link.
%
% No screen update if 'update' is false.
%
% ( update ) ==> ( )
%
/help.sel.lastlink {
  getlinks {
    getlinks 1 sub -1 0 {
      dup
      getlink 4 1 roll pop pop pop
      dup help.startrow lt {
        pop pop exit
      } if
      dup help.startrow help.text.rows add lt {
        pop
        over { help.selectlink } { /help.selectedlink exch dup setlink def } ifelse
        exit
      } if
      pop pop
    } for
  } if
  pop
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Push current help context to history.
%
% ( ) ==> ( )
%
/help.add2history {
  help.hist.index help.hist.page length lt {
    help.hist.page help.hist.index help.currenttext put
    help.hist.startrow help.hist.index help.startrow put
    help.hist.selectedlink help.hist.index help.selectedlink put
    /help.hist.index help.hist.index 1 add def
  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Follow currently selected link.
%
% ( ) ==> ( )
%
/help.followlink {
  getlinks {
    help.selectedlink getlink pop pop pop
    help.add2history
    help.findpage
    dup "" eq {
      pop
    } {
      0 0 help.initpage
    } ifelse
  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Go back to previous page.
%
% ( ) ==> ( )
%
/help.prevlink {
  help.hist.index 0 gt {
    /help.hist.index help.hist.index 1 sub def
    help.hist.page help.hist.index get
    help.hist.startrow help.hist.index get
    help.hist.selectedlink help.hist.index get
    help.initpage
  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Scroll a page down.
%
% ( ) ==> ( )
%
/help.key.pagedown {
  help.startrow
  gettextrows help.text.rows gt {
    pop
    gettextrows help.text.rows sub
    help.startrow help.text.rows add
    min
  } if

  dup help.startrow eq {
    pop
    true help.sel.lastlink
  } {
    /help.startrow exch def
    false help.sel.firstlink
    help.updatepage
  } ifelse
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Scroll a page up.
%
% ( ) ==> ( )
%
/help.key.pageup {
  help.startrow
  gettextrows help.text.rows gt {
    pop
    0
    help.startrow help.text.rows sub
    max
  } if

  dup help.startrow eq {
    pop
    true help.sel.firstlink
  } {
    /help.startrow exch def
    false help.sel.firstlink
    help.updatepage
  } ifelse
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Go to page start.
%
% ( ) ==> ( )
%
/help.key.home {
  help.startrow 0 eq {
    true help.sel.firstlink
  } {
    /help.startrow 0 def
    false help.sel.firstlink
    help.updatepage
  } ifelse
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Go to page end.
%
% ( ) ==> ( )
%
/help.key.end {
  gettextrows help.text.rows sub 0 max
  dup help.startrow  eq {
    pop
    true help.sel.lastlink
  } {
    /help.startrow exch def
    false help.sel.lastlink
    help.updatepage
  } ifelse
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Next link or scroll down.
%
% ( ) ==> ( )
%
/help.key.down {
  help.selectedlink getlinks 1 sub lt {
    help.selectedlink 1 add getlink 4 1 roll pop pop pop
    dup help.startrow help.text.rows add lt {
      % link visible
      pop help.selectedlink 1 add help.selectlink
      return
    } {
      help.startrow help.text.rows add eq {
        % link visible after scrolling down
        /help.selectedlink help.selectedlink 1 add dup setlink def
      } if
    } ifelse
  } if

  % scroll down

  help.startrow help.text.rows add gettextrows lt {
    /help.startrow help.startrow 1 add def
    help.updatepage
  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Previous link or scroll up.
%
% ( ) ==> ( )
%
/help.key.up {
  help.selectedlink 0 gt {
    help.selectedlink 1 sub getlink 4 1 roll pop pop pop
    % row
    dup help.startrow ge {
      % link visible
      pop help.selectedlink 1 sub help.selectlink
      return
    } {
      help.startrow 1 sub eq {
        % link visible after scrolling up
        /help.selectedlink help.selectedlink 1 sub dup setlink def
      } if
    } ifelse
  } if

  % scroll up

  help.startrow 0 gt {
    /help.startrow help.startrow 1 sub def
    help.updatepage
  } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Handle keyboard input.
%
% ( key_in ) ==> ( key_out )
%
/help.input {
  dup 0 eq { return } if

  dup keyEsc eq { /window.action actNothing def window.done } if
  dup keyCtrlDown eq { 1 help.test 0 0 help.initpage } if 
  dup keyCtrlUp eq { -1 help.test 0 0 help.initpage } if 
  dup keyDown eq { help.key.down } if 
  dup keyUp eq { help.key.up } if 
  dup keyPgDown eq { help.key.pagedown } if 
  dup keyPgUp eq { help.key.pageup } if 
  dup keyHome eq { help.key.home } if 
  dup keyEnd eq { help.key.end } if 
  dup keyRight eq { help.followlink } if 
  dup keyEnter eq { help.followlink } if 
  dup 0xff and ' ' eq { help.followlink } if 
  dup keyLeft eq { help.prevlink } if 
  dup 0xff and '\x08' eq { help.prevlink } if 
  dup keyF1 eq {
    "help" help.findpage
    dup help.currenttext eq {
      pop
    } {
      help.add2history
      0 0 help.initpage
    } ifelse
  } if 
%  dup keyF9 eq {
%    /help.font help.font 8 add 10 mod def help.reinit
%    help.currenttext help.startrow help.selectedlink help.initpage
%  } if 
  pop 0
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Recalculate some sizes and redraw help screen.
%
% ( ) ==> ( )
%
/help.reinit {
  help.normal.bg setcolor
  help.x help.y moveto
  help.width help.height fillrect

  help.x 1 add help.y 1 add help.title.height add moveto
  help.dark help.light
  help.width 2 sub help.height 2 sub help.title.height sub
  drawborder

  help.font setfont

  /help.text.rows help.text.height lineheight div def
  help.text.rows setmaxrows

  help.text.rightmargin settextwrap
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Initialize help window.
%
% ( window ) ==> ( )
%
/help.init {
  /help.tmp exch def

  help.x 1 sub help.y 1 sub moveto
  help.light help.dark
  help.width 2 add help.height 2 add
  over over
  savescreen
  help.tmp .saved rot put
  drawborder

  help.reinit

  4 seteotchar

  /help.hist.index 0 def

  /help.test.cnt 1 def

  help.context help.findpage 0 0 help.initpage
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Draw help window.
%
% ( window ) ==> ( )
%
/help.show {
  window.push
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Close current help window.
%
% ( ) ==> ( )
%
/help.done {
  0 settextwrap
  0 seteotchar
  0 setmaxrows
} def



% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Create new help window.
%
% ( ) ==> ( window )
%
/window.help {
  widget.size array
  dup .type t_help put

  dup .x help.x put
  dup .y help.y put

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Find help texts.
%
% ( ) ==> ( start_of_help_messages )
%
/help.getmessages {

  help.messages .undef eq {
    % find help texts
    /help.messages
      help.file free /help.file .undef def
      16 string dup config.lang "%s.hlp" 2 index sprintf
      findfile exch free
      dup .undef eq { pop "en.hlp" findfile } if
      dup .undef eq { pop "" } if
      /help.file over def
      cvs
    def
  } if

  help.messages

} def