]> andersk Git - moira.git/blame - lib/strs.c
use CODE=ANSI_C option to proc
[moira.git] / lib / strs.c
CommitLineData
68687902 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
babbc197 7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
68687902 9 *
10 * Miscellaneous string functions.
11 */
12
13#ifndef lint
14static char *rcsid_strs_c = "$Header$";
a43ce477 15#endif
68687902 16
babbc197 17#include <mit-copyright.h>
0fed7e9b 18#include <sys/types.h>
a43ce477 19#include <stdlib.h>
501a4b9d 20#include <string.h>
0fed7e9b 21#include <ctype.h>
22
68687902 23/*
24 * Random string functions which should be in the C library..
25 */
26
27/*
28 * Make a copy of a string.
29 */
5eaef520 30char *strsave(char *s)
68687902 31{
44d12d58 32 int len;
33 char *p;
5eaef520 34 /* Kludge for sloppy string semantics */
35 if (!s)
36 {
37 p = malloc(1);
38 *p = '\0';
39 return p;
0fed7e9b 40 }
5eaef520 41 len = strlen(s) + 1;
42 p = malloc(len);
43 if (p)
44 memcpy(p, s, len);
45 return p;
68687902 46}
5eaef520 47
68687902 48/*
49 * Trim whitespace off both ends of a string.
50 */
44d12d58 51char *strtrim(char *save)
68687902 52{
44d12d58 53 char *t, *s;
5eaef520 54
55 s = save;
56 while (isspace(*s))
57 s++;
58 /* skip to end of string */
59 if (*s == '\0')
60 {
61 *save = '\0';
62 return save;
9ca8ff13 63 }
68687902 64
5eaef520 65 for (t = s; *t; t++)
66 continue;
67 while (t > s)
68 {
69 --t;
70 if (!isspace(*t))
71 {
72 t++;
73 break;
68687902 74 }
75 }
5eaef520 76 if (*t)
77 *t = '\0';
78 return s;
68687902 79}
77f073b6 80
81
82/* Modify a string for all of the letters to be uppercase. */
83
5eaef520 84char *uppercase(char *s)
77f073b6 85{
44d12d58 86 char *p;
77f073b6 87
5eaef520 88 for (p = s; *p; p++)
89 {
77f073b6 90 if (islower(*p))
91 *p = toupper(*p);
5eaef520 92 }
93 return s;
77f073b6 94}
bc5b5d78 95
96
5eaef520 97char *lowercase(char *s)
bc5b5d78 98{
44d12d58 99 char *p;
bc5b5d78 100
5eaef520 101 for (p = s; *p; p++)
102 {
bc5b5d78 103 if (isupper(*p))
104 *p = tolower(*p);
501a4b9d 105 }
5eaef520 106 return s;
501a4b9d 107}
This page took 0.097376 seconds and 5 git commands to generate.