src/player-birth.c
static int roman_to_int(const char *roman)
{
	size_t i;
	int n = 0;
	char *p;

	char roman_token_chr1[] = "MDCLXVI";
	const char *roman_token_chr2[] = {0, 0, "DM", 0, "LC", 0, "VX"};

	int roman_token_vals[7][3] = {{1000},
	                              {500},
	                              {100, 400, 900},
	                              {50},
	                              {10, 40, 90},
	                              {5},
	                              {1, 4, 9}};

	if (strlen(roman) == 0)
		return -1;

	/* Check each character for a roman token, and look ahead to the
	   character after this one to check for subtraction */
	for (i = 0; i < strlen(roman); i++) {
		char c1, c2;
		int c1i, c2i;

		/* Get the first and second chars of the next roman token */
		c1 = roman[i];
		c2 = roman[i + 1];

		/* Find the index for the first character */
		p = strchr(roman_token_chr1, c1);
		if (p)
			c1i = p - roman_token_chr1;
		else
			return -1;

		/* Find the index for the second character */
		c2i = 0;
		if (roman_token_chr2[c1i] && c2) {
			p = strchr(roman_token_chr2[c1i], c2);
			if (p) {
				c2i = (p - roman_token_chr2[c1i]) + 1;
				/* Two-digit token, so skip a char on the next pass */
				i++;
			}
		}

		/* Increase the arabic numeral */
		n += roman_token_vals[c1i][c2i];
	}

	return n;
}
/**
 * Converts a roman numeral (char *) to an arabic numeral (int).
 *
 * The null-terminated roman numeral is accepted in the `roman`
 * parameter and the corresponding integer arabic numeral is returned.
 * Only upper-case values are considered. When the `roman` parameter
 * is empty or does not resemble a roman numeral, a value of -1 is
 * returned.
 *
 * XXX This function will parse certain non-sense strings as roman
 *     numerals, such as IVXCCCVIII
 */
Converts a roman numeral (char *) to an arabic numeral (int).
The null-terminated roman numeral is accepted in the `roman`
parameter and the corresponding integer arabic numeral is returned.
Only upper-case values are considered. When the `roman` parameter
is empty or does not resemble a roman numeral, a value of -1 is
returned.

XXX This function will parse certain non-sense strings as roman
numerals, such as IVXCCCVIII
Converts a roman numeral ( char * ) to an arabic numeral ( int ) . The null - terminated roman numeral is accepted in the ` roman ` parameter and the corresponding integer arabic numeral is returned . Only upper - case values are considered . When the ` roman ` parameter is empty or does not resemble a roman numeral a value of - 1 is returned . XXX This function will parse certain non - sense strings as roman numerals such as IVXCCCVIII
static int roman_to_int(const char *roman)
{
	size_t i;
	int n = 0;
	char *p;
	char roman_token_chr1[] = "MDCLXVI";
	const char *roman_token_chr2[] = {0, 0, "DM", 0, "LC", 0, "VX"};
	int roman_token_vals[7][3] = {{1000},
	                              {500},
	                              {100, 400, 900},
	                              {50},
	                              {10, 40, 90},
	                              {5},
	                              {1, 4, 9}};
	if (strlen(roman) == 0)
		return -1;
	for (i = 0; i < strlen(roman); i++) {
		char c1, c2;
		int c1i, c2i;
		c1 = roman[i];
		c2 = roman[i + 1];
		p = strchr(roman_token_chr1, c1);
		if (p)
			c1i = p - roman_token_chr1;
		else
			return -1;
		c2i = 0;
		if (roman_token_chr2[c1i] && c2) {
			p = strchr(roman_token_chr2[c1i], c2);
			if (p) {
				c2i = (p - roman_token_chr2[c1i]) + 1;
				i++;
			}
		}
		n += roman_token_vals[c1i][c2i];
	}
	return n;
}
static int roman_to_int ( const char * roman ) { size_t i ; int n = 0 ; char * p ; char roman_token_chr1 [ ] = " " ; const char * roman_token_chr2 [ ] = { 0 , 0 , " " , 0 , " " , 0 , " " } ; int roman_token_vals [ 7 ] [ 3 ] = { { 1000 } , { 500 } , { 100 , 400 , 900 } , { 50 } , { 10 , 40 , 90 } , { 5 } , { 1 , 4 , 9 } } ; if ( strlen ( roman ) == 0 ) return -1 ; for ( i = 0 ; i < strlen ( roman ) ; i ++ ) { char c1 , c2 ; int c1i , c2i ; c1 = roman [ i ] ; c2 = roman [ i + 1 ] ; p = strchr ( roman_token_chr1 , c1 ) ; if ( p ) c1i = p - roman_token_chr1 ; else return -1 ; c2i = 0 ; if ( roman_token_chr2 [ c1i ] && c2 ) { p = strchr ( roman_token_chr2 [ c1i ] , c2 ) ; if ( p ) { c2i = ( p - roman_token_chr2 [ c1i ] ) + 1 ; i ++ ; } } n += roman_token_vals [ c1i ] [ c2i ] ; } return n ; }
Converts a roman numeral (char *) to an arabic numeral (int).
Converts a roman numeral ( char * ) to an arabic numeral ( int ) .
/* Check each character for a roman token, and look ahead to the
	   character after this one to check for subtraction */ /* Get the first and second chars of the next roman token */ /* Find the index for the first character */ /* Find the index for the second character */ /* Two-digit token, so skip a char on the next pass */ /* Increase the arabic numeral */