aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2011-02-13 20:30:03 +0200
committerArnold D. Robbins <arnold@skeeve.com>2011-02-13 20:30:03 +0200
commit32086b1f52a9978db1e8168b56a312e76afcf5ab (patch)
treede490c1c7d47bcbc6428d622957240679483d6b6
parent6bfbae33e99c401f89a4d650ea7958bbdebd362e (diff)
downloadegawk-32086b1f52a9978db1e8168b56a312e76afcf5ab.tar.gz
egawk-32086b1f52a9978db1e8168b56a312e76afcf5ab.tar.bz2
egawk-32086b1f52a9978db1e8168b56a312e76afcf5ab.zip
PC fixes for portability and dependencies.
-rw-r--r--ChangeLog12
-rw-r--r--awk.h7
-rw-r--r--awkgram.c2
-rw-r--r--awkgram.y2
-rw-r--r--debug.c18
-rw-r--r--gawkmisc.c6
-rw-r--r--io.c4
-rw-r--r--main.c2
-rw-r--r--pc/ChangeLog8
-rw-r--r--pc/Makefile24
-rw-r--r--pc/config.h4
-rw-r--r--pc/gawkmisc.pc31
-rw-r--r--posix/ChangeLog5
-rw-r--r--posix/gawkmisc.c8
-rw-r--r--vms/ChangeLog7
-rw-r--r--vms/gawkmisc.vms5
16 files changed, 116 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index 74146501..f76bc66f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Sun Feb 13 20:22:47 2011 Eli Zaretskii <eliz@gnu.org>
+
+ * awkgram.y (add_srcfile):
+ * debug.c (source_find): Pass `path' and `src' to files_are_same.
+ * gawkmisc.c [__DJGPP__ || __MINGW32__]: Include pc/gawkmisc.pc,
+ for consistency with __EMX__ and pc/Makefile.
+ * debug.c (interpret, initialize_pager, prompt_continue)
+ (set_gawk_output): Use ISATTY instead of isatty.
+ * io.c (redirect, iop_alloc): Same.
+ * main.c (main): Same.
+ * awk.h (ISATTY): Trivial definition, if not defined elsewhere.
+
Sun Feb 13 20:16:04 2011 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (check_funcs): Update warning about never called to say
diff --git a/awk.h b/awk.h
index 93822bde..4bc4983a 100644
--- a/awk.h
+++ b/awk.h
@@ -163,6 +163,11 @@ typedef int off_t;
#define O_BINARY 0
#endif
+/* Windows needs a separate definition, see pc/config.h. */
+#ifndef ISATTY
+# define ISATTY(fd) isatty(fd)
+#endif
+
#ifndef HAVE_VPRINTF
#error "you lose: you need a system with vfprintf"
#endif /* HAVE_VPRINTF */
@@ -1122,7 +1127,7 @@ extern INSTRUCTION *bcalloc(OPCODE op, int size, int srcline);
extern void bcfree(INSTRUCTION *);
extern SRCFILE *add_srcfile(int stype, char *src, SRCFILE *curr, int *already_included, int *errcode);
extern void register_deferred_variable(const char *name, NODE *(*load_func)(void));
-extern int files_are_same(struct stat *f1, struct stat *f2);
+extern int files_are_same(char *path, SRCFILE *src);
extern void valinfo(NODE *n, Func_print print_func, FILE *fp);
extern void print_vars(Func_print print_func, FILE *fp);
extern AWK_CONTEXT *new_context(void);
diff --git a/awkgram.c b/awkgram.c
index b6b07649..8d812c40 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -4889,7 +4889,7 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, int *already_included, int
for (s = srcfiles->next; s != srcfiles; s = s->next) {
if ((s->stype == SRC_FILE || s->stype == SRC_INC)
- && files_are_same(& sbuf, & s->sbuf)
+ && files_are_same(path, s)
) {
if (do_lint)
lintwarn(_("already included source file `%s'"), src);
diff --git a/awkgram.y b/awkgram.y
index d491b56f..04313e6f 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -2242,7 +2242,7 @@ add_srcfile(int stype, char *src, SRCFILE *thisfile, int *already_included, int
for (s = srcfiles->next; s != srcfiles; s = s->next) {
if ((s->stype == SRC_FILE || s->stype == SRC_INC)
- && files_are_same(& sbuf, & s->sbuf)
+ && files_are_same(path, s)
) {
if (do_lint)
lintwarn(_("already included source file `%s'"), src);
diff --git a/debug.c b/debug.c
index c54af488..fafbc7f7 100644
--- a/debug.c
+++ b/debug.c
@@ -496,11 +496,13 @@ source_find(char *src)
path = find_source(src, &sbuf, &errno_val);
if (path != NULL) {
- efree(path);
for (s = srcfiles->next; s != srcfiles; s = s->next) {
if ((s->stype == SRC_FILE || s->stype == SRC_INC)
- && files_are_same(& s->sbuf, & sbuf))
+ && files_are_same(path, s)) {
+ efree(path);
return s;
+ }
+ efree(path);
}
}
@@ -2736,7 +2738,7 @@ interpret(INSTRUCTION *pc)
input_fd = fileno(stdin);
out_fp = stdout;
- if (isatty(input_fd))
+ if (ISATTY(input_fd))
input_from_tty = TRUE;
if (input_fd == 0 && input_from_tty)
initialize_readline();
@@ -4084,7 +4086,7 @@ do_option(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
void
initialize_pager(FILE *fp)
{
- if (! isatty(fileno(fp)) || ! input_from_tty || input_fd != 0) {
+ if (! ISATTY(fileno(fp)) || ! input_from_tty || input_fd != 0) {
screen_width = INT_MAX;
screen_height = INT_MAX;
} else {
@@ -4108,7 +4110,7 @@ prompt_continue(FILE *fp)
{
int quit_pager = FALSE;
- if (isatty(fileno(fp)) && input_fd == 0)
+ if (ISATTY(fileno(fp)) && input_fd == 0)
quit_pager = prompt_yes_no(
_("\t------[Enter] to continue or q [Enter] to quit------"),
_("q")[0], FALSE, fp);
@@ -5066,7 +5068,7 @@ set_gawk_output(const char *file)
efree(output_file);
}
output_fp = stdout;
- output_is_tty = isatty(fileno(stdout));
+ output_is_tty = ISATTY(fileno(stdout));
output_file = "/dev/stdout";
}
@@ -5087,7 +5089,7 @@ set_gawk_output(const char *file)
if (STREQ(cp, "stderr")) {
output_fp = stderr;
output_file = "/dev/stderr";
- output_is_tty = isatty(fileno(stderr));
+ output_is_tty = ISATTY(fileno(stderr));
return;
}
@@ -5120,7 +5122,7 @@ set_gawk_output(const char *file)
output_fp = fp;
output_file = estrdup(file, strlen(file));
setbuf(fp, (char *) NULL);
- output_is_tty = isatty(fileno(fp));
+ output_is_tty = ISATTY(fileno(fp));
} else {
d_error(_("could not open `%s' for writing (%s)"),
file,
diff --git a/gawkmisc.c b/gawkmisc.c
index ba37fc2b..7a91e364 100644
--- a/gawkmisc.c
+++ b/gawkmisc.c
@@ -32,11 +32,8 @@
/* some old compilers don't grok #elif. sigh */
-#ifdef __EMX__
+#if defined(__EMX__) || defined(__DJGPP__) || defined(__MINGW32__)
#include "pc/gawkmisc.pc"
-#else /* not __EMX__ */
-#if defined(__DJGPP__) || defined(__MINGW32__)
-#include "gawkmisc.pc"
#else /* not __DJGPP__, not __MINGW32__ */
#if defined(VMS)
#include "vms/gawkmisc.vms"
@@ -44,7 +41,6 @@
#include "posix/gawkmisc.c"
#endif /* not VMS */
#endif /* not __DJGPP__, not __MINGW32__ */
-#endif /* not __EMX__ */
/* xmalloc --- provide this so that other GNU library routines work */
diff --git a/io.c b/io.c
index be6c462c..d14796ba 100644
--- a/io.c
+++ b/io.c
@@ -781,7 +781,7 @@ redirect(NODE *redir_exp, int redirtype, int *errflg)
if (rp->fp == NULL)
close(fd);
}
- if (rp->fp != NULL && isatty(fd))
+ if (rp->fp != NULL && ISATTY(fd))
rp->flag |= RED_NOBUF;
/* Move rp to the head of the list. */
@@ -2561,7 +2561,7 @@ iop_alloc(int fd, const char *name, IOBUF *iop, int do_openhooks)
return NULL;
}
- if (isatty(iop->fd))
+ if (ISATTY(iop->fd))
iop->flag |= IOP_IS_TTY;
iop->readsize = iop->size = optimal_bufsize(iop->fd, & sbuf);
iop->sbuf = sbuf;
diff --git a/main.c b/main.c
index 79178ae8..ff322670 100644
--- a/main.c
+++ b/main.c
@@ -634,7 +634,7 @@ out:
#ifdef GAWKDEBUG
setbuf(stdout, (char *) NULL); /* make debugging easier */
#endif
- if (isatty(fileno(stdout)))
+ if (ISATTY(fileno(stdout)))
output_is_tty = TRUE;
/* No -f or --source options, use next arg */
if (srcfiles->next == srcfiles) {
diff --git a/pc/ChangeLog b/pc/ChangeLog
index da02a048..9143dee5 100644
--- a/pc/ChangeLog
+++ b/pc/ChangeLog
@@ -1,3 +1,11 @@
+Sun Feb 13 20:23:07 2011 Eli Zaretskii <eliz@gnu.org>
+
+ * gawkmisc.pc (files_are_same): Change arguments. Compare file
+ names and modification times in addition to devices and inodes.
+ * Makefile (LIBOBJS): Add hard-locale$O.
+ Update prerequisites.
+ * config.h (ISATTY) [__MINGW32__ || _MSC_VER]: Define.
+
Mon Feb 7 22:45:28 2011 Arnold Robbins <arnold@skeeve.com>
* Makefile.tst: Sync with mainline version.
diff --git a/pc/Makefile b/pc/Makefile
index 8a8888e0..9d681458 100644
--- a/pc/Makefile
+++ b/pc/Makefile
@@ -188,7 +188,7 @@ ALLOBJS = $(AWKOBJS) awkgram$O getid$O $(OBJ)
# LIBOBJS
# GNU and other stuff that gawk uses as library routines.
-LIBOBJS= getopt$O getopt1$O dfa$O regex$O random$O
+LIBOBJS= getopt$O getopt1$O dfa$O regex$O random$O hard-locale$O
GAWKOBJS = $(ALLOBJS) $(LIBOBJS)
PGAWKOBJS = $(PAWKOBJS1) $(PAWKOBJS2) $(LIBOBJS) awkgram$O getid$O $(OBJ)
@@ -231,16 +231,32 @@ $(DRSPFILE) : $(DGAWKOBJS)
echo $(DAWKOBJS2)$P >> $@
echo awkgram$O getid$O $(OBJ) $(LIBOBJS)$P >> $@
-$(ALLOBJS) eval_p$O profile_p$O: awk.h regex.h config.h
+# Notes to dependencies:
+# 1. The dependency on getopt.h is because unistd.h includes it,
+# and we have -I. on the compiler command line. unistd.h is
+# included by awk.h.
+# 2. custom.h is not mentioned because pc ports don't use it.
+$(ALLOBJS) $(LIBOBJS) eval_p$O profile_p$O: \
+ awk.h regex.h config.h gettext.h mbsupport.h protos.h dfa.h getopt.h
+
+builtin$O random$O: awkprintf.h floatmagic.h random.h
+
+debug$O: awkprintf.h floatmagic.h
+
+command$O debug$O: cmd.h
+
+dfa$O: hard-locale.h xalloc.h
gawkmisc$O: pc/gawkmisc.pc
-getopt$O: getopt.h
+getopt$O getopt1$O : getopt_int.h
-getopt1$O: getopt.h
+hard-locale$O: hard-locale.h
io$O: popen.h
+regex$O: regcomp.c regexec.c regex_internal.h
+
eval_p$O: eval.c
profile_p$O: profile.c
diff --git a/pc/config.h b/pc/config.h
index 4dd797c1..4ec2d711 100644
--- a/pc/config.h
+++ b/pc/config.h
@@ -518,4 +518,8 @@
#define HAVE_USLEEP 1
#endif
+#if defined(__MINGW32__) || defined(_MSC_VER)
+# define ISATTY(fd) (isatty(fd) && lseek(fd,SEEK_CUR,0) == -1)
+#endif
+
/* #define NO_LINT 1 */
diff --git a/pc/gawkmisc.pc b/pc/gawkmisc.pc
index 74a2d7db..67760676 100644
--- a/pc/gawkmisc.pc
+++ b/pc/gawkmisc.pc
@@ -284,9 +284,36 @@ int fd;
/* files_are_same --- return true if files are identical */
int
-files_are_same(struct stat *f1, struct stat *f2)
+files_are_same(char *path, SRCFILE *src)
{
- return (f1->st_dev == f2->st_dev && f1->st_ino == f2->st_ino);
+ struct stat st;
+ size_t pathlen;
+ char *p, *s;
+
+ if (stat (path, & st) == 0) {
+ /* If they have a working `stat', honor that. */
+ if (!(st.st_dev == src->sbuf.st_dev
+ && st.st_ino == src->sbuf.st_ino))
+ return 0;
+
+ /* Compare modification times. */
+ if (st.st_mtime != src->mtime)
+ return 0;
+
+ /* Compare absolute file names case-insensitively, and
+ treat forward- and back-slashes as equal. */
+ pathlen = strlen(path);
+ for (p = path, s = src->fullpath;
+ p <= path + pathlen;
+ p++, s++) {
+ if (tolower(*p) != tolower(*s)
+ && !((*p == '/' || *p == '\\')
+ && (*s == '/' || *s == '\\')))
+ return 0;
+ }
+ return 1;
+ }
+ return 0;
}
diff --git a/posix/ChangeLog b/posix/ChangeLog
index 7df9b9e6..e0cce059 100644
--- a/posix/ChangeLog
+++ b/posix/ChangeLog
@@ -1,3 +1,8 @@
+Sun Feb 13 20:23:34 2011 Eli Zaretskii <eliz@gnu.org>
+
+ * gawkmisc.c (files_are_same): Change arguments; call `stat' as
+ part of the body.
+
Tue Feb 1 23:05:51 2011 Corinna Vinschen <vinschen@redhat.com>
Make values of ctype macros into unsigned char to fix
diff --git a/posix/gawkmisc.c b/posix/gawkmisc.c
index 2e70cf9c..0b3aa6d5 100644
--- a/posix/gawkmisc.c
+++ b/posix/gawkmisc.c
@@ -237,9 +237,13 @@ os_restore_mode(int fd)
/* files_are_same --- return true if files are identical */
int
-files_are_same(struct stat *f1, struct stat *f2)
+files_are_same(char *path, SRCFILE *src)
{
- return (f1->st_dev == f2->st_dev && f1->st_ino == f2->st_ino);
+ struct stat st;
+
+ return (stat(path, & st) == 0
+ && st.st_dev == src->sbuf.st_dev
+ && st.st_ino == src->sbuf.st_ino);
}
#ifdef __CYGWIN__
diff --git a/vms/ChangeLog b/vms/ChangeLog
index cf7b9f9e..1347bc37 100644
--- a/vms/ChangeLog
+++ b/vms/ChangeLog
@@ -1,3 +1,8 @@
+Sun Feb 13 20:23:57 2011 Eli Zaretskii <eliz@gnu.org>
+
+ * gawkmisc.vms (files_are_same): Change arguments; call `stat' as
+ part of the body.
+
Sat Feb 12 19:29:41 2011 Pat Rankin <rankin@pactechdata.com>
* redirect.h (snprintf): Declare regardless of HAVE_SNPRINTF or
@@ -7,7 +12,7 @@ Mon Feb 7 22:43:37 2011 Arnold Robbins <arnold@skeeve.com>
* vmstest.com (negrange): Add new test.
-Sub Feb 6 18:54:20 2011 Pat Rankin <rankin@pactechdata.com>
+Sun Feb 6 18:54:20 2011 Pat Rankin <rankin@pactechdata.com>
* vmstest.com (psx96sub, whiny): Remove obsolete tests.
(aadelete1, aadelete2, aarray1, aasort, assorti, fpat1,
diff --git a/vms/gawkmisc.vms b/vms/gawkmisc.vms
index 6f8fdaef..316e613d 100644
--- a/vms/gawkmisc.vms
+++ b/vms/gawkmisc.vms
@@ -175,7 +175,10 @@ int fd;
int
files_are_same(struct stat *f1, struct stat *f2)
{
- return (strcmp(f1->st_dev, f2->st_dev) == 0
+ struct stat st;
+
+ return (stat(path, & st) == 0
+ && strcmp(f1->st_dev, f2->st_dev) == 0
&& f1->st_ino[0] == f2->st_ino[0]
&& f1->st_ino[1] == f2->st_ino[1]
&& f1->st_ino[2] == f2->st_ino[2]);