campo-sirio/gfm/dtoui.c

60 lines
970 B
C
Raw Normal View History

/* unsigned ConvDecimalToUns(x)
*
* ARGUMENT
* DEC *x;
*
* DESCRIPTION
* Converts a DEC to an unsigned (integer).
*
* SIDE EFFECTS
* None.
*
* RETURNS
* The integer if the conversion is successful, and the error code
* otherwise.
*
* AUTHOR
* Jared Levy Feb. 9, 1987
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* POSSIBLE ERROR CODES
*
* GM_NULLPOINTER
* GM_CNVRE
* GM_CNVRW
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
unsigned ConvDecimalToUns(x)
DEC *x;
{
DEC temp;
DEC *pt;
unsigned SHORT i;
_MacStart(GM_DTOUI);
_MacInVar(x, 0);
pt = &temp;
(void) _ScaleDec80Bit(pt, x, 0); /* convert to integer */
/* 0 <= x <= 65535 */
if(!(pt->dc.sl[1] | pt->dc.sl[2] | pt->dc.sl[3] | pt->dc.msd)
&& !_MacIsDecN(pt)) {
if (CompareDecimal(x,pt)!=0)
_MacErr(GM_CNVRW);
i = pt->dc.sl[0];
_MacRet (i);
}
/* overflow */
_MacErr(GM_CNVRE);
_MacRet(0);
}