Browse Source

Autotools. Doesn't work yet

Serj Kalichev 1 year ago
parent
commit
9217870057
14 changed files with 902 additions and 0 deletions
  1. 98 0
      LICENCE
  2. 33 0
      Makefile.am
  3. 38 0
      README.md
  4. 5 0
      autogen.sh
  5. 11 0
      bin/Makefile.am
  6. 0 0
      bin/ytree.c
  7. 521 0
      configure.ac
  8. 14 0
      src/Makefile.am
  9. 0 0
      src/pline.c
  10. 0 0
      src/pline.h
  11. 68 0
      src/plugin.c
  12. 36 0
      src/private.h
  13. 62 0
      src/sr_copypaste.c
  14. 16 0
      src/sr_copypaste.h

+ 98 - 0
LICENCE

@@ -0,0 +1,98 @@
+================================================================================
+Overview
+This package contains code which is copyrighted to multiple sources.
+
+================================================================================
+3Com Corporation
+The intial public release of this software was developed by Graeme McKerrell
+whilst in the employment of 3Com Europe Ltd.
+
+Copyright (c) 2005, 3Com Corporation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of 3Com Corporation nor the names of its contributors may
+      be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+================================================================================
+Newport Networks Ltd.
+The 0.6-0.7 releases of this software was developed by Graeme McKerrell whilst in the 
+employment of Newport Networks Ltd.
+As well as enhancing the existing code the new modules were developed.
+
+Copyright (c) 2005,2006, Newport Networks Ltd
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of Newport Networks Ltd nor the names of its contributors may
+      be used to endorse or promote products derived from this software without
+      specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+================================================================================
+Serj Kalichev
+The klish is a fork of original clish.
+
+Copyright (c) 2010 Serj Kalichev.
+All Rights Reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+3. The name of the author may not be used to endorse or promote products derived
+   from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+

+ 33 - 0
Makefile.am

@@ -0,0 +1,33 @@
+## Process this file with automake to generate Makefile.in
+AUTOMAKE_OPTIONS = foreign nostdinc
+ACLOCAL_AMFLAGS = -I m4
+
+AM_CPPFLAGS = -I. -I$(top_srcdir) -I$(top_srcdir)/src
+AM_LD = $(CC)
+VERSION_INFO = -version-info $(SONAME_CURRENT):$(SONAME_REVISION):$(SONAME_AGE)
+
+if DEBUG
+DEBUG_CFLAGS = -DDEBUG
+endif
+
+if TESTC
+TESTC_CFLAGS = -DTESTC
+endif
+
+AM_CFLAGS = -Wall $(DEBUG_CFLAGS) $(TESTC_CFLAGS)
+AM_LDFLAGS = -z relro -z now -z defs
+
+bin_PROGRAMS =
+lib_LTLIBRARIES =
+lib_LIBRARIES =
+nobase_include_HEADERS =
+noinst_HEADERS =
+
+EXTRA_DIST =
+	bin/Makefile.am \
+	src/Makefile.am
+	LICENCE \
+	README.md
+
+include $(top_srcdir)/bin/Makefile.am
+include $(top_srcdir)/src/Makefile.am

+ 38 - 0
README.md

@@ -0,0 +1,38 @@
+# Klish Project
+
+## About
+
+The klish is a framework for implementing a CISCO-like CLI on a UNIX systems.
+
+NOTE: It's a development branch for fully rewritten klish version 3.
+It's not functional for now.
+For stable klish version 2 see the "2.2" branch.
+
+The main target for the klish is a Linux platform.
+
+
+## Build
+
+NOTE:
+You need branch "master" for development non-stable version.
+You need branch "2.2" for stable version.
+
+The development master branch needs libfaux (http://faux.libcode.org) to be built.
+The stable branch 2.2 doesn't need libfaux library.
+
+
+## Resources
+
+Homepage : http://klish.libcode.org
+
+Docs : See the sourcecode tree "doc/" dir for documenation
+
+Repository : https://src.libcode.org/pkun/klish
+
+Mailing list : http://groups.google.com/group/klish
+
+Dev mailing list : http://groups.google.com/group/klish-dev
+
+Download : https://src.libcode.org/download/klish/
+
+Author : Serj Kalichev `serj.kalichev(_at_)libcode.org`

+ 5 - 0
autogen.sh

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+set -x -e
+mkdir -p m4
+autoreconf -fvi

+ 11 - 0
bin/Makefile.am

@@ -0,0 +1,11 @@
+bin_PROGRAMS += \
+	bin/ytree
+
+bin_ytree_SOURCES = \
+	bin/ytree.c \
+	src/sr_copypaste.c \
+	src/pline.c
+
+#bin_klish_klish_LDADD = \
+#	libklish.la \
+#	libtinyrl.la

+ 0 - 0
ytree.c → bin/ytree.c


+ 521 - 0
configure.ac

@@ -0,0 +1,521 @@
+#                                               -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+m4_define([MAJOR_VERSION], 3)
+m4_define([MINOR_VERSION], 0)
+m4_define([MICRO_VERSION], 0)
+
+AC_PREREQ(2.59)
+AC_INIT([klish],
+        [MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION],
+        [serj.kalichev at gmail dot com])
+
+AC_CONFIG_AUX_DIR(aux_scripts)
+AC_CONFIG_MACRO_DIR([m4])
+
+# Values for SONAME. See -version-info for details.
+AC_SUBST(SONAME_CURRENT, 3)
+AC_SUBST(SONAME_REVISION, 0)
+AC_SUBST(SONAME_AGE, 0)
+
+# Check for system extensions (_POSIX_THREAD_SEMANTICS for Solaris)
+AC_USE_SYSTEM_EXTENSIONS
+
+# Checks for programs.
+AC_PROG_CC
+AC_LIBTOOL_WIN32_DLL
+AC_PROG_LIBTOOL
+
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE(subdir-objects)
+AM_PROG_CC_C_O
+
+# Dir for libc replacements
+AC_CONFIG_LIBOBJ_DIR([libc])
+
+# needed to handle 64-bit architecture
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(size_t)
+
+
+#########################################
+# See if linker supports version scripts
+#########################################
+# Check if LD supports linker scripts,
+# and define automake conditional HAVE_LD_VERSION_SCRIPT if so.
+AC_ARG_ENABLE([ld-version-script],
+              AS_HELP_STRING([--enable-ld-version-script],
+                             [enable linker version script (default is enabled when possible)]),
+                             [have_ld_version_script=$enableval], [])
+if test -z "$have_ld_version_script"; then
+    AC_MSG_CHECKING([if LD -Wl,--version-script works])
+    save_LDFLAGS="$LDFLAGS"
+    LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
+    cat > conftest.map <<EOF
+VERS_1 {
+    global: sym;
+};
+
+VERS_2 {
+    global: sym;
+} VERS_1;
+EOF
+    AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])],
+                   [have_ld_version_script=yes], [have_ld_version_script=no])
+    rm -f conftest.map
+    LDFLAGS="$save_LDFLAGS"
+    AC_MSG_RESULT($have_ld_version_script)
+fi
+AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
+
+
+################################
+# Deal with debugging options
+################################
+AC_ARG_ENABLE(debug,
+              [AS_HELP_STRING([--enable-debug],
+                              [Turn on debugging including asserts [default=no]])],
+              [],
+              [enable_debug=no])
+AM_CONDITIONAL(DEBUG,test x$enable_debug = xyes)
+
+
+################################
+# Compile in testc tests
+################################
+AC_ARG_ENABLE(testc,
+              [AS_HELP_STRING([--enable-testc],
+                              [Enable testc tests compiling [default=no]])],
+              [],
+              [enable_testc=no])
+AM_CONDITIONAL(TESTC,test x$enable_testc = xyes)
+
+
+################################
+# Search for network functions (like connect())
+################################
+AC_SEARCH_LIBS([socket], [socket])
+
+
+################################
+# Check for regex.h
+################################
+AC_CHECK_HEADERS(regex.h, [],
+    AC_MSG_ERROR([regex.h not found: regular expressions are not supported]))
+
+
+################################
+# Internal getopt()
+################################
+AC_ARG_WITH(internal-getopt,
+            [AS_HELP_STRING([--with-internal-getopt],
+            [Use internal implementation of getopt [default=no]])],
+            [],
+            [with_internal_getopt=no])
+
+if test x$with_internal_getopt != xno; then
+    AC_DEFINE([WITH_INTERNAL_GETOPT], [1], [Use internal getopt() implementation])
+    AC_LIBOBJ([getopt])
+    AC_MSG_WARN([Use internal implementation of getopt() and getopt_long()])
+else
+    AC_CHECK_HEADERS(getopt.h, [found_getopt_h=yes],
+        AC_MSG_WARN([getopt.h not found: only short parameters can be used on command line]))
+fi
+
+AC_MSG_CHECKING([for getopt_long()])
+if test x$with_internal_getopt = xyes -o x$found_getopt_h = xyes; then
+    AC_DEFINE([HAVE_GETOPT_LONG], [1], [getopt_long() function])
+    AC_MSG_RESULT([yes])
+else
+    AC_MSG_RESULT([no])
+fi
+
+
+################################
+# Check for locale.h
+################################
+AC_CHECK_HEADERS(locale.h, [],
+    AC_MSG_WARN([locale.h not found: the locales is not supported]))
+
+
+################################
+# Check for CODESET within nl_langinfo
+################################
+AC_DEFUN([AM_LANGINFO_CODESET],
+[
+  AC_CACHE_CHECK([for nl_langinfo and CODESET], [am_cv_langinfo_codeset],
+    [AC_TRY_LINK([#include <langinfo.h>],
+      [char* cs = nl_langinfo(CODESET); return !cs;],
+      [am_cv_langinfo_codeset=yes],
+      [am_cv_langinfo_codeset=no])
+    ])
+  if test $am_cv_langinfo_codeset = yes; then
+    AC_DEFINE([HAVE_LANGINFO_CODESET], [1],
+      [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
+  fi
+])
+AM_LANGINFO_CODESET
+
+
+################################
+# Check for pwd.h and grp.h
+################################
+AC_CHECK_HEADERS(pwd.h, [],
+    AC_MSG_WARN([pwd.h not found: the pwd operations is not supported]))
+AC_CHECK_HEADERS(grp.h, [],
+    AC_MSG_WARN([grp.h not found: the grp operations is not supported]))
+
+
+################################
+# Check for chroot
+################################
+AC_CHECK_FUNCS(chroot, [],
+    AC_MSG_WARN([chroot() not found: the choot is not supported]))
+
+
+################################
+# Check for dlopen
+################################
+CLISH_PLUGIN_BUILTIN_LIST=
+CLISH_PLUGIN_BUILTIN_DEFS=
+CLISH_PLUGIN_BUILTIN_LIBS=
+
+AC_DEFUN([AC_PLUGIN_BUILTIN],
+[
+  CLISH_PLUGIN_BUILTIN_LIBS="$CLISH_PLUGIN_BUILTIN_LIBS clish_plugin_$1.la"
+  CLISH_PLUGIN_BUILTIN_DEFS="$CLISH_PLUGIN_BUILTIN_DEFS CLISH_PLUGIN_INIT($1);"
+  CLISH_PLUGIN_BUILTIN_LIST="$CLISH_PLUGIN_BUILTIN_LIST { \"$1\", clish_plugin_$1_init },"
+])
+
+AC_CHECK_HEADERS(dlfcn.h, [
+        AC_SEARCH_LIBS([dlopen], [dl dld], [], [
+          AC_MSG_ERROR([unable to find the dlopen() function])
+        ])
+    ],[
+          AC_MSG_WARN([dlfcn.h not found: the dl operations is not supported])
+          AC_PLUGIN_BUILTIN([clish])
+          if test x$use_lua != xno; then
+            AC_PLUGIN_BUILTIN([lua])
+          fi
+    ])
+
+AC_SUBST([CLISH_PLUGIN_BUILTIN_LIST])
+AC_SUBST([CLISH_PLUGIN_BUILTIN_DEFS])
+AC_SUBST([CLISH_PLUGIN_BUILTIN_LIBS])
+#AC_CONFIG_FILES([clish/plugin_builtin.c])
+
+
+################################
+# Variables to install plugins
+################################
+DBS_SUBDIR=dbs
+AC_SUBST(DBS_SUBDIR)
+PLUGINS_SUBDIR=plugins
+AC_SUBST(PLUGINS_SUBDIR)
+
+
+################################
+# Check for mandatory faux library
+################################
+AC_ARG_WITH(faux,
+            [AS_HELP_STRING([--with-faux=DIR],
+                            [Search DIR directory for faux library files [default=yes]])],
+            [use_faux=$withval],
+            [use_faux=yes])
+
+AS_IF([test x$use_faux != xyes],
+  [
+    CPPFLAGS="-I${use_faux} ${CPPFLAGS}"
+    LDFLAGS="-L${use_faux}/.libs ${LDFLAGS}"
+  ]
+)
+
+AC_CHECK_HEADERS([faux/faux.h],
+	[],
+	[AC_MSG_ERROR([cannot find <faux/faux.h> header file])]
+	)
+AC_SEARCH_LIBS([faux_zmalloc], [faux],
+	[],
+	[AC_MSG_ERROR([cannot find working faux library])]
+	)
+
+
+################################
+# Check for the libxml2 library
+################################
+AC_ARG_WITH(libxml2,
+	[AS_HELP_STRING([--with-libxml2=DIR],
+		[Use libxml2 as the XML parser implementation [default=no]])],
+	[use_libxml2=$withval],
+	[use_libxml2=no])
+
+AM_CONDITIONAL(WITH_LIBXML2,test x$use_libxml2 != xno)
+
+case x$use_libxml2 in
+xno)
+	/bin/true
+	;;
+xyes)
+	# I would love to avoid using pkg-config (which may not be available on
+	# some compilation environment) but doing so really add a lot of
+	# complexity to the system, as the headers don't lie in a standard
+	# directory (they lie in a subdirectory of a standard include directory;
+	# not the same thing for configure scripts).
+	LIBXML2_CFLAGS="`pkg-config libxml-2.0 --cflags`"
+	LIBXML2_LDFLAGS="`pkg-config libxml-2.0 --libs-only-L`"
+	LIBXML2_LIBS="`pkg-config libxml-2.0 --libs-only-l`"
+	AC_CHECK_LIB([xml2],
+		[xmlNewDoc],
+		[],
+		[AC_MSG_ERROR([cannot find libxml2 headers])],
+		[])
+	# the header file is installed in a subdirectory of one of the standard
+	# include directory. This might prove to be a problem if the cross-
+	# compile environment is not complete enough (i.e. if it misses
+	# pkg-config, or if pkg-config returns wrong values). In most cases, the
+	# environment is likely to be OK so we will never hit any issue.
+	saved_CFLAGS="$CFLAGS"
+	CFLAGS="$CFLAGS $LIBXML2_CFLAGS"
+	AC_CHECK_HEADER([libxml/tree.h],
+		[],
+		[AC_MSG_ERROR([cannot find libxml2 headers])],
+		[/* */])
+	CFLAGS="$saved_CFLAGS"
+	AC_DEFINE([HAVE_LIB_LIBXML2],
+		[],
+		[libxml2-based XML backend])
+	;;
+*)
+	# this is probably broken. We consider that the user supplied path is
+	# a non-standard path. But we're not going to check anything.
+	AC_MSG_WARN([--with-libxml2=DIR is probably broken, just trying])
+	LIBXML2_LDFLAGS="-L${use_libxml2}/lib"
+	LIBXML2_CFLAGS="-I${use_libxml2}/include/libxml2"
+	LIBXML2_LIBS="-lxml2"
+	AC_MSG_CHECKING([for libxml2 support])
+	AC_MSG_RESULT([yes])
+	AC_MSG_NOTICE([headers for libxml2 hopefully in ${use_libxml2}/include/libxml2])
+	AC_MSG_NOTICE([library libxml2 hopefully in ${use_libxml2}/lib])
+	AC_DEFINE([HAVE_LIB_LIBXML2],
+		[],
+		[libxml2-based XML backend])
+	;;
+esac
+
+AC_SUBST(LIBXML2_LIBS)
+AC_SUBST(LIBXML2_LDFLAGS)
+AC_SUBST(LIBXML2_CFLAGS)
+
+
+################################
+# Check for the roxml library
+################################
+AC_ARG_WITH(roxml,
+	[AS_HELP_STRING([--with-roxml=DIR],
+		[Use roxml as the XML parser implementation [default=no]])],
+	[use_roxml=$withval],
+	[use_roxml=no])
+
+AM_CONDITIONAL(WITH_ROXML,test x$use_roxml != xno)
+
+case x$use_roxml in
+xno)
+	/bin/true
+	;;
+xyes)
+	# we choose to NOT rely on pkg-config on this one. We may do it as
+	# roxml provides a .pc file but some environment (both cross-compile
+	# or native environment) may lack this support. The good thing is that
+	# it doesn't add much complexity to the configure.ac file (and we
+	# may move these tests to another m4 file later).
+	# The header is installed in the standard path
+	AC_CHECK_HEADER([roxml.h],
+		[],
+		[AC_MSG_ERROR([cannot find <roxml.h> header file])],
+		[/* */])
+	# The library is installed in the standard path
+	AC_CHECK_LIB([roxml],
+		[roxml_load_doc],
+		[],
+		[AC_MSG_ERROR([cannot find roxml library])],
+		[])
+	ROXML_CFLAGS=""
+	ROXML_LDFLAGS=""
+	ROXML_LIBS="-lroxml"
+	AC_DEFINE([HAVE_LIB_ROXML],
+		[],
+		[roxml-based XML backend])
+	;;
+*)
+	# first, we check if we're not looking for an alternate include
+	# directory -for example, if the user feeds the script with the
+	# option --with-roxml=/usr/local
+	# NOTE: we search for include/roxml.h and inc/roxml.h to defeat
+	# the caching algorithm of the configure script. If someone knows
+	# a better way, please do not hesitate
+	saved_CFLAGS="$CFLAGS"
+	CFLAGS="$CFLAGS -I${use_roxml}"
+	AC_CHECK_HEADER([include/roxml.h],
+		[roxml_h_found=yes],
+		[roxml_h_found=no],
+		[/* */])
+	if test "x$roxml_h_found" = "xno"; then
+		# the directory might be a source directory, so check
+		# if the include file is to be found here
+		AC_CHECK_HEADER([inc/roxml.h],
+			[roxml_h_found=yes],
+			[roxml_h_found=no],
+			[/* */])
+		if test "x$roxml_h_found" = "xno"; then
+			AC_MSG_ERROR([cannot find <roxml.h> header file])
+		fi
+		ROXML_CFLAGS="-I${use_roxml}/inc"
+		AC_MSG_NOTICE([header file <roxml.h> found in ${use_roxml}/inc])
+	else
+		ROXML_CFLAGS="-I${use_roxml}/include"
+		AC_MSG_NOTICE([header file <roxml.h> found in ${use_roxml}/include])
+	fi
+	CFLAGS="$saved_CFLAGS"
+	# we're doing both previous checks, but we are trying to find a library
+	# now, so the check themselves are a bit different
+	# NOTE: we search for roxml_load_doc and roxml_close to defeat
+	# the caching algorithm of the configure script. If someone knows
+	# a better way, please do not hesitate.
+	saved_LDFLAGS="$LDFLAGS"
+	LDFLAGS="$LDFLAGS -L${use_roxml}/lib"
+	AC_CHECK_LIB([roxml],
+		[roxml_load_doc],
+		[roxml_lib_found=yes],
+		[roxml_lib_found=no],
+		[])
+	LDFLAGS="$saved_LDFLAGS"
+	if test "x$roxml_lib_found" = "xno"; then
+		LDFLAGS="$LDFLAGS -L${use_roxml}"
+		AC_CHECK_LIB([roxml],
+			[roxml_close],
+			[],
+			[AC_MSG_ERROR([cannot find roxml library])],
+			[])
+		LDFLAGS=$saved_LDFLAGS
+		ROXML_LDFLAGS="-L${use_roxml}"
+		ROXML_LIBS="-lroxml"
+		AC_MSG_NOTICE([library roxml found in ${use_roxml}])
+	else
+		ROXML_LDFLAGS="-L${use_roxml}/lib"
+		ROXML_LIBS="-lroxml"
+		AC_MSG_NOTICE([library roxml found in ${use_roxml}/lib])
+	fi
+	AC_DEFINE([HAVE_LIB_ROXML],
+		[],
+		[roxml-based XML backend])
+	;;
+esac
+
+AC_SUBST(ROXML_LIBS)
+AC_SUBST(ROXML_LDFLAGS)
+AC_SUBST(ROXML_CFLAGS)
+
+
+################################
+# Check for the expat library
+################################
+AC_ARG_WITH(expat,
+            [AS_HELP_STRING([--with-expat=DIR],
+                            [Use expat as the XML parser implementation [default=no]])],
+            [use_expat=$withval],
+            [use_expat=no])
+
+AM_CONDITIONAL(WITH_EXPAT,test x$use_expat != xno)
+
+case x$use_expat in
+xno)
+	/bin/true
+	;;
+xyes)
+	# we choose to NOT rely on pkg-config on this one. Instead, we
+	# check for the library and the header file - that should be
+	# enough.
+	AC_CHECK_HEADER([expat.h],
+		[expat_h_found=yes],
+		[expat_h_found=no],
+		[/* */])
+	if test "x$expat_h_found" != "xyes"; then
+		AC_CHECK_HEADER([bsdxml.h],
+			[expat_h_found=yes],
+			[expat_h_found=no],
+			[/* */])
+		if test "x$expat_h_found" != "xyes"; then
+			AC_MSG_ERROR([cannot find <expat.h> header file])
+		fi
+	fi
+	EXPAT_CFLAGS=""
+	AC_CHECK_LIB([expat],
+		[XML_ParserCreate],
+		[expat_lib_found=yes],
+		[expat_lib_found=no],
+		[])
+	if test "x$expat_lib_found" != "xyes"; then
+		AC_CHECK_LIB([bsdxml],
+			[XML_ParserCreate],
+			[],
+			[AC_MSG_ERROR([cannot find expat library])],
+			[])
+		EXPAT_LIBS="-lbsdxml"
+		AC_DEFINE([HAVE_LIB_BSDXML],
+			[],
+			[libbsdxml-based XML backend])
+	else
+		EXPAT_LIBS="-lexpat"
+	fi
+	EXPAT_LDFLAGS=""
+	AC_DEFINE([HAVE_LIB_EXPAT],
+		[],
+		[expat-based XML backend])
+	;;
+*)
+	# this is probably broken. We consider that the user supplied path is
+	# a non-standard path. But we're not going to check anything.
+	AC_MSG_WARN([--with-expat=DIR is probably broken, just trying])
+	EXPAT_LDFLAGS="-L${use_expat}/lib"
+	EXPAT_CFLAGS="-I${use_expat}/include"
+	EXPAT_LIBS="-lexpat"
+	AC_MSG_CHECKING([for expat support])
+	AC_MSG_RESULT([yes])
+	AC_MSG_NOTICE([headers for expat hopefully in ${use_expat}/include])
+	AC_MSG_NOTICE([library expat hopefully in ${use_expat}/lib])
+	AC_DEFINE([HAVE_LIB_EXPAT],
+		[],
+		[expat-based XML backend])
+	;;
+esac
+
+AC_SUBST(EXPAT_LIBS)
+AC_SUBST(EXPAT_LDFLAGS)
+AC_SUBST(EXPAT_CFLAGS)
+
+
+################################
+# Check for Lua support
+################################
+AC_ARG_WITH(lua,
+	[AS_HELP_STRING([--with-lua=DIR],
+		[Build Lua ACTION plugin [default=no]])],
+	[use_lua=$withval],
+	[use_lua=no])
+AM_CONDITIONAL(WITH_LUA,test x$use_lua != xno)
+
+if test x$use_lua != xno; then
+	if test x$use_lua != xyes; then
+		CPPFLAGS="${CPPFLAGS} -I$use_lua/include"
+		LDFLAGS="${LDFLAGS} -L$use_lua/lib"
+	fi
+	if test x$LUA_VERSION = x; then
+		AX_PROG_LUA([5.1])
+	fi
+	AX_LUA_HEADERS()
+	AX_LUA_LIBS()
+fi
+
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT

+ 14 - 0
src/Makefile.am

@@ -0,0 +1,14 @@
+plugin_LTLIBRARIES += kplugin-sysrepo.la
+kplugin_sysrepo_la_SOURCES =
+kplugin_sysrepo_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version -module
+kplugin_sysrepo_la_LIBS =
+kplugin_sysrepo_la_CFLAGS = $(AM_LDFLAGS)
+#kplugin_sysrepo_la_LIBADD = libsysrepo.la
+
+kplugin_sysrepo_la_SOURCES += \
+	src/private.h \
+	src/plugin.c \
+	src/sr_copypaste.h \
+	src/sr_copypaste.c \
+	src/pline.h \
+	src/pline.c

+ 0 - 0
pline.c → src/pline.c


+ 0 - 0
pline.h → src/pline.h


+ 68 - 0
src/plugin.c

@@ -0,0 +1,68 @@
+/*
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <assert.h>
+
+#include <faux/faux.h>
+#include <klish/kplugin.h>
+#include <klish/kcontext.h>
+
+#include "private.h"
+
+
+const uint8_t kplugin_sysrepo_major = KPLUGIN_MAJOR;
+const uint8_t kplugin_sysrepo_minor = KPLUGIN_MINOR;
+
+
+int kplugin_sysrepo_init(kcontext_t *context)
+{
+	kplugin_t *plugin = NULL;
+	ksym_t *sym = NULL;
+
+	assert(context);
+	plugin = kcontext_plugin(context);
+	assert(plugin);
+
+/*
+	// Misc
+	kplugin_add_syms(plugin, ksym_new_ext("nop", klish_nop,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+	kplugin_add_syms(plugin, ksym_new("tsym", klish_tsym));
+	kplugin_add_syms(plugin, ksym_new("print", klish_print));
+	kplugin_add_syms(plugin, ksym_new_ext("pwd", klish_pwd,
+		KSYM_PERMANENT, KSYM_SYNC));
+
+	// Navigation
+	// Navigation must be permanent (no dry-run) and sync. Because unsync
+	// actions will be fork()-ed so it can't change current path.
+	kplugin_add_syms(plugin, ksym_new_ext("nav", klish_nav,
+		KSYM_PERMANENT, KSYM_SYNC));
+
+	// PTYPEs
+	// These PTYPEs are simple and fast so set SYNC flag
+	kplugin_add_syms(plugin, ksym_new_ext("COMMAND", klish_ptype_COMMAND,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+	kplugin_add_syms(plugin, ksym_new_ext("completion_COMMAND", klish_completion_COMMAND,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+	kplugin_add_syms(plugin, ksym_new_ext("COMMAND_CASE", klish_ptype_COMMAND_CASE,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+	kplugin_add_syms(plugin, ksym_new_ext("INT", klish_ptype_INT,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+	kplugin_add_syms(plugin, ksym_new_ext("UINT", klish_ptype_UINT,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+	kplugin_add_syms(plugin, ksym_new_ext("STRING", klish_ptype_STRING,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+*/
+	return 0;
+}
+
+
+int kplugin_sysrepo_fini(kcontext_t *context)
+{
+	context = context; // Happy compiler
+
+	return 0;
+}

+ 36 - 0
src/private.h

@@ -0,0 +1,36 @@
+/*
+ * private.h
+ */
+
+#ifndef _private_h
+#define _private_h
+
+#include <faux/faux.h>
+#include <klish/kcontext_base.h>
+
+
+C_DECL_BEGIN
+
+/*
+// Misc
+int klish_nop(kcontext_t *context);
+int klish_tsym(kcontext_t *context);
+int klish_print(kcontext_t *context);
+int klish_pwd(kcontext_t *context);
+
+// Navigation
+int klish_nav(kcontext_t *context);
+
+// PTYPEs
+int klish_ptype_COMMAND(kcontext_t *context);
+int klish_completion_COMMAND(kcontext_t *context);
+int klish_ptype_COMMAND_CASE(kcontext_t *context);
+int klish_ptype_INT(kcontext_t *context);
+int klish_ptype_UINT(kcontext_t *context);
+int klish_ptype_STRING(kcontext_t *context);
+*/
+
+C_DECL_END
+
+
+#endif // _private_h

+ 62 - 0
src/sr_copypaste.c

@@ -0,0 +1,62 @@
+#include <sysrepo.h>
+#include <sysrepo/xpath.h>
+
+
+static int
+sr_ly_module_is_internal(const struct lys_module *ly_mod)
+{
+    if (!ly_mod->revision) {
+        return 0;
+    }
+
+    if (!strcmp(ly_mod->name, "ietf-yang-metadata") && !strcmp(ly_mod->revision, "2016-08-05")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "yang") && !strcmp(ly_mod->revision, "2021-04-07")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-inet-types") && !strcmp(ly_mod->revision, "2013-07-15")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-yang-types") && !strcmp(ly_mod->revision, "2013-07-15")) {
+        return 1;
+    }
+
+    return 0;
+}
+
+
+int
+sr_module_is_internal(const struct lys_module *ly_mod)
+{
+    if (!ly_mod->revision) {
+        return 0;
+    }
+
+    if (sr_ly_module_is_internal(ly_mod)) {
+        return 1;
+    }
+
+    if (!strcmp(ly_mod->name, "ietf-datastores") && !strcmp(ly_mod->revision, "2018-02-14")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-yang-schema-mount")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-yang-library")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-netconf")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-netconf-with-defaults") && !strcmp(ly_mod->revision, "2011-06-01")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-origin") && !strcmp(ly_mod->revision, "2018-02-14")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-netconf-notifications") && !strcmp(ly_mod->revision, "2012-02-06")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "sysrepo")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "sysrepo-monitoring")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "sysrepo-plugind")) {
+        return 1;
+    } else if (!strcmp(ly_mod->name, "ietf-netconf-acm")) {
+        return 1;
+    }
+
+    return 0;
+}

+ 16 - 0
src/sr_copypaste.h

@@ -0,0 +1,16 @@
+#ifndef _sr_copypaste_h
+#define _sr_copypaste_h
+
+
+#include <sysrepo.h>
+#include <sysrepo/xpath.h>
+
+
+static int
+sr_ly_module_is_internal(const struct lys_module *ly_mod);
+
+int
+sr_module_is_internal(const struct lys_module *ly_mod);
+
+
+#endif // _sr_copypaste_h