Commit 0dcc9aca authored by Jon Nordby's avatar Jon Nordby

Allow operations to include their source as class metadata

Allows GEGL applications to show the code, so users can
study them or create new operations based on them easily.
parent cbfbceb9
...@@ -267,6 +267,10 @@ gegl_module_register (GTypeModule *module) ...@@ -267,6 +267,10 @@ gegl_module_register (GTypeModule *module)
#undef enum_value #undef enum_value
#undef enum_end #undef enum_end
#ifdef GEGL_OP_C_FILE_SOURCE
#include GEGL_OP_C_FILE_SOURCE
#endif
#ifdef GETTEXT_PACKAGE #ifdef GETTEXT_PACKAGE
static const gchar *gegl_op_gettext_package G_GNUC_UNUSED = GETTEXT_PACKAGE; static const gchar *gegl_op_gettext_package G_GNUC_UNUSED = GETTEXT_PACKAGE;
#else #else
...@@ -815,6 +819,13 @@ gegl_op_class_intern_init (gpointer klass) ...@@ -815,6 +819,13 @@ gegl_op_class_intern_init (gpointer klass)
gboolean G_GNUC_UNUSED ui_digits_set = FALSE; gboolean G_GNUC_UNUSED ui_digits_set = FALSE;
GParamFlags flags G_GNUC_UNUSED = (GParamFlags)(G_PARAM_READWRITE | G_PARAM_CONSTRUCT | GEGL_PARAM_PAD_INPUT); GParamFlags flags G_GNUC_UNUSED = (GParamFlags)(G_PARAM_READWRITE | G_PARAM_CONSTRUCT | GEGL_PARAM_PAD_INPUT);
#ifdef GEGL_OP_C_FILE_SOURCE
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
gegl_operation_class_set_keys (operation_class,
"source", op_c_source,
NULL);
#endif
object_class->set_property = set_property; object_class->set_property = set_property;
object_class->get_property = get_property; object_class->get_property = get_property;
object_class->constructor = gegl_op_constructor; object_class->constructor = gegl_op_constructor;
......
/Makefile /Makefile
/Makefile.in /Makefile.in
*/*.c.h
...@@ -31,3 +31,6 @@ AM_CFLAGS = $(DEP_CFLAGS) $(BABL_CFLAGS) ...@@ -31,3 +31,6 @@ AM_CFLAGS = $(DEP_CFLAGS) $(BABL_CFLAGS)
AM_LDFLAGS = -avoid-version -export-dynamic -module $(no_undefined) AM_LDFLAGS = -avoid-version -export-dynamic -module $(no_undefined)
ext_dir = $(libdir)/gegl-@GEGL_API_VERSION@ ext_dir = $(libdir)/gegl-@GEGL_API_VERSION@
%.c.h: %.c $(top_builddir)/tools/csourcetostring.py
$(PYTHON) $(top_builddir)/tools/csourcetostring.py $<
...@@ -4,6 +4,8 @@ include $(top_srcdir)/operations/Makefile-common.am ...@@ -4,6 +4,8 @@ include $(top_srcdir)/operations/Makefile-common.am
EXTRA_DIST = $(wildcard $(srcdir)/*.h) EXTRA_DIST = $(wildcard $(srcdir)/*.h)
BUILT_SOURCES = $(subst .c,.c.h,$(wildcard $(srcdir)/*.c))
AM_CPPFLAGS += -I$(srcdir) AM_CPPFLAGS += -I$(srcdir)
LIBS = $(op_libs) LIBS = $(op_libs)
......
include $(top_srcdir)/operations/Makefile-common.am include $(top_srcdir)/operations/Makefile-common.am
EXTRA_DIST = $(wildcard $(srcdir)/*.h) EXTRA_DIST = $(wildcard $(srcdir)/*.h)
BUILT_SOURCES = $(subst .c,.c.h,$(wildcard $(srcdir)/*.c))
AM_CPPFLAGS += -I$(srcdir) AM_CPPFLAGS += -I$(srcdir)
......
...@@ -158,5 +158,7 @@ rgbe_save_la_SOURCES = rgbe-save.c ...@@ -158,5 +158,7 @@ rgbe_save_la_SOURCES = rgbe-save.c
rgbe_save_la_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/libs rgbe_save_la_CFLAGS = $(AM_CFLAGS) -I $(top_srcdir)/libs
rgbe_save_la_LIBADD = $(op_libs) $(top_builddir)/libs/rgbe/librgbe.la rgbe_save_la_LIBADD = $(op_libs) $(top_builddir)/libs/rgbe/librgbe.la
BUILT_SOURCES = $(subst .c,.c.h,$(wildcard $(srcdir)/*.c))
opdir = $(libdir)/gegl-@GEGL_API_VERSION@ opdir = $(libdir)/gegl-@GEGL_API_VERSION@
op_LTLIBRARIES = $(ops) op_LTLIBRARIES = $(ops)
...@@ -4,6 +4,8 @@ include $(top_srcdir)/operations/Makefile-common.am ...@@ -4,6 +4,8 @@ include $(top_srcdir)/operations/Makefile-common.am
EXTRA_DIST = $(wildcard $(srcdir)/*.h) EXTRA_DIST = $(wildcard $(srcdir)/*.h)
BUILT_SOURCES = $(subst .c,.c.h,$(wildcard $(srcdir)/*.c))
AM_CPPFLAGS += -I$(srcdir) AM_CPPFLAGS += -I$(srcdir)
LIBS = $(op_libs) LIBS = $(op_libs)
......
...@@ -39,5 +39,7 @@ v4l2_la_LIBADD = $(op_libs) $(V4L2_LIBS) ...@@ -39,5 +39,7 @@ v4l2_la_LIBADD = $(op_libs) $(V4L2_LIBS)
v4l2_la_CFLAGS = $(AM_CFLAGS) $(V4L2_CFLAGS) v4l2_la_CFLAGS = $(AM_CFLAGS) $(V4L2_CFLAGS)
endif endif
BUILT_SOURCES = $(subst .c,.c.h,$(wildcard $(srcdir)/*.c))
opdir = $(libdir)/gegl-@GEGL_API_VERSION@ opdir = $(libdir)/gegl-@GEGL_API_VERSION@
op_LTLIBRARIES = $(ops) op_LTLIBRARIES = $(ops)
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
if len(sys.argv) != 2:
print("Usage: %s file.c" % sys.argv[0])
sys.exit(1)
# From http://stackoverflow.com/questions/14945095/how-to-escape-string-for-generated-c
def escape_string(s):
return s.replace('\\', r'\\').replace('"', r'\"')
infile = open(sys.argv[1], "r")
outfile = open(sys.argv[1] + ".h", "w")
cl_source = infile.read()
infile.close()
string_var_name = os.path.basename(sys.argv[1]).replace("-", "_").replace(":", "_")
if string_var_name.endswith(".c"):
string_var_name = string_var_name.rstrip(".c")
outfile.write("static const char* %s_c_source =\n" % "op")
for line in cl_source.rstrip().split("\n"):
line = line.rstrip()
line = escape_string(line)
line = '"%-78s\\n"\n' % line
outfile.write(line)
outfile.write(";\n")
outfile.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment