Mercurial > emacs
changeset 49114:c87af62cc6b4
(format-network-address): Added optional OMIT-PORT arg. Callers changed.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Wed, 08 Jan 2003 15:35:03 +0000 |
parents | fd13501a746f |
children | e5b797f8b060 |
files | src/process.c |
diffstat | 1 files changed, 24 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/process.c Wed Jan 08 15:33:55 2003 +0000 +++ b/src/process.c Wed Jan 08 15:35:03 2003 +0000 @@ -1052,11 +1052,13 @@ #ifdef HAVE_SOCKETS DEFUN ("format-network-address", Fformat_network_address, Sformat_network_address, - 1, 1, 0, + 1, 2, 0, doc: /* Convert network ADDRESS from internal format to a string. -Returns nil if format of ADDRESS is invalid. */) - (address) - Lisp_Object address; +If optional second argument OMIT-PORT is non-nil, don't include a port +number in the string; in this case, interpret a 4 element vector as an +IP address. Returns nil if format of ADDRESS is invalid. */) + (address, omit_port) + Lisp_Object address, omit_port; { if (NILP (address)) return Qnil; @@ -1068,17 +1070,24 @@ { register struct Lisp_Vector *p = XVECTOR (address); Lisp_Object args[6]; - - if (p->size != 5) + int nargs, i; + + if (!NILP (omit_port) && (p->size == 4 || p->size == 5)) + { + args[0] = build_string ("%d.%d.%d.%d"); + nargs = 4; + } + else if (p->size == 5) + { + args[0] = build_string ("%d.%d.%d.%d:%d"); + nargs = 5; + } + else return Qnil; - args[0] = build_string ("%d.%d.%d.%d:%d"); - args[1] = p->contents[0]; - args[2] = p->contents[1]; - args[3] = p->contents[2]; - args[4] = p->contents[3]; - args[5] = p->contents[4]; - return Fformat (6, args); + for (i = 0; i < nargs; i++) + args[i+1] = p->contents[i]; + return Fformat (nargs+1, args); } if (CONSP (address)) @@ -1255,7 +1264,7 @@ if (INTEGERP (port)) port = Fnumber_to_string (port); if (NILP (port)) - port = Fformat_network_address (Fplist_get (p->childp, QClocal)); + port = Fformat_network_address (Fplist_get (p->childp, QClocal), Qnil); sprintf (tembuf, "(network %s server on %s)\n", (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"), (STRINGP (port) ? (char *)SDATA (port) : "?")); @@ -1273,7 +1282,7 @@ host = Fnumber_to_string (host); } if (NILP (host)) - host = Fformat_network_address (Fplist_get (p->childp, QCremote)); + host = Fformat_network_address (Fplist_get (p->childp, QCremote), Qnil); sprintf (tembuf, "(network %s connection to %s)\n", (DATAGRAM_CHAN_P (XINT (p->infd)) ? "datagram" : "stream"), (STRINGP (host) ? (char *)SDATA (host) : "?"));