home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xmu / Lower.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-05  |  3.2 KB  |  111 lines

  1. /* $XConsortium: Lower.c,v 1.6 91/01/05 17:38:12 converse Exp $ */
  2.  
  3. /* 
  4.  * Copyright 1988 by the Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided 
  8.  * that the above copyright notice appear in all copies and that both that 
  9.  * copyright notice and this permission notice appear in supporting 
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific, 
  12.  * written prior permission. M.I.T. makes no representations about the 
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  */
  17.  
  18. #define  XK_LATIN1
  19. #include <X11/keysymdef.h>
  20. #include <X11/Xmu/CharSet.h>
  21.  
  22. /*
  23.  * ISO Latin-1 case conversion routine
  24.  */
  25.  
  26. #if NeedFunctionPrototypes
  27. void XmuCopyISOLatin1Lowered(char *dst, _Xconst char *src)
  28. #else
  29. void XmuCopyISOLatin1Lowered(dst, src)
  30.     char *dst, *src;
  31. #endif
  32. {
  33.     register unsigned char *dest, *source;
  34.  
  35.     for (dest = (unsigned char *)dst, source = (unsigned char *)src;
  36.      *source;
  37.      source++, dest++)
  38.     {
  39.     if ((*source >= XK_A) && (*source <= XK_Z))
  40.         *dest = *source + (XK_a - XK_A);
  41.     else if ((*source >= XK_Agrave) && (*source <= XK_Odiaeresis))
  42.         *dest = *source + (XK_agrave - XK_Agrave);
  43.     else if ((*source >= XK_Ooblique) && (*source <= XK_Thorn))
  44.         *dest = *source + (XK_oslash - XK_Ooblique);
  45.     else
  46.         *dest = *source;
  47.     }
  48.     *dest = '\0';
  49. }
  50.  
  51. #if NeedFunctionPrototypes
  52. void XmuCopyISOLatin1Uppered(char *dst, _Xconst char *src)
  53. #else
  54. void XmuCopyISOLatin1Uppered(dst, src)
  55.     char *dst, *src;
  56. #endif
  57. {
  58.     register unsigned char *dest, *source;
  59.  
  60.     for (dest = (unsigned char *)dst, source = (unsigned char *)src;
  61.      *source;
  62.      source++, dest++)
  63.     {
  64.     if ((*source >= XK_a) && (*source <= XK_z))
  65.         *dest = *source - (XK_a - XK_A);
  66.     else if ((*source >= XK_agrave) && (*source <= XK_odiaeresis))
  67.         *dest = *source - (XK_agrave - XK_Agrave);
  68.     else if ((*source >= XK_slash) && (*source <= XK_thorn))
  69.         *dest = *source - (XK_oslash - XK_Ooblique);
  70.     else
  71.         *dest = *source;
  72.     }
  73.     *dest = '\0';
  74. }
  75.  
  76. #if NeedFunctionPrototypes
  77. int XmuCompareISOLatin1 (_Xconst char *first, _Xconst char *second)
  78. #else
  79. int XmuCompareISOLatin1 (first, second)
  80.     char *first, *second;
  81. #endif
  82. {
  83.     register unsigned char *ap, *bp;
  84.  
  85.     for (ap = (unsigned char *) first, bp = (unsigned char *) second;
  86.      *ap && *bp; ap++, bp++) {
  87.     register unsigned char a, b;
  88.  
  89.     if ((a = *ap) != (b = *bp)) {
  90.         /* try lowercasing and try again */
  91.  
  92.         if ((a >= XK_A) && (a <= XK_Z))
  93.           a += (XK_a - XK_A);
  94.         else if ((a >= XK_Agrave) && (a <= XK_Odiaeresis))
  95.           a += (XK_agrave - XK_Agrave);
  96.         else if ((a >= XK_Ooblique) && (a <= XK_Thorn))
  97.           a += (XK_oslash - XK_Ooblique);
  98.  
  99.         if ((b >= XK_A) && (b <= XK_Z))
  100.           b += (XK_a - XK_A);
  101.         else if ((b >= XK_Agrave) && (b <= XK_Odiaeresis))
  102.           b += (XK_agrave - XK_Agrave);
  103.         else if ((b >= XK_Ooblique) && (b <= XK_Thorn))
  104.           b += (XK_oslash - XK_Ooblique);
  105.  
  106.         if (a != b) return (((int) a) - ((int) b));
  107.     }
  108.     }
  109.     return (((int) *ap) - ((int) *bp));
  110. }
  111.