aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.jap9
-rw-r--r--config/open-axiom.m42
-rwxr-xr-xconfigure92
-rw-r--r--configure.ac2
-rw-r--r--src/ChangeLog.jap35
-rw-r--r--src/hyper/Makefile.in38
-rwxr-xr-xsrc/hyper/htsearch12
-rw-r--r--src/hyper/htsearch.cc229
-rwxr-xr-xsrc/hyper/presea.in28
-rw-r--r--src/include/cfuns.h6
-rw-r--r--src/lib/cfuns-c.c65
11 files changed, 380 insertions, 138 deletions
diff --git a/ChangeLog.jap b/ChangeLog.jap
new file mode 100644
index 00000000..cd01fdf3
--- /dev/null
+++ b/ChangeLog.jap
@@ -0,0 +1,9 @@
+2010-08-17 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * config/open-axiom.m4 (OPENAXIOM_HOST_PROGS): Don't check for awk
+ anymore.
+
+2009-07-16 Alfredo Portes <doyenatccny@gmail.com>
+
+ * configure.ac.pamphlet: Remove presea.
+
diff --git a/config/open-axiom.m4 b/config/open-axiom.m4
index 478bb9ad..ae73ec67 100644
--- a/config/open-axiom.m4
+++ b/config/open-axiom.m4
@@ -596,8 +596,6 @@ dnl --------------------------
dnl Check for programs we need in the host environment.
AC_DEFUN([OPENAXIOM_HOST_PROGS],[
OPENAXIOM_HOST_EDITOR
-AC_PATH_PROGS([HOST_AWK],[awk nawk gawk mawk])
-
AC_PATH_PROG([PDFLATEX], [pdflatex])
if test -z "$PDFLATEX"; then
AC_PATH_PROG([LATEX], [latex],
diff --git a/configure b/configure
index c32311cd..93619bd0 100755
--- a/configure
+++ b/configure
@@ -813,7 +813,6 @@ axiom_src_subdirs
MAKEINDEX
LATEX
PDFLATEX
-HOST_AWK
oa_editor
oa_optimize_options
oa_enable_checking
@@ -6969,13 +6968,13 @@ if test "${lt_cv_nm_interface+set}" = set; then
else
lt_cv_nm_interface="BSD nm"
echo "int some_variable = 0;" > conftest.$ac_ext
- (eval echo "\"\$as_me:6972: $ac_compile\"" >&5)
+ (eval echo "\"\$as_me:6971: $ac_compile\"" >&5)
(eval "$ac_compile" 2>conftest.err)
cat conftest.err >&5
- (eval echo "\"\$as_me:6975: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+ (eval echo "\"\$as_me:6974: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
cat conftest.err >&5
- (eval echo "\"\$as_me:6978: output\"" >&5)
+ (eval echo "\"\$as_me:6977: output\"" >&5)
cat conftest.out >&5
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
lt_cv_nm_interface="MS dumpbin"
@@ -8177,7 +8176,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
- echo '#line 8180 "configure"' > conftest.$ac_ext
+ echo '#line 8179 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
@@ -10457,11 +10456,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:10460: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:10459: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:10464: \$? = $ac_status" >&5
+ echo "$as_me:10463: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -10796,11 +10795,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:10799: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:10798: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:10803: \$? = $ac_status" >&5
+ echo "$as_me:10802: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -10901,11 +10900,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:10904: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:10903: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:10908: \$? = $ac_status" >&5
+ echo "$as_me:10907: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -10956,11 +10955,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:10959: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:10958: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:10963: \$? = $ac_status" >&5
+ echo "$as_me:10962: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -13756,7 +13755,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 13759 "configure"
+#line 13758 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -13852,7 +13851,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 13855 "configure"
+#line 13854 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -15872,11 +15871,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:15875: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:15874: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:15879: \$? = $ac_status" >&5
+ echo "$as_me:15878: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -15971,11 +15970,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:15974: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:15973: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:15978: \$? = $ac_status" >&5
+ echo "$as_me:15977: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -16023,11 +16022,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:16026: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:16025: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:16030: \$? = $ac_status" >&5
+ echo "$as_me:16029: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -17710,52 +17709,6 @@ done
;;
esac
-for ac_prog in awk nawk gawk mawk
-do
- # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
-{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if test "${ac_cv_path_HOST_AWK+set}" = set; then
- $as_echo_n "(cached) " >&6
-else
- case $HOST_AWK in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_HOST_AWK="$HOST_AWK" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
- ac_cv_path_HOST_AWK="$as_dir/$ac_word$ac_exec_ext"
- $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
-done
-IFS=$as_save_IFS
-
- ;;
-esac
-fi
-HOST_AWK=$ac_cv_path_HOST_AWK
-if test -n "$HOST_AWK"; then
- { $as_echo "$as_me:$LINENO: result: $HOST_AWK" >&5
-$as_echo "$HOST_AWK" >&6; }
-else
- { $as_echo "$as_me:$LINENO: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
- test -n "$HOST_AWK" && break
-done
-
-
# Extract the first word of "pdflatex", so it can be a program name with args.
set dummy pdflatex; ac_word=$2
{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
@@ -22170,9 +22123,6 @@ ac_config_files="$ac_config_files src/etc/Makefile:config/var-def.mk:src/etc/Mak
ac_config_files="$ac_config_files src/doc/Makefile:config/var-def.mk:src/doc/Makefile.in:config/setup-dep.mk"
-ac_config_files="$ac_config_files src/hyper/presea"
-
-
## We now generate the "document" script and support files at configure time.
## We put them in the build directory because they are intended to be
## build support utils only.
@@ -23158,7 +23108,6 @@ do
"src/input/Makefile") CONFIG_FILES="$CONFIG_FILES src/input/Makefile:config/var-def.mk:src/input/Makefile.in:config/setup-dep.mk" ;;
"src/etc/Makefile") CONFIG_FILES="$CONFIG_FILES src/etc/Makefile:config/var-def.mk:src/etc/Makefile.in:config/setup-dep.mk" ;;
"src/doc/Makefile") CONFIG_FILES="$CONFIG_FILES src/doc/Makefile:config/var-def.mk:src/doc/Makefile.in:config/setup-dep.mk" ;;
- "src/hyper/presea") CONFIG_FILES="$CONFIG_FILES src/hyper/presea" ;;
"build/scripts/document") CONFIG_FILES="$CONFIG_FILES build/scripts/document:$srcdir/src/scripts/document.in" ;;
*) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
@@ -24582,7 +24531,6 @@ compiler_lib_search_path=$lt_compiler_lib_search_path_CXX
_LT_EOF
;;
- "src/hyper/presea":F) chmod +x src/hyper/presea ;;
"build/scripts/document":F) \
chmod +x build/scripts/document ;;
diff --git a/configure.ac b/configure.ac
index ea793867..8ada2984 100644
--- a/configure.ac
+++ b/configure.ac
@@ -121,8 +121,6 @@ OPENAXIOM_MAKEFILE([src/input/Makefile])
OPENAXIOM_MAKEFILE([src/etc/Makefile])
OPENAXIOM_MAKEFILE([src/doc/Makefile])
-AC_CONFIG_FILES([src/hyper/presea], [chmod +x src/hyper/presea])
-
## We now generate the "document" script and support files at configure time.
## We put them in the build directory because they are intended to be
## build support utils only.
diff --git a/src/ChangeLog.jap b/src/ChangeLog.jap
new file mode 100644
index 00000000..055af804
--- /dev/null
+++ b/src/ChangeLog.jap
@@ -0,0 +1,35 @@
+2010-08-17 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * hyper/htsearch.cc: Rename from htsearch.c to avoid confusions.
+
+2010-08-17 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * hyper/htsearch.c: Tidy.
+
+2010-08-17 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * hyper/Makefile.in (${OUTLIB}/htsearch$(EXEEXT)): Link with a C++
+ compiler.
+
+2010-07-25 Alfredo Portes <doyenatccny@gmail.com>
+
+ * src/lib/cfuns-c.c: (oa_insert) Change return value.
+ Misc cleanup.
+ * src/include/cfuns.h: Adjust.
+
+2010-07-12 Alfredo Portes <doyenatccny@gmail.com>
+
+ * src/hyper/Makefile.in: Adjust.
+ * src/hyper/htsearch.c: Add more documentation.
+ * src/lib/cfuns-c.c: Add String manipulation functions.
+
+2009-07-16 Alfredo Portes <doyenatccny@gmail.com>
+
+ * lib/cfuns-c.c: New string manipulation functions.
+ * include/cfuns.h: Likewise.
+ * hyper/htsearch.c: Add new C replacement for htsearch
+ and presea scripts.
+ * hyper/htsearch: Remove.
+ * hyper/presea.in: Remove.
+ * hyper/Makefile.in: Adjust.
+
diff --git a/src/hyper/Makefile.in b/src/hyper/Makefile.in
index d690bf35..bd5e04c2 100644
--- a/src/hyper/Makefile.in
+++ b/src/hyper/Makefile.in
@@ -29,41 +29,37 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
openaxiom_host_has_regex = @openaxiom_host_has_regex@
bin_PROGRAMS = htadd$(EXEEXT) ex2ht$(EXEEXT)
ifeq ($(strip $(openaxiom_host_has_regex)),yes)
-bin_PROGRAMS += hthits$(EXEEXT)
+bin_PROGRAMS += hthits$(EXEEXT) htsearch$(EXEEXT)
endif
ifeq ($(strip $(axiom_use_x)),yes)
bin_PROGRAMS += hypertex$(EXEEXT) spadbuf$(EXEEXT)
endif
# this is where to put the various commands
-OUTLIB= $(axiom_target_libdir)
+OUTLIB = $(axiom_target_libdir)
# this is where the include files live
-INC= $(axiom_src_srcdir)/include
+INC = $(axiom_src_srcdir)/include
# this is where the hypertex documentation files are
HYPER=$(axiom_target_datadir)/hypertex
-HTADD=$(OUTLIB)/htadd
+HTADD = $(OUTLIB)/htadd
BITMAPS = mouse11.bitmap mouse11.mask sdown3d.bitmap sdown3dpr.bitmap \
sdown.bitmap sup3d.bitmap sup3dpr.bitmap sup.bitmap ht_icon
-SCRIPTS=${OUTLIB}/htsearch ${OUTLIB}/presea
-
-BINFILES= $(addprefix $(OUTLIB)/,$(bin_PROGRAMS))
+BINFILES = $(addprefix $(OUTLIB)/,$(bin_PROGRAMS))
HEADERS = display.h event.h extent.h node.h \
group.h hyper.h initx.h keyin.h lex.h \
parse.h parse-paste.h parse-types.h scrollbar.h \
titlebar.h token.h $(axiom_c_macros_h)
-
build_libdir = $(top_builddir)/src/lib
hypertex_SOURCES = addfile.c cond.c dialog.c display.c event.c extent1.c \
@@ -102,11 +98,16 @@ ex2ht_objects = $(ex2ht_SOURCES:.c=.$(OBJEXT))
ex2ht_LDADD = $(libspad_la) -L$(build_libdir) $(oa_c_libs)
ex2ht_DEPENDENCIES =
+htsearch_SOURCES = htsearch.cc
+htsearch_objects = $(htsearch_SOURCES:.cc=.$(OBJEXT))
+htsearch_LDADD = $(libspad_la) -L$(build_libdir) $(oa_c_libs)
+htsearch_DEPENDENCIES =
+
subdir = src/hyper/
.PHONY: all all-hyper all-hyper-pre all-hyper-post
.SUFFIXES:
-.SUFFIXES: .c .$(OBJEXT) .h
+.SUFFIXES: .c .cc .$(OBJEXT) .h
all: all-ax
@@ -117,7 +118,7 @@ stamp: all-hyper-post
-rm -f stamp
$(STAMP) stamp
-all-hyper-pre: $(BINFILES) $(SCRIPTS) $(HYPER)/pages/util.ht
+all-hyper-pre: $(BINFILES) $(HYPER)/pages/util.ht
$(HYPER)/pages/util.ht: $(srcdir)/pages/util.ht
rm -f $@
@@ -128,12 +129,11 @@ all-hyper-post: all-hyper-pre $(HYPER)/pages/ht.db
mostclean-local:
$(LIBTOOL) --mode=clean rm -f $(hypertex_objects) $(htadd_objects) \
- $(spadbuf_objects) $(hthits_objects) $(ex2ht_objects)
+ $(spadbuf_objects) $(hthits_objects) $(ex2ht_objects) $(htsearch_objects)
clean-local: mostclean-local
-rm -f $(BINFILES)
-rm -rf $(HYPER)/pages
- -rm -f $(SCRIPTS)
-rm -f stamp
distclean-local: clean-local
@@ -143,6 +143,9 @@ distclean-local: clean-local
%.$(OBJEXT) %.lo: %.c $(HEADERS)
$(CXXCOMPILE) -o $@ $(CFLAGS) ${CCF} $(axiom_includes) $(AXIOM_X11_CFLAGS) -I. $<
+%.$(OBJEXT) %.lo: %.cc $(HEADERS)
+ $(CXXCOMPILE) -o $@ $(CXXFLAGS) $(axiom_includes) $(AXIOM_X11_CFLAGS) -I. $<
+
${HYPER}/pages/ht.db: all-hyper-pre $(srcdir)/pages/*.pht
@echo making ${HYPER}/pages from $(axiom_src_srcdir)/pages directory
@ mkdir -p "${HYPER}"/pages
@@ -161,12 +164,8 @@ ${HYPER}/pages/ht.db: all-hyper-pre $(srcdir)/pages/*.pht
cp -p $$f "$(HYPER)"/bitmaps; done
@ # cp -pr "$(srcdir)"/viewports "$(axiom_target_datadir)"
-
-${OUTLIB}/htsearch: htsearch
- cp -p $< $@ && chmod +x $@
-
-${OUTLIB}/presea: presea
- cp -p $< $@ && chmod +x $@
+${OUTLIB}/htsearch$(EXEEXT): $(htsearch_objects) $(htsearch_DEPENDENCIES)
+ ${CXXLINK} -o $@ $(htsearch_objects) $(htsearch_LDADD)
${OUTLIB}/ex2ht$(EXEEXT): $(ex2ht_objects) $(ex2ht_DEPENDENCIES)
${CXXLINK} -o $@ $(ex2ht_objects) $(ex2ht_LDADD)
@@ -177,7 +176,6 @@ $(OUTLIB)/htadd$(EXEEXT): $(htadd_objects) $(htadd_DEPENDENCIES)
${OUTLIB}/hthits$(EXEEXT): $(hthits_objects) $(hthits_DEPENDENCIES)
${CXXLINK} -o $@ $(hthits_objects) $(hthits_LDADD)
-
$(OUTLIB)/hypertex$(EXEEXT): $(hypertex_objects) $(hypertex_DEPENDENCIES)
${CXXLINK} -o $@ $(hypertex_objects) $(hypertex_LDADD)
diff --git a/src/hyper/htsearch b/src/hyper/htsearch
deleted file mode 100755
index 76d95063..00000000
--- a/src/hyper/htsearch
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-htbindir=$AXIOM/lib
-htpagedir=$AXIOM/share/hypertex/pages
-
-
-if test -z "$1"
-then
- echo ""|$htbindir/presea case=1 -
-else
-( cd $htpagedir; $htbindir/hthits "$1" $htpagedir/ht.db |sort -r -n -k 1.22 |$htbindir/presea case=0 expr="$1" -)
-fi
diff --git a/src/hyper/htsearch.cc b/src/hyper/htsearch.cc
new file mode 100644
index 00000000..d67c6074
--- /dev/null
+++ b/src/hyper/htsearch.cc
@@ -0,0 +1,229 @@
+/*
+ Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
+ All rights reserved.
+ Copyright (C) 2007-2010, Gabriel Dos Reis.
+ All rights reserved.
+ Copyright (C) 2009-2010, Alfredo Portes.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of The Numerical Algorithms Group Ltd. nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+ * htsearch: is used by Hyperdoc to search for keywords in
+ * Hyperdoc pages and create a HyperDoc page of the search
+ * result.
+ */
+
+#include "openaxiom-c-macros.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <string>
+#include <iostream>
+#include "cfuns.h"
+
+ // Path to the directory containing the hyperdoc pages.
+static std::string htpagedir;
+
+// Path to the hthits program.
+static std::string hthitscmd;
+
+// Path to the database file of the hyperdoc pages.
+static std::string htdbfile;
+
+/*
+ * pages_cmp compares two strings.
+ *
+ * @param str1 string to be compared.
+ * @param str2 string to be compared.
+ *
+ * @returns 0 when the strings are equal, a negative integer
+ * when str1 is less than str2, or a positive integer if str1 is
+ * greater than str2, according to the lexicographical order.
+ */
+static int
+pages_cmp(const void* str1, const void* str2)
+{
+ return strcmp((const char*)str1, (const char*)str2);
+}
+
+/*
+ * sort_pages sorts a list of HyperDoc pages links.
+ *
+ * @param links is an array containing the HyperDoc
+ * links to be sorted.
+ *
+ * @size of the number of elements in the links array.
+ */
+static void
+sort_pages(char** links, int size)
+{
+ qsort(links, size, sizeof (char*), pages_cmp);
+}
+
+/*
+ * presea function constructs a HyperDoc
+ * page with the links to HyperDoc pages
+ * that contain the given pattern.
+ *
+ * @param links array with the links to the matched
+ * HyperDoc pages.
+ * @param n number of elements in the links array.
+ * @param cases flag indicating if there was any matches.
+ * @param pattern searched in the HyperDoc pages.
+ */
+static void
+presea(char** links, int n, int cases, const char* pattern)
+{
+ int m = 0;
+ char** tokens = NULL;
+ static const char* delimiter = "{";
+
+ for (int i = 0; i < n; i++) {
+ int j = 0;
+
+ tokens = oa_split(links[i],delimiter,&j);
+ if (j >= 2)
+ m = m + atol(oa_substr(tokens[1],0,strlen(tokens[1])-2));
+ }
+
+ if (cases==1)
+ printf("\\begin{page}{staticsearchpage}{No matches found}\n");
+ else if ( n==0 || m==0 )
+ printf("\\begin{page}{staticsearchpage}{No matches found for {\\em %s}}\n",pattern);
+ else
+ printf("\\begin{page}{staticsearchpage}{%d matches found in %d pages for {\\em %s}}\n",m,n,pattern);
+ printf("Matches\\tab{8}in Page\n");
+ printf("\\beginscroll\n");
+ printf("\\beginmenu\n");
+ for(int i = n-1; i >= 0; i--)
+ printf ("%s\n",links[i]);
+ printf("\\endmenu\n");
+ printf("\\endscroll\n");
+ printf("\\end{page}\n");
+}
+
+/*
+ * Set global variables with the locations of the
+ * Hyperdoc pages, the hthits program and the Hyperdoc
+ * pages database.
+ */
+static void
+set_variables(void) {
+ const std::string systemdir(oa_getenv("AXIOM"));
+
+ if (systemdir.empty()) {
+ std::cerr << "Could not locate OpenAxiom installation." << std::endl;
+ exit(-1);
+ }
+
+ htpagedir = systemdir + "/share/hypertex/pages/";
+ hthitscmd = systemdir + "/lib/hthits";
+ htdbfile = htpagedir + "ht.db";
+}
+
+/*
+ * htsearch invokes hthits to search for pattern
+ * in the HyperDoc pages.
+ *
+ * @param pattern string to be searched in the
+ * HyperDoc pages.
+ */
+static void
+htsearch(const char* pattern)
+{
+ FILE* hits;
+ char buf[1024];
+ char** sorted_hits;
+ const char* matches = "";
+ int size = 0;
+ static const char* delimiter = "\n";
+
+ set_variables();
+
+ if (strcmp(pattern,"") == 0)
+ presea(NULL,size,1,pattern);
+ else {
+
+ // hthits requires to change directory
+ // to where the HyperDoc pages reside.
+ if (oa_chdir(htpagedir.c_str()) == -1) {
+ std::cerr << "Cannot change the page directory: "
+ << htpagedir << std::endl;
+ exit(-1);
+ }
+
+ // Call hthits with: hthits pattern ht.db
+ hthitscmd = hthitscmd + " " + pattern + " " + htdbfile;
+ if ((hits = popen(hthitscmd.c_str(), "r")) != NULL) {
+ while (fgets(buf, 1024, hits) != NULL)
+ matches = oa_strcat(matches,buf);
+ pclose(hits);
+ }
+ else {
+ std::cerr << "Could not execute " << hthitscmd << std::endl;
+ exit(-1);
+ }
+
+ sorted_hits = oa_split(matches,delimiter,&size);
+ sort_pages(sorted_hits, size);
+ presea(sorted_hits,size,0,pattern);
+ }
+}
+
+/*
+ * Display how to use the htsearch program.
+ */
+static void
+usage(void)
+{
+ std::cerr << "Usage: htsearch pattern" << std::endl;
+ exit(1);
+}
+
+
+/* Main routine */
+int
+main(int argc, char** argv)
+{
+ if (argc == 1)
+ htsearch("");
+ else if (argc == 2) {
+
+ if (strcmp(argv[1],"--help") == 0)
+ usage();
+ else
+ htsearch(argv[1]);
+ }
+ else
+ usage();
+ return 0;
+}
diff --git a/src/hyper/presea.in b/src/hyper/presea.in
deleted file mode 100755
index 788a28b6..00000000
--- a/src/hyper/presea.in
+++ /dev/null
@@ -1,28 +0,0 @@
-#!@HOST_AWK@ -f
-BEGIN {n=0;m=0
-}
-
-{
- a[n] = $0;
- n=n+1;
- j=split($0,b,"{");
- if ( j>= 2)
- m=m+substr(b[2],1,length(b[2])-1);
-}
-
-END {
- if (case==1)
- printf ("\\begin{page}{staticsearchpage}{No matches found}\n")
- else if ( n==0 || m==0 )
- printf ("\\begin{page}{staticsearchpage}{No matches found for {\\em %s}}\n",expr)
- else
- printf ("\\begin{page}{staticsearchpage}{%d matches found in %d pages for {\\em %s}}\n",m,n,expr);
- printf ("Matches\\tab{8}in Page\n");
- printf "\\beginscroll\n";
- printf "\\beginmenu\n";
- for(i=0;i<n;i++) printf ("%s\n",a[i]);
- printf "\\endmenu\n";
- printf "\\endscroll\n";
- printf "\\end{page}\n";
-}
-
diff --git a/src/include/cfuns.h b/src/include/cfuns.h
index 4c84a6c0..10f439d2 100644
--- a/src/include/cfuns.h
+++ b/src/include/cfuns.h
@@ -4,7 +4,7 @@
/*
Copyright (C) 1991-2002, The Numerical ALgorithms Group Ltd.
All rights reserved.
- Copyright (C) 2007-2009, Gabriel Dos Reis.
+ Copyright (C) 2007-2010, Gabriel Dos Reis.
All rights resrved.
Redistribution and use in source and binary forms, with or without
@@ -68,6 +68,10 @@ OPENAXIOM_EXPORT double minus_infinity(void);
OPENAXIOM_EXPORT double quiet_double_NaN(void);
OPENAXIOM_EXPORT openaxiom_byteorder oa_get_host_byteorder(void);
+OPENAXIOM_EXPORT const char* oa_concatenate_string(const char*, const char*);
+OPENAXIOM_EXPORT const char* oa_strcat(const char*, const char*);
+OPENAXIOM_EXPORT char* oa_substr(const char*, const size_t, const size_t);
+OPENAXIOM_EXPORT char** oa_split(const char*, const char*, int*);
#ifdef __cplusplus
}
diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c
index e8f2562b..62d401dd 100644
--- a/src/lib/cfuns-c.c
+++ b/src/lib/cfuns-c.c
@@ -2,7 +2,7 @@
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
All rights reserved.
- Copyright (C) 2007-2009, Gabriel Dos Reis.
+ Copyright (C) 2007-2010, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -544,6 +544,22 @@ oa_concatenate_string(const char* lhs, const char* rhs)
}
}
+/* Return a string object that is the result of catenating the strings
+ designated by `left' and `right'. */
+OPENAXIOM_EXPORT const char*
+oa_strcat(const char* left, const char* right)
+{
+ int left_size = strlen(left);
+ int right_size = strlen(right);
+ int size = left_size + right_size;
+ char* buffer = malloc(size + 1);
+
+ memcpy(buffer, left, left_size);
+ memcpy(buffer + left_size, right, right_size);
+ buffer[size] = '\0';
+ return buffer;
+}
+
/* Return the value of an environment variable. */
OPENAXIOM_EXPORT char*
oa_getenv(const char* var)
@@ -811,3 +827,50 @@ oa_spawn(openaxiom_process* proc, openaxiom_spawn_flags flags)
return proc->id;
#endif
}
+
+OPENAXIOM_EXPORT char*
+oa_substr(const char* str, const size_t begin, const size_t end)
+{
+ char* substring;
+ int len;
+
+ if (str == NULL || strlen(str) == 0 ||
+ strlen(str) < begin || end >= strlen(str) ||
+ begin > end || begin < 0 || end < 0)
+ return NULL;
+
+ len = (end - begin) + 2;
+ substring = malloc(len * sizeof(char));
+ memset(substring,'\0',len);
+ memcpy(substring, str+begin, len-1);
+
+ return substring;
+}
+
+OPENAXIOM_EXPORT char**
+oa_split(const char* sequence, const char* delimiter, int* size)
+{
+ int sequence_length = 0, newsize = 0;
+ char* token;
+ char** tokens = NULL;
+ char* sequence_copy;
+
+ sequence_length = strlen(sequence);
+ sequence_copy = (char*) malloc((sequence_length + 1) * sizeof(char*));
+ strcpy(sequence_copy,sequence);
+ sequence_copy[sequence_length] = '\0';
+
+ token = strtok(sequence_copy, delimiter);
+ while (token != NULL) {
+
+ tokens = (char**) realloc(tokens,(newsize + 1) * sizeof(char*));
+ tokens[newsize] = token;
+ newsize++;
+ token = strtok (NULL, delimiter);
+ }
+
+ *size = newsize;
+
+ return tokens;
+}
+