home *** CD-ROM | disk | FTP | other *** search
- /*
- * strd.c
- * contains: strd(),strdlf(),strdrt()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include "gfuncts.h"
-
- int GF_CONV strmove(),GF_CONV strd(),GF_CONV strdlf(),GF_CONV strdrt();
-
- /*
- * int
- * strd(str,start,num)
- *
- * ARGUMENT
- * (char *) str - pointer to string to operate on
- * (int) start - position to begin deletion
- * (int) num - number of characters to delete
- *
- * DESCRIPTION
- * deletes characters from string, starting at str+start continuing for
- * num characters
- *
- * RETURNS
- * Actual number of characters deleted.
- */
- int GF_CONV strd(str,start,num)
- char *str;
- int start,num;
- {
- int del,slen,i,j,min1;
- char *pt,*ps;
-
- ps=str;
- slen=strlen(ps);
- min1=xmin(slen,num);
- del=xmax(0,min1);
- if((del<=0)||(start>=slen))
- return 0;
- i=j=0;
- while(*ps) {
- if(i==start)
- break;
- ++ps;
- ++i;
- }
- pt=ps;
- while(*ps) {
- if(j==del)
- break;
- ++ps;
- ++j;
- }
- strmove(pt,ps);
- return j;
- }
-
- /*
- * int
- * strdlf(str,num)
- *
- * ARGUMENT
- * (char *) str - pointer to string to operate on
- * (int) num - number of characters to delete
- *
- * DESCRIPTION
- * deletes characters from the left side of the string, continuing for
- * num characters
- *
- * RETURNS
- * Actual number of characters deleted.
- */
- int GF_CONV strdlf(str,num)
- char *str;
- int num;
- {
- return(strd(str,0,num));
- }
-
- /*
- * int
- * strdrt(str,num)
- *
- * ARGUMENT
- * (char *) str - pointer to string to operate on
- * (int) num - number of characters to delete
- *
- * DESCRIPTION
- * deletes characters from right side of string, continuing for
- * num characters
- *
- * RETURNS
- * Actual number of characters deleted.
- */
- int GF_CONV strdrt(str,num)
- char *str;
- int num;
- {
- int start,slen;
-
- slen=strlen(str);
- start=slen-num;
- if (start<=0) {
- *str='\0';
- return slen;
- } else
- return strd(str,start,num);
- }
-