
/*============================================================================

This C source file is part of TestFloat, Release 3, a package of programs for
testing the correctness of floating-point arithmetic complying with the IEEE
Standard for Floating-Point, by John R. Hauser.

Copyright 2011, 2012, 2013, 2014 The Regents of the University of California
(Regents).  All Rights Reserved.  Redistribution and use in source and binary
forms, with or without modification, are permitted provided that the following
conditions are met:

Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following two paragraphs of disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following two paragraphs of disclaimer in the
documentation and/or other materials provided with the distribution.  Neither
the name of the Regents nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.

IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
HEREUNDER IS PROVIDED "AS IS".  REGENTS HAS NO OBLIGATION TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

=============================================================================*/

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "platform.h"
#include "readHex.h"

bool readHex_bool( bool *aPtr, char sepChar )
{
    int i;
    bool a;

    i = fgetc( stdin );
    if ( (i == EOF) || (i < '0') || ('1' < i) ) return false;
    a = i - '0';
    if ( sepChar ) {
        i = fgetc( stdin );
        if ( (sepChar != '\n') || (i != '\r') ) {
            if ( i != sepChar ) return false;
        }
    }
    *aPtr = a;
    return true;

}

bool readHex_ui8( uint_least8_t *aPtr, char sepChar )
{
    int i;
    uint_fast8_t a;

    i = fgetc( stdin );
    if ( i == EOF ) return false;
    if ( ('0' <= i) && (i <= '9') ) {
        i -= '0';
    } else if ( ('A' <= i) && (i <= 'F') ) {
        i -= 'A' - 10;
    } else if ( ('a' <= i) && (i <= 'f') ) {
        i -= 'a' - 10;
    } else {
        return false;
    }
    a = i<<4;
    i = fgetc( stdin );
    if ( i == EOF ) return false;
    if ( ('0' <= i) && (i <= '9') ) {
        i -= '0';
    } else if ( ('A' <= i) && (i <= 'F') ) {
        i -= 'A' - 10;
    } else if ( ('a' <= i) && (i <= 'f') ) {
        i -= 'a' - 10;
    } else {
        return false;
    }
    a |= i;
    if ( sepChar ) {
        i = fgetc( stdin );
        if ( (sepChar != '\n') || (i != '\r') ) {
            if ( i != sepChar ) return false;
        }
    }
    *aPtr = a;
    return true;

}

bool readHex_ui16( uint16_t *aPtr, char sepChar )
{
    int i;
    uint_fast16_t a;

    i = fgetc( stdin );
    if ( i == EOF ) return false;
    if ( ('0' <= i) && (i <= '9') ) {
        i -= '0';
    } else if ( ('A' <= i) && (i <= 'F') ) {
        i -= 'A' - 10;
    } else if ( ('a' <= i) && (i <= 'f') ) {
        i -= 'a' - 10;
    } else {
        return false;
    }
    a = (uint_fast16_t) i<<12;
    i = fgetc( stdin );
    if ( i == EOF ) return false;
    if ( ('0' <= i) && (i <= '9') ) {
        i -= '0';
    } else if ( ('A' <= i) && (i <= 'F') ) {
        i -= 'A' - 10;
    } else if ( ('a' <= i) && (i <= 'f') ) {
        i -= 'a' - 10;
    } else {
        return false;
    }
    a |= (uint_fast16_t) i<<8;
    i = fgetc( stdin );
    if ( i == EOF ) return false;
    if ( ('0' <= i) && (i <= '9') ) {
        i -= '0';
    } else if ( ('A' <= i) && (i <= 'F') ) {
        i -= 'A' - 10;
    } else if ( ('a' <= i) && (i <= 'f') ) {
        i -= 'a' - 10;
    } else {
        return false;
    }
    a |= (uint_fast16_t) i<<4;
    i = fgetc( stdin );
    if ( i == EOF ) return false;
    if ( ('0' <= i) && (i <= '9') ) {
        i -= '0';
    } else if ( ('A' <= i) && (i <= 'F') ) {
        i -= 'A' - 10;
    } else if ( ('a' <= i) && (i <= 'f') ) {
        i -= 'a' - 10;
    } else {
        return false;
    }
    a |= i;
    if ( sepChar ) {
        i = fgetc( stdin );
        if ( (sepChar != '\n') || (i != '\r') ) {
            if ( i != sepChar ) return false;
        }
    }
    *aPtr = a;
    return true;

}

bool readHex_ui32( uint32_t *aPtr, char sepChar )
{
    uint16_t v16, v0;

    if ( ! readHex_ui16( &v16, 0 ) || ! readHex_ui16( &v0, sepChar ) ) {
        return false;
    }
    *aPtr = (uint_fast32_t) v16<<16 | v0;
    return true;

}

bool readHex_ui64( uint64_t *aPtr, char sepChar )
{
    uint32_t v32, v0;

    if ( ! readHex_ui32( &v32, 0 ) || ! readHex_ui32( &v0, sepChar ) ) {
        return false;
    }
    *aPtr = (uint_fast64_t) v32<<32 | v0;
    return true;

}

