From 78eefa4b5a74690a537fc725b4de2224548a0826 Mon Sep 17 00:00:00 2001 From: dol-sen Date: Wed, 5 Oct 2011 13:50:03 -0700 Subject: move everything to prep for a merge into layman. --- c-layman/src/Makefile.in | 515 ++++++++++++++++++++++++++++++++++++ c-layman/src/config.c | 164 ++++++++++++ c-layman/src/config.h | 20 ++ c-layman/src/dict.c | 77 ++++++ c-layman/src/dict.h | 11 + c-layman/src/internal.h | 21 ++ c-layman/src/interpreter.c | 189 ++++++++++++++ c-layman/src/interpreter.h | 7 + c-layman/src/layman.h | 11 + c-layman/src/laymanapi.c | 638 +++++++++++++++++++++++++++++++++++++++++++++ c-layman/src/laymanapi.h | 56 ++++ c-layman/src/message.c | 321 +++++++++++++++++++++++ c-layman/src/message.h | 12 + c-layman/src/stringlist.c | 155 +++++++++++ c-layman/src/stringlist.h | 15 ++ c-layman/src/tester.c | 72 +++++ 16 files changed, 2284 insertions(+) create mode 100644 c-layman/src/Makefile.in create mode 100644 c-layman/src/config.c create mode 100644 c-layman/src/config.h create mode 100644 c-layman/src/dict.c create mode 100644 c-layman/src/dict.h create mode 100644 c-layman/src/internal.h create mode 100644 c-layman/src/interpreter.c create mode 100644 c-layman/src/interpreter.h create mode 100644 c-layman/src/layman.h create mode 100644 c-layman/src/laymanapi.c create mode 100644 c-layman/src/laymanapi.h create mode 100644 c-layman/src/message.c create mode 100644 c-layman/src/message.h create mode 100644 c-layman/src/stringlist.c create mode 100644 c-layman/src/stringlist.h create mode 100644 c-layman/src/tester.c (limited to 'c-layman/src') diff --git a/c-layman/src/Makefile.in b/c-layman/src/Makefile.in new file mode 100644 index 0000000..05ac4fb --- /dev/null +++ b/c-layman/src/Makefile.in @@ -0,0 +1,515 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +bin_PROGRAMS = tester$(EXEEXT) +subdir = src +DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + AUTHORS COPYING ChangeLog INSTALL NEWS +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am_tester_OBJECTS = config.$(OBJEXT) dict.$(OBJEXT) \ + interpreter.$(OBJEXT) laymanapi.$(OBJEXT) message.$(OBJEXT) \ + stringlist.$(OBJEXT) tester.$(OBJEXT) +tester_OBJECTS = $(am_tester_OBJECTS) +am__DEPENDENCIES_1 = +tester_DEPENDENCIES = $(am__DEPENDENCIES_1) +DEFAULT_INCLUDES = -I.@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(tester_SOURCES) +DIST_SOURCES = $(tester_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PYTHON_CFLAGS = @PYTHON_CFLAGS@ +PYTHON_LIBS = @PYTHON_LIBS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AM_CFLAGS = $(PYTHON_CFLAGS) --std=c99 -W -Wall +tester_SOURCES = config.c dict.c interpreter.c laymanapi.c message.c stringlist.c tester.c config.h dict.h interpreter.h laymanapi.h message.h stringlist.h +tester_LDADD = $(PYTHON_LIBS) +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +tester$(EXEEXT): $(tester_OBJECTS) $(tester_DEPENDENCIES) + @rm -f tester$(EXEEXT) + $(LINK) $(tester_OBJECTS) $(tester_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dict.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interpreter.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/laymanapi.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/message.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stringlist.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tester.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic clean-libtool ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-binPROGRAMS install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-binPROGRAMS + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/c-layman/src/config.c b/c-layman/src/config.c new file mode 100644 index 0000000..c578d90 --- /dev/null +++ b/c-layman/src/config.c @@ -0,0 +1,164 @@ +#include + +#include "config.h" +#include "internal.h" + +/** + * \internal + */ +#define debug(x) printf(x) + +/** \defgroup config Config + * \brief Layman library configuration module + */ + +/** \addtogroup config + * @{ + */ + + +/** + * \internal + */ +struct BareConfig +{ + PyObject *object; +}; + +/** + * \internal + * Returns the internal Python object. + */ +PyObject *_bareConfigObject(BareConfig *c) +{ + if (c && c->object) + return c->object; + else + Py_RETURN_NONE; +} + +/** + * Creates a bare config object with default values. + * + * \param outFd where information must be written to + * \param inFd where information must be read from + * \param errFd where errors must be written to + * + * \return a new instance of a BareConfig object. It must be freed with bareConfigFree() + */ +BareConfig *bareConfigCreate(Message *m, FILE* outFd, FILE* inFd, FILE* errFd) +{ + if (!outFd || fileno(outFd) <= 0) + outFd = stdout; + if (!inFd || fileno(inFd) <= 0) + inFd = stdin; + if (!errFd || fileno(errFd) <= 0) + errFd = stderr; + + PyObject *pyout = PyFile_FromFile(outFd, "", "w", 0); + PyObject *pyin = PyFile_FromFile(inFd, "", "r", 0); + PyObject *pyerr = PyFile_FromFile(errFd, "", "w", 0); + + PyObject *obj = executeFunction("layman.config", "BareConfig", "OOOO", _messageObject(m), pyout, pyin, pyerr); + Py_DECREF(pyout); + Py_DECREF(pyin); + Py_DECREF(pyerr); + + if (!obj) + { + debug("The execution failed, Are you sure app-portage/layman-8888 is properly installed ?\n"); + return NULL; + } + + BareConfig *ret = malloc(sizeof(BareConfig)); + ret->object = obj; + + return ret; +} + +/** + * Frees a BareConfig object. + */ +void bareConfigFree(BareConfig* cfg) +{ + if (cfg && cfg->object) + { + Py_DECREF(cfg->object); + } + + if (cfg) + free(cfg); +} + +/** + * Get an option's default value. + * + * \param opt the name of the option + * + * \return the value or NULL on failure. + */ +const char* bareConfigGetDefaultValue(BareConfig* cfg, const char* opt) +{ + PyObject *obj = PyObject_CallMethod(cfg->object, "get_defaults", NULL); + if (!obj) + return NULL; + + if (PyDict_Contains(obj, PyString_FromString(opt))) + { + PyObject *pyopt = PyString_FromString(opt); + char *tmp = PyString_AsString(PyDict_GetItem(obj, pyopt)); + Py_DECREF(pyopt); + + char *ret = malloc(sizeof(char) * strlen(tmp)); + strcpy(ret, tmp); + Py_DECREF(obj); + + return ret; + } + else + return ""; +} + +/* + * Get an option's current value. + * + * \param opt the name of the option + * + * \return the value or NULL on failure + */ +const char* bareConfigGetOptionValue(BareConfig* cfg, const char* opt) +{ + PyObject *obj = PyObject_CallMethod(cfg->object, "get_option", "(z)", opt); + char *tmp = PyString_AsString(obj); + char *ret = malloc(sizeof(char) * (strlen(tmp) + 1)); + + strcpy(ret, tmp); + + Py_DECREF(obj); + + return ret; +} + +/* + * Modifies an option's value + * + * \param opt the name of the option + * \param val the new value for this option + * + * \return True on success, 0 on failure + */ +int bareConfigSetOptionValue(BareConfig* cfg, const char* opt, const char* val) +{ + PyObject *obj = PyObject_CallMethod(cfg->object, "set_option", "(zz)", opt, val); + int ret; + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** @} */ diff --git a/c-layman/src/config.h b/c-layman/src/config.h new file mode 100644 index 0000000..cb3c726 --- /dev/null +++ b/c-layman/src/config.h @@ -0,0 +1,20 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#include "stringlist.h" +#include "message.h" + +typedef struct BareConfig BareConfig; + +BareConfig* bareConfigCreate(Message* m, FILE* outFd, FILE* inFd, FILE* errFd); + +/* + * FIXME : could the Python lib work the same way ? + */ + +const char* bareConfigGetDefaultValue(BareConfig* cfg, const char*); +const char* bareConfigGetOptionValue(BareConfig* cfg, const char* opt); +int bareConfigSetOptionValue(BareConfig* cfg, const char*, const char*); +void bareConfigFree(BareConfig*); + +#endif diff --git a/c-layman/src/dict.c b/c-layman/src/dict.c new file mode 100644 index 0000000..29c1dea --- /dev/null +++ b/c-layman/src/dict.c @@ -0,0 +1,77 @@ +#include +#include +#include + +#include "internal.h" +#include "dict.h" + +/* + * Dict + */ +typedef struct DictElem DictElem; +struct DictElem +{ + const char *key; + const char *val; + struct DictElem *next; +}; + +struct Dict +{ + DictElem *root; + int count; +}; + +Dict *dictCreate() +{ + Dict *ret = malloc(sizeof(Dict)); + ret->count = 0; + ret->root = 0; + return ret; +} + +void dictInsert(Dict* list, const char* key, const char* value) +{ + if (!list) + return; + DictElem *node = malloc(sizeof(DictElem)); + node->key = key; + node->val = value; + node->next = list->root; + list->root = node; + list->count++; +} + +unsigned int dictCount(Dict *list) +{ + return (list ? list->count : 0); +} + +void dictFree(Dict *list) +{ + if (!list) + return; + + DictElem *node = list->root; + while (node) + { + DictElem *tmp = node; + node = node->next; + free(tmp); + } + + free(list); +} + +PyObject *dictToPyDict(Dict *dict) +{ + PyObject *pydict = PyDict_New(); + DictElem *node = dict->root; + while (node) + { + PyDict_SetItem(pydict, PyBytes_FromString(node->key), PyBytes_FromString(node->val)); + node = node->next; + } + + return pydict; +} diff --git a/c-layman/src/dict.h b/c-layman/src/dict.h new file mode 100644 index 0000000..86cbbb3 --- /dev/null +++ b/c-layman/src/dict.h @@ -0,0 +1,11 @@ +#ifndef DICT_H +#define DICT_H + +typedef struct Dict Dict; + +Dict* dictCreate(); +//char* tableFind(Dict *table, char* key); +void dictFree(Dict *t); +void dictInsert(Dict* list, const char* key, const char* value); +unsigned int dictCount(Dict *table); +#endif diff --git a/c-layman/src/internal.h b/c-layman/src/internal.h new file mode 100644 index 0000000..5d05d09 --- /dev/null +++ b/c-layman/src/internal.h @@ -0,0 +1,21 @@ +#ifndef INTERNAL_H +#define INTERNAL_H + +#include +#include "stringlist.h" +#include "dict.h" +#include "config.h" +#include "message.h" + +PyObject* executeFunction(const char *module, const char *funcName, const char* format, ...); + +PyObject* _bareConfigObject(BareConfig*); + +PyObject* _messageObject(Message* m); + +StringList* listToCList(PyObject* list); +PyObject* cListToPyList(StringList*); + +PyObject* dictToPyDict(Dict *dict); + +#endif diff --git a/c-layman/src/interpreter.c b/c-layman/src/interpreter.c new file mode 100644 index 0000000..95d40d9 --- /dev/null +++ b/c-layman/src/interpreter.c @@ -0,0 +1,189 @@ +#include +#include +#include +#include "interpreter.h" + +/** + * \internal + * Stores modules in a linked list so that they don't have to be reloaded every time. + */ +typedef struct PyObjectListElem +{ + PyObject *object; + struct PyObjectListElem *next; +} PyObjectListElem; + +typedef struct PyObjectList +{ + PyObjectListElem *root; + int count; +} PyObjectList; + +PyObjectList *createObjectList() +{ + PyObjectList *ret = malloc(sizeof(PyObjectList)); + ret->count = 0; + ret->root = 0; + return ret; +} + +void insert(PyObjectList* list, PyObject *object) +{ + if (!list || !object) + return; + PyObjectListElem *node = malloc(sizeof(PyObjectListElem)); + node->object = object; + node->next = list->root; + list->root = node; + list->count++; +} + +PyObject *moduleNamed(const char *name, PyObjectList *list) +{ + PyObjectListElem *node = list->root; + while (node) + { + if (strcmp(PyModule_GetName(node->object), name) == 0) + return node->object; + node = node->next; + } + + return NULL; +} + +int listCount(PyObjectList *list) +{ + return (list ? list->count : 0); +} + +void freeList(PyObjectList *list, int deref) +{ + if (!list) + return; + + PyObjectListElem *node = list->root; + while (node) + { + PyObjectListElem *tmp = node; + node = node->next; + if (deref) + { + Py_DECREF(tmp->object); + } + free(tmp); + } + + free(list); +} + +/** + * \internal + * A Python interpreter object keeps the context like the loaded modules. + */ +struct Interpreter +{ + PyObjectList *modules; +} *in = 0; + + +/** \defgroup layman_base Layman base + * + * \brief Layman Base functions + * + * These functions are used when you want to begin or end using the library. + */ + +/** \addtogroup layman_base + * @{ + */ + +/** + * This is the first function that must be called before using the library. + * It initializes the Python interpreter. + */ +void laymanInit() +{ + if (in) + return; + + if (!Py_IsInitialized()) + Py_Initialize(); + + in = malloc(sizeof(struct Interpreter)); + in->modules = createObjectList(); +} + +/** + * Call this function when you're done using the library. + * It will free memory. + */ +void laymanFinalize() +{ + if (!in) + return; + freeList(in->modules, 1); + free(in); + + if (Py_IsInitialized()) + Py_Finalize(); +} + +/** @} */ + +/** + * \internal + * printf() like function that executes a python function + * + * \param module name of the python module in which the function is + * \param funcName the function name to call + * \param format printf() like list of arguments. See Python documentation + * \param ... arguments for the function + * + * \return the result of the execution. Can be NULL if the call failed. + */ +PyObject *executeFunction(const char *module, const char *funcName, const char* format, ...) +{ + assert(in); + + // Make argument list + PyObject *args; + if (format == NULL || strcmp(format, "") == 0) + args = PyTuple_New(0); + else + { + va_list listArgs; + va_start(listArgs, format); + + args = Py_VaBuildValue(format, listArgs); + } + + // Look for the module. + PyObject *mod = 0; + if (in->modules) + { + mod = moduleNamed(module, in->modules); + } + // If module is not loaded yet, do it. + if (!mod) + { + mod = PyImport_ImportModule(module); + if (!mod) + return NULL; + insert(in->modules, mod); + } + + // Look for the function + PyObject *func = PyObject_GetAttrString(mod, funcName); + if (!PyCallable_Check(func)) + return NULL; + + // Execute it + PyObject *val = PyObject_CallObject(func, args); + + if (args != NULL) + { + Py_DECREF(args); + } + + return val; +} diff --git a/c-layman/src/interpreter.h b/c-layman/src/interpreter.h new file mode 100644 index 0000000..b280ad2 --- /dev/null +++ b/c-layman/src/interpreter.h @@ -0,0 +1,7 @@ +#ifndef INTERPRETER_H +#define INTERPRETER_H + +void laymanInit(); +void laymanFinalize(); + +#endif diff --git a/c-layman/src/layman.h b/c-layman/src/layman.h new file mode 100644 index 0000000..9811ba5 --- /dev/null +++ b/c-layman/src/layman.h @@ -0,0 +1,11 @@ +#ifndef LAYMAN_H +#define LAYMAN_H + +#include "laymanapi.h" +#include "message.h" +#include "stringlist.h" +#include "config.h" +#include "dict.h" +#include "interpreter.h" + +#endif diff --git a/c-layman/src/laymanapi.c b/c-layman/src/laymanapi.c new file mode 100644 index 0000000..d733cfd --- /dev/null +++ b/c-layman/src/laymanapi.c @@ -0,0 +1,638 @@ +#include +#include "internal.h" +#include "laymanapi.h" + +/** \defgroup layman_api Layman API + * \brief Main API functions + */ + +/** \addtogroup layman_api + * @{ + */ + +static int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* overlays, OverlayInfo *results, const char *overlay); + +/** + * Layman structure that is used in all functions + */ +struct LaymanAPI +{ + /** + * \internal + * PyObject that is used to call methods + */ + PyObject *object; +}; + + +/** + * Creates a LaymanAPI object that must be used in all function in this file. + * + * \param config a BareConfig object that contains all configuration options. If NULL, the default configuration will be used. + * \param report_error if True, errors reporting on stdout will be activated. + * \param output ? + * \return a new instance of the LaymanAPI class, to be freed with laymanAPIFree() + */ +LaymanAPI* laymanAPICreate(BareConfig* config, int report_error, int output) +{ + PyObject *cfg; + if (!config) + cfg = Py_None; + else + cfg = _bareConfigObject(config); + + PyObject *obj = executeFunction("layman.api", "LaymanAPI", "Oii", cfg, report_error, output); + if (!obj) + return NULL; + + LaymanAPI *ret = malloc(sizeof(LaymanAPI)); + ret->object = obj; + + return ret; +} + +/** + * Check if the given string is a valid repository + * + * \param l the LaymanAPI object. + * \param repo the repository to be checked. + * + * \return True if the repository is valid, False if not + */ +int laymanAPIIsRepo(LaymanAPI *l, const char* repo) +{ + if (!l || !l->object) + return 0; + + PyObject *obj = PyObject_CallMethod(l->object, "is_repo", "(s)", repo); + if (!obj) + return 0; + + int ret = PyObject_IsTrue(obj); + // ret must be 1 or 0 + assert(-1 != ret); + + Py_DECREF(obj); + + return ret; +} + +/** + * Check if the given string is a valid and installed repository + * + * \param l the LaymanAPI object. + * \param repo the repository to be checked. + * + * \return True if the repository is valid and installed, False if not + */ +int laymanAPIIsInstalled(LaymanAPI *l, const char* repo) +{ + if (!l || !l->object) + return 0; + + PyObject *obj = PyObject_CallMethod(l->object, "is_installed", "(s)", repo); + if (!obj) + return 0; + + int ret = PyObject_IsTrue(obj); + // ret must be 1 or 0 + assert(-1 != ret); + + Py_DECREF(obj); + + return ret; +} + +/** + * Returns a list of the available overlays. + * + * \param l the LaymanAPI object. + * \param reload if True, reloads the list + * + * \return the list of available overlays + */ +StringList* laymanAPIGetAvailable(LaymanAPI* l, int reload) +{ + if (!l || !l->object) + return NULL; + + PyObject *obj = PyObject_CallMethod(l->object, "get_available", "(i)", reload); + if (!obj) + return NULL; + + //listToCList() will return Type_NONE if the python list is not valid. + StringList *ret = listToCList(obj); + Py_DECREF(obj); + + return ret; +} + +/** + * Returns a list of the installed overlays. + * + * \param l the LaymanAPI object. + * \param reload if True, reloads the list + * + * \return the list of installed overlays + */ +StringList* laymanAPIGetInstalled(LaymanAPI* l, int reload) +{ + if (!l || !l->object) + return NULL; + + PyObject *obj = PyObject_CallMethod(l->object, "get_installed", "(i)", reload); + if (!obj) + return NULL; + + StringList* ret = listToCList(obj); + Py_DECREF(obj); + + return ret; +} + +/** + * Syncs an overlay. + * + * \param overlay The name of the overlay to sync + * \param verbose if True, the output will be more verbose. + * + * \return True if it succeeded, False if not. + */ +int laymanAPISync(LaymanAPI* l, const char* overlay, int verbose) +{ + if (!l || !l->object) + return 0; + + PyObject *obj = PyObject_CallMethod(l->object, "sync", "(si)", overlay, verbose); + if (!obj) + return 0; + + int ret = PyObject_IsTrue(obj); + + // ret must be 1 or 0 + assert(-1 != ret); + + Py_DECREF(obj); + + return ret; +} + +/** + * Updates the local overlay list. + * + * \return True if it succeeded, False if not. + */ +int laymanAPIFetchRemoteList(LaymanAPI* l) +{ + if (!l || !l->object) + return 0; + + PyObject *obj = PyObject_CallMethod(l->object, "fetch_remote_list", NULL); + if (!obj) + return 0; + + int ret = PyObject_IsTrue(obj); + assert(-1 != ret); + + Py_DECREF(obj); + + return ret; +} + +/** + * Gets the information from the overlays given in the StringList overlays. + * The results are stored in the results table which must be initialized with N structures, + * N being the number of overlays in the overlays StringList. + * This function fills the name, text, supported and official fields of the OverlayInfo structure. + * + * \param overlays the list of overlays to get information from + * \param results a pointer to a table of OverlayInfo structures + * + * \return the number of results structures that have been filled + */ +int laymanAPIGetInfoStrList(LaymanAPI* l, StringList* overlays, OverlayInfo* results) +{ + // Check input data. + if (!l || !l->object || !overlays || !results) + return 0; + + // Convert the StringList to a Python list object. + PyObject *list = cListToPyList(overlays); + + // Call the method + PyObject *obj = PyObject_CallMethod(l->object, "get_info_str", "(O)", list); + Py_DECREF(list); + + // Check if the returned value is a dict as expected. + if (!obj || !PyDict_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return 0; + } + + PyObject *name, *tuple; + Py_ssize_t i = 0; + + int k = 0; + + // Loop in the dict to get all tuples. + while (PyDict_Next(obj, &i, &name, &tuple)) + { + // If it's not a sequence, it's ignored + // FIXME:should an assert be used ? + if (!tuple || !PySequence_Check(tuple)) + { + Py_DECREF(obj); + continue; + } + + PyObject *text = PySequence_GetItem(tuple, 0); + PyObject *official = PySequence_GetItem(tuple, 1); + PyObject *supported = PySequence_GetItem(tuple, 2); + + // Check if text and name are Strings + if (!PyString_Check(text) || !PyString_Check(name)) + continue; + + // Copy values in the kth structure of the results. + char* tmp = PyString_AsString(name); + assert(NULL != tmp); + results[k].name = strdup(tmp); + + tmp = PyString_AsString(text); + assert(NULL != tmp); + results[k].text = strdup(tmp); + + results[k].official = PyObject_IsTrue(official); + assert(-1 != results[k].official); + results[k].supported = PyObject_IsTrue(supported); + assert(-1 != results[k].supported); + + k++; + } + + Py_DECREF(obj); + + //Return the number of structures that have been filled. + return k; +} + +/** + * Provided for convenience, this function get the information for only 1 overlay. + * + * \param overlay the overlay name to get info from + * + * \return NULL if it fails, an OverlayInfo struct if not. + */ +OverlayInfo *laymanAPIGetInfoStr(LaymanAPI* l, const char* overlay) +{ + // Check input data. + if (!l || !l->object || !overlay) + return NULL; + + // Create a list containing the overlay string + StringList *olist = stringListCreate(1); + stringListInsertAt(olist, 0, overlay); + + OverlayInfo *oi = malloc(sizeof(OverlayInfo)); + int count = laymanAPIGetInfoStrList(l, olist, oi); + assert(1 != count); + + stringListFree(olist); + + return oi; +} + +/** + * Get all information from an overlay. + * This function fills every fields but the text field of the OverlayInfo structure. + * + * \param overlay the overlay name to get info from + * + * \return NULL if it fails, an OverlayInfo struct if not. + */ +OverlayInfo *laymanAPIGetAllInfo(LaymanAPI* l, const char* overlay) +{ + // Check input data. + if (!l || !l->object || !overlay) + return NULL; + + // Prepare the structure to be returned. + OverlayInfo *ret = calloc(1, sizeof(OverlayInfo)); + + // Fill it in. + if (0 == _laymanAPIGetAllInfos(l, NULL, ret, overlay)) + { + free(ret); + return NULL; + } + + // Return it + return ret; +} + +/** + * Gives a list of OverlayInfo's from the overaly names found in the overlays StringList. + * results must be allocated and initialized with zeroes. + * + * If an information is unavailable (no owner email for example), + * the correpsonding field will stay to NULL + * + * This function fills every fields but the text field of the OverlayInfo structure. + * + * @param overlays the list of overlays to get information from + * @param results a pointer to a table of OverlayInfo structures + * + * @return the number of OverlayInfo structures filled. + */ +int laymanAPIGetAllInfoList(LaymanAPI* l, StringList* overlays, OverlayInfo *results) +{ + return _laymanAPIGetAllInfos(l, overlays, results, NULL); +} + +/** + * \internal + * \brief Gives a list of OverlayInfo's from the overaly names found in the overlays StringList if it's not NULL + * If it's NULL, and overlay is not NULL, the information for Overlay will be fetched. + * results must be allocated and initialized with zeroes. + * + * If an information is unavailable (no owner email for example), + * the correpsonding field will stay to NULL + * + * \param l Layman object + * \param overlays List of overlays + * \param results results of the call + * \param overlay overlay to provide + * + * \return the number of OverlayInfo structures filled. + */ +int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* overlays, OverlayInfo *results, const char *overlay) +{ + // Check input data. + if (!l || !l->object || !results || (!overlays && !overlay)) + return 0; + + PyObject *obj = NULL; + + // First case : overlay list + if (overlays != NULL) + { + // Convert the StringList to a Python list object. + PyObject *list = cListToPyList(overlays); + + // Call the method + obj = PyObject_CallMethod(l->object, "get_all_info", "(O)", list); + Py_DECREF(list); + } + // Second case : overlay name + else if (overlay != NULL) + { + obj = PyObject_CallMethod(l->object, "get_all_info", "(s)", overlay); + } + + // Check if the returned value is a dict as expected. + if (!obj || !PyDict_Check(obj)) + { + if (obj) + { + Py_DECREF(obj); + } + return 0; + } + + PyObject *name, *dict; + Py_ssize_t i = 0; + + int k = 0; + + // Loop in the dict to get all dicts. + while (PyDict_Next(obj, &i, &name, &dict)) + { + // If it's not a dict, it's ignored + // FIXME:should an assert be used ? + if (!dict || !PyDict_Check(dict)) + continue; + + PyObject *official = PyDict_GetItemString(dict, "official"); + PyObject *supported = PyDict_GetItemString(dict, "supported"); + PyObject *ownerName = PyDict_GetItemString(dict, "owner_name"); + PyObject *ownerEmail = PyDict_GetItemString(dict, "owner_email"); + PyObject *homepage = PyDict_GetItemString(dict, "homepage"); + PyObject *description = PyDict_GetItemString(dict, "description"); + PyObject *srcUris = PyDict_GetItemString(dict, "src_uris"); + PyObject *srcType = PyDict_GetItemString(dict, "src_type"); + PyObject *priority = PyDict_GetItemString(dict, "priority"); + PyObject *quality = PyDict_GetItemString(dict, "quality"); +//'status':?? TODO + + // Copy values in the kth structure of the results. + char* tmp = PyString_AsString(name); + assert(NULL != tmp); //name must not be NULL + results[k].name = strdup(tmp); + + tmp = PyString_AsString(ownerName); + if (tmp != NULL) + results[k].ownerName = strdup(tmp); + + tmp = PyString_AsString(ownerEmail); + if (tmp != NULL) + results[k].ownerEmail = strdup(tmp); + + tmp = PyString_AsString(homepage); + if (tmp != NULL) + results[k].homepage = strdup(tmp); + + tmp = PyString_AsString(description); + if (tmp != NULL) + results[k].description = strdup(tmp); + + tmp = PyString_AsString(srcType); + if (tmp != NULL) + results[k].srcType = strdup(tmp); + + tmp = PyString_AsString(quality); + if (tmp != NULL) + results[k].quality = strdup(tmp); + + results[k].priority = PyLong_AsLong(priority); + + results[k].srcUris = listToCList(srcUris); + + // If official or supported is neither True or False, abort. + results[k].official = PyObject_IsTrue(official); + assert(-1 != results[k].official); + results[k].supported = PyObject_IsTrue(supported); + assert(-1 != results[k].supported); + + k++; + } + + //The returned value is not necessary anymore. + Py_DECREF(obj); + + //Return the number of structures that have been filled. + return k; +} + +/** + * Adds an overlay to layman + * + * \param repo the name of the repository to add + * + * \return True if it succeeded, False if not + */ +int laymanAPIAddRepo(LaymanAPI* l, const char *repo) +{ + if (!l || !l->object || !repo) + return 0; + + // Call the method + PyObject *obj = PyObject_CallMethod(l->object, "delete_repos", "(s)", repo); + + // If the call returned NULL, it failed. + int ret; + if (!obj) + ret = 0; + else + ret = 1; + + Py_DECREF(obj); + + return ret; +} + +/** + * Adds a list of overlays to layman + * + * \param repo the list of the repositories to add + * + * Return True if it succeeded, False if not + */ +int laymanAPIAddRepoList(LaymanAPI* l, StringList *repos) +{ + if (!l || !l->object || !repos) + return 0; + + // Converting the C list to a python list + PyObject *pyrepos = cListToPyList(repos); + + // Call the method + PyObject *obj = PyObject_CallMethod(l->object, "add_repos", "(O)", pyrepos); + Py_DECREF(pyrepos); + + // If the call returned NULL, it failed. + int ret; + if (!obj) + ret = 0; + else + ret = 1; + + Py_DECREF(obj); + + return ret; +} + +/** + * Deletes an overlay from layman + * + * \param repo the name of the repository to delete + * + * \return True if it succeeded, False if not + */ +int laymanAPIDeleteRepo(LaymanAPI* l, const char *repo) +{ + if (!l || !l->object || !repo) + return 0; + + // Call the method + PyObject *obj = PyObject_CallMethod(l->object, "delete_repos", "(s)", repo); + + // If the call returned NULL, it failed. + int ret; + if (!obj) + ret = 0; + else + ret = 1; + + Py_DECREF(obj); + + return ret; +} + +/** + * Deletes a list of overlays from layman + * + * \param repo the list of the repositories to delete + * + * \return True if it succeeded, False if not + */ +int laymanAPIDeleteRepoList(LaymanAPI* l, StringList *repos) +{ + if (!l || !l->object || !repos) + return 0; + + // Converting the C list to a python list + PyObject *pyrepos = cListToPyList(repos); + + // Call the method + PyObject *obj = PyObject_CallMethod(l->object, "delete_repos", "(O)", pyrepos); + Py_DECREF(pyrepos); + + // If the call returned NULL, it failed. + int ret; + if (!obj) + ret = 0; + else + ret = 1; + + Py_DECREF(obj); + + return ret; +} + +/** + * Frees a LaymanAPI object from memory + */ +void laymanAPIFree(LaymanAPI* l) +{ + if (l && l->object) + { + Py_DECREF(l->object); + } + + if (l) + free(l); +} + + +/* + * Function that properly frees an OverlayInfo structure's data + */ +void overlayInfoFree(OverlayInfo oi) +{ + if (oi.name) + free(oi.name); + if (oi.text) + free(oi.text); + if (oi.ownerEmail) + free(oi.ownerEmail); + if (oi.ownerName) + free(oi.ownerName); + if (oi.homepage) + free(oi.homepage); + if (oi.description) + free(oi.description); + if (oi.srcType) + free(oi.srcType); + if (oi.quality) + free(oi.quality); + if (oi.srcUris) + stringListFree(oi.srcUris); +} + +/** + * @} + */ diff --git a/c-layman/src/laymanapi.h b/c-layman/src/laymanapi.h new file mode 100644 index 0000000..60e20e0 --- /dev/null +++ b/c-layman/src/laymanapi.h @@ -0,0 +1,56 @@ +#ifndef LAYMAN_API_H +#define LAYMAN_API_H + +#include "config.h" +#include "stringlist.h" + +typedef struct LaymanAPI LaymanAPI; + +/** + * Contains all information for an overlay + */ +typedef struct OverlayInfo +{ + char* name; + char* text; + char* ownerEmail; + char* ownerName; + char* homepage; + char* description; + char* srcType; + char* quality; + int priority; + StringList* srcUris; + int official; + int supported; +} OverlayInfo; + +/** + * Creates a LaymanAPI object that must be used in all function in this file. + * + * \param config a BareConfig object that contains all configuration options. If NULL, the default configuration will be used. + * \param report_error if True, errors reporting on stdout will be activated. + * \param output ? + * \return a new instance of the LaymanAPI class, to be freed with laymanAPIFree() + */ +LaymanAPI* laymanAPICreate(BareConfig* config, int report_error, int output); + +int laymanAPIIsRepo(LaymanAPI *l, const char* repo); +int laymanAPIIsInstalled(LaymanAPI *l, const char* repo); +StringList* laymanAPIGetAvailable(LaymanAPI*, int reload); +StringList* laymanAPIGetInstalled(LaymanAPI*, int reload); +int laymanAPISync(LaymanAPI* l, const char* overlay, int verbose); +int laymanAPIFetchRemoteList(LaymanAPI*); +int laymanAPIGetInfoStrList(LaymanAPI* l, StringList* overlays, OverlayInfo* results); +OverlayInfo* laymanAPIGetInfoStr(LaymanAPI* l, const char* overlay); +int laymanAPIGetAllInfoList(LaymanAPI* l, StringList*, OverlayInfo*); +OverlayInfo* laymanAPIGetAllInfo(LaymanAPI* l, const char*); +int laymanAPIAddRepo(LaymanAPI* l, const char *repo); +int laymanAPIAddRepoList(LaymanAPI* l, StringList *repos); +int laymanAPIDeleteRepo(LaymanAPI* l, const char *repo); +int laymanAPIDeleteRepoList(LaymanAPI* l, StringList *repos); +OverlayInfo* laymanAPIGetInfo(LaymanAPI* l, const char* overlay); +void laymanAPIFree(LaymanAPI*); +void overlayInfoFree(OverlayInfo oi); + +#endif diff --git a/c-layman/src/message.c b/c-layman/src/message.c new file mode 100644 index 0000000..4d35bb6 --- /dev/null +++ b/c-layman/src/message.c @@ -0,0 +1,321 @@ +#include +#include "message.h" +#include "internal.h" + +/** \defgroup message Message + * \brief Debug message management + * + * This class relays all debug messages to the given files and set different + * debug levels. + */ + +/** \addtogroup message + * @{ + */ + +/** + * Message structure that is used in all functions + */ +struct Message +{ + /** + * \internal + */ + PyObject *object; +}; + +/** + * Creates a Message instance with default values. + * To modify those values, use the corresponding functions. + * + * \param module the module to debug. If you don't know, set "layman" + * \param out where to write info + * \param err where to write errors + * \param dbg where to write debug information + * + * \return a new instance of a Message object. It must be freed with messageFree() + */ +Message *messageCreate(const char* module, + FILE* out, + FILE* err, + FILE* dbg) +{ + PyObject *pyout, *pyerr, *pydbg; + + if (!out || fileno(out) <= 0) + out = stdout; + if (!err || fileno(err) <= 0) + err = stderr; + if (!dbg || fileno(dbg) <= 0) + dbg = stderr; + + pyout = PyFile_FromFile(out, "", "w", 0); + pyerr = PyFile_FromFile(err, "", "w", 0); + pydbg = PyFile_FromFile(dbg, "", "w", 0); + + PyObject *object = executeFunction("layman.debug", "Message", + "(sOOO)", + module, + pyout, + pyerr, + pydbg); + + Py_DECREF(pyout); + Py_DECREF(pyerr); + Py_DECREF(pydbg); + + if (!object) + return NULL; + + Message *ret = malloc(sizeof(Message)); + ret->object = object; + + return ret; +} + +/** + * Set the debug level. + * + * \param debug_level the debug level + * + * \return True on success, False on failure. + */ +int messageSetDebugLevel(Message *m, int debug_level) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "set_debug_level", "(I)", debug_level); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Set the debug verbosity. + * + * \param debug_verbosity the debug verbosity + * + * \return True on success, False on failure. + */ +int messageSetDebugVerbosity(Message *m, int debug_verbosity) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "set_debug_verbosity", "(I)", debug_verbosity); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Set the info level. + * + * \param info_level the info level + * + * \return True on success, False on failure. + */ +int messageSetInfoLevel(Message *m, int info_level) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "set_info_level", "(I)", info_level); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Set the warning level. + * + * \param warn_level the warning level + * + * \return True on success, False on failure. + */ +int messageSetWarnLevel(Message *m, int warn_level) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "set_warn_level", "(I)", warn_level); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Activates colors in the output + * + * \return 1 on success, 0 on failure + */ +int messageSetColorsOn(Message *m) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "color_on", NULL); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Deactivates colors in the output + * + * \return 1 on success, 0 on failure + */ +int messageSetColorsOff(Message *m) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "color_off", NULL); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Sets the methods to be debugged. + * + * \param mth the list of methods to be debugged, separated by comas + * + * \return 1 on success, 0 on failure + */ +int messageSetDebugMethods(Message *m, const char* mth) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "set_debug_methods", "(s)", mth); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Sets the classes to be debugged. + * + * \param mth the list of classes to be debugged, separated by comas + * + * \return 1 on success, 0 on failure + */ +int messageSetDebugClasses(Message *m, const char* cla) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "set_debug_classes", "(s)", cla); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Sets the variables to be debugged. + * + * \param mth the list of variables to be debugged, separated by comas + * + * \return 1 on success, 0 on failure + */ +int messageSetDebugVariables(Message *m, const char* var) +{ + if (!m || !m->object) + return 0; + + PyObject *obj = PyObject_CallMethod(m->object, "set_debug_variables", "(s)", var); + int ret; + + if (obj) + ret = 1; + else + ret = 0; + + Py_DECREF(obj); + + return ret; +} + +/** + * Frees a message structure. + */ +void messageFree(Message *m) +{ + if (m && m->object) + { + Py_DECREF(m->object); + } + if (m) + free(m); +} + +/** + * \internal + * Returns the internal Python object + */ +PyObject *_messageObject(Message* m) +{ + if (m && m->object) + return m->object; + else + Py_RETURN_NONE; +} +/** @} */ diff --git a/c-layman/src/message.h b/c-layman/src/message.h new file mode 100644 index 0000000..7fe8668 --- /dev/null +++ b/c-layman/src/message.h @@ -0,0 +1,12 @@ +#ifndef MESSAGE_H +#define MESSAGE_H + +#include +#include "stringlist.h" + +typedef struct Message Message; + +Message* messageCreate(const char* module, FILE* out, FILE* err, FILE* dbg); +void messageFree(Message *m); + +#endif diff --git a/c-layman/src/stringlist.c b/c-layman/src/stringlist.c new file mode 100644 index 0000000..fed7b8b --- /dev/null +++ b/c-layman/src/stringlist.c @@ -0,0 +1,155 @@ +#include +#include +#include "stringlist.h" + +/** \defgroup string_list StringList + * \brief String list management class + */ + +/** \addtogroup string_list + * @{ + */ +struct StringList +{ + char **list; + unsigned int count; +}; + +/** + * Creates a String list to use with the library. + * \param len the number of strings in the list. + */ +StringList* stringListCreate(size_t len) +{ + StringList *ret = malloc(sizeof(StringList)); + ret->count = len; + ret->list = malloc(sizeof(char*) * len); + + return ret; +} + +/** + * Inserts the string str in the list l at position pos. + * \return True if it succeeded, False if not. + */ +int stringListInsertAt(StringList *l, unsigned int pos, char *str) +{ + if(!l || !l->list || l->count < pos) + return 0; + + l->list[pos] = str; + + return 1; +} + +/** + * Get the number of strings in the list. + * + * \return the number of strings in the list + */ +unsigned int stringListCount(StringList *l) +{ + if (!l) + return 0; + return l->count; +} + +/** + * Get the String at position pos + * \return the String at position pos + */ +char* stringListGetAt(StringList *l, unsigned int pos) +{ + if (!l || !l->list || pos >= l->count) + return NULL; + + return l->list[pos]; +} + +/** + * \section internal + * @{ + * \internal + */ + +/** + * Converts a Python list object to a C String list + */ +StringList* listToCList(PyObject* list) +{ + if (!list || !PyList_Check(list)) + return NULL; + + unsigned int len = PyList_Size(list); + StringList *ret = malloc(sizeof(StringList)); + ret->count = len; + ret->list = malloc(sizeof(char*) * len); + + for (unsigned int i = 0; i < len; i++) + { + //Item are copied so that the PyObject can be deleted after the call without + //destroying the data in the returned list. + PyObject *elem = PyList_GetItem(list, i); + ret->list[i] = malloc(sizeof(char) * (PyBytes_Size(elem) + 1)); + strcpy(ret->list[i], PyBytes_AsString(elem)); + } + + return ret; +} + +/** + * Converts a C String list to a Python List object + */ +PyObject* cListToPyList(StringList* list) +{ + if (!list) + Py_RETURN_NONE; + + PyObject *ret = PyList_New(list->count); + for(unsigned int i = 0; i < list->count; i++) + { + PyList_SetItem(ret, i, PyBytes_FromString(list->list[i])); + } + + return ret; +} + +/** @} */ + +/** + * Prints a C String list. + */ +void stringListPrint(StringList* list) +{ + if (!list) + return; + + for(unsigned int i = 0; i < list->count; i++) + { + printf("\"%s\"", list->list[i]); + // No coma after the last item. + if (i < list->count - 1) + printf(", "); + } +} + +/** + * Frees a string list and it's data + */ +void stringListFree(StringList* list) +{ + if (list && list->list) + { + for(unsigned int i = 0; i < list->count; i++) + { + free(list->list[i]); + } + + free(list->list); + } + + if (list) + free(list); +} + +/** @} */ diff --git a/c-layman/src/stringlist.h b/c-layman/src/stringlist.h new file mode 100644 index 0000000..60800f0 --- /dev/null +++ b/c-layman/src/stringlist.h @@ -0,0 +1,15 @@ +#ifndef STRINGLIST_H +#define STRINGLIST_H + +#include + +typedef struct StringList StringList; + +StringList* stringListCreate(size_t); +unsigned int stringListCount(StringList*); +int stringListInsertAt(StringList*, unsigned int, char*); +char* stringListGetAt(StringList*, unsigned int); +void stringListPrint(StringList*); +void stringListFree(StringList*); + +#endif diff --git a/c-layman/src/tester.c b/c-layman/src/tester.c new file mode 100644 index 0000000..de0b6c7 --- /dev/null +++ b/c-layman/src/tester.c @@ -0,0 +1,72 @@ +#include +#include "interpreter.h" +#include "config.h" +#include "laymanapi.h" +#include "message.h" + +int main(int argc, char *argv[]) +{ + argc = argc; + argv = argv; + int ret = 0; + laymanInit(); + + Message *msg = messageCreate("layman", 0, 0, 0); + BareConfig *cfg = bareConfigCreate(msg, 0, 0, 0); + /*if (!bareConfigSetOptionValue(cfg, "local_list", "/home/detlev/src/gsoc2010/layman/layman/tests/testfiles/global-overlays.xml")) + printf("Error setting config option.\n"); + if (!bareConfigSetOptionValue(cfg, "storage", "/home/detlev/gsoc2010/layman-test")) + printf("Error setting config option.\n"); + printf("config: %s\n", bareConfigGetOptionValue(cfg, "config")); + printf("storage: %s\n", bareConfigGetOptionValue(cfg, "storage")); + printf("local_list: %s\n", bareConfigGetOptionValue(cfg, "local_list"));*/ + + LaymanAPI *l = laymanAPICreate(cfg, 0, 0); + if (0 == laymanAPIFetchRemoteList(l)) + { + printf("Unable to fetch the remote list.\n"); + ret = -1; + } + + StringList *strs = laymanAPIGetAvailable(l, 0); + printf("list:\n"); + stringListPrint(strs); + + printf("\n"); + + unsigned int len = stringListCount(strs); + //OverlayInfo *infos = calloc(len, sizeof(OverlayInfo)); + //int count = laymanAPIGetAllInfos(l, strs, infos); + + OverlayInfo *oi = laymanAPIGetAllInfo(l, "kuroo"); + if (oi) + { + printf("%s\n~~~~~~~~~~~~~~~~~~~~\n", oi->name); + printf("%s\n\n", oi->description); + overlayInfoFree(*oi); + free(oi); + } + + /*for (unsigned int i = 0; i < len; i++) + { + OverlayInfo *oi = laymanAPIGetAllInfo(l, stringListGetAt(strs, i)); + if (!oi) + continue; + printf("%s\n~~~~~~~~~~~~~~~~~~~~\n", oi->name); + printf("%s\n\n", oi->description); + overlayInfoFree(*oi); + free(oi); + }*/ + + printf("\n"); + + //free(infos); + stringListFree(strs); + + bareConfigFree(cfg); + laymanAPIFree(l); + + laymanFinalize(); + + return ret; +} -- cgit v1.2.3-1-g7c22