Debian Codegraph @

components/chsdet/src/nsPkg.pas

raw
1 // +----------------------------------------------------------------------+
2 // | chsdet - Charset Detector Library |
3 // +----------------------------------------------------------------------+
4 // | Copyright (C) 2006, Nick Yakowlew http://chsdet.sourceforge.net |
5 // +----------------------------------------------------------------------+
6 // | Based on Mozilla sources http://www.mozilla.org/projects/intl/ |
7 // +----------------------------------------------------------------------+
8 // | This library is free software; you can redistribute it and/or modify |
9 // | it under the terms of the GNU General Public License as published by |
10 // | the Free Software Foundation; either version 2 of the License, or |
11 // | (at your option) any later version. |
12 // | This library is distributed in the hope that it will be useful |
13 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 // | See the GNU Lesser General Public License for more details. |
16 // | http://www.opensource.org/licenses/lgpl-license.php |
17 // +----------------------------------------------------------------------+
18 //
19 // $Id: nsPkg.pas,v 1.3 2013/04/23 19:47:10 ya_nick Exp $
20
21 unit nsPkg;
22
23 interface
24 uses
25 nsCore;
26
27 type
28 nsIdxSft = (
29 eIdxSft4bits = 3
30 // NOT used
31 // eIdxSft8bits = 2,
32 // eIdxSft16bits = 1
33 );
34
35 nsSftMsk = (
36 eSftMsk4bits = 7
37 // NOT used
38 // eSftMsk8bits = 3,
39 // eSftMsk16bits = 1
40 );
41
42 nsBitSft = (
43 eBitSft4bits = 2
44 // NOT used
45 // eBitSft8bits = 3,
46 // eBitSft16bits = 4
47 );
48
49 nsUnitMsk = (
50 eUnitMsk4bits = $0000000F
51 // NOT used
52 // eUnitMsk8bits = $000000FF,
53 // eUnitMsk16bits = $0000FFFF
54 );
55
56
57 nsPkgInt = record
58 idxsft: nsIdxSft;
59 sftmsk: nsSftMsk;
60 bitsft: nsBitSft;
61 unitmsk: nsUnitMsk;
62 data: puInt32;
63 end;
64 pnsPkgInt = ^nsPkgInt;
65
66
67 function PCK4BITS(a, b, c, d, e, f, g, h: integer): integer;
68
69 function GETFROMPCK(i: integer; c: pnsPkgInt): integer;
70
71 implementation
72
73
74 function PCK16BITS(a: integer; b: integer): integer;
75 begin
76 Result:= ((b shl 16) or a);
77 end;
78
79 function PCK8BITS(a, b, c, d: integer): integer;
80 begin
81 Result:= PCK16BITS(((b shl 8) or a), ((d shl 8) or c));
82 end;
83
84 function PCK4BITS(a, b, c, d, e, f, g, h: integer): integer;
85 begin
86 Result:= PCK8BITS(((b shl 4) or a), ((d shl 4) or c), ((f shl 4) or e), ((h shl 4) or g));
87 end;
88
89 function GETFROMPCK(i: integer; c: pnsPkgInt): integer;
90 begin
91 Result:= (((auInt32(c^.data)[i shr integer(c^.idxsft)]) shr (i and integer(c^.sftmsk) shl integer(c^.bitsft))) and integer(c^.unitmsk));
92 end;
93
94 end.