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