home *** CD-ROM | disk | FTP | other *** search
- /*
- * strwr.c
- * contains: strwr(),strwrlf(),strwrrt(),strwb(),strwblf(),strwbrt()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include "gfuncts.h"
-
- int GF_CONV strwc(),GF_CONV strwr(),GF_CONV strwrlf(),GF_CONV strwrrt();
-
- /*
- * int
- * strwr(ps,repl,start,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string to operate on
- * (char) repl - character to substitute in string
- * (int) start - word position of first word to replace/blank
- * (int) num - number of words to replace with "repl"
- *
- * DESCRIPTION
- * string word replace, the specified number or less of words are replaced
- * by a series of one or more characters "repl". The string is not copied.
- * the actual number of words is the lesser of "num" or the actual
- * number of words found in the string. The actual number of characters
- * is limited by the length of the string.
- *
- * RETURNS
- * Number of characters replaced
- */
- int GF_CONV strwr(ps,repl,start,num)
- char *ps,repl;
- int start,num;
- {
- int words,curword,chs,inword,stop,replon,min1;
-
- min1=xmin(num,strwc(ps));
- words=xmax(0,min1);
- if(!words)
- return 0;
- stop=start+words-1;
- inword=chs=curword=replon=0;
- while (1) {
- if(!*ps)
- return chs;
- if (gisspace(*ps)) {
- if(inword)
- inword=0;
- if(curword==stop)
- return chs;
- else
- goto point1;
- }
- else if(!inword) {
- inword=1;
- ++curword;
- if(curword==start)
- replon=1;
- }
- point1:
- if (replon) {
- *ps=repl;
- ++chs;
- }
- ++ps;
- }
- }
-
- /*
- * int
- * strwrlf(ps,repl,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string to operate on
- * (char) repl - character to substitute in string
- * (int) num - number of words to replace with "repl"
- *
- * DESCRIPTION
- * replace leftmost "num" words in string, the specified number or less of
- * words are replaced by a series of one or more characters "repl". The
- * string is not copied.
- * The actual number of words is the lesser of "num" or the actual
- * number of words found in the string. The actual number of characters
- * is limited by the length of the string.
- *
- * RETURNS
- * Number of characters replaced
- */
- int GF_CONV strwrlf(ps,repl,num)
- char *ps,repl;
- int num;
- {
- return(strwr(ps,repl,1,num));
- }
-
- /*
- * int
- * strwrrt(ps,repl,num)
- *
- * ARGUMENT
- * (char *) ps - pointer to string to operate on
- * (char) repl - character to substitute in string
- * (int) num - number of words to replace with "repl"
- *
- * DESCRIPTION
- * replace rightmost "num" words in string, the specified number or less of
- * words are replaced by a series of one or more characters "repl". The
- * string is not copied.
- * The actual number of words is the lesser of "num" or the actual
- * number of words found in the string. The actual number of characters
- * is limited by the length of the string.
- *
- * RETURNS
- * Number of characters replaced
- */
- int GF_CONV strwrrt(ps,repl,num)
- char *ps,repl;
- int num;
- {
- int skipto,nwords;
-
- nwords=strwc(ps);
- skipto=nwords-num+1;
- return(strwr(ps,repl,skipto,num));
- }
-
- /*
- * int
- * strwb(str,start,num)
- *
- * ARGUMENT
- * (char *) str - pointer to string to operate on
- * (int) start - word position to start blanking
- * (int) num - number of words to replace with "repl"
- *
- * DESCRIPTION
- * replace "num" words in string starting at "start", the specified number
- * or less of words are replaced by a series of BLANKS.
- * The actual number of words is the lesser of "num" or the actual
- * number of words found in the string. The actual number of characters
- * is limited by the length of the string.
- *
- * RETURNS
- * Number of characters replaced
- */
- int GF_CONV strwb(str,start,num)
- char *str;
- int start,num;
- {
- return(strwr(str,' ',start,num));
- }
-
- /*
- * int
- * strwblf(str,num)
- *
- * ARGUMENT
- * (char *) str - pointer to string to operate on
- * (int) num - number of words to replace with "repl"
- *
- * DESCRIPTION
- * replace "num" words in string starting at the left position. The
- * specified number or less of words are replaced by a series of BLANKS.
- * The actual number of words is the lesser of "num" or the actual
- * number of words found in the string. The actual number of characters
- * is limited by the length of the string.
- *
- * RETURNS
- * Number of characters replaced
- */
- int GF_CONV strwblf(str,num)
- char *str;
- int num;
- {
- return strwrlf(str,' ',num);
- }
-
- /*
- * int
- * strwbrt(str,num)
- *
- * ARGUMENT
- * (char *) str - pointer to string to operate on
- * (int) num - number of words to replace with "repl"
- *
- * DESCRIPTION
- * replace "num" words in string starting at the right position. The
- * specified number or less of words are replaced by a series of BLANKS.
- * The actual number of words is the lesser of "num" or the actual
- * number of words found in the string. The actual number of characters
- * is limited by the length of the string.
- *
- * RETURNS
- * Number of characters replaced
- */
- int GF_CONV strwbrt(str,num)
- char *str;
- int num;
- {
- return(strwrrt(str,' ',num));
- }
-