Skip to content

Commit

Permalink
Add support for writer in C (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 25, 2024
1 parent f370270 commit 15db495
Show file tree
Hide file tree
Showing 30 changed files with 1,801 additions and 442 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ jobs:
include:
- description: "default"
- compiler: gcc
configure: "--disable-c-pkgconfig --disable-c-pages --disable-c-fsindex --disable-c-readerchannel --disable-c-writerchannel --disable-c-vfs"
description: "no pkgcfg, pages, fsindex, readedchannel, writerchannel, vfs"
configure: "--disable-c-pkgconfig --disable-c-pages --disable-c-fsindex --disable-c-readerchannel --disable-c-writer --disable-c-writerchannel --disable-c-vfs"
description: "no pkgcfg, pages, fsindex, readedchannel, writer, writerchannel, vfs"
- compiler: gcc
configure: "--disable-c-pages --disable-c-fsindex --disable-c-readerchannel --disable-c-writerchannel --disable-c-vfs"
description: "no pages, fsindex, readedchannel, writerchannel, vfs"
configure: "--disable-c-pages --disable-c-fsindex --disable-c-readerchannel --disable-c-writer --disable-c-writerchannel --disable-c-vfs"
description: "no pages, fsindex, readedchannel, writer, writerchannel, vfs"
- compiler: gcc
configure: "--disable-c-fsindex --disable-c-readerchannel --disable-c-writerchannel --disable-c-vfs"
description: "no fsindex, readedchannel, writerchannel, vfs"
configure: "--disable-c-fsindex --disable-c-readerchannel --disable-c-writer --disable-c-writerchannel --disable-c-vfs"
description: "no fsindex, readedchannel, writer, writerchannel, vfs"
- compiler: gcc
configure: "--disable-c-readerchannel --disable-c-writerchannel --disable-c-vfs"
description: "no readedchannel, writerchannel, vfs"
configure: "--disable-c-readerchannel --disable-c-writer --disable-c-writerchannel --disable-c-vfs"
description: "no readedchannel, writer, writerchannel, vfs"
- compiler: gcc
configure: "--disable-c-writerchannel --disable-c-vfs"
description: "no writerchannel, vfs"
- compiler: gcc
configure: "--disable-c-vfs"
description: "no vfs"
configure: " --disable-c-writer --disable-c-writerchannel --disable-c-vfs"
description: "no writer, writerchannel, vfs"
name: build (${{ matrix.compiler }}, ${{ matrix.description }})
steps:
- name: Checkout
Expand Down
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2024-05-25 Konstantin Kushnir <[email protected]>
* Add support for writer in C

2024-05-21 Konstantin Kushnir <[email protected]>
* Add support for vfs in C
* Make the writer object available for C functions
Expand Down
77 changes: 68 additions & 9 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ MAKE_LIB
EGREP
GREP
COOKFS_PKGCONFIG_USECPKGCONFIG
COOKFS_PKGCONFIG_USECWRITER
COOKFS_PKGCONFIG_USECVFS
COOKFS_PKGCONFIG_FEATURE_METADATA
COOKFS_PKGCONFIG_USECFSINDEX
Expand Down Expand Up @@ -793,6 +794,7 @@ enable_c_readerchannel
enable_c_writerchannel
enable_c_pkgconfig
enable_c_vfs
enable_c_writer
'
ac_precious_vars='build_alias
host_alias
Expand Down Expand Up @@ -1439,6 +1441,7 @@ Optional Features:
--disable-c-writerchannel Use writer handler written in C. Defaults to true
--disable-c-pkgconfig Use pkgconfig written in C. Defaults to true
--disable-c-vfs Use VFS support written in C. Defaults to true
--disable-c-writer Use writer handler written in C. Defaults to true
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
Expand Down Expand Up @@ -8650,6 +8653,14 @@ else $as_nop
USECVFS=yes
fi

# Check whether --enable-c-writer was given.
if test ${enable_c_writer+y}
then :
enableval=$enable_c_writer; USECWRITER=${enableval}
else $as_nop
USECWRITER=yes
fi


if test ${INTERNALDEBUG} = yes; then
printf "%s\n" "#define COOKFS_INTERNAL_DEBUG 1" >>confdefs.h
Expand Down Expand Up @@ -8935,6 +8946,8 @@ else
USECREADERCHAN="no"
# c-writerchannel requires c-pages
USECWRITERCHAN="no"
# c-writer requires c-pages
USECWRITER="no"
fi

if test ${USECFSINDEX} = yes; then
Expand Down Expand Up @@ -8984,6 +8997,8 @@ else
USECREADERCHAN="no"
# c-writerchannel requires c-fsindex
USECWRITERCHAN="no"
# c-writer requires c-pages
USECWRITER="no"
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1
Expand Down Expand Up @@ -9033,7 +9048,51 @@ else
USECVFS="no"
fi

if test ${USECWRITERCHAN} = yes; then
# c-writer / c-writerchan / c-vfs must be enabled together
if test ${USECWRITER} = yes \
&& test ${USECWRITERCHAN} = yes \
&& test ${USECVFS} = yes
then

printf "%s\n" "#define COOKFS_USECWRITER 1" >>confdefs.h

COOKFS_PKGCONFIG_USECWRITER=1

vars="writer.c writerCmd.c"
for i in $vars; do
case $i in
\$*)
# allow $-var names
PKG_SOURCES="$PKG_SOURCES $i"
PKG_OBJECTS="$PKG_OBJECTS $i"
;;
*)
# check for existence - allows for generic/win/unix VPATH
# To add more dirs here (like 'src'), you have to update VPATH
# in Makefile.in as well
if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
-a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
-a ! -f "${srcdir}/macosx/$i" \
; then
as_fn_error $? "could not find source file '$i'" "$LINENO" 5
fi
PKG_SOURCES="$PKG_SOURCES $i"
# this assumes it is in a VPATH dir
i=`basename $i`
# handle user calling this before or after TEA_SETUP_COMPILER
if test x"${OBJEXT}" != x ; then
j="`echo $i | sed -e 's/\.[^.]*$//'`.${OBJEXT}"
else
j="`echo $i | sed -e 's/\.[^.]*$//'`.\${OBJEXT}"
fi
PKG_OBJECTS="$PKG_OBJECTS $j"
;;
esac
done




printf "%s\n" "#define COOKFS_USECWRITERCHAN 1" >>confdefs.h

COOKFS_PKGCONFIG_USECWRITERCHAN=1
Expand Down Expand Up @@ -9072,18 +9131,12 @@ if test ${USECWRITERCHAN} = yes; then



else
COOKFS_PKGCONFIG_USECWRITERCHAN=0
# c-vfs requires c-writerchannel
USECVFS="no"
fi

if test ${USECVFS} = yes; then
printf "%s\n" "#define COOKFS_USECVFS 1" >>confdefs.h

COOKFS_PKGCONFIG_USECVFS=1

vars="writer.c vfsDriver.c vfsVfs.c vfs.c vfsCmd.c"
vars="vfsDriver.c vfsVfs.c vfs.c vfsCmd.c"
for i in $vars; do
case $i in
\$*)
Expand Down Expand Up @@ -9117,7 +9170,10 @@ if test ${USECVFS} = yes; then




else
COOKFS_PKGCONFIG_USECWRITER=0
COOKFS_PKGCONFIG_USECWRITERCHAN=0
COOKFS_PKGCONFIG_USECVFS=0
fi

Expand All @@ -9131,6 +9187,7 @@ fi




if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
printf "%s\n" "#define COOKFS_PKGCONFIG_FEATURE_ASIDE $COOKFS_PKGCONFIG_FEATURE_ASIDE" >>confdefs.h
Expand All @@ -9153,8 +9210,10 @@ if test ${USECPKGCONFIG} = yes; then

printf "%s\n" "#define COOKFS_PKGCONFIG_USECVFS $COOKFS_PKGCONFIG_USECVFS" >>confdefs.h

printf "%s\n" "#define COOKFS_PKGCONFIG_USECWRITER $COOKFS_PKGCONFIG_USECWRITER" >>confdefs.h


printf "%s\n" "#define COOKFS_USEPKGCONFIG 1" >>confdefs.h
printf "%s\n" "#define COOKFS_USECPKGCONFIG 1" >>confdefs.h

else
COOKFS_PKGCONFIG_USECPKGCONFIG=0
Expand Down
31 changes: 22 additions & 9 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ AC_ARG_ENABLE(c-readerchannel, [ --disable-c-readerchannel Use reader handler w
AC_ARG_ENABLE(c-writerchannel, [ --disable-c-writerchannel Use writer handler written in C. Defaults to true], USECWRITERCHAN=${enableval}, USECWRITERCHAN=yes)
AC_ARG_ENABLE(c-pkgconfig, [ --disable-c-pkgconfig Use pkgconfig written in C. Defaults to true], USECPKGCONFIG=${enableval}, USECPKGCONFIG=yes)
AC_ARG_ENABLE(c-vfs, [ --disable-c-vfs Use VFS support written in C. Defaults to true], USECVFS=${enableval}, USECVFS=yes)
AC_ARG_ENABLE(c-writer, [ --disable-c-writer Use writer handler written in C. Defaults to true], USECWRITER=${enableval}, USECWRITER=yes)

if test ${INTERNALDEBUG} = yes; then
AC_DEFINE(COOKFS_INTERNAL_DEBUG)
Expand Down Expand Up @@ -190,6 +191,8 @@ else
USECREADERCHAN="no"
# c-writerchannel requires c-pages
USECWRITERCHAN="no"
# c-writer requires c-pages
USECWRITER="no"
fi

if test ${USECFSINDEX} = yes; then
Expand All @@ -204,6 +207,8 @@ else
USECREADERCHAN="no"
# c-writerchannel requires c-fsindex
USECWRITERCHAN="no"
# c-writer requires c-pages
USECWRITER="no"
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1
Expand All @@ -218,21 +223,27 @@ else
USECVFS="no"
fi

if test ${USECWRITERCHAN} = yes; then
# c-writer / c-writerchan / c-vfs must be enabled together
if test ${USECWRITER} = yes \
&& test ${USECWRITERCHAN} = yes \
&& test ${USECVFS} = yes
then

AC_DEFINE(COOKFS_USECWRITER)
COOKFS_PKGCONFIG_USECWRITER=1
TEA_ADD_SOURCES([writer.c writerCmd.c])

AC_DEFINE(COOKFS_USECWRITERCHAN)
COOKFS_PKGCONFIG_USECWRITERCHAN=1
TEA_ADD_SOURCES([writerchannel.c writerchannelIO.c])
else
COOKFS_PKGCONFIG_USECWRITERCHAN=0
# c-vfs requires c-writerchannel
USECVFS="no"
fi

if test ${USECVFS} = yes; then
AC_DEFINE(COOKFS_USECVFS)
COOKFS_PKGCONFIG_USECVFS=1
TEA_ADD_SOURCES([writer.c vfsDriver.c vfsVfs.c vfs.c vfsCmd.c])
TEA_ADD_SOURCES([vfsDriver.c vfsVfs.c vfs.c vfsCmd.c])

else
COOKFS_PKGCONFIG_USECWRITER=0
COOKFS_PKGCONFIG_USECWRITERCHAN=0
COOKFS_PKGCONFIG_USECVFS=0
fi

Expand All @@ -245,6 +256,7 @@ AC_SUBST(COOKFS_PKGCONFIG_USEXZ)
AC_SUBST(COOKFS_PKGCONFIG_USECFSINDEX)
AC_SUBST(COOKFS_PKGCONFIG_FEATURE_METADATA)
AC_SUBST(COOKFS_PKGCONFIG_USECVFS)
AC_SUBST(COOKFS_PKGCONFIG_USECWRITER)

if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
Expand All @@ -258,8 +270,9 @@ if test ${USECPKGCONFIG} = yes; then
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECFSINDEX, $COOKFS_PKGCONFIG_USECFSINDEX)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_FEATURE_METADATA, $COOKFS_PKGCONFIG_FEATURE_METADATA)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECVFS, $COOKFS_PKGCONFIG_USECVFS)
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USECWRITER, $COOKFS_PKGCONFIG_USECWRITER)

AC_DEFINE(COOKFS_USEPKGCONFIG)
AC_DEFINE(COOKFS_USECPKGCONFIG)
else
COOKFS_PKGCONFIG_USECPKGCONFIG=0
fi
Expand Down
8 changes: 7 additions & 1 deletion generic/cookfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Cookfs_Init(Tcl_Interp *interp)
}
#endif

#ifdef COOKFS_USECWRITER
if (Cookfs_InitWriterCmd(interp) != TCL_OK) {
return TCL_ERROR;
}
#endif

#ifdef COOKFS_USECWRITERCHAN
if (Cookfs_InitWriterchannelCmd(interp) != TCL_OK) {
return TCL_ERROR;
Expand All @@ -76,7 +82,7 @@ Cookfs_Init(Tcl_Interp *interp)
}
#endif

#ifdef COOKFS_USEPKGCONFIG
#ifdef COOKFS_USECPKGCONFIG
Tcl_RegisterConfig(interp, PACKAGE_NAME, cookfs_pkgconfig, "iso8859-1");

if (Tcl_PkgProvide(interp, PACKAGE_NAME "::pkgconfig", PACKAGE_VERSION) != TCL_OK) {
Expand Down
10 changes: 8 additions & 2 deletions generic/cookfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
#include "readerchannelIO.h"
#endif /* COOKFS_USECREADERCHAN */

#ifdef COOKFS_USECWRITER
#include "writer.h"
#include "writerCmd.h"
#endif /* COOKFS_USECWRITER */

#ifdef COOKFS_USECVFS
#include "writer.h"
#include "vfs.h"
Expand All @@ -65,20 +70,21 @@
#include "writerchannelIO.h"
#endif /* COOKFS_USECWRITERCHAN */

#ifdef COOKFS_USEPKGCONFIG
#ifdef COOKFS_USECPKGCONFIG
static Tcl_Config const cookfs_pkgconfig[] = {
{"package-version", PACKAGE_VERSION},
{"c-pages", STRINGIFY(COOKFS_PKGCONFIG_USECPAGES)},
{"c-fsindex", STRINGIFY(COOKFS_PKGCONFIG_USECFSINDEX)},
{"c-readerchannel", STRINGIFY(COOKFS_PKGCONFIG_USECREADERCHAN)},
{"c-writerchannel", STRINGIFY(COOKFS_PKGCONFIG_USECWRITERCHAN)},
{"c-vfs", STRINGIFY(COOKFS_PKGCONFIG_USECVFS)},
{"c-writer", STRINGIFY(COOKFS_PKGCONFIG_USECWRITER)},
{"feature-aside", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_ASIDE)},
{"feature-bzip2", STRINGIFY(COOKFS_PKGCONFIG_USEBZ2)},
{"feature-xz", STRINGIFY(COOKFS_PKGCONFIG_USEXZ)},
{"feature-metadata", STRINGIFY(COOKFS_PKGCONFIG_FEATURE_METADATA)},
{NULL, NULL}
};
#endif /* COOKFS_USEPKGCONFIG */
#endif /* COOKFS_USECPKGCONFIG */

#endif /* COOKFS_H */
Loading

0 comments on commit 15db495

Please sign in to comment.