forked from mojadita/twelvedays
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeco.c
106 lines (90 loc) · 2.93 KB
/
deco.c
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* $Id: main.c.m4,v 1.7 2005/11/07 19:39:53 luis Exp $
* Author: Luis Colorado <[email protected]>
* Date: Wed Jan 28 10:50:41 EET 2015
*
* Disclaimer:
* (C) 2015 ERICSSON AB.
*
* All Rights Reserved. Reproduction in whole or in part is prohibited
* without the written consent of the copyright owner.
*
* ERICSSON MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. ERICSSON SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/
#define IN_DECO_C
/* Standard include files */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "deco.h"
#include "rom.i"
/* variables */
const UWord8 **the_strings = NULL;
const UWord8 **the_macros = NULL;
/* functions */
int deco_macro(const UWord8 *in, UWord16 len, UWord8 *out)
{
int res = 0;
for (; len > 0; len--, in++) {
if (*in == ESCAPE) {
len--; in++;
assert(len > 0);
if (*in == ESCOUT) {
*out++ = ESCAPE; res++;
} else {
register int n = deco_macro(
the_macros[*in - OFFSET],
macros_sz[*in - OFFSET],
out);
out += n; res += n;
} /* if */
} else {
*out++ = *in;
res++;
} /* if */
} /* for */
return res;
} /* deco_macro */
int deco_string(UWord8 *out)
{
int i, res = 0;
const UWord8 *p = strings;
/* INITIALIZATION */
if (!the_strings) {
the_strings = calloc(strings_n, sizeof(UWord8 *));
for (i = 0; i < strings_n; i++) {
the_strings[i] = p;
p += strings_sz[i];
} /* for */
} /* if */
if (!the_macros) {
the_macros = calloc(macros_n, sizeof(UWord8 *));
for (i = 0; i < macros_n; i++) {
the_macros[i] = p;
p += macros_sz[i];
} /* for */
} /* if */
/* PROCESSING */
for (i = 0; i < strings_n; i++) {
register int n;
n = deco_macro(the_strings[i], strings_sz[i], out);
res += n; out += n;
} /* for */
fprintf(stderr,
"Sizeof strings_n: %8ld\n"
"Sizeof strings_sz: %8ld\n"
"Sizeof macros_n: %8ld\n"
"Sizeof macros_sz: %8ld\n"
"Sizeof strings: %8ld\n"
" Total: %8ld\n"
" Output: %8ld\n",
sizeof strings_n, sizeof strings_sz, sizeof macros_n, sizeof macros_sz, sizeof strings,
sizeof strings_n + sizeof strings_sz + sizeof macros_n + sizeof macros_sz + sizeof strings,
res);
return res;
} /* deco */
/* $Id: main.c.m4,v 1.7 2005/11/07 19:39:53 luis Exp $ */