home *** CD-ROM | disk | FTP | other *** search
- /*
- * strx.c
- * contains: strx(),strxlf(),strxrt()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include "gfuncts.h"
-
- int GF_CONV strx(),GF_CONV strxlf(),GF_CONV strxrt();
-
- /*
- * int
- * strx(pd,ps,start,num)
- *
- * ARGUMENT
- * (char *) pd - destination string pointer
- * (char *) ps - source string pointer
- * (int) start - position to start (0 is leftmost)
- * (int) num - number of characters to extract and copy
- *
- * DESCRIPTION
- * Extract characters from string. Characters are extracted from "source"
- * and copied to "destination". The number of characters to copy is "num".
- * The first position (from left to right) to extract is "start".
- * The actual number of characters moved is the lesser of "num" and
- * the source string. No check is made to assure that the destination
- * is large enough to hold the characters copied.
- *
- * RETURNS
- * Actual number of characters copied.
- */
- int GF_CONV strx(pd,ps,start,num)
- char *pd,*ps;
- int start,num;
- {
- int i,j;
- j=i=0;
- while (*ps) {
- if(i==start)
- break;
- ++i;
- ++ps;
- }
- if(i<start)
- return 0;
- while (*ps) {
- *pd++ = *ps++;
- ++j;
- if(j==num)
- break;
- }
- *pd='\0';
- return j;
- }
-
- /*
- * int
- * strxlf(pd,ps,num)
- *
- * ARGUMENT
- * (char *) pd - destination string pointer
- * (char *) ps - source string pointer
- * (int) num - number of characters to extract and copy
- *
- * DESCRIPTION
- * Extract characters from left side of string. Characters are extracted
- * from "source" and copied to "destination". The number of characters to
- * copy is "num".
- *
- * RETURNS
- * Actual number of characters copied.
- */
- int GF_CONV strxlf(pd,ps,num)
- char *pd,*ps;
- int num;
- {
- return(strx(pd,ps,0,num));
- }
-
- /*
- * int
- * strxrt(pd,ps,num)
- *
- * ARGUMENT
- * (char *) pd - destination string pointer
- * (char *) ps - source string pointer
- * (int) num - number of characters to extract and copy
- *
- * DESCRIPTION
- * Extract characters from right side of string. Characters are extracted
- * from "source" and copied to "destination". The number of characters to
- * copy is "num".
- *
- * RETURNS
- * Actual number of characters copied.
- */
- int GF_CONV strxrt(pd,ps,num)
- char *pd,*ps;
- int num;
- {
- int slen,start,cpy,min1;
-
- slen=strlen(ps);
- min1=xmin(num,slen);
- cpy=xmax(0,min1);
- start=slen - cpy;
- return(strx(pd,ps,start,num));
- }
-