home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / xcmstest / TekCMS_LT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-31  |  58.9 KB  |  2,783 lines

  1. /* $XConsortium: TekCMS_LT.c,v 1.7 91/05/31 19:14:10 rws Exp $ */
  2.  
  3. /*
  4.  * (c) Copyright 1990, Tektronix Inc.
  5.  *     All Rights Reserved
  6.  *
  7.  * Permission to use, copy, modify, and distribute this software and its
  8.  * documentation for any purpose and without fee is hereby granted,
  9.  * provided that the above copyright notice appear in all copies and that
  10.  * both that copyright notice and this permission notice appear in
  11.  * supporting documentation, and that the name of Tektronix not be used
  12.  * in advertising or publicity pertaining to distribution of the software
  13.  * without specific, written prior permission.
  14.  *
  15.  * Tektronix disclaims all warranties with regard to this software, including
  16.  * all implied warranties of merchantability and fitness, in no event shall
  17.  * Tektronix be liable for any special, indirect or consequential damages or
  18.  * any damages whatsoever resulting from loss of use, data or profits,
  19.  * whether in an action of contract, negligence or other tortious action,
  20.  * arising out of or in connection with the use or performance of this
  21.  * software.
  22.  *
  23.  *    NAME
  24.  *        TekCMS_LT.c -- TekCMS API LibTest Command Source
  25.  *
  26.  *    DESCRIPTION
  27.  *        TekCMS API library tester.
  28.  *
  29.  *        For each command, two things are necessary:
  30.  *            1. Entry into the Command Table
  31.  *            Create an entry into the Command Table (LibTstCmdTbl)
  32.  *            which is a command string and then a pointer to
  33.  *            the command function.
  34.  *            2. Command Function
  35.  *            Create the command function which should process
  36.  *            the remainder of the command line.  Don't forget
  37.  *            to predefine the function in the INTERNALS section.
  38.  *            Each command function receives one (1) argument
  39.  *            which is a pointer to a string of characters that
  40.  *            contains the remainder of the command.
  41.  */
  42.  
  43. /*
  44.  *      EXTERNAL INCLUDES
  45.  *              Include files that must be exported to any package or
  46.  *              program using this package.
  47.  */
  48. #include "LibTest.h"
  49.  
  50.  
  51. /*
  52.  *      INTERNAL INCLUDES
  53.  *              Include files that need NOT be exported to any package or
  54.  *              program using this package.
  55.  */
  56. #include <stdio.h>
  57. #include <X11/Xlib.h>
  58. #include <sys/stat.h>
  59. #include <X11/Xcms.h>
  60.  
  61. #ifdef AUTOHEADER
  62. #  include "TestInit.ah"
  63. #  include "TekCMS_TCI.ah"
  64. #  include "TekCMSglob.ah"
  65. #  include "TekCMSutil.ah"
  66. #else
  67. #  include "TestInit.h"
  68. #  include "TekCMS_TCI.h"
  69. #  include "TekCMSglob.h"
  70. #  include "TekCMSutil.h"
  71. #endif
  72.  
  73. /*
  74.  *    INTERNALS
  75.  *        Declarations that are local to this module.
  76.  *        (ignored by 'autohdr').
  77.  */
  78. #define MAXCOLORS    256
  79. #define MAXCMAPS    8
  80.  
  81. #define NO_COMP_FLAG 0
  82. #define COMP_FLAG    1
  83.  
  84. #ifndef X_NOT_STDC_ENV
  85. #include <stdlib.h>
  86. #else
  87. extern int atoi();
  88. extern double atof();
  89. char *calloc();
  90. void exit();
  91. #endif
  92. #if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
  93. char *calloc();
  94. #endif /* macII */
  95. extern XcmsColorSpace XcmsCIELabColorSpace;
  96. extern XcmsColorSpace XcmsCIELuvColorSpace;
  97. extern XcmsColorSpace XcmsTekHVCColorSpace;
  98. extern int EchoInput;
  99. extern void TestInit();
  100. Status Cmd_AddDIColorSpace();
  101. Status Cmd_AdjustValue();
  102. Status Cmd_AllocColor();
  103. Status Cmd_AllocNamedColor();
  104. Status Cmd_ConvertColor();
  105. Status Cmd_CreateColormap();
  106. Status Cmd_FreeColormap();
  107. Status Cmd_GetInputDir();
  108. Status Cmd_GetResultDir();
  109. Status Cmd_GetVerificationDir();
  110. Status Cmd_FormatOfPrefix();
  111. Status Cmd_init();
  112. Status Cmd_List();
  113. Status Cmd_LookupColor();
  114. Status Cmd_MaxChroma();
  115. Status Cmd_MaxValue();
  116. Status Cmd_MaxValueChroma();
  117. Status Cmd_MaxValueSamples();
  118. Status Cmd_MinValue();
  119. Status Cmd_PrefixOfId();
  120. Status Cmd_QueryColor();
  121. Status Cmd_QueryColors();
  122. Status Cmd_quit();
  123. Status Cmd_ReduceChroma();
  124. Status Cmd_SetInputDir();
  125. Status Cmd_SetResultDir();
  126. Status Cmd_SetVerificationDir();
  127. Status Cmd_ShortestValueChroma();
  128. Status Cmd_StoreColor();
  129. Status Cmd_StoreColors();
  130. Status Cmd_XAllocNamedColor();
  131. Status Cmd_XLookupColor();
  132. Status Cmd_XParseColor();
  133. Status Cmd_XStoreNamedColor();
  134. Status Cmd_XSynchronize();
  135.  
  136. typedef struct {
  137.     Colormap cmap;
  138.     int active;
  139.     char name[BUFSIZ];
  140. } CmapTblEntry;
  141.  
  142. CmapTblEntry CmapTbl[MAXCMAPS];
  143. int    Initialized = 0;
  144. XcmsCCC  _test_ccc = NULL;
  145.  
  146.  
  147. /*
  148.  *    EXTERNALS
  149.  *        Declarations that are needed by calling modules.
  150.  *        When using 'autohdr', these declaration will be placed
  151.  *        in the resulting header file.
  152.  */
  153. #define LIBTEST_CMDTBL    LibTstCmdTbl
  154. #define LIBTEST_COMMENT_CHAR    '#'
  155. #define LIBTEST_PROMPT    "XCMS > "
  156.  
  157.  
  158. FuncTableEntry LibTstCmdTbl[] = {
  159. /*
  160.  * Admin Commands
  161.  */
  162.  
  163.     /*
  164.      * Initialize Test
  165.      */
  166.     "init",        Cmd_init,
  167.  
  168.     /*
  169.      * Quit
  170.      */
  171.     "quit",        Cmd_quit,
  172.     "bye",        Cmd_quit,
  173.     "halt",        Cmd_quit,
  174.     "q",        Cmd_quit,
  175.  
  176.     /*
  177.      * List Commands
  178.      */
  179.     "list",        Cmd_List,
  180.     "?",        Cmd_List,
  181.  
  182.     /*
  183.      * Create Test Colormaps
  184.      */
  185.     "CreateColormap",    Cmd_CreateColormap,
  186.     "FreeColormap",    Cmd_FreeColormap,
  187.  
  188.     /*
  189.      * Set Input Directory
  190.      */
  191.     "Set_idir",    Cmd_SetInputDir,
  192.  
  193.     /*
  194.      * Set Verification Directory
  195.      */
  196.     "Set_vdir",    Cmd_SetVerificationDir,
  197.  
  198.     /*
  199.      * Set Result Directory
  200.      */
  201.     "Set_rdir",    Cmd_SetResultDir,
  202.  
  203.     /*
  204.      * Get Input Directory
  205.      */
  206.     "Get_idir",    Cmd_GetInputDir,
  207.  
  208.     /*
  209.      * Get Verification Directory
  210.      */
  211.     "Get_vdir",    Cmd_GetVerificationDir,
  212.  
  213.     /*
  214.      * Get Results Directory
  215.      */
  216.     "Get_rdir",    Cmd_GetResultDir,
  217.  
  218.     /*
  219.      * Set XSynchronize
  220.      */
  221.     "XSynchronize",    Cmd_XSynchronize,
  222.  
  223.     /*
  224.      * Execute Test Case
  225.      */
  226.     "TestCase",        TCI,
  227.     "tc",        TCI,
  228.  
  229.     /*
  230.      * List Test Cases
  231.      */
  232.     "ListTC",        Cmd_ListTC,
  233.  
  234. /*
  235.  * API Testing Commands
  236.  */
  237.  
  238.     /*
  239.      * XcmsAllocColor
  240.      */
  241.     "XcmsAllocColor",    Cmd_AllocColor,
  242.     "AllocColor",    Cmd_AllocColor,
  243.  
  244.     /*
  245.      * XcmsAllocNamedColor
  246.      */
  247.     "XcmsAllocNamedColor", Cmd_AllocNamedColor,
  248.     "AllocNamedColor",    Cmd_AllocNamedColor,
  249.  
  250.     /*
  251.      * XcmsConvertColors
  252.      */
  253.     "XcmsConvertColor", Cmd_ConvertColor,
  254.     "ConvertColor",    Cmd_ConvertColor,
  255.  
  256.     /*
  257.      * XcmsLookupColor
  258.      */
  259.     "XcmsLookupColor",    Cmd_LookupColor,
  260.     "LookupColor",    Cmd_LookupColor,
  261.  
  262.     /*
  263.      * XcmsQueryColor
  264.      */
  265.     "XcmsQueryColor",    Cmd_QueryColor,
  266.     "QueryColor",    Cmd_QueryColor,
  267.  
  268.     /*
  269.      * XcmsQueryColors
  270.      */
  271.     "XcmsQueryColors",    Cmd_QueryColors,
  272.     "QueryColors",    Cmd_QueryColors,
  273.  
  274.  
  275.     /*
  276.      * XcmsStoreColor
  277.      */
  278.     "XcmsStoreColor",    Cmd_StoreColor,
  279.     "StoreColor",    Cmd_StoreColor,
  280.  
  281.     /*
  282.      * XcmsStoreColors
  283.      */
  284.     "XcmsStoreColors",    Cmd_StoreColors,
  285.     "StoreColors",    Cmd_StoreColors,
  286.  
  287.  
  288.     /*
  289.      * Color Space Extension
  290.      */
  291.  
  292.     "XcmsAddColorSpace",    Cmd_AddDIColorSpace,
  293.     "AddDIColorSpace",    Cmd_AddDIColorSpace,
  294.     "XcmsFormatOfPrefix",    Cmd_FormatOfPrefix,
  295.     "FormatOfPrefix",        Cmd_FormatOfPrefix,
  296.     "XcmsPrefixOfFormat",    Cmd_PrefixOfId,
  297.     "PrefixOfId",        Cmd_PrefixOfId,
  298.     /*
  299.      * Query Gamut Boundaries
  300.      */
  301.  
  302.     /* TekHVC MaxChroma */
  303.     "XcmsTekHVCQueryMaxC",        Cmd_MaxChroma,
  304.     "MaxChroma",            Cmd_MaxChroma,
  305.  
  306.     /* TekHVC MaxValue */
  307.     "XcmsTekHVCQueryMaxV",    Cmd_MaxValue,
  308.     "MaxValue",            Cmd_MaxValue,
  309.  
  310.     /* TekHVC MaxValueSamples */
  311.     "XcmsTekHVCQueryMaxVSamples",     Cmd_MaxValueSamples,
  312.     "MaxValueSamples",        Cmd_MaxValueSamples,
  313.  
  314.     /* TekHVC MaxValueChroma */
  315.     "XcmsTekHVCQueryMaxVC", Cmd_MaxValueChroma,
  316.     "MaxValueChroma",        Cmd_MaxValueChroma,
  317.  
  318.     /* TekHVC MinValue */
  319.     "XcmsTekHVCQueryMinV",        Cmd_MinValue,
  320.     "MinValue",            Cmd_MinValue,
  321.  
  322.     /* TekHVC AdjustValue */
  323.     "XcmsTekHVCClipV",    Cmd_AdjustValue,
  324.     "AdjustValue",            Cmd_AdjustValue,
  325.  
  326.     /* TekHVC ReduceChroma */
  327.     "XcmsTekHVCClipC",    Cmd_ReduceChroma,
  328.     "ReduceChroma",            Cmd_ReduceChroma,
  329.  
  330.     /* TekHVC ShortestValueChroma */
  331.     "XcmsTekHVCClipVC",    Cmd_ShortestValueChroma,
  332.     "ShortestValueChroma",        Cmd_ShortestValueChroma,
  333.     "ShortestVC",            Cmd_ShortestValueChroma,
  334.     "Shortest",            Cmd_ShortestValueChroma,
  335.     /*
  336.      * XLib Modifications
  337.      */
  338.     "XAllocNamedColor",    Cmd_XAllocNamedColor,
  339.     "XLookupColor",    Cmd_XLookupColor,
  340.     "XParseColor",    Cmd_XParseColor,
  341.     "XStoreNamedColor",    Cmd_XStoreNamedColor,
  342.  
  343.     "",            0
  344. };
  345.  
  346.  
  347. /************************************************************************
  348.  *                                    *
  349.  *            PRIVATE ROUTINES                *
  350.  *                                    *
  351.  *                                    *
  352.  ************************************************************************/
  353.  
  354.  
  355.  
  356. /*
  357.  *    NAME
  358.  *        StrToCmap - convert a string to a colormap
  359.  *
  360.  *    SYNOPSIS
  361.  */
  362. static int
  363. StrToCmap(pCmapTbl, pstring, pcmap)
  364.     CmapTblEntry pCmapTbl[];    
  365.     char *pstring;
  366.     Colormap *pcmap;
  367. /*
  368.  *    DESCRIPTION
  369.  *        Returns the colormap associated to a string.
  370.  *
  371.  *    RETURNS
  372.  *        0 if failed; non-zero otherwise.
  373.  *        Also the associated colormap via pcmap.
  374.  *
  375.  */
  376. {
  377.     int i;
  378.  
  379.     if (strcmp("default", pstring) == 0) {
  380.     *pcmap = XDefaultColormap(pDpy,XDefaultScreen(pDpy));
  381.     return(1);
  382.     }
  383.     for (i = 0; i < MAXCMAPS; pCmapTbl++, i++) {
  384.     if((strcmp(pCmapTbl->name, pstring) == 0) && (pCmapTbl->active)) {
  385.         *pcmap = pCmapTbl->cmap;
  386.         return(1);
  387.     }
  388.     }
  389.     return(0);
  390. }
  391.  
  392. /*
  393.  *    NAME
  394.  *        NextFreeCmapEntry - convert a string to a define
  395.  *
  396.  *    SYNOPSIS
  397.  */
  398. static int
  399. NextFreeCmapEntry(pCmapTbl)
  400.     CmapTblEntry    pCmapTbl[];    
  401. /*
  402.  *    DESCRIPTION
  403.  *        Obtains the index to the next free CmapTblEntry.
  404.  *
  405.  *    RETURNS
  406.  *        Returns the index to the next free CmapTblEntry.
  407.  *
  408.  */
  409. {
  410.     int i;
  411.  
  412.     for (i = 0; i < MAXCMAPS; pCmapTbl++, i++) {
  413.     if(!pCmapTbl->active) {
  414.         return(i);
  415.     }
  416.     }
  417.     return(-1);
  418. }
  419.  
  420. /*
  421.  *      NAME
  422.  *              CheckPrintRetVal - check the retval and print readable result
  423.  *
  424.  *      SYNOPSIS
  425.  */
  426. static int
  427. CheckPrintRetVal (pWord, retval, compFlag) 
  428.     char *pWord;
  429.     Status retval;
  430.     int compFlag;
  431. /*
  432.  *      DESCRIPTION
  433.  *        Checks the Status return value and prints the readable
  434.  *        result.
  435.  *
  436.  *      RETURNS
  437.  *        0 if failed; non-zero otherwise.
  438.  *
  439.  */
  440. {
  441.     if (compFlag) {
  442.     printf ("\t%s() returned %s", pWord, 
  443.             (retval == XcmsFailure) ? "XcmsFailure" :
  444.          ((retval == XcmsSuccess) ? "XcmsSuccess" :
  445.          ((retval == XcmsSuccessWithCompression) ? 
  446.           "XcmsSuccessWithCompression" : "invalid value ")));
  447.     if (retval == XcmsSuccess ||
  448.         retval == XcmsSuccessWithCompression) {
  449.         printf ("\n");
  450.         return(1);
  451.     } else if (retval != XcmsFailure) {
  452.         printf ("%d\n");
  453.     } else {
  454.         printf ("\n");
  455.     }
  456.     return(0);
  457.     } else {
  458.     printf ("\t%s() returned %s", pWord,
  459.         (retval == XcmsFailure) ? "XcmsFailure" :
  460.         ((retval == XcmsSuccess) ? "XcmsSuccess" : "invalid value"));
  461.     if (retval == XcmsSuccess) {
  462.         printf ("\n");
  463.         return(1);
  464.     } else if (retval != XcmsFailure) {
  465.         printf ("%d\n");
  466.     } else {
  467.         printf ("\n");
  468.     }
  469.     return(0);
  470.     }
  471. }
  472.  
  473.  
  474. /************************************************************************
  475.  *                                    *
  476.  *             PUBLIC ROUTINES                *
  477.  *                                    *
  478.  ************************************************************************/
  479.  
  480. /*
  481.  *    NAME
  482.  *        Check_init - Check if Initialized
  483.  *
  484.  *    SYNOPSIS
  485.  */
  486. int
  487. Check_init()
  488. /*
  489.  *    DESCRIPTION
  490.  *        Check if this package is initialized
  491.  *
  492.  *    RETURNS
  493.  *        Status: 0=fail, 1=Success
  494.  *
  495.  */
  496. {
  497.     if (Initialized) {
  498.     return(1);
  499.     }
  500. #ifdef NO_AUTO_INIT
  501.     printf("Error: Test not initialized\n");
  502.     return(0);
  503. #else
  504.     TekCMS_idir[0] = TekCMS_vdir[0] = TekCMS_rdir[0] = '\0';
  505.     TestInit();
  506.     _test_ccc = XcmsDefaultCCC(pDpy, DefaultScreen(pDpy));
  507.     Initialized = 1;
  508.     if ((Cmd_CreateColormap("TstCmap_AllocColor AllocNone") == 0) ||
  509.         (Cmd_CreateColormap("TstCmap_StoreColor AllocAll") == 0)) {
  510.     printf("Error: Unable to create TstCmap_AllocColor or TstCmap_StoreColor colormaps\n");
  511.     return(0);
  512.     }
  513.     return(1);
  514. #endif /* NO_AUTO_INIT */
  515. }
  516.  
  517.  
  518. /************************************************************************
  519.  *                                    *
  520.  *             ADMIN COMMANDS                    *
  521.  *                                    *
  522.  ************************************************************************/
  523.  
  524. /*
  525.  *    NAME
  526.  *        Cmd_List
  527.  *
  528.  *    SYNOPSIS
  529.  */
  530. int
  531. Cmd_List(argbuf)
  532.     char *argbuf;
  533. /*
  534.  *    DESCRIPTION
  535.  *        List TekCMS test interface commands
  536.  *
  537.  *    RETURNS
  538.  *        0=fail, 1=Success
  539.  *
  540.  */
  541. {
  542.     char tmpstr[BUFSIZ];
  543.     FuncTableEntry    *pCmdEntry;
  544.  
  545.     tmpstr[0] = '\0';
  546.  
  547.     if (sscanf(argbuf, "%s", tmpstr) > 0) {
  548.         printf("Usage:\n");
  549.         printf("\tlist\n\n");
  550.         return(0);
  551.     } 
  552.  
  553.     for (pCmdEntry = LibTstCmdTbl; *pCmdEntry->pstring != '\0'; pCmdEntry++) {
  554.     printf("\t%s\n", pCmdEntry->pstring);
  555.     }
  556.     printf("\n");
  557.  
  558.     return(1);
  559. }
  560.  
  561. /*
  562.  *    NAME
  563.  *        Cmd_SetInputDir
  564.  *
  565.  *    SYNOPSIS
  566.  */
  567. int
  568. Cmd_SetInputDir(argbuf)
  569.     char *argbuf;
  570. /*
  571.  *    DESCRIPTION
  572.  *        Set TekCMS_idir
  573.  *
  574.  *    RETURNS
  575.  *        0=fail, 1=Success
  576.  *
  577.  */
  578. {
  579.     char tmpstr[BUFSIZ];
  580.     struct stat statbuf;
  581.  
  582.     if ((sscanf(argbuf, "%s", tmpstr) < 1) || (strcmp("-help", tmpstr) == 0)) {
  583. SetInputDir_Usage:
  584.         printf("Usage:\n");
  585.         printf("\tSet_idir dirname \n\n");
  586.         return(0);
  587.     } 
  588.  
  589.     /* Verify that it is a directory */
  590.     if (stat(tmpstr, &statbuf) == 0) {
  591.     /* stat succeeded */
  592.     if (statbuf.st_mode & S_IFDIR) {
  593.         strcpy(TekCMS_idir, tmpstr);
  594.         return(1);
  595.     }
  596.     printf("Error: %s not a directory\n", tmpstr);
  597.     return(0);
  598.     } else {
  599.     /* stat failed */
  600.     printf("Error: cannot find directory %s\n", tmpstr);
  601.     return(0);
  602.     }
  603. }
  604.  
  605. /*
  606.  *    NAME
  607.  *        Cmd_SetVerificationDir
  608.  *
  609.  *    SYNOPSIS
  610.  */
  611. int
  612. Cmd_SetVerificationDir(argbuf)
  613.     char *argbuf;
  614. /*
  615.  *    DESCRIPTION
  616.  *        Set TekCMS_vdir
  617.  *
  618.  *    RETURNS
  619.  *        0=fail, 1=Success
  620.  *
  621.  */
  622. {
  623.     char tmpstr[BUFSIZ];
  624.     struct stat statbuf;
  625.  
  626.     if ((sscanf(argbuf, "%s", tmpstr) < 1) || (strcmp("-help", tmpstr) == 0)) {
  627. SetVerificationDir_Usage:
  628.         printf("Usage:\n");
  629.         printf("\tSet_vdir dirname \n\n");
  630.         return(0);
  631.     } 
  632.  
  633.     /* Verify that it is a directory */
  634.     if (stat(tmpstr, &statbuf) == 0) {
  635.     /* stat succeeded */
  636.     if (statbuf.st_mode & S_IFDIR) {
  637.         strcpy(TekCMS_vdir, tmpstr);
  638.         return(1);
  639.     }
  640.     printf("Error: %s not a directory\n", tmpstr);
  641.     return(0);
  642.     } else {
  643.     /* stat failed */
  644.     printf("Error: cannot find directory %s\n", tmpstr);
  645.     return(0);
  646.     }
  647. }
  648.  
  649. /*
  650.  *    NAME
  651.  *        Cmd_SetResultDir
  652.  *
  653.  *    SYNOPSIS
  654.  */
  655. int
  656. Cmd_SetResultDir(argbuf)
  657.     char *argbuf;
  658. /*
  659.  *    DESCRIPTION
  660.  *        Set TekCMS_rdir
  661.  *
  662.  *    RETURNS
  663.  *        0=fail, 1=Success
  664.  *
  665.  */
  666. {
  667.     char tmpstr[BUFSIZ];
  668.     struct stat statbuf;
  669.  
  670.     if ((sscanf(argbuf, "%s", tmpstr) < 1) || (strcmp("-help", tmpstr) == 0)) {
  671. SetResultDir_Usage:
  672.         printf("Usage:\n");
  673.         printf("\tSet_rdir dirname \n\n");
  674.         return(0);
  675.     } 
  676.  
  677.     /* Verify that it is a directory */
  678.     if (stat(tmpstr, &statbuf) == 0) {
  679.     /* stat succeeded */
  680.     if (statbuf.st_mode & S_IFDIR) {
  681.         strcpy(TekCMS_rdir, tmpstr);
  682.         return(1);
  683.     }
  684.     printf("Error: %s not a directory\n", tmpstr);
  685.     return(0);
  686.     } else {
  687.     /* stat failed */
  688.     printf("Error: cannot find directory %s\n", tmpstr);
  689.     return(0);
  690.     }
  691. }
  692.  
  693. /*
  694.  *    NAME
  695.  *        Cmd_GetInputDir
  696.  *
  697.  *    SYNOPSIS
  698.  */
  699. int
  700. Cmd_GetInputDir(argbuf)
  701.     char *argbuf;
  702. /*
  703.  *    DESCRIPTION
  704.  *        Get TekCMS_idir
  705.  *
  706.  *    RETURNS
  707.  *        0=fail, 1=Success
  708.  *
  709.  */
  710. {
  711.     char tmpstr[BUFSIZ];
  712.  
  713.     if (sscanf(argbuf, "%s", tmpstr) > 0) {
  714. GetInputDir_Usage:
  715.         printf("Usage:\n");
  716.         printf("\tGet_idir\n\n");
  717.         return(0);
  718.     } 
  719.  
  720.     printf("\tInput Directory = %s\n", TekCMS_idir);
  721.     return(1);
  722. }
  723.  
  724. /*
  725.  *    NAME
  726.  *        Cmd_GetVerificationDir
  727.  *
  728.  *    SYNOPSIS
  729.  */
  730. int
  731. Cmd_GetVerificationDir(argbuf)
  732.     char *argbuf;
  733. /*
  734.  *    DESCRIPTION
  735.  *        Get TekCMS_vdir
  736.  *
  737.  *    RETURNS
  738.  *        0=fail, 1=Success
  739.  *
  740.  */
  741. {
  742.     char tmpstr[BUFSIZ];
  743.  
  744.     if (sscanf(argbuf, "%s", tmpstr) > 0) {
  745. GetVerificationDir_Usage:
  746.         printf("Usage:\n");
  747.         printf("\tGet_vdir\n\n");
  748.         return(0);
  749.     } 
  750.  
  751.     printf("\tVerification Directory = %s\n", TekCMS_vdir);
  752.     return(1);
  753. }
  754.  
  755. /*
  756.  *    NAME
  757.  *        Cmd_GetResultDir
  758.  *
  759.  *    SYNOPSIS
  760.  */
  761. int
  762. Cmd_GetResultDir(argbuf)
  763.     char *argbuf;
  764. /*
  765.  *    DESCRIPTION
  766.  *        Get TekCMS_rdir
  767.  *
  768.  *    RETURNS
  769.  *        0=fail, 1=Success
  770.  *
  771.  */
  772. {
  773.     char tmpstr[BUFSIZ];
  774.  
  775.     if (sscanf(argbuf, "%s", tmpstr) > 0) {
  776. GetResultDir_Usage:
  777.         printf("Usage:\n");
  778.         printf("\tGet_rdir\n\n");
  779.         return(0);
  780.     } 
  781.  
  782.     printf("\tResult Directory = %s\n", TekCMS_rdir);
  783.     return(1);
  784. }
  785.  
  786.  
  787. /*
  788.  *    NAME
  789.  *        Cmd_CreateColormap - LibTest "CreateColormap" command
  790.  *
  791.  *    SYNOPSIS
  792.  */
  793. int
  794. Cmd_CreateColormap(buf)
  795.     char *buf;
  796. /*
  797.  *    DESCRIPTION
  798.  *        "CreateColormap" command for LibTest.
  799.  *
  800.  *    RETURNS
  801.  *        0=fail, 1=Success
  802.  *
  803.  */
  804. {
  805.     Colormap cMap;
  806.     int iCmap;
  807.     char allocStr[BUFSIZ];
  808.  
  809.     allocStr[0] = '\0';
  810.  
  811.     if (!Check_init()) {
  812.     return(0);
  813.     }
  814.     if ((iCmap = NextFreeCmapEntry(CmapTbl)) == -1) {
  815.     return(0);
  816.     }
  817.  
  818.     if (sscanf(buf, "%s %s",
  819.         CmapTbl[iCmap].name,
  820.         allocStr
  821.         ) < 2) {
  822.     printf("Invalid argument(s): %s\n", buf);
  823. CreateColormap_Usage:
  824.     printf("Usage:\n");
  825.     printf("    CreateColormap <Name> <AllocFlag>\n\n");
  826.     printf("\tWhere:\n");
  827.     printf("\t    Name :== string\n");
  828.     printf("\t    AllocFlag :== AllocNone | AllocAll\n");
  829.     CmapTbl[iCmap].active = 0;
  830.     return(0);
  831.     }
  832.  
  833.     cMap = XCreateColormap(pDpy,
  834.         RootWindow(pDpy, DefaultScreen(pDpy)),
  835.         DefaultVisual(pDpy, DefaultScreen(pDpy)),
  836.         LtStrToDefine(AllocTbl, allocStr));
  837.     XSync(pDpy, False);
  838.     CmapTbl[iCmap].cmap = cMap;
  839.     CmapTbl[iCmap].active = 1;
  840.     return(1);
  841. }
  842.  
  843.  
  844. /*
  845.  *    NAME
  846.  *        Cmd_FreeColormap - LibTest "FreeColormap" command
  847.  *
  848.  *    SYNOPSIS
  849.  */
  850. int
  851. Cmd_FreeColormap(buf)
  852.     char *buf;
  853. /*
  854.  *    DESCRIPTION
  855.  *        "FreeColormap" command for LibTest.
  856.  *
  857.  *    RETURNS
  858.  *        0=fail, 1=Success
  859.  *
  860.  */
  861. {
  862.     char name[BUFSIZ];
  863.     int i;
  864.  
  865.     if (!Check_init()) {
  866.     return(0);
  867.     }
  868.  
  869.     name[0] = '\0';
  870.  
  871.     if (sscanf(buf, "%s",
  872.         name
  873.         ) < 1) {
  874.     printf("Invalid argument(s): %s\n", buf);
  875. FreeColormap_Usage:
  876.     printf("Usage:\n");
  877.     printf("    FreeColormap <Name>\n\n");
  878.     printf("\tWhere:\n");
  879.     printf("\t    Name :== string\n");
  880.     return(0);
  881.     }
  882.     for (i = 0; i < MAXCMAPS; i++) {
  883.     if((strcmp(CmapTbl[i].name, name) == 0) && (CmapTbl[i].active)) {
  884.         XFreeColormap(pDpy, CmapTbl[i].cmap);
  885.         XSync(pDpy, False);
  886.         CmapTbl[i].active = 0;
  887.         return(1);
  888.     }
  889.     }
  890.     printf("Warning: colormap %s already freed or is non-existent\n", name);
  891.     return(0);
  892. }
  893.  
  894.  
  895. /*
  896. *    NAME
  897. *        Cmd_init - LibTest "init" command
  898. *
  899. *    SYNOPSIS
  900. */
  901. /* ARGSUSED */
  902. int
  903. Cmd_init(buf)
  904.     char *buf;
  905. /*
  906.  *    DESCRIPTION
  907.  *        "init" command for this test package.
  908.  *
  909.  *    RETURNS
  910.  *        Status: 0=fail, 1=Success
  911.  *
  912.  */
  913. {
  914.     int i;
  915.  
  916.     if (Initialized) {
  917.     printf("Error: Test already initialized\n");
  918.     return(0);
  919.     }
  920.     TekCMS_idir[0] = TekCMS_vdir[0] = TekCMS_rdir[0] = '\0';
  921.     TestInit();
  922.     Initialized = 1;
  923.     for (i = 0; i < MAXCMAPS; i++) {
  924.     CmapTbl[i].active = 0;
  925.     }
  926.     if ((Cmd_CreateColormap("TstCmap_AllocColor AllocNone") == 0) ||
  927.         (Cmd_CreateColormap("TstCmap_StoreColor AllocAll") == 0)) {
  928.     printf("Error: Unable to create TstCmap_AllocColor or TstCmap_StoreColor colormaps\n");
  929.     return(0);
  930.     }
  931.     return(1);
  932. }
  933.  
  934.  
  935. /*
  936.  *    NAME
  937.  *        Cmd_quit - "quit" command
  938.  *
  939.  *    SYNOPSIS
  940.  */
  941. /* ARGSUSED */
  942. int
  943. Cmd_quit(buf)
  944.     char *buf;
  945. /*
  946.  *    DESCRIPTION
  947.  *        "quit" command for LibTest.
  948.  *
  949.  *    RETURNS
  950.  *        0=fail, 1=Success
  951.  *
  952.  */
  953. {
  954.     int i;
  955.  
  956.     if (Initialized) {
  957.     for (i = 0; i < MAXCMAPS; i++) {
  958.         if (CmapTbl[i].active) {
  959.         XFreeColormap(pDpy, CmapTbl[i].cmap);
  960.         XSync(pDpy, False);
  961.         }
  962.     }
  963.     }
  964.     exit(1);
  965. }
  966.  
  967.  
  968. /*
  969.  *    NAME
  970.  *        Cmd_XSynchronize - Set X synchronization
  971.  *
  972.  *    SYNOPSIS
  973.  */
  974. int
  975. Cmd_XSynchronize(buf)
  976.     char *buf;
  977. /*
  978.  *    DESCRIPTION
  979.  *
  980.  *    RETURNS
  981.  *        0=fail, 1=Success
  982.  *
  983.  */
  984. {
  985.     Bool setting = 0;
  986.     char settingStr[BUFSIZ];
  987.     char tmpstr[BUFSIZ];
  988.  
  989.     if (!Check_init()) {
  990.     return(0);
  991.     }
  992.  
  993.     settingStr[0] = '\0';
  994.     tmpstr[0] = '\0';
  995.  
  996.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  997.     goto XSynchronize_Usage;
  998.     }
  999.  
  1000.     if (!sscanf(buf, "%s", settingStr)) {
  1001.     printf("Invalid argument(s): %s\n", buf);
  1002. XSynchronize_Usage:
  1003.     printf("Usage:\n");
  1004.     printf("    XSynchronize <ON | OFF>\n\n");
  1005.     return(0);
  1006.     }
  1007.  
  1008.     if (strcmp(settingStr, "ON") == 0) {
  1009.     setting = 1;
  1010.     } else if (strcmp(settingStr, "OFF") == 0) {
  1011.     setting = 0;
  1012.     } else {
  1013.     printf("Invalid format argument: %s\n", tmpstr);
  1014.     goto XSynchronize_Usage;
  1015.     }
  1016.  
  1017.     printf("\tREQUESTED:\n");
  1018.     printf("XSynchronize = %s\n", settingStr);
  1019.     XSynchronize(pDpy, setting);
  1020.     return(1);
  1021. }
  1022.  
  1023. /************************************************************************
  1024.  *                                    *
  1025.  *             API TESTING COMMANDS                *
  1026.  *                                    *
  1027.  ************************************************************************/
  1028.  
  1029. /*
  1030.  *    NAME
  1031.  *        Cmd_AllocColor - LibTest "AllocColor" command
  1032.  *
  1033.  *    SYNOPSIS
  1034.  */
  1035. int
  1036. Cmd_AllocColor(buf)
  1037.     char *buf;
  1038. /*
  1039.  *    DESCRIPTION
  1040.  *        "AllocColor" command for LibTest.
  1041.  *
  1042.  *    RETURNS
  1043.  *        0=fail, 1=Success
  1044.  *
  1045.  */
  1046. {
  1047.     Colormap cmap;
  1048.     XcmsColor color;
  1049.     char formatStr[BUFSIZ];
  1050.     char resultFormatStr[BUFSIZ];
  1051.     XcmsColorFormat result_format;
  1052.     char cmapname[BUFSIZ];
  1053.     char stim1[BUFSIZ];
  1054.     char stim2[BUFSIZ];
  1055.     char stim3[BUFSIZ];
  1056.     char tmpstr[BUFSIZ];
  1057.     int nargs;
  1058.     Status retval;
  1059.  
  1060.     if (!Check_init()) {
  1061.     return(0);
  1062.     }
  1063.  
  1064.     formatStr[0] = '\0';
  1065.     cmapname[0] = '\0';
  1066.     stim1[0] = '\0';
  1067.     stim2[0] = '\0';
  1068.     stim3[0] = '\0';
  1069.     tmpstr[0] = '\0';
  1070.  
  1071.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1072.     goto AllocColor_Usage;
  1073.     }
  1074.  
  1075.     color.pixel = 0;
  1076.     if ((nargs = sscanf(buf, "%s %s %s %s %s %s",
  1077.         formatStr,
  1078.         stim1,
  1079.         stim2,
  1080.         stim3,
  1081.         resultFormatStr,
  1082.         cmapname
  1083.         )) < 5) {
  1084.     printf("Invalid argument(s): %s\n", buf);
  1085. AllocColor_Usage:
  1086.     printf("Usage:\n");
  1087.     printf("    AllocColor <Format> <Stim1> <Stim2> <Stim3> <Result_Format> [Colormap]\n\n");
  1088.     printf("    Where:\n");
  1089.     printf("\tStim1,Stim2,Stim3 :== int for RGB, otherwise float\n");
  1090.     printf("\tFormat, Result_Format :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  1091.     printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  1092.     printf("\tStim1,Stim2,Stim3 :== int for RGB, otherwise float\n");
  1093.     printf("\tColormap :== string\n");
  1094.     return(0);
  1095.     }
  1096.     color.format = LtStrToDefine(FormatTbl, formatStr);
  1097.     result_format = LtStrToDefine(FormatTbl, resultFormatStr);
  1098.     if (color.format == XcmsRGBFormat) {
  1099.     color.spec.RGB.red = atoi(stim1);
  1100.     color.spec.RGB.green = atoi(stim2);
  1101.     color.spec.RGB.blue = atoi(stim3);
  1102.     } else {
  1103.     color.spec.CIEXYZ.X = atof(stim1);
  1104.     color.spec.CIEXYZ.Y = atof(stim2);
  1105.     color.spec.CIEXYZ.Z = atof(stim3);
  1106.     }
  1107.     if (nargs < 6) {
  1108.     strcpy(cmapname, "TstCmap_AllocColor");
  1109.     }
  1110.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  1111.     printf("Error: Colormap named %s not found\n", cmapname);
  1112.     return(0);
  1113.     }
  1114.  
  1115.     printf("    REQUESTED:\n");
  1116.     printf("\tColormap:\t%s\n", cmapname);
  1117.     PrintXcmsColorSpec(&color);
  1118.     printf("\tresult_format:\t%s\n", resultFormatStr);
  1119.     printf("    RESULT:\n");
  1120.     retval = XcmsAllocColor(pDpy, cmap, &color, result_format);
  1121.     if (!CheckPrintRetVal ("XcmsAllocColor", retval, COMP_FLAG))
  1122.     return(0);
  1123.     PrintXcmsColor(&color);
  1124.     return(1);
  1125. }
  1126.  
  1127.  
  1128. /*
  1129.  *    NAME
  1130.  *        Cmd_StoreColor - LibTest "StoreColor" command
  1131.  *
  1132.  *    SYNOPSIS
  1133.  */
  1134. int
  1135. Cmd_StoreColor(buf)
  1136.     char *buf;
  1137. /*
  1138.  *    DESCRIPTION
  1139.  *        "StoreColor" command for LibTest.
  1140.  *
  1141.  *    RETURNS
  1142.  *        0=fail, 1=Success
  1143.  *
  1144.  */
  1145. {
  1146.     Colormap cmap;
  1147.     XcmsColor color;
  1148.     char formatStr[BUFSIZ];
  1149.     char cmapname[BUFSIZ];
  1150.     char stim1[BUFSIZ];
  1151.     char stim2[BUFSIZ];
  1152.     char stim3[BUFSIZ];
  1153.     char tmpstr[BUFSIZ];
  1154.     int nargs;
  1155.     Status retval;
  1156.  
  1157.     if (!Check_init()) {
  1158.     return(0);
  1159.     }
  1160.  
  1161.     formatStr[0] = '\0';
  1162.     cmapname[0] = '\0';
  1163.     stim1[0] = '\0';
  1164.     stim2[0] = '\0';
  1165.     stim3[0] = '\0';
  1166.     tmpstr[0] = '\0';
  1167.  
  1168.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1169.     goto StoreColor_Usage;
  1170.     }
  1171.  
  1172.     color.pixel = 0;
  1173.     if ((nargs = sscanf(buf, "%d %s %s %s %s %s",
  1174.         &color.pixel,
  1175.         formatStr,
  1176.         stim1,
  1177.         stim2,
  1178.         stim3,
  1179.         cmapname
  1180.         )) < 5) {
  1181.     printf("Invalid argument(s): %s\n", buf);
  1182. StoreColor_Usage:
  1183.     printf("Usage:\n");
  1184.     printf("    StoreColor <Pixel> <Format> <Stim1> <Stim2> <Stim3> [Colormap]\n\n");
  1185.     printf("    Where:\n");
  1186.     printf("\tPixel :== integer\n");
  1187.     printf("\tFormat :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  1188.     printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  1189.     printf("\tStim1,Stim2,Stim3 :== int for RGB, otherwise float\n");
  1190.     printf("\tColormap :== string\n");
  1191.     return(0);
  1192.     }
  1193.     color.format = LtStrToDefine(FormatTbl, formatStr);
  1194.     if (color.format == XcmsRGBFormat) {
  1195.     color.spec.RGB.red = atoi(stim1);
  1196.     color.spec.RGB.green = atoi(stim2);
  1197.     color.spec.RGB.blue = atoi(stim3);
  1198.     } else {
  1199.     color.spec.CIEXYZ.X = atof(stim1);
  1200.     color.spec.CIEXYZ.Y = atof(stim2);
  1201.     color.spec.CIEXYZ.Z = atof(stim3);
  1202.     }
  1203.     if (nargs < 6) {
  1204.     strcpy(cmapname, "TstCmap_StoreColor");
  1205.     }
  1206.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  1207.     printf("Error: Colormap named %s not found\n", cmapname);
  1208.     return(0);
  1209.     }
  1210.  
  1211.     printf("    REQUESTED:\n");
  1212.     printf("\tColormap:\t%s\n", cmapname);
  1213.     PrintXcmsColor(&color);
  1214.     printf("    RESULT:\n");
  1215.     retval = XcmsStoreColor(pDpy, cmap, &color);
  1216.     if (!CheckPrintRetVal ("XcmsStoreColor", retval, COMP_FLAG))
  1217.     return(0);
  1218.     return(1);
  1219. }
  1220.  
  1221.  
  1222.  
  1223. /*
  1224.  *    NAME
  1225.  *        Cmd_QueryColor - LibTest "QueryColor" command
  1226.  *
  1227.  *    SYNOPSIS
  1228.  */
  1229. int
  1230. Cmd_QueryColor(buf)
  1231.     char *buf;
  1232. /*
  1233.  *    DESCRIPTION
  1234.  *        "QueryColor" command for LibTest.
  1235.  *
  1236.  *    RETURNS
  1237.  *        0=fail, 1=Success
  1238.  *
  1239.  */
  1240. {
  1241.     Colormap cmap;
  1242.     XcmsColor color;
  1243.     char formatStr[BUFSIZ];
  1244.     XcmsColorFormat result_format;
  1245.     char cmapname[BUFSIZ];
  1246.     char stim1[BUFSIZ];
  1247.     char stim2[BUFSIZ];
  1248.     char stim3[BUFSIZ];
  1249.     char tmpstr[BUFSIZ];
  1250.     int nargs;
  1251.     Status retval;
  1252.  
  1253.     if (!Check_init()) {
  1254.     return(0);
  1255.     }
  1256.  
  1257.     formatStr[0] = '\0';
  1258.     cmapname[0] = '\0';
  1259.     stim1[0] = '\0';
  1260.     stim2[0] = '\0';
  1261.     stim3[0] = '\0';
  1262.     tmpstr[0] = '\0';
  1263.  
  1264.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1265.     goto QueryColor_Usage;
  1266.     }
  1267.  
  1268.     color.pixel = 0;
  1269.     if ((nargs = sscanf(buf, "%d %s %s",
  1270.         &color.pixel,
  1271.         formatStr,
  1272.         cmapname
  1273.         )) < 2) {
  1274.     printf("Invalid argument(s): %s\n", buf);
  1275. QueryColor_Usage:
  1276.     printf("Usage:\n");
  1277.     printf("    QueryColor <Pixel> <result_format> [Colormap]\n\n");
  1278.     printf("    Where:\n");
  1279.     printf("\tPixel :== integer\n");
  1280.     printf("\tresult_format :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  1281.     printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  1282.     printf("\tColormap :== string\n");
  1283.     return(0);
  1284.     }
  1285.     result_format = LtStrToDefine(FormatTbl, formatStr);
  1286.     if (nargs < 3) {
  1287.     strcpy(cmapname, "TstCmap_StoreColor");
  1288.     }
  1289.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  1290.     printf("Error: Colormap named %s not found\n", cmapname);
  1291.     return(0);
  1292.     }
  1293.  
  1294.     printf("    REQUESTED:\n");
  1295.     printf("\tQuery pixel:\t%lu\n", color.pixel);
  1296.     printf("\tresult_format:\t%s\n", formatStr);
  1297.     printf("\tColormap:\t%s\n", cmapname);
  1298.     printf("    RESULT:\n");
  1299.     retval = XcmsQueryColor(pDpy, cmap, &color, result_format);
  1300.     if (!CheckPrintRetVal ("XcmsQueryColor", retval, NO_COMP_FLAG))
  1301.     return(0);
  1302.     PrintXcmsColor(&color);
  1303.     return(1);
  1304. }
  1305.  
  1306.  
  1307. /*
  1308.  *    NAME
  1309.  *        Cmd_QueryColors - LibTest "QueryColors" command
  1310.  *
  1311.  *    SYNOPSIS
  1312.  */
  1313. int
  1314. Cmd_QueryColors(buf)
  1315.     char *buf;
  1316. /*
  1317.  *    DESCRIPTION
  1318.  *        "QueryColors" command for LibTest.
  1319.  *
  1320.  *    RETURNS
  1321.  *        0=fail, 1=Success
  1322.  *
  1323.  */
  1324. {
  1325.     Colormap cmap;
  1326.     XcmsColor color[MAXCOLORS];
  1327.     char resultFormatStr[BUFSIZ];
  1328.     XcmsColorFormat result_format;
  1329.     char cmapname[BUFSIZ];
  1330.     char tmpstr[BUFSIZ];
  1331.     int begin, ncolors;
  1332.     Status retval;
  1333.  
  1334.     if (!Check_init()) {
  1335.     return(0);
  1336.     }
  1337.  
  1338.     cmapname[0] = '\0';
  1339.     tmpstr[0] = '\0';
  1340.  
  1341.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1342.     goto QueryColors_Usage;
  1343.     }
  1344.  
  1345.     if (sscanf(buf, "%s %s", resultFormatStr, cmapname) < 2) {
  1346.     strcpy(cmapname, "TstCmap_AllocColor");
  1347.     }
  1348.     result_format = LtStrToDefine(FormatTbl, resultFormatStr);
  1349.  
  1350.  
  1351.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  1352.     printf("Error: Colormap named %s not found\n", cmapname);
  1353.     return(0);
  1354.     }
  1355.  
  1356.     printf("    REQUESTED:\n");
  1357.     printf("\tresult_format:\t%s\n", resultFormatStr);
  1358.     printf("\tColormap:\t%s\n", cmapname);
  1359.     printf("\tPixel\tFormat\n");
  1360.     for(ncolors = 0;;) {
  1361.     if (ncolors >= MAXCOLORS) {
  1362.         return(0);
  1363.     }
  1364.     if (fgets(buf, BUFSIZ, stdin) == NULL) {
  1365.         return(0);
  1366.     }
  1367.     if (EchoInput) {
  1368.         printf("%s", buf);
  1369.     }
  1370.     if (buf[0] == LIBTEST_COMMENT_CHAR) {
  1371.         continue;
  1372.     }
  1373.     if (strcmp(buf, "BEGIN\n") == 0) {
  1374.         begin = 1;
  1375.         continue;
  1376.     }
  1377.     if (begin && (strcmp(buf, "END\n") == 0)) {
  1378.         break;
  1379.     }
  1380.     if (!begin) {
  1381.         goto QueryColors_Usage;
  1382.     } 
  1383.     if (sscanf(buf, "%d",
  1384.         &color[ncolors].pixel
  1385.         ) < 1) {
  1386.         printf("Invalid argument(s): %s\n", buf);
  1387. QueryColors_Usage:
  1388.         printf("Usage:\n");
  1389.         printf("    QueryColors <result_format> [Colormap]\n");
  1390.         printf("\tBEGIN\n");
  1391.         printf("\t<Pixel>\n");
  1392.         printf("\t<Pixel>\n");
  1393.         printf("\t.\t.\n");
  1394.         printf("\t.\t\n");
  1395.         printf("\t.\t\n");
  1396.         printf("\tEND\n\n");
  1397.         printf("    Where:\n");
  1398.         printf("\tColormap :== string\n");
  1399.         printf("\tPixel :== integer\n");
  1400.         printf("\tFormat :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  1401.         printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  1402.         return(0);
  1403.     }
  1404.     printf("\t%5lu\n", color[ncolors].pixel);
  1405.     ncolors++;
  1406.     }
  1407.  
  1408.     printf("    RESULT:\n");
  1409.     retval = XcmsQueryColors(pDpy, cmap, color, ncolors, result_format);
  1410.     if (!CheckPrintRetVal ("XcmsQueryColors", retval, NO_COMP_FLAG))
  1411.     return(0);
  1412.     PrintXcmsColors(color, ncolors);
  1413.     return(1);
  1414. }
  1415.  
  1416.  
  1417. /*
  1418.  *    NAME
  1419.  *        Cmd_ConvertColor - LibTest "ConvertColor" command
  1420.  *
  1421.  *    SYNOPSIS
  1422.  */
  1423. int
  1424. Cmd_ConvertColor(buf)
  1425.     char *buf;
  1426. /*
  1427.  *    DESCRIPTION
  1428.  *        "ConvertColor" command for LibTest.
  1429.  *
  1430.  *    RETURNS
  1431.  *        0=fail, 1=Success
  1432.  *
  1433.  */
  1434. {
  1435.     XcmsColor color;
  1436.     char fromFormatStr[BUFSIZ];
  1437.     char toFormatStr[BUFSIZ];
  1438.     char stim1[BUFSIZ];
  1439.     char stim2[BUFSIZ];
  1440.     char stim3[BUFSIZ];
  1441.     char tmpstr[BUFSIZ];
  1442.     XcmsColorFormat    toFormat;
  1443.     Bool compressed;
  1444.     Status retval;
  1445.  
  1446.     if (!Check_init()) {
  1447.     return(0);
  1448.     }
  1449.  
  1450.     fromFormatStr[0] = '\0';
  1451.     toFormatStr[0] = '\0';
  1452.     stim1[0] = '\0';
  1453.     stim2[0] = '\0';
  1454.     stim3[0] = '\0';
  1455.     tmpstr[0] = '\0';
  1456.  
  1457.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1458.     goto ConvertColor_Usage;
  1459.     }
  1460.  
  1461.     if (sscanf(buf, "%s %s %s %s %s",
  1462.         fromFormatStr,
  1463.         stim1,
  1464.         stim2,
  1465.         stim3,
  1466.         toFormatStr
  1467.         ) != 5) {
  1468.     printf("Invalid argument(s): %s\n", buf);
  1469. ConvertColor_Usage:
  1470.     printf("Usage:\n");
  1471.     printf("    ConvertColor <From_Format> <Stim1> <Stim2> <Stim3> <To_Format>\n\n");
  1472.     printf("    Where:\n");
  1473.     printf("\tFromFormat, ToFormat :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  1474.     printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  1475.     printf("\tStim1,Stim2,Stim3 :== int for RGB, otherwise float\n");
  1476.     return(0);
  1477.     }
  1478.     color.format = LtStrToDefine(FormatTbl, fromFormatStr);
  1479.     if (color.format == XcmsRGBFormat) {
  1480.     color.spec.RGB.red = atoi(stim1);
  1481.     color.spec.RGB.green = atoi(stim2);
  1482.     color.spec.RGB.blue = atoi(stim3);
  1483.     } else {
  1484.     color.spec.CIEXYZ.X = atof(stim1);
  1485.     color.spec.CIEXYZ.Y = atof(stim2);
  1486.     color.spec.CIEXYZ.Z = atof(stim3);
  1487.     }
  1488.     toFormat = LtStrToDefine(FormatTbl, toFormatStr);
  1489.  
  1490.     printf("    FROM:\n");
  1491.     PrintXcmsColorSpec(&color);
  1492.     retval = XcmsConvertColors(_test_ccc, &color, 1, toFormat, &compressed);
  1493.     if (!CheckPrintRetVal ("XcmsConvertColors", retval, COMP_FLAG))
  1494.     return(0);
  1495.     printf("    TO:\n");
  1496.     PrintXcmsColorSpec(&color);
  1497.     return(1);
  1498. }
  1499.  
  1500.  
  1501. /*
  1502.  *    NAME
  1503.  *        Cmd_LookupColor - LibTest "LookupColor" command
  1504.  *
  1505.  *    SYNOPSIS
  1506.  */
  1507. int
  1508. Cmd_LookupColor(buf)
  1509.     char *buf;
  1510. /*
  1511.  *    DESCRIPTION
  1512.  *        "LookupColor" command for LibTest.
  1513.  *
  1514.  *    RETURNS
  1515.  *        0=fail, 1=Success
  1516.  *
  1517.  */
  1518. {
  1519.     XcmsColor scrnColor, exactColor;
  1520.     Colormap cmap;
  1521.     char colorStr[BUFSIZ], cmapname[BUFSIZ];
  1522.     char tmpstr[BUFSIZ];
  1523.     char resultFormatStr[BUFSIZ];
  1524.     int nargs;
  1525.     Status retval;
  1526.     XcmsColorFormat result_format;
  1527.  
  1528.     if (!Check_init()) {
  1529.     return(0);
  1530.     }
  1531.  
  1532.     colorStr[0] = '\0';
  1533.     cmapname[0] = '\0';
  1534.     tmpstr[0] = '\0';
  1535.     resultFormatStr[0] = '\0';
  1536.  
  1537.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1538.     goto LookupColor_Usage;
  1539.     }
  1540.  
  1541.     if ((nargs = sscanf(buf, "%s %s",
  1542.         colorStr,
  1543.         resultFormatStr
  1544.         )) < 2) {
  1545.     printf("Invalid argument(s): %s\n", buf);
  1546. LookupColor_Usage:
  1547.     printf("Usage:\n");
  1548.     printf("    LookupColor <color_string> <result_format> [Colormap]\n\n");
  1549.     printf("    Where:\n");
  1550.     printf("\tcolor_string :== string\n");
  1551.     printf("\tresult_format :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  1552.     printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  1553.     printf("\tColormap :== string\n");
  1554.     return(0);
  1555.     }
  1556.     result_format = LtStrToDefine(FormatTbl, resultFormatStr);
  1557.     if (nargs < 3) {
  1558.     strcpy(cmapname, "TstCmap_AllocColor");
  1559.     }
  1560.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  1561.     printf("Error: Colormap named %s not found\n", cmapname);
  1562.     return(0);
  1563.     }
  1564.  
  1565.     printf("    REQUESTED:\n");
  1566.     printf("\tLookup:\t%s\n", colorStr);
  1567.     printf("\tresult_format:\t%s\n", resultFormatStr);
  1568.     printf("\tColormap:\t%s\n", cmapname);
  1569.     printf("    RESULT:\n");
  1570.     retval = XcmsLookupColor(pDpy, cmap, colorStr, &exactColor,
  1571.                  &scrnColor, result_format);
  1572.     if (!CheckPrintRetVal ("XcmsLookupColor", retval, NO_COMP_FLAG))
  1573.     return(0);
  1574.     printf("\tScreen:\n");
  1575.     PrintXcmsColor(&scrnColor);
  1576.     printf("\tExact:\n");
  1577.     PrintXcmsColorSpec(&exactColor);
  1578.     return(1);
  1579. }
  1580.  
  1581.  
  1582. /*
  1583.  *    NAME
  1584.  *        Cmd_AllocNamedColor - LibTest "AllocNamedColor" command
  1585.  *
  1586.  *    SYNOPSIS
  1587.  */
  1588. int
  1589. Cmd_AllocNamedColor(buf)
  1590.     char *buf;
  1591. /*
  1592.  *    DESCRIPTION
  1593.  *        "AllocNamedColor" command for LibTest.
  1594.  *
  1595.  *    RETURNS
  1596.  *        0=fail, 1=Success
  1597.  *
  1598.  */
  1599. {
  1600.     XcmsColor scrnColor;
  1601.     XcmsColor exactColor;
  1602.     Colormap cmap;
  1603.     int nargs;
  1604.     char colorStr[BUFSIZ], cmapname[BUFSIZ];
  1605.     XcmsColorFormat result_format;
  1606.     char resultFormatStr[BUFSIZ];
  1607.     char tmpstr[BUFSIZ];
  1608.     Status retval;
  1609.  
  1610.     if (!Check_init()) {
  1611.     return(0);
  1612.     }
  1613.  
  1614.     colorStr[0] = '\0';
  1615.     cmapname[0] = '\0';
  1616.     resultFormatStr[0] = '\0';
  1617.     tmpstr[0] = '\0';
  1618.  
  1619.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1620.     goto AllocNamedColor_Usage;
  1621.     }
  1622.  
  1623.     if ((nargs = sscanf(buf, "%s %s %s",
  1624.         colorStr,
  1625.         resultFormatStr,
  1626.         cmapname
  1627.         )) < 2) {
  1628.     printf("Invalid argument(s): %s\n", buf);
  1629. AllocNamedColor_Usage:
  1630.     printf("Usage:\n");
  1631.     printf("    AllocNamedColor <color_string> <result_format> [Colormap]\n\n");
  1632.     printf("    Where:\n");
  1633.     printf("\tcolor_string :== string\n");
  1634.     printf("\tresult_format :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  1635.     printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  1636.     printf("\tColormap :== string\n");
  1637.     return(0);
  1638.     }
  1639.     result_format = LtStrToDefine(FormatTbl, resultFormatStr);
  1640.     if (nargs < 3) {
  1641.     strcpy(cmapname, "TstCmap_AllocColor");
  1642.     }
  1643.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  1644.     printf("Error: Colormap named %s not found\n", cmapname);
  1645.     return(0);
  1646.     }
  1647.  
  1648.     printf("    REQUESTED:\n");
  1649.     printf("\tStore:\t%s\n", colorStr);
  1650.     printf("\tresult_format:\t%s\n", resultFormatStr);
  1651.     printf("\tColormap:\t%s\n", cmapname);
  1652.  
  1653.     printf("    RESULT:\n");
  1654.     retval = XcmsAllocNamedColor(pDpy, cmap, colorStr, &scrnColor, 
  1655.                  &exactColor, result_format);
  1656.     if (!CheckPrintRetVal ("XcmsAllocNamedColor", retval, COMP_FLAG))
  1657.     return(0);
  1658.     printf("\tScreen:\n");
  1659.     PrintXcmsColor(&scrnColor);
  1660.     printf("\tExact:\n");
  1661.     PrintXcmsColorSpec(&exactColor);
  1662.     return(1);
  1663. }
  1664.  
  1665.     /****************************************************
  1666.      *                            *
  1667.      *        QUERY GAMUT BOUNDARIES            *
  1668.      *                            *
  1669.      ****************************************************/
  1670.  
  1671. /*
  1672.  *    NAME
  1673.  *        Cmd_MaxChroma - LibTest "MaxChroma" command
  1674.  *
  1675.  *    SYNOPSIS
  1676.  */
  1677. int
  1678. Cmd_MaxChroma(buf)
  1679.     char *buf;
  1680. /*
  1681.  *    DESCRIPTION
  1682.  *        "MaxChroma" command for LibTest.
  1683.  *
  1684.  *    RETURNS
  1685.  *        0=fail, 1=Success
  1686.  *
  1687.  */
  1688. {
  1689.     XcmsColor HVC_return;
  1690.     char tmpstr[BUFSIZ];
  1691.  
  1692.     if (!Check_init()) {
  1693.     return(0);
  1694.     }
  1695.  
  1696.     tmpstr[0] = '\0';
  1697.  
  1698.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1699.     goto MaxChroma_Usage;
  1700.     }
  1701.  
  1702.     if (sscanf(buf, "%lf %lf",
  1703.         &HVC_return.spec.TekHVC.H,
  1704.         &HVC_return.spec.TekHVC.V
  1705.         ) < 2) {
  1706.     printf("Invalid argument(s): %s", buf);
  1707. MaxChroma_Usage:
  1708.     printf("Usage:\n");
  1709.     printf("    MaxChroma <Hue> <Value>\n\n");
  1710.     return(0);
  1711.     }
  1712.     HVC_return.spec.TekHVC.C = 0;
  1713.     HVC_return.format = XcmsTekHVCFormat;
  1714.     HVC_return.pixel = 0;
  1715.     printf("\tHUE VALUE IN:\n");
  1716.     PrintXcmsColorSpec(&HVC_return);
  1717.     if ((XcmsTekHVCQueryMaxC(_test_ccc,
  1718.         HVC_return.spec.TekHVC.H,
  1719.         HVC_return.spec.TekHVC.V,
  1720.         &HVC_return)) == 0) {
  1721.     printf("\tXcmsTekHVCQueryMaxC() returned FAIL\n");
  1722.     return(0);
  1723.     }
  1724.     printf("\tRESULT:\n");
  1725.     PrintXcmsColorSpec(&HVC_return);
  1726.     return(1);
  1727. }
  1728.  
  1729.  
  1730. /*
  1731.  *    NAME
  1732.  *        Cmd_MaxValue - LibTest "MaxValue" command
  1733.  *
  1734.  *    SYNOPSIS
  1735.  */
  1736. int
  1737. Cmd_MaxValue(buf)
  1738.     char *buf;
  1739. /*
  1740.  *    DESCRIPTION
  1741.  *        "MaxValue" command for LibTest.
  1742.  *
  1743.  *    RETURNS
  1744.  *        0=fail, 1=Success
  1745.  *
  1746.  */
  1747. {
  1748.     XcmsColor HVC_return;
  1749.     char tmpstr[BUFSIZ];
  1750.  
  1751.     if (!Check_init()) {
  1752.     return(0);
  1753.     }
  1754.  
  1755.     tmpstr[0] = '\0';
  1756.  
  1757.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1758.     goto MaxValue_Usage;
  1759.     }
  1760.  
  1761.     if (sscanf(buf, "%lf %lf",
  1762.         &HVC_return.spec.TekHVC.H,
  1763.         &HVC_return.spec.TekHVC.C
  1764.         ) < 2) {
  1765.     printf("Invalid argument(s): %s", buf);
  1766. MaxValue_Usage:
  1767.     printf("Usage:\n");
  1768.     printf("    MaxValue <Hue> <Chroma>\n\n");
  1769.     return(0);
  1770.     }
  1771.     HVC_return.spec.TekHVC.V = 0;
  1772.     HVC_return.format = XcmsTekHVCFormat;
  1773.     HVC_return.pixel = 0;
  1774.     printf("\tHUE CHROMA IN:\n");
  1775.     PrintXcmsColorSpec(&HVC_return);
  1776.     if ((XcmsTekHVCQueryMaxV(_test_ccc,
  1777.         HVC_return.spec.TekHVC.H,
  1778.         HVC_return.spec.TekHVC.C,
  1779.         &HVC_return)) == 0) {
  1780.     printf("\tXcmsTekHVCQueryMaxV() returned FAIL\n");
  1781.     return(0);
  1782.     }
  1783.     printf("\tRESULT:\n");
  1784.     PrintXcmsColorSpec(&HVC_return);
  1785.     return(1);
  1786. }
  1787.  
  1788.  
  1789. /*
  1790.  *    NAME
  1791.  *        Cmd_MaxValueSamples - LibTest "MaxValueSamples" command
  1792.  *
  1793.  *    SYNOPSIS
  1794.  */
  1795. int
  1796. Cmd_MaxValueSamples(buf)
  1797.     char *buf;
  1798. /*
  1799.  *    DESCRIPTION
  1800.  *        "MaxValueSamples" command for LibTest.
  1801.  *
  1802.  *    RETURNS
  1803.  *        0=fail, 1=Success
  1804.  *
  1805.  */
  1806. {
  1807.     XcmsColor *pHVC_return;
  1808.     XcmsFloat hue;
  1809.     char tmpstr[BUFSIZ];
  1810.     int nSamples;
  1811.  
  1812.     if (!Check_init()) {
  1813.     return(0);
  1814.     }
  1815.  
  1816.     tmpstr[0] = '\0';
  1817.  
  1818.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1819.     goto MaxValueSamples_Usage;
  1820.     }
  1821.  
  1822.     if (sscanf(buf, "%lf %d",
  1823.         &hue,
  1824.         &nSamples
  1825.         ) < 2) {
  1826.     printf("Invalid argument(s): %s", buf);
  1827. MaxValueSamples_Usage:
  1828.     printf("Usage:\n");
  1829.     printf("    MaxValueSamples <Hue> <nSamples>\n\n");
  1830.     return(0);
  1831.     }
  1832.     printf("\tHUE IN:\n");
  1833.     printf("\t    %lf\n", hue);
  1834.     pHVC_return = (XcmsColor *)calloc(nSamples, sizeof(XcmsColor));
  1835.     if (XcmsTekHVCQueryMaxVSamples(_test_ccc, hue, pHVC_return, nSamples) == 0) {
  1836.     printf("\tXcmsTekHVCQueryMaxVSamples() returned FAIL\n");
  1837.     free(pHVC_return);
  1838.     return(0);
  1839.     }
  1840.     printf("\tRESULT:\n");
  1841.     PrintXcmsColorSpecs(pHVC_return, nSamples);
  1842.     free(pHVC_return);
  1843.     return(1);
  1844. }
  1845.  
  1846.  
  1847. /*
  1848.  *    NAME
  1849.  *        Cmd_MaxValueChroma - LibTest "MaxValueChroma" command
  1850.  *
  1851.  *    SYNOPSIS
  1852.  */
  1853. int
  1854. Cmd_MaxValueChroma(buf)
  1855.     char *buf;
  1856. /*
  1857.  *    DESCRIPTION
  1858.  *        "MaxValueChroma" command for LibTest.
  1859.  *
  1860.  *    RETURNS
  1861.  *        0=fail, 1=Success
  1862.  *
  1863.  */
  1864. {
  1865.     XcmsColor HVC_return;
  1866.     char tmpstr[BUFSIZ];
  1867.  
  1868.     if (!Check_init()) {
  1869.     return(0);
  1870.     }
  1871.  
  1872.     tmpstr[0] = '\0';
  1873.  
  1874.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1875.     goto MaxValueChroma_Usage;
  1876.     }
  1877.  
  1878.     if (sscanf(buf, "%lf",
  1879.         &HVC_return.spec.TekHVC.H
  1880.         ) < 1) {
  1881.     printf("Invalid argument(s): %s", buf);
  1882. MaxValueChroma_Usage:
  1883.     printf("Usage:\n");
  1884.     printf("    MaxValueChroma <Hue>\n\n");
  1885.     return(0);
  1886.     }
  1887.     HVC_return.spec.TekHVC.V = HVC_return.spec.TekHVC.C = 0;
  1888.     HVC_return.format = XcmsTekHVCFormat;
  1889.     HVC_return.pixel = 0;
  1890.     printf("\tHUE IN:\n");
  1891.     PrintXcmsColorSpec(&HVC_return);
  1892.     if ((XcmsTekHVCQueryMaxVC(_test_ccc, HVC_return.spec.TekHVC.H,
  1893.         &HVC_return)) == 0) {
  1894.     printf("\tXcmsTekHVCQueryMaxVC() returned FAIL\n");
  1895.     return(0);
  1896.     }
  1897.     printf("\tRESULT:\n");
  1898.     PrintXcmsColorSpec(&HVC_return);
  1899.     return(1);
  1900. }
  1901.  
  1902.  
  1903. /*
  1904.  *    NAME
  1905.  *        Cmd_MinValue - LibTest "MinValue" command
  1906.  *
  1907.  *    SYNOPSIS
  1908.  */
  1909. int
  1910. Cmd_MinValue(buf)
  1911.     char *buf;
  1912. /*
  1913.  *    DESCRIPTION
  1914.  *        "MinValue" command for LibTest.
  1915.  *
  1916.  *    RETURNS
  1917.  *        0=fail, 1=Success
  1918.  *
  1919.  */
  1920. {
  1921.     XcmsColor HVC_return;
  1922.     char tmpstr[BUFSIZ];
  1923.  
  1924.     if (!Check_init()) {
  1925.     return(0);
  1926.     }
  1927.  
  1928.     tmpstr[0] = '\0';
  1929.  
  1930.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1931.     goto MinValue_Usage;
  1932.     }
  1933.  
  1934.     if (sscanf(buf, "%lf %lf",
  1935.         &HVC_return.spec.TekHVC.H,
  1936.         &HVC_return.spec.TekHVC.C
  1937.         ) < 2) {
  1938.     printf("Invalid argument(s): %s", buf);
  1939. MinValue_Usage:
  1940.     printf("Usage:\n");
  1941.     printf("    MinValue <Hue> <Chroma>\n\n");
  1942.     return(0);
  1943.     }
  1944.     HVC_return.spec.TekHVC.V = 0;
  1945.     HVC_return.format = XcmsTekHVCFormat;
  1946.     HVC_return.pixel = 0;
  1947.     printf("\tHUE CHROMA IN:\n");
  1948.     PrintXcmsColorSpec(&HVC_return);
  1949.     if ((XcmsTekHVCQueryMinV(_test_ccc,
  1950.         HVC_return.spec.TekHVC.H,
  1951.         HVC_return.spec.TekHVC.C,
  1952.         &HVC_return)) == 0) {
  1953.     printf("\tXcmsTekHVCQueryMinV() returned FAIL\n");
  1954.     return(0);
  1955.     }
  1956.     printf("\tRESULT:\n");
  1957.     PrintXcmsColorSpec(&HVC_return);
  1958.     return(1);
  1959. }
  1960.  
  1961.  
  1962. /*
  1963.  *    NAME
  1964.  *        Cmd_AdjustValue - LibTest "AdjustValue" command
  1965.  *
  1966.  *    SYNOPSIS
  1967.  */
  1968. int
  1969. Cmd_AdjustValue(buf)
  1970.     char *buf;
  1971. /*
  1972.  *    DESCRIPTION
  1973.  *        "AdjustValue" command for LibTest.
  1974.  *
  1975.  *    RETURNS
  1976.  *        0=fail, 1=Success
  1977.  *
  1978.  */
  1979. {
  1980.     XcmsColor HVC_return;
  1981.     char tmpstr[BUFSIZ];
  1982.     Bool compressed;
  1983.  
  1984.     if (!Check_init()) {
  1985.     return(0);
  1986.     }
  1987.  
  1988.     tmpstr[0] = '\0';
  1989.  
  1990.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  1991.     goto AdjustValue_Usage;
  1992.     }
  1993.  
  1994.     if (sscanf(buf, "%lf %lf %lf",
  1995.         &HVC_return.spec.TekHVC.H,
  1996.         &HVC_return.spec.TekHVC.V,
  1997.         &HVC_return.spec.TekHVC.C
  1998.         ) < 3) {
  1999.     printf("Invalid argument(s): %s", buf);
  2000. AdjustValue_Usage:
  2001.     printf("Usage:\n");
  2002.     printf("    AdjustValue <Hue> <Value> <Chroma>\n\n");
  2003.     return(0);
  2004.     }
  2005.     HVC_return.format = XcmsTekHVCFormat;
  2006.     HVC_return.pixel = 0;
  2007.     printf("\tHUE CHROMA IN:\n");
  2008.     PrintXcmsColorSpec(&HVC_return);
  2009.     if ((XcmsConvertColors(_test_ccc, &HVC_return, 1, 
  2010.                XcmsCIEXYZFormat, NULL))
  2011.     == XcmsFailure) {
  2012.     printf("\tXcmsConvertColors returned FAIL\n");
  2013.     return(0);
  2014.     }
  2015.     printf("\t  CIEXYZ IN:\n");
  2016.     PrintXcmsColorSpec(&HVC_return);
  2017.     if ((XcmsTekHVCClipV(_test_ccc, &HVC_return, 1, 0, &compressed)) == 0) {
  2018.     printf("\tXcmsTekHVCClipV() returned FAIL\n");
  2019.     return(0);
  2020.     }
  2021.     printf("\tRESULT:\n");
  2022.     printf("\t  CIEXYZ RETURN:\n");
  2023.     PrintXcmsColorSpec(&HVC_return);
  2024.     printf("\t  TekHVC RETURN:\n");
  2025.     if ((XcmsConvertColors(_test_ccc, &HVC_return, 1, XcmsTekHVCFormat, NULL))
  2026.     == XcmsFailure) {
  2027.     printf("\tXcmsConvertColors returned FAIL\n");
  2028.     return(0);
  2029.     }
  2030.     PrintXcmsColorSpec(&HVC_return);
  2031.     return(1);
  2032. }
  2033.  
  2034.  
  2035. /*
  2036.  *    NAME
  2037.  *        Cmd_ReduceChroma - LibTest "ReduceChroma" command
  2038.  *
  2039.  *    SYNOPSIS
  2040.  */
  2041. int
  2042. Cmd_ReduceChroma(buf)
  2043.     char *buf;
  2044. /*
  2045.  *    DESCRIPTION
  2046.  *        "ReduceChroma" command for LibTest.
  2047.  *
  2048.  *    RETURNS
  2049.  *        0=fail, 1=Success
  2050.  *
  2051.  */
  2052. {
  2053.     XcmsColor HVC_return;
  2054.     char tmpstr[BUFSIZ];
  2055.     Bool compressed;
  2056.  
  2057.     if (!Check_init()) {
  2058.     return(0);
  2059.     }
  2060.  
  2061.     tmpstr[0] = '\0';
  2062.  
  2063.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2064.     goto ReduceChroma_Usage;
  2065.     }
  2066.  
  2067.     if (sscanf(buf, "%lf %lf %lf",
  2068.         &HVC_return.spec.TekHVC.H,
  2069.         &HVC_return.spec.TekHVC.V,
  2070.         &HVC_return.spec.TekHVC.C
  2071.         ) < 3) {
  2072.     printf("Invalid argument(s): %s", buf);
  2073. ReduceChroma_Usage:
  2074.     printf("Usage:\n");
  2075.     printf("    ReduceChroma <Hue> <Value> <Chroma>\n\n");
  2076.     return(0);
  2077.     }
  2078.     HVC_return.format = XcmsTekHVCFormat;
  2079.     HVC_return.pixel = 0;
  2080.     printf("\tHUE CHROMA IN:\n");
  2081.     PrintXcmsColorSpec(&HVC_return);
  2082.     if ((XcmsConvertColors(_test_ccc, &HVC_return, 1, XcmsCIEXYZFormat, NULL))
  2083.     == XcmsFailure) {
  2084.     printf("\tXcmsConvertColors returned FAIL\n");
  2085.     return(0);
  2086.     }
  2087.     printf("\t  CIEXYZ IN:\n");
  2088.     PrintXcmsColorSpec(&HVC_return);
  2089.     if ((XcmsTekHVCClipC(_test_ccc, &HVC_return, 1, 0, &compressed)) == 0) {
  2090.     printf("\tXcmsTekHVCClipC() returned FAIL\n");
  2091.     return(0);
  2092.     }
  2093.     printf("\tRESULT:\n");
  2094.     printf("\t    CIEXYZ RETURN:\n");
  2095.     PrintXcmsColorSpec(&HVC_return);
  2096.     if ((XcmsConvertColors(_test_ccc, &HVC_return, 1, XcmsTekHVCFormat, NULL))
  2097.     == XcmsFailure) {
  2098.     printf("\tXcmsConvertColors returned FAIL\n");
  2099.     return(0);
  2100.     }
  2101.     printf("\t  TekHVC RETURN:\n");
  2102.     PrintXcmsColorSpec(&HVC_return);
  2103.     return(1);
  2104. }
  2105.  
  2106.  
  2107. /*
  2108.  *    NAME
  2109.  *        Cmd_ShortestValueChroma - LibTest "ShortestValueChroma" command
  2110.  *
  2111.  *    SYNOPSIS
  2112.  */
  2113. int
  2114. Cmd_ShortestValueChroma(buf)
  2115.     char *buf;
  2116. /*
  2117.  *    DESCRIPTION
  2118.  *        "ShortestValueChroma" command for LibTest.
  2119.  *
  2120.  *    RETURNS
  2121.  *        0=fail, 1=Success
  2122.  *
  2123.  */
  2124. {
  2125.     XcmsColor HVC_return;
  2126.     char tmpstr[BUFSIZ];
  2127.     Bool compressed;
  2128.  
  2129.     if (!Check_init()) {
  2130.     return(0);
  2131.     }
  2132.  
  2133.     tmpstr[0] = '\0';
  2134.  
  2135.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2136.     goto ShortestValueChroma_Usage;
  2137.     }
  2138.  
  2139.     if (sscanf(buf, "%lf %lf %lf",
  2140.         &HVC_return.spec.TekHVC.H,
  2141.         &HVC_return.spec.TekHVC.V,
  2142.         &HVC_return.spec.TekHVC.C
  2143.         ) < 3) {
  2144.     printf("Invalid argument(s): %s", buf);
  2145. ShortestValueChroma_Usage:
  2146.     printf("Usage:\n");
  2147.     printf("    ShortestValueChroma <Hue> <Value> <Chroma>\n\n");
  2148.     return(0);
  2149.     }
  2150.     HVC_return.format = XcmsTekHVCFormat;
  2151.     HVC_return.pixel = 0;
  2152.     printf("\tHUE CHROMA IN:\n");
  2153.     PrintXcmsColorSpec(&HVC_return);
  2154.     if ((XcmsConvertColors(_test_ccc, &HVC_return, 1, XcmsCIEXYZFormat, NULL))
  2155.     == XcmsFailure) {
  2156.     printf("\tXcmsConvertColors returned FAIL\n");
  2157.     return(0);
  2158.     }
  2159.     printf("\t  CIEXYZ IN:\n");
  2160.     PrintXcmsColorSpec(&HVC_return);
  2161.     if ((XcmsTekHVCClipVC(_test_ccc, &HVC_return, 1, 0,
  2162.     &compressed)) == 0) {
  2163.     printf("\tXcmsTekHVCClipVC() returned FAIL\n");
  2164.     return(0);
  2165.     }
  2166.     printf("\tRESULT:\n");
  2167.     printf("\t    CIEXYZ RETURN:\n");
  2168.     PrintXcmsColorSpec(&HVC_return);
  2169.     if ((XcmsConvertColors(_test_ccc, &HVC_return, 1, XcmsTekHVCFormat, NULL))
  2170.     == XcmsFailure) {
  2171.     printf("\tXcmsConvertColors returned FAIL\n");
  2172.     return(0);
  2173.     }
  2174.     printf("\t  TekHVC RETURN:\n");
  2175.     PrintXcmsColorSpec(&HVC_return);
  2176.     return(1);
  2177. }
  2178.  
  2179.  
  2180.     /****************************************************
  2181.      *                            *
  2182.      *        COLOR SPACE EXTENSION            *
  2183.      *                            *
  2184.      ****************************************************/
  2185.  
  2186. /*
  2187.  *    NAME
  2188.  *        Cmd_PrefixOfId - LibTest "PrefixOfId" command
  2189.  *
  2190.  *    SYNOPSIS
  2191.  */
  2192. int
  2193. Cmd_PrefixOfId(buf)
  2194.     char *buf;
  2195. /*
  2196.  *    DESCRIPTION
  2197.  *        "PrefixOfId" command for LibTest.
  2198.  *
  2199.  *    RETURNS
  2200.  *        0=fail, 1=Success
  2201.  *
  2202.  */
  2203. {
  2204.     char tmpstr[BUFSIZ];
  2205.     char formatStr[BUFSIZ];
  2206.     char *prefix;
  2207.     XcmsColorFormat formatID;
  2208.  
  2209.     tmpstr[0] = '\0';
  2210.     formatStr[0] = '\0';
  2211.  
  2212.     if (!Check_init()) {
  2213.     return(0);
  2214.     }
  2215.  
  2216.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2217.     goto PrefixOfId_Usage;
  2218.     }
  2219.  
  2220.     if (sscanf(buf, "%s", formatStr) < 1) {
  2221.     printf("Invalid argument(s): %s\n", buf);
  2222. PrefixOfId_Usage:
  2223.     printf("Usage:\n");
  2224.     printf("    PrefixOfId <Format>\n\n");
  2225.     printf("    Where:\n");
  2226.     printf("\tFormat :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  2227.     printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  2228.     return(0);
  2229.     }
  2230.     formatID = LtStrToDefine(FormatTbl, formatStr);
  2231.  
  2232.     printf("    REQUESTED:\n");
  2233.     printf("\tFormat:\t%s\n", formatStr);
  2234.  
  2235.     printf("    RESULT:\n");
  2236.     if ((prefix = XcmsPrefixOfFormat(formatID)) == NULL) {
  2237.     printf("\tXcmsPrefixOfFormat() returned NULL\n");
  2238.     return(0);
  2239.     }
  2240.     printf("\tXcmsPrefixOfFormat() returned %s\n", prefix);
  2241.     return(1);
  2242. }
  2243.  
  2244. /*
  2245.  *    NAME
  2246.  *        Cmd_FormatOfPrefix - LibTest "FormatOfPrefix" command
  2247.  *
  2248.  *    SYNOPSIS
  2249.  */
  2250. int
  2251. Cmd_FormatOfPrefix(buf)
  2252.     char *buf;
  2253. /*
  2254.  *    DESCRIPTION
  2255.  *        "FormatOfPrefix" command for LibTest.
  2256.  *
  2257.  *    RETURNS
  2258.  *        0=fail, 1=Success
  2259.  *
  2260.  */
  2261. {
  2262.     char tmpstr[BUFSIZ];
  2263.     char prefix[BUFSIZ];
  2264.     XcmsColorFormat formatID;
  2265.  
  2266.     tmpstr[0] = '\0';
  2267.     prefix[0] = '\0';
  2268.  
  2269.     if (!Check_init()) {
  2270.     return(0);
  2271.     }
  2272.  
  2273.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2274.     goto FormatOfPrefix_Usage;
  2275.     }
  2276.  
  2277.     if (sscanf(buf, "%s", prefix) < 1) {
  2278.     printf("Invalid argument(s): %s\n", buf);
  2279. FormatOfPrefix_Usage:
  2280.     printf("Usage:\n");
  2281.     printf("    FormatOfPrefix <prefix>\n\n");
  2282.     printf("    Where:\n");
  2283.     printf("\tprefix :== string\n");
  2284.     return(0);
  2285.     }
  2286.  
  2287.     printf("    REQUESTED:\n");
  2288.     printf("\tprefix:\t%s\n", prefix);
  2289.  
  2290.     printf("    RESULT:\n");
  2291.     formatID = XcmsFormatOfPrefix(prefix);
  2292.     printf("\tXcmsFormatOfPrefix() returned %u\n", formatID);
  2293.     printf("\t    %s\n", LtDefineToStr(FormatTbl, (int)formatID));
  2294.     return(1);
  2295. }
  2296.  
  2297. /*
  2298.  *    NAME
  2299.  *        Cmd_AddDIColorSpace - LibTest "AddDIColorSpace" command
  2300.  *
  2301.  *    SYNOPSIS
  2302.  */
  2303. int
  2304. Cmd_AddDIColorSpace(buf)
  2305.     char *buf;
  2306. /*
  2307.  *    DESCRIPTION
  2308.  *        "AddDIColorSpace" command for LibTest.
  2309.  *
  2310.  *    RETURNS
  2311.  *        0=fail, 1=Success
  2312.  *
  2313.  */
  2314. {
  2315.     char tmpstr[BUFSIZ];
  2316.     char colorspaceStr[BUFSIZ];
  2317.     XcmsColorSpace *pSCCFuncSet = NULL;
  2318.     Status retval;
  2319.  
  2320.     tmpstr[0] = '\0';
  2321.     colorspaceStr[0] = '\0';
  2322.  
  2323.     if (!Check_init()) {
  2324.     return(0);
  2325.     }
  2326.  
  2327.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2328.     goto AddDIColorSpace_Usage;
  2329.     }
  2330.  
  2331.     if (sscanf(buf, "%s", colorspaceStr) < 1) {
  2332.     printf("Invalid argument(s): %s\n", buf);
  2333. AddDIColorSpace_Usage:
  2334.     printf("Usage:\n");
  2335.     printf("    AddDIColorSpace <Format>\n\n");
  2336.     printf("    Where:\n");
  2337.     printf("\tFormat :== CIELab | CIELuv | TekHVC\n");
  2338.     return(0);
  2339.     }
  2340.     if (strcmp(colorspaceStr, "CIELab") == 0) {
  2341.     pSCCFuncSet = &XcmsCIELabColorSpace;
  2342.     } else if (strcmp(colorspaceStr, "CIELuv") == 0) {
  2343.     pSCCFuncSet = &XcmsCIELuvColorSpace;
  2344.     } else if (strcmp(colorspaceStr, "TekHVC") == 0) {
  2345.     pSCCFuncSet = &XcmsTekHVCColorSpace;
  2346.     }
  2347.  
  2348.     printf("    REQUESTED:\n");
  2349.     printf("\tFormat:\t%s\n", colorspaceStr);
  2350.  
  2351.     printf("    RESULT:\n");
  2352.     retval = XcmsAddColorSpace(pSCCFuncSet);
  2353.     return(CheckPrintRetVal("XcmsAddColorSpace", retval, NO_COMP_FLAG));
  2354. }
  2355.  
  2356. /*
  2357.  *    NAME
  2358.  *        Cmd_XAllocNamedColor - LibTest "XAllocNamedColor" command
  2359.  *
  2360.  *    SYNOPSIS
  2361.  */
  2362. int
  2363. Cmd_XAllocNamedColor(buf)
  2364.     char *buf;
  2365. /*
  2366.  *    DESCRIPTION
  2367.  *        "XAllocNamedColor" command for LibTest.
  2368.  *
  2369.  *    RETURNS
  2370.  *        0=fail, 1=Success
  2371.  *
  2372.  */
  2373. {
  2374.     Colormap cmap;
  2375.     XColor hardware_def;
  2376.     XColor rgb_db_def;
  2377.     int nargs;
  2378.     char exactFormatStr[BUFSIZ];
  2379.     char colorStr[BUFSIZ];
  2380.     char cmapname[BUFSIZ];
  2381.     char tmpstr[BUFSIZ];
  2382.  
  2383.     if (!Check_init()) {
  2384.     return(0);
  2385.     }
  2386.  
  2387.     exactFormatStr[0] = '\0';
  2388.     colorStr[0] = '\0';
  2389.     cmapname[0] = '\0';
  2390.     tmpstr[0] = '\0';
  2391.  
  2392.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2393.     goto XAllocNamedColor_Usage;
  2394.     }
  2395.  
  2396.     if ((nargs = sscanf(buf, "%s %s", colorStr, cmapname)) < 1) {
  2397.     printf("Invalid argument(s): %s\n", buf);
  2398. XAllocNamedColor_Usage:
  2399.     printf("Usage:\n");
  2400.     printf("    XAllocNamedColor <color_string> [Colormap]\n\n");
  2401.     printf("    Where:\n");
  2402.     printf("\tcolor_string :== string\n");
  2403.     printf("\tColormap :== string\n");
  2404.     return(0);
  2405.     }
  2406.     if (nargs < 2) {
  2407.     strcpy(cmapname, "TstCmap_AllocColor");
  2408.     }
  2409.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  2410.     printf("Error: Colormap named %s not found\n", cmapname);
  2411.     return(0);
  2412.     }
  2413.  
  2414.     printf("    REQUESTED:\n");
  2415.     printf("\tColor String:\t%s\n", colorStr);
  2416.     printf("\tColormap:\t%s\n", cmapname);
  2417.     printf("    RESULT:\n");
  2418.     if ((XAllocNamedColor(pDpy, cmap, colorStr, &hardware_def,
  2419.         &rgb_db_def)) == 0) {
  2420.     printf("\tXcmsAllocNamedColor() returned FAIL\n");
  2421.     return(0);
  2422.     }
  2423.     printf("\t    rgb_db_def.red   = 0x%x\n", rgb_db_def.red);
  2424.     printf("\t    rgb_db_def.green = 0x%x\n", rgb_db_def.green);
  2425.     printf("\t    rgb_db_def.blue  = 0x%x\n", rgb_db_def.blue);
  2426.     printf("\t    hardware_def.pixel   = %d\n", hardware_def.pixel);
  2427.     printf("\t    hardware_def.red   = 0x%x\n", hardware_def.red);
  2428.     printf("\t    hardware_def.green = 0x%x\n", hardware_def.green);
  2429.     printf("\t    hardware_def.blue  = 0x%x\n", hardware_def.blue);
  2430.     return(1);
  2431. }
  2432.  
  2433.  
  2434. /*
  2435.  *    NAME
  2436.  *        Cmd_XLookupColor - LibTest "XLookupColor" command
  2437.  *
  2438.  *    SYNOPSIS
  2439.  */
  2440. int
  2441. Cmd_XLookupColor(buf)
  2442.     char *buf;
  2443. /*
  2444.  *    DESCRIPTION
  2445.  *        "XLookupColor" command for LibTest.
  2446.  *
  2447.  *    RETURNS
  2448.  *        0=fail, 1=Success
  2449.  *
  2450.  */
  2451. {
  2452.     Colormap cmap;
  2453.     XColor hardware_def;
  2454.     XColor rgb_db_def;
  2455.     int nargs;
  2456.     char colorStr[BUFSIZ];
  2457.     char cmapname[BUFSIZ];
  2458.     char tmpstr[BUFSIZ];
  2459.  
  2460.     if (!Check_init()) {
  2461.     return(0);
  2462.     }
  2463.  
  2464.     colorStr[0] = '\0';
  2465.     cmapname[0] = '\0';
  2466.     tmpstr[0] = '\0';
  2467.  
  2468.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2469.     goto XLookupColor_Usage;
  2470.     }
  2471.  
  2472.     if ((nargs = sscanf(buf, "%s %s %s", colorStr, cmapname)) < 1) {
  2473.     printf("Invalid argument(s): %s\n", buf);
  2474. XLookupColor_Usage:
  2475.     printf("Usage:\n");
  2476.     printf("    XLookupColor <color_string> [Colormap]\n\n");
  2477.     printf("    Where:\n");
  2478.     printf("\tcolor_string :== string\n");
  2479.     printf("\tColormap :== string\n");
  2480.     return(0);
  2481.     }
  2482.     if (nargs < 3) {
  2483.     strcpy(cmapname, "TstCmap_AllocColor");
  2484.     }
  2485.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  2486.     printf("Error: Colormap named %s not found\n", cmapname);
  2487.     return(0);
  2488.     }
  2489.  
  2490.     printf("    REQUESTED:\n");
  2491.     printf("\tColor String:\t%s\n", colorStr);
  2492.     printf("\tColormap:\t%s\n", cmapname);
  2493.     printf("    RESULT:\n");
  2494.     if ((XLookupColor(pDpy, cmap, colorStr, &rgb_db_def, &hardware_def)) == 0) {
  2495.     printf("\tXLookupColor() returned FAIL\n");
  2496.     return(0);
  2497.     }
  2498.     printf("\t    rgb_db_def.red   = 0x%x\n", rgb_db_def.red);
  2499.     printf("\t    rgb_db_def.green = 0x%x\n", rgb_db_def.green);
  2500.     printf("\t    rgb_db_def.blue  = 0x%x\n", rgb_db_def.blue);
  2501.     printf("\t    hardware_def.red   = 0x%x\n", hardware_def.red);
  2502.     printf("\t    hardware_def.green = 0x%x\n", hardware_def.green);
  2503.     printf("\t    hardware_def.blue  = 0x%x\n", hardware_def.blue);
  2504.     return(1);
  2505. }
  2506.  
  2507.  
  2508. /*
  2509.  *    NAME
  2510.  *        Cmd_XParseColor - LibTest "XParseColor" command
  2511.  *
  2512.  *    SYNOPSIS
  2513.  */
  2514. int
  2515. Cmd_XParseColor(buf)
  2516.     char *buf;
  2517. /*
  2518.  *    DESCRIPTION
  2519.  *        "XParseColor" command for LibTest.
  2520.  *
  2521.  *    RETURNS
  2522.  *        0=fail, 1=Success
  2523.  *
  2524.  */
  2525. {
  2526.     Colormap cmap;
  2527.     XColor exactSpec;
  2528.     int nargs;
  2529.     char exactFormatStr[BUFSIZ];
  2530.     char colorStr[BUFSIZ];
  2531.     char cmapname[BUFSIZ];
  2532.     char tmpstr[BUFSIZ];
  2533.  
  2534.     if (!Check_init()) {
  2535.     return(0);
  2536.     }
  2537.  
  2538.     exactFormatStr[0] = '\0';
  2539.     colorStr[0] = '\0';
  2540.     cmapname[0] = '\0';
  2541.     tmpstr[0] = '\0';
  2542.  
  2543.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2544.     goto XParseColor_Usage;
  2545.     }
  2546.  
  2547.     if ((nargs = sscanf(buf, "%s %s", colorStr, cmapname)) < 1) {
  2548.     printf("Invalid argument(s): %s\n", buf);
  2549. XParseColor_Usage:
  2550.     printf("Usage:\n");
  2551.     printf("    XParseColor <color_string> [colormap]\n\n");
  2552.     return(0);
  2553.     }
  2554.     if (nargs < 2) {
  2555.     strcpy(cmapname, "TstCmap_AllocColor");
  2556.     }
  2557.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  2558.     printf("Error: Colormap named %s not found\n", cmapname);
  2559.     return(0);
  2560.     }
  2561.  
  2562.     printf("    REQUESTED:\n");
  2563.     printf("\tParse:\t%s\n", colorStr);
  2564.     printf("\tColormap:\t%s\n", cmapname);
  2565.     printf("    RESULT:\n");
  2566.     if ((XParseColor(pDpy, cmap, colorStr, &exactSpec)) == 0) {
  2567.     printf("\tXcmsParseColor() returned FAIL\n");
  2568.     return(0);
  2569.     }
  2570.     printf("\t    spec.red   = 0x%x\n", exactSpec.red);
  2571.     printf("\t    spec.green = 0x%x\n", exactSpec.green);
  2572.     printf("\t    spec.blue  = 0x%x\n", exactSpec.blue);
  2573.     return(1);
  2574. }
  2575.  
  2576.  
  2577. /*
  2578.  *    NAME
  2579.  *        Cmd_XStoreNamedColor - LibTest "StoreNamedColor" command
  2580.  *
  2581.  *    SYNOPSIS
  2582.  */
  2583. int
  2584. Cmd_XStoreNamedColor(buf)
  2585.     char *buf;
  2586. /*
  2587.  *    DESCRIPTION
  2588.  *        "XStoreNamedColor" command for LibTest.
  2589.  *
  2590.  *    RETURNS
  2591.  *        0=fail, 1=Success
  2592.  *
  2593.  */
  2594. {
  2595.     Colormap cmap;
  2596.     int nargs;
  2597.     char colorStr[BUFSIZ], cmapname[BUFSIZ];
  2598.     char tmpstr[BUFSIZ];
  2599.     unsigned long pixel;
  2600.  
  2601.     colorStr[0] = '\0';
  2602.     cmapname[0] = '\0';
  2603.     tmpstr[0] = '\0';
  2604.  
  2605.  
  2606.     if (!Check_init()) {
  2607.     return(0);
  2608.     }
  2609.  
  2610.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2611.     goto XStoreNamedColor_Usage;
  2612.     }
  2613.  
  2614.     if ((nargs = sscanf(buf, "%s %lu %s %s",
  2615.         colorStr,
  2616.         &pixel,
  2617.         cmapname
  2618.         )) < 2) {
  2619.     printf("Invalid argument(s): %s\n", buf);
  2620. XStoreNamedColor_Usage:
  2621.     printf("Usage:\n");
  2622.     printf("    XStoreNamedColor <color_string> <pixel> [Colormap]\n\n");
  2623.     printf("    Where:\n");
  2624.     printf("\tcolor_string :== string\n");
  2625.     printf("\tpixel :== unsigned int\n");
  2626.     printf("\tColormap :== string\n");
  2627.     return(0);
  2628.     }
  2629.     if (nargs < 3) {
  2630.     strcpy(cmapname, "TstCmap_StoreColor");
  2631.     }
  2632.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  2633.     printf("Error: Colormap named %s not found\n", cmapname);
  2634.     return(0);
  2635.     }
  2636.  
  2637.     printf("    REQUESTED:\n");
  2638.     printf("\tStore:\t%s\n", colorStr);
  2639.     printf("\tpixel:\t%lu\n", pixel);
  2640.     printf("\tColormap:\t%s\n\n", cmapname);
  2641.  
  2642.     XStoreNamedColor(pDpy, cmap, colorStr, pixel, DoRed | DoGreen | DoBlue);
  2643.     printf("\tXStoreNamedColor() has no return value\n");
  2644.     printf("\t    Use QueryColor() to see what was stored\n");
  2645.     return(1);
  2646. }
  2647.  
  2648. /*
  2649.  *    NAME
  2650.  *        Cmd_StoreColors - LibTest "StoreColors" command
  2651.  *
  2652.  *    SYNOPSIS
  2653.  */
  2654. int
  2655. Cmd_StoreColors(buf)
  2656.     char *buf;
  2657. /*
  2658.  *    DESCRIPTION
  2659.  *        "StoreColors" command for LibTest.
  2660.  *
  2661.  *    RETURNS
  2662.  *        0=fail, 1=Success
  2663.  *
  2664.  */
  2665. {
  2666.     Colormap cmap;
  2667.     XcmsColor color[MAXCOLORS];
  2668.     Bool compressed[MAXCOLORS];
  2669.     char firstFormatStr[BUFSIZ];
  2670.     char formatStr[BUFSIZ];
  2671.     char cmapname[BUFSIZ];
  2672.     char stim1[BUFSIZ];
  2673.     char stim2[BUFSIZ];
  2674.     char stim3[BUFSIZ];
  2675.     char tmpstr[BUFSIZ];
  2676.     int begin;
  2677.     Status retval;
  2678.     int ncolors;
  2679.  
  2680.     if (!Check_init()) {
  2681.     return(0);
  2682.     }
  2683.  
  2684.     firstFormatStr[0] = '\0';
  2685.     formatStr[0] = '\0';
  2686.     cmapname[0] = '\0';
  2687.     stim1[0] = '\0';
  2688.     stim2[0] = '\0';
  2689.     stim3[0] = '\0';
  2690.     tmpstr[0] = '\0';
  2691.  
  2692.     if (sscanf(buf, "%s", tmpstr) && (strcmp("-help", tmpstr) == 0)) {
  2693.     goto StoreColors_Usage;
  2694.     }
  2695.  
  2696.     if (sscanf(buf, "%s", cmapname) < 1) {
  2697.     strcpy(cmapname, "TstCmap_StoreColor");
  2698.     }
  2699.     if (StrToCmap(CmapTbl, cmapname, &cmap) == 0) {
  2700.     printf("Error: Colormap named %s not found\n", cmapname);
  2701.     return(0);
  2702.     }
  2703.  
  2704.     printf("    REQUESTED:\n");
  2705.     printf("\tColormap:\t%s\n", cmapname);
  2706.     printf("\tPixel\tFormat\tStim1\tStim2\tStim3\n");
  2707.     for(ncolors = 0;;) {
  2708.     if (ncolors >= MAXCOLORS) {
  2709.         return(0);
  2710.     }
  2711.     if (fgets(buf, BUFSIZ, stdin) == NULL) {
  2712.         return(0);
  2713.     }
  2714.     if (EchoInput) {
  2715.         printf("%s", buf);
  2716.     }
  2717.     if (buf[0] == LIBTEST_COMMENT_CHAR) {
  2718.         continue;
  2719.     }
  2720.     if (strcmp(buf, "BEGIN\n") == 0) {
  2721.         begin = 1;
  2722.         continue;
  2723.     }
  2724.     if (begin && (strcmp(buf, "END\n") == 0)) {
  2725.         break;
  2726.     }
  2727.     if (!begin) {
  2728.         goto StoreColors_Usage;
  2729.     } 
  2730.     if (sscanf(buf, "%d %s %s %s %s",
  2731.         &color[ncolors].pixel,
  2732.         formatStr,
  2733.         stim1,
  2734.         stim2,
  2735.         stim3
  2736.         ) < 5) {
  2737.         printf("Invalid argument(s): %s\n", buf);
  2738. StoreColors_Usage:
  2739.         printf("Usage:\n");
  2740.         printf("    StoreColors [Colormap]\n");
  2741.         printf("\tBEGIN\n");
  2742.         printf("\t<Pixel>\t<Format>\t<Stim1>\t<Stim2>\t<Stim3>\n");
  2743.         printf("\t<Pixel>\t<Format>\t<Stim1>\t<Stim2>\t<Stim3>\n");
  2744.         printf("\t.\t.\t.\t.\t.\n");
  2745.         printf("\t.\t.\t.\t.\t.\n");
  2746.         printf("\t.\t.\t.\t.\t.\n");
  2747.         printf("\tEND\n\n");
  2748.         printf("    Where:\n");
  2749.         printf("\tPixel :== integer\n");
  2750.         printf("\tFormat :== UNDEFINED | CIEXYZ | CIExyY | CIEuvY\n");
  2751.         printf("\t    | CIELab | CIELuv | TekHVC | RGBi | RGB\n");
  2752.         printf("\tStim1,Stim2,Stim3 :== int for RGB, otherwise float\n");
  2753.         printf("\tColormap :== string\n");
  2754.         return(0);
  2755.     }
  2756.     color[ncolors].format = LtStrToDefine(FormatTbl, formatStr);
  2757.     if (color[ncolors].format == XcmsRGBFormat) {
  2758.         color[ncolors].spec.RGB.red = atoi(stim1);
  2759.         color[ncolors].spec.RGB.green = atoi(stim2);
  2760.         color[ncolors].spec.RGB.blue = atoi(stim3);
  2761.     } else {
  2762.         color[ncolors].spec.CIEXYZ.X = atof(stim1);
  2763.         color[ncolors].spec.CIEXYZ.Y = atof(stim2);
  2764.         color[ncolors].spec.CIEXYZ.Z = atof(stim3);
  2765.     }
  2766.     printf("\t%5lu\t%s\t%s\t%s\t%s\n", color[ncolors].pixel, formatStr,
  2767.         stim1, stim2, stim3);
  2768.     if (ncolors == 0)
  2769.         strcpy (firstFormatStr, formatStr);
  2770.     ncolors++;
  2771.     }
  2772.  
  2773.     printf("\tFormat:\t%s\n", firstFormatStr);
  2774.     printf("    REQUESTED:\n");
  2775.     printf("\tColormap:\t%s\n", cmapname);
  2776.     PrintXcmsColors(color, ncolors);
  2777.     printf("    RESULT:\n");
  2778.     retval = XcmsStoreColors(pDpy, cmap, color, ncolors, compressed);
  2779.     if (!CheckPrintRetVal ("XcmsStoreColors", retval, COMP_FLAG))
  2780.     return(0);
  2781.     return(1);
  2782. }
  2783.