/* * $Source$ * $Author$ * $Header$ * * Copyright (C) 1987 by the Massachusetts Institute of Technology * For copying and distribution information, please see the file * . * * Miscellaneous string functions. */ #ifndef lint static char *rcsid_strs_c = "$Header$"; #endif #include #include #include #include #include /* * Random string functions which should be in the C library.. */ /* * Make a copy of a string. */ char *strsave(char *s) { int len; char *p; /* Kludge for sloppy string semantics */ if (!s) { p = malloc(1); *p = '\0'; return p; } len = strlen(s) + 1; p = malloc(len); if (p) memcpy(p, s, len); return p; } /* * Trim whitespace off both ends of a string. */ char *strtrim(char *save) { char *t, *s; s = save; while (isspace(*s)) s++; /* skip to end of string */ if (*s == '\0') { *save = '\0'; return save; } for (t = s; *t; t++) continue; while (t > s) { --t; if (!isspace(*t)) { t++; break; } } if (*t) *t = '\0'; return s; } /* Modify a string for all of the letters to be uppercase. */ char *uppercase(char *s) { char *p; for (p = s; *p; p++) { if (islower(*p)) *p = toupper(*p); } return s; } char *lowercase(char *s) { char *p; for (p = s; *p; p++) { if (isupper(*p)) *p = tolower(*p); } return s; }