comparison src/process.c @ 814:a634e3b7acc8

[xemacs-hg @ 2002-04-14 12:41:59 by ben] latest changes TODO.ben-mule-21-5: Update. make-docfile.c: Add basic support for handling ISO 2022 doc strings -- we parse the basic charset designation sequences so we know whether we're in ASCII and have to pay attention to end quotes and such. Reformat code according to coding standards. abbrev.el: Add `global-abbrev-mode', which turns on or off abbrev-mode in all buffers. Added `defining-abbrev-turns-on-abbrev-mode' -- if non-nil, defining an abbrev through an interactive function will automatically turn on abbrev-mode, either globally or locally depending on the command. This is the "what you'd expect" behavior. indent.el: general function for indenting a balanced expression in a mode-correct way. Works similar to indent-region in that a mode can specify a specific command to do the whole operation; if not, figure out the region using forward-sexp and indent each line using indent-according-to-mode. keydefs.el: Removed. Modify M-C-backslash to do indent-region-or-balanced-expression. Make S-Tab just insert a TAB char, like it's meant to do. make-docfile.el: Now that we're using the call-process-in-lisp, we need to load an extra file win32-native.el because we're running a bare temacs. menubar-items.el: Totally redo the Cmds menu so that most used commands appear directly on the menu and less used commands appear in submenus. The old way may have been very pretty, but rather impractical. process.el: Under Windows, don't ever use old-call-process-internal, even in batch mode. We can do processes in batch mode. subr.el: Someone recoded truncate-string-to-width, saying "the FSF version is too complicated and does lots of hard-to-understand stuff" but the resulting recoded version was *totally* wrong! it misunderstood the basic point of this function, which is work in *columns* not chars. i dumped ours and copied the version from FSF 21.1. Also added truncate-string-with-continuation-dots, since this idiom is used often. config.inc.samp, xemacs.mak: Separate out debug and optimize flags. Remove all vestiges of USE_MINIMAL_TAGBITS, USE_INDEXED_LRECORD_IMPLEMENTATION, and GUNG_HO, since those ifdefs have long been removed. Make error-checking support actually work. Some rearrangement of config.inc.samp to make it more logical. Remove callproc.c and ntproc.c from xemacs.mak, no longer used. Make pdump the default. lisp.h: Add support for strong type-checking of Bytecount, Bytebpos, Charcount, Charbpos, and others, by making them classes, overloading the operators to provide integer-like operation and carefully controlling what operations are allowed. Not currently enabled in C++ builds because there are still a number of compile errors, and it won't really work till we merge in my "8-bit-Mule" workspace, in which I make use of the new types Charxpos, Bytexpos, Memxpos, representing a "position" either in a buffer or a string. (This is especially important in the extent code.) abbrev.c, alloc.c, eval.c, buffer.c, buffer.h, editfns.c, fns.c, text.h: Warning fixes, some of them related to new C++ strict type checking of Bytecount, Charbpos, etc. dired.c: Caught an actual error due to strong type checking -- char len being passed when should be byte len. alloc.c, backtrace.h, bytecode.c, bytecode.h, eval.c, sysdep.c: Further optimize Ffuncall: -- process arg list at compiled-function creation time, converting into an array for extra-quick access at funcall time. -- rewrite funcall_compiled_function to use it, and inline this function. -- change the order of check for magic stuff in SPECBIND_FAST_UNSAFE to be faster. -- move the check for need to garbage collect into the allocation code, so only a single flag needs to be checked in funcall. buffer.c, symbols.c: add debug funs to check on mule optimization info in buffers and strings. eval.c, emacs.c, text.c, regex.c, scrollbar-msw.c, search.c: Fix evil crashes due to eistrings not properly reinitialized under pdump. Redo a bit some of the init routines; convert some complex_vars_of() into simple vars_of(), because they didn't need complex processing. callproc.c, emacs.c, event-stream.c, nt.c, process.c, process.h, sysdep.c, sysdep.h, syssignal.h, syswindows.h, ntproc.c: Delete. Hallelujah, praise the Lord, there is no god but Allah!!! fix so that processes can be invoked in bare temacs -- thereby eliminating any need for callproc.c. (currently only eliminated under NT.) remove all crufty and unnecessary old process code in ntproc.c and elsewhere. move non-callproc-specific stuff (mostly environment) into process.c, so callproc.c can be left out under NT. console-tty.c, doc.c, file-coding.c, file-coding.h, lstream.c, lstream.h: fix doc string handling so it works with Japanese, etc docs. change handling of "character mode" so callers don't have to manually set it (quite error-prone). event-msw.c: spacing fixes. lread.c: eliminate unused crufty vintage-19 "FSF defun hack" code. lrecord.h: improve pdump description docs. buffer.c, ntheap.c, unexnt.c, win32.c, emacs.c: Mule-ize some unexec and startup code. It was pseudo-Mule-ized before by simply always calling the ...A versions of functions, but that won't cut it -- eventually we want to be able to run properly even if XEmacs has been installed in a Japanese directory. (The current problem is the timing of the loading of the Unicode tables; this will eventually be fixed.) Go through and fix various other places where the code was not Mule-clean. Provide a function mswindows_get_module_file_name() to get our own name without resort to PATH_MAX and such. Add a big comment in main() about the problem with Unicode table load timing that I just alluded to. emacs.c: When error-checking is enabled (interpreted as "user is developing XEmacs"), don't ask user to "pause to read messages" when a fatal error has occurred, because it will wedge if we are in an inner modal loop (typically when a menu is popped up) and make us unable to get a useful stack trace in the debugger. text.c: Correct update_entirely_ascii_p_flag to actually work. lisp.h, symsinit.h: declarations for above changes.
author ben
date Sun, 14 Apr 2002 12:43:31 +0000
parents 2b676dc88c66
children 39b1580316c8
comparison
equal deleted inserted replaced
813:9541922fb765 814:a634e3b7acc8
19 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
20 along with XEmacs; see the file COPYING. If not, write to 20 along with XEmacs; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */ 22 Boston, MA 02111-1307, USA. */
23 23
24 /* This file has been Mule-ized except for `start-process-internal', 24 /* This file has been Mule-ized. */
25 `open-network-stream-internal' and `open-multicast-group-internal'. */
26 25
27 /* This file has been split into process.c and process-unix.c by 26 /* This file has been split into process.c and process-unix.c by
28 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not 27 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not
29 the original author(s) */ 28 the original author(s).
29
30 Non-synch-subprocess stuff (mostly process environment) moved from
31 callproc.c, 4-3-02, Ben Wing. */
30 32
31 #include <config.h> 33 #include <config.h>
32 34
33 #if !defined (NO_SUBPROCESSES) 35 #if defined (NO_SUBPROCESSES)
34 36 #error "We don't support this anymore."
35 /* The entire file is within this conditional */ 37 #endif
36 38
37 #include "lisp.h" 39 #include "lisp.h"
38 40
39 #include "buffer.h" 41 #include "buffer.h"
40 #include "commands.h" 42 #include "commands.h"
50 #include "procimpl.h" 52 #include "procimpl.h"
51 #include "window.h" 53 #include "window.h"
52 54
53 #include "sysfile.h" 55 #include "sysfile.h"
54 #include "sysproc.h" 56 #include "sysproc.h"
57 #include "syssignal.h"
55 #include "systime.h" 58 #include "systime.h"
56 #include "syssignal.h" /* Always include before systty.h */
57 #include "systty.h" 59 #include "systty.h"
58 #include "syswait.h" 60 #include "syswait.h"
59 61
60 Lisp_Object Qprocessp, Qprocess_live_p; 62 Lisp_Object Qprocessp, Qprocess_live_p;
61 63
103 struct hash_table *usid_to_process; 105 struct hash_table *usid_to_process;
104 106
105 /* List of process objects. */ 107 /* List of process objects. */
106 Lisp_Object Vprocess_list; 108 Lisp_Object Vprocess_list;
107 109
108 extern Lisp_Object Vlisp_EXEC_SUFFIXES;
109 Lisp_Object Vnull_device; 110 Lisp_Object Vnull_device;
110 111
111 /* Cons of coding systems used to initialize process I/O on a newly- 112 /* Cons of coding systems used to initialize process I/O on a newly-
112 created process. */ 113 created process. */
113 Lisp_Object Vdefault_process_coding_system; 114 Lisp_Object Vdefault_process_coding_system;
114 115
115 Lisp_Object Qprocess_error; 116 Lisp_Object Qprocess_error;
116 Lisp_Object Qnetwork_error; 117 Lisp_Object Qnetwork_error;
117 118
118 Fixnum debug_process_io; 119 Fixnum debug_process_io;
120
121 Lisp_Object Vshell_file_name;
122
123 /* The environment to pass to all subprocesses when they are started.
124 This is in the semi-bogus format of ("VAR=VAL" "VAR2=VAL2" ... )
125 */
126 Lisp_Object Vprocess_environment;
127
128 /* Make sure egetenv() not called too soon */
129 int env_initted;
130
131 Lisp_Object Vlisp_EXEC_SUFFIXES;
119 132
120 133
121 134
122 static Lisp_Object 135 static Lisp_Object
123 mark_process (Lisp_Object object) 136 mark_process (Lisp_Object object)
525 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, flags)); 538 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, flags));
526 539
527 p->coding_instream = 540 p->coding_instream =
528 make_coding_input_stream (XLSTREAM (p->pipe_instream), incode, 541 make_coding_input_stream (XLSTREAM (p->pipe_instream), incode,
529 CODING_DECODE, 0); 542 CODING_DECODE, 0);
530 Lstream_set_character_mode (XLSTREAM (p->coding_instream));
531 p->coding_outstream = 543 p->coding_outstream =
532 make_coding_output_stream (XLSTREAM (p->pipe_outstream), outcode, 544 make_coding_output_stream (XLSTREAM (p->pipe_outstream), outcode,
533 CODING_ENCODE, 0); 545 CODING_ENCODE, 0);
534 } 546 }
535 547
581 from/to the process. 593 from/to the process.
582 */ 594 */
583 (int nargs, Lisp_Object *args)) 595 (int nargs, Lisp_Object *args))
584 { 596 {
585 /* This function can call lisp */ 597 /* This function can call lisp */
586 /* !!#### This function has not been Mule-ized */
587 Lisp_Object buffer, name, program, process, current_dir; 598 Lisp_Object buffer, name, program, process, current_dir;
588 Lisp_Object tem; 599 Lisp_Object tem;
589 int speccount = specpdl_depth (); 600 int speccount = specpdl_depth ();
590 struct gcpro gcpro1, gcpro2, gcpro3; 601 struct gcpro gcpro1, gcpro2, gcpro3;
591 602
663 program); 674 program);
664 675
665 process = make_process_internal (name); 676 process = make_process_internal (name);
666 677
667 XPROCESS (process)->buffer = buffer; 678 XPROCESS (process)->buffer = buffer;
668 XPROCESS (process)->command = Flist (nargs - 2, 679 XPROCESS (process)->command = Flist (nargs - 2, args + 2);
669 args + 2);
670 680
671 /* Make the process marker point into the process buffer (if any). */ 681 /* Make the process marker point into the process buffer (if any). */
672 if (!NILP (buffer)) 682 if (!NILP (buffer))
673 Fset_marker (XPROCESS (process)->mark, 683 Fset_marker (XPROCESS (process)->mark,
674 make_int (BUF_ZV (XBUFFER (buffer))), buffer); 684 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
2046 { 2056 {
2047 CHECK_PROCESS (process); 2057 CHECK_PROCESS (process);
2048 return XPROCESS (process)->kill_without_query ? Qt : Qnil; 2058 return XPROCESS (process)->kill_without_query ? Qt : Qnil;
2049 } 2059 }
2050 2060
2061
2062 #if 0
2063
2064 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
2065 Return the connection type of `PROCESS'. This can be nil (pipe),
2066 t or pty (pty) or stream (socket connection).
2067 */
2068 (process))
2069 {
2070 return XPROCESS (process)->type;
2071 }
2072
2073 #endif /* 0 */
2074
2075
2076 static int
2077 getenv_internal (const Intbyte *var,
2078 Bytecount varlen,
2079 Intbyte **value,
2080 Bytecount *valuelen)
2081 {
2082 Lisp_Object scan;
2083
2084 assert (env_initted);
2085
2086 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
2087 {
2088 Lisp_Object entry = XCAR (scan);
2089
2090 if (STRINGP (entry)
2091 && XSTRING_LENGTH (entry) > varlen
2092 && XSTRING_BYTE (entry, varlen) == '='
2093 #ifdef WIN32_NATIVE
2094 /* NT environment variables are case insensitive. */
2095 && ! memicmp (XSTRING_DATA (entry), var, varlen)
2096 #else /* not WIN32_NATIVE */
2097 && ! memcmp (XSTRING_DATA (entry), var, varlen)
2098 #endif /* not WIN32_NATIVE */
2099 )
2100 {
2101 *value = XSTRING_DATA (entry) + (varlen + 1);
2102 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
2103 return 1;
2104 }
2105 }
2106
2107 return 0;
2108 }
2109
2110 static void
2111 putenv_internal (const Intbyte *var,
2112 Bytecount varlen,
2113 const Intbyte *value,
2114 Bytecount valuelen)
2115 {
2116 Lisp_Object scan;
2117
2118 assert (env_initted);
2119
2120 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
2121 {
2122 Lisp_Object entry = XCAR (scan);
2123
2124 if (STRINGP (entry)
2125 && XSTRING_LENGTH (entry) > varlen
2126 && XSTRING_BYTE (entry, varlen) == '='
2127 #ifdef WIN32_NATIVE
2128 /* NT environment variables are case insensitive. */
2129 && ! memicmp (XSTRING_DATA (entry), var, varlen)
2130 #else /* not WIN32_NATIVE */
2131 && ! memcmp (XSTRING_DATA (entry), var, varlen)
2132 #endif /* not WIN32_NATIVE */
2133 )
2134 {
2135 XCAR (scan) = concat3 (make_string (var, varlen),
2136 build_string ("="),
2137 make_string (value, valuelen));
2138 return;
2139 }
2140 }
2141
2142 Vprocess_environment = Fcons (concat3 (make_string (var, varlen),
2143 build_string ("="),
2144 make_string (value, valuelen)),
2145 Vprocess_environment);
2146 }
2147
2148 /* NOTE:
2149
2150 FSF has this as a Lisp function, as follows. Generally moving things
2151 out of C and into Lisp is a good idea, but in this case the Lisp
2152 function is used so early in the startup sequence that it would be ugly
2153 to rearrange the early dumped code to accommodate this.
2154
2155 (defun getenv (variable)
2156 "Get the value of environment variable VARIABLE.
2157 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
2158 the environment. Otherwise, value is a string.
2159
2160 This function consults the variable `process-environment'
2161 for its value."
2162 (interactive (list (read-envvar-name "Get environment variable: " t)))
2163 (let ((value (getenv-internal variable)))
2164 (when (interactive-p)
2165 (message "%s" (if value value "Not set")))
2166 value))
2167 */
2168
2169 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
2170 Return the value of environment variable VAR, as a string.
2171 VAR is a string, the name of the variable.
2172 When invoked interactively, prints the value in the echo area.
2173 */
2174 (var, interactivep))
2175 {
2176 Intbyte *value;
2177 Bytecount valuelen;
2178 Lisp_Object v = Qnil;
2179 struct gcpro gcpro1;
2180
2181 CHECK_STRING (var);
2182 GCPRO1 (v);
2183 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
2184 &value, &valuelen))
2185 v = make_string (value, valuelen);
2186 if (!NILP (interactivep))
2187 {
2188 if (NILP (v))
2189 message ("%s not defined in environment", XSTRING_DATA (var));
2190 else
2191 /* #### Should use Fprin1_to_string or Fprin1 to handle string
2192 containing quotes correctly. */
2193 message ("\"%s\"", value);
2194 }
2195 RETURN_UNGCPRO (v);
2196 }
2197
2198 /* A version of getenv that consults Vprocess_environment, easily
2199 callable from C.
2200
2201 (At init time, Vprocess_environment is initialized from the
2202 environment, stored in the global variable environ. [Note that
2203 at startup time, `environ' should be the same as the envp parameter
2204 passed to main(); however, later calls to putenv() may change
2205 `environ', making the envp parameter inaccurate.] Calls to getenv()
2206 and putenv() consult and modify `environ'. However, once
2207 Vprocess_environment is initted, XEmacs C code should *NEVER* call
2208 getenv() or putenv() directly, because (1) Lisp code that modifies
2209 the environment only modifies Vprocess_environment, not `environ';
2210 and (2) Vprocess_environment is in internal format but `environ'
2211 is in some external format, and getenv()/putenv() are not Mule-
2212 encapsulated.
2213
2214 WARNING: This value points into Lisp string data and thus will become
2215 invalid after a GC. */
2216
2217 Intbyte *
2218 egetenv (const CIntbyte *var)
2219 {
2220 /* This cannot GC -- 7-28-00 ben */
2221 Intbyte *value;
2222 Bytecount valuelen;
2223
2224 if (getenv_internal ((const Intbyte *) var, strlen (var), &value, &valuelen))
2225 return value;
2226 else
2227 return 0;
2228 }
2229
2230 void
2231 eputenv (const CIntbyte *var, const CIntbyte *value)
2232 {
2233 putenv_internal ((Intbyte *) var, strlen (var), (Intbyte *) value,
2234 strlen (value));
2235 }
2236
2051 2237
2052 /* This is not named init_process in order to avoid a conflict with NS 3.3 */ 2238 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
2053 void 2239 void
2054 init_xemacs_process (void) 2240 init_xemacs_process (void)
2055 { 2241 {
2242 /* This function can GC */
2243
2056 MAYBE_PROCMETH (init_process, ()); 2244 MAYBE_PROCMETH (init_process, ());
2057 2245
2058 Vprocess_list = Qnil; 2246 Vprocess_list = Qnil;
2059 2247
2060 if (usid_to_process) 2248 if (usid_to_process)
2061 clrhash (usid_to_process); 2249 clrhash (usid_to_process);
2062 else 2250 else
2063 usid_to_process = make_hash_table (32); 2251 usid_to_process = make_hash_table (32);
2064 } 2252
2065 2253 {
2066 #if 0 2254 /* jwz: always initialize Vprocess_environment, so that egetenv()
2067 2255 works in temacs. */
2068 xxDEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /* 2256 char **envp;
2069 Return the connection type of `PROCESS'. This can be nil (pipe), 2257 Vprocess_environment = Qnil;
2070 t or pty (pty) or stream (socket connection). 2258 for (envp = environ; envp && *envp; envp++)
2071 */ 2259 Vprocess_environment =
2072 (process)) 2260 Fcons (build_ext_string (*envp, Qnative), Vprocess_environment);
2073 { 2261 /* This gets set back to 0 in disksave_object_finalization() */
2074 return XPROCESS (process)->type; 2262 env_initted = 1;
2075 } 2263 }
2076 2264
2265 {
2266 /* Initialize shell-file-name from environment variables or best guess. */
2267 #ifdef WIN32_NATIVE
2268 const Intbyte *shell = egetenv ("SHELL");
2269 if (!shell) shell = egetenv ("COMSPEC");
2270 /* Should never happen! */
2271 if (!shell) shell =
2272 (Intbyte *) (GetVersion () & 0x80000000 ? "command" : "cmd");
2273 #else /* not WIN32_NATIVE */
2274 const Intbyte *shell = egetenv ("SHELL");
2275 if (!shell) shell = (Intbyte *) "/bin/sh";
2276 #endif
2277
2278 #if 0 /* defined (WIN32_NATIVE) */
2279 /* BAD BAD BAD. We do not wanting to be passing an XEmacs-created
2280 SHELL var down to some inferior Cygwin process, which might get
2281 screwed up.
2282
2283 There are a few broken apps (eterm/term.el, eterm/tshell.el,
2284 os-utils/terminal.el, texinfo/tex-mode.el) where this will
2285 cause problems. Those broken apps don't look at
2286 shell-file-name, instead just at explicit-shell-file-name,
2287 ESHELL and SHELL. They are apparently attempting to borrow
2288 what `M-x shell' uses, but that latter also looks at
2289 shell-file-name. What we want is for all of these apps to look
2290 at shell-file-name, so that the user can change the value of
2291 shell-file-name and everything will work out hunky-dorey.
2292 */
2293
2294 if (!egetenv ("SHELL"))
2295 {
2296 Intbyte *faux_var = alloca_array (Intbyte, 7 + qxestrlen (shell));
2297 qxesprintf (faux_var, "SHELL=%s", shell);
2298 Vprocess_environment = Fcons (build_intstring (faux_var),
2299 Vprocess_environment);
2300 }
2077 #endif /* 0 */ 2301 #endif /* 0 */
2302
2303 Vshell_file_name = build_intstring (shell);
2304 }
2305 }
2078 2306
2079 void 2307 void
2080 syms_of_process (void) 2308 syms_of_process (void)
2081 { 2309 {
2082 INIT_LRECORD_IMPLEMENTATION (process); 2310 INIT_LRECORD_IMPLEMENTATION (process);
2142 DEFSUBR (Fprocess_output_coding_system); 2370 DEFSUBR (Fprocess_output_coding_system);
2143 DEFSUBR (Fset_process_input_coding_system); 2371 DEFSUBR (Fset_process_input_coding_system);
2144 DEFSUBR (Fset_process_output_coding_system); 2372 DEFSUBR (Fset_process_output_coding_system);
2145 DEFSUBR (Fprocess_coding_system); 2373 DEFSUBR (Fprocess_coding_system);
2146 DEFSUBR (Fset_process_coding_system); 2374 DEFSUBR (Fset_process_coding_system);
2375 DEFSUBR (Fgetenv);
2147 } 2376 }
2148 2377
2149 void 2378 void
2150 vars_of_process (void) 2379 vars_of_process (void)
2151 { 2380 {
2230 Nil value means to set a default(non-blocking) I/O mode. 2459 Nil value means to set a default(non-blocking) I/O mode.
2231 The value takes effect when `open-network-stream-internal' is called. 2460 The value takes effect when `open-network-stream-internal' is called.
2232 */ ); 2461 */ );
2233 network_stream_blocking_port_list = Qnil; 2462 network_stream_blocking_port_list = Qnil;
2234 #endif /* PROCESS_IO_BLOCKING */ 2463 #endif /* PROCESS_IO_BLOCKING */
2235 } 2464
2236 2465 /* This function can GC */
2237 #endif /* not NO_SUBPROCESSES */ 2466 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
2467 *File name to load inferior shells from.
2468 Initialized from the SHELL environment variable.
2469 */ );
2470
2471 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
2472 List of environment variables for subprocesses to inherit.
2473 Each element should be a string of the form ENVVARNAME=VALUE.
2474 The environment which Emacs inherits is placed in this variable
2475 when Emacs starts.
2476 */ );
2477
2478 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES);
2479 staticpro (&Vlisp_EXEC_SUFFIXES);
2480 }