Mercurial > emacs
comparison lib-src/emacsclient.c @ 83603:54df157e987d
(emacs_socket): Rename from s.
Move definition below includes it depends on.
(SEND_STRING, SEND_QUOTED): Remove obfuscation macros.
(quote_argument, set_tcp_socket, handle_sigcont, handle_sigtstp):
(main): Expand removed macros inline.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Wed, 16 May 2007 21:35:06 +0000 |
parents | 8365dbf64d14 |
children | b009fb9581ca |
comparison
equal
deleted
inserted
replaced
83602:8ea0b74f4daa | 83603:54df157e987d |
---|---|
106 | 106 |
107 #ifndef VERSION | 107 #ifndef VERSION |
108 #define VERSION "unspecified" | 108 #define VERSION "unspecified" |
109 #endif | 109 #endif |
110 | 110 |
111 #define SEND_STRING(data) (send_to_emacs (emacs_socket, (data))) | |
112 #define SEND_QUOTED(data) (quote_argument (emacs_socket, (data))) | |
113 | 111 |
114 #ifndef EXIT_SUCCESS | 112 #ifndef EXIT_SUCCESS |
115 #define EXIT_SUCCESS 0 | 113 #define EXIT_SUCCESS 0 |
116 #endif | 114 #endif |
117 | 115 |
643 *q++ = *p++; | 641 *q++ = *p++; |
644 } | 642 } |
645 } | 643 } |
646 *q++ = 0; | 644 *q++ = 0; |
647 | 645 |
648 SEND_STRING (copy); | 646 send_to_emacs (s, copy); |
649 | 647 |
650 free (copy); | 648 free (copy); |
651 } | 649 } |
652 | 650 |
653 | 651 |
876 /* | 874 /* |
877 * Send the authentication | 875 * Send the authentication |
878 */ | 876 */ |
879 auth_string[AUTH_KEY_LENGTH] = '\0'; | 877 auth_string[AUTH_KEY_LENGTH] = '\0'; |
880 | 878 |
881 SEND_STRING ("-auth "); | 879 send_to_emacs (s, "-auth "); |
882 SEND_STRING (auth_string); | 880 send_to_emacs (s, auth_string); |
883 SEND_STRING ("\n"); | 881 send_to_emacs (s, "\n"); |
884 | 882 |
885 return s; | 883 return s; |
886 } | 884 } |
887 | 885 |
888 | 886 |
951 int old_errno = errno; | 949 int old_errno = errno; |
952 | 950 |
953 if (tcgetpgrp (1) == getpgrp ()) | 951 if (tcgetpgrp (1) == getpgrp ()) |
954 { | 952 { |
955 /* We are in the foreground. */ | 953 /* We are in the foreground. */ |
956 SEND_STRING ("-resume \n"); | 954 send_to_emacs (emacs_socket, "-resume \n"); |
957 } | 955 } |
958 else | 956 else |
959 { | 957 { |
960 /* We are in the background; cancel the continue. */ | 958 /* We are in the background; cancel the continue. */ |
961 kill (getpid (), SIGSTOP); | 959 kill (getpid (), SIGSTOP); |
976 { | 974 { |
977 int old_errno = errno; | 975 int old_errno = errno; |
978 sigset_t set; | 976 sigset_t set; |
979 | 977 |
980 if (s) | 978 if (s) |
981 SEND_STRING ("-suspend \n"); | 979 send_to_emacs (emacs_socket, "-suspend \n"); |
982 | 980 |
983 /* Unblock this signal and call the default handler by temprarily | 981 /* Unblock this signal and call the default handler by temprarily |
984 changing the handler and resignalling. */ | 982 changing the handler and resignalling. */ |
985 sigprocmask (SIG_BLOCK, NULL, &set); | 983 sigprocmask (SIG_BLOCK, NULL, &set); |
986 sigdelset (&set, signalnum); | 984 sigdelset (&set, signalnum); |
1296 #ifdef WINDOWSNT | 1294 #ifdef WINDOWSNT |
1297 w32_give_focus (); | 1295 w32_give_focus (); |
1298 #endif | 1296 #endif |
1299 | 1297 |
1300 /* First of all, send our version number for verification. */ | 1298 /* First of all, send our version number for verification. */ |
1301 SEND_STRING ("-version "); | 1299 send_to_emacs (emacs_socket, "-version "); |
1302 SEND_STRING (VERSION); | 1300 send_to_emacs (emacs_socket, VERSION); |
1303 SEND_STRING (" "); | 1301 send_to_emacs (emacs_socket, " "); |
1304 | 1302 |
1305 /* Send over our environment. */ | 1303 /* Send over our environment. */ |
1306 if (!current_frame) | 1304 if (!current_frame) |
1307 { | 1305 { |
1308 extern char **environ; | 1306 extern char **environ; |
1309 int i; | 1307 int i; |
1310 for (i = 0; environ[i]; i++) | 1308 for (i = 0; environ[i]; i++) |
1311 { | 1309 { |
1312 char *name = xstrdup (environ[i]); | 1310 char *name = xstrdup (environ[i]); |
1313 char *value = strchr (name, '='); | 1311 char *value = strchr (name, '='); |
1314 SEND_STRING ("-env "); | 1312 send_to_emacs (emacs_socket, "-env "); |
1315 SEND_QUOTED (environ[i]); | 1313 quote_argument (emacs_socket, environ[i]); |
1316 SEND_STRING (" "); | 1314 send_to_emacs (emacs_socket, " "); |
1317 } | 1315 } |
1318 } | 1316 } |
1319 | 1317 |
1320 /* Send over our current directory. */ | 1318 /* Send over our current directory. */ |
1321 if (!current_frame) | 1319 if (!current_frame) |
1322 { | 1320 { |
1323 SEND_STRING ("-dir "); | 1321 send_to_emacs (emacs_socket, "-dir "); |
1324 SEND_QUOTED (cwd); | 1322 quote_argument (emacs_socket, cwd); |
1325 SEND_STRING ("/"); | 1323 send_to_emacs (emacs_socket, "/"); |
1326 SEND_STRING (" "); | 1324 send_to_emacs (emacs_socket, " "); |
1327 } | 1325 } |
1328 | 1326 |
1329 retry: | 1327 retry: |
1330 if (nowait) | 1328 if (nowait) |
1331 SEND_STRING ("-nowait "); | 1329 send_to_emacs (emacs_socket, "-nowait "); |
1332 | 1330 |
1333 if (current_frame) | 1331 if (current_frame) |
1334 SEND_STRING ("-current-frame "); | 1332 send_to_emacs (emacs_socket, "-current-frame "); |
1335 | 1333 |
1336 if (display) | 1334 if (display) |
1337 { | 1335 { |
1338 SEND_STRING ("-display "); | 1336 send_to_emacs (emacs_socket, "-display "); |
1339 SEND_QUOTED (display); | 1337 quote_argument (emacs_socket, display); |
1340 SEND_STRING (" "); | 1338 send_to_emacs (emacs_socket, " "); |
1341 } | 1339 } |
1342 | 1340 |
1343 if (tty) | 1341 if (tty) |
1344 { | 1342 { |
1345 char *tty_name = NULL; | 1343 char *tty_name = NULL; |
1370 } | 1368 } |
1371 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM) | 1369 #if !defined (NO_SOCKETS_IN_FILE_SYSTEM) |
1372 init_signals (); | 1370 init_signals (); |
1373 #endif | 1371 #endif |
1374 | 1372 |
1375 SEND_STRING ("-tty "); | 1373 send_to_emacs (emacs_socket, "-tty "); |
1376 SEND_QUOTED (tty_name); | 1374 quote_argument (emacs_socket, tty_name); |
1377 SEND_STRING (" "); | 1375 send_to_emacs (emacs_socket, " "); |
1378 SEND_QUOTED (type); | 1376 quote_argument (emacs_socket, type); |
1379 SEND_STRING (" "); | 1377 send_to_emacs (emacs_socket, " "); |
1380 } | 1378 } |
1381 | 1379 |
1382 if (window_system) | 1380 if (window_system) |
1383 SEND_STRING ("-window-system "); | 1381 send_to_emacs (emacs_socket, "-window-system "); |
1384 | 1382 |
1385 if ((argc - optind > 0)) | 1383 if ((argc - optind > 0)) |
1386 { | 1384 { |
1387 for (i = optind; i < argc; i++) | 1385 for (i = optind; i < argc; i++) |
1388 { | 1386 { |
1389 int relative = 0; | 1387 int relative = 0; |
1390 | 1388 |
1391 if (eval) | 1389 if (eval) |
1392 { | 1390 { |
1393 /* Don't prepend cwd or anything like that. */ | 1391 /* Don't prepend cwd or anything like that. */ |
1394 SEND_STRING ("-eval "); | 1392 send_to_emacs (emacs_socket, "-eval "); |
1395 SEND_QUOTED (argv[i]); | 1393 quote_argument (emacs_socket, argv[i]); |
1396 SEND_STRING (" "); | 1394 send_to_emacs (emacs_socket, " "); |
1397 continue; | 1395 continue; |
1398 } | 1396 } |
1399 | 1397 |
1400 if (*argv[i] == '+') | 1398 if (*argv[i] == '+') |
1401 { | 1399 { |
1402 char *p = argv[i] + 1; | 1400 char *p = argv[i] + 1; |
1403 while (isdigit ((unsigned char) *p) || *p == ':') p++; | 1401 while (isdigit ((unsigned char) *p) || *p == ':') p++; |
1404 if (*p == 0) | 1402 if (*p == 0) |
1405 { | 1403 { |
1406 SEND_STRING ("-position "); | 1404 send_to_emacs (emacs_socket, "-position "); |
1407 SEND_QUOTED (argv[i]); | 1405 quote_argument (emacs_socket, argv[i]); |
1408 SEND_STRING (" "); | 1406 send_to_emacs (emacs_socket, " "); |
1409 continue; | 1407 continue; |
1410 } | 1408 } |
1411 else | 1409 else |
1412 relative = 1; | 1410 relative = 1; |
1413 } | 1411 } |
1414 else if (! file_name_absolute_p (argv[i])) | 1412 else if (! file_name_absolute_p (argv[i])) |
1415 relative = 1; | 1413 relative = 1; |
1416 | 1414 |
1417 SEND_STRING ("-file "); | 1415 send_to_emacs (emacs_socket, "-file "); |
1418 if (relative) | 1416 if (relative) |
1419 { | 1417 { |
1420 SEND_QUOTED (cwd); | 1418 quote_argument (emacs_socket, cwd); |
1421 SEND_STRING ("/"); | 1419 send_to_emacs (emacs_socket, "/"); |
1422 } | 1420 } |
1423 SEND_QUOTED (argv[i]); | 1421 quote_argument (emacs_socket, argv[i]); |
1424 SEND_STRING (" "); | 1422 send_to_emacs (emacs_socket, " "); |
1425 } | 1423 } |
1426 } | 1424 } |
1427 else | 1425 else |
1428 { | 1426 { |
1429 if (!tty && !window_system) | 1427 if (!tty && !window_system) |
1430 { | 1428 { |
1431 while ((str = fgets (string, BUFSIZ, stdin))) | 1429 while ((str = fgets (string, BUFSIZ, stdin))) |
1432 { | 1430 { |
1433 if (eval) | 1431 if (eval) |
1434 SEND_STRING ("-eval "); | 1432 send_to_emacs (emacs_socket, "-eval "); |
1435 else | 1433 else |
1436 SEND_STRING ("-file "); | 1434 send_to_emacs (emacs_socket, "-file "); |
1437 SEND_QUOTED (str); | 1435 quote_argument (emacs_socket, str); |
1438 } | 1436 } |
1439 SEND_STRING (" "); | 1437 send_to_emacs (emacs_socket, " "); |
1440 } | 1438 } |
1441 } | 1439 } |
1442 | 1440 |
1443 SEND_STRING ("\n"); | 1441 send_to_emacs (emacs_socket, "\n"); |
1444 | 1442 |
1445 /* Wait for an answer. */ | 1443 /* Wait for an answer. */ |
1446 if (!eval && !tty && !nowait) | 1444 if (!eval && !tty && !nowait) |
1447 { | 1445 { |
1448 printf ("Waiting for Emacs..."); | 1446 printf ("Waiting for Emacs..."); |