aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2018-11-19 09:51:57 -0800
committerPaul Eggert2018-11-19 11:38:20 -0800
commit51f9c5a6d16bcba6182cb9bbb9b09330cd6d0a86 (patch)
tree29e410fadafd4296751ead21b268fe793a0dbb55 /lib-src
parent9f47bb229dfc31716f58dd5587bf3b45cb855135 (diff)
downloademacs-51f9c5a6d16bcba6182cb9bbb9b09330cd6d0a86.tar.gz
emacs-51f9c5a6d16bcba6182cb9bbb9b09330cd6d0a86.zip
emacsclient.c: use bool for boolean
* lib-src/emacsclient.c (nowait, quiet, suppress_output, eval, tty) (decode_options, file_name_absolute_p, get_server_config) (strprefix, find_tty, set_socket, main): Use bool for boolean. (create_frame): New static var, replacing the old current_frame and with inverted sense, as this is clearer.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/emacsclient.c167
1 files changed, 78 insertions, 89 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index f2771445d8a..c0721c049d2 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -101,19 +101,19 @@ static int main_argc;
101static char *const *main_argv; 101static char *const *main_argv;
102 102
103/* True means don't wait for a response from Emacs. --no-wait. */ 103/* True means don't wait for a response from Emacs. --no-wait. */
104static int nowait; 104static bool nowait;
105 105
106/* True means don't print messages for successful operations. --quiet. */ 106/* True means don't print messages for successful operations. --quiet. */
107static int quiet; 107static bool quiet;
108 108
109/* True means don't print values returned from emacs. --suppress-output. */ 109/* True means don't print values returned from emacs. --suppress-output. */
110static int suppress_output; 110static bool suppress_output;
111 111
112/* True means args are expressions to be evaluated. --eval. */ 112/* True means args are expressions to be evaluated. --eval. */
113static int eval; 113static bool eval;
114 114
115/* Nonzero means don't open a new frame. Inverse of --create-frame. */ 115/* True means open a new frame. --create-frame etc. */
116static int current_frame = 1; 116static bool create_frame;
117 117
118/* The display on which Emacs should work. --display. */ 118/* The display on which Emacs should work. --display. */
119static char const *display; 119static char const *display;
@@ -125,7 +125,7 @@ static char const *alt_display;
125static char *parent_id; 125static char *parent_id;
126 126
127/* True means open a new Emacs frame on the current terminal. */ 127/* True means open a new Emacs frame on the current terminal. */
128static int tty; 128static bool tty;
129 129
130/* If non-NULL, the name of an editor to fallback to if the server 130/* If non-NULL, the name of an editor to fallback to if the server
131 is not running. --alternate-editor. */ 131 is not running. --alternate-editor. */
@@ -478,7 +478,7 @@ decode_options (int argc, char **argv)
478 alternate_editor = egetenv ("ALTERNATE_EDITOR"); 478 alternate_editor = egetenv ("ALTERNATE_EDITOR");
479 tramp_prefix = egetenv ("EMACSCLIENT_TRAMP"); 479 tramp_prefix = egetenv ("EMACSCLIENT_TRAMP");
480 480
481 while (1) 481 while (true)
482 { 482 {
483 int opt = getopt_long_only (argc, argv, 483 int opt = getopt_long_only (argc, argv,
484#ifndef NO_SOCKETS_IN_FILE_SYSTEM 484#ifndef NO_SOCKETS_IN_FILE_SYSTEM
@@ -521,19 +521,19 @@ decode_options (int argc, char **argv)
521 break; 521 break;
522 522
523 case 'n': 523 case 'n':
524 nowait = 1; 524 nowait = true;
525 break; 525 break;
526 526
527 case 'e': 527 case 'e':
528 eval = 1; 528 eval = true;
529 break; 529 break;
530 530
531 case 'q': 531 case 'q':
532 quiet = 1; 532 quiet = true;
533 break; 533 break;
534 534
535 case 'u': 535 case 'u':
536 suppress_output = 1; 536 suppress_output = true;
537 break; 537 break;
538 538
539 case 'V': 539 case 'V':
@@ -542,17 +542,17 @@ decode_options (int argc, char **argv)
542 break; 542 break;
543 543
544 case 't': 544 case 't':
545 tty = 1; 545 tty = true;
546 current_frame = 0; 546 create_frame = true;
547 break; 547 break;
548 548
549 case 'c': 549 case 'c':
550 current_frame = 0; 550 create_frame = true;
551 break; 551 break;
552 552
553 case 'p': 553 case 'p':
554 parent_id = optarg; 554 parent_id = optarg;
555 current_frame = 0; 555 create_frame = true;
556 break; 556 break;
557 557
558 case 'H': 558 case 'H':
@@ -585,7 +585,7 @@ decode_options (int argc, char **argv)
585 reflected in the DISPLAY variable. If the user didn't give us an 585 reflected in the DISPLAY variable. If the user didn't give us an
586 explicit display, try this platform-specific after trying the 586 explicit display, try this platform-specific after trying the
587 display in DISPLAY (if any). */ 587 display in DISPLAY (if any). */
588 if (!current_frame && !tty && !display) 588 if (create_frame && !tty && !display)
589 { 589 {
590 /* Set these here so we use a default_display only when the user 590 /* Set these here so we use a default_display only when the user
591 didn't give us an explicit display. */ 591 didn't give us an explicit display. */
@@ -605,24 +605,24 @@ decode_options (int argc, char **argv)
605 } 605 }
606 606
607 /* A null-string display is invalid. */ 607 /* A null-string display is invalid. */
608 if (display && strlen (display) == 0) 608 if (display && !display[0])
609 display = NULL; 609 display = NULL;
610 610
611 /* If no display is available, new frames are tty frames. */ 611 /* If no display is available, new frames are tty frames. */
612 if (!current_frame && !display) 612 if (create_frame && !display)
613 tty = 1; 613 tty = true;
614 614
615#ifdef WINDOWSNT 615#ifdef WINDOWSNT
616 /* Emacs on Windows does not support graphical and text terminal 616 /* Emacs on Windows does not support graphical and text terminal
617 frames in the same instance. So, treat the -t and -c options as 617 frames in the same instance. So, treat the -t and -c options as
618 equivalent, and open a new frame on the server's terminal. 618 equivalent, and open a new frame on the server's terminal.
619 Ideally, we would only set tty = 1 when the serve is running in a 619 Ideally, we would set tty = true only if the server is running in a
620 console, but alas we don't know that. As a workaround, always 620 console, but alas we don't know that. As a workaround, always
621 ask for a tty frame, and let server.el figure it out. */ 621 ask for a tty frame, and let server.el figure it out. */
622 if (!current_frame) 622 if (create_frame)
623 { 623 {
624 display = NULL; 624 display = NULL;
625 tty = 1; 625 tty = true;
626 } 626 }
627#endif /* WINDOWSNT */ 627#endif /* WINDOWSNT */
628} 628}
@@ -892,7 +892,7 @@ unquote_argument (char *str)
892} 892}
893 893
894 894
895static int 895static bool
896file_name_absolute_p (const char *filename) 896file_name_absolute_p (const char *filename)
897{ 897{
898 /* Sanity check, it shouldn't happen. */ 898 /* Sanity check, it shouldn't happen. */
@@ -947,7 +947,7 @@ initialize_sockets (void)
947/* Read the information needed to set up a TCP comm channel with 947/* Read the information needed to set up a TCP comm channel with
948 the Emacs server: host, port, and authentication string. */ 948 the Emacs server: host, port, and authentication string. */
949 949
950static int 950static bool
951get_server_config (const char *config_file, struct sockaddr_in *server, 951get_server_config (const char *config_file, struct sockaddr_in *server,
952 char *authentication) 952 char *authentication)
953{ 953{
@@ -1064,19 +1064,19 @@ set_tcp_socket (const char *local_server_file)
1064} 1064}
1065 1065
1066 1066
1067/* Returns 1 if PREFIX is a prefix of STRING. */ 1067/* Return true if PREFIX is a prefix of STRING. */
1068static int 1068static bool
1069strprefix (const char *prefix, const char *string) 1069strprefix (const char *prefix, const char *string)
1070{ 1070{
1071 return !strncmp (prefix, string, strlen (prefix)); 1071 return !strncmp (prefix, string, strlen (prefix));
1072} 1072}
1073 1073
1074/* Get tty name and type. If successful, return the type in TTY_TYPE 1074/* Get tty name and type. If successful, store the type into
1075 and the name in TTY_NAME, and return 1. Otherwise, fail if NOABORT 1075 *TTY_TYPE and the name into *TTY_NAME, and return true.
1076 is zero, or return 0 if NOABORT is non-zero. */ 1076 Otherwise, fail if NOABORT is zero, or return false if NOABORT. */
1077 1077
1078static int 1078static bool
1079find_tty (const char **tty_type, const char **tty_name, int noabort) 1079find_tty (const char **tty_type, const char **tty_name, bool noabort)
1080{ 1080{
1081 const char *type = egetenv ("TERM"); 1081 const char *type = egetenv ("TERM");
1082 const char *name = ttyname (fileno (stdout)); 1082 const char *name = ttyname (fileno (stdout));
@@ -1084,24 +1084,18 @@ find_tty (const char **tty_type, const char **tty_name, int noabort)
1084 if (!name) 1084 if (!name)
1085 { 1085 {
1086 if (noabort) 1086 if (noabort)
1087 return 0; 1087 return false;
1088 else 1088 message (true, "%s: could not get terminal name\n", progname);
1089 { 1089 fail ();
1090 message (true, "%s: could not get terminal name\n", progname);
1091 fail ();
1092 }
1093 } 1090 }
1094 1091
1095 if (!type) 1092 if (!type)
1096 { 1093 {
1097 if (noabort) 1094 if (noabort)
1098 return 0; 1095 return false;
1099 else 1096 message (true, "%s: please set the TERM variable to your terminal type\n",
1100 { 1097 progname);
1101 message (true, "%s: please set the TERM variable to your terminal type\n", 1098 fail ();
1102 progname);
1103 fail ();
1104 }
1105 } 1099 }
1106 1100
1107 const char *inside_emacs = egetenv ("INSIDE_EMACS"); 1101 const char *inside_emacs = egetenv ("INSIDE_EMACS");
@@ -1109,19 +1103,17 @@ find_tty (const char **tty_type, const char **tty_name, int noabort)
1109 && strprefix ("eterm", type)) 1103 && strprefix ("eterm", type))
1110 { 1104 {
1111 if (noabort) 1105 if (noabort)
1112 return 0; 1106 return false;
1113 else 1107 /* This causes nasty, MULTI_KBOARD-related input lockouts. */
1114 { 1108 message (true, ("%s: opening a frame in an Emacs term buffer"
1115 /* This causes nasty, MULTI_KBOARD-related input lockouts. */ 1109 " is not supported\n"),
1116 message (true, "%s: opening a frame in an Emacs term buffer" 1110 progname);
1117 " is not supported\n", progname); 1111 fail ();
1118 fail ();
1119 }
1120 } 1112 }
1121 1113
1122 *tty_name = name; 1114 *tty_name = name;
1123 *tty_type = type; 1115 *tty_type = type;
1124 return 1; 1116 return true;
1125} 1117}
1126 1118
1127 1119
@@ -1375,7 +1367,7 @@ To start the server in Emacs, type \"M-x server-start\".\n",
1375# endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */ 1367# endif /* ! NO_SOCKETS_IN_FILE_SYSTEM */
1376 1368
1377static HSOCKET 1369static HSOCKET
1378set_socket (int no_exit_if_error) 1370set_socket (bool no_exit_if_error)
1379{ 1371{
1380 HSOCKET s; 1372 HSOCKET s;
1381 const char *local_server_file = server_file; 1373 const char *local_server_file = server_file;
@@ -1390,7 +1382,7 @@ set_socket (int no_exit_if_error)
1390 if (socket_name) 1382 if (socket_name)
1391 { 1383 {
1392 s = set_local_socket (socket_name); 1384 s = set_local_socket (socket_name);
1393 if ((s != INVALID_SOCKET) || no_exit_if_error) 1385 if (s != INVALID_SOCKET || no_exit_if_error)
1394 return s; 1386 return s;
1395 message (true, "%s: error accessing socket \"%s\"\n", 1387 message (true, "%s: error accessing socket \"%s\"\n",
1396 progname, socket_name); 1388 progname, socket_name);
@@ -1405,7 +1397,7 @@ set_socket (int no_exit_if_error)
1405 if (local_server_file) 1397 if (local_server_file)
1406 { 1398 {
1407 s = set_tcp_socket (local_server_file); 1399 s = set_tcp_socket (local_server_file);
1408 if ((s != INVALID_SOCKET) || no_exit_if_error) 1400 if (s != INVALID_SOCKET || no_exit_if_error)
1409 return s; 1401 return s;
1410 1402
1411 message (true, "%s: error accessing server file \"%s\"\n", 1403 message (true, "%s: error accessing server file \"%s\"\n",
@@ -1422,7 +1414,7 @@ set_socket (int no_exit_if_error)
1422 1414
1423 /* Implicit server file. */ 1415 /* Implicit server file. */
1424 s = set_tcp_socket ("server"); 1416 s = set_tcp_socket ("server");
1425 if ((s != INVALID_SOCKET) || no_exit_if_error) 1417 if (s != INVALID_SOCKET || no_exit_if_error)
1426 return s; 1418 return s;
1427 1419
1428 /* No implicit or explicit socket, and no alternate editor. */ 1420 /* No implicit or explicit socket, and no alternate editor. */
@@ -1535,10 +1527,9 @@ start_daemon_and_retry_set_socket (void)
1535 1527
1536 if (dpid > 0) 1528 if (dpid > 0)
1537 { 1529 {
1538 pid_t w; 1530 pid_t w = waitpid (dpid, &status, WUNTRACED | WCONTINUED);
1539 w = waitpid (dpid, &status, WUNTRACED | WCONTINUED);
1540 1531
1541 if ((w == -1) || !WIFEXITED (status) || WEXITSTATUS (status)) 1532 if (w < 0 || !WIFEXITED (status) || WEXITSTATUS (status))
1542 { 1533 {
1543 message (true, "Error: Could not start the Emacs daemon\n"); 1534 message (true, "Error: Could not start the Emacs daemon\n");
1544 exit (EXIT_FAILURE); 1535 exit (EXIT_FAILURE);
@@ -1653,10 +1644,10 @@ start_daemon_and_retry_set_socket (void)
1653int 1644int
1654main (int argc, char **argv) 1645main (int argc, char **argv)
1655{ 1646{
1656 int rl = 0, needlf = 0; 1647 int rl = 0;
1648 bool skiplf = true;
1657 char *cwd, *str; 1649 char *cwd, *str;
1658 char string[BUFSIZ+1]; 1650 char string[BUFSIZ+1];
1659 int start_daemon_if_needed;
1660 int exit_status = EXIT_SUCCESS; 1651 int exit_status = EXIT_SUCCESS;
1661 1652
1662 main_argc = argc; 1653 main_argc = argc;
@@ -1674,7 +1665,7 @@ main (int argc, char **argv)
1674 /* Process options. */ 1665 /* Process options. */
1675 decode_options (argc, argv); 1666 decode_options (argc, argv);
1676 1667
1677 if ((argc - optind < 1) && !eval && current_frame) 1668 if (! (optind < argc || eval || create_frame))
1678 { 1669 {
1679 message (true, "%s: file name or argument required\n" 1670 message (true, "%s: file name or argument required\n"
1680 "Try '%s --help' for more information\n", 1671 "Try '%s --help' for more information\n",
@@ -1694,8 +1685,7 @@ main (int argc, char **argv)
1694 1685
1695 /* If alternate_editor is the empty string, start the emacs daemon 1686 /* If alternate_editor is the empty string, start the emacs daemon
1696 in case of failure to connect. */ 1687 in case of failure to connect. */
1697 start_daemon_if_needed = (alternate_editor 1688 bool start_daemon_if_needed = alternate_editor && !alternate_editor[0];
1698 && (alternate_editor[0] == '\0'));
1699 1689
1700 emacs_socket = set_socket (alternate_editor || start_daemon_if_needed); 1690 emacs_socket = set_socket (alternate_editor || start_daemon_if_needed);
1701 if (emacs_socket == INVALID_SOCKET) 1691 if (emacs_socket == INVALID_SOCKET)
@@ -1720,7 +1710,7 @@ main (int argc, char **argv)
1720# endif /* HAVE_NTGUI */ 1710# endif /* HAVE_NTGUI */
1721 1711
1722 /* Send over our environment and current directory. */ 1712 /* Send over our environment and current directory. */
1723 if (!current_frame) 1713 if (create_frame)
1724 { 1714 {
1725 int i; 1715 int i;
1726 for (i = 0; environ[i]; i++) 1716 for (i = 0; environ[i]; i++)
@@ -1742,7 +1732,7 @@ main (int argc, char **argv)
1742 if (nowait) 1732 if (nowait)
1743 send_to_emacs (emacs_socket, "-nowait "); 1733 send_to_emacs (emacs_socket, "-nowait ");
1744 1734
1745 if (current_frame) 1735 if (!create_frame)
1746 send_to_emacs (emacs_socket, "-current-frame "); 1736 send_to_emacs (emacs_socket, "-current-frame ");
1747 1737
1748 if (display) 1738 if (display)
@@ -1759,7 +1749,7 @@ main (int argc, char **argv)
1759 send_to_emacs (emacs_socket, " "); 1749 send_to_emacs (emacs_socket, " ");
1760 } 1750 }
1761 1751
1762 if (frame_parameters && !current_frame) 1752 if (frame_parameters && create_frame)
1763 { 1753 {
1764 send_to_emacs (emacs_socket, "-frame-parameters "); 1754 send_to_emacs (emacs_socket, "-frame-parameters ");
1765 quote_argument (emacs_socket, frame_parameters); 1755 quote_argument (emacs_socket, frame_parameters);
@@ -1769,7 +1759,7 @@ main (int argc, char **argv)
1769 /* Unless we are certain we don't want to occupy the tty, send our 1759 /* Unless we are certain we don't want to occupy the tty, send our
1770 tty information to Emacs. For example, in daemon mode Emacs may 1760 tty information to Emacs. For example, in daemon mode Emacs may
1771 need to occupy this tty if no other frame is available. */ 1761 need to occupy this tty if no other frame is available. */
1772 if (!current_frame || !eval) 1762 if (create_frame || !eval)
1773 { 1763 {
1774 const char *tty_type, *tty_name; 1764 const char *tty_type, *tty_name;
1775 1765
@@ -1786,10 +1776,10 @@ main (int argc, char **argv)
1786 } 1776 }
1787 } 1777 }
1788 1778
1789 if (!current_frame && !tty) 1779 if (create_frame && !tty)
1790 send_to_emacs (emacs_socket, "-window-system "); 1780 send_to_emacs (emacs_socket, "-window-system ");
1791 1781
1792 if ((argc - optind > 0)) 1782 if (optind < argc)
1793 { 1783 {
1794 int i; 1784 int i;
1795 for (i = optind; i < argc; i++) 1785 for (i = optind; i < argc; i++)
@@ -1861,7 +1851,7 @@ main (int argc, char **argv)
1861 if (!eval && !tty && !nowait && !quiet) 1851 if (!eval && !tty && !nowait && !quiet)
1862 { 1852 {
1863 printf ("Waiting for Emacs..."); 1853 printf ("Waiting for Emacs...");
1864 needlf = 2; 1854 skiplf = false;
1865 } 1855 }
1866 fflush (stdout); 1856 fflush (stdout);
1867 while (fdatasync (1) != 0 && errno == EINTR) 1857 while (fdatasync (1) != 0 && errno == EINTR)
@@ -1909,8 +1899,8 @@ main (int argc, char **argv)
1909 } 1899 }
1910 else 1900 else
1911 { 1901 {
1912 nowait = 0; 1902 nowait = false;
1913 tty = 1; 1903 tty = true;
1914 } 1904 }
1915 1905
1916 goto retry; 1906 goto retry;
@@ -1921,10 +1911,9 @@ main (int argc, char **argv)
1921 if (!suppress_output) 1911 if (!suppress_output)
1922 { 1912 {
1923 str = unquote_argument (p + strlen ("-print ")); 1913 str = unquote_argument (p + strlen ("-print "));
1924 if (needlf) 1914 printf (&"\n%s"[skiplf], str);
1925 printf ("\n"); 1915 if (str[0])
1926 printf ("%s", str); 1916 skiplf = str[strlen (str) - 1] == '\n';
1927 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n';
1928 } 1917 }
1929 } 1918 }
1930 else if (strprefix ("-print-nonl ", p)) 1919 else if (strprefix ("-print-nonl ", p))
@@ -1935,41 +1924,41 @@ main (int argc, char **argv)
1935 { 1924 {
1936 str = unquote_argument (p + strlen ("-print-nonl ")); 1925 str = unquote_argument (p + strlen ("-print-nonl "));
1937 printf ("%s", str); 1926 printf ("%s", str);
1938 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; 1927 if (str[0])
1928 skiplf = str[strlen (str) - 1] == '\n';
1939 } 1929 }
1940 } 1930 }
1941 else if (strprefix ("-error ", p)) 1931 else if (strprefix ("-error ", p))
1942 { 1932 {
1943 /* -error DESCRIPTION: Signal an error on the terminal. */ 1933 /* -error DESCRIPTION: Signal an error on the terminal. */
1944 str = unquote_argument (p + strlen ("-error ")); 1934 str = unquote_argument (p + strlen ("-error "));
1945 if (needlf) 1935 if (!skiplf)
1946 printf ("\n"); 1936 printf ("\n");
1947 fprintf (stderr, "*ERROR*: %s", str); 1937 fprintf (stderr, "*ERROR*: %s", str);
1948 needlf = str[0] == '\0' ? needlf : str[strlen (str) - 1] != '\n'; 1938 if (str[0])
1939 skiplf = str[strlen (str) - 1] == '\n';
1949 exit_status = EXIT_FAILURE; 1940 exit_status = EXIT_FAILURE;
1950 } 1941 }
1951# ifdef SIGSTOP 1942# ifdef SIGSTOP
1952 else if (strprefix ("-suspend ", p)) 1943 else if (strprefix ("-suspend ", p))
1953 { 1944 {
1954 /* -suspend: Suspend this terminal, i.e., stop the process. */ 1945 /* -suspend: Suspend this terminal, i.e., stop the process. */
1955 if (needlf) 1946 if (!skiplf)
1956 printf ("\n"); 1947 printf ("\n");
1957 needlf = 0; 1948 skiplf = true;
1958 kill (0, SIGSTOP); 1949 kill (0, SIGSTOP);
1959 } 1950 }
1960# endif 1951# endif
1961 else 1952 else
1962 { 1953 {
1963 /* Unknown command. */ 1954 /* Unknown command. */
1964 if (needlf) 1955 printf (&"\n*ERROR*: Unknown message: %s\n"[skiplf], p);
1965 printf ("\n"); 1956 skiplf = true;
1966 needlf = 0;
1967 printf ("*ERROR*: Unknown message: %s\n", p);
1968 } 1957 }
1969 } 1958 }
1970 } 1959 }
1971 1960
1972 if (needlf) 1961 if (!skiplf)
1973 printf ("\n"); 1962 printf ("\n");
1974 fflush (stdout); 1963 fflush (stdout);
1975 while (fdatasync (1) != 0 && errno == EINTR) 1964 while (fdatasync (1) != 0 && errno == EINTR)