11ab64890Smrg
21ab64890Smrg/*
31ab64890Smrg * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
41ab64890Smrg * 	All Rights Reserved
561b2299dSmrg *
61ab64890Smrg * This file is a component of an X Window System-specific implementation
71ab64890Smrg * of Xcms based on the TekColor Color Management System.  Permission is
81ab64890Smrg * hereby granted to use, copy, modify, sell, and otherwise distribute this
91ab64890Smrg * software and its documentation for any purpose and without fee, provided
101ab64890Smrg * that this copyright, permission, and disclaimer notice is reproduced in
111ab64890Smrg * all copies of this software and in supporting documentation.  TekColor
121ab64890Smrg * is a trademark of Tektronix, Inc.
1361b2299dSmrg *
141ab64890Smrg * Tektronix makes no representation about the suitability of this software
151ab64890Smrg * for any purpose.  It is provided "as is" and with all faults.
1661b2299dSmrg *
171ab64890Smrg * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
181ab64890Smrg * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
191ab64890Smrg * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
201ab64890Smrg * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
211ab64890Smrg * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
221ab64890Smrg * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
231ab64890Smrg * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
241ab64890Smrg *
251ab64890Smrg *
261ab64890Smrg *	NAME
271ab64890Smrg *		XcmsIdOfPr.c
281ab64890Smrg *
291ab64890Smrg *	DESCRIPTION
301ab64890Smrg *		Source for XcmsFormatOfPrefix()
311ab64890Smrg *
321ab64890Smrg *
331ab64890Smrg */
341ab64890Smrg
351ab64890Smrg#ifdef HAVE_CONFIG_H
361ab64890Smrg#include <config.h>
371ab64890Smrg#endif
381ab64890Smrg#include "Xlibint.h"
391ab64890Smrg#include "Xcmsint.h"
401ab64890Smrg#include "Cv.h"
411ab64890Smrg
421ab64890Smrg
431ab64890Smrg/*
441ab64890Smrg *	NAME
451ab64890Smrg *		XcmsFormatOfPrefix
461ab64890Smrg *
471ab64890Smrg *	SYNOPSIS
481ab64890Smrg */
491ab64890SmrgXcmsColorFormat
501ab64890SmrgXcmsFormatOfPrefix(char *prefix)
511ab64890Smrg/*
521ab64890Smrg *	DESCRIPTION
531ab64890Smrg *		Returns the Color Space ID for the specified prefix
541ab64890Smrg *		if the color space is found in the Color Conversion
551ab64890Smrg *		Context.
561ab64890Smrg *
571ab64890Smrg *	RETURNS
581ab64890Smrg *		Color Space ID if found; zero otherwise.
591ab64890Smrg */
601ab64890Smrg{
611ab64890Smrg    XcmsColorSpace	**papColorSpaces;
621ab64890Smrg    char		string_buf[64];
631ab64890Smrg    char		*string_lowered;
642d67cb4fSmrg    size_t		len;
651ab64890Smrg
661ab64890Smrg    /*
671ab64890Smrg     * While copying prefix to string_lowered, convert to lowercase
681ab64890Smrg     */
691ab64890Smrg    if ((len = strlen(prefix)) >= sizeof(string_buf)) {
70818534a1Smrg	string_lowered = Xmalloc(len+1);
711ab64890Smrg    } else {
721ab64890Smrg	string_lowered = string_buf;
731ab64890Smrg    }
741ab64890Smrg    _XcmsCopyISOLatin1Lowered(string_lowered, prefix);
751ab64890Smrg
761ab64890Smrg    /*
771ab64890Smrg     * First try Device-Independent color spaces
781ab64890Smrg     */
791ab64890Smrg    papColorSpaces = _XcmsDIColorSpaces;
801ab64890Smrg    if (papColorSpaces != NULL) {
811ab64890Smrg	while (*papColorSpaces != NULL) {
821ab64890Smrg	    if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) {
831ab64890Smrg		if (len >= sizeof(string_buf)) Xfree(string_lowered);
841ab64890Smrg		return((*papColorSpaces)->id);
851ab64890Smrg	    }
861ab64890Smrg	    papColorSpaces++;
871ab64890Smrg	}
881ab64890Smrg    }
891ab64890Smrg
901ab64890Smrg    /*
911ab64890Smrg     * Next try Device-Dependent color spaces
921ab64890Smrg     */
931ab64890Smrg    papColorSpaces = _XcmsDDColorSpaces;
941ab64890Smrg    if (papColorSpaces != NULL) {
951ab64890Smrg	while (*papColorSpaces != NULL) {
961ab64890Smrg	    if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) {
971ab64890Smrg		if (len >= sizeof(string_buf)) Xfree(string_lowered);
981ab64890Smrg		return((*papColorSpaces)->id);
991ab64890Smrg	    }
1001ab64890Smrg	    papColorSpaces++;
1011ab64890Smrg	}
1021ab64890Smrg    }
1031ab64890Smrg
1041ab64890Smrg    if (len >= sizeof(string_buf)) Xfree(string_lowered);
1051ab64890Smrg    return(XcmsUndefinedFormat);
1061ab64890Smrg}
107