FS-4657 --resolve update libsndfile to its latest master

This commit is contained in:
Jeff Lenk 2014-02-21 16:09:43 -06:00
parent 0c1f6ef2ed
commit 199a64bf6a
291 changed files with 25966 additions and 5745 deletions

View File

@ -1 +1 @@
Wed Aug 28 03:22:32 CDT 2013
Fri Feb 28 03:45:32 CDT 2014

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
## Process this file with automake to produce Makefile.in
EXTRA_DIST = add_cflags.m4 clip_mode.m4 endian.m4 extra_largefile.m4 \
EXTRA_DIST = add_cflags.m4 clip_mode.m4 endian.m4 \
flexible_array.m4 llrint.m4 lrint.m4 lrintf.m4 octave.m4 extra_pkg.m4

View File

@ -1,17 +1,18 @@
dnl @synopsis AC_ADD_CFLAGS
dnl @synopsis MN_ADD_CFLAGS
dnl
dnl Add the given option to CFLAGS, if it doesn't break the compiler
AC_DEFUN([AC_ADD_CFLAGS],
AC_DEFUN([MN_ADD_CFLAGS],
[AC_MSG_CHECKING([if $CC accepts $1])
ac_add_cflags__old_cflags="$CFLAGS"
CFLAGS="$CFLAGS $1"
CFLAGS="$1"
AC_TRY_LINK([
#include <stdio.h>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([yes])
CFLAGS="$ac_add_cflags__old_cflags $1",
AC_MSG_RESULT([no])
CFLAGS="$ac_add_cflags__old_cflags"
CFLAGS="$ac_add_cflags__old_cflags"
)
])# AC_ADD_CFLAGS
])# MN_ADD_CFLAGS

View File

@ -1,17 +1,19 @@
dnl @synopsis AC_ADD_CXXFLAGS
dnl @synopsis MN_ADD_CXXFLAGS
dnl
dnl Add the given option to CXXFLAGS, if it doesn't break the compiler
AC_DEFUN([AC_ADD_CXXFLAGS],
AC_DEFUN([MN_ADD_CXXFLAGS],
[AC_MSG_CHECKING([if $CXX accepts $1])
AC_LANG_ASSERT([C++])
ac_add_cxxflags__old_cxxflags="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $1"
CXXFLAGS="$1"
AC_TRY_LINK([
#include <cstdio>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([yes])
CXXFLAGS="$ac_add_cxxflags__old_cxxflags $1",
AC_MSG_RESULT([no])
CXXFLAGS="$ac_add_cxxflags__old_cxxflags"
CXXFLAGS="$ac_add_cxxflags__old_cxxflags"
)
])# AC_ADD_CXXFLAGS
])# MN_ADD_CXXFLAGS

View File

@ -0,0 +1,31 @@
dnl @synopsis MN_C_COMPILER_IS_CLANG
dnl
dnl Find out if a compiler claiming to be gcc really is gcc (fuck you clang).
dnl @version 1.0 Oct 31 2013
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([MN_C_COMPILER_IS_CLANG],
[AC_CACHE_CHECK(whether we are using the CLANG C compiler,
mn_cv_c_compiler_clang,
[ AC_LANG_ASSERT(C)
AC_TRY_LINK([
#include <stdio.h>
],
[
#ifndef __clang__
This is not clang!
#endif
],
mn_cv_c_compiler_clang=yes,
mn_cv_c_compiler_clang=no
])
)
])

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C_CLIP_MODE
dnl @synopsis MN_C_CLIP_MODE
dnl
dnl Determine the clipping mode when converting float to int.
dnl @version 1.0 May 17 2003
@ -20,7 +20,7 @@ dnl Find the clipping mode in the following way:
dnl 1) If we are not cross compiling test it.
dnl 2) IF we are cross compiling, assume that clipping isn't done correctly.
AC_DEFUN([AC_C_CLIP_MODE],
AC_DEFUN([MN_C_CLIP_MODE],
[AC_CACHE_CHECK(processor clipping capabilities,
ac_cv_c_clip_type,
@ -119,6 +119,6 @@ case "$ac_cv_c_clip_positive$ac_cv_c_clip_negative" in
)
]
)# AC_C_CLIP_MODE
)# MN_C_CLIP_MODE

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C_FIND_ENDIAN
dnl @synopsis MN_C_FIND_ENDIAN
dnl
dnl Determine endian-ness of target processor.
dnl @version 1.1 Mar 03 2002
@ -20,7 +20,7 @@ dnl 2) If 1) fails, look in <sys/types.h> and <sys/param.h>.
dnl 3) If 1) and 2) fails and not cross compiling run a test program.
dnl 4) If 1) and 2) fails and cross compiling then guess based on target.
AC_DEFUN([AC_C_FIND_ENDIAN],
AC_DEFUN([MN_C_FIND_ENDIAN],
[AC_CACHE_CHECK(processor byte ordering,
ac_cv_c_byte_order,
@ -92,13 +92,11 @@ if test $ac_cv_c_byte_order = unknown ; then
[
case "$target_cpu" in
alpha* | i?86* | mipsel* | ia64*)
ac_cv_c_big_endian=0
ac_cv_c_little_endian=1
ac_cv_c_byte_order=little
;;
m68* | mips* | powerpc* | hppa* | sparc*)
ac_cv_c_big_endian=1
ac_cv_c_little_endian=0
ac_cv_c_byte_order=big
;;
esac
@ -116,7 +114,6 @@ if test $ac_cv_c_byte_order = unknown ; then
return (u.c [sizeof (long) - 1] == 1);
}
]], , ac_cv_c_byte_order=big,
ac_cv_c_byte_order=unknown
)
AC_TRY_RUN(
@ -129,7 +126,6 @@ if test $ac_cv_c_byte_order = unknown ; then
u.l = 1 ;
return (u.c [0] == 1);
}]], , ac_cv_c_byte_order=little,
ac_cv_c_byte_order=unknown
)
fi
fi
@ -154,6 +150,6 @@ else
fi
]
)# AC_C_FIND_ENDIAN
)# MN_C_FIND_ENDIAN

View File

@ -6,8 +6,8 @@ dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
dnl Written by Paul Eggert <eggert@twinsun.com>.
dnl Internal subroutine of AC_SYS_EXTRA_LARGEFILE.
dnl AC_SYS_EXTRA_LARGEFILE_FLAGS(FLAGSNAME)
AC_DEFUN([AC_SYS_EXTRA_LARGEFILE_FLAGS],
dnl MN_SYS_EXTRA_LARGEFILE_FLAGS(FLAGSNAME)
AC_DEFUN([MN_SYS_EXTRA_LARGEFILE_FLAGS],
[AC_CACHE_CHECK([for $1 value to request large file support],
ac_cv_sys_largefile_$1,
[ac_cv_sys_largefile_$1=`($GETCONF LFS_$1) 2>/dev/null` || {
@ -67,9 +67,9 @@ AC_DEFUN([AC_SYS_EXTRA_LARGEFILE],
[ --disable-largefile omit support for large files])
if test "$enable_largefile" != no; then
AC_CHECK_TOOL(GETCONF, getconf)
AC_SYS_EXTRA_LARGEFILE_FLAGS(CFLAGS)
AC_SYS_EXTRA_LARGEFILE_FLAGS(LDFLAGS)
AC_SYS_EXTRA_LARGEFILE_FLAGS(LIBS)
MN_SYS_EXTRA_LARGEFILE_FLAGS(CFLAGS)
MN_SYS_EXTRA_LARGEFILE_FLAGS(LDFLAGS)
MN_SYS_EXTRA_LARGEFILE_FLAGS(LIBS)
for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
case "$ac_flag" in

View File

@ -1,5 +1,6 @@
# extra_pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
#
#
# Copyright (c) 2008-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
# Copyright (c) 2004 Scott James Remnant <scott@netsplit.com>.
#
# This program is free software; you can redistribute it and/or modify
@ -40,6 +41,25 @@ AC_MSG_CHECKING([for $2 ])
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
pkg_link_saved_CFLAGS=$CFLAGS
pkg_link_saved_LIBS=$LIBS
eval "pkg_CFLAGS=\${pkg_cv_[]$1[]_CFLAGS}"
eval "pkg_LIBS=\${pkg_cv_[]$1[]_LIBS}"
CFLAGS="$CFLAGS $pkg_CFLAGS"
LIBS="$LIBS $pkg_LIBS"
AC_TRY_LINK([], puts ("");, pkg_link=yes, pkg_link=no)
CFLAGS=$pkg_link_saved_CFLAGS
LIBS=$pkg_link_saved_LIBS
if test $pkg_link = no ; then
$as_echo_n "link failed ... "
pkg_failed=yes
fi
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
and $1[]_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.])
@ -48,7 +68,7 @@ if test $pkg_failed = yes; then
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
else
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
fi
# Put the nasty error message in config.log where it belongs

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FLEXIBLE_ARRAY
dnl @synopsis MN_C99_FLEXIBLE_ARRAY
dnl
dnl Dose the compiler support the 1999 ISO C Standard "stuct hack".
dnl @version 1.1 Mar 15 2004
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
AC_DEFUN([AC_C99_FLEXIBLE_ARRAY],
AC_DEFUN([MN_C99_FLEXIBLE_ARRAY],
[AC_CACHE_CHECK(C99 struct flexible array support,
ac_cv_c99_flexible_array,
@ -28,5 +28,5 @@ AC_TRY_LINK([[
ac_cv_c99_flexible_array=yes,
ac_cv_c99_flexible_array=no
))]
) # AC_C99_FLEXIBLE_ARRAY
) # MN_C99_FLEXIBLE_ARRAY

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_GCC_VERSION
dnl @synopsis MN_GCC_VERSION
dnl
dnl Find the version of gcc.
dnl @version 1.0 Nov 05 2007
@ -11,7 +11,7 @@ dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_GCC_VERSION],
AC_DEFUN([MN_GCC_VERSION],
[
if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then
@ -20,8 +20,8 @@ if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then
AC_MSG_RESULT($GCC_VERSION)
changequote(,)dnl
GCC_MINOR_VERSION=`echo $GCC_VERSION | sed "s/^[0-9]\+\.//" | sed "s/\..*//"`
GCC_MAJOR_VERSION=`echo $GCC_VERSION | sed "s/\..*//"`
GCC_MINOR_VERSION=`echo $GCC_VERSION | sed "s/$GCC_MAJOR_VERSION\.//" | sed "s/\..*//"`
changequote([,])dnl
fi
@ -29,5 +29,5 @@ AC_SUBST(GCC_VERSION)
AC_SUBST(GCC_MAJOR_VERSION)
AC_SUBST(GCC_MINOR_VERSION)
])# AC_GCC_VERSION
])# MN_GCC_VERSION

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FUNC_LLRINT
dnl @synopsis MN_C99_FUNC_LLRINT
dnl
dnl Check whether C99's llrint function is available.
dnl @version 1.1 Sep 30 2002
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LLRINT],
AC_DEFUN([MN_C99_FUNC_LLRINT],
[AC_CACHE_CHECK(for llrint,
ac_cv_c99_llrint,
[
@ -34,5 +34,5 @@ if test "$ac_cv_c99_llrint" = yes; then
AC_DEFINE(HAVE_LLRINT, 1,
[Define if you have C99's llrint function.])
fi
])# AC_C99_FUNC_LLRINT
])# MN_C99_FUNC_LLRINT

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FUNC_LRINT
dnl @synopsis MN_C99_FUNC_LRINT
dnl
dnl Check whether C99's lrint function is available.
dnl @version 1.3 Feb 12 2002
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LRINT],
AC_DEFUN([MN_C99_FUNC_LRINT],
[AC_CACHE_CHECK(for lrint,
ac_cv_c99_lrint,
[
@ -33,5 +33,5 @@ if test "$ac_cv_c99_lrint" = yes; then
AC_DEFINE(HAVE_LRINT, 1,
[Define if you have C99's lrint function.])
fi
])# AC_C99_FUNC_LRINT
])# MN_C99_FUNC_LRINT

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_C99_FUNC_LRINTF
dnl @synopsis MN_C99_FUNC_LRINTF
dnl
dnl Check whether C99's lrintf function is available.
dnl @version 1.3 Feb 12 2002
@ -10,7 +10,7 @@ dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_C99_FUNC_LRINTF],
AC_DEFUN([MN_C99_FUNC_LRINTF],
[AC_CACHE_CHECK(for lrintf,
ac_cv_c99_lrintf,
[
@ -33,5 +33,5 @@ if test "$ac_cv_c99_lrintf" = yes; then
AC_DEFINE(HAVE_LRINTF, 1,
[Define if you have C99's lrintf function.])
fi
])# AC_C99_FUNC_LRINTF
])# MN_C99_FUNC_LRINTF

View File

@ -1,4 +1,4 @@
dnl @synopsis AC_MKOCTFILE_VERSION
dnl @synopsis OCTAVE_MKOCTFILE_VERSION
dnl
dnl Find the version of mkoctfile.
dnl @version 1.0 Aug 23 2007
@ -11,7 +11,7 @@ dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
AC_DEFUN([AC_MKOCTFILE_VERSION],
AC_DEFUN([OCTAVE_MKOCTFILE_VERSION],
[
@ -34,5 +34,5 @@ if test "x$ac_cv_prog_HAVE_MKOCTFILE" = "xyes" ; then
AC_SUBST(MKOCTFILE)
AC_SUBST(MKOCTFILE_VERSION)
])# AC_MKOCTFILE_VERSION
])# OCTAVE_MKOCTFILE_VERSION

View File

@ -18,10 +18,10 @@ dnl Find the version of Octave.
dnl @version 1.0 Aug 23 2007
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
@ -52,10 +52,10 @@ dnl Find the version of Octave.
dnl @version 1.0 Aug 23 2007
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
@ -102,7 +102,7 @@ dnl Default to no.
OCTAVE_BUILD=no
AC_OCTAVE_VERSION
AC_MKOCTFILE_VERSION
OCTAVE_MKOCTFILE_VERSION
AC_OCTAVE_CONFIG_VERSION
prog_concat="$ac_cv_prog_HAVE_OCTAVE$ac_cv_prog_HAVE_OCTAVE_CONFIG$ac_cv_prog_HAVE_MKOCTFILE"
@ -119,7 +119,7 @@ if test "x$prog_concat" = "xyesyesyes" ; then
2.*)
AC_MSG_WARN([Octave version 2.X is not supported.])
;;
3.0.*)
3.*)
OCTAVE_DEST_ODIR=`$OCTAVE_CONFIG --oct-site-dir | sed 's%^/usr%${prefix}%'`
OCTAVE_DEST_MDIR=`$OCTAVE_CONFIG --m-site-dir | sed 's%^/usr%${prefix}%'`

View File

@ -0,0 +1,33 @@
dnl @synopsis MN_GCC_REALLY_IS_GCC
dnl
dnl Find out if a compiler claiming to be gcc really is gcc (fuck you clang).
dnl @version 1.0 Oct 31 2013
dnl @author Erik de Castro Lopo <erikd AT mega-nerd DOT com>
dnl
dnl Permission to use, copy, modify, distribute, and sell this file for any
dnl purpose is hereby granted without fee, provided that the above copyright
dnl and this permission notice appear in all copies. No representations are
dnl made about the suitability of this software for any purpose. It is
dnl provided "as is" without express or implied warranty.
dnl
# If the configure script has already detected GNU GCC, then make sure it
# isn't CLANG masquerading as GCC.
AC_DEFUN([MN_GCC_REALLY_IS_GCC],
[ AC_LANG_ASSERT(C)
if test "x$ac_cv_c_compiler_gnu" = "xyes" ; then
AC_TRY_LINK([
#include <stdio.h>
],
[
#ifdef __clang__
This is clang!
#endif
],
ac_cv_c_compiler_gnu=yes,
ac_cv_c_compiler_gnu=no
)
fi
])

View File

@ -0,0 +1,73 @@
dnl Copyright (C) 2013 Xiph.org Foundation
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions
dnl are met:
dnl
dnl - Redistributions of source code must retain the above copyright
dnl notice, this list of conditions and the following disclaimer.
dnl
dnl - Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl - Neither the name of the Xiph.org Foundation nor the names of its
dnl contributors may be used to endorse or promote products derived from
dnl this software without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
dnl CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl Want to know of GCC stack protector works, botfor the C and for the C++
dnl compiler.
dnl
dnl Just checking if the compiler accepts the required CFLAGSs is not enough
dnl because we have seen at least one instance where this check was
dnl in-sufficient.
dnl
dnl Instead, try to compile and link a test program with the stack protector
dnl flags. If that works, we use it.
AC_DEFUN([XIPH_GCC_STACK_PROTECTOR],
[AC_LANG_ASSERT(C)
AC_MSG_CHECKING([if $CC supports stack smash protection])
xiph_stack_check_old_cflags="$CFLAGS"
SSP_FLAGS="-fstack-protector --param ssp-buffer-size=4"
CFLAGS=$SSP_FLAGS
AC_TRY_LINK([
#include <stdio.h>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes])
CFLAGS="$xiph_stack_check_old_cflags $SSP_FLAGS",
AC_MSG_RESULT([no])
CFLAGS="$xiph_stack_check_old_cflags"
)
])# XIPH_GCC_STACK_PROTECTOR
AC_DEFUN([XIPH_GXX_STACK_PROTECTOR],
[AC_LANG_PUSH([C++])
AC_MSG_CHECKING([if $CXX supports stack smash protection])
xiph_stack_check_old_cflags="$CFLAGS"
SSP_FLAGS="-fstack-protector --param ssp-buffer-size=4"
CFLAGS=$SSP_FLAGS
AC_TRY_LINK([
#include <cstdio>
],
[puts("Hello, World!"); return 0;],
AC_MSG_RESULT([yes])
CFLAGS="$xiph_stack_check_old_cflags $SSP_FLAGS",
AC_MSG_RESULT([no])
CFLAGS="$xiph_stack_check_old_cflags"
)
AC_LANG_POP([C++])
])# XIPH_GXX_STACK_PROTECTOR

View File

@ -1,29 +1,44 @@
## Process this file with automake to produce Makefile.in
DISTCHECK_CONFIGURE_FLAGS = --enable-gcc-werror
if BUILD_OCTAVE_MOD
octave_dir = Octave
endif
SUBDIRS = M4 Win32 src $(octave_dir)
#man doc examples regtest tests programs
DIST_SUBDIRS = M4 man doc Win32 src Octave examples regtest tests programs
EXTRA_DIST = libsndfile.spec.in sndfile.pc.in Mingw-make-dist.sh
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = sndfile.pc
m4datadir = $(datadir)/aclocal
test: check-recursive
# Target to make autogenerated files.
genfiles :
(cd src ; make genfiles)
(cd tests ; make genfiles)
## Process this file with automake to produce Makefile.in
ACLOCAL_AMFLAGS = -I M4
DISTCHECK_CONFIGURE_FLAGS = --enable-gcc-werror
if BUILD_OCTAVE_MOD
octave_dir = Octave
endif
SUBDIRS = M4 man doc Win32 src $(octave_dir) examples regtest tests programs
DIST_SUBDIRS = M4 man doc Win32 src Octave examples regtest tests programs
EXTRA_DIST = libsndfile.spec.in sndfile.pc.in Scripts/android-configure.sh \
Scripts/linux-to-win-cross-configure.sh Scripts/build-test-tarball.mk.in
CLEANFILES = *~
pkgconfig_DATA = sndfile.pc
m4datadir = $(datadir)/aclocal
#===============================================================================
test: check-recursive
# Target to make autogenerated files.
genfiles :
(cd src ; make genfiles)
(cd tests ; make genfiles)
checkprograms :
(cd src ; make libsndfile.la checkprograms)
(cd tests ; make checkprograms)
testprogs :
(cd src ; make testprogs)
(cd tests ; make testprogs)
test-tarball : Scripts/build-test-tarball.mk
(cd src ; make all libsndfile.la checkprograms)
(cd tests ; make all checkprograms)
make -f Scripts/build-test-tarball.mk

View File

@ -1,3 +1,37 @@
Version 1.0.25 (2011-07-13)
* Fix for Secunia Advisory SA45125, heap overflow in PAF file handler.
* Accept broken WAV files with blockalign == 0.
* Minor bug fixes and improvements.
Version 1.0.24 (2011-03-23)
* WAV files now have an 18 byte u-law and A-law fmt chunk.
* Document virtual I/O functionality.
* Two new methods rawHandle() and takeOwnership() in sndfile.hh.
* AIFF fix for non-zero offset value in SSND chunk.
* Minor bug fixes and improvements.
Version 1.0.23 (2010-10-10)
* Add version metadata to Windows DLL.
* Add a missing 'inline' to sndfile.hh.
* Update docs.
* Minor bug fixes and improvements.
Version 1.0.22 (2010-10-04)
* Couple of fixes for SDS file writer.
* Fixes arising from static analysis.
* Handle FLAC files with ID3 meta data at start of file.
* Handle FLAC files which report zero length.
* Other minor bug fixes and improvements.
Version 1.0.21 (2009-12-13)
* Add a couple of new binary programs to programs/ dir.
* Remove sndfile-jackplay (now in sndfile-tools package).
* Add windows only function sf_wchar_open().
* Bunch of minor bug fixes.
Version 1.0.20 (2009-05-14)
* Fix potential heap overflow in VOC file parser (Tobias Klein, http://www.trapkit.de/).
Version 1.0.19 (2009-03-02)
* Fix for CVE-2009-0186 (Alin Rad Pop, Secunia Research).
* Huge number of minor bug fixes as a result of static analysis.

View File

@ -21,7 +21,7 @@ OCT_LIB_DIR = @OCT_LIB_DIR@
OCT_LIBS = @OCT_LIBS@
SNDFILEDIR = $(top_builddir)/src
INCLUDES = -I$(SNDFILEDIR)
AM_CPPFLAGS = -I$(SNDFILEDIR)
oct_module_srcs = sndfile.cc
oct_module_files = sndfile.oct PKG_ADD
@ -30,13 +30,19 @@ oct_module_files = sndfile.oct PKG_ADD
noinst_DATA = $(oct_module_files)
# Used by shave which cleans up automake generated Makefile output.
V = @
Q = $(V:1=)
QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
# Use Octave's mkoctfile to do all the heavy lifting. Unfortunately, its
# a little dumb so we need to guide it carefully.
sndfile.oct : sndfile.o
$(MKOCTFILE) -v $(INCLUDES) $(top_builddir)/Octave/$+ -L$(SNDFILEDIR)/.libs -L$(SNDFILEDIR) -lsndfile -o $(top_builddir)/Octave/$@
$(QUIET_GEN) $(MKOCTFILE) -v $(INCLUDES) $(top_builddir)/Octave/$+ -L$(SNDFILEDIR)/.libs -L$(SNDFILEDIR) -lsndfile -o $(top_builddir)/Octave/$@ > /dev/null
sndfile.o : sndfile.cc
$(MKOCTFILE) -v $(INCLUDES) -c $+ -o $(top_builddir)/Octave/$@
$(QUIET_GEN) $(MKOCTFILE) -v $(INCLUDES) -c $+ -o $(top_builddir)/Octave/$@ > /dev/null
# Allow for the test being run in the build dir, but the test script
# being located in the source dir.
@ -70,3 +76,4 @@ uninstall-local :
clean-local :
rm -f sndfile.o sndfile.oct
@if test $(abs_builddir) != $(abs_srcdir) ; then rm -f PKG_ADD ; fi

View File

@ -0,0 +1,23 @@
The libsndfile Modules for GNU Octave
=====================================
These modules are currently known to work with version 3.0 of GNU Octave on
Linux. They have not been tested elsewhere.
Build Requirements
------------------
In order to build these libsndfile related modules for GNU Octave on a Debian
GNU/Linux (or Debian derived) system, you will need (on top of what is normally
required to build libsndfile) the package:
octaveX.Y-headers
where X.Y matches the version number of your installation of GNU Octave.
The configure script in the top level libsndfile directory will detect the
presence and correct versions of the Octave build tools. The building of these
modules will only go ahead if everything is correct.

View File

@ -0,0 +1,21 @@
/*
** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program 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 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 Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
int format_of_str (const std::string & fmt) ;
void string_of_format (std::string & fmt, int format) ;

View File

@ -1,4 +1,4 @@
# Copyright (C) 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
# Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
@ -16,9 +16,7 @@
# These tests are nowhere near comprehensive.
printf ("\n\n\n\n\n\n\n") ;
printf (" Running Octave tests : ") ;
printf (" Running Octave tests : ") ;
fflush (stdout) ;
filename = "whatever" ;
@ -51,6 +49,4 @@ if (err > 1e-7)
printf ("ok") ;
printf ("\n\n\n\n\n\n\n") ;
unlink (filename) ;

View File

@ -2,28 +2,34 @@
# Check where we're being run from.
if [ -d Octave ]; then
if test -d Octave ; then
cd Octave
octave_src_dir=$(pwd)
elif test -z "$octave_src_dir" ; then
echo
echo "Error : \$octave_src_dir is undefined."
echo
exit 1
else
octave_src_dir=$(cd $octave_src_dir && pwd)
fi
# Find libsndfile shared object.
libsndfile_lib_location=""
if [ -f "../src/.libs/libsndfile.so" ]; then
if test -f "../src/.libs/libsndfile.so" ; then
libsndfile_lib_location="../src/.libs/"
elif [ -f "../src/libsndfile.so" ]; then
elif test -f "../src/libsndfile.so" ; then
libsndfile_lib_location="../src/"
elif [ -f "../src/.libs/libsndfile.dylib" ]; then
elif test -f "../src/.libs/libsndfile.dylib" ; then
libsndfile_lib_location="../src/.libs/"
elif [ -f "../src/libsndfile.dylib" ]; then
elif test -f "../src/libsndfile.dylib" ; then
libsndfile_lib_location="../src/"
else
echo
echo
echo "Not able to find the libsndfile shared lib we've just built."
echo "This may cause the following test to fail."
echo
echo
fi
libsndfile_lib_location=`(cd $libsndfile_lib_location && pwd)`
@ -32,9 +38,9 @@ libsndfile_lib_location=`(cd $libsndfile_lib_location && pwd)`
# Find sndfile.oct
sndfile_oct_location=""
if [ -f .libs/sndfile.oct ]; then
if test -f .libs/sndfile.oct ; then
sndfile_oct_location=".libs"
elif [ -f sndfile.oct ]; then
elif test -f sndfile.oct ; then
sndfile_oct_location="."
else
echo "Not able to find the sndfile.oct binaries we've just built."
@ -49,7 +55,7 @@ case `file -b $sndfile_oct_location/sndfile.oct` in
exit 0
;;
*)
echo "Not able to find the sndfile.oct binaries we've just built."
echo "Not able to find the sndfile.oct binary we just built."
exit 1
;;
esac
@ -57,16 +63,19 @@ case `file -b $sndfile_oct_location/sndfile.oct` in
# Make sure the TERM environment variable doesn't contain anything wrong.
unset TERM
# echo "octave_src_dir : $octave_src_dir"
# echo "libsndfile_lib_location : $libsndfile_lib_location"
# echo "sndfile_oct_location : $sndfile_oct_location"
export LD_LIBRARY_PATH="$libsndfile_lib_location:$LD_LIBRARY_PATH"
if test ! -f PKG_ADD ; then
cp $octave_src_dir/PKG_ADD .
fi
octave_src_dir=`(cd $octave_src_dir && pwd)`
export LD_LIBRARY_PATH="$libsndfile_lib_location:$LD_LIBRARY_PATH"
octave_script="$octave_src_dir/octave_test.m"
(cd $sndfile_oct_location && octave -qH $octave_script)
res=$?
echo
exit $res

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2007 Erik de Castro Lopo <erikd@mega-nerd.com>
** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
@ -367,7 +367,7 @@ string_of_minor_format (int format)
case SF_FORMAT_G723_40 : return "g723_40" ;
default : break ;
} ;
return "unknown" ;
} /* string_of_minor_format */

View File

@ -1,4 +1,4 @@
## Copyright (C) 2002 Erik de Castro Lopo
## Copyright (C) 2002-2011 Erik de Castro Lopo
##
## 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
@ -33,7 +33,7 @@ samplingrate = -1 ;
wavedata = -1 ;
eval (sprintf ('load -f %s', filename)) ;
eval (sprintf ('load -f %s', filename)) ;
if (samplerate > 0),
fs = samplerate ;
@ -42,7 +42,7 @@ elseif (samplingrate > 0),
else
error ("Not able to find sample rate.") ;
endif
if (max (size (wavedata)) > 1),
data = wavedata ;
else

View File

@ -1,4 +1,4 @@
## Copyright (C) 2002 Erik de Castro Lopo
## Copyright (C) 2002-2011 Erik de Castro Lopo
##
## 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

View File

@ -1,4 +1,4 @@
## Copyright (C) 2002 Erik de Castro Lopo
## Copyright (C) 2002-2011 Erik de Castro Lopo
##
## 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

View File

@ -1,4 +1,4 @@
This is libsndfile, 1.0.19
This is libsndfile, 1.0.25
libsndfile is a library of C routines for reading and writing
files containing sampled audio data.
@ -20,6 +20,9 @@ Bormann. Their original code can be found at :
The src/G72x directory contains code written and released by Sun Microsystems
under a suitably free license.
The src/ALAC directory contains code written and released by Apple Inc and
released under the Apache license.
LINUX
-----

79
libs/libsndfile/README.md Normal file
View File

@ -0,0 +1,79 @@
# libsndfile
libsndfile is a C library for reading and writing files containing sampled audio
data.
## Hacking
The canonical source code repository for libsndfile is at
[https://github.com/erikd/libsndfile/][github].
You can grab the source code using:
$ git clone git://github.com/erikd/libsndfile.git
Building on Linux, OSX and Windows (Using GNU GCC) will require a number of GNU
and other Free and Open Source Software tools including:
* [Autoconf][autoconf]
* [Autogen][autogen]
* [Automake][automake]
* [Libtool][libtool]
* [Pkgconfig][pkgconfig]
* [Python][python]
If you are on Linux, its probably best to install these via your Linux
distribution's package manager.
If you want to compile libsndfile with support for formats like FLAC and
Ogg/Vorbis you will also need to install the following optional libraries:
* [FLAC][flac]
* [libogg][libogg]
* [libvorbis][libvorbis]
Support for these extra libraries is an all or nothing affair. Unless all of
them are installed none of them will be supported.
$ ./autogen.sh
Running `autogen.sh` also installs a git pre-commit hook. The pre-commit hook
is run each time a user tries to commit and checks code about to be committed
against coding guidelines.
Nest step is to run configure, with the following configure options being
recommended for anyone contemplating sending libsndfile patches:
$ ./configure --enable-gcc-werror
Finally libsndfile can be built and tested:
$ make
$ make check
## Submitting Patches.
* Patches should pass all pre-commit hook tests.
* Patches should always be submitted via a either Github "pull request" or a
via emailed patches created using "git format-patch".
* Patches for new features should include tests and documentation.
* Patches to fix bugs should either pass all tests, or modify the tests in some
sane way.
* When a new feature is added for a particular file format and that feature
makes sense for other formats, then it should also be implemented for one
or two of the other formats.
[autoconf]: http://www.gnu.org/s/autoconf/
[autogen]: http://www.gnu.org/s/autogen/
[automake]: http://www.gnu.org/software/automake/
[flac]: http://flac.sourceforge.net/
[github]: https://github.com/erikd/libsndfile/
[libogg]: http://xiph.org/ogg/
[libtool]: http://www.gnu.org/software/libtool/
[libvorbis]: http://www.vorbis.com/
[pkgconfig]: http://www.freedesktop.org/wiki/Software/pkg-config
[python]: http://www.python.org/

View File

@ -0,0 +1,92 @@
#!/bin/bash -e
# Copyright (C) 2013 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# 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.
# * Neither the author nor the names of any 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.
# Android NDK version number; eg r8e, r9 etc
ANDROID_NDK_VER=r9
# Android NDK gcc version; eg 4.7, 4.9 etc.
ANDROID_GCC_VER=4.8
# Android API version; eg 9 (Android 2.3), 14 (Android 4.0) etc.
ANDROID_API_VER=9
#-------------------------------------------------------------------------------
# No more user config beyond here.
BUILD_MACHINE=$(uname -s | tr 'A-Z' 'a-z')-$(uname -m)
function die_with {
echo $1
exit 1
}
export CROSS_COMPILE=arm-linux-androideabi
# I put all my dev stuff in here
export DEV_PREFIX=$HOME/Android
test -d ${DEV_PREFIX} || die_with "Error : DEV_PREFIX '$DEV_PREFIX' does not exist."
# Don't forget to adjust this to your NDK path
export ANDROID_NDK=${DEV_PREFIX}/android-ndk-${ANDROID_NDK_VER}
test -d ${ANDROID_NDK} || die_with "Error : ANDROID_NDK '$ANDROID_NDK' does not exist."
export ANDROID_PREFIX=${ANDROID_NDK}/toolchains/arm-linux-androideabi-${ANDROID_GCC_VER}/prebuilt/${BUILD_MACHINE}
test -d ${ANDROID_PREFIX} || die_with "Error : ANDROID_PREFIX '$ANDROID_PREFIX' does not exist."
export SYSROOT=${ANDROID_NDK}/platforms/android-${ANDROID_API_VER}/arch-arm
test -d ${SYSROOT} || die_with "Error : SYSROOT '$SYSROOT' does not exist."
export CROSS_PREFIX=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}
test -f ${CROSS_PREFIX}-gcc || die_with "Error : CROSS_PREFIX compiler '${CROSS_PREFIX}-gcc' does not exist."
# Non-exhaustive lists of compiler + binutils
# Depending on what you compile, you might need more binutils than that
export CPP=${CROSS_PREFIX}-cpp
export AR=${CROSS_PREFIX}-ar
export AS=${CROSS_PREFIX}-as
export NM=${CROSS_PREFIX}-nm
export CC=${CROSS_PREFIX}-gcc
export CXX=${CROSS_PREFIX}-g++
export LD=${CROSS_PREFIX}-ld
export RANLIB=${CROSS_PREFIX}-ranlib
# Don't mix up .pc files from your host and build target
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
# Set up the needed FLAGS.
export CFLAGS="${CFLAGS} -gstabs --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"
export CXXFLAGS="${CXXFLAGS} -gstabs -fno-exceptions --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VER}/include/ -I${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_GCC_VER}/libs/armeabi/include"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"
# Create a symlink to the gdbclient.
test -h gdbclient || ln -s ${ANDROID_PREFIX}/bin/arm-linux-androideabi-gdb gdbclient
./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} "$@"

View File

@ -0,0 +1,61 @@
#!/usr/bin/make -f
# This is probably only going to work with GNU Make.
# This in a separate file instead of in Makefile.am because Automake complains
# about the GNU Make-isms.
EXEEXT = @EXEEXT@
PACKAGE_VERSION = @PACKAGE_VERSION@
HOST_TRIPLET = @HOST_TRIPLET@
SRC_BINDIR = @SRC_BINDIR@
TEST_BINDIR = @TEST_BINDIR@
LIBRARY := $(SRC_BINDIR)libsndfile.so.$(LIB_VERSION)
LIB_VERSION := $(shell echo $(PACKAGE_VERSION) | sed -e 's/[a-z].*//')
TESTNAME = libsndfile-testsuite-$(HOST_TRIPLET)-$(PACKAGE_VERSION)
TARBALL = $(TESTNAME).tar.gz
# Find the test programs by grepping the script for the programs it executes.
testprogs := $(shell grep '^\./' tests/test_wrapper.sh | sed -e "s|./||" -e "s/ .*//" | sort | uniq)
# Also add the programs not found by the above.
testprogs += sfversion@EXEEXT@ stdin_test@EXEEXT@ stdout_test@EXEEXT@ cpp_test@EXEEXT@ win32_test@EXEEXT@
# Find the single test program in src/ .
srcprogs := $(shell if test -x src/.libs/test_main$(EXEEXT) ; then echo "src/.libs/test_main$(EXEEXT)" ; else echo "src/test_main$(EXEEXT)" ; fi)
libfiles := $(shell if test ! -z $(EXEEXT) ; then echo "src/libsndfile-1.def src/.libs/libsndfile-1.dll" ; elif test -f $(LIBRARY) ; then echo $(LIBRARY) ; fi ; fi)
testbins := $(addprefix $(TEST_BINDIR),$(subst @EXEEXT@,$(EXEEXT),$(testprogs))) $(libfiles) $(srcprogs)
all : $(TARBALL)
clean :
rm -rf $(TARBALL) $(TESTNAME)/
check : $(TESTNAME)/test_wrapper.sh
(cd ./$(TESTNAME)/ && ./test_wrapper.sh)
$(TARBALL) : $(TESTNAME)/test_wrapper.sh
tar zcf $@ $(TESTNAME)
rm -rf $(TESTNAME)
@echo
@echo "Created : $(TARBALL)"
@echo
$(TESTNAME)/test_wrapper.sh : $(testbins) tests/test_wrapper.sh tests/pedantic-header-test.sh
rm -rf $(TESTNAME)
mkdir -p $(TESTNAME)/tests/
cp $(testbins) $(TESTNAME)/tests/
cp tests/test_wrapper.sh $(TESTNAME)/
cp tests/pedantic-header-test.sh $(TESTNAME)/tests/
chmod u+x $@
tests/test_wrapper.sh : tests/test_wrapper.sh.in
(cd tests/ ; make $@)

View File

@ -0,0 +1,13 @@
#!/bin/bash
# This is known to work with clang-3.4 from Debian testing/unstable.
# 2013/07/14
export CC=clang
export CXX=clang++
export CFLAGS="-O3 -fsanitize=address,integer,undefined"
export CXXFLAGS="-O3 -fsanitize=address,integer,undefined"
./configure --enable-gcc-werror
make clean all check

View File

@ -0,0 +1,246 @@
#!/usr/bin/python -tt
#
# Copyright (C) 2005-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
#
# Released under the 2 clause BSD license.
"""
This program checks C code for compliance to coding standards used in
libsndfile and other projects I run.
"""
import re
import sys
class Preprocessor:
"""
Preprocess lines of C code to make it easier for the CStyleChecker class to
test for correctness. Preprocessing works on a single line at a time but
maintains state between consecutive lines so it can preprocessess multi-line
comments.
Preprocessing involves:
- Strip C++ style comments from a line.
- Strip C comments from a series of lines. When a C comment starts and
ends on the same line it will be replaced with 'comment'.
- Replace arbitrary C strings with the zero length string.
- Replace '#define f(x)' with '#define f (c)' (The C #define requires that
there be no space between defined macro name and the open paren of the
argument list).
Used by the CStyleChecker class.
"""
def __init__ (self):
self.comment_nest = 0
self.leading_space_re = re.compile ('^(\t+| )')
self.trailing_space_re = re.compile ('(\t+| )$')
self.define_hack_re = re.compile ("(#\s*define\s+[a-zA-Z0-9_]+)\(")
def comment_nesting (self):
"""
Return the currect comment nesting. At the start and end of the file,
this value should be zero. Inside C comments it should be 1 or
(possibly) more.
"""
return self.comment_nest
def __call__ (self, line):
"""
Strip the provided line of C and C++ comments. Stripping of multi-line
C comments works as expected.
"""
line = self.define_hack_re.sub (r'\1 (', line)
line = self.process_strings (line)
# Strip C++ style comments.
if self.comment_nest == 0:
line = re.sub ("( |\t*)//.*", '', line)
# Strip C style comments.
open_comment = line.find ('/*')
close_comment = line.find ('*/')
if self.comment_nest > 0 and close_comment < 0:
# Inside a comment block that does not close on this line.
return ""
if open_comment >= 0 and close_comment < 0:
# A comment begins on this line but doesn't close on this line.
self.comment_nest += 1
return self.trailing_space_re.sub ('', line [:open_comment])
if open_comment < 0 and close_comment >= 0:
# Currently open comment ends on this line.
self.comment_nest -= 1
return self.trailing_space_re.sub ('', line [close_comment + 2:])
if open_comment >= 0 and close_comment > 0 and self.comment_nest == 0:
# Comment begins and ends on this line. Replace it with 'comment'
# so we don't need to check whitespace before and after the comment
# we're removing.
newline = line [:open_comment] + "comment" + line [close_comment + 2:]
return self.__call__ (newline)
return line
def process_strings (self, line):
"""
Given a line of C code, return a string where all literal C strings have
been replaced with the empty string literal "".
"""
for k in range (0, len (line)):
if line [k] == '"':
start = k
for k in range (start + 1, len (line)):
if line [k] == '"' and line [k - 1] != '\\':
return line [:start + 1] + '"' + self.process_strings (line [k + 1:])
return line
class CStyleChecker:
"""
A class for checking the whitespace and layout of a C code.
"""
def __init__ (self, debug):
self.debug = debug
self.filename = None
self.error_count = 0
self.line_num = 1
self.orig_line = ''
self.trailing_newline_re = re.compile ('[\r\n]+$')
self.indent_re = re.compile ("^\s*")
self.last_line_indent = ""
self.last_line_indent_curly = False
self.re_checks = \
[ ( re.compile (" "), "multiple space instead of tab" )
, ( re.compile ("\t "), "space after tab" )
, ( re.compile ("[^ ];"), "missing space before semi-colon" )
, ( re.compile ("{[^\s}]"), "missing space after open brace" )
, ( re.compile ("[^{\s]}"), "missing space before close brace" )
, ( re.compile ("[ \t]+$"), "contains trailing whitespace" )
, ( re.compile (",[^\s\n]"), "missing space after comma" )
, ( re.compile (";[a-zA-Z0-9]"), "missing space after semi-colon" )
, ( re.compile ("=[^\s\"'=]"), "missing space after assignment" )
# Open and close parenthesis.
, ( re.compile ("[^\s\(\[\*&']\("), "missing space before open parenthesis" )
, ( re.compile ("\)(-[^>]|[^,'\s\n\)\]-])"), "missing space after close parenthesis" )
, ( re.compile ("\s(do|for|if|when)\s.*{$"), "trailing open parenthesis at end of line" )
, ( re.compile ("\( [^;]"), "space after open parenthesis" )
, ( re.compile ("[^;] \)"), "space before close parenthesis" )
# Open and close square brace.
, ( re.compile ("[^\s\(\]]\["), "missing space before open square brace" )
, ( re.compile ("\][^,\)\]\[\s\.-]"), "missing space after close square brace" )
, ( re.compile ("\[ "), "space after open square brace" )
, ( re.compile (" \]"), "space before close square brace" )
# Space around operators.
, ( re.compile ("[^\s][\*/%+-][=][^\s]"), "missing space around opassign" )
, ( re.compile ("[^\s][<>!=^/][=]{1,2}[^\s]"), "missing space around comparison" )
# Parens around single argument to return.
, ( re.compile ("\s+return\s+\([a-zA-Z0-9_]+\)\s+;"), "parens around return value" )
]
def get_error_count (self):
"""
Return the current error count for this CStyleChecker object.
"""
return self.error_count
def check_files (self, files):
"""
Run the style checker on all the specified files.
"""
for filename in files:
self.check_file (filename)
def check_file (self, filename):
"""
Run the style checker on the specified file.
"""
self.filename = filename
cfile = open (filename, "r")
self.line_num = 1
preprocess = Preprocessor ()
while 1:
line = cfile.readline ()
if not line:
break
line = self.trailing_newline_re.sub ('', line)
self.orig_line = line
self.line_checks (preprocess (line))
self.line_num += 1
cfile.close ()
self.filename = None
# Check for errors finding comments.
if preprocess.comment_nesting () != 0:
print ("Weird, comments nested incorrectly.")
sys.exit (1)
return
def line_checks (self, line):
"""
Run the style checker on provided line of text, but within the context
of how the line fits within the file.
"""
indent = len (self.indent_re.search (line).group ())
if re.search ("^\s+}", line):
if not self.last_line_indent_curly and indent != self.last_line_indent:
None # self.error ("bad indent on close curly brace")