[BusyBox] ctype, isspace, tolower all-glibc routines
olivier.delouya at takimaging.com
olivier.delouya at takimaging.com
Mon Feb 28 14:01:00 UTC 2005
This is a contribution for all that have issues with ctype routines and
version of their glibc.
(specially at the border of 2.2 and 2.3!)
They are not internationalized, and they bring a (very) small code
overhead
Eventually, you can insert your native ctype.h in the empty else branch
for futur use
cut the rest of that email and save it under ctype.h
May it help
Olivier Delouya
/*
this file = ctype.h
*/
/*******************************************************************************************************
* *
* The jeep of ctype.h versions! avoid linkage issues with glibc_xxx
!! *
* - Olivier Delouya (olivier_delouya at hotmail.com) - Feb 28 2005 *
* come back to the good old time of Unix ctype defs (remember, small
is beautifull?) *
* with further experience in addition.. *
* select the level you need on your target *
* first one is the pre-historic form.. *
* The second one takes care of modifying the parameter in macro
call. *
* None of them resist to the (dirty) assumption that the defs are
functions and not macros.. *
* The third, yes, with only few code overhead (~ 700 bytes on
busybox binary..) *
* Of course, they are NOT internationalized! if your application
need to interface with foreign *
* users (customer devices), undef CTYPE_MACROS and good luck with
your compiler/linker/loader! *
* *
*******************************************************************************************************/
#ifndef _CTYPE_H
#define _CTYPE_H
# define CTYPE_MACROS 1
# define CTYPE_MACROS_SAFE 2
# define CTYPE_MACROS_INLINE 3
/* undef CTYPE_MACROS if you are happy with the native compiler
defs */
#ifndef CTYPE_DEFS
#define CTYPE_DEFS CTYPE_MACROS_INLINE
#endif
#if (CTYPE_DEFS == CTYPE_MACROS)
# define isalnum(c) (isalpha(c) || isdigit(c))
# define isalpha(c) {isupper(c) || islower(c))
# define isascii(c) (c > 0 && c <= 0x7f)
# define iscntrl(c) ((c >= 0) && ((c <= 0x1F) || (c == 0x7f)))
# define isdigit(c) (c >= '0' && c <= '9')
# define isgraph(c) (c != ' ' && isprint(c))
# define islower(c) (c >= 'a' && c <= 'z')
# define isprint(c) (c >= ' ' && c <= '~')
# define ispunct(c) ((c > ' ' && c <= '~') && !isalnum(c))
# define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c ==
'\r' ||\
c == '\t' || c == '\v')
# define isupper(c) (c >= 'A' && c <= 'Z')
# define isxdigit(c) (isxupper(c) || isxlower(c))
# define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f'))
# define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F'))
# define tolower(c) (isupper(c) ? ( c - 'A' + 'a') : (c))
# define toupper(c) (islower(c) ? (c - 'a' + 'A') : (c))
#elif (CTYPE_DEFS == CTYPE_MACROS_SAFE)
# define isalnum(c) ({ int __c = c; isalpha(__c) || isdigit(__c);
})
# define isalpha(c) ({ int __c = c; isupper(__c) || islower(__c);
})
# define isascii(c) ({ int __c = c; __c > 0 && __c <= 0x7f; })
# define iscntrl(c) ({ int __c = c; \
(__c >= 0) && ((__c <= 0x1F) || (__c ==
0x7f)); })
# define isdigit(c) ({ int __c = c; __c >= '0' && __c <= '9'; })
# define isgraph(c) ({ int __c = c; __c != ' ' && isprint(__c); })
# define islower(c) ({ int __c = c; __c >= 'a' && __c <= 'z'; })
# define isprint(c) ({ int __c = c; __c >= ' ' && __c <= '~'; })
# define ispunct(c) ({ int __c = c; \
(__c > ' ' && __c <= '~') && !isalnum(__c); })
# define isspace(c) ({ int __c = c; \
__c == ' ' || __c == '\f' || __c == '\n' ||
__c == '\r' || \
__c == '\t' || __c == '\v'; })
# define isupper(c) ({ int __c = c; __c >= 'A' && __c <= 'Z'; })
# define isxdigit(c) ({ int __c = c; isxupper(__c) || isxlower(__c);
})
# define isxlower(c) ({ int __c = c; \
isdigit(__c) || (__c >= 'a' && __c <= 'f'); })
# define isxupper(c) ({ int __c = c; \
isdigit(__c) || (__c >= 'A' && __c <= 'F'); })
# define toascii(c) (c & 0x7f)
# define tolower(c) ({ int __c = c; \
isupper(__c) ? ( __c - 'A' + 'a') : (__c); })
# define toupper(c) ({ int __c = c; \
islower(__c) ? (__c - 'a' + 'A') : (__c); })
#elif (CTYPE_DEFS == CTYPE_MACROS_INLINE)
static inline int isalnum(int c) { return isalpha(c) ||
isdigit(c); }
static inline int isalpha(int c) { return isupper(c) ||
islower(c); }
static inline int isascii(int c) { return c > 0 && c <= 0x7f; }
static inline int iscntrl(int c) { return (c >= 0) && ((c <=
0x1F) || (c == 0x7f)); }
static inline int isdigit(int c) { return c >= '0' && c <= '9'; }
static inline int isgraph(int c) { return c != ' ' && isprint(c);
}
static inline int islower(int c) { return c >= 'a' && c <= 'z';
}
static inline int isprint(int c) { return c >= ' ' && c <= '~'; }
static inline int ispunct(int c) { return (c > ' ' && c <= '~')
&& !isalnum(c); }
static inline int isspace(int c) { return c == ' ' || c == '\f'
|| c == '\n' || c == '\r' ||
c == '\t'
|| c == '\v' ; }
static inline int isupper(int c) { return c >= 'A' && c <= 'Z';
}
static inline int isxdigit(int c) { return isxupper(c) ||
isxlower(c); }
static inline int isxlower(int c) { return isdigit(c) || (c >= 'a'
&& c <= 'f'); }
static inline int isxupper(int c) { return isdigit(c) || (c >= 'A'
&& c <= 'F'); }
static inline int tolower(int c) { return isupper(c) ? ( c - 'A'
+ 'a') : (c); }
static inline int toupper(int c) { return islower(c) ? (c - 'a' +
'A') : (c); }
#else /* Put here the standards defs of your compiler.. */
/* ..... */
#endif
#endif /* ctype.h */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/busybox/attachments/20050228/7017a299/attachment-0001.htm
More information about the busybox
mailing list