4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Cscope: Avoid a hang when cscope waits for a response while Vim
13 Error messages from Cscope mess up the display.
14 Solution: Detect the hit-enter message and respond by sending a return
15 character to cscope. (Gary Johnson)
16 Use EMSG() and strerror() when possible. Replace perror() with
17 PERROR() everywhere, add emsg3().
18 Files: src/diff.c, src/if_cscope.c, src/integration.c, src/message.c,
19 src/proto/message.pro, src/misc2.c, src/netbeans.c, src/vim.h
22 *** ../vim-6.2.222/src/diff.c Sun Jan 18 20:58:01 2004
23 --- src/diff.c Sun Feb 1 15:01:19 2004
29 ! EMSG2(_("E96: Can not diff more than %ld buffers"), DB_COUNT);
37 ! EMSGN(_("E96: Can not diff more than %ld buffers"), DB_COUNT);
41 *** ../vim-6.2.222/src/if_cscope.c Wed Sep 10 21:35:55 2003
42 --- src/if_cscope.c Sun Feb 1 15:23:43 2004
45 err_save = dup(STDERR_FILENO);
47 if (dup2(to_cs[0], STDIN_FILENO) == -1)
48 ! perror("cs_create_connection 1");
49 if (dup2(from_cs[1], STDOUT_FILENO) == -1)
50 ! perror("cs_create_connection 2");
51 if (dup2(from_cs[1], STDERR_FILENO) == -1)
52 ! perror("cs_create_connection 3");
57 err_save = dup(STDERR_FILENO);
59 if (dup2(to_cs[0], STDIN_FILENO) == -1)
60 ! PERROR("cs_create_connection 1");
61 if (dup2(from_cs[1], STDOUT_FILENO) == -1)
62 ! PERROR("cs_create_connection 2");
63 if (dup2(from_cs[1], STDERR_FILENO) == -1)
64 ! PERROR("cs_create_connection 3");
72 if (execl("/bin/sh", "sh", "-c", cmd, NULL) == -1)
73 ! perror(_("cs_create_connection exec failed"));
80 if (execl("/bin/sh", "sh", "-c", cmd, NULL) == -1)
81 ! PERROR(_("cs_create_connection exec failed"));
90 ! perror(_("cs_create_connection exec failed"));
91 (void)EMSG(_("E623: Could not spawn cscope process"));
98 ! PERROR(_("cs_create_connection exec failed"));
99 (void)EMSG(_("E623: Could not spawn cscope process"));
106 if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL)
107 ! perror(_("cs_create_connection: fdopen for to_fp failed"));
108 if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL)
109 ! perror(_("cs_create_connection: fdopen for fr_fp failed"));
116 if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL)
117 ! PERROR(_("cs_create_connection: fdopen for to_fp failed"));
118 if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL)
119 ! PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
126 char *buf = NULL; /* buffer for possible error message from cscope */
128 ! static char *cs_emsg = N_("E609: Cscope error: %s");
129 ! /* maximum allowed len for Cscope error message */
130 ! int maxlen = IOSIZE - strlen(_(cs_emsg));
134 while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0])
135 ! /* if verbose, have space and char is printable */
136 ! if (p_csverbose && bufpos < maxlen - 1 && vim_isprintc(ch))
138 if (buf == NULL) /* lazy buffer allocation */
139 buf = (char *)alloc(maxlen);
141 ! if (buf != NULL) /* append character to a string */
150 ! perror("cs_read_prompt EOF(1)");
151 ! if (buf != NULL && buf[0] != NUL)
152 ! (void)EMSG2(_(cs_emsg), buf);
153 ! else if (p_csverbose)
154 ! cs_reading_emsg(i); /* don't have additional information */
155 ! cs_release_csp(i, TRUE);
157 ! return CSCOPE_FAILURE;
160 ! ch = getc(csinfo[i].fr_fp);
162 ! perror("cs_read_prompt EOF(2)");
163 ! if (ch != CSCOPE_PROMPT[1])
166 - ch = getc(csinfo[i].fr_fp);
168 ! perror("cs_read_prompt EOF(3)");
169 ! if (ch != CSCOPE_PROMPT[2])
174 return CSCOPE_SUCCESS;
175 ! } /* cs_read_prompt */
181 char *buf = NULL; /* buffer for possible error message from cscope */
185 ! static char *eprompt = "Press the RETURN key to continue:";
186 ! int epromptlen = strlen(eprompt);
189 ! cs_emsg = _("E609: Cscope error: %s");
190 ! /* compute maximum allowed len for Cscope error message */
191 ! maxlen = (int)(IOSIZE - strlen(cs_emsg));
195 while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0])
196 ! /* if there is room and char is printable */
197 ! if (bufpos < maxlen - 1 && vim_isprintc(ch))
199 if (buf == NULL) /* lazy buffer allocation */
200 buf = (char *)alloc(maxlen);
203 + /* append character to the message */
206 + if (bufpos >= epromptlen
207 + && strcmp(&buf[bufpos - epromptlen], eprompt) == 0)
209 + /* remove eprompt from buf */
210 + buf[bufpos - epromptlen] = NUL;
212 + /* print message to user */
213 + (void)EMSG2(cs_emsg, buf);
215 + /* send RETURN to cscope */
216 + (void)putc('\n', csinfo[i].to_fp);
217 + (void)fflush(csinfo[i].to_fp);
226 ! for (n = 0; n < (int)strlen(CSCOPE_PROMPT); ++n)
229 ! ch = getc(csinfo[i].fr_fp);
232 ! PERROR("cs_read_prompt EOF");
233 ! if (buf != NULL && buf[0] != NUL)
234 ! (void)EMSG2(cs_emsg, buf);
235 ! else if (p_csverbose)
236 ! cs_reading_emsg(i); /* don't have additional information */
237 ! cs_release_csp(i, TRUE);
239 ! return CSCOPE_FAILURE;
242 ! if (ch != CSCOPE_PROMPT[n])
250 ! continue; /* didn't find the prompt */
251 ! break; /* did find the prompt */
255 return CSCOPE_SUCCESS;
260 *** ../vim-6.2.222/src/integration.c Sun Jul 27 14:16:53 2003
261 --- src/integration.c Sun Feb 1 15:20:40 2004
264 port = atoi(address);
266 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
267 ! perror(NOCATGETS("workshop_connect"));
272 port = atoi(address);
274 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
275 ! PERROR(NOCATGETS("workshop_connect"));
281 server.sin_family = AF_INET;
282 server.sin_port = port;
283 if ((host = gethostbyname(NOCATGETS("localhost"))) == NULL) {
284 ! perror(NOCATGETS("gethostbyname"));
288 memcpy((char *)&server.sin_addr, host->h_addr, host->h_length);
290 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
291 ! perror(NOCATGETS("workshop_connect"));
296 server.sin_family = AF_INET;
297 server.sin_port = port;
298 if ((host = gethostbyname(NOCATGETS("localhost"))) == NULL) {
299 ! PERROR(NOCATGETS("gethostbyname"));
303 memcpy((char *)&server.sin_addr, host->h_addr, host->h_length);
305 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
306 ! PERROR(NOCATGETS("workshop_connect"));
314 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
315 ! perror(NOCATGETS("workshop_connect"));
319 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
320 ! perror(NOCATGETS("workshop_connect"));
324 if (connect(sd, (struct sockaddr *)&server,
326 ! perror(NOCATGETS("workshop_connect"));
331 ! perror(NOCATGETS("workshop_connect"));
338 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
339 ! PERROR(NOCATGETS("workshop_connect"));
343 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
344 ! PERROR(NOCATGETS("workshop_connect"));
348 if (connect(sd, (struct sockaddr *)&server,
350 ! PERROR(NOCATGETS("workshop_connect"));
355 ! PERROR(NOCATGETS("workshop_connect"));
359 *** ../vim-6.2.222/src/message.c Sun Jan 25 20:28:03 2004
360 --- src/message.c Sun Feb 1 15:14:08 2004
364 return msg_attr(s, attr);
368 + * Print an error message with one "%s" and one string argument.
374 + return emsg3(s, a1, NULL);
378 + * Print an error message with one or two "%s" and one or two string arguments.
382 + char_u *s, *a1, *a2;
384 if ((emsg_off > 0 && *p_debug == NUL)
389 /* Check for NULL strings (just in case) */
391 a1 = (char_u *)"[NULL]";
392 ! /* Check for very long strings (can happen with ":help ^A<CR>").
393 ! * Careful, the argument could actually be a long. */
394 ! if (STRLEN(s) + (strstr((char *)s, "%s") != NULL ? STRLEN(a1) : 20)
396 ! a1 = (char_u *)_("[string too long]");
397 ! sprintf((char *)IObuff, (char *)s, (char *)a1);
405 /* Check for NULL strings (just in case) */
407 a1 = (char_u *)"[NULL]";
409 ! a2 = (char_u *)"[NULL]";
411 ! /* Check for very long strings (can happen with ":help ^A<CR>"). */
412 ! if (STRLEN(s) + STRLEN(a1) + STRLEN(a2) >= (size_t)IOSIZE)
413 ! a1 = a2 = (char_u *)_("[string too long]");
415 ! sprintf((char *)IObuff, (char *)s, (char *)a1, (char *)a2);
420 + * Print an error message with one "%ld" and one long int argument.
425 *** ../vim-6.2.222/src/proto/message.pro Sun Jun 1 12:26:14 2003
426 --- src/proto/message.pro Sun Feb 1 15:23:42 2004
430 void trunc_string __ARGS((char_u *s, char_u *buf, int room));
431 int emsg __ARGS((char_u *s));
432 int emsg2 __ARGS((char_u *s, char_u *a1));
433 + int emsg3 __ARGS((char_u *s, char_u *a1, char_u *a2));
434 int emsgn __ARGS((char_u *s, long n));
435 char_u *msg_trunc_attr __ARGS((char_u *s, int force, int attr));
436 char_u *msg_may_trunc __ARGS((int force, char_u *s));
437 *** ../vim-6.2.222/src/misc2.c Sun Jan 18 20:58:01 2004
438 --- src/misc2.c Sun Feb 1 15:26:21 2004
442 /* Don't hide this message */
444 ! EMSG2(_("E342: Out of memory! (allocating %lu bytes)"), size);
445 did_outofmem_msg = TRUE;
450 /* Don't hide this message */
452 ! EMSGN(_("E342: Out of memory! (allocating %lu bytes)"), size);
453 did_outofmem_msg = TRUE;
456 *** ../vim-6.2.222/src/netbeans.c Fri Jan 30 21:03:16 2004
457 --- src/netbeans.c Sun Feb 1 15:21:15 2004
461 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
463 ! perror("socket() in netbeans_connect()");
469 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
471 ! PERROR("socket() in netbeans_connect()");
477 sd = open(hostname, O_RDONLY);
480 ! perror("gethostbyname() in netbeans_connect()");
485 sd = open(hostname, O_RDONLY);
488 ! PERROR("gethostbyname() in netbeans_connect()");
495 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
497 ! perror("socket()");
503 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
505 ! PERROR("socket()");
512 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
514 ! perror("socket()#2 in netbeans_connect()");
518 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
520 ! perror("socket()#2 in netbeans_connect()");
526 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
528 ! PERROR("socket()#2 in netbeans_connect()");
532 if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
534 ! PERROR("socket()#2 in netbeans_connect()");
542 /* Get here when the server can't be found. */
543 ! perror(_("Cannot connect to Netbeans #2"));
550 /* Get here when the server can't be found. */
551 ! PERROR(_("Cannot connect to Netbeans #2"));
560 ! perror(_("Cannot connect to Netbeans"));
568 ! PERROR(_("Cannot connect to Netbeans"));
574 netbeans_disconnect();
575 nbdebug(("messageFromNetbeans: Error in read() from socket\n"));
577 ! perror(_("read from Netbeans socket"));
578 return; /* don't try to parse it */;
582 netbeans_disconnect();
583 nbdebug(("messageFromNetbeans: Error in read() from socket\n"));
585 ! PERROR(_("read from Netbeans socket"));
586 return; /* don't try to parse it */;
589 *** ../vim-6.2.222/src/vim.h Wed Nov 5 10:32:28 2003
590 --- src/vim.h Sun Feb 1 15:17:21 2004
594 #define MSG_PUTS_LONG(s) msg_puts_long((char_u *)(s))
595 #define MSG_PUTS_LONG_ATTR(s, a) msg_puts_long_attr((char_u *)(s), (a))
597 + /* Prefer using emsg3(), because perror() may send the output to the wrong
598 + * destination and mess up the screen. */
599 + #ifdef HAVE_STRERROR
600 + # define PERROR(msg) (void)emsg3((char_u *)"%s: %s", (char_u *)msg, (char_u *)strerror(errno))
602 + # define PERROR(msg) perror(msg)
605 typedef long linenr_T; /* line number type */
606 typedef unsigned colnr_T; /* column number type */
607 typedef unsigned short disptick_T; /* display tick type */
608 *** ../vim-6.2.222/src/version.c Mon Feb 2 10:03:01 2004
609 --- src/version.c Mon Feb 2 12:47:46 2004
613 { /* Add new patch number below this line */
619 hundred-and-one symptoms of being an internet addict:
620 25. You believe nothing looks sexier than a man in boxer shorts illuminated
621 only by a 17" inch svga monitor.
623 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
624 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
625 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
626 \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///