(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
[emacs.git] / src / callproc.c
blobbf2fabcc75004e80b6674a5b695e395861d3b66f
1 /* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985,86,87,88,93,94,95,99,2000 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <config.h>
23 #include <signal.h>
24 #include <errno.h>
25 #include <stdio.h>
27 #ifndef USE_CRT_DLL
28 extern int errno;
29 #endif
31 /* Define SIGCHLD as an alias for SIGCLD. */
33 #if !defined (SIGCHLD) && defined (SIGCLD)
34 #define SIGCHLD SIGCLD
35 #endif /* SIGCLD */
37 #include <sys/types.h>
39 #ifdef HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
43 #include <sys/file.h>
44 #ifdef USG5
45 #define INCLUDED_FCNTL
46 #include <fcntl.h>
47 #endif
49 #ifdef WINDOWSNT
50 #define NOMINMAX
51 #include <windows.h>
52 #include <stdlib.h> /* for proper declaration of environ */
53 #include <fcntl.h>
54 #include "w32.h"
55 #define _P_NOWAIT 1 /* from process.h */
56 #endif
58 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
59 #define INCLUDED_FCNTL
60 #include <fcntl.h>
61 #include <sys/stat.h>
62 #include <sys/param.h>
63 #include <errno.h>
64 #endif /* MSDOS */
66 #ifndef O_RDONLY
67 #define O_RDONLY 0
68 #endif
70 #ifndef O_WRONLY
71 #define O_WRONLY 1
72 #endif
74 #include "lisp.h"
75 #include "commands.h"
76 #include "buffer.h"
77 #include "charset.h"
78 #include "ccl.h"
79 #include "coding.h"
80 #include "composite.h"
81 #include <epaths.h>
82 #include "process.h"
83 #include "syssignal.h"
84 #include "systty.h"
86 #ifdef MSDOS
87 #include "msdos.h"
88 #endif
90 #ifdef VMS
91 extern noshare char **environ;
92 #else
93 #ifndef USE_CRT_DLL
94 extern char **environ;
95 #endif
96 #endif
98 #ifdef HAVE_SETPGID
99 #if !defined (USG) || defined (BSD_PGRPS)
100 #undef setpgrp
101 #define setpgrp setpgid
102 #endif
103 #endif
105 #define max(a, b) ((a) > (b) ? (a) : (b))
107 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory, Vdoc_directory;
108 Lisp_Object Vconfigure_info_directory;
109 Lisp_Object Vtemp_file_name_pattern;
111 Lisp_Object Vshell_file_name;
113 Lisp_Object Vprocess_environment;
115 #ifdef DOS_NT
116 Lisp_Object Qbuffer_file_type;
117 #endif /* DOS_NT */
119 /* True iff we are about to fork off a synchronous process or if we
120 are waiting for it. */
121 int synch_process_alive;
123 /* Nonzero => this is a string explaining death of synchronous subprocess. */
124 char *synch_process_death;
126 /* If synch_process_death is zero,
127 this is exit code of synchronous subprocess. */
128 int synch_process_retcode;
130 extern Lisp_Object Vdoc_file_name;
132 extern Lisp_Object Vfile_name_coding_system, Vdefault_file_name_coding_system;
134 /* Clean up when exiting Fcall_process.
135 On MSDOS, delete the temporary file on any kind of termination.
136 On Unix, kill the process and any children on termination by signal. */
138 /* Nonzero if this is termination due to exit. */
139 static int call_process_exited;
141 #ifndef VMS /* VMS version is in vmsproc.c. */
143 static Lisp_Object
144 call_process_kill (fdpid)
145 Lisp_Object fdpid;
147 emacs_close (XFASTINT (Fcar (fdpid)));
148 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL);
149 synch_process_alive = 0;
150 return Qnil;
153 Lisp_Object
154 call_process_cleanup (fdpid)
155 Lisp_Object fdpid;
157 #if defined (MSDOS) || defined (macintosh)
158 /* for MSDOS fdpid is really (fd . tempfile) */
159 register Lisp_Object file;
160 file = Fcdr (fdpid);
161 emacs_close (XFASTINT (Fcar (fdpid)));
162 if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0)
163 unlink (XSTRING (file)->data);
164 #else /* not MSDOS and not macintosh */
165 register int pid = XFASTINT (Fcdr (fdpid));
167 if (call_process_exited)
169 emacs_close (XFASTINT (Fcar (fdpid)));
170 return Qnil;
173 if (EMACS_KILLPG (pid, SIGINT) == 0)
175 int count = specpdl_ptr - specpdl;
176 record_unwind_protect (call_process_kill, fdpid);
177 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
178 immediate_quit = 1;
179 QUIT;
180 wait_for_termination (pid);
181 immediate_quit = 0;
182 specpdl_ptr = specpdl + count; /* Discard the unwind protect. */
183 message1 ("Waiting for process to die...done");
185 synch_process_alive = 0;
186 emacs_close (XFASTINT (Fcar (fdpid)));
187 #endif /* not MSDOS */
188 return Qnil;
191 DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
192 "Call PROGRAM synchronously in separate process.\n\
193 The remaining arguments are optional.\n\
194 The program's input comes from file INFILE (nil means `/dev/null').\n\
195 Insert output in BUFFER before point; t means current buffer;\n\
196 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
197 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
198 REAL-BUFFER says what to do with standard output, as above,\n\
199 while STDERR-FILE says what to do with standard error in the child.\n\
200 STDERR-FILE may be nil (discard standard error output),\n\
201 t (mix it with ordinary output), or a file name string.\n\
203 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
204 Remaining arguments are strings passed as command arguments to PROGRAM.\n\
206 If BUFFER is 0, `call-process' returns immediately with value nil.\n\
207 Otherwise it waits for PROGRAM to terminate\n\
208 and returns a numeric exit status or a signal description string.\n\
209 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
210 (nargs, args)
211 int nargs;
212 register Lisp_Object *args;
214 Lisp_Object infile, buffer, current_dir, display, path;
215 int fd[2];
216 int filefd;
217 register int pid;
218 char buf[16384];
219 char *bufptr = buf;
220 int bufsize = 16384;
221 int count = specpdl_ptr - specpdl;
223 register unsigned char **new_argv
224 = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *));
225 struct buffer *old = current_buffer;
226 /* File to use for stderr in the child.
227 t means use same as standard output. */
228 Lisp_Object error_file;
229 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
230 char *outf, *tempfile;
231 int outfilefd;
232 #endif
233 #ifdef macintosh
234 char *tempfile;
235 int outfilefd;
236 #endif
237 #if 0
238 int mask;
239 #endif
240 struct coding_system process_coding; /* coding-system of process output */
241 struct coding_system argument_coding; /* coding-system of arguments */
242 /* Set to the return value of Ffind_operation_coding_system. */
243 Lisp_Object coding_systems;
245 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
246 coding_systems = Qt;
248 CHECK_STRING (args[0], 0);
250 error_file = Qt;
252 #ifndef subprocesses
253 /* Without asynchronous processes we cannot have BUFFER == 0. */
254 if (nargs >= 3
255 && (INTEGERP (CONSP (args[2]) ? XCAR (args[2]) : args[2])))
256 error ("Operating system cannot handle asynchronous subprocesses");
257 #endif /* subprocesses */
259 /* Decide the coding-system for giving arguments. */
261 Lisp_Object val, *args2;
262 int i;
264 /* If arguments are supplied, we may have to encode them. */
265 if (nargs >= 5)
267 int must_encode = 0;
269 for (i = 4; i < nargs; i++)
270 CHECK_STRING (args[i], i);
272 for (i = 4; i < nargs; i++)
273 if (STRING_MULTIBYTE (args[i]))
274 must_encode = 1;
276 if (!NILP (Vcoding_system_for_write))
277 val = Vcoding_system_for_write;
278 else if (! must_encode)
279 val = Qnil;
280 else
282 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
283 args2[0] = Qcall_process;
284 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
285 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
286 if (CONSP (coding_systems))
287 val = XCDR (coding_systems);
288 else if (CONSP (Vdefault_process_coding_system))
289 val = XCDR (Vdefault_process_coding_system);
290 else
291 val = Qnil;
293 setup_coding_system (Fcheck_coding_system (val), &argument_coding);
297 if (nargs >= 2 && ! NILP (args[1]))
299 infile = Fexpand_file_name (args[1], current_buffer->directory);
300 CHECK_STRING (infile, 1);
302 else
303 infile = build_string (NULL_DEVICE);
305 if (nargs >= 3)
307 buffer = args[2];
309 /* If BUFFER is a list, its meaning is
310 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
311 if (CONSP (buffer))
313 if (CONSP (XCDR (buffer)))
315 Lisp_Object stderr_file;
316 stderr_file = XCAR (XCDR (buffer));
318 if (NILP (stderr_file) || EQ (Qt, stderr_file))
319 error_file = stderr_file;
320 else
321 error_file = Fexpand_file_name (stderr_file, Qnil);
324 buffer = XCAR (buffer);
327 if (!(EQ (buffer, Qnil)
328 || EQ (buffer, Qt)
329 || INTEGERP (buffer)))
331 Lisp_Object spec_buffer;
332 spec_buffer = buffer;
333 buffer = Fget_buffer_create (buffer);
334 /* Mention the buffer name for a better error message. */
335 if (NILP (buffer))
336 CHECK_BUFFER (spec_buffer, 2);
337 CHECK_BUFFER (buffer, 2);
340 else
341 buffer = Qnil;
343 /* Make sure that the child will be able to chdir to the current
344 buffer's current directory, or its unhandled equivalent. We
345 can't just have the child check for an error when it does the
346 chdir, since it's in a vfork.
348 We have to GCPRO around this because Fexpand_file_name,
349 Funhandled_file_name_directory, and Ffile_accessible_directory_p
350 might call a file name handling function. The argument list is
351 protected by the caller, so all we really have to worry about is
352 buffer. */
354 struct gcpro gcpro1, gcpro2, gcpro3;
356 current_dir = current_buffer->directory;
358 GCPRO3 (infile, buffer, current_dir);
360 current_dir
361 = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
362 Qnil);
363 if (NILP (Ffile_accessible_directory_p (current_dir)))
364 report_file_error ("Setting current directory",
365 Fcons (current_buffer->directory, Qnil));
367 UNGCPRO;
370 display = nargs >= 4 ? args[3] : Qnil;
372 filefd = emacs_open (XSTRING (infile)->data, O_RDONLY, 0);
373 if (filefd < 0)
375 report_file_error ("Opening process input file", Fcons (infile, Qnil));
377 /* Search for program; barf if not found. */
379 struct gcpro gcpro1;
381 GCPRO1 (current_dir);
382 openp (Vexec_path, args[0], EXEC_SUFFIXES, &path, 1);
383 UNGCPRO;
385 if (NILP (path))
387 emacs_close (filefd);
388 report_file_error ("Searching for program", Fcons (args[0], Qnil));
390 new_argv[0] = XSTRING (path)->data;
391 if (nargs > 4)
393 register int i;
394 struct gcpro gcpro1, gcpro2, gcpro3;
396 GCPRO3 (infile, buffer, current_dir);
397 argument_coding.dst_multibyte = 0;
398 for (i = 4; i < nargs; i++)
400 argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
401 if (CODING_REQUIRE_ENCODING (&argument_coding))
403 /* We must encode this argument. */
404 args[i] = encode_coding_string (args[i], &argument_coding, 1);
405 if (argument_coding.type == coding_type_ccl)
406 setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil);
408 new_argv[i - 3] = XSTRING (args[i])->data;
410 UNGCPRO;
411 new_argv[nargs - 3] = 0;
413 else
414 new_argv[1] = 0;
416 #ifdef MSDOS /* MW, July 1993 */
417 if ((outf = egetenv ("TMPDIR")))
418 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
419 else
421 tempfile = alloca (20);
422 *tempfile = '\0';
424 dostounix_filename (tempfile);
425 if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
426 strcat (tempfile, "/");
427 strcat (tempfile, "detmp.XXX");
428 mktemp (tempfile);
430 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
431 if (outfilefd < 0)
433 emacs_close (filefd);
434 report_file_error ("Opening process output file",
435 Fcons (build_string (tempfile), Qnil));
437 fd[0] = filefd;
438 fd[1] = outfilefd;
439 #endif /* MSDOS */
441 #ifdef macintosh
442 /* Since we don't have pipes on the Mac, create a temporary file to
443 hold the output of the subprocess. */
444 tempfile = (char *) alloca (STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
445 bcopy (XSTRING (Vtemp_file_name_pattern)->data, tempfile,
446 STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
448 mktemp (tempfile);
450 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
451 if (outfilefd < 0)
453 close (filefd);
454 report_file_error ("Opening process output file",
455 Fcons (build_string (tempfile), Qnil));
457 fd[0] = filefd;
458 fd[1] = outfilefd;
459 #endif /* macintosh */
461 if (INTEGERP (buffer))
462 fd[1] = emacs_open (NULL_DEVICE, O_WRONLY, 0), fd[0] = -1;
463 else
465 #ifndef MSDOS
466 #ifndef macintosh
467 pipe (fd);
468 #endif
469 #endif
470 #if 0
471 /* Replaced by close_process_descs */
472 set_exclusive_use (fd[0]);
473 #endif
477 /* child_setup must clobber environ in systems with true vfork.
478 Protect it from permanent change. */
479 register char **save_environ = environ;
480 register int fd1 = fd[1];
481 int fd_error = fd1;
483 #if 0 /* Some systems don't have sigblock. */
484 mask = sigblock (sigmask (SIGCHLD));
485 #endif
487 /* Record that we're about to create a synchronous process. */
488 synch_process_alive = 1;
490 /* These vars record information from process termination.
491 Clear them now before process can possibly terminate,
492 to avoid timing error if process terminates soon. */
493 synch_process_death = 0;
494 synch_process_retcode = 0;
496 if (NILP (error_file))
497 fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0);
498 else if (STRINGP (error_file))
500 #ifdef DOS_NT
501 fd_error = emacs_open (XSTRING (error_file)->data,
502 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
503 S_IREAD | S_IWRITE);
504 #else /* not DOS_NT */
505 fd_error = creat (XSTRING (error_file)->data, 0666);
506 #endif /* not DOS_NT */
509 if (fd_error < 0)
511 emacs_close (filefd);
512 if (fd[0] != filefd)
513 emacs_close (fd[0]);
514 if (fd1 >= 0)
515 emacs_close (fd1);
516 #ifdef MSDOS
517 unlink (tempfile);
518 #endif
519 report_file_error ("Cannot redirect stderr",
520 Fcons ((NILP (error_file)
521 ? build_string (NULL_DEVICE) : error_file),
522 Qnil));
525 current_dir = ENCODE_FILE (current_dir);
527 #ifdef macintosh
529 /* Call run_mac_command in sysdep.c here directly instead of doing
530 a child_setup as for MSDOS and other platforms. Note that this
531 code does not handle passing the environment to the synchronous
532 Mac subprocess. */
533 char *infn, *outfn, *errfn, *currdn;
535 /* close these files so subprocess can write to them */
536 close (outfilefd);
537 if (fd_error != outfilefd)
538 close (fd_error);
539 fd1 = -1; /* No harm in closing that one! */
541 infn = XSTRING (infile)->data;
542 outfn = tempfile;
543 if (NILP (error_file))
544 errfn = NULL_DEVICE;
545 else if (EQ (Qt, error_file))
546 errfn = outfn;
547 else
548 errfn = XSTRING (error_file)->data;
549 currdn = XSTRING (current_dir)->data;
550 pid = run_mac_command (new_argv, currdn, infn, outfn, errfn);
552 /* Record that the synchronous process exited and note its
553 termination status. */
554 synch_process_alive = 0;
555 synch_process_retcode = pid;
556 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
558 synchronize_system_messages_locale ();
559 synch_process_death = strerror (errno);
562 /* Since CRLF is converted to LF within `decode_coding', we can
563 always open a file with binary mode. */
564 fd[0] = open (tempfile, O_BINARY);
565 if (fd[0] < 0)
567 unlink (tempfile);
568 close (filefd);
569 report_file_error ("Cannot re-open temporary file", Qnil);
572 #else /* not macintosh */
573 #ifdef MSDOS /* MW, July 1993 */
574 /* Note that on MSDOS `child_setup' actually returns the child process
575 exit status, not its PID, so we assign it to `synch_process_retcode'
576 below. */
577 pid = child_setup (filefd, outfilefd, fd_error, (char **) new_argv,
578 0, current_dir);
580 /* Record that the synchronous process exited and note its
581 termination status. */
582 synch_process_alive = 0;
583 synch_process_retcode = pid;
584 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
586 synchronize_system_messages_locale ();
587 synch_process_death = strerror (errno);
590 emacs_close (outfilefd);
591 if (fd_error != outfilefd)
592 emacs_close (fd_error);
593 fd1 = -1; /* No harm in closing that one! */
594 /* Since CRLF is converted to LF within `decode_coding', we can
595 always open a file with binary mode. */
596 fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0);
597 if (fd[0] < 0)
599 unlink (tempfile);
600 emacs_close (filefd);
601 report_file_error ("Cannot re-open temporary file", Qnil);
603 #else /* not MSDOS */
604 #ifdef WINDOWSNT
605 pid = child_setup (filefd, fd1, fd_error, (char **) new_argv,
606 0, current_dir);
607 #else /* not WINDOWSNT */
608 pid = vfork ();
610 if (pid == 0)
612 if (fd[0] >= 0)
613 emacs_close (fd[0]);
614 #ifdef HAVE_SETSID
615 setsid ();
616 #endif
617 #if defined (USG) && !defined (BSD_PGRPS)
618 setpgrp ();
619 #else
620 setpgrp (pid, pid);
621 #endif /* USG */
622 child_setup (filefd, fd1, fd_error, (char **) new_argv,
623 0, current_dir);
625 #endif /* not WINDOWSNT */
627 /* The MSDOS case did this already. */
628 if (fd_error >= 0)
629 emacs_close (fd_error);
630 #endif /* not MSDOS */
631 #endif /* not macintosh */
633 environ = save_environ;
635 /* Close most of our fd's, but not fd[0]
636 since we will use that to read input from. */
637 emacs_close (filefd);
638 if (fd1 >= 0 && fd1 != fd_error)
639 emacs_close (fd1);
642 if (pid < 0)
644 if (fd[0] >= 0)
645 emacs_close (fd[0]);
646 report_file_error ("Doing vfork", Qnil);
649 if (INTEGERP (buffer))
651 if (fd[0] >= 0)
652 emacs_close (fd[0]);
653 #ifndef subprocesses
654 /* If Emacs has been built with asynchronous subprocess support,
655 we don't need to do this, I think because it will then have
656 the facilities for handling SIGCHLD. */
657 wait_without_blocking ();
658 #endif /* subprocesses */
659 return Qnil;
662 /* Enable sending signal if user quits below. */
663 call_process_exited = 0;
665 #if defined(MSDOS) || defined(macintosh)
666 /* MSDOS needs different cleanup information. */
667 record_unwind_protect (call_process_cleanup,
668 Fcons (make_number (fd[0]), build_string (tempfile)));
669 #else
670 record_unwind_protect (call_process_cleanup,
671 Fcons (make_number (fd[0]), make_number (pid)));
672 #endif /* not MSDOS and not macintosh */
675 if (BUFFERP (buffer))
676 Fset_buffer (buffer);
678 if (NILP (buffer))
680 /* If BUFFER is nil, we must read process output once and then
681 discard it, so setup coding system but with nil. */
682 setup_coding_system (Qnil, &process_coding);
684 else
686 Lisp_Object val, *args2;
688 val = Qnil;
689 if (!NILP (Vcoding_system_for_read))
690 val = Vcoding_system_for_read;
691 else
693 if (EQ (coding_systems, Qt))
695 int i;
697 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
698 args2[0] = Qcall_process;
699 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
700 coding_systems
701 = Ffind_operation_coding_system (nargs + 1, args2);
703 if (CONSP (coding_systems))
704 val = XCAR (coding_systems);
705 else if (CONSP (Vdefault_process_coding_system))
706 val = XCAR (Vdefault_process_coding_system);
707 else
708 val = Qnil;
710 setup_coding_system (Fcheck_coding_system (val), &process_coding);
711 /* In unibyte mode, character code conversion should not take
712 place but EOL conversion should. So, setup raw-text or one
713 of the subsidiary according to the information just setup. */
714 if (NILP (current_buffer->enable_multibyte_characters)
715 && !NILP (val))
716 setup_raw_text_coding_system (&process_coding);
718 process_coding.src_multibyte = 0;
719 process_coding.dst_multibyte
720 = (BUFFERP (buffer)
721 ? ! NILP (XBUFFER (buffer)->enable_multibyte_characters)
722 : ! NILP (current_buffer->enable_multibyte_characters));
724 immediate_quit = 1;
725 QUIT;
728 register int nread;
729 int first = 1;
730 int total_read = 0;
731 int carryover = 0;
732 int display_on_the_fly = !NILP (display) && INTERACTIVE;
733 struct coding_system saved_coding;
734 int pt_orig = PT, pt_byte_orig = PT_BYTE;
735 int inserted;
737 saved_coding = process_coding;
738 if (process_coding.composing != COMPOSITION_DISABLED)
739 coding_allocate_composition_data (&process_coding, PT);
740 while (1)
742 /* Repeatedly read until we've filled as much as possible
743 of the buffer size we have. But don't read
744 less than 1024--save that for the next bufferful. */
745 nread = carryover;
746 while (nread < bufsize - 1024)
748 int this_read = emacs_read (fd[0], bufptr + nread,
749 bufsize - nread);
751 if (this_read < 0)
752 goto give_up;
754 if (this_read == 0)
756 process_coding.mode |= CODING_MODE_LAST_BLOCK;
757 break;
760 nread += this_read;
761 total_read += this_read;
763 if (display_on_the_fly)
764 break;
767 /* Now NREAD is the total amount of data in the buffer. */
768 immediate_quit = 0;
770 if (!NILP (buffer))
772 if (! CODING_MAY_REQUIRE_DECODING (&process_coding))
773 insert_1_both (bufptr, nread, nread, 0, 1, 0);
774 else
775 { /* We have to decode the input. */
776 int size;
777 char *decoding_buf;
779 repeat_decoding:
780 size = decoding_buffer_size (&process_coding, nread);
781 decoding_buf = (char *) xmalloc (size);
782 if (process_coding.cmp_data)
783 process_coding.cmp_data->char_offset = PT;
784 decode_coding (&process_coding, bufptr, decoding_buf,
785 nread, size);
786 if (display_on_the_fly
787 && saved_coding.type == coding_type_undecided
788 && process_coding.type != coding_type_undecided)
790 /* We have detected some coding system. But,
791 there's a possibility that the detection was
792 done by insufficient data. So, we give up
793 displaying on the fly. */
794 xfree (decoding_buf);
795 display_on_the_fly = 0;
796 process_coding = saved_coding;
797 carryover = nread;
798 continue;
800 if (process_coding.produced > 0)
801 insert_1_both (decoding_buf, process_coding.produced_char,
802 process_coding.produced, 0, 1, 0);
803 xfree (decoding_buf);
804 nread -= process_coding.consumed;
805 carryover = nread;
806 if (carryover > 0)
807 /* As CARRYOVER should not be that large, we had
808 better avoid overhead of bcopy. */
809 BCOPY_SHORT (bufptr + process_coding.consumed, bufptr,
810 carryover);
811 if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP)
813 /* The decoding ended because of insufficient data
814 area to record information about composition.
815 We must try decoding with additional data area
816 before reading more output for the process. */
817 coding_allocate_composition_data (&process_coding, PT);
818 goto repeat_decoding;
823 if (process_coding.mode & CODING_MODE_LAST_BLOCK)
824 break;
826 /* Make the buffer bigger as we continue to read more data,
827 but not past 64k. */
828 if (bufsize < 64 * 1024 && total_read > 32 * bufsize)
830 bufsize *= 2;
831 bufptr = (char *) alloca (bufsize);
834 if (!NILP (display) && INTERACTIVE)
836 if (first)
837 prepare_menu_bars ();
838 first = 0;
839 redisplay_preserve_echo_area ();
841 immediate_quit = 1;
842 QUIT;
844 give_up: ;
846 if (!NILP (buffer)
847 && process_coding.cmp_data)
849 coding_restore_composition (&process_coding, Fcurrent_buffer ());
850 coding_free_composition_data (&process_coding);
854 int post_read_count = specpdl_ptr - specpdl;
856 record_unwind_protect (save_excursion_restore, save_excursion_save ());
857 inserted = PT - pt_orig;
858 TEMP_SET_PT_BOTH (pt_orig, pt_byte_orig);
859 if (SYMBOLP (process_coding.post_read_conversion)
860 && !NILP (Ffboundp (process_coding.post_read_conversion)))
861 call1 (process_coding.post_read_conversion, make_number (inserted));
863 Vlast_coding_system_used = process_coding.symbol;
865 /* If the caller required, let the buffer inherit the
866 coding-system used to decode the process output. */
867 if (inherit_process_coding_system)
868 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
869 make_number (total_read));
871 unbind_to (post_read_count, Qnil);
875 /* Wait for it to terminate, unless it already has. */
876 wait_for_termination (pid);
878 immediate_quit = 0;
880 set_buffer_internal (old);
882 /* Don't kill any children that the subprocess may have left behind
883 when exiting. */
884 call_process_exited = 1;
886 unbind_to (count, Qnil);
888 if (synch_process_death)
889 return code_convert_string_norecord (build_string (synch_process_death),
890 Vlocale_coding_system, 0);
891 return make_number (synch_process_retcode);
893 #endif
895 static Lisp_Object
896 delete_temp_file (name)
897 Lisp_Object name;
899 /* Use Fdelete_file (indirectly) because that runs a file name handler.
900 We did that when writing the file, so we should do so when deleting. */
901 internal_delete_file (name);
902 return Qnil;
905 DEFUN ("call-process-region", Fcall_process_region, Scall_process_region,
906 3, MANY, 0,
907 "Send text from START to END to a synchronous process running PROGRAM.\n\
908 The remaining arguments are optional.\n\
909 Delete the text if fourth arg DELETE is non-nil.\n\
911 Insert output in BUFFER before point; t means current buffer;\n\
912 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
913 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
914 REAL-BUFFER says what to do with standard output, as above,\n\
915 while STDERR-FILE says what to do with standard error in the child.\n\
916 STDERR-FILE may be nil (discard standard error output),\n\
917 t (mix it with ordinary output), or a file name string.\n\
919 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
920 Remaining args are passed to PROGRAM at startup as command args.\n\
922 If BUFFER is nil, `call-process-region' returns immediately with value nil.\n\
923 Otherwise it waits for PROGRAM to terminate\n\
924 and returns a numeric exit status or a signal description string.\n\
925 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
926 (nargs, args)
927 int nargs;
928 register Lisp_Object *args;
930 struct gcpro gcpro1;
931 Lisp_Object filename_string;
932 register Lisp_Object start, end;
933 int count = specpdl_ptr - specpdl;
934 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
935 Lisp_Object coding_systems;
936 Lisp_Object val, *args2;
937 int i;
938 #ifdef DOS_NT
939 char *tempfile;
940 char *outf = '\0';
942 if ((outf = egetenv ("TMPDIR"))
943 || (outf = egetenv ("TMP"))
944 || (outf = egetenv ("TEMP")))
945 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
946 else
948 tempfile = alloca (20);
949 *tempfile = '\0';
951 if (!IS_DIRECTORY_SEP (tempfile[strlen (tempfile) - 1]))
952 strcat (tempfile, "/");
953 if ('/' == DIRECTORY_SEP)
954 dostounix_filename (tempfile);
955 else
956 unixtodos_filename (tempfile);
957 #ifdef WINDOWSNT
958 strcat (tempfile, "emXXXXXX");
959 #else
960 strcat (tempfile, "detmp.XXX");
961 #endif
962 #else /* not DOS_NT */
963 char *tempfile = (char *) alloca (STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
964 bcopy (XSTRING (Vtemp_file_name_pattern)->data, tempfile,
965 STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
966 #endif /* not DOS_NT */
968 coding_systems = Qt;
970 mktemp (tempfile);
972 filename_string = build_string (tempfile);
973 GCPRO1 (filename_string);
974 start = args[0];
975 end = args[1];
976 /* Decide coding-system of the contents of the temporary file. */
977 if (!NILP (Vcoding_system_for_write))
978 val = Vcoding_system_for_write;
979 else if (NILP (current_buffer->enable_multibyte_characters))
980 val = Qnil;
981 else
983 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
984 args2[0] = Qcall_process_region;
985 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
986 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
987 if (CONSP (coding_systems))
988 val = XCDR (coding_systems);
989 else if (CONSP (Vdefault_process_coding_system))
990 val = XCDR (Vdefault_process_coding_system);
991 else
992 val = Qnil;
996 int count1 = specpdl_ptr - specpdl;
998 specbind (intern ("coding-system-for-write"), val);
999 Fwrite_region (start, end, filename_string, Qnil, Qlambda, Qnil, Qnil);
1001 unbind_to (count1, Qnil);
1004 /* Note that Fcall_process takes care of binding
1005 coding-system-for-read. */
1007 record_unwind_protect (delete_temp_file, filename_string);
1009 if (nargs > 3 && !NILP (args[3]))
1010 Fdelete_region (start, end);
1012 if (nargs > 3)
1014 args += 2;
1015 nargs -= 2;
1017 else
1019 args[0] = args[2];
1020 nargs = 2;
1022 args[1] = filename_string;
1024 RETURN_UNGCPRO (unbind_to (count, Fcall_process (nargs, args)));
1027 #ifndef VMS /* VMS version is in vmsproc.c. */
1029 static int relocate_fd ();
1031 /* This is the last thing run in a newly forked inferior
1032 either synchronous or asynchronous.
1033 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
1034 Initialize inferior's priority, pgrp, connected dir and environment.
1035 then exec another program based on new_argv.
1037 This function may change environ for the superior process.
1038 Therefore, the superior process must save and restore the value
1039 of environ around the vfork and the call to this function.
1041 SET_PGRP is nonzero if we should put the subprocess into a separate
1042 process group.
1044 CURRENT_DIR is an elisp string giving the path of the current
1045 directory the subprocess should have. Since we can't really signal
1046 a decent error from within the child, this should be verified as an
1047 executable directory by the parent. */
1050 child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1051 int in, out, err;
1052 register char **new_argv;
1053 int set_pgrp;
1054 Lisp_Object current_dir;
1056 char **env;
1057 char *pwd_var;
1058 #ifdef WINDOWSNT
1059 int cpid;
1060 HANDLE handles[3];
1061 #endif /* WINDOWSNT */
1063 int pid = getpid ();
1065 #ifdef SET_EMACS_PRIORITY
1067 extern int emacs_priority;
1069 if (emacs_priority < 0)
1070 nice (- emacs_priority);
1072 #endif
1074 #ifdef subprocesses
1075 /* Close Emacs's descriptors that this process should not have. */
1076 close_process_descs ();
1077 #endif
1078 /* DOS_NT isn't in a vfork, so if we are in the middle of load-file,
1079 we will lose if we call close_load_descs here. */
1080 #ifndef DOS_NT
1081 close_load_descs ();
1082 #endif
1084 /* Note that use of alloca is always safe here. It's obvious for systems
1085 that do not have true vfork or that have true (stack) alloca.
1086 If using vfork and C_ALLOCA it is safe because that changes
1087 the superior's static variables as if the superior had done alloca
1088 and will be cleaned up in the usual way. */
1090 register char *temp;
1091 register int i;
1093 i = STRING_BYTES (XSTRING (current_dir));
1094 #ifdef MSDOS
1095 /* MSDOS must have all environment variables malloc'ed, because
1096 low-level libc functions that launch subsidiary processes rely
1097 on that. */
1098 pwd_var = (char *) xmalloc (i + 6);
1099 #else
1100 pwd_var = (char *) alloca (i + 6);
1101 #endif
1102 temp = pwd_var + 4;
1103 bcopy ("PWD=", pwd_var, 4);
1104 bcopy (XSTRING (current_dir)->data, temp, i);
1105 if (!IS_DIRECTORY_SEP (temp[i - 1])) temp[i++] = DIRECTORY_SEP;
1106 temp[i] = 0;
1108 #ifndef DOS_NT
1109 /* We can't signal an Elisp error here; we're in a vfork. Since
1110 the callers check the current directory before forking, this
1111 should only return an error if the directory's permissions
1112 are changed between the check and this chdir, but we should
1113 at least check. */
1114 if (chdir (temp) < 0)
1115 _exit (errno);
1116 #endif
1118 #ifdef DOS_NT
1119 /* Get past the drive letter, so that d:/ is left alone. */
1120 if (i > 2 && IS_DEVICE_SEP (temp[1]) && IS_DIRECTORY_SEP (temp[2]))
1122 temp += 2;
1123 i -= 2;
1125 #endif
1127 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1128 while (i > 2 && IS_DIRECTORY_SEP (temp[i - 1]))
1129 temp[--i] = 0;
1132 /* Set `env' to a vector of the strings in Vprocess_environment. */
1134 register Lisp_Object tem;
1135 register char **new_env;
1136 register int new_length;
1138 new_length = 0;
1139 for (tem = Vprocess_environment;
1140 CONSP (tem) && STRINGP (XCAR (tem));
1141 tem = XCDR (tem))
1142 new_length++;
1144 /* new_length + 2 to include PWD and terminating 0. */
1145 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
1147 /* If we have a PWD envvar, pass one down,
1148 but with corrected value. */
1149 if (getenv ("PWD"))
1150 *new_env++ = pwd_var;
1152 /* Copy the Vprocess_environment strings into new_env. */
1153 for (tem = Vprocess_environment;
1154 CONSP (tem) && STRINGP (XCAR (tem));
1155 tem = XCDR (tem))
1157 char **ep = env;
1158 char *string = (char *) XSTRING (XCAR (tem))->data;
1159 /* See if this string duplicates any string already in the env.
1160 If so, don't put it in.
1161 When an env var has multiple definitions,
1162 we keep the definition that comes first in process-environment. */
1163 for (; ep != new_env; ep++)
1165 char *p = *ep, *q = string;
1166 while (1)
1168 if (*q == 0)
1169 /* The string is malformed; might as well drop it. */
1170 goto duplicate;
1171 if (*q != *p)
1172 break;
1173 if (*q == '=')
1174 goto duplicate;
1175 p++, q++;
1178 *new_env++ = string;
1179 duplicate: ;
1181 *new_env = 0;
1183 #ifdef WINDOWSNT
1184 prepare_standard_handles (in, out, err, handles);
1185 set_process_dir (XSTRING (current_dir)->data);
1186 #else /* not WINDOWSNT */
1187 /* Make sure that in, out, and err are not actually already in
1188 descriptors zero, one, or two; this could happen if Emacs is
1189 started with its standard in, out, or error closed, as might
1190 happen under X. */
1192 int oin = in, oout = out;
1194 /* We have to avoid relocating the same descriptor twice! */
1196 in = relocate_fd (in, 3);
1198 if (out == oin)
1199 out = in;
1200 else
1201 out = relocate_fd (out, 3);
1203 if (err == oin)
1204 err = in;
1205 else if (err == oout)
1206 err = out;
1207 else
1208 err = relocate_fd (err, 3);
1211 #ifndef MSDOS
1212 emacs_close (0);
1213 emacs_close (1);
1214 emacs_close (2);
1216 dup2 (in, 0);
1217 dup2 (out, 1);
1218 dup2 (err, 2);
1219 emacs_close (in);
1220 emacs_close (out);
1221 emacs_close (err);
1222 #endif /* not MSDOS */
1223 #endif /* not WINDOWSNT */
1225 #if defined(USG) && !defined(BSD_PGRPS)
1226 #ifndef SETPGRP_RELEASES_CTTY
1227 setpgrp (); /* No arguments but equivalent in this case */
1228 #endif
1229 #else
1230 setpgrp (pid, pid);
1231 #endif /* USG */
1232 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
1233 EMACS_SET_TTY_PGRP (0, &pid);
1235 #ifdef vipc
1236 something missing here;
1237 #endif /* vipc */
1239 #ifdef MSDOS
1240 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env);
1241 xfree (pwd_var);
1242 if (pid == -1)
1243 /* An error occurred while trying to run the subprocess. */
1244 report_file_error ("Spawning child process", Qnil);
1245 return pid;
1246 #else /* not MSDOS */
1247 #ifdef WINDOWSNT
1248 /* Spawn the child. (See ntproc.c:Spawnve). */
1249 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
1250 reset_standard_handles (in, out, err, handles);
1251 if (cpid == -1)
1252 /* An error occurred while trying to spawn the process. */
1253 report_file_error ("Spawning child process", Qnil);
1254 return cpid;
1255 #else /* not WINDOWSNT */
1256 /* execvp does not accept an environment arg so the only way
1257 to pass this environment is to set environ. Our caller
1258 is responsible for restoring the ambient value of environ. */
1259 environ = env;
1260 execvp (new_argv[0], new_argv);
1262 emacs_write (1, "Can't exec program: ", 20);
1263 emacs_write (1, new_argv[0], strlen (new_argv[0]));
1264 emacs_write (1, "\n", 1);
1265 _exit (1);
1266 #endif /* not WINDOWSNT */
1267 #endif /* not MSDOS */
1270 /* Move the file descriptor FD so that its number is not less than MINFD.
1271 If the file descriptor is moved at all, the original is freed. */
1272 static int
1273 relocate_fd (fd, minfd)
1274 int fd, minfd;
1276 if (fd >= minfd)
1277 return fd;
1278 else
1280 int new = dup (fd);
1281 if (new == -1)
1283 char *message1 = "Error while setting up child: ";
1284 char *errmessage = strerror (errno);
1285 char *message2 = "\n";
1286 emacs_write (2, message1, strlen (message1));
1287 emacs_write (2, errmessage, strlen (errmessage));
1288 emacs_write (2, message2, strlen (message2));
1289 _exit (1);
1291 /* Note that we hold the original FD open while we recurse,
1292 to guarantee we'll get a new FD if we need it. */
1293 new = relocate_fd (new, minfd);
1294 emacs_close (fd);
1295 return new;
1299 static int
1300 getenv_internal (var, varlen, value, valuelen)
1301 char *var;
1302 int varlen;
1303 char **value;
1304 int *valuelen;
1306 Lisp_Object scan;
1308 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
1310 Lisp_Object entry;
1312 entry = XCAR (scan);
1313 if (STRINGP (entry)
1314 && STRING_BYTES (XSTRING (entry)) > varlen
1315 && XSTRING (entry)->data[varlen] == '='
1316 #ifdef WINDOWSNT
1317 /* NT environment variables are case insensitive. */
1318 && ! strnicmp (XSTRING (entry)->data, var, varlen)
1319 #else /* not WINDOWSNT */
1320 && ! bcmp (XSTRING (entry)->data, var, varlen)
1321 #endif /* not WINDOWSNT */
1324 *value = (char *) XSTRING (entry)->data + (varlen + 1);
1325 *valuelen = STRING_BYTES (XSTRING (entry)) - (varlen + 1);
1326 return 1;
1330 return 0;
1333 DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 1, 0,
1334 "Return the value of environment variable VAR, as a string.\n\
1335 VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
1336 This function consults the variable ``process-environment'' for its value.")
1337 (var)
1338 Lisp_Object var;
1340 char *value;
1341 int valuelen;
1343 CHECK_STRING (var, 0);
1344 if (getenv_internal (XSTRING (var)->data, STRING_BYTES (XSTRING (var)),
1345 &value, &valuelen))
1346 return make_string (value, valuelen);
1347 else
1348 return Qnil;
1351 /* A version of getenv that consults process_environment, easily
1352 callable from C. */
1353 char *
1354 egetenv (var)
1355 char *var;
1357 char *value;
1358 int valuelen;
1360 if (getenv_internal (var, strlen (var), &value, &valuelen))
1361 return value;
1362 else
1363 return 0;
1366 #endif /* not VMS */
1368 /* This is run before init_cmdargs. */
1370 void
1371 init_callproc_1 ()
1373 char *data_dir = egetenv ("EMACSDATA");
1374 char *doc_dir = egetenv ("EMACSDOC");
1376 Vdata_directory
1377 = Ffile_name_as_directory (build_string (data_dir ? data_dir
1378 : PATH_DATA));
1379 Vdoc_directory
1380 = Ffile_name_as_directory (build_string (doc_dir ? doc_dir
1381 : PATH_DOC));
1383 /* Check the EMACSPATH environment variable, defaulting to the
1384 PATH_EXEC path from epaths.h. */
1385 Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
1386 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
1387 Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
1390 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1392 void
1393 init_callproc ()
1395 char *data_dir = egetenv ("EMACSDATA");
1397 register char * sh;
1398 Lisp_Object tempdir;
1400 if (!NILP (Vinstallation_directory))
1402 /* Add to the path the lib-src subdir of the installation dir. */
1403 Lisp_Object tem;
1404 tem = Fexpand_file_name (build_string ("lib-src"),
1405 Vinstallation_directory);
1406 #ifndef DOS_NT
1407 /* MSDOS uses wrapped binaries, so don't do this. */
1408 if (NILP (Fmember (tem, Vexec_path)))
1409 Vexec_path = nconc2 (Vexec_path, Fcons (tem, Qnil));
1411 Vexec_directory = Ffile_name_as_directory (tem);
1412 #endif /* not DOS_NT */
1414 /* Maybe use ../etc as well as ../lib-src. */
1415 if (data_dir == 0)
1417 tem = Fexpand_file_name (build_string ("etc"),
1418 Vinstallation_directory);
1419 Vdoc_directory = Ffile_name_as_directory (tem);
1423 /* Look for the files that should be in etc. We don't use
1424 Vinstallation_directory, because these files are never installed
1425 near the executable, and they are never in the build
1426 directory when that's different from the source directory.
1428 Instead, if these files are not in the nominal place, we try the
1429 source directory. */
1430 if (data_dir == 0)
1432 Lisp_Object tem, tem1, newdir;
1434 tem = Fexpand_file_name (build_string ("GNU"), Vdata_directory);
1435 tem1 = Ffile_exists_p (tem);
1436 if (NILP (tem1))
1438 newdir = Fexpand_file_name (build_string ("../etc/"),
1439 build_string (PATH_DUMPLOADSEARCH));
1440 tem = Fexpand_file_name (build_string ("GNU"), newdir);
1441 tem1 = Ffile_exists_p (tem);
1442 if (!NILP (tem1))
1443 Vdata_directory = newdir;
1447 #ifndef CANNOT_DUMP
1448 if (initialized)
1449 #endif
1451 tempdir = Fdirectory_file_name (Vexec_directory);
1452 if (access (XSTRING (tempdir)->data, 0) < 0)
1453 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n",
1454 Vexec_directory);
1457 tempdir = Fdirectory_file_name (Vdata_directory);
1458 if (access (XSTRING (tempdir)->data, 0) < 0)
1459 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n",
1460 Vdata_directory);
1462 #ifdef VMS
1463 Vshell_file_name = build_string ("*dcl*");
1464 #else
1465 sh = (char *) getenv ("SHELL");
1466 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
1467 #endif
1469 #ifdef VMS
1470 Vtemp_file_name_pattern = build_string ("tmp:emacsXXXXXX.");
1471 #else
1472 if (getenv ("TMPDIR"))
1474 char *dir = getenv ("TMPDIR");
1475 Vtemp_file_name_pattern
1476 = Fexpand_file_name (build_string ("emacsXXXXXX"),
1477 build_string (dir));
1479 else
1480 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX");
1481 #endif
1484 void
1485 set_process_environment ()
1487 register char **envp;
1489 Vprocess_environment = Qnil;
1490 #ifndef CANNOT_DUMP
1491 if (initialized)
1492 #endif
1493 for (envp = environ; *envp; envp++)
1494 Vprocess_environment = Fcons (build_string (*envp),
1495 Vprocess_environment);
1498 void
1499 syms_of_callproc ()
1501 #ifdef DOS_NT
1502 Qbuffer_file_type = intern ("buffer-file-type");
1503 staticpro (&Qbuffer_file_type);
1504 #endif /* DOS_NT */
1506 DEFVAR_LISP ("shell-file-name", &Vshell_file_name,
1507 "*File name to load inferior shells from.\n\
1508 Initialized from the SHELL environment variable.");
1510 DEFVAR_LISP ("exec-path", &Vexec_path,
1511 "*List of directories to search programs to run in subprocesses.\n\
1512 Each element is a string (directory name) or nil (try default directory).");
1514 DEFVAR_LISP ("exec-directory", &Vexec_directory,
1515 "Directory for executables for Emacs to invoke.\n\
1516 More generally, this includes any architecture-dependent files\n\
1517 that are built and installed from the Emacs distribution.");
1519 DEFVAR_LISP ("data-directory", &Vdata_directory,
1520 "Directory of machine-independent files that come with GNU Emacs.\n\
1521 These are files intended for Emacs to use while it runs.");
1523 DEFVAR_LISP ("doc-directory", &Vdoc_directory,
1524 "Directory containing the DOC file that comes with GNU Emacs.\n\
1525 This is usually the same as data-directory.");
1527 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory,
1528 "For internal use by the build procedure only.\n\
1529 This is the name of the directory in which the build procedure installed\n\
1530 Emacs's info files; the default value for Info-default-directory-list\n\
1531 includes this.");
1532 Vconfigure_info_directory = build_string (PATH_INFO);
1534 DEFVAR_LISP ("temp-file-name-pattern", &Vtemp_file_name_pattern,
1535 "Pattern for making names for temporary files.\n\
1536 This is used by `call-process-region'.");
1537 /* This variable is initialized in init_callproc. */
1539 DEFVAR_LISP ("process-environment", &Vprocess_environment,
1540 "List of environment variables for subprocesses to inherit.\n\
1541 Each element should be a string of the form ENVVARNAME=VALUE.\n\
1542 The environment which Emacs inherits is placed in this variable\n\
1543 when Emacs starts.");
1545 #ifndef VMS
1546 defsubr (&Scall_process);
1547 defsubr (&Sgetenv_internal);
1548 #endif
1549 defsubr (&Scall_process_region);