blob: 4f95a26d7bb02ac7f41f8c7c96641a6579028ae6 (
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
|
%%
%% This is file 'upkcat.sty'.
%%
%% Copyright (c) 2008-2021 Takayuki YATO (aka. "ZR")
%% GitHub: https://github.com/zr-tex8r
%% Twitter: @zr_tex8r
%%
%% This package is distributed under the MIT License.
%%
% Note: This package supports both upLaTeX and plain upTeX.
%% avoid multiple loading
\csname\if11upkcatstyLoaded\fi\endcsname
%% code guards
\edef\x{\catcode32=\the\catcode32%
\catcode43=\the\catcode43\catcode45=\the\catcode45%
\catcode46=\the\catcode46\catcode47=\the\catcode47%
\catcode60=\the\catcode60\catcode63=\the\catcode63%
\catcode64=\the\catcode64\catcode96=\the\catcode96%
\endlinechar=\the\endlinechar\relax}
\catcode32=10\relax\endlinechar=13\relax
\catcode43=12 \catcode45=12 % <+><->
\catcode46=12 \catcode47=12 % <.></>
\catcode60=12 \catcode63=12 % <<><?>
\catcode64=11 \catcode96=12 % <@><`>
\edef\pxkq@restore@codes{\x\let\noexpand\pxkq@restore@codes\relax}
%% check for LaTeX
\ifx\RequirePackage\@undefined %<*!LaTeX>
\long\def\x#1\ProvidesPackage#2[#3]{\immediate\write-1{Package: #2 #3}}
\expandafter\x
\else %<*LaTeX>
\RequirePackage{ifuptex}[2008/03/14]\RequireupTeX
\fi %</LaTeX>
%% package declaration
\NeedsTeXFormat{pLaTeX2e}
\ProvidesPackage{upkcat}[2021/05/22 v1.2 safe kcatcode access]
%--------------------------------------- main
%%<*> \getkcatcode{<jachar>}
\def\getkcatcode#1{\pxkq@getcp{#1}%
\edef\thekcatcode{\the\kcatcode\pxkq@cp}}
%%<*> \setkcatcode{<jachar>}{<value>}
\def\setkcatcode#1#2{\pxkq@getcp{#1}\kcatcode\pxkq@cp#2}
\newcount\pxkq@cp \newif\ifpxkq@ok
\def\pxkq@getcp#1{\pxkq@getcp@a#1\relax\relax}
\def\pxkq@nxt#1#2#3#4#5{\pxkq@cp#1\loop
{\lccode`\?\pxkq@cp \advance\pxkq@cp-#3%
\lowercase{\expandafter\xdef\csname pxkq@#4?\endcsname}{#5}}%
\advance\pxkq@cp\@ne \ifnum\pxkq@cp<#2\repeat}
\pxkq@nxt{240}{248}{240}l{\pxkq@cp\the\pxkq@cp\noexpand\pxkq@da}
\pxkq@nxt{224}{240}{224}l{\pxkq@cp\the\pxkq@cp\noexpand\pxkq@ca}
\pxkq@nxt{194}{224}{192}l{\pxkq@cp\the\pxkq@cp\noexpand\pxkq@ba}
\pxkq@nxt{128}{192}{128}t{\advance\pxkq@cp\the\pxkq@cp\noexpand\pxkq@oktrue}
\def\pxkq@getcp@a#1{\pxkq@cp`#1\relax\pxkq@chkk#1%
\ifpxkq@ok \let\pxkq@nxt\pxkq@end \else
\expandafter\let\expandafter\pxkq@nxt\csname pxkq@l\string#1\endcsname
\ifx\pxkq@nxt\relax \let\pxkq@nxt\pxkq@err \fi
\fi \pxkq@nxt}
\def\pxkq@stp#1#2{\multiply\pxkq@cp64\pxkq@okfalse
\csname pxkq@t\string#2\endcsname
\ifpxkq@ok \expandafter#1\else \expandafter\pxkq@err \fi}
\def\pxkq@end#1\relax{}
\def\pxkq@ba{\pxkq@stp\pxkq@end}\def\pxkq@ca{\pxkq@stp\pxkq@cb}
\def\pxkq@cb{\pxkq@stp\pxkq@end}\def\pxkq@da{\pxkq@stp\pxkq@db}
\def\pxkq@db{\pxkq@stp\pxkq@dc}\def\pxkq@dc{\pxkq@stp\pxkq@end}
\begingroup\lccode`8=`k\lccode`9=`a \lowercase{\endgroup
\def\pxkq@chkk#1{\pxkq@okfalse\expandafter\pxkq@chkk@a\meaning#189\@nil}
\def\pxkq@chkk@a#189#2\@nil{\ifcat @#1@\pxkq@oktrue\fi}}
\def\pxkq@err#1\relax{\errhelp{I regard it as U+FFFF}%
\errmessage{Corrupted UTF-8 bytes}\pxkq@cp65535\relax}
%\def\pxkq@end#1\relax{\showthe\pxkq@cp}
%--------------------------------------- all done
\pxkq@restore@codes
\endinput
%% EOF
|