-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
graphics/pixmap: Fix build with newer libxpm
libXpm version 3.5.17 and above hides the xpm* functions like xpmReadRgbNames that pixmap uses. Solve this by compiling rgb.c from libxpm with pixmap. The function names have been altered to not conflict the the functions in libxpm in versions where they are not hidden.
- Loading branch information
nros
committed
Dec 4, 2024
1 parent
aebfda8
commit ce09a37
Showing
8 changed files
with
332 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$NetBSD: COPYRIGHT.rgb,v 1.1 2024/12/04 10:40:37 nros Exp $ | ||
/* | ||
* Copyright (C) 1989-95 GROUPE BULL | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to | ||
* deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* Except as contained in this notice, the name of GROUPE BULL shall not be | ||
* used in advertising or otherwise to promote the sale, use or other dealings | ||
* in this Software without prior written authorization from GROUPE BULL. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright (C) 1989-95 GROUPE BULL | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to | ||
* deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* Except as contained in this notice, the name of GROUPE BULL shall not be | ||
* used in advertising or otherwise to promote the sale, use or other dealings | ||
* in this Software without prior written authorization from GROUPE BULL. | ||
*/ | ||
|
||
/*****************************************************************************\ | ||
* rgb.c: * | ||
* * | ||
* XPM library * | ||
* Rgb file utilities * | ||
* * | ||
* Developed by Arnaud Le Hors * | ||
\*****************************************************************************/ | ||
|
||
/* | ||
* Part of this code has been taken from the ppmtoxpm.c file written by Mark | ||
* W. Snitily but has been modified for my special need | ||
*/ | ||
|
||
/* $NetBSD: rgb.c,v 1.1 2024/12/04 10:40:37 nros Exp $ */ | ||
|
||
#include "rgb.h" | ||
#include <ctype.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
/* | ||
* Read a rgb text file. It stores the rgb values (0->65535) | ||
* and the rgb mnemonics (malloc'ed) into the "rgbn" array. Returns the | ||
* number of entries stored. | ||
*/ | ||
int | ||
pm_xpmReadRgbNames( | ||
const char *rgb_fname, | ||
xpmRgbName rgbn[]) | ||
{ | ||
FILE *rgbf; | ||
int n, items, red, green, blue; | ||
char line[512], name[512], *rgbname, *s1, *s2; | ||
xpmRgbName *rgb; | ||
|
||
/* Open the rgb text file. Abort if error. */ | ||
if ((rgbf = fopen(rgb_fname, FOPEN_RES)) == NULL) | ||
return 0; | ||
|
||
/* Loop reading each line in the file. */ | ||
n = 0; | ||
rgb = rgbn; | ||
/* Quit if rgb text file has too many entries. */ | ||
while (fgets(line, sizeof(line), rgbf) && n < MAX_RGBNAMES) { | ||
|
||
/* Skip silently if line is bad. */ | ||
items = sscanf(line, "%d %d %d %[^\n]\n", &red, &green, &blue, name); | ||
if (items != 4) | ||
continue; | ||
|
||
/* | ||
* Make sure rgb values are within 0->255 range. Skip silently if | ||
* bad. | ||
*/ | ||
if (red < 0 || red > 0xFF || | ||
green < 0 || green > 0xFF || | ||
blue < 0 || blue > 0xFF) | ||
continue; | ||
|
||
/* Allocate memory for ascii name. If error give up here. */ | ||
if (!(rgbname = (char *) malloc(strlen(name) + 1))) | ||
break; | ||
|
||
/* Copy string to ascii name and lowercase it. */ | ||
for (s1 = name, s2 = rgbname; *s1; s1++) | ||
*s2++ = tolower(*s1); | ||
*s2 = '\0'; | ||
|
||
/* Save the rgb values and ascii name in the array. */ | ||
rgb->r = red * 257; /* 65535/255 = 257 */ | ||
rgb->g = green * 257; | ||
rgb->b = blue * 257; | ||
rgb->name = rgbname; | ||
rgb++; | ||
n++; | ||
} | ||
|
||
fclose(rgbf); | ||
|
||
/* Return the number of read rgb names. */ | ||
return n < 0 ? 0 : n; | ||
} | ||
|
||
/* | ||
* Return the color name corresponding to the given rgb values | ||
*/ | ||
char * | ||
pm_xpmGetRgbName( | ||
xpmRgbName rgbn[], /* rgb mnemonics from rgb text file */ | ||
int rgbn_max, /* number of rgb mnemonics in table */ | ||
int red, /* rgb values */ | ||
int green, | ||
int blue) | ||
{ | ||
int i; | ||
xpmRgbName *rgb; | ||
|
||
/* | ||
* Just perform a dumb linear search over the rgb values of the color | ||
* mnemonics. One could speed things up by sorting the rgb values and | ||
* using a binary search, or building a hash table, etc... | ||
*/ | ||
for (i = 0, rgb = rgbn; i < rgbn_max; i++, rgb++) | ||
if (red == rgb->r && green == rgb->g && blue == rgb->b) | ||
return rgb->name; | ||
|
||
/* if not found return NULL */ | ||
return NULL; | ||
} | ||
|
||
/* | ||
* Free the strings which have been malloc'ed in xpmReadRgbNames | ||
*/ | ||
void | ||
pm_xpmFreeRgbNames( | ||
xpmRgbName rgbn[], | ||
int rgbn_max) | ||
{ | ||
int i; | ||
xpmRgbName *rgb; | ||
|
||
for (i = 0, rgb = rgbn; i < rgbn_max; i++, rgb++) | ||
free(rgb->name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* $NETBSD$ */ | ||
/* | ||
* Copyright (C) 1989-95 GROUPE BULL | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to | ||
* deal in the Software without restriction, including without limitation the | ||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
* sell copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | ||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* Except as contained in this notice, the name of GROUPE BULL shall not be | ||
* used in advertising or otherwise to promote the sale, use or other dealings | ||
* in this Software without prior written authorization from GROUPE BULL. | ||
*/ | ||
|
||
/*****************************************************************************\ | ||
* XpmI.h: * | ||
* * | ||
* XPM library * | ||
* Internal Include file * | ||
* * | ||
* ** Everything defined here is subject to changes any time. ** * | ||
* * | ||
* Developed by Arnaud Le Hors * | ||
\*****************************************************************************/ | ||
|
||
#ifndef __PIXMAP_RGB_H__ | ||
#define __PIXMAP_RGB_H__ | ||
|
||
#include <fcntl.h> | ||
|
||
#ifdef O_CLOEXEC | ||
# define FOPEN_RES "re" | ||
#else | ||
# define FOPEN_RES "r" | ||
# define O_CLOEXEC 0 | ||
#endif | ||
|
||
/* | ||
* rgb values and ascii names (from rgb text file) rgb values, | ||
* range of 0 -> 65535 color mnemonic of rgb value | ||
*/ | ||
typedef struct { | ||
int r, g, b; | ||
char *name; | ||
} xpmRgbName; | ||
|
||
/* Maximum number of rgb mnemonics allowed in rgb text file. */ | ||
#define MAX_RGBNAMES 1024 | ||
|
||
int pm_xpmReadRgbNames(const char *rgb_fname, xpmRgbName *rgbn); | ||
char* pm_xpmGetRgbName(xpmRgbName *rgbn, int rgbn_max, int red, int green, int blue); | ||
void pm_xpmFreeRgbNames(xpmRgbName *rgbn, int rgbn_max); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,67 @@ | ||
$NetBSD: patch-Pixmap.c,v 1.1 2024/01/02 20:41:47 nros Exp $ | ||
$NetBSD: patch-Pixmap.c,v 1.2 2024/12/04 10:40:37 nros Exp $ | ||
|
||
Fix implicit funvtion declaration of exit | ||
Fix implicit function declaration of exit. | ||
|
||
--- Pixmap.c.orig 2024-01-02 09:18:23.243143182 +0000 | ||
Use bundled version of rgb.c since libxpm | ||
does make the xpm* function names visible | ||
anymore. | ||
|
||
--- Pixmap.c.orig 2024-12-02 10:40:36.762246945 +0000 | ||
+++ Pixmap.c | ||
@@ -67,6 +67,7 @@ static char rcsid[] = "$Id: Pixmap.c,v 1 | ||
@@ -65,8 +65,10 @@ static char rcsid[] = "$Id: Pixmap.c,v 1 | ||
#include <X11/cursorfont.h> | ||
#define AVOID /* Avoid some clashing prototyping in Pixmap.h */ | ||
#include "PixmapP.h" | ||
+#include "rgb.h" | ||
|
||
#include <stdio.h> | ||
+#include <stdlib.h> | ||
#include <math.h> | ||
|
||
#define XtStrlen(s) ((s) ? strlen(s) : 0) | ||
@@ -84,17 +86,8 @@ static int max_ncolors = -1; | ||
|
||
/* picked up from rgb.c of Xpm lib */ | ||
static char *rgb_fname = RGBF ; | ||
-#ifndef UNUSE_XPM | ||
-typedef struct { /* rgb values and ascii names (from rgb text file) */ | ||
- int r, g, b; /* rgb values, range of 0 -> 65535 */ | ||
- char *name; /* color mnemonic of rgb value */ | ||
-} RgbName; | ||
-#define MAX_RGBNAMES 1024 | ||
-#endif /* UNUSE_XPM */ | ||
-static RgbName rgb_table[MAX_RGBNAMES]; | ||
+static xpmRgbName rgb_table[MAX_RGBNAMES]; | ||
|
||
-extern int xpmReadRgbNames(); | ||
-extern char *xpmGetRgbName(); | ||
|
||
#define DefaultGridTolerance 5 | ||
#define DefaultPixmapWidth 32 | ||
@@ -1142,7 +1135,7 @@ static void Initialize(request, new, arg | ||
depth = DefaultDepth(dpy,screen); | ||
|
||
if (max_ncolors == -1) | ||
- max_ncolors = xpmReadRgbNames(rgb_fname, rgb_table); | ||
+ max_ncolors = pm_xpmReadRgbNames(rgb_fname, rgb_table); | ||
|
||
/* allocate max colors + 1 colorTable entries because 0 is transparent */ | ||
if (depth <= MAX_DEPTH) { | ||
@@ -1703,7 +1696,7 @@ void PWUpdateColorInTable(w, pixel, symb | ||
|
||
xcolor.pixel = pixel; | ||
XQueryColor(dpy, PW->core.colormap, &xcolor); | ||
- rgb_name = xpmGetRgbName(rgb_table, max_ncolors, | ||
+ rgb_name = pm_xpmGetRgbName(rgb_table, max_ncolors, | ||
(int) xcolor.red, | ||
(int) xcolor.green, | ||
(int) xcolor.blue); | ||
@@ -1722,7 +1715,7 @@ void PWUpdateColorInTable(w, pixel, symb | ||
xcolor.pixel = pixel; | ||
XQueryColor(dpy, PW->core.colormap, &xcolor); | ||
|
||
- if (!(rgb_name = xpmGetRgbName(rgb_table, max_ncolors, | ||
+ if (!(rgb_name = pm_xpmGetRgbName(rgb_table, max_ncolors, | ||
(int) xcolor.red, | ||
(int) xcolor.green, | ||
(int) xcolor.blue))) |
Oops, something went wrong.