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 / STRD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  1.9 KB  |  112 lines

  1. /*
  2.  * strd.c
  3.  * contains: strd(),strdlf(),strdrt()
  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 strmove(),GF_CONV strd(),GF_CONV strdlf(),GF_CONV strdrt();
  13.  
  14. /*
  15.  *  int
  16.  * strd(str,start,num)
  17.  *
  18.  * ARGUMENT
  19.  *  (char *)    str    -    pointer to string to operate on
  20.  *  (int)    start    -    position to begin deletion
  21.  *  (int)    num    -    number of characters to delete
  22.  *
  23.  * DESCRIPTION
  24.  *  deletes characters from string, starting at str+start continuing for
  25.  *  num characters
  26.  *
  27.  * RETURNS
  28.  *  Actual number of characters deleted.
  29.  */
  30. int GF_CONV strd(str,start,num)
  31. char *str;
  32. int start,num;
  33. {
  34.     int del,slen,i,j,min1;
  35.     char *pt,*ps;
  36.  
  37.     ps=str;
  38.     slen=strlen(ps);
  39.     min1=xmin(slen,num);
  40.     del=xmax(0,min1);
  41.     if((del<=0)||(start>=slen))
  42.         return 0;
  43.     i=j=0;
  44.     while(*ps) {
  45.         if(i==start)
  46.             break;
  47.         ++ps;
  48.         ++i;
  49.     }
  50.     pt=ps;
  51.     while(*ps) {
  52.         if(j==del)
  53.             break;
  54.         ++ps;
  55.         ++j;
  56.     }
  57.     strmove(pt,ps);
  58.     return j;
  59. }
  60.  
  61. /*
  62.  *  int
  63.  * strdlf(str,num)
  64.  *
  65.  * ARGUMENT
  66.  *  (char *)    str    -    pointer to string to operate on
  67.  *  (int)    num    -    number of characters to delete
  68.  *
  69.  * DESCRIPTION
  70.  *  deletes characters from the left side of the string, continuing for
  71.  *  num characters
  72.  *
  73.  * RETURNS
  74.  *  Actual number of characters deleted.
  75.  */
  76. int GF_CONV strdlf(str,num)
  77. char *str;
  78. int num;
  79. {
  80.     return(strd(str,0,num));
  81. }
  82.  
  83. /*
  84.  *  int
  85.  * strdrt(str,num)
  86.  *
  87.  * ARGUMENT
  88.  *  (char *)    str    -    pointer to string to operate on
  89.  *  (int)    num    -    number of characters to delete
  90.  *
  91.  * DESCRIPTION
  92.  *  deletes characters from right side of string, continuing for
  93.  *  num characters
  94.  *
  95.  * RETURNS
  96.  *  Actual number of characters deleted.
  97.  */
  98. int GF_CONV strdrt(str,num)
  99. char *str;
  100. int num;
  101. {
  102.     int start,slen;
  103.  
  104.     slen=strlen(str);
  105.     start=slen-num;
  106.     if (start<=0) {
  107.         *str='\0';
  108.         return slen;
  109.     } else 
  110.         return strd(str,start,num);
  111. }
  112.