home *** CD-ROM | disk | FTP | other *** search
- /*
- * strwi.c
- * contains: strwi(),strwilf(),strwirt()
- *
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include "gfuncts.h"
-
- int GF_CONV strwc(),GF_CONV strwi(),GF_CONV strwilf(),GF_CONV strwirt();
-
- /*
- * int
- * strwi(ps,pi,pos)
- *
- * ARGUMENT
- * (char *) ps - points to string to operate on
- * (char *) pi - string to insert
- * (int) pos - word position at which to insert
- *
- * DESCRIPTION
- * General word insert, the string pi is inserted into the indicated string
- * ps. pi is assummed to be one or more words but can be any string.
- * The insertion begins at the word position "pos". Hence if pos=1 the
- * existing string is pushed to the right in its entirety.
- *
- * RETURNS
- * Number of characters inserted. 0 if no insertion.
- */
- int GF_CONV strwi(ps,pi,pos)
- char *ps,*pi;
- int pos;
- {
- int words,curword,inword,inslen;
- char *pt;
-
- words=strwc(ps);
- inslen= strlen(pi);
- if (!inslen||!words||pos==0||pos>(words+1))
- return 0;
- inword=curword=0;
- if(pos==(words+1)) {
- pt=ps;
- strcat(ps," ");
- strcat(pt,pi);
- return inslen;
- } else while (1) {
- if(!*ps)
- return 0;
- if(!gisspace(*ps)) {
- if(!inword) {
- inword=1;
- ++curword;
- if(curword!=pos)
- goto point1;
- else {
- pt=ps;
- pt+=inslen;
- pt++;
- strmove(pt,ps);
- while(*pi)
- *ps++=*pi++;
- *ps=' ';
- return inslen;
- }
- }
- } else if(inword)
- inword=0;
- point1:
- ++ps;
- }
- }
-
- /*
- * int
- * strwilf(ps,pi)
- *
- * ARGUMENT
- * (char *) ps - points to string to operate on
- * (char *) pi - string to insert
- *
- * DESCRIPTION
- * String Word insert left, the string pi is inserted into the indicated
- * string starting at the left side. ps. pi is assummed to be one or more
- * words but can be any string.
- *
- * RETURNS
- * Number of characters inserted. 0 if no insertion.
- */
- int GF_CONV strwilf(ps,ins)
- char *ps,*ins;
- {
- return strwi(ps,ins,1);
- }
-
- /* String Word Insert Right
- */
- /*
- * int
- * strwirt(ps,pi)
- *
- * ARGUMENT
- * (char *) ps - points to string to operate on
- * (char *) pi - string to insert
- *
- * DESCRIPTION
- * String Word insert right, the string pi is inserted into the indicated
- * string starting at the right side. ps. pi is assummed to be one or more
- * words but can be any string.
- *
- * RETURNS
- * Number of characters inserted. 0 if no insertion.
- */
- int GF_CONV strwirt(ps,ins)
- char *ps,*ins;
- {
- int words;
-
- words=strwc(ps);
- return strwi(ps,ins,(words+1));
- }
-