386BSD 0.1 development
[unix-history] / usr / othersrc / contrib / isode / psap / bit2prim.c
CommitLineData
cf908fd1
WJ
1/* bit2prim.c - bit string to presentation element */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/psap/RCS/bit2prim.c,v 7.1 91/02/22 09:35:29 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/psap/RCS/bit2prim.c,v 7.1 91/02/22 09:35:29 mrose Interim $
9 *
10 *
11 * $Log: bit2prim.c,v $
12 * Revision 7.1 91/02/22 09:35:29 mrose
13 * Interim 6.8
14 *
15 * Revision 7.0 89/11/23 22:12:31 mrose
16 * Release 6.0
17 *
18 */
19
20/*
21 * NOTICE
22 *
23 * Acquisition, use, and distribution of this module and related
24 * materials are subject to the restrictions of a license agreement.
25 * Consult the Preface in the User's Manual for the full terms of
26 * this agreement.
27 *
28 */
29
30
31/* LINTLIBRARY */
32
33#include <stdio.h>
34#include "psap.h"
35
36
37PE bit2prim_aux ();
38
39/* \f */
40
41PE bit2prim (pe)
42register PE pe;
43{
44 if (pe == NULLPE)
45 return NULLPE;
46
47 switch (pe -> pe_form) {
48 case PE_FORM_PRIM:
49 if (pe -> pe_prim == NULLPED) {
50 if ((pe -> pe_prim = PEDalloc (1)) == NULLPED)
51 return NULLPE;
52 pe -> pe_len = 1;
53 pe -> pe_nbits = 0;
54 }
55 /* and fall */
56
57 case PE_FORM_CONS:
58 if (bit2prim_aux (pe) == NULLPE)
59 return NULLPE;
60 break;
61 }
62
63 return pe;
64}
65
66/* \f */
67
68static PE bit2prim_aux (pe)
69register PE pe;
70{
71 int i;
72 register PE p;
73
74 if (pe == NULLPE)
75 return NULLPE;
76
77 switch (pe -> pe_form) {
78 case PE_FORM_PRIM:
79 if (pe -> pe_prim && pe -> pe_len) {
80 if ((i = (((pe -> pe_len - 1) * 8) - pe -> pe_nbits)) > 7)
81 return pe_seterr (pe, PE_ERR_BITS, NULLPE);
82 pe -> pe_prim[0] = i & 0xff;
83
84 }
85 break;
86
87 case PE_FORM_CONS:
88 for (p = pe -> pe_cons; p; p = p -> pe_next)
89 if (bit2prim (p) == NULLPE)
90 return NULLPE;
91 break;
92 }
93
94 return pe;
95}