aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2008-09-25 04:59:08 +0000
committerdos-reis <gdr@axiomatics.org>2008-09-25 04:59:08 +0000
commite0c8f3d8155dabb7d7d54e426f56febfab77ee92 (patch)
tree4240cc0b9ec9eb01a4bf3e067a13cc74d6c7d403
parente2b728ff9a53eb2ff4518ad10beb649b5e636f74 (diff)
downloadopen-axiom-e0c8f3d8155dabb7d7d54e426f56febfab77ee92.tar.gz
* include/cfuns.h (oa_copy_file): Declare.
* lib/cfuns-c.c (oa_chdir): Define. (oa_dirname): Fix typo. * hyper/htadd.c (copy_file): Remove. (build_db_filename): Tidy. (delete_file): Use oa_copy_file.
-rw-r--r--src/ChangeLog9
-rw-r--r--src/hyper/Makefile.in1
-rw-r--r--src/hyper/htadd.c29
-rw-r--r--src/include/cfuns.h11
-rw-r--r--src/include/open-axiom.h9
-rw-r--r--src/lib/Makefile.in2
-rw-r--r--src/lib/cfuns-c.c32
7 files changed, 68 insertions, 25 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 3f0acc98..6d17d7b4 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2008-09-25 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * include/cfuns.h (oa_copy_file): Declare.
+ * lib/cfuns-c.c (oa_chdir): Define.
+ (oa_dirname): Fix typo.
+ * hyper/htadd.c (copy_file): Remove.
+ (build_db_filename): Tidy.
+ (delete_file): Use oa_copy_file.
+
2008-09-24 Gabriel Dos Reis <gdr@cs.tamu.edu>
* interp/i-analy.boot (putCallInfo): New.
diff --git a/src/hyper/Makefile.in b/src/hyper/Makefile.in
index 034180f3..a29c2601 100644
--- a/src/hyper/Makefile.in
+++ b/src/hyper/Makefile.in
@@ -150,6 +150,7 @@ ${HYPER}/pages/ht.db: all-hyper-pre $(srcdir)/pages/*.pht
done
@ rm -f "${HYPER}"/pages/ht.db
@ rm -f "${HYPER}"/pages/*~
+ @ touch "${HYPER}"/pages/ht.db
for f in `ls "${HYPER}"/pages/*.ht "${HYPER}"/pages/*.pht`; do \
AXIOM="$(AXIOM)" $(HTADD) -s $$f || exit 1; done
@ mkdir -p "$(HYPER)"/bitmaps
diff --git a/src/hyper/htadd.c b/src/hyper/htadd.c
index f08a6205..4e122e45 100644
--- a/src/hyper/htadd.c
+++ b/src/hyper/htadd.c
@@ -54,7 +54,6 @@
static void add_file(char*, char*, int);
static void add_new_pages(FILE*, FILE*, char*, char*);
static int build_db_filename(short, char*, char*);
-static void copy_file(char*, char*);
static void delete_db(FILE*, FILE*, char*);
static int delete_file(char*, char*);
static void get_filename(void);
@@ -217,10 +216,10 @@ build_db_filename(short flag, char *db_dir, char *dbfilename)
}
}
- if (writeablep(dbfilename) != 0)
+ if (writeablep(dbfilename) > 0)
return 1;
- fprintf(stderr, "build_db_filename: Database file name is not writable\n");
+ fprintf(stderr, "build_db_filename: '%s' is not writable\n",dbfilename);
exit(1);
return 0;
}
@@ -270,6 +269,7 @@ add_file(char *dbname, char *name, int fresh)
}
else {
if ((db_fp = fopen(dbname, "r")) == NULL) {
+ exit(-1);
}
}
if (!fresh)
@@ -284,7 +284,8 @@ add_file(char *dbname, char *name, int fresh)
if (db_fp != NULL)
fclose(db_fp);
if (!fresh) {
- copy_file(temp_db_file, dbname);
+ if (oa_copy_file(temp_db_file, dbname) < 0)
+ exit(-1);
unlink(temp_db_file);
}
}
@@ -400,23 +401,6 @@ add_new_pages(FILE *temp_db, FILE *new_file, char *addname, char *fullname)
printf("Added %3d pages and/or macros from %s\n", pages, addname);
}
-static void
-copy_file(char *f1, char *f2)
-{
- FILE *fp1, *fp2;
- int c;
-
- fp1 = fopen(f1, "r");
- fp2 = fopen(f2, "w");
- while ((c = getc(fp1)) != EOF) {
- putc(c, fp2);
- }
- fclose(fp2);
- fclose(fp1);
-}
-
-
-
#define whitespace(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
#define delim(c) \
(whitespace(c) )
@@ -481,7 +465,8 @@ delete_file(char *dbname, char *name)
fclose(temp_db_fp);
if (db_fp != NULL)
fclose(db_fp);
- copy_file(temp_db_file, dbname);
+ if (oa_copy_file(temp_db_file, dbname) < 0)
+ return -1;
unlink(temp_db_file);
return 0;
}
diff --git a/src/include/cfuns.h b/src/include/cfuns.h
index 225ce6de..932c6d2c 100644
--- a/src/include/cfuns.h
+++ b/src/include/cfuns.h
@@ -38,6 +38,10 @@
#include "open-axiom.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
OPENAXIOM_EXPORT int addtopath(char*);
OPENAXIOM_EXPORT int directoryp(char*);
OPENAXIOM_EXPORT int make_path_from_file(char*, char*);
@@ -55,8 +59,15 @@ OPENAXIOM_EXPORT char* oa_getcwd(void);
OPENAXIOM_EXPORT int oa_access_file_for_read(const char*);
OPENAXIOM_EXPORT char* oa_dirname(const char*);
OPENAXIOM_EXPORT const char* oa_get_tmpdir(void);
+OPENAXIOM_EXPORT int oa_copy_file(const char*, const char*);
+
OPENAXIOM_EXPORT double plus_infinity(void);
OPENAXIOM_EXPORT double minus_infinity(void);
OPENAXIOM_EXPORT double NANQ(void);
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* OPENAXIOM_CFUNS_included */
diff --git a/src/include/open-axiom.h b/src/include/open-axiom.h
index 19cbfedf..cae21d08 100644
--- a/src/include/open-axiom.h
+++ b/src/include/open-axiom.h
@@ -65,6 +65,10 @@ typedef void* openaxiom_handle;
#include <unistd.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* Do we have graphics support? */
#ifdef X_DISPLAY_MISSING
# define OPENAXIOM_HAVE_GRAPHICS 0
@@ -94,4 +98,9 @@ openaxiom_sleep(int n)
#endif
}
+
+#ifdef __cplusplus
+}
+#endif
+
#endif /* OPENAXIOM_included */
diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in
index 7ce00fad..fd84b82c 100644
--- a/src/lib/Makefile.in
+++ b/src/lib/Makefile.in
@@ -100,7 +100,7 @@ libspad.$(LIBEXT): $(libspad_objects)
.PRECIOUS: %.$(OBJEXT)
%.$(OBJEXT) %.lo: %.c $(axiom_c_macros_h)
- $(COMPILE) $(oa_shrobj_flags) -no-suppress -o $@ $(CCF) \
+ $(COMPILE) $(oa_shrobj_flags) -no-suppress -o $@ $(CCF) -g \
$(axiom_includes) $(AXIOM_X11_CFLAGS) $<
# This is a support library, so it does not change often and
diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c
index 47a1f8c4..fc2a7e14 100644
--- a/src/lib/cfuns-c.c
+++ b/src/lib/cfuns-c.c
@@ -39,18 +39,19 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
+#include <unistd.h>
#ifdef __WIN32__
# include <windows.h>
#else
# include <dirent.h>
+# include <fcntl.h>
#endif
#include "cfuns.h"
@@ -115,7 +116,7 @@ OPENAXIOM_EXPORT char*
oa_dirname(const char* path)
{
const int n = strlen(path);
- char* mark = mark + n;
+ char* mark = path + n;
if (n == 0)
return strdup(".");
@@ -608,6 +609,33 @@ oa_get_tmpdir(void)
}
+OPENAXIOM_EXPORT int
+oa_copy_file(const char* src, const char* dst)
+{
+#ifdef __WIN32__
+ return CopyFile(src,dst, /* bFailIfExists = */ 0) ? 0 : -1;
+#else
+#define OA_BUFSZ 512
+ char buf[OA_BUFSZ];
+ int src_fd;
+ int dst_fd;
+ int count;
+ if((src_fd = open(src, O_RDONLY)) < 0)
+ return -1;
+ if ((dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC)) < 0) {
+ close(src_fd);
+ return -1;
+ }
+
+ while ((count = read(src_fd, buf, OA_BUFSZ)) > 0)
+ if (write(dst_fd, buf, count) != count)
+ break;
+
+#undef OA_BUFSZ
+ return (close(dst_fd) < 0 || close(src_fd) < 0 || count < 0) ? -1 : 0;
+#endif
+}
+
OPENAXIOM_EXPORT double
plus_infinity(void )