Skip to content

Commit

Permalink
Refactor Tcl/C code
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 15, 2024
1 parent 08864d4 commit 93a196b
Show file tree
Hide file tree
Showing 31 changed files with 979 additions and 376 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-05-15 Konstantin Kushnir <[email protected]>
* Refactor Tcl/C code
* Add support for changecount subcommand for fsindex
* Add support for import subcommand for fsindex (undocumented)

2024-05-10 Konstantin Kushnir <[email protected]>
* Make pkgconfig.tcl file optional, implement it in C

Expand Down
160 changes: 113 additions & 47 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_USECVFS
COOKFS_PKGCONFIG_FEATURE_METADATA
COOKFS_PKGCONFIG_USECFSINDEX
COOKFS_PKGCONFIG_USEXZ
Expand Down Expand Up @@ -789,6 +790,7 @@ enable_c_pages
enable_c_fsindex
enable_c_readerchannel
enable_c_pkgconfig
enable_c_vfs
'
ac_precious_vars='build_alias
host_alias
Expand Down Expand Up @@ -1433,6 +1435,7 @@ Optional Features:
--disable-c-fsindex Use index handling written in C. Defaults to true
--disable-c-readerchannel Use reader handler written in C. Defaults to true
--disable-c-pkgconfig Use pkgconfig written in C. Defaults to true
--enable-c-vfs Use VFS support written in C. Defaults to false
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
Expand Down Expand Up @@ -8643,6 +8646,14 @@ else $as_nop
USECPKGCONFIG=yes
fi

# Check whether --enable-c-vfs was given.
if test ${enable_c_vfs+y}
then :
enableval=$enable_c_vfs; USECVFS=${enableval}
else $as_nop
USECVFS=no
fi


if test ${INTERNALDEBUG} = yes; then
printf "%s\n" "#define COOKFS_INTERNAL_DEBUG 1" >>confdefs.h
Expand Down Expand Up @@ -8724,50 +8735,6 @@ if test ${USECPAGES} = yes; then



# reader channel requires support for pages in C
if test ${USECREADERCHAN} = yes; then
printf "%s\n" "#define COOKFS_USECREADERCHAN 1" >>confdefs.h

COOKFS_PKGCONFIG_USECREADERCHAN=1

vars="readerchannel.c readerchannelIO.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



else
COOKFS_PKGCONFIG_USECREADERCHAN=0
fi

# enable bz2 files only if pages are handled using C
if test ${USEBZ2} = yes; then
BUILDCCODE=yes
Expand Down Expand Up @@ -8963,11 +8930,13 @@ else
COOKFS_PKGCONFIG_FEATURE_ASIDE=0
COOKFS_PKGCONFIG_USEXZ=0

# if not using c-pages, use Tcl only readerchannel
COOKFS_PKGCONFIG_USECREADERCHAN=0

# Tcl implementation offers bzip2 compression only with Trf package
COOKFS_PKGCONFIG_USEBZ2=0

# c-vfs requires c-pages
USECVFS="no"
# c-readerchannel requires c-pages
USECREADERCHAN="no"
fi

if test ${USECFSINDEX} = yes; then
Expand Down Expand Up @@ -9011,10 +8980,105 @@ if test ${USECFSINDEX} = yes; then

else
COOKFS_PKGCONFIG_USECFSINDEX=0
# c-vfs requires c-fsindex
USECVFS="no"
# c-readerchannel requires c-fsindex
USECREADERCHAN="no"
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1

# reader channel requires support for pages in C
if test ${USECREADERCHAN} = yes; then
printf "%s\n" "#define COOKFS_USECREADERCHAN 1" >>confdefs.h

COOKFS_PKGCONFIG_USECREADERCHAN=1

vars="readerchannel.c readerchannelIO.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



else
COOKFS_PKGCONFIG_USECREADERCHAN=0
# c-vfs requires c-readerchannel
USECVFS="no"
fi

if test ${USECVFS} = yes; then
as_fn_error $? "support for c-vfs is not ready yet" "$LINENO" 5
printf "%s\n" "#define COOKFS_USECVFS 1" >>confdefs.h

COOKFS_PKGCONFIG_USECVFS=1

vars="vfs.c vfsCmd.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



else
COOKFS_PKGCONFIG_USECVFS=0
fi





Expand All @@ -9041,6 +9105,8 @@ if test ${USECPKGCONFIG} = yes; then

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

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


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

Expand Down
44 changes: 32 additions & 12 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ AC_ARG_ENABLE(c-pages, [ --disable-c-pages Use pages handling w
AC_ARG_ENABLE(c-fsindex, [ --disable-c-fsindex Use index handling written in C. Defaults to true], USECFSINDEX=${enableval}, USECFSINDEX=yes)
AC_ARG_ENABLE(c-readerchannel, [ --disable-c-readerchannel Use reader handler written in C. Defaults to true], USECREADERCHAN=${enableval}, USECREADERCHAN=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, [ --enable-c-vfs Use VFS support written in C. Defaults to false], USECVFS=${enableval}, USECVFS=no)

if test ${INTERNALDEBUG} = yes; then
AC_DEFINE(COOKFS_INTERNAL_DEBUG)
Expand All @@ -131,15 +132,6 @@ if test ${USECPAGES} = yes; then
COOKFS_PKGCONFIG_FEATURE_ASIDE=1
TEA_ADD_SOURCES([pages.c pagesCompr.c pagesCmd.c])

# reader channel requires support for pages in C
if test ${USECREADERCHAN} = yes; then
AC_DEFINE(COOKFS_USECREADERCHAN)
COOKFS_PKGCONFIG_USECREADERCHAN=1
TEA_ADD_SOURCES([readerchannel.c readerchannelIO.c])
else
COOKFS_PKGCONFIG_USECREADERCHAN=0
fi

# enable bz2 files only if pages are handled using C
if test ${USEBZ2} = yes; then
BUILDCCODE=yes
Expand Down Expand Up @@ -183,11 +175,13 @@ else
COOKFS_PKGCONFIG_FEATURE_ASIDE=0
COOKFS_PKGCONFIG_USEXZ=0

# if not using c-pages, use Tcl only readerchannel
COOKFS_PKGCONFIG_USECREADERCHAN=0

# Tcl implementation offers bzip2 compression only with Trf package
COOKFS_PKGCONFIG_USEBZ2=0

# c-vfs requires c-pages
USECVFS="no"
# c-readerchannel requires c-pages
USECREADERCHAN="no"
fi

if test ${USECFSINDEX} = yes; then
Expand All @@ -196,17 +190,42 @@ if test ${USECFSINDEX} = yes; then
TEA_ADD_SOURCES([fsindex.c fsindexIO.c fsindexCmd.c])
else
COOKFS_PKGCONFIG_USECFSINDEX=0
# c-vfs requires c-fsindex
USECVFS="no"
# c-readerchannel requires c-fsindex
USECREADERCHAN="no"
fi

COOKFS_PKGCONFIG_FEATURE_METADATA=1

# reader channel requires support for pages in C
if test ${USECREADERCHAN} = yes; then
AC_DEFINE(COOKFS_USECREADERCHAN)
COOKFS_PKGCONFIG_USECREADERCHAN=1
TEA_ADD_SOURCES([readerchannel.c readerchannelIO.c])
else
COOKFS_PKGCONFIG_USECREADERCHAN=0
# c-vfs requires c-readerchannel
USECVFS="no"
fi

if test ${USECVFS} = yes; then
AC_MSG_ERROR([support for c-vfs is not ready yet])
AC_DEFINE(COOKFS_USECVFS)
COOKFS_PKGCONFIG_USECVFS=1
TEA_ADD_SOURCES([vfs.c vfsCmd.c])
else
COOKFS_PKGCONFIG_USECVFS=0
fi

AC_SUBST(COOKFS_PKGCONFIG_FEATURE_ASIDE)
AC_SUBST(COOKFS_PKGCONFIG_USECPAGES)
AC_SUBST(COOKFS_PKGCONFIG_USECREADERCHAN)
AC_SUBST(COOKFS_PKGCONFIG_USEBZ2)
AC_SUBST(COOKFS_PKGCONFIG_USEXZ)
AC_SUBST(COOKFS_PKGCONFIG_USECFSINDEX)
AC_SUBST(COOKFS_PKGCONFIG_FEATURE_METADATA)
AC_SUBST(COOKFS_PKGCONFIG_USECVFS)

if test ${USECPKGCONFIG} = yes; then
COOKFS_PKGCONFIG_USECPKGCONFIG=1
Expand All @@ -218,6 +237,7 @@ if test ${USECPKGCONFIG} = yes; then
AC_DEFINE_UNQUOTED(COOKFS_PKGCONFIG_USEXZ, $COOKFS_PKGCONFIG_USEXZ)
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(COOKFS_USEPKGCONFIG)
else
Expand Down
8 changes: 8 additions & 0 deletions doc/cookfs_fsindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ <h1 class="doctools_title">cookfs::fsindex(n) 1.6.0 cookfs_fsindex &quot;vfs::co
<li><a href="#11"><i class="arg">fsindexHandle</i> <b class="method">setmetadata</b> <i class="arg">name</i> <i class="arg">value</i></a></li>
<li><a href="#12"><i class="arg">fsindexHandle</i> <b class="method">unsetmetadata</b> <i class="arg">name</i></a></li>
<li><a href="#13"><i class="arg">fsindexHandle</i> <b class="method">getblockusage</b> <i class="arg">block</i></a></li>
<li><a href="#14"><i class="arg">fsindexHandle</i> <b class="method">changecount</b></a></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -193,6 +194,13 @@ <h1 class="doctools_title">cookfs::fsindex(n) 1.6.0 cookfs_fsindex &quot;vfs::co
<dt><a name="13"><i class="arg">fsindexHandle</i> <b class="method">getblockusage</b> <i class="arg">block</i></a></dt>
<dd><p>Returns the number of files using the specified block (index of cookfs page).
Returns zero if the specified block is not used by any file.</p></dd>
<dt><a name="14"><i class="arg">fsindexHandle</i> <b class="method">changecount</b></a></dt>
<dd><p>Returns a counter corresponding to the number of changes to an index since
the last import/export or create operation. Initially, this value is <b class="const">0</b>.</p>
<p>This counter is incremented by one after each <b class="method">set</b>, <b class="method">unset</b>,
<b class="method">setmetadata</b>, <b class="method">unsetmetadata</b> or <b class="method">setmtime</b> operation.</p>
<p>This method can be used to check whether changes have been made to an index
and whether it should be saved before deleting it.</p></dd>
</dl>
</div>
<div id="section3" class="doctools_section"><h2><a name="section3">BLOCK-OFFSET-SIZE INFORMATION</a></h2>
Expand Down
12 changes: 12 additions & 0 deletions doc/cookfs_fsindex.man
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ Removes metadata with specified name from index.
Returns the number of files using the specified block (index of cookfs page).
Returns zero if the specified block is not used by any file.

[call [arg fsindexHandle] [method changecount]]
Returns a counter corresponding to the number of changes to an index since
the last import/export or create operation. Initially, this value is [const 0].

[para]
This counter is incremented by one after each [method set], [method unset],
[method setmetadata], [method unsetmetadata] or [method setmtime] operation.

[para]
This method can be used to check whether changes have been made to an index
and whether it should be saved before deleting it.

[list_end]

[section {BLOCK-OFFSET-SIZE INFORMATION}]
Expand Down
12 changes: 12 additions & 0 deletions doc/cookfs_fsindex.n
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ package require \fBvfs::cookfs ?1\&.6\&.0?\fR
.sp
\fIfsindexHandle\fR \fBgetblockusage\fR \fIblock\fR
.sp
\fIfsindexHandle\fR \fBchangecount\fR
.sp
.BE
.SH DESCRIPTION
Cookfs fsindex provide a low level mechanism for storing mapping between files in cookfs archive and pages they correspond to\&.
Expand Down Expand Up @@ -378,6 +380,16 @@ Removes metadata with specified name from index\&.
\fIfsindexHandle\fR \fBgetblockusage\fR \fIblock\fR
Returns the number of files using the specified block (index of cookfs page)\&.
Returns zero if the specified block is not used by any file\&.
.TP
\fIfsindexHandle\fR \fBchangecount\fR
Returns a counter corresponding to the number of changes to an index since
the last import/export or create operation\&. Initially, this value is \fB0\fR\&.
.sp
This counter is incremented by one after each \fBset\fR, \fBunset\fR,
\fBsetmetadata\fR, \fBunsetmetadata\fR or \fBsetmtime\fR operation\&.
.sp
This method can be used to check whether changes have been made to an index
and whether it should be saved before deleting it\&.
.PP
.SH "BLOCK-OFFSET-SIZE INFORMATION"
Files in cookfs are described storing block-offset-size triplets\&. These specify
Expand Down
Loading

0 comments on commit 93a196b

Please sign in to comment.