%
% pxcjkcat.sty
%
%%%% package declaration
\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{pxcjkcat}[2012/09/22 v1.0 PX cjk-category mode]
%\RequirePackage{ifuptex}[2008/03/14]\RequirenativeupTeX


%%%% error messages
\def\pxkc@pkgname{pxcjkcat}
\def\pxkc@error{\PackageError\pxkc@pkgname}
\def\pxkc@err@ivcsy#1{\pxkc@error
  {Invalid name (#1) for cjk-category}%
  {It was replaced by 18(cjk).}}
\def\pxkc@err@ivbsy#1{\pxkc@error
  {Invalid name (#1) for Unicode block}\@eha}
\def\pxkc@err@ivmsy#1{\pxkc@error
  {Invalid name (#1) for cjk-category mode}\@eha}
\ifx\bxUseDebug\@undefined
\let\pxkc@debug\@gobble
\else
\def\pxkc@debug#1{\typeout{**[\pxkc@pkgname] #1}}
\fi

%%%% environment check
\@tempswafalse
\ifx\ucs\@undefined\else \ifnum\ucs"3000="3000
    \@tempswatrue
\fi\fi
\if@tempswa\else
  \pxkc@error{Native upTeX is required.}%
    {Package loading is aborted.}
\expandafter\endinput\fi\relax

%%%% prepraration
\newif\ifpxkc@ok

%%%% option handler
\chardef\pxkc@mccv=1
\DeclareOption{ccv1}{\chardef\pxkc@mccv=1 }
\DeclareOption{ccv2}{\chardef\pxkc@mccv=2 }
\chardef\pxkc@rccv=0
%% ** These options are for debugging!
\DeclareOption{@ccv1}{\chardef\pxkc@rccv=1 }
\DeclareOption{@ccv2}{\chardef\pxkc@rccv=2 }
\let\pxkc@ccmode\relax
\DeclareOption*{\edef\pxkc@ccmode{\CurrentOption}}
\ProcessOptions\relax

%%-------- classification version check

%% \pxkc@issameblock
\def\pxkc@issameblock#1#2{%
  \pxkc@okfalse{\kcatcode#1=16\kcatcode#2=17\relax
    \ifnum\kcatcode#1=17 \aftergroup\pxkc@oktrue\fi}}
\pxkc@issameblock{"FF01}{"FF11}
\ifpxkc@ok
\chardef\pxkc@ccv=1   % v0.11+
\else
\chardef\pxkc@ccv=2   % v0.29+
\fi
\ifnum\pxkc@rccv>\z@ \let\pxkc@ccv\pxkc@rccv \fi
\pxkc@debug{CJK category version \number\pxkc@ccv}
%
\ifnum\pxkc@mccv>\pxkc@ccv
  \pxkc@error{Invalid mode-CCV option (ccv\number\pxkc@mccv)}%
  {The mode-CCV value given (\number\pxkc@mccv) is
  larger than the real CCV (\number\pxkc@ccv).\MessageBreak
  I assume the mode-CCV equals the real CCV.}
  \let\pxkc@mccv\pxkc@ccv
\fi

%%------ \setcjkcategory, etc.

%% \pxkc@kcatcode
\ifx\bxUseDebug\@undefined
\def\pxkc@kcatcode#1#2{\kcatcode#1=#2\relax}
\else
\def\pxkc@kcatcode#1#2{\kcatcode#1=#2\relax
  \chardef\pxkc@xa=#1\chardef\pxkc@xb=#2\relax
  \expandafter\pxkc@kcatcode@a\meaning\pxkc@xa\@nil}
\def\pxkc@kcatcode@a#1"#2\@nil{%
  \pxkc@debug{\string\kcatcode"#2 set to \number\pxkc@xb}}
\fi


%%%% table
\def\pxkc@bval#1#2{%
  \edef\pxkc@bslst{\pxkc@bslst\pxkc@sep#1}%
  \@namedef{pxkc@B@@#1}{#2}\def\pxkc@sep{,}}
\def\pxkc@bslst{}\def\pxkc@sep{}
\def\pxkc@cval#1#2{\@namedef{pxkc@C@@#1}{#2}}
\def\pxkc@gval#1#2{\@namedef{pxkc@G@@#1}{#2}}
  %
\pxkc@bval{latn}{"0}        % Basic Latin
\pxkc@bval{latn1}{"80}      % Latin-1 Supplement
\pxkc@bval{latnA}{"100}     % Latin Extended-A
\pxkc@bval{latnB}{"180}     % Latin Extended-B
\pxkc@bval{latn2}{"250}     % IPA Extensions
\pxkc@bval{sym01}{"2B0}     % Spacing Modifier Letters
\pxkc@bval{sym02}{"300}     % Combining Diacritical Marks
\pxkc@bval{grek}{"370}      % Greek and Coptic
\pxkc@bval{cyrl}{"400}      % Cyrillic
\pxkc@bval{cyrl1}{"500}     % Cyrillic Supplement
\pxkc@bval{armn}{"530}      % Armenian
\pxkc@bval{hebr}{"590}      % Hebrew
\pxkc@bval{arab}{"600}      % Arabic
\pxkc@bval{syrc}{"700}      % Syriac
\pxkc@bval{arab1}{"750}     % Arabic Supplement
\pxkc@bval{thaa}{"780}      % Thaana
\pxkc@bval{nkoo}{"7C0}      % NKo
\ifnum\pxkc@ccv<2\else
\pxkc@bval{samr}{"800}      % Samaritan
\fi
\pxkc@bval{deva}{"900}      % Devanagari
\pxkc@bval{beng}{"980}      % Bengali
\pxkc@bval{guru}{"A00}      % Gurmukhi
\pxkc@bval{gujr}{"A80}      % Gujarati
\pxkc@bval{orya}{"B00}      % Oriya
\pxkc@bval{taml}{"B80}      % Tamil
\pxkc@bval{telu}{"C00}      % Telugu
\pxkc@bval{knda}{"C80}      % Kannada
\pxkc@bval{mlym}{"D00}      % Malayalam
\pxkc@bval{sinh}{"D80}      % Sinhala
\pxkc@bval{thai}{"E00}      % Thai
\pxkc@bval{laoo}{"E80}      % Lao
\pxkc@bval{tibt}{"F00}      % Tibetan
\pxkc@bval{mymr}{"1000}     % Myanmar
\pxkc@bval{geor}{"10A0}     % Georgian
\pxkc@bval{hang1}{"1100}    % Hangul Jamo
\pxkc@bval{ethi}{"1200}     % Ethiopic
\pxkc@bval{ethi1}{"1380}    % Ethiopic Supplement
\pxkc@bval{cher}{"13A0}     % Cherokee
\pxkc@bval{cans}{"1400}     % Unified Canadian Aboriginal Syllabics
\pxkc@bval{ogam}{"1680}     % Ogham
\pxkc@bval{runr}{"16A0}     % Runic
\pxkc@bval{tglg}{"1700}     % Tagalog
\pxkc@bval{hano}{"1720}     % Hanunoo
\pxkc@bval{buhd}{"1740}     % Buhid
\pxkc@bval{tagb}{"1760}     % Tagbanwa
\pxkc@bval{khmr}{"1780}     % Khmer
\pxkc@bval{mong}{"1800}     % Mongolian
\ifnum\pxkc@ccv<2\else
\pxkc@bval{cans1}{"1880}    % Unified Canadian Aboriginal Syll. Ext.
\fi
\pxkc@bval{limb}{"1900}     % Limbu
\pxkc@bval{tale}{"1950}     % Tai Le
\pxkc@bval{talu}{"1980}     % New Tai Lue
\pxkc@bval{khmr1}{"19E0}    % Khmer Symbols
\pxkc@bval{bugi}{"1A00}     % Buginese
\ifnum\pxkc@ccv<2\else
\pxkc@bval{lana}{"1A20}     % Tai Tham
\fi
\pxkc@bval{bali}{"1B00}     % Balinese
\ifnum\pxkc@ccv<2\else
\pxkc@bval{sund}{"1B80}     % Sundanese
\pxkc@bval{lepc}{"1C00}     % Lepcha
\pxkc@bval{olck}{"1C50}     % Ol Chiki
\pxkc@bval{sym38}{"1CD0}    % Vedic Extensions
\fi
\pxkc@bval{latn4}{"1D00}    % Phonetic Extensions
\pxkc@bval{latn5}{"1D80}    % Phonetic Extensions Supplement
\pxkc@bval{sym03}{"1DC0}    % Combining Diacritical Marks Supplement
\pxkc@bval{latn3}{"1E00}    % Latin Extended Additional
\pxkc@bval{grek1}{"1F00}    % Greek Extended
\pxkc@bval{sym04}{"2000}    % General Punctuation
\pxkc@bval{sym05}{"2070}    % Superscripts and Subscripts
\pxkc@bval{sym06}{"20A0}    % Currency Symbols
\pxkc@bval{sym07}{"20D0}    % Combining Diacritical Marks for Symbols
\pxkc@bval{sym08}{"2100}    % Letterlike Symbols
\pxkc@bval{sym09}{"2150}    % Number Forms
\pxkc@bval{sym10}{"2190}    % Arrows
\pxkc@bval{sym11}{"2200}    % Mathematical Operators
\pxkc@bval{sym12}{"2300}    % Miscellaneous Technical
\pxkc@bval{sym13}{"2400}    % Control Pictures
\pxkc@bval{sym14}{"2440}    % Optical Character Recognition
\pxkc@bval{sym15}{"2460}    % Enclosed Alphanumerics
\pxkc@bval{sym16}{"2500}    % Box Drawing
\pxkc@bval{sym17}{"2580}    % Block Elements
\pxkc@bval{sym18}{"25A0}    % Geometric Shapes
\pxkc@bval{sym19}{"2600}    % Miscellaneous Symbols
\pxkc@bval{sym20}{"2700}    % Dingbats
\pxkc@bval{sym21}{"27C0}    % Miscellaneous Mathematical Symbols-A
\pxkc@bval{sym22}{"27F0}    % Supplemental Arrows-A
\pxkc@bval{brai}{"2800}     % Braille Patterns
\pxkc@bval{sym23}{"2900}    % Supplemental Arrows-B
\pxkc@bval{sym24}{"2980}    % Miscellaneous Mathematical Symbols-B
\pxkc@bval{sym25}{"2A00}    % Supplemental Mathematical Operators
\pxkc@bval{sym26}{"2B00}    % Miscellaneous Symbols and Arrows
\pxkc@bval{glag}{"2C00}     % Glagolitic
\pxkc@bval{latnC}{"2C60}    % Latin Extended-C
\pxkc@bval{copt}{"2C80}     % Coptic
\pxkc@bval{geor1}{"2D00}    % Georgian Supplement
\pxkc@bval{tfng}{"2D30}     % Tifinagh
\pxkc@bval{ethi2}{"2D80}    % Ethiopic Extended
\ifnum\pxkc@ccv<2\else
\pxkc@bval{cyrlA}{"2DE0}    % Cyrillic Extended-A
\fi
\pxkc@bval{sym27}{"2E00}    % Supplemental Punctuation
\pxkc@bval{cjk01}{"2E80}    % CJK Radicals Supplement
\pxkc@bval{cjk02}{"2F00}    % Kangxi Radicals
\pxkc@bval{cjk03}{"2FF0}    % Ideographic Description Characters
\pxkc@bval{cjk04}{"3000}    % CJK Symbols and Punctuation
\pxkc@bval{hira}{"3040}     % Hiragana
\pxkc@bval{kana}{"30A0}     % Katakana
\pxkc@bval{bopo}{"3100}     % Bopomofo
\pxkc@bval{hang2}{"3130}    % Hangul Compatibility Jamo
\pxkc@bval{cjk05}{"3190}    % Kanbun
\pxkc@bval{bopo1}{"31A0}    % Bopomofo Extended
\pxkc@bval{cjk06}{"31C0}    % CJK Strokes
\pxkc@bval{kana1}{"31F0}    % Katakana Phonetic Extensions
\pxkc@bval{cjk07}{"3200}    % Enclosed CJK Letters and Months
\pxkc@bval{cjk08}{"3300}    % CJK Compatibility
\pxkc@bval{haniA}{"3400}    % CJK Unified Ideographs Extension A
\pxkc@bval{sym28}{"4DC0}    % Yijing Hexagram Symbols
\pxkc@bval{hani}{"4E00}     % CJK Unified Ideographs
\pxkc@bval{yiii}{"A000}     % Yi Syllables
\pxkc@bval{yiii1}{"A490}    % Yi Radicals
\ifnum\pxkc@ccv<2\else
\pxkc@bval{lisu}{"A4D0}     % Lisu
\pxkc@bval{vaii}{"A500}     % Vai
\pxkc@bval{cyrlB}{"A640}    % Cyrillic Extended-B
\pxkc@bval{bamu}{"A6A0}     % Bamum
\fi
\pxkc@bval{sym29}{"A700}    % Modifier Tone Letters
\pxkc@bval{latnD}{"A720}    % Latin Extended-D
\pxkc@bval{sylo}{"A800}     % Syloti Nagri
\ifnum\pxkc@ccv<2\else
\pxkc@bval{sym39}{"A830}    % Common Indic Number Forms
\fi
\pxkc@bval{phag}{"A840}     % Phags-pa
\ifnum\pxkc@ccv<2\else
\pxkc@bval{saur}{"A830}     % Saurashtra
\pxkc@bval{deva1}{"A8E0}    % Devanagari Extended
\pxkc@bval{kali}{"A900}     % Kayah Li
\pxkc@bval{rjng}{"A930}     % Rejang
\pxkc@bval{hangA}{"A960}    % Hangul Jamo Extended-A
\pxkc@bval{java}{"A980}     % Javanese
\pxkc@bval{cham}{"AA00}     % Cham
\pxkc@bval{mymrA}{"AA60}    % Myanmar Extended-A
\pxkc@bval{tavt}{"AA80}     % Tai Viet
\pxkc@bval{mtei}{"ABC0}     % Meetei Mayek
\fi
\pxkc@bval{hang}{"AC00}     % Hangul Syllables
\ifnum\pxkc@ccv<2\else
\pxkc@bval{hangB}{"D7B0}    % Hangul Jamo Extended-B
\fi
\pxkc@bval{spc01}{"D800}    % High Surrogates
\pxkc@bval{spc02}{"DB80}    % High Private Use Surrogates
\pxkc@bval{spc03}{"DC00}    % Low Surrogates
\pxkc@bval{spc04}{"E000}    % Private Use Area
\pxkc@bval{hani1}{"F900}    % CJK Compatibility Ideographs
\pxkc@bval{latn6}{"FB00}    % Alphabetic Presentation Forms
\pxkc@bval{arab2}{"FB50}    % Arabic Presentation Forms-A
\pxkc@bval{spc05}{"FE00}    % Variation Selectors
\pxkc@bval{cjk09}{"FE10}    % Vertical Forms
\pxkc@bval{sym30}{"FE20}    % Combining Half Marks
\pxkc@bval{cjk10}{"FE30}    % CJK Compatibility Forms
\pxkc@bval{cjk11}{"FE50}    % Small Form Variants
\pxkc@bval{arab3}{"FE70}    % Arabic Presentation Forms-B
\ifnum\pxkc@ccv<2
\pxkc@bval{cjk12}{"FF00}    % Halfwidth and Fullwidth Forms
\else
\pxkc@gval{cjk12}{cjk1a,cjk1b,cjk1c} % Halfwidth and Fullwidth Forms
\pxkc@bval{cjk1a}{"FF01}    % cjk12 subblock A
\pxkc@bval{cjk1b}{"FF10}    % cjk12 subblock B
\pxkc@bval{cjk1c}{"FF66}    % cjk12 subblock C
\fi
\pxkc@bval{spc06}{"FFF0}    % Specials
\pxkc@bval{linb}{"10000}    % Linear B Syllabary
\pxkc@bval{linb1}{"10080}   % Linear B Ideograms
\pxkc@bval{sym31}{"10100}   % Aegean Numbers
\pxkc@bval{grek2}{"10140}   % Ancient Greek Numbers
\ifnum\pxkc@ccv<2\else
\pxkc@bval{sym40}{"10190}   % Ancient Greek Numbers
\pxkc@bval{sym41}{"101D0}   % Ancient Greek Numbers
\pxkc@bval{lyci}{"10280}    % Ancient Greek Numbers
\pxkc@bval{cari}{"102A0}    % Ancient Greek Numbers
\fi
\pxkc@bval{ital}{"10300}    % Old Italic
\pxkc@bval{goth}{"10330}    % Gothic
\pxkc@bval{ugar}{"10380}    % Ugaritic
\pxkc@bval{xpeo}{"103A0}    % Old Persian
\pxkc@bval{dsrt}{"10400}    % Deseret
\pxkc@bval{shaw}{"10450}    % Shavian
\pxkc@bval{osma}{"10480}    % Osmanya
\pxkc@bval{cprt}{"10800}    % Cypriot Syllabary
\ifnum\pxkc@ccv<2\else
\pxkc@bval{armi}{"10840}    % Imperial Aramaic
\fi
\pxkc@bval{phnx}{"10900}    % Phoenician
\ifnum\pxkc@ccv<2\else
\pxkc@bval{lydi}{"10920}    % Lydian
\fi
\pxkc@bval{khar}{"10A00}    % Kharoshthi
\ifnum\pxkc@ccv<2\else
\pxkc@bval{sarb}{"10A60}    % Old South Arabian
\pxkc@bval{avst}{"10B00}    % Avestan
\pxkc@bval{prti}{"10B40}    % Inscriptional Parthian
\pxkc@bval{phli}{"10B60}    % Inscriptional Pahlavi
\pxkc@bval{orkh}{"10C00}    % Old Turkic
\pxkc@bval{sym42}{"10E60}   % Rumi Numeral Symbols
\pxkc@bval{kthi}{"11080}    % Kaithi
\fi
\pxkc@bval{xsux}{"12000}    % Cuneiform
\pxkc@bval{xsux1}{"12400}   % Cuneiform Numbers and Punctuation
\ifnum\pxkc@ccv<2\else
\pxkc@bval{egyp}{"13000}    % Egyptian Hieroglyphs
\fi
\pxkc@bval{sym32}{"1D000}   % Byzantine Musical Symbols
\pxkc@bval{sym33}{"1D100}   % Musical Symbols
\pxkc@bval{sym34}{"1D200}   % Ancient Greek Musical Notation
\pxkc@bval{sym35}{"1D300}   % Tai Xuan Jing Symbols
\pxkc@bval{sym36}{"1D360}   % Counting Rod Numerals
\pxkc@bval{sym37}{"1D400}   % Mathematical Alphanumeric Symbols
\ifnum\pxkc@ccv<2\else
\pxkc@bval{sym43}{"1F000}   % Mahjong Tiles
\pxkc@bval{sym44}{"1F030}   % Domino Tiles
\pxkc@bval{sym45}{"1F100}   % Enclosed Alphanumeric Supplement
\pxkc@bval{cjk13}{"1F200}   % Enclosed Ideographic Supplement
\fi
\pxkc@bval{haniB}{"20000}   % CJK Unified Ideographs Extension B
\ifnum\pxkc@ccv<2\else
\pxkc@bval{haniC}{"2A700}   % CJK Unified Ideographs Extension C
\fi
\pxkc@bval{hani2}{"2F800}   % CJK Compatibility Ideographs Supplement
\pxkc@bval{spc07}{"E0000}   % Tags
\pxkc@bval{spc08}{"E0100}   % Variation Selectors Supplement
\pxkc@bval{spc09}{"F0000}   % Supplementary Private Use Area-A
\pxkc@bval{spc10}{"100000}  % Supplementary Private Use Area-B
\pxkc@bval{spc11}{"200000}  % illegal
  %
\pxkc@cval{noncjk}{15}
\pxkc@cval{kanji}{16}
\pxkc@cval{han}{16}
\pxkc@cval{kana}{17}
\pxkc@cval{cjk}{18}
\pxkc@cval{hangul}{19}
  %
\edef\pxkc@foreachblk{\noexpand\@for\noexpand\x:={\pxkc@bslst}}
\let\pxkc@bval\relax\let\pxkc@cval\relax\let\pxkc@bslst\relax

%%<*> \cjkcategory{<block>}{<category>}
% Sets the kcatcode of block <block> to <category>.
% Here <block> is given as a block name or a single character in the
% block to be specified; <category> is given as a category name or
% a number ranged in 15--19.
\def\cjkcategory{%
  \bgroup\forcecjktoken\pxkc@cjkcategory@oa}
\def\pxkc@cjkcategory@oa#1{%
  \gdef\pxkc@nxt{\pxkc@cjkcategory@ob{#1}}%
  \egroup\pxkc@nxt}
\def\pxkc@cjkcategory@ob#1#2{%
  \ifnum2<1#2 \edef\pxkc@arg{#2}%
  \else\@ifundefined{pxkc@C@@#2}%
   {\pxkc@err@ivcsy{#2}\def\pxkc@arg{18}}%
   {\edef\pxkc@arg{\@nameuse{pxkc@C@@#2}}}\fi
  \pxkc@cjkcategory@a{#1}}
\chardef\pxkc@la="7F
\def\pxkc@cjkcategory@a#1{%
  \@for\pxkc@x:={#1}\do{%
    \expandafter\pxkc@cjkcategory@b\expandafter{\pxkc@x}}}
\def\pxkc@cjkcategory@b#1{%
  \pxkc@chkchr{#1}\ifnum\pxkc@cc>\pxkc@la
    \pxkc@kcatcode{\pxkc@cc}{\pxkc@arg}%
  \else\expandafter\ifx\csname pxkc@G@@#1\endcsname\relax
    \expandafter\ifx\csname pxkc@B@@#1\endcsname\relax
      \pxkc@err@ivbsy{#1}%
    \else \pxkc@kcatcode{\@nameuse{pxkc@B@@#1}}{\pxkc@arg}\fi
  \else \edef\pxkc@nxt{\noexpand\pxkc@cjkcategory@a
         {\@nameuse{pxkc@G@@#1}}}\pxkc@nxt
  \fi\fi}
\def\pxkc@chkchr#1{%
  \afterassignment\pxkc@chkchr@a\chardef\pxkc@cc=`#1?\relax}
\def\pxkc@chkchr@a#1\relax{}

%%<*> \cjkcategorymode{<mode>}
% Invokes the cjk-category mode <mode>.
\def\cjkcategorymode#1{%
  \@ifundefined{pxkc@M@@#1}{\pxkc@err@ivmsy}
   {\@nameuse{pxkc@M@@#1}}}

%%%% cjkcategory modes
\def\pxkc@resetcjkcat{%
  \pxkc@foreachblk\do{\pxkc@kcatcode{\@nameuse{pxkc@B@@\x}}{18}}}
\def\pxkc@M@@forcecjk{\pxkc@resetcjkcat
  \cjkcategory{latn}{noncjk}%
  \cjkcategory{bopo,bopo1,cjk01,cjk02,cjk03,cjk05,cjk06,hani,hani1}{kanji}%
  \cjkcategory{hani2,haniA,haniB}{kanji}%
  \cjkcategory{hira,kana,kana1}{kana}%
  \cjkcategory{hang,hang1,hang2}{hangul}%
  \ifnum\pxkc@mccv<2\else
    \cjkcategory{cjk1b,cjk1c}{kana}%
  \fi
  \ifnum\pxkc@ccv<2\else
    \cjkcategory{haniC}{kanji}%
    \cjkcategory{hangA,hangB}{hangul}%
  \fi
}
\def\pxkc@M@@prefercjk{\pxkc@M@@forcecjk
  \@for\x:={%
    cyrl1,armn,hebr,arab,syrc,arab1,thaa,nkoo,deva,beng,%
    guru,gujr,orya,taml,telu,knda,mlym,sinh,thai,laoo,%
    tibt,mymr,geor,ethi,ethi1,cher,cans,ogam,runr,tglg,%
    hano,buhd,tagb,khmr,mong,limb,tale,talu,khmr1,bugi,%
    bali,latn4,latn5,sym03,sym14,sym21,sym22,brai,sym25,glag,%
    latnC,copt,geor1,tfng,ethi2,sym27,sym28,sym29,latnD,sylo,%
    phag,spc01,spc02,spc03,arab2,spc05,sym30,arab3,spc06,linb,%
    linb1,sym31,grek2,ital,goth,ugar,xpeo,dsrt,shaw,osma,%
    cprt,phnx,khar,xsux,xsux1,sym32,sym33,sym34,sym35,sym36,%
    sym37,spc07,spc08,spc09,spc10%
  }\do{\pxkc@kcatcode{\@nameuse{pxkc@B@@\x}}{15}}%
  \ifnum\pxkc@ccv<2\else
    \cjkcategory{samr,cans1,lana,sund,lepc,olck,sym38,cyrlA}{noncjk}%
    \cjkcategory{lisu,vaii,cyrlB,bamu,sym39,saur,deva1,kali}{noncjk}%
    \cjkcategory{rjng,java,cham,mymrA,tavt,mtei,sym40,sym41}{noncjk}%
    \cjkcategory{lyci,cari,armi,lydi,sarb,avst,prti,phli}{noncjk}%
    \cjkcategory{orkh,sym42,kthi,egyp,sym43,sym44,sym45}{noncjk}%
  \fi
}
\@namedef{pxkc@M@@prefercjkvar}{\pxkc@M@@prefercjk
  \cjkcategory{cyrl,grek,grek1}{noncjk}%
}
\def\pxkc@M@@prefernoncjk{\pxkc@M@@prefercjkvar
  \cjkcategory{latn1,latn2,latn3,latn6,latnA,latnB,spc04,sym01}{noncjk}%
  \cjkcategory{sym02,sym04,sym05,sym06,sym07,sym08,sym09,sym10}{noncjk}%
  \cjkcategory{sym11,sym12,sym13,sym16,sym17,sym18,sym19,sym20}{noncjk}%
  \cjkcategory{sym23,sym24,sym26}{noncjk}%
}
\def\pxkc@M@@prefernoncjkvar{\pxkc@M@@prefernoncjk
  \cjkcategory{sym04,sym10,sym18}{other}%
}

%%%% \showcjkcategory
\def\showcjkcategory{%
  \pxkc@foreachblk\do{%
   \typeout{\x\space= \the\kcatcode\@nameuse{pxkc@B@@\x}}}}

%%-------- \withcjktokendisabled, etc.

%% \pxkc@genprobe
\def\pxkc@genprobe{%
  \edef\pxkc@tmpa{\expandafter\string\csname
   pxkc@@\string ^^e3\string ^^81\string ^^82%
   \string ^^e3\string ^^82\string ^^a2\endcsname}}
\bgroup \kcatcode"3040=15\kcatcode"30A0=18
  \disablecjktoken\pxkc@genprobe \global\let\pxkc@prb@d\pxkc@tmpa
  \enablecjktoken\pxkc@genprobe  \global\let\pxkc@prb@e\pxkc@tmpa
  \forcecjktoken\pxkc@genprobe   \global\let\pxkc@prb@f\pxkc@tmpa
\egroup

%% \pxkc@getcjktokmod\CS
\def\pxkc@getcjktokmod#1{%
  \bgroup \kcatcode"3040=15\kcatcode"30A0=18\pxkc@genprobe
    \ifx\pxkc@tmpa\pxkc@prb@d \global\chardef\pxkc@gtmpa\z@
    \else\ifx\pxkc@tmpa\pxkc@prb@e \global\chardef\pxkc@gtmpa\@ne
    \else\ifx\pxkc@tmpa\pxkc@prb@f \global\chardef\pxkc@gtmpa\tw@
    \else \global\let\pxkc@gtmpa\m@ne \fi\fi\fi
  \egroup \let#1\pxkc@gtmpa}

%%<+> \getcjktokenmode
% Returns the value showing current mode to \thecjktokenmode
%  0: \disablecjktoken
%  1: \enablecjktoken
%  2: \forcecjktoken
\def\getcjktokenmode{\pxkc@getcjktokmod\thecjktokenmode}

%%<*> \setcjktokenmode{<val>}
\def\pxkc@setcjktokmod#1{%
  \ifcase#1\disablecjktoken\or\enablecjktoken\or\forcecjktoken\fi}

%%<*> \withcjktokendisabled, etc.
\def\withcjktokendisabled{\pxkc@withcjktokmod\disablecjktoken\@iden}
\def\withcjktokenenabled{\pxkc@withcjktokmod\enablecjktoken\@iden}
\def\withcjktokenforced{\pxkc@withcjktokmod\forcecjktoken\@iden}
\def\withcjktokendisabledex{\pxkc@withcjktokmod\disablecjktoken}
\def\withcjktokenenabledex{\pxkc@withcjktokmod\enablecjktoken}
\def\withcjktokenforcedex{\pxkc@withcjktokmod\forcecjktoken}
\def\pxkc@withcjktokmod#1{%
  \pxkc@getcjktokmod\pxkc@tokmod #1\pxkc@withcjktokmod@a}
\def\pxkc@withcjktokmod@a#1#2{%
  #1{#2}\pxkc@setcjktokmod\pxkc@tokmod}

%%------ initial setup

\ifx\pxkc@ccmode\relax\else
\cjkcategorymode{\pxkc@ccmode}
\fi

%%------ all done
\endinput
%% EOF
