/* VALUE.C - Return longword value of ZONED DECIMAL number

; 21-Jul-92  DTH  Created to support DYNARRAY

;=============================================================================*/

#include <descrip.h>

typedef struct dsc$descriptor_s DESC;

long value (DESC *zoned)
	{
	long num = 0;
	int negative = 0;
	unsigned char ch, num1;
	char *cptr;
	int i;

	cptr = zoned->dsc$a_pointer;
	for (i=1; i<=zoned->dsc$w_length; i++)
	    {
	    ch = *cptr++;
	    if (ch >= '0' && ch <= '9')
		num1 = ch-48;
	    else
		if (ch >= 'p' && ch <= 'y' && i == zoned->dsc$w_length)
		    {
		    num1 = ch - 112;
		    negative = 1;
		    }
		else
		    return (0);			/* invalid number */
	    num = num * 10 + num1;
	    };
	if (negative) num = num * -1;
	return (num);
	}
