home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / BENCH / CVTS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  1.9 KB  |  101 lines

  1. /* ==( bench/cvts.c )== */
  2.  
  3. /* ----------------------------------------------- */
  4. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  5. /* Modification to this source is not supported    */
  6. /* by Vestronix Inc.                               */
  7. /*            All Rights Reserved                  */
  8. /* ----------------------------------------------- */
  9. /* Written   Nig   1-Jan-87                        */
  10. /* Modified  Geo   4-Oct-89  See comments below    */
  11. /* ----------------------------------------------- */
  12. /* %W%  (%H% %T%) */
  13.  
  14. /*
  15.  *  Modifications
  16.  *
  17.  *   4-Nov-89  Geo - V2 version
  18.  *  25-Oct-89  Geo - 1.32 Merge
  19. */
  20.  
  21. # include <bench.h>
  22.  
  23. /* Function prototypes */
  24. # ifdef ANSI
  25. static void no_trailing(char *);
  26. static void no_leading(char *);
  27. # else
  28. static void no_trailing();
  29. static void no_leading();
  30. # endif
  31.  
  32. /*
  33.  *
  34.  * 1 - remove leading spaces
  35.  * 2 - remove trailing spaces
  36.  * 4 - convert to UPPER case
  37. */
  38. char *cvt_str(str, fmode)
  39. char *str;
  40. int fmode;
  41. {
  42.    register int i;
  43.  
  44.    for (i = 1; i < 16; i <<= 1)
  45.       switch(fmode & i)
  46.       {
  47.       case  1 : no_leading(str);  break;
  48.       case  2 : no_trailing(str); break;
  49.       case  4 : cvt_upper(str);   break;
  50.       }
  51.    return str;
  52. }
  53.  
  54. static void no_leading(str)
  55. char *str;
  56. {
  57.    int slen;
  58.    register int i;
  59.    register int j;
  60.  
  61.    for (i = 0, slen = strlen(str); i < slen && str[i] == ' '; i++)
  62.       ;
  63.    for (j = i, i = 0; j < slen; j++, i++)
  64.       str[i] = str[j];
  65.    str[i] = '\0';
  66. }
  67.  
  68. static void no_trailing(str)
  69. char *str;
  70. {
  71.    register int i;
  72.  
  73.    for (i = strlen(str) - 1; i > -1 && str[i] == ' '; i--)
  74.       ;
  75.    str[i+1] = '\0';
  76. }
  77.  
  78. char *cvt_upper(str)
  79. char *str;
  80. {
  81.    char *ptr = str;
  82.  
  83.    for ( ; *str; str++)
  84.         if (islower(*str))
  85.             *str = toupper(*str);
  86.  
  87.    return ptr;
  88. }
  89.  
  90. char *cvt_lower(str)
  91. char *str;
  92. {
  93.    char *ptr = str;
  94.  
  95.    for ( ; *str; str++)
  96.         if (isupper(*str))
  97.             *str = tolower(*str);
  98.  
  99.    return ptr;
  100. }
  101.