about summary refs log tree commit diff
path: root/other/pamx
diff options
context:
space:
mode:
Diffstat (limited to 'other/pamx')
-rw-r--r--other/pamx/Makefile48
-rw-r--r--other/pamx/pamx.c7
-rw-r--r--other/pamx/send.c6
-rw-r--r--other/pamx/window.c27
4 files changed, 51 insertions, 37 deletions
diff --git a/other/pamx/Makefile b/other/pamx/Makefile
index a40ea3a6..4e06e0fd 100644
--- a/other/pamx/Makefile
+++ b/other/pamx/Makefile
@@ -8,30 +8,37 @@ VPATH=.:$(SRCDIR)/$(SUBDIR)
 include $(BUILDDIR)/config.mk
 
 EXTERN_INCLUDE =
-ifneq ($(X11LIB),NONE)
-  ifneq ($(X11HDR_DIR),)
-    EXTERN_INCLUDES += -I$(X11HDR_DIR)
+
+ifeq ($(shell pkg-config x11 --modversion --silence-errors),)
+  # Pkg-config has never heard of X11, or doesn't even exist
+
+  ifneq ($(X11LIB),NONE)
+    HAVE_X11LIB = Y
+    ifneq ($(X11HDR_DIR)x,x)
+      EXTERN_INCLUDES += -I$(X11HDR_DIR)
+    endif
   endif
+else
+  HAVE_X11LIB = Y
+  X11LIB = $(shell pkg-config x11 --libs)
+  EXTERN_INCLUDES += $(shell pkg-config x11 --cflags)
 endif
 
-ifneq ($(X11LIB),NONE)
-  BINARIES += pamx
-
-  PAMX_OBJECTS = \
-	  pamx.o \
-	  image.o \
-	  send.o \
-	  window.o \
+ifeq ($(HAVE_X11LIB),Y)
+  PORTBINARIES += pamx
 
-  MERGE_OBJECTS = \
-	  pamx.o2 \
+  EXTRA_OBJECTS = \
 	  image.o \
 	  send.o \
 	  window.o \
 
 endif
 
-OBJECTS = $(PAMX_OBJECTS)
+BINARIES = $(PORTBINARIES)
+
+OBJECTS = $(BINARIES:%=%.o) $(EXTRA_OBJECTS)
+
+MERGE_OBJECTS = $(BINARIES:%=%.o2) $(EXTRA_OBJECTS)
 
 MERGEBINARIES = $(BINARIES)
 
@@ -39,7 +46,12 @@ all: $(BINARIES)
 
 include $(SRCDIR)/common.mk
 
-pamx: $(PAMX_OBJECTS) $(NETPBMLIB) $(LIBOPT)
-	$(LD) -o $@ $(PAMX_OBJECTS) \
-	  $(shell $(LIBOPT) $(NETPBMLIB) $(X11LIB)) \
-	  $(LDFLAGS) $(LDLIBS) $(MATHLIB) $(RPATH) $(LADD)
+ifeq ($(shell pkg-config x11 --libs),)
+  X11_LIBOPTS = $(shell $(LIBOPT) $(LIBOPTR) $(X11LIB))
+else
+  X11_LIBOPTS = $(shell pkg-config x11 --libs)
+endif
+
+pamx: image.o send.o window.o
+pamx: ADDL_OBJECTS = image.o send.o window.o
+pamx: LDFLAGS_TARGET = $(X11_LIBOPTS)
diff --git a/other/pamx/pamx.c b/other/pamx/pamx.c
index 130cc64c..e22693ea 100644
--- a/other/pamx/pamx.c
+++ b/other/pamx/pamx.c
@@ -3,6 +3,7 @@
    Copyright information is in the file COPYRIGHT
 */
 
+#define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
 #define _BSD_SOURCE  /* Make sure strdup() is in <string.h> */
 #include <signal.h>
 #include <unistd.h>
@@ -65,7 +66,7 @@ parseCommandLine(int argc,
    was passed to us as the argv array.  We also trash *argv.
 --------------------------------------------------------------------------*/
     optEntry *option_def;
-        /* Instructions to optParseOptions3 on how to parse our options. */
+        /* Instructions to pm_optParseOptions3 on how to parse our options. */
     optStruct3 opt;
   
     unsigned int option_def_index;
@@ -110,7 +111,7 @@ parseCommandLine(int argc,
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
     opt.allowNegNum = FALSE;   /* We have no parms that are negative numbers */
     
-    optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
+    pm_optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and some of *cmdlineP and others. */
 
     if (geometrySpec) {
@@ -360,7 +361,7 @@ main(int     argc,
     destroyViewer(viewerP);
 
     if (title)
-        strfree(title);
+        pm_strfree(title);
 
     XCloseDisplay(dispP);
 
diff --git a/other/pamx/send.c b/other/pamx/send.c
index 5413308b..fd50d5e9 100644
--- a/other/pamx/send.c
+++ b/other/pamx/send.c
@@ -78,8 +78,8 @@ ximageToPixmap(Display *    const disp,
 
 
 
-/* find the best pixmap depth supported by the server for a particular
- * visual and return that depth.
+/* find the best pixmap depth the server can do for a particular visual and
+ * return that depth.
  *
  * this is complicated by R3's lack of XListPixmapFormats so we fake it
  * by looking at the structure ourselves.
@@ -587,7 +587,7 @@ makeXImage(XImageInfo * const ximageinfoP,
         MALLOCARRAY(data, byteCount);
         if (data == NULL)
             pm_error("Can't allocate space for %u byte image", byteCount);
-        bcopy(imageP->data, data, byteCount);
+        memcpy(data, imageP->data, byteCount);
 
         ximageinfoP->ximageP =
             XCreateImage(disp, visualP, 1, XYBitmap,
diff --git a/other/pamx/window.c b/other/pamx/window.c
index 2eb48241..e2de1577 100644
--- a/other/pamx/window.c
+++ b/other/pamx/window.c
@@ -6,6 +6,7 @@
    See COPYRIGHT file for copyright information.
 */
 
+#define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
 #define _BSD_SOURCE    /* Make sure strcaseeq() is in nstring.h */
 
 #include <assert.h>
@@ -112,11 +113,11 @@ getInitialViewerGeometry(const char *   const geometryString,
         *userChoseP = TRUE;
     } else if (geometryString) {
         const char * defGeom;
-        asprintfN(&defGeom, "%ux%u+0+0", defaultWidth, defaultHeight);
+        pm_asprintf(&defGeom, "%ux%u+0+0", defaultWidth, defaultHeight);
         XGeometry(dispP, scrn, geometryString, defGeom, 0, 1, 1, 0, 0,
                   (int *)xposP, (int *)yposP,
                   (int *)widthP, (int *)heightP);
-        strfree(defGeom);
+        pm_strfree(defGeom);
         *userChoseP = TRUE;
     } else {
         *widthP     = defaultWidth;
@@ -193,7 +194,7 @@ determineRepaintStrategy(viewer  *    const viewerP,
                         
     /* Decide how we're going to handle repaints.  We have three modes:
        use backing-store, use background pixmap, and use exposures.
-       If the server supports backing-store, we enable it and use it.
+       If the server allows backing-store, we enable it and use it.
        This really helps servers which are memory constrained.  If the
        server does not have backing-store, we try to send the image to
        a pixmap and use that as backing-store.  If that fails, we use
@@ -499,10 +500,10 @@ iconName(const char * const s) {
         char * t;
 
         STRSCPY(buf, s);
-        /* strip off stuff following 1st word.  This strips
+        /* chop off stuff following 1st word.  This strips
            info added by processing functions too.
         */
-        t = index(buf, ' ');
+        t = strchr(buf, ' ');
         if (t)
             *t = '\0';
     
@@ -510,15 +511,15 @@ iconName(const char * const s) {
            You might want to change this.
         */
     
-        t= rindex(buf, '/');
+        t= strrchr(buf, '/');
         if (t) {
             char * p;
             for (p = buf, ++t; *t; ++p, ++t)
                 *p = *t;
             *p = '\0';
         }
-        /* look for an extension and strip it off */
-        t = index(buf, '.');
+        /* Chop off any filename extension */
+        t = strchr(buf, '.');
         if (t)
             *t = '\0';
     }
@@ -652,9 +653,9 @@ bestVisual(Display *      const disp,
     Visual * visualP;
     Visual * default_visualP;
 
-    /* Figure out the best depth the server supports.  note that some servers
-       (such as the HP 11.3 server) actually say they support some depths but
-       have no visuals that support that depth.  Seems silly to me ...
+    /* Figure out the best depth the server allows.  note that some servers
+       (such as the HP 11.3 server) actually say they allow some depths but
+       have no visuals that allow that depth.  Seems silly to me ...
     */
 
     depth = 0;
@@ -1079,7 +1080,7 @@ retvalueFromExitReason(exitReason const exitReason) {
     switch (exitReason) {
     case EXIT_NONE:      assert(false); break;
     case EXIT_QUIT:      retval =  0;     break;
-    case EXIT_WM_KILL:   retval = 10;     break;
+    case EXIT_WM_KILL:   retval =  0;     break;
     case EXIT_DESTROYED: retval = 20;     break;
     }
     return retval;
@@ -1175,7 +1176,7 @@ displayInViewer(viewer *       const viewerP,
     {
         const char * const name = iconName(title);
         XSetIconName(viewerP->dispP, viewerP->viewportWin, name);
-        strfree(name);
+        pm_strfree(name);
     }
     setNormalSizeHints(viewerP, imageP);