about summary refs log tree commit diff
path: root/Src/Zle/zle_main.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2013-11-12 20:41:06 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2013-11-12 20:41:06 +0000
commit2fc2bb7c17aeb7514e5d42e46bb08304480bf125 (patch)
treeafb737eff06f9a69d2889905484685bbe35d6eb0 /Src/Zle/zle_main.c
parent3c733361c45f98b7740388fc78d77a1a307e9a20 (diff)
downloadzsh-2fc2bb7c17aeb7514e5d42e46bb08304480bf125.tar.gz
zsh-2fc2bb7c17aeb7514e5d42e46bb08304480bf125.tar.xz
zsh-2fc2bb7c17aeb7514e5d42e46bb08304480bf125.zip
31961: rationalise fd watching to use structure
Diffstat (limited to 'Src/Zle/zle_main.c')
-rw-r--r--Src/Zle/zle_main.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index 6822230b4..040b7cb83 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -197,12 +197,11 @@ static int delayzsetterm;
  */
 /**/
 int nwatch;		/* Number of fd's we are watching */
+/*
+ * Array of nwatch structures.
+ */
 /**/
-int *watch_fds;		/* The list of fds, not terminated! */
-/**/
-char **watch_funcs;	/* The corresponding functions to call, normal array */
-/**/
-int *watch_widgets;     /* 1 if corresponding function is called as widget */
+Watch_fd watch_fds;
 
 /* set up terminal */
 
@@ -588,7 +587,7 @@ raw_getbyte(long do_keytmout, char *cptr)
 	 */
 	fds[0].events = POLLIN;
 	for (i = 0; i < nwatch; i++) {
-	    fds[i+1].fd = watch_fds[i];
+	    fds[i+1].fd = watch_fds[i].fd;
 	    fds[i+1].events = POLLIN;
 	}
 # endif
@@ -613,7 +612,7 @@ raw_getbyte(long do_keytmout, char *cptr)
 	    FD_SET(SHTTY, &foofd);
 	    if (!errtry) {
 		for (i = 0; i < nwatch; i++) {
-		    int fd = watch_fds[i];
+		    int fd = watch_fds[i].fd;
 		    FD_SET(fd, &foofd);
 		    if (fd > fdmax)
 			fdmax = fd;
@@ -725,33 +724,33 @@ raw_getbyte(long do_keytmout, char *cptr)
 		 * handler function.
 		 */
 		int lnwatch = nwatch;
-		int *lwatch_fds = zalloc(lnwatch*sizeof(int));
-		char **lwatch_funcs = zarrdup(watch_funcs);
-		int *lwatch_widgets = zalloc(lnwatch*sizeof(int));
-		memcpy(lwatch_fds, watch_fds, lnwatch*sizeof(int));
-		memcpy(lwatch_widgets, watch_widgets, lnwatch*sizeof(int));
+		Watch_fd lwatch_fds = zalloc(lnwatch*sizeof(struct watch_fd));
+		memcpy(lwatch_fds, watch_fds, lnwatch*sizeof(struct watch_fd));
+		for (i = 0; i < lnwatch; i++)
+		    lwatch_fds[i].func = ztrdup(lwatch_fds[i].func);
 		for (i = 0; i < lnwatch; i++) {
+		    Watch_fd lwatch_fd = lwatch_fds + i;
 		    if (
 # ifdef HAVE_POLL
 			(fds[i+1].revents & POLLIN)
 # else
-			FD_ISSET(lwatch_fds[i], &foofd)
+			FD_ISSET(lwatch_fd->fd, &foofd)
 # endif
 			) {
 			/* Handle the fd. */
 			char *fdbuf;
 			{
 			    char buf[BDIGBUFSIZE];
-			    convbase(buf, lwatch_fds[i], 10);
+			    convbase(buf, lwatch_fd->fd, 10);
 			    fdbuf = ztrdup(buf);
 			}
 
-			if (lwatch_widgets[i]) {
-			    zlecallhook(lwatch_funcs[i], fdbuf);
+			if (lwatch_fd->widget) {
+			    zlecallhook(lwatch_fd->func, fdbuf);
 			    zsfree(fdbuf);
 			} else {
 			    LinkList funcargs = znewlinklist();
-			    zaddlinknode(funcargs, ztrdup(lwatch_funcs[i]));
+			    zaddlinknode(funcargs, ztrdup(lwatch_fd->func));
 			    zaddlinknode(funcargs, fdbuf);
 # ifdef HAVE_POLL
 #  ifdef POLLERR
@@ -767,7 +766,7 @@ raw_getbyte(long do_keytmout, char *cptr)
 				zaddlinknode(funcargs, ztrdup("nval"));
 #  endif
 # endif
-			    callhookfunc(lwatch_funcs[i], funcargs, 0, NULL);
+			    callhookfunc(lwatch_fd->func, funcargs, 0, NULL);
 			    freelinklist(funcargs, freestr);
 			}
 			if (errflag) {
@@ -784,8 +783,9 @@ raw_getbyte(long do_keytmout, char *cptr)
 		/* Function may have invalidated the display. */
 		if (resetneeded)
 		    zrefresh();
-		zfree(lwatch_fds, lnwatch*sizeof(int));
-		freearray(lwatch_funcs);
+		for (i = 0; i < lnwatch; i++)
+		    zsfree(lwatch_fds[i].func);
+		zfree(lwatch_fds, lnwatch*sizeof(struct watch_fd));
 	    }
 	}
 # ifdef HAVE_POLL