blob: 6a6fb297823f88d93cc9fc3aa0e96180ab925dd8 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001 /*
2 * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3 * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4 * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5 */
6
7/*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/sweet.c,v 1.2 1996/07/02 10:15:53 jutta Exp $*/
8
9/* Generate code to unpack a bit array from name:#bits description */
10
11#include <stdio.h>
12#include "taste.h"
13#include "proto.h"
14
15void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
16{
17 struct spex * sp = s_spex;
18 int bits = 8;
19 int vars;
20
21 if (!n_spex) return;
22
23 vars = sp->varsize;
24
25 while (n_spex) {
26
27 if (vars == sp->varsize) {
28 printf("\t%s = ", sp->var);
29 } else printf("\t%s |= ", sp->var);
30
31 if (vars == bits) {
32
33 if (bits == 8) printf( "*c++;\n" );
34 else printf( "*c++ & 0x%lX;\n",
35 ~(0xfffffffe << (bits - 1)) );
36
37 if (!-- n_spex) break;
38 sp++;
39 vars = sp->varsize;
40 bits = 8;
41
42 } else if (vars < bits) {
43
44 printf( "(*c >> %d) & 0x%lX;\n",
45 bits - vars,
46 ~(0xfffffffe << (vars - 1)));
47
48 bits -= vars;
49 if (!--n_spex) break;
50 sp++;
51 vars = sp->varsize;
52
53 } else {
54 /* vars > bits. We're eating lower-all of c,
55 * but we must shift it.
56 */
57 printf( "(*c++ & 0x%X) << %d;\n",
58 ~(0xfffffffe << (bits - 1)),
59 vars - bits );
60
61 vars -= bits;
62 bits = 8;
63 }
64 }
65}
66