1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * codesyms.c -- Functions which code the symbol sequence
|
---|
4 | * Copyright (C) 1994 Hugh Emberson
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | * $Id: codesyms.c 16583 2008-07-29 10:20:36Z davidb $
|
---|
21 | *
|
---|
22 | **************************************************************************/
|
---|
23 |
|
---|
24 | #include "sysfuncs.h"
|
---|
25 |
|
---|
26 | #include "arithcode.h"
|
---|
27 | #include "marklist.h"
|
---|
28 | #include "pbmtools.h"
|
---|
29 | #include "utils.h"
|
---|
30 | #include "codesyms.h"
|
---|
31 |
|
---|
32 | int charsetsize = 256;
|
---|
33 |
|
---|
34 | void
|
---|
35 | EncodeSymbols (marklistptr MarkList, int NSyms)
|
---|
36 | {
|
---|
37 | marklistptr step;
|
---|
38 | unsigned short Events[PPM_CHUNK];
|
---|
39 | int j = 0;
|
---|
40 |
|
---|
41 | charsetsize = max (NSyms, 256);
|
---|
42 |
|
---|
43 | step = MarkList;
|
---|
44 | while (step)
|
---|
45 | {
|
---|
46 | Events[j] = step->data.symnum;
|
---|
47 |
|
---|
48 | assert (Events[j] > 0 || Events[j] < (unsigned) NSyms);
|
---|
49 |
|
---|
50 | j++;
|
---|
51 |
|
---|
52 | if (j == PPM_CHUNK)
|
---|
53 | {
|
---|
54 | encodestring (Events, PPM_CHUNK);
|
---|
55 | j = 0;
|
---|
56 | }
|
---|
57 | step = step->next;
|
---|
58 | };
|
---|
59 |
|
---|
60 | if (j != 0)
|
---|
61 | encodestring (Events, j);
|
---|
62 |
|
---|
63 | encodestring (Events, 0);
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | marklistptr
|
---|
68 | DecodeSymbols (int NSyms)
|
---|
69 | {
|
---|
70 | marklistptr MarkList = NULL;
|
---|
71 | unsigned short Events[PPM_CHUNK];
|
---|
72 | int j, n;
|
---|
73 | marktype d;
|
---|
74 |
|
---|
75 | charsetsize = max (NSyms, 256);
|
---|
76 |
|
---|
77 | do
|
---|
78 | {
|
---|
79 | decodestring (Events, &n);
|
---|
80 |
|
---|
81 | for (j = 0; j < n; j++)
|
---|
82 | {
|
---|
83 | d.symnum = Events[j];
|
---|
84 | marklist_add (&MarkList, d);
|
---|
85 | }
|
---|
86 | }
|
---|
87 | while (n != 0);
|
---|
88 |
|
---|
89 | return MarkList;
|
---|
90 | }
|
---|
91 |
|
---|
92 | void
|
---|
93 | InitPPM (void)
|
---|
94 | {
|
---|
95 | kbytes = 896;
|
---|
96 | }
|
---|