home *** CD-ROM | disk | FTP | other *** search
- /*
- * stri.c
- * contains: stri(),strilf(),strirt()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include "gfuncts.h"
-
- /*
- * int
- * stri(ps,cins,start,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string
- * (char) cins - character to insert
- * (int) start - position to begin insertion
- * (int) num - number of times to insert character
- *
- * DESCRIPTION
- * The indicated character is inserted into the source string num times.
- * Beginning at the position indicated by start.
- *
- * SIDE EFFECTS
- * string is modified
- *
- * RETURNS
- * number of characters inserted
- */
- int GF_CONV stri(ps,cins,start,num)
- char *ps,cins;
- int start,num;
- {
- int i,k,len,GF_CONV strmove();
- char *pt;
-
- len=strlen(ps);
- if(!num||start>len)
- return 0;
- i=k=0;
- while(1) {
- if(!*ps)
- return k;
- if(i<start) {
- ++i;
- ++ps;
- } else {
- pt=ps;
- ps+=num;
- if(start<len)
- strmove(ps,pt);
- while(k<num) {
- pt[k]=cins;
- ++k;
- }
- if(start==len)
- pt[k+1]='\0';
- return k;
- }
- }
- }
-
- /*
- * int
- * strilf(ps,cins,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string
- * (char) cins - character to insert
- * (int) num - number of times to insert character
- *
- * DESCRIPTION
- * The indicated character is inserted into the source string num times.
- * Beginning at the left.
- *
- * SIDE EFFECTS
- * string is modified
- *
- * RETURNS
- * number of characters inserted
- */
- int GF_CONV strilf(str,c,num)
- char *str,c;
- int num;
- {
- return(stri(str,c,0,num));
- }
-
- /*
- * int
- * strirt(ps,cins,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string
- * (char) cins - character to insert
- * (int) num - number of times to insert character
- *
- * DESCRIPTION
- * The indicated character is inserted into the source string num times.
- * Beginning at the right.
- *
- * SIDE EFFECTS
- * string is modified
- *
- * RETURNS
- * number of characters inserted
- */
- int GF_CONV strirt(str,c,num)
- char *str,c;
- int num;
- {
- int i;
-
- while (*str++)
- ;
- --str;
- for (i=1;i<=num;i++)
- *str++=c;
- *str='\0';
- return i;
- }
-