Back to index

plt-scheme  4.2.1
misc.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1989-95 GROUPE BULL
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to
00006  * deal in the Software without restriction, including without limitation the
00007  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00008  * sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017  * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00018  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00019  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00020  *
00021  * Except as contained in this notice, the name of GROUPE BULL shall not be
00022  * used in advertising or otherwise to promote the sale, use or other dealings
00023  * in this Software without prior written authorization from GROUPE BULL.
00024  */
00025 
00026 /*****************************************************************************\
00027 * misc.c:                                                                     *
00028 *                                                                             *
00029 *  XPM library                                                                *
00030 *  Miscellaneous utilities                                                    *
00031 *                                                                             *
00032 *  Developed by Arnaud Le Hors                                                *
00033 \*****************************************************************************/
00034 
00035 #include "xpmP.h"
00036 
00037 #ifdef NEED_STRDUP
00038 /*
00039  * in case strdup is not provided by the system here is one
00040  * which does the trick
00041  */
00042 char *
00043 strdup(s1)
00044     char *s1;
00045 {
00046     char *s2;
00047     int l = strlen(s1) + 1;
00048 
00049     if (s2 = (char *) XpmMalloc(l))
00050        strncpy(s2, s1, l);
00051     return s2;
00052 }
00053 
00054 #endif
00055 
00056 unsigned int
00057 xpmatoui(p, l, ui_return)
00058     register char *p;
00059     unsigned int l;
00060     unsigned int *ui_return;
00061 {
00062     register unsigned int n, i;
00063 
00064     n = 0;
00065     for (i = 0; i < l; i++)
00066        if (*p >= '0' && *p <= '9')
00067            n = n * 10 + *p++ - '0';
00068        else
00069            break;
00070 
00071     if (i != 0 && i == l) {
00072        *ui_return = n;
00073        return 1;
00074     } else
00075        return 0;
00076 }
00077 
00078 /*
00079  * Function returning a character string related to an error code.
00080  */
00081 char *
00082 XpmGetErrorString(errcode)
00083     int errcode;
00084 {
00085     switch (errcode) {
00086     case XpmColorError:
00087        return ("XpmColorError");
00088     case XpmSuccess:
00089        return ("XpmSuccess");
00090     case XpmOpenFailed:
00091        return ("XpmOpenFailed");
00092     case XpmFileInvalid:
00093        return ("XpmFileInvalid");
00094     case XpmNoMemory:
00095        return ("XpmNoMemory");
00096     case XpmColorFailed:
00097        return ("XpmColorFailed");
00098     default:
00099        return ("Invalid XpmError");
00100     }
00101 }
00102 
00103 /*
00104  * The following function provides a way to figure out if the linked library is
00105  * newer or older than the one with which a program has been first compiled.
00106  */
00107 int
00108 XpmLibraryVersion()
00109 {
00110     return XpmIncludeVersion;
00111 }