From 54b7f6247be611d1f357220a59be05322d78998a Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 30 Apr 2022 11:02:27 -0700 Subject: Adopt X.Org standard coding style Signed-off-by: Alan Coopersmith --- loadData.c | 2340 +++++++++++++++++++++++++++++++----------------------------- xcmsdb.c | 1124 +++++++++++++++-------------- 2 files changed, 1767 insertions(+), 1697 deletions(-) diff --git a/loadData.c b/loadData.c index e1bb2a0..ef4e335 100644 --- a/loadData.c +++ b/loadData.c @@ -123,8 +123,9 @@ static DefineEntry VisualOptKeyTbl[] = { { "blue_mask", KEY_BLUE_MASK }, { "colormap_size", KEY_COLORMAP_SIZE }, { "bits_per_rgb", KEY_BITS_PER_RGB }, - { "", -1 } + { "", -1 } }; + static DefineEntry VisualClassTbl[] = { { "StaticGray", StaticGray }, { "GrayScale", GrayScale }, @@ -132,7 +133,7 @@ static DefineEntry VisualClassTbl[] = { { "PseudoColor", PseudoColor }, { "TrueColor", TrueColor }, { "DirectColor", DirectColor }, - { "", -1 } + { "", -1 } }; @@ -149,9 +150,9 @@ static DefineEntry VisualClassTbl[] = { * SYNOPSIS */ static int -StrToDefine(DefineEntry pde[], /* IN: table of X string-define pairs */ - /* last entry must contain pair "", 0 */ - const char *pstring) /* IN: string to be looked up in that table */ +StrToDefine(DefineEntry pde[], /* IN: table of X string-define pairs */ + /* last entry must contain pair "", 0 */ + const char *pstring) /* IN: string to be looked up in that table */ /* * DESCRIPTION * Converts a string to an integer define. @@ -169,13 +170,13 @@ StrToDefine(DefineEntry pde[], /* IN: table of X string-define pairs */ * */ { - while( strcmp(pde->pString,"") != 0 ){ - if( strcmp(pde->pString,pstring) == 0){ - return(pde->define); - } - pde++; + while (strcmp(pde->pString, "") != 0) { + if (strcmp(pde->pString, pstring) == 0) { + return (pde->define); + } + pde++; } - return(-1); + return (-1); } /* @@ -185,9 +186,9 @@ StrToDefine(DefineEntry pde[], /* IN: table of X string-define pairs */ * SYNOPSIS */ static const char * -DefineToStr(DefineEntry pde[], /* IN: table of X string-define pairs */ - /* last entry must contain pair "", 0 */ - int id) /* IN: id to be looked up in that table */ +DefineToStr(DefineEntry pde[], /* IN: table of X string-define pairs */ + /* last entry must contain pair "", 0 */ + int id) /* IN: id to be looked up in that table */ /* * DESCRIPTION * Converts a string to an integer define. @@ -205,13 +206,13 @@ DefineToStr(DefineEntry pde[], /* IN: table of X string-define pairs */ * */ { - while(pde->define != -1) { - if (pde->define == id) { - return(pde->pString); - } - pde++; + while (pde->define != -1) { + if (pde->define == id) { + return (pde->pString); + } + pde++; } - return(NULL); + return (NULL); } /* @@ -239,9 +240,8 @@ SCKeyOf(const char *string) * */ { - return(StrToDefine(KeyTbl, string)); + return (StrToDefine(KeyTbl, string)); } - /* * NAME @@ -268,9 +268,8 @@ SCScrnClassOf(const char *string) * */ { - return(StrToDefine(ScrnClassTbl, string)); + return (StrToDefine(ScrnClassTbl, string)); } - /* * NAME @@ -289,22 +288,22 @@ SCScrnClassStringOf(int id) * */ { - return(DefineToStr(ScrnClassTbl, id)); + return (DefineToStr(ScrnClassTbl, id)); } /* close the stream and return any memory allocated. */ -/*ARGSUSED*/ static void closeS(FILE *stream, XDCCC_Correction *pCorrection) { - XDCCC_Correction* pNext; + XDCCC_Correction *pNext; + if (stream) { - fclose (stream); + fclose(stream); } while (pCorrection) { - pNext = pCorrection->next; - free(pCorrection); - pCorrection = pNext; + pNext = pCorrection->next; + free(pCorrection); + pCorrection = pNext; } } @@ -317,7 +316,6 @@ nextline(char *buf, int maxch, FILE *stream) linenum++; return (fgets(buf, maxch, stream)); } - static int ProcessColorimetric(FILE *stream, XDCCC_Matrix *pMatrix, int VisualFlag) @@ -338,175 +336,178 @@ ProcessColorimetric(FILE *stream, XDCCC_Matrix *pMatrix, int VisualFlag) XcmsFloat *pElement = NULL; while ((nextline(buf, BUFSIZ, stream)) != NULL) { - if ((ntok = sscanf(buf, "%s %s", keyword, token)) > 0) { - switch (SCKeyOf(keyword)) { - case XYZTORGBMAT_BEGIN : - if (VisualFlag != VIDEO_RGB) { - fprintf(stderr, - "Line %d: Keyword XYZTORGBMAT_BEGIN mismatch for visual %s.\n", - linenum, SCScrnClassStringOf(VisualFlag)); - return (0); - } - if (state != 0) { - fprintf(stderr, - "Line %d: Extraneous keyword %s.\n", - linenum, keyword); - return (0); - } - state = 1; - count = 0; - pElement = (XcmsFloat *) pMatrix->XYZtoRGBmatrix; - break; - case XYZTORGBMAT_END : - if (VisualFlag != VIDEO_RGB) { - fprintf(stderr, - "Line %d: Keyword XYZTORGBMAT_END mismatch for visual %s.\n", - linenum, SCScrnClassStringOf(VisualFlag)); - return (0); - } - if ((state != 1) || (count != 9)) { - fprintf(stderr, - "Line %d: Incomplete XYZtoRGB matrix -- Premature %s\n", - linenum, keyword); - return (0); - } - matrices_processed |= 0x1; - if (matrices_processed == 3) { - state = 2; - } else { - state = 0; - } - break; - case RGBTOXYZMAT_BEGIN : - if (VisualFlag != VIDEO_RGB) { - fprintf(stderr, - "Line %d: Keyword RGBTOXYZMAT_BEGIN mismatch for visual %s.\n", - linenum, SCScrnClassStringOf(VisualFlag)); - return (0); - } - if (state != 0) { - fprintf(stderr, "Line %d: Extraneous keyword %s.\n", - linenum, keyword); - return (0); - } - state = 1; - count = 0; - pElement = (XcmsFloat *) pMatrix->RGBtoXYZmatrix; - break; - case RGBTOXYZMAT_END : - if (VisualFlag != VIDEO_RGB) { - fprintf(stderr, - "Line %d: Keyword RGBTOXYZMAT_END mismatch for visual %s.\n", - linenum, SCScrnClassStringOf(VisualFlag)); - return (0); - } - if ((state != 1) || (count != 9)) { - fprintf(stderr, - "Line %d: Incomplete RGBtoXYZ matrix -- Premature %s\n", - linenum, keyword); - return (0); - } - matrices_processed |= 0x2; - if (matrices_processed == 3) { - state = 2; - } else { - state = 0; - } - break; + if ((ntok = sscanf(buf, "%s %s", keyword, token)) > 0) { + switch (SCKeyOf(keyword)) { + case XYZTORGBMAT_BEGIN: + if (VisualFlag != VIDEO_RGB) { + fprintf(stderr, + "Line %d: Keyword XYZTORGBMAT_BEGIN mismatch for visual %s.\n", + linenum, SCScrnClassStringOf(VisualFlag)); + return (0); + } + if (state != 0) { + fprintf(stderr, + "Line %d: Extraneous keyword %s.\n", + linenum, keyword); + return (0); + } + state = 1; + count = 0; + pElement = (XcmsFloat *) pMatrix->XYZtoRGBmatrix; + break; + case XYZTORGBMAT_END: + if (VisualFlag != VIDEO_RGB) { + fprintf(stderr, + "Line %d: Keyword XYZTORGBMAT_END mismatch for visual %s.\n", + linenum, SCScrnClassStringOf(VisualFlag)); + return (0); + } + if ((state != 1) || (count != 9)) { + fprintf(stderr, + "Line %d: Incomplete XYZtoRGB matrix -- Premature %s\n", + linenum, keyword); + return (0); + } + matrices_processed |= 0x1; + if (matrices_processed == 3) { + state = 2; + } + else { + state = 0; + } + break; + case RGBTOXYZMAT_BEGIN: + if (VisualFlag != VIDEO_RGB) { + fprintf(stderr, + "Line %d: Keyword RGBTOXYZMAT_BEGIN mismatch for visual %s.\n", + linenum, SCScrnClassStringOf(VisualFlag)); + return (0); + } + if (state != 0) { + fprintf(stderr, "Line %d: Extraneous keyword %s.\n", + linenum, keyword); + return (0); + } + state = 1; + count = 0; + pElement = (XcmsFloat *) pMatrix->RGBtoXYZmatrix; + break; + case RGBTOXYZMAT_END: + if (VisualFlag != VIDEO_RGB) { + fprintf(stderr, + "Line %d: Keyword RGBTOXYZMAT_END mismatch for visual %s.\n", + linenum, SCScrnClassStringOf(VisualFlag)); + return (0); + } + if ((state != 1) || (count != 9)) { + fprintf(stderr, + "Line %d: Incomplete RGBtoXYZ matrix -- Premature %s\n", + linenum, keyword); + return (0); + } + matrices_processed |= 0x2; + if (matrices_processed == 3) { + state = 2; + } + else { + state = 0; + } + break; #ifdef GRAY - case WHITEPT_XYZ_BEGIN : - if (VisualFlag != VIDEO_GRAY) { - fprintf(stderr, - "Line %d: Keyword WHITEPT_XYZ_BEGIN mismatch for visual %s.\n", - linenum, SCScrnClassStringOf(VisualFlag)); - return (0); - } - if (state != 0) { - fprintf(stderr, - "Line %d: Extraneous keyword %s.\n", - linenum, keyword); - return (0); - } - state = 1; - count = 0; - pElement = (XcmsFloat *) pMatrix->XYZtoRGBmatrix; - break; - case WHITEPT_XYZ_END : - if (VisualFlag != VIDEO_GRAY) { - fprintf(stderr, - "Line %d: Keyword WHITEPT_XYZ_END mismatch for visual %s.\n", - linenum, SCScrnClassStringOf(VisualFlag)); - return (0); - } - if ((state != 1) || (count != 3)) { - fprintf(stderr, - "Line %d: Incomplete white point -- Premature %s\n", - linenum, keyword); - return (0); - } - state = 2; - break; + case WHITEPT_XYZ_BEGIN: + if (VisualFlag != VIDEO_GRAY) { + fprintf(stderr, + "Line %d: Keyword WHITEPT_XYZ_BEGIN mismatch for visual %s.\n", + linenum, SCScrnClassStringOf(VisualFlag)); + return (0); + } + if (state != 0) { + fprintf(stderr, + "Line %d: Extraneous keyword %s.\n", + linenum, keyword); + return (0); + } + state = 1; + count = 0; + pElement = (XcmsFloat *) pMatrix->XYZtoRGBmatrix; + break; + case WHITEPT_XYZ_END: + if (VisualFlag != VIDEO_GRAY) { + fprintf(stderr, + "Line %d: Keyword WHITEPT_XYZ_END mismatch for visual %s.\n", + linenum, SCScrnClassStringOf(VisualFlag)); + return (0); + } + if ((state != 1) || (count != 3)) { + fprintf(stderr, + "Line %d: Incomplete white point -- Premature %s\n", + linenum, keyword); + return (0); + } + state = 2; + break; #endif /* GRAY */ - case DATA : - for (ptoken = strtok(buf, DATA_DELIMS); ptoken != NULL; - ptoken = strtok(NULL, DATA_DELIMS)) { - if (sscanf(ptoken, "%lf", pElement) != 1) { - if (VisualFlag == VIDEO_RGB) { - fprintf(stderr, - "Line %d: Invalid matrix value %s.", - linenum, ptoken); - } else { - fprintf(stderr, - "Line %d: Invalid CIEXYZ value %s.\n", - linenum, ptoken); - } - return (0); - } - pElement++; - if (VisualFlag == VIDEO_RGB) { - if (++count > 9) { - fprintf(stderr, - "Line %d: Extra matrix value %s\n", - linenum, ptoken); - return (0); - } - } else { - if (++count > 3) { - fprintf(stderr, - "Line %d: Extra CIEXYZ value %s.\n", - linenum, ptoken); - return (0); - } - } - } - break; - case COLORIMETRIC_BEGIN : - fprintf(stderr, - "Line %d: Extraneous keyword %s.\n", - linenum, keyword); - return (0); - case COLORIMETRIC_END : - if (state != 2) { - fprintf(stderr, - "Line %d: Incomplete Colorimetric data -- Premature %s\n", - linenum, keyword); - return (0); - } - return (1); - case COMMENT : - /* Currently, do nothing. */ - break; - default : - fprintf(stderr, - "Line %d: Unexpected keyword %s\n", - linenum, keyword); - return (0); - } - } else if (ntok < 0) { - /* mismatch */ - fprintf(stderr, "Line %d: Unrecognized keyword\n", linenum); - return (0); - } + case DATA: + for (ptoken = strtok(buf, DATA_DELIMS); ptoken != NULL; + ptoken = strtok(NULL, DATA_DELIMS)) { + if (sscanf(ptoken, "%lf", pElement) != 1) { + if (VisualFlag == VIDEO_RGB) { + fprintf(stderr, + "Line %d: Invalid matrix value %s.", + linenum, ptoken); + } + else { + fprintf(stderr, + "Line %d: Invalid CIEXYZ value %s.\n", + linenum, ptoken); + } + return (0); + } + pElement++; + if (VisualFlag == VIDEO_RGB) { + if (++count > 9) { + fprintf(stderr, + "Line %d: Extra matrix value %s\n", + linenum, ptoken); + return (0); + } + } + else { + if (++count > 3) { + fprintf(stderr, + "Line %d: Extra CIEXYZ value %s.\n", + linenum, ptoken); + return (0); + } + } + } + break; + case COLORIMETRIC_BEGIN: + fprintf(stderr, + "Line %d: Extraneous keyword %s.\n", linenum, keyword); + return (0); + case COLORIMETRIC_END: + if (state != 2) { + fprintf(stderr, + "Line %d: Incomplete Colorimetric data -- Premature %s\n", + linenum, keyword); + return (0); + } + return (1); + case COMMENT: + /* Currently, do nothing. */ + break; + default: + fprintf(stderr, + "Line %d: Unexpected keyword %s\n", linenum, keyword); + return (0); + } + } + else if (ntok < 0) { + /* mismatch */ + fprintf(stderr, "Line %d: Unrecognized keyword\n", linenum); + return (0); + } } return (0); } @@ -518,194 +519,204 @@ ProcessIProfile(FILE *stream, XDCCC_Correction *pCorrection) char *keyword; char *tableStr, *sizeStr, *ptoken; int size; - int state = 0; - /************************************************ + int state = 0; + /************************************************ * 0 -- Looking for Intensity Table(s) * * 1 -- Processing Intensity Table(s) * ************************************************/ - int nTbl = 0; - int count = 0; + int nTbl = 0; + int count = 0; IntensityRec *pIRec = NULL; while ((nextline(buf, BUFSIZ, stream)) != NULL) { - ptoken = keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char*)NULL) { - switch (SCKeyOf(keyword)) { - case ITBL_BEGIN : - if (state != 0) { - fprintf(stderr,"Line %d: unexpected keyword %s\n", - linenum, keyword); - return (0); - } - tableStr = strtok((char*)NULL, DATA_DELIMS); - sizeStr = strtok((char*)NULL, DATA_DELIMS); - if ((sizeStr == (char*)NULL) || - sscanf(sizeStr, "%d", &size) != 1) { - fprintf(stderr, - "Line %d: invalid Intensity Table size, %s.\n", - linenum, sizeStr); - return (0); - } - if (size < 0) { - fprintf(stderr, - "Line %d: count %d < 0 for Intensity Table.\n", - linenum, size); - return (0); - } - if (strcmp(tableStr, "GREEN") == 0) { - if (pCorrection->nTables != 3) { - fprintf(stderr,"Line %d: incorrect number of tables\n", - linenum); - return (0); - } - if (pCorrection->pGreenTbl->pBase != NULL) { - fprintf(stderr, - "Line %d: multiple GREEN Intensity Profiles\n", - linenum); - return (0); - } - pCorrection->pGreenTbl->nEntries = size; - pCorrection->pGreenTbl->pBase = - (IntensityRec *) calloc (size, sizeof(IntensityRec)); - if (!pCorrection->pGreenTbl->pBase) { - fprintf(stderr, - "Line %d: Unable to allocate space for GREEN Intensity Profile\n", linenum); - return (0); - } - pIRec = pCorrection->pGreenTbl->pBase; - } else if (strcmp(tableStr, "BLUE") == 0) { - if (pCorrection->nTables != 3) { - fprintf(stderr, - "Line %d: incorrect number of tables\n", - linenum); - return (0); - } - if (pCorrection->pBlueTbl->pBase != NULL) { - fprintf(stderr, - "Line %d: multiple BLUE Intensity Profiles\n", - linenum); - return (0); - } - pCorrection->pBlueTbl->nEntries = size; - pCorrection->pBlueTbl->pBase = - (IntensityRec *) calloc (size, sizeof(IntensityRec)); - if (!pCorrection->pBlueTbl->pBase) { - fprintf(stderr, - "Line %d: Unable to allocate space for BLUE Intensity Profile\n", linenum); - return (0); - } - pIRec = pCorrection->pBlueTbl->pBase; - } else { - if (!strcmp(tableStr, "RGB") && pCorrection->nTables != 1) { - fprintf(stderr,"Line %d: multiple RGB Intensity Tables", - linenum); - return (0); - } - if (pCorrection->pRedTbl->pBase != NULL) { - fprintf(stderr, - "Line %d: multiple RED or GREEN or BLUE Intensity Tables\n", - linenum); - return (0); - } - pCorrection->pRedTbl->nEntries = size; - pCorrection->pRedTbl->pBase = - (IntensityRec *) calloc (size, sizeof(IntensityRec)); - if (!pCorrection->pRedTbl->pBase) { - fprintf(stderr, - "Line %d: Unable to allocate space for intensity table\n", linenum); - return (0); - } - pIRec = pCorrection->pRedTbl->pBase; - } - state = 1; - count = 0; - break; - case ITBL_END : - if ((state != 1) || (count != size)) { - fprintf(stderr, - "Line %d: incomplete Intensity Table -- Premature %s\n", - linenum, keyword); - return (0); - } - nTbl++; - state = 0; - break; - case DATA : - if(pIRec == NULL) { - fprintf(stderr, "Line %d: Invalid Intensity Profile -- Premature %s\n", - linenum, keyword); - return (0); - } - do { - /******************************************************** + ptoken = keyword = strtok(buf, DATA_DELIMS); + if (keyword != (char *) NULL) { + switch (SCKeyOf(keyword)) { + case ITBL_BEGIN: + if (state != 0) { + fprintf(stderr, "Line %d: unexpected keyword %s\n", + linenum, keyword); + return (0); + } + tableStr = strtok((char *) NULL, DATA_DELIMS); + sizeStr = strtok((char *) NULL, DATA_DELIMS); + if ((sizeStr == (char *) NULL) || + sscanf(sizeStr, "%d", &size) != 1) { + fprintf(stderr, + "Line %d: invalid Intensity Table size, %s.\n", + linenum, sizeStr); + return (0); + } + if (size < 0) { + fprintf(stderr, + "Line %d: count %d < 0 for Intensity Table.\n", + linenum, size); + return (0); + } + if (strcmp(tableStr, "GREEN") == 0) { + if (pCorrection->nTables != 3) { + fprintf(stderr, "Line %d: incorrect number of tables\n", + linenum); + return (0); + } + if (pCorrection->pGreenTbl->pBase != NULL) { + fprintf(stderr, + "Line %d: multiple GREEN Intensity Profiles\n", + linenum); + return (0); + } + pCorrection->pGreenTbl->nEntries = size; + pCorrection->pGreenTbl->pBase = + (IntensityRec *) calloc(size, sizeof(IntensityRec)); + if (!pCorrection->pGreenTbl->pBase) { + fprintf(stderr, + "Line %d: Unable to allocate space for GREEN Intensity Profile\n", + linenum); + return (0); + } + pIRec = pCorrection->pGreenTbl->pBase; + } + else if (strcmp(tableStr, "BLUE") == 0) { + if (pCorrection->nTables != 3) { + fprintf(stderr, + "Line %d: incorrect number of tables\n", + linenum); + return (0); + } + if (pCorrection->pBlueTbl->pBase != NULL) { + fprintf(stderr, + "Line %d: multiple BLUE Intensity Profiles\n", + linenum); + return (0); + } + pCorrection->pBlueTbl->nEntries = size; + pCorrection->pBlueTbl->pBase = + (IntensityRec *) calloc(size, sizeof(IntensityRec)); + if (!pCorrection->pBlueTbl->pBase) { + fprintf(stderr, + "Line %d: Unable to allocate space for BLUE Intensity Profile\n", + linenum); + return (0); + } + pIRec = pCorrection->pBlueTbl->pBase; + } + else { + if (!strcmp(tableStr, "RGB") && pCorrection->nTables != 1) { + fprintf(stderr, + "Line %d: multiple RGB Intensity Tables", + linenum); + return (0); + } + if (pCorrection->pRedTbl->pBase != NULL) { + fprintf(stderr, + "Line %d: multiple RED or GREEN or BLUE Intensity Tables\n", + linenum); + return (0); + } + pCorrection->pRedTbl->nEntries = size; + pCorrection->pRedTbl->pBase = + (IntensityRec *) calloc(size, sizeof(IntensityRec)); + if (!pCorrection->pRedTbl->pBase) { + fprintf(stderr, + "Line %d: Unable to allocate space for intensity table\n", + linenum); + return (0); + } + pIRec = pCorrection->pRedTbl->pBase; + } + state = 1; + count = 0; + break; + case ITBL_END: + if ((state != 1) || (count != size)) { + fprintf(stderr, + "Line %d: incomplete Intensity Table -- Premature %s\n", + linenum, keyword); + return (0); + } + nTbl++; + state = 0; + break; + case DATA: + if (pIRec == NULL) { + fprintf(stderr, + "Line %d: Invalid Intensity Profile -- Premature %s\n", + linenum, keyword); + return (0); + } + do { + /******************************************************** * Note: tableType should only be 0 or 1 at this point. * 0 indicates value and intensity stored. * 1 indicates only intensity stored. ********************************************************/ - if (pCorrection->tableType) { - if (sscanf(ptoken, "%lf", &pIRec->intensity) != 1) { - fprintf(stderr, - "Line %d: invalid Intensity Profile value %s\n", - linenum, ptoken); - return (0); - } - /* With tableType 1 only store the intensity. */ - pIRec++; - } else { - short tmp; - /* Note ANSI C can handle 0x preceding hex number */ - if (sscanf(ptoken, "%hi", &tmp) != 1) { - fprintf(stderr, - "Line %d: invalid Intensity Profile value %s\n", - linenum, ptoken); - return (0); - } else - pIRec->value = tmp; - if ((ptoken = strtok(NULL, DATA_DELIMS)) == NULL) { - fprintf(stderr, - "Line %d: missing Intensity Profile value\n", - linenum); - return (0); - } - if (sscanf(ptoken, "%lf", &pIRec->intensity) != 1) { - fprintf(stderr, - "Line %d: invalid Intensity Profile intensity %s\n", - linenum, ptoken); - return (0); - } - /* With tableType 0 only store both value & intensity*/ - pIRec++; - } - if (++count > size) { - fprintf(stderr, - "Line %d: extra Intensity value %s\n", - linenum, ptoken); - return (0); - } - ptoken = strtok(NULL, DATA_DELIMS); - } while(ptoken != NULL); - break; - case IPROFILE_BEGIN : - fprintf(stderr,"Line %d: extraneous keyword %s\n", - linenum, keyword); - return (0); - case IPROFILE_END : - if ((state != 0) || (nTbl != pCorrection->nTables)) { - fprintf(stderr, - "Line %d: incomplete Intensity Profile data -- Premature %s\n", - linenum, keyword); - return (0); - } - return (1); - case COMMENT : - /* ignore line */ - break; - default : - fprintf(stderr,"Line %d: unexpected keyword %s\n", - linenum, keyword); - return (0); - } - } /* else its was just a blank line */ + if (pCorrection->tableType) { + if (sscanf(ptoken, "%lf", &pIRec->intensity) != 1) { + fprintf(stderr, + "Line %d: invalid Intensity Profile value %s\n", + linenum, ptoken); + return (0); + } + /* With tableType 1 only store the intensity. */ + pIRec++; + } + else { + short tmp; + + /* Note ANSI C can handle 0x preceding hex number */ + if (sscanf(ptoken, "%hi", &tmp) != 1) { + fprintf(stderr, + "Line %d: invalid Intensity Profile value %s\n", + linenum, ptoken); + return (0); + } + else + pIRec->value = tmp; + if ((ptoken = strtok(NULL, DATA_DELIMS)) == NULL) { + fprintf(stderr, + "Line %d: missing Intensity Profile value\n", + linenum); + return (0); + } + if (sscanf(ptoken, "%lf", &pIRec->intensity) != 1) { + fprintf(stderr, + "Line %d: invalid Intensity Profile intensity %s\n", + linenum, ptoken); + return (0); + } + /* With tableType 0 only store both value & intensity */ + pIRec++; + } + if (++count > size) { + fprintf(stderr, + "Line %d: extra Intensity value %s\n", + linenum, ptoken); + return (0); + } + ptoken = strtok(NULL, DATA_DELIMS); + } while (ptoken != NULL); + break; + case IPROFILE_BEGIN: + fprintf(stderr, "Line %d: extraneous keyword %s\n", + linenum, keyword); + return (0); + case IPROFILE_END: + if ((state != 0) || (nTbl != pCorrection->nTables)) { + fprintf(stderr, + "Line %d: incomplete Intensity Profile data -- Premature %s\n", + linenum, keyword); + return (0); + } + return (1); + case COMMENT: + /* ignore line */ + break; + default: + fprintf(stderr, "Line %d: unexpected keyword %s\n", + linenum, keyword); + return (0); + } + } /* else its was just a blank line */ } return (0); } @@ -721,10 +732,10 @@ PutTableType0Card8(IntensityTbl *pTbl, unsigned char **pCard8) **pCard8 = count - 1; *pCard8 += 1; for (; count; count--, pIRec++) { - **pCard8 = pIRec->value >> 8; - *pCard8 += 1; - **pCard8 = pIRec->intensity * 255.0; - *pCard8 += 1; + **pCard8 = pIRec->value >> 8; + *pCard8 += 1; + **pCard8 = pIRec->intensity * 255.0; + *pCard8 += 1; } } @@ -739,8 +750,8 @@ PutTableType1Card8(IntensityTbl *pTbl, unsigned char **pCard8) **pCard8 = count - 1; *pCard8 += 1; for (; count; count--, pIRec++) { - **pCard8 = pIRec->intensity * 255.0; - *pCard8 += 1; + **pCard8 = pIRec->intensity * 255.0; + *pCard8 += 1; } } @@ -755,10 +766,10 @@ PutTableType0Card16(IntensityTbl *pTbl, unsigned short **pCard16) **pCard16 = count - 1; *pCard16 += 1; for (; count; count--, pIRec++) { - **pCard16 = pIRec->value; - *pCard16 += 1; - **pCard16 = pIRec->intensity * 65535.0; - *pCard16 += 1; + **pCard16 = pIRec->value; + *pCard16 += 1; + **pCard16 = pIRec->intensity * 65535.0; + *pCard16 += 1; } } @@ -773,8 +784,8 @@ PutTableType1Card16(IntensityTbl *pTbl, unsigned short **pCard16) **pCard16 = count - 1; *pCard16 += 1; for (; count; count--, pIRec++) { - **pCard16 = pIRec->intensity * 65535.0; - *pCard16 += 1; + **pCard16 = pIRec->intensity * 65535.0; + *pCard16 += 1; } } @@ -789,10 +800,10 @@ PutTableType0Card32(IntensityTbl *pTbl, unsigned long **pCard32) **pCard32 = count - 1; *pCard32 += 1; for (; count; count--, pIRec++) { - **pCard32 = pIRec->value; - *pCard32 += 1; - **pCard32 = pIRec->intensity * 4294967295.0; - *pCard32 += 1; + **pCard32 = pIRec->value; + *pCard32 += 1; + **pCard32 = pIRec->intensity * 4294967295.0; + *pCard32 += 1; } } @@ -807,18 +818,17 @@ PutTableType1Card32(IntensityTbl *pTbl, unsigned long **pCard32) **pCard32 = count - 1; *pCard32 += 1; for (; count; count--, pIRec++) { - **pCard32 = pIRec->intensity * 4294967295.0; - *pCard32 += 1; + **pCard32 = pIRec->intensity * 4294967295.0; + *pCard32 += 1; } } - static void -LoadMatrix(Display *pDpy, Window root, XDCCC_Matrix *pMatrix) +LoadMatrix(Display * pDpy, Window root, XDCCC_Matrix * pMatrix) { - int count; - unsigned long *pCard32; - unsigned long Card32Array[18]; + int count; + unsigned long *pCard32; + unsigned long Card32Array[18]; Atom MatricesAtom; XcmsFloat *pValue; @@ -826,263 +836,294 @@ LoadMatrix(Display *pDpy, Window root, XDCCC_Matrix *pMatrix) * Store the XDCCC_LINEAR_RGB_MATRICES */ pCard32 = Card32Array; - pValue = (XcmsFloat *)pMatrix->XYZtoRGBmatrix; + pValue = (XcmsFloat *) pMatrix->XYZtoRGBmatrix; for (count = 0; count < 9; count++) { - *pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER); + *pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER); } - pValue = (XcmsFloat *)pMatrix->RGBtoXYZmatrix; + pValue = (XcmsFloat *) pMatrix->RGBtoXYZmatrix; for (count = 0; count < 9; count++) { - *pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER); + *pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER); } - MatricesAtom = XInternAtom (pDpy, XDCCC_MATRIX_ATOM_NAME, False); - XChangeProperty (pDpy, root, MatricesAtom, XA_INTEGER, 32, - PropModeReplace, (unsigned char *)Card32Array, 18); + MatricesAtom = XInternAtom(pDpy, XDCCC_MATRIX_ATOM_NAME, False); + XChangeProperty(pDpy, root, MatricesAtom, XA_INTEGER, 32, + PropModeReplace, (unsigned char *) Card32Array, 18); } - static int LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, - int targetFormat) + int targetFormat) { - unsigned char *pCard8; - unsigned char *pCard8Array = (unsigned char *)NULL; - unsigned short *pCard16; - unsigned short *pCard16Array = (unsigned short *)NULL; - unsigned long *pCard32; - unsigned long *pCard32Array = (unsigned long *)NULL; + unsigned char *pCard8; + unsigned char *pCard8Array = (unsigned char *) NULL; + unsigned short *pCard16; + unsigned short *pCard16Array = (unsigned short *) NULL; + unsigned long *pCard32; + unsigned long *pCard32Array = (unsigned long *) NULL; Atom CorrectAtom; - int total; + int total; int i; /* * Store each XDCCC_CORRECTION into XDCCC_LINEAR_RGB_CORRECTION property */ - CorrectAtom = XInternAtom (pDpy, XDCCC_CORRECT_ATOM_NAME, False); + CorrectAtom = XInternAtom(pDpy, XDCCC_CORRECT_ATOM_NAME, False); for (i = 0; pCorrection; i++, pCorrection = pCorrection->next) { - if ((pCorrection->tableType != 0) && (pCorrection->tableType != 1)) { - if (pCorrection->visual_info.visualid) { - fprintf(stderr,"RGB Correction for visualid %ld: Invalid intensity table type %d.\n", - pCorrection->visual_info.visualid, - pCorrection->tableType); - } else { - fprintf(stderr,"Global RGB Correction: Invalid intensity table type %d.\n", - pCorrection->tableType); - } - return(0); - } - - if (pCorrection->nTables != 1 && pCorrection->nTables != 3) { - if (pCorrection->visual_info.visualid) { - fprintf(stderr,"RGB Correction for visualid %ld: %d invalid number of tables.\n", - pCorrection->visual_info.visualid, - pCorrection->nTables); - } else { - fprintf(stderr,"Global RGB Correction: %d invalid number of tables.\n", - pCorrection->nTables); - } - return(0); - } - - if (pCorrection->nTables == 1) { - if (pCorrection->pRedTbl->nEntries < 2) { - if (pCorrection->visual_info.visualid) { - fprintf(stderr,"RGB Correction for visualid %ld: Illegal number of entries in table\n", - pCorrection->visual_info.visualid); - } else { - fprintf(stderr,"Global RGB Correction: Illegal number of entries in table\n"); - } - return (0); - } - switch (targetFormat) { - case 8: - total = 7 + (pCorrection->pRedTbl->nEntries * - (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard8 = pCard8Array = (unsigned char *) calloc (total, - sizeof (unsigned char))) == NULL) { - fprintf(stderr,"Unable allocate array of ints\n"); - return (0); - } - *pCard8++ = (pCorrection->visual_info.visualid >> 24) & 0xFF; - *pCard8++ = (pCorrection->visual_info.visualid >> 16) & 0xFF; - *pCard8++ = (pCorrection->visual_info.visualid >> 8) & 0xFF; - *pCard8++ = (pCorrection->visual_info.visualid) & 0xFF; - *pCard8++ = pCorrection->tableType; /* type */ - *pCard8++ = 1; /* number of tables = 1 */ - if (pCorrection->tableType == 0) { - PutTableType0Card8(pCorrection->pRedTbl, &pCard8); - } else { - PutTableType1Card8(pCorrection->pRedTbl, &pCard8); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 8, - i ? PropModeAppend : PropModeReplace, - (unsigned char *)pCard8Array, total); - free(pCard8Array); - break; - case 16: - total = 5 + (pCorrection->pRedTbl->nEntries * - (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard16 = pCard16Array = (unsigned short *) calloc (total, - sizeof (unsigned short))) == NULL) { - fprintf(stderr,"Unable allocate array of ints\n"); - return (0); - } - *pCard16++ = (pCorrection->visual_info.visualid >> 16) & 0xFFFF; - *pCard16++ = (pCorrection->visual_info.visualid) & 0xFFFF; - *pCard16++ = pCorrection->tableType; /* type */ - *pCard16++ = 1; /* number of tables = 1 */ - if (pCorrection->tableType == 0) { - PutTableType0Card16(pCorrection->pRedTbl, &pCard16); - } else { - PutTableType1Card16(pCorrection->pRedTbl, &pCard16); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 16, - i ? PropModeAppend : PropModeReplace, - (unsigned char *)pCard16Array, total); - free(pCard16Array); - break; - case 32: - total = 4 + (pCorrection->pRedTbl->nEntries * - (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard32 = pCard32Array = - (unsigned long *) calloc (total, - sizeof (unsigned long))) == NULL) { - fprintf(stderr,"Unable allocate array of ints\n"); - return (0); - } - *pCard32++ = pCorrection->visual_info.visualid; - *pCard32++ = pCorrection->tableType; /* type */ - *pCard32++ = 1; /* number of tables = 1 */ - if (pCorrection->tableType == 0) { - PutTableType0Card32(pCorrection->pRedTbl, &pCard32); - } else { - PutTableType1Card32(pCorrection->pRedTbl, &pCard32); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 32, - i ? PropModeAppend : PropModeReplace, - (unsigned char *)pCard32Array, total); - free(pCard32Array); - break; - default: - if (pCorrection->visual_info.visualid) { - fprintf(stderr,"RGB Correction for visualid %ld: Invalid property format\n", - pCorrection->visual_info.visualid); - } else { - fprintf(stderr,"Global RGB Correction: Invalid property format\n"); - } - return (0); - } - } else { /* pCorrection->nTables == 3 */ - if ((pCorrection->pRedTbl->nEntries < 2) || - (pCorrection->pGreenTbl->nEntries < 2) || - (pCorrection->pBlueTbl->nEntries < 2)) { - if (pCorrection->visual_info.visualid) { - fprintf(stderr,"RGB Correction for visualid %ld: Illegal number of entries in table\n", - pCorrection->visual_info.visualid); - } else { - fprintf(stderr,"Global RGB Correction: Illegal number of entries in table\n"); - } - return (0); - } - switch (targetFormat) { - case 8: - total = 9 + /* visualID, type, and 3 lengths */ - (pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) + - (pCorrection->pGreenTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) + - (pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard8 = pCard8Array = - (unsigned char *) calloc (total, - sizeof (unsigned char))) == NULL) { - fprintf(stderr,"Unable allocate array of ints\n"); - return (0); - } - *pCard8++ = (pCorrection->visual_info.visualid >> 24) & 0xFF; - *pCard8++ = (pCorrection->visual_info.visualid >> 16) & 0xFF; - *pCard8++ = (pCorrection->visual_info.visualid >> 8) & 0xFF; - *pCard8++ = (pCorrection->visual_info.visualid) & 0xFF; - *pCard8++ = pCorrection->tableType; /* type */ - *pCard8++ = 3; /* number of tables = 3 */ - if (pCorrection->tableType == 0) { - PutTableType0Card8(pCorrection->pRedTbl, &pCard8); - PutTableType0Card8(pCorrection->pGreenTbl, &pCard8); - PutTableType0Card8(pCorrection->pBlueTbl, &pCard8); - } else { - PutTableType1Card8(pCorrection->pRedTbl, &pCard8); - PutTableType1Card8(pCorrection->pGreenTbl, &pCard8); - PutTableType1Card8(pCorrection->pBlueTbl, &pCard8); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 8, - i ? PropModeAppend : PropModeReplace, - (unsigned char *)pCard8Array, total); - free(pCard8Array); - break; - case 16: - total = 7 + /* visualID, type, and 3 lengths */ - (pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) + - (pCorrection->pGreenTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) + - (pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard16 = pCard16Array = - (unsigned short *) calloc (total, - sizeof (unsigned short))) == NULL) { - fprintf(stderr,"Unable allocate array of ints\n"); - return (0); - } - *pCard16++ = (pCorrection->visual_info.visualid >> 16) & 0xFFFF; - *pCard16++ = (pCorrection->visual_info.visualid) & 0xFFFF; - *pCard16++ = pCorrection->tableType; /* type = 0 */ - *pCard16++ = 3; /* number of tables = 3 */ - if (pCorrection->tableType == 0) { - PutTableType0Card16(pCorrection->pRedTbl, &pCard16); - PutTableType0Card16(pCorrection->pGreenTbl, &pCard16); - PutTableType0Card16(pCorrection->pBlueTbl, &pCard16); - } else { - PutTableType1Card16(pCorrection->pRedTbl, &pCard16); - PutTableType1Card16(pCorrection->pGreenTbl, &pCard16); - PutTableType1Card16(pCorrection->pBlueTbl, &pCard16); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 16, - i ? PropModeAppend : PropModeReplace, - (unsigned char *)pCard16Array, total); - free(pCard16Array); - break; - case 32: - total = 6 + /* visualID, type, and 3 lengths */ - (pCorrection->pRedTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) + - (pCorrection->pGreenTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)) + - (pCorrection->pBlueTbl->nEntries * (pCorrection->tableType == 0 ? 2 : 1)); - if ((pCard32 = pCard32Array = - (unsigned long *) calloc (total, - sizeof (unsigned long))) == NULL) { - fprintf(stderr,"Unable allocate array of ints\n"); - return (0); - } - *pCard32++ = pCorrection->visual_info.visualid; - *pCard32++ = pCorrection->tableType; /* type */ - *pCard32++ = 3; /* number of tables = 3 */ - if (pCorrection->tableType == 0) { - PutTableType0Card32(pCorrection->pRedTbl, &pCard32); - PutTableType0Card32(pCorrection->pGreenTbl, &pCard32); - PutTableType0Card32(pCorrection->pBlueTbl, &pCard32); - } else { - PutTableType1Card32(pCorrection->pRedTbl, &pCard32); - PutTableType1Card32(pCorrection->pGreenTbl, &pCard32); - PutTableType1Card32(pCorrection->pBlueTbl, &pCard32); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 32, - i ? PropModeAppend : PropModeReplace, - (unsigned char *)pCard32Array, total); - free(pCard32Array); - break; - default: - if (pCorrection->visual_info.visualid) { - fprintf(stderr,"RGB Correction for visualid %ld: Invalid property format\n", - pCorrection->visual_info.visualid); - } else { - fprintf(stderr,"Global RGB Correction: Invalid property format\n"); - } - return (0); - } - } + if ((pCorrection->tableType != 0) && (pCorrection->tableType != 1)) { + if (pCorrection->visual_info.visualid) { + fprintf(stderr, + "RGB Correction for visualid %ld: Invalid intensity table type %d.\n", + pCorrection->visual_info.visualid, + pCorrection->tableType); + } + else { + fprintf(stderr, + "Global RGB Correction: Invalid intensity table type %d.\n", + pCorrection->tableType); + } + return (0); + } + + if (pCorrection->nTables != 1 && pCorrection->nTables != 3) { + if (pCorrection->visual_info.visualid) { + fprintf(stderr, + "RGB Correction for visualid %ld: %d invalid number of tables.\n", + pCorrection->visual_info.visualid, + pCorrection->nTables); + } + else { + fprintf(stderr, + "Global RGB Correction: %d invalid number of tables.\n", + pCorrection->nTables); + } + return (0); + } + + if (pCorrection->nTables == 1) { + if (pCorrection->pRedTbl->nEntries < 2) { + if (pCorrection->visual_info.visualid) { + fprintf(stderr, + "RGB Correction for visualid %ld: Illegal number of entries in table\n", + pCorrection->visual_info.visualid); + } + else { + fprintf(stderr, + "Global RGB Correction: Illegal number of entries in table\n"); + } + return (0); + } + switch (targetFormat) { + case 8: + total = 7 + (pCorrection->pRedTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)); + if ((pCard8 = pCard8Array = (unsigned char *) + calloc(total, sizeof(unsigned char))) == NULL) { + fprintf(stderr, "Unable allocate array of ints\n"); + return (0); + } + *pCard8++ = (pCorrection->visual_info.visualid >> 24) & 0xFF; + *pCard8++ = (pCorrection->visual_info.visualid >> 16) & 0xFF; + *pCard8++ = (pCorrection->visual_info.visualid >> 8) & 0xFF; + *pCard8++ = (pCorrection->visual_info.visualid) & 0xFF; + *pCard8++ = pCorrection->tableType; /* type */ + *pCard8++ = 1; /* number of tables = 1 */ + if (pCorrection->tableType == 0) { + PutTableType0Card8(pCorrection->pRedTbl, &pCard8); + } + else { + PutTableType1Card8(pCorrection->pRedTbl, &pCard8); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 8, + i ? PropModeAppend : PropModeReplace, + (unsigned char *) pCard8Array, total); + free(pCard8Array); + break; + case 16: + total = 5 + (pCorrection->pRedTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)); + if ((pCard16 = pCard16Array = (unsigned short *) + calloc(total, sizeof (unsigned short))) == NULL) { + fprintf(stderr, "Unable allocate array of ints\n"); + return (0); + } + *pCard16++ = (pCorrection->visual_info.visualid >> 16) & 0xFFFF; + *pCard16++ = (pCorrection->visual_info.visualid) & 0xFFFF; + *pCard16++ = pCorrection->tableType; /* type */ + *pCard16++ = 1; /* number of tables = 1 */ + if (pCorrection->tableType == 0) { + PutTableType0Card16(pCorrection->pRedTbl, &pCard16); + } + else { + PutTableType1Card16(pCorrection->pRedTbl, &pCard16); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 16, + i ? PropModeAppend : PropModeReplace, + (unsigned char *) pCard16Array, total); + free(pCard16Array); + break; + case 32: + total = 4 + (pCorrection->pRedTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)); + if ((pCard32 = pCard32Array = + (unsigned long *) calloc(total, + sizeof(unsigned long))) == NULL) { + fprintf(stderr, "Unable allocate array of ints\n"); + return (0); + } + *pCard32++ = pCorrection->visual_info.visualid; + *pCard32++ = pCorrection->tableType; /* type */ + *pCard32++ = 1; /* number of tables = 1 */ + if (pCorrection->tableType == 0) { + PutTableType0Card32(pCorrection->pRedTbl, &pCard32); + } + else { + PutTableType1Card32(pCorrection->pRedTbl, &pCard32); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 32, + i ? PropModeAppend : PropModeReplace, + (unsigned char *) pCard32Array, total); + free(pCard32Array); + break; + default: + if (pCorrection->visual_info.visualid) { + fprintf(stderr, + "RGB Correction for visualid %ld: Invalid property format\n", + pCorrection->visual_info.visualid); + } + else { + fprintf(stderr, + "Global RGB Correction: Invalid property format\n"); + } + return (0); + } + } + else { /* pCorrection->nTables == 3 */ + if ((pCorrection->pRedTbl->nEntries < 2) || + (pCorrection->pGreenTbl->nEntries < 2) || + (pCorrection->pBlueTbl->nEntries < 2)) { + if (pCorrection->visual_info.visualid) { + fprintf(stderr, + "RGB Correction for visualid %ld: Illegal number of entries in table\n", + pCorrection->visual_info.visualid); + } + else { + fprintf(stderr, + "Global RGB Correction: Illegal number of entries in table\n"); + } + return (0); + } + switch (targetFormat) { + case 8: + total = 9 + /* visualID, type, and 3 lengths */ + (pCorrection->pRedTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)) + + (pCorrection->pGreenTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)) + + (pCorrection->pBlueTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)); + if ((pCard8 = pCard8Array = + (unsigned char *) calloc(total, + sizeof(unsigned char))) == NULL) { + fprintf(stderr, "Unable allocate array of ints\n"); + return (0); + } + *pCard8++ = (pCorrection->visual_info.visualid >> 24) & 0xFF; + *pCard8++ = (pCorrection->visual_info.visualid >> 16) & 0xFF; + *pCard8++ = (pCorrection->visual_info.visualid >> 8) & 0xFF; + *pCard8++ = (pCorrection->visual_info.visualid) & 0xFF; + *pCard8++ = pCorrection->tableType; /* type */ + *pCard8++ = 3; /* number of tables = 3 */ + if (pCorrection->tableType == 0) { + PutTableType0Card8(pCorrection->pRedTbl, &pCard8); + PutTableType0Card8(pCorrection->pGreenTbl, &pCard8); + PutTableType0Card8(pCorrection->pBlueTbl, &pCard8); + } + else { + PutTableType1Card8(pCorrection->pRedTbl, &pCard8); + PutTableType1Card8(pCorrection->pGreenTbl, &pCard8); + PutTableType1Card8(pCorrection->pBlueTbl, &pCard8); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 8, + i ? PropModeAppend : PropModeReplace, + (unsigned char *) pCard8Array, total); + free(pCard8Array); + break; + case 16: + total = 7 + /* visualID, type, and 3 lengths */ + (pCorrection->pRedTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)) + + (pCorrection->pGreenTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)) + + (pCorrection->pBlueTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)); + if ((pCard16 = pCard16Array = (unsigned short *) + calloc(total, sizeof(unsigned short))) == NULL) { + fprintf(stderr, "Unable allocate array of ints\n"); + return (0); + } + *pCard16++ = (pCorrection->visual_info.visualid >> 16) & 0xFFFF; + *pCard16++ = (pCorrection->visual_info.visualid) & 0xFFFF; + *pCard16++ = pCorrection->tableType; /* type = 0 */ + *pCard16++ = 3; /* number of tables = 3 */ + if (pCorrection->tableType == 0) { + PutTableType0Card16(pCorrection->pRedTbl, &pCard16); + PutTableType0Card16(pCorrection->pGreenTbl, &pCard16); + PutTableType0Card16(pCorrection->pBlueTbl, &pCard16); + } + else { + PutTableType1Card16(pCorrection->pRedTbl, &pCard16); + PutTableType1Card16(pCorrection->pGreenTbl, &pCard16); + PutTableType1Card16(pCorrection->pBlueTbl, &pCard16); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 16, + i ? PropModeAppend : PropModeReplace, + (unsigned char *) pCard16Array, total); + free(pCard16Array); + break; + case 32: + total = 6 + /* visualID, type, and 3 lengths */ + (pCorrection->pRedTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)) + + (pCorrection->pGreenTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)) + + (pCorrection->pBlueTbl->nEntries * + (pCorrection->tableType == 0 ? 2 : 1)); + if ((pCard32 = pCard32Array = (unsigned long *) + calloc(total, sizeof(unsigned long))) == NULL) { + fprintf(stderr, "Unable allocate array of ints\n"); + return (0); + } + *pCard32++ = pCorrection->visual_info.visualid; + *pCard32++ = pCorrection->tableType; /* type */ + *pCard32++ = 3; /* number of tables = 3 */ + if (pCorrection->tableType == 0) { + PutTableType0Card32(pCorrection->pRedTbl, &pCard32); + PutTableType0Card32(pCorrection->pGreenTbl, &pCard32); + PutTableType0Card32(pCorrection->pBlueTbl, &pCard32); + } + else { + PutTableType1Card32(pCorrection->pRedTbl, &pCard32); + PutTableType1Card32(pCorrection->pGreenTbl, &pCard32); + PutTableType1Card32(pCorrection->pBlueTbl, &pCard32); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 32, + i ? PropModeAppend : PropModeReplace, + (unsigned char *) pCard32Array, total); + free(pCard32Array); + break; + default: + if (pCorrection->visual_info.visualid) { + fprintf(stderr, + "RGB Correction for visualid %ld: Invalid property format\n", + pCorrection->visual_info.visualid); + } + else { + fprintf(stderr, + "Global RGB Correction: Invalid property format\n"); + } + return (0); + } + } } return (1); @@ -1092,19 +1133,19 @@ LoadCorrections(Display *pDpy, Window root, XDCCC_Correction *pCorrection, static int LoadDataGray(Display *pDpy, window root, int tableType, - LINEAR_RGB_SCCData *pScreenData, int targetFormat) + LINEAR_RGB_SCCData *pScreenData, int targetFormat) { unsigned char *ret_prop; - int count; - int nLevels; - unsigned char *pCard8; - unsigned char *pCard8Array = (unsigned char *)NULL; - unsigned short *pCard16; - unsigned short *pCard16Array = (unsigned short *)NULL; - unsigned long *pCard32; - unsigned long *pCard32Array = (unsigned long *)NULL; - unsigned long Card32Array[18]; - int ret_format; + int count; + int nLevels; + unsigned char *pCard8; + unsigned char *pCard8Array = (unsigned char *) NULL; + unsigned short *pCard16; + unsigned short *pCard16Array = (unsigned short *) NULL; + unsigned long *pCard32; + unsigned long *pCard32Array = (unsigned long *) NULL; + unsigned long Card32Array[18]; + int ret_format; unsigned long ret_len, ret_after; Atom MatricesAtom, CorrectAtom, ret_atom; XcmsFloat *pValue; @@ -1112,152 +1153,150 @@ LoadDataGray(Display *pDpy, window root, int tableType, /* Now store the XDCCC_SCREENWHITEPT */ pCard32 = Card32Array; - pValue = (XcmsFloat *)pScreenData->XYZtoRGBmatrix; + pValue = (XcmsFloat *) pScreenData->XYZtoRGBmatrix; for (count = 0; count < 3; count++) { - *pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER); + *pCard32++ = (unsigned long) (*pValue++ * (XcmsFloat) XDCCC_NUMBER); } - MatricesAtom = XInternAtom (pDpy,XDCCC_SCREENWHITEPT_ATOM_NAME,False); - XChangeProperty (pDpy, root, MatricesAtom, XA_INTEGER, 32, - PropModeReplace, (unsigned char *)Card32Array, 3); + MatricesAtom = XInternAtom(pDpy, XDCCC_SCREENWHITEPT_ATOM_NAME, False); + XChangeProperty(pDpy, root, MatricesAtom, XA_INTEGER, 32, + PropModeReplace, (unsigned char *) Card32Array, 3); /* Now store the XDCCC_GRAY_CORRECTION */ - CorrectAtom = XInternAtom (pDpy, XDCCC_GRAY_CORRECT_ATOM_NAME, False); + CorrectAtom = XInternAtom(pDpy, XDCCC_GRAY_CORRECT_ATOM_NAME, False); if (tableType == CORR_TYPE_NONE) { - XGetWindowProperty (pDpy, root, CorrectAtom, - 0, 5, False, XA_INTEGER, - &ret_atom, &ret_format, &ret_len, &ret_after, - &ret_prop); - if (ret_format != 0) { - XDeleteProperty (pDpy, root, CorrectAtom); - XFree ((char *)ret_prop); - } - return (1); + XGetWindowProperty(pDpy, root, CorrectAtom, + 0, 5, False, XA_INTEGER, + &ret_atom, &ret_format, &ret_len, &ret_after, + &ret_prop); + if (ret_format != 0) { + XDeleteProperty(pDpy, root, CorrectAtom); + XFree((char *) ret_prop); + } + return (1); } nLevels = pScreenData->pRedTbl->nEntries; if (nLevels < 2) { - fprintf(stderr,"Illegal number of entries in table\n"); - return (0); + fprintf(stderr, "Illegal number of entries in table\n"); + return (0); } switch (targetFormat) { - case 8: - total = 6 /* visualID, type, length */ - + (nLevels * (tableType == 0 ? 2 : 1)); - if ((pCard8 = pCard8Array = (unsigned char *) - calloc (total, sizeof (unsigned char))) == NULL) { - fprintf(stderr,"Unable allocate array of Card8\n"); - return (0); - } - *pCard8++ = 0; /* VisualID = 0 */ - *pCard8++ = 0; /* VisualID = 0 */ - *pCard8++ = 0; /* VisualID = 0 */ - *pCard8++ = 0; /* VisualID = 0 */ - *pCard8++ = tableType; /* type */ - if (tableType == 0) { - PutTableType0Card8(pScreenData->pRedTbl, &pCard8); - } else { /* tableType == 1 */ - PutTableType1Card8(pScreenData->pRedTbl, &pCard8); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 8, - PropModeReplace, (unsigned char *)pCard8Array, - total); - free (pCard8Array); - break; - case 16: - total = 4 /* visualID, type, length */ - + (nLevels * (tableType == 0 ? 2 : 1)); - if ((pCard16 = pCard16Array = (unsigned short *) - calloc (total, sizeof (unsigned short))) == NULL) { - fprintf(stderr,"Unable allocate array of Card16\n"); - return (0); - } - *pCard16++ = 0; /* VisualID = 0 */ - *pCard16++ = 0; /* VisualID = 0 */ - *pCard16++ = tableType; /* type */ - if (tableType == 0) { - PutTableType0Card16(pScreenData->pRedTbl, &pCard16); - } else { /* tableType == 1 */ - PutTableType1Card16(pScreenData->pRedTbl, &pCard16); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 16, - PropModeReplace, (unsigned char *)pCard16Array, - total); - free (pCard16Array); - break; - case 32: - total = 3 /* visualID, type, length */ - + (nLevels * (tableType == 0 ? 2 : 1)); - if ((pCard32 = pCard32Array = (unsigned long *) - calloc (total, sizeof (unsigned long))) == NULL) { - fprintf(stderr,"Unable allocate array of Card32\n"); - return (0); - } - *pCard32++ = 0; /* VisualID = 0 */ - *pCard32++ = tableType; /* type */ - if (tableType == 0) { - PutTableType0Card32(pScreenData->pRedTbl, &pCard32); - } else { /* tableType == 1 */ - PutTableType1Card32(pScreenData->pRedTbl, &pCard32); - } - XChangeProperty (pDpy, root, CorrectAtom, XA_INTEGER, 32, - PropModeReplace, (unsigned char *)pCard32Array, - total); - free (pCard32Array); - break; - default: - fprintf(stderr,"Invalid property format\n"); - return (0); + case 8: + total = 6 /* visualID, type, length */ + + (nLevels * (tableType == 0 ? 2 : 1)); + if ((pCard8 = pCard8Array = (unsigned char *) + calloc(total, sizeof(unsigned char))) == NULL) { + fprintf(stderr, "Unable allocate array of Card8\n"); + return (0); + } + *pCard8++ = 0; /* VisualID = 0 */ + *pCard8++ = 0; /* VisualID = 0 */ + *pCard8++ = 0; /* VisualID = 0 */ + *pCard8++ = 0; /* VisualID = 0 */ + *pCard8++ = tableType; /* type */ + if (tableType == 0) { + PutTableType0Card8(pScreenData->pRedTbl, &pCard8); + } + else { /* tableType == 1 */ + PutTableType1Card8(pScreenData->pRedTbl, &pCard8); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 8, + PropModeReplace, (unsigned char *) pCard8Array, total); + free(pCard8Array); + break; + case 16: + total = 4 /* visualID, type, length */ + + (nLevels * (tableType == 0 ? 2 : 1)); + if ((pCard16 = pCard16Array = (unsigned short *) + calloc(total, sizeof(unsigned short))) == NULL) { + fprintf(stderr, "Unable allocate array of Card16\n"); + return (0); + } + *pCard16++ = 0; /* VisualID = 0 */ + *pCard16++ = 0; /* VisualID = 0 */ + *pCard16++ = tableType; /* type */ + if (tableType == 0) { + PutTableType0Card16(pScreenData->pRedTbl, &pCard16); + } + else { /* tableType == 1 */ + PutTableType1Card16(pScreenData->pRedTbl, &pCard16); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 16, + PropModeReplace, (unsigned char *) pCard16Array, total); + free(pCard16Array); + break; + case 32: + total = 3 /* visualID, type, length */ + + (nLevels * (tableType == 0 ? 2 : 1)); + if ((pCard32 = pCard32Array = (unsigned long *) + calloc(total, sizeof(unsigned long))) == NULL) { + fprintf(stderr, "Unable allocate array of Card32\n"); + return (0); + } + *pCard32++ = 0; /* VisualID = 0 */ + *pCard32++ = tableType; /* type */ + if (tableType == 0) { + PutTableType0Card32(pScreenData->pRedTbl, &pCard32); + } + else { /* tableType == 1 */ + PutTableType1Card32(pScreenData->pRedTbl, &pCard32); + } + XChangeProperty(pDpy, root, CorrectAtom, XA_INTEGER, 32, + PropModeReplace, (unsigned char *) pCard32Array, total); + free(pCard32Array); + break; + default: + fprintf(stderr, "Invalid property format\n"); + return (0); } return (1); } -#endif /* GRAY */ - +#endif /* GRAY */ static void -PrintVisualOptions(XDCCC_Correction *pCorrection) +PrintVisualOptions(XDCCC_Correction * pCorrection) { if (pCorrection->visual_info_mask & VisualIDMask) { - fprintf(stderr, "\t%s:0x%lx\n", - DefineToStr(VisualOptKeyTbl, KEY_VISUALID), - (unsigned long)pCorrection->visual_info.visualid); + fprintf(stderr, "\t%s:0x%lx\n", + DefineToStr(VisualOptKeyTbl, KEY_VISUALID), + (unsigned long) pCorrection->visual_info.visualid); } if (pCorrection->visual_info_mask & VisualDepthMask) { - fprintf(stderr, "\t%s:%d\n", - DefineToStr(VisualOptKeyTbl, KEY_DEPTH), - pCorrection->visual_info.depth); + fprintf(stderr, "\t%s:%d\n", + DefineToStr(VisualOptKeyTbl, KEY_DEPTH), + pCorrection->visual_info.depth); } if (pCorrection->visual_info_mask & VisualClassMask) { - fprintf(stderr, "\t%s:%s\n", - DefineToStr(VisualOptKeyTbl, KEY_CLASS), - DefineToStr(VisualClassTbl, pCorrection->visual_info.class)); + fprintf(stderr, "\t%s:%s\n", + DefineToStr(VisualOptKeyTbl, KEY_CLASS), + DefineToStr(VisualClassTbl, pCorrection->visual_info.class)); } if (pCorrection->visual_info_mask & VisualRedMaskMask) { - fprintf(stderr, "\t%s:0x%lx\n", - DefineToStr(VisualOptKeyTbl, KEY_RED_MASK), - pCorrection->visual_info.red_mask); + fprintf(stderr, "\t%s:0x%lx\n", + DefineToStr(VisualOptKeyTbl, KEY_RED_MASK), + pCorrection->visual_info.red_mask); } if (pCorrection->visual_info_mask & VisualGreenMaskMask) { - fprintf(stderr, "\t%s:0x%lx\n", - DefineToStr(VisualOptKeyTbl, KEY_GREEN_MASK), - pCorrection->visual_info.green_mask); + fprintf(stderr, "\t%s:0x%lx\n", + DefineToStr(VisualOptKeyTbl, KEY_GREEN_MASK), + pCorrection->visual_info.green_mask); } if (pCorrection->visual_info_mask & VisualBlueMaskMask) { - fprintf(stderr, "\t%s:0x%lx\n", - DefineToStr(VisualOptKeyTbl, KEY_BLUE_MASK), - pCorrection->visual_info.blue_mask); + fprintf(stderr, "\t%s:0x%lx\n", + DefineToStr(VisualOptKeyTbl, KEY_BLUE_MASK), + pCorrection->visual_info.blue_mask); } if (pCorrection->visual_info_mask & VisualColormapSizeMask) { - fprintf(stderr, "\t%s:0x%x\n", - DefineToStr(VisualOptKeyTbl, KEY_COLORMAP_SIZE), - pCorrection->visual_info.colormap_size); + fprintf(stderr, "\t%s:0x%x\n", + DefineToStr(VisualOptKeyTbl, KEY_COLORMAP_SIZE), + pCorrection->visual_info.colormap_size); } if (pCorrection->visual_info_mask & VisualBitsPerRGBMask) { - fprintf(stderr, "\t%s:%d\n", - DefineToStr(VisualOptKeyTbl, KEY_BITS_PER_RGB), - pCorrection->visual_info.bits_per_rgb); + fprintf(stderr, "\t%s:%d\n", + DefineToStr(VisualOptKeyTbl, KEY_BITS_PER_RGB), + pCorrection->visual_info.bits_per_rgb); } } - static int ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf) @@ -1273,131 +1312,137 @@ ParseVisualOptions(Display *pDpy, XDCCC_Correction *pCorrection, char *pbuf) pCorrection->visual_info_mask = VisualNoMask; key = strtok(pbuf, delims); do { - long tmp; - value = strtok((char*)NULL, delims); - if ((key == (char*)NULL) || (value == (char*)NULL)) { - return (0); - } - switch (StrToDefine(VisualOptKeyTbl, key)) { - case KEY_VISUALID: - if (sscanf(value, "%li", &tmp) != 1) { - fprintf(stderr, - "Line %d: invalid VisualID specified, %s\n", - linenum, value); - return (0); - } else - pCorrection->visual_info.visualid = tmp; - pCorrection->visual_info_mask |= VisualIDMask; - break; - case KEY_DEPTH: - if (sscanf(value, "%i", &pCorrection->visual_info.depth) != 1) { - fprintf(stderr, - "Line %d: invalid depth specified, %s\n", - linenum, value); - return (0); - } - pCorrection->visual_info_mask |= VisualDepthMask; - break; - case KEY_CLASS: - switch (pCorrection->visual_info.class = - StrToDefine(VisualClassTbl, value)) { - case StaticColor: - break; - case PseudoColor: - break; - case TrueColor: - break; - case DirectColor: - break; - case StaticGray: - /* invalid, fall through */ - case GrayScale: - /* invalid, fall through */ - default: - fprintf(stderr, - "Line %d: invalid Visual Class -- %s\n", - linenum, value); - return (0); - } - pCorrection->visual_info_mask |= VisualClassMask; - break; - case KEY_RED_MASK: - if (sscanf(value, "%li", &tmp) != 1) { - fprintf(stderr, - "Line %d: invalid red_mask specified -- %s\n", - linenum, value); - return (0); - } else - pCorrection->visual_info.red_mask = tmp; - pCorrection->visual_info_mask |= VisualRedMaskMask; - break; - case KEY_GREEN_MASK: - if (sscanf(value, "%li", &tmp) != 1) { - fprintf(stderr, - "Line %d: invalid green_mask specified -- %s\n", - linenum, value); - return (0); - } else - pCorrection->visual_info.green_mask = tmp; - pCorrection->visual_info_mask |= VisualGreenMaskMask; - break; - case KEY_BLUE_MASK: - if (sscanf(value, "%li", &tmp) != 1) { - fprintf(stderr, - "Line %d: invalid blue_mask specified -- %s\n", - linenum, value); - return (0); - } else - pCorrection->visual_info.blue_mask = tmp; - pCorrection->visual_info_mask |= VisualBlueMaskMask; - break; - case KEY_COLORMAP_SIZE: - if (sscanf(value, "%i", &pCorrection->visual_info.colormap_size) != 1) { - fprintf(stderr, - "Line %d: invalid colormap_size specified -- %s\n", - linenum, value); - return (0); - } - pCorrection->visual_info_mask |= VisualColormapSizeMask; - break; - case KEY_BITS_PER_RGB: - if (sscanf(value, "%i", &pCorrection->visual_info.bits_per_rgb) != 1) { - fprintf(stderr, - "Line %d: invalid bits_per_rgb specified -- %s\n", - linenum, value); - return (0); - } - pCorrection->visual_info_mask |= VisualBitsPerRGBMask; - break; - default: - fprintf(stderr, - "Line %d: invalid keyword %s\n", linenum, key); - return (0); - } - key = strtok((char*)NULL, delims); - } while (key != (char *)NULL); + long tmp; + + value = strtok((char *) NULL, delims); + if ((key == (char *) NULL) || (value == (char *) NULL)) { + return (0); + } + switch (StrToDefine(VisualOptKeyTbl, key)) { + case KEY_VISUALID: + if (sscanf(value, "%li", &tmp) != 1) { + fprintf(stderr, + "Line %d: invalid VisualID specified, %s\n", + linenum, value); + return (0); + } + else + pCorrection->visual_info.visualid = tmp; + pCorrection->visual_info_mask |= VisualIDMask; + break; + case KEY_DEPTH: + if (sscanf(value, "%i", &pCorrection->visual_info.depth) != 1) { + fprintf(stderr, + "Line %d: invalid depth specified, %s\n", + linenum, value); + return (0); + } + pCorrection->visual_info_mask |= VisualDepthMask; + break; + case KEY_CLASS: + switch (pCorrection->visual_info.class = + StrToDefine(VisualClassTbl, value)) { + case StaticColor: + break; + case PseudoColor: + break; + case TrueColor: + break; + case DirectColor: + break; + case StaticGray: + /* invalid, fall through */ + case GrayScale: + /* invalid, fall through */ + default: + fprintf(stderr, + "Line %d: invalid Visual Class -- %s\n", + linenum, value); + return (0); + } + pCorrection->visual_info_mask |= VisualClassMask; + break; + case KEY_RED_MASK: + if (sscanf(value, "%li", &tmp) != 1) { + fprintf(stderr, + "Line %d: invalid red_mask specified -- %s\n", + linenum, value); + return (0); + } + else + pCorrection->visual_info.red_mask = tmp; + pCorrection->visual_info_mask |= VisualRedMaskMask; + break; + case KEY_GREEN_MASK: + if (sscanf(value, "%li", &tmp) != 1) { + fprintf(stderr, + "Line %d: invalid green_mask specified -- %s\n", + linenum, value); + return (0); + } + else + pCorrection->visual_info.green_mask = tmp; + pCorrection->visual_info_mask |= VisualGreenMaskMask; + break; + case KEY_BLUE_MASK: + if (sscanf(value, "%li", &tmp) != 1) { + fprintf(stderr, + "Line %d: invalid blue_mask specified -- %s\n", + linenum, value); + return (0); + } + else + pCorrection->visual_info.blue_mask = tmp; + pCorrection->visual_info_mask |= VisualBlueMaskMask; + break; + case KEY_COLORMAP_SIZE: + if (sscanf(value, "%i", &pCorrection->visual_info.colormap_size) != + 1) { + fprintf(stderr, + "Line %d: invalid colormap_size specified -- %s\n", + linenum, value); + return (0); + } + pCorrection->visual_info_mask |= VisualColormapSizeMask; + break; + case KEY_BITS_PER_RGB: + if (sscanf(value, "%i", &pCorrection->visual_info.bits_per_rgb) != + 1) { + fprintf(stderr, + "Line %d: invalid bits_per_rgb specified -- %s\n", + linenum, value); + return (0); + } + pCorrection->visual_info_mask |= VisualBitsPerRGBMask; + break; + default: + fprintf(stderr, "Line %d: invalid keyword %s\n", linenum, key); + return (0); + } + key = strtok((char *) NULL, delims); + } while (key != (char *) NULL); vinfo = XGetVisualInfo(pDpy, - pCorrection->visual_info_mask, - &pCorrection->visual_info, - &n_matches); + pCorrection->visual_info_mask, + &pCorrection->visual_info, &n_matches); if (!n_matches) { - fprintf(stderr, "Line %d: Cannot find visual matching ...\n", linenum); - PrintVisualOptions(pCorrection); - fprintf(stderr, "\n"); - return(0); + fprintf(stderr, "Line %d: Cannot find visual matching ...\n", linenum); + PrintVisualOptions(pCorrection); + fprintf(stderr, "\n"); + return (0); } if (n_matches > 1) { - fprintf(stderr, "Line %d: Found more than one visual matching ...\n", linenum); - PrintVisualOptions(pCorrection); - fprintf(stderr, " Using VisualId 0x%lx\n", (unsigned long)vinfo->visualid); + fprintf(stderr, "Line %d: Found more than one visual matching ...\n", + linenum); + PrintVisualOptions(pCorrection); + fprintf(stderr, " Using VisualId 0x%lx\n", + (unsigned long) vinfo->visualid); } - memcpy((char*)&pCorrection->visual_info, (char*)vinfo, - sizeof(XVisualInfo)); + memcpy((char *) &pCorrection->visual_info, (char *) vinfo, + sizeof(XVisualInfo)); return (1); } - /************************************************************************ * * @@ -1430,34 +1475,35 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, char *pStr; char buf[BUFSIZ]; char *keyword, *token1, *token2, *token3; - int state = 0; + int state = 0; int VisualFlag = -2; Window root; XDCCC_Matrix matrix; - XDCCC_Correction* CorrectionTail = (XDCCC_Correction*)NULL; - XDCCC_Correction* CorrectionHead = (XDCCC_Correction*)NULL; - XDCCC_Correction* pCurrent; + XDCCC_Correction *CorrectionTail = (XDCCC_Correction *) NULL; + XDCCC_Correction *CorrectionHead = (XDCCC_Correction *) NULL; + XDCCC_Correction *pCurrent; if (screenNumber < 0) { - fprintf(stderr,"Invalid Screen Number %d\n", screenNumber); - return(0); + fprintf(stderr, "Invalid Screen Number %d\n", screenNumber); + return (0); } root = RootWindow(pDpy, screenNumber); if (!root) { - /* if no root window is available then return an error */ - fprintf(stderr,"Could not open root window supplied.\n "); - return (0); + /* if no root window is available then return an error */ + fprintf(stderr, "Could not open root window supplied.\n "); + return (0); } /* * Open the file, determine its size, then read it into memory. */ if (filename == NULL) { - stream = stdin; - filename = "stdin"; - } else if ((stream = fopen(filename, "r")) == NULL) { - fprintf(stderr,"Could not open file %s.\n", filename); - return (0); + stream = stdin; + filename = "stdin"; + } + else if ((stream = fopen(filename, "r")) == NULL) { + fprintf(stderr, "Could not open file %s.\n", filename); + return (0); } /* @@ -1465,267 +1511,271 @@ LoadSCCData(Display *pDpy, int screenNumber, const char *filename, * Anything before this keyword is just treated as comments. */ - while((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { - keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char *)NULL && - (strcmp(keyword, SC_BEGIN_KEYWORD) == 0)) { - break; - } /* else ignore the line */ + while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { + keyword = strtok(buf, DATA_DELIMS); + if (keyword != (char *) NULL && + (strcmp(keyword, SC_BEGIN_KEYWORD) == 0)) { + break; + } /* else ignore the line */ } if (pStr == NULL) { - fprintf(stderr,"File %s is missing %s\n", filename, SC_BEGIN_KEYWORD); - closeS (stream, CorrectionHead); - return (0); + fprintf(stderr, "File %s is missing %s\n", filename, SC_BEGIN_KEYWORD); + closeS(stream, CorrectionHead); + return (0); } - token1 = strtok((char*)NULL, DATA_DELIMS); - if ( token1 && (strcmp(token1, TXT_FORMAT_VERSION) != 0) && - (strcmp(token1, "0.3") != 0)) { - fprintf(stderr, - "Screen data format version mismatch in file %s-- expected %s, found %s\n", - filename, TXT_FORMAT_VERSION, token1); - closeS (stream, CorrectionHead); - return (0); + token1 = strtok((char *) NULL, DATA_DELIMS); + if (token1 && (strcmp(token1, TXT_FORMAT_VERSION) != 0) && + (strcmp(token1, "0.3") != 0)) { + fprintf(stderr, + "Screen data format version mismatch in file %s-- expected %s, found %s\n", + filename, TXT_FORMAT_VERSION, token1); + closeS(stream, CorrectionHead); + return (0); } while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { - keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char*)NULL) { - switch (SCKeyOf(keyword)) { - case COMMENT : - case NAME : - case PART_NUMBER : - case MODEL : - case SERIAL_NUMBER : - case REVISION : - /* Do nothing */ - break; - case SCREEN_CLASS : - token1 = strtok((char*)NULL, DATA_DELIMS); - token2 = strtok((char*)NULL, DATA_DELIMS); - if ((token1 == (char*)NULL) - || ((VisualFlag = SCScrnClassOf(token1)) == -1)) { - closeS (stream, CorrectionHead); - return (0); - } - /*include code to handle screen number input*/ - if (token2 != (char*)NULL) { - screenNumber = atoi(token2); - - if (screenNumber < 0) { - fprintf(stderr,"Invalid Screen Number %d\n", - screenNumber); - } - else { - root = RootWindow(pDpy, screenNumber); - if (!root) { - /* if no root window is available then return an error */ - fprintf(stderr, - "Could not open root window supplied.\n "); - return (0); - } - } - } - break; - case COLORIMETRIC_BEGIN : - if (VisualFlag == -2) { - closeS (stream, CorrectionHead); - return (0); - } - if (!ProcessColorimetric(stream, - &matrix, VisualFlag)) { - closeS (stream, CorrectionHead); - return (0); - } - state |= 0x02; - break; - case IPROFILE_BEGIN : - if (VisualFlag == -2) { - closeS (stream, CorrectionHead); - return (0); - } - token1 = strtok((char*)NULL, DATA_DELIMS); - token2 = strtok((char*)NULL, DATA_DELIMS); - if ((token1 == (char*)NULL) || (token2 == (char*)NULL)) { - fprintf(stderr, - "Line %d: Intensity profile missing TableType and/or nTables.", - linenum); - closeS (stream, CorrectionHead); - return (0); - } - - if ((pCurrent = (XDCCC_Correction *) - calloc(1, sizeof(XDCCC_Correction))) ==NULL) { - fprintf(stderr, - "Line %d: Could not allocate memory for intensity profile.", - linenum); - closeS (stream, CorrectionHead); - return (0); - } - - if (sscanf(token1, "%d", &pCurrent->tableType) != 1 || - (pCurrent->tableType < 0 || pCurrent->tableType > 1)) { - fprintf(stderr, - "Line %d: invalid table type specified -- %s\n", - linenum, buf); - closeS (stream, CorrectionHead); - return (0); - } - - if ((VisualFlag == VIDEO_RGB) && (token2 == (char *)NULL)) { - fprintf(stderr, - "Line %d: invalid number of tables specified -- %s\n", - linenum, buf); - closeS (stream, CorrectionHead); - return (0); - } - - if (VisualFlag == VIDEO_RGB) { - if (sscanf(token2, "%d", &pCurrent->nTables) != 1 || - (pCurrent->nTables != 0 && pCurrent->nTables != 1 - && pCurrent->nTables != 3)) { - fprintf(stderr, - "Line %d: invalid number of tables (must be 0, 1, or 3)\n", - linenum); - closeS (stream, CorrectionHead); - return (0); - } - } else { - pCurrent->nTables = 0; - } - - token3 = strtok((char*)NULL, "\n"); - if (token3 != (char*)NULL) { - if (!ParseVisualOptions(pDpy, pCurrent, token3)) { - goto ByPassThisIProfile; - } - } - - switch (pCurrent->nTables) { - case 3 : - if (!(pCurrent->pRedTbl = (IntensityTbl *) - calloc (1, sizeof (IntensityTbl)))) { - fprintf(stderr, - "Line %d: Could not allocate Red Intensity Table\n", - linenum); - closeS (stream, CorrectionHead); - return (0); - } - if (!(pCurrent->pGreenTbl = (IntensityTbl *) - calloc (1, sizeof (IntensityTbl)))) { - fprintf(stderr, - "Line %d: Could not allocate Green Intensity Table\n", - linenum); - closeS (stream, CorrectionHead); - return (0); - } - if (!(pCurrent->pBlueTbl = (IntensityTbl *) - calloc (1, sizeof (IntensityTbl)))) { - fprintf(stderr, - "Line %d: Could not allocate Blue Intensity Table", - linenum); - closeS (stream, CorrectionHead); - return (0); - } - if (!ProcessIProfile(stream, pCurrent)) { - goto ByPassThisIProfile; - } - break; - case 1 : - if (!(pCurrent->pRedTbl = (IntensityTbl *) - calloc (1, sizeof (IntensityTbl)))) { - fprintf(stderr, - "Line %d: Could not allocate Red Intensity Table", - linenum); - closeS (stream, CorrectionHead); - return (0); - } - pCurrent->pGreenTbl = pCurrent->pRedTbl; - pCurrent->pBlueTbl = pCurrent->pRedTbl; - if (!ProcessIProfile(stream, pCurrent)) { - goto ByPassThisIProfile; - } - break; - default : - /* do nothing */ - break; - } - - if (CorrectionHead == NULL) { - CorrectionHead = CorrectionTail = pCurrent; - } else { - CorrectionTail->next = pCurrent; - CorrectionTail = pCurrent; - } - state |= 0x04; - break; -ByPassThisIProfile: - /* read till INTENSITY_PROFILE_END */ - while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { - keyword = strtok(buf, DATA_DELIMS); - if (keyword != (char*)NULL) { - switch (SCKeyOf(keyword)) { - case ITBL_BEGIN: - case ITBL_END: - case COMMENT: - case DATA: - break; - case IPROFILE_END: - goto IProfileProcessed; - default: - closeS (stream, CorrectionHead); - return (0); - } - } - } - free(pCurrent); -IProfileProcessed: - state |= 0x04; - break; - case SC_END : - if (!(state & 0x02)) { - fprintf(stderr, - "File %s is missing Colorimetric data.\n", - filename); - closeS (stream, CorrectionHead); - return (0); - } - if (!(state & 0x04)) { - fprintf(stderr, - "File %s is missing Intensity Profile Data.\n", - filename); - } - if (VisualFlag == VIDEO_RGB) { - LoadMatrix(pDpy, root, &matrix); - if (!LoadCorrections(pDpy, root, CorrectionHead, - targetFormat)) { - closeS (stream, CorrectionHead); - return (0); - } + keyword = strtok(buf, DATA_DELIMS); + if (keyword != (char *) NULL) { + switch (SCKeyOf(keyword)) { + case COMMENT: + case NAME: + case PART_NUMBER: + case MODEL: + case SERIAL_NUMBER: + case REVISION: + /* Do nothing */ + break; + case SCREEN_CLASS: + token1 = strtok((char *) NULL, DATA_DELIMS); + token2 = strtok((char *) NULL, DATA_DELIMS); + if ((token1 == (char *) NULL) + || ((VisualFlag = SCScrnClassOf(token1)) == -1)) { + closeS(stream, CorrectionHead); + return (0); + } + /*include code to handle screen number input */ + if (token2 != (char *) NULL) { + screenNumber = atoi(token2); + + if (screenNumber < 0) { + fprintf(stderr, "Invalid Screen Number %d\n", + screenNumber); + } + else { + root = RootWindow(pDpy, screenNumber); + if (!root) { + /* if no root window is available then return an error */ + fprintf(stderr, + "Could not open root window supplied.\n "); + return (0); + } + } + } + break; + case COLORIMETRIC_BEGIN: + if (VisualFlag == -2) { + closeS(stream, CorrectionHead); + return (0); + } + if (!ProcessColorimetric(stream, &matrix, VisualFlag)) { + closeS(stream, CorrectionHead); + return (0); + } + state |= 0x02; + break; + case IPROFILE_BEGIN: + if (VisualFlag == -2) { + closeS(stream, CorrectionHead); + return (0); + } + token1 = strtok((char *) NULL, DATA_DELIMS); + token2 = strtok((char *) NULL, DATA_DELIMS); + if ((token1 == (char *) NULL) || (token2 == (char *) NULL)) { + fprintf(stderr, + "Line %d: Intensity profile missing TableType and/or nTables.", + linenum); + closeS(stream, CorrectionHead); + return (0); + } + + if ((pCurrent = (XDCCC_Correction *) + calloc(1, sizeof(XDCCC_Correction))) == NULL) { + fprintf(stderr, + "Line %d: Could not allocate memory for intensity profile.", + linenum); + closeS(stream, CorrectionHead); + return (0); + } + + if (sscanf(token1, "%d", &pCurrent->tableType) != 1 || + (pCurrent->tableType < 0 || pCurrent->tableType > 1)) { + fprintf(stderr, + "Line %d: invalid table type specified -- %s\n", + linenum, buf); + closeS(stream, CorrectionHead); + return (0); + } + + if ((VisualFlag == VIDEO_RGB) && (token2 == (char *) NULL)) { + fprintf(stderr, + "Line %d: invalid number of tables specified -- %s\n", + linenum, buf); + closeS(stream, CorrectionHead); + return (0); + } + + if (VisualFlag == VIDEO_RGB) { + if (sscanf(token2, "%d", &pCurrent->nTables) != 1 || + (pCurrent->nTables != 0 && pCurrent->nTables != 1 + && pCurrent->nTables != 3)) { + fprintf(stderr, + "Line %d: invalid number of tables (must be 0, 1, or 3)\n", + linenum); + closeS(stream, CorrectionHead); + return (0); + } + } + else { + pCurrent->nTables = 0; + } + + token3 = strtok((char *) NULL, "\n"); + if (token3 != (char *) NULL) { + if (!ParseVisualOptions(pDpy, pCurrent, token3)) { + goto ByPassThisIProfile; + } + } + + switch (pCurrent->nTables) { + case 3: + if (!(pCurrent->pRedTbl = (IntensityTbl *) + calloc(1, sizeof(IntensityTbl)))) { + fprintf(stderr, + "Line %d: Could not allocate Red Intensity Table\n", + linenum); + closeS(stream, CorrectionHead); + return (0); + } + if (!(pCurrent->pGreenTbl = (IntensityTbl *) + calloc(1, sizeof(IntensityTbl)))) { + fprintf(stderr, + "Line %d: Could not allocate Green Intensity Table\n", + linenum); + closeS(stream, CorrectionHead); + return (0); + } + if (!(pCurrent->pBlueTbl = (IntensityTbl *) + calloc(1, sizeof(IntensityTbl)))) { + fprintf(stderr, + "Line %d: Could not allocate Blue Intensity Table", + linenum); + closeS(stream, CorrectionHead); + return (0); + } + if (!ProcessIProfile(stream, pCurrent)) { + goto ByPassThisIProfile; + } + break; + case 1: + if (!(pCurrent->pRedTbl = (IntensityTbl *) + calloc(1, sizeof(IntensityTbl)))) { + fprintf(stderr, + "Line %d: Could not allocate Red Intensity Table", + linenum); + closeS(stream, CorrectionHead); + return (0); + } + pCurrent->pGreenTbl = pCurrent->pRedTbl; + pCurrent->pBlueTbl = pCurrent->pRedTbl; + if (!ProcessIProfile(stream, pCurrent)) { + goto ByPassThisIProfile; + } + break; + default: + /* do nothing */ + break; + } + + if (CorrectionHead == NULL) { + CorrectionHead = CorrectionTail = pCurrent; + } + else { + CorrectionTail->next = pCurrent; + CorrectionTail = pCurrent; + } + state |= 0x04; + break; + ByPassThisIProfile: + /* read till INTENSITY_PROFILE_END */ + while ((pStr = nextline(buf, BUFSIZ, stream)) != NULL) { + keyword = strtok(buf, DATA_DELIMS); + if (keyword != (char *) NULL) { + switch (SCKeyOf(keyword)) { + case ITBL_BEGIN: + case ITBL_END: + case COMMENT: + case DATA: + break; + case IPROFILE_END: + goto IProfileProcessed; + default: + closeS(stream, CorrectionHead); + return (0); + } + } + } + free(pCurrent); + IProfileProcessed: + state |= 0x04; + break; + case SC_END: + if (!(state & 0x02)) { + fprintf(stderr, + "File %s is missing Colorimetric data.\n", + filename); + closeS(stream, CorrectionHead); + return (0); + } + if (!(state & 0x04)) { + fprintf(stderr, + "File %s is missing Intensity Profile Data.\n", + filename); + } + if (VisualFlag == VIDEO_RGB) { + LoadMatrix(pDpy, root, &matrix); + if (!LoadCorrections(pDpy, root, CorrectionHead, + targetFormat)) { + closeS(stream, CorrectionHead); + return (0); + } #ifdef GRAY - } else if (VisualFlag == VIDEO_GRAY) { - if (!LoadDataGray(pDpy, root, - pCurrent->tableType, pScreenData, targetFormat)) { - closeS (stream, CorrectionHead); - return (0); - } -#endif /* GRAY */ - } else { - fprintf(stderr,"File %s Visual missing.", filename); - } - closeS (stream, CorrectionHead); - return (1); - - default : - fprintf(stderr,"Line %d: extraneous keyword %s\n", - linenum, keyword); - closeS (stream, CorrectionHead); - return (0); - - } - } /* else it was just a blank line */ + } + else if (VisualFlag == VIDEO_GRAY) { + if (!LoadDataGray(pDpy, root, + pCurrent->tableType, pScreenData, + targetFormat)) { + closeS(stream, CorrectionHead); + return (0); + } +#endif /* GRAY */ + } + else { + fprintf(stderr, "File %s Visual missing.", filename); + } + closeS(stream, CorrectionHead); + return (1); + + default: + fprintf(stderr, "Line %d: extraneous keyword %s\n", + linenum, keyword); + closeS(stream, CorrectionHead); + return (0); + + } + } /* else it was just a blank line */ } - closeS (stream, CorrectionHead); + closeS(stream, CorrectionHead); return (1); } diff --git a/xcmsdb.c b/xcmsdb.c index 4fe579a..c02968a 100644 --- a/xcmsdb.c +++ b/xcmsdb.c @@ -36,7 +36,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include @@ -51,39 +51,37 @@ static void QuerySCCDataRGB(Display *dpy, Window root); static void RemoveSCCData(Display *dpy, Window root, int colorFlag); static unsigned long _XcmsGetElement(int format, char **pValue, - unsigned long *pCount); + unsigned long *pCount); static int _XcmsGetProperty(Display *pDpy, Window w, Atom property, - int *pFormat, unsigned long *pNItems, - unsigned long *pNBytes, char **pValue); - + int *pFormat, unsigned long *pNItems, + unsigned long *pNBytes, char **pValue); static char *ProgramName; static void -Syntax (int exitcode) +Syntax(int exitcode) { - fprintf (stderr, - "usage: %s [-options ...] [filename]\n\n%s", - ProgramName, - "where options include:\n" - " -display host:dpy[.scrn] display to use\n" - " -format [ 32 | 16 | 8 ] property format\n" - " -query query Screen Color Characterization Data\n" - " -remove remove Screen Color Characterization Data\n" + fprintf(stderr, + "usage: %s [-options ...] [filename]\n\n%s", + ProgramName, + "where options include:\n" + " -display host:dpy[.scrn] display to use\n" + " -format [ 32 | 16 | 8 ] property format\n" + " -query query Screen Color Characterization Data\n" + " -remove remove Screen Color Characterization Data\n" #ifdef GRAY - " -color use color as default\n"); - " -gray use gray-scale as default\n"); -#endif /* GRAY */ - " -version print program version\n" - "\n"); - exit (exitcode); + " -color use color as default\n" + " -gray use gray-scale as default\n" +#endif /* GRAY */ + " -version print program version\n" "\n"); + exit(exitcode); } static void -MissingArg (const char *option) +MissingArg(const char *option) { - fprintf (stderr, "%s: %s requires an argument\n", ProgramName, option); - Syntax (1); + fprintf(stderr, "%s: %s requires an argument\n", ProgramName, option); + Syntax(1); } static Bool @@ -92,18 +90,18 @@ optionmatch(const char *opt, const char *arg, int minlen) int arglen; if (strcmp(opt, arg) == 0) { - return(True); + return (True); } - if ((arglen = strlen(arg)) >= (int)strlen(opt) || arglen < minlen) { - return(False); + if ((arglen = strlen(arg)) >= (int) strlen(opt) || arglen < minlen) { + return (False); } - if (strncmp (opt, arg, arglen) == 0) { - return(True); + if (strncmp(opt, arg, arglen) == 0) { + return (True); } - return(False); + return (False); } int @@ -122,96 +120,104 @@ main(int argc, char *argv[]) ProgramName = argv[0]; for (i = 1; i < argc; i++) { - char *arg = argv[i]; - - if (arg[0] == '-') { - if (arg[1] == '\0') { - filename = NULL; - continue; - } else if (optionmatch ("-help", arg, 1)) { - Syntax (0); - /* doesn't return */ - } else if (optionmatch ("-display", arg, 1)) { - if (++i >= argc) MissingArg ("-display"); - displayname = argv[i]; - continue; - } else if (optionmatch ("-format", arg, 1)) { - if (++i >= argc) MissingArg ("-format"); - targetFormat = atoi(argv[i]); - if (targetFormat != 32 && targetFormat != 16 && - targetFormat != 8) { - fprintf (stderr, "%s: invalid value for -format: %d\n", - ProgramName, targetFormat); - Syntax (1); - } - continue; - } else if (optionmatch ("-query", arg, 1)) { - query = 1; - continue; - } else if (optionmatch ("-remove", arg, 1)) { - remove = 1; - continue; + char *arg = argv[i]; + + if (arg[0] == '-') { + if (arg[1] == '\0') { + filename = NULL; + continue; + } + else if (optionmatch("-help", arg, 1)) { + Syntax(0); + /* doesn't return */ + } + else if (optionmatch("-display", arg, 1)) { + if (++i >= argc) + MissingArg("-display"); + displayname = argv[i]; + continue; + } + else if (optionmatch("-format", arg, 1)) { + if (++i >= argc) + MissingArg("-format"); + targetFormat = atoi(argv[i]); + if (targetFormat != 32 && targetFormat != 16 && + targetFormat != 8) { + fprintf(stderr, "%s: invalid value for -format: %d\n", + ProgramName, targetFormat); + Syntax(1); + } + continue; + } + else if (optionmatch("-query", arg, 1)) { + query = 1; + continue; + } + else if (optionmatch("-remove", arg, 1)) { + remove = 1; + continue; #ifdef GRAY - } else if (optionmatch ("-color", arg, 1)) { - color = 1; - continue; - } else if (optionmatch ("-gray", arg, 1)) { - color = 0; - continue; -#endif /* GRAY */ - } else if (optionmatch ("-version", arg, 1)) { - puts (PACKAGE_STRING); - exit (0); - } - fprintf (stderr, "%s: unrecognized option '%s'\n", - ProgramName, arg); - Syntax (1); - } else { - load = 1; - filename = arg; - } + } + else if (optionmatch("-color", arg, 1)) { + color = 1; + continue; + } + else if (optionmatch("-gray", arg, 1)) { + color = 0; + continue; +#endif /* GRAY */ + } + else if (optionmatch("-version", arg, 1)) { + puts(PACKAGE_STRING); + exit(0); + } + fprintf(stderr, "%s: unrecognized option '%s'\n", ProgramName, arg); + Syntax(1); + } + else { + load = 1; + filename = arg; + } } /* Open display */ - if (!(dpy = XOpenDisplay (displayname))) { - fprintf (stderr, "%s: Can't open display '%s'\n", - ProgramName, XDisplayName(displayname)); - exit (1); + if (!(dpy = XOpenDisplay(displayname))) { + fprintf(stderr, "%s: Can't open display '%s'\n", + ProgramName, XDisplayName(displayname)); + exit(1); } if (query || remove) { - load = 0; + load = 0; } if (load) { - LoadSCCData(dpy, DefaultScreen(dpy), filename, targetFormat); + LoadSCCData(dpy, DefaultScreen(dpy), filename, targetFormat); } if (query) { - if (color != 0) - QuerySCCDataRGB(dpy, RootWindow(dpy, DefaultScreen(dpy))); + if (color != 0) + QuerySCCDataRGB(dpy, RootWindow(dpy, DefaultScreen(dpy))); #ifdef GRAY - if (color != 1) - QuerySCCDataGray(dpy, RootWindow(dpy, DefaultScreen(dpy))); + if (color != 1) + QuerySCCDataGray(dpy, RootWindow(dpy, DefaultScreen(dpy))); #endif /* GRAY */ } if (remove) { - RemoveSCCData(dpy, RootWindow(dpy, DefaultScreen(dpy)), color); + RemoveSCCData(dpy, RootWindow(dpy, DefaultScreen(dpy)), color); } XCloseDisplay(dpy); - exit (0); + exit(0); /*NOTREACHED*/ } - static Atom ParseAtom(Display *dpy, const char *name, int only_flag) { - return(XInternAtom(dpy, name, only_flag)); + return (XInternAtom(dpy, name, only_flag)); } - /* * NAME @@ -235,39 +241,38 @@ PrintTableType0(int format, char **pChar, unsigned long *pCount) XcmsFloat fValue; nElements = _XcmsGetElement(format, pChar, pCount) + 1; - printf ("\t length:%d\n", nElements); + printf("\t length:%d\n", nElements); switch (format) { - case 8: - while (nElements--) { - /* 0xFFFF/0xFF = 0x101 */ - hValue = _XcmsGetElement (format, pChar, pCount) * 0x101; - fValue = _XcmsGetElement (format, pChar, pCount) - / (XcmsFloat)255.0; - printf ("\t\t0x%x\t%8.5f\n", hValue, fValue); - } - break; - case 16: - while (nElements--) { - hValue = _XcmsGetElement (format, pChar, pCount); - fValue = _XcmsGetElement (format, pChar, pCount) - / (XcmsFloat)65535.0; - printf ("\t\t0x%x\t%8.5f\n", hValue, fValue); - } - break; - case 32: - while (nElements--) { - hValue = _XcmsGetElement (format, pChar, pCount); - fValue = _XcmsGetElement (format, pChar, pCount) - / (XcmsFloat)4294967295.0; - printf ("\t\t0x%x\t%8.5f\n", hValue, fValue); - } - break; - default: - return; + case 8: + while (nElements--) { + /* 0xFFFF/0xFF = 0x101 */ + hValue = _XcmsGetElement(format, pChar, pCount) * 0x101; + fValue = _XcmsGetElement(format, pChar, pCount) + / (XcmsFloat) 255.0; + printf("\t\t0x%x\t%8.5f\n", hValue, fValue); + } + break; + case 16: + while (nElements--) { + hValue = _XcmsGetElement(format, pChar, pCount); + fValue = _XcmsGetElement(format, pChar, pCount) + / (XcmsFloat) 65535.0; + printf("\t\t0x%x\t%8.5f\n", hValue, fValue); + } + break; + case 32: + while (nElements--) { + hValue = _XcmsGetElement(format, pChar, pCount); + fValue = _XcmsGetElement(format, pChar, pCount) + / (XcmsFloat) 4294967295.0; + printf("\t\t0x%x\t%8.5f\n", hValue, fValue); + } + break; + default: + return; } } - /* * NAME @@ -292,38 +297,37 @@ PrintTableType1(int format, char **pChar, unsigned long *pCount) XcmsFloat fValue; max_index = _XcmsGetElement(format, pChar, pCount); - printf ("\t length:%d\n", max_index + 1); + printf("\t length:%d\n", max_index + 1); switch (format) { - case 8: - for (count = 0; count < max_index+1; count++) { - hValue = (count * 65535) / max_index; - fValue = _XcmsGetElement (format, pChar, pCount) - / (XcmsFloat)255.0; - printf ("\t\t0x%x\t%8.5f\n", hValue, fValue); - } - break; - case 16: - for (count = 0; count < max_index+1; count++) { - hValue = (count * 65535) / max_index; - fValue = _XcmsGetElement (format, pChar, pCount) - / (XcmsFloat)65535.0; - printf ("\t\t0x%x\t%8.5f\n", hValue, fValue); - } - break; - case 32: - for (count = 0; count < max_index+1; count++) { - hValue = (count * 65535) / max_index; - fValue = _XcmsGetElement (format, pChar, pCount) - / (XcmsFloat)4294967295.0; - printf ("\t\t0x%x\t%8.5f\n", hValue, fValue); - } - break; - default: - return; + case 8: + for (count = 0; count < max_index + 1; count++) { + hValue = (count * 65535) / max_index; + fValue = _XcmsGetElement(format, pChar, pCount) + / (XcmsFloat) 255.0; + printf("\t\t0x%x\t%8.5f\n", hValue, fValue); + } + break; + case 16: + for (count = 0; count < max_index + 1; count++) { + hValue = (count * 65535) / max_index; + fValue = _XcmsGetElement(format, pChar, pCount) + / (XcmsFloat) 65535.0; + printf("\t\t0x%x\t%8.5f\n", hValue, fValue); + } + break; + case 32: + for (count = 0; count < max_index + 1; count++) { + hValue = (count * 65535) / max_index; + fValue = _XcmsGetElement(format, pChar, pCount) + / (XcmsFloat) 4294967295.0; + printf("\t\t0x%x\t%8.5f\n", hValue, fValue); + } + break; + default: + return; } } - /* * NAME @@ -332,7 +336,7 @@ PrintTableType1(int format, char **pChar, unsigned long *pCount) * SYNOPSIS */ static void -QuerySCCDataRGB(Display *dpy, Window root) +QuerySCCDataRGB(Display * dpy, Window root) /* * DESCRIPTION * @@ -341,214 +345,218 @@ QuerySCCDataRGB(Display *dpy, Window root) */ { char *property_return, *pChar; - int i, j; - int count, format, cType, nTables; + int i, j; + int count, format, cType, nTables; unsigned long nitems, nbytes_return; Atom MatricesAtom, CorrectAtom; VisualID visualID; XVisualInfo vinfo_template, *vinfo_ret; int nvis; + static const char *visual_strings[] = { - "StaticGray", - "GrayScale", - "StaticColor", - "PseudoColor", - "TrueColor", - "DirectColor" - }; + "StaticGray", + "GrayScale", + "StaticColor", + "PseudoColor", + "TrueColor", + "DirectColor" + }; /* * Get Matrices */ - MatricesAtom = ParseAtom (dpy, XDCCC_MATRIX_ATOM_NAME, True); + MatricesAtom = ParseAtom(dpy, XDCCC_MATRIX_ATOM_NAME, True); if (MatricesAtom != None) { - if (_XcmsGetProperty (dpy, root, MatricesAtom, &format, &nitems, - &nbytes_return, &property_return) == XcmsFailure) { - format = 0; - } else if (nitems != 18) { - printf ("Property %s had invalid length of %ld\n", - XDCCC_MATRIX_ATOM_NAME, nitems); - if (property_return) { - XFree (property_return); - } - return; - } + if (_XcmsGetProperty(dpy, root, MatricesAtom, &format, &nitems, + &nbytes_return, &property_return) == XcmsFailure) { + format = 0; + } + else if (nitems != 18) { + printf("Property %s had invalid length of %ld\n", + XDCCC_MATRIX_ATOM_NAME, nitems); + if (property_return) { + XFree(property_return); + } + return; + } } if (MatricesAtom == None || !format) { - printf ("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME); - } else if (format != 32) { - printf ("Data in property %s not in 32 bit format\n", - XDCCC_MATRIX_ATOM_NAME); - } else { - pChar = property_return; - printf ("Screen: %d\n", DefaultScreen(dpy)); - printf ("Querying property %s\n", XDCCC_MATRIX_ATOM_NAME); - printf ("\tXYZtoRGB matrix :\n"); - for (i = 0; i < 3; i++) { - printf ("\t"); - for (j = 0; j < 3; j++) { - printf ("\t%8.5f", - (long)_XcmsGetElement(format, &pChar, &nitems) - / (XcmsFloat) XDCCC_NUMBER); - } - printf ("\n"); - } - printf ("\tRGBtoXYZ matrix :\n"); - for (i = 0; i < 3; i++) { - printf ("\t"); - for (j = 0; j < 3; j++) { - printf ("\t%8.5f", - (long) _XcmsGetElement(format, &pChar, &nitems) - / (XcmsFloat) XDCCC_NUMBER); - } - printf ("\n"); - } - XFree (property_return); + printf("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME); + } + else if (format != 32) { + printf("Data in property %s not in 32 bit format\n", + XDCCC_MATRIX_ATOM_NAME); + } + else { + pChar = property_return; + printf("Screen: %d\n", DefaultScreen(dpy)); + printf("Querying property %s\n", XDCCC_MATRIX_ATOM_NAME); + printf("\tXYZtoRGB matrix :\n"); + for (i = 0; i < 3; i++) { + printf("\t"); + for (j = 0; j < 3; j++) { + printf("\t%8.5f", + (long) _XcmsGetElement(format, &pChar, &nitems) + / (XcmsFloat) XDCCC_NUMBER); + } + printf("\n"); + } + printf("\tRGBtoXYZ matrix :\n"); + for (i = 0; i < 3; i++) { + printf("\t"); + for (j = 0; j < 3; j++) { + printf("\t%8.5f", + (long) _XcmsGetElement(format, &pChar, &nitems) + / (XcmsFloat) XDCCC_NUMBER); + } + printf("\n"); + } + XFree(property_return); } - /* * Get Intensity Tables */ - CorrectAtom = XInternAtom (dpy, XDCCC_CORRECT_ATOM_NAME, True); + CorrectAtom = XInternAtom(dpy, XDCCC_CORRECT_ATOM_NAME, True); if (CorrectAtom != None) { - if (_XcmsGetProperty (dpy, root, CorrectAtom, &format, &nitems, - &nbytes_return, &property_return) == XcmsFailure) { - format = 0; - } else if (nitems <= 0) { - printf ("Property %s had invalid length of %ld\n", - XDCCC_CORRECT_ATOM_NAME, nitems); - if (property_return) { - XFree (property_return); - } - return; - } + if (_XcmsGetProperty(dpy, root, CorrectAtom, &format, &nitems, + &nbytes_return, &property_return) == XcmsFailure) { + format = 0; + } + else if (nitems <= 0) { + printf("Property %s had invalid length of %ld\n", + XDCCC_CORRECT_ATOM_NAME, nitems); + if (property_return) { + XFree(property_return); + } + return; + } } if (CorrectAtom == None || !format) { - printf ("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME); - } else { - printf ("\nQuerying property %s\n", XDCCC_CORRECT_ATOM_NAME); - pChar = property_return; - - while (nitems) { - switch (format) { - case 8: - /* - * Must have at least: - * VisualID0 - * VisualID1 - * VisualID2 - * VisualID3 - * type - * count - * length - * intensity1 - * intensity2 - */ - if (nitems < 9) { - goto IntensityTblError; - } - count = 3; - break; - case 16: - /* - * Must have at least: - * VisualID0 - * VisualID3 - * type - * count - * length - * intensity1 - * intensity2 - */ - if (nitems < 7) { - goto IntensityTblError; - } - count = 1; - break; - case 32: - /* - * Must have at least: - * VisualID0 - * type - * count - * length - * intensity1 - * intensity2 - */ - if (nitems < 6) { - goto IntensityTblError; - } - count = 0; - break; - default: - goto IntensityTblError; - } - - /* - * Get VisualID - */ - visualID = _XcmsGetElement(format, &pChar, &nitems); - /* add the depth, class, and bits info in output */ - vinfo_template.visualid = visualID; - vinfo_ret = XGetVisualInfo(dpy, VisualIDMask, &vinfo_template, - &nvis); - while (count--) { - visualID = visualID << format; - visualID |= _XcmsGetElement(format, &pChar, &nitems); - } - - if (vinfo_ret != NULL) { - printf - ("\n\tVisualID: 0x%lx class: %s depth: %d bits_per_rgb: %d\n", - visualID, visual_strings[vinfo_ret->class], - vinfo_ret->depth, vinfo_ret->bits_per_rgb); - } - else - printf ("\n\tVisualID: 0x%lx\n", visualID); - XFree(vinfo_ret); - cType = _XcmsGetElement(format, &pChar, &nitems); - printf ("\ttype: %d\n", cType); - nTables = _XcmsGetElement(format, &pChar, &nitems); - printf ("\tcount: %d\n", nTables); - - switch (cType) { - case 0: - /* Red Table should always exist */ - printf ("\tRed Conversion Table:\n"); - PrintTableType0(format, &pChar, &nitems); - if (nTables > 1) { - printf ("\tGreen Conversion Table:\n"); - PrintTableType0(format, &pChar, &nitems); - printf ("\tBlue Conversion Table:\n"); - PrintTableType0(format, &pChar, &nitems); - } - break; - case 1: - /* Red Table should always exist */ - printf ("\tRed Conversion Table:\n"); - PrintTableType1(format, &pChar, &nitems); - if (nTables > 1) { - printf ("\tGreen Conversion Table:\n"); - PrintTableType1(format, &pChar, &nitems); - printf ("\tBlue Conversion Table:\n"); - PrintTableType1(format, &pChar, &nitems); - } - break; - default: - goto IntensityTblError; - } - } - XFree (property_return); + printf("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME); + } + else { + printf("\nQuerying property %s\n", XDCCC_CORRECT_ATOM_NAME); + pChar = property_return; + + while (nitems) { + switch (format) { + case 8: + /* + * Must have at least: + * VisualID0 + * VisualID1 + * VisualID2 + * VisualID3 + * type + * count + * length + * intensity1 + * intensity2 + */ + if (nitems < 9) { + goto IntensityTblError; + } + count = 3; + break; + case 16: + /* + * Must have at least: + * VisualID0 + * VisualID3 + * type + * count + * length + * intensity1 + * intensity2 + */ + if (nitems < 7) { + goto IntensityTblError; + } + count = 1; + break; + case 32: + /* + * Must have at least: + * VisualID0 + * type + * count + * length + * intensity1 + * intensity2 + */ + if (nitems < 6) { + goto IntensityTblError; + } + count = 0; + break; + default: + goto IntensityTblError; + } + + /* + * Get VisualID + */ + visualID = _XcmsGetElement(format, &pChar, &nitems); + /* add the depth, class, and bits info in output */ + vinfo_template.visualid = visualID; + vinfo_ret = XGetVisualInfo(dpy, VisualIDMask, &vinfo_template, + &nvis); + while (count--) { + visualID = visualID << format; + visualID |= _XcmsGetElement(format, &pChar, &nitems); + } + + if (vinfo_ret != NULL) { + printf + ("\n\tVisualID: 0x%lx class: %s depth: %d bits_per_rgb: %d\n", + visualID, visual_strings[vinfo_ret->class], + vinfo_ret->depth, vinfo_ret->bits_per_rgb); + } + else + printf("\n\tVisualID: 0x%lx\n", visualID); + XFree(vinfo_ret); + cType = _XcmsGetElement(format, &pChar, &nitems); + printf("\ttype: %d\n", cType); + nTables = _XcmsGetElement(format, &pChar, &nitems); + printf("\tcount: %d\n", nTables); + + switch (cType) { + case 0: + /* Red Table should always exist */ + printf("\tRed Conversion Table:\n"); + PrintTableType0(format, &pChar, &nitems); + if (nTables > 1) { + printf("\tGreen Conversion Table:\n"); + PrintTableType0(format, &pChar, &nitems); + printf("\tBlue Conversion Table:\n"); + PrintTableType0(format, &pChar, &nitems); + } + break; + case 1: + /* Red Table should always exist */ + printf("\tRed Conversion Table:\n"); + PrintTableType1(format, &pChar, &nitems); + if (nTables > 1) { + printf("\tGreen Conversion Table:\n"); + PrintTableType1(format, &pChar, &nitems); + printf("\tBlue Conversion Table:\n"); + PrintTableType1(format, &pChar, &nitems); + } + break; + default: + goto IntensityTblError; + } + } + XFree(property_return); } return; -IntensityTblError: - XFree (property_return); + IntensityTblError: + XFree(property_return); printf("Fatal error in %s property\n", XDCCC_CORRECT_ATOM_NAME); } - #ifdef GRAY /* @@ -558,7 +566,7 @@ IntensityTblError: * SYNOPSIS */ int -QuerySCCDataGray(Display *dpy, Window root) +QuerySCCDataGray(Display * dpy, Window root) /* * DESCRIPTION * @@ -567,151 +575,154 @@ QuerySCCDataGray(Display *dpy, Window root) */ { char *property_return, *pChar; - int j; - int count, format, cType; - unsigned long nitems, nbytes_return; + int j; + int count, format, cType; + unsigned long nitems, nbytes_return; Atom MatricesAtom, CorrectAtom; VisualID visualID; - MatricesAtom = ParseAtom (dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True); + MatricesAtom = ParseAtom(dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True); if (MatricesAtom != None) { - if (_XcmsGetProperty (dpy, root, MatricesAtom, &format, &nitems, - &nbytes_return, &property_return) == XcmsFailure) { - format = 0; - } else if (nitems != 3) { - printf ("Property %s had invalid length of %d\n", - XDCCC_SCREENWHITEPT_ATOM_NAME, nitems); - if (property_return) { - XFree (property_return); - } - return; - } + if (_XcmsGetProperty(dpy, root, MatricesAtom, &format, &nitems, + &nbytes_return, &property_return) == XcmsFailure) { + format = 0; + } + else if (nitems != 3) { + printf("Property %s had invalid length of %d\n", + XDCCC_SCREENWHITEPT_ATOM_NAME, nitems); + if (property_return) { + XFree(property_return); + } + return; + } } if (MatricesAtom == None || !format) { - printf ("Could not find property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); - } else { - pChar = property_return; - printf ("\nQuerying property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); - printf ("\tWhite Point XYZ :\n"); - printf ("\t"); - for (j = 0; j < 3; j++) { - printf ("\t%8.5lf", - (long) _XcmsGetElement(format, &pChar, &nitems) / - (XcmsFloat) XDCCC_NUMBER); - } - printf ("\n"); - XFree (property_return); + printf("Could not find property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); + } + else { + pChar = property_return; + printf("\nQuerying property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); + printf("\tWhite Point XYZ :\n"); + printf("\t"); + for (j = 0; j < 3; j++) { + printf("\t%8.5lf", + (long) _XcmsGetElement(format, &pChar, &nitems) / + (XcmsFloat) XDCCC_NUMBER); + } + printf("\n"); + XFree(property_return); } - CorrectAtom = XInternAtom (dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True); + CorrectAtom = XInternAtom(dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True); if (CorrectAtom != None) { - if (_XcmsGetProperty (dpy, root, CorrectAtom, &format, &nitems, - &nbytes_return, &property_return) == XcmsFailure) { - format = 0; - } else if (nitems <= 0) { - printf ("Property %s had invalid length of %d\n", - XDCCC_GRAY_CORRECT_ATOM_NAME, nitems); - if (property_return) { - XFree (property_return); - } - return; - } + if (_XcmsGetProperty(dpy, root, CorrectAtom, &format, &nitems, + &nbytes_return, &property_return) == XcmsFailure) { + format = 0; + } + else if (nitems <= 0) { + printf("Property %s had invalid length of %d\n", + XDCCC_GRAY_CORRECT_ATOM_NAME, nitems); + if (property_return) { + XFree(property_return); + } + return; + } } if (CorrectAtom == None || !format) { - printf ("Could not find property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME); - } else { - printf ("\nQuerying property %s\n\n", XDCCC_GRAY_CORRECT_ATOM_NAME); - pChar = property_return; - - while (nitems) { - switch (format) { - case 8: - /* - * Must have at least: - * VisualID0 - * VisualID1 - * VisualID2 - * VisualID3 - * type - * count - * length - * intensity1 - * intensity2 - */ - if (nitems < 9) { - goto IntensityTblError; - } - count = 3; - break; - case 16: - /* - * Must have at least: - * VisualID0 - * VisualID3 - * type - * count - * length - * intensity1 - * intensity2 - */ - if (nitems < 7) { - goto IntensityTblError; - } - count = 1; - break; - case 32: - /* - * Must have at least: - * VisualID0 - * type - * count - * length - * intensity1 - * intensity2 - */ - if (nitems < 6) { - goto IntensityTblError; - } - count = 0; - break; - default: - goto IntensityTblError; - break; - } - - /* - * Get VisualID - */ - visualID = _XcmsGetElement(format, &pChar, &nitems); - while (count--) { - visualID = visualID << format; - visualID |= _XcmsGetElement(format, &pChar, &nitems); - } - - printf ("\n\tVisualID: 0x%lx\n", visualID); - cType = _XcmsGetElement(format, &pChar, &nitems); - printf ("\ttype: %d\n", cType); - printf ("\tGray Conversion Table:\n"); - switch (cType) { - case 0: - PrintTableType0(format, &pChar, &nitems); - break; - case 1: - PrintTableType1(format, &pChar, &nitems); - break; - default: - goto IntensityTblError; - } - } - XFree (property_return); + printf("Could not find property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME); + } + else { + printf("\nQuerying property %s\n\n", XDCCC_GRAY_CORRECT_ATOM_NAME); + pChar = property_return; + + while (nitems) { + switch (format) { + case 8: + /* + * Must have at least: + * VisualID0 + * VisualID1 + * VisualID2 + * VisualID3 + * type + * count + * length + * intensity1 + * intensity2 + */ + if (nitems < 9) { + goto IntensityTblError; + } + count = 3; + break; + case 16: + /* + * Must have at least: + * VisualID0 + * VisualID3 + * type + * count + * length + * intensity1 + * intensity2 + */ + if (nitems < 7) { + goto IntensityTblError; + } + count = 1; + break; + case 32: + /* + * Must have at least: + * VisualID0 + * type + * count + * length + * intensity1 + * intensity2 + */ + if (nitems < 6) { + goto IntensityTblError; + } + count = 0; + break; + default: + goto IntensityTblError; + break; + } + + /* + * Get VisualID + */ + visualID = _XcmsGetElement(format, &pChar, &nitems); + while (count--) { + visualID = visualID << format; + visualID |= _XcmsGetElement(format, &pChar, &nitems); + } + + printf("\n\tVisualID: 0x%lx\n", visualID); + cType = _XcmsGetElement(format, &pChar, &nitems); + printf("\ttype: %d\n", cType); + printf("\tGray Conversion Table:\n"); + switch (cType) { + case 0: + PrintTableType0(format, &pChar, &nitems); + break; + case 1: + PrintTableType1(format, &pChar, &nitems); + break; + default: + goto IntensityTblError; + } + } + XFree(property_return); } return; -IntensityTblError: - XFree (property_return); + IntensityTblError: + XFree(property_return); printf("Fatal error in %s property\n", XDCCC_CORRECT_ATOM_NAME); } -#endif /* GRAY */ - +#endif /* GRAY */ /* * NAME @@ -730,69 +741,79 @@ RemoveSCCData(Display *dpy, Window root, int colorFlag) { unsigned char *ret_prop; unsigned long ret_len, ret_after; - int ret_format, status = -1; + int ret_format, status = -1; Atom MatricesAtom, CorrectAtom, ret_atom; if (colorFlag != 0) { - MatricesAtom = ParseAtom (dpy, XDCCC_MATRIX_ATOM_NAME, True); - if (MatricesAtom != None) { - status = XGetWindowProperty (dpy, root, MatricesAtom, 0, 8192, - False, XA_INTEGER, &ret_atom, &ret_format, &ret_len, - &ret_after, &ret_prop); - } - if (MatricesAtom == None || status != Success || !ret_format) { - printf ("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME); - } else { - printf ("Deleting property %s\n", XDCCC_MATRIX_ATOM_NAME); - XDeleteProperty (dpy, root, MatricesAtom); - XFree ((char *)ret_prop); - } - - CorrectAtom = XInternAtom (dpy, XDCCC_CORRECT_ATOM_NAME, True); - if (CorrectAtom != None) { - status = XGetWindowProperty (dpy, root, CorrectAtom, 0, 8192, - False, XA_INTEGER, &ret_atom, &ret_format, &ret_len, - &ret_after, &ret_prop); - } - if (CorrectAtom == None || status != Success || !ret_format) { - printf ("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME); - } else { - printf ("Deleting property %s\n", XDCCC_CORRECT_ATOM_NAME); - XDeleteProperty (dpy, root, CorrectAtom); - XFree ((char *)ret_prop); - } + MatricesAtom = ParseAtom(dpy, XDCCC_MATRIX_ATOM_NAME, True); + if (MatricesAtom != None) { + status = XGetWindowProperty(dpy, root, MatricesAtom, 0, 8192, + False, XA_INTEGER, &ret_atom, + &ret_format, &ret_len, &ret_after, + &ret_prop); + } + if (MatricesAtom == None || status != Success || !ret_format) { + printf("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME); + } + else { + printf("Deleting property %s\n", XDCCC_MATRIX_ATOM_NAME); + XDeleteProperty(dpy, root, MatricesAtom); + XFree((char *) ret_prop); + } + + CorrectAtom = XInternAtom(dpy, XDCCC_CORRECT_ATOM_NAME, True); + if (CorrectAtom != None) { + status = XGetWindowProperty(dpy, root, CorrectAtom, 0, 8192, + False, XA_INTEGER, &ret_atom, + &ret_format, &ret_len, &ret_after, + &ret_prop); + } + if (CorrectAtom == None || status != Success || !ret_format) { + printf("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME); + } + else { + printf("Deleting property %s\n", XDCCC_CORRECT_ATOM_NAME); + XDeleteProperty(dpy, root, CorrectAtom); + XFree((char *) ret_prop); + } } #ifdef GRAY if (colorFlag != 1) { - MatricesAtom = ParseAtom (dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True); - if (MatricesAtom != None) { - status = XGetWindowProperty (dpy, root, MatricesAtom, 0, 8192, - False, XA_INTEGER, &ret_atom, &ret_format, &ret_len, - &ret_after, &ret_prop); - } - if (MatricesAtom == None || status != Success || !ret_format) { - printf ("Could not find property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); - } else { - printf ("Deleting property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); - XDeleteProperty (dpy, root, MatricesAtom); - XFree ((char *)ret_prop); - } - - CorrectAtom = XInternAtom (dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True); - if (CorrectAtom != None) { - status = XGetWindowProperty (dpy, root, CorrectAtom, 0, 8192, - False, XA_INTEGER, &ret_atom, &ret_format, &ret_len, - &ret_after, &ret_prop); - } - if (CorrectAtom == None || status != Success || !ret_format) { - printf ("Could not find property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME); - } else { - printf ("Deleting property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME); - XDeleteProperty (dpy, root, CorrectAtom); - XFree ((char *)ret_prop); - } + MatricesAtom = ParseAtom(dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True); + if (MatricesAtom != None) { + status = XGetWindowProperty(dpy, root, MatricesAtom, 0, 8192, + False, XA_INTEGER, &ret_atom, + &ret_format, &ret_len, &ret_after, + &ret_prop); + } + if (MatricesAtom == None || status != Success || !ret_format) { + printf("Could not find property %s\n", + XDCCC_SCREENWHITEPT_ATOM_NAME); + } + else { + printf("Deleting property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME); + XDeleteProperty(dpy, root, MatricesAtom); + XFree((char *) ret_prop); + } + + CorrectAtom = XInternAtom(dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True); + if (CorrectAtom != None) { + status = XGetWindowProperty(dpy, root, CorrectAtom, 0, 8192, + False, XA_INTEGER, &ret_atom, + &ret_format, &ret_len, &ret_after, + &ret_prop); + } + if (CorrectAtom == None || status != Success || !ret_format) { + printf("Could not find property %s\n", + XDCCC_GRAY_CORRECT_ATOM_NAME); + } + else { + printf("Deleting property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME); + XDeleteProperty(dpy, root, CorrectAtom); + XFree((char *) ret_prop); + } } -#endif /* GRAY */ +#endif /* GRAY */ } static unsigned long @@ -809,28 +830,27 @@ _XcmsGetElement(int format, char **pValue, unsigned long *pCount) unsigned long value; switch (format) { - case 32: - value = *((unsigned long *)(*pValue)) & 0xFFFFFFFF; - *pValue += sizeof(unsigned long); - *pCount -= 1; - break; - case 16: - value = *((unsigned short *)(*pValue)); - *pValue += sizeof(unsigned short); - *pCount -= 1; - break; - case 8: - value = *((unsigned char *) (*pValue)); - *pValue += 1; - *pCount -= 1; - break; - default: - value = 0; - break; + case 32: + value = *((unsigned long *) (*pValue)) & 0xFFFFFFFF; + *pValue += sizeof(unsigned long); + *pCount -= 1; + break; + case 16: + value = *((unsigned short *) (*pValue)); + *pValue += sizeof(unsigned short); + *pCount -= 1; + break; + case 8: + value = *((unsigned char *) (*pValue)); + *pValue += 1; + *pCount -= 1; + break; + default: + value = 0; + break; } - return(value); + return (value); } - /* * NAME @@ -840,8 +860,7 @@ _XcmsGetElement(int format, char **pValue, unsigned long *pCount) */ static int _XcmsGetProperty(Display *pDpy, Window w, Atom property, int *pFormat, - unsigned long *pNItems, unsigned long *pNBytes, - char **pValue) + unsigned long *pNItems, unsigned long *pNBytes, char **pValue) /* * DESCRIPTION * @@ -858,26 +877,27 @@ _XcmsGetProperty(Display *pDpy, Window w, Atom property, int *pFormat, int xgwp_ret; while (True) { - xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, - XA_INTEGER, &atom_ret, &format_ret, - &nitems_ret, &after_ret, - (unsigned char **)&prop_ret); - if (xgwp_ret == Success && after_ret > 0) { - len += nitems_ret * (format_ret >> 3); - XFree (prop_ret); - } else { - break; - } + xgwp_ret = XGetWindowProperty(pDpy, w, property, 0, len, False, + XA_INTEGER, &atom_ret, &format_ret, + &nitems_ret, &after_ret, + (unsigned char **) &prop_ret); + if (xgwp_ret == Success && after_ret > 0) { + len += nitems_ret * (format_ret >> 3); + XFree(prop_ret); + } + else { + break; + } } if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) { - /* the property does not exist or is of an unexpected type or + /* the property does not exist or is of an unexpected type or getting window property failed */ - return(XcmsFailure); + return (XcmsFailure); } *pFormat = format_ret; *pNItems = nitems_ret; *pNBytes = nitems_ret * (format_ret >> 3); *pValue = prop_ret; - return(XcmsSuccess); + return (XcmsSuccess); } -- cgit v1.2.3