summaryrefslogtreecommitdiff
path: root/third_party/gsm/tls/sweet.c
blob: 6a6fb297823f88d93cc9fc3aa0e96180ab925dd8 (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
 /*
  * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
  * Universitaet Berlin.  See the accompanying file "COPYRIGHT" for
  * details.  THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
  */

/*$Header: /tmp_amd/presto/export/kbs/jutta/src/gsm/RCS/sweet.c,v 1.2 1996/07/02 10:15:53 jutta Exp $*/
 
/* Generate code to unpack a bit array from name:#bits description */

#include	<stdio.h>
#include	"taste.h"
#include	"proto.h"

void write_code P2((s_spex, n_spex), struct spex * s_spex, int n_spex)
{
	struct spex	* sp = s_spex;
	int		bits = 8;
	int		vars;

	if (!n_spex) return;

	vars = sp->varsize;

	while (n_spex) {

		if (vars == sp->varsize) {
			printf("\t%s  = ", sp->var);
		} else printf("\t%s |= ", sp->var);

		if (vars == bits) {
	
			if (bits == 8) printf( "*c++;\n" );
			else printf( "*c++ & 0x%lX;\n",
				~(0xfffffffe << (bits - 1)) );

			if (!-- n_spex) break;
			sp++;
			vars = sp->varsize;
			bits = 8;

		} else if (vars < bits) {

			printf( "(*c >> %d) & 0x%lX;\n", 
				bits - vars,
				~(0xfffffffe << (vars - 1)));

			bits -= vars;
			if (!--n_spex) break;
			sp++;
			vars = sp->varsize;

		} else {
			/*   vars > bits.  We're eating lower-all of c,
			 *   but we must shift it.
			 */
			printf(	"(*c++ & 0x%X) << %d;\n",
				~(0xfffffffe << (bits - 1)),
				vars - bits );

			vars -= bits;
			bits = 8;
		}
	}
}