Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Initial git commit for GXLib, a library with extensions for GLib
  • Loading branch information
djcb committed Sep 11, 2015
0 parents commit d47aa2b
Show file tree
Hide file tree
Showing 53 changed files with 6,253 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dirk-Jan C. Binnema <[email protected]>
482 changes: 482 additions & 0 deletions COPYING

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please use `git log' to get the latest ChangeLog, or NEWS for user-visible changes.
370 changes: 370 additions & 0 deletions INSTALL

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Copyright (C) 2015 Dirk-Jan C. Binnema <[email protected]>
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public License
## as published by the Free Software Foundation; either version 2.1
## of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free
## Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.

include $(top_srcdir)/gtest.mk

check: test

ACLOCAL_AMFLAGS=-I m4
SUBDIRS=gxlib gxio m4 docs

# borrowed from Json-Glib
if ENABLE_GCOV
# use recursive makes in order to ignore errors during check/perf
lcov:
-$(MAKE) $(AM_MAKEFLAGS) check
$(MAKE) $(AM_MAKEFLAGS) genlcov

# we have to massage the lcov.info file slightly to hide the effect of libtool
# placing the objects files in the .libs/ directory separate from the *.c
genlcov:
$(LTP) --directory $(top_builddir) --capture --output-file gxlib-lcov.info --test-name GXLIB_TEST --no-checksum
$(SED) -e 's#.libs/##' < gxlib-lcov.info > gxlib-lcov.info.tmp
LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory gxlib-lcov --title "GXLib Code Coverage" --show-details gxlib-lcov.info.tmp
$(RM) -f gxlib-lcov.info.tmp

lcov-clean:
-$(LTP) --directory $(top_builddir) -z
-$(RM) -rf gxlib-lcov.info gxlib-lcov
else
lcov genlcov lcov-clean:
@echo You need to configure GXLib with support for gcov enabled.
@echo e.g., ./configure --enable-gcov
endif
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GXLib -- history of user-visible changes

* Initial import <2015-09-05 Sat>

- First public version of GXLib

# Local Variables:
# mode: org; org-startup-folded: nil
# End:
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# GXLib

[GLib](https://developer.gnome.org/glib/) is a library that provides
(among others) many of the basic data structures such as lists and
hash-tables one needs when programming in C.

GXLib is a library that provides extensions to GLib as I'm using for
my own programs. Since it depends on GLib 2.x, GXLib's versioning also
starts with 2.x.

So far, there are a number of extensions fo `GList` that allows for
using it with a functional flavor, and takes inspiration from
[Mozilla's Rust](https://www.rust-lang.org) and
[Scheme's SRFI-1](http://srfi.schemers.org/srfi-1/srfi-1.html) and the
way they allow for solving problems such as those from
[Project Euler](https://projecteuler.net).

# Examples

Here are some examples. If you're not familiar with ``map`` and
``fold`` etc., it might look a little bit bewildering at first,
esp. since you can probably think of a way to do it with an explicit
loop.

However, after a while, many common problems can be easily expressed
as number of those operations.

##

Let's take an array of strings, uppercase them, and then combine them
in a single string, separated by colons.

## Product of primes

Let's take the product of the prime numbers up to 20. We could make a
one-liner, but let's do it step by step.

First, create a list of numbers 1..20, using ``gx_list_iota``:
``` c
gint prod;
GList *nums;
nums = gx_list_iota (20 /*number*/, 1/*start*/, 1/*step*/);
```

Now, we filter out any non-prime numbers. And we do it in-place (ie.,
changing the list we have, rather than making copy).

``` c
nums = gx_list_filter_in_place (nums, (GXPred)gx_is_prime, NULL, NULL);
```

finally, we take the product:

``` c
prod = gx_list_product (nums); /* 9699690 */
g_list_free (nums);
```
# Contributing
`GXLib` is a young library, so there is ample opportunity for adding
more functionality.... contributations are welcome! Here are some
guidelines:
- Follow the existing coding style; like `GLib` itself, `GXLib` uses
the GNU-coding style. It looks a bit unusual in the beginning, but
one gets used to it quickly. In Emacs: `C-c . gnu RET`.
- We strive to keep the code-coverage for the tests at 100%. So for
each function, there needs to be one or more unit tests (in the
`tests/` directory).
- When documenting things, follow the `gtk-doc` style already in
use. If you add example code to the documentation, add the code
snippet to `test-examples.c` as well, so they can be unit-tested,
too. Always nice if the example code keeps working!
45 changes: 45 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
# Run this to generate all the initial makefiles, etc.

test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.

olddir=`pwd`

cd $srcdir
PROJECT=gxlib
TEST_TYPE=-f
FILE=gxlib/gxlib.h

test $TEST_TYPE $FILE || {
echo "You must run this script in the top-level $PROJECT directory"
exit 1
}

GTKDOCIZE=`which gtkdocize`
if test -z $GTKDOCIZE; then
echo "*** No GTK-Doc found, please install it ***"
exit 1
fi

AUTORECONF=`which autoreconf`
if test -z $AUTORECONF; then
echo "*** No autoreconf found, please install it ***"
exit 1
fi

# NOCONFIGURE is used by gnome-common
if test -z "$NOCONFIGURE"; then
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
fi

rm -rf autom4te.cache

gtkdocize || exit $?
autoreconf --force --install --verbose || exit $?

cd "$olddir"
test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"
143 changes: 143 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
## Copyright (C) 2015 Dirk-Jan C. Binnema <[email protected]>
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public License
## as published by the Free Software Foundation; either version 2.1
## of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free
## Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.

AC_PREREQ([2.62])
AC_INIT([gxlib],[2.0.0],
[https://github.com/djcb/gxlib/issues],[gxlib])
AC_COPYRIGHT([Copyright (C) 2015 Dirk-Jan C. Binnema])

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([gxlib/gxlib.h])
AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE([1.11 -Wno-portability no-define no-dist-gzip
dist-xz tar-ustar])
AM_MAINTAINER_MODE([enable])

LT_PREREQ([2.2])
LT_INIT([disable-static])

# Support silent build rules. Disable by passing
# --disable-silent-rules to configure or passing V=1 to make
AM_SILENT_RULES([yes])

AC_PROG_CC
AC_PROG_CPP
AC_PROG_SED
AC_CANONICAL_HOST

AX_COMPILER_FLAGS([WARN_CFLAGS],[WARN_LDFLAGS])
LT_LIB_M

AC_PATH_PROG([PKG_CONFIG],[pkg-config],[no])
AS_IF([test "x$PKG_CONFIG" = "xno"],[
AC_MSG_ERROR([
*** The pkg-config script could not be found. Make sure it is
*** in your path, or set the PKG_CONFIG environment variable
*** to the full path to pkg-config.])
])

PKG_CHECK_MODULES(GLIB,glib-2.0 >= 2.38)
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)

PKG_CHECK_MODULES(GOBJECT,gobject-2.0 >= 2.38)
AC_SUBST(GOBJECT_CFLAGS)
AC_SUBST(GOBJECT_LIBS)

PKG_CHECK_MODULES(GIO,gio-2.0 >= 2.38)
AC_SUBST(GIO_CFLAGS)
AC_SUBST(GIO_LIBS)

# we need some special tricks for filesystems that don't have d_type;
# e.g. Solaris. See mu-maildir.c. Explicitly disabling it is for
# testing purposes only
AC_ARG_ENABLE([dirent-d-type],
AC_HELP_STRING([--disable-dirent-d-type],
[Don't use dirent->d_type]),
[], [AC_STRUCT_DIRENT_D_TYPE]
)
AS_IF([test "x$ac_cv_member_struct_dirent_d_type" != "xyes"],
[use_dirent_d_type="no"], [use_dirent_d_type="yes"])

# support for d_ino (inode) in struct dirent is optional; if it's
# available we can sort direntries by inode and access them in that
# order; this is much faster on some file systems (such as extfs3).
# Explicity disabling it is for testing purposes only.
AC_ARG_ENABLE([dirent-d-ino],
AC_HELP_STRING([--disable-dirent-d-ino],
[Don't use dirent->d_ino]),
[], [AC_STRUCT_DIRENT_D_INO]
)
AS_IF([test "x$ac_cv_member_struct_dirent_d_ino" != "xyes"],
[use_dirent_d_ino="no"], [use_dirent_d_ino="yes"])


# check for gtk-doc (optional)
m4_ifdef([GTK_DOC_CHECK], [
GTK_DOC_CHECK([1.14],[--flavour no-tmpl])
],[
AM_CONDITIONAL([ENABLE_GTK_DOC], false)
])

AX_VALGRIND_CHECK

####################################################################
dnl code coverage
AC_ARG_ENABLE([gcov],
[AS_HELP_STRING([--enable-gcov], [Enable gcov])],
[use_gcov=$enableval],
[use_gcov=no])
AS_IF([test "x$use_gcov" = "xyes"],[
AC_CHECK_PROG(LTP, lcov, lcov)
AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml)
AC_DEFINE(HAVE_GCOV,1,[Whether you have gcov])
dnl Remove all optimization flags from CFLAGS
changequote({,})
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
changequote([,])
dnl Define the special gcc flags
GCOV_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
GCOV_LDADD="-lgcov"
AC_SUBST(GCOV_CFLAGS)
AC_SUBST(GCOV_LDADD)
])
AM_CONDITIONAL(ENABLE_GCOV, test "x$use_gcov" = "xyes")
####################################################################

AC_CONFIG_FILES([
Makefile
gxlib/Makefile
gxlib/gxlib-2.0.pc
gxlib/tests/Makefile
gxio/gxio-2.0.pc
gxio/Makefile
gxio/tests/Makefile
docs/Makefile
docs/reference/Makefile
docs/reference/gxlib/Makefile
docs/reference/gxio/Makefile
m4/Makefile
])
AC_OUTPUT


19 changes: 19 additions & 0 deletions docs/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Copyright (C) 2015 Dirk-Jan C. Binnema <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software Foundation,
## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

include $(top_srcdir)/gtest.mk

SUBDIRS=reference
19 changes: 19 additions & 0 deletions docs/reference/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Copyright (C) 2015 Dirk-Jan C. Binnema <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software Foundation,
## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

include $(top_srcdir)/gtest.mk

SUBDIRS=gxlib gxio
Loading

0 comments on commit d47aa2b

Please sign in to comment.