Skip to content

Commit

Permalink
graphics/pixmap: Fix build with newer libxpm
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 11 deletions.
14 changes: 12 additions & 2 deletions graphics/pixmap/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# $NetBSD: Makefile,v 1.36 2024/01/02 20:41:47 nros Exp $
# $NetBSD: Makefile,v 1.37 2024/12/04 10:40:37 nros Exp $

DISTNAME= pixmap2.6
PKGNAME= pixmap-2.6.4
PKGREVISION= 8
PKGREVISION= 9
CATEGORIES= graphics
MASTER_SITES= ${MASTER_SITE_XCONTRIB:=applications/pixmap/}
LICENSE= x11
Expand Down Expand Up @@ -36,8 +36,18 @@ SUBST_STAGE.rgb= pre-configure
SUBST_FILES.rgb= Imakefile
SUBST_VARS.rgb= RGBTXT

INSTALLATION_DIRS+= share/doc/${PKGBASE}

post-extract:
rm -rf ${WRKSRC}/X11
${CP} ${FILESDIR}/rgb.h ${WRKSRC}
${CP} ${FILESDIR}/rgb.c ${WRKSRC}

post-install:
${INSTALL_DATA} ${WRKSRC}/COPYRIGHT \
${DESTDIR}${PREFIX}/share/doc/${PKGBASE}
${INSTALL_DATA} ${FILESDIR}/COPYRIGHT.rgb \
${DESTDIR}${PREFIX}/share/doc/${PKGBASE}

.include "../../x11/libX11/buildlink3.mk"
.include "../../x11/libXmu/buildlink3.mk"
Expand Down
4 changes: 3 additions & 1 deletion graphics/pixmap/PLIST
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@comment $NetBSD: PLIST,v 1.4 2008/11/30 08:43:16 obache Exp $
@comment $NetBSD: PLIST,v 1.5 2024/12/04 10:40:37 nros Exp $
bin/pixmap
lib/X11/Pixmap/MDown
lib/X11/Pixmap/MFlipHoriz
Expand All @@ -12,3 +12,5 @@ lib/X11/Pixmap/MUp
lib/X11/Pixmap/Stipple
lib/X11/app-defaults/Pixmap
${IMAKE_MAN_DIR}/pixmap.${IMAKE_MAN_SUFFIX}
share/doc/pixmap/COPYRIGHT
share/doc/pixmap/COPYRIGHT.rgb
6 changes: 3 additions & 3 deletions graphics/pixmap/distinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$NetBSD: distinfo,v 1.11 2024/01/02 20:41:47 nros Exp $
$NetBSD: distinfo,v 1.12 2024/12/04 10:40:37 nros Exp $

BLAKE2s (pixmap2.6.tar.gz) = 191d681fd102a90f99369f8def34fc0dbfa5394a180db7eb25076f9dd2bf6a3f
SHA512 (pixmap2.6.tar.gz) = 2943c8f9fdab8fcb979711bbace95595fcccd4b498041016ba7b82fa20ad9fbbba68c7359b3bfe4eb05555b4913ff0316752640f40efe0ace31ff4b401bb008f
Expand All @@ -17,7 +17,7 @@ SHA512 (pixmap_2.6.patch4.gz) = f30cfe7018a1a16db9f5c2b6c692b082c3ab83a4f79262cf
Size (pixmap_2.6.patch4.gz) = 1269 bytes
SHA1 (patch-Dialog.c) = a59038561837ff2377277821bcf841c965bab924
SHA1 (patch-PixEdit.c) = 96b9bddb9d4d597176f09527e12f9d6c5de0b748
SHA1 (patch-Pixmap.c) = 7a30b060fb82c617c11e574088898cdec61473a7
SHA1 (patch-Pixmap.c) = f1e492ca2d86ea45f662ce4eb461ee6e9bce8e97
SHA1 (patch-aa) = e0912b53bc09dcea4d233aa3a2c63997a53d5c50
SHA1 (patch-ab) = d7da0a7998bbac1e25763eea5a64afb79d98d1e6
SHA1 (patch-ac) = 5872ddb3275e2939152df87596e4bbf0b2ff5e35
SHA1 (patch-ac) = 79ee6f598d2cace44c51c373d6274ee9f5fd1a9f
25 changes: 25 additions & 0 deletions graphics/pixmap/files/COPYRIGHT.rgb
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.
*/
151 changes: 151 additions & 0 deletions graphics/pixmap/files/rgb.c
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);
}
66 changes: 66 additions & 0 deletions graphics/pixmap/files/rgb.h
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
61 changes: 57 additions & 4 deletions graphics/pixmap/patches/patch-Pixmap.c
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)))
Loading

0 comments on commit ce09a37

Please sign in to comment.