1a966c04fSmrg/*
2a966c04fSmrg * Copyright (C) 1989-95 GROUPE BULL
3a966c04fSmrg *
4a966c04fSmrg * Permission is hereby granted, free of charge, to any person obtaining a copy
5a966c04fSmrg * of this software and associated documentation files (the "Software"), to
6a966c04fSmrg * deal in the Software without restriction, including without limitation the
7a966c04fSmrg * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8a966c04fSmrg * sell copies of the Software, and to permit persons to whom the Software is
9a966c04fSmrg * furnished to do so, subject to the following conditions:
10a966c04fSmrg *
11a966c04fSmrg * The above copyright notice and this permission notice shall be included in
12a966c04fSmrg * all copies or substantial portions of the Software.
13a966c04fSmrg *
14a966c04fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15a966c04fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16a966c04fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17a966c04fSmrg * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18a966c04fSmrg * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19a966c04fSmrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20a966c04fSmrg *
21a966c04fSmrg * Except as contained in this notice, the name of GROUPE BULL shall not be
22a966c04fSmrg * used in advertising or otherwise to promote the sale, use or other dealings
23a966c04fSmrg * in this Software without prior written authorization from GROUPE BULL.
24a966c04fSmrg */
25a966c04fSmrg
26a966c04fSmrg/*****************************************************************************\
27a966c04fSmrg* misc.c:                                                                     *
28a966c04fSmrg*                                                                             *
29a966c04fSmrg*  XPM library                                                                *
30a966c04fSmrg*  Miscellaneous utilities                                                    *
31a966c04fSmrg*                                                                             *
32a966c04fSmrg*  Developed by Arnaud Le Hors                                                *
33a966c04fSmrg\*****************************************************************************/
34a966c04fSmrg
35a966c04fSmrg#ifdef HAVE_CONFIG_H
36a966c04fSmrg#include <config.h>
37a966c04fSmrg#endif
38a966c04fSmrg#include "XpmI.h"
39a966c04fSmrg
40a966c04fSmrg#ifdef NEED_STRDUP
41a966c04fSmrg/*
42a966c04fSmrg * in case strdup is not provided by the system here is one
43a966c04fSmrg * which does the trick
44a966c04fSmrg */
45a966c04fSmrgchar *
462e2dd055Smrgxpmstrdup(char *s1)
47a966c04fSmrg{
48a966c04fSmrg    char *s2;
49a966c04fSmrg    size_t l = strlen(s1) + 1;
50a966c04fSmrg
51a966c04fSmrg    if (s2 = (char *) XpmMalloc(l))
52a966c04fSmrg	strcpy(s2, s1);
53a966c04fSmrg    return s2;
54a966c04fSmrg}
55a966c04fSmrg
56a966c04fSmrg#endif
57a966c04fSmrg
58a966c04fSmrgunsigned int
592e2dd055Smrgxpmatoui(
602e2dd055Smrg    register char	*p,
612e2dd055Smrg    unsigned int	 l,
622e2dd055Smrg    unsigned int	*ui_return)
63a966c04fSmrg{
64a966c04fSmrg    register unsigned int n, i;
65a966c04fSmrg
66a966c04fSmrg    n = 0;
67a966c04fSmrg    for (i = 0; i < l; i++)
68a966c04fSmrg	if (*p >= '0' && *p <= '9')
69a966c04fSmrg	    n = n * 10 + *p++ - '0';
70a966c04fSmrg	else
71a966c04fSmrg	    break;
72a966c04fSmrg
73a966c04fSmrg    if (i != 0 && i == l) {
74a966c04fSmrg	*ui_return = n;
75a966c04fSmrg	return 1;
76a966c04fSmrg    } else
77a966c04fSmrg	return 0;
78a966c04fSmrg}
79a966c04fSmrg
80a966c04fSmrg/*
81a966c04fSmrg * Function returning a character string related to an error code.
82a966c04fSmrg */
83a966c04fSmrgchar *
842e2dd055SmrgXpmGetErrorString(int errcode)
85a966c04fSmrg{
86a966c04fSmrg    switch (errcode) {
87a966c04fSmrg    case XpmColorError:
88a966c04fSmrg	return ("XpmColorError");
89a966c04fSmrg    case XpmSuccess:
90a966c04fSmrg	return ("XpmSuccess");
91a966c04fSmrg    case XpmOpenFailed:
92a966c04fSmrg	return ("XpmOpenFailed");
93a966c04fSmrg    case XpmFileInvalid:
94a966c04fSmrg	return ("XpmFileInvalid");
95a966c04fSmrg    case XpmNoMemory:
96a966c04fSmrg	return ("XpmNoMemory");
97a966c04fSmrg    case XpmColorFailed:
98a966c04fSmrg	return ("XpmColorFailed");
99a966c04fSmrg    default:
100a966c04fSmrg	return ("Invalid XpmError");
101a966c04fSmrg    }
102a966c04fSmrg}
103a966c04fSmrg
104a966c04fSmrg/*
105a966c04fSmrg * The following function provides a way to figure out if the linked library is
106a966c04fSmrg * newer or older than the one with which a program has been first compiled.
107a966c04fSmrg */
108a966c04fSmrgint
1092e2dd055SmrgXpmLibraryVersion(void)
110a966c04fSmrg{
111a966c04fSmrg    return XpmIncludeVersion;
112a966c04fSmrg}
113a966c04fSmrg
114a966c04fSmrg
115a966c04fSmrg/* The following should help people wanting to use their own functions */
116a966c04fSmrg#ifdef XpmFree
117a966c04fSmrg#undef XpmFree
118a966c04fSmrg#endif
119a966c04fSmrg
120a966c04fSmrgvoid
1212e2dd055SmrgXpmFree(void *ptr)
122a966c04fSmrg{
123a966c04fSmrg    free(ptr);
124a966c04fSmrg}
125