21.4.14 "Reasonable Discussion".
[chise/xemacs-chise.git.1] / lisp / code-process.el
index 7174f97..1b493d5 100644 (file)
@@ -1,6 +1,7 @@
 ;;; code-process.el --- Process coding functions for XEmacs.
 
-;; Copyright (C) 1985-1987, 1993, 1994, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1987, 1993, 1994, 1997, 2003
+;;               Free Software Foundation, Inc.
 ;; Copyright (C) 1995 Ben Wing
 ;; Copyright (C) 1997 MORIOKA Tomohiko
 
@@ -11,8 +12,6 @@
 
 ;; This file is part of XEmacs.
 
-;; This file is very similar to code-process.el
-
 ;; XEmacs 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 2, or (at your option)
 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 ;; 02111-1307, USA.
 
+;;; Commentary:
+
+;; This file has some similarities to code-files.el.
+
 ;;; Code:
 
 (defvar process-coding-system-alist nil
@@ -60,13 +63,18 @@ If BUFFER is 0, `call-process' returns immediately with value nil.
 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status
  or a signal description string.
 If you quit, the process is killed with SIGINT, or SIGKILL if you
- quit again."
+ quit again.
+
+Coding systems are taken from `coding-system-for-read' for input and
+`coding-system-for-write' for output if those variables are bound.
+Otherwise they are looked up in `process-coding-system-alist'.  If not
+found, they default to `nil' for both input and output."
   (let* ((coding-system-for-read
          (or coding-system-for-read
              (let (ret)
                (catch 'found
                  (let ((alist process-coding-system-alist)
-                       (case-fold-search (eq system-type 'vax-vms)))
+                       (case-fold-search nil))
                    (while alist
                      (if (string-match (car (car alist)) program)
                          (throw 'found (setq ret (cdr (car alist))))
@@ -105,26 +113,21 @@ If BUFFER is 0, returns immediately with value nil.
 Otherwise waits for PROGRAM to terminate
 and returns a numeric exit status or a signal description string.
 If you quit, the process is first killed with SIGINT, then with SIGKILL if
-you quit again before the process exits."
-  (let ((temp (cond ((eq system-type 'vax-vms)
-                     (make-temp-name "tmp:emacs"))
-                   ((or (eq system-type 'ms-dos)
-                        (eq system-type 'windows-nt))
-                    (make-temp-name
-                     (concat (file-name-as-directory
-                              (temp-directory))
-                              "em")))
-                    (t
-                    (make-temp-name
-                     (concat (file-name-as-directory
-                              (temp-directory))
-                             "emacs"))))))
+you quit again before the process exits.
+
+Coding systems are taken from `coding-system-for-read' for input and
+`coding-system-for-write' for output if those variables are bound.
+Otherwise they are looked up in `process-coding-system-alist'.  If not
+found, they default to `nil' for both input and output."
+  (let ((temp
+        (make-temp-name
+         (concat (file-name-as-directory (temp-directory)) "emacs"))))
     (unwind-protect
        (let (cs-r cs-w)
          (let (ret)
            (catch 'found
              (let ((alist process-coding-system-alist)
-                   (case-fold-search (eq system-type 'vax-vms)))
+                   (case-fold-search nil))
                (while alist
                  (if (string-match (car (car alist)) program)
                      (throw 'found (setq ret (cdr (car alist)))))
@@ -135,6 +138,9 @@ you quit again before the process exits."
            (cond ((consp ret)
                   (setq cs-r (car ret)
                         cs-w (cdr ret)))
+                 ((null ret)
+                  (setq cs-r buffer-file-coding-system
+                        cs-w buffer-file-coding-system))
                  ((find-coding-system ret)
                   (setq cs-r ret
                         cs-w ret))))
@@ -142,16 +148,10 @@ you quit again before the process exits."
                 (or coding-system-for-read cs-r))
                (coding-system-for-write
                 (or coding-system-for-write cs-w)))
-           (if (or (eq system-type 'ms-dos)
-                   (eq system-type 'windows-nt))
-               (let ((buffer-file-type binary-process-output))
-                 (write-region start end temp nil 'silent))
-             (write-region start end temp nil 'silent))
+           (write-region start end temp nil 'silent)
            (if deletep (delete-region start end))
            (apply #'call-process program temp buffer displayp args)))
-      (condition-case ()
-          (delete-file temp)
-        (file-error nil)))))
+      (ignore-file-errors (delete-file temp)))))
 
 (defun start-process (name buffer program &rest program-args)
   "Start a program in a subprocess.  Return the process object for it.
@@ -164,13 +164,17 @@ BUFFER is the buffer or (buffer-name) to associate with the process.
  with any buffer
 Third arg is program file name.  It is searched for as in the shell.
 Remaining arguments are strings to give program as arguments.
-INCODE and OUTCODE specify the coding-system objects used in input/output
- from/to the process."
+
+Coding systems are taken from `coding-system-for-read' for input and
+`coding-system-for-write' for output if those variables are bound.
+Otherwise they are looked up in `process-coding-system-alist'.  If not
+found, they default to `undecided' for input and `nil' (binary) for
+output."
   (let (cs-r cs-w)
     (let (ret)
       (catch 'found
        (let ((alist process-coding-system-alist)
-             (case-fold-search (eq system-type 'vax-vms)))
+             (case-fold-search nil))
          (while alist
            (if (string-match (car (car alist)) program)
                (throw 'found (setq ret (cdr (car alist)))))
@@ -206,9 +210,9 @@ or a cons of coding systems which are used as above.
 
 See also the function `find-operation-coding-system'.")
 
-(defun open-network-stream (name buffer host service)
+(defun open-network-stream (name buffer host service &optional protocol)
   "Open a TCP connection for a service to a host.
-Returns a subprocess-object to represent the connection.
+Return a process object to represent the connection.
 Input and output work as for subprocesses; `delete-process' closes it.
 Args are NAME BUFFER HOST SERVICE.
 NAME is name for process.  It is modified if necessary to make it unique.
@@ -219,12 +223,22 @@ BUFFER is the buffer (or buffer-name) to associate with the process.
  with any buffer
 Third arg is name of the host to connect to, or its IP address.
 Fourth arg SERVICE is name of the service desired, or an integer
- specifying a port number to connect to."
+ specifying a port number to connect to.
+Fifth argument PROTOCOL is a network protocol.  Currently 'tcp
+ (Transmission Control Protocol) and 'udp (User Datagram Protocol) are
+ supported.  When omitted, 'tcp is assumed.
+
+Output via `process-send-string' and input via buffer or filter (see
+`set-process-filter') are stream-oriented.  That means UDP datagrams are
+not guaranteed to be sent and received in discrete packets. (But small
+datagrams around 500 bytes that are not truncated by `process-send-string'
+are usually fine.)  Note further that UDP protocol does not guard against 
+lost packets."
   (let (cs-r cs-w)
     (let (ret)
       (catch 'found
        (let ((alist network-coding-system-alist)
-             (case-fold-search (eq system-type 'vax-vms))
+             (case-fold-search nil)
              pattern)
          (while alist
            (setq pattern (car (car alist)))
@@ -253,6 +267,6 @@ Fourth arg SERVICE is name of the service desired, or an integer
           (or coding-system-for-read cs-r))
          (coding-system-for-write
           (or coding-system-for-write cs-w)))
-      (open-network-stream-internal name buffer host service))))
+      (open-network-stream-internal name buffer host service protocol))))
 
-;;; mule-process.el ends here
+;;; code-process.el ends here