annotate lisp/mule/mule-process.el @ 207:e45d5e7c476e r20-4b2

Import from CVS: tag r20-4b2
author cvs
date Mon, 13 Aug 2007 10:03:52 +0200
parents acd284d43ca1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
1 ;;; mule-process.el --- Process functions for XEmacs/mule.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
2
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985-1987, 1993, 1994, 1997 Free Software Foundation, Inc.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Ben Wing
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
6
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
7 ;; Author: Ben Wing
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
8 ;; MORIOKA Tomohiko
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
9 ;; Maintainer: XEmacs Development Team
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
10 ;; Keywords: mule, multilingual, coding system, process
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
11
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
12 ;; This file is part of XEmacs.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
13
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
14 ;; XEmacs is free software; you can redistribute it and/or modify it
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
15 ;; under the terms of the GNU General Public License as published by
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
16 ;; the Free Software Foundation; either version 2, or (at your option)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
17 ;; any later version.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
18
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
19 ;; XEmacs is distributed in the hope that it will be useful, but
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
22 ;; General Public License for more details.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
23
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
24 ;; You should have received a copy of the GNU General Public License
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
25 ;; along with XEmacs; see the file COPYING. If not, write to the Free
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
26 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
27 ;; 02111-1307, USA.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
28
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
29 ;;; Code:
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
30
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
31 (defvar process-coding-system-alist nil
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
32 "Alist to decide a coding system to use for a process I/O operation.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
33 The format is ((PATTERN . VAL) ...),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
34 where PATTERN is a regular expression matching a program name,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
35 VAL is a coding system, a cons of coding systems, or a function symbol.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
36 If VAL is a coding system, it is used for both decoding what received
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
37 from the program and encoding what sent to the program.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
38 If VAL is a cons of coding systems, the car part is used for decoding,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
39 and the cdr part is used for encoding.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
40 If VAL is a function symbol, the function must return a coding system
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
41 or a cons of coding systems which are used as above.")
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
42
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
43 (defun call-process (program &optional infile buffer displayp &rest args)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
44 "Call PROGRAM synchronously in separate process.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
45 The program's input comes from file INFILE (nil means `/dev/null').
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
46 Insert output in BUFFER before point; t means current buffer;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
47 nil for BUFFER means discard it; 0 means discard and don't wait.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
48 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
49 REAL-BUFFER says what to do with standard output, as above,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
50 while STDERR-FILE says what to do with standard error in the child.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
51 STDERR-FILE may be nil (discard standard error output),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
52 t (mix it with ordinary output), or a file name string.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
53
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
54 Fourth arg DISPLAYP non-nil means redisplay buffer as output is inserted.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
55 Remaining arguments are strings passed as command arguments to PROGRAM.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
56
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
57 If BUFFER is 0, `call-process' returns immediately with value nil.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
58 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
59 or a signal description string.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
60 If you quit, the process is killed with SIGINT, or SIGKILL if you
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
61 quit again."
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
62 (let* ((coding-system-for-read
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
63 (or coding-system-for-read
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
64 (let (ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
65 (catch 'found
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
66 (let ((alist process-coding-system-alist)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
67 (case-fold-search (eq system-type 'vax-vms)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
68 (while alist
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
69 (if (string-match (car (car alist)) program)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
70 (throw 'found (setq ret (cdr (car alist))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
71 )
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
72 (setq alist (cdr alist))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
73 )))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
74 (if (functionp ret)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
75 (setq ret (funcall ret 'call-process program))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
76 )
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
77 (cond ((consp ret) (car ret))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
78 ((find-coding-system ret) ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
79 )
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
80 ))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
81 (apply 'call-process-internal program infile buffer displayp args)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
82 ))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
83
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
84 (defun call-process-region (start end program
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
85 &optional deletep buffer displayp
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
86 &rest args)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
87 "Send text from START to END to a synchronous process running PROGRAM.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
88 Delete the text if fourth arg DELETEP is non-nil.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
89
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
90 Insert output in BUFFER before point; t means current buffer;
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
91 nil for BUFFER means discard it; 0 means discard and don't wait.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
92 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
93 REAL-BUFFER says what to do with standard output, as above,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
94 while STDERR-FILE says what to do with standard error in the child.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
95 STDERR-FILE may be nil (discard standard error output),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
96 t (mix it with ordinary output), or a file name string.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
97
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
98 Sixth arg DISPLAYP non-nil means redisplay buffer as output is inserted.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
99 Remaining args are passed to PROGRAM at startup as command args.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
100
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
101 If BUFFER is 0, returns immediately with value nil.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
102 Otherwise waits for PROGRAM to terminate
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
103 and returns a numeric exit status or a signal description string.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
104 If you quit, the process is first killed with SIGINT, then with SIGKILL if
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
105 you quit again before the process exits."
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
106 (let ((temp (cond ((eq system-type 'vax-vms)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
107 (make-temp-name "tmp:emacs"))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
108 ((or (eq system-type 'ms-dos)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
109 (eq system-type 'windows-nt))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
110 (make-temp-name
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
111 (concat (file-name-as-directory
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
112 (or (getenv "TMP")
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
113 (getenv "TEMP")
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
114 ""))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
115 "em")))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
116 (t
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
117 (make-temp-name "/tmp/emacs")))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
118 (unwind-protect
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
119 (let (cs-r cs-w)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
120 (let (ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
121 (catch 'found
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
122 (let ((alist process-coding-system-alist)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
123 (case-fold-search (eq system-type 'vax-vms)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
124 (while alist
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
125 (if (string-match (car (car alist)) program)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
126 (throw 'found (setq ret (cdr (car alist)))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
127 (setq alist (cdr alist))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
128 )))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
129 (if (functionp ret)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
130 (setq ret (funcall ret 'call-process-region program)))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
131 (cond ((consp ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
132 (setq cs-r (car ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
133 cs-w (cdr ret)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
134 ((find-coding-system ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
135 (setq cs-r ret
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
136 cs-w ret))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
137 (let ((coding-system-for-read
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
138 (or coding-system-for-read cs-r))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
139 (coding-system-for-write
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
140 (or coding-system-for-write cs-w)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
141 (if (or (eq system-type 'ms-dos)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
142 (eq system-type 'windows-nt))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
143 (let ((buffer-file-type binary-process-output))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
144 (write-region start end temp nil 'silent))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
145 (write-region start end temp nil 'silent))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
146 (if deletep (delete-region start end))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
147 (apply #'call-process program temp buffer displayp args)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
148 (condition-case ()
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
149 (delete-file temp)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
150 (file-error nil)))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
151
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
152 (defun start-process (name buffer program &rest program-args)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
153 "Start a program in a subprocess. Return the process object for it.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
154 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
155 NAME is name for process. It is modified if necessary to make it unique.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
156 BUFFER is the buffer or (buffer-name) to associate with the process.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
157 Process output goes at end of that buffer, unless you specify
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
158 an output stream or filter function to handle the output.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
159 BUFFER may be also nil, meaning that this process is not associated
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
160 with any buffer
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
161 Third arg is program file name. It is searched for as in the shell.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
162 Remaining arguments are strings to give program as arguments.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
163 INCODE and OUTCODE specify the coding-system objects used in input/output
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
164 from/to the process."
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
165 (let (cs-r cs-w)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
166 (let (ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
167 (catch 'found
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
168 (let ((alist process-coding-system-alist)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
169 (case-fold-search (eq system-type 'vax-vms)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
170 (while alist
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
171 (if (string-match (car (car alist)) program)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
172 (throw 'found (setq ret (cdr (car alist)))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
173 (setq alist (cdr alist))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
174 )))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
175 (if (functionp ret)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
176 (setq ret (funcall ret 'start-process program)))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
177 (cond ((consp ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
178 (setq cs-r (car ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
179 cs-w (cdr ret)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
180 ((find-coding-system ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
181 (setq cs-r ret
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
182 cs-w ret))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
183 (let ((coding-system-for-read
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
184 (or coding-system-for-read cs-r))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
185 (coding-system-for-write
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
186 (or coding-system-for-write cs-w)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
187 (apply 'start-process-internal name buffer program program-args)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
188 )))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
189
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
190 (defvar network-coding-system-alist nil
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
191 "Alist to decide a coding system to use for a network I/O operation.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
192 The format is ((PATTERN . VAL) ...),
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
193 where PATTERN is a regular expression matching a network service name
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
194 or is a port number to connect to,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
195 VAL is a coding system, a cons of coding systems, or a function symbol.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
196 If VAL is a coding system, it is used for both decoding what received
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
197 from the network stream and encoding what sent to the network stream.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
198 If VAL is a cons of coding systems, the car part is used for decoding,
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
199 and the cdr part is used for encoding.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
200 If VAL is a function symbol, the function must return a coding system
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
201 or a cons of coding systems which are used as above.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
202
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
203 See also the function `find-operation-coding-system'.")
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
204
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
205 (defun open-network-stream (name buffer host service)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
206 "Open a TCP connection for a service to a host.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
207 Returns a subprocess-object to represent the connection.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
208 Input and output work as for subprocesses; `delete-process' closes it.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
209 Args are NAME BUFFER HOST SERVICE.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
210 NAME is name for process. It is modified if necessary to make it unique.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
211 BUFFER is the buffer (or buffer-name) to associate with the process.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
212 Process output goes at end of that buffer, unless you specify
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
213 an output stream or filter function to handle the output.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
214 BUFFER may be also nil, meaning that this process is not associated
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
215 with any buffer
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
216 Third arg is name of the host to connect to, or its IP address.
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
217 Fourth arg SERVICE is name of the service desired, or an integer
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
218 specifying a port number to connect to."
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
219 (let (cs-r cs-w)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
220 (let (ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
221 (catch 'found
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
222 (let ((alist network-coding-system-alist)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
223 (case-fold-search (eq system-type 'vax-vms))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
224 pattern)
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
225 (while alist
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
226 (setq pattern (car (car alist)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
227 (and
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
228 (cond ((numberp pattern)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
229 (and (numberp service)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
230 (eq pattern service)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
231 ((stringp pattern)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
232 (or (and (stringp service)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
233 (string-match pattern service))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
234 (and (numberp service)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
235 (string-match pattern
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
236 (number-to-string service))))))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
237 (throw 'found (setq ret (cdr (car alist)))))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
238 (setq alist (cdr alist))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
239 )))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
240 (if (functionp ret)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
241 (setq ret (funcall ret 'open-network-stream service)))
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
242 (cond ((consp ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
243 (setq cs-r (car ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
244 cs-w (cdr ret)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
245 ((find-coding-system ret)
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
246 (setq cs-r ret
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
247 cs-w ret))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
248 (let ((coding-system-for-read
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
249 (or coding-system-for-read cs-r))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
250 (coding-system-for-write
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
251 (or coding-system-for-write cs-w)))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
252 (open-network-stream-internal name buffer host service))))
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
253
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents:
diff changeset
254 ;;; mule-process.el ends here