XEmacs 21.2.28 "Hermes".
[chise/xemacs-chise.git.1] / lisp / process.el
index fb46f35..0c7b46a 100644 (file)
@@ -62,14 +62,10 @@ BUFFER is the buffer or (buffer-name) to associate with the process.
 Third arg is command name, the name of a shell command.
 Remaining arguments are the arguments for the command.
 Wildcards and redirection are handled as usual in the shell."
-  (cond
-   ((eq system-type 'vax-vms)
-    (apply 'start-process name buffer args))
-   ;; We used to use `exec' to replace the shell with the command,
-   ;; but that failed to handle (...) and semicolon, etc.
-   (t
-    (start-process name buffer shell-file-name shell-command-switch
-                  (mapconcat 'identity args " ")))))
+  ;; We used to use `exec' to replace the shell with the command,
+  ;; but that failed to handle (...) and semicolon, etc.
+  (start-process name buffer shell-file-name shell-command-switch
+                (mapconcat #'identity args " ")))
 
 (defun call-process (program &optional infile buffer displayp &rest args)
   "Call PROGRAM synchronously in separate process.
@@ -114,31 +110,15 @@ 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"))))))
+  (let ((temp
+        (make-temp-name
+         (concat (file-name-as-directory (temp-directory)) "emacs"))))
     (unwind-protect
        (progn
-         (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)))))
 
 \f
 (defun shell-command (command &optional output-buffer)
@@ -188,7 +168,7 @@ In either case, the output is inserted after point (leaving mark after it)."
 ;; in the buffer itself.
 (defun shell-command-sentinel (process signal)
   (if (memq (process-status process) '(exit signal))
-      (message "%s: %s." 
+      (message "%s: %s."
               (car (cdr (cdr (process-command process))))
               (substring signal 0 -1))))
 
@@ -245,6 +225,7 @@ In either case, the output is inserted after point (leaving mark after it)."
     (let ((buffer (get-buffer-create
                   (or output-buffer "*Shell Command Output*")))
          (success nil)
+         (exit-status nil)
          (directory default-directory))
       (unwind-protect
          (if (eq buffer (current-buffer))
@@ -254,11 +235,12 @@ In either case, the output is inserted after point (leaving mark after it)."
              (progn (setq buffer-read-only nil)
                     (delete-region (max start end) (point-max))
                     (delete-region (point-min) (max start end))
-                    (call-process-region (point-min) (point-max)
-                                         shell-file-name t t nil
-                                         shell-command-switch command)
+                    (setq exit-status
+                          (call-process-region (point-min) (point-max)
+                                               shell-file-name t t nil
+                                               shell-command-switch command))
                     (setq success t))
-           ;; Clear the output buffer, 
+           ;; Clear the output buffer,
            ;; then run the command with output there.
            (save-excursion
              (set-buffer buffer)
@@ -266,9 +248,10 @@ In either case, the output is inserted after point (leaving mark after it)."
              ;; XEmacs change
              (setq default-directory directory)
              (erase-buffer))
-           (call-process-region start end shell-file-name
-                                nil buffer nil
-                                shell-command-switch command)
+           (setq exit-status
+                 (call-process-region start end shell-file-name
+                                      nil buffer nil
+                                      shell-command-switch command))
            (setq success t))
        ;; Report the amount of output.
        (let ((lines (save-excursion
@@ -280,7 +263,9 @@ In either case, the output is inserted after point (leaving mark after it)."
                 (if success
                     (display-message
                      'command
-                     "(Shell command completed with no output)"))
+                     (if (eql exit-status 0)
+                         "(Shell command succeeded with no output)"
+                       "(Shell command failed with no output)")))
                 (kill-buffer buffer))
                ((and success (= lines 1))
                 (message "%s"
@@ -290,7 +275,7 @@ In either case, the output is inserted after point (leaving mark after it)."
                            (buffer-substring (point)
                                              (progn (end-of-line)
                                                     (point))))))
-               (t 
+               (t
                 (set-window-start (display-buffer buffer) 1))))))))
 
 \f
@@ -307,7 +292,7 @@ Third arg is program file name.  It is searched for as in the shell.
 Remaining arguments are strings to give program as arguments."
   (apply 'start-process-internal name buffer program program-args))
 
-(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.
 Input and output work as for subprocesses; `delete-process' closes it.
@@ -320,33 +305,38 @@ 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."
-  (open-network-stream-internal name buffer host service))
+ 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.
+
+Ouput 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."
+  (open-network-stream-internal name buffer host service protocol))
 
 (defun shell-quote-argument (argument)
   "Quote an argument for passing as argument to an inferior shell."
-  (if (eq system-type 'ms-dos)
-      ;; MS-DOS shells don't have quoting, so don't do any.
-      argument
-    (if (eq system-type 'windows-nt)
-       (concat "\"" argument "\"")
-      ;; Quote everything except POSIX filename characters.
-      ;; This should be safe enough even for really weird shells.
-      (let ((result "") (start 0) end)
-       (while (string-match "[^-0-9a-zA-Z_./]" argument start)
-         (setq end (match-beginning 0)
-               result (concat result (substring argument start end)
-                              "\\" (substring argument end (1+ end)))
-               start (1+ end)))
-       (concat result (substring argument start))))))
-
-(defun exec-to-string (command)
-  "Execute COMMAND as an external process and return the output of that
-process as a string"
-  ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu>
+  (if (eq system-type 'windows-nt)
+      (nt-quote-process-args (list shell-file-name argument))
+    ;; Quote everything except POSIX filename characters.
+    ;; This should be safe enough even for really weird shells.
+    (let ((result "") (start 0) end)
+      (while (string-match "[^-0-9a-zA-Z_./]" argument start)
+       (setq end (match-beginning 0)
+             result (concat result (substring argument start end)
+                            "\\" (substring argument end (1+ end)))
+             start (1+ end)))
+      (concat result (substring argument start)))))
+
+(defun shell-command-to-string (command)
+  "Execute shell command COMMAND and return its output as a string."
   (with-output-to-string
-    (call-process shell-file-name nil t nil "-c" command)))
+    (call-process shell-file-name nil t nil shell-command-switch command)))
 
-(defalias 'shell-command-to-string 'exec-to-string)
+(defalias 'exec-to-string 'shell-command-to-string)
 
 ;;; process.el ends here