Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source libSC G2++ g2++lib g2ntostr.c
Document Actions

g2ntostr.c

by Michael L Powell last modified 2007-01-26 03:23

Click here to get the file

Size 2.9 kB - File type text/plain

File contents

/*ident	"@(#)G2++:g2++lib/g2ntostr.c	3.1" */
/******************************************************************************
*
* C++ Standard Components, Release 3.0.
*
* Copyright (c) 1991, 1992 AT&T and Unix System Laboratories, Inc.
* Copyright (c) 1988, 1989, 1990 AT&T.  All Rights Reserved.
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T and Unix System
* Laboratories, Inc.  The copyright notice above does not evidence
* any actual or intended publication of such source code.
*
******************************************************************************/

#include <g2io.h>

//
// _g2ltostr - long to string mapping
// 	returns pointer into usr buffer where output string begins
//	(N.B. this will probably not be the beginning of the buffer.)

char* _g2ltostr_ATTLC(
    char buf[], 
    int bufsize, 
    register long n
){
    int	sign;
    register char* cp = buf+bufsize;

    *--cp = '\0';

    if( n < 0 ){
	sign = 1;

	if( n == HIBITL ){
	    unsigned long m = (unsigned long)n;
	    n = m/10;
	    *--cp = (unsigned char)(m - 10*n + '0');
	}else{ 
	    n = -n;
	}
    }else{
	sign = 0;
    }
    do{
	int val = (int)n;
	n /= 10;
	*--cp = (unsigned char)(val - 10*n + '0');
    }while (n);

    if( sign ){
	*--cp = '-';
    }
    return cp;
}
#ifndef _g2itostr

// _g2itostr - int to string mapping
// 	returns pointer into usr buffer where output string begins
//	(N.B. this will probably not be the beginning of the buffer.)

char* _g2itostr(char buf[], int bufsize, register int n){

    int	sign;
    register char* cp = buf+bufsize;

    *--cp = '\0';

    if (n < 0) {
	sign = 1;

	if (n == HIBITI) {
	    unsigned long m = (unsigned int)n;
	    n = m/10;
	    *--cp = m - 10*n + '0';
	}else{ 
	    n = -n;
	}
    }else{
	sign = 0;
    }
    do{
	int val = n;
	n /= 10;
	*--cp = val - 10*n + '0';
    }while (n);

    if(sign){
	*--cp = '-';
    }
    return cp;
}
#endif

char* _g2ctostr_ATTLC(char buf[], int bufsize, register int n){
    register char* cp = buf+bufsize;

    *--cp = '\0';

    do{
	*--cp = (n&07) + '0';
	n = (n>>1) & ~HIBITI;
	n >>= 2;
    }while (n);
    
    return cp;	
}

#ifdef TEST
_main()
{
    char buf[20]; 
    char* cp;
    printf("%s\n", _g2ltostr(buf, sizeof(buf), 0L));
    printf("%s\n", _g2ltostr(buf, sizeof(buf), 1000000L));
    printf("%s\n", _g2ltostr(buf, sizeof(buf), -1000000L));
    printf("%s\n", _g2ltostr(buf, sizeof(buf), 0x80000000));
    printf("%s\n", _g2itostr(buf, sizeof(buf), 0));
    printf("%s\n", _g2itostr(buf, sizeof(buf), 10000));
    printf("%s\n", _g2itostr(buf, sizeof(buf), -10000));
    printf("%s\n", _g2itostr(buf, sizeof(buf), 0x8000));
    printf("%s\n", _g2itostr(buf, sizeof(buf), 0x80000000));
    printf("%s\n", _g2ctostr(buf, sizeof(buf), 0));
    printf("%s\n", _g2ctostr(buf, sizeof(buf), 10000));
    printf("%s\n", _g2ctostr(buf, sizeof(buf), -10000));
    printf("%s\n", _g2ctostr(buf, sizeof(buf), 0x8000));
    printf("%s\n", _g2ctostr(buf, sizeof(buf), 0x80000000));
}
#endif
« May 2024 »
Su Mo Tu We Th Fr Sa
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
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: