diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 48ae5fc270ea3bbb965b4bd07cb1691a5c115642 (patch) | |
tree | 639ac5dd123a7fd28dfe4c86743b37c23b199b46 /libutil++ | |
parent | cc2ee177dbb3befca43e36cfc56778b006c3d050 (diff) | |
download | oprofile-48ae5fc270ea3bbb965b4bd07cb1691a5c115642.tar.gz |
Initial Contributionandroid-1.0release-1.0
Diffstat (limited to 'libutil++')
40 files changed, 0 insertions, 5861 deletions
diff --git a/libutil++/Makefile.am b/libutil++/Makefile.am deleted file mode 100644 index 5c894a4..0000000 --- a/libutil++/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -SUBDIRS = . tests - -AM_CPPFLAGS= \ - -I ${top_srcdir}/libutil \ - -I ${top_srcdir}/libop -AM_CXXFLAGS = @OP_CXXFLAGS@ - -noinst_LIBRARIES = libutil++.a -libutil___a_SOURCES = \ - op_bfd.cpp \ - op_bfd.h \ - bfd_support.cpp \ - bfd_support.h \ - string_filter.cpp \ - string_filter.h \ - glob_filter.cpp \ - glob_filter.h \ - growable_vector.h \ - path_filter.cpp \ - path_filter.h \ - file_manip.cpp \ - file_manip.h \ - stream_util.cpp \ - stream_util.h \ - string_manip.cpp \ - string_manip.h \ - cverb.cpp \ - cverb.h \ - generic_spec.h \ - op_exception.cpp \ - op_exception.h \ - child_reader.cpp \ - child_reader.h \ - unique_storage.h \ - utility.h \ - cached_value.h \ - comma_list.h diff --git a/libutil++/Makefile.in b/libutil++/Makefile.in deleted file mode 100644 index 53f9405..0000000 --- a/libutil++/Makefile.in +++ /dev/null @@ -1,597 +0,0 @@ -# Makefile.in generated by automake 1.9.5 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -SOURCES = $(libutil___a_SOURCES) - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -top_builddir = .. -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = @INSTALL@ -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -subdir = libutil++ -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/binutils.m4 \ - $(top_srcdir)/m4/builtinexpect.m4 \ - $(top_srcdir)/m4/compileroption.m4 \ - $(top_srcdir)/m4/configmodule.m4 \ - $(top_srcdir)/m4/copyifchange.m4 $(top_srcdir)/m4/docbook.m4 \ - $(top_srcdir)/m4/extradirs.m4 $(top_srcdir)/m4/findkernel.m4 \ - $(top_srcdir)/m4/kerneloption.m4 \ - $(top_srcdir)/m4/kernelversion.m4 \ - $(top_srcdir)/m4/mallocattribute.m4 \ - $(top_srcdir)/m4/poptconst.m4 \ - $(top_srcdir)/m4/precompiledheader.m4 $(top_srcdir)/m4/qt.m4 \ - $(top_srcdir)/m4/resultyn.m4 $(top_srcdir)/m4/sstream.m4 \ - $(top_srcdir)/m4/typedef.m4 $(top_srcdir)/configure.in -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -LIBRARIES = $(noinst_LIBRARIES) -AR = ar -ARFLAGS = cru -libutil___a_AR = $(AR) $(ARFLAGS) -libutil___a_LIBADD = -am_libutil___a_OBJECTS = op_bfd.$(OBJEXT) bfd_support.$(OBJEXT) \ - string_filter.$(OBJEXT) glob_filter.$(OBJEXT) \ - path_filter.$(OBJEXT) file_manip.$(OBJEXT) \ - stream_util.$(OBJEXT) string_manip.$(OBJEXT) cverb.$(OBJEXT) \ - op_exception.$(OBJEXT) child_reader.$(OBJEXT) -libutil___a_OBJECTS = $(am_libutil___a_OBJECTS) -DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ - -o $@ -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(libutil___a_SOURCES) -DIST_SOURCES = $(libutil___a_SOURCES) -RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ - html-recursive info-recursive install-data-recursive \ - install-exec-recursive install-info-recursive \ - install-recursive installcheck-recursive installdirs-recursive \ - pdf-recursive ps-recursive uninstall-info-recursive \ - uninstall-recursive -ETAGS = etags -CTAGS = ctags -DIST_SUBDIRS = $(SUBDIRS) -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ -AMTAR = @AMTAR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BFD_LIBS = @BFD_LIBS@ -CAT_ENTRY_END = @CAT_ENTRY_END@ -CAT_ENTRY_START = @CAT_ENTRY_START@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DATE = @DATE@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DOCBOOK_ROOT = @DOCBOOK_ROOT@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -EXTRA_CFLAGS_MODULE = @EXTRA_CFLAGS_MODULE@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -KINC = @KINC@ -KSRC = @KSRC@ -KVERS = @KVERS@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBERTY_LIBS = @LIBERTY_LIBS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MOC = @MOC@ -MODINSTALLDIR = @MODINSTALLDIR@ -OBJEXT = @OBJEXT@ -OPROFILE_DIR = @OPROFILE_DIR@ -OPROFILE_MODULE_ARCH = @OPROFILE_MODULE_ARCH@ -OP_CFLAGS = @OP_CFLAGS@ -OP_CXXFLAGS = @OP_CXXFLAGS@ -OP_DOCDIR = @OP_DOCDIR@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -POPT_LIBS = @POPT_LIBS@ -PTRDIFF_T_TYPE = @PTRDIFF_T_TYPE@ -QT_INCLUDES = @QT_INCLUDES@ -QT_LDFLAGS = @QT_LDFLAGS@ -QT_LIB = @QT_LIB@ -QT_VERSION = @QT_VERSION@ -RANLIB = @RANLIB@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -SIZE_T_TYPE = @SIZE_T_TYPE@ -STRIP = @STRIP@ -UIC = @UIC@ -VERSION = @VERSION@ -XML_CATALOG = @XML_CATALOG@ -XSLTPROC = @XSLTPROC@ -XSLTPROC_FLAGS = @XSLTPROC_FLAGS@ -X_CFLAGS = @X_CFLAGS@ -X_EXTRA_LIBS = @X_EXTRA_LIBS@ -X_LIBS = @X_LIBS@ -X_PRE_LIBS = @X_PRE_LIBS@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -ac_ct_STRIP = @ac_ct_STRIP@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ -am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build_alias = @build_alias@ -datadir = @datadir@ -enable_abi_FALSE = @enable_abi_FALSE@ -enable_abi_TRUE = @enable_abi_TRUE@ -exec_prefix = @exec_prefix@ -have_qt_FALSE = @have_qt_FALSE@ -have_qt_TRUE = @have_qt_TRUE@ -have_xsltproc_FALSE = @have_xsltproc_FALSE@ -have_xsltproc_TRUE = @have_xsltproc_TRUE@ -host_alias = @host_alias@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -kernel_support_FALSE = @kernel_support_FALSE@ -kernel_support_TRUE = @kernel_support_TRUE@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -topdir = @topdir@ -SUBDIRS = . tests -AM_CPPFLAGS = \ - -I ${top_srcdir}/libutil \ - -I ${top_srcdir}/libop - -AM_CXXFLAGS = @OP_CXXFLAGS@ -noinst_LIBRARIES = libutil++.a -libutil___a_SOURCES = \ - op_bfd.cpp \ - op_bfd.h \ - bfd_support.cpp \ - bfd_support.h \ - string_filter.cpp \ - string_filter.h \ - glob_filter.cpp \ - glob_filter.h \ - growable_vector.h \ - path_filter.cpp \ - path_filter.h \ - file_manip.cpp \ - file_manip.h \ - stream_util.cpp \ - stream_util.h \ - string_manip.cpp \ - string_manip.h \ - cverb.cpp \ - cverb.h \ - generic_spec.h \ - op_exception.cpp \ - op_exception.h \ - child_reader.cpp \ - child_reader.h \ - unique_storage.h \ - utility.h \ - cached_value.h \ - comma_list.h - -all: all-recursive - -.SUFFIXES: -.SUFFIXES: .cpp .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libutil++/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign libutil++/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -clean-noinstLIBRARIES: - -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) -libutil++.a: $(libutil___a_OBJECTS) $(libutil___a_DEPENDENCIES) - -rm -f libutil++.a - $(libutil___a_AR) libutil++.a $(libutil___a_OBJECTS) $(libutil___a_LIBADD) - $(RANLIB) libutil++.a - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bfd_support.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/child_reader.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cverb.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file_manip.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glob_filter.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/op_bfd.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/op_exception.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/path_filter.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_util.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string_filter.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string_manip.Po@am__quote@ - -.cpp.o: -@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ -@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: -@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ -@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` -uninstall-info-am: - -# This directory's subdirectories are mostly independent; you can cd -# into them and run `make' without going through this Makefile. -# To change the values of `make' variables: instead of editing Makefiles, -# (1) if the variable is set in `config.status', edit `config.status' -# (which will cause the Makefiles to be regenerated when you run `make'); -# (2) otherwise, pass the desired values on the `make' command line. -$(RECURSIVE_TARGETS): - @failcom='exit 1'; \ - for f in x $$MAKEFLAGS; do \ - case $$f in \ - *=* | --[!k]*);; \ - *k*) failcom='fail=yes';; \ - esac; \ - done; \ - dot_seen=no; \ - target=`echo $@ | sed s/-recursive//`; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - dot_seen=yes; \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || eval $$failcom; \ - done; \ - if test "$$dot_seen" = "no"; then \ - $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ - fi; test -z "$$fail" - -mostlyclean-recursive clean-recursive distclean-recursive \ -maintainer-clean-recursive: - @failcom='exit 1'; \ - for f in x $$MAKEFLAGS; do \ - case $$f in \ - *=* | --[!k]*);; \ - *k*) failcom='fail=yes';; \ - esac; \ - done; \ - dot_seen=no; \ - case "$@" in \ - distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ - *) list='$(SUBDIRS)' ;; \ - esac; \ - rev=''; for subdir in $$list; do \ - if test "$$subdir" = "."; then :; else \ - rev="$$subdir $$rev"; \ - fi; \ - done; \ - rev="$$rev ."; \ - target=`echo $@ | sed s/-recursive//`; \ - for subdir in $$rev; do \ - echo "Making $$target in $$subdir"; \ - if test "$$subdir" = "."; then \ - local_target="$$target-am"; \ - else \ - local_target="$$target"; \ - fi; \ - (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ - || eval $$failcom; \ - done && test -z "$$fail" -tags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ - done -ctags-recursive: - list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ - done - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ - include_option=--etags-include; \ - empty_fix=.; \ - else \ - include_option=--include; \ - empty_fix=; \ - fi; \ - list='$(SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test ! -f $$subdir/TAGS || \ - tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \ - fi; \ - done; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkdir_p) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ - if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done - list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ - test -d "$(distdir)/$$subdir" \ - || $(mkdir_p) "$(distdir)/$$subdir" \ - || exit 1; \ - distdir=`$(am__cd) $(distdir) && pwd`; \ - top_distdir=`$(am__cd) $(top_distdir) && pwd`; \ - (cd $$subdir && \ - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$$top_distdir" \ - distdir="$$distdir/$$subdir" \ - distdir) \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-recursive -all-am: Makefile $(LIBRARIES) -installdirs: installdirs-recursive -installdirs-am: -install: install-recursive -install-exec: install-exec-recursive -install-data: install-data-recursive -uninstall: uninstall-recursive - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-recursive -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-recursive - -clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am - -distclean: distclean-recursive - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-recursive - -dvi-am: - -html: html-recursive - -info: info-recursive - -info-am: - -install-data-am: - -install-exec-am: - -install-info: install-info-recursive - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-recursive - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-recursive - -mostlyclean-am: mostlyclean-compile mostlyclean-generic - -pdf: pdf-recursive - -pdf-am: - -ps: ps-recursive - -ps-am: - -uninstall-am: uninstall-info-am - -uninstall-info: uninstall-info-recursive - -.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \ - clean clean-generic clean-noinstLIBRARIES clean-recursive \ - ctags ctags-recursive distclean distclean-compile \ - distclean-generic distclean-recursive distclean-tags distdir \ - dvi dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-exec install-exec-am \ - install-info install-info-am install-man install-strip \ - installcheck installcheck-am installdirs installdirs-am \ - maintainer-clean maintainer-clean-generic \ - maintainer-clean-recursive mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-recursive pdf pdf-am ps ps-am \ - tags tags-recursive uninstall uninstall-am uninstall-info-am - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/libutil++/bfd_support.cpp b/libutil++/bfd_support.cpp deleted file mode 100644 index af83b1d..0000000 --- a/libutil++/bfd_support.cpp +++ /dev/null @@ -1,556 +0,0 @@ -/** - * @file bfd_support.cpp - * BFD muck we have to deal with. - * - * @remark Copyright 2005 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - */ - -#include "bfd_support.h" - -#include "op_bfd.h" -#include "op_fileio.h" -#include "string_manip.h" -#include "cverb.h" - -#include <iostream> -#include <fstream> -#include <sstream> -#include <string> - -using namespace std; - -extern verbose vbfd; - -namespace { - - -void check_format(string const & file, bfd ** ibfd) -{ - if (!bfd_check_format_matches(*ibfd, bfd_object, NULL)) { - cverb << vbfd << "BFD format failure for " << file << endl; - bfd_close(*ibfd); - *ibfd = NULL; - } -} - - -bool separate_debug_file_exists(string const & name, unsigned long const crc) -{ - unsigned long file_crc = 0; - // The size of 2 * 1024 elements for the buffer is arbitrary. - char buffer[2 * 1024]; - - ifstream file(name.c_str()); - if (!file) - return false; - - cverb << vbfd << "found " << name; - while (file) { - file.read(buffer, sizeof(buffer)); - file_crc = calc_crc32(file_crc, - reinterpret_cast<unsigned char *>(&buffer[0]), - file.gcount()); - } - cverb << vbfd << " with crc32 = " << hex << file_crc << endl; - return crc == file_crc; -} - - -bool get_debug_link_info(bfd * ibfd, string & filename, unsigned long & crc32) -{ - asection * sect; - - cverb << vbfd << "fetching .gnu_debuglink section" << endl; - sect = bfd_get_section_by_name(ibfd, ".gnu_debuglink"); - - if (sect == NULL) - return false; - - bfd_size_type debuglink_size = bfd_section_size(ibfd, sect); - char contents[debuglink_size]; - cverb << vbfd - << ".gnu_debuglink section has size " << debuglink_size << endl; - - bfd_get_section_contents(ibfd, sect, - reinterpret_cast<unsigned char *>(contents), - static_cast<file_ptr>(0), debuglink_size); - - /* CRC value is stored after the filename, aligned up to 4 bytes. */ - size_t filename_len = strlen(contents); - size_t crc_offset = filename_len + 1; - crc_offset = (crc_offset + 3) & ~3; - - crc32 = bfd_get_32(ibfd, - reinterpret_cast<bfd_byte *>(contents + crc_offset)); - filename = string(contents, filename_len); - cverb << vbfd << ".gnu_debuglink filename is " << filename << endl; - return true; -} - - -/** - * With Objective C, we'll get strings like: - * - * _i_GSUnicodeString__rangeOfCharacterSetFromSet_options_range - * - * for the symbol name, and: - * -[GSUnicodeString rangeOfCharacterFromSet:options:range:] - * - * for the function name, so we have to do some looser matching - * than for other languages (unfortunately, it's not possible - * to demangle Objective C symbols). - */ -bool objc_match(string const & sym, string const & method) -{ - if (method.length() < 3) - return false; - - string mangled; - - if (is_prefix(method, "-[")) { - mangled += "_i_"; - } else if (is_prefix(method, "+[")) { - mangled += "_c_"; - } else { - return false; - } - - string::const_iterator it = method.begin() + 2; - string::const_iterator const end = method.end(); - - bool found_paren = false; - - for (; it != end; ++it) { - switch (*it) { - case ' ': - mangled += '_'; - if (!found_paren) - mangled += '_'; - break; - case ':': - mangled += '_'; - break; - case ')': - case ']': - break; - case '(': - found_paren = true; - mangled += '_'; - break; - default: - mangled += *it; - } - } - - return sym == mangled; -} - - -/* - * With a binary image where some objects are missing debug - * info, we can end up attributing to a completely different - * function (#484660): bfd_nearest_line() will happily move from one - * symbol to the nearest one it can find with debug information. - * To mitigate this problem, we check that the symbol name - * matches the returned function name. - * - * However, this check fails in some cases it shouldn't: - * Objective C, and C++ static inline functions (as discussed in - * GCC bugzilla #11774). So, we have a looser check that - * accepts merely a substring, plus some magic for Objective C. - * - * If even the loose check fails, then we give up. - */ -bool is_correct_function(string const & function, string const & name) -{ - if (name == function) - return true; - - if (objc_match(name, function)) - return true; - - // warn the user if we had to use the loose check - if (name.find(function) != string::npos) { - static bool warned = false; - if (!warned) { - cerr << "warning: some functions compiled without " - << "debug information may have incorrect source " - << "line attributions" << endl; - warned = true; - } - cverb << vbfd << "is_correct_function(" << function << ", " - << name << ") fuzzy match." << endl; - return true; - } - - return false; -} - - -/* - * binutils 2.12 and below have a small bug where functions without a - * debug entry at the prologue start do not give a useful line number - * from bfd_find_nearest_line(). This can happen with certain gcc - * versions such as 2.95. - * - * We work around this problem by scanning forward for a vma with valid - * linenr info, if we can't get a valid line number. Problem uncovered - * by Norbert Kaufmann. The work-around decreases, on the tincas - * application, the number of failure to retrieve linenr info from 835 - * to 173. Most of the remaining are c++ inline functions mainly from - * the STL library. Fix #529622 - */ -void fixup_linenr(bfd * abfd, asection * section, asymbol ** syms, - string const & name, bfd_vma pc, - char const ** filename, unsigned int * line) -{ - char const * cfilename; - char const * function; - unsigned int linenr; - - // FIXME: looking at debug info for all gcc version shows than - // the same problems can -perhaps- occur for epilog code: find a - // samples files with samples in epilog and try opreport -l -g - // on it, check it also with opannotate. - - // first restrict the search on a sensible range of vma, 16 is - // an intuitive value based on epilog code look - size_t max_search = 16; - size_t section_size = bfd_section_size(abfd, section); - if (pc + max_search > section_size) - max_search = section_size - pc; - - for (size_t i = 1; i < max_search; ++i) { - bool ret = bfd_find_nearest_line(abfd, section, syms, pc + i, - &cfilename, &function, - &linenr); - - if (ret && cfilename && function && linenr != 0 - && is_correct_function(function, name)) { - *filename = cfilename; - *line = linenr; - return; - } - } -} - - -} // namespace anon - - -bfd * open_bfd(string const & file) -{ - /* bfd keeps its own reference to the filename char *, - * so it must have a lifetime longer than the ibfd */ - bfd * ibfd = bfd_openr(file.c_str(), NULL); - if (!ibfd) { - cverb << vbfd << "bfd_openr failed for " << file << endl; - return NULL; - } - - check_format(file, &ibfd); - - return ibfd; -} - - -bfd * fdopen_bfd(string const & file, int fd) -{ - /* bfd keeps its own reference to the filename char *, - * so it must have a lifetime longer than the ibfd */ - bfd * ibfd = bfd_fdopenr(file.c_str(), NULL, fd); - if (!ibfd) { - cverb << vbfd << "bfd_openr failed for " << file << endl; - return NULL; - } - - check_format(file, &ibfd); - - return ibfd; -} - - -bool find_separate_debug_file(bfd * ibfd, string const & dir_in, - string const & global_in, string & filename) -{ - string dir(dir_in); - string global(global_in); - string basename; - unsigned long crc32; - - if (!get_debug_link_info(ibfd, basename, crc32)) - return false; - - if (dir.size() > 0 && dir.at(dir.size() - 1) != '/') - dir += '/'; - - if (global.size() > 0 && global.at(global.size() - 1) != '/') - global += '/'; - - cverb << vbfd << "looking for debugging file " << basename - << " with crc32 = " << hex << crc32 << endl; - - string first_try(dir + basename); - string second_try(dir + ".debug/" + basename); - - if (dir.size() > 0 && dir[0] == '/') - dir = dir.substr(1); - - string third_try(global + dir + basename); - - if (separate_debug_file_exists(first_try, crc32)) - filename = first_try; - else if (separate_debug_file_exists(second_try, crc32)) - filename = second_try; - else if (separate_debug_file_exists(third_try, crc32)) - filename = third_try; - else - return false; - - return true; -} - - -bool interesting_symbol(asymbol * sym) -{ - // #717720 some binutils are miscompiled by gcc 2.95, one of the - // typical symptom can be catched here. - if (!sym->section) { - ostringstream os; - os << "Your version of binutils seems to have a bug.\n" - << "Read http://oprofile.sf.net/faq/#binutilsbug\n"; - throw op_runtime_error(os.str()); - } - - if (!(sym->section->flags & SEC_CODE)) - return false; - - // returning true for fix up in op_bfd_symbol() - if (!sym->name || sym->name[0] == '\0') - return true; - - // C++ exception stuff - if (sym->name[0] == '.' && sym->name[1] == 'L') - return false; - - /* This case cannot be moved to boring_symbol(), - * because that's only used for duplicate VMAs, - * and sometimes this symbol appears at an address - * different from all other symbols. - */ - if (!strcmp("gcc2_compiled.", sym->name)) - return false; - - return true; -} - - -bool boring_symbol(op_bfd_symbol const & first, op_bfd_symbol const & second) -{ - if (first.name() == "Letext") - return true; - else if (second.name() == "Letext") - return false; - - if (first.name().substr(0, 2) == "??") - return true; - else if (second.name().substr(0, 2) == "??") - return false; - - if (first.hidden() && !second.hidden()) - return true; - else if (!first.hidden() && second.hidden()) - return false; - - if (first.name()[0] == '_' && second.name()[0] != '_') - return true; - else if (first.name()[0] != '_' && second.name()[0] == '_') - return false; - - if (first.weak() && !second.weak()) - return true; - else if (!first.weak() && second.weak()) - return false; - - return false; -} - - -bool bfd_info::has_debug_info() const -{ - if (!valid()) - return false; - - for (asection const * sect = abfd->sections; sect; sect = sect->next) { - if (sect->flags & SEC_DEBUGGING) - return true; - } - - return false; -} - - -bfd_info::~bfd_info() -{ - free(synth_syms); - close(); -} - - -void bfd_info::close() -{ - if (abfd) - bfd_close(abfd); -} - - -#if SYNTHESIZE_SYMBOLS -bool bfd_info::get_synth_symbols() -{ - extern const bfd_target bfd_elf64_powerpc_vec; - extern const bfd_target bfd_elf64_powerpcle_vec; - bool is_elf64_powerpc_target = (abfd->xvec == &bfd_elf64_powerpc_vec) - || (abfd->xvec == &bfd_elf64_powerpcle_vec); - - if (!is_elf64_powerpc_target) - return false; - - void * buf; - uint tmp; - long nr_mini_syms = bfd_read_minisymbols(abfd, 0, &buf, &tmp); - if (nr_mini_syms < 1) - return false; - - asymbol ** mini_syms = (asymbol **)buf; - buf = NULL; - - long nr_synth_syms = bfd_get_synthetic_symtab(abfd, nr_mini_syms, - mini_syms, 0, - NULL, &synth_syms); - - if (nr_synth_syms < 0) { - free(mini_syms); - return false; - } - - cverb << vbfd << "mini_syms: " << dec << nr_mini_syms << hex << endl; - cverb << vbfd << "synth_syms: " << dec << nr_synth_syms << hex << endl; - - nr_syms = nr_mini_syms + nr_synth_syms; - syms.reset(new asymbol *[nr_syms + 1]); - - for (size_t i = 0; i < (size_t)nr_mini_syms; ++i) - syms[i] = mini_syms[i]; - - - for (size_t i = 0; i < (size_t)nr_synth_syms; ++i) - syms[nr_mini_syms + i] = synth_syms + i; - - - free(mini_syms); - - // bfd_canonicalize_symtab does this, so shall we - syms[nr_syms] = NULL; - - return true; -} -#else -bool bfd_info::get_synth_symbols() -{ - return false; -} -#endif /* SYNTHESIZE_SYMBOLS */ - - -void bfd_info::get_symbols() -{ - if (!abfd) - return; - - cverb << vbfd << "bfd_info::get_symbols() for " - << bfd_get_filename(abfd) << endl; - - if (get_synth_symbols()) - return; - - if (bfd_get_file_flags(abfd) & HAS_SYMS) - nr_syms = bfd_get_symtab_upper_bound(abfd); - - cverb << vbfd << "bfd_get_symtab_upper_bound: " << dec - << nr_syms << hex << endl; - - nr_syms /= sizeof(asymbol *); - - if (nr_syms < 1) - return; - - syms.reset(new asymbol *[nr_syms]); - - nr_syms = bfd_canonicalize_symtab(abfd, syms.get()); - - cverb << vbfd << "bfd_canonicalize_symtab: " << dec - << nr_syms << hex << endl; -} - - -linenr_info const -find_nearest_line(bfd_info const & b, op_bfd_symbol const & sym, - unsigned int offset) -{ - char const * function = ""; - char const * cfilename = ""; - unsigned int linenr = 0; - linenr_info info; - bfd * abfd; - asymbol ** syms; - asection * section; - bfd_vma pc; - bool ret; - - if (!b.valid()) - goto fail; - - // take care about artificial symbol - if (!sym.symbol()) - goto fail; - - abfd = b.abfd; - syms = b.syms.get(); - section = sym.symbol()->section; - pc = (sym.value() + offset) - sym.filepos(); - - if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0) - goto fail; - - if (pc >= bfd_section_size(abfd, section)) - goto fail; - - ret = bfd_find_nearest_line(abfd, section, syms, pc, &cfilename, - &function, &linenr); - - if (!ret || !cfilename) - goto fail; - - if (!is_correct_function(function, sym.name())) - goto fail; - - if (linenr == 0) { - fixup_linenr(abfd, section, syms, sym.name(), pc, &cfilename, - &linenr); - } - - info.found = true; - info.filename = cfilename; - info.line = linenr; - return info; - -fail: - info.found = false; - // some stl lacks string::clear() - info.filename.erase(info.filename.begin(), info.filename.end()); - info.line = 0; - return info; -} diff --git a/libutil++/bfd_support.h b/libutil++/bfd_support.h deleted file mode 100644 index 3b92655..0000000 --- a/libutil++/bfd_support.h +++ /dev/null @@ -1,123 +0,0 @@ -/** - * @file bfd_support.h - * BFD muck we have to deal with. - * - * @remark Copyright 2005 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - */ - -#ifndef BFD_SUPPORT_H -#define BFD_SUPPORT_H - -#include "utility.h" -#include "op_types.h" - -#include <bfd.h> - -#include <string> - -class op_bfd_symbol; - -/// holder for BFD state we must keep -struct bfd_info { - bfd_info() : abfd(0), nr_syms(0), synth_syms(0) {} - - ~bfd_info(); - - /// close the BFD, setting abfd to NULL - void close(); - - /// return true if BFD is readable - bool valid() const { return abfd; } - - /// return true if BFD has debug info - bool has_debug_info() const; - - /// pick out the symbols from the bfd, if we can - void get_symbols(); - - /// the actual BFD - bfd * abfd; - /// normal symbols (includes synthesized symbols) - scoped_array<asymbol *> syms; - /// nr. symbols - size_t nr_syms; - -private: - /** - * Acquire the synthetic symbols if we need to. - */ - bool get_synth_symbols(); - - /** - * On PPC64, synth_syms points to an array of synthetic asymbol - * structs returned from bfd_get_synthetic_symtab. The syms - * member points into this array, so we have to keep it around - * until ~bfd_info time. - */ - asymbol * synth_syms; - -}; - - -/* - * find_separate_debug_file - return true if a valid separate debug file found - * @param ibfd binary file - * @param dir_in directory holding the binary file - * @param global_in - * @param filename path to valid debug file - * - * Search order for debug file and use first one found: - * 1) dir_in directory - * 2) dir_in/.debug directory - * 3) global_in/dir_in directory - * - * Newer binutils and Linux distributions (e.g. Fedora) allow the - * creation of debug files that are separate from the binary. The - * debugging information is stripped out of the binary file, placed in - * this separate file, and a link to the new file is placed in the - * binary. The debug files hold the information needed by the debugger - * (and OProfile) to map machine instructions back to source code. - */ -extern bool -find_separate_debug_file(bfd * ibfd, - std::string const & dir_in, - std::string const & global_in, - std::string & filename); - -/// open the given BFD -bfd * open_bfd(std::string const & file); - -/// open the given BFD from the fd -bfd * fdopen_bfd(std::string const & file, int fd); - -/// Return true if the symbol is worth looking at -bool interesting_symbol(asymbol * sym); - -/** - * return true if the first symbol is less interesting than the second symbol - * boring symbol are eliminated when multiple symbol exist at the same vma - */ -bool boring_symbol(op_bfd_symbol const & first, op_bfd_symbol const & second); - -/// debug info for a given pc -struct linenr_info { - /// did we find something? - bool found; - /// filename - std::string filename; - /// line number - unsigned int line; -}; - -/** - * Attempt to locate a filename + line number for the given symbol and - * offset. - */ -linenr_info const -find_nearest_line(bfd_info const & ibfd, op_bfd_symbol const & sym, - unsigned int offset); - -#endif /* !BFD_SUPPORT_H */ diff --git a/libutil++/cached_value.h b/libutil++/cached_value.h deleted file mode 100644 index 362e16a..0000000 --- a/libutil++/cached_value.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @file cached_value.h - * Hold a cached value. - * - * @remark Copyright 2005 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - */ - -#ifndef CACHED_VALUE_H -#define CACHED_VALUE_H - -#include "op_exception.h" - -/** - * Hold a single value, returning a cached value if there is one. - */ -template <class T> -class cached_value -{ -public: - cached_value() : set(false) {} - - typedef T value_type; - - /// return the cached value - value_type const get() const { - if (!set) - throw op_fatal_error("cached value not set"); - return value; - } - - /// return true if a value is cached - bool cached() const { return set; } - - /// set the contained value - value_type const reset(value_type const & val) { - value = val; - set = true; - return value; - } - -private: - /// the cached value - value_type value; - /// is the value valid? - bool set; -}; - - -#endif /* !CACHED_VALUE_H */ diff --git a/libutil++/child_reader.cpp b/libutil++/child_reader.cpp deleted file mode 100644 index 8e1ea70..0000000 --- a/libutil++/child_reader.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/** - * @file child_reader.cpp - * Facility for reading from child processes - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <unistd.h> -#include <sys/wait.h> - -#include <cerrno> -#include <sstream> -#include <iostream> - -#include "op_libiberty.h" -#include "child_reader.h" - -using namespace std; - -child_reader::child_reader(string const & cmd, vector<string> const & args) - : - fd1(-1), fd2(-1), - pos1(0), end1(0), - pos2(0), end2(0), - pid(0), - first_error(0), - buf2(0), sz_buf2(0), - buf1(new char[PIPE_BUF]), - process_name(cmd), - is_terminated(true), - terminate_on_exception(false), - forked(false) -{ - exec_command(cmd, args); -} - - -child_reader::~child_reader() -{ - terminate_process(); - delete [] buf1; - if (buf2) { - // allocated through C alloc - free(buf2); - } -} - - -void child_reader::exec_command(string const & cmd, vector<string> const & args) -{ - int pstdout[2]; - int pstderr[2]; - - if (pipe(pstdout) == -1 || pipe(pstderr) == -1) { - first_error = errno; - return; - } - - pid = fork(); - switch (pid) { - case -1: - first_error = errno; - return; - - case 0: { - char const ** argv = new char const *[args.size() + 2]; - size_t i; - argv[0] = cmd.c_str(); - - for (i = 1 ; i <= args.size() ; ++i) - argv[i] = args[i - 1].c_str(); - - argv[i] = 0; - - // child: we can cleanup a few fd - close(pstdout[0]); - dup2(pstdout[1], STDOUT_FILENO); - close(pstdout[1]); - close(pstderr[0]); - dup2(pstderr[1], STDERR_FILENO); - close(pstderr[1]); - - execvp(cmd.c_str(), (char * const *)argv); - - int ret_code = errno; - - // we can communicate with parent by writing to stderr - // and by returning a non zero error code. Setting - // first_error in the child is a non-sense - - // we are in the child process: so this error message - // is redirect to the parent process - cerr << "Couldn't exec \"" << cmd << "\" : " - << strerror(errno) << endl; - exit(ret_code); - } - - default:; - // parent: we do not write on these fd. - close(pstdout[1]); - close(pstderr[1]); - forked = true; - break; - } - - fd1 = pstdout[0]; - fd2 = pstderr[0]; - - is_terminated = false; - - return; -} - - -bool child_reader::block_read() -{ - fd_set read_fs; - - FD_ZERO(&read_fs); - FD_SET(fd1, &read_fs); - FD_SET(fd2, &read_fs); - - if (select(max(fd1, fd2) + 1, &read_fs, 0, 0, 0) >= 0) { - if (FD_ISSET(fd1, &read_fs)) { - ssize_t temp = read(fd1, buf1, PIPE_BUF); - if (temp >= 0) - end1 = temp; - else - end1 = 0; - } - - if (FD_ISSET(fd2, &read_fs)) { - if (end2 >= sz_buf2) { - sz_buf2 = sz_buf2 ? sz_buf2 * 2 : PIPE_BUF; - buf2 = (char *)xrealloc(buf2, sz_buf2); - } - - ssize_t temp = read(fd2, buf2 + end2, sz_buf2 - end2); - if (temp > 0) - end2 += temp; - } - } - - bool ret = !(end1 == 0 && end2 == 0); - - if (end1 == -1) - end1 = 0; - if (end2 == -1) - end2 = 0; - - return ret; -} - - -bool child_reader::getline(string & result) -{ - // some stl lacks string::clear() - result.erase(result.begin(), result.end()); - - bool ok = true; - bool ret = true; - bool can_stop = false; - do { - int temp = end2; - if (pos1 >= end1) { - pos1 = 0; - ret = block_read(); - } - - // for efficiency try to copy as much as we can of data - ssize_t temp_pos = pos1; - while (temp_pos < end1 && ok) { - char ch = buf1[temp_pos++]; - if (ch == '\n') - ok = false; - } - - // !ok ==> endl has been read so do not copy it. - result.append(&buf1[pos1], (temp_pos - pos1) - !ok); - - if (!ok || !end1) - can_stop = true; - - // reading zero byte from stdout don't mean than we exhausted - // all stdout output, we must continue to try until reading - // stdout and stderr return zero byte. - if (ok && temp != end2) - can_stop = false; - - pos1 = temp_pos; - } while (!can_stop); - - // Is this correct ? - return end1 != 0 || result.length() != 0; -} - - -bool child_reader::get_data(ostream & out, ostream & err) -{ - bool ret = true; - while (ret) { - ret = block_read(); - - out.write(buf1, end1); - err.write(buf2, end2); - - end1 = end2 = 0; - } - - return first_error == 0; -} - - -int child_reader::terminate_process() -{ - // can be called explicitely or by dtor, - // we must protect against multiple call - if (!is_terminated) { - int ret; - waitpid(pid, &ret, 0); - - is_terminated = true; - - if (WIFEXITED(ret)) { - first_error = WEXITSTATUS(ret) | WIFSIGNALED(ret); - } else if (WIFSIGNALED(ret)) { - terminate_on_exception = true; - first_error = WTERMSIG(ret); - } else { - // FIXME: this seems impossible, waitpid *must* wait - // and either the process terminate normally or through - // a signal. - first_error = -1; - } - } - - if (fd1 != -1) { - close(fd1); - fd1 = -1; - } - if (fd2 != -1) { - close(fd2); - fd2 = -1; - } - - return first_error; -} - - -string child_reader::error_str() const -{ - ostringstream err; - if (!forked) { - err << string("unable to fork, error: ") - << strerror(first_error); - } else if (is_terminated) { - if (first_error) { - if (terminate_on_exception) { - err << process_name << " terminated by signal " - << first_error; - } else { - err << process_name << " return " - << first_error; - } - } - } - - return err.str(); -} diff --git a/libutil++/child_reader.h b/libutil++/child_reader.h deleted file mode 100644 index f3bf71a..0000000 --- a/libutil++/child_reader.h +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @file child_reader.h - * Facility for reading from child processes - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef CHILD_READER_H -#define CHILD_READER_H - -#include <sys/types.h> - -#include <vector> -#include <string> - -/** - * a class to read stdout / stderr from a child process. - * - * two interfaces are provided. read line by line: getline() or read all data - * in one : get_data(). In all case get_data() must be called once to flush the - * stderr child output - */ -/* - * FIXME: code review is needed: - * - check the getline()/get_data()/block_read() interface. - * the expected behavior is: - * caller can call getline until nothing is available from the stdout of the - * child. in this case child stderr is acumulated in buf2 and can be read - * through get_data(). get_data() is blocking until the child close stderr / - * stdout (even if the child die by a signal ?). The following corner case must - * work but I'm unsure if the code reflect this behavior: the last line of the - * child stdout have not necessarilly a LF terminator. the child can output any - * size of data in stderr. - */ -class child_reader { -public: - /** fork a process. use error() to get error code. Do not try to - * use other public member interface if error() return non-zero */ - child_reader(std::string const & cmd, - std::vector<std::string> const & args); - - /** wait for the termination of the child process if this have not - * already occur. In this case return code of the child process is not - * available. */ - ~child_reader(); - - /** fill result from on line of stdout of the child process. - * must be used as: - * child_reader reader(...); - * while (reader.getline(line)) .... */ - bool getline(std::string & result); - - /** fill out / err with the stdout / stderr of the child process. - * You can call this after calling one or more time getline(...). This - * call is blocking until the child die and so on all subsequent - * call will fail */ - bool get_data(std::ostream & out, std::ostream & err); - - /** rather to rely on dtor to wait for the termination of the child you - * can use terminate_process() to get the return code of the child - * process */ - int terminate_process(); - - /** return the status of the first error encoutered - * != 0 : something feel wrong, use error_str() to get an error - * message */ - int error() const { return first_error; } - - /** - * return an error message if appropriate, if the process has - * been successfully exec'ed and is not terminate the error message - * is always empty. Error message is also empty if the child process - * terminate successfully. Else three type of error message exist: - * - "unable to fork" followed by sterror(errno) - * - "process_name return xxx" xxx is return code - * - "process_name terminated by signal xxx" xxx is signal number - */ - std::string error_str() const; - -private: - // ctor helper: create the child process. - void exec_command(std::string const & cmd, - std::vector<std::string> const & args); - // return false when eof condition is reached on fd1. fd2 can have - // already input in the pipe buffer or in buf2. - bool block_read(); - - int fd1; - int fd2; - ssize_t pos1; - ssize_t end1; - ssize_t pos2; - ssize_t end2; - pid_t pid; - int first_error; - // child stderr is handled especially, we need to retain data even - // if caller read only stdout of the child. - char * buf2; - ssize_t sz_buf2; - char * buf1; - std::string process_name; - bool is_terminated; - bool terminate_on_exception; - bool forked; -}; - -#endif // CHILD_READER_H diff --git a/libutil++/comma_list.h b/libutil++/comma_list.h deleted file mode 100644 index 1868ee0..0000000 --- a/libutil++/comma_list.h +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @file comma_list.h - * Container holding items from a list of comma separated items - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - */ - -#ifndef COMMA_LIST_H -#define COMMA_LIST_H - -#include <string> -#include <vector> - -#include "string_manip.h" - -/** - * hold a list of item of type T, tracking also if item has been set. - */ -template <class T> -class comma_list -{ -public: - comma_list(); - - /** - * @param str list of comma separated item - * - * setup items array according to str parameters. Implement PP:3.17 - * w/o restriction on charset and with the special string all which - * match anything. - */ - void set(std::string const & str); - - /// return true if a specific value is held by this container - bool is_set() const { - return !is_all; - } - - /** - * @param value the value to test - * - * return true if value match one the stored value in items - */ - bool match(T const & value) const; - -private: - typedef T value_type; - typedef std::vector<value_type> container_type; - typedef typename container_type::const_iterator const_iterator; - bool is_all; - container_type items; -}; - - -template <class T> -comma_list<T>::comma_list() - : is_all(true) -{ -} - - -template <class T> -void comma_list<T>::set(std::string const & str) -{ - items.clear(); - - is_all = false; - - std::vector<std::string> result = separate_token(str, ','); - for (size_t i = 0 ; i < result.size() ; ++i) { - if (result[i] == "all") { - is_all = true; - items.clear(); - break; - } - items.push_back(op_lexical_cast<T>(result[i])); - } -} - - -template <class T> -bool comma_list<T>::match(T const & value) const -{ - if (is_all) - return true; - - const_iterator cit = items.begin(); - const_iterator const end = items.end(); - - for (; cit != end; ++cit) { - if (value == *cit) - return true; - } - - return false; -} - - -#endif /* !COMMA_LIST_H */ diff --git a/libutil++/cverb.cpp b/libutil++/cverb.cpp deleted file mode 100644 index 247794c..0000000 --- a/libutil++/cverb.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @file cverb.cpp - * verbose output stream - * - * @remark Copyright 2002, 2004 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <fstream> -#include <iostream> -#include <map> -#include <string> - -#include "cverb.h" - -using namespace std; - -cverb_object cverb; -verbose vlevel1("level1"); -verbose vdebug("debug"); -verbose vstats("stats"); -verbose vsfile("sfile"); - -namespace { - -// The right way is to use: ofstream fout; but cverb(fout.rdbuf()) receive -// a null pointer and stl shipped with 2.91 segfault. -ofstream fout("/dev/null"); -ostream null_stream(fout.rdbuf()); - -// Used to setup the bad bit in our null stream so output will fail earlier -// and overhead will be smaller. -struct setup_stream { - setup_stream(); -}; - -setup_stream::setup_stream() -{ - null_stream.clear(ios::badbit); -} - -setup_stream setup; - -// We use a multimap because user can create multiple verbose object with -// the same name, these are synonymous, setting up one to true will setup -// all with the same name to true. -typedef multimap<string, verbose *> recorder_t; -// The recorder is lazilly created by verbose object ctor -static recorder_t * object_map; - -} // anonymous namespace - - -verbose::verbose(char const * name) - : - set(false) -{ - // all params is treated a part, there is no need to create a - // verbose all("all"); it's meaningless. "all" verbose named object is - // reserved. - if (strcmp(name, "all") == 0) - return; - if (!object_map) - object_map = new recorder_t; - object_map->insert(recorder_t::value_type(name, this)); -} - - -verbose verbose::operator|(verbose const & rhs) -{ - verbose result(*this); - result.set = result.set || rhs.set; - return result; -} - - -verbose verbose::operator&(verbose const & rhs) -{ - verbose result(*this); - result.set = result.set && rhs.set; - return result; -} - - -bool verbose::setup(string const & name) -{ - if (name == "all") { - null_stream.rdbuf(cout.rdbuf()); - null_stream.clear(); - return true; - } - if (!object_map) - object_map = new recorder_t; - pair<recorder_t::iterator, recorder_t::iterator> p_it = - object_map->equal_range(name); - if (p_it.first == p_it.second) - return false; - for (; p_it.first != p_it.second; ++p_it.first) - p_it.first->second->set = true; - return true; -} - - -bool verbose::setup(vector<string> const & names) -{ - for (size_t i = 0; i < names.size(); ++i) - if (!setup(names[i])) - return false; - return true; -} - - -ostream& operator<<(cverb_object &, verbose const & v) -{ - return v.set ? cout : null_stream; -} diff --git a/libutil++/cverb.h b/libutil++/cverb.h deleted file mode 100644 index 6e71dc3..0000000 --- a/libutil++/cverb.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file cverb.h - * verbose output stream - * - * @remark Copyright 2002, 2004 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef CVERB_H -#define CVERB_H - -#include <iosfwd> -#include <string> -#include <vector> - -struct cverb_object { }; - -/** - * verbose object, all output through this stream are made only - * if a verbose object with a true state is injected in the stream. - */ -extern cverb_object cverb; - -/** - * typical use: - * declare some verbose global object: - * verbose debug("debug"); - * verbose stats("stats"); - * verbose level2("level2"); - * - * setup from command line the state of these objects - * - * verbose::setup(command_line_args_to'--verbose='); - * - * cverb << stats << "stats\n"; - * cverb << (stats&level2) << "very verbose stats\n" - * cverb << (stats|debug) << "bar\n"; - * these will give a compile time error - * cverb << stats << "foo" << debug << "bar"; - * cout << stats << "foo"; - * - * In critical code path cverb can be used in the more efficient way: - * if (cverb << vdebug) - * cverb << vdebug << "foo" << "bar"; - * the condition test the fails bit for the returned stream while the later - * build a sentry object for each << (more efficient even with one level of <<) - */ -class verbose { - /// The returned stream is either a null stream or cout. - friend std::ostream & operator<<(cverb_object &, verbose const &); -public: - /** - * create a verbose object named name, the ctor auto-register name - * as a verbose object, the set state can be intialized through - * verbose::setup(name) - */ - verbose(char const * name); - - verbose operator|(verbose const &); - verbose operator&(verbose const &); - - /// Return false if this named verbose object has not be registred. - static bool setup(std::string const &); - /// convenient interface calling the above for string in args - static bool setup(std::vector<std::string> const & args); -private: - bool set; -}; - -/** - * predefined general purpose verbose object, comment give their names - */ -extern verbose vlevel1; /**< named "level1" */ -extern verbose vdebug; /**< named "debug" */ -extern verbose vstats; /**< named "stats" */ -// all sample filename manipulation. -extern verbose vsfile; /**< named "sfile" */ - -#endif /* !CVERB_H */ diff --git a/libutil++/file_manip.cpp b/libutil++/file_manip.cpp deleted file mode 100644 index 0d35acd..0000000 --- a/libutil++/file_manip.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * @file file_manip.cpp - * Useful file management helpers - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <unistd.h> -#include <sys/stat.h> -#include <dirent.h> -#include <fnmatch.h> - -#include <cstdio> -#include <cerrno> -#include <iostream> -#include <vector> - -#include "op_file.h" - -#include "file_manip.h" -#include "string_manip.h" - -using namespace std; - - -bool copy_file(string const & source, string const & destination) -{ - struct stat buf; - int status = stat(source.c_str(), &buf); - - if (status == 0) { - /* FIXME: This code should avoid using system() if possible. */ - string copy_command("cp -a -f " + source + " " + destination); - status = system(copy_command.c_str()); - } - return !status; -} - - -bool is_directory(string const & dirname) -{ - struct stat st; - return !stat(dirname.c_str(), &st) && S_ISDIR(st.st_mode); -} - - -bool is_files_identical(string const & file1, string const & file2) -{ - struct stat st1; - struct stat st2; - - if (stat(file1.c_str(), &st1) == 0 && stat(file2.c_str(), &st2) == 0) { - if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) - return true; - } - - return false; -} - - -string const op_realpath(string const & name) -{ - static char tmp[PATH_MAX]; - if (!realpath(name.c_str(), tmp)) - return name; - return string(tmp); -} - - -bool op_file_readable(string const & file) -{ - return op_file_readable(file.c_str()); -} - -inline static bool is_directory_name(char const * name) -{ - return name[0] == '.' && - (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0')); -} - - -bool create_file_list(list<string> & file_list, string const & base_dir, - string const & filter, bool recursive) -{ - DIR * dir; - struct dirent * ent; - - if (!(dir = opendir(base_dir.c_str()))) - return false; - - while ((ent = readdir(dir)) != 0) { - if (!is_directory_name(ent->d_name) && - fnmatch(filter.c_str(), ent->d_name, 0) != FNM_NOMATCH) { - if (recursive) { - struct stat stat_buffer; - string name = base_dir + '/' + ent->d_name; - if (stat(name.c_str(), &stat_buffer) == 0) { - if (S_ISDIR(stat_buffer.st_mode) && - !S_ISLNK(stat_buffer.st_mode)) { - // recursive retrieve - create_file_list(file_list, - name, filter, - recursive); - } else { - file_list.push_back(name); - } - } - } else { - file_list.push_back(ent->d_name); - } - } - } - - closedir(dir); - - return true; -} - - -/** - * @param path_name the path where we remove trailing '/' - * - * erase all trailing '/' in path_name except if the last '/' is at pos 0 - */ -static string erase_trailing_path_separator(string const & path_name) -{ - string result(path_name); - - while (result.length() > 1) { - if (result[result.length() - 1] != '/') - break; - result.erase(result.length() - 1, 1); - } - - return result; -} - - -string op_dirname(string const & file_name) -{ - string result = erase_trailing_path_separator(file_name); - if (result.find_first_of('/') == string::npos) - return "."; - - // catch result == "/" - if (result.length() == 1) - return result; - - size_t pos = result.find_last_of('/'); - - // "/usr" must return "/" - if (pos == 0) - pos = 1; - - result.erase(pos, result.length() - pos); - - // "////usr" must return "/" - return erase_trailing_path_separator(result); -} - - -string op_basename(string const & path_name) -{ - string result = erase_trailing_path_separator(path_name); - - // catch result == "/" - if (result.length() == 1) - return result; - - return erase_to_last_of(result, '/'); -} diff --git a/libutil++/file_manip.h b/libutil++/file_manip.h deleted file mode 100644 index ce4154f..0000000 --- a/libutil++/file_manip.h +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @file file_manip.h - * Useful file management helpers - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef FILE_MANIP_H -#define FILE_MANIP_H - -#include <string> -#include <list> - - -/** - * copy_file - copy a file or subtree - * @param source filename to copy from - * @param destination filename to copy into - * - * return true if copying successful - */ -bool copy_file(std::string const & source, std::string const & destination); - -/// return true if dir is an existing directory -bool is_directory(std::string const & dirname); - -/** - * is_file_identical - check for identical files - * @param file1 first filename - * @param file2 second filename - * - * return true if the two filenames belong to the same file - */ -bool is_files_identical(std::string const & file1, std::string const & file2); - -/** - * op_realpath - resolve symlinks etc. - * Resolve a path as much as possible. Accounts for relative - * paths (from cwd), ".." and ".". For success, the target - * file must exist ! - * - * Resolve a symbolic link as far as possible. - * Returns the original string on failure. - */ -std::string const op_realpath(std::string const & name); - -/// return true if the given file is readable -bool op_file_readable(std::string const & file); - -/** - * @param file_list where to store result - * @param base_dir directory from where lookup start - * @param filter a filename filter - * @param recursive if true lookup in sub-directory - * - * create a filelist under base_dir, filtered by filter and optionally - * looking in sub-directory. If we look in sub-directory only sub-directory - * which match filter are traversed. - */ -bool create_file_list(std::list<std::string> & file_list, - std::string const & base_dir, - std::string const & filter = "*", - bool recursive = false); - -/** - * op_dirname - get the path component of a filename - * @param file_name filename - * - * Returns the path name of a filename with trailing '/' removed. - */ -std::string op_dirname(std::string const & file_name); - -/** - * op_basename - get the basename of a path - * @param path_name path - * - * Returns the basename of a path with trailing '/' removed. - * - * Always use this instead of the C basename() - header order - * can affect behaviour for basename("/") - */ -std::string op_basename(std::string const & path_name); - -#endif /* !FILE_MANIP_H */ diff --git a/libutil++/generic_spec.h b/libutil++/generic_spec.h deleted file mode 100644 index 18bff51..0000000 --- a/libutil++/generic_spec.h +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @file generic_spec.h - * Container holding an item or a special "match all" item - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#ifndef GENERIC_SPEC_H -#define GENERIC_SPEC_H - -#include <stdexcept> -#include <string> -#include <sstream> - -#include "string_manip.h" - - -/** - * used to hold something like { int cpu_nr, bool is_all }; - * to store a sub part of a samples filename see PP:3.21. - */ -template <class T> -class generic_spec -{ -public: - /** - * build a default spec which match anything - */ - generic_spec(); - - /// build a spec from a string, valid argument are "all" - /// or a string convertible to T through istringtream(str) >> data - /// conversion is strict, no space are allowed at begin or end of str - void set(std::string const &); - - /// return true if a specific value is held by this container - bool is_set() const { - return !is_all; - } - - /// return the specific value (only if is_set() == true) - T const value() const { - if (!is_all) - return data; - throw std::out_of_range("generic_spec holds no value"); - } - - /// return true if rhs match this spec. Sub part of PP:3.24 - bool match(T const & rhs) const { - return rhs == data; - } - - /// return true if rhs match this spec. Sub part of PP:3.24 - bool match(generic_spec<T> const & rhs) const { - return is_all || rhs.is_all || rhs.data == data; - } - -private: - T data; - bool is_all; -}; - - -template <class T> -generic_spec<T>::generic_spec() - : - data(T()), - is_all(true) -{ -} - - -template <class T> -void generic_spec<T>::set(std::string const & str) -{ - if (str == "all") { - is_all = true; - return; - } - - is_all = false; - data = op_lexical_cast<T>(str); -} - - -/// We don't use generic_spec<string>, since it's probably an error to try -/// to use generic_spec<string> we specialize but don't define it to get a -/// link error (using generic_spec<string> is problematic because g.set("all") -/// is ambiguous) -template <> -void generic_spec<std::string>::set(std::string const & str); - -#endif /* !GENERIC_SPEC_H */ diff --git a/libutil++/glob_filter.cpp b/libutil++/glob_filter.cpp deleted file mode 100644 index e44549f..0000000 --- a/libutil++/glob_filter.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @file glob_filter.cpp - * Filter strings based on globbed exclude/include list - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <fnmatch.h> - -#include <algorithm> - -#include "glob_filter.h" -#include "string_manip.h" - -using namespace std; - -bool glob_filter::fnmatcher::operator()(string const & s) -{ - return fnmatch(s.c_str(), str_.c_str(), 0) != FNM_NOMATCH; -} - - -bool glob_filter::match(string const & str) const -{ - vector<string>::const_iterator cit; - cit = find_if(exclude.begin(), exclude.end(), fnmatcher(str)); - if (cit != exclude.end()) - return false; - - cit = find_if(include.begin(), include.end(), fnmatcher(str)); - if (include.empty() || cit != include.end()) - return true; - - return false; -} diff --git a/libutil++/glob_filter.h b/libutil++/glob_filter.h deleted file mode 100644 index 6887cbf..0000000 --- a/libutil++/glob_filter.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file glob_filter.h - * Filter strings based on globbed exclude/include list - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef GLOB_FILTER_H -#define GLOB_FILTER_H - -#include "string_filter.h" - -/** - * glob_filter - filtering of a string based on globbed include/exclude list - * - * This class is an oracle on whether a particular string matches - * the given list of included and excluded strings. - * - * This class gives glob-based matches on each pattern, as with fnmatch(3) - */ -class glob_filter : public string_filter { -public: - /** - * Initialise the filter with the include and exclude list, - * comma-separated. - */ - glob_filter(std::string const & include_patterns, - std::string const & exclude_patterns) - : string_filter(include_patterns, exclude_patterns) {} - - /** - * Initialise the filter with the include and exclude list. - */ - glob_filter(std::vector<std::string> const & include_patterns, - std::vector<std::string> const & exclude_patterns) - : string_filter(include_patterns, exclude_patterns) {} - - /// Returns true if the given string matches - virtual bool match(std::string const & str) const; - -protected: - - /// function object for fnmatching - struct fnmatcher { - fnmatcher(std::string const & str) : str_(str) {} - - bool operator()(std::string const & s); - - std::string const & str_; - }; -}; - -#endif /* GLOB_FILTER_H */ diff --git a/libutil++/growable_vector.h b/libutil++/growable_vector.h deleted file mode 100644 index afc73f2..0000000 --- a/libutil++/growable_vector.h +++ /dev/null @@ -1,105 +0,0 @@ -/** - * @file growable_vector.h - * Auto-expanding vector type - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#ifndef GROWABLE_VECTOR_H -#define GROWABLE_VECTOR_H - -#include <vector> -#include <algorithm> -#include <functional> - -/** - * A simple growable vector template. - */ -template <typename T> class growable_vector { -public: - typedef std::vector<T> container_type; - typedef typename container_type::size_type size_type; - - - /** - * Index into the vector for a value. An out of - * bounds index will return a default-constructed value. - */ - T operator[](size_type index) const { - if (index >= container.size()) - return 0; - return container[index]; - } - - - /** - * Index into the vector for a value. If the index is larger than - * the current max index, the array is expanded, default-filling - * any intermediary gaps. - */ - T & operator[](size_type index) { - if (index >= container.size()) - container.resize(index + 1); - return container[index]; - } - - - /** - * vectorized += operator - */ - growable_vector<T> & operator+=(growable_vector<T> const & rhs) { - if (rhs.container.size() > container.size()) - container.resize(rhs.container.size()); - - size_type min_size = min(container.size(), rhs.container.size()); - for (size_type i = 0 ; i < min_size; ++i) - container[i] += rhs.container[i]; - - return *this; - } - - - /** - * vectorized -= operator, overflow shouldn't occur during substraction - * (iow: for each components lhs[i] >= rhs[i] - */ - growable_vector<T> & operator-=(growable_vector<T> const & rhs) { - if (rhs.container.size() > container.size()) - container.resize(rhs.container.size()); - - size_type min_size = min(container.size(), rhs.container.size()); - for (size_type i = 0 ; i < min_size; ++i) - container[i] -= rhs.container[i]; - - return *this; - } - - - /// return current size of vector - size_type size() const { - return container.size(); - } - - - /// fill container with given value - void fill(size_type size, T const & value) { - container.resize(size, value); - } - - - /// return true if all elements have the default constructed value - bool zero() const { - return std::find_if(container.begin(), container.end(), - std::bind2nd(std::not_equal_to<T>(), T())) - == container.end(); - } - -private: - container_type container; -}; - -#endif // GROWABLE_VECTOR_H diff --git a/libutil++/op_bfd.cpp b/libutil++/op_bfd.cpp deleted file mode 100644 index f1bef78..0000000 --- a/libutil++/op_bfd.cpp +++ /dev/null @@ -1,429 +0,0 @@ -/** - * @file op_bfd.cpp - * Encapsulation of bfd objects - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include "op_file.h" -#include "op_config.h" -#include "config.h" - -#include <fcntl.h> -#include <sys/stat.h> - -#include <cstdlib> - -#include <algorithm> -#include <iostream> -#include <iomanip> -#include <sstream> - -#include "op_bfd.h" -#include "string_filter.h" -#include "stream_util.h" -#include "cverb.h" - -using namespace std; - - -verbose vbfd("bfd"); - - -namespace { - -/// function object for filtering symbols to remove -struct remove_filter { - remove_filter(string_filter const & filter) - : filter_(filter) {} - - bool operator()(op_bfd_symbol const & symbol) { - return !filter_.match(symbol.name()); - } - - string_filter filter_; -}; - - -} // namespace anon - - -op_bfd_symbol::op_bfd_symbol(asymbol const * a) - : bfd_symbol(a), symb_value(a->value), - section_filepos(a->section->filepos), - section_vma(a->section->vma), - symb_size(0), symb_hidden(false), symb_weak(false) -{ - // Some sections have unnamed symbols in them. If - // we just ignore them then we end up sticking - // things like .plt hits inside of _init. So instead - // we name the symbol after the section. - if (a->name && a->name[0] != '\0') { - symb_name = a->name; - symb_weak = a->flags & BSF_WEAK; - symb_hidden = (a->flags & BSF_LOCAL) - && !(a->flags & BSF_GLOBAL); - } else { - symb_name = string("??") + a->section->name; - } -} - - -op_bfd_symbol::op_bfd_symbol(bfd_vma vma, size_t size, string const & name) - : bfd_symbol(0), symb_value(vma), - section_filepos(0), section_vma(0), - symb_size(size), symb_name(name) -{ -} - - -bool op_bfd_symbol::operator<(op_bfd_symbol const & rhs) const -{ - return filepos() < rhs.filepos(); -} - - -op_bfd::op_bfd(string const & archive, string const & fname, - string_filter const & symbol_filter, bool & ok) - : - filename(fname), - archive_path(archive), - file_size(-1) -{ - int fd; - struct stat st; - // after creating all symbol it's convenient for user code to access - // symbols through a vector. We use an intermediate list to avoid a - // O(N²) behavior when we will filter vector element below - symbols_found_t symbols; - asection const * sect; - - string const image_path = archive_path + filename; - - cverb << vbfd << "op_bfd ctor for " << image_path << endl; - - // if there's a problem already, don't try to open it - if (!ok) - goto out_fail; - - fd = open(image_path.c_str(), O_RDONLY); - if (fd == -1) { - cverb << vbfd << "open failed for " << image_path << endl; - ok = false; - goto out_fail; - } - - if (fstat(fd, &st)) { - cverb << vbfd << "stat failed for " << image_path << endl; - ok = false; - goto out_fail; - } - - file_size = st.st_size; - - ibfd.abfd = fdopen_bfd(image_path, fd); - - if (!ibfd.valid()) { - cverb << vbfd << "fdopen_bfd failed for " << image_path << endl; - ok = false; - goto out_fail; - } - - // find .text and use it - for (sect = ibfd.abfd->sections; sect; sect = sect->next) { - if (sect->flags & SEC_CODE) { - if (filepos_map[sect->name] != 0) { - cerr << "Found section \"" << sect->name - << "\" twice for " << get_filename() - << endl; - abort(); - } - - filepos_map[sect->name] = sect->filepos; - } - } - - get_symbols(symbols); - -out: - add_symbols(symbols, symbol_filter); - return; -out_fail: - ibfd.close(); - dbfd.close(); - // make the fake symbol fit within the fake file - file_size = -1; - goto out; -} - - -op_bfd::~op_bfd() -{ -} - - -unsigned long const op_bfd::get_start_offset(bfd_vma vma) const -{ - if (!vma || !ibfd.valid()) { - filepos_map_t::const_iterator it = filepos_map.find(".text"); - if (it != filepos_map.end()) - return it->second; - return 0; - } - - for (asection * sect = ibfd.abfd->sections; sect; sect = sect->next) { - if (sect->vma == vma) - return sect->filepos; - } - - return 0; -} - - -void op_bfd::get_symbols(op_bfd::symbols_found_t & symbols) -{ - ibfd.get_symbols(); - - // On separate debug file systems, the main bfd has no symbols, - // so even for non -g reports, we want to process the dbfd. - // This hurts us pretty badly (the CRC), but we really don't - // have much choice at the moment. - has_debug_info(); - - dbfd.get_symbols(); - - size_t i; - for (i = 0; i < ibfd.nr_syms; ++i) { - if (interesting_symbol(ibfd.syms[i])) - symbols.push_back(op_bfd_symbol(ibfd.syms[i])); - } - - for (i = 0; i < dbfd.nr_syms; ++i) { - if (!interesting_symbol(dbfd.syms[i])) - continue; - - // need to use filepos of original file's section for - // debug file symbols. We probably need to be more - // careful for special symbols which have ->section from - // .rodata like *ABS* - u32 filepos = filepos_map[dbfd.syms[i]->section->name]; - if (filepos != 0) - dbfd.syms[i]->section->filepos = filepos; - symbols.push_back(op_bfd_symbol(dbfd.syms[i])); - } - - symbols.sort(); - - symbols_found_t::iterator it = symbols.begin(); - - // we need to ensure than for a given vma only one symbol exist else - // we read more than one time some samples. Fix #526098 - for (; it != symbols.end();) { - symbols_found_t::iterator temp = it; - ++temp; - if (temp != symbols.end() && (it->vma() == temp->vma())) { - if (boring_symbol(*it, *temp)) { - it = symbols.erase(it); - } else { - symbols.erase(temp); - } - } else { - ++it; - } - } - - // now we can calculate the symbol size, we can't first include/exclude - // symbols because the size of symbol is calculated from the difference - // between the vma of a symbol and the next one. - for (it = symbols.begin() ; it != symbols.end(); ++it) { - op_bfd_symbol const * next = 0; - symbols_found_t::iterator temp = it; - ++temp; - if (temp != symbols.end()) - next = &*temp; - it->size(symbol_size(*it, next)); - } -} - - -void op_bfd::add_symbols(op_bfd::symbols_found_t & symbols, - string_filter const & symbol_filter) -{ - // images with no symbols debug info available get a placeholder symbol - if (symbols.empty()) - symbols.push_back(create_artificial_symbol()); - - cverb << vbfd << "number of symbols before filtering " - << dec << symbols.size() << hex << endl; - - symbols_found_t::iterator it; - it = remove_if(symbols.begin(), symbols.end(), - remove_filter(symbol_filter)); - - copy(symbols.begin(), it, back_inserter(syms)); - - cverb << vbfd << "number of symbols now " - << dec << syms.size() << hex << endl; -} - - -unsigned long op_bfd::sym_offset(symbol_index_t sym_index, u32 num) const -{ - /* take off section offset and symb value */ - return num - syms[sym_index].filepos(); -} - - -bfd_vma op_bfd::offset_to_pc(bfd_vma offset) const -{ - asection const * sect = ibfd.abfd->sections; - - for (; sect; sect = sect->next) { - if (offset >= bfd_vma(sect->filepos) && - (!sect->next || offset < bfd_vma(sect->next->filepos))) { - return sect->vma + (offset - sect->filepos); - } - } - - return 0; -} - - -bool op_bfd::has_debug_info() const -{ - if (debug_info.cached()) - return debug_info.get(); - - if (!ibfd.valid()) - return debug_info.reset(false); - - if (ibfd.has_debug_info()) - return debug_info.reset(true); - - // check to see if there is an .debug file - string const global(archive_path + DEBUGDIR); - string const image_path = archive_path + filename; - string const dirname(image_path.substr(0, image_path.rfind('/'))); - - if (find_separate_debug_file(ibfd.abfd, dirname, global, debug_filename)) { - cverb << vbfd << "now loading: " << debug_filename << endl; - dbfd.abfd = open_bfd(debug_filename); - if (dbfd.has_debug_info()) - return debug_info.reset(true); - } - - // .debug is optional, so will not fail if there's a problem - cverb << vbfd << "failed to process separate debug file " - << debug_filename << endl; - - return debug_info.reset(false); -} - - -bool op_bfd::get_linenr(symbol_index_t sym_idx, unsigned int offset, - string & source_filename, unsigned int & linenr) const -{ - if (!has_debug_info()) - return false; - - // FIXME: to test, I'm unsure if from this point we must use abfd - // or the check if (pc >= bfd_section_size(abfd, section)) must be done - // with ibfd. - bfd_info const & b = dbfd.valid() ? dbfd : ibfd; - - linenr_info const info = find_nearest_line(b, syms[sym_idx], offset); - - if (!info.found) - return false; - - source_filename = info.filename; - linenr = info.line; - return true; -} - - -size_t op_bfd::symbol_size(op_bfd_symbol const & sym, - op_bfd_symbol const * next) const -{ - unsigned long start = sym.filepos(); - unsigned long end = next ? next->filepos() : file_size; - - return end - start; -} - - -void op_bfd::get_symbol_range(symbol_index_t sym_idx, - unsigned long & start, unsigned long & end) const -{ - op_bfd_symbol const & sym = syms[sym_idx]; - - bool const verbose = cverb << (vbfd & vlevel1); - - start = sym.filepos(); - end = start + sym.size(); - - if (!verbose) - return; - - io_state state(cverb << (vbfd & vlevel1)); - - cverb << (vbfd & vlevel1) << "symbol " << sym.name() - << ", value " << hex << sym.value() << endl; - cverb << (vbfd & vlevel1) - << "start " << hex << start << ", end " << end << endl; - - if (sym.symbol()) { - cverb << (vbfd & vlevel1) << "in section " - << sym.symbol()->section->name << ", filepos " - << hex << sym.symbol()->section->filepos << endl; - } -} - - -void op_bfd::get_vma_range(bfd_vma & start, bfd_vma & end) const -{ - if (!syms.empty()) { - // syms are sorted by vma so vma of the first symbol and vma + - // size of the last symbol give the vma range for gprof output - op_bfd_symbol const & last_symb = syms[syms.size() - 1]; - start = syms[0].vma(); - // end is excluded from range so + 1 *if* last_symb.size() != 0 - end = last_symb.vma() + last_symb.size() + (last_symb.size() != 0); - } else { - start = 0; - end = file_size; - } -} - - -op_bfd_symbol const op_bfd::create_artificial_symbol() -{ - // FIXME: prefer a bool artificial; to this ?? - string symname = "?"; - - symname += get_filename(); - - bfd_vma start, end; - get_vma_range(start, end); - return op_bfd_symbol(start, end - start, symname); -} - - -string op_bfd::get_filename() const -{ - return filename; -} - - -size_t op_bfd::bfd_arch_bits_per_address() const -{ - if (ibfd.valid()) - return ::bfd_arch_bits_per_address(ibfd.abfd); - // FIXME: this function should be called only if the underlined ibfd - // is ok, must we throw ? - return sizeof(bfd_vma); -} diff --git a/libutil++/op_bfd.h b/libutil++/op_bfd.h deleted file mode 100644 index 701a1aa..0000000 --- a/libutil++/op_bfd.h +++ /dev/null @@ -1,253 +0,0 @@ -/** - * @file op_bfd.h - * Encapsulation of bfd objects - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef OP_BFD_H -#define OP_BFD_H - -#include "config.h" - -#include <vector> -#include <string> -#include <list> -#include <map> - -#include "bfd_support.h" -#include "utility.h" -#include "cached_value.h" -#include "op_types.h" - -class op_bfd; -class string_filter; - -/// all symbol vector indexing uses this type -typedef size_t symbol_index_t; - -/** - * A symbol description from a bfd point of view. This duplicate - * information pointed by an asymbol, we need this duplication in case - * the symbol is an artificial symbol - */ -class op_bfd_symbol { -public: - - /// ctor for real symbols - op_bfd_symbol(asymbol const * a); - - /// ctor for artificial symbols - op_bfd_symbol(bfd_vma vma, size_t size, std::string const & name); - - bfd_vma vma() const { return symb_value + section_vma; } - unsigned long value() const { return symb_value; } - unsigned long filepos() const { return symb_value + section_filepos; } - std::string const & name() const { return symb_name; } - asymbol const * symbol() const { return bfd_symbol; } - size_t size() const { return symb_size; } - void size(size_t s) { symb_size = s; } - bool hidden() const { return symb_hidden; } - bool weak() const { return symb_weak; } - - /// compare two symbols by their filepos() - bool operator<(op_bfd_symbol const & lhs) const; - -private: - /// the original bfd symbol, this can be null if the symbol is an - /// artificial symbol - asymbol const * bfd_symbol; - /// the offset of this symbol relative to the begin of the section's - /// symbol - unsigned long symb_value; - /// the section filepos for this symbol - unsigned long section_filepos; - /// the section vma for this symbol - bfd_vma section_vma; - /// the size of this symbol - size_t symb_size; - /// the name of the symbol - std::string symb_name; - /// normally not externally visible symbol - bool symb_hidden; - /// whether other symbols can override it - bool symb_weak; -}; - -/** - * Encapsulation of a bfd object. Simplifies open/close of bfd, enumerating - * symbols and retrieving informations for symbols or vma. - * - * Use of this class relies on a std::ostream cverb - */ -class op_bfd { -public: - /** - * @param archive_path oparchive prefix path - * @param filename the name of the image file - * @param symbol_filter filter to apply to symbols - * @param ok in-out parameter: on in, if not set, don't - * open the bfd (because it's not there or whatever). On out, - * it's set to false if the bfd couldn't be loaded. - */ - op_bfd(std::string const & archive_path, - std::string const & filename, - string_filter const & symbol_filter, - bool & ok); - - /// close an opened bfd image and free all related resources - ~op_bfd(); - - /** - * @param sym_idx index of the symbol - * @param offset fentry number - * @param filename output parameter to store filename - * @param linenr output parameter to store linenr. - * - * Retrieve the relevant finename:linenr information for the sym_idx - * at offset. If the lookup fails, return false. In some cases this - * function can retrieve the filename and return true but fail to - * retrieve the linenr and so can return zero in linenr - */ - bool get_linenr(symbol_index_t sym_idx, unsigned int offset, - std::string & filename, unsigned int & linenr) const; - - /** - * @param sym_idx symbol index - * @param start reference to start var - * @param end reference to end var - * - * Calculates the range of sample file entries covered by sym. start - * and end will be filled in appropriately. If index is the last entry - * in symbol table, all entries up to the end of the sample file will - * be used. After calculating start and end they are sanitized - * - * All errors are fatal. - */ - void get_symbol_range(symbol_index_t sym_idx, - unsigned long & start, unsigned long & end) const; - - /** - * sym_offset - return offset from a symbol's start - * @param num_symbols symbol number - * @param num number of fentry - * - * Returns the offset of a sample at position num - * in the samples file from the start of symbol sym_idx. - */ - unsigned long sym_offset(symbol_index_t num_symbols, u32 num) const; - - /** - * @param start reference to the start vma - * @param end reference to the end vma - * - * return in start, end the vma range for this binary object. - */ - void get_vma_range(bfd_vma & start, bfd_vma & end) const; - - /** return the relocated PC value for the given file offset */ - bfd_vma offset_to_pc(bfd_vma offset) const; - - /** - * If passed 0, return the file position of the .text section. - * Otherwise, return the filepos of a section with a matching - * vma. - */ - unsigned long const get_start_offset(bfd_vma vma = 0) const; - - /** - * Return the image name of the underlying binary image. For an - * archive, this returns the path *within* the archive, not the - * full path of the file. - */ - std::string get_filename() const; - - /// sorted vector by vma of interesting symbol. - std::vector<op_bfd_symbol> syms; - - /// return in bits the bfd_vma size for this binary. This is needed - /// because gprof output depend on the bfd_vma for *this* binary - /// and do not depend on sizeof(bfd_vma) - size_t bfd_arch_bits_per_address() const; - - /// return true if binary contain some debug information - bool has_debug_info() const; - -private: - /// temporary container type for getting symbols - typedef std::list<op_bfd_symbol> symbols_found_t; - - /** - * Parse and sort in ascending order all symbols - * in the file pointed to by abfd that reside in - * a %SEC_CODE section. - * - * The symbols are filtered through - * the interesting_symbol() predicate and sorted - * with op_bfd_symbol::operator<() comparator. - */ - void get_symbols(symbols_found_t & symbols); - - /** - * Helper function for get_symbols. - * Populates bfd_syms and extracts the "interesting_symbol"s. - */ - void get_symbols_from_file(bfd_info & bfd, size_t start, - op_bfd::symbols_found_t & symbols, - bool debug_file); - - /** - * Add the symbols in the binary, applying filtering, - * and handling artificial symbols. - */ - void add_symbols(symbols_found_t & symbols, - string_filter const & symbol_filter); - - /** - * symbol_size - return the size of a symbol - * @param sym symbol to get size - * @param next next symbol in vma order if any - */ - size_t symbol_size(op_bfd_symbol const & sym, - op_bfd_symbol const * next) const; - - /// create an artificial symbol for a symbolless binary - op_bfd_symbol const create_artificial_symbol(); - - /* Generate symbols using bfd functions for - * the image file associated with the ibfd arg. - */ - uint process_symtab(bfd_info * bfd, uint start); - - /// filename we open (not including archive path) - std::string filename; - - /// path to archive - std::string archive_path; - - /// file size in bytes - off_t file_size; - - /// corresponding debug file name - mutable std::string debug_filename; - - /// true if at least one section has (flags & SEC_DEBUGGING) != 0 - mutable cached_value<bool> debug_info; - - /// our main bfd object: .bfd may be NULL - bfd_info ibfd; - - // corresponding debug bfd object, if one is found - mutable bfd_info dbfd; - - typedef std::map<std::string, u32> filepos_map_t; - // mapping of section names to filepos in the original binary - filepos_map_t filepos_map; -}; - - -#endif /* !OP_BFD_H */ diff --git a/libutil++/op_exception.cpp b/libutil++/op_exception.cpp deleted file mode 100644 index 235b9bc..0000000 --- a/libutil++/op_exception.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @file op_exception.cpp - * exception base class - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <cstring> - -#include "op_exception.h" - -using namespace std; - -op_exception::op_exception(string const & msg) - : - message(msg) -{ -} - -op_exception::~op_exception() throw() -{ -} - -char const * op_exception::what() const throw() -{ - return message.c_str(); -} - - -op_fatal_error::op_fatal_error(string const & msg) - : - op_exception(msg) -{ -} - - -op_runtime_error::op_runtime_error(string const & msg) - : - runtime_error(msg) -{ -} - -op_runtime_error::op_runtime_error(string const & msg, int cerrno) - : - runtime_error(msg + "\ncause: " + strerror(cerrno)) -{ -} - -op_runtime_error::~op_runtime_error() throw() -{ -} diff --git a/libutil++/op_exception.h b/libutil++/op_exception.h deleted file mode 100644 index af344ed..0000000 --- a/libutil++/op_exception.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * @file op_exception.h - * exception base class - * - * This provide simple base class for exception object. All - * exception are derived from directly or indirectly from - * std::exception. This class are not itended to be catched - * in your code except at top level, derive what you want - * and catch derived class rather. - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef OP_EXCEPTION_H -#define OP_EXCEPTION_H - -#include <stdexcept> -#include <string> - - -/** - * exception abstract base class - */ -class op_exception : public std::exception { -public: - explicit op_exception(std::string const& msg); - ~op_exception() throw() = 0; - - char const * what() const throw(); -private: - std::string message; -}; - - -/** - * fatal exception, never catch it except at top level (likely main or - * gui). Intended to replace cerr << "blah"; exit(EXIT_FAILURE); by a - * throw op_fatal_error("blah") when returning error code is not an option - */ -struct op_fatal_error : op_exception -{ - explicit op_fatal_error(std::string const & msg); -}; - -/** - * Encapsulate a runtime error with or w/o a valid errno - */ -struct op_runtime_error : std::runtime_error -{ - explicit op_runtime_error(std::string const & err); - op_runtime_error(std::string const & err, int cerrno); - ~op_runtime_error() throw(); -}; - - -#endif /* !OP_EXCEPTION_H */ diff --git a/libutil++/path_filter.cpp b/libutil++/path_filter.cpp deleted file mode 100644 index 94db94e..0000000 --- a/libutil++/path_filter.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file path_filter.cpp - * Filter paths based on globbed exclude/include list - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <fnmatch.h> - -#include <algorithm> - -#include "path_filter.h" -#include "string_manip.h" -#include "file_manip.h" - -using namespace std; - -bool path_filter::match(string const & str) const -{ - vector<string>::const_iterator cit; - - // first, if any component of the dir is listed in exclude -> no - string comp = op_dirname(str); - while (!comp.empty() && comp != "/") { - cit = find_if(exclude.begin(), exclude.end(), - fnmatcher(op_basename(comp))); - if (cit != exclude.end()) - return false; - - // dirname("foo") == "foo" - if (comp == op_dirname(comp)) - break; - comp = op_dirname(comp); - } - - string const base = op_basename(str); - - // now if the file name is specifically excluded -> no - cit = find_if(exclude.begin(), exclude.end(), fnmatcher(base)); - if (cit != exclude.end()) - return false; - - // now if the file name is specifically included -> yes - cit = find_if(include.begin(), include.end(), fnmatcher(base)); - if (cit != include.end()) - return true; - - // now if any component of the path is included -> yes - // note that the include pattern defaults to '*' - string compi = op_dirname(str); - while (!compi.empty() && compi != "/") { - cit = find_if(include.begin(), include.end(), - fnmatcher(op_basename(compi))); - if (cit != include.end()) - return true; - - // dirname("foo") == "foo" - if (compi == op_dirname(compi)) - break; - compi = op_dirname(compi); - } - - return include.empty(); -} diff --git a/libutil++/path_filter.h b/libutil++/path_filter.h deleted file mode 100644 index 21203fb..0000000 --- a/libutil++/path_filter.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @file path_filter.h - * Filter paths based on globbed exclude/include list - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef PATH_FILTER_H -#define PATH_FILTER_H - -#include "glob_filter.h" - -/** - * path_filter - filtering of a string based on globbed include/exclude list - * - * This class is an oracle on whether a particular string matches - * the given list of included and excluded strings. - * - * This class gives glob-based matches on each pattern, as with fnmatch(3), - * where each component of the candidate path is considered separately. - */ -class path_filter : public glob_filter { -public: - /** - * Initialise the filter with the include and exclude list, - * comma-separated. - */ - path_filter(std::string const & include_patterns = std::string(), - std::string const & exclude_patterns = std::string()) - : glob_filter(include_patterns, exclude_patterns) {} - - /** - * Initialise the filter with the include and exclude list. - */ - path_filter(std::vector<std::string> const & include_patterns, - std::vector<std::string> const & exclude_patterns) - : glob_filter(include_patterns, exclude_patterns) {} - - - /// Returns true if the given string matches - virtual bool match(std::string const & str) const; -}; - -#endif /* PATH_FILTER_H */ diff --git a/libutil++/stream_util.cpp b/libutil++/stream_util.cpp deleted file mode 100644 index 750b0d3..0000000 --- a/libutil++/stream_util.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @file stream_util.cpp - * C++ stream utility - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include "stream_util.h" - -using namespace std; - -io_state::io_state(ios & stream_) - : - stream(stream_), - format(stream.flags()), - precision(stream.precision()), - fill(stream.fill()) -{ -} - - -io_state::~io_state() -{ - stream.flags(format); - stream.precision(precision); - stream.fill(fill); -} diff --git a/libutil++/stream_util.h b/libutil++/stream_util.h deleted file mode 100644 index 0ccee9a..0000000 --- a/libutil++/stream_util.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @file stream_util.h - * C++ stream utility - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef STREAM_UTIL_H -#define STREAM_UTIL_H - -#include <iostream> - -/// class which save a stream state and restore it at dtor time -class io_state { -public: - /** - * save the stream flags, precision and fill char. - * - * width is restored at end of expression, there is no need to save it. - * tie and locale are not saved currently - * - * error state shouldn't be saved. - */ - io_state(std::ios & stream); - /// restore the stream state - ~io_state(); -private: - std::ios & stream; - - std::ios::fmtflags format; - std::streamsize precision; - char fill; -}; - -#endif /* !STREAM_UTIL_H */ diff --git a/libutil++/string_filter.cpp b/libutil++/string_filter.cpp deleted file mode 100644 index 2a10cc6..0000000 --- a/libutil++/string_filter.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file string_filter.cpp - * Filter strings based on exclude/include list - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <algorithm> - -#include "string_filter.h" -#include "string_manip.h" - -using namespace std; - - -string_filter::string_filter(string const & include_patterns, - string const & exclude_patterns) - : include(separate_token(include_patterns, ',')), - exclude(separate_token(exclude_patterns, ',')) -{ -} - - -string_filter::string_filter(vector<string> const & include_patterns, - vector<string> const & exclude_patterns) - : include(include_patterns), - exclude(exclude_patterns) -{ -} - - -// FIXME: PP reference -bool string_filter::match(string const & str) const -{ - vector<string>::const_iterator cit; - cit = find(exclude.begin(), exclude.end(), str); - if (cit != exclude.end()) - return false; - - cit = find(include.begin(), include.end(), str); - if (include.empty() || cit != include.end()) - return true; - - return false; -} diff --git a/libutil++/string_filter.h b/libutil++/string_filter.h deleted file mode 100644 index c008fe3..0000000 --- a/libutil++/string_filter.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @file string_filter.h - * Filter strings based on exclude/include list - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef STRING_FILTER_H -#define STRING_FILTER_H - -#include <string> -#include <vector> - -/** - * string_filter - filtering of a string based on include/exclude list - * - * This class is an oracle on whether a particular string matches - * the given list of included and excluded strings. - * - * This base class gives a default exact-match semantics. - */ -class string_filter { -public: - string_filter() {} - - /** - * Initialise the filter with the include and exclude list, - * comma-separated. - */ - string_filter(std::string const & include_patterns, - std::string const & exclude_patterns); - - /** - * Initialise the filter with the include and exclude list. - */ - string_filter(std::vector<std::string> const & include_patterns, - std::vector<std::string> const & exclude_patterns); - - virtual ~string_filter() {} - - /// Returns true if the given string matches - virtual bool match(std::string const & str) const; - -protected: - /// include patterns - std::vector<std::string> include; - /// exclude patterns - std::vector<std::string> exclude; -}; - -#endif /* STRING_FILTER_H */ diff --git a/libutil++/string_manip.cpp b/libutil++/string_manip.cpp deleted file mode 100644 index d9e83b8..0000000 --- a/libutil++/string_manip.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/** - * @file string_manip.cpp - * std::string helpers - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#include <sstream> -#include <iomanip> - -#include <cstdlib> -#include <cmath> - -#include "string_manip.h" - -using namespace std; - - -string erase_to_last_of(string const & str, char ch) -{ - string result = str; - string::size_type pos = result.find_last_of(ch); - if (pos != string::npos) - result.erase(0, pos + 1); - - return result; -} - - -string split(string & s, char c) -{ - string::size_type i = s.find_first_of(c); - if (i == string::npos) - return string(); - - string const tail = s.substr(i + 1); - s = s.substr(0, i); - return tail; -} - - -bool is_prefix(string const & s, string const & prefix) -{ - // gcc 2.95 and below don't have this - // return s.compare(0, prefix.length(), prefix) == 0; - return s.find(prefix) == 0; -} - - -vector<string> separate_token(string const & str, char sep) -{ - vector<string> result; - string next; - - for (size_t pos = 0 ; pos != str.length() ; ++pos) { - char ch = str[pos]; - if (ch == '\\') { - if (pos < str.length() - 1 && str[pos + 1] == sep) { - ++pos; - next += sep; - } else { - next += '\\'; - } - } else if (ch == sep) { - result.push_back(next); - // some stl lacks string::clear() - next.erase(next.begin(), next.end()); - } else { - next += ch; - } - } - - if (!next.empty()) - result.push_back(next); - - return result; -} - - -string ltrim(string const & str, string const & totrim) -{ - string result(str); - - return result.erase(0, result.find_first_not_of(totrim)); -} - - -string rtrim(string const & str, string const & totrim) -{ - string result(str); - - return result.erase(result.find_last_not_of(totrim) + 1); -} - - -string trim(string const & str, string const & totrim) -{ - return rtrim(ltrim(str, totrim), totrim); -} - - -string const -format_percent(double value, size_t int_width, size_t fract_width, bool showpos) -{ - ostringstream os; - - if (value == 0.0) - return string(int_width + fract_width, ' ') + "0"; - - if (showpos) - os.setf(ios::showpos); - - if (fabs(value) > .001) { - // os << fixed << value unsupported by gcc 2.95 - os.setf(ios::fixed, ios::floatfield); - os << setw(int_width + fract_width + 1) - << setprecision(fract_width) << value; - } else { - // os << scientific << value unsupported by gcc 2.95 - os.setf(ios::scientific, ios::floatfield); - os << setw(int_width + fract_width + 1) - // - 3 to count exponent part - << setprecision(fract_width - 3) << value; - } - - string formatted = os.str(); - if (is_prefix(formatted, "100.")) - formatted.erase(formatted.size() - 1); - return formatted; -} - - -template <> -unsigned int op_lexical_cast<unsigned int, string>(string const & str) -{ - char* endptr; - - // 2.91.66 fix - unsigned long ret = 0; - ret = strtoul(str.c_str(), &endptr, 0); - if (*endptr) { - throw invalid_argument("op_lexical_cast(\""+ str +"\")"); - } - return ret; -} diff --git a/libutil++/string_manip.h b/libutil++/string_manip.h deleted file mode 100644 index 9fe74ce..0000000 --- a/libutil++/string_manip.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * @file string_manip.h - * std::string helpers - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef STRING_MANIP_H -#define STRING_MANIP_H - -#include <string> -#include <vector> -#include <sstream> -#include <stdexcept> - -/** - * @param str string - * @param ch the characterto search - * - * erase char from the begin of str to the last - * occurence of ch from and return the string - */ -std::string erase_to_last_of(std::string const & str, char ch); - -/// split string s by first occurence of char c, returning the second part. -/// s is set to the first part. Neither include the split character -std::string split(std::string & s, char c); - -/// return true if "prefix" is a prefix of "s", behavior is undefined -/// if prefix is an empty string -bool is_prefix(std::string const & s, std::string const & prefix); - -/** - * @param str the string to tokenize - * @param sep the separator_char - * - * separate fields in a string in a list of token; field are - * separated by the sep character, sep char can be escaped - * by '\\' to specify a sep char in a token, '\\' not followed - * by a sep is taken as it e.g. "\,\a" --> ",\a" - */ -std::vector<std::string> separate_token(std::string const & str, char sep); - -/// remove trim chars from start of input string return the new string -std::string ltrim(std::string const & str, std::string const & totrim = "\t "); -/// remove trim chars from end of input string return the new string -std::string rtrim(std::string const & str, std::string const & totrim = "\t "); -/// ltrim(rtrim(str)) -std::string trim(std::string const & str, std::string const & totrim = "\t "); - -/** - * format_percent - smart format of double percentage value - * @param value - the value - * @param int_width - the maximum integer integer width default to 2 - * @param frac_width - the fractionnary width default to 4 - * @param showpos - show + sign for positive values - * - * This formats a percentage into exactly the given width and returns - * it. If the integer part is larger than the given int_width, the - * returned string will be wider. The returned string is never - * shorter than (fract_with + int_width + 1) - * - */ -std::string const -format_percent(double value, size_t int_width, - size_t frac_width, bool showpos = false); - -/// prefered width to format percentage -static unsigned int const percent_int_width = 2; -static unsigned int const percent_fract_width = 4; -static unsigned int const percent_width = percent_int_width + percent_fract_width + 1; - - -/** - * @param src input parameter - * convert From src to a T through an istringstream. - * - * Throws invalid_argument if conversion fail. - * - * Note that this is not as foolproof as boost's lexical_cast - */ -template <typename To, typename From> -To op_lexical_cast(From const & src) -{ - std::ostringstream in; - if (!(in << src)) { - throw std::invalid_argument("op_lexical_cast<T>()"); - } - std::istringstream out(in.str()); - To value; - if (!(out >> value)) { - throw std::invalid_argument("op_lexical_cast<T>(\"" + - in.str() +"\")"); - } - return value; -} - -// specialization accepting hexadecimal and octal number in input. Note that -// op_lexical_cast<unsigned int>("0x23"); will fail because it call the -// non specialized template. -template <> -unsigned int op_lexical_cast<unsigned int>(std::string const & str); - -#endif /* !STRING_MANIP_H */ diff --git a/libutil++/tests/Makefile.am b/libutil++/tests/Makefile.am deleted file mode 100644 index fcc9a7d..0000000 --- a/libutil++/tests/Makefile.am +++ /dev/null @@ -1,49 +0,0 @@ - -REALPATH= readlink -f - -SRCDIR := $(shell $(REALPATH) $(topdir)/libutil++/tests/ ) - -AM_CPPFLAGS = \ - -I ${top_srcdir}/libutil++ -D SRCDIR="\"$(SRCDIR)/\"" - -COMMON_LIBS = ../libutil++.a ../../libutil/libutil.a - -LIBS = @LIBERTY_LIBS@ - -AM_CXXFLAGS = @OP_CXXFLAGS@ - -check_PROGRAMS = \ - string_manip_tests \ - string_filter_tests \ - comma_list_tests \ - file_manip_tests \ - glob_filter_tests \ - path_filter_tests \ - cached_value_tests \ - utility_tests - -string_manip_tests_SOURCES = string_manip_tests.cpp -string_manip_tests_LDADD = ${COMMON_LIBS} - -string_filter_tests_SOURCES = string_filter_tests.cpp -string_filter_tests_LDADD = ${COMMON_LIBS} - -glob_filter_tests_SOURCES = glob_filter_tests.cpp -glob_filter_tests_LDADD = ${COMMON_LIBS} - -path_filter_tests_SOURCES = path_filter_tests.cpp -path_filter_tests_LDADD = ${COMMON_LIBS} - -comma_list_tests_SOURCES = comma_list_tests.cpp -comma_list_tests_LDADD = ${COMMON_LIBS} - -file_manip_tests_SOURCES = file_manip_tests.cpp -file_manip_tests_LDADD = ${COMMON_LIBS} - -cached_value_tests_SOURCES = cached_value_tests.cpp -cached_value_tests_LDADD = ${COMMON_LIBS} - -utility_tests_SOURCES = utility_tests.cpp -utility_tests_LDADD = ${COMMON_LIBS} - -TESTS = ${check_PROGRAMS} diff --git a/libutil++/tests/Makefile.in b/libutil++/tests/Makefile.in deleted file mode 100644 index f5980df..0000000 --- a/libutil++/tests/Makefile.in +++ /dev/null @@ -1,586 +0,0 @@ -# Makefile.in generated by automake 1.9.5 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ -SOURCES = $(cached_value_tests_SOURCES) $(comma_list_tests_SOURCES) $(file_manip_tests_SOURCES) $(glob_filter_tests_SOURCES) $(path_filter_tests_SOURCES) $(string_filter_tests_SOURCES) $(string_manip_tests_SOURCES) $(utility_tests_SOURCES) - -srcdir = @srcdir@ -top_srcdir = @top_srcdir@ -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -top_builddir = ../.. -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -INSTALL = @INSTALL@ -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -check_PROGRAMS = string_manip_tests$(EXEEXT) \ - string_filter_tests$(EXEEXT) comma_list_tests$(EXEEXT) \ - file_manip_tests$(EXEEXT) glob_filter_tests$(EXEEXT) \ - path_filter_tests$(EXEEXT) cached_value_tests$(EXEEXT) \ - utility_tests$(EXEEXT) -subdir = libutil++/tests -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/binutils.m4 \ - $(top_srcdir)/m4/builtinexpect.m4 \ - $(top_srcdir)/m4/compileroption.m4 \ - $(top_srcdir)/m4/configmodule.m4 \ - $(top_srcdir)/m4/copyifchange.m4 $(top_srcdir)/m4/docbook.m4 \ - $(top_srcdir)/m4/extradirs.m4 $(top_srcdir)/m4/findkernel.m4 \ - $(top_srcdir)/m4/kerneloption.m4 \ - $(top_srcdir)/m4/kernelversion.m4 \ - $(top_srcdir)/m4/mallocattribute.m4 \ - $(top_srcdir)/m4/poptconst.m4 \ - $(top_srcdir)/m4/precompiledheader.m4 $(top_srcdir)/m4/qt.m4 \ - $(top_srcdir)/m4/resultyn.m4 $(top_srcdir)/m4/sstream.m4 \ - $(top_srcdir)/m4/typedef.m4 $(top_srcdir)/configure.in -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_HEADER = $(top_builddir)/config.h -CONFIG_CLEAN_FILES = -am_cached_value_tests_OBJECTS = cached_value_tests.$(OBJEXT) -cached_value_tests_OBJECTS = $(am_cached_value_tests_OBJECTS) -am__DEPENDENCIES_1 = ../libutil++.a ../../libutil/libutil.a -cached_value_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_comma_list_tests_OBJECTS = comma_list_tests.$(OBJEXT) -comma_list_tests_OBJECTS = $(am_comma_list_tests_OBJECTS) -comma_list_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_file_manip_tests_OBJECTS = file_manip_tests.$(OBJEXT) -file_manip_tests_OBJECTS = $(am_file_manip_tests_OBJECTS) -file_manip_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_glob_filter_tests_OBJECTS = glob_filter_tests.$(OBJEXT) -glob_filter_tests_OBJECTS = $(am_glob_filter_tests_OBJECTS) -glob_filter_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_path_filter_tests_OBJECTS = path_filter_tests.$(OBJEXT) -path_filter_tests_OBJECTS = $(am_path_filter_tests_OBJECTS) -path_filter_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_string_filter_tests_OBJECTS = string_filter_tests.$(OBJEXT) -string_filter_tests_OBJECTS = $(am_string_filter_tests_OBJECTS) -string_filter_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_string_manip_tests_OBJECTS = string_manip_tests.$(OBJEXT) -string_manip_tests_OBJECTS = $(am_string_manip_tests_OBJECTS) -string_manip_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -am_utility_tests_OBJECTS = utility_tests.$(OBJEXT) -utility_tests_OBJECTS = $(am_utility_tests_OBJECTS) -utility_tests_DEPENDENCIES = $(am__DEPENDENCIES_1) -DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -CXXLD = $(CXX) -CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ - -o $@ -SOURCES = $(cached_value_tests_SOURCES) $(comma_list_tests_SOURCES) \ - $(file_manip_tests_SOURCES) $(glob_filter_tests_SOURCES) \ - $(path_filter_tests_SOURCES) $(string_filter_tests_SOURCES) \ - $(string_manip_tests_SOURCES) $(utility_tests_SOURCES) -DIST_SOURCES = $(cached_value_tests_SOURCES) \ - $(comma_list_tests_SOURCES) $(file_manip_tests_SOURCES) \ - $(glob_filter_tests_SOURCES) $(path_filter_tests_SOURCES) \ - $(string_filter_tests_SOURCES) $(string_manip_tests_SOURCES) \ - $(utility_tests_SOURCES) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMDEP_FALSE = @AMDEP_FALSE@ -AMDEP_TRUE = @AMDEP_TRUE@ -AMTAR = @AMTAR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BFD_LIBS = @BFD_LIBS@ -CAT_ENTRY_END = @CAT_ENTRY_END@ -CAT_ENTRY_START = @CAT_ENTRY_START@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DATE = @DATE@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DOCBOOK_ROOT = @DOCBOOK_ROOT@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -EXTRA_CFLAGS_MODULE = @EXTRA_CFLAGS_MODULE@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -KINC = @KINC@ -KSRC = @KSRC@ -KVERS = @KVERS@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBERTY_LIBS = @LIBERTY_LIBS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBERTY_LIBS@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MOC = @MOC@ -MODINSTALLDIR = @MODINSTALLDIR@ -OBJEXT = @OBJEXT@ -OPROFILE_DIR = @OPROFILE_DIR@ -OPROFILE_MODULE_ARCH = @OPROFILE_MODULE_ARCH@ -OP_CFLAGS = @OP_CFLAGS@ -OP_CXXFLAGS = @OP_CXXFLAGS@ -OP_DOCDIR = @OP_DOCDIR@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -POPT_LIBS = @POPT_LIBS@ -PTRDIFF_T_TYPE = @PTRDIFF_T_TYPE@ -QT_INCLUDES = @QT_INCLUDES@ -QT_LDFLAGS = @QT_LDFLAGS@ -QT_LIB = @QT_LIB@ -QT_VERSION = @QT_VERSION@ -RANLIB = @RANLIB@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -SIZE_T_TYPE = @SIZE_T_TYPE@ -STRIP = @STRIP@ -UIC = @UIC@ -VERSION = @VERSION@ -XML_CATALOG = @XML_CATALOG@ -XSLTPROC = @XSLTPROC@ -XSLTPROC_FLAGS = @XSLTPROC_FLAGS@ -X_CFLAGS = @X_CFLAGS@ -X_EXTRA_LIBS = @X_EXTRA_LIBS@ -X_LIBS = @X_LIBS@ -X_PRE_LIBS = @X_PRE_LIBS@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_RANLIB = @ac_ct_RANLIB@ -ac_ct_STRIP = @ac_ct_STRIP@ -am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ -am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ -am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build_alias = @build_alias@ -datadir = @datadir@ -enable_abi_FALSE = @enable_abi_FALSE@ -enable_abi_TRUE = @enable_abi_TRUE@ -exec_prefix = @exec_prefix@ -have_qt_FALSE = @have_qt_FALSE@ -have_qt_TRUE = @have_qt_TRUE@ -have_xsltproc_FALSE = @have_xsltproc_FALSE@ -have_xsltproc_TRUE = @have_xsltproc_TRUE@ -host_alias = @host_alias@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -kernel_support_FALSE = @kernel_support_FALSE@ -kernel_support_TRUE = @kernel_support_TRUE@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -topdir = @topdir@ -REALPATH = readlink -f -SRCDIR := $(shell $(REALPATH) $(topdir)/libutil++/tests/ ) -AM_CPPFLAGS = \ - -I ${top_srcdir}/libutil++ -D SRCDIR="\"$(SRCDIR)/\"" - -COMMON_LIBS = ../libutil++.a ../../libutil/libutil.a -AM_CXXFLAGS = @OP_CXXFLAGS@ -string_manip_tests_SOURCES = string_manip_tests.cpp -string_manip_tests_LDADD = ${COMMON_LIBS} -string_filter_tests_SOURCES = string_filter_tests.cpp -string_filter_tests_LDADD = ${COMMON_LIBS} -glob_filter_tests_SOURCES = glob_filter_tests.cpp -glob_filter_tests_LDADD = ${COMMON_LIBS} -path_filter_tests_SOURCES = path_filter_tests.cpp -path_filter_tests_LDADD = ${COMMON_LIBS} -comma_list_tests_SOURCES = comma_list_tests.cpp -comma_list_tests_LDADD = ${COMMON_LIBS} -file_manip_tests_SOURCES = file_manip_tests.cpp -file_manip_tests_LDADD = ${COMMON_LIBS} -cached_value_tests_SOURCES = cached_value_tests.cpp -cached_value_tests_LDADD = ${COMMON_LIBS} -utility_tests_SOURCES = utility_tests.cpp -utility_tests_LDADD = ${COMMON_LIBS} -TESTS = ${check_PROGRAMS} -all: all-am - -.SUFFIXES: -.SUFFIXES: .cpp .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign libutil++/tests/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --foreign libutil++/tests/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -clean-checkPROGRAMS: - -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS) -cached_value_tests$(EXEEXT): $(cached_value_tests_OBJECTS) $(cached_value_tests_DEPENDENCIES) - @rm -f cached_value_tests$(EXEEXT) - $(CXXLINK) $(cached_value_tests_LDFLAGS) $(cached_value_tests_OBJECTS) $(cached_value_tests_LDADD) $(LIBS) -comma_list_tests$(EXEEXT): $(comma_list_tests_OBJECTS) $(comma_list_tests_DEPENDENCIES) - @rm -f comma_list_tests$(EXEEXT) - $(CXXLINK) $(comma_list_tests_LDFLAGS) $(comma_list_tests_OBJECTS) $(comma_list_tests_LDADD) $(LIBS) -file_manip_tests$(EXEEXT): $(file_manip_tests_OBJECTS) $(file_manip_tests_DEPENDENCIES) - @rm -f file_manip_tests$(EXEEXT) - $(CXXLINK) $(file_manip_tests_LDFLAGS) $(file_manip_tests_OBJECTS) $(file_manip_tests_LDADD) $(LIBS) -glob_filter_tests$(EXEEXT): $(glob_filter_tests_OBJECTS) $(glob_filter_tests_DEPENDENCIES) - @rm -f glob_filter_tests$(EXEEXT) - $(CXXLINK) $(glob_filter_tests_LDFLAGS) $(glob_filter_tests_OBJECTS) $(glob_filter_tests_LDADD) $(LIBS) -path_filter_tests$(EXEEXT): $(path_filter_tests_OBJECTS) $(path_filter_tests_DEPENDENCIES) - @rm -f path_filter_tests$(EXEEXT) - $(CXXLINK) $(path_filter_tests_LDFLAGS) $(path_filter_tests_OBJECTS) $(path_filter_tests_LDADD) $(LIBS) -string_filter_tests$(EXEEXT): $(string_filter_tests_OBJECTS) $(string_filter_tests_DEPENDENCIES) - @rm -f string_filter_tests$(EXEEXT) - $(CXXLINK) $(string_filter_tests_LDFLAGS) $(string_filter_tests_OBJECTS) $(string_filter_tests_LDADD) $(LIBS) -string_manip_tests$(EXEEXT): $(string_manip_tests_OBJECTS) $(string_manip_tests_DEPENDENCIES) - @rm -f string_manip_tests$(EXEEXT) - $(CXXLINK) $(string_manip_tests_LDFLAGS) $(string_manip_tests_OBJECTS) $(string_manip_tests_LDADD) $(LIBS) -utility_tests$(EXEEXT): $(utility_tests_OBJECTS) $(utility_tests_DEPENDENCIES) - @rm -f utility_tests$(EXEEXT) - $(CXXLINK) $(utility_tests_LDFLAGS) $(utility_tests_OBJECTS) $(utility_tests_LDADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cached_value_tests.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/comma_list_tests.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file_manip_tests.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glob_filter_tests.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/path_filter_tests.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string_filter_tests.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/string_manip_tests.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utility_tests.Po@am__quote@ - -.cpp.o: -@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ -@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: -@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ -@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` -uninstall-info-am: - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) ' { files[$$0] = 1; } \ - END { for (i in files) print i; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -check-TESTS: $(TESTS) - @failed=0; all=0; xfail=0; xpass=0; skip=0; \ - srcdir=$(srcdir); export srcdir; \ - list='$(TESTS)'; \ - if test -n "$$list"; then \ - for tst in $$list; do \ - if test -f ./$$tst; then dir=./; \ - elif test -f $$tst; then dir=; \ - else dir="$(srcdir)/"; fi; \ - if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ - all=`expr $$all + 1`; \ - case " $(XFAIL_TESTS) " in \ - *" $$tst "*) \ - xpass=`expr $$xpass + 1`; \ - failed=`expr $$failed + 1`; \ - echo "XPASS: $$tst"; \ - ;; \ - *) \ - echo "PASS: $$tst"; \ - ;; \ - esac; \ - elif test $$? -ne 77; then \ - all=`expr $$all + 1`; \ - case " $(XFAIL_TESTS) " in \ - *" $$tst "*) \ - xfail=`expr $$xfail + 1`; \ - echo "XFAIL: $$tst"; \ - ;; \ - *) \ - failed=`expr $$failed + 1`; \ - echo "FAIL: $$tst"; \ - ;; \ - esac; \ - else \ - skip=`expr $$skip + 1`; \ - echo "SKIP: $$tst"; \ - fi; \ - done; \ - if test "$$failed" -eq 0; then \ - if test "$$xfail" -eq 0; then \ - banner="All $$all tests passed"; \ - else \ - banner="All $$all tests behaved as expected ($$xfail expected failures)"; \ - fi; \ - else \ - if test "$$xpass" -eq 0; then \ - banner="$$failed of $$all tests failed"; \ - else \ - banner="$$failed of $$all tests did not behave as expected ($$xpass unexpected passes)"; \ - fi; \ - fi; \ - dashes="$$banner"; \ - skipped=""; \ - if test "$$skip" -ne 0; then \ - skipped="($$skip tests were not run)"; \ - test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ - dashes="$$skipped"; \ - fi; \ - report=""; \ - if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ - report="Please report to $(PACKAGE_BUGREPORT)"; \ - test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ - dashes="$$report"; \ - fi; \ - dashes=`echo "$$dashes" | sed s/./=/g`; \ - echo "$$dashes"; \ - echo "$$banner"; \ - test -z "$$skipped" || echo "$$skipped"; \ - test -z "$$report" || echo "$$report"; \ - echo "$$dashes"; \ - test "$$failed" -eq 0; \ - else :; fi - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ - list='$(DISTFILES)'; for file in $$list; do \ - case $$file in \ - $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ - $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ - esac; \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test "$$dir" != "$$file" && test "$$dir" != "."; then \ - dir="/$$dir"; \ - $(mkdir_p) "$(distdir)$$dir"; \ - else \ - dir=''; \ - fi; \ - if test -d $$d/$$file; then \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) - $(MAKE) $(AM_MAKEFLAGS) check-TESTS -check: check-am -all-am: Makefile -installdirs: -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-checkPROGRAMS clean-generic mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: - -install-exec-am: - -install-info: install-info-am - -install-man: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-info-am - -.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ - clean-checkPROGRAMS clean-generic ctags distclean \ - distclean-compile distclean-generic distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-exec install-exec-am \ - install-info install-info-am install-man install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ - uninstall-am uninstall-info-am - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/libutil++/tests/cached_value_tests.cpp b/libutil++/tests/cached_value_tests.cpp deleted file mode 100644 index b50c5d4..0000000 --- a/libutil++/tests/cached_value_tests.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file cached_value_tests.cpp - * tests cached_value.h - * - * @remark Copyright 2005 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - */ - -#include <cstdlib> -#include <iostream> -#include <string> - -#include "cached_value.h" - -using namespace std; - -namespace { - - -bool check_throw(cached_value<bool> const & boolval) -{ - try { - bool foo = boolval.get(); - foo = false; - } catch (op_fatal_error const & e) { - return true; - } - return false; -} - - -int check_cached(void) -{ - cached_value<bool> boolval; - cached_value<string> strval; - - if (!check_throw(boolval)) { - cerr << "get() on no value didn't throw\n"; - return EXIT_FAILURE; - } - - if (boolval.reset(false) != false || boolval.get() != false) { - cerr << "reset() of cached value \"false\" didn't work\n"; - return EXIT_FAILURE; - } - - if (boolval.reset(true) != true || boolval.get() != true) { - cerr << "reset() of cached value \"true\" didn't work\n"; - return EXIT_FAILURE; - } - - if (strval.reset("foo") != "foo" || strval.get() != "foo") { - cerr << "reset() of cached value \"foo\" didn't work\n"; - return EXIT_FAILURE; - } - - if (strval.reset("") != "" || strval.get() != "") { - cerr << "reset() of cached value \"\" didn't work\n"; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} - -}; - -int main() -{ - try { - check_cached(); - } - catch (...) { - cerr << "unknown exception\n"; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/libutil++/tests/comma_list_tests.cpp b/libutil++/tests/comma_list_tests.cpp deleted file mode 100644 index b30feef..0000000 --- a/libutil++/tests/comma_list_tests.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @file comma_list_tests.cpp - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#include <stdlib.h> - -#include <iostream> - -#include "comma_list.h" - -using namespace std; - -#define check(clist, val, result) \ - if (clist.match(val) != result) { \ - cerr << "\"" << #val << "\" matched with " #clist \ - << " did not return " #result << endl; \ - exit(EXIT_FAILURE); \ - } - -int main() -{ - comma_list<int> c1; - - check(c1, 1, true); - - c1.set("2"); - - check(c1, 2, true); - check(c1, 3, false); - - c1.set("3"); - - check(c1, 2, false); - check(c1, 3, true); - - c1.set("2,3"); - - check(c1, 2, true); - check(c1, 3, true); - check(c1, 4, false); - - c1.set("all"); - - check(c1, 2, true); - check(c1, 4, true); - check(c1, 5, true); - - comma_list<int> c2; - - c2.set("6,all"); - - check(c2, 4, true); - check(c2, 0, true); - - c2.set("all,6"); - - check(c2, 4, true); - check(c2, 0, true); - - c2.set("10"); - check(c2, 10, true); - check(c2, 11, false); - return EXIT_SUCCESS; -} diff --git a/libutil++/tests/file_manip_tests.cpp b/libutil++/tests/file_manip_tests.cpp deleted file mode 100644 index dfe161b..0000000 --- a/libutil++/tests/file_manip_tests.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/** - * @file file_manip_tests.cpp - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#include <unistd.h> -#include <stdlib.h> - -#include <string> -#include <iostream> -#include <list> - -#include "file_manip.h" - -using namespace std; - -template <typename Input, typename Output> -struct input_output { - Input input; - Output output; -}; - - -template <typename Input, typename Output, typename Result> -static void check_result(char const * fct_name, Input const & input, - Output const & output, Result const & result) -{ - if (result != output) { - cerr << fct_name << " " - << "for:\n\"" << input << "\"\n" - << "expect:\n\"" << output << "\"\n" - << "found:\n\"" << result << "\"\n"; - exit(EXIT_FAILURE); - } -} - -template <typename Input, typename Output, typename Result> -static void check_result(char const * fct_name, Input const & input1, - Input input2, Output const & output, Result const & result) -{ - if (result != output) { - cerr << fct_name << ": \n" - << "for:\n\"" << input1 << "\"\n" - << "\"" << input2 << "\"\n" - << "expect:\n\"" << output << "\"\n" - << "found:\n\"" << result << "\"\n"; - exit(EXIT_FAILURE); - } -} - - -static input_output<char const *, char const *> expect_dirname[] = -{ - { "/", "/" }, - { "//////", "/" }, - { "/usr", "/" }, - { "///usr", "/" }, - // suprising but conform to dirname(1) - { "///usr/dir", "///usr" }, - { "usr/dir", "usr" }, - { "usr", "." }, - { "n", "." }, - { "../..", ".." }, - { "/../..", "/.." }, - { "./..", "." }, - { "./.", "." }, - { "..", "." }, - { ".", "." }, - { "", "." }, - { 0, 0 } -}; - -static void dirname_tests() -{ - input_output<char const *, char const *> const * cur; - for (cur = expect_dirname; cur->input; ++cur) { - string result = op_dirname(cur->input); - check_result("dirname", cur->input, cur->output, result); - } -} - - -static input_output<char const *, char const*> expect_basename[] = -{ - { "/", "/" }, - { "//////", "/" }, - { "/usr", "usr" }, - { "///usr", "usr" }, - { "///usr/dir", "dir" }, - { "///usr//dir", "dir" }, - { "usr/dir", "dir" }, - { "usr", "usr" }, - { "../..", ".." }, - { "/../..", ".." }, - { "./..", ".." }, - { "./.", "." }, - { ".", "." }, - { 0, 0 } -}; - -static void basename_tests() -{ - input_output<char const *, char const *> const * cur; - for (cur = expect_basename; cur->input; ++cur) { - string result = op_basename(cur->input); - check_result("basename", cur->input, cur->output, result); - } -} - - -static input_output<char const *, bool> expect_is_directory[] = -{ - { ".", true }, - { "/.", true }, - { "./", true }, - { "/", true }, - { "../", true }, - { "../.", true }, - { "non_existing_dir", false }, - { 0, 0 } -}; - -static void is_directory_tests() -{ - input_output<char const *, bool> const * cur; - for (cur = expect_is_directory; cur->input; ++cur) { - bool result = is_directory(cur->input); - check_result("is_directory", cur->input, cur->output, result); - } -} - - -static input_output<pair<string, string>, bool> -expect_is_files_identical[] = { -#define MAKE_PAIR(a, b) make_pair(string(a), string(b)) - { MAKE_PAIR(__FILE__, __FILE__), true }, - { MAKE_PAIR(__FILE__, "not_existing"), false }, - { MAKE_PAIR("not_exisiting", __FILE__), false }, - { MAKE_PAIR("not_exisiting", "not_existing"), false }, - { MAKE_PAIR("", ""), false } -#undef MAKE_PAIR -}; - -void is_files_identical_tests(char const * prog_name) -{ - check_result("is_files_identical", prog_name, prog_name, - is_files_identical(prog_name, prog_name), true); - - input_output<pair<string, string>, bool> const * cur; - for (cur = expect_is_files_identical; !cur->input.first.empty(); ++cur) { - bool result = is_files_identical(cur->input.first, - cur->input.second); - check_result("is_files_identical", cur->input.first, - cur->input.second, cur->output, result); - } -} - - -static input_output<char const *, bool> expect_op_file_readable[] = -{ - { __FILE__, true }, - { "./" __FILE__, true }, - { ".", false }, - { "/.", false }, - { "./", false }, - { "/", false }, - { "../", false }, - { "../.", false }, - { "non_existing_file", false }, - { 0, 0 } -}; - -static void op_file_readable_tests() -{ - input_output<char const *, bool> const * cur; - for (cur = expect_op_file_readable; cur->input; ++cur) { - bool result = op_file_readable(cur->input); - check_result("op_file_readable", cur->input, cur->output, result); - } -} - - -static input_output<string, string> expect_realpath[] = -{ - // realpath() file argument must exists. - { "file_manip_tests.o", "file_manip_tests.o" }, - { "../tests/" "file_manip_tests.o", "file_manip_tests.o" }, - { ".//.//" "file_manip_tests.o", "file_manip_tests.o" }, - // POSIX namespaces ignored by realpath(3) - { "//", "/" }, - { "//usr", "/usr" }, - { "///", "/" }, - { "", "" } -}; - - -// FIXME: useful to test symlinks too -static void realpath_tests() -{ - input_output<string, string> const * cur; - for (cur = expect_realpath; !cur->input.empty(); ++cur) { - string result = op_realpath(cur->input); - string expect = cur->output; - if (cur->input[0] != '/') - expect = SRCDIR + expect; - check_result("op_realpath", cur->input, - expect, result); - } -} - - -void create_file_list_tests() -{ - list<string> result; - if (!create_file_list(result, ".")) { - cerr << "create_file_list() fail\n"; - exit(EXIT_FAILURE); - } - if (result.empty()) { - cerr << "create_file_list(); empty result\n"; - exit(EXIT_FAILURE); - } -} - - -int main(int, char * argv[]) -{ - dirname_tests(); - basename_tests(); - is_directory_tests(); - is_files_identical_tests(argv[0]); - op_file_readable_tests(); - realpath_tests(); - create_file_list_tests(); - return EXIT_SUCCESS; -} diff --git a/libutil++/tests/glob_filter_tests.cpp b/libutil++/tests/glob_filter_tests.cpp deleted file mode 100644 index e88a3ed..0000000 --- a/libutil++/tests/glob_filter_tests.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file glob_filter_tests.cpp - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#include <stdlib.h> - -#include <iostream> - -#include "glob_filter.h" - -using namespace std; - -#define check(filter, str, result) \ - if (filter.match(str) != result) { \ - cerr << "\"" << str << "\" matched with " #filter \ - << " did not return " #result << endl; \ - exit(EXIT_FAILURE); \ - } - -int main() -{ - glob_filter f1("foo,*bar", "foobar"); - check(f1, "foo/barfoobar", true); - check(f1, "foo/bar", true); - check(f1, "/foo/foobar/foo", false); - check(f1, "fooobar1", false); - check(f1, "foo1", false); - check(f1, "foobar", false); - check(f1, "bar1", false); - - glob_filter f2("foo", ""); - check(f2, "foo", true); - check(f2, "foo1", false); - check(f2, "foo/foo", false); - - glob_filter f3("", "foo"); - check(f3, "foo", false); - check(f3, "foo1", true); - check(f3, "foo/foo", true); - - glob_filter f4("foo", "foo"); - check(f4, "foo", false); - check(f4, "foo1", false); - check(f4, "foo/foo", false); - - return EXIT_SUCCESS; -} diff --git a/libutil++/tests/path_filter_tests.cpp b/libutil++/tests/path_filter_tests.cpp deleted file mode 100644 index e664d0f..0000000 --- a/libutil++/tests/path_filter_tests.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/** - * @file path_filter_tests.cpp - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#include <stdlib.h> - -#include <iostream> - -#include "path_filter.h" - -using namespace std; - -#define check(filter, str, result) \ - if (filter.match(str) != result) { \ - cerr << "\"" << str << "\" matched with " #filter \ - << " did not return " #result << endl; \ - exit(EXIT_FAILURE); \ - } - -int main() -{ - path_filter f1("foo,*bar", "foobar"); - check(f1, "foo/barfoobar", true); - check(f1, "foo/bar", true); - check(f1, "/foo/foobar/foo", false); - check(f1, "fooobar1", false); - check(f1, "foo1", false); - check(f1, "foobar", false); - check(f1, "bar1", false); - - path_filter f2("foo", ""); - check(f2, "foo", true); - check(f2, "foo1", false); - check(f2, "foo/foo", true); - - path_filter f3("", "foo"); - check(f3, "foo", false); - check(f3, "foo1", true); - check(f3, "foo/foo", false); - - path_filter f4("foo", "foo"); - check(f4, "foo", false); - check(f4, "foo1", false); - check(f4, "foo/foo", false); - - path_filter f5("*foo*", "*bar*"); - check(f5, "foo", true); - check(f5, "bar", false); - check(f5, "foobar", false); - check(f5, "barfoo", false); - check(f5, "foo/bar", false); - - path_filter f6(" foo,bar", "bar "); - check(f6, "foo", false); - check(f6, "foo ", false); - check(f6, " foo", true); - check(f6, "bar", true); - check(f6, "bar ", false); - check(f6, " bar", false); - check(f6, "foo ", false); - check(f6, "foo/ bar", false); - - path_filter f7(".", ""); - check(f7, ".", true); - // a bit surprising but right IMHO, our implementation use successive - // dirname(input) to check vs the included path and - // dirname("foo") == "." so all relative path input match a "." - // included filter - check(f7, "foo", true); - - return EXIT_SUCCESS; -} diff --git a/libutil++/tests/string_filter_tests.cpp b/libutil++/tests/string_filter_tests.cpp deleted file mode 100644 index 7d06039..0000000 --- a/libutil++/tests/string_filter_tests.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/** - * @file string_filter_tests.cpp - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#include <stdlib.h> - -#include <iostream> - -#include "string_filter.h" - -using namespace std; - -#define check(filter, str, result) \ - if (filter.match(str) != result) { \ - cerr << "\"" << str << "\" matched with " #filter \ - << " did not return " #result << endl; \ - exit(EXIT_FAILURE); \ - } - -int main() -{ - string_filter f1; - check(f1, "", true); - check(f1, "ok", true); - - string_filter f2("ok", ""); - check(f2, "ok", true); - check(f2, "no", false); - - string_filter f3("", "no"); - check(f3, "ok", true); - check(f3, "no", false); - - string_filter f4("ok,ok2,", ""); - check(f4, "ok", true); - check(f4, "ok2", true); - check(f4, "no", false); - - string_filter f5("ok,ok2", "no,no2"); - check(f5, "ok", true); - check(f5, "ok2", true); - check(f5, "no", false); - check(f5, "no2", false); - - vector<string> v1; - vector<string> v2; - - string_filter f6(v1, v2); - check(f6, "", true); - check(f6, "ok", true); - - v1.push_back("ok"); - v1.push_back("ok2"); - - string_filter f7(v1, v2); - check(f7, "ok", true); - check(f7, "ok2", true); - check(f7, "no", false); - - v1.clear(); - - v2.push_back("no"); - v2.push_back("no2"); - - string_filter f8(v1, v2); - check(f8, "ok", true); - check(f8, "no", false); - check(f8, "no", false); - - v1.push_back("ok"); - v1.push_back("ok2"); - - string_filter f9(v1, v2); - check(f9, "ok", true); - check(f9, "no2", false); - - string_filter f10(" foo ", ""); - check(f10, " foo ", true); - check(f10, " foo", false); - check(f10, "foo ", false); - check(f10, "foo", false); - - return EXIT_SUCCESS; -} diff --git a/libutil++/tests/string_manip_tests.cpp b/libutil++/tests/string_manip_tests.cpp deleted file mode 100644 index 1cb07df..0000000 --- a/libutil++/tests/string_manip_tests.cpp +++ /dev/null @@ -1,325 +0,0 @@ -/** - * @file string_manip_tests.cpp - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#include <stdlib.h> - -#include <algorithm> -#include <iterator> -#include <iostream> -#include <utility> - -#include "string_manip.h" - -using namespace std; - -template <typename Input, typename Output> -struct input_output { - Input input; - Output output; -}; - - -template <typename Input, typename Output, typename Result> -static void check_result(char const * fct_name, Input const & input, - Output const & output, Result const & result) -{ - if (result != output) { - cerr << fct_name << ": \n" - << "for:\n\"" << input << "\"\n" - << "expect:\n\"" << output << "\"\n" - << "found:\n\"" << result << "\"\n"; - exit(EXIT_FAILURE); - } -} - - -static input_output<char const*, char const*> expect_erase[] = -{ - { "", "" }, - { ";;;", "" }, - { "ab;;;cd", "cd" }, - { ";;;cd", "cd" }, - { "ab;;;", "" }, - { 0, 0 } -}; - -static void erase_to_last_of_tests() -{ - input_output<char const *, char const*> const * cur; - for (cur = expect_erase; cur->input; ++cur) { - string result = erase_to_last_of(cur->input, ';'); - check_result("erase_to_last_of()", cur->input, cur->output, - result); - } -} - - -static input_output<char const *, pair<string, string> > expect_split[] = -{ -#define MAKE_PAIR(a, b) make_pair(string(a), string(b)) - { "ab;cd", MAKE_PAIR("ab", "cd") }, - { ";cd", MAKE_PAIR("", "cd") }, - { "ab;", MAKE_PAIR("ab", "") }, - { "b;d", MAKE_PAIR("b", "d") }, - { ";d", MAKE_PAIR("", "d") }, - { "a;", MAKE_PAIR("a", "") }, - { ";", MAKE_PAIR("", "") }, - { "", MAKE_PAIR("", "") }, - { 0, MAKE_PAIR("", "") } -#undef MAKE_PAIR -}; - -static void split_tests() -{ - input_output<char const *, pair<string, string> > const * cur; - for (cur = expect_split; cur->input; ++cur) { - string temp = cur->input; - string result = split(temp, ';'); - check_result("split()", cur->input, cur->output.first, temp); - check_result("split()", cur->input, cur->output.second, result); - } -} - -static input_output<char const *, pair<string, bool> > expect_is_prefix[] = -{ -#define MAKE_PAIR(a, b) make_pair(string(a), b) - { "abcd", MAKE_PAIR("abc", true) }, - { "abcd", MAKE_PAIR("ac", false) }, - { "babcd", MAKE_PAIR("abc", false) }, - // these invoke undefined behavior from is_prefix, we keep them - // for the record. -// { "babcd", MAKE_PAIR("", false) }, -// { "", MAKE_PAIR("", false) }, - { 0, MAKE_PAIR("", true) } -#undef MAKE_PAIR -}; - -static void is_prefix_tests() -{ - input_output<char const *, pair<string, bool> > const * cur; - for (cur = expect_is_prefix; cur->input; ++cur) { - bool result = is_prefix(cur->input, cur->output.first); - if (result != cur->output.second) { - cerr << "is_prefix(" << cur->input << ", " - << cur->output.first << ") " - << "return " << result << endl; - exit(EXIT_FAILURE); - } - } -} - - -static const size_t max_token = 8; -static input_output<char const *, char const *[max_token]> expect_separate_token[] = -{ - { "aa", { "aa" } }, - { "a\\c", { "a\\c" } }, - { "a\\\\c", { "a\\\\c" } }, - { "a\\\\c\\", { "a\\\\c\\" } }, - { "ab;cd;ef;gh", { "ab", "cd", "ef", "gh" } }, - { "ab\\;cd", { "ab;cd" } }, - { "a;a", { "a", "a" } }, - { ";a", { "", "a" } }, - { ";", { "", "" } }, - { ";;", { "", "", "" } }, - { 0, { 0, } } -}; - - -static void separate_token_tests() -{ - input_output<char const *, char const *[max_token]> const * cur; - for (cur = expect_separate_token; cur->input; ++cur) { - vector<string> result = separate_token(cur->input, ';'); - if (result.size() > max_token) { - cerr << "separate_token(): too many token\n" - << "input:\n" - << '"' << cur->input << "\"\n" - << "output\n"; - copy(result.begin(), result.end(), - ostream_iterator<string>(cerr, "\n")); - exit(EXIT_FAILURE); - } - for (size_t i = 0; i < result.size(); ++i) { - if (result[i] != cur->output[i]) { - cerr << "separate_token():\n" - << "input:\n" - << cur->input << endl; - cerr << "expect:\n"; - for (size_t i = 0; i < max_token; ++i) { - if (!cur->output[i]) - break; - cerr << cur->output[i] << endl; - } - cerr << "output:\n"; - copy(result.begin(), result.end(), - ostream_iterator<string>(cerr, "\n")); - exit(EXIT_FAILURE); - } - } - } -} - - -static input_output<char const *, char const *> expect_rtrim[] = -{ - { "abc", "abc" }, - { "abc ", "abc" }, - { " abc ", " abc" }, - { " abc \t \t", " abc" }, - { " ", "" }, - { "\t \t", "" }, - { "", "" }, - { 0, 0 } -}; - -static void rtrim_tests() -{ - input_output<char const *, char const*> const * cur; - for (cur = expect_rtrim; cur->input; ++cur) { - string result = rtrim(cur->input); - check_result("rtrim()", cur->input, cur->output, result); - } -} - - -static input_output<char const *, char const *> expect_ltrim[] = -{ - { "abc", "abc" }, - { "abc ", "abc " }, - { " abc ", "abc " }, - { "\t \tabc ", "abc " }, - { " ", "" }, - { "\t \t", "" }, - { "", "" }, - { 0, 0 } -}; - -static void ltrim_tests() -{ - input_output<char const *, char const*> const * cur; - for (cur = expect_ltrim; cur->input; ++cur) { - string result = ltrim(cur->input); - check_result("ltrim()", cur->input, cur->output, result); - } -} - - -static input_output<char const *, char const *> expect_trim[] = -{ - { "abc", "abc" }, - { "abc ", "abc" }, - { " abc ", "abc" }, - { "\t \tabc \t", "abc" }, - { " ", "" }, - { "\t \t", "" }, - { "", "" }, - { 0, 0 } -}; - -static void trim_tests() -{ - input_output<char const *, char const*> const * cur; - for (cur = expect_trim; cur->input; ++cur) { - string result = trim(cur->input); - check_result("trim()", cur->input, cur->output, result); - } -} - - -static input_output<double, char const *> expect_format_percent[] = -{ - { 2.2, " 2.2000" }, - { 0, " 0" }, - { 100.00, "100.000" }, - { 99.99999, "100.000" }, - { 0.00000344, "3.4e-06" }, - // FIXME, must be 3.e-124 but output is 3.4e-124 -// { 0.34e-123, "3.e-124" }, - { -1.0, 0 } -}; - -static void format_percent_tests() -{ - input_output<double, char const*> const * cur; - for (cur = expect_format_percent; cur->input != -1.0; ++cur) { - string result = format_percent(cur->input, percent_int_width, - percent_fract_width); - check_result("format_percent()", cur->input, cur->output, - result); - } -} - - -static input_output<unsigned int, char const *> expect_from_str_to_uint[] = -{ - { 123, "123" }, - { 33, "33" }, - { 0, "0" }, - { 0, 0 } -}; - -static void tostr_tests() -{ - input_output<unsigned int, char const *> const * cur; - for (cur = expect_from_str_to_uint; cur->output; ++cur) { - string result = op_lexical_cast<string>(cur->input); - check_result("op_lexical_cast()", cur->input, - cur->output, result); - } -} - -static void touint_tests() -{ - // reversed input/output of the previous tests - input_output<unsigned int, char const *> const * cur; - for (cur = expect_from_str_to_uint; cur->output; ++cur) { - unsigned int result = - op_lexical_cast<unsigned int>(cur->output); - check_result("op_lexical_cast()", cur->output, cur->input, - result); - } -} - - -static input_output<char const*, bool> expect_from_str_to_bool[] = -{ - { "0", false }, - { "1", true }, - { 0, 0 } -}; - -static void tobool_tests() -{ - input_output<char const *, bool> const * cur; - for (cur = expect_from_str_to_bool; cur->input; ++cur) { - bool result = op_lexical_cast<bool>(cur->input); - check_result("op_lexical_cast()", cur->input, cur->output, - result); - } -} - -// FIXME: more op_lexical_cast<> tests - -int main() -{ - erase_to_last_of_tests(); - tostr_tests(); - touint_tests(); - tobool_tests(); - split_tests(); - is_prefix_tests(); - separate_token_tests(); - rtrim_tests(); - ltrim_tests(); - trim_tests(); - format_percent_tests(); - return EXIT_SUCCESS; -} diff --git a/libutil++/tests/utility_tests.cpp b/libutil++/tests/utility_tests.cpp deleted file mode 100644 index 8de000f..0000000 --- a/libutil++/tests/utility_tests.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/** - * @file utility_tests.cpp - * tests utility.h and op_exception.h - * - * @remark Copyright 2003 OProfile authors - * @remark Read the file COPYING - * - * @author John Levon - * @author Philippe Elie - */ - -#include <stdlib.h> -#include <new> -#include <iostream> - -#include "utility.h" -#include "op_exception.h" - -using namespace std; - -static int nb_new; -static int nb_new_array; - -void* operator new(size_t size) throw(bad_alloc) -{ - nb_new++; - return malloc(size); -} - -void* operator new[](size_t size) throw(bad_alloc) -{ - nb_new_array++; - return malloc(size); -} - -void operator delete(void * p) throw() -{ - nb_new--; - if (p) - free(p); -} - -void operator delete[](void * p) throw() -{ - nb_new_array--; - if (p) - free(p); -} - - -void check_alloc() -{ - if (nb_new) { - cerr << "new(size_t) leak\n"; - exit(EXIT_FAILURE); - } - - if (nb_new_array) { - cerr << "new[](size_t) leak\n"; - exit(EXIT_FAILURE); - } -} - - -struct A {}; - -template <typename Throw, typename Catch> -void throw_tests() -{ - scoped_ptr<A> a(new A); - try { - scoped_ptr<A> a(new A); - throw Throw(""); - } - catch (Catch const &) { - } -} - - -template <typename Throw, typename Catch> -void throw_tests(bool) -{ - scoped_array<A> b(new A[10]); - try { - scoped_array<A> a(new A[10]); - throw Throw(""); - } - catch (Catch const &) { - } -} - - -void tests_new() -{ - throw_tests<op_fatal_error, op_fatal_error>(); - throw_tests<op_fatal_error, op_exception>(); - throw_tests<op_runtime_error, op_runtime_error>(); - throw_tests<op_runtime_error, runtime_error>(); - throw_tests<op_fatal_error, op_fatal_error>(true); - throw_tests<op_fatal_error, op_exception>(true); - throw_tests<op_runtime_error, op_runtime_error>(true); - throw_tests<op_runtime_error, runtime_error>(true); -} - - -int main() -{ - try { - tests_new(); - check_alloc(); - } - catch (...) { - cerr << "unknown exception\n"; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/libutil++/unique_storage.h b/libutil++/unique_storage.h deleted file mode 100644 index 0f7fd71..0000000 --- a/libutil++/unique_storage.h +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @file unique_storage.h - * Unique storage of values - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef UNIQUE_STORAGE_H -#define UNIQUE_STORAGE_H - -#include <vector> -#include <map> -#include <stdexcept> - -/** - * Store values such that only one copy of the value - * is ever stored. - * - * I is an arbitrary typename that's never - * used. - * - * It is a required parameter in order to enforce - * type-safety for a collection. - * - * The value type "V" must be default-constructible, - * and this is the value returned by a stored id_value - * where .set() is false - */ -template <typename I, typename V> class unique_storage { - -public: - unique_storage() { - // id 0 - values.push_back(V()); - } - - virtual ~unique_storage() {} - - typedef std::vector<V> stored_values; - - /// the actual ID type - struct id_value { - /// id == 0 means "empty" / "undefined" - id_value() : id(0) {} - - /// does this ID map to a non-default value ? - bool set() const { - return id; - } - - bool operator<(id_value const & rhs) const { - return id < rhs.id; - } - - bool operator==(id_value const & rhs) const { - return id == rhs.id; - } - - bool operator!=(id_value const & rhs) const { - return !(id == rhs.id); - } - - private: - friend class unique_storage<I, V>; - - typedef typename stored_values::size_type size_type; - - explicit id_value(size_type s) : id(s) {} - - /// actual ID value - size_type id; - }; - - - /// ensure this value is available - id_value const create(V const & value) { - typename id_map::value_type val(value, id_value(values.size())); - std::pair<typename id_map::iterator, bool> - inserted = ids.insert(val); - if (inserted.second) { - values.push_back(value); - } - - return inserted.first->second; - } - - - /// return the stored value for the given ID - V const & get(id_value const & id) const { - // some stl lack at(), so we emulate it - if (id.id < values.size()) - return values[id.id]; - - throw std::out_of_range("unique_storage::get(): out of bounds"); - } - -private: - typedef std::map<V, id_value> id_map; - - /// the contained values - stored_values values; - - /// map from ID to value - id_map ids; -}; - -#endif /* !UNIQUE_STORAGE_H */ diff --git a/libutil++/utility.h b/libutil++/utility.h deleted file mode 100644 index 83c36ca..0000000 --- a/libutil++/utility.h +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @file utility.h - * General purpose C++ utility - * - * @remark Copyright 2002 OProfile authors - * @remark Read the file COPYING - * - * @author Philippe Elie - * @author John Levon - */ - -#ifndef UTILITY_H -#define UTILITY_H - -#include <cstddef> - -/** noncopyable : object of class derived from this class can't be copied - * and isn't copy-constructible */ -class noncopyable { -protected: - noncopyable() {} - ~noncopyable() {} -private: - noncopyable(noncopyable const &); - noncopyable const & operator=(noncopyable const &); -}; - - -template<typename T> class scoped_ptr { -public: - explicit scoped_ptr(T * p = 0) : p_(p) {} - ~scoped_ptr() { delete p_; } - - void reset(T * p = 0) { - if (p == p_) - return; - delete p_; - p_ = p; - } - - T & operator*() const { return *p_; } - T * operator->() const { return p_; } - T * get() const { return p_; } - - void swap(scoped_ptr & sp) { - T * tmp = sp.p_; - sp.p_ = p_; - p_ = tmp; - } - -private: - scoped_ptr & operator=(scoped_ptr const &); - scoped_ptr(scoped_ptr const &); - T * p_; -}; - -template<typename T> class scoped_array { -public: - explicit scoped_array(T * p = 0) : p_(p) {} - ~scoped_array() { delete [] p_; } - - void reset(T * p = 0) { - if (p == p_) - return; - delete [] p_; - p_ = p; - } - - T & operator[](std::ptrdiff_t i) const { return p_[i]; } - T * get() const { return p_; } - - void swap(scoped_array & sp) { - T * tmp = sp.p_; - sp.p_ = p_; - p_ = tmp; - } - -private: - scoped_array & operator=(scoped_array const &); - scoped_array(scoped_array const &); - T * p_; -}; - -/** - * @param count - * @param total - * - * return total == 0 ? 1.0 : (count / total); - */ -inline double op_ratio(double count, double total) -{ - return total == 0 ? 0.0 : (count / total); -} - -// Part copyright: -// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell -// and distribute this software is granted provided this copyright -// notice appears in all copies. This software is provided "as is" without -// express or implied warranty, and with no claim as to its suitability for -// any purpose. - -#endif /* !UTILITY_H */ |