summaryrefslogtreecommitdiff
path: root/Build/source/utils/xindy-old/src/markup.lsp
blob: 4cb73feb508773b5114d4f2f0abaa915b8322fd6 (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
;; line 1154 "markup.nw"
;; $Id: markup.nw,v 1.24 1997/03/26 16:18:58 kehr Exp $

(lisp:defpackage "MARKUP")
(lisp:in-package "MARKUP")
(lisp:provide "markup")
#+CLISP (lisp:require "base")
#+CLISP (lisp:require "locref")
#+CLISP (lisp:require "idxstyle")
#+CLISP (lisp:require "index")

(eval-when (compile load eval)
  (lisp:use-package "CLOS")
  #+(and :XP CLISP) (lisp:use-package "XP")
  #+CLISP (setq custom:*suppress-check-redefinition* t)
  #-CLISP (lisp:require "base")
  #-CLISP (lisp:require "locref")
  #-CLISP (lisp:require "idxstyle")
  #-CLISP (lisp:require "index")
  (lisp:require "version")
  (lisp:use-package "BASE")
  (lisp:use-package "LOCREF")
  (lisp:use-package "IDXSTYLE")
  (lisp:use-package "INDEX"))

;; line 1222 "markup.nw"
;; $Id: markup.nw,v 1.24 1997/03/26 16:18:58 kehr Exp $

;; line 71 "markup.nw"
(defparameter *markup-output-stream* *standard-output*)
(defparameter *markup-verbose-mode*  nil)
(defparameter *markup-verbose-open*  "<")
(defparameter *markup-verbose-close* ">")
(defparameter *markup-indentation*   2)
(defparameter *markup-indent-level*  0)
(defparameter *empty-markup* "")

(defvar *markup-percentage-list*)
(defvar *current-number*)

(defun do-markup-indent ()
  (incf *markup-indent-level* *markup-indentation*))
(defun do-markup-outdent ()
  (decf *markup-indent-level* *markup-indentation*))
;; line 102 "markup.nw"
(defun do-markup-string (str)
  (declare (inline))
  (write-string str *markup-output-stream*))
;; line 111 "markup.nw"
(defun do-markup-default (str &optional arg1 arg2 arg3)
  (when *markup-verbose-mode*
    (loop for x from 1 to *markup-indent-level*
          do (write-string " " *markup-output-stream*))
    (do-markup-string *markup-verbose-open*)
    (do-markup-string str)
    (when arg1
      (format *markup-output-stream* " [~S]" arg1)
      (when arg2
        (format *markup-output-stream* " [~S]" arg2)
        (when arg3
          (format *markup-output-stream* " [~S]" arg3)
          )))
    (do-markup-string *markup-verbose-close*)
    (terpri *markup-output-stream*)
    ))
;; line 138 "markup.nw"
(defmacro do-markup-list (some-list
                          &key
                          identifier counter
                          elt-body   sep-body
                          open-body  close-body)
  `(PROGN
    ,(when open-body `,open-body)
    (LET ,(if counter
              `((LIST-END (CAR (LAST ,some-list)))
                (COUNTER ,counter))
              `((LIST-END (CAR (LAST ,some-list)))))
      (DO ((SLIST ,some-list (CDR SLIST)))
          ((ENDP SLIST))
        (LET ((,identifier (CAR SLIST)))
          ,elt-body
          ,(if sep-body
               `(UNLESS (EQL ,identifier LIST-END)
                 ,sep-body)))))
    ,(when close-body close-body)))
;; line 162 "markup.nw"
#|
(macroexpand '(markup-list '(1 2 3) :identifier FOO
               :open-body  (print "open")
               :close-body (print "close")
               :elt-body   (print FOO)
               :sep-body   (print ",")))

expands to

(PROGN (PRINT "open")
  (LET ((LIST-END (CAR (LAST '(1 2 3)))))
    (DO ((SLIST '(1 2 3) (CDR SLIST))) ((ENDP SLIST))
      (LET ((FOO (CAR SLIST))) (PRINT FOO)
        (UNLESS (EQL FOO LIST-END) (PRINT ","))
  ) ) )
  (PRINT "close")
) ;
T
|#
;; line 193 "markup.nw"
(defmacro define-list-environment-methods (name
                                           signature
                                           &key open close sep declare body)
  (let ((name (stringify name)))
    `(EVAL-WHEN (COMPILE LOAD EVAL)
      (HANDLER-BIND ((WARNING #'MUFFLE-WARNING))
       (CL:DEFMETHOD
           ,(intern (string-upcase (concatenate 'string name "-open"))
                    'markup)
           ,signature ,@declare ,@open ,@body)
       (CL:DEFMETHOD
           ,(intern (string-upcase (concatenate 'string name "-close"))
                    'markup)
           ,signature ,@declare ,@close ,@body)
       (CL:DEFMETHOD
           ,(intern (string-upcase (concatenate 'string name "-sep"))
                    'markup)
           ,signature ,@declare ,@sep ,@body)))))
;; line 214 "markup.nw"
(defmacro define-environment-methods (name
                                      signature
                                      &key open close declare body)
  (let ((name (stringify name)))
    `(EVAL-WHEN (COMPILE LOAD EVAL)
      (HANDLER-BIND ((WARNING #'MUFFLE-WARNING))
       (CL:DEFMETHOD
           ,(intern (string-upcase (concatenate 'string name "-open"))
                    'markup)
           ,signature ,@declare ,@open ,@body)
       (CL:DEFMETHOD
           ,(intern (string-upcase (concatenate 'string name "-close"))
                    'markup)
           ,signature ,@declare ,@close ,@body)))))

(defmacro define-method (name
                         signature
                         &key declare body)
  (let ((name (stringify name)))
    `(EVAL-WHEN (COMPILE LOAD EVAL)
      (HANDLER-BIND ((WARNING #'MUFFLE-WARNING))
       (CL:DEFMETHOD
           ,(intern (string-upcase name) 'markup)
           ,signature ,@declare ,@body)))))
;; line 326 "markup.nw"
(defmethod do-markup-index ((idx base-index))
  (setq *current-number* 0)
  (setq *markup-percentage-list* index:*percentage-list*)
  (do-markup-index-open idx)
  (do-markup-list (get-entries idx)
    :identifier LETTER-GRP
    :open-body  (do-markup-letter-group-list-open)
    :elt-body   (do-markup-letter-group LETTER-GRP)
    :sep-body   (do-markup-letter-group-list-sep)
    :close-body (do-markup-letter-group-list-close))
  (index:print-rest-of-percentages *markup-percentage-list*)
  (do-markup-index-close idx))

(define-environment-methods do-markup-index ((idx base-index))
  :open  ((do-markup-default "INDEX:OPEN")
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "INDEX:CLOSE")))
;; line 351 "markup.nw"
(defmacro markup-index (&whole whole &rest args)
  (destructuring-switch-bind (&key
                              open close hierdepth
                              &switch
                              tree flat)
      args
    (let (hierdepth-cmd)
      (when (or hierdepth tree flat)
        (cond
          ((and tree flat)
             (error "you can't specify :tree and :flat simultaneously in ~%~S~%"
                     whole))
          ((and hierdepth (or tree flat))
             (error "you can't specify :hierdepth with :tree or :flat simultaneously in ~%~S~%"
                     whole))
          (flat (setq hierdepth-cmd
                      `(SET-HIERDEPTH 0 *INDEX*)));; no tree-structure
          ;; MOST-POSITIVE-FIXNUM means make all trees
          (tree (setq hierdepth-cmd
                      `(SET-HIERDEPTH MOST-POSITIVE-FIXNUM *INDEX*)))
          (hierdepth
             (when (not (numberp hierdepth))
               (error "~S is not a number in ~S~%" whole))
             (setq hierdepth-cmd
                   `(SET-HIERDEPTH ,hierdepth *INDEX*))))
        `(LET ()
          (markup::define-environment-methods
              DO-MARKUP-INDEX ((idx index:base-index))
            :declare ((declare (ignore idx)))
            :open  ,(when open  `((do-markup-string ,open)))
            :close ,(when close `((do-markup-string ,close))))
          ,hierdepth-cmd)))))
;; line 390 "markup.nw"
(define-list-environment-methods do-markup-letter-group-list ()
  :open  ((do-markup-default "LETTER-GROUP-LIST:OPEN")
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LETTER-GROUP-LIST:CLOSE"))
  :sep   ((do-markup-default "LETTER-GROUP-LIST:SEP")))
;; line 409 "markup.nw"
(defmethod do-markup-letter-group ((letter-grp letter-group))
  (let ((group-definition (get-group-definition letter-grp)))
    (do-markup-letter-group-open       group-definition)
    (do-markup-letter-group-head-open  group-definition)
    (do-markup-letter-group-head       group-definition)
    (do-markup-letter-group-head-close group-definition)
    (do-markup-list (get-members letter-grp)
      :identifier IDXENT #| the identifier to use in the expansion |#
      :open-body  (do-markup-indexentry-list-open  0
                    #|initial depth:=0|#)
      :elt-body   (do-markup-indexentry IDXENT     0)
      :sep-body   (do-markup-indexentry-list-sep   0)
      :close-body (do-markup-indexentry-list-close 0))
    (do-markup-letter-group-close group-definition)))

(define-environment-methods do-markup-letter-group
    ((group letter-group-definition))
  :open  ((do-markup-default "LETTER-GROUP:OPEN"  (get-name group))
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LETTER-GROUP:CLOSE" (get-name group))))

(define-environment-methods do-markup-letter-group-head
    ((group letter-group-definition))
  :open  ((do-markup-default "LETTER-GROUP-HEAD:OPEN"  (get-name group))
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LETTER-GROUP-HEAD:CLOSE" (get-name group))))

(define-method do-markup-letter-group-head ((group letter-group-definition))
  :body ((do-markup-default "LETTER-GROUP-HEAD" (get-name group))))
;; line 503 "markup.nw"
(define-list-environment-methods do-markup-indexentry-list ((depth number))
  :open  ((do-markup-default "INDEXENTRY-LIST:OPEN"  depth)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "INDEXENTRY-LIST:CLOSE" depth))
  :sep   ((do-markup-default "INDEXENTRY-LIST:SEP"   depth)))
;; line 525 "markup.nw"
(defmethod do-markup-indexentry ((idxent index-entry)
                                 (depth number))
  (when (>= (incf *current-number*) (caar *markup-percentage-list*))
    (index:print-percent (pop *markup-percentage-list*)))

  (do-markup-indexentry-open depth)

  (let ((print-key (get-print-key idxent)))
    (do-markup-list (merge-print-and-main-key print-key (get-main-key idxent))
      :identifier KEYWORD
      :open-body  (do-markup-keyword-list-open  depth)
      :elt-body   (do-markup-keyword   KEYWORD  depth)
      :sep-body   (do-markup-keyword-list-sep   depth)
      :close-body (do-markup-keyword-list-close depth)))

  (let ((locrefs (get-locrefs idxent)))
    (unless (endp locrefs)
      (do-markup-list locrefs
        :identifier LOCCLS-GRP
        :open-body  (do-markup-locclass-list-open)
        :elt-body   (do-markup-locclass LOCCLS-GRP)
        :sep-body   (do-markup-locclass-list-sep)
        :close-body (do-markup-locclass-list-close))))

  (let ((subentries (get-subentries idxent)))
    (unless (endp subentries)
      (let ((new-depth (1+ depth)))
        (do-markup-list subentries
          :identifier IDXENT
          :open-body  (do-markup-indexentry-list-open  new-depth)
          :elt-body   (do-markup-indexentry IDXENT     new-depth)
          :sep-body   (do-markup-indexentry-list-sep   new-depth)
          :close-body (do-markup-indexentry-list-close new-depth)))))

  (do-markup-indexentry-close depth))

(defun merge-print-and-main-key (print-key main-key)
  ;;(info "~&(merge-print-and-main-key ~S ~S)" print-key main-key)
  (if print-key
      (mapcar #'(lambda (print main)
                  (or print main))
              print-key main-key)
      main-key))
;; line 571 "markup.nw"
(define-environment-methods do-markup-indexentry ((depth number))
  :open  ((do-markup-default "INDEXENTRY:OPEN"  depth)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "INDEXENTRY:CLOSE" depth)))
;; line 595 "markup.nw"
(define-list-environment-methods do-markup-keyword-list ((depth number))
  :open  ((do-markup-default "KEYWORD-LIST:OPEN"  depth)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "KEYWORD-LIST:CLOSE" depth))
  :sep   ((do-markup-default "KEYWORD-LIST:SEP"   depth)))
;; line 617 "markup.nw"
(defmethod do-markup-keyword (keyword (depth number))
  (do-markup-keyword-open depth)
  (do-markup-string keyword)
  (do-markup-keyword-close depth))
;; line 624 "markup.nw"
(define-environment-methods do-markup-keyword ((depth number))
  :open  ((do-markup-default "KEYWORD:OPEN"  depth)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "KEYWORD:CLOSE" depth)))
;; line 654 "markup.nw"
(define-list-environment-methods do-markup-locclass-list ()
  :open  ((do-markup-default "LOCCLASS-LIST:OPEN")
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LOCCLASS-LIST:CLOSE"))
  :sep   ((do-markup-default "LOCCLASS-LIST:SEP")))
;; line 677 "markup.nw"
(defmethod do-markup-locclass ((locref-cls-grp locref-class-group))
  (let ((locclass (get-locclass locref-cls-grp)))
    (do-markup-locref-class-open locclass)

    (do-markup-list (get-members locref-cls-grp)
      :identifier ATTRIBUTE-GRP
      :open-body  (do-markup-attribute-group-list-open)
      :elt-body   (do-markup-attribute-group ATTRIBUTE-GRP locclass)
      :sep-body   (do-markup-attribute-group-list-sep)
      :close-body (do-markup-attribute-group-list-close))

    (do-markup-locref-class-close locclass)))

(define-environment-methods do-markup-locref-class
    ((locrefcls layered-location-class))
  :open  ((do-markup-default "LOCREF-CLASS:OPEN"  (get-name locrefcls))
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LOCREF-CLASS:CLOSE" (get-name locrefcls))))
;; line 1044 "markup.nw"
(defmethod do-markup-locclass ((xref-cls-grp crossref-class-group))
  (let ((xrefclass (get-locclass xref-cls-grp)))

    (do-markup-list (get-members xref-cls-grp)
      :identifier XREF
      :open-body  (do-markup-crossref-list-open  xrefclass)
      :elt-body   (do-markup-crossref            XREF)
      :sep-body   (do-markup-crossref-list-sep   xrefclass)
      :close-body (do-markup-crossref-list-close xrefclass))))

(define-list-environment-methods do-markup-crossref-list
    ((xrefclass crossref-location-class))
  :open  ((do-markup-default "CROSSREF-LIST:OPEN"  (get-name xrefclass))
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "CROSSREF-LIST:CLOSE" (get-name xrefclass)))
  :sep   ((do-markup-default "CROSSREF-LIST:SEP"   (get-name xrefclass))))
;; line 1080 "markup.nw"
(defmethod do-markup-crossref ((xref crossref-location-reference))
  (let ((xrefclass (get-locclass xref)))

    (do-markup-list (get-target xref)
      :identifier XREF-LAYER
      :open-body  (do-markup-crossref-layer-list-open  xrefclass)
      :elt-body   (do-markup-crossref-layer XREF-LAYER xrefclass)
      :sep-body   (do-markup-crossref-layer-list-sep   xrefclass)
      :close-body (do-markup-crossref-layer-list-close xrefclass))))

(define-list-environment-methods do-markup-crossref-layer-list
    ((xref-class crossref-location-class))
  :open  ((do-markup-default "CROSSREF-LAYER-LIST:OPEN"
            (get-name xref-class))
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "CROSSREF-LAYER-LIST:CLOSE"
            (get-name xref-class)))
  :sep   ((do-markup-default "CROSSREF-LAYER-LIST:SEP"
            (get-name xref-class))))
;; line 1119 "markup.nw"
(defmethod do-markup-crossref-layer (xref-layer
                                     (xref-class crossref-location-class))
  (do-markup-crossref-layer-open  xref-class)
  (do-markup-string               xref-layer)
  (do-markup-crossref-layer-close xref-class))

(define-environment-methods do-markup-crossref-layer
    ((xref-class crossref-location-class))
  :open  ((do-markup-default "CROSSREF-LAYER:OPEN"  (get-name xref-class))
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "CROSSREF-LAYER:CLOSE" (get-name xref-class))))
;; line 718 "markup.nw"
(define-list-environment-methods do-markup-attribute-group-list ()
  :open  ((do-markup-default "ATTRIBUTE-GROUP-LIST:OPEN")
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "ATTRIBUTE-GROUP-LIST:CLOSE"))
  :sep   ((do-markup-default "ATTRIBUTE-GROUP-LIST:SEP")))
;; line 737 "markup.nw"
(defmethod do-markup-attribute-group ((attribute-group category-attribute-group)
                                      (loccls layered-location-class))
  (let ((ordnum (get-ordnum attribute-group)))
    (do-markup-attribute-group-open ordnum)

    (do-markup-list (get-members attribute-group)
      :identifier LOCREF
      :open-body  (do-markup-locref-list-open  loccls 0)
      :elt-body   (do-markup-locref     LOCREF loccls 0)
      :sep-body   (do-markup-locref-list-sep   loccls 0)
      :close-body (do-markup-locref-list-close loccls 0))

    (do-markup-attribute-group-close ordnum)))

(define-environment-methods do-markup-attribute-group ((ordnum number))
  :open  ((do-markup-default "ATTRIBUTE-GROUP:OPEN"  ordnum)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "ATTRIBUTE-GROUP:CLOSE" ordnum)))
;; line 776 "markup.nw"
(define-list-environment-methods do-markup-locref-list
    ((loccls layered-location-class) (depth number))
  :open  ((do-markup-default "LOCREF-LIST:OPEN"  (get-name loccls) depth)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LOCREF-LIST:CLOSE" (get-name loccls) depth))
  :sep   ((do-markup-default "LOCREF-LIST:SEP"   (get-name loccls) depth)))
;; line 808 "markup.nw"
(defmethod do-markup-locref ((locref location-reference)
                             (loccls layered-location-class)
                             (depth  number))
  #+ASSERT! (assert! (and (typep locref 'layered-location-reference)
                          (typep depth 'number)))
  (let ((attr    (get-catattr  locref))
        (subrefs (get-subrefs  locref))
        (new-depth (1+ depth)))

    (do-markup-locref-open attr loccls depth)

    (cond
      (subrefs
         (let ((layer 0))
           (do-markup-list (get-layers locref)
             :identifier LOCREF-LAYER
             :open-body  (do-markup-locref-layer-list-open  loccls depth)
             :elt-body   (do-markup-locref-layer LOCREF-LAYER loccls depth
                                                 (prog1 layer
                                                   (incf layer)))
             :sep-body   (do-markup-locref-layer-list-sep   loccls depth)
             :close-body (do-markup-locref-layer-list-close loccls depth)))

         (do-markup-list subrefs
           :identifier LOCREF
           :open-body  (do-markup-locref-list-open  loccls new-depth)
           :elt-body   (do-markup-locref     LOCREF loccls new-depth)
           :sep-body   (do-markup-locref-list-sep   loccls new-depth)
           :close-body (do-markup-locref-list-close loccls new-depth)))

      ((= 0 depth)
         (do-markup-string (get-locref-string locref)))

      (t (let ((layer 0))
           (do-markup-list (get-layers locref)
             :identifier LOCREF-LAYER
             :open-body  (do-markup-locref-layer-list-open  loccls depth)
             :elt-body   (do-markup-locref-layer LOCREF-LAYER loccls depth
                                                 (prog1 layer
                                                   (incf layer)))
             :sep-body   (do-markup-locref-layer-list-sep   loccls depth)
             :close-body (do-markup-locref-layer-list-close loccls depth)))))

    (do-markup-locref-close attr loccls depth)))
;; line 855 "markup.nw"
(define-list-environment-methods do-markup-locref-layer-list
    ((loccls layered-location-class) (depth  number))
  :open  ((do-markup-default "LOCREF-LAYER-LIST:OPEN"  (get-name loccls) depth)
          (do-markup-indent))
  :sep   ((do-markup-default "LOCREF-LAYER-LIST:SEP"   (get-name loccls) depth))
  :close ((do-markup-outdent)
          (do-markup-default "LOCREF-LAYER-LIST:CLOSE" (get-name loccls) depth)))
;; line 883 "markup.nw"
(defun do-markup-locref-layer (locref-layer loccls depth layer)
  (do-markup-locref-layer-open loccls depth layer)
  (do-markup-string locref-layer)
  (do-markup-locref-layer-close loccls depth layer))

(define-environment-methods do-markup-locref-layer
    ((locref-class layered-location-class) (depth number) (layer number))
  :open  ((do-markup-default "LOCREF-LAYER:OPEN"
            (get-name locref-class) depth layer)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LOCREF-LAYER:CLOSE"
            (get-name locref-class) depth layer)))
;; line 918 "markup.nw"
(define-environment-methods do-markup-locref ((attr   category-attribute)
                                              (loccls layered-location-class)
                                              (depth  number))
  :open  ((do-markup-default "LOCREF:OPEN"
            (get-name attr) (get-name loccls) depth)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "LOCREF:CLOSE"
            (get-name attr) (get-name loccls) depth)))
;; line 955 "markup.nw"
(defmethod do-markup-locref ((range location-range)
                             (loccls layered-location-class)
                             (depth number))
  (let ((length (get-length range)))
    (do-markup-range-open  loccls length)
    (do-markup-locref (get-first range) loccls depth)
    (do-markup-range-sep   loccls length)
    (when (markup-range-print-end-p loccls length)
      (do-markup-locref (get-last range)  loccls depth))
    (do-markup-range-close loccls length)))

(define-list-environment-methods do-markup-range
    ((loccls layered-location-class) (length number))
  :open  ((do-markup-default "RANGE:OPEN"  (get-name loccls) length)
          (do-markup-indent))
  :close ((do-markup-outdent)
          (do-markup-default "RANGE:CLOSE" (get-name loccls) length))
  :sep   ((do-markup-default "RANGE:SEP" (get-name loccls) length)))

(defmethod markup-range-print-end-p ((loccls layered-location-class)
                                     (length number))
  t)
;; line 304 "markup.nw"
(defmacro markup-trace (&rest args)
  (destructuring-switch-bind (&key
                              (open  *markup-verbose-open*)
                              (close *markup-verbose-close*)
                              &switch
                              on)
      args
    (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 312 "markup.nw"
          (t `(LET ()
               (SETQ *markup-verbose-open*  ,open)
               (SETQ *markup-verbose-close* ,close)
               ,(when on `(SETQ *markup-verbose-mode* t)))))))
;; line 399 "markup.nw"
(defmacro markup-letter-group-list (&key open close sep)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 401 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-LETTER-GROUP-LIST ()
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 443 "markup.nw"
(defmacro markup-letter-group (&whole whole &rest args)
  (destructuring-switch-bind (&key
                              open close group
                              open-head close-head
                              &switch
                              upcase downcase capitalize)
      args
    (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 451 "markup.nw"

;; line 252 "markup.nw"
((and open-head (not (stringp open-head)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open-head))
((and close-head (not (stringp close-head)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close-head))
;; line 452 "markup.nw"

;; line 275 "markup.nw"
((and group (progn
              (setq group (stringify group))
              (not (lookup-letter-group-definition *indexstyle* group))))
 (nraw "parameter `~S' is not a valid letter-group! (ignored)~%" group))
;; line 453 "markup.nw"
          ((or (and upcase downcase)
               (and upcase capitalize)
               (and downcase capitalize))
             (error "more than one modifier in~%~S" whole))
          (t `(LET ()
               (markup::define-environment-methods
                   DO-MARKUP-LETTER-GROUP
                   (,(if group
                         `(lg-def (EQL ',(lookup-letter-group-definition
                                          *indexstyle* group)))
                         '(lg-def letter-group-definition)))
                 :declare ((declare (ignore lg-def)))
                 :open  ,(when open  `((do-markup-string ,open)))
                 :close ,(when close `((do-markup-string ,close))))
               (markup::define-environment-methods
                   DO-MARKUP-LETTER-GROUP-HEAD
                   (,(if group
                         `(lg-def (EQL ',(lookup-letter-group-definition
                                          *indexstyle* group)))
                         '(lg-def letter-group-definition)))
                 :declare ((declare (ignore lg-def)))
                 :open  ,(when open-head  `((do-markup-string ,open-head)))
                 :close ,(when close-head `((do-markup-string ,close-head))))
               ,(when (or open-head close-head)
                      `(markup::define-method
                        DO-MARKUP-LETTER-GROUP-HEAD
                        (,(if group
                              `(lg-def (EQL ',(lookup-letter-group-definition
                                               *indexstyle* group)))
                              '(lg-def letter-group-definition)))
                        :body ((do-markup-string
                                   ,(cond (upcase     `(string-upcase
                                                        (get-name lg-def)))
                                          (downcase   `(string-downcase
                                                        (get-name lg-def)))
                                          (capitalize `(string-capitalize
                                                        (get-name lg-def)))
                                          (t `(get-name lg-def))))))))))))
;; line 512 "markup.nw"
(defmacro markup-indexentry-list (&key open close sep depth)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 514 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 515 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-INDEXENTRY-LIST
             (,(if depth `(depth (EQL ,depth)) '(depth number)))
             :declare ((declare (ignore depth)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 579 "markup.nw"
(defmacro markup-indexentry (&key open close depth)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 581 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 582 "markup.nw"
        (t `(markup::define-environment-methods
             DO-MARKUP-INDEXENTRY
             (,(if depth `(depth (EQL ,depth)) '(depth number)))
             :declare ((declare (ignore depth)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))))))
;; line 604 "markup.nw"
(defmacro markup-keyword-list (&key open close sep depth)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 606 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 607 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-KEYWORD-LIST
             (,(if depth `(depth (EQL ,depth)) '(depth number)))
             :declare ((declare (ignore depth)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 632 "markup.nw"
(defmacro markup-keyword (&key open close depth)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 634 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 635 "markup.nw"
        (t `(markup::define-environment-methods
             DO-MARKUP-KEYWORD
             (,(if depth `(depth (EQL ,depth)) '(depth number)))
             :declare ((declare (ignore depth)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))))))
;; line 663 "markup.nw"
(defmacro markup-locclass-list (&key open close sep)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 665 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-LOCCLASS-LIST ()
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 699 "markup.nw"
(defmacro markup-locref-class (&key open close class)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 701 "markup.nw"

;; line 282 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-locref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a location-reference class! (ignored)~%" class))
;; line 702 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-LOCREF-CLASS
             (,(if class
                   `(locrefcls (EQL ',(cdr (lookup-locref-class
                                            *indexstyle* class))))
                   '(locrefcls layered-location-class)))
             :declare ((declare (ignore locrefcls)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))))))
;; line 727 "markup.nw"
(defmacro markup-attribute-group-list (&key open close sep)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 729 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-ATTRIBUTE-GROUP-LIST ()
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 759 "markup.nw"
(defmacro markup-attribute-group (&key open close group)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 761 "markup.nw"

;; line 275 "markup.nw"
((and group (progn
              (setq group (stringify group))
              (not (lookup-letter-group-definition *indexstyle* group))))
 (nraw "parameter `~S' is not a valid letter-group! (ignored)~%" group))
;; line 762 "markup.nw"
        (t `(markup::define-environment-methods
             DO-MARKUP-ATTRIBUTE-GROUP
             (,(if group
                   `(ordnum (EQL ,group))
                   '(ordnum number)))
             :declare ((declare (ignore ordnum)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))))))
;; line 786 "markup.nw"
(defmacro markup-locref-list (&key open close sep class depth)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 788 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 789 "markup.nw"

;; line 282 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-locref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a location-reference class! (ignored)~%" class))
;; line 790 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-LOCREF-LIST
             (,(if class
                   `(locrefcls (EQL ',(cdr (lookup-locref-class
                                            *indexstyle* class))))
                   '(locrefcls layered-location-class))
              ,(if depth `(depth (EQL ,depth)) '(depth number)))
             :declare ((declare (ignore locrefcls depth)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 865 "markup.nw"
(defmacro markup-locref-layer-list (&key open close sep class depth)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 867 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 868 "markup.nw"

;; line 282 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-locref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a location-reference class! (ignored)~%" class))
;; line 869 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-LOCREF-LAYER-LIST
             (,(if class
                   `(locrefcls (EQL ',(cdr (lookup-locref-class
                                            *indexstyle* class))))
                   '(locrefcls layered-location-class))
              ,(if depth `(depth (EQL ,depth)) '(depth number)))
             :declare ((declare (ignore locrefcls depth)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 899 "markup.nw"
(defmacro markup-locref-layer (&key class open close depth layer)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 901 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 902 "markup.nw"

;; line 270 "markup.nw"
((and layer (not (integerp layer)))
 (nraw "parameter `~S' is not a number! (ignored)~%" layer))
;; line 903 "markup.nw"

;; line 282 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-locref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a location-reference class! (ignored)~%" class))
;; line 904 "markup.nw"
        (t `(markup::define-environment-methods
             DO-MARKUP-LOCREF-LAYER
             (,(if class
                   `(locrefcls (EQL ',(cdr (lookup-locref-class
                                            *indexstyle* class))))
                   '(locrefcls layered-location-class))
              ,(if depth `(depth (EQL ,depth)) '(depth number))
              ,(if layer `(layer (EQL ,layer)) '(layer number)))
             :declare ((declare (ignore depth layer)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))))))
;; line 930 "markup.nw"
(defmacro markup-locref (&key open close class attr depth)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 932 "markup.nw"

;; line 294 "markup.nw"
((and attr (progn (setq attr (stringify attr))
                   (not (lookup-catattr *indexstyle* attr))))
 (nraw "parameter `~S' is not an attribute! (ignored)~%" attr))
;; line 933 "markup.nw"

;; line 265 "markup.nw"
((and depth (not (integerp depth)))
 (nraw "parameter `~S' is not a number! (ignored)~%" depth))
;; line 934 "markup.nw"

;; line 282 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-locref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a location-reference class! (ignored)~%" class))
;; line 935 "markup.nw"
        (t `(markup::define-environment-methods
             DO-MARKUP-LOCREF
             (,(if attr
                   `(attr (EQL ',(lookup-catattr *indexstyle* attr)))
                   '(attr category-attribute))
              ,(if class
                   `(locrefcls (EQL ',(cdr (lookup-locref-class
                                            *indexstyle* class))))
                   '(locrefcls layered-location-class))
              ,(if depth `(depth (EQL ,depth)) '(depth number)))
             :declare ((declare (ignore attr locrefcls depth)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))))))
;; line 1002 "markup.nw"
(defmacro markup-range (&whole whole &rest args)
  (destructuring-switch-bind (&key
                              open close sep class length
                              &switch ignore-end)
      args
    (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 1008 "markup.nw"

;; line 282 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-locref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a location-reference class! (ignored)~%" class))
;; line 1009 "markup.nw"
          ((and length (not (numberp length)))
             (nraw "parameter `~S' is not a number! (ignored)~%" length))
          (t `(let ()
               (markup::define-list-environment-methods
                   DO-MARKUP-RANGE
                   (,(if class
                         `(locrefcls (EQL ',(cdr (lookup-locref-class
                                                  *indexstyle* class))))
                         '(locrefcls layered-location-class))
                    ,(if length
                         `(length (EQL ,length))
                         '(length number)))
                 :open  ,(when open  `((do-markup-string ,open)))
                 :close ,(when close `((do-markup-string ,close)))
                 :sep   ,(when sep   `((do-markup-string ,sep))))
               (define-method markup::MARKUP-RANGE-PRINT-END-P
                   (,(if class
                         `(locrefcls (EQL ',(cdr (lookup-locref-class
                                                  *indexstyle* class))))
                         '(locrefcls layered-location-class))
                    ,(if length
                         `(length (EQL ,length))
                         '(length number)))
                 :declare ((declare (ignore locrefcls length)))
                 :body    (,(not ignore-end))))))))
;; line 1064 "markup.nw"
(defmacro markup-crossref-list (&key open sep close class)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 1066 "markup.nw"

;; line 288 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-crossref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a cross-reference class! (ignored)~%" class))
;; line 1067 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-CROSSREF-LIST
             (,(if class
                   `(xrefcls (EQL ',(cdr (lookup-crossref-class *indexstyle*
                                                                class))))
                   '(xrefcls crossref-location-class)))
             :declare ((declare (ignore xrefcls)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 1103 "markup.nw"
(defmacro markup-crossref-layer-list (&key open sep close class)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 260 "markup.nw"
((and sep  (not (stringp sep)))
 (nraw "parameter `~S' is not a string! (ignored)~%" sep))
;; line 1105 "markup.nw"

;; line 288 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-crossref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a cross-reference class! (ignored)~%" class))
;; line 1106 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-CROSSREF-LAYER-LIST
             (,(if class
                   `(xrefcls (EQL ',(cdr (lookup-crossref-class *indexstyle*
                                                                class))))
                   '(xrefcls crossref-location-class)))
             :declare ((declare (ignore xrefcls)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))
             :sep   ,(when sep   `((do-markup-string ,sep)))))))
;; line 1134 "markup.nw"
(defmacro markup-crossref-layer (&key open close class)
  (cond
;; line 245 "markup.nw"
((and open (not (stringp open)))
 (nraw "parameter `~S' is not a string! (ignored)~%" open))
((and close (not (stringp close)))
 (nraw "parameter `~S' is not a string! (ignored)~%" close))
;; line 1136 "markup.nw"

;; line 288 "markup.nw"
((and class (progn (setq class (stringify class))
                   (not (lookup-crossref-class *indexstyle* class))))
 (nraw "parameter `~S' is not a cross-reference class! (ignored)~%" class))
;; line 1137 "markup.nw"
        (t `(markup::define-list-environment-methods
             DO-MARKUP-CROSSREF-LAYER
             (,(if class
                   `(xrefcls (EQL ',(cdr (lookup-crossref-class *indexstyle*
                                                                class))))
                   '(xrefcls crossref-location-class)))
             :declare ((declare (ignore xrefcls)))
             :open  ,(when open  `((do-markup-string ,open)))
             :close ,(when close `((do-markup-string ,close)))))))
;; line 1188 "markup.nw"
(eval-when (compile load eval)
  (defparameter *markup-user-interface-definitions*
    '(*markup-verbose-mode*
      *markup-verbose-open*
      *markup-verbose-close*
      markup-crossref-layer
      markup-crossref-layer-list
      markup-crossref-list
      markup-index
      markup-letter-group
      markup-letter-group-list
      markup-indexentry
      markup-indexentry-list
      markup-keyword
      markup-keyword-list
      markup-locclass-list
      markup-locref-class
      markup-attribute-group-list
      markup-attribute-group
      markup-locref-list
      markup-locref
      markup-locref-layer-list
      markup-locref-layer
      markup-range
      markup-trace
      )))

;; line 1238 "markup.nw"
(eval-when (compile load eval)

;; line 89 "markup.nw"
(export '(*markup-output-stream*
          *markup-verbose-mode*
          *markup-verbose-open*
          *markup-verbose-close*
          *indexstyle-readtable*))
;; line 347 "markup.nw"
(export '(do-markup-index))
;; line 1217 "markup.nw"
(export '*markup-user-interface-definitions*)
(export *markup-user-interface-definitions*)
;; line 1240 "markup.nw"
  )

;; line 1178 "markup.nw"
(defvar *RCS-Identifier* '(
;; line 1244 "markup.nw"
("markup" . "$Id: markup.nw,v 1.24 1997/03/26 16:18:58 kehr Exp $")
;; line 236 "startup.nw"
("startup" . "$Id: startup.nw,v 1.17 1997/03/26 16:19:03 kehr Exp $")
;; line 1178 "markup.nw"
                                               ))

;; this should be the last of the module since it defines the
;; additional package `xindy'.
;; line 210 "startup.nw"
;; $Id: startup.nw,v 1.17 1997/03/26 16:19:03 kehr Exp $

(lisp:defpackage  "XINDY")
(lisp:in-package  "XINDY")

(eval-when (compile load eval)
  (lisp:use-package "BASE")
  (lisp:use-package :xindy-version)
  (lisp:use-package "MARKUP")
  (lisp:use-package "CLOS")
  (lisp:use-package "COMMON-LISP")
  #+CLISP (lisp:use-package "EXT")
  (lisp:import markup:*markup-user-interface-definitions*))

(eval-when (compile load eval)
  (pushnew :HANDLER      *features*))
;; FIXME: error messages about package locks
;(eval-when (compile load eval)
;  (pushnew :BREAK-DRIVER *features*))

;; line 44 "startup.nw"
(defun issue-startup-message ()
  (info "xindy kernel version: ~A~%" *xindy-kernel-version*)
  (info "xindy run time engine: ~A, version ~A~%"
	*xindy-platform* xindy::*xindy-rte-version*)
  (info "~A version ~A~%    architecture: ~A~%"
	(lisp-implementation-type) (lisp-implementation-version)
	(machine-version))
  )

(defun startup (&key idxstyle rawindex output logfile
                     show-version markup-trace (trace-level 0))
  (when show-version
    (issue-startup-message)
    (exit-normally))
  (when markup-trace (setq *markup-verbose-mode* t))
  #+:HANDLER
  (handler-case
      (do-startup idxstyle rawindex output logfile trace-level)
    (error
        (condition)
      (oops* (simple-condition-format-string    condition)
             (simple-condition-format-arguments condition))
      (error-exit)))
  #-:HANDLER
  (do-startup idxstyle rawindex output logfile trace-level))
;; line 70 "startup.nw"
(defun do-startup (idxstyle raw-index output logfile trace-level)
  (set-searchpath-by-environment)
  (setq custom:*default-file-encoding* charset:iso-8859-1
	custom:*foreign-encoding* charset:iso-8859-1)
  (when logfile
    (info "~&Opening logfile ~S " logfile)
    (handler-case
        (setq *logging-stream* (open logfile
                                     :direction :output
                                     :if-does-not-exist :create
                                     :if-exists :supersede))
      (error ()
             (oops "Opening logfile ~S failed!" logfile)
             (error-exit)))
    (info "(done)~%")
    ;; Set necessary flags...
    (setq *logging-on* t)
    (case trace-level
      (0)
      (1 (setq *mappings-trace* t))
      (2 (setq *mappings-trace* t) (setq *locref-trace* t))
      (3 (setq *mappings-trace* t) (setq *locref-trace* t))
      (t (error "Invalid :trace-level ~S !" trace-level)))
    #+:ORDRULES (when *mappings-trace*
                  (setq ordrules::*message-logging* 1))

    (multiple-value-bind (sec min hour day mon year)
        (get-decoded-time)
      (gol t ";; This logfile was generated automatically by `xindy'~%")
      (gol t ";; at ~2,'0D.~2,'0D.~4,'0D  ~2,'0D:~2,'0D:~2,'0D~%"
           day mon year hour min sec))
    (gol t ";; Indexstyle: ~S, Rawindex: ~S, Output: ~S~%~%"
         idxstyle raw-index output)
    )

  (info "~&Reading indexstyle...~%")
  (let ((*readtable* idxstyle:*indexstyle-readtable*))
    (idxstyle:do-require idxstyle))
  (info "~&Finished reading indexstyle.")
  (info "~&Finalizing indexstyle... ")
  (idxstyle:make-ready idxstyle:*indexstyle*)
  (info "(done)~%~%")

  (info "~&Reading raw-index ~S..." raw-index)
  (load raw-index :verbose nil)
  (info "~&Finished reading raw-index.~%~%")

  (handler-case
      (setq *markup-output-stream*
            (open output
                  :direction :output
                  :if-does-not-exist :create
                  :if-exists :supersede))
    (error ()
           (oops "Opening file ~S failed!" output)
           (error-exit)))

  (info "~&Processing index...")
  (index:process-index index:*index*)
  (info "~&Finished processing index.~%~%")

  (info "~&Writing markup...")
  (markup:do-markup-index index:*index*)
  (info "~%Markup written into file ~S.~%" output))
;; line 139 "startup.nw"
(defun set-searchpath-by-environment ()
  (let ((sp (#+CLISP
             system::getenv
             #+ALLEGRO
             sys:getenv
             "XINDY_SEARCHPATH")))
    (when sp (idxstyle:set-searchpath-by-string sp))))
;; line 170 "startup.nw"
#+:BREAK-DRIVER
(fmakunbound '*break-driver*)

#+:BREAK-DRIVER
(defun *break-driver* (continuable
                       &optional (condition nil) (print-it nil)
                       &aux (may-continue
                             (or continuable
                                 (and condition
                                      (find-restart 'continue condition))
                                 ) )
                       (interactive-p (interactive-stream-p *debug-io*))
                       (commandsr '())
                       )
  (declare (ignore may-continue interactive-p commandsr))
  ;; This when-clause is from Bruno Haible.
  (when (and condition print-it)
    (terpri *error-output*)
    (write-string "*** - " *error-output*)
    #+CLISP (system::print-condition condition *error-output*)
    #-CLISP (print condition *error-output*)
    )
  (format *ERROR-OUTPUT* "~&Bye.")
  (error-exit))

#+:BREAK-DRIVER-OLD
(defun *break-driver* (continuable &rest rest)
  (declare (ignore continuable rest))
  (format *ERROR-OUTPUT* "~&Bye.")
  (error-exit))

#+:BREAK-DRIVER
(eval-when (compile load eval)
  (export '*break-driver*))

;; line 230 "startup.nw"
(eval-when (compile load eval)

;; line 135 "startup.nw"
(export '(startup *xindy-core-version* *xindy-platform*))
;; line 232 "startup.nw"
  )