home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / bitstrip.c < prev    next >
C/C++ Source or Header  |  1993-10-14  |  2KB  |  80 lines

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: bitstrip.c
  5.  * Author....: Andy M Leighton
  6.  * BBS.......: The Dark Knight Returns
  7.  * Net/Node..: 050/069
  8.  * User Name.: Andy Leighton
  9.  * Date......: 23/05/93
  10.  * Revision..: 1.00
  11.  *
  12.  * This is an original work by Andy Leighton and is placed in the
  13.  * public domain.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. /*
  23.  *  $DOC$
  24.  *  $FUNCNAME$
  25.  *      GT_BITSTRIP()
  26.  *  $CATEGORY$
  27.  *      String
  28.  *  $ONELINER$
  29.  *      Clear the high bit for every character in a string
  30.  *  $SYNTAX$
  31.  *      GT_BitStrip(<cStr>) --> cOut
  32.  *  $ARGUMENTS$
  33.  *      <cStr>  - The string to strip
  34.  *  $RETURNS$
  35.  *      <cOut>  - The stripped string
  36.  *  $DESCRIPTION$
  37.  *      Return the supplied string with all high bits turned off.
  38.  *      Useful for clearing the high bits ready for transfer to a
  39.  *      system that only understands true ASCII and not IBM's
  40.  *      bastardized version.
  41.  *
  42.  *      NOTE:
  43.  *         invalid parameters will return ""
  44.  *  $EXAMPLES$
  45.  *
  46.  *      local cStr := ""
  47.  *      local i
  48.  *
  49.  *      for i := asc("A") to asc("Z")
  50.  *         cStr := cStr + chr(i + 128)
  51.  *      next
  52.  *
  53.  *      ? GT_BitStrip(cStr)         // prints ABCDEFGHIJKLMNOPQRSTUVWXYZ
  54.  *  $END$
  55.  */
  56.  
  57. #include "extend.h"
  58.  
  59. CLIPPER
  60. gt_bitstri()
  61. {
  62.   char *s1, *s2;
  63.   int len, i;
  64.  
  65.   if (ISCHAR(1)) {
  66.     s1  = _parc(1);
  67.     len = _parclen(1);
  68.  
  69.     s2  = _xgrab(len);              // grab us some mem to work with
  70.  
  71.     for (i = 0; i <= len; i++)
  72.       s2[i] = s1[i] & 0x7f;         // strip off high bit
  73.  
  74.     _retc(s2);
  75.     _xfree(s2);                     // free alloc'ed mem
  76.   } else {
  77.     _retc((char *) NULL);           // parameter mismatch - error NullStr
  78.   }
  79. }
  80.