home *** CD-ROM | disk | FTP | other *** search
- /*
- * strr.c
- * contains: strr(),strrlf(),strrt()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include "gfuncts.h"
-
-
- /*
- * int
- * strr(ps,repl,start,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string to be operated on
- * (char) repl - character to substitute in string
- * (int) start - position at which to start (0==leftmost)
- * (int) num - number of characters to replace
- *
- * DESCRIPTION
- * Replace characters in string starting at position indicated by
- * start.
- *
- * RETURNS
- * Actual number of characters replaced.
- */
- int GF_CONV strr(ps,repl,start,num)
- char *ps,repl;
- int start,num;
- {
- int i,j;
- j=i=0;
- while(*ps) {
- if(i==start)
- break;
- ++i;
- ++ps;
- }
- if(i<start)
- return 0; /* if start is past end of string */
- while (*ps) {
- *ps = repl;
- ++j;
- if(j==num)
- break;
- ++ps;
- }
- return j;
- }
-
- /*
- * int
- * strrlf(ps,repl,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string to be operated on
- * (char) repl - character to substitute in string
- * (int) num - number of characters to replace
- *
- * DESCRIPTION
- * Replace characters in string starting at left most position.
- *
- * RETURNS
- * Actual number of characters replaced.
- */
- int GF_CONV strrlf(ps,repl,num)
- char *ps,repl;
- int num;
- {
- int iret,quan,min1;
-
- min1=xmin(num,strlen(ps));
- quan=xmax(0,min1);
- iret=quan;
- while(quan--)
- *ps++=repl;
- return iret;
- }
-
- /*
- * int
- * strrrt(ps,repl,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string to be operated on
- * (char) repl - character to substitute in string
- * (int) num - number of characters to replace
- *
- * DESCRIPTION
- * Replace characters in string starting at right most position.
- *
- * RETURNS
- * Actual number of characters replaced.
- */
- int GF_CONV strrrt(ps,repl,num)
- char *ps,repl;
- int num;
- {
- int iret,quan,min1;
-
- min1=xmin(num,strlen(ps));
- quan=xmax(0,min1);
- iret = quan;
- while(*ps++)
- ;
- --ps;
- while(quan--)
- *--ps=repl;
- return iret;
- }
-