OSDN Git Service

Fix error messages (cf. ticket #28169).
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 4 May 2012 07:50:54 +0000 (16:50 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Fri, 4 May 2012 07:50:54 +0000 (16:50 +0900)
src/ltj-charrange.lua
src/ltj-compat.lua
src/ltj-stack.lua
src/luatexja-compat.sty
src/luatexja-core.sty
src/luatexja.lua

index 8608300..6d7f5c3 100644 (file)
@@ -28,7 +28,7 @@ for i=0x100,ucs_out-1 do jcr_table_main[i]=0 end
 
 -- EXT: add characters to a range
 function add_char_range(b,e,ind) -- ind: external range number
-   if not ind or ind<0 or ind>216 then 
+   if not ind or ind<0 or ind>216 then -- 0 は error にしない(隠し)
       ltjb.package_error('luatexja',
                         "invalid character range number (" .. ind .. ")",
                         {"A character range number should be in the range 1..216,",
@@ -47,9 +47,9 @@ function add_char_range(b,e,ind) -- ind: external range number
 end
 
 function char_to_range(c) -- return the (external) range number
-   if c<0 or c>0x10FFFF then
+   if not c or c<0 or c>0x10FFFF then
         ltjb.package_error('luatexja',
-                           'bad character code (' .. c .. ')',
+                           'bad character code (' .. tostring(c) .. ')',
                            {'A character number must be between 0 and 0x10ffff.',
                             'So I changed this one to zero.'})
         c=0
@@ -80,7 +80,11 @@ end
 
 -- EXT
 function toggle_char_range(g, i) -- i: external range number
-   if i==0 then return 
+   if type(i)~='number' then
+             ltjb.package_error('luatexja',
+                                "invalid character range number (" .. tostring(i).. ")",
+                                "A character range number must be a number, ignored.")
+   elseif i==0 then return 
    else
       local kc
       if i>0 then kc=0 else kc=1; i=-i end
index d72cce3..6e1da77 100644 (file)
@@ -31,35 +31,56 @@ end
 
 -- \ucs: 単なる identity
 function from_ucs(i)
+   if type(i)~='number' then 
+      ltjb.package_error('luatexja',
+                        "invalid character code (".. tostring(i) .. ")",
+                        "I'm going to use 0 instead of that illegal character code.")
+      i=0 
+   end
    tex.write(i)
 end
 
--- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicode 符号位置
+-- \kuten: 面区点 (それぞれで16進2桁を使用)=> Unicharacter code 符号位置
 function from_kuten(i)
-   if not i then i=0 end
+   if type(i)~='number' then 
+      ltjb.package_error('luatexja',
+                        "invalid character code (".. tostring(i) .. ")",
+                        "I'm going to use 0 instead of that illegal character code.")
+      i=0 
+   end
    tex.write(tostring(luatexja.jisx0208.table_jisx0208_uptex[i] or 0))
 end
 
--- \euc: EUC-JP による符号位置 => Unicode 符号位置
+-- \euc: EUC-JP による符号位置 => Unicharacter code 符号位置
 function from_euc(i)
-   if not i then i=0
+   if type(i)~='number' then 
+      ltjb.package_error('luatexja',
+                        "invalid character code (".. tostring(i) .. ")",
+                        "I'm going to use 0 instead of that illegal character code.")
+      i=0
    elseif i>=0x10000 or i<0xa0a0 then 
       i=0
    end
    from_kuten(i-0xa0a0)
 end
 
--- \jis: ISO-2022-JP による符号位置 => Unicode 符号位置
+-- \jis: ISO-2022-JP による符号位置 => Unicharacter code 符号位置
 function from_jis(i)
-   if (not i) or i>=0x10000 or i<0 then 
+   if (type(i)~='number') or i>=0x10000 or i<0 then 
+      ltjb.package_error('luatexja',
+                        "invalid character code (".. tostring(i) .. ")",
+                        "I'm going to use 0 instead of that illegal character code.")
       i=0
    end
    from_kuten(i-0x2020)
 end
 
--- \sjis: Shift_JIS による符号位置 => Unicode 符号位置
+-- \sjis: Shift_JIS による符号位置 => Unicharacter code 符号位置
 function from_sjis(i)
-   if (not i) or i>=0x10000 or i<0 then 
+   if (type(i)~='number') or i>=0x10000 or i<0 then 
+      ltjb.package_error('luatexja',
+                        "invalid character code (".. tostring(i) .. ")",
+                        "I'm going to use 0 instead of that illegal character code.")
       tex.write('0'); return 
    end
    local c2 = math.floor(i/256)
index dd31ab0..88d2a67 100644 (file)
@@ -82,18 +82,19 @@ end
 -- EXT
 function set_stack_table(g,m,c,p,lb,ub)
    local i = get_stack_level()
-   if p<lb or p>ub then 
+   if type(p)~='number' or p<lb or p>ub then
       ltjb.package_error('luatexja',
-                        "invalid code (".. p .. ")",
-                        {"The code should in the range "..tostring(lb) ..'..'.. tostring(ub) .. ".",
-                         "I'm going to use 0 instead of that illegal code value."})
+                        "invalid code (".. tostring(p) .. ")",
+                        "The code should in the range "..tostring(lb) .. '..' ..
+                        tostring(ub) .. ".\n" ..
+                     "I'm going to use 0 instead of that illegal code value.")
       p=0
-   elseif c<-1 or c>0x10ffff then 
+   elseif type(c)~='number' or c<-1 or c>0x10ffff then
       ltjb.package_error('luatexja',
-                        'bad character code (' .. c .. ')',
-                        {'A character number must be between -1 and 0x10ffff.',
-                         "(-1 is used for denoting `math boundary')",
-                         'So I changed this one to zero.'})
+                        'bad character code (' .. tostring(c) .. ')',
+                        'A character number must be between -1 and 0x10ffff.\n' ..
+                        "(-1 is used for denoting `math boundary')\n" ..
+                        'So I changed this one to zero.')
       c=0
    elseif not charprop_stack_table[i][m] then 
       charprop_stack_table[i][m] = {} 
@@ -110,11 +111,11 @@ end
 -- EXT
 function set_stack_font(g,m,c,p)
    local i = get_stack_level()
-   if c<0 or c>255 then 
+   if type(c)~='number' or c<0 or c>255 then 
       ltjb.package_error('luatexja',
-                        "invalid family number (".. p .. ")",
-                        {"The family number should in the range 0 .. 255.",
-                         "I'm going to use 0 instead of that illegal family number."})
+                        "invalid family number (".. tostring(c) .. ")",
+                        "The family number should in the range 0 .. 255.\n" ..
+                         "I'm going to use 0 instead of that illegal family number.")
       c=0
    elseif not charprop_stack_table[i][m] then 
       charprop_stack_table[i][m] = {} 
index 79687d7..bc29828 100644 (file)
    \ltj@code@convB\ltj@grab@num
 }
 \def\ltj@code@convB#1{%
-  \directlua{luatexja._cc_next(\ltj@safe@num{#1}) }%
+  \directlua{luatexja._cc_next(\ltj@safe@num@or{nil}{#1}) }%
 }
 
 \def\kansuji{%
index f8a7b11..1a2cb2d 100644 (file)
   \expandafter\ltj@@set@stack#1:{post}{-10000}{10000}}
 \def\ltj@@set@stack#1,#2:#3#4#5{%
   \directlua{luatexja.stack.set_stack_table(luatexja.isglobal, \asluastring{#3},
-    \ltj@safe@num@or\ltj@defnum{#1},\ltj@safe@num@or\ltj@defnum{#2},#4,#5)}}
+    \ltj@safe@num@or{nil}{#1},\ltj@safe@num@or{nil}{#2},#4,#5)}}
 
 % jatextfont = {<char_code>, <font_cs>}
 \define@key[ltj]{japaram}{jatextfont}{%
      a Japanese font}{}%
   \else
     \directlua{luatexja.stack.set_stack_font(luatexja.isglobal, \asluastring{#3},
-    \ltj@safe@num@or\ltj@defnum{#1}, \the\ltj@curjfnt)}%
+    \ltj@safe@num@or{nil}{#1}, \the\ltj@curjfnt)}%
   \fi
   \ltj@curjfnt=\ltj@tempcnta
   \ltj@restore@globaldefs
   \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
   \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
   \directlua{luatexja.stack.set_stack_table(luatexja.isglobal, 'xsp', 
-    \ltj@safe@num@or\ltj@defnum{#1},
-    \ltj@safe@num@or\ltj@defnum{\ltj@temp},0,3)}}
+    \ltj@safe@num@or{nil}{#1},
+    \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
 
 % alxspmode = {<char_code>, <mode>}
 % mode: inhibit, preonly, postonly, allow
   \def\ltj@tempa{postonly}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{2}\fi
   \def\ltj@tempa{allow}\ifx\ltj@temp\ltj@tempa\def\ltj@temp{3}\fi
   \directlua{luatexja.stack.set_stack_table(luatexja.isglobal, 'xsp', 
-    \ltj@safe@num@or\ltj@defnum{#1},
-    \ltj@safe@num@or\ltj@defnum{\ltj@temp},0,3)}}
+    \ltj@safe@num@or{nil}{#1},
+    \ltj@safe@num@or{nil}{\ltj@temp},0,3)}}
 
 % autospacing = <bool> (default: true)
 \define@boolkey[ltj]{japaram}{autospacing}[true]{%
   \edef\ltj@temp{#1}%
   \ifx\ltj@temp\empty\let\next=\relax\else\let\next=\ltj@@scrange
     \directlua{luatexja.charrange.toggle_char_range(%
-      luatexja.is_global,\ltj@safe@num@or\ltj@defnum{#1})}%
+      luatexja.is_global,\ltj@safe@num@or{nil}{#1})}%
   \fi\next
 }
 
 \def\ltj@@getparam@one#1{%
   \directlua{luatexja.ext_get_parameter_unary('#1')}}%
 \def\ltj@@getparam@two#1#2{%
-  \directlua{luatexja.ext_get_parameter_binary('#1', \ltj@safe@num{#2})}%
+  \directlua{luatexja.ext_get_parameter_binary('#1', \ltj@safe@num@or{nil}{#2})}%
 }
 
 %%%%%%%% \ltjalchar<number>, \ltjjachar<number>
index 1e00f47..7b608d5 100644 (file)
@@ -174,6 +174,12 @@ end
 
 -- EXT: print parameters that need arguments
 function luatexja.ext_get_parameter_binary(k,c)
+   if type(c)~='number' then
+      ltjb.package_error('luatexja',
+                        'invalid the second argument (' .. tostring(c) .. ')',
+                        'I changed this one to zero.')
+      c=0
+   end
    if k == 'jacharrange' then
       if c<0 or c>216 then 
         ltjb.package_error('luatexja',