OSDN Git Service

use pre_shipout_filter hook if available
[luatex-ja/luatexja.git] / src / luatexja.lua
1 require 'lualibs'
2 ------------------------------------------------------------------------
3 local function load_lua(fn)
4    local found = kpse.find_file(fn, 'tex')
5    if not found then
6       tex.error("LuaTeX-ja error: File `" .. fn .. "' not found")
7    else
8       texio.write_nl('(' .. found .. ')'); dofile(found)
9    end
10 end
11 luatexja.load_lua = load_lua
12 function luatexja.load_module(name) require('ltj-' .. name.. '.lua') end
13
14 do
15    local setfield = node.direct.setfield
16    luatexja.setglue = node.direct.setglue or
17    function(g,w,st,sh,sto,sho)
18       setfield(g,'width', w or 0); setfield(g,'stretch',st or 0); setfield(g,'shrink', sh or 0)
19       setfield(g,'stretch_order',sto or 0)
20       setfield(g,'shrink_order', sho or 0)
21    end
22    local getfield = node.direct.getfield
23    luatexja.getglue = node.direct.getglue or
24    function(g)
25       return getfield(g,'width'), getfield(g,'stretch'), getfield(g,'shrink'),
26              getfield(g,'stretch_order'), getfield(g,'shrink_order')
27    end
28 end
29
30 --- 以下は全ファイルで共有される定数
31 local icflag_table = {}
32 luatexja.icflag_table = icflag_table
33 icflag_table.ITALIC          = 1
34 icflag_table.PACKED          = 2
35 icflag_table.KINSOKU         = 3
36 icflag_table.FROM_JFM        = 4
37 icflag_table.KANJI_SKIP      = 68 -- = 4+64
38 icflag_table.KANJI_SKIP_JFM  = 69
39 icflag_table.XKANJI_SKIP     = 70
40 icflag_table.XKANJI_SKIP_JFM = 71
41 icflag_table.LINEEND         = 72
42 icflag_table.PROCESSED       = 73
43 icflag_table.IC_PROCESSED    = 74
44 icflag_table.BOXBDD          = 75
45 icflag_table.SPECIAL_JAGLUE  = 76
46 -- 段落組版中のノードリストでは通常のノード (not whatsit) だが
47 -- 和文処理グルー挿入プロセスで長さが決定されるもの
48 icflag_table.PROCESSED_BEGIN_FLAG = 4096 -- sufficiently large power of 2
49
50 local stack_ind = {}
51 luatexja.stack_table_index = stack_ind
52 stack_ind.PRE  = 0x200000 -- characterごと
53 stack_ind.POST = 0x400000 -- characterごと
54 stack_ind.KCAT = 0x600000 -- characterごと
55 stack_ind.XSP  = 0x800000 -- characterごと
56 stack_ind.RIPRE  = 0xA00000 -- characterごと,ruby pre
57 stack_ind.RIPOST = 0xC00000 -- characterごと,ruby post
58 stack_ind.JWP  = 0 -- これだけ
59 stack_ind.KSK  = 1 -- これだけ
60 stack_ind.XSK  = 2 -- これだけ
61 stack_ind.MJT  = 0x100 -- 0--255
62 stack_ind.MJS  = 0x200 -- 0--255
63 stack_ind.MJSS = 0x300 -- 0--255
64 stack_ind.KSJ  = 0x400 -- 0--9
65
66 local uid_table = {}
67 luatexja.userid_table = uid_table
68 uid_table.IHB  = luatexbase.newuserwhatsitid('inhibitglue',  'luatexja') -- \inhibitglue
69 uid_table.STCK = luatexbase.newuserwhatsitid('stack_marker', 'luatexja') -- スタック管理
70 uid_table.BPAR = luatexbase.newuserwhatsitid('begin_par',    'luatexja') -- 「段落始め」
71 uid_table.DIR  = luatexbase.newuserwhatsitid('direction',    'luatexja') -- 組方向
72 uid_table.BOXB = luatexbase.newuserwhatsitid('box_boundary', 'luatexja') -- 「ボックス始め・終わり」
73 uid_table.JA_AL_BDD = luatexbase.newuserwhatsitid('ja_al_boundary', 'luatexja')
74
75 local dir_table = {}
76 luatexja.dir_table = dir_table
77 dir_table.dir_dtou = 1
78 dir_table.dir_tate = 3
79 dir_table.dir_yoko = 4
80 dir_table.dir_math_mod    = 8
81 dir_table.dir_node_auto   = 128 -- 組方向を合わせるために自動で作られたもの
82 dir_table.dir_node_manual = 256 -- 寸法代入によって作られたもの
83 dir_table.dir_utod = dir_table.dir_tate + dir_table.dir_math_mod
84   -- 「縦数式ディレクション」 in pTeX
85 --- 定義終わり
86
87 local load_module = luatexja.load_module
88 load_module 'base';      local ltjb = luatexja.base
89 if tex.outputmode==0 then
90     ltjb.package_error('luatexja',
91       'DVI output is not supported in LuaTeX-ja',
92       'Use lua*tex instead dvilua*tex.')
93 end
94 load_module 'rmlgbm';    local ltjr = luatexja.rmlgbm -- must be 1st
95 if luatexja_debug then load_module('debug') end
96 load_module 'lotf_aux';  local ltju = luatexja.lotf_aux
97 load_module 'charrange'; local ltjc = luatexja.charrange
98 load_module 'stack';     local ltjs = luatexja.stack
99 load_module 'direction'; local ltjd = luatexja.direction -- +1 hlist +1 attr_list
100 load_module 'lineskip';  local ltjl = luatexja.lineskip -- +1 hlist +1 attr_list
101 load_module 'jfont';     local ltjf = luatexja.jfont
102 load_module 'inputbuf';  local ltji = luatexja.inputbuf
103 load_module 'pretreat';  local ltjp = luatexja.pretreat
104 load_module 'setwidth';  local ltjw = luatexja.setwidth
105 load_module 'jfmglue';   local ltjj = luatexja.jfmglue -- +1 glue +1 gs +1 attr_list
106 load_module 'math';      local ltjm = luatexja.math
107 load_module 'base';      local ltjb = luatexja.base
108
109 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
110 local attr_jchar_code = luatexbase.attributes['ltj@charcode']
111 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
112 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
113 local attr_icflag = luatexbase.attributes['ltj@icflag']
114 local attr_uniqid = luatexbase.attributes['ltj@uniqid']
115 local attr_dir = luatexbase.attributes['ltj@dir']
116 local cat_lp = luatexbase.catcodetables['latex-package']
117
118 -- Three aux. functions, borrowed from tex.web
119
120 local floor = math.floor
121 local function print_scaled(s)
122    local out, delta = '', 10
123    if s<0 then s, out = -s, out..'-' end
124    out=out..tostring(floor(s/65536)) .. '.'
125    s=10*(s%65536)+5
126    repeat
127       if delta>65536 then s=s+32768-50000 end
128       out=out .. tostring(floor(s/65536))
129       s=10*(s%65536); delta=delta*10
130    until s<=delta
131    return out
132 end
133 luatexja.print_scaled = print_scaled
134
135 local function print_glue(d,order)
136    local out=print_scaled(d)
137    if order>0 then
138       out=out..'fi'
139       while order>1 do out=out..'l'; order=order-1 end
140    else out=out..'pt'
141    end
142    return out
143 end
144
145 local function print_spec(p)
146    local out=print_scaled(p.width)..'pt'
147    if p.stretch~=0 then
148       out=out..' plus '..print_glue(p.stretch,p.stretch_order)
149    end
150    if p.shrink~=0 then
151       out=out..' minus '..print_glue(p.shrink,p.shrink_order)
152    end
153 return out
154 end
155
156
157 ------------------------------------------------------------------------
158 -- CODE FOR GETTING/SETTING PARAMETERS
159 ------------------------------------------------------------------------
160
161 -- EXT: print parameters that don't need arguments
162 do
163    local tex_getattr = tex.getattribute
164    local function getattr(a)
165       local r = tex_getattr(a)
166       return (r==-0x7FFFFFFF) and 0 or r
167    end 
168    luatexja.unary_pars = {
169       yalbaselineshift = function(t)
170          return print_scaled(getattr('ltj@yablshift'))..'pt'
171       end,
172       yjabaselineshift = function(t)
173          return print_scaled(getattr('ltj@ykblshift'))..'pt'
174       end,
175       talbaselineshift = function(t)
176          return print_scaled(getattr('ltj@tablshift'))..'pt'
177       end,
178       tjabaselineshift = function(t)
179          return print_scaled(getattr('ltj@tkblshift'))..'pt'
180       end,
181       kanjiskip = function(t)
182          return print_spec(ltjs.get_stack_skip(stack_ind.KSK, t))
183       end,
184       xkanjiskip = function(t)
185          return print_spec(ltjs.get_stack_skip(stack_ind.XSK, t))
186       end,
187       jcharwidowpenalty = function(t)
188          return ltjs.get_stack_table(stack_ind.JWP, 0, t)
189       end,
190       autospacing = function(t)
191          return getattr('ltj@autospc')
192       end,
193       autoxspacing = function(t)
194          return getattr('ltj@autoxspc')
195       end,
196       differentjfm = function(t)
197          local f, r = luatexja.jfmglue.diffmet_rule, '???'
198          if f == math.max then r = 'large'
199          elseif f == math.min then r = 'small'
200          elseif f == math.two_average then r = 'average'
201          elseif f == math.two_paverage then r = 'paverage'
202          elseif f == math.two_pleft then r = 'pleft'
203          elseif f == math.two_pright then r = 'pright'
204          elseif f == math.two_add then r = 'both'
205          end
206          return r
207       end,
208       direction = function()
209          local v = ltjd.get_dir_count()
210          if math.abs(tex.nest[tex.nest.ptr].mode) == ltjs.mmode and v == dir_table.dir_tate then
211             v = dir_table.dir_utod
212          end
213          return v
214       end,
215       adjustdir = ltjd.get_adjust_dir_count,
216    }
217
218    local unary_pars = luatexja.unary_pars
219    local scan_arg = token.scan_argument
220    function luatexja.ext_get_parameter_unary()
221       local k= scan_arg()
222       if unary_pars[k] then
223          tex.write(tostring(unary_pars[k](tex.getcount('ltj@@stack'))))
224       end
225       ltjb.stop_time_measure('get_par')
226    end
227 end
228
229
230 -- EXT: print parameters that need arguments
231 do
232    luatexja.binary_pars = {
233       jacharrange = function(c, t)
234          if type(c)~='number' or c<-1 or c>31*ltjc.ATTR_RANGE then
235             -- 0, -1 はエラーにしない(隠し)
236             ltjb.package_error('luatexja',
237                                'invalid character range number (' .. tostring(c) .. ')',
238                                'A character range number should be in the range 1..'
239                                .. 31*ltjc.ATTR_RANGE .. ",\n"..
240                                'So I changed this one to ' .. 31*ltjc.ATTR_RANGE .. ".")
241             c=0 -- external range 217 == internal range 0
242          elseif c==31*ltjc.ATTR_RANGE then c=0
243          end
244       -- 負の値は <U+0080 の文字の文字範囲,として出てくる.この時はいつも欧文文字なので 1 を返す
245          return (c<0) and 1 or ltjc.get_range_setting(c)
246       end,
247       prebreakpenalty = function(c, t)
248          return ltjs.get_stack_table(stack_ind.PRE + ltjb.in_unicode(c, true), 0, t)
249       end,
250       postbreakpenalty = function(c, t)
251          return ltjs.get_stack_table(stack_ind.POST + ltjb.in_unicode(c, true), 0, t)
252       end,
253       kcatcode = function(c, t)
254          return ltjs.get_stack_table(stack_ind.KCAT + ltjb.in_unicode(c, false), 0, t)
255       end,
256       chartorange = function(c, t)
257          return ltjc.char_to_range(ltjb.in_unicode(c, false))
258       end,
259       jaxspmode = function(c, t)
260          return ltjs.get_stack_table(stack_ind.XSP + ltjb.in_unicode(c, true), 3, t)
261       end,
262       boxdir = function(c, t)
263          if type(c)~='number' or c<0 or c>65535 then
264             ltjb.package_error('luatexja',
265                                'Bad register code (' .. tostring(c) .. ')',
266                                'A register must be between 0 and 65535.\n'..
267                                'I changed this one to zero.')
268             c=0
269          end
270          return ltjd.get_register_dir(c)
271       end,
272    }
273    local binary_pars = luatexja.binary_pars
274    local scan_arg, scan_int = token.scan_argument, token.scan_int
275    binary_pars.alxspmode = binary_pars.jaxspmode
276    function luatexja.ext_get_parameter_binary(k, c)
277       if binary_pars[k] then
278          tex.write(tostring(binary_pars[k](c,tex.getcount('ltj@@stack'))))
279       end
280       ltjb.stop_time_measure('get_par')
281    end
282 end
283
284 -- EXT: print \global if necessary
285 function luatexja.ext_print_global()
286    if luatexja.isglobal=='global' then tex.sprint(cat_lp, '\\global') end
287 end
288
289
290 -- main process
291 do
292    local start_time_measure, stop_time_measure
293       = ltjb.start_time_measure, ltjb.stop_time_measure
294    local nullfunc = function (n) return n end
295    local to_node = node.direct.tonode
296    local to_direct = node.direct.todirect
297    local ensure_tex_attr = ltjb.ensure_tex_attr
298
299    -- mode = true iff main_process is called from pre_linebreak_filter
300    local function main_process(head, mode, dir, gc)
301       ensure_tex_attr(attr_icflag, 0)
302       if gc == 'fin_row' then return head
303       else
304             start_time_measure('jfmglue')
305             local p = ltjj.main(to_direct(head),mode, dir)
306             stop_time_measure('jfmglue')
307             return to_node(p)
308       end
309    end
310
311    local function adjust_icflag(h)
312       -- kern from luaotfload will have icflag = 1
313       -- (same as italic correction)
314       ensure_tex_attr(attr_icflag, 1)
315       return h
316    end
317
318    -- callbacks
319    ltjb.add_to_callback(
320       'pre_linebreak_filter',
321       function (head,groupcode)
322          return main_process(head, true, tex.textdir, groupcode)
323       end,'ltj.main',
324       luatexbase.priority_in_callback('pre_linebreak_filter', 'luaotfload.node_processor')+1)
325    ltjb.add_to_callback(
326       'hpack_filter',
327       function (head,groupcode,size,packtype, dir)
328          return main_process(head, false, dir, groupcode)
329       end,'ltj.main',
330       luatexbase.priority_in_callback('hpack_filter', 'luaotfload.node_processor')+1)
331    ltjb.add_to_callback('pre_linebreak_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
332    ltjb.add_to_callback('hpack_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
333 end
334
335 -- lastnodechar
336 do
337    local id_glyph = node.id('glyph')
338    function luatexja.pltx_composite_last_node_char()
339       local n = tex.nest[tex.nest.ptr].tail
340       local r = '-1'
341       if n then
342          if n.id==id_glyph then
343             while n.componetns and  n.subtype and n.subtype%4 >= 2 do
344                n = node.tail(n)
345             end
346             r = tostring(n.char)
347          end
348       end
349       tex.sprint(-2, r)
350    end
351 end
352
353 do
354     local cache_ver = 3 -- must be same as ltj-kinsoku.tex
355     local cache_outdate_fn = function (t) return t.version~=cache_ver end
356     local t = ltjs.charprop_stack_table
357     function luatexja.load_kinsoku()
358         for i,_ in pairs(t) do t[i]=nil end
359         local kinsoku = ltjb.load_cache('ltj-kinsoku_default',cache_outdate_fn)
360         if kinsoku and kinsoku[1] then
361             t[0] = kinsoku[1]
362         else
363             t[0] = {}; tex.print(cat_lp, '\\input ltj-kinsoku.tex\\relax')
364         end
365         luatexja.load_kinsoku=nil
366     end
367 end
368
369 -- debug
370
371 do
372
373 local node_type = node.type
374 local node_next = node.next
375 local has_attr = node.has_attribute
376
377 local id_penalty = node.id('penalty')
378 local id_glyph = node.id('glyph')
379 local id_glue = node.id('glue')
380 local id_kern = node.id('kern')
381 local id_hlist = node.id('hlist')
382 local id_vlist = node.id('vlist')
383 local id_rule = node.id('rule')
384 local id_math = node.id('math')
385 local id_whatsit = node.id('whatsit')
386 local sid_user = node.subtype('user_defined')
387
388 local prefix, inner_depth
389 local utfchar = utf.char
390 local function debug_show_node_X(p,print_fn, limit, inner_depth)
391    local k = prefix
392    local s
393    local pt, pic = node_type(p.id), (has_attr(p, attr_icflag) or 0) % icflag_table.PROCESSED_BEGIN_FLAG
394    local base = prefix .. string.format('%X', pic) .. ' ' .. pt .. ' ' .. tostring(p.subtype) .. ' '
395    if pt == 'glyph' then
396       s = base .. ' ' 
397           .. (p.char<0xF0000 and utfchar(p.char) or '') 
398           .. string.format(' (U+%X) ', p.char)
399           .. tostring(p.font) .. ' (' .. print_scaled(p.height) .. '+'
400           .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
401       if p.xoffset~=0 or p.yoffset~=0 then
402          s = s .. ' off: (' .. print_scaled(p.xoffset)
403                .. ',' .. print_scaled(p.yoffset) .. ')'
404       end
405       print_fn(s)
406    elseif pt=='hlist' or pt=='vlist' or pt=='unset'or pt=='ins' then
407       if pt=='ins' then
408          s = base .. '(' .. print_scaled(p.height) .. '+'
409             .. print_scaled(p.depth) .. ')'
410             .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
411       else
412          s = base .. '(' .. print_scaled(p.height) .. '+'
413             .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
414             .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
415       end
416       if (p.shift or 0)~=0 then
417          s = s .. ', shifted ' .. print_scaled(p.shift)
418       end
419       if p.glue_set and p.glue_sign ==2 or ( p.glue_sign==1 and p.glue_set>0) then
420          s = s .. ' glue set '
421          if p.glue_sign == 2 then s = s .. '-' end
422          s = s .. tostring(floor(p.glue_set*10000)/10000)
423          if p.glue_order == 0 then s = s .. 'pt'
424          else
425             s = s .. 'fi'
426             for i = 2, p.glue_order do s = s .. 'l' end
427          end
428       end
429       if pic == icflag_table.PACKED then s = s .. ' (packed)' end
430       print_fn(s);
431       local bid = inner_depth
432       prefix, inner_depth = prefix.. '.', inner_depth + 1
433       if inner_depth < limit then
434          for q in node.traverse(p.head) do
435             debug_show_node_X(q, print_fn, limit, inner_depth)
436          end
437       end
438       prefix=k
439    elseif pt=='rule' then
440       s = base .. '(' .. print_scaled(p.height) .. '+'
441          .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
442          .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
443       print_fn(s)
444    elseif pt=='disc' then
445       print_fn(s)
446       local bid = inner_depth
447       if inner_depth < limit then
448          prefix, inner_depth = k.. 'p.', inner_depth + 1
449          for q in node.traverse(p.pre) do
450             debug_show_node_X(q, print_fn, limit, inner_depth)
451          end
452          prefix = k.. 'P.'
453          for q in node.traverse(p.post) do
454             debug_show_node_X(q, print_fn, limit, inner_depth)
455          end
456          prefix = k.. 'R.'
457          for q in node.traverse(p.replace) do
458             debug_show_node_X(q, print_fn, limit, inner_depth)
459          end
460       end
461       prefix=k
462    elseif pt == 'glue' then
463       s = base .. ' ' ..  print_spec(p)
464       if pic>icflag_table.KINSOKU and pic<icflag_table.KANJI_SKIP then
465          s = s .. ' (from JFM: priority ' .. pic-icflag_table.FROM_JFM .. ')'
466       elseif pic==icflag_table.KANJI_SKIP then
467          s = s .. ' (kanjiskip)'
468       elseif pic==icflag_table.KANJI_SKIP_JFM then
469          s = s .. ' (kanjiskip, JFM specified)'
470       elseif pic==icflag_table.XKANJI_SKIP then
471          s = s .. ' (xkanjiskip)'
472       elseif pic==icflag_table.XKANJI_SKIP_JFM then
473          s = s .. ' (xkanjiskip, JFM specified)'
474       end
475       print_fn(s)
476    elseif pt == 'kern' then
477       s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
478       if p.subtype==2 then
479          s = s .. ' (for accent)'
480       elseif pic==icflag_table.IC_PROCESSED then
481          s = s .. ' (italic correction)'
482       elseif pic==icflag_table.LINEEND then
483          s = s .. ' (end-of-line)'
484       elseif pic>icflag_table.KINSOKU
485          and pic<icflag_table.KANJI_SKIP then
486          s = s .. ' (from JFM: priority ' .. pic-icflag_table.FROM_JFM .. ')'
487       end
488       print_fn(s)
489    elseif pt == 'penalty' then
490       s = base .. ' ' .. tostring(p.penalty)
491       if pic==icflag_table.KINSOKU then s = s .. ' (for kinsoku)' end
492       print_fn(s)
493    elseif pt == 'dir' then
494       print_fn(base .. ' ' .. tostring(p.dir) .. ' (level ' .. tostring(p.level) .. ')')
495    elseif pt == 'whatsit' then
496       s = base
497       if p.subtype==sid_user then
498          local t = tostring(p.user_id) .. ' (' ..
499             luatexbase.get_user_whatsit_name(p.user_id) .. ') '
500          if p.type ~= 110 then
501             s = s .. ' userid:' .. t .. p.value
502             print_fn(s)
503          else
504             s = s .. ' userid:' .. t .. '(node list)'
505             if p.user_id==uid_table.DIR then
506                s = s .. ' dir: ' .. tostring(node.has_attribute(p, attr_dir))
507             end
508             print_fn(s)
509             local bid = inner_depth
510             prefix, inner_depth = prefix.. '.', inner_depth + 1
511             if inner_depth < limit then
512                for q in node.traverse(p.value) do
513                   debug_show_node_X(q, print_fn, limit, inner_depth)
514                end
515             end
516             prefix, inner_depth = k, bid
517          end
518       else
519          s = s .. (node.subtype(p.subtype) or '')
520          if p.subtype==1 then
521             s = s .. ' stream=' .. p.stream
522             print_fn(s)
523             for i=1,#p.data do
524                print_fn(s .. '  [' .. i .. '] = ' .. tostring(p.data[i].csname))
525             end
526          elseif p.subtype==16 then
527             s = s .. ' mode=' .. p.mode .. ', literal="' .. p.data .. '"'
528             print_fn(s)
529          else
530             print_fn(s)
531          end
532       end
533    -------- math node --------
534    elseif pt=='noad' then
535       print_fn(base)
536       if p.nucleus then
537          prefix = k .. 'N'; debug_show_node_X(p.nucleus, print_fn, limit, inner_depth);
538       end
539       if p.sup then
540          prefix = k .. '^'; debug_show_node_X(p.sup, print_fn, limit, inner_depth);
541       end
542       if p.sub then
543          prefix = k .. '_'; debug_show_node_X(p.sub, print_fn, limit, inner_depth);
544       end
545       prefix = k;
546    elseif pt=='math_char' then
547       s = base .. ' fam: ' .. p.fam .. ' , char = ' .. utfchar(p.char)
548       print_fn(s)
549    elseif pt=='sub_box' or pt=='sub_mlist' then
550       print_fn(base)
551       if p.head then
552          prefix = k .. '.';
553          for q in node.traverse(p.head) do
554             debug_show_node_X(q, print_fn, limit, inner_depth)
555          end
556       end
557    else
558       print_fn(base)
559    end
560    p=node_next(p)
561 end
562 function luatexja.ext_show_node_list(head,depth,print_fn, lim)
563    prefix = depth
564    inner_depth = 0
565    if head then
566       while head do
567          debug_show_node_X(head, print_fn, lim or 1/0, inner_depth); head = node_next(head)
568       end
569    else
570       print_fn(prefix .. ' (null list)')
571    end
572 end
573 function luatexja.ext_show_node(head,depth,print_fn, lim)
574    prefix = depth
575    inner_depth = 0
576    if head then
577       debug_show_node_X(head, print_fn, lim or 1/0, inner_depth)
578    else
579       print_fn(prefix .. ' (null list)')
580    end
581 end
582
583 end