about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/compctl.c2
-rw-r--r--Src/Zle/zle_params.c61
-rw-r--r--Src/builtin.c25
-rw-r--r--Src/hist.c48
-rw-r--r--Src/params.c27
-rw-r--r--Src/prompt.c4
-rw-r--r--Src/zsh.h3
7 files changed, 106 insertions, 64 deletions
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index 689d28a30..2f2996013 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -3692,7 +3692,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
 	/* We have a pattern to take things from the history. */
 	Patprog pprogc = NULL;
 	char *e, *h, hpatsav;
-	int i = addhistnum(curhist,-1,HIST_FOREIGN), n = cc->hnum;
+	zlong i = addhistnum(curhist,-1,HIST_FOREIGN), n = cc->hnum;
 	Histent he = gethistent(i, GETHIST_UPWARD);
 
 	/* Parse the pattern, if it isn't the null string. */
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index f0f1cde95..efbad97f5 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -55,43 +55,45 @@ static struct zleparam {
 } zleparams[] = {
     { "BUFFER",  PM_SCALAR,  FN(set_buffer),  FN(get_buffer),
 	zleunsetfn, NULL },
-    { "CURSOR",  PM_INTEGER, FN(set_cursor),  FN(get_cursor),
-	zleunsetfn, NULL },
-    { "MARK",  PM_INTEGER, FN(set_mark),  FN(get_mark),
-	zleunsetfn, NULL },
-    { "LBUFFER", PM_SCALAR,  FN(set_lbuffer), FN(get_lbuffer),
-	zleunsetfn, NULL },
-    { "RBUFFER", PM_SCALAR,  FN(set_rbuffer), FN(get_rbuffer),
+    { "BUFFERLINES", PM_INTEGER | PM_READONLY, NULL, FN(get_bufferlines),
+        zleunsetfn, NULL },
+    { "CONTEXT", PM_SCALAR | PM_READONLY, NULL, FN(get_context),
 	zleunsetfn, NULL },
-    { "PREBUFFER",  PM_SCALAR | PM_READONLY,  NULL,  FN(get_prebuffer),
+    { "CURSOR",  PM_INTEGER, FN(set_cursor),  FN(get_cursor),
 	zleunsetfn, NULL },
-    { "WIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_widget),
-        zleunsetfn, NULL },
-    { "LASTWIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_lwidget),
+    { "CUTBUFFER", PM_SCALAR, FN(set_cutbuffer), FN(get_cutbuffer),
+	unset_cutbuffer, NULL },
+    { "HISTNO", PM_INTEGER, FN(set_histno), FN(get_histno),
         zleunsetfn, NULL },
     { "KEYMAP", PM_SCALAR | PM_READONLY, NULL, FN(get_keymap),
         zleunsetfn, NULL },
     { "KEYS", PM_SCALAR | PM_READONLY, NULL, FN(get_keys),
         zleunsetfn, NULL },
-    { "NUMERIC", PM_INTEGER | PM_UNSET, FN(set_numeric), FN(get_numeric),
-        unset_numeric, NULL },
-    { "HISTNO", PM_INTEGER, FN(set_histno), FN(get_histno),
+    { "killring", PM_ARRAY, FN(set_killring), FN(get_killring),
+	unset_killring, NULL },
+    { "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch),
         zleunsetfn, NULL },
-    { "BUFFERLINES", PM_INTEGER | PM_READONLY, NULL, FN(get_bufferlines),
+    { "LASTWIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_lwidget),
         zleunsetfn, NULL },
+    { "LBUFFER", PM_SCALAR,  FN(set_lbuffer), FN(get_lbuffer),
+	zleunsetfn, NULL },
+    { "MARK",  PM_INTEGER, FN(set_mark),  FN(get_mark),
+	zleunsetfn, NULL },
+    { "NUMERIC", PM_INTEGER | PM_UNSET, FN(set_numeric), FN(get_numeric),
+        unset_numeric, NULL },
     { "PENDING", PM_INTEGER | PM_READONLY, NULL, FN(get_pending),
         zleunsetfn, NULL },
-    { "CUTBUFFER", PM_SCALAR, FN(set_cutbuffer), FN(get_cutbuffer),
-	unset_cutbuffer, NULL },
-    { "killring", PM_ARRAY, FN(set_killring), FN(get_killring),
-	unset_killring, NULL },
+    { "POSTDISPLAY", PM_SCALAR, FN(set_postdisplay), FN(get_postdisplay),
+	zleunsetfn, NULL },
+    { "PREBUFFER",  PM_SCALAR | PM_READONLY,  NULL,  FN(get_prebuffer),
+	zleunsetfn, NULL },
     { "PREDISPLAY", PM_SCALAR, FN(set_predisplay), FN(get_predisplay),
 	zleunsetfn, NULL },
-    { "POSTDISPLAY", PM_SCALAR, FN(set_postdisplay), FN(get_postdisplay),
+    { "RBUFFER", PM_SCALAR,  FN(set_rbuffer), FN(get_rbuffer),
 	zleunsetfn, NULL },
-    { "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch),
+    { "WIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_widget),
         zleunsetfn, NULL },
-    { "CONTEXT", PM_SCALAR | PM_READONLY, NULL, FN(get_context),
+    { "WIDGETSTYLE", PM_SCALAR | PM_READONLY, NULL, FN(get_widgetstyle),
 	zleunsetfn, NULL },
     { NULL, 0, NULL, NULL, NULL, NULL }
 };
@@ -280,6 +282,21 @@ get_widget(UNUSED(Param pm))
 
 /**/
 static char *
+get_widgetstyle(UNUSED(Param pm))
+{
+    Widget widget = bindk->widget;
+    int flags = widget->flags;
+
+    if (flags & WIDGET_INT)
+	return ".internal";	/* Don't see how this can ever be returned... */
+    else if (flags & WIDGET_NCOMP)
+	return widget->u.comp.wid;
+    else
+	return widget->u.fnnam;
+}
+
+/**/
+static char *
 get_lwidget(UNUSED(Param pm))
 {
     return (lbindk ? lbindk->nam : "");
diff --git a/Src/builtin.c b/Src/builtin.c
index 0a2d55587..1cfad3e8a 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -1293,7 +1293,8 @@ printif(char *str, int c)
 int
 bin_fc(char *nam, char **argv, Options ops, int func)
 {
-    int first = -1, last = -1, retval;
+    zlong first = -1, last = -1;
+    int retval;
     char *s;
     struct asgment *asgf = NULL, *asgl = NULL;
     Patprog pprog = NULL;
@@ -1305,15 +1306,15 @@ bin_fc(char *nam, char **argv, Options ops, int func)
     }
     if (OPT_ISSET(ops,'p')) {
 	char *hf = "";
-	int hs = DEFAULT_HISTSIZE;
-	int shs = 0;
+	zlong hs = DEFAULT_HISTSIZE;
+	zlong shs = 0;
 	int level = OPT_ISSET(ops,'a') ? locallevel : -1;
 	if (*argv) {
 	    hf = *argv++;
 	    if (*argv) {
-		hs = atoi(*argv++);
+		hs = zstrtol(*argv++, NULL, 10);
 		if (*argv)
-		    shs = atoi(*argv++);
+		    shs = zstrtol(*argv++, NULL, 10);
 		else
 		    shs = hs;
 		if (*argv) {
@@ -1490,10 +1491,10 @@ bin_fc(char *nam, char **argv, Options ops, int func)
 /* get the history event associated with s */
 
 /**/
-static int
+static zlong
 fcgetcomm(char *s)
 {
-    int cmd;
+    zlong cmd;
 
     /* First try to match a history number.  Negative *
      * numbers indicate reversed numbering.           */
@@ -1558,9 +1559,11 @@ fcsubs(char **sp, struct asgment *sub)
 
 /**/
 static int
-fclist(FILE *f, Options ops, int first, int last, struct asgment *subs, Patprog pprog)
+fclist(FILE *f, Options ops, zlong first, zlong last,
+       struct asgment *subs, Patprog pprog)
 {
-    int fclistdone = 0, tmp;
+    int fclistdone = 0;
+    zlong tmp;
     char *s;
     Histent ent;
 
@@ -1592,7 +1595,9 @@ fclist(FILE *f, Options ops, int first, int last, struct asgment *subs, Patprog
 
 	    /* do numbering */
 	    if (!OPT_ISSET(ops,'n')) {
-		fprintf(f, "%5d%c ", ent->histnum,
+		char buf[DIGBUFSIZE];
+		convbase(buf, ent->histnum, 10);
+		fprintf(f, "%5s%c ", buf,
 			ent->flags & HIST_FOREIGN? '*' : ' ');
 	    }
 	    /* output actual time (and possibly date) of execution of the
diff --git a/Src/hist.c b/Src/hist.c
index 0a2226341..74b302cff 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -79,7 +79,7 @@ mod_export int excs, exlast;
  */
  
 /**/
-mod_export int curhist;
+mod_export zlong curhist;
 
 /**/
 struct histent curline;
@@ -87,7 +87,7 @@ struct histent curline;
 /* current line count of allocated history entries */
 
 /**/
-int histlinect;
+zlong histlinect;
 
 /* The history lines are kept in a hash, and also doubly-linked in a ring */
 
@@ -99,12 +99,12 @@ mod_export Histent hist_ring;
 /* capacity of history lists */
  
 /**/
-int histsiz;
+zlong histsiz;
  
 /* desired history-file size (in lines) */
  
 /**/
-int savehistsiz;
+zlong savehistsiz;
  
 /* if = 1, we have performed history substitution on the current line *
  * if = 2, we have used the 'p' modifier                              */
@@ -178,7 +178,7 @@ int hlinesz;
  
 /* default event (usually curhist-1, that is, "!!") */
  
-static int defev;
+static zlong defev;
 
 /* add a character to the current history word */
 
@@ -339,8 +339,10 @@ getargc(Histent ehist)
 static int
 histsubchar(int c)
 {
-    int ev, farg, evset = -1, larg, argc, cflag = 0, bflag = 0;
-    static int mev = -1, marg = -1;
+    int farg, evset = -1, larg, argc, cflag = 0, bflag = 0;
+    zlong ev;
+    static int marg = -1;
+    static zlong mev = -1;
     char buf[256], *ptr;
     char *sline;
     Histent ehist;
@@ -410,7 +412,7 @@ histsubchar(int c)
 		return -1;
 	    }
 	} else {
-	    int t0;
+	    zlong t0;
 
 	    for (;;) {
 		if (inblank(c) || c == ';' || c == ':' || c == '^' ||
@@ -448,7 +450,7 @@ histsubchar(int c)
 			ev = defev;
 		    evset = 0;
 		}
-	    } else if ((t0 = atoi(buf))) {
+	    } else if ((t0 = zstrtol(buf, NULL, 10))) {
 		ev = (t0 < 0) ? addhistnum(curhist,t0,HIST_FOREIGN) : t0;
 		evset = 1;
 	    } else if ((unsigned)*buf == bangchar) {
@@ -839,8 +841,8 @@ histremovedups(void)
 }
 
 /**/
-mod_export int
-addhistnum(int hl, int n, int xflags)
+mod_export zlong
+addhistnum(zlong hl, int n, int xflags)
 {
     int dir = n < 0? -1 : n > 0? 1 : 0;
     Histent he = gethistent(hl, dir);
@@ -892,7 +894,7 @@ down_histent(Histent he)
 
 /**/
 mod_export Histent
-gethistent(int ev, int nearmatch)
+gethistent(zlong ev, int nearmatch)
 {
     Histent he;
 
@@ -927,7 +929,7 @@ putoldhistentryontop(short keep_going)
     Histent he = keep_going? next : hist_ring->down;
     next = he->down;
     if (isset(HISTEXPIREDUPSFIRST) && !(he->flags & HIST_DUP)) {
-	static int max_unique_ct = 0;
+	static zlong max_unique_ct = 0;
 	if (!keep_going)
 	    max_unique_ct = savehistsiz;
 	do {
@@ -1346,7 +1348,7 @@ getargspec(int argc, int marg, int evset)
 /* do ?foo? search */
 
 /**/
-static int
+static zlong
 hconsearch(char *str, int *marg)
 {
     int t1 = 0;
@@ -1370,7 +1372,7 @@ hconsearch(char *str, int *marg)
 /* do !foo search */
 
 /**/
-int
+zlong
 hcomsearch(char *str)
 {
     Histent he;
@@ -1795,7 +1797,7 @@ static struct histfile_stats {
     char *text;
     time_t stim, mtim;
     off_t fpos, fsiz;
-    int next_write_ev;
+    zlong next_write_ev;
 } lasthist;
 
 static struct histsave {
@@ -1803,16 +1805,16 @@ static struct histsave {
     char *histfile;
     HashTable histtab;
     Histent hist_ring;
-    int curhist;
-    int histlinect;
-    int histsiz;
-    int savehistsiz;
+    zlong curhist;
+    zlong histlinect;
+    zlong histsiz;
+    zlong savehistsiz;
     int locallevel;
 } *histsave_stack;
 static int histsave_stack_size = 0;
 static int histsave_stack_pos = 0;
 
-static int histfile_linect;
+static zlong histfile_linect;
 
 static int
 readhistline(int start, char **bufp, int *bufsiz, FILE *in)
@@ -2006,7 +2008,7 @@ savehistfile(char *fn, int err, int writeflags)
     char *t, *start = NULL;
     FILE *out;
     Histent he;
-    int xcurhist = curhist - !!(histactive & HA_ACTIVE);
+    zlong xcurhist = curhist - !!(histactive & HA_ACTIVE);
     int extended_history = isset(EXTENDEDHISTORY);
 
     if (!interact || savehistsiz <= 0 || !hist_ring
@@ -2345,7 +2347,7 @@ bufferwords(LinkList list, char *buf, int *index)
 
 /**/
 int
-pushhiststack(char *hf, int hs, int shs, int level)
+pushhiststack(char *hf, zlong hs, zlong shs, int level)
 {
     struct histsave *h;
     int curline_in_ring = (histactive & HA_ACTIVE) && hist_ring == &curline;
diff --git a/Src/params.c b/Src/params.c
index 4c2a17ee8..f9e382004 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2493,7 +2493,7 @@ nullintsetfn(UNUSED(Param pm), UNUSED(zlong x))
 mod_export zlong
 intvargetfn(Param pm)
 {
-    return *((zlong *)pm->u.data);
+    return *pm->u.valptr;
 }
 
 /* Function to set value of generic special integer *
@@ -2504,7 +2504,7 @@ intvargetfn(Param pm)
 mod_export void
 intvarsetfn(Param pm, zlong x)
 {
-    *((zlong *)pm->u.data) = x;
+    *pm->u.valptr = x;
 }
 
 /* Function to set value of any ZLE-related integer *
@@ -2515,7 +2515,7 @@ intvarsetfn(Param pm, zlong x)
 void
 zlevarsetfn(Param pm, zlong x)
 {
-    zlong *p = (zlong *)pm->u.data;
+    zlong *p = pm->u.valptr;
 
     *p = x;
     if (p == &lines || p == &columns)
@@ -2745,7 +2745,13 @@ randomsetfn(UNUSED(Param pm), zlong v)
 zlong
 intsecondsgetfn(Param pm)
 {
-    return (zlong)floatsecondsgetfn(pm);
+    struct timeval now;
+    struct timezone dummy_tz;
+
+    gettimeofday(&now, &dummy_tz);
+
+    return (zlong)(now.tv_sec - shtimer.tv_sec) +
+	(zlong)(now.tv_usec - shtimer.tv_usec) / (zlong)1000000;
 }
 
 /* Function to set value of special parameter `SECONDS' */
@@ -2754,7 +2760,16 @@ intsecondsgetfn(Param pm)
 void
 intsecondssetfn(Param pm, zlong x)
 {
-    floatsecondssetfn(pm, (double)x);
+    struct timeval now;
+    struct timezone dummy_tz;
+    zlong diff;
+
+    gettimeofday(&now, &dummy_tz);
+    diff = (zlong)now.tv_sec - x;
+    shtimer.tv_sec = diff;
+    if ((zlong)shtimer.tv_sec != diff)
+	zwarn("SECONDS truncated on assignment", NULL, 0);
+    shtimer.tv_usec = 0;
 }
 
 /**/
@@ -3090,6 +3105,8 @@ void
 errnosetfn(UNUSED(Param pm), zlong x)
 {
     errno = (int)x;
+    if ((zlong)errno != x)
+	zwarn("errno truncated on assignment", NULL, 0);
 }
 
 /* Function to get value for special parameter `ERRNO' */
diff --git a/Src/prompt.c b/Src/prompt.c
index c0e73fb5f..fd2977ab6 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -384,7 +384,7 @@ putpromptchar(int doprint, int endchar)
 	    case 'h':
 	    case '!':
 		addbufspc(DIGBUFSIZE);
-		sprintf(bp, "%d", curhist);
+		convbase(bp, curhist, 10);
 		bp += strlen(bp);
 		break;
 	    case 'j':
@@ -676,7 +676,7 @@ putpromptchar(int doprint, int endchar)
 		    pputc('!');
 		} else {
 		    addbufspc(DIGBUFSIZE);
-		    sprintf(bp, "%d", curhist);
+		    convbase(bp, curhist, 10);
 		    bp += strlen(bp);
 		}
 	    }
diff --git a/Src/zsh.h b/Src/zsh.h
index 40d506044..d6515b171 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1129,6 +1129,7 @@ struct param {
 	char **arr;		/* value if declared array   (PM_ARRAY)   */
 	char *str;		/* value if declared string  (PM_SCALAR)  */
 	zlong val;		/* value if declared integer (PM_INTEGER) */
+	zlong *valptr;		/* value if special pointer to integer */
 	double dval;		/* value if declared float
 				                    (PM_EFLOAT|PM_FFLOAT) */
         HashTable hash;		/* value if declared assoc   (PM_HASHED)  */
@@ -1334,7 +1335,7 @@ struct histent {
     short *words;		/* Position of words in history     */
 				/*   line:  as pairs of start, end  */
     int nwords;			/* Number of words in history line  */
-    int histnum;		/* A sequential history number      */
+    zlong histnum;		/* A sequential history number      */
 };
 
 #define HIST_MAKEUNIQUE	0x00000001	/* Kill this new entry if not unique */