about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2012-03-05 10:06:28 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2012-03-05 10:06:28 +0000
commit86f8e8de696404b85c334916bfe3d69bdd4291c6 (patch)
treea37c7c91bfe9f5b92bf574e56009ff86f49e3f0f
parent7614be7fe1b9a9692a6c8f5c5f471df3ef288366 (diff)
downloadzsh-86f8e8de696404b85c334916bfe3d69bdd4291c6.tar.gz
zsh-86f8e8de696404b85c334916bfe3d69bdd4291c6.tar.xz
zsh-86f8e8de696404b85c334916bfe3d69bdd4291c6.zip
30307 plus tweak suggsted by Wayne: use %lld for zlong when long long
-rw-r--r--ChangeLog9
-rw-r--r--Src/Modules/parameter.c20
-rw-r--r--Src/exec.c4
-rw-r--r--Src/glob.c4
-rw-r--r--Src/prompt.c16
-rw-r--r--Src/utils.c8
-rw-r--r--configure.ac31
7 files changed, 87 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 867a702be..7fdb14252 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-03-05  Peter Stephenson  <pws@csr.com>
+
+	* 30307 plus change suggested by Wayne in 30309: configure.ac,
+	Src/exec.c, Src/glob.c, Src/prompt.c, Src/utils.c,
+	Src/Modules/parameter.c: use %lld format where available when
+	zlong is long long.
+
 2012-03-01  Peter Stephenson  <pws@csr.com>
 
 	* 30303: Doc/builtins.yo, Src/options.c: emulate executed inside
@@ -16055,5 +16062,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5600 $
+* $Revision: 1.5601 $
 *****************************************************
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index 092efa0c3..4d29ba635 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -531,7 +531,11 @@ functracegetfn(UNUSED(Param pm))
 	char *colonpair;
 
 	colonpair = zhalloc(strlen(f->caller) + (f->lineno > 9999 ? 24 : 6));
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+	sprintf(colonpair, "%s:%lld", f->caller, f->lineno);
+#else
 	sprintf(colonpair, "%s:%ld", f->caller, (long)f->lineno);
+#endif
 
 	*p = colonpair;
     }
@@ -559,7 +563,11 @@ funcsourcetracegetfn(UNUSED(Param pm))
 	char *fname = f->filename ? f->filename : "";
 
 	colonpair = zhalloc(strlen(fname) + (f->flineno > 9999 ? 24 : 6));
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+	sprintf(colonpair, "%s:%lld", fname, f->flineno);
+#else
 	sprintf(colonpair, "%s:%ld", fname, (long)f->flineno);
+#endif
 
 	*p = colonpair;
     }
@@ -594,7 +602,11 @@ funcfiletracegetfn(UNUSED(Param pm))
 	     */
 	    colonpair = zhalloc(strlen(f->caller) +
 				(f->lineno > 9999 ? 24 : 6));
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+	    sprintf(colonpair, "%s:%lld", f->caller, f->lineno);
+#else
 	    sprintf(colonpair, "%s:%ld", f->caller, (long)f->lineno);
+#endif
 	} else {
 	    /*
 	     * Calling context is a function or eval; we need to find
@@ -604,7 +616,7 @@ funcfiletracegetfn(UNUSED(Param pm))
 	     * together with the $functrace line number for the current
 	     * context.
 	     */
-	    long flineno = (long)(f->prev->flineno + f->lineno);
+	    zlong flineno = f->prev->flineno + f->lineno;
 	    /*
 	     * Line numbers in eval start from 1, not zero,
 	     * so offset by one to get line in file.
@@ -614,7 +626,11 @@ funcfiletracegetfn(UNUSED(Param pm))
 	    fname = f->prev->filename ? f->prev->filename : "";
 
 	    colonpair = zhalloc(strlen(fname) + (flineno > 9999 ? 24 : 6));
-	    sprintf(colonpair, "%s:%ld", fname, flineno);
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+	    sprintf(colonpair, "%s:%lld", fname, flineno);
+#else
+	    sprintf(colonpair, "%s:%ld", fname, (long)flineno);
+#endif
 	}
 
 	*p = colonpair;
diff --git a/Src/exec.c b/Src/exec.c
index aa5c1000e..6ebc9c014 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3252,7 +3252,11 @@ execcmd(Estate state, int input, int output, int how, int last1)
 	    }
 	    if (isset(PRINTEXITVALUE) && isset(SHINSTDIN) &&
 		lastval && !subsh) {
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+		fprintf(stderr, "zsh: exit %lld\n", lastval);
+#else
 		fprintf(stderr, "zsh: exit %ld\n", (long)lastval);
+#endif
 		fflush(stderr);
 	    }
 
diff --git a/Src/glob.c b/Src/glob.c
index 55983815f..d3ce73310 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -2148,7 +2148,11 @@ xpandbraces(LinkList list, LinkNode *np)
 	    for (; rend >= rstart; rend -= rincr) {
 		/* Node added in at end, so do highest first */
 		p = dupstring(str3);
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+		sprintf(p + strp, "%0*lld", minw, rend);
+#else
 		sprintf(p + strp, "%0*ld", minw, (long)rend);
+#endif
 		strcat(p + strp, str2 + 1);
 		insertlinknode(list, last, p);
 		if (rev)	/* decreasing:  add in reverse order. */
diff --git a/Src/prompt.c b/Src/prompt.c
index d15b7c0d4..e51ce2451 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -663,12 +663,20 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		break;
 	    case 'L':
 		addbufspc(DIGBUFSIZE);
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+		sprintf(bv->bp, "%lld", shlvl);
+#else
 		sprintf(bv->bp, "%ld", (long)shlvl);
+#endif
 		bv->bp += strlen(bv->bp);
 		break;
 	    case '?':
 		addbufspc(DIGBUFSIZE);
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+		sprintf(bv->bp, "%lld", lastval);
+#else
 		sprintf(bv->bp, "%ld", (long)lastval);
+#endif
 		bv->bp += strlen(bv->bp);
 		break;
 	    case '%':
@@ -764,7 +772,11 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		    if (funcstack->tp == FS_EVAL)
 			lineno--;
 		    addbufspc(DIGBUFSIZE);
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+		    sprintf(bv->bp, "%lld", flineno);
+#else
 		    sprintf(bv->bp, "%ld", (long)flineno);
+#endif
 		    bv->bp += strlen(bv->bp);
 		    break;
 		}
@@ -772,7 +784,11 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		/* FALLTHROUGH */
 	    case 'i':
 		addbufspc(DIGBUFSIZE);
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+		sprintf(bv->bp, "%lld", lineno);
+#else
 		sprintf(bv->bp, "%ld", (long)lineno);
+#endif
 		bv->bp += strlen(bv->bp);
 		break;
 	    case 'x':
diff --git a/Src/utils.c b/Src/utils.c
index 014cb2fa2..f07d8cc31 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -275,9 +275,13 @@ zerrmsg(FILE *file, const char *fmt, va_list ap)
 #endif
     char *errmsg;
 
-    if ((unset(SHINSTDIN) || locallevel) && lineno)
+    if ((unset(SHINSTDIN) || locallevel) && lineno) {
+#if defined(ZLONG_IS_LONG_LONG) && defined(PRINTF_HAS_LLD)
+	fprintf(file, "%lld: ", lineno);
+#else
 	fprintf(file, "%ld: ", (long)lineno);
-    else
+#endif
+    } else
 	fputc((unsigned char)' ', file);
 
     while (*fmt)
diff --git a/configure.ac b/configure.ac
index 54999b164..82903ca81 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1010,6 +1010,37 @@ main() { return sizeof(ino_t) < 8; }
     fi
   fi
 fi
+AH_TEMPLATE([ZLONG_IS_LONG_LONG],
+[Define to 1 if the zlong type uses long long int.])
+if test "$zsh_cv_64_bit_type" = "long long"; then
+  dnl Remember this so we can get (s)printf output right.
+  AC_DEFINE(ZLONG_IS_LONG_LONG)
+fi
+
+dnl We'll blithely assume (f)printf supports the same types as sprintf.
+AC_CACHE_CHECK(for %lld printf support, zsh_cv_printf_has_lld,
+[AC_TRY_RUN(
+[#include <stdio.h>
+#include <string.h>
+int main(int argc, char **argv)
+{
+   long long foo = ((long long)0xdead << 40) | 0xf00d;
+   char buf[80];
+   sprintf(buf, "before%lldafter", foo);
+   if (!strcmp(buf, "before62677660341432333after")) {
+      return 0;
+   }
+   return 1;
+}
+],
+zsh_cv_printf_has_lld=yes,
+zsh_cv_printf_has_lld=no,
+zsh_cv_printf_has_lld=no)])
+AH_TEMPLATE(PRINTF_HAS_LLD,
+[Define to 1 if printf and sprintf support %lld for long long.])
+if test x$zsh_cv_printf_has_lld = xyes; then
+  AC_DEFINE(PRINTF_HAS_LLD)
+fi
 
 dnl Check for sigset_t.  Currently I'm looking in
 dnl <sys/types.h> and <signal.h>.  Others might need