Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update Makefile and arrange files to match the Library Template:

- each objectclass in its own file with the same name as the class
- shared functions in libpurest_json.c
- shared functions declared in purest_json.h
  • Loading branch information...
commit 5a9caf949a0dc665b0b562fa5dc5afdba8cf2ced 1 parent badd72e
Hans-Christoph Steiner eighthave authored
693 Makefile
View
@@ -1,283 +1,410 @@
-## Pd library template version 1.0
-# For instructions on how to use this template, see:
-# http://puredata.info/docs/developer/MakefileTemplate
-LIBRARY_NAME = purest_json
-
-# add your .c source files to the SOURCES variable, help files will be
-# included automatically
-SOURCES = purest_json.c
-
-# For objects that only build on certain platforms, add those to the SOURCES
-# line for the right platforms.
-#SOURCES_android =
-#SOURCES_cygwin =
-#SOURCES_macosx =
-#SOURCES_iphoneos =
-#SOURCES_linux =
-#SOURCES_windows =
-
-# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
-# be included automatically
-#PDOBJECTS = rest json-encode json-decode
-
-# example patches and related files, in the 'examples' subfolder
-EXAMPLES = purest-json-test.pd the-sound-of-money.pd
-
-# manuals and related files, in the 'manual' subfolder
-MANUAL = index.html couchdb-example.png webservice-example.png
-
-# if you want to include any other files in the source and binary tarballs,
-# list them here. This can be anything from header files, example patches,
-# documentation, etc. README.txt and LICENSE.txt are required and therefore
-# automatically included
-EXTRA_DIST = json-help.pd rest-json-help.pd Changelog.txt json.c purest_json.h rest.c
-
-#------------------------------------------------------------------------------#
-#
-# you shouldn't need to edit anything below here, if we did it right :)
-#
-#------------------------------------------------------------------------------#
-
-# get library version from meta file
-LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd)
-
-# where Pd lives
-PD_PATH = ../../pd
-# where to install the library
-prefix = /usr/local
-libdir = $(prefix)/lib
-pkglibdir = $(libdir)/pd-externals
-objectsdir = $(pkglibdir)
-
-
-INSTALL = install
-INSTALL_FILE = $(INSTALL) -p -m 644
-INSTALL_DIR = $(INSTALL) -p -m 755 -d
-
-CFLAGS = -DPD -I$(PD_PATH)/src -Wall -W -g -std=c99 -pthread
-LDFLAGS =
-LIBS = -lcurl -ljson -pthread
-ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) \
- $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows)
-
-UNAME := $(shell uname -s)
-ifeq ($(UNAME),Darwin)
- CPU := $(shell uname -p)
- ifeq ($(CPU),arm) # iPhone/iPod Touch
- SOURCES += $(SOURCES_iphoneos)
- EXTENSION = pd_darwin
- OS = iphoneos
- IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
- CC=$(IPHONE_BASE)/gcc
- CPP=$(IPHONE_BASE)/cpp
- CXX=$(IPHONE_BASE)/g++
- ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk
- IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6
- OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer
- CFLAGS := $(IPHONE_CFLAGS) $(OPT_CFLAGS) $(CFLAGS) \
- -I/Applications/Pd-extended.app/Contents/Resources/include
- LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT)
- LIBS += -lc
- STRIP = strip -x
- DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION)
- DISTBINDIR=$(DISTDIR)-$(OS)
- else # Mac OS X
- SOURCES += $(SOURCES_macosx)
- EXTENSION = pd_darwin
- OS = macosx
- OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast
-# build universal 32-bit on 10.4 and 32/64 on newer
- ifeq ($(shell uname -r | sed 's|\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*|\1|'), 8)
- FAT_FLAGS = -arch ppc -arch i386 -mmacosx-version-min=10.4
- else
- FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4
- SOURCES += $(SOURCES_iphoneos)
- endif
- CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include \
- -I/Applications/Pd-extended.app/Contents/Resources/include
- LDFLAGS += $(FAT_FLAGS) -bundle -undefined dynamic_lookup -L/sw/lib
- # if the 'pd' binary exists, check the linking against it to aid with stripping
- LDFLAGS += $(shell test -e $(PD_PATH)/bin/pd && echo -bundle_loader $(PD_PATH)/bin/pd)
- LIBS += -lc
- STRIP = strip -x
- DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION)
- DISTBINDIR=$(DISTDIR)-$(OS)
-# install into ~/Library/Pd on Mac OS X since /usr/local isn't used much
- pkglibdir=$(HOME)/Library/Pd
- endif
-endif
-ifeq ($(UNAME),Linux)
- SOURCES += $(SOURCES_linux)
- EXTENSION = pd_linux
- OS = linux
- OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
- CFLAGS += -fPIC
- LDFLAGS += -Wl,--export-dynamic -shared -fPIC
- LIBS += -lc
- STRIP = strip --strip-unneeded -R .note -R .comment
- DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION)
- DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
-endif
-ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME)))
- SOURCES += $(SOURCES_cygwin)
- EXTENSION = dll
- OS = cygwin
- OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
- CFLAGS +=
- LDFLAGS += -Wl,--export-dynamic -shared -L$(PD_PATH)/src
- LIBS += -lc -lpd
- STRIP = strip --strip-unneeded -R .note -R .comment
- DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION)
- DISTBINDIR=$(DISTDIR)-$(OS)
-endif
-ifeq (MINGW,$(findstring MINGW,$(UNAME)))
- SOURCES += $(SOURCES_windows)
- CFLAGS = -DPD -I$(PD_PATH)/src -Wall -W -g -std=c99 -mthreads
- LIBS = -L./lib -lcurl -ljson -lpthread -mthreads
- EXTENSION = dll
- OS = windows
- OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer -march=i686 -mtune=pentium4
- CFLAGS += -mms-bitfields
- LDFLAGS += -s -shared -Wl,--enable-auto-import
- LIBS += -L$(PD_PATH)/src -L$(PD_PATH)/bin -L$(PD_PATH)/obj -lpd -lwsock32 -lkernel32 -luser32 -lgdi32
- STRIP = strip --strip-unneeded -R .note -R .comment
- DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION)
- DISTBINDIR=$(DISTDIR)-$(OS)
-endif
-
-CFLAGS += $(OPT_CFLAGS)
-
-
-.PHONY = install libdir_install single_install install-doc install-exec install-examples install-manual clean dist etags
-
-all: $(SOURCES:.c=.$(EXTENSION))
-
-%.o: %.c
- $(CC) $(CFLAGS) -o "$*.o" -c "$*.c"
-
-%.$(EXTENSION): %.o
- $(CC) $(LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(LIBS)
- chmod a-x "$*.$(EXTENSION)"
-
-# this links everything into a single binary file
-$(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o
- $(CC) $(LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(LIBS)
- chmod a-x $(LIBRARY_NAME).$(EXTENSION)
-
-
-install: libdir_install
-
-# The meta and help files are explicitly installed to make sure they are
-# actually there. Those files are not optional, then need to be there.
-libdir_install: $(SOURCES:.c=.$(EXTENSION)) install-doc install-examples install-manual
- $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
- $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd \
- $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
- test -z "$(strip $(SOURCES))" || (\
- $(INSTALL_FILE) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \
- $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION))))
- test -z "$(strip $(PDOBJECTS))" || \
- $(INSTALL_FILE) $(PDOBJECTS) \
- $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
-
-# install library linked as single binary
-single_install: $(LIBRARY_NAME) install-doc install-exec
- $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
- $(INSTALL_FILE) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
- $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION)
-
-install-doc:
- $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
- test -z "$(strip $(SOURCES))" || \
- $(INSTALL_FILE) $(SOURCES:.c=-help.pd) \
- $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
- test -z "$(strip $(PDOBJECTS))" || \
- $(INSTALL_FILE) $(PDOBJECTS:.pd=-help.pd) \
- $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
- $(INSTALL_FILE) README.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/README.txt
- $(INSTALL_FILE) LICENSE.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/LICENSE.txt
-
-install-examples:
- test -z "$(strip $(EXAMPLES))" || \
- $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples && \
- for file in $(EXAMPLES); do \
- $(INSTALL_FILE) examples/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples; \
- done
-
-install-manual:
- test -z "$(strip $(MANUAL))" || \
- $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual && \
- for file in $(MANUAL); do \
- $(INSTALL_FILE) manual/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual; \
- done
-
-
-clean:
- -rm -f -- $(SOURCES:.c=.o)
- -rm -f -- $(SOURCES:.c=.$(EXTENSION))
- -rm -f -- $(LIBRARY_NAME).o
- -rm -f -- $(LIBRARY_NAME).$(EXTENSION)
-
-distclean: clean
- -rm -f -- $(DISTBINDIR).tar.gz
- -rm -rf -- $(DISTBINDIR)
- -rm -f -- $(DISTDIR).tar.gz
- -rm -rf -- $(DISTDIR)
-
-
-$(DISTBINDIR):
- $(INSTALL_DIR) $(DISTBINDIR)
-
-libdir: all $(DISTBINDIR)
- $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR)
- $(INSTALL_FILE) $(SOURCES) $(DISTBINDIR)
- #$(INSTALL_FILE) $(SOURCES:.c=-help.pd) $(DISTBINDIR)
- test -z "$(strip $(EXTRA_DIST))" || \
- $(INSTALL_FILE) $(EXTRA_DIST) $(DISTBINDIR)
-# tar --exclude-vcs -czpf $(DISTBINDIR).tar.gz $(DISTBINDIR)
-
-$(DISTDIR):
- $(INSTALL_DIR) $(DISTDIR)
-
-dist: $(DISTDIR)
- $(INSTALL_FILE) Makefile $(DISTDIR)
- $(INSTALL_FILE) README.txt $(DISTDIR)
- $(INSTALL_FILE) LICENSE.txt $(DISTDIR)
- $(INSTALL_FILE) $(LIBRARY_NAME)-meta.pd $(DISTDIR)
- test -z "$(strip $(ALLSOURCES))" || \
- $(INSTALL_FILE) $(ALLSOURCES) $(DISTDIR)
- #test -z "$(strip $(ALLSOURCES))" || \
- # $(INSTALL_FILE) $(ALLSOURCES:.c=-help.pd) $(DISTDIR)
- test -z "$(strip $(PDOBJECTS))" || \
- $(INSTALL_FILE) $(PDOBJECTS) $(DISTDIR)
- test -z "$(strip $(PDOBJECTS))" || \
- $(INSTALL_FILE) $(PDOBJECTS:.pd=-help.pd) $(DISTDIR)
- test -z "$(strip $(EXTRA_DIST))" || \
- $(INSTALL_FILE) $(EXTRA_DIST) $(DISTDIR)
- test -z "$(strip $(EXAMPLES))" || \
- $(INSTALL_DIR) $(DISTDIR)/examples && \
- for file in $(EXAMPLES); do \
- $(INSTALL_FILE) examples/$$file $(DISTDIR)/examples; \
- done
- test -z "$(strip $(MANUAL))" || \
- $(INSTALL_DIR) $(DISTDIR)/manual && \
- for file in $(MANUAL); do \
- $(INSTALL_FILE) manual/$$file $(DISTDIR)/manual; \
- done
- tar --exclude-vcs -czpf $(DISTDIR).tar.gz $(DISTDIR)
-
-
-etags:
- etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h
-
-showsetup:
- @echo "PD_PATH: $(PD_PATH)"
- @echo "objectsdir: $(objectsdir)"
- @echo "LIBRARY_NAME: $(LIBRARY_NAME)"
- @echo "LIBRARY_VERSION: $(LIBRARY_VERSION)"
- @echo "SOURCES: $(SOURCES)"
- @echo "PDOBJECTS: $(PDOBJECTS)"
- @echo "ALLSOURCES: $(ALLSOURCES)"
- @echo "UNAME: $(UNAME)"
- @echo "CPU: $(CPU)"
- @echo "pkglibdir: $(pkglibdir)"
+## Pd library template version 1.0.11
+# For instructions on how to use this template, see:
+# http://puredata.info/docs/developer/MakefileTemplate
+LIBRARY_NAME = purest_json
+
+# add your .c source files, one object per file, to the SOURCES
+# variable, help files will be included automatically, and for GUI
+# objects, the matching .tcl file too
+SOURCES = rest-json.c json-decode.c json-encode.c
+
+# list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
+# be included automatically
+PDOBJECTS =
+
+# example patches and related files, in the 'examples' subfolder
+EXAMPLES = purest-json-test.pd the-sound-of-money.pd
+
+# manuals and related files, in the 'manual' subfolder
+MANUAL = index.html couchdb-example.png webservice-example.png
+
+# if you want to include any other files in the source and binary tarballs,
+# list them here. This can be anything from header files, test patches,
+# documentation, etc. README.txt and LICENSE.txt are required and therefore
+# automatically included
+EXTRA_DIST = Changelog.txt
+
+HELPPATCHES = json-help.pd rest-json-help.pd
+
+#------------------------------------------------------------------------------#
+#
+# things you might need to edit if you are using other C libraries
+#
+#------------------------------------------------------------------------------#
+
+ALL_CFLAGS = -I"$(PD_INCLUDE)" -std=c99
+ALL_LDFLAGS =
+SHARED_LDFLAGS =
+ALL_LIBS = -lcurl -ljson
+
+
+#------------------------------------------------------------------------------#
+#
+# you shouldn't need to edit anything below here, if we did it right :)
+#
+#------------------------------------------------------------------------------#
+
+# these can be set from outside without (usually) breaking the build
+CFLAGS = -Wall -W -g
+LDFLAGS =
+LIBS =
+
+# get library version from meta file
+LIBRARY_VERSION = $(shell sed -n 's|^\#X text [0-9][0-9]* [0-9][0-9]* VERSION \(.*\);|\1|p' $(LIBRARY_NAME)-meta.pd)
+
+ALL_CFLAGS += -DPD -DVERSION='"$(LIBRARY_VERSION)"'
+
+PD_INCLUDE = $(PD_PATH)/include/pd
+# where to install the library, overridden below depending on platform
+prefix = /usr/local
+libdir = $(prefix)/lib
+pkglibdir = $(libdir)/pd-externals
+objectsdir = $(pkglibdir)
+
+INSTALL = install
+INSTALL_PROGRAM = $(INSTALL) -p -m 644
+INSTALL_DATA = $(INSTALL) -p -m 644
+INSTALL_DIR = $(INSTALL) -p -m 755 -d
+
+ALLSOURCES := $(SOURCES) $(SOURCES_android) $(SOURCES_cygwin) $(SOURCES_macosx) \
+ $(SOURCES_iphoneos) $(SOURCES_linux) $(SOURCES_windows)
+
+DISTDIR=$(LIBRARY_NAME)-$(LIBRARY_VERSION)
+ORIGDIR=pd-$(LIBRARY_NAME:~=)_$(LIBRARY_VERSION)
+
+UNAME := $(shell uname -s)
+ifeq ($(UNAME),Darwin)
+ CPU := $(shell uname -p)
+ ifeq ($(CPU),arm) # iPhone/iPod Touch
+ SOURCES += $(SOURCES_iphoneos)
+ EXTENSION = pd_darwin
+ SHARED_EXTENSION = dylib
+ OS = iphoneos
+ PD_PATH = /Applications/Pd-extended.app/Contents/Resources
+ IPHONE_BASE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
+ CC=$(IPHONE_BASE)/gcc
+ CPP=$(IPHONE_BASE)/cpp
+ CXX=$(IPHONE_BASE)/g++
+ ISYSROOT = -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk
+ IPHONE_CFLAGS = -miphoneos-version-min=3.0 $(ISYSROOT) -arch armv6
+ OPT_CFLAGS = -fast -funroll-loops -fomit-frame-pointer
+ ALL_CFLAGS := $(IPHONE_CFLAGS) $(ALL_CFLAGS)
+ ALL_LDFLAGS += -arch armv6 -bundle -undefined dynamic_lookup $(ISYSROOT)
+ SHARED_LDFLAGS += -arch armv6 -dynamiclib -undefined dynamic_lookup $(ISYSROOT)
+ ALL_LIBS += -lc $(LIBS_iphoneos)
+ STRIP = strip -x
+ DISTBINDIR=$(DISTDIR)-$(OS)
+ else # Mac OS X
+ SOURCES += $(SOURCES_macosx)
+ EXTENSION = pd_darwin
+ SHARED_EXTENSION = dylib
+ OS = macosx
+ PD_PATH = /Applications/Pd-extended.app/Contents/Resources
+ OPT_CFLAGS = -ftree-vectorize -ftree-vectorizer-verbose=2 -fast
+# build universal 32-bit on 10.4 and 32/64 on newer
+ ifeq ($(shell uname -r | sed 's|\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*|\1|'), 8)
+ #FAT_FLAGS = -arch ppc -arch i386 -mmacosx-version-min=10.4
+ else
+ #FAT_FLAGS = -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4
+ SOURCES += $(SOURCES_iphoneos)
+ endif
+ ALL_CFLAGS += $(FAT_FLAGS) -fPIC -I/sw/include
+ # if the 'pd' binary exists, check the linking against it to aid with stripping
+ BUNDLE_LOADER = $(shell test ! -e $(PD_PATH)/bin/pd || echo -bundle_loader $(PD_PATH)/bin/pd)
+ ALL_LDFLAGS += $(FAT_FLAGS) -bundle $(BUNDLE_LOADER) -undefined dynamic_lookup -L/sw/lib
+ SHARED_LDFLAGS += $(FAT_FLAGS) -dynamiclib -undefined dynamic_lookup \
+ -install_name @loader_path/$(SHARED_LIB) -compatibility_version 1 -current_version 1.0
+ ALL_LIBS += -lc $(LIBS_macosx)
+ STRIP = strip -x
+ DISTBINDIR=$(DISTDIR)-$(OS)
+# install into ~/Library/Pd on Mac OS X since /usr/local isn't used much
+ pkglibdir=$(HOME)/Library/Pd
+ endif
+endif
+# Tho Android uses Linux, we use this fake uname to provide an easy way to
+# setup all this things needed to cross-compile for Android using the NDK
+ifeq ($(UNAME),ANDROID)
+ CPU := arm
+ SOURCES += $(SOURCES_android)
+ EXTENSION = pd_linux
+ SHARED_EXTENSION = so
+ OS = android
+ PD_PATH = /usr
+ NDK_BASE := /usr/local/android-ndk
+ NDK_PLATFORM_VERSION := 5
+ NDK_SYSROOT=$(NDK_BASE)/platforms/android-$(NDK_PLATFORM_VERSION)/arch-arm
+ NDK_UNAME := $(shell uname -s | tr '[A-Z]' '[a-z]')
+ NDK_TOOLCHAIN_BASE=$(NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(NDK_UNAME)-x86
+ CC := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-gcc --sysroot=$(NDK_SYSROOT)
+ OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+ CFLAGS +=
+ LDFLAGS += -rdynamic -shared
+ SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared
+ LIBS += -lc $(LIBS_android)
+ STRIP := $(NDK_TOOLCHAIN_BASE)/bin/arm-linux-androideabi-strip \
+ --strip-unneeded -R .note -R .comment
+ DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
+endif
+ifeq ($(UNAME),Linux)
+ CPU := $(shell uname -m)
+ SOURCES += $(SOURCES_linux)
+ EXTENSION = pd_linux
+ SHARED_EXTENSION = so
+ OS = linux
+ PD_PATH = /usr
+ OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+ ALL_CFLAGS += -fPIC
+ ALL_LDFLAGS += -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags
+ SHARED_LDFLAGS += -Wl,-soname,$(SHARED_LIB) -shared
+ ALL_LIBS += -lc $(LIBS_linux)
+ STRIP = strip --strip-unneeded -R .note -R .comment
+ DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
+endif
+ifeq ($(UNAME),GNU)
+ # GNU/Hurd, should work like GNU/Linux for basically all externals
+ CPU := $(shell uname -m)
+ SOURCES += $(SOURCES_linux)
+ EXTENSION = pd_linux
+ SHARED_EXTENSION = so
+ OS = linux
+ PD_PATH = /usr
+ OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+ ALL_CFLAGS += -fPIC
+ ALL_LDFLAGS += -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags
+ SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB)
+ ALL_LIBS += -lc $(LIBS_linux)
+ STRIP = strip --strip-unneeded -R .note -R .comment
+ DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
+endif
+ifeq ($(UNAME),GNU/kFreeBSD)
+ # Debian GNU/kFreeBSD, should work like GNU/Linux for basically all externals
+ CPU := $(shell uname -m)
+ SOURCES += $(SOURCES_linux)
+ EXTENSION = pd_linux
+ SHARED_EXTENSION = so
+ OS = linux
+ PD_PATH = /usr
+ OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+ ALL_CFLAGS += -fPIC
+ ALL_LDFLAGS += -rdynamic -shared -fPIC -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags
+ SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB)
+ ALL_LIBS += -lc $(LIBS_linux)
+ STRIP = strip --strip-unneeded -R .note -R .comment
+ DISTBINDIR=$(DISTDIR)-$(OS)-$(shell uname -m)
+endif
+ifeq (CYGWIN,$(findstring CYGWIN,$(UNAME)))
+ CPU := $(shell uname -m)
+ SOURCES += $(SOURCES_cygwin)
+ EXTENSION = dll
+ SHARED_EXTENSION = dll
+ OS = cygwin
+ PD_PATH = $(shell cygpath $$PROGRAMFILES)/pd
+ OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+ ALL_CFLAGS +=
+ ALL_LDFLAGS += -rdynamic -shared -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin"
+ SHARED_LDFLAGS += -shared -Wl,-soname,$(SHARED_LIB)
+ ALL_LIBS += -lc -lpd $(LIBS_cygwin)
+ STRIP = strip --strip-unneeded -R .note -R .comment
+ DISTBINDIR=$(DISTDIR)-$(OS)
+endif
+ifeq (MINGW,$(findstring MINGW,$(UNAME)))
+ CPU := $(shell uname -m)
+ SOURCES += $(SOURCES_windows)
+ EXTENSION = dll
+ SHARED_EXTENSION = dll
+ OS = windows
+ PD_PATH = $(shell cd "$$PROGRAMFILES/pd" && pwd)
+ # MinGW doesn't seem to include cc so force gcc
+ CC=gcc
+ OPT_CFLAGS = -O3 -funroll-loops -fomit-frame-pointer
+ ALL_CFLAGS += -mms-bitfields
+ ALL_LDFLAGS += -s -shared -Wl,--enable-auto-import -L"$(PD_PATH)/src" -L"$(PD_PATH)/bin" -L"$(PD_PATH)/obj"
+ SHARED_LDFLAGS += -shared
+ ALL_LIBS += -lpd -lwsock32 -lkernel32 -luser32 -lgdi32 $(LIBS_windows)
+ STRIP = strip --strip-unneeded -R .note -R .comment
+ DISTBINDIR=$(DISTDIR)-$(OS)
+endif
+
+# in case somebody manually set the HELPPATCHES above
+HELPPATCHES ?= $(SOURCES:.c=-help.pd) $(PDOBJECTS:.pd=-help.pd)
+
+ALL_CFLAGS := $(ALL_CFLAGS) $(CFLAGS) $(OPT_CFLAGS)
+ALL_LDFLAGS := $(LDFLAGS) $(ALL_LDFLAGS)
+ALL_LIBS := $(LIBS) $(ALL_LIBS)
+
+SHARED_SOURCE ?= $(shell test ! -e lib$(LIBRARY_NAME).c || \
+ echo lib$(LIBRARY_NAME).c )
+SHARED_HEADER ?= $(shell test ! -e $(LIBRARY_NAME).h || echo $(LIBRARY_NAME).h)
+SHARED_LIB = $(SHARED_SOURCE:.c=.$(SHARED_EXTENSION))
+
+.PHONY = install libdir_install single_install install-doc install-examples install-manual clean distclean dist etags $(LIBRARY_NAME)
+
+all: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB)
+
+%.o: %.c
+ $(CC) $(ALL_CFLAGS) -o "$*.o" -c "$*.c"
+
+%.$(EXTENSION): %.o $(SHARED_LIB)
+ $(CC) $(ALL_LDFLAGS) -o "$*.$(EXTENSION)" "$*.o" $(ALL_LIBS) $(SHARED_LIB)
+ chmod a-x "$*.$(EXTENSION)"
+
+# this links everything into a single binary file
+$(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o
+ $(CC) $(ALL_LDFLAGS) -o $(LIBRARY_NAME).$(EXTENSION) $(SOURCES:.c=.o) $(LIBRARY_NAME).o $(ALL_LIBS)
+ chmod a-x $(LIBRARY_NAME).$(EXTENSION)
+
+$(SHARED_LIB): $(SHARED_SOURCE:.c=.o)
+ $(CC) $(SHARED_LDFLAGS) -o $(SHARED_LIB) $(SHARED_SOURCE:.c=.o) $(LIBS)
+
+install: libdir_install
+
+# The meta and help files are explicitly installed to make sure they are
+# actually there. Those files are not optional, then need to be there.
+libdir_install: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB) install-doc install-examples install-manual
+ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd \
+ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ test -z "$(strip $(SOURCES))" || (\
+ $(INSTALL_PROGRAM) $(SOURCES:.c=.$(EXTENSION)) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME) && \
+ $(STRIP) $(addprefix $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/,$(SOURCES:.c=.$(EXTENSION))))
+ test -z "$(strip $(SHARED_LIB))" || \
+ $(INSTALL_DATA) $(SHARED_LIB) \
+ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ test -z "$(strip $(wildcard $(SOURCES:.c=.tcl)))" || \
+ $(INSTALL_DATA) $(wildcard $(SOURCES:.c=.tcl)) \
+ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ test -z "$(strip $(PDOBJECTS))" || \
+ $(INSTALL_DATA) $(PDOBJECTS) \
+ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+
+# install library linked as single binary
+single_install: $(LIBRARY_NAME) install-doc install-examples install-manual
+ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ $(INSTALL_PROGRAM) $(LIBRARY_NAME).$(EXTENSION) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ $(STRIP) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/$(LIBRARY_NAME).$(EXTENSION)
+
+install-doc:
+ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ test -z "$(strip $(SOURCES) $(PDOBJECTS))" || \
+ $(INSTALL_DATA) $(HELPPATCHES) \
+ $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)
+ $(INSTALL_DATA) README.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/README.txt
+ $(INSTALL_DATA) LICENSE.txt $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/LICENSE.txt
+
+install-examples:
+ test -z "$(strip $(EXAMPLES))" || \
+ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples && \
+ for file in $(EXAMPLES); do \
+ $(INSTALL_DATA) examples/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/examples; \
+ done
+
+install-manual:
+ test -z "$(strip $(MANUAL))" || \
+ $(INSTALL_DIR) $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual && \
+ for file in $(MANUAL); do \
+ $(INSTALL_DATA) manual/$$file $(DESTDIR)$(objectsdir)/$(LIBRARY_NAME)/manual; \
+ done
+
+
+clean:
+ -rm -f -- $(SOURCES:.c=.o) $(SOURCES_LIB:.c=.o) $(SHARED_SOURCE:.c=.o)
+ -rm -f -- $(SOURCES:.c=.$(EXTENSION))
+ -rm -f -- $(LIBRARY_NAME).o
+ -rm -f -- $(LIBRARY_NAME).$(EXTENSION)
+ -rm -f -- $(SHARED_LIB)
+
+distclean: clean
+ -rm -f -- $(DISTBINDIR).tar.gz
+ -rm -rf -- $(DISTBINDIR)
+ -rm -f -- $(DISTDIR).tar.gz
+ -rm -rf -- $(DISTDIR)
+ -rm -f -- $(ORIGDIR).tar.gz
+ -rm -rf -- $(ORIGDIR)
+
+
+$(DISTBINDIR):
+ $(INSTALL_DIR) $(DISTBINDIR)
+
+libdir: all $(DISTBINDIR)
+ $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTBINDIR)
+ $(INSTALL_DATA) $(SOURCES) $(SHARED_SOURCE) $(SHARED_HEADER) $(DISTBINDIR)
+ $(INSTALL_DATA) $(HELPPATCHES) $(DISTBINDIR)
+ test -z "$(strip $(EXTRA_DIST))" || \
+ $(INSTALL_DATA) $(EXTRA_DIST) $(DISTBINDIR)
+# tar --exclude-vcs -czpf $(DISTBINDIR).tar.gz $(DISTBINDIR)
+
+$(DISTDIR):
+ $(INSTALL_DIR) $(DISTDIR)
+
+$(ORIGDIR):
+ $(INSTALL_DIR) $(ORIGDIR)
+
+dist: $(DISTDIR)
+ $(INSTALL_DATA) Makefile $(DISTDIR)
+ $(INSTALL_DATA) README.txt $(DISTDIR)
+ $(INSTALL_DATA) LICENSE.txt $(DISTDIR)
+ $(INSTALL_DATA) $(LIBRARY_NAME)-meta.pd $(DISTDIR)
+ test -z "$(strip $(ALLSOURCES))" || \
+ $(INSTALL_DATA) $(ALLSOURCES) $(DISTDIR)
+ test -z "$(strip $(wildcard $(ALLSOURCES:.c=.tcl)))" || \
+ $(INSTALL_DATA) $(wildcard $(ALLSOURCES:.c=.tcl)) $(DISTDIR)
+ test -z "$(strip $(SHARED_HEADER))" || \
+ $(INSTALL_DATA) $(SHARED_HEADER) $(DISTDIR)
+ test -z "$(strip $(SHARED_SOURCE))" || \
+ $(INSTALL_DATA) $(SHARED_SOURCE) $(DISTDIR)
+ test -z "$(strip $(PDOBJECTS))" || \
+ $(INSTALL_DATA) $(PDOBJECTS) $(DISTDIR)
+ test -z "$(strip $(HELPPATCHES))" || \
+ $(INSTALL_DATA) $(HELPPATCHES) $(DISTDIR)
+ test -z "$(strip $(EXTRA_DIST))" || \
+ $(INSTALL_DATA) $(EXTRA_DIST) $(DISTDIR)
+ test -z "$(strip $(EXAMPLES))" || \
+ $(INSTALL_DIR) $(DISTDIR)/examples && \
+ for file in $(EXAMPLES); do \
+ $(INSTALL_DATA) examples/$$file $(DISTDIR)/examples; \
+ done
+ test -z "$(strip $(MANUAL))" || \
+ $(INSTALL_DIR) $(DISTDIR)/manual && \
+ for file in $(MANUAL); do \
+ $(INSTALL_DATA) manual/$$file $(DISTDIR)/manual; \
+ done
+ tar --exclude-vcs -czpf $(DISTDIR).tar.gz $(DISTDIR)
+
+# make a Debian source package
+dpkg-source:
+ debclean
+ make distclean dist
+ mv $(DISTDIR) $(ORIGDIR)
+ tar --exclude-vcs -czpf ../$(ORIGDIR).orig.tar.gz $(ORIGDIR)
+ rm -f -- $(DISTDIR).tar.gz
+ rm -rf -- $(DISTDIR) $(ORIGDIR)
+ cd .. && dpkg-source -b $(LIBRARY_NAME)
+
+etags:
+ etags *.h $(SOURCES) ../../pd/src/*.[ch] /usr/include/*.h /usr/include/*/*.h
+
+showsetup:
+ @echo "CC: $(CC)"
+ @echo "CFLAGS: $(CFLAGS)"
+ @echo "LDFLAGS: $(LDFLAGS)"
+ @echo "LIBS: $(LIBS)"
+ @echo "ALL_CFLAGS: $(ALL_CFLAGS)"
+ @echo "ALL_LDFLAGS: $(ALL_LDFLAGS)"
+ @echo "ALL_LIBS: $(ALL_LIBS)"
+ @echo "PD_INCLUDE: $(PD_INCLUDE)"
+ @echo "PD_PATH: $(PD_PATH)"
+ @echo "objectsdir: $(objectsdir)"
+ @echo "LIBRARY_NAME: $(LIBRARY_NAME)"
+ @echo "LIBRARY_VERSION: $(LIBRARY_VERSION)"
+ @echo "SOURCES: $(SOURCES)"
+ @echo "SHARED_HEADER: $(SHARED_HEADER)"
+ @echo "SHARED_SOURCE: $(SHARED_SOURCE)"
+ @echo "SHARED_LIB: $(SHARED_LIB)"
+ @echo "PDOBJECTS: $(PDOBJECTS)"
+ @echo "ALLSOURCES: $(ALLSOURCES)"
+ @echo "ALLSOURCES TCL: $(wildcard $(ALLSOURCES:.c=.tcl))"
+ @echo "UNAME: $(UNAME)"
+ @echo "CPU: $(CPU)"
+ @echo "pkglibdir: $(pkglibdir)"
+ @echo "DISTDIR: $(DISTDIR)"
+ @echo "ORIGDIR: $(ORIGDIR)"
25 json-decode.c
View
@@ -0,0 +1,25 @@
+#include "purest_json.h"
+
+static t_class *json_decode_class;
+
+void setup_json0x2ddecode(void) {
+ json_decode_class = class_new(gensym("json-decode"), (t_newmethod)json_decode_new,
+ 0, sizeof(t_json_decode), 0, A_GIMME, 0);
+ class_addsymbol(json_decode_class, (t_method)json_decode_string);
+ class_sethelpsymbol(json_decode_class, gensym("json"));
+}
+
+void *json_decode_new(t_symbol *selector, int argcount, t_atom *argvec) {
+ t_json_decode *x = (t_json_decode*)pd_new(json_decode_class);
+ outlet_new(&x->x_ob, NULL);
+ x->done_outlet = outlet_new(&x->x_ob, &s_bang);
+ return (void *)x;
+}
+
+void json_decode_string(t_json_decode *x, t_symbol *data) {
+ char *json_string = data->s_name;
+ json_object *jobj;
+ jobj = json_tokener_parse(json_string);
+ output_json(jobj, x->x_ob.ob_outlet, x->done_outlet);
+ json_object_put(jobj);
+}
122 json-encode.c
View
@@ -0,0 +1,122 @@
+#include "purest_json.h"
+
+static t_class *json_encode_class;
+
+void setup_json0x2dencode(void) {
+ json_encode_class = class_new(gensym("json-encode"), (t_newmethod)json_encode_new,
+ 0, sizeof(t_json_encode), 0, A_GIMME, 0);
+ class_addbang(json_encode_class, (t_method)json_encode_bang);
+ class_addmethod(json_encode_class, (t_method)json_encode_add, gensym("add"), A_GIMME, 0);
+ class_addmethod(json_encode_class, (t_method)json_encode_array_add, gensym("array"), A_GIMME, 0);
+ class_addmethod(json_encode_class, (t_method)json_encode_clear, gensym("clear"), A_GIMME, 0);
+ class_sethelpsymbol(json_encode_class, gensym("json"));
+}
+
+void *json_encode_new(t_symbol *selector, int argcount, t_atom *argvec) {
+ t_json_encode *x = (t_json_encode*)pd_new(json_encode_class);
+ x->data_count = 0;
+ outlet_new(&x->x_ob, NULL);
+ return (void *)x;
+}
+
+void json_encode_bang(t_json_encode *x) {
+ int i, j, k;
+ int array_member_numbers[x->data_count];
+ int array_member_count = 0;
+ short already_added = 0;
+ json_object *jobj = json_object_new_object();
+ json_object *value;
+ if (x->data_count > 0) {
+ for (i = 0; i < x->data_count; i++) {
+ already_added = 0;
+ /* Is it an array member? */
+ if (x->data[i].is_array == 1) {
+ value = json_object_new_array();
+ for (j = i; j < x->data_count; j++) {
+ if (strcmp(x->data[j].key, x->data[i].key) == 0) {
+ for (k = 0; k < array_member_count; k++) {
+ /* If already inserted, continue i loop */
+ if (array_member_numbers[k] == j) {
+ already_added = 1;
+ break;
+ }
+ }
+ json_object *array_member = create_object(x->data[j].value);
+ json_object_array_add(value, array_member);
+ array_member_numbers[array_member_count] = j;
+ array_member_count++;
+ json_object_put(array_member);
+ }
+ }
+ } else {
+ value = create_object(x->data[i].value);
+ }
+ if (already_added == 0) {
+ json_object_object_add(jobj, x->data[i].key, value);
+ }
+ }
+ outlet_symbol(x->x_ob.ob_outlet, gensym(json_object_to_json_string(jobj)));
+ json_object_put(jobj);
+ }
+}
+
+json_object *create_object(char *value) {
+ json_object *object;
+ char *parsed_string;
+ /* if stored value is string is starting with { and ending with },
+ then create a json object from it. */
+ if (value[0] == '{' && value[strlen(value) - 1] == '}') {
+ parsed_string = remove_backslashes(value);
+ object = json_tokener_parse(parsed_string);
+ free(parsed_string);
+ } else {
+ object = json_object_new_string(value);
+ }
+ return object;
+}
+
+void json_encode_add(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec) {
+ char key[MAX_STRING_SIZE];
+ char value[MAX_STRING_SIZE];
+ int i;
+ if (argcount < 2) {
+ error("For method 'add' You need to specify a value.");
+ } else {
+ atom_string(argvec, key, MAX_STRING_SIZE);
+ strcpy(x->data[x->data_count].key, key);
+ atom_string(argvec + 1, value, MAX_STRING_SIZE);
+ strcpy(x->data[x->data_count].value, value);
+ for(i = 2; i < argcount; i++) {
+ atom_string(argvec + i, value, MAX_STRING_SIZE);
+ strcat(x->data[x->data_count].value, " ");
+ strcat(x->data[x->data_count].value, value);
+ }
+ x->data[x->data_count].is_array = 0;
+ x->data_count++;
+ }
+}
+
+void json_encode_array_add(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec) {
+ char key[MAX_STRING_SIZE];
+ char value[MAX_STRING_SIZE];
+ int i;
+ if (argcount < 2) {
+ error("For method 'array' You need to specify a value.");
+ } else {
+ atom_string(argvec, key, MAX_STRING_SIZE);
+ strcpy(x->data[x->data_count].key, key);
+ atom_string(argvec + 1, value, MAX_STRING_SIZE);
+ strcpy(x->data[x->data_count].value, value);
+ for(i = 2; i < argcount; i++) {
+ atom_string(argvec + i, value, MAX_STRING_SIZE);
+ strcat(x->data[x->data_count].value, " ");
+ strcat(x->data[x->data_count].value, value);
+ }
+ x->data[x->data_count].is_array = 1;
+ x->data_count++;
+ }
+}
+
+void json_encode_clear(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec) {
+ x->data_count = 0;
+}
245 json.c
View
@@ -1,245 +0,0 @@
-void setup_json_encoder(void) {
- json_encode_class = class_new(gensym("json-encode"), (t_newmethod)json_encode_new,
- 0, sizeof(t_json_encode), 0, A_GIMME, 0);
- class_addbang(json_encode_class, (t_method)json_encode_bang);
- class_addmethod(json_encode_class, (t_method)json_encode_add, gensym("add"), A_GIMME, 0);
- class_addmethod(json_encode_class, (t_method)json_encode_array_add, gensym("array"), A_GIMME, 0);
- class_addmethod(json_encode_class, (t_method)json_encode_clear, gensym("clear"), A_GIMME, 0);
- class_sethelpsymbol(json_encode_class, gensym("json"));
-}
-
-void *json_encode_new(t_symbol *selector, int argcount, t_atom *argvec) {
- t_json_encode *x = (t_json_encode*)pd_new(json_encode_class);
- x->data_count = 0;
- outlet_new(&x->x_ob, NULL);
- return (void *)x;
-}
-
-void json_encode_bang(t_json_encode *x) {
- int i, j, k;
- int array_member_numbers[x->data_count];
- int array_member_count = 0;
- short already_added = 0;
- json_object *jobj = json_object_new_object();
- json_object *value;
- if (x->data_count > 0) {
- for (i = 0; i < x->data_count; i++) {
- already_added = 0;
- /* Is it an array member? */
- if (x->data[i].is_array == 1) {
- value = json_object_new_array();
- for (j = i; j < x->data_count; j++) {
- if (strcmp(x->data[j].key, x->data[i].key) == 0) {
- for (k = 0; k < array_member_count; k++) {
- /* If already inserted, continue i loop */
- if (array_member_numbers[k] == j) {
- already_added = 1;
- break;
- }
- }
- json_object *array_member = create_object(x->data[j].value);
- json_object_array_add(value, array_member);
- array_member_numbers[array_member_count] = j;
- array_member_count++;
- json_object_put(array_member);
- }
- }
- } else {
- value = create_object(x->data[i].value);
- }
- if (already_added == 0) {
- json_object_object_add(jobj, x->data[i].key, value);
- }
- }
- outlet_symbol(x->x_ob.ob_outlet, gensym(json_object_to_json_string(jobj)));
- json_object_put(jobj);
- }
-}
-
-json_object *create_object(char *value) {
- json_object *object;
- char *parsed_string;
- /* if stored value is string is starting with { and ending with },
- then create a json object from it. */
- if (value[0] == '{' && value[strlen(value) - 1] == '}') {
- parsed_string = remove_backslashes(value);
- object = json_tokener_parse(parsed_string);
- free(parsed_string);
- } else {
- object = json_object_new_string(value);
- }
- return object;
-}
-
-void json_encode_add(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec) {
- char key[MAX_STRING_SIZE];
- char value[MAX_STRING_SIZE];
- int i;
- if (argcount < 2) {
- error("For method 'add' You need to specify a value.");
- } else {
- atom_string(argvec, key, MAX_STRING_SIZE);
- strcpy(x->data[x->data_count].key, key);
- atom_string(argvec + 1, value, MAX_STRING_SIZE);
- strcpy(x->data[x->data_count].value, value);
- for(i = 2; i < argcount; i++) {
- atom_string(argvec + i, value, MAX_STRING_SIZE);
- strcat(x->data[x->data_count].value, " ");
- strcat(x->data[x->data_count].value, value);
- }
- x->data[x->data_count].is_array = 0;
- x->data_count++;
- }
-}
-
-void json_encode_array_add(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec) {
- char key[MAX_STRING_SIZE];
- char value[MAX_STRING_SIZE];
- int i;
- if (argcount < 2) {
- error("For method 'array' You need to specify a value.");
- } else {
- atom_string(argvec, key, MAX_STRING_SIZE);
- strcpy(x->data[x->data_count].key, key);
- atom_string(argvec + 1, value, MAX_STRING_SIZE);
- strcpy(x->data[x->data_count].value, value);
- for(i = 2; i < argcount; i++) {
- atom_string(argvec + i, value, MAX_STRING_SIZE);
- strcat(x->data[x->data_count].value, " ");
- strcat(x->data[x->data_count].value, value);
- }
- x->data[x->data_count].is_array = 1;
- x->data_count++;
- }
-}
-
-void json_encode_clear(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec) {
- x->data_count = 0;
-}
-
-void output_json(json_object *jobj, t_outlet *data_outlet, t_outlet *done_outlet) {
- enum json_type outer_type = json_object_get_type(jobj);
- enum json_type inner_type;
- t_atom out_data[2];
- t_float out_float;
- char *remainder;
- float float_value;
- const char *string_value;
- int array_len;
- int i;
-
- if (is_error(jobj)) {
- error("Not a JSON object.");
- } else {
- switch (outer_type) {
- /* We really have a JSON object */
- case json_type_boolean:
- SETFLOAT(&out_data[1], json_object_get_boolean(jobj) ? 1: 0);
- out_float = atom_getfloat(&out_data[1]);
- outlet_float(data_outlet, out_float);
- outlet_bang(done_outlet);
- break;
- case json_type_double:
- SETFLOAT(&out_data[1], json_object_get_double(jobj));
- out_float = atom_getfloat(&out_data[1]);
- outlet_float(data_outlet, out_float);
- outlet_bang(done_outlet);
- break;
- case json_type_int:
- SETFLOAT(&out_data[1], json_object_get_int(jobj));
- out_float = atom_getfloat(&out_data[1]);
- outlet_float(data_outlet, out_float);
- outlet_bang(done_outlet);
- break;
- case json_type_string:
- outlet_symbol(data_outlet, gensym(json_object_get_string(jobj)));
- outlet_bang(done_outlet);
- break;
- case json_type_null:
- outlet_symbol(data_outlet, gensym(""));
- outlet_bang(done_outlet);
- break;
- case json_type_object:
- ;
- json_object_object_foreach(jobj, key, val) { /* Passing through every json object */
- SETSYMBOL(&out_data[0], gensym(key));
- /* Problem with null as value */
- if (val == NULL) {
- SETSYMBOL(&out_data[1], gensym(""));
- } else {
- inner_type = json_object_get_type(val);
- switch (inner_type) {
- case json_type_boolean:
- SETFLOAT(&out_data[1], json_object_get_boolean(val) ? 1: 0);
- break;
- case json_type_double:
- SETFLOAT(&out_data[1], json_object_get_double(val));
- break;
- case json_type_int:
- SETFLOAT(&out_data[1], json_object_get_int(val));
- break;
- case json_type_string:
- /* Float values might come as string */
- string_value = json_object_get_string(val);
- float_value = (float)strtod(string_value, &remainder);
- /* String to float has no remainder => float */
- if (strlen(remainder) == 0) {
- SETFLOAT(&out_data[1], float_value);
- /* Boolean values might come as string */
- } else if (str_ccmp(string_value, "true") == 0) {
- SETFLOAT(&out_data[1], 1);
- } else if (str_ccmp(string_value, "false") == 0) {
- SETFLOAT(&out_data[1], 0);
- /* String */
- } else {
- SETSYMBOL(&out_data[1], gensym(string_value));
- }
- break;
- case json_type_object:
- SETSYMBOL(&out_data[1], gensym(json_object_get_string(val)));
- break;
- case json_type_array:
- SETSYMBOL(&out_data[1], gensym(json_object_get_string(val)));
- break;
- case json_type_null:
- SETSYMBOL(&out_data[1], gensym(""));
- break;
- }
- }
- outlet_list(data_outlet, &s_list, 2, &out_data[0]);
- }
- outlet_bang(done_outlet);
- break;
- case json_type_array:
- ;
- array_len = json_object_array_length(jobj);
- for (i = 0; i < array_len; i++) {
- json_object *array_member = json_object_array_get_idx(jobj, i);
- output_json(array_member, data_outlet, done_outlet);
- }
- break;
- }
- }
-}
-
-void setup_json_decoder(void) {
- json_decode_class = class_new(gensym("json-decode"), (t_newmethod)json_decode_new,
- 0, sizeof(t_json_decode), 0, A_GIMME, 0);
- class_addsymbol(json_decode_class, (t_method)json_decode_string);
- class_sethelpsymbol(json_decode_class, gensym("json"));
-}
-
-void *json_decode_new(t_symbol *selector, int argcount, t_atom *argvec) {
- t_json_decode *x = (t_json_decode*)pd_new(json_decode_class);
- outlet_new(&x->x_ob, NULL);
- x->done_outlet = outlet_new(&x->x_ob, &s_bang);
- return (void *)x;
-}
-
-void json_decode_string(t_json_decode *x, t_symbol *data) {
- char *json_string = data->s_name;
- json_object *jobj;
- jobj = json_tokener_parse(json_string);
- output_json(jobj, x->x_ob.ob_outlet, x->done_outlet);
- json_object_put(jobj);
-}
151 libpurest_json.c
View
@@ -0,0 +1,151 @@
+#include "purest_json.h"
+
+void output_json(json_object *jobj, t_outlet *data_outlet, t_outlet *done_outlet) {
+ enum json_type outer_type = json_object_get_type(jobj);
+ enum json_type inner_type;
+ t_atom out_data[2];
+ t_float out_float;
+ char *remainder;
+ float float_value;
+ const char *string_value;
+ int array_len;
+ int i;
+
+ if (is_error(jobj)) {
+ error("Not a JSON object.");
+ } else {
+ switch (outer_type) {
+ /* We really have a JSON object */
+ case json_type_boolean:
+ SETFLOAT(&out_data[1], json_object_get_boolean(jobj) ? 1: 0);
+ out_float = atom_getfloat(&out_data[1]);
+ outlet_float(data_outlet, out_float);
+ outlet_bang(done_outlet);
+ break;
+ case json_type_double:
+ SETFLOAT(&out_data[1], json_object_get_double(jobj));
+ out_float = atom_getfloat(&out_data[1]);
+ outlet_float(data_outlet, out_float);
+ outlet_bang(done_outlet);
+ break;
+ case json_type_int:
+ SETFLOAT(&out_data[1], json_object_get_int(jobj));
+ out_float = atom_getfloat(&out_data[1]);
+ outlet_float(data_outlet, out_float);
+ outlet_bang(done_outlet);
+ break;
+ case json_type_string:
+ outlet_symbol(data_outlet, gensym(json_object_get_string(jobj)));
+ outlet_bang(done_outlet);
+ break;
+ case json_type_null:
+ outlet_symbol(data_outlet, gensym(""));
+ outlet_bang(done_outlet);
+ break;
+ case json_type_object:
+ ;
+ json_object_object_foreach(jobj, key, val) { /* Passing through every json object */
+ SETSYMBOL(&out_data[0], gensym(key));
+ /* Problem with null as value */
+ if (val == NULL) {
+ SETSYMBOL(&out_data[1], gensym(""));
+ } else {
+ inner_type = json_object_get_type(val);
+ switch (inner_type) {
+ case json_type_boolean:
+ SETFLOAT(&out_data[1], json_object_get_boolean(val) ? 1: 0);
+ break;
+ case json_type_double:
+ SETFLOAT(&out_data[1], json_object_get_double(val));
+ break;
+ case json_type_int:
+ SETFLOAT(&out_data[1], json_object_get_int(val));
+ break;
+ case json_type_string:
+ /* Float values might come as string */
+ string_value = json_object_get_string(val);
+ float_value = (float)strtod(string_value, &remainder);
+ /* String to float has no remainder => float */
+ if (strlen(remainder) == 0) {
+ SETFLOAT(&out_data[1], float_value);
+ /* Boolean values might come as string */
+ } else if (str_ccmp(string_value, "true") == 0) {
+ SETFLOAT(&out_data[1], 1);
+ } else if (str_ccmp(string_value, "false") == 0) {
+ SETFLOAT(&out_data[1], 0);
+ /* String */
+ } else {
+ SETSYMBOL(&out_data[1], gensym(string_value));
+ }
+ break;
+ case json_type_object:
+ SETSYMBOL(&out_data[1], gensym(json_object_get_string(val)));
+ break;
+ case json_type_array:
+ SETSYMBOL(&out_data[1], gensym(json_object_get_string(val)));
+ break;
+ case json_type_null:
+ SETSYMBOL(&out_data[1], gensym(""));
+ break;
+ }
+ }
+ outlet_list(data_outlet, &s_list, 2, &out_data[0]);
+ }
+ outlet_bang(done_outlet);
+ break;
+ case json_type_array:
+ ;
+ array_len = json_object_array_length(jobj);
+ for (i = 0; i < array_len; i++) {
+ json_object *array_member = json_object_array_get_idx(jobj, i);
+ output_json(array_member, data_outlet, done_outlet);
+ }
+ break;
+ }
+ }
+}
+
+char *remove_backslashes(char *source_string) {
+ char *dest = NULL;
+ char remove[2] = "\\,";
+ size_t len_src = strlen(source_string);
+ int found;
+ unsigned int i = 0;
+ int j = 0;
+
+ dest = (char *) calloc(len_src + 1, sizeof(char));
+ if (dest == NULL) {
+ printf("Unable to allocate memory\n");
+ }
+ memset(dest, 0x00,sizeof(char) * len_src + 1 );
+
+ for ( i = 0; i < len_src; i++ ) {
+ found = FALSE;
+ if (source_string[i] == remove[0] && source_string[i +1] == remove[1]) {
+ i++;
+ found = TRUE;
+ }
+
+ if (FALSE == found) {
+ dest[j] = source_string[i];
+ } else {
+ dest[j] = ',';
+ }
+ j++;
+ }
+ return (dest);
+}
+
+int str_ccmp(const char *s1, const char *s2) {
+ const unsigned char *p1 = (const unsigned char *)s1;
+ const unsigned char *p2 = (const unsigned char *)s2;
+
+ while (toupper(*p1) == toupper(*p2)) {
+ if (*p1 == '\0') {
+ return 0;
+ }
+ ++p1;
+ ++p2;
+ }
+ return toupper(*p2) > toupper(*p1) ? -1 : 1;
+}
53 purest_json.c
View
@@ -1,57 +1,10 @@
#include "purest_json.h"
-#include "rest.c"
-#include "json.c"
void purest_json_setup(void) {
post("PuREST JSON version %s: A library for executing HTTP queries and encoding and decoding JSON data from Puredata.", LIBRARY_VERSION);
post("(c) Thomas Mayer (Residuum) 2011");
post("Get the latest source from https://github.com/residuum/PuRestJson");
- setup_rest();
- setup_json_encoder();
- setup_json_decoder();
-}
-
-char *remove_backslashes(char *source_string) {
- char *dest = NULL;
- char remove[2] = "\\,";
- size_t len_src = strlen(source_string);
- int found;
- unsigned int i = 0;
- int j = 0;
-
- dest = (char *) calloc(len_src + 1, sizeof(char));
- if (dest == NULL) {
- printf("Unable to allocate memory\n");
- }
- memset(dest, 0x00,sizeof(char) * len_src + 1 );
-
- for ( i = 0; i < len_src; i++ ) {
- found = FALSE;
- if (source_string[i] == remove[0] && source_string[i +1] == remove[1]) {
- i++;
- found = TRUE;
- }
-
- if (FALSE == found) {
- dest[j] = source_string[i];
- } else {
- dest[j] = ',';
- }
- j++;
- }
- return (dest);
-}
-
-int str_ccmp(const char *s1, const char *s2) {
- const unsigned char *p1 = (const unsigned char *)s1;
- const unsigned char *p2 = (const unsigned char *)s2;
-
- while (toupper(*p1) == toupper(*p2)) {
- if (*p1 == '\0') {
- return 0;
- }
- ++p1;
- ++p2;
- }
- return toupper(*p2) > toupper(*p1) ? -1 : 1;
+ rest0x2djson_setup();
+ json0x2dencoder_setup();
+ json0x2ddecoder_setup();
}
9 purest_json.h
View
@@ -48,8 +48,7 @@ typedef struct json_decode {
} t_json_decode;
/* rest */
-t_class *rest_class;
-void setup_rest(void);
+void setup_rest0x2djson(void);
void *rest_new(t_symbol *selector, int argcount, t_atom *argvec);
void rest_command(t_rest *x, t_symbol *selector, int argcount, t_atom *argvec);
@@ -62,8 +61,7 @@ void execute_rest(t_rest *x);
void *execute_rest_thread(void *thread_args);
/* json-encode */
-t_class *json_encode_class;
-void setup_json_encode(void);
+void setup_json0x2dencode(void);
void *json_encode_new(t_symbol *selector, int argcount, t_atom *argvec);
void json_encode_bang(t_json_encode *x);
@@ -74,8 +72,7 @@ void json_encode_clear(t_json_encode *x, t_symbol *selector, int argcount, t_ato
json_object *create_object(char *value);
/* json-decode */
-t_class *json_decode_class;
-void setup_json_decode(void);
+void setup_json0x2ddecode(void);
void *json_decode_new(t_symbol *selector, int argcount, t_atom *argvec);
void json_decode_string(t_json_decode *x, t_symbol *data);
6 rest.c → rest-json.c
View
@@ -1,3 +1,7 @@
+#include "purest_json.h"
+
+static t_class *rest_class;
+
static size_t write_memory_callback(void *ptr, size_t size, size_t nmemb, void *data) {
size_t realsize = size * nmemb;
t_memory_struct *mem = (t_memory_struct *)data;
@@ -29,7 +33,7 @@ static size_t read_memory_callback(void *ptr, size_t size, size_t nmemb, void *d
return to_copy;
}
-void setup_rest(void) {
+void setup_rest0x2djson(void) {
rest_class = class_new(gensym("rest-json"), (t_newmethod)rest_new,
0, sizeof(t_rest), 0, A_GIMME, 0);
class_addmethod(rest_class, (t_method)rest_oauth, gensym("oauth"), A_GIMME, 0);
Please sign in to comment.
Something went wrong with that request. Please try again.