home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / mysql-c.zip / ansi.cpp next >
C/C++ Source or Header  |  1999-12-17  |  4KB  |  113 lines

  1. /***************************************************************************/
  2. /* F r e e C o d e                                                         */
  3. /*                                                                         */
  4. /* THIS CODE IS FREEWARE AND AS SUCH YOU ARE PERMITTED TO DO WHAT YOU WISH */
  5. /* WITH IT. THESE PROGRAMS ARE PROVIDED AS IS WITHOUT ANY WARRANTY,        */
  6. /* EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO FITNESS FOR ANY      */
  7. /* PARTICULAR PURPOSE.                                                     */
  8. /*                                                                         */
  9. /* However, we would appriciate if you shared any enhancements to us       */
  10. /* Please send them to www.jmast.se/free/ and we will include them in      */
  11. /* future distributions.                                                   */
  12. /*                                                                         */
  13. /***************************************************************************/
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <ctype.h>
  19. #include <direct.h>
  20.  
  21. void strreplace(char *szText, char sLookFor, char sReplaceWith);
  22. char *OemToAnsi(char *szOemText);
  23. char *AnsiToOem(char *szAnsiText);
  24.  
  25. /*-----------------------------------------------------------------------------
  26.    strreplace: Replaces all sLookFor with sReplaceWith.
  27. -----------------------------------------------------------------------------*/
  28. void strreplace(char *szText, char sLookFor, char sReplaceWith)
  29.      {
  30.      char       *pchFound;
  31.  
  32.      if (szText == NULL)
  33.         return;
  34.  
  35.      if (strlen(szText) == 0)
  36.         return;
  37.  
  38.      if (sLookFor == sReplaceWith)
  39.         return;
  40.  
  41.      /* Change all sLookFor to sReplaceWith ones */
  42.      pchFound = strrchr(szText, sLookFor);
  43.      while (pchFound != 0)
  44.            {
  45.            (*pchFound) = sReplaceWith;
  46.            pchFound = strrchr(szText, sLookFor);
  47.            }
  48.      }
  49.  
  50. /*-----------------------------------------------------------------------------
  51.    OemToAnsi: Converts from 850 to ANSI.
  52. -----------------------------------------------------------------------------*/
  53. char *OemToAnsi(char *szOemText)
  54.      {
  55.      static char       szAnsiText[1024] = "";
  56.  
  57.  
  58.      if (szOemText == NULL)
  59.         return (NULL);
  60.  
  61.      if (strlen(szOemText) == 0)
  62.         return (szOemText);
  63.  
  64.      memset(szAnsiText, 0, 1024);
  65.      strcpy(szAnsiText, szOemText);
  66.  
  67.      strreplace(szAnsiText, 'Å', '┼');
  68.      strreplace(szAnsiText, 'Ä', '─');
  69.      strreplace(szAnsiText, 'Ö', '╓');
  70.      strreplace(szAnsiText, 'å', 'σ');
  71.      strreplace(szAnsiText, 'ä', 'Σ');
  72.      strreplace(szAnsiText, 'ö', '÷');
  73.      strreplace(szAnsiText, 'Ü', '▄');
  74.      strreplace(szAnsiText, 'ü', 'ⁿ');
  75.      strreplace(szAnsiText, 'É', '╔');
  76.      strreplace(szAnsiText, 'é', 'Θ');
  77.  
  78.      return(szAnsiText);
  79.      }
  80.  
  81.  
  82. /*-----------------------------------------------------------------------------
  83.    AnsiToOem: Converts from ANSI to 850
  84. -----------------------------------------------------------------------------*/
  85. char *AnsiToOem(char *szAnsiText)
  86.      {
  87.      static char       szOemText[1024] = "";
  88.  
  89.  
  90.      if (szAnsiText == NULL)
  91.         return (NULL);
  92.  
  93.   
  94.      if (strlen(szAnsiText) == 0)
  95.         return (szAnsiText);
  96.  
  97.      memset(szOemText, 0, 1024);
  98.      strcpy(szOemText, szAnsiText);
  99.  
  100.      strreplace(szOemText, '┼', 'Å');
  101.      strreplace(szOemText, '─', 'Ä');
  102.      strreplace(szOemText, '╓', 'Ö');
  103.      strreplace(szOemText, 'σ', 'å');
  104.      strreplace(szOemText, 'Σ', 'ä');
  105.      strreplace(szOemText, '÷', 'ö');
  106.      strreplace(szOemText, '▄', 'Ü');
  107.      strreplace(szOemText, 'ⁿ', 'ü');
  108.      strreplace(szOemText, '╔', 'É');
  109.      strreplace(szOemText, 'Θ', 'é');
  110.  
  111.      return(szOemText);
  112.      }
  113.