aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorChong Yidong2008-11-02 21:41:57 +0000
committerChong Yidong2008-11-02 21:41:57 +0000
commit273b9028637f6af2ed95adc349e2e02155f98800 (patch)
tree99b9181ebbadb461f27c34bb41d6f8daa4398681 /lib-src
parent48c2dc6801dc61afc01605dc78023269e7155b35 (diff)
downloademacs-273b9028637f6af2ed95adc349e2e02155f98800.tar.gz
emacs-273b9028637f6af2ed95adc349e2e02155f98800.zip
(window_system): Delete redundant variable.
(decode_options): Don't use it. (find_tty): New function. (main): Use find_tty, and don't use window_system.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c164
1 files changed, 85 insertions, 79 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index cac8bce2fd2..a2479b3d6bf 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -129,9 +129,6 @@ int eval = 0;
129/* Nonzero means don't open a new frame. Inverse of --create-frame. */ 129/* Nonzero means don't open a new frame. Inverse of --create-frame. */
130int current_frame = 1; 130int current_frame = 1;
131 131
132/* Nonzero means open a new graphical frame. */
133int window_system = 0;
134
135/* The display on which Emacs should work. --display. */ 132/* The display on which Emacs should work. --display. */
136char *display = NULL; 133char *display = NULL;
137 134
@@ -527,11 +524,9 @@ decode_options (argc, argv)
527 to allow it, for the occasional case where the user is 524 to allow it, for the occasional case where the user is
528 connecting with a w32 client to a server compiled with X11 525 connecting with a w32 client to a server compiled with X11
529 support. */ 526 support. */
530#if 1 /* !defined WINDOWS */
531 case 'd': 527 case 'd':
532 display = optarg; 528 display = optarg;
533 break; 529 break;
534#endif
535 530
536 case 'n': 531 case 'n':
537 nowait = 1; 532 nowait = 1;
@@ -566,38 +561,27 @@ decode_options (argc, argv)
566 } 561 }
567 } 562 }
568 563
569 /* We used to set `display' to $DISPLAY by default, but this changed the 564 /* If the -c option is used (without -t) and no --display argument
570 default behavior and is sometimes inconvenient. So instead of forcing 565 is provided, try $DISPLAY.
571 users to say "--display ''" when they want to use Emacs's existing tty 566 Without the -c option, we used to set `display' to $DISPLAY by
572 or display connection, we force them to use "--display $DISPLAY" if 567 default, but this changed the default behavior and is sometimes
573 they want Emacs to connect to their current display. 568 inconvenient. So we force users to use "--display $DISPLAY" if
574 -c still implicitly passes --display $DISPLAY unless -t was specified 569 they want Emacs to connect to their current display. */
575 so as to try and mimick the behavior of `emacs' which either uses
576 the current tty or the current $DISPLAY. */
577 if (!current_frame && !tty && !display) 570 if (!current_frame && !tty && !display)
578 display = egetenv ("DISPLAY"); 571 display = egetenv ("DISPLAY");
579 572
573 /* A null-string display is invalid. */
580 if (display && strlen (display) == 0) 574 if (display && strlen (display) == 0)
581 display = NULL; 575 display = NULL;
582 576
583 if (!tty && display) 577 /* If no display is available, new frames are tty frames. */
584 window_system = 1; 578 if (!current_frame && !display)
585 else if (!current_frame)
586 tty = 1; 579 tty = 1;
587 580
588 /* --no-wait implies --current-frame on ttys when there are file 581 /* --no-wait implies --current-frame on ttys when there are file
589 arguments or expressions given. */ 582 arguments or expressions given. */
590 if (nowait && tty && argc - optind > 0) 583 if (nowait && tty && argc - optind > 0)
591 current_frame = 1; 584 current_frame = 1;
592
593 if (current_frame)
594 {
595 tty = 0;
596 window_system = 0;
597 }
598
599 if (tty)
600 window_system = 0;
601} 585}
602 586
603 587
@@ -1099,6 +1083,60 @@ handle_sigtstp (int signalnum)
1099 1083
1100 errno = old_errno; 1084 errno = old_errno;
1101} 1085}
1086
1087
1088/* Get tty name and type. If successful, return the type in TTY_TYPE
1089 and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT
1090 is zero, or return 0 if NOABORT is non-zero. */
1091
1092int
1093find_tty (char **tty_type, char **tty_name, int noabort)
1094{
1095 char *type = egetenv ("TERM");
1096 char *name = ttyname (fileno (stdout));
1097
1098 if (!name)
1099 {
1100 if (noabort)
1101 return 0;
1102 else
1103 {
1104 message (TRUE, "%s: could not get terminal name\n", progname);
1105 fail ();
1106 }
1107 }
1108
1109 if (!type)
1110 {
1111 if (noabort)
1112 return 0;
1113 else
1114 {
1115 message (TRUE, "%s: please set the TERM variable to your terminal type\n",
1116 progname);
1117 fail ();
1118 }
1119 }
1120
1121 if (strcmp (type, "eterm") == 0)
1122 {
1123 if (noabort)
1124 return 0;
1125 else
1126 {
1127 /* This causes nasty, MULTI_KBOARD-related input lockouts. */
1128 message (TRUE, "%s: opening a frame in an Emacs term buffer"
1129 " is not supported\n", progname);
1130 fail ();
1131 }
1132 }
1133
1134 *tty_name = name;
1135 *tty_type = type;
1136 return 1;
1137}
1138
1139
1102/* Set up signal handlers before opening a frame on the current tty. */ 1140/* Set up signal handlers before opening a frame on the current tty. */
1103 1141
1104void 1142void
@@ -1384,7 +1422,7 @@ main (argc, argv)
1384 /* Process options. */ 1422 /* Process options. */
1385 decode_options (argc, argv); 1423 decode_options (argc, argv);
1386 1424
1387 if ((argc - optind < 1) && !eval && !tty && !window_system) 1425 if ((argc - optind < 1) && !eval && current_frame)
1388 { 1426 {
1389 message (TRUE, "%s: file name or argument required\n" 1427 message (TRUE, "%s: file name or argument required\n"
1390 "Try `%s --help' for more information\n", 1428 "Try `%s --help' for more information\n",
@@ -1409,7 +1447,7 @@ main (argc, argv)
1409 w32_give_focus (); 1447 w32_give_focus ();
1410#endif 1448#endif
1411 1449
1412 /* Send over our environment. */ 1450 /* Send over our environment and current directory. */
1413 if (!current_frame) 1451 if (!current_frame)
1414 { 1452 {
1415 extern char **environ; 1453 extern char **environ;
@@ -1422,11 +1460,6 @@ main (argc, argv)
1422 quote_argument (emacs_socket, environ[i]); 1460 quote_argument (emacs_socket, environ[i]);
1423 send_to_emacs (emacs_socket, " "); 1461 send_to_emacs (emacs_socket, " ");
1424 } 1462 }
1425 }
1426
1427 /* Send over our current directory. */
1428 if (!current_frame)
1429 {
1430 send_to_emacs (emacs_socket, "-dir "); 1463 send_to_emacs (emacs_socket, "-dir ");
1431 quote_argument (emacs_socket, cwd); 1464 quote_argument (emacs_socket, cwd);
1432 send_to_emacs (emacs_socket, "/"); 1465 send_to_emacs (emacs_socket, "/");
@@ -1452,43 +1485,22 @@ main (argc, argv)
1452 frame is available. */ 1485 frame is available. */
1453 if (tty || (current_frame && !eval)) 1486 if (tty || (current_frame && !eval))
1454 { 1487 {
1455 char *type = egetenv ("TERM"); 1488 char *tty_type, *tty_name;
1456 char *tty_name = NULL;
1457
1458 tty_name = ttyname (fileno (stdout));
1459 1489
1460 if (! tty_name) 1490 if (find_tty (&tty_type, &tty_name, !tty))
1461 { 1491 {
1462 message (TRUE, "%s: could not get terminal name\n", progname);
1463 fail ();
1464 }
1465
1466 if (! type)
1467 {
1468 message (TRUE, "%s: please set the TERM variable to your terminal type\n",
1469 progname);
1470 fail ();
1471 }
1472
1473 if (! strcmp (type, "eterm"))
1474 {
1475 /* This causes nasty, MULTI_KBOARD-related input lockouts. */
1476 message (TRUE, "%s: opening a frame in an Emacs term buffer"
1477 " is not supported\n", progname);
1478 fail ();
1479 }
1480#if !defined (NO_SOCKETS_IN_FILE_SYSTEM) 1492#if !defined (NO_SOCKETS_IN_FILE_SYSTEM)
1481 init_signals (); 1493 init_signals ();
1482#endif 1494#endif
1483 1495 send_to_emacs (emacs_socket, "-tty ");
1484 send_to_emacs (emacs_socket, "-tty "); 1496 quote_argument (emacs_socket, tty_name);
1485 quote_argument (emacs_socket, tty_name); 1497 send_to_emacs (emacs_socket, " ");
1486 send_to_emacs (emacs_socket, " "); 1498 quote_argument (emacs_socket, tty_type);
1487 quote_argument (emacs_socket, type); 1499 send_to_emacs (emacs_socket, " ");
1488 send_to_emacs (emacs_socket, " "); 1500 }
1489 } 1501 }
1490 1502
1491 if (window_system) 1503 if (!current_frame && !tty)
1492 send_to_emacs (emacs_socket, "-window-system "); 1504 send_to_emacs (emacs_socket, "-window-system ");
1493 1505
1494 if ((argc - optind > 0)) 1506 if ((argc - optind > 0))
@@ -1555,20 +1567,15 @@ main (argc, argv)
1555 send_to_emacs (emacs_socket, " "); 1567 send_to_emacs (emacs_socket, " ");
1556 } 1568 }
1557 } 1569 }
1558 else 1570 else if (eval)
1559 { 1571 {
1560 if (!tty && !window_system) 1572 /* Read expressions interactively. */
1561 { 1573 while ((str = fgets (string, BUFSIZ, stdin)))
1562 while ((str = fgets (string, BUFSIZ, stdin))) 1574 {
1563 { 1575 send_to_emacs (emacs_socket, "-eval ");
1564 if (eval) 1576 quote_argument (emacs_socket, str);
1565 send_to_emacs (emacs_socket, "-eval "); 1577 }
1566 else 1578 send_to_emacs (emacs_socket, " ");
1567 send_to_emacs (emacs_socket, "-file ");
1568 quote_argument (emacs_socket, str);
1569 }
1570 send_to_emacs (emacs_socket, " ");
1571 }
1572 } 1579 }
1573 1580
1574 send_to_emacs (emacs_socket, "\n"); 1581 send_to_emacs (emacs_socket, "\n");
@@ -1601,7 +1608,6 @@ main (argc, argv)
1601 { 1608 {
1602 /* -window-system-unsupported: Emacs was compiled without X 1609 /* -window-system-unsupported: Emacs was compiled without X
1603 support. Try again on the terminal. */ 1610 support. Try again on the terminal. */
1604 window_system = 0;
1605 nowait = 0; 1611 nowait = 0;
1606 tty = 1; 1612 tty = 1;
1607 goto retry; 1613 goto retry;