aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
7 files changed, 351 insertions, 62 deletions
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;
+}
+