summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2011-05-13 09:06:56 +0000
committerCarsten Haitzler <raster@rasterman.com>2011-05-13 09:06:56 +0000
commit259a9356de14a22c0a2633a06bb64f18e00ef728 (patch)
treeb2e6a3451e9825fc8c9fa06fa10044c11c0fb7c6
parentbd683af1d51eb4fea23bce7fcba27092a83bcc9b (diff)
downloadevas_generic_loaders-259a9356de14a22c0a2633a06bb64f18e00ef728.tar.gz
make shmfile common code.
SVN revision: 59365
-rw-r--r--configure.ac3
-rw-r--r--src/bin/Makefile.am3
-rw-r--r--src/bin/common/Makefile.am3
-rw-r--r--src/bin/common/shmfile.c82
-rw-r--r--src/bin/common/shmfile.h20
-rw-r--r--src/bin/pdf/Makefile.am5
-rw-r--r--src/bin/pdf/main.cpp59
-rw-r--r--src/bin/xcf/Makefile.am5
-rw-r--r--src/bin/xcf/main.c59
9 files changed, 119 insertions, 120 deletions
diff --git a/configure.ac b/configure.ac
index ccf5c01..da8e13d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
y##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
m4_define([v_maj], [0])
-m4_define([v_min], [9])
+m4_define([v_min], [1])
m4_define([v_mic], [999])
m4_define([v_rev], m4_esyscmd([(svnversion "${SVN_REPO_PATH:-.}" | grep -v export || echo 0) | awk -F : '{printf("%s\n", $1);}' | tr -d ' :MSP\n']))
m4_if(v_rev, [0], [m4_define([v_rev], m4_esyscmd([git log 2> /dev/null | (grep -m1 git-svn-id || echo 0) | sed -e 's/.*@\([0-9]*\).*/\1/' | tr -d '\n']))])
@@ -111,6 +111,7 @@ AC_CONFIG_FILES([
Makefile
src/Makefile
src/bin/Makefile
+src/bin/common/Makefile
src/bin/xcf/Makefile
src/bin/pdf/Makefile
])
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index eae5af3..313e122 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -1,6 +1,7 @@
MAINTAINERCLEANFILES = Makefile.in
-SUBDIRS = xcf
+SUBDIRS = common \
+xcf
if HAVE_PDF
SUBDIRS += pdf
diff --git a/src/bin/common/Makefile.am b/src/bin/common/Makefile.am
new file mode 100644
index 0000000..94aa560
--- /dev/null
+++ b/src/bin/common/Makefile.am
@@ -0,0 +1,3 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+EXTRA_DIST = shmfile.c shmfile.h
diff --git a/src/bin/common/shmfile.c b/src/bin/common/shmfile.c
new file mode 100644
index 0000000..7af1f75
--- /dev/null
+++ b/src/bin/common/shmfile.c
@@ -0,0 +1,82 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <math.h>
+#include <netinet/in.h>
+#include <time.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <zlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int shm_fd = -1;
+int shm_size = 0;
+void *shm_addr = NULL;
+char shmfile[1024] = "";
+
+void
+shm_alloc(int dsize)
+{
+#ifdef HAVE_SHM_OPEN
+ srand(time(NULL));
+ do
+ {
+ snprintf(shmfile, sizeof(shmfile), "/evas-loader-xcf.%i.%i",
+ (int)getpid(), (int)rand());
+ shm_fd = shm_open(shmfile, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+ }
+ while (shm_fd < 0);
+
+ if (ftruncate(shm_fd, dsize) < 0)
+ {
+ close(shm_fd);
+ shm_unlink(shmfile);
+ shm_fd = -1;
+ goto failed;
+ }
+ shm_addr = mmap(NULL, dsize, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
+ if (shm_addr == MAP_FAILED)
+ {
+ close(shm_fd);
+ shm_unlink(shmfile);
+ shm_fd = -1;
+ goto failed;
+ }
+ shm_size = dsize;
+ return;
+failed:
+#endif
+ shm_addr = malloc(dsize);
+}
+
+void
+shm_free(void)
+{
+#ifdef HAVE_SHM_OPEN
+ if (shm_fd >= 0)
+ {
+ munmap(shm_addr, shm_size);
+ close(shm_fd);
+ shm_fd = -1;
+ shm_addr = NULL;
+ return;
+ }
+#endif
+ free(shm_addr);
+ shm_addr = NULL;
+ shm_fd = -1;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/bin/common/shmfile.h b/src/bin/common/shmfile.h
new file mode 100644
index 0000000..b41c9cb
--- /dev/null
+++ b/src/bin/common/shmfile.h
@@ -0,0 +1,20 @@
+#ifndef SHMFILE_H
+#define SHMFILE_H 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int shm_fd;
+extern int shm_size;
+extern void *shm_addr;
+extern char *shmfile;
+
+void shm_alloc (int dsize);
+void shm_free (void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/bin/pdf/Makefile.am b/src/bin/pdf/Makefile.am
index 3700ceb..a909b01 100644
--- a/src/bin/pdf/Makefile.am
+++ b/src/bin/pdf/Makefile.am
@@ -4,6 +4,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/bin \
+-I$(top_srcdir)/src/bin/common \
-I$(top_srcdir)/src/bin/pdf \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
@@ -13,7 +14,9 @@ AM_CPPFLAGS = \
bin_PROGRAMS = evas_image_loader.pdf
-evas_image_loader_pdf_SOURCES = main.cpp
+evas_image_loader_pdf_SOURCES = \
+main.cpp \
+$(top_srcdir)/src/bin/common/shmfile.c
evas_image_loader_pdf_CFLAGS =
evas_image_loader_pdf_LDADD = @POPPLER_LIBS@ @EINA_LIBS@ @SHM_OPEN_LIBS@
evas_image_loader_pdf_LDFLAGS =
diff --git a/src/bin/pdf/main.cpp b/src/bin/pdf/main.cpp
index 2dcbe62..115b3be 100644
--- a/src/bin/pdf/main.cpp
+++ b/src/bin/pdf/main.cpp
@@ -14,6 +14,7 @@
#include <Eina.h>
+#include "shmfile.h"
#define DATA32 unsigned int
@@ -36,66 +37,8 @@ int crop_width = 0, crop_height = 0;
void *data = NULL;
double dpi = -1.0;
-static int shm_fd = -1;
-static int shm_size = 0;
-static void *shm_addr = NULL;
-static char shmfile[1024] = "";
-
#define DEF_DPI 72.0
-static void
-shm_alloc(int dsize)
-{
-#ifdef HAVE_SHM_OPEN
- srand(time(NULL));
- do
- {
- snprintf(shmfile, sizeof(shmfile), "/evas-loader-xcf.%i.%i",
- (int)getpid(), (int)rand());
- shm_fd = shm_open(shmfile, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
- }
- while (shm_fd < 0);
-
- if (ftruncate(shm_fd, dsize) < 0)
- {
- close(shm_fd);
- shm_unlink(shmfile);
- shm_fd = -1;
- goto failed;
- }
- shm_addr = mmap(NULL, dsize, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
- if (shm_addr == MAP_FAILED)
- {
- close(shm_fd);
- shm_unlink(shmfile);
- shm_fd = -1;
- goto failed;
- }
- shm_size = dsize;
- return;
-failed:
-#endif
- shm_addr = malloc(dsize);
-}
-
-static void
-shm_free(void)
-{
-#ifdef HAVE_SHM_OPEN
- if (shm_fd >= 0)
- {
- munmap(shm_addr, shm_size);
- close(shm_fd);
- shm_fd = -1;
- shm_addr = NULL;
- return;
- }
-#endif
- free(shm_addr);
- shm_addr = NULL;
- shm_fd = -1;
-}
-
Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
{
Object obj;
diff --git a/src/bin/xcf/Makefile.am b/src/bin/xcf/Makefile.am
index 8a1f15c..6c85eb2 100644
--- a/src/bin/xcf/Makefile.am
+++ b/src/bin/xcf/Makefile.am
@@ -4,6 +4,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/bin \
+-I$(top_srcdir)/src/bin/common \
-I$(top_srcdir)/src/bin/xcf \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
@@ -12,7 +13,9 @@ AM_CPPFLAGS = \
bin_PROGRAMS = evas_image_loader.xcf
-evas_image_loader_xcf_SOURCES = main.c pixelfuncs.c common.h
+evas_image_loader_xcf_SOURCES = \
+main.c pixelfuncs.c common.h \
+$(top_srcdir)/src/bin/common/shmfile.c
evas_image_loader_xcf_CFLAGS = @EINA_CFLAGS@
evas_image_loader_xcf_LDADD = @EINA_LIBS@ -lz -lm @SHM_OPEN_LIBS@
evas_image_loader_xcf_LDFLAGS =
diff --git a/src/bin/xcf/main.c b/src/bin/xcf/main.c
index e154812..071d763 100644
--- a/src/bin/xcf/main.c
+++ b/src/bin/xcf/main.c
@@ -46,6 +46,7 @@
*/
#include "common.h"
+#include "shmfile.h"
#define FREE(X) { free(X); X = NULL; }
@@ -300,64 +301,6 @@ extern void combine_pixels_val (DATA8* src, int src_w, int src_h, DATA8* dest, i
extern void combine_pixels_col (DATA8* src, int src_w, int src_h, DATA8* dest, int dest_w, int dest_h, int dest_x, int dest_y);
extern void combine_pixels_diss (DATA8* src, int src_w, int src_h, DATA8* dest, int dest_w, int dest_h, int dest_x, int dest_y);
-static int shm_fd = -1;
-static int shm_size = 0;
-static void *shm_addr = NULL;
-static char shmfile[1024] = "";
-
-static void
-shm_alloc(int dsize)
-{
-#ifdef HAVE_SHM_OPEN
- srand(time(NULL));
- do
- {
- snprintf(shmfile, sizeof(shmfile), "/evas-loader-xcf.%i.%i",
- (int)getpid(), (int)rand());
- shm_fd = shm_open(shmfile, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
- }
- while (shm_fd < 0);
-
- if (ftruncate(shm_fd, dsize) < 0)
- {
- close(shm_fd);
- shm_unlink(shmfile);
- shm_fd = -1;
- goto failed;
- }
- shm_addr = mmap(NULL, dsize, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
- if (shm_addr == MAP_FAILED)
- {
- close(shm_fd);
- shm_unlink(shmfile);
- shm_fd = -1;
- goto failed;
- }
- shm_size = dsize;
- return;
-failed:
-#endif
- shm_addr = malloc(dsize);
-}
-
-static void
-shm_free(void)
-{
-#ifdef HAVE_SHM_OPEN
- if (shm_fd >= 0)
- {
- munmap(shm_addr, shm_size);
- close(shm_fd);
- shm_fd = -1;
- shm_addr = NULL;
- return;
- }
-#endif
- free(shm_addr);
- shm_addr = NULL;
- shm_fd = -1;
-}
-
/* ---------------------------------------------------------------------------- globals ------------ */
/* This makes using the Gimp sources easier */