home *** CD-ROM | disk | FTP | other *** search
- /* (c) 1985, Phoenix Computer Products Corp. and Novum Organum, Inc. */
- /***
- * name : strinsc - insert a character into a string
- *
- * synopsis: char *strinsc ( str, chr )
- * char *str; string to work on
- * int chr; character to insert
- *
- * description: Inserts a character at the beginning of a string.
- *
- * returns: An echo of the input string address.
- *
- *
- * (C) novum organum, inc. 1985
- *
- ***/
- #include "cptpdf.h"
-
- char *strinsc (str,chr)
- char *str;
- int chr;
- {
- mempp ( str + 1, str, strlen(str) + 1); /* make room */
- *str = chr; /* insert character */
- return (str);
- }
-
-
- #ifdef use
-
- /***
- * name : strninsc - insert a char, truncate to maximum buffer length
- *
- * synopsis: char *strinsc ( str, chr, maxlen )
- * char *str; string to work on
- * int chr; character to insert
- * int maxlen; maximum output buffer length
- *
- * description: Inserts a character at the beginning of a string. If the new
- * length would exceed the buffer size (stralen()+1), the last
- * character is deleted before insertion.
- *
- * returns: An echo of the input string address.
- *
- *
- * (C) novum organum, inc. 1985
- *
- ***/
-
- char *strninsc ( str, chr, maxlen )
- char *str;
- int chr, maxlen;
- {
- char *strinsc();
-
- maxlen -= 2; /* maximum offset to EOS */
-
- if (maxlen >= 0) /* if STR will hold even 1 char */
- {
- if (strlen(str) > maxlen)/* if STR is too long */
- *(str+maxlen) = EOS; /* truncate it */
- strinsc (str, chr); /* insert the character */
- }
- return ( str );
- }
-
-
- /***
- * name : strins - insert a string
- *
- * synopsis: char *strinsc ( str, insert_str )
- * char *str; string to work on
- * char *insert_str; string to insert
- *
- * description: Inserts a sub-string at the beginning of a string.
- *
- * returns: An echo of the original string address (STR).
- *
- *
- * (C) novum organum, inc. 1985
- *
- ***/
-
- char *strins (str, insert_str)
- char *str, *insert_str;
- {
- int inslen;
-
- inslen = stralen (insert_str); /* length of insert string */
-
- if (inslen > 0)
- {
- mempp(str+inslen,str,(stralen(str)+1));/* move original */
- /* moved an extra byte to make sure 3rd arg non-zero */
- mempp(str, insert_str, inslen); /* move the insert */
- }
- return (str);
- }
-
- /***
- * name : strnins - insert a string, truncate to maximum buffer length
- *
- * synopsis: char *strinsc ( str, insert_str, maxlen )
- * char *str; string to work on
- * char *insert_str; string to insert
- * int maxlen; maximum output buffer length
- *
- * description: Inserts a sub-string at the beginning of a string. If the
- * new length would exceed the buffer size (stralen()+1), the
- * string is truncated before insertion.
- *
- * returns: An echo of the original string address (STR).
- *
- *
- * (C) novum organum, inc. 1985
- *
- ***/
-
- char *strnins (str, insert_str, maxlen)
- char *str, *insert_str;
- int maxlen;
- {
- int inslen, curlen;
-
- maxlen--; /* exclude final end of string */
- inslen = stralen (insert_str); /* length of insert string */
-
- if (maxlen <= 0 || inslen <= 0) /* nothing to be done */
- goto end;
-
- if (inslen >= maxlen) /* only the insert fits */
- inslen = maxlen; /* limit size of insert */
- else /* some of the original STR fits */
- {
- curlen = stralen (str); /* size of original */
-
- if ( inslen+curlen > maxlen )/* if not room for both */
- curlen = maxlen-inslen; /* limit size of original */
- else /* there is room for both */
- maxlen = inslen+curlen; /* mark where EOS goes */
- mempp(str+inslen,str,(curlen+1));/* move original */
- /* moved an extra byte to make sure 3rd arg non-zero */
- }
- mempp(str, insert_str, inslen); /* move the insert */
- *(str+maxlen) = EOS; /* put in final end of string */
- end:
- return (str);
- }
-
- #endif
-