386BSD 0.1 development
[unix-history] / usr / othersrc / contrib / isode / psap / num2prim.c
CommitLineData
cf908fd1
WJ
1/* num2prim.c - integer to presentation element */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/psap/RCS/num2prim.c,v 7.1 91/02/22 09:35:49 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/psap/RCS/num2prim.c,v 7.1 91/02/22 09:35:49 mrose Interim $
9 *
10 *
11 * $Log: num2prim.c,v $
12 * Revision 7.1 91/02/22 09:35:49 mrose
13 * Interim 6.8
14 *
15 * Revision 7.0 89/11/23 22:12:45 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/* \f */
37
38PE num2prim (i, class, id)
39register integer i;
40PElementClass class;
41PElementID id;
42{
43 register integer mask,
44 sign,
45 n;
46 register PElementData dp;
47 register PE pe;
48
49 if ((pe = pe_alloc (class, PE_FORM_PRIM, id)) == NULLPE)
50 return NULLPE;
51
52 sign = i >= 0 ? i : i ^ (-1);
53 mask = 0x1ff << (((n = sizeof i) - 1) * 8 - 1);
54 while (n > 1 && (sign & mask) == 0)
55 mask >>= 8, n--;
56
57 if ((pe -> pe_prim = PEDalloc (n)) == NULLPED) {
58 pe_free (pe);
59 return NULLPE;
60 }
61
62 for (dp = pe -> pe_prim + (pe -> pe_len = n); n-- > 0; i >>= 8)
63 *--dp = i & 0xff;
64
65 return pe;
66}