/* Asynchronous subprocess control for GNU Emacs.
Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
1996, 1998, 1999, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007 Free Software Foundation, Inc.
+ 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
This file is part of GNU Emacs.
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA. */
+along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#ifdef NEED_NET_ERRNO_H
-#include <net/errno.h>
-#endif /* NEED_NET_ERRNO_H */
/* Are local (unix) sockets supported? */
-#if defined (HAVE_SYS_UN_H) && !defined (NO_SOCKETS_IN_FILE_SYSTEM)
+#if defined (HAVE_SYS_UN_H)
#if !defined (AF_LOCAL) && defined (AF_UNIX)
#define AF_LOCAL AF_UNIX
#endif
#include <client.h>
#endif
-/* On some systems, e.g. DGUX, inet_addr returns a 'struct in_addr'. */
-#ifdef HAVE_BROKEN_INET_ADDR
-#define IN_ADDR struct in_addr
-#define NUMERIC_ADDR_ERROR (numeric_addr.s_addr == -1)
-#else
-#define IN_ADDR unsigned long
-#define NUMERIC_ADDR_ERROR (numeric_addr == -1)
-#endif
-
-#if defined(BSD_SYSTEM) || defined(STRIDE)
+#if defined(BSD_SYSTEM)
#include <sys/ioctl.h>
#if !defined (O_NDELAY) && defined (HAVE_PTYS) && !defined(USG5)
#include <fcntl.h>
#endif /* HAVE_PTYS and no O_NDELAY */
-#endif /* BSD_SYSTEM || STRIDE */
-
-#ifdef BROKEN_O_NONBLOCK
-#undef O_NONBLOCK
-#endif /* BROKEN_O_NONBLOCK */
+#endif /* BSD_SYSTEM */
#ifdef NEED_BSDTTY
#include <bsdtty.h>
Lisp_Object Qrun, Qstop, Qsignal;
Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
Lisp_Object Qlocal, Qipv4, Qdatagram;
+Lisp_Object Qreal, Qnetwork, Qserial;
#ifdef AF_INET6
Lisp_Object Qipv6;
#endif
+Lisp_Object QCport, QCspeed, QCprocess;
+Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven;
+Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary;
Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype;
Lisp_Object QClocal, QCremote, QCcoding;
Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
Lisp_Object QCsentinel, QClog, QCoptions, QCplist;
-Lisp_Object QCfilter_multibyte;
Lisp_Object Qlast_nonmenu_event;
/* QCfamily is declared and initialized in xfaces.c,
QCfilter in keyboard.c. */
/* QCfilter is defined in keyboard.c. */
extern Lisp_Object QCfilter;
-/* a process object is a network connection when its childp field is neither
- Qt nor Qnil but is instead a property list (KEY VAL ...). */
-
#ifdef HAVE_SOCKETS
-#define NETCONN_P(p) (CONSP (XPROCESS (p)->childp))
-#define NETCONN1_P(p) (CONSP ((p)->childp))
+#define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork))
+#define NETCONN1_P(p) (EQ ((p)->type, Qnetwork))
+#define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial))
+#define SERIALCONN1_P(p) (EQ ((p)->type, Qserial))
#else
#define NETCONN_P(p) 0
#define NETCONN1_P(p) 0
+#define SERIALCONN_P(p) 0
+#define SERIALCONN1_P(p) 0
#endif /* HAVE_SOCKETS */
/* Define first descriptor number available for subprocesses. */
extern char *get_operating_system_release ();
+/* Serial processes require termios or Windows. */
+#if defined (HAVE_TERMIOS) || defined (WINDOWSNT)
+#define HAVE_SERIAL
+#endif
+
+#ifdef HAVE_SERIAL
+/* From sysdep.c or w32.c */
+extern int serial_open (char *port);
+extern void serial_configure (struct Lisp_Process *p, Lisp_Object contact);
+#endif
+
#ifndef USE_CRT_DLL
extern int errno;
#endif
maybe other values to come. */
static Lisp_Object Vprocess_connection_type;
-#ifdef SKTPAIR
-#ifndef HAVE_SOCKETS
-#include <sys/socket.h>
-#endif
-#endif /* SKTPAIR */
-
/* These next two vars are non-static since sysdep.c uses them in the
emulation of `select'. */
/* Number of events of change of status of a process. */
#else
sprintf (pty_name, "/dev/tty%c%x", c, i);
#endif /* no PTY_TTY_NAME_SPRINTF */
-#ifndef UNIPLUS
if (access (pty_name, 6) != 0)
{
emacs_close (fd);
return -1;
# endif /* IRIS */
}
-#endif /* not UNIPLUS */
setup_pty (fd);
return fd;
}
p->tick = 0;
p->update_tick = 0;
p->pid = 0;
+ p->pty_flag = 0;
p->raw_status_new = 0;
p->status = Qrun;
p->mark = Fmake_marker ();
= (struct coding_system *) xmalloc (sizeof (struct coding_system));
coding_system = p->decode_coding_system;
if (! NILP (p->filter))
- {
- if (!p->filter_multibyte)
- coding_system = raw_text_coding_system (coding_system);
- }
+ ;
else if (BUFFERP (p->buffer))
{
if (NILP (XBUFFER (p->buffer)->enable_multibyte_characters))
p = XPROCESS (process);
p->raw_status_new = 0;
- if (NETCONN1_P (p))
+ if (NETCONN1_P (p) || SERIALCONN1_P (p))
{
p->status = Fcons (Qexit, Fcons (make_number (0), Qnil));
p->tick = ++process_tick;
status = p->status;
if (CONSP (status))
status = XCAR (status);
- if (NETCONN1_P (p))
+ if (NETCONN1_P (p) || SERIALCONN1_P (p))
{
if (EQ (status, Qexit))
status = Qclosed;
doc: /* Return the command that was executed to start PROCESS.
This is a list of strings, the first string being the program executed
and the rest of the strings being the arguments given to it.
-For a non-child channel, this is nil. */)
+For a network or serial process, this is nil (process is running) or t
+\(process is stopped). */)
(process)
register Lisp_Object process;
{
CHECK_BUFFER (buffer);
p = XPROCESS (process);
p->buffer = buffer;
- if (NETCONN1_P (p))
+ if (NETCONN1_P (p) || SERIALCONN1_P (p))
p->childp = Fplist_put (p->childp, QCbuffer, buffer);
setup_process_coding_systems (process);
return buffer;
FD_CLR (p->infd, &non_keyboard_wait_mask);
}
else if (EQ (p->filter, Qt)
- && !EQ (p->command, Qt)) /* Network process not stopped. */
+ /* Network or serial process not stopped: */
+ && !EQ (p->command, Qt))
{
FD_SET (p->infd, &input_wait_mask);
FD_SET (p->infd, &non_keyboard_wait_mask);
}
p->filter = filter;
- if (NETCONN1_P (p))
+ if (NETCONN1_P (p) || SERIALCONN1_P (p))
p->childp = Fplist_put (p->childp, QCfilter, filter);
setup_process_coding_systems (process);
return filter;
p = XPROCESS (process);
p->sentinel = sentinel;
- if (NETCONN1_P (p))
+ if (NETCONN1_P (p) || SERIALCONN1_P (p))
p->childp = Fplist_put (p->childp, QCsentinel, sentinel);
return sentinel;
}
DEFUN ("process-contact", Fprocess_contact, Sprocess_contact,
1, 2, 0,
doc: /* Return the contact info of PROCESS; t for a real child.
-For a net connection, the value depends on the optional KEY arg.
-If KEY is nil, value is a cons cell of the form (HOST SERVICE),
-if KEY is t, the complete contact information for the connection is
-returned, else the specific value for the keyword KEY is returned.
-See `make-network-process' for a list of keywords. */)
+For a network or serial connection, the value depends on the optional
+KEY arg. If KEY is nil, value is a cons cell of the form (HOST
+SERVICE) for a network connection or (PORT SPEED) for a serial
+connection. If KEY is t, the complete contact information for the
+connection is returned, else the specific value for the keyword KEY is
+returned. See `make-network-process' or `make-serial-process' for a
+list of keywords. */)
(process, key)
register Lisp_Object process, key;
{
Fprocess_datagram_address (process));
#endif
- if (!NETCONN_P (process) || EQ (key, Qt))
+ if ((!NETCONN_P (process) && !SERIALCONN_P (process)) || EQ (key, Qt))
return contact;
- if (NILP (key))
+ if (NILP (key) && NETCONN_P (process))
return Fcons (Fplist_get (contact, QChost),
Fcons (Fplist_get (contact, QCservice), Qnil));
+ if (NILP (key) && SERIALCONN_P (process))
+ return Fcons (Fplist_get (contact, QCport),
+ Fcons (Fplist_get (contact, QCspeed), Qnil));
return Fplist_get (contact, key);
}
return XPROCESS (process)->type;
}
#endif
+
+DEFUN ("process-type", Fprocess_type, Sprocess_type, 1, 1, 0,
+ doc: /* Return the connection type of PROCESS.
+The value is either the symbol `real', `network', or `serial'.
+PROCESS may be a process, a buffer, the name of a process or buffer, or
+nil, indicating the current buffer's process. */)
+ (process)
+ Lisp_Object process;
+{
+ Lisp_Object proc;
+ proc = get_process (process);
+ return XPROCESS (proc)->type;
+}
#ifdef HAVE_SOCKETS
DEFUN ("format-network-address", Fformat_network_address, Sformat_network_address,
proc = Fcdr (XCAR (tail));
p = XPROCESS (proc);
- if (NILP (p->childp))
+ if (NILP (p->type))
continue;
if (!NILP (query_only) && p->kill_without_query)
continue;
w_proc = i;
if (!NILP (p->buffer))
{
- if (NILP (XBUFFER (p->buffer)->name) && w_buffer < 8)
- w_buffer = 8; /* (Killed) */
+ if (NILP (XBUFFER (p->buffer)->name))
+ {
+ if (w_buffer < 8)
+ w_buffer = 8; /* (Killed) */
+ }
else if ((i = SCHARS (XBUFFER (p->buffer)->name), (i > w_buffer)))
w_buffer = i;
}
if (w_tty)
{
XSETFASTINT (i_tty, XFASTINT (i_buffer) + w_buffer + 1);
- XSETFASTINT (i_command, XFASTINT (i_buffer) + w_tty + 1);
- } else {
+ XSETFASTINT (i_command, XFASTINT (i_tty) + w_tty + 1);
+ }
+ else
+ {
i_tty = Qnil;
XSETFASTINT (i_command, XFASTINT (i_buffer) + w_buffer + 1);
}
proc = Fcdr (XCAR (tail));
p = XPROCESS (proc);
- if (NILP (p->childp))
+ if (NILP (p->type))
continue;
if (!NILP (query_only) && p->kill_without_query)
continue;
#endif
Fprinc (symbol, Qnil);
}
- else if (NETCONN1_P (p))
+ else if (NETCONN1_P (p) || SERIALCONN1_P (p))
{
if (EQ (symbol, Qexit))
write_string ("closed", -1);
else
Fprinc (symbol, Qnil);
}
+ else if (SERIALCONN1_P (p))
+ {
+ write_string ("running", -1);
+ }
else
Fprinc (symbol, Qnil);
(STRINGP (host) ? (char *)SDATA (host) : "?"));
insert_string (tembuf);
}
+ else if (SERIALCONN1_P (p))
+ {
+ Lisp_Object port = Fplist_get (p->childp, QCport);
+ Lisp_Object speed = Fplist_get (p->childp, QCspeed);
+ insert_string ("(serial port ");
+ if (STRINGP (port))
+ insert_string (SDATA (port));
+ else
+ insert_string ("?");
+ if (INTEGERP (speed))
+ {
+ sprintf (tembuf, " at %d b/s", XINT (speed));
+ insert_string (tembuf);
+ }
+ insert_string (")\n");
+ }
else
{
tem = p->command;
GCPRO2 (buffer, current_dir);
- current_dir
- = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
- Qnil);
+ current_dir = Funhandled_file_name_directory (current_dir);
+ if (NILP (current_dir))
+ /* If the file name handler says that current_dir is unreachable, use
+ a sensible default. */
+ current_dir = build_string ("~/");
+ current_dir = expand_and_dir_to_file (current_dir, Qnil);
if (NILP (Ffile_accessible_directory_p (current_dir)))
report_file_error ("Setting current directory",
Fcons (current_buffer->directory, Qnil));
XPROCESS (proc)->childp = Qt;
XPROCESS (proc)->plist = Qnil;
+ XPROCESS (proc)->type = Qreal;
XPROCESS (proc)->buffer = buffer;
XPROCESS (proc)->sentinel = Qnil;
XPROCESS (proc)->filter = Qnil;
- XPROCESS (proc)->filter_multibyte
- = !NILP (buffer_defaults.enable_multibyte_characters);
XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
#ifdef ADAPTIVE_READ_BUFFERING
#endif
if (forkin < 0)
report_file_error ("Opening pty", Qnil);
-#if defined (RTU) || defined (UNIPLUS) || defined (DONT_REOPEN_PTY)
+#if defined (DONT_REOPEN_PTY)
/* In the case that vfork is defined as fork, the parent process
(Emacs) may send some data before the child process completes
tty options setup. So we setup tty before forking. */
child_setup_tty (forkout);
-#endif /* RTU or UNIPLUS or DONT_REOPEN_PTY */
+#endif /* DONT_REOPEN_PTY */
#else
forkin = forkout = -1;
#endif /* not USG, or USG_SUBTTY_WORKS */
}
else
#endif /* HAVE_PTYS */
-#ifdef SKTPAIR
- {
- if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
- report_file_error ("Opening socketpair", Qnil);
- outchannel = inchannel = sv[0];
- forkout = forkin = sv[1];
- }
-#else /* not SKTPAIR */
{
int tem;
tem = pipe (sv);
outchannel = sv[1];
forkin = sv[0];
}
-#endif /* not SKTPAIR */
#if 0
/* Replaced by close_process_descs */
set_exclusive_use (outchannel);
#endif
-/* Stride people say it's a mystery why this is needed
- as well as the O_NDELAY, but that it fails without this. */
-#if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS))
- {
- int one = 1;
- ioctl (inchannel, FIONBIO, &one);
- }
-#endif
-
#ifdef O_NONBLOCK
fcntl (inchannel, F_SETFL, O_NONBLOCK);
fcntl (outchannel, F_SETFL, O_NONBLOCK);
sigprocmask (SIG_BLOCK, &blocked, &procmask);
#else /* !POSIX_SIGNALS */
#ifdef SIGCHLD
-#ifdef BSD4_1
- sighold (SIGCHLD);
-#else /* not BSD4_1 */
-#if defined (BSD_SYSTEM) || defined (UNIPLUS) || defined (HPUX)
+#if defined (BSD_SYSTEM) || defined (HPUX)
sigsetmask (sigmask (SIGCHLD));
#else /* ordinary USG */
#if 0
sigchld = signal (SIGCHLD, create_process_sigchld);
#endif
#endif /* ordinary USG */
-#endif /* not BSD4_1 */
#endif /* SIGCHLD */
#endif /* !POSIX_SIGNALS */
}
#endif /* TIOCNOTTY */
-#if !defined (RTU) && !defined (UNIPLUS) && !defined (DONT_REOPEN_PTY)
+#if !defined (DONT_REOPEN_PTY)
/*** There is a suggestion that this ought to be a
conditional on TIOCSPGRP,
or !(defined (HAVE_SETSID) && defined (TIOCSCTTY)).
This makes the pty the controlling terminal of the subprocess. */
if (pty_flag)
{
-#ifdef SET_CHILD_PTY_PGRP
- int pgrp = getpid ();
-#endif
/* I wonder if emacs_close (emacs_open (pty_name, ...))
would work? */
_exit (1);
}
-#ifdef SET_CHILD_PTY_PGRP
- ioctl (xforkin, TIOCSPGRP, &pgrp);
- ioctl (xforkout, TIOCSPGRP, &pgrp);
-#endif
}
-#endif /* not UNIPLUS and not RTU and not DONT_REOPEN_PTY */
+#endif /* not DONT_REOPEN_PTY */
#ifdef SETUP_SLAVE_PTY
if (pty_flag)
sigprocmask (SIG_SETMASK, &procmask, 0);
#else /* !POSIX_SIGNALS */
#ifdef SIGCHLD
-#ifdef BSD4_1
- sigrelse (SIGCHLD);
-#else /* not BSD4_1 */
-#if defined (BSD_SYSTEM) || defined (UNIPLUS) || defined (HPUX)
+#if defined (BSD_SYSTEM) || defined (HPUX)
sigsetmask (SIGEMPTYMASK);
#else /* ordinary USG */
#if 0
signal (SIGCHLD, sigchld);
#endif
#endif /* ordinary USG */
-#endif /* not BSD4_1 */
#endif /* SIGCHLD */
#endif /* !POSIX_SIGNALS */
-#if !defined (RTU) && !defined (UNIPLUS) && !defined (DONT_REOPEN_PTY)
+#if !defined (DONT_REOPEN_PTY)
if (pty_flag)
child_setup_tty (xforkout);
-#endif /* not RTU and not UNIPLUS and not DONT_REOPEN_PTY */
+#endif /* not DONT_REOPEN_PTY */
#ifdef WINDOWSNT
pid = child_setup (xforkin, xforkout, xforkout,
new_argv, 1, current_dir);
sigprocmask (SIG_SETMASK, &procmask, 0);
#else /* !POSIX_SIGNALS */
#ifdef SIGCHLD
-#ifdef BSD4_1
- sigrelse (SIGCHLD);
-#else /* not BSD4_1 */
-#if defined (BSD_SYSTEM) || defined (UNIPLUS) || defined (HPUX)
+#if defined (BSD_SYSTEM) || defined (HPUX)
sigsetmask (SIGEMPTYMASK);
#else /* ordinary USG */
#if 0
kill (getpid (), SIGCHLD);
#endif
#endif /* ordinary USG */
-#endif /* not BSD4_1 */
#endif /* SIGCHLD */
#endif /* !POSIX_SIGNALS */
}
\f
-/* A version of request_sigio suitable for a record_unwind_protect. */
+#ifdef HAVE_SERIAL
+DEFUN ("serial-process-configure",
+ Fserial_process_configure,
+ Sserial_process_configure,
+ 0, MANY, 0,
+ doc: /* Configure speed, bytesize, etc. of a serial process.
-#ifdef __ultrix__
-static Lisp_Object
-unwind_request_sigio (dummy)
- Lisp_Object dummy;
+Arguments are specified as keyword/argument pairs. Attributes that
+are not given are re-initialized from the process's current
+configuration (available via the function `process-contact') or set to
+reasonable default values. The following arguments are defined:
+
+:process PROCESS
+:name NAME
+:buffer BUFFER
+:port PORT
+-- Any of these arguments can be given to identify the process that is
+to be configured. If none of these arguments is given, the current
+buffer's process is used.
+
+:speed SPEED -- SPEED is the speed of the serial port in bits per
+second, also called baud rate. Any value can be given for SPEED, but
+most serial ports work only at a few defined values between 1200 and
+115200, with 9600 being the most common value. If SPEED is nil, the
+serial port is not configured any further, i.e., all other arguments
+are ignored. This may be useful for special serial ports such as
+Bluetooth-to-serial converters which can only be configured through AT
+commands. A value of nil for SPEED can be used only when passed
+through `make-serial-process' or `serial-term'.
+
+:bytesize BYTESIZE -- BYTESIZE is the number of bits per byte, which
+can be 7 or 8. If BYTESIZE is not given or nil, a value of 8 is used.
+
+:parity PARITY -- PARITY can be nil (don't use parity), the symbol
+`odd' (use odd parity), or the symbol `even' (use even parity). If
+PARITY is not given, no parity is used.
+
+:stopbits STOPBITS -- STOPBITS is the number of stopbits used to
+terminate a byte transmission. STOPBITS can be 1 or 2. If STOPBITS
+is not given or nil, 1 stopbit is used.
+
+:flowcontrol FLOWCONTROL -- FLOWCONTROL determines the type of
+flowcontrol to be used, which is either nil (don't use flowcontrol),
+the symbol `hw' (use RTS/CTS hardware flowcontrol), or the symbol `sw'
+\(use XON/XOFF software flowcontrol). If FLOWCONTROL is not given, no
+flowcontrol is used.
+
+`serial-process-configure' is called by `make-serial-process' for the
+initial configuration of the serial port.
+
+Examples:
+
+\(serial-process-configure :process "/dev/ttyS0" :speed 1200)
+
+\(serial-process-configure
+ :buffer "COM1" :stopbits 1 :parity 'odd :flowcontrol 'hw)
+
+\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7)
+
+usage: (serial-process-configure &rest ARGS) */)
+ (nargs, args)
+ int nargs;
+ Lisp_Object *args;
{
- if (interrupt_input)
- request_sigio ();
+ struct Lisp_Process *p;
+ Lisp_Object contact = Qnil;
+ Lisp_Object proc = Qnil;
+ struct gcpro gcpro1;
+
+ contact = Flist (nargs, args);
+ GCPRO1 (contact);
+
+ proc = Fplist_get (contact, QCprocess);
+ if (NILP (proc))
+ proc = Fplist_get (contact, QCname);
+ if (NILP (proc))
+ proc = Fplist_get (contact, QCbuffer);
+ if (NILP (proc))
+ proc = Fplist_get (contact, QCport);
+ proc = get_process (proc);
+ p = XPROCESS (proc);
+ if (!EQ (p->type, Qserial))
+ error ("Not a serial process");
+
+ if (NILP (Fplist_get (p->childp, QCspeed)))
+ {
+ UNGCPRO;
+ return Qnil;
+ }
+
+ serial_configure (p, contact);
+
+ UNGCPRO;
return Qnil;
}
-#endif
+#endif /* HAVE_SERIAL */
+
+#ifdef HAVE_SERIAL
+/* Used by make-serial-process to recover from errors. */
+Lisp_Object make_serial_process_unwind (Lisp_Object proc)
+{
+ if (!PROCESSP (proc))
+ abort ();
+ remove_process (proc);
+ return Qnil;
+}
+#endif /* HAVE_SERIAL */
+
+#ifdef HAVE_SERIAL
+DEFUN ("make-serial-process", Fmake_serial_process, Smake_serial_process,
+ 0, MANY, 0,
+ doc: /* Create and return a serial port process.
+
+In Emacs, serial port connections are represented by process objects,
+so input and output work as for subprocesses, and `delete-process'
+closes a serial port connection. However, a serial process has no
+process id, it cannot be signaled, and the status codes are different
+from normal processes.
+
+`make-serial-process' creates a process and a buffer, on which you
+probably want to use `process-send-string'. Try \\[serial-term] for
+an interactive terminal. See below for examples.
+
+Arguments are specified as keyword/argument pairs. The following
+arguments are defined:
+
+:port PORT -- (mandatory) PORT is the path or name of the serial port.
+For example, this could be "/dev/ttyS0" on Unix. On Windows, this
+could be "COM1", or "\\\\.\\COM10" for ports higher than COM9 (double
+the backslashes in strings).
+
+:speed SPEED -- (mandatory) is handled by `serial-process-configure',
+which is called by `make-serial-process'.
+
+:name NAME -- NAME is the name of the process. If NAME is not given,
+the value of PORT is used.
+
+:buffer BUFFER -- BUFFER is the buffer (or buffer-name) to associate
+with the process. Process output goes at the end of that buffer,
+unless you specify an output stream or filter function to handle the
+output. If BUFFER is not given, the value of NAME is used.
+
+:coding CODING -- If CODING is a symbol, it specifies the coding
+system used for both reading and writing for this process. If CODING
+is a cons (DECODING . ENCODING), DECODING is used for reading, and
+ENCODING is used for writing.
+
+:noquery BOOL -- When exiting Emacs, query the user if BOOL is nil and
+the process is running. If BOOL is not given, query before exiting.
+
+:stop BOOL -- Start process in the `stopped' state if BOOL is non-nil.
+In the stopped state, a serial process does not accept incoming data,
+but you can send outgoing data. The stopped state is cleared by
+`continue-process' and set by `stop-process'.
+
+:filter FILTER -- Install FILTER as the process filter.
+
+:sentinel SENTINEL -- Install SENTINEL as the process sentinel.
+
+:plist PLIST -- Install PLIST as the initial plist of the process.
+
+:speed
+:bytesize
+:parity
+:stopbits
+:flowcontrol
+-- These arguments are handled by `serial-process-configure', which is
+called by `make-serial-process'.
+
+The original argument list, possibly modified by later configuration,
+is available via the function `process-contact'.
+
+Examples:
+
+\(make-serial-process :port "/dev/ttyS0" :speed 9600)
+
+\(make-serial-process :port "COM1" :speed 115200 :stopbits 2)
+
+\(make-serial-process :port "\\\\.\\COM13" :speed 1200 :bytesize 7 :parity 'odd)
+
+\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil)
+
+usage: (make-serial-process &rest ARGS) */)
+ (nargs, args)
+ int nargs;
+ Lisp_Object *args;
+{
+ int fd = -1;
+ Lisp_Object proc, contact, port;
+ struct Lisp_Process *p;
+ struct gcpro gcpro1;
+ Lisp_Object name, buffer;
+ Lisp_Object tem, val;
+ int specpdl_count = -1;
+
+ if (nargs == 0)
+ return Qnil;
+
+ contact = Flist (nargs, args);
+ GCPRO1 (contact);
+
+ port = Fplist_get (contact, QCport);
+ if (NILP (port))
+ error ("No port specified");
+ CHECK_STRING (port);
+
+ if (NILP (Fplist_member (contact, QCspeed)))
+ error (":speed not specified");
+ if (!NILP (Fplist_get (contact, QCspeed)))
+ CHECK_NUMBER (Fplist_get (contact, QCspeed));
+
+ name = Fplist_get (contact, QCname);
+ if (NILP (name))
+ name = port;
+ CHECK_STRING (name);
+ proc = make_process (name);
+ specpdl_count = SPECPDL_INDEX ();
+ record_unwind_protect (make_serial_process_unwind, proc);
+ p = XPROCESS (proc);
+
+ fd = serial_open ((char*) SDATA (port));
+ p->infd = fd;
+ p->outfd = fd;
+ if (fd > max_process_desc)
+ max_process_desc = fd;
+ chan_process[fd] = proc;
+
+ buffer = Fplist_get (contact, QCbuffer);
+ if (NILP (buffer))
+ buffer = name;
+ buffer = Fget_buffer_create (buffer);
+ p->buffer = buffer;
+
+ p->childp = contact;
+ p->plist = Fcopy_sequence (Fplist_get (contact, QCplist));
+ p->type = Qserial;
+ p->sentinel = Fplist_get (contact, QCsentinel);
+ p->filter = Fplist_get (contact, QCfilter);
+ p->log = Qnil;
+ if (tem = Fplist_get (contact, QCnoquery), !NILP (tem))
+ p->kill_without_query = 1;
+ if (tem = Fplist_get (contact, QCstop), !NILP (tem))
+ p->command = Qt;
+ p->pty_flag = 0;
+
+ if (!EQ (p->command, Qt))
+ {
+ FD_SET (fd, &input_wait_mask);
+ FD_SET (fd, &non_keyboard_wait_mask);
+ }
+
+ if (BUFFERP (buffer))
+ {
+ set_marker_both (p->mark, buffer,
+ BUF_ZV (XBUFFER (buffer)),
+ BUF_ZV_BYTE (XBUFFER (buffer)));
+ }
+
+ tem = Fplist_member (contact, QCcoding);
+ if (!NILP (tem) && (!CONSP (tem) || !CONSP (XCDR (tem))))
+ tem = Qnil;
+
+ val = Qnil;
+ if (!NILP (tem))
+ {
+ val = XCAR (XCDR (tem));
+ if (CONSP (val))
+ val = XCAR (val);
+ }
+ else if (!NILP (Vcoding_system_for_read))
+ val = Vcoding_system_for_read;
+ else if ((!NILP (buffer) && NILP (XBUFFER (buffer)->enable_multibyte_characters))
+ || (NILP (buffer) && NILP (buffer_defaults.enable_multibyte_characters)))
+ val = Qnil;
+ p->decode_coding_system = val;
+
+ val = Qnil;
+ if (!NILP (tem))
+ {
+ val = XCAR (XCDR (tem));
+ if (CONSP (val))
+ val = XCDR (val);
+ }
+ else if (!NILP (Vcoding_system_for_write))
+ val = Vcoding_system_for_write;
+ else if ((!NILP (buffer) && NILP (XBUFFER (buffer)->enable_multibyte_characters))
+ || (NILP (buffer) && NILP (buffer_defaults.enable_multibyte_characters)))
+ val = Qnil;
+ p->encode_coding_system = val;
+
+ setup_process_coding_systems (proc);
+ p->decoding_buf = make_uninit_string (0);
+ p->decoding_carryover = 0;
+ p->encoding_buf = make_uninit_string (0);
+ p->inherit_coding_system_flag
+ = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system);
+
+ Fserial_process_configure(nargs, args);
+
+ specpdl_ptr = specpdl + specpdl_count;
+
+ UNGCPRO;
+ return proc;
+}
+#endif /* HAVE_SERIAL */
/* Create a network stream/datagram client/server process. Treated
exactly like a normal process when reading and writing. Primary
else
/* Attempt to interpret host as numeric inet address */
{
- IN_ADDR numeric_addr;
+ unsigned long numeric_addr;
numeric_addr = inet_addr ((char *) SDATA (host));
- if (NUMERIC_ADDR_ERROR)
+ if (numeric_addr == -1)
error ("Unknown host \"%s\"", SDATA (host));
bcopy ((char *)&numeric_addr, (char *) &address_in.sin_addr,
open_socket:
-#ifdef __ultrix__
- /* Previously this was compiled unconditionally, but that seems
- unnecessary on modern systems, and `unrequest_sigio' was a noop
- under X anyway. --lorentey */
- /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
- when connect is interrupted. So let's not let it get interrupted.
- Note we do not turn off polling, because polling is only used
- when not interrupt_input, and thus not normally used on the systems
- which have this bug. On systems which use polling, there's no way
- to quit if polling is turned off. */
- if (interrupt_input
- && !is_server && socktype == SOCK_STREAM)
- {
- /* Comment from KFS: The original open-network-stream code
- didn't unwind protect this, but it seems like the proper
- thing to do. In any case, I don't see how it could harm to
- do this -- and it makes cleanup (using unbind_to) easier. */
- record_unwind_protect (unwind_request_sigio, Qnil);
- unrequest_sigio ();
- }
-#endif
-
/* Do this in case we never enter the for-loop below. */
count1 = SPECPDL_INDEX ();
s = -1;
p->childp = contact;
p->plist = Fcopy_sequence (Fplist_get (contact, QCplist));
+ p->type = Qnetwork;
p->buffer = buffer;
p->sentinel = sentinel;
p->filter = filter;
- p->filter_multibyte = !NILP (buffer_defaults.enable_multibyte_characters);
- /* Override the above only if :filter-multibyte is specified. */
- if (! NILP (Fplist_member (contact, QCfilter_multibyte)))
- p->filter_multibyte = !NILP (Fplist_get (contact, QCfilter_multibyte));
p->log = Fplist_get (contact, QClog);
if (tem = Fplist_get (contact, QCnoquery), !NILP (tem))
p->kill_without_query = 1;
seconds and milliseconds to wait; return after that much time whether
or not there is input. If SECONDS is a floating point number,
it specifies a fractional number of seconds to wait.
+The MILLISEC argument is obsolete and should be avoided.
If optional fourth arg JUST-THIS-ONE is non-nil, only accept output
from PROCESS, suspending reading output from other processes.
else
just_this_one = Qnil;
+ if (!NILP (millisec))
+ { /* Obsolete calling convention using integers rather than floats. */
+ CHECK_NUMBER (millisec);
+ if (NILP (seconds))
+ seconds = make_float (XINT (millisec) / 1000.0);
+ else
+ {
+ CHECK_NUMBER (seconds);
+ seconds = make_float (XINT (millisec) / 1000.0 + XINT (seconds));
+ }
+ }
+
if (!NILP (seconds))
{
if (INTEGERP (seconds))
else
wrong_type_argument (Qnumberp, seconds);
- if (INTEGERP (millisec))
- {
- int carry;
- usecs += XINT (millisec) * 1000;
- carry = usecs / 1000000;
- secs += carry;
- if ((usecs -= carry * 1000000) < 0)
- {
- secs--;
- usecs += 1000000;
- }
- }
-
if (secs < 0 || (secs == 0 && usecs == 0))
secs = -1, usecs = 0;
}
#endif
default:
caller = Fnumber_to_string (make_number (connect_counter));
- caller = concat3 (build_string (" <*"), caller, build_string ("*>"));
+ caller = concat3 (build_string (" <"), caller, build_string (">"));
break;
}
p->childp = contact;
p->plist = Fcopy_sequence (ps->plist);
+ p->type = Qnetwork;
p->buffer = buffer;
p->sentinel = ps->sentinel;
EMACS_SET_SECS_USECS (timeout, time_limit, microsecs);
EMACS_ADD_TIME (end_time, end_time, timeout);
}
-#ifdef POLL_INTERRUPTED_SYS_CALL
- /* AlainF 5-Jul-1996
- HP-UX 10.10 seem to have problems with signals coming in
- Causes "poll: interrupted system call" messages when Emacs is run
- in an X window
- Turn off periodic alarms (in case they are in use),
- and then turn off any other atimers. */
- stop_polling ();
- turn_on_atimers (0);
-#endif /* POLL_INTERRUPTED_SYS_CALL */
while (1)
{
if (read_kbd >= 0)
QUIT;
#ifdef SYNC_INPUT
- else if (interrupt_input_pending)
- handle_async_input ();
+ else
+ {
+ if (interrupt_input_pending)
+ handle_async_input ();
+ if (pending_atimers)
+ do_pending_atimers ();
+ }
#endif
/* Exit now if the cell we're waiting for became non-nil. */
{
int old_timers_run = timers_run;
struct buffer *old_buffer = current_buffer;
+ Lisp_Object old_window = selected_window;
timer_delay = timer_check (1);
/* If a timer has run, this might have changed buffers
an alike. Make read_key_sequence aware of that. */
if (timers_run != old_timers_run
- && old_buffer != current_buffer
+ && (old_buffer != current_buffer
+ || !EQ (old_window, selected_window))
&& waiting_for_user_input_p == -1)
record_asynch_buffer_change ();
/* If status of something has changed, and no input is
available, notify the user of the change right away. After
this explicit check, we'll let the SIGCHLD handler zap
- timeout to get our attention. */
- if (update_tick != process_tick && do_display)
+ timeout to get our attention. When Emacs is run
+ interactively, only do this with a nonzero DO_DISPLAY
+ argument, because status_notify triggers redisplay. */
+ if (update_tick != process_tick
+ && (do_display || noninteractive))
{
SELECT_TYPE Atemp;
#ifdef NON_BLOCKING_CONNECT
break;
if (0 < nread)
- total_nread += nread;
+ {
+ total_nread += nread;
+ got_some_input = 1;
+ }
#ifdef EIO
else if (nread == -1 && EIO == errno)
break;
{
if (xerrno == EINTR)
no_avail = 1;
-#ifdef ultrix
- /* Ultrix select seems to return ENOMEM when it is
- interrupted. Treat it just like EINTR. Bleah. Note
- that we want to test for the "ultrix" CPP symbol, not
- "__ultrix__"; the latter is only defined under GCC, but
- not by DEC's bundled CC. -JimB */
- else if (xerrno == ENOMEM)
- no_avail = 1;
-#endif
-#ifdef ALLIANT
- /* This happens for no known reason on ALLIANT.
- I am guessing that this is the right response. -- RMS. */
- else if (xerrno == EFAULT)
- no_avail = 1;
-#endif
else if (xerrno == EBADF)
{
#ifdef AIX
{
int old_timers_run = timers_run;
struct buffer *old_buffer = current_buffer;
+ Lisp_Object old_window = selected_window;
int leave = 0;
if (detect_input_pending_run_timers (do_display))
an alike. Make read_key_sequence aware of that. */
if (timers_run != old_timers_run
&& waiting_for_user_input_p == -1
- && old_buffer != current_buffer)
+ && (old_buffer != current_buffer
+ || !EQ (old_window, selected_window)))
record_asynch_buffer_change ();
if (leave)
available now and a closed pipe.
With luck, a closed pipe will be accompanied by
subprocess termination and SIGCHLD. */
- else if (nread == 0 && !NETCONN_P (proc))
+ else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc))
;
#endif /* O_NDELAY */
#endif /* O_NONBLOCK */
/* If we can detect process termination, don't consider the process
gone just because its pipe is closed. */
#ifdef SIGCHLD
- else if (nread == 0 && !NETCONN_P (proc))
+ else if (nread == 0 && !NETCONN_P (proc) && !SERIALCONN_P (proc))
;
#endif
else
clear_input_pending ();
QUIT;
}
-#ifdef POLL_INTERRUPTED_SYS_CALL
- /* AlainF 5-Jul-1996
- HP-UX 10.10 seems to have problems with signals coming in
- Causes "poll: interrupted system call" messages when Emacs is run
- in an X window
- Turn periodic alarms back on */
- start_polling ();
-#endif /* POLL_INTERRUPTED_SYS_CALL */
return got_some_input;
}
coding->carryover_bytes);
p->decoding_carryover = coding->carryover_bytes;
}
- /* Adjust the multibyteness of TEXT to that of the filter. */
- if (!p->filter_multibyte != !STRING_MULTIBYTE (text))
- text = (STRING_MULTIBYTE (text)
- ? Fstring_as_unibyte (text)
- : Fstring_to_multibyte (text));
if (SBYTES (text) > 0)
internal_condition_case_1 (read_process_output_call,
Fcons (outstream,
send_process_trap ()
{
SIGNAL_THREAD_CHECK (SIGPIPE);
-#ifdef BSD4_1
- sigrelse (SIGPIPE);
- sigrelse (SIGALRM);
-#endif /* BSD4_1 */
sigunblock (sigmask (SIGPIPE));
longjmp (send_process_frame, 1);
}
this -= rv;
}
- /* If we sent just part of the string, put in an EOF
+ /* If we sent just part of the string, put in an EOF (C-d)
to force it through, before we send the rest. */
if (len > 0)
Fprocess_send_eof (proc);
int fd;
/* Some OS:es (Solaris 8/9) does not allow TIOCGPGRP from the
master side. Try the slave side. */
- fd = emacs_open (XSTRING (p->tty_name)->data, O_RDONLY, 0);
+ fd = emacs_open (SDATA (p->tty_name), O_RDONLY, 0);
if (fd != -1)
{
proc = get_process (process);
p = XPROCESS (proc);
- if (!EQ (p->childp, Qt))
+ if (!EQ (p->type, Qreal))
error ("Process %s is not a subprocess",
SDATA (p->name));
if (p->infd < 0)
proc = get_process (process);
p = XPROCESS (proc);
- if (!EQ (p->childp, Qt))
+ if (!EQ (p->type, Qreal))
error ("Process %s is not a subprocess",
SDATA (p->name));
if (p->infd < 0)
you'd better be using one of the alternatives above! */
#endif /* ! defined (TCGETA) */
#endif /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
- /* In this case, the code above should alway returns. */
+ /* In this case, the code above should alway return. */
abort ();
#endif /* ! defined HAVE_TERMIOS */
DEFUN ("stop-process", Fstop_process, Sstop_process, 0, 2, 0,
doc: /* Stop process PROCESS. May be process or name of one.
See function `interrupt-process' for more details on usage.
-If PROCESS is a network process, inhibit handling of incoming traffic. */)
+If PROCESS is a network or serial process, inhibit handling of incoming
+traffic. */)
(process, current_group)
Lisp_Object process, current_group;
{
#ifdef HAVE_SOCKETS
- if (PROCESSP (process) && NETCONN_P (process))
+ if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process)))
{
struct Lisp_Process *p;
DEFUN ("continue-process", Fcontinue_process, Scontinue_process, 0, 2, 0,
doc: /* Continue process PROCESS. May be process or name of one.
See function `interrupt-process' for more details on usage.
-If PROCESS is a network process, resume handling of incoming traffic. */)
+If PROCESS is a network or serial process, resume handling of incoming
+traffic. */)
(process, current_group)
Lisp_Object process, current_group;
{
#ifdef HAVE_SOCKETS
- if (PROCESSP (process) && NETCONN_P (process))
+ if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process)))
{
struct Lisp_Process *p;
{
FD_SET (p->infd, &input_wait_mask);
FD_SET (p->infd, &non_keyboard_wait_mask);
+#ifdef WINDOWSNT
+ if (fd_info[ p->infd ].flags & FILE_SERIAL)
+ PurgeComm (fd_info[ p->infd ].hnd, PURGE_RXABORT | PURGE_RXCLEAR);
+#endif
+#ifdef HAVE_TERMIOS
+ tcflush (p->infd, TCIFLUSH);
+#endif
}
p->command = Qnil;
return process;
got_it:
#define parse_signal(NAME, VALUE) \
- else if (!xstricmp (name, NAME)) \
+ else if (!xstrcasecmp (name, NAME)) \
XSETINT (sigcode, VALUE)
if (INTEGERP (sigcode))
nil, indicating the current buffer's process.
If PROCESS is a network connection, or is a process communicating
through a pipe (as opposed to a pty), then you cannot send any more
-text to PROCESS after you call this function. */)
+text to PROCESS after you call this function.
+If PROCESS is a serial process, wait until all output written to the
+process has been transmitted to the serial port. */)
(process)
Lisp_Object process;
{
#else
if (XPROCESS (proc)->pty_flag)
send_process (proc, "\004", 1, Qnil);
+ else if (EQ (XPROCESS (proc)->type, Qserial))
+ {
+#ifdef HAVE_TERMIOS
+ if (tcdrain (XPROCESS (proc)->outfd) != 0)
+ error ("tcdrain() failed: %s", emacs_strerror (errno));
+#endif
+ /* Do nothing on Windows because writes are blocking. */
+ }
else
{
int old_outfd, new_outfd;
for communication with the subprocess, call shutdown to cause EOF.
(In some old system, shutdown to socketpair doesn't work.
Then we just can't win.) */
- if (XPROCESS (proc)->pid == 0
+ if (EQ (XPROCESS (proc)->type, Qnetwork)
|| XPROCESS (proc)->outfd == XPROCESS (proc)->infd)
shutdown (XPROCESS (proc)->outfd, 1);
/* In case of socketpair, outfd == infd, so don't close it. */
if (PROCESSP (proc)
&& (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)))
{
- if (NETCONN_P (proc))
+ if (NETCONN_P (proc) || SERIALCONN_P (proc))
Fdelete_process (proc);
else if (XPROCESS (proc)->infd >= 0)
process_send_signal (proc, SIGHUP, Qnil, 1);
SIGNAL_THREAD_CHECK (signo);
-#ifdef BSD4_1
- extern int sigheld;
- sigheld |= sigbit (SIGCHLD);
-#endif
-
while (1)
{
pid_t pid;
must reestablish each time */
#if defined (USG) && !defined (POSIX_SIGNALS)
signal (signo, sigchld_handler); /* WARNING - must come after wait3() */
-#endif
-#ifdef BSD4_1
- sigheld &= ~sigbit (SIGCHLD);
- sigrelse (SIGCHLD);
#endif
errno = old_errno;
return;
{
proc = XCDR (XCAR (tail));
p = XPROCESS (proc);
- if (EQ (p->childp, Qt) && p->pid == pid)
+ if (EQ (p->type, Qreal) && p->pid == pid)
break;
p = 0;
}
while (! EQ (p->filter, Qt)
&& ! EQ (p->status, Qconnect)
&& ! EQ (p->status, Qlisten)
- && ! EQ (p->command, Qt) /* Network process not stopped. */
+ /* Network or serial process not stopped: */
+ && ! EQ (p->command, Qt)
&& p->infd >= 0
&& p != deleting_process
&& read_process_output (proc, p->infd) > 0);
CHECK_PROCESS (process);
p = XPROCESS (process);
- p->filter_multibyte = !NILP (flag);
+ if (NILP (flag))
+ p->decode_coding_system = raw_text_coding_system (p->decode_coding_system);
setup_process_coding_systems (process);
return Qnil;
Lisp_Object process;
{
register struct Lisp_Process *p;
+ struct coding_system *coding;
CHECK_PROCESS (process);
p = XPROCESS (process);
-
- return (p->filter_multibyte ? Qt : Qnil);
+ coding = proc_decode_coding_system[p->infd];
+ return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt);
}
Qdatagram = intern ("datagram");
staticpro (&Qdatagram);
+ QCport = intern (":port");
+ staticpro (&QCport);
+ QCspeed = intern (":speed");
+ staticpro (&QCspeed);
+ QCprocess = intern (":process");
+ staticpro (&QCprocess);
+
+ QCbytesize = intern (":bytesize");
+ staticpro (&QCbytesize);
+ QCstopbits = intern (":stopbits");
+ staticpro (&QCstopbits);
+ QCparity = intern (":parity");
+ staticpro (&QCparity);
+ Qodd = intern ("odd");
+ staticpro (&Qodd);
+ Qeven = intern ("even");
+ staticpro (&Qeven);
+ QCflowcontrol = intern (":flowcontrol");
+ staticpro (&QCflowcontrol);
+ Qhw = intern ("hw");
+ staticpro (&Qhw);
+ Qsw = intern ("sw");
+ staticpro (&Qsw);
+ QCsummary = intern (":summary");
+ staticpro (&QCsummary);
+
+ Qreal = intern ("real");
+ staticpro (&Qreal);
+ Qnetwork = intern ("network");
+ staticpro (&Qnetwork);
+ Qserial = intern ("serial");
+ staticpro (&Qserial);
+
QCname = intern (":name");
staticpro (&QCname);
QCbuffer = intern (":buffer");
staticpro (&QCoptions);
QCplist = intern (":plist");
staticpro (&QCplist);
- QCfilter_multibyte = intern (":filter-multibyte");
- staticpro (&QCfilter_multibyte);
Qlast_nonmenu_event = intern ("last-nonmenu-event");
staticpro (&Qlast_nonmenu_event);
defsubr (&Slist_processes);
defsubr (&Sprocess_list);
defsubr (&Sstart_process);
+#ifdef HAVE_SERIAL
+ defsubr (&Sserial_process_configure);
+ defsubr (&Smake_serial_process);
+#endif /* HAVE_SERIAL */
#ifdef HAVE_SOCKETS
defsubr (&Sset_network_process_option);
defsubr (&Smake_network_process);
defsubr (&Sprocess_send_eof);
defsubr (&Ssignal_process);
defsubr (&Swaiting_for_user_input_p);
-/* defsubr (&Sprocess_connection); */
+ defsubr (&Sprocess_type);
defsubr (&Sset_process_coding_system);
defsubr (&Sprocess_coding_system);
defsubr (&Sset_process_filter_multibyte);