diff options
| author | Paul Eggert | 2018-11-23 00:12:54 -0800 |
|---|---|---|
| committer | Paul Eggert | 2018-11-23 00:13:08 -0800 |
| commit | ef1f60301aabbcfc940bf8a826cd174ba2d0439c (patch) | |
| tree | 770e4b553bb8d3935ccd77587f59bd1f3fc9f2dc /lib-src | |
| parent | 5daba9d8a55d4fa28600f097490bc675eb848957 (diff) | |
| download | emacs-ef1f60301aabbcfc940bf8a826cd174ba2d0439c.tar.gz emacs-ef1f60301aabbcfc940bf8a826cd174ba2d0439c.zip | |
emacsclient: one ‘main’ function
* lib-src/emacsclient.c (main): Simplify by having just one
‘main’ function instead of two. Don’t assume argc is positive (!).
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/emacsclient.c | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c index ef510b1f8bc..b5ed2e0435a 100644 --- a/lib-src/emacsclient.c +++ b/lib-src/emacsclient.c | |||
| @@ -732,21 +732,7 @@ fail (void) | |||
| 732 | } | 732 | } |
| 733 | 733 | ||
| 734 | 734 | ||
| 735 | #if !defined (HAVE_SOCKETS) || !defined (HAVE_INET_SOCKETS) | 735 | #if defined HAVE_SOCKETS && defined HAVE_INET_SOCKETS |
| 736 | |||
| 737 | int | ||
| 738 | main (int argc, char **argv) | ||
| 739 | { | ||
| 740 | main_argc = argc; | ||
| 741 | main_argv = argv; | ||
| 742 | progname = argv[0]; | ||
| 743 | message (true, ("%s: Sorry, the Emacs server is supported only\n" | ||
| 744 | "on systems with Berkeley sockets.\n"), | ||
| 745 | argv[0]); | ||
| 746 | fail (); | ||
| 747 | } | ||
| 748 | |||
| 749 | #else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ | ||
| 750 | 736 | ||
| 751 | enum { AUTH_KEY_LENGTH = 64 }; | 737 | enum { AUTH_KEY_LENGTH = 64 }; |
| 752 | 738 | ||
| @@ -1519,7 +1505,7 @@ start_daemon_and_retry_set_socket (void) | |||
| 1519 | d_argv[0] = emacs; | 1505 | d_argv[0] = emacs; |
| 1520 | d_argv[1] = daemon_option; | 1506 | d_argv[1] = daemon_option; |
| 1521 | d_argv[2] = 0; | 1507 | d_argv[2] = 0; |
| 1522 | #ifndef NO_SOCKETS_IN_FILE_SYSTEM | 1508 | # ifndef NO_SOCKETS_IN_FILE_SYSTEM |
| 1523 | if (socket_name != NULL) | 1509 | if (socket_name != NULL) |
| 1524 | { | 1510 | { |
| 1525 | /* Pass --daemon=socket_name as argument. */ | 1511 | /* Pass --daemon=socket_name as argument. */ |
| @@ -1529,7 +1515,7 @@ start_daemon_and_retry_set_socket (void) | |||
| 1529 | strcpy (stpcpy (daemon_arg, deq), socket_name); | 1515 | strcpy (stpcpy (daemon_arg, deq), socket_name); |
| 1530 | d_argv[1] = daemon_arg; | 1516 | d_argv[1] = daemon_arg; |
| 1531 | } | 1517 | } |
| 1532 | #endif | 1518 | # endif |
| 1533 | execvp ("emacs", d_argv); | 1519 | execvp ("emacs", d_argv); |
| 1534 | message (true, "%s: error starting emacs daemon\n", progname); | 1520 | message (true, "%s: error starting emacs daemon\n", progname); |
| 1535 | } | 1521 | } |
| @@ -1605,26 +1591,32 @@ start_daemon_and_retry_set_socket (void) | |||
| 1605 | } | 1591 | } |
| 1606 | # endif /* WINDOWSNT */ | 1592 | # endif /* WINDOWSNT */ |
| 1607 | } | 1593 | } |
| 1594 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ | ||
| 1608 | 1595 | ||
| 1609 | int | 1596 | int |
| 1610 | main (int argc, char **argv) | 1597 | main (int argc, char **argv) |
| 1611 | { | 1598 | { |
| 1599 | main_argc = argc; | ||
| 1600 | main_argv = argv; | ||
| 1601 | progname = argv[0] ? argv[0] : "emacsclient"; | ||
| 1602 | |||
| 1603 | #if ! (defined HAVE_SOCKETS && defined HAVE_INET_SOCKETS) | ||
| 1604 | message (true, "%s: Sorry, support for Berkeley sockets is required.\n", | ||
| 1605 | progname); | ||
| 1606 | fail (); | ||
| 1607 | #else /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ | ||
| 1612 | int rl = 0; | 1608 | int rl = 0; |
| 1613 | bool skiplf = true; | 1609 | bool skiplf = true; |
| 1614 | char string[BUFSIZ+1]; | 1610 | char string[BUFSIZ + 1]; |
| 1615 | int exit_status = EXIT_SUCCESS; | 1611 | int exit_status = EXIT_SUCCESS; |
| 1616 | 1612 | ||
| 1617 | main_argc = argc; | 1613 | # ifdef HAVE_NTGUI |
| 1618 | main_argv = argv; | ||
| 1619 | progname = argv[0]; | ||
| 1620 | |||
| 1621 | #ifdef HAVE_NTGUI | ||
| 1622 | /* On Windows 7 and later, we need to explicitly associate | 1614 | /* On Windows 7 and later, we need to explicitly associate |
| 1623 | emacsclient with emacs so the UI behaves sensibly. This | 1615 | emacsclient with emacs so the UI behaves sensibly. This |
| 1624 | association does no harm if we're not actually connecting to an | 1616 | association does no harm if we're not actually connecting to an |
| 1625 | Emacs using a window display. */ | 1617 | Emacs using a window display. */ |
| 1626 | w32_set_user_model_id (); | 1618 | w32_set_user_model_id (); |
| 1627 | #endif /* HAVE_NTGUI */ | 1619 | # endif /* HAVE_NTGUI */ |
| 1628 | 1620 | ||
| 1629 | /* Process options. */ | 1621 | /* Process options. */ |
| 1630 | decode_options (argc, argv); | 1622 | decode_options (argc, argv); |
| @@ -1637,7 +1629,7 @@ main (int argc, char **argv) | |||
| 1637 | exit (EXIT_FAILURE); | 1629 | exit (EXIT_FAILURE); |
| 1638 | } | 1630 | } |
| 1639 | 1631 | ||
| 1640 | #ifndef WINDOWSNT | 1632 | # ifndef WINDOWSNT |
| 1641 | if (tty) | 1633 | if (tty) |
| 1642 | { | 1634 | { |
| 1643 | pid_t pgrp = getpgrp (); | 1635 | pid_t pgrp = getpgrp (); |
| @@ -1645,7 +1637,7 @@ main (int argc, char **argv) | |||
| 1645 | if (0 <= tcpgrp && tcpgrp != pgrp) | 1637 | if (0 <= tcpgrp && tcpgrp != pgrp) |
| 1646 | kill (-pgrp, SIGTTIN); | 1638 | kill (-pgrp, SIGTTIN); |
| 1647 | } | 1639 | } |
| 1648 | #endif /* !WINDOWSNT */ | 1640 | # endif /* !WINDOWSNT */ |
| 1649 | 1641 | ||
| 1650 | /* If alternate_editor is the empty string, start the emacs daemon | 1642 | /* If alternate_editor is the empty string, start the emacs daemon |
| 1651 | in case of failure to connect. */ | 1643 | in case of failure to connect. */ |
| @@ -1935,6 +1927,5 @@ main (int argc, char **argv) | |||
| 1935 | 1927 | ||
| 1936 | CLOSE_SOCKET (emacs_socket); | 1928 | CLOSE_SOCKET (emacs_socket); |
| 1937 | return exit_status; | 1929 | return exit_status; |
| 1938 | } | ||
| 1939 | |||
| 1940 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ | 1930 | #endif /* HAVE_SOCKETS && HAVE_INET_SOCKETS */ |
| 1931 | } | ||