upload tizen2.0 source
[framework/uifw/xorg/lib/libx11.git] / src / xcms / IdOfPr.c
1
2 /*
3  * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
4  *      All Rights Reserved
5  *
6  * This file is a component of an X Window System-specific implementation
7  * of Xcms based on the TekColor Color Management System.  Permission is
8  * hereby granted to use, copy, modify, sell, and otherwise distribute this
9  * software and its documentation for any purpose and without fee, provided
10  * that this copyright, permission, and disclaimer notice is reproduced in
11  * all copies of this software and in supporting documentation.  TekColor
12  * is a trademark of Tektronix, Inc.
13  *
14  * Tektronix makes no representation about the suitability of this software
15  * for any purpose.  It is provided "as is" and with all faults.
16  *
17  * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
18  * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19  * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
20  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21  * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
22  * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23  * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
24  *
25  *
26  *      NAME
27  *              XcmsIdOfPr.c
28  *
29  *      DESCRIPTION
30  *              Source for XcmsFormatOfPrefix()
31  *
32  *
33  */
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38 #include "Xlibint.h"
39 #include "Xcmsint.h"
40 #include "Cv.h"
41
42 \f
43 /*
44  *      NAME
45  *              XcmsFormatOfPrefix
46  *
47  *      SYNOPSIS
48  */
49 XcmsColorFormat
50 XcmsFormatOfPrefix(char *prefix)
51 /*
52  *      DESCRIPTION
53  *              Returns the Color Space ID for the specified prefix
54  *              if the color space is found in the Color Conversion
55  *              Context.
56  *
57  *      RETURNS
58  *              Color Space ID if found; zero otherwise.
59  */
60 {
61     XcmsColorSpace      **papColorSpaces;
62     char                string_buf[64];
63     char                *string_lowered;
64     int                 len;
65
66     /*
67      * While copying prefix to string_lowered, convert to lowercase
68      */
69     if ((len = strlen(prefix)) >= sizeof(string_buf)) {
70         string_lowered = (char *) Xmalloc(len+1);
71     } else {
72         string_lowered = string_buf;
73     }
74     _XcmsCopyISOLatin1Lowered(string_lowered, prefix);
75
76     /*
77      * First try Device-Independent color spaces
78      */
79     papColorSpaces = _XcmsDIColorSpaces;
80     if (papColorSpaces != NULL) {
81         while (*papColorSpaces != NULL) {
82             if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) {
83                 if (len >= sizeof(string_buf)) Xfree(string_lowered);
84                 return((*papColorSpaces)->id);
85             }
86             papColorSpaces++;
87         }
88     }
89
90     /*
91      * Next try Device-Dependent color spaces
92      */
93     papColorSpaces = _XcmsDDColorSpaces;
94     if (papColorSpaces != NULL) {
95         while (*papColorSpaces != NULL) {
96             if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) {
97                 if (len >= sizeof(string_buf)) Xfree(string_lowered);
98                 return((*papColorSpaces)->id);
99             }
100             papColorSpaces++;
101         }
102     }
103
104     if (len >= sizeof(string_buf)) Xfree(string_lowered);
105     return(XcmsUndefinedFormat);
106 }