1if not modules then modules = { } end modules [ ' typo-duc ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to typo-dir.mkiv " ,
4 author = " Hans Hagen, PRAGMA-ADE, Hasselt NL " ,
5 copyright = " PRAGMA ADE / ConTeXt Development Team " ,
6 license = " see context related readme files " ,
7 comment = " Unicode bidi (sort of) variant c " ,
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
49local insert , remove , unpack , concat = table . insert , table . remove , table . unpack , table . concat
50local utfchar = utf . char
51local setmetatable = setmetatable
52local formatters = string . formatters
53
54local directiondata = characters . directions
55local mirrordata = characters . mirrors
56local textclassdata = characters . textclasses
57
58local nuts = nodes . nuts
59
60local getnext = nuts . getnext
61local getid = nuts . getid
62local getsubtype = nuts . getsubtype
63local getlist = nuts . getlist
64local getchar = nuts . getchar
65local getattr = nuts . getattr
66local getprop = nuts . getprop
67local getdirection = nuts . getdirection
68local isglyph = nuts . isglyph
69
70local setprop = nuts . setprop
71local setchar = nuts . setchar
72local setdirection = nuts . setdirection
73local setattrlist = nuts . setattrlist
74
75local properties = nodes . properties . data
76
77local remove_node = nuts . remove
78local insert_node_after = nuts . insert_after
79local insert_node_before = nuts . insert_before
80local start_of_par = nuts . start_of_par
81
82local nodepool = nuts . pool
83local new_direction = nodepool . direction
84
85local nodecodes = nodes . nodecodes
86local gluecodes = nodes . gluecodes
87
88local glyph_code = nodecodes . glyph
89local glue_code = nodecodes . glue
90local hlist_code = nodecodes . hlist
91local vlist_code = nodecodes . vlist
92local math_code = nodecodes . math
93local dir_code = nodecodes . dir
94local localpar_code = nodecodes . localpar
95
96local parfillskip_code = gluecodes . parfillskip
97
98local dirvalues = nodes . dirvalues
99local lefttoright_code = dirvalues . lefttoright
100local righttoleft_code = dirvalues . righttoleft
101
102local maximum_stack = 0xFF
103
104local a_directions = attributes . private ( ' directions ' )
105
106local directions = typesetters . directions
107local setcolor = directions . setcolor
108local getfences = directions . getfences
109
110local remove_controls = true directives . register ( " typesetters.directions.removecontrols " , function ( v ) remove_controls = v end )
111
112
113local report_directions = logs . reporter ( " typesetting " , " directions three " )
114
115local trace_directions = false trackers . register ( " typesetters.directions " , function ( v ) trace_directions = v end )
116local trace_details = false trackers . register ( " typesetters.directions.details " , function ( v ) trace_details = v end )
117local trace_list = false trackers . register ( " typesetters.directions.list " , function ( v ) trace_list = v end )
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
167local whitespace = {
168 lre = true ,
169 rle = true ,
170 lro = true ,
171 rlo = true ,
172 pdf = true ,
173 bn = true ,
174 ws = true ,
175}
176
177local b_s_ws_on = {
178 b = true ,
179 s = true ,
180 ws = true ,
181 on = true
182}
183
184
185
186local function show_list ( list , size , what )
187 local what = what or " direction "
188 local joiner = utfchar ( 0x200C )
189 local result = { }
190 for i = 1 , size do
191 local entry = list [ i ]
192 local character = entry . char
193 local direction = entry [ what ]
194 if character = = 0xFFFC then
195 local first = entry . id
196 local last = entry . last
197 local skip = entry . skip
198 if last then
199 result [ i ] = formatters [ " %-3s:%s %s..%s (%i) " ] ( direction , joiner , nodecodes [ first ] , nodecodes [ last ] , skip or 0 )
200 else
201 result [ i ] = formatters [ " %-3s:%s %s (%i) " ] ( direction , joiner , nodecodes [ first ] , skip or 0 )
202 end
203 elseif character > = 0x202A and character < = 0x202C then
204 result [ i ] = formatters [ " %-3s:%s %U " ] ( direction , joiner , character )
205 else
206 result [ i ] = formatters [ " %-3s:%s %c %U " ] ( direction , joiner , character , character )
207 end
208 end
209 return concat ( result , joiner . . " | " . . joiner )
210end
211
212
213
214local function show_done ( list , size )
215 local joiner = utfchar ( 0x200C )
216 local result = { }
217 local format = formatters [ " <%s> " ]
218 for i = 1 , size do
219 local entry = list [ i ]
220 local character = entry . char
221 local begindir = entry . begindir
222 local enddir = entry . enddir
223 if begindir then
224 result [ # result + 1 ] = format ( begindir )
225 end
226 if entry . remove then
227
228 elseif character = = 0xFFFC then
229 result [ # result + 1 ] = format ( " ? " )
230 elseif character = = 0x0020 then
231 result [ # result + 1 ] = format ( " " )
232 elseif character > = 0x202A and character < = 0x202C then
233 result [ # result + 1 ] = format ( entry . original )
234 else
235 result [ # result + 1 ] = utfchar ( character )
236 end
237 if enddir then
238 result [ # result + 1 ] = format ( enddir )
239 end
240 end
241 return concat ( result , joiner )
242end
243
244
245
246
247
248
249
250
251local mt_space = { __index = { char = 0x0020 , direction = " ws " , original = " ws " , level = 0 , skip = 0 } }
252local mt_lre = { __index = { char = 0x202A , direction = " lre " , original = " lre " , level = 0 , skip = 0 } }
253local mt_rle = { __index = { char = 0x202B , direction = " rle " , original = " rle " , level = 0 , skip = 0 } }
254local mt_pdf = { __index = { char = 0x202C , direction = " pdf " , original = " pdf " , level = 0 , skip = 0 } }
255local mt_object = { __index = { char = 0xFFFC , direction = " on " , original = " on " , level = 0 , skip = 0 } }
256
257local stack = table . setmetatableindex ( " table " )
258local list = { }
259
260local function build_list ( head , where )
261
262 local current = head
263 local size = 0
264 while current do
265 size = size + 1
266 local id = getid ( current )
267 local p = properties [ current ]
268 if p and p . directions then
269
270 local skip = 0
271 local last = id
272 current = getnext ( current )
273 while current do
274 local id = getid ( current )
275 local p = properties [ current ]
276 if p and p . directions then
277 skip = skip + 1
278 last = id
279 current = getnext ( current )
280 else
281 break
282 end
283 end
284 if id = = last then
285 list [ size ] = setmetatable ( { skip = skip , id = id } , mt_object )
286 else
287 list [ size ] = setmetatable ( { skip = skip , id = id , last = last } , mt_object )
288 end
289 elseif id = = glyph_code then
290 local chr = getchar ( current )
291 local dir = directiondata [ chr ]
292
293 list [ size ] = { char = chr , direction = dir , original = dir , level = 0 }
294 current = getnext ( current )
295
296 elseif id = = glue_code then
297 list [ size ] = setmetatable ( { } , mt_space )
298 current = getnext ( current )
299 elseif id = = dir_code then
300 local dir , pop = getdirection ( current )
301 if dir = = lefttoright_code then
302 list [ size ] = setmetatable ( { } , pop and mt_pdf or mt_lre )
303 elseif dir = = righttoleft_code then
304 list [ size ] = setmetatable ( { } , pop and mt_pdf or mt_rle )
305 else
306 list [ size ] = setmetatable ( { id = id } , mt_object )
307 end
308 current = getnext ( current )
309 elseif id = = math_code then
310 local skip = 0
311 current = getnext ( current )
312 while getid ( current ) ~ = math_code do
313 skip = skip + 1
314 current = getnext ( current )
315 end
316 skip = skip + 1
317 current = getnext ( current )
318 list [ size ] = setmetatable ( { id = id , skip = skip } , mt_object )
319 else
320 local skip = 0
321 local last = id
322 current = getnext ( current )
323 while n do
324 local id = getid ( current )
325 if id ~ = glyph_code and id ~ = glue_code and id ~ = dir_code then
326 skip = skip + 1
327 last = id
328 current = getnext ( current )
329 else
330 break
331 end
332 end
333 if id = = last then
334 list [ size ] = setmetatable ( { id = id , skip = skip } , mt_object )
335 else
336 list [ size ] = setmetatable ( { id = id , skip = skip , last = last } , mt_object )
337 end
338 end
339 end
340 return list , size
341end
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357local fencestack = table . setmetatableindex ( " table " )
358
359local function resolve_fences ( list , size , start , limit )
360
361 local nofstack = 0
362 for i = start , limit do
363 local entry = list [ i ]
364 if entry . direction = = " on " then
365 local char = entry . char
366 local mirror = mirrordata [ char ]
367 if mirror then
368 local class = textclassdata [ char ]
369 entry . mirror = mirror
370 entry . class = class
371 if class = = " open " then
372 nofstack = nofstack + 1
373 local stacktop = fencestack [ nofstack ]
374 stacktop [ 1 ] = mirror
375 stacktop [ 2 ] = i
376 elseif nofstack = = 0 then
377
378 elseif class = = " close " then
379 while nofstack > 0 do
380 local stacktop = fencestack [ nofstack ]
381 if stacktop [ 1 ] = = char then
382 local open = stacktop [ 2 ]
383 local close = i
384 list [ open ] . paired = close
385 list [ close ] . paired = open
386 break
387 else
388
389 end
390 nofstack = nofstack - 1
391 end
392 end
393 end
394 end
395 end
396end
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413local function get_baselevel ( head , list , size , direction )
414 if direction = = lefttoright_code or direction = = righttoleft_code then
415 return direction , true
416 elseif getid ( head ) = = localpar_code and start_of_par ( head ) then
417 direction = getdirection ( head )
418 if direction = = lefttoright_code or direction = = righttoleft_code then
419 return direction , true
420 end
421 end
422
423 if direction = = " TLT " then
424 return lefttoright_code , true
425 elseif direction = = " TRT " then
426 return righttoleft_code , true
427 end
428
429 for i = 1 , size do
430 local entry = list [ i ]
431 local direction = entry . direction
432 if direction = = " r " or direction = = " al " then
433 return righttoleft_code , true
434 elseif direction = = " l " then
435 return lefttoright_code , true
436 end
437 end
438 return lefttoright_code , false
439end
440
441local function resolve_explicit ( list , size , baselevel )
442
443
444 local level = baselevel
445 local override = " on "
446 local nofstack = 0
447 for i = 1 , size do
448 local entry = list [ i ]
449 local direction = entry . direction
450
451 if direction = = " rle " then
452 if nofstack < maximum_stack then
453 nofstack = nofstack + 1
454 local stacktop = stack [ nofstack ]
455 stacktop [ 1 ] = level
456 stacktop [ 2 ] = override
457 level = level + ( level % 2 = = 1 and 2 or 1 )
458 override = " on "
459 entry . level = level
460 entry . direction = " bn "
461 entry . remove = true
462 elseif trace_directions then
463 report_directions ( " stack overflow at position %a with direction %a " , i , direction )
464 end
465
466 elseif direction = = " lre " then
467 if nofstack < maximum_stack then
468 nofstack = nofstack + 1
469 local stacktop = stack [ nofstack ]
470 stacktop [ 1 ] = level
471 stacktop [ 2 ] = override
472 level = level + ( level % 2 = = 1 and 1 or 2 )
473 override = " on "
474 entry . level = level
475 entry . direction = " bn "
476 entry . remove = true
477 elseif trace_directions then
478 report_directions ( " stack overflow at position %a with direction %a " , i , direction )
479 end
480
481 elseif direction = = " rlo " then
482 if nofstack < maximum_stack then
483 nofstack = nofstack + 1
484 local stacktop = stack [ nofstack ]
485 stacktop [ 1 ] = level
486 stacktop [ 2 ] = override
487 level = level + ( level % 2 = = 1 and 2 or 1 )
488 override = " r "
489 entry . level = level
490 entry . direction = " bn "
491 entry . remove = true
492 elseif trace_directions then
493 report_directions ( " stack overflow at position %a with direction %a " , i , direction )
494 end
495
496 elseif direction = = " lro " then
497 if nofstack < maximum_stack then
498 nofstack = nofstack + 1
499 local stacktop = stack [ nofstack ]
500 stacktop [ 1 ] = level
501 stacktop [ 2 ] = override
502 level = level + ( level % 2 = = 1 and 1 or 2 )
503 override = " l "
504 entry . level = level
505 entry . direction = " bn "
506 entry . remove = true
507 elseif trace_directions then
508 report_directions ( " stack overflow at position %a with direction %a " , i , direction )
509 end
510
511 elseif direction = = " pdf " then
512 if nofstack > 0 then
513 local stacktop = stack [ nofstack ]
514 level = stacktop [ 1 ]
515 override = stacktop [ 2 ]
516 nofstack = nofstack - 1
517 entry . level = level
518 entry . direction = " bn "
519 entry . remove = true
520 elseif trace_directions then
521 report_directions ( " stack underflow at position %a with direction %a " ,
522 i , direction )
523 else
524 report_directions ( " stack underflow at position %a with direction %a: %s " ,
525 i , direction , show_list ( list , size ) )
526 end
527
528 else
529 entry . level = level
530 if override ~ = " on " then
531 entry . direction = override
532 end
533 end
534 end
535
536end
537
538local function resolve_weak ( list , size , start , limit , orderbefore , orderafter )
539
540
541 for i = start , limit do
542 local entry = list [ i ]
543 if entry . direction = = " nsm " then
544 if i = = start then
545 entry . direction = orderbefore
546 else
547 entry . direction = list [ i -1 ] . direction
548 end
549 end
550 end
551
552
553
554 for i = start , limit do
555 local entry = list [ i ]
556 if entry . direction = = " en " then
557 for j = i -1 , start , -1 do
558 local prev = list [ j ]
559 local direction = prev . direction
560 if direction = = " al " then
561 entry . direction = " an "
562 break
563 elseif direction = = " r " or direction = = " l " then
564 break
565 end
566 end
567 end
568 end
569
570
571
572 for i = start , limit do
573 local entry = list [ i ]
574 if entry . direction = = " al " then
575 entry . direction = " r "
576 end
577 end
578
579
580
581
582 if false then
583 for i = start + 1 , limit -1 do
584 local entry = list [ i ]
585 local direction = entry . direction
586 if direction = = " es " then
587 if list [ i -1 ] . direction = = " en " and list [ i + 1 ] . direction = = " en " then
588 entry . direction = " en "
589 end
590 elseif direction = = " cs " then
591 local prevdirection = list [ i -1 ] . direction
592 if prevdirection = = " en " then
593 if list [ i + 1 ] . direction = = " en " then
594 entry . direction = " en "
595 end
596 elseif prevdirection = = " an " and list [ i + 1 ] . direction = = " an " then
597 entry . direction = " an "
598 end
599 end
600 end
601 else
602 local runner = start + 2
603 if runner < = limit then
604 local before = list [ start ]
605 local entry = list [ start + 1 ]
606 local after = list [ runner ]
607 while after do
608 local direction = entry . direction
609 if direction = = " es " then
610 if before . direction = = " en " and after . direction = = " en " then
611 entry . direction = " en "
612 end
613 elseif direction = = " cs " then
614 local prevdirection = before . direction
615 if prevdirection = = " en " then
616 if after . direction = = " en " then
617 entry . direction = " en "
618 end
619 elseif prevdirection = = " an " and after . direction = = " an " then
620 entry . direction = " an "
621 end
622 end
623 before = current
624 current = after
625 after = list [ runner ]
626 runner = runner + 1
627 end
628 end
629 end
630
631
632
633 local i = start
634 while i < = limit do
635 if list [ i ] . direction = = " et " then
636 local runstart = i
637 local runlimit = runstart
638 for i = runstart , limit do
639 if list [ i ] . direction = = " et " then
640 runlimit = i
641 else
642 break
643 end
644 end
645 local rundirection = runstart = = start and sor or list [ runstart -1 ] . direction
646 if rundirection ~ = " en " then
647 rundirection = runlimit = = limit and orderafter or list [ runlimit + 1 ] . direction
648 end
649 if rundirection = = " en " then
650 for j = runstart , runlimit do
651 list [ j ] . direction = " en "
652 end
653 end
654 i = runlimit
655 end
656 i = i + 1
657 end
658
659
660
661 for i = start , limit do
662 local entry = list [ i ]
663 local direction = entry . direction
664 if direction = = " es " or direction = = " et " or direction = = " cs " then
665 entry . direction = " on "
666 end
667 end
668
669
670 for i = start , limit do
671 local entry = list [ i ]
672 if entry . direction = = " en " then
673 local prev_strong = orderbefore
674 for j = i -1 , start , -1 do
675 local direction = list [ j ] . direction
676 if direction = = " l " or direction = = " r " then
677 prev_strong = direction
678 break
679 end
680 end
681 if prev_strong = = " l " then
682 entry . direction = " l "
683 end
684 end
685 end
686end
687
688local function resolve_neutral ( list , size , start , limit , orderbefore , orderafter )
689
690 for i = start , limit do
691 local entry = list [ i ]
692 if b_s_ws_on [ entry . direction ] then
693
694 local leading_direction , trailing_direction , resolved_direction
695 local runstart = i
696 local runlimit = runstart
697
698 for j = runstart + 1 , limit do
699 if b_s_ws_on [ list [ j ] . direction ] then
700
701 runlimit = j
702 else
703 break
704 end
705 end
706 if runstart = = start then
707 leading_direction = orderbefore
708 else
709 leading_direction = list [ runstart -1 ] . direction
710 if leading_direction = = " en " or leading_direction = = " an " then
711 leading_direction = " r "
712 end
713 end
714 if runlimit = = limit then
715 trailing_direction = orderafter
716 else
717 trailing_direction = list [ runlimit + 1 ] . direction
718 if trailing_direction = = " en " or trailing_direction = = " an " then
719 trailing_direction = " r "
720 end
721 end
722 if leading_direction = = trailing_direction then
723
724 resolved_direction = leading_direction
725 else
726
727 resolved_direction = entry . level % 2 = = 1 and " r " or " l "
728 end
729 for j = runstart , runlimit do
730 list [ j ] . direction = resolved_direction
731 end
732 i = runlimit
733 end
734 i = i + 1
735 end
736end
737
738local function resolve_implicit ( list , size , start , limit , orderbefore , orderafter , baselevel )
739 for i = start , limit do
740 local entry = list [ i ]
741 local level = entry . level
742 local direction = entry . direction
743 if level % 2 ~ = 1 then
744
745 if direction = = " r " then
746 entry . level = level + 1
747 elseif direction = = " an " or direction = = " en " then
748 entry . level = level + 2
749 end
750 else
751
752 if direction = = " l " or direction = = " en " or direction = = " an " then
753 entry . level = level + 1
754 end
755 end
756 end
757end
758
759local function resolve_levels ( list , size , baselevel , analyze_fences )
760
761 local start = 1
762 while start < size do
763 local level = list [ start ] . level
764 local limit = start + 1
765 while limit < size and list [ limit ] . level = = level do
766 limit = limit + 1
767 end
768 local prev_level = start = = 1 and baselevel or list [ start -1 ] . level
769 local next_level = limit = = size and baselevel or list [ limit + 1 ] . level
770 local orderbefore = ( level > prev_level and level or prev_level ) % 2 = = 1 and " r " or " l "
771 local orderafter = ( level > next_level and level or next_level ) % 2 = = 1 and " r " or " l "
772
773 resolve_weak ( list , size , start , limit , orderbefore , orderafter )
774
775 if analyze_fences then
776 resolve_fences ( list , size , start , limit )
777 end
778
779 resolve_neutral ( list , size , start , limit , orderbefore , orderafter )
780
781 resolve_implicit ( list , size , start , limit , orderbefore , orderafter , baselevel )
782 start = limit
783 end
784
785 for i = 1 , size do
786 local entry = list [ i ]
787 local direction = entry . original
788
789 if direction = = " s " or direction = = " b " then
790 entry . level = baselevel
791
792 for j = i -1 , 1 , -1 do
793 local entry = list [ j ]
794 if whitespace [ entry . original ] then
795 entry . level = baselevel
796 else
797 break
798 end
799 end
800 end
801 end
802
803 for i = size , 1 , -1 do
804 local entry = list [ i ]
805 if whitespace [ entry . original ] then
806 entry . level = baselevel
807 else
808 break
809 end
810 end
811
812 if analyze_fences then
813 for i = 1 , size do
814 local entry = list [ i ]
815 if entry . level % 2 = = 1 then
816 if entry . mirror and not entry . paired then
817 entry . mirror = false
818 end
819
820 elseif entry . mirror then
821 entry . mirror = false
822 end
823 end
824 else
825 for i = 1 , size do
826 local entry = list [ i ]
827 if entry . level % 2 = = 1 then
828 local mirror = mirrordata [ entry . char ]
829 if mirror then
830 entry . mirror = mirror
831 end
832 end
833 end
834 end
835end
836
837local stack = { }
838
839local function insert_dir_points ( list , size )
840
841
842 local maxlevel = 0
843 local toggle = true
844 for i = 1 , size do
845 local level = list [ i ] . level
846 if level > maxlevel then
847 maxlevel = level
848 end
849 end
850 for level = 0 , maxlevel do
851 local started
852 local begindir
853 local enddir
854 local prev
855 if toggle then
856 begindir = lefttoright_code
857 enddir = lefttoright_code
858 toggle = false
859 else
860 begindir = righttoleft_code
861 enddir = righttoleft_code
862 toggle = true
863 end
864 for i = 1 , size do
865 local entry = list [ i ]
866 if entry . level > = level then
867 if not started then
868 entry . begindir = begindir
869 started = true
870 end
871 else
872 if started then
873 prev . enddir = enddir
874 started = false
875 end
876 end
877 prev = entry
878 end
879 end
880
881 local last = list [ size ]
882 if not last . enddir then
883 local n = 0
884 for i = 1 , size do
885 local entry = list [ i ]
886 local e = entry . enddir
887 local b = entry . begindir
888 if e then
889 n = n - 1
890 end
891 if b then
892 n = n + 1
893 stack [ n ] = b
894 end
895 end
896 if n > 0 then
897 if trace_list and n > 1 then
898 report_directions ( " unbalanced list " )
899 end
900 last . enddir = stack [ n ]
901 end
902 end
903end
904
905
906
907
908
909local function apply_to_list ( list , size , head , pardir )
910 local index = 1
911 local current = head
912 if trace_list then
913 report_directions ( " start run " )
914 end
915 while current do
916 if index > size then
917 report_directions ( " fatal error, size mismatch " )
918 break
919 end
920 local id = getid ( current )
921 local entry = list [ index ]
922 local begindir = entry . begindir
923 local enddir = entry . enddir
924 local p = properties [ current ]
925 if p then
926 p . directions = true
927 else
928 properties [ current ] = { directions = true }
929 end
930 if id = = glyph_code then
931 local mirror = entry . mirror
932 if mirror then
933 setchar ( current , mirror )
934 end
935 if trace_directions then
936 local direction = entry . direction
937 if trace_list then
938 local original = entry . original
939 local char = entry . char
940 local level = entry . level
941 if direction = = original then
942 report_directions ( " %2i : %C : %s " , level , char , direction )
943 else
944 report_directions ( " %2i : %C : %s -> %s " , level , char , original , direction )
945 end
946 end
947 setcolor ( current , direction , false , mirror )
948 end
949 elseif id = = hlist_code or id = = vlist_code then
950 setdirection ( current , pardir )
951 elseif id = = glue_code then
952 if enddir and getsubtype ( current ) = = parfillskip_code then
953
954 head = insert_node_before ( head , current , new_direction ( enddir , true ) )
955 enddir = false
956 end
957 elseif begindir then
958 if id = = localpar_code and start_of_par ( current ) then
959
960 head , current = insert_node_after ( head , current , new_direction ( begindir ) )
961 begindir = nil
962 end
963 end
964 if begindir then
965 head = insert_node_before ( head , current , new_direction ( begindir ) )
966 end
967 local skip = entry . skip
968 if skip and skip > 0 then
969 for i = 1 , skip do
970 current = getnext ( current )
971 local p = properties [ current ]
972 if p then
973 p . directions = true
974 else
975 properties [ current ] = { directions = true }
976 end
977 end
978 end
979 if enddir then
980 head , current = insert_node_after ( head , current , new_direction ( enddir , true ) )
981 end
982 if not entry . remove then
983 current = getnext ( current )
984 elseif remove_controls then
985
986 head , current = remove_node ( head , current , true )
987 else
988 current = getnext ( current )
989 end
990 index = index + 1
991 end
992 if trace_list then
993 report_directions ( " stop run " )
994 end
995 return head
996end
997
998
999
1000
1001
1002
1003
1004local function process ( head , direction , only_one , where )
1005
1006 local attr = getattr ( head , a_directions )
1007 local analyze_fences = getfences ( attr )
1008
1009 local list , size = build_list ( head , where )
1010 local baselevel , dirfound = get_baselevel ( head , list , size , direction )
1011 if trace_details then
1012 report_directions ( " analyze: baselevel %a " , baselevel = = righttoleft_code and " r2l " or " l2r " )
1013 report_directions ( " before : %s " , show_list ( list , size , " original " ) )
1014 end
1015 resolve_explicit ( list , size , baselevel )
1016 resolve_levels ( list , size , baselevel , analyze_fences )
1017 insert_dir_points ( list , size )
1018 if trace_details then
1019 report_directions ( " after : %s " , show_list ( list , size , " direction " ) )
1020 report_directions ( " result : %s " , show_done ( list , size ) )
1021 end
1022 return apply_to_list ( list , size , head , baselevel )
1023end
1024
1025local variables = interfaces . variables
1026
1027directions . installhandler ( variables . one , process )
1028directions . installhandler ( variables . two , process )
1029directions . installhandler ( variables . three , process )
1030directions . installhandler ( variables . unicode , process )
1031 |