-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogl.txt
More file actions
2244 lines (2024 loc) · 72.2 KB
/
progl.txt
File metadata and controls
2244 lines (2024 loc) · 72.2 KB
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; form.l -- screen forms handler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declare
(specials t)
(macros t))
(eval-when (compile)
(load 'utilities)
(load 'constants)
(load 'zone)
(load 'look)
(load 'font)
(load 'text)
(load 'text-edit))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; generic fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct
(field ; generic field
(:displace t)
(:list)
(:conc-name))
(type 'generic-field) ; type = generic
(zone (make-zone)) ; bounding zone
(properties (list nil)) ; empty property list
)
(defvar field-properties ; list of expected field properties
'("field-properties"
fill-ground (solid pattern) ; should we draw when highlit?
fill-colour (x_colour x_pattern) ; what colour or pattern?
empty-ground (solid pattern) ; should we draw when unlit?
empty-colour (x_colour x_pattern) ; what colour or pattern?
border-colour (x_colour) ; should we draw border (and what colour?)
)) ; can use this as real plist for online documentation
(defun draw-field (f) ; draw field from scratch
(apply (concat 'draw- (field-type f)) ; construct draw function name
(ncons f))) ; then call it
(defun init-field (f) ; initialize a field
(apply (concat 'init- (field-type f)) ; construct init function name
(ncons f))) ; then call it
(defun resize-field (f box) ; resize a field
(apply ; construct resize function name
(concat 'resize- (field-type f))
(list f box))) ; then call it
(defun toggle-field (f) ; toggle a field
(apply (concat 'toggle- (field-type f)) ; construct toggle fcn name
(ncons f))) ; then call it
(defun check-field (f p) ; check if point is inside field excl.border
(cond ((point-in-box-interior p (zone-box (field-zone f)))
(apply ; if so, construct check function name
(concat 'check- (field-type f))
(list f p))) ; then call it and return result
(t nil))) ; otherwise return nil
(defun fill-field (f) ; fill the field interior, if defined
(let ((b (get (field-properties f) 'fill-ground)) ; check if has one
(c (get (field-properties f) 'fill-colour)))
(cond ((eq b 'solid) ; solid background
(cond (c (clear-zone-interior (field-zone f) c))
(t (clear-zone-interior (field-zone f) W-CONTRAST))))
((eq b 'pattern) ; patterned background
(cond (c (pattern-zone-interior (field-zone f) c))
(t (pattern-zone-interior (field-zone f) W-PATTERN-1))))
))) ; no background at all!
(defun empty-field (f) ; empty the field interior, if defined
(let ((b (get (field-properties f) 'empty-ground)) ; check if has one
(c (get (field-properties f) 'empty-colour)))
(cond ((eq b 'solid) ; solid background
(cond (c (clear-zone-interior (field-zone f) c))
(t (clear-zone-interior (field-zone f) W-BACKGROUND))))
((eq b 'pattern) ; patterned background
(cond (c (pattern-zone-interior (field-zone f) c))
(t (pattern-zone-interior (field-zone f) W-PATTERN-1))))
))) ; no background at all!
(defun draw-field-background (f) ; just what it says
(let ((b (get (field-properties f) 'empty-ground)) ; check if has one
(c (get (field-properties f) 'empty-colour)))
(cond ((eq b 'solid) ; solid background
(cond (c (clear-zone (field-zone f) c))
(t (clear-zone (field-zone f) W-BACKGROUND))))
((eq b 'pattern) ; patterned background
(cond (c (pattern-zone (field-zone f) c))
(t (pattern-zone (field-zone f) W-PATTERN-1))))
))) ; no background at all!
(defun draw-field-border (f) ; draw outline, if any
(let ((c (get (field-properties f) 'border-colour)))
(cond (c (draw-zone-outline (field-zone f) c)))
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; aggregate fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct
(aggregate-field ; aggregate field = form
(:displace t)
(:list)
(:conc-name))
(type 'aggregate-field) ; type
(zone (make-zone)) ; bounding zone
(properties (list nil)) ; empty property list
subfields ; list of subfields
selection ; which subfield was last hit
)
(defvar aggregate-field-properties
`("aggregate-field-properties"
= ,field-properties
)) ; can use this as real plist for online documentation
(defun draw-aggregate-field (f)
(draw-field-background f) ; clear background, if any
(draw-field-border f) ; draw border, if any
(mapc 'draw-field (aggregate-field-subfields f)) ; draw subfields
(w-flush (window-w (zone-window (field-zone f)))) t) ; flush it out
(defun init-aggregate-field (f)
(mapc 'init-field (aggregate-field-subfields f))
(alter-aggregate-field f selection nil) t)
(defun resize-aggregate-field (f box)
(alter-zone (field-zone f) box box))
(defun check-aggregate-field (f p)
(do ((subfields (aggregate-field-subfields f) ; go through subfields
(cdr subfields))
(gotcha))
((or (null subfields) ; stop when no more
(setq gotcha (check-field (car subfields) p))) ; or when one is hit
(alter-aggregate-field f selection gotcha) ; remember which one
gotcha))) ; also return it
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; remote fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; A remote field is a field which activates another field when hit.
;;; Usually the remote field has some functional significance!
(defstruct
(remote-field ; remote field
(:displace t)
(:list)
(:conc-name))
(type 'remote-field) ; type = remote
(zone (make-zone)) ; bounding zone
(properties (list nil)) ; empty plist
(target) ; the actual target field
(point) ; x,y coords to pretend to use
)
(defvar remote-field-properties
`("remote-field-properties"
= ,field-properties
)) ; can use this as real plist for online documentation
(defun draw-remote-field (f) 't) ; nothing to draw
(defun init-remote-field (f) 't) ; nothing to initialize
(defun resize-remote-field (f box)
(alter-zone (field-zone f) box box))
(defun check-remote-field (f p)
(check-field
(remote-field-target f)
(remote-field-point f))) ; return result of checking target
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; button fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct
(button-field ; button field
(:displace t)
(:list)
(:conc-name))
(type 'button-field) ; type = button
(zone (make-zone)) ; bounding zone
(properties
(list nil ; default properties
'fill-ground 'solid
'empty-ground 'solid
'border-colour W-CONTRAST
))
(value nil) ; value
)
(defvar button-field-properties
`("button-field-properties"
= ,field-properties
)) ; can use this as real plist for online documentation
(defun draw-button-field (f)
(draw-field-border f)
(cond ((button-field-value f)
(fill-field f))
(t (empty-field f))))
(defun toggle-button-field (f)
(alter-button-field f value (not (button-field-value f)))
(clear-zone-interior (field-zone f) W-XOR))
(defun init-button-field (f)
(alter-button-field f value nil)) ; turn it off
(defun resize-button-field (f box)
(alter-zone (field-zone f) box box))
(defun check-button-field (f p)
(toggle-button-field f) f) ; if we get here it's a hit -> return self
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; radio-button fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Named for the buttons on radios in which only one is "in" at a time.
(defstruct
(radio-button-field ; radio-button field
(:displace t)
(:list)
(:conc-name))
(type 'radio-button-field) ; type = radio-button
(zone (make-zone)) ; bounding zone
(properties (list nil)) ; empty plist
(subfields nil) ; individual buttons
(selection nil) ; which one last hit
)
(defvar radio-button-field-properties
`("radio-button-field-properties"
= ,aggregate-field-properties
)) ; can use this as real plist for online documentation
(defun draw-radio-button-field (f)
(draw-aggregate-field f))
(defun init-radio-button-field (f)
(init-aggregate-field f))
(defun resize-radio-button-field (f box)
(alter-zone (field-zone f) box box))
(defun check-radio-button-field (f p)
(cond ((and (radio-button-field-selection f) ; if button previously sel'd
(button-field-value
(radio-button-field-selection f))) ; and it has a value
(toggle-field ; turn it off
(radio-button-field-selection f))))
(check-aggregate-field f p) ; check individual buttons
) ; this will turn back on if same one sel'd, and return it
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; text fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct
(text-field ; text field
(:displace t)
(:list)
(:conc-name))
(type 'text-field) ; type = text
(zone (make-zone)) ; bounding zone
(properties
(list nil
'fill-ground 'solid
'empty-ground 'solid
'border-colour W-CONTRAST
'x-offset 5 ; offset from left
))
(value nil)
(text '||) ; text of text
)
(defvar text-field-properties
`("text-field-properties"
x-offset (x_pixels) ; text offset from box ll, otherwise centred
y-offset (x_pixels) ; text offset from box ll, otherwise centred
+ ,button-field-properties
)) ; can use this as real plist for online documentation
(defun draw-text-field (f)
(draw-button-field f)
(w-flush (window-w (zone-window (field-zone f)))) ; guarantee text on top
(draw-text (text-field-text f)))
(defun redraw-text-field (f)
(empty-field f)
(w-flush (window-w (zone-window (field-zone f)))) ; guarantee text on top
(draw-text (text-field-text f)))
(defun init-text-field (f) ; position & position the text in the field
(let ((s (text-field-text f))
(x-offset (get (field-properties f) 'x-offset)) ; x offset from ll
(y-offset (get (field-properties f) 'y-offset))); y offset from ll
(alter-text s
zone (make-zone ; ensure it has a zone
window (zone-window (field-zone f))
box (box-interior (zone-box (field-zone f)))))
(format-text s) ; ensure text delta calculated
(cond ((null x-offset) ; x-offset specified?
(setq x-offset ; nope! centre it left-right
(/ (- (x (box-size (zone-box (field-zone f))))
(x (text-delta s)))
2))))
(cond ((null y-offset) ; y-offset specified?
(setq y-offset ; nope! centre it up-down
(/ (- (y (box-size (zone-box (field-zone f))))
(font-x-height (look-font (text-look s))))
2))))
(alter-text s ; now position the text
offset (make-point x x-offset y y-offset))
))
(defun resize-text-field (f box) ; position the text in the field
(alter-zone (field-zone f) box box)
(init-text-field f))
(defun check-text-field (f p)
(input-text-field f) f) ; if we get here it's a hit -> return self
(defun input-text-field (f)
(alter-text (text-field-text f)
text '|| nn 0 kr 0 kl 0 delta (make-point x 0 y 0))
(draw-text-field f)
(edit-text-field f (ll (zone-box (text-zone (text-field-text f))))))
(defun edit-text-field (f p) ; edit in middle of text field
(edit-text (text-field-text f) p) ; edit the text
(draw-field f)) ; redraw
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; prompt fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct
(prompt-field ; prompt field
(:displace t)
(:list)
(:conc-name))
(type 'prompt-field) ; type = prompt
(zone (make-zone)) ; bounding zone
(properties
(list nil 'x-offset 0)) ; put it exactly where spec indicates.
(value nil)
(text '||) ; text of prompt
)
(defvar prompt-field-properties
`("prompt-field-properties"
= ,text-field-properties
)) ; can use this as real plist for online documentation
(defun draw-prompt-field (f)
(draw-text-field f))
(defun init-prompt-field (f)
(init-text-field f))
(defun resize-prompt-field (f box) ; position the text in the field
(resize-text-field f box))
(defun check-prompt-field (f p) f) ; just return self
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; text-button fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; A text-button is a button tied to a text.
;;; When the button is pressed, the text is input from the keyboard.
;;; Zone could same as either the button (activation by button only)
;;; or include both button & text (should then be adjacent)
(defstruct
(text-button-field ; text-button field
(:displace t)
(:list)
(:conc-name))
(type 'text-button-field) ; type = text-button
(zone (make-zone)) ; bounding zone
(properties (list nil)) ; empty plist
(button) ; button subfield
(text) ; text subfield
)
(defvar text-button-field-properties
`("text-button-field-properties"
= ,field-properties
)) ; can use this as real plist for online documentation
(defun draw-text-button-field (f)
(draw-field (text-button-field-button f))
(draw-text-field (text-button-field-text f)))
(defun init-text-button-field (f)
(init-field (text-button-field-button f))
(init-text-field (text-button-field-text f)))
(defun resize-text-button-field (f box)
(alter-zone (field-zone f) box box))
(defun toggle-text-button-field (f) ; toggle only the button part
(cond ((button-field-value ; and only if non-nil
(text-button-field-button f))
(toggle-button-field (text-button-field-button f)))))
(defun check-text-button-field (f p)
(cond ((check-field (text-button-field-button f) p)
(input-text-field ; input from scratch
(text-button-field-text f))) ; get the data
(t (toggle-button-field ; must be pointing at text
(text-button-field-button f)) ; toggle only the button part
(edit-text-field
(text-button-field-text f) p)) ; edit the data
)
(toggle-button-field ; toggle button back
(text-button-field-button f))
(alter-button-field (text-button-field-button f)
value nil) ; keep aggregate from toggling again
f) ; return self
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; labelled button fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct
(labelled-button-field ; labelled button field
(:displace t)
(:list)
(:conc-name))
(type 'labelled-button-field) ; type = labelled-button
(zone (make-zone)) ; bounding zone
(properties
(list nil
'fill-ground 'solid
'empty-ground 'solid
'border-colour W-CONTRAST
))
(value nil) ; value
(text '||) ; label text
)
(defvar labelled-button-field-properties
`("labelled-button-field-properties"
= ,text-field-properties
)) ; can use this as real plist for online documentation
(defun draw-labelled-button-field (f)
(draw-text-field f))
(defun init-labelled-button-field (f)
(init-text-field f))
(defun resize-labelled-button-field (f box)
(resize-text-field f box))
(defun check-labelled-button-field (f p)
(toggle-button-field f) f) ; if we get here it's a hit -> return self
(defun toggle-labelled-button-field (f)
(toggle-button-field f))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; expanded-bitmap fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defstruct
(expanded-bitmap-field ; expanded-bitmap field
(:displace t)
(:list)
(:conc-name))
(type 'expanded-bitmap-field) ; type = expanded-bitmap
(zone (make-zone)) ; bounding zone
(properties (list nil)) ; empty plist
(subfields nil) ; individual bits
(selection nil) ; which one last hit
(nrows 1)
(ncols 1)
)
(defvar expanded-bitmap-field-properties
`("expanded-bitmap-field-properties"
= ,aggregate-field-properties
)) ; can use this as real plist for online documentation
(defun draw-expanded-bitmap-field (f)
(draw-aggregate-field f))
(defun init-expanded-bitmap-field (f)
(let ((s (divide-points ; calculate x,y dimensions
(box-size (zone-box (field-zone f)))
(make-point
x (expanded-bitmap-field-ncols f)
y (expanded-bitmap-field-nrows f)))))
(do ((z (field-zone f))
(r nil)
(x (x (ll (zone-box (field-zone f)))))
(y (y (ll (zone-box (field-zone f))))
(+ y dy))
(dx (x s))
(dy (y s))
(nc (expanded-bitmap-field-nrows f))
(nr (expanded-bitmap-field-nrows f))
(j 0 (1+ j)))
((= j nr) (alter-aggregate-field f subfields (nreverse r)) 't)
(do ((x x (+ x dx))
(p)
(i 0 (1+ i)))
((= i nc)) ; create a row of buttons
(setq p (make-point x x y y))
(setq r (xcons r (make-button-field zone (append z nil))))
(alter-zone (field-zone (car r))
box (make-box ll p ur (add-points p s)))
))))
(defun resize-expanded-bitmap-field (f box)
(alter-zone (field-zone f) box box)
(let ((s (divide-points ; calculate x,y dimensions
(box-size box)
(make-point
x (expanded-bitmap-field-ncols f)
y (expanded-bitmap-field-nrows f)))))
(do ((z (field-zone f))
(r (expanded-bitmap-field-subfields f))
(x (x (ll box)))
(y (y (ll box)) (+ y dy))
(dx (x s))
(dy (y s))
(nc (expanded-bitmap-field-nrows f))
(nr (expanded-bitmap-field-nrows f))
(j 0 (1+ j)))
((= j nr) t)
(do ((x x (+ x dx))
(p)
(i 0 (1+ i)))
((= i nc)) ; create a row of buttons
(setq p (make-point x x y y))
(resize-button-field (car r)
(make-box ll p ur (add-points p s)))
(setq r (cdr r))
))))
(defun check-expanded-bitmap-field (f p)
(check-aggregate-field f p)) ; if we get here it's a hit -> check subfields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; utilities.l ;
;;; ;
;;; These macros and functions are thought to be generally useful. ;
;;; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Macros ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declare
(macros t) ; keep macros around after compiling
(localf pairify* pairifyq* split2* sublist*)
(special compiled-with-help))
(defmacro copy-all-but-last (ls) ; copy all but last member of list
`(let ((ls ,ls))
(firstn (1- (length ls))
ls)))
(defmacro all-but-last (ls) ; destructive all-but-last
`(let ((ls ,ls))
(cond ((cdr ls)
(rplacd (nthcdr (- (length ls) 2) ls) nil)
ls))))
(def hex (macro (arglist) ; hex to integer conversion
`(car (hex-to-int ',(cdr arglist)))))
;;; define properties on symbols for use by help routines
(defmacro def-usage (fun usage returns group)
(cond (compiled-with-help ; flag controls help generation
`(progn (putprop ,fun ,usage 'fcn-usage)
(putprop ,fun ,returns 'fcn-returns)
(putprop ,fun (nconc ,group (ncons ,fun)) 'fcn-group)))))
(defvar compiled-with-help t) ; unless otherwise notified
;;; (letenv 'l_bind_plist g_expr1 ... g_exprn) -- pair-list form of "let"
;;; Lambda-binds pairs of "binding-objects" (see description of let,let*),
;;; at RUN TIME, then evaluates g_expr1 to g_exprn, returning g_exprn. eg:
;;; (apply 'letenv '(letenv '(a 1 b (+ c d))
;;; (e)(f g)))
;-> (eval (cons 'let (cons (pairify '(a 1 b (+ c d)))
;;; '((e) (f g)))))
;-> (let ((a 1) (b (+ c d)))
;;; (e) (f g))
(def letenv
(macro (x)
`(eval (cons 'let
(cons
(pairify ,(cadr x)) ; plist of binding objects
',(cddr x)))))) ; exprs to be eval'ed
(def letenvq ; letenv, quoted binding objects
(macro (x)
`(eval (cons 'let
(cons
(pairifyq ,(cadr x)) ; plist of binding objects
',(cddr x)))))) ; exprs to be eval'ed
(defmacro mergecar (L1 L2 cmpfn) ; merge, comparing by car's
`(merge ,L1 ,L2 '(lambda (e1 e2) ; (like sortcar)
(funcall ,cmpfn (car e1) (car e2)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Functions ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; (all-but-last l_items) -- copy all but last list element
;(defun all-but-last (ls)
; (cond ((cdr ls) (cons (car ls) (all-but-last (cdr ls))))))
;;; (alphap sx_char)
(defun alphap (char) ; is char alphabetic?
(cond ((symbolp char)
(setq char (car (exploden char)))))
(and (fixp char)
(or (and (>& char #.(1- #/A))
(<& char #.(1+ #/Z)))
(and (>& char #.(1- #/a))
(<& char #.(1+ #/z))))))
;;; (alphanumericp sx_char)
(defun alphanumericp (char) ; is char alphabetic or numeric?
(cond ((symbolp char)
(setq char (car (exploden char)))))
(and (fixp char)
(or (and (>& char #.(1- #/A))
(<& char #.(1+ #/Z)))
(and (>& char #.(1- #/a))
(<& char #.(1+ #/z)))
(and (>& char #.(1- #/0))
(<& char #.(1+ #/9))))))
;;; (assqonc 'g_key 'g_val 'l_al)
;;; like (cond ((assq key alist))
;;; (t (cadr (rplacd (last alist)
;;; (ncons (cons key val))))))
(defun assqonc (key val al) ; tack (key.val) on end if not found
(do ((al al (cdr al)))
((or (eq key (caar al))
(and (null (cdr al))
(rplacd al (setq al (ncons (cons key val))))))
(car al))))
;;; (cartesian l_xset l_yset)
(defun cartesian (xset yset) ; cartesian product of elements
(mapcan
'(lambda (x)
(mapcar
'(lambda (y) (cons x y))
yset))
xset))
(defun concat-pairs (sb-list) ; concat neighbouring symbol pairs
(do ((s1 (car sb-list) s2)
(s2 (cadr sb-list) (car sbs-left))
(sbs-left (cddr sb-list) (cdr sbs-left))
(result nil (cons (concat s1 s2) result)))
((null s2) (nreverse result))))
;;; (detach l)
;;; Detaches (and throws away) first element of list (converse of attach)
;;; keeping the same initial list cell.
(defun detach (l)
(cond (l (rplacd l (cddr (rplaca l (cadr l)))))))
;;; (distribute x_Q x_N)
;;; returns list of the form: (1 1 1 0 0 0 0 1 1) or (3 2 2 2 3)
;;; i.e. a list of length <N> containing quantity <Q> evenly distributed
;;; with the excess <Q mod N> surrounding a "core" of <Q div N>'s
;;; Useful (?) for padding spaces in line adjustment.
;(defun distribute (Q N) ; this one only does 1's and 0's
; (cond ((signp le Q) (duplicate N 0))
; ((eq Q 1) (pad 0 N '(1)))
; (t (cons 1 (nconc
; (distribute (- Q 2) (- N 2))
; '(1))))))
(defun distribute (Q N) ; distribute quantity Q among N elements
(let ((tmp (Divide (abs Q) N)))
(setq tmp (distribute0 (cadr tmp) N (car tmp) (1+ (car tmp))))
(cond ((signp ge Q) tmp)
(t (mapcar 'minus tmp)))))
(defun distribute0 (Q N X X1)
(cond ((signp le Q) (duplicate N X))
((eq Q 1) (pad X N (ncons X1)))
(t (cons X1 (nconc
(distribute0 (- Q 2) (- N 2) X X1)
(ncons X1))))))
;;; (duplicate x_n g_object)
;;; Returns list of n copies of object (nil if n <= 0)
(defun duplicate (n object)
(do ((res nil (cons object res))
(i n (1- i)))
((signp le i) res)))
(defun e0 (in out) ; simulate binary insertion procedure
(let ((lin (length in))
(lout (length out)))
(cond ((> lin lout)
(e0
(nthcdr lout in)
(mapcan 'list out (firstn lout in))))
(t (nconc (mapcan 'list (firstn lin out) in)
(nthcdr lin out))))))
(defun e (files) ; determine file permutation for emacs insert
(let ((i (e0 (cdr (iota (length files))) '(0)))
(f (append files nil)))
(mapc '(lambda (f-index f-name)
(rplaca (nthcdr f-index f) f-name))
i files)
f))
;;; (firstn x_n l_listarg)
(defun firstn (n l) ; copy first <n> elements of list
(do ((n n (1- n))
(l l (cdr l))
(r nil))
((not (plusp n)) (nreverse r)) ; <nil> if n=0 or -ve
(setq r (cons (car l) r))))
;;; (iota x_n)
;;; APL index generator (0,1,2,...,<n>-1)
(defun iota (n)
(do ((i (1- n) (1- i))
(res nil))
((minusp i) res)
(setq res (cons i res))))
(defun hex-to-int (numlist) ; eg. (hex-to-int '(12b3 120 8b))
(cond
(numlist ; terminate recursion on null numlist
(cons
(apply '+
(maplist
'(lambda (digits)
(lsh
(get '(hex |0| 0 |1| 1 |2| 2 |3| 3
|4| 4 |5| 5 |6| 6 |7| 7
|8| 8 |9| 9 a 10 b 11
c 12 d 13 e 14 f 15)
(car digits))
(lsh (1- (length digits)) 2)))
(explodec (car numlist))))
(hex-to-int (cdr numlist))))))
;;; (lctouc g_expr)
;;; Returns s-expression formed by translating lower-case alphabetic
;;; characters in <expr> to their upper-case equivalents.
;;; Operates by imploding the translated characters, in the case of a
;;; symbol or string, or by recursively calling on members of a list.
;;; Other object types are returned unchanged.
(defun lctouc (expr)
(cond
((dtpr expr) (mapcar 'uctolc expr))
((or (symbolp expr) (stringp expr))
(implode
(mapcar
'(lambda (ch)
(cond ((alphap ch) ; and-out lower-case bit
(boole 1 #.(1- (1- #/a)) ch)) (t ch)))
(exploden expr))))
(t expr)))
;;; (log2 x_n)
(defun log2 (n) ; log base 2 (truncated)
(do ((n (lsh n -1) (lsh n -1))
(p 0 (1+ p)))
((zerop n) p)))
;;; (lowerp sx_char)
(defun lowerp (char) ; is char lower-case alphabetic?
(cond ((symbolp char)
(setq char (car (exploden char)))))
(and (fixp char)
(or (and (> char #.(1- #/a))
(< char #.(1+ #/z))))))
;;; (numericp sx_char)
;;; returns t if char is numeric, otherwise nil
(defun numericp (char)
(cond ((symbolp char)(setq char (car (exploden char)))))
(and (fixp char)
(and (> char #.(1- #/0))
(< char #.(1+ #/9)))))
;;; (pad g_item x_n l_list)
;;; Returns <list> padded with copies of <item> to length <n>
(defun pad (item n list)
(append list (duplicate (- n (length list)) item)))
;;; (pairify l_items) ; make a-list from alternating elements
(defun pairify (pl)
(pairify* nil pl))
(defun pairify* (rs pl) ; tail-recursive local fun
(cond (pl (pairify* (cons (list (car pl) (cadr pl)) rs)
(cddr pl)))
(t (nreverse rs))))
;;; (pairifyq l_items) ; make a-list from alternating elements
(defun pairifyq (pl) ; with each second element quoted
(pairifyq* nil pl))
(defun pairifyq* (rs pl) ; tail-recursive local fun
(cond (pl (pairifyq* (cons (list (car pl) (kwote (cadr pl))) rs)
(cddr pl)))
(t (nreverse rs))))
;;; (penultimate l_items) ; cdr down to next-to-last list element
(defun penultimate (ls)
(cond ((cddr ls) (penultimate (cdr ls)))
(t ls)))
;;; (split2 l_L)
;;; Splits list <L> into two (new) second-level lists
(defun split2* (L tc1 tc2)
(cond ((null L) (list (nreverse tc1) (nreverse tc2)))
(t (split2* (cddr L)
(cons (car L) tc1)
(cons (cadr L) tc2)))))
(defun split2 (L)
(split2* L nil nil))
;;; (sublist L IL)
;;; Splits list <L> (destructively) into (length IL) sub-lists.
;;; IL is a list of starting indices, base zero, should be unique positive
;;; fixnums in ascending order, and shouldn't exceed the length of L.
;;; Each resulting sublist <i> begins with (nthcdr (nth <i> IL) L)
(defun sublist (L IL)
(sublist* 0 nil (cons nil L) IL))
(defun sublist* (I R L IL) ; tail-recursion function
(cond ((and L IL)
(cond
((<& I (car IL))
(sublist* (1+ I) R (cdr L) IL))
(t (sublist* (1+ I)
(cons (cdr L) R)
(prog1 (cdr L) (rplacd L nil))
(cdr IL)))))
(t (nreverse R))))
(defun try-fun (fun l-arg) ; try function on each arg until non-nil
(cond ((funcall fun (car l-arg)))
(l-arg (try-fun fun (cdr l-arg)))))
;;; (uctolc g_expr)
;;; Returns s-expression formed by translating upper-case alphabetic
;;; characters in <expr> to their lower-case equivalents.
;;; Operates by imploding the translated characters, in the case of a
;;; symbol or string, or by recursively calling on members of a list.
;;; Other object types are returned unchanged.
(defun uctolc (expr)
(cond
((dtpr expr) (mapcar 'uctolc expr))
((or (symbolp expr) (stringp expr))
(implode
(mapcar
'(lambda (ch)
(cond ((alphap ch) ; or-in lower-case bit
(boole 7 #.(1- #/a) ch)) (t ch)))
(exploden expr))))
(t expr)))
;;; (unique a l) -- Scan <l> for an element <e> "equal" to <a>.
;;; If found, return <e>. Otherwise nconc <a> onto <l>; return <a>.
(defun unique (a l) ; ensure unique in list
(car
(do ((cdr_ul l (cdr ul))
(ul l cdr_ul))
((null cdr_ul) (rplacd ul (ncons a)))
(cond ((equal a (car cdr_ul)) (return cdr_ul))))))
;;; (upperp sx_char)
(defun upperp (char) ; is char upper-case alphabetic?
(cond ((symbolp char)
(setq char (car (exploden char)))))
(and (fixp char)
(or (and (> char #.(1- #/A))
(< char #.(1+ #/Z))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; zone.l -- data structures and routines for concrete window zones
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; a "point" is a pair of integer x,y coordinates
;;; a "box" is a pair of points defining lower left and upper right corners
;;; a "position" is a point coupled with a window
;;; a "zone" is a box coupled with a window
;;; a "window" is a machine, integer window id and, for compatibility
;;; with the toolbox, an integer toolbox window pointer
;;; a "machine" is a name coupled with the j-process-id's of resident servers
;;; The basic idea is to define a notion of a concrete position for a
;;; display object, that can be incorporated into the object data structure.
;;; Higher levels of software can use the objects without explicit reference
;;; to server processes, windows and machines.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declare
(specials t) ; global vars not local to this file
(macros t)) ; compile macros as well
(eval-when (compile) ; trust to higher level for eval & load
(load 'utilities) ; utility functions
(load 'constants) ; common constants for window toolbox
; (load 'shape) ; arbitrarily shaped screen areas
)
(defstruct
(position ; a concrete display position
(:displace t)
(:list)
(:conc-name))
(window (make-window)) ; concrete window
(point (make-point)) ; actual x, y coordinates
)
(defstruct
(zone ; a concrete display zone
(:displace t)
(:list)
(:conc-name))
(window (make-window)) ; concrete window
(box (make-box)) ; bounding box of zone
(colour W-BACKGROUND) ; colour (for scrolling etc)
shape
)
(defstruct
(window ; concrete window
(:displace t)
(:list)
(:conc-name))
(id 0) ; integer window id
(machine (make-machine)) ; machine (workstation)
(w 0) ; toolbox window structure pointer
)
(defstruct
(machine ; machine (workstation)
(:displace t)
(:list)
(:conc-name))
(name 'unknown-machine) ; machine name
(servers nil) ; plist of server processes living there
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; manipulation routines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun add-points (p q) ; vector sum (x1+x2) (y1+y2)
(make-point
x (+ (x p) (x q))
y (+ (y p) (y q))))
(defun subtract-points (p q) ; vector subtract (x1-x2) (y1-y2)
(make-point
x (- (x p) (x q))
y (- (y p) (y q))))
(defun multiply-points (p q) ; vector multiply (x1*x2) (y1*y2)
(make-point
x (* (x p) (x q))
y (* (y p) (y q))))
(defun divide-points (p q) ; vector division (x1-x2) (y1-y2)
(make-point
x (/ (x p) (x q))
y (/ (y p) (y q))))
(defun move-point (p q) ; move point p to point q
(alter-point p
x (x q)
y (y q))
t) ; return true
(defun box-size (b) ; size of box = ur - ll
(subtract-points (ur b) (ll b)))
(defun box-interior (b) ; return box just inside this box dimensions
(make-box
ll (add-points (ll b) '(1 1))