home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / STRX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  2.4 KB  |  112 lines

  1. /*
  2.  * strx.c
  3.  * contains: strx(),strxlf(),strxrt()
  4.  *
  5.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include "gfuncts.h"
  11.  
  12. int GF_CONV strx(),GF_CONV strxlf(),GF_CONV strxrt();
  13.  
  14. /*
  15.  *  int
  16.  * strx(pd,ps,start,num)
  17.  *
  18.  * ARGUMENT
  19.  *  (char *)    pd    -    destination string pointer
  20.  *  (char *)    ps    -    source string pointer
  21.  *  (int)    start    -    position to start (0 is leftmost)
  22.  *  (int)    num    -    number of characters to extract and copy
  23.  *
  24.  * DESCRIPTION
  25.  *  Extract characters from string.  Characters are extracted from "source"
  26.  *  and copied to "destination".  The number of characters to copy is "num".
  27.  *  The first position (from left to right) to extract is "start".
  28.  *  The actual number of characters moved is the lesser of "num" and
  29.  *  the source string.  No check is made to assure that the destination
  30.  *  is large enough to hold the characters copied.
  31.  *
  32.  * RETURNS
  33.  *  Actual number of characters copied.
  34.  */
  35. int GF_CONV strx(pd,ps,start,num)
  36. char *pd,*ps;
  37. int start,num;
  38. {
  39.     int i,j;
  40.     j=i=0;
  41.     while (*ps) {
  42.         if(i==start) 
  43.             break;
  44.         ++i;
  45.         ++ps;
  46.     }
  47.     if(i<start) 
  48.         return 0;
  49.     while (*ps) {
  50.         *pd++ = *ps++;
  51.         ++j;
  52.         if(j==num) 
  53.             break;
  54.     }
  55.     *pd='\0';
  56.     return j;
  57. }
  58.  
  59. /*
  60.  *  int
  61.  * strxlf(pd,ps,num)
  62.  *
  63.  * ARGUMENT
  64.  *  (char *)    pd    -    destination string pointer
  65.  *  (char *)    ps    -    source string pointer
  66.  *  (int)    num    -    number of characters to extract and copy
  67.  *
  68.  * DESCRIPTION
  69.  *  Extract characters from left side of string.  Characters are extracted
  70.  *  from "source" and copied to "destination".  The number of characters to
  71.  *  copy is "num".
  72.  *
  73.  * RETURNS
  74.  *  Actual number of characters copied.
  75.  */
  76. int GF_CONV strxlf(pd,ps,num)
  77. char *pd,*ps;
  78. int num;
  79. {
  80.     return(strx(pd,ps,0,num));
  81. }
  82.  
  83. /*
  84.  *  int
  85.  * strxrt(pd,ps,num)
  86.  *
  87.  * ARGUMENT
  88.  *  (char *)    pd    -    destination string pointer
  89.  *  (char *)    ps    -    source string pointer
  90.  *  (int)    num    -    number of characters to extract and copy
  91.  *
  92.  * DESCRIPTION
  93.  *  Extract characters from right side of string.  Characters are extracted
  94.  *  from "source" and copied to "destination".  The number of characters to
  95.  *  copy is "num".
  96.  *
  97.  * RETURNS
  98.  *  Actual number of characters copied.
  99.  */
  100. int GF_CONV strxrt(pd,ps,num)
  101. char *pd,*ps;
  102. int num;
  103. {
  104.     int slen,start,cpy,min1;
  105.  
  106.     slen=strlen(ps);
  107.     min1=xmin(num,slen);
  108.     cpy=xmax(0,min1);
  109.     start=slen - cpy;
  110.     return(strx(pd,ps,start,num));
  111. }
  112.