From e4edeb3446e6e6cbe38eee061d6e1cc60aa4b094 Mon Sep 17 00:00:00 2001 From: Detlev Casanova Date: Thu, 29 Jul 2010 13:43:26 +0200 Subject: Initial library commit --- src/Makefile.in | 515 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/dict.c | 77 ++++++++ src/dict.h | 11 ++ src/internal.h | 15 ++ src/interpreter.c | 176 +++++++++++++++++++ src/interpreter.h | 7 + src/portage.h | 8 + src/stringlist.c | 134 ++++++++++++++ src/stringlist.h | 15 ++ src/tester.c | 51 ++++++ 10 files changed, 1009 insertions(+) create mode 100644 src/Makefile.in create mode 100644 src/dict.c create mode 100644 src/dict.h create mode 100644 src/internal.h create mode 100644 src/interpreter.c create mode 100644 src/interpreter.h create mode 100644 src/portage.h create mode 100644 src/stringlist.c create mode 100644 src/stringlist.h create mode 100644 src/tester.c (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..05ac4fb --- /dev/null +++ b/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/src/dict.c b/src/dict.c new file mode 100644 index 0000000..29c1dea --- /dev/null +++ b/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/src/dict.h b/src/dict.h new file mode 100644 index 0000000..86cbbb3 --- /dev/null +++ b/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/src/internal.h b/src/internal.h new file mode 100644 index 0000000..8f44213 --- /dev/null +++ b/src/internal.h @@ -0,0 +1,15 @@ +#ifndef INTERNAL_H +#define INTERNAL_H + +#include +#include "stringlist.h" +#include "dict.h" + +PyObject* executeFunction(const char *module, const char *funcName, const char* format, ...); + +StringList* listToCList(PyObject* list); +PyObject* cListToPyList(StringList*); + +PyObject* dictToPyDict(Dict *dict); + +#endif diff --git a/src/interpreter.c b/src/interpreter.c new file mode 100644 index 0000000..941d2b2 --- /dev/null +++ b/src/interpreter.c @@ -0,0 +1,176 @@ +#include +#include +#include +#include "interpreter.h" + +/** + * PyObjectList + * 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); +} + +/* + * Interpreter + * + * A Python interpreter object keeps the context like the loaded modules. + */ + +struct Interpreter +{ + PyObjectList *modules; +} *in = 0; + +/** + * This is the first function that must be called before using the library. + */ +void portageInit() +{ + 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 portageFinalize() +{ + if (!in) + return; + freeList(in->modules, 1); + free(in); + + if (Py_IsInitialized()) + Py_Finalize(); +} + +/** + * 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, ...) +{ + if (!Py_IsInitialized()) + Py_Initialize(); + + // 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/src/interpreter.h b/src/interpreter.h new file mode 100644 index 0000000..0c1eae0 --- /dev/null +++ b/src/interpreter.h @@ -0,0 +1,7 @@ +#ifndef INTERPRETER_H +#define INTERPRETER_H + +void portageInit(); +void portageFinalize(); + +#endif diff --git a/src/portage.h b/src/portage.h new file mode 100644 index 0000000..374c721 --- /dev/null +++ b/src/portage.h @@ -0,0 +1,8 @@ +#ifndef PORTAGE_H +#define PORTAGE_H + +#include "stringlist.h" +#include "dict.h" +//#include "interpreter.h" + +#endif diff --git a/src/stringlist.c b/src/stringlist.c new file mode 100644 index 0000000..915cca4 --- /dev/null +++ b/src/stringlist.c @@ -0,0 +1,134 @@ +#include +#include +#include "stringlist.h" + +struct StringList +{ + char **list; + unsigned int count; +}; + +// Creates a String list to use with the library. +// len is 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; +} + +/* + * Returns the number of strings in the list + */ +unsigned int stringListCount(StringList *l) +{ + if (!l) + return 0; + return l->count; +} + +/* + * Returns 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]; +} + +/* + * 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/src/stringlist.h b/src/stringlist.h new file mode 100644 index 0000000..60800f0 --- /dev/null +++ b/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/src/tester.c b/src/tester.c new file mode 100644 index 0000000..02e43df --- /dev/null +++ b/src/tester.c @@ -0,0 +1,51 @@ +#include +#include "interpreter.h" + +int main(int argc, char *argv[]) +{ + argc = argc; + argv = argv; + int ret = 0; + portageInit(); + + /*Message *msg = messageCreate("portage", 0, 0, 0); + BareConfig *cfg = bareConfigCreate(msg, 0, 0, 0); + + LaymanAPI *l = portageAPICreate(cfg, 0, 0); + if (0 == portageAPIFetchRemoteList(l)) + { + printf("Unable to fetch the remote list.\n"); + ret = -1; + } + + StringList *strs = portageAPIGetAvailable(l, 0); + printf("list:\n"); + stringListPrint(strs); + + printf("\n"); + + unsigned int len = stringListCount(strs); + //OverlayInfo *infos = calloc(len, sizeof(OverlayInfo)); + //int count = portageAPIGetAllInfos(l, strs, infos); + + OverlayInfo *oi = portageAPIGetAllInfo(l, "kuroo"); + if (oi) + { + printf("%s\n~~~~~~~~~~~~~~~~~~~~\n", oi->name); + printf("%s\n\n", oi->description); + overlayInfoFree(*oi); + free(oi); + } + + printf("\n"); + + //free(infos); + stringListFree(strs); + + bareConfigFree(cfg); + portageAPIFree(l);*/ + + portageFinalize(); + + return ret; +} -- cgit v1.2.3-65-gdbad