Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2. FUNCTION
  3.         <<toupper>>---translate characters to uppercase
  4.  
  5. INDEX
  6.         toupper
  7. INDEX
  8.         _toupper
  9.  
  10. ANSI_SYNOPSIS
  11.         #include <ctype.h>
  12.         int toupper(int <[c]>);
  13.         int _toupper(int <[c]>);
  14.  
  15. TRAD_SYNOPSIS
  16.         #include <ctype.h>
  17.         int toupper(<[c]>);
  18.         int _toupper(<[c]>);
  19.  
  20.  
  21. DESCRIPTION
  22. <<toupper>> is a macro which converts lowercase characters to uppercase,
  23. leaving all other characters unchanged.  It is only defined when
  24. <[c]> is an integer in the range <<EOF>> to <<255>>.
  25.  
  26. You can use a compiled subroutine instead of the macro definition by
  27. undefining this macro using `<<#undef toupper>>'.
  28.  
  29. <<_toupper>> performs the same conversion as <<toupper>>, but should
  30. only be used when <[c]> is known to be a lowercase character (<<a>>--<<z>>).
  31.  
  32. RETURNS
  33. <<toupper>> returns the uppercase equivalent of <[c]> when it is a
  34. character between <<a>> and <<z>>, and <[c]> otherwise.
  35.  
  36. <<_toupper>> returns the uppercase equivalent of <[c]> when it is a
  37. character between <<a>> and <<z>>.  If <[c]> is not one of these
  38. characters, the behaviour of <<_toupper>> is undefined.
  39.  
  40. PORTABILITY
  41. <<toupper>> is ANSI C.  <<_toupper>> is not recommended for portable programs.
  42.  
  43. No supporting OS subroutines are required.
  44. */
  45.  
  46. #include <_ansi.h>
  47. #include <ctype.h>
  48. #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
  49. #include <limits.h>
  50. #include <stdio.h>
  51. #include <stdlib.h>
  52. #include <wctype.h>
  53. #include <wchar.h>
  54. #endif
  55.  
  56. #undef toupper
  57. int
  58. _DEFUN(toupper,(c),int c)
  59. {
  60. #if defined (_MB_EXTENDED_CHARSETS_ISO) || defined (_MB_EXTENDED_CHARSETS_WINDOWS)
  61.   if ((unsigned char) c <= 0x7f)
  62.     return islower (c) ? c - 'a' + 'A' : c;
  63.   else if (c != EOF && MB_CUR_MAX == 1 && islower (c))
  64.     {
  65.       char s[MB_LEN_MAX] = { c, '\0' };
  66.       wchar_t wc;
  67.       if (mbtowc (&wc, s, 1) >= 0
  68.           && wctomb (s, (wchar_t) towupper ((wint_t) wc)) == 1)
  69.         c = (unsigned char) s[0];
  70.     }
  71.   return c;
  72. #else
  73.   return islower (c) ? c - 'a' + 'A' : c;
  74. #endif
  75. }
  76.