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
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
/*
 *  This software is derived from f2c (http://www.netlib.org/f2c)
 *
 *  Copyright 1990, 1992 - 1997, 1999, 2000 by AT&T, Lucent Technologies
 *  and Bellcore.
 *
 *  See the LICENCE file for the permission notice and warranty disclaimer
 *  provided by the f2c authors.
 *
 */

#include <f77crash/auxiliary.h>
#include <cassert>
#include <climits>

static bool initialized = false;

static unsigned char hexToIntTab[1 << CHAR_BIT];
static unsigned char isAlpha_Tab[1 << CHAR_BIT];
static unsigned char letterTab[1 << CHAR_BIT];

void
initAuxiliary()
{
//
//  Init table for hexToInt
//
    const char    *hex = "0123456789abcdef";
    const char    *Hex = "ABCDEF";

    for (int i = 0; hex[i]; ++i) {
        hexToIntTab[(unsigned char)(hex[i])] = i;
    }
    for (int i=0, j=10; Hex[i]; ++i, ++j) {
        hexToIntTab[(unsigned char)(Hex[i])] = j;
    }

//
//  Init table for isAlpha_
//
    const char *alpha_ = "abcdefghijklmnopqrstuvwxyz"
                         "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
    const char *Alpha_ = "0123456789";

    while (unsigned char i = *alpha_++) {
        isAlpha_Tab[i] = 1;
    }

    while (unsigned char i = *Alpha_++) {
        isAlpha_Tab[i] = 2;
    }

//
//  Init table for letter
//
    const char    *letter = "abcdefghijklmnopqrstuvwxyz";

    for(int j=0, i=0; (i = *letter); ++j, ++letter) {
        letterTab[i] = letterTab[(unsigned char)(i+'A'-'a')] = j;
    }

    initialized = true;
}

int
hexToInt(char c)
{
    assert(initialized);

    return hexToIntTab[(unsigned char)(c)];
}

bool
isAlpha_(int c)
{
    assert(initialized);

    return isAlpha_Tab[(unsigned char)(c)] == 1;
}

bool
isAlphaNum_(int c)
{
    assert(initialized);

    return isAlpha_Tab[(unsigned char)(c)];
}

unsigned char
letter(char c)
{
    assert(initialized);
    return letterTab[(unsigned char)(c)];
}