annotate lisp/code-process.el @ 424:11054d720c21 r21-2-20

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