From ab4a8ba818d6fa8d237a55639c7361b376162f81 Mon Sep 17 00:00:00 2001 From: dos-reis Date: Wed, 21 May 2008 16:10:51 +0000 Subject: * include/cfuns.h (oa_get_tmpdir): Declare. (oa_access_file_for_read): Likewise. * lib/cfuns-c.c (oa_getcwd): Define. (oa_access_file_for_read): Likewise. (oa_get_tmpdir): Likewise. * hyper/addfile.c: Don't include hyper.h (build_ht_filename): Use oa_getcwd, oa_access_file_for_read. (temp_file_open): Use oa_get_tmpdir. * hyper/htadd.c (build_db_filename): Don't fall back to bogus filename. * hyper/hyper.h (temp_dir): Remove. (def_spad): Likewise. --- configure | 18 ++++++------- configure.ac | 2 +- configure.ac.pamphlet | 2 +- src/ChangeLog | 13 +++++++++ src/hyper/Makefile.in | 1 + src/hyper/addfile.c | 35 +++++++++++++----------- src/hyper/htadd.c | 4 +-- src/hyper/hyper.h | 2 -- src/include/cfuns.h | 3 +++ src/lib/cfuns-c.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 123 insertions(+), 31 deletions(-) diff --git a/configure b/configure index a2c821d3..eb6a42b2 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.60 for OpenAxiom 1.2.0-2008-05-17. +# Generated by GNU Autoconf 2.60 for OpenAxiom 1.2.0-2008-05-21. # # Report bugs to . # @@ -713,8 +713,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='OpenAxiom' PACKAGE_TARNAME='openaxiom' -PACKAGE_VERSION='1.2.0-2008-05-17' -PACKAGE_STRING='OpenAxiom 1.2.0-2008-05-17' +PACKAGE_VERSION='1.2.0-2008-05-21' +PACKAGE_STRING='OpenAxiom 1.2.0-2008-05-21' PACKAGE_BUGREPORT='open-axiom-bugs@lists.sf.net' ac_unique_file="src/Makefile.pamphlet" @@ -1402,7 +1402,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures OpenAxiom 1.2.0-2008-05-17 to adapt to many kinds of systems. +\`configure' configures OpenAxiom 1.2.0-2008-05-21 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1472,7 +1472,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of OpenAxiom 1.2.0-2008-05-17:";; + short | recursive ) echo "Configuration of OpenAxiom 1.2.0-2008-05-21:";; esac cat <<\_ACEOF @@ -1576,7 +1576,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -OpenAxiom configure 1.2.0-2008-05-17 +OpenAxiom configure 1.2.0-2008-05-21 generated by GNU Autoconf 2.60 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -1590,7 +1590,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by OpenAxiom $as_me 1.2.0-2008-05-17, which was +It was created by OpenAxiom $as_me 1.2.0-2008-05-21, which was generated by GNU Autoconf 2.60. Invocation command line was $ $0 $@ @@ -26078,7 +26078,7 @@ exec 6>&1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by OpenAxiom $as_me 1.2.0-2008-05-17, which was +This file was extended by OpenAxiom $as_me 1.2.0-2008-05-21, which was generated by GNU Autoconf 2.60. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -26127,7 +26127,7 @@ Report bugs to ." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -OpenAxiom config.status 1.2.0-2008-05-17 +OpenAxiom config.status 1.2.0-2008-05-21 configured by $0, generated by GNU Autoconf 2.60, with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index 93cce25d..03d52d80 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ sinclude(config/open-axiom.m4) sinclude(config/aclocal.m4) -AC_INIT([OpenAxiom], [1.2.0-2008-05-17], +AC_INIT([OpenAxiom], [1.2.0-2008-05-21], [open-axiom-bugs@lists.sf.net]) AC_CONFIG_AUX_DIR(config) diff --git a/configure.ac.pamphlet b/configure.ac.pamphlet index a805f7b9..027ed12d 100644 --- a/configure.ac.pamphlet +++ b/configure.ac.pamphlet @@ -1108,7 +1108,7 @@ information: <>= sinclude(config/open-axiom.m4) sinclude(config/aclocal.m4) -AC_INIT([OpenAxiom], [1.2.0-2008-05-17], +AC_INIT([OpenAxiom], [1.2.0-2008-05-21], [open-axiom-bugs@lists.sf.net]) @ diff --git a/src/ChangeLog b/src/ChangeLog index 738b80d7..181b1f70 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,18 @@ 2008-05-21 Gabriel Dos Reis + * include/cfuns.h (oa_get_tmpdir): Declare. + (oa_access_file_for_read): Likewise. + * lib/cfuns-c.c (oa_getcwd): Define. + (oa_access_file_for_read): Likewise. + (oa_get_tmpdir): Likewise. + * hyper/addfile.c: Don't include hyper.h + (build_ht_filename): Use oa_getcwd, oa_access_file_for_read. + (temp_file_open): Use oa_get_tmpdir. + * hyper/htadd.c (build_db_filename): Don't fall back to bogus + filename. + * hyper/hyper.h (temp_dir): Remove. + (def_spad): Likewise. + * hyper/hyper.h (connect_spad): Declare. (gPageBeingParsed): Likewise. * hyper/htadd.c (session_server): Remove. diff --git a/src/hyper/Makefile.in b/src/hyper/Makefile.in index a09184c9..83ca718f 100644 --- a/src/hyper/Makefile.in +++ b/src/hyper/Makefile.in @@ -117,6 +117,7 @@ clean-local: mostclean-local -rm -f $(BINFILES) -rm -rf $(HYPER)/pages -rm -f $(SCRIPTS) + -rm -f stamp distclean-local: clean-local diff --git a/src/hyper/addfile.c b/src/hyper/addfile.c index 6e460fc6..7b6121b5 100644 --- a/src/hyper/addfile.c +++ b/src/hyper/addfile.c @@ -33,19 +33,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define _ADDFILE_C +#include "openaxiom-c-macros.h" -#include "debug.h" +#include +#include +#include +#include +#include "debug.h" +#include "cfuns.h" +#include "halloc.h" #include "sockio.h" #include "addfile.h" -#include "hyper.h" -#include "addfile.h" -#include -#include -#include "halloc.h" static int build_ht_filename(char*, char*, char*); static int pathname(char*); @@ -91,7 +92,6 @@ extend_ht(char *name) static int build_ht_filename(char *fname, char *aname, char *name) { - char cdir[256]; char *c_dir; char *HTPATH; char *trace; @@ -100,8 +100,9 @@ build_ht_filename(char *fname, char *aname, char *name) if (cwd(name)) { /* user wants to use the current working directory */ - c_dir = (char *) getcwd(cdir, 254); + c_dir = oa_getcwd(); strcpy(fname, c_dir); + free(c_dir); /* Now add the rest of the filename */ strcat(fname, "/"); @@ -123,7 +124,7 @@ build_ht_filename(char *fname, char *aname, char *name) extend_ht(fname); /* Now just try to access the file */ - return (access(fname, R_OK)); + return oa_access_file_for_read(fname); } else if (pathname(name)) { /* filename already has the path specified */ @@ -145,7 +146,7 @@ build_ht_filename(char *fname, char *aname, char *name) extend_ht(fname); /* Now just try to access the file */ - return (access(fname, R_OK)); + return oa_access_file_for_read(fname); } else {/** If not I am going to have to append path names to it **/ HTPATH = (char *) getenv("HTPATH"); @@ -175,13 +176,15 @@ build_ht_filename(char *fname, char *aname, char *name) *trace = 0; if (!strcmp(fname, "./")) { /** The person wishes me to check the current directory too **/ - getcwd(fname, 256); - strcat(fname, "/"); + c_dir = oa_getcwd(); + strcpy(fname,c_dir); + free(c_dir); + strcat(fname, "/"); } if (*trace2) trace2++; strcat(fname, aname); - ht_file = access(fname, R_OK); + ht_file = oa_access_file_for_read(fname); } return (ht_file); } @@ -303,8 +306,8 @@ temp_file_open(char *temp_db_file) /** Just make the name and open it **/ - strcpy(temp_db_file, temp_dir); - strcat(temp_db_file, "ht2.db" /* db_file_name */ ); + strcpy(temp_db_file, oa_get_tmpdir()); + strcat(temp_db_file, "/ht2.db" /* db_file_name */ ); temp_db_fp = fopen(temp_db_file, "w"); if (temp_db_fp == NULL) { diff --git a/src/hyper/htadd.c b/src/hyper/htadd.c index 2c0a1990..18345d8f 100644 --- a/src/hyper/htadd.c +++ b/src/hyper/htadd.c @@ -211,8 +211,8 @@ build_db_filename(short flag, char *db_dir, char *dbfilename) SPAD = (char *) getenv("AXIOM"); if (SPAD == NULL) { fprintf(stderr, - "Build_db_filename: Defaulting on $AXIOM\n"); - SPAD = (char *) def_spad; + "build_db_filename: cannot find system root directory\n"); + exit(-1); } sprintf(dbfilename, "%s/share/hypertex/pages/%s", SPAD, db_file_name); sprintf(path, "%s/share/hypertex/pages", SPAD); diff --git a/src/hyper/hyper.h b/src/hyper/hyper.h index 7107d7d3..cbb2b506 100644 --- a/src/hyper/hyper.h +++ b/src/hyper/hyper.h @@ -446,9 +446,7 @@ extern int space_width; htadd.c ******/ #define NoChar -9999 -#define temp_dir "/tmp/" #define db_file_name "ht.db" -#define def_spad "/usr/local/axiom" /* Types of HyperDoc pages */ diff --git a/src/include/cfuns.h b/src/include/cfuns.h index 52ad54f7..21f5d037 100644 --- a/src/include/cfuns.h +++ b/src/include/cfuns.h @@ -51,5 +51,8 @@ OPENAXIOM_EXPORT int oa_rename(const char*, const char*); OPENAXIOM_EXPORT int oa_mkdir(const char*); OPENAXIOM_EXPORT int oa_system(const char*); OPENAXIOM_EXPORT char* oa_getenv(const char*); +OPENAXIOM_EXPORT char* oa_getcwd(void); +OPENAXIOM_EXPORT int oa_access_file_for_read(const char*); +OPENAXIOM_EXPORT const char* oa_get_tmpdir(void); #endif /* OPENAXIOM_CFUNS_included */ diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c index 4a1e596f..bc6e10bd 100644 --- a/src/lib/cfuns-c.c +++ b/src/lib/cfuns-c.c @@ -466,3 +466,77 @@ oa_getenv(const char* var) return getenv(var); #endif } + + +OPENAXIOM_EXPORT char* +oa_getcwd(void) +{ + int bufsz = 256; + char* buf = (char*) malloc(bufsz); +#ifdef __MINGW32__ + int n = GetCurrentDirectory(bufsz, bufsz); + if (n == 0) { + perror("oa_getcwd"); + exit(-1); + } + else if (n > bufsz) { + buf = realloc(buf,n); + if (GetCurrentDirectory(n, buf) != n) { + perror("oa_getcwd"); + exit(-1); + } + } + return buf; +#else /* __MINGW32__ */ + errno = 0; + while (getcwd(buf,bufsz) == 0) { + if (errno == ERANGE) { + errno = 0; + bufsz *= 2; + buf = realloc(buf, bufsz); + } + else { + perror("oa_getcwd"); + exit(-1); + } + } + return buf; +#endif +} + +OPENAXIOM_EXPORT int +oa_access_file_for_read(const char* path) +{ +#ifdef __MINGW32__ + GetFileAttributes(path) == INVALID_FILE_ATTRIBUTES ? -1 : 1; +#else + return access(path, R_OK); +#endif +} + + +OPENAXIOM_EXPORT const char* +oa_get_tmpdir(void) +{ +#ifdef __MINGW32__ + char* buf; + /* First, probe. */ + int bufsz = GetTempPath(0, NULL); + if (bufsz == 0) { + perror("oa_get_tmpdir"); + exit(-1); + } + else { + buf = (char*) malloc(bufsz + 1); + if(GetTempPath(bufsz, buf) != bufsz) { + perror("oa_get_tmpdir"); + free(buf); + exit(-1); + } + buf[bufsz] = '\0'; + } + return buf; +#else + return "/tmp"; +#endif +} -- cgit v1.2.3