Files
ipxe/src/include/ctype.h
Michael Brown c30b71ee9c [console] Restore compatibility with "--key" values in existing scripts
Commit 3ef4f7e ("[console] Avoid overlap between special keys and
Unicode characters") renumbered the special key encoding to avoid
collisions with Unicode key values outside the ASCII range.  This
change broke backwards compatibility with existing scripts that
specify key values using e.g. "prompt --key" or "menu --key".

Restore compatibility with existing scripts by tweaking the special
key encoding so that the relative key value (i.e. the delta from
KEY_MIN) is numerically equal to the old pre-Unicode key value, and by
modifying parse_key() to accept a relative key value.

Reported-by: Sven Dreyer <sven@dreyer-net.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2023-07-07 15:14:00 +01:00

129 lines
2.6 KiB
C

#ifndef _CTYPE_H
#define _CTYPE_H
/** @file
*
* Character types
*
*/
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/**
* Check if character is ASCII
*
* @v character Character
* @ret is_ascii Character is an ASCII character
*/
static inline int isascii ( int character ) {
return ( character <= '\x7f' );
}
/**
* Check if character is a decimal digit
*
* @v character ASCII character
* @ret is_digit Character is a decimal digit
*/
static inline int isdigit ( int character ) {
return ( ( character >= '0' ) && ( character <= '9' ) );
}
/**
* Check if character is a hexadecimal digit
*
* @v character ASCII character
* @ret is_xdigit Character is a hexadecimal digit
*/
static inline int isxdigit ( int character ) {
return ( ( ( character >= '0' ) && ( character <= '9' ) ) ||
( ( character >= 'A' ) && ( character <= 'F' ) ) ||
( ( character >= 'a' ) && ( character <= 'f' ) ) );
}
/**
* Check if character is an upper-case letter
*
* @v character ASCII character
* @ret is_upper Character is an upper-case letter
*/
static inline int isupper ( int character ) {
return ( ( character >= 'A' ) && ( character <= 'Z' ) );
}
/**
* Check if character is a lower-case letter
*
* @v character ASCII character
* @ret is_lower Character is a lower-case letter
*/
static inline int islower ( int character ) {
return ( ( character >= 'a' ) && ( character <= 'z' ) );
}
/**
* Check if character is alphabetic
*
* @v character ASCII character
* @ret is_alpha Character is alphabetic
*/
static inline int isalpha ( int character ) {
return ( isupper ( character ) || islower ( character ) );
}
/**
* Check if character is alphanumeric
*
* @v character ASCII character
* @ret is_alnum Character is alphanumeric
*/
static inline int isalnum ( int character ) {
return ( isalpha ( character ) || isdigit ( character ) );
}
/**
* Check if character is printable
*
* @v character ASCII character
* @ret is_print Character is printable
*/
static inline int isprint ( int character ) {
return ( ( character >= ' ' ) && ( character <= '~' ) );
}
/**
* Convert character to lower case
*
* @v character Character
* @v character Lower-case character
*/
static inline int tolower ( int character ) {
return ( isupper ( character ) ?
( character - 'A' + 'a' ) : character );
}
/**
* Convert character to upper case
*
* @v character Character
* @v character Upper-case character
*/
static inline int toupper ( int character ) {
return ( islower ( character ) ?
( character - 'a' + 'A' ) : character );
}
extern int isspace ( int character );
#endif /* _CTYPE_H */