#include <stdinc.h>#include <strlib.h>char *getmem(nbytes) string scopy(source)string sconc(s1,s2) string substr(s, p1, p2) int findstr(text, pat) int nbytes, p1, p2; string filename, ext, mode, path, source, s1, s2, text, pat DescriptionThe strlib package contains the implementations for several routines that use dynamically-allocated string storage. Since these routines tend to fill up memory, this package is not suitable for use in applications which will run for extended periods or which require tight memory control. Nonetheless, this package does provide an easy-to-use interface which is applicable to a wide range of programs. getmem() is exactly like malloc(3) except that (1) it checks for no memory errors, and (2) it is defined to take an integer rather than an unsigned to keep lint(1) happier. If no memory could be allocated, error(3NEMO) is called. scopy() copies the string source into dynamically-allocated storage. sconc concatenates two strings s1 and s2 and returns the result in dynamically-allocated storage. substr() returns the substring of s extending from the integer indices p1 and p2 (inclusive). The following edge cases apply: if p1 < 0 then p1 <- 0; if p2 > strlen(s) then p2 <- strlen(s); if p1 > p2 then return "";
findstr searches for the string pat in text and returns the first index at which it appears, or -1 if no match is found. This function executes a simple compare and advance algorithm (see e.g. K&R1 p.67), and is inappropriate if text contains a very long string.
~/src/kernel/cores filefn.c
4-dec-86 Last modified Roberts 6-dec-86 Updated for Nemo Josh 7-oct-90 Manual page written Peter