1 /* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
32 /* Define SIGCHLD as an alias for SIGCLD. */
34 #if !defined (SIGCHLD) && defined (SIGCLD)
35 #define SIGCHLD SIGCLD
38 #include <sys/types.h>
46 #define INCLUDED_FCNTL
53 #include <stdlib.h> /* for proper declaration of environ */
56 #define _P_NOWAIT 1 /* from process.h */
59 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
60 #define INCLUDED_FCNTL
63 #include <sys/param.h>
81 #include "composite.h"
84 #include "syssignal.h"
86 #include "blockinput.h"
88 #include "termhooks.h"
95 extern noshare
char **environ
;
98 extern char **environ
;
103 #if !defined (USG) || defined (BSD_PGRPS)
105 #define setpgrp setpgid
109 Lisp_Object Vexec_path
, Vexec_directory
, Vexec_suffixes
;
110 Lisp_Object Vdata_directory
, Vdoc_directory
;
111 Lisp_Object Vconfigure_info_directory
, Vshared_game_score_directory
;
112 Lisp_Object Vtemp_file_name_pattern
;
114 Lisp_Object Vshell_file_name
;
116 Lisp_Object Vglobal_environment
;
117 Lisp_Object Vprocess_environment
;
120 Lisp_Object Qbuffer_file_type
;
123 /* True iff we are about to fork off a synchronous process or if we
124 are waiting for it. */
125 int synch_process_alive
;
127 /* Nonzero => this is a string explaining death of synchronous subprocess. */
128 char *synch_process_death
;
130 /* Nonzero => this is the signal number that terminated the subprocess. */
131 int synch_process_termsig
;
133 /* If synch_process_death is zero,
134 this is exit code of synchronous subprocess. */
135 int synch_process_retcode
;
137 /* List of environment variables to look up in emacsclient. */
138 Lisp_Object Vlocal_environment_variables
;
141 /* Clean up when exiting Fcall_process.
142 On MSDOS, delete the temporary file on any kind of termination.
143 On Unix, kill the process and any children on termination by signal. */
145 /* Nonzero if this is termination due to exit. */
146 static int call_process_exited
;
148 #ifndef VMS /* VMS version is in vmsproc.c. */
151 call_process_kill (fdpid
)
154 emacs_close (XFASTINT (Fcar (fdpid
)));
155 EMACS_KILLPG (XFASTINT (Fcdr (fdpid
)), SIGKILL
);
156 synch_process_alive
= 0;
161 call_process_cleanup (fdpid
)
164 #if defined (MSDOS) || defined (MAC_OS8)
165 /* for MSDOS fdpid is really (fd . tempfile) */
166 register Lisp_Object file
;
168 emacs_close (XFASTINT (Fcar (fdpid
)));
169 if (strcmp (SDATA (file
), NULL_DEVICE
) != 0)
170 unlink (SDATA (file
));
171 #else /* not MSDOS and not MAC_OS8 */
172 register int pid
= XFASTINT (Fcdr (fdpid
));
174 if (call_process_exited
)
176 emacs_close (XFASTINT (Fcar (fdpid
)));
180 if (EMACS_KILLPG (pid
, SIGINT
) == 0)
182 int count
= SPECPDL_INDEX ();
183 record_unwind_protect (call_process_kill
, fdpid
);
184 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
187 wait_for_termination (pid
);
189 specpdl_ptr
= specpdl
+ count
; /* Discard the unwind protect. */
190 message1 ("Waiting for process to die...done");
192 synch_process_alive
= 0;
193 emacs_close (XFASTINT (Fcar (fdpid
)));
194 #endif /* not MSDOS */
198 DEFUN ("call-process", Fcall_process
, Scall_process
, 1, MANY
, 0,
199 doc
: /* Call PROGRAM synchronously in separate process.
200 The remaining arguments are optional.
201 The program's input comes from file INFILE (nil means `/dev/null').
202 Insert output in BUFFER before point; t means current buffer;
203 nil for BUFFER means discard it; 0 means discard and don't wait.
204 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
205 REAL-BUFFER says what to do with standard output, as above,
206 while STDERR-FILE says what to do with standard error in the child.
207 STDERR-FILE may be nil (discard standard error output),
208 t (mix it with ordinary output), or a file name string.
210 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
211 Remaining arguments are strings passed as command arguments to PROGRAM.
213 If BUFFER is 0, `call-process' returns immediately with value nil.
214 Otherwise it waits for PROGRAM to terminate
215 and returns a numeric exit status or a signal description string.
216 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
218 usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
221 register Lisp_Object
*args
;
223 Lisp_Object infile
, buffer
, current_dir
, path
;
228 #define CALLPROC_BUFFER_SIZE_MIN (16 * 1024)
229 #define CALLPROC_BUFFER_SIZE_MAX (4 * CALLPROC_BUFFER_SIZE_MIN)
230 char buf
[CALLPROC_BUFFER_SIZE_MAX
];
231 int bufsize
= CALLPROC_BUFFER_SIZE_MIN
;
232 int count
= SPECPDL_INDEX ();
234 register const unsigned char **new_argv
235 = (const unsigned char **) alloca ((max (2, nargs
- 2)) * sizeof (char *));
236 struct buffer
*old
= current_buffer
;
237 /* File to use for stderr in the child.
238 t means use same as standard output. */
239 Lisp_Object error_file
;
240 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
241 char *outf
, *tempfile
;
251 struct coding_system process_coding
; /* coding-system of process output */
252 struct coding_system argument_coding
; /* coding-system of arguments */
253 /* Set to the return value of Ffind_operation_coding_system. */
254 Lisp_Object coding_systems
;
256 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
259 CHECK_STRING (args
[0]);
264 /* Without asynchronous processes we cannot have BUFFER == 0. */
266 && (INTEGERP (CONSP (args
[2]) ? XCAR (args
[2]) : args
[2])))
267 error ("Operating system cannot handle asynchronous subprocesses");
268 #endif /* subprocesses */
270 /* Decide the coding-system for giving arguments. */
272 Lisp_Object val
, *args2
;
275 /* If arguments are supplied, we may have to encode them. */
280 for (i
= 4; i
< nargs
; i
++)
281 CHECK_STRING (args
[i
]);
283 for (i
= 4; i
< nargs
; i
++)
284 if (STRING_MULTIBYTE (args
[i
]))
287 if (!NILP (Vcoding_system_for_write
))
288 val
= Vcoding_system_for_write
;
289 else if (! must_encode
)
293 args2
= (Lisp_Object
*) alloca ((nargs
+ 1) * sizeof *args2
);
294 args2
[0] = Qcall_process
;
295 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
296 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
297 if (CONSP (coding_systems
))
298 val
= XCDR (coding_systems
);
299 else if (CONSP (Vdefault_process_coding_system
))
300 val
= XCDR (Vdefault_process_coding_system
);
304 setup_coding_system (Fcheck_coding_system (val
), &argument_coding
);
305 if (argument_coding
.common_flags
& CODING_ASCII_INCOMPATIBLE_MASK
)
306 setup_coding_system (Qraw_text
, &argument_coding
);
307 if (argument_coding
.eol_type
== CODING_EOL_UNDECIDED
)
308 argument_coding
.eol_type
= system_eol_type
;
312 if (nargs
>= 2 && ! NILP (args
[1]))
314 infile
= Fexpand_file_name (args
[1], current_buffer
->directory
);
315 CHECK_STRING (infile
);
318 infile
= build_string (NULL_DEVICE
);
324 /* If BUFFER is a list, its meaning is
325 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
328 if (CONSP (XCDR (buffer
)))
330 Lisp_Object stderr_file
;
331 stderr_file
= XCAR (XCDR (buffer
));
333 if (NILP (stderr_file
) || EQ (Qt
, stderr_file
))
334 error_file
= stderr_file
;
336 error_file
= Fexpand_file_name (stderr_file
, Qnil
);
339 buffer
= XCAR (buffer
);
342 if (!(EQ (buffer
, Qnil
)
344 || INTEGERP (buffer
)))
346 Lisp_Object spec_buffer
;
347 spec_buffer
= buffer
;
348 buffer
= Fget_buffer_create (buffer
);
349 /* Mention the buffer name for a better error message. */
351 CHECK_BUFFER (spec_buffer
);
352 CHECK_BUFFER (buffer
);
358 /* Make sure that the child will be able to chdir to the current
359 buffer's current directory, or its unhandled equivalent. We
360 can't just have the child check for an error when it does the
361 chdir, since it's in a vfork.
363 We have to GCPRO around this because Fexpand_file_name,
364 Funhandled_file_name_directory, and Ffile_accessible_directory_p
365 might call a file name handling function. The argument list is
366 protected by the caller, so all we really have to worry about is
369 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
371 current_dir
= current_buffer
->directory
;
373 GCPRO4 (infile
, buffer
, current_dir
, error_file
);
376 = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir
),
378 if (NILP (Ffile_accessible_directory_p (current_dir
)))
379 report_file_error ("Setting current directory",
380 Fcons (current_buffer
->directory
, Qnil
));
382 if (STRING_MULTIBYTE (infile
))
383 infile
= ENCODE_FILE (infile
);
384 if (STRING_MULTIBYTE (current_dir
))
385 current_dir
= ENCODE_FILE (current_dir
);
386 if (STRINGP (error_file
) && STRING_MULTIBYTE (error_file
))
387 error_file
= ENCODE_FILE (error_file
);
391 display_p
= INTERACTIVE
&& nargs
>= 4 && !NILP (args
[3]);
393 filefd
= emacs_open (SDATA (infile
), O_RDONLY
, 0);
396 infile
= DECODE_FILE (infile
);
397 report_file_error ("Opening process input file", Fcons (infile
, Qnil
));
399 /* Search for program; barf if not found. */
403 GCPRO1 (current_dir
);
404 openp (Vexec_path
, args
[0], Vexec_suffixes
, &path
, make_number (X_OK
));
409 emacs_close (filefd
);
410 report_file_error ("Searching for program", Fcons (args
[0], Qnil
));
413 /* If program file name starts with /: for quoting a magic name,
415 if (SBYTES (path
) > 2 && SREF (path
, 0) == '/'
416 && SREF (path
, 1) == ':')
417 path
= Fsubstring (path
, make_number (2), Qnil
);
419 new_argv
[0] = SDATA (path
);
423 struct gcpro gcpro1
, gcpro2
, gcpro3
;
425 GCPRO3 (infile
, buffer
, current_dir
);
426 argument_coding
.dst_multibyte
= 0;
427 for (i
= 4; i
< nargs
; i
++)
429 argument_coding
.src_multibyte
= STRING_MULTIBYTE (args
[i
]);
430 if (CODING_REQUIRE_ENCODING (&argument_coding
))
432 /* We must encode this argument. */
433 args
[i
] = encode_coding_string (args
[i
], &argument_coding
, 1);
434 if (argument_coding
.type
== coding_type_ccl
)
435 setup_ccl_program (&(argument_coding
.spec
.ccl
.encoder
), Qnil
);
437 new_argv
[i
- 3] = SDATA (args
[i
]);
440 new_argv
[nargs
- 3] = 0;
445 #ifdef MSDOS /* MW, July 1993 */
446 if ((outf
= egetenv ("TMPDIR")))
447 strcpy (tempfile
= alloca (strlen (outf
) + 20), outf
);
450 tempfile
= alloca (20);
453 dostounix_filename (tempfile
);
454 if (*tempfile
== '\0' || tempfile
[strlen (tempfile
) - 1] != '/')
455 strcat (tempfile
, "/");
456 strcat (tempfile
, "detmp.XXX");
459 outfilefd
= creat (tempfile
, S_IREAD
| S_IWRITE
);
462 emacs_close (filefd
);
463 report_file_error ("Opening process output file",
464 Fcons (build_string (tempfile
), Qnil
));
471 /* Since we don't have pipes on the Mac, create a temporary file to
472 hold the output of the subprocess. */
473 tempfile
= (char *) alloca (SBYTES (Vtemp_file_name_pattern
) + 1);
474 bcopy (SDATA (Vtemp_file_name_pattern
), tempfile
,
475 SBYTES (Vtemp_file_name_pattern
) + 1);
479 outfilefd
= creat (tempfile
, S_IREAD
| S_IWRITE
);
483 report_file_error ("Opening process output file",
484 Fcons (build_string (tempfile
), Qnil
));
490 if (INTEGERP (buffer
))
491 fd
[1] = emacs_open (NULL_DEVICE
, O_WRONLY
, 0), fd
[0] = -1;
499 emacs_close (filefd
);
500 report_file_error ("Creating process pipe", Qnil
);
505 /* Replaced by close_process_descs */
506 set_exclusive_use (fd
[0]);
511 /* child_setup must clobber environ in systems with true vfork.
512 Protect it from permanent change. */
513 register char **save_environ
= environ
;
514 register int fd1
= fd
[1];
517 #if 0 /* Some systems don't have sigblock. */
518 mask
= sigblock (sigmask (SIGCHLD
));
521 /* Record that we're about to create a synchronous process. */
522 synch_process_alive
= 1;
524 /* These vars record information from process termination.
525 Clear them now before process can possibly terminate,
526 to avoid timing error if process terminates soon. */
527 synch_process_death
= 0;
528 synch_process_retcode
= 0;
529 synch_process_termsig
= 0;
531 if (NILP (error_file
))
532 fd_error
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
533 else if (STRINGP (error_file
))
536 fd_error
= emacs_open (SDATA (error_file
),
537 O_WRONLY
| O_TRUNC
| O_CREAT
| O_TEXT
,
539 #else /* not DOS_NT */
540 fd_error
= creat (SDATA (error_file
), 0666);
541 #endif /* not DOS_NT */
546 emacs_close (filefd
);
554 if (NILP (error_file
))
555 error_file
= build_string (NULL_DEVICE
);
556 else if (STRINGP (error_file
))
557 error_file
= DECODE_FILE (error_file
);
558 report_file_error ("Cannot redirect stderr", Fcons (error_file
, Qnil
));
563 /* Call run_mac_command in sysdep.c here directly instead of doing
564 a child_setup as for MSDOS and other platforms. Note that this
565 code does not handle passing the environment to the synchronous
567 char *infn
, *outfn
, *errfn
, *currdn
;
569 /* close these files so subprocess can write to them */
571 if (fd_error
!= outfilefd
)
573 fd1
= -1; /* No harm in closing that one! */
575 infn
= SDATA (infile
);
577 if (NILP (error_file
))
579 else if (EQ (Qt
, error_file
))
582 errfn
= SDATA (error_file
);
583 currdn
= SDATA (current_dir
);
584 pid
= run_mac_command (new_argv
, currdn
, infn
, outfn
, errfn
);
586 /* Record that the synchronous process exited and note its
587 termination status. */
588 synch_process_alive
= 0;
589 synch_process_retcode
= pid
;
590 if (synch_process_retcode
< 0) /* means it couldn't be exec'ed */
592 synchronize_system_messages_locale ();
593 synch_process_death
= strerror (errno
);
596 /* Since CRLF is converted to LF within `decode_coding', we can
597 always open a file with binary mode. */
598 fd
[0] = open (tempfile
, O_BINARY
);
603 report_file_error ("Cannot re-open temporary file", Qnil
);
606 #else /* not MAC_OS8 */
607 #ifdef MSDOS /* MW, July 1993 */
608 /* Note that on MSDOS `child_setup' actually returns the child process
609 exit status, not its PID, so we assign it to `synch_process_retcode'
611 pid
= child_setup (filefd
, outfilefd
, fd_error
, (char **) new_argv
,
614 /* Record that the synchronous process exited and note its
615 termination status. */
616 synch_process_alive
= 0;
617 synch_process_retcode
= pid
;
618 if (synch_process_retcode
< 0) /* means it couldn't be exec'ed */
620 synchronize_system_messages_locale ();
621 synch_process_death
= strerror (errno
);
624 emacs_close (outfilefd
);
625 if (fd_error
!= outfilefd
)
626 emacs_close (fd_error
);
627 fd1
= -1; /* No harm in closing that one! */
628 /* Since CRLF is converted to LF within `decode_coding', we can
629 always open a file with binary mode. */
630 fd
[0] = emacs_open (tempfile
, O_RDONLY
| O_BINARY
, 0);
634 emacs_close (filefd
);
635 report_file_error ("Cannot re-open temporary file", Qnil
);
637 #else /* not MSDOS */
639 pid
= child_setup (filefd
, fd1
, fd_error
, (char **) new_argv
,
641 #else /* not WINDOWSNT */
653 #if defined (USG) && !defined (BSD_PGRPS)
658 child_setup (filefd
, fd1
, fd_error
, (char **) new_argv
,
663 #endif /* not WINDOWSNT */
665 /* The MSDOS case did this already. */
667 emacs_close (fd_error
);
668 #endif /* not MSDOS */
669 #endif /* not MAC_OS8 */
671 environ
= save_environ
;
673 /* Close most of our fd's, but not fd[0]
674 since we will use that to read input from. */
675 emacs_close (filefd
);
676 if (fd1
>= 0 && fd1
!= fd_error
)
684 report_file_error ("Doing vfork", Qnil
);
687 if (INTEGERP (buffer
))
692 /* If Emacs has been built with asynchronous subprocess support,
693 we don't need to do this, I think because it will then have
694 the facilities for handling SIGCHLD. */
695 wait_without_blocking ();
696 #endif /* subprocesses */
700 /* Enable sending signal if user quits below. */
701 call_process_exited
= 0;
703 #if defined(MSDOS) || defined(MAC_OS8)
704 /* MSDOS needs different cleanup information. */
705 record_unwind_protect (call_process_cleanup
,
706 Fcons (make_number (fd
[0]), build_string (tempfile
)));
708 record_unwind_protect (call_process_cleanup
,
709 Fcons (make_number (fd
[0]), make_number (pid
)));
710 #endif /* not MSDOS and not MAC_OS8 */
713 if (BUFFERP (buffer
))
714 Fset_buffer (buffer
);
718 /* If BUFFER is nil, we must read process output once and then
719 discard it, so setup coding system but with nil. */
720 setup_coding_system (Qnil
, &process_coding
);
724 Lisp_Object val
, *args2
;
727 if (!NILP (Vcoding_system_for_read
))
728 val
= Vcoding_system_for_read
;
731 if (EQ (coding_systems
, Qt
))
735 args2
= (Lisp_Object
*) alloca ((nargs
+ 1) * sizeof *args2
);
736 args2
[0] = Qcall_process
;
737 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
739 = Ffind_operation_coding_system (nargs
+ 1, args2
);
741 if (CONSP (coding_systems
))
742 val
= XCAR (coding_systems
);
743 else if (CONSP (Vdefault_process_coding_system
))
744 val
= XCAR (Vdefault_process_coding_system
);
748 setup_coding_system (Fcheck_coding_system (val
), &process_coding
);
749 /* In unibyte mode, character code conversion should not take
750 place but EOL conversion should. So, setup raw-text or one
751 of the subsidiary according to the information just setup. */
752 if (NILP (current_buffer
->enable_multibyte_characters
)
754 setup_raw_text_coding_system (&process_coding
);
756 process_coding
.src_multibyte
= 0;
757 process_coding
.dst_multibyte
759 ? ! NILP (XBUFFER (buffer
)->enable_multibyte_characters
)
760 : ! NILP (current_buffer
->enable_multibyte_characters
));
770 int display_on_the_fly
= display_p
;
771 struct coding_system saved_coding
;
772 int pt_orig
= PT
, pt_byte_orig
= PT_BYTE
;
775 saved_coding
= process_coding
;
776 if (process_coding
.composing
!= COMPOSITION_DISABLED
)
777 coding_allocate_composition_data (&process_coding
, PT
);
780 /* Repeatedly read until we've filled as much as possible
781 of the buffer size we have. But don't read
782 less than 1024--save that for the next bufferful. */
784 while (nread
< bufsize
- 1024)
786 int this_read
= emacs_read (fd
[0], buf
+ nread
,
794 process_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
799 total_read
+= this_read
;
801 if (display_on_the_fly
)
805 /* Now NREAD is the total amount of data in the buffer. */
810 if (! CODING_MAY_REQUIRE_DECODING (&process_coding
))
811 insert_1_both (buf
, nread
, nread
, 0, 1, 0);
813 { /* We have to decode the input. */
818 size
= decoding_buffer_size (&process_coding
, nread
);
819 decoding_buf
= (char *) xmalloc (size
);
821 /* We can't use the macro CODING_REQUIRE_DETECTION
822 because it always returns nonzero if the coding
823 system requires EOL detection. Here, we have to
824 check only whether or not the coding system
825 requires text-encoding detection. */
826 if (process_coding
.type
== coding_type_undecided
)
828 detect_coding (&process_coding
, buf
, nread
);
829 if (process_coding
.composing
!= COMPOSITION_DISABLED
)
830 /* We have not yet allocated the composition
831 data because the coding type was undecided. */
832 coding_allocate_composition_data (&process_coding
, PT
);
834 if (process_coding
.cmp_data
)
835 process_coding
.cmp_data
->char_offset
= PT
;
837 decode_coding (&process_coding
, buf
, decoding_buf
,
840 if (display_on_the_fly
841 && saved_coding
.type
== coding_type_undecided
842 && process_coding
.type
!= coding_type_undecided
)
844 /* We have detected some coding system. But,
845 there's a possibility that the detection was
846 done by insufficient data. So, we try the code
847 detection again with more data. */
848 xfree (decoding_buf
);
849 display_on_the_fly
= 0;
850 process_coding
= saved_coding
;
852 /* This is to make the above condition always
853 fails in the future. */
854 saved_coding
.type
= coding_type_no_conversion
;
858 if (process_coding
.produced
> 0)
859 insert_1_both (decoding_buf
, process_coding
.produced_char
,
860 process_coding
.produced
, 0, 1, 0);
861 xfree (decoding_buf
);
863 if (process_coding
.result
== CODING_FINISH_INCONSISTENT_EOL
)
865 Lisp_Object eol_type
, coding
;
867 if (process_coding
.eol_type
== CODING_EOL_CR
)
869 /* CRs have been replaced with LFs. Undo
870 that in the text inserted above. */
873 move_gap_both (PT
, PT_BYTE
);
875 p
= BYTE_POS_ADDR (pt_byte_orig
);
876 for (; p
< GPT_ADDR
; ++p
)
880 else if (process_coding
.eol_type
== CODING_EOL_CRLF
)
882 /* CR LFs have been replaced with LFs. Undo
883 that by inserting CRs in front of LFs in
884 the text inserted above. */
885 EMACS_INT bytepos
, old_pt
, old_pt_byte
, nCR
;
888 old_pt_byte
= PT_BYTE
;
891 for (bytepos
= PT_BYTE
- 1;
892 bytepos
>= pt_byte_orig
;
894 if (FETCH_BYTE (bytepos
) == '\n')
896 EMACS_INT charpos
= BYTE_TO_CHAR (bytepos
);
897 TEMP_SET_PT_BOTH (charpos
, bytepos
);
898 insert_1_both ("\r", 1, 1, 0, 1, 0);
902 TEMP_SET_PT_BOTH (old_pt
+ nCR
, old_pt_byte
+ nCR
);
905 /* Set the coding system symbol to that for
907 eol_type
= Fget (saved_coding
.symbol
, Qeol_type
);
908 if (VECTORP (eol_type
)
909 && ASIZE (eol_type
) == 3
910 && SYMBOLP (AREF (eol_type
, CODING_EOL_LF
)))
911 coding
= AREF (eol_type
, CODING_EOL_LF
);
913 coding
= saved_coding
.symbol
;
915 process_coding
.symbol
= coding
;
916 process_coding
.eol_type
= CODING_EOL_LF
;
918 &= ~CODING_MODE_INHIBIT_INCONSISTENT_EOL
;
921 nread
-= process_coding
.consumed
;
924 /* As CARRYOVER should not be that large, we had
925 better avoid overhead of bcopy. */
926 BCOPY_SHORT (buf
+ process_coding
.consumed
, buf
,
928 if (process_coding
.result
== CODING_FINISH_INSUFFICIENT_CMP
)
930 /* The decoding ended because of insufficient data
931 area to record information about composition.
932 We must try decoding with additional data area
933 before reading more output for the process. */
934 coding_allocate_composition_data (&process_coding
, PT
);
935 goto repeat_decoding
;
940 if (process_coding
.mode
& CODING_MODE_LAST_BLOCK
)
943 #if (CALLPROC_BUFFER_SIZE_MIN != CALLPROC_BUFFER_SIZE_MAX)
944 /* Make the buffer bigger as we continue to read more data,
945 but not past CALLPROC_BUFFER_SIZE_MAX. */
946 if (bufsize
< CALLPROC_BUFFER_SIZE_MAX
&& total_read
> 32 * bufsize
)
947 if ((bufsize
*= 2) > CALLPROC_BUFFER_SIZE_MAX
)
948 bufsize
= CALLPROC_BUFFER_SIZE_MAX
;
954 prepare_menu_bars ();
956 redisplay_preserve_echo_area (1);
957 /* This variable might have been set to 0 for code
958 detection. In that case, we set it back to 1 because
959 we should have already detected a coding system. */
960 display_on_the_fly
= 1;
968 && process_coding
.cmp_data
)
970 coding_restore_composition (&process_coding
, Fcurrent_buffer ());
971 coding_free_composition_data (&process_coding
);
975 int post_read_count
= SPECPDL_INDEX ();
977 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
978 inserted
= PT
- pt_orig
;
979 TEMP_SET_PT_BOTH (pt_orig
, pt_byte_orig
);
980 if (SYMBOLP (process_coding
.post_read_conversion
)
981 && !NILP (Ffboundp (process_coding
.post_read_conversion
)))
982 call1 (process_coding
.post_read_conversion
, make_number (inserted
));
984 Vlast_coding_system_used
= process_coding
.symbol
;
986 /* If the caller required, let the buffer inherit the
987 coding-system used to decode the process output. */
988 if (inherit_process_coding_system
)
989 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
990 make_number (total_read
));
992 unbind_to (post_read_count
, Qnil
);
996 /* Wait for it to terminate, unless it already has. */
997 wait_for_termination (pid
);
1001 set_buffer_internal (old
);
1003 /* Don't kill any children that the subprocess may have left behind
1005 call_process_exited
= 1;
1007 unbind_to (count
, Qnil
);
1009 if (synch_process_termsig
)
1013 synchronize_system_messages_locale ();
1014 signame
= strsignal (synch_process_termsig
);
1017 signame
= "unknown";
1019 synch_process_death
= signame
;
1022 if (synch_process_death
)
1023 return code_convert_string_norecord (build_string (synch_process_death
),
1024 Vlocale_coding_system
, 0);
1025 return make_number (synch_process_retcode
);
1030 delete_temp_file (name
)
1033 /* Suppress jka-compr handling, etc. */
1034 int count
= SPECPDL_INDEX ();
1035 specbind (intern ("file-name-handler-alist"), Qnil
);
1036 internal_delete_file (name
);
1037 unbind_to (count
, Qnil
);
1041 DEFUN ("call-process-region", Fcall_process_region
, Scall_process_region
,
1043 doc
: /* Send text from START to END to a synchronous process running PROGRAM.
1044 The remaining arguments are optional.
1045 Delete the text if fourth arg DELETE is non-nil.
1047 Insert output in BUFFER before point; t means current buffer;
1048 nil for BUFFER means discard it; 0 means discard and don't wait.
1049 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
1050 REAL-BUFFER says what to do with standard output, as above,
1051 while STDERR-FILE says what to do with standard error in the child.
1052 STDERR-FILE may be nil (discard standard error output),
1053 t (mix it with ordinary output), or a file name string.
1055 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.
1056 Remaining args are passed to PROGRAM at startup as command args.
1058 If BUFFER is 0, `call-process-region' returns immediately with value nil.
1059 Otherwise it waits for PROGRAM to terminate
1060 and returns a numeric exit status or a signal description string.
1061 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
1063 usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
1066 register Lisp_Object
*args
;
1068 struct gcpro gcpro1
;
1069 Lisp_Object filename_string
;
1070 register Lisp_Object start
, end
;
1071 int count
= SPECPDL_INDEX ();
1072 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
1073 Lisp_Object coding_systems
;
1074 Lisp_Object val
, *args2
;
1080 if ((outf
= egetenv ("TMPDIR"))
1081 || (outf
= egetenv ("TMP"))
1082 || (outf
= egetenv ("TEMP")))
1083 strcpy (tempfile
= alloca (strlen (outf
) + 20), outf
);
1086 tempfile
= alloca (20);
1089 if (!IS_DIRECTORY_SEP (tempfile
[strlen (tempfile
) - 1]))
1090 strcat (tempfile
, "/");
1091 if ('/' == DIRECTORY_SEP
)
1092 dostounix_filename (tempfile
);
1094 unixtodos_filename (tempfile
);
1096 strcat (tempfile
, "emXXXXXX");
1098 strcat (tempfile
, "detmp.XXX");
1100 #else /* not DOS_NT */
1101 char *tempfile
= (char *) alloca (SBYTES (Vtemp_file_name_pattern
) + 1);
1102 bcopy (SDATA (Vtemp_file_name_pattern
), tempfile
,
1103 SBYTES (Vtemp_file_name_pattern
) + 1);
1104 #endif /* not DOS_NT */
1106 coding_systems
= Qt
;
1110 int fd
= mkstemp (tempfile
);
1112 report_file_error ("Failed to open temporary file",
1113 Fcons (Vtemp_file_name_pattern
, Qnil
));
1121 filename_string
= build_string (tempfile
);
1122 GCPRO1 (filename_string
);
1125 /* Decide coding-system of the contents of the temporary file. */
1126 if (!NILP (Vcoding_system_for_write
))
1127 val
= Vcoding_system_for_write
;
1128 else if (NILP (current_buffer
->enable_multibyte_characters
))
1132 args2
= (Lisp_Object
*) alloca ((nargs
+ 1) * sizeof *args2
);
1133 args2
[0] = Qcall_process_region
;
1134 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
1135 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1136 if (CONSP (coding_systems
))
1137 val
= XCDR (coding_systems
);
1138 else if (CONSP (Vdefault_process_coding_system
))
1139 val
= XCDR (Vdefault_process_coding_system
);
1145 int count1
= SPECPDL_INDEX ();
1147 specbind (intern ("coding-system-for-write"), val
);
1148 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
1149 happen to get a ".Z" suffix. */
1150 specbind (intern ("file-name-handler-alist"), Qnil
);
1151 Fwrite_region (start
, end
, filename_string
, Qnil
, Qlambda
, Qnil
, Qnil
);
1153 unbind_to (count1
, Qnil
);
1156 /* Note that Fcall_process takes care of binding
1157 coding-system-for-read. */
1159 record_unwind_protect (delete_temp_file
, filename_string
);
1161 if (nargs
> 3 && !NILP (args
[3]))
1162 Fdelete_region (start
, end
);
1174 args
[1] = filename_string
;
1176 RETURN_UNGCPRO (unbind_to (count
, Fcall_process (nargs
, args
)));
1179 #ifndef VMS /* VMS version is in vmsproc.c. */
1181 static int relocate_fd ();
1184 add_env (char **env
, char **new_env
, char *string
)
1191 /* See if this string duplicates any string already in the env.
1192 If so, don't put it in.
1193 When an env var has multiple definitions,
1194 we keep the definition that comes first in process-environment. */
1195 for (ep
= env
; ok
&& ep
!= new_env
; ep
++)
1197 char *p
= *ep
, *q
= string
;
1203 /* The string is a lone variable name; keep it for now, we
1204 will remove it later. It is a placeholder for a
1205 variable that is not to be included in the environment. */
1213 *new_env
++ = string
;
1217 /* This is the last thing run in a newly forked inferior
1218 either synchronous or asynchronous.
1219 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
1220 Initialize inferior's priority, pgrp, connected dir and environment.
1221 then exec another program based on new_argv.
1223 This function may change environ for the superior process.
1224 Therefore, the superior process must save and restore the value
1225 of environ around the vfork and the call to this function.
1227 SET_PGRP is nonzero if we should put the subprocess into a separate
1230 CURRENT_DIR is an elisp string giving the path of the current
1231 directory the subprocess should have. Since we can't really signal
1232 a decent error from within the child, this should be verified as an
1233 executable directory by the parent. */
1236 child_setup (in
, out
, err
, new_argv
, set_pgrp
, current_dir
)
1238 register char **new_argv
;
1240 Lisp_Object current_dir
;
1247 #endif /* WINDOWSNT */
1249 int pid
= getpid ();
1251 #ifdef SET_EMACS_PRIORITY
1253 extern EMACS_INT emacs_priority
;
1255 if (emacs_priority
< 0)
1256 nice (- emacs_priority
);
1261 /* Close Emacs's descriptors that this process should not have. */
1262 close_process_descs ();
1264 /* DOS_NT isn't in a vfork, so if we are in the middle of load-file,
1265 we will lose if we call close_load_descs here. */
1267 close_load_descs ();
1270 /* Note that use of alloca is always safe here. It's obvious for systems
1271 that do not have true vfork or that have true (stack) alloca.
1272 If using vfork and C_ALLOCA it is safe because that changes
1273 the superior's static variables as if the superior had done alloca
1274 and will be cleaned up in the usual way. */
1276 register char *temp
;
1279 i
= SBYTES (current_dir
);
1281 /* MSDOS must have all environment variables malloc'ed, because
1282 low-level libc functions that launch subsidiary processes rely
1284 pwd_var
= (char *) xmalloc (i
+ 6);
1286 pwd_var
= (char *) alloca (i
+ 6);
1289 bcopy ("PWD=", pwd_var
, 4);
1290 bcopy (SDATA (current_dir
), temp
, i
);
1291 if (!IS_DIRECTORY_SEP (temp
[i
- 1])) temp
[i
++] = DIRECTORY_SEP
;
1295 /* We can't signal an Elisp error here; we're in a vfork. Since
1296 the callers check the current directory before forking, this
1297 should only return an error if the directory's permissions
1298 are changed between the check and this chdir, but we should
1300 if (chdir (temp
) < 0)
1305 /* Get past the drive letter, so that d:/ is left alone. */
1306 if (i
> 2 && IS_DEVICE_SEP (temp
[1]) && IS_DIRECTORY_SEP (temp
[2]))
1313 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1314 while (i
> 2 && IS_DIRECTORY_SEP (temp
[i
- 1]))
1318 /* Set `env' to a vector of the strings in the environment. */
1320 register Lisp_Object tem
;
1321 register char **new_env
;
1323 register int new_length
;
1324 Lisp_Object environment
= Vglobal_environment
;
1329 for (tem
= Vprocess_environment
;
1330 CONSP (tem
) && STRINGP (XCAR (tem
));
1334 if (!NILP (Vlocal_environment_variables
))
1336 local
= get_frame_param (XFRAME (Fframe_with_environment (selected_frame
)),
1338 if (EQ (Vlocal_environment_variables
, Qt
)
1340 environment
= local
;
1341 else if (CONSP (local
))
1343 new_length
+= Fsafe_length (Vlocal_environment_variables
);
1347 for (tem
= environment
;
1348 CONSP (tem
) && STRINGP (XCAR (tem
));
1352 /* new_length + 2 to include PWD and terminating 0. */
1353 env
= new_env
= (char **) alloca ((new_length
+ 2) * sizeof (char *));
1355 /* If we have a PWD envvar, pass one down,
1356 but with corrected value. */
1358 *new_env
++ = pwd_var
;
1361 for (tem
= Vprocess_environment
;
1362 CONSP (tem
) && STRINGP (XCAR (tem
));
1364 new_env
= add_env (env
, new_env
, SDATA (XCAR (tem
)));
1366 /* Local part of environment, if Vlocal_environment_variables is a list. */
1367 for (tem
= Vlocal_environment_variables
;
1368 CONSP (tem
) && STRINGP (XCAR (tem
));
1370 new_env
= add_env (env
, new_env
, egetenv (SDATA (XCAR (tem
))));
1372 /* The rest of the environment (either Vglobal_environment or the
1373 'environment frame parameter). */
1374 for (tem
= environment
;
1375 CONSP (tem
) && STRINGP (XCAR (tem
));
1377 new_env
= add_env (env
, new_env
, SDATA (XCAR (tem
)));
1381 /* Remove variable names without values. */
1385 while (*q
!= 0 && strchr (*q
, '=') == NULL
)
1393 prepare_standard_handles (in
, out
, err
, handles
);
1394 set_process_dir (SDATA (current_dir
));
1395 #else /* not WINDOWSNT */
1396 /* Make sure that in, out, and err are not actually already in
1397 descriptors zero, one, or two; this could happen if Emacs is
1398 started with its standard in, out, or error closed, as might
1401 int oin
= in
, oout
= out
;
1403 /* We have to avoid relocating the same descriptor twice! */
1405 in
= relocate_fd (in
, 3);
1410 out
= relocate_fd (out
, 3);
1414 else if (err
== oout
)
1417 err
= relocate_fd (err
, 3);
1431 #endif /* not MSDOS */
1432 #endif /* not WINDOWSNT */
1434 #if defined(USG) && !defined(BSD_PGRPS)
1435 #ifndef SETPGRP_RELEASES_CTTY
1436 setpgrp (); /* No arguments but equivalent in this case */
1441 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
1442 EMACS_SET_TTY_PGRP (0, &pid
);
1445 pid
= run_msdos_command (new_argv
, pwd_var
+ 4, in
, out
, err
, env
);
1448 /* An error occurred while trying to run the subprocess. */
1449 report_file_error ("Spawning child process", Qnil
);
1451 #else /* not MSDOS */
1453 /* Spawn the child. (See ntproc.c:Spawnve). */
1454 cpid
= spawnve (_P_NOWAIT
, new_argv
[0], new_argv
, env
);
1455 reset_standard_handles (in
, out
, err
, handles
);
1457 /* An error occurred while trying to spawn the process. */
1458 report_file_error ("Spawning child process", Qnil
);
1460 #else /* not WINDOWSNT */
1461 /* execvp does not accept an environment arg so the only way
1462 to pass this environment is to set environ. Our caller
1463 is responsible for restoring the ambient value of environ. */
1465 execvp (new_argv
[0], new_argv
);
1467 emacs_write (1, "Can't exec program: ", 20);
1468 emacs_write (1, new_argv
[0], strlen (new_argv
[0]));
1469 emacs_write (1, "\n", 1);
1471 #endif /* not WINDOWSNT */
1472 #endif /* not MSDOS */
1475 /* Move the file descriptor FD so that its number is not less than MINFD.
1476 If the file descriptor is moved at all, the original is freed. */
1478 relocate_fd (fd
, minfd
)
1488 char *message1
= "Error while setting up child: ";
1489 char *errmessage
= strerror (errno
);
1490 char *message2
= "\n";
1491 emacs_write (2, message1
, strlen (message1
));
1492 emacs_write (2, errmessage
, strlen (errmessage
));
1493 emacs_write (2, message2
, strlen (message2
));
1496 /* Note that we hold the original FD open while we recurse,
1497 to guarantee we'll get a new FD if we need it. */
1498 new = relocate_fd (new, minfd
);
1505 getenv_internal (var
, varlen
, value
, valuelen
, frame
)
1513 Lisp_Object environment
= Vglobal_environment
;
1515 /* Try to find VAR in Vprocess_environment first. */
1516 for (scan
= Vprocess_environment
; CONSP (scan
); scan
= XCDR (scan
))
1518 Lisp_Object entry
= XCAR (scan
);
1520 && SBYTES (entry
) >= varlen
1522 /* NT environment variables are case insensitive. */
1523 && ! strnicmp (SDATA (entry
), var
, varlen
)
1524 #else /* not WINDOWSNT */
1525 && ! bcmp (SDATA (entry
), var
, varlen
)
1526 #endif /* not WINDOWSNT */
1529 if (SBYTES (entry
) > varlen
&& SREF (entry
, varlen
) == '=')
1531 *value
= (char *) SDATA (entry
) + (varlen
+ 1);
1532 *valuelen
= SBYTES (entry
) - (varlen
+ 1);
1535 else if (SBYTES (entry
) == varlen
)
1537 /* Lone variable names in Vprocess_environment mean that
1538 variable should be removed from the environment. */
1544 /* Find the environment in which to search the variable. */
1549 CHECK_FRAME (frame
);
1550 frame
= Fframe_with_environment (frame
);
1551 local
= get_frame_param (XFRAME (frame
), Qenvironment
);
1552 /* Use Vglobal_environment if there is no local environment. */
1554 environment
= local
;
1556 else if (!NILP (Vlocal_environment_variables
))
1558 Lisp_Object local
= get_frame_param (XFRAME (Fframe_with_environment (selected_frame
)),
1560 if (EQ (Vlocal_environment_variables
, Qt
)
1562 environment
= local
;
1563 else if (CONSP (local
))
1565 for (scan
= Vlocal_environment_variables
; CONSP (scan
); scan
= XCDR (scan
))
1567 Lisp_Object entry
= XCAR (scan
);
1569 && SBYTES (entry
) == varlen
1571 /* NT environment variables are case insensitive. */
1572 && ! strnicmp (SDATA (entry
), var
, varlen
)
1573 #else /* not WINDOWSNT */
1574 && ! bcmp (SDATA (entry
), var
, varlen
)
1575 #endif /* not WINDOWSNT */
1578 environment
= local
;
1585 for (scan
= environment
; CONSP (scan
); scan
= XCDR (scan
))
1589 entry
= XCAR (scan
);
1591 && SBYTES (entry
) > varlen
1592 && SREF (entry
, varlen
) == '='
1594 /* NT environment variables are case insensitive. */
1595 && ! strnicmp (SDATA (entry
), var
, varlen
)
1596 #else /* not WINDOWSNT */
1597 && ! bcmp (SDATA (entry
), var
, varlen
)
1598 #endif /* not WINDOWSNT */
1601 *value
= (char *) SDATA (entry
) + (varlen
+ 1);
1602 *valuelen
= SBYTES (entry
) - (varlen
+ 1);
1610 DEFUN ("getenv-internal", Fgetenv_internal
, Sgetenv_internal
, 1, 2, 0,
1611 doc
: /* Get the value of environment variable VARIABLE.
1612 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1613 the environment. Otherwise, value is a string.
1615 If optional parameter FRAME is non-nil, then it should be a frame. If
1616 that frame has its own set of environment variables, this function
1617 will look up VARIABLE in there.
1619 Otherwise, this function searches `process-environment' for VARIABLE.
1620 If it is not found there, then it continues the search in either
1621 `global-environment' or the environment list of the selected frame,
1622 depending on the value of `local-environment-variables'. */)
1624 Lisp_Object variable
, frame
;
1629 CHECK_STRING (variable
);
1630 if (getenv_internal (SDATA (variable
), SBYTES (variable
),
1631 &value
, &valuelen
, frame
))
1632 return make_string (value
, valuelen
);
1637 /* A version of getenv that consults the Lisp environment lists,
1638 easily callable from C. */
1646 if (getenv_internal (var
, strlen (var
), &value
, &valuelen
, Qnil
))
1652 #endif /* not VMS */
1654 /* This is run before init_cmdargs. */
1659 char *data_dir
= egetenv ("EMACSDATA");
1660 char *doc_dir
= egetenv ("EMACSDOC");
1663 = Ffile_name_as_directory (build_string (data_dir
? data_dir
1666 = Ffile_name_as_directory (build_string (doc_dir
? doc_dir
1669 /* Check the EMACSPATH environment variable, defaulting to the
1670 PATH_EXEC path from epaths.h. */
1671 Vexec_path
= decode_env_path ("EMACSPATH", PATH_EXEC
);
1672 Vexec_directory
= Ffile_name_as_directory (Fcar (Vexec_path
));
1673 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1676 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1681 char *data_dir
= egetenv ("EMACSDATA");
1684 Lisp_Object tempdir
;
1686 if (!NILP (Vinstallation_directory
))
1688 /* Add to the path the lib-src subdir of the installation dir. */
1690 tem
= Fexpand_file_name (build_string ("lib-src"),
1691 Vinstallation_directory
);
1693 /* MSDOS uses wrapped binaries, so don't do this. */
1694 if (NILP (Fmember (tem
, Vexec_path
)))
1696 Vexec_path
= decode_env_path ("EMACSPATH", PATH_EXEC
);
1697 Vexec_path
= Fcons (tem
, Vexec_path
);
1698 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1701 Vexec_directory
= Ffile_name_as_directory (tem
);
1702 #endif /* not DOS_NT */
1704 /* Maybe use ../etc as well as ../lib-src. */
1707 tem
= Fexpand_file_name (build_string ("etc"),
1708 Vinstallation_directory
);
1709 Vdoc_directory
= Ffile_name_as_directory (tem
);
1713 /* Look for the files that should be in etc. We don't use
1714 Vinstallation_directory, because these files are never installed
1715 near the executable, and they are never in the build
1716 directory when that's different from the source directory.
1718 Instead, if these files are not in the nominal place, we try the
1719 source directory. */
1722 Lisp_Object tem
, tem1
, srcdir
;
1724 srcdir
= Fexpand_file_name (build_string ("../src/"),
1725 build_string (PATH_DUMPLOADSEARCH
));
1726 tem
= Fexpand_file_name (build_string ("GNU"), Vdata_directory
);
1727 tem1
= Ffile_exists_p (tem
);
1728 if (!NILP (Fequal (srcdir
, Vinvocation_directory
)) || NILP (tem1
))
1731 newdir
= Fexpand_file_name (build_string ("../etc/"),
1732 build_string (PATH_DUMPLOADSEARCH
));
1733 tem
= Fexpand_file_name (build_string ("GNU"), newdir
);
1734 tem1
= Ffile_exists_p (tem
);
1736 Vdata_directory
= newdir
;
1744 tempdir
= Fdirectory_file_name (Vexec_directory
);
1745 if (access (SDATA (tempdir
), 0) < 0)
1746 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n",
1750 tempdir
= Fdirectory_file_name (Vdata_directory
);
1751 if (access (SDATA (tempdir
), 0) < 0)
1752 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n",
1756 Vshell_file_name
= build_string ("*dcl*");
1758 sh
= (char *) getenv ("SHELL");
1759 Vshell_file_name
= build_string (sh
? sh
: "/bin/sh");
1763 Vtemp_file_name_pattern
= build_string ("tmp:emacsXXXXXX.");
1765 if (getenv ("TMPDIR"))
1767 char *dir
= getenv ("TMPDIR");
1768 Vtemp_file_name_pattern
1769 = Fexpand_file_name (build_string ("emacsXXXXXX"),
1770 build_string (dir
));
1773 Vtemp_file_name_pattern
= build_string ("/tmp/emacsXXXXXX");
1777 Vshared_game_score_directory
= Qnil
;
1779 Vshared_game_score_directory
= build_string (PATH_GAME
);
1780 if (NILP (Ffile_directory_p (Vshared_game_score_directory
)))
1781 Vshared_game_score_directory
= Qnil
;
1786 set_global_environment ()
1788 register char **envp
;
1790 Vglobal_environment
= Qnil
;
1794 for (envp
= environ
; *envp
; envp
++)
1795 Vglobal_environment
= Fcons (build_string (*envp
),
1796 Vglobal_environment
);
1803 Qbuffer_file_type
= intern ("buffer-file-type");
1804 staticpro (&Qbuffer_file_type
);
1807 DEFVAR_LISP ("shell-file-name", &Vshell_file_name
,
1808 doc
: /* *File name to load inferior shells from.
1809 Initialized from the SHELL environment variable. */);
1811 DEFVAR_LISP ("exec-path", &Vexec_path
,
1812 doc
: /* *List of directories to search programs to run in subprocesses.
1813 Each element is a string (directory name) or nil (try default directory). */);
1815 DEFVAR_LISP ("exec-suffixes", &Vexec_suffixes
,
1816 doc
: /* *List of suffixes to try to find executable file names.
1817 Each element is a string. */);
1818 Vexec_suffixes
= Qnil
;
1820 DEFVAR_LISP ("exec-directory", &Vexec_directory
,
1821 doc
: /* Directory for executables for Emacs to invoke.
1822 More generally, this includes any architecture-dependent files
1823 that are built and installed from the Emacs distribution. */);
1825 DEFVAR_LISP ("data-directory", &Vdata_directory
,
1826 doc
: /* Directory of machine-independent files that come with GNU Emacs.
1827 These are files intended for Emacs to use while it runs. */);
1829 DEFVAR_LISP ("doc-directory", &Vdoc_directory
,
1830 doc
: /* Directory containing the DOC file that comes with GNU Emacs.
1831 This is usually the same as data-directory. */);
1833 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory
,
1834 doc
: /* For internal use by the build procedure only.
1835 This is the name of the directory in which the build procedure installed
1836 Emacs's info files; the default value for Info-default-directory-list
1838 Vconfigure_info_directory
= build_string (PATH_INFO
);
1840 DEFVAR_LISP ("shared-game-score-directory", &Vshared_game_score_directory
,
1841 doc
: /* Directory of score files for games which come with GNU Emacs.
1842 If this variable is nil, then Emacs is unable to use a shared directory. */);
1844 Vshared_game_score_directory
= Qnil
;
1846 Vshared_game_score_directory
= build_string (PATH_GAME
);
1849 DEFVAR_LISP ("temp-file-name-pattern", &Vtemp_file_name_pattern
,
1850 doc
: /* Pattern for making names for temporary files.
1851 This is used by `call-process-region'. */);
1852 /* This variable is initialized in init_callproc. */
1854 DEFVAR_LISP ("global-environment", &Vglobal_environment
,
1855 doc
: /* Global list of environment variables for subprocesses to inherit.
1856 Each element should be a string of the form ENVVARNAME=VALUE.
1858 The environment which Emacs inherits is placed in this variable when
1861 Some frames may have their own local list of environment variables in
1862 their 'environment parameter, which may override this global list; see
1863 `local-environment-variables' and `frame-with-environment'. See
1864 `process-environment' for a way to modify an environment variable on
1867 If multiple entries define the same variable, the first one always
1870 Non-ASCII characters are encoded according to the initial value of
1871 `locale-coding-system', i.e. the elements must normally be decoded for use.
1872 See `setenv' and `getenv'. */);
1874 DEFVAR_LISP ("process-environment", &Vprocess_environment
,
1875 doc
: /* List of overridden environment variables for subprocesses to inherit.
1876 Each element should be a string of the form ENVVARNAME=VALUE.
1878 Entries in this list take precedence to those in `global-environment'
1879 or the frame-local environments. (See `local-environment-variables'
1880 and `frame-with-environment'.) Therefore, let-binding
1881 `process-environment' is an easy way to temporarily change the value
1882 of an environment variable, irrespective of where it comes from. To
1883 use `process-environment' to remove an environment variable, include
1884 only its name in the list, without "=VALUE".
1886 This variable is set to nil when Emacs starts.
1888 If multiple entries define the same variable, the first one always
1891 Non-ASCII characters are encoded according to the initial value of
1892 `locale-coding-system', i.e. the elements must normally be decoded for
1895 See `setenv' and `getenv'. */);
1896 Vprocess_environment
= Qnil
;
1899 defsubr (&Scall_process
);
1900 defsubr (&Sgetenv_internal
);
1902 defsubr (&Scall_process_region
);
1904 DEFVAR_LISP ("local-environment-variables", &Vlocal_environment_variables
,
1905 doc
: /* Enable or disable frame-local environment variables.
1906 If set to t, `getenv', `setenv' and subprocess creation functions use
1907 the local environment of the selected frame, ignoring
1908 `global-environment'.
1910 If set to nil, Emacs uses `global-environment' and ignores the
1911 frame-local environment.
1913 Otherwise, `local-environment-variables' should be a list of variable
1914 names (represented by Lisp strings) to look up in the frame's
1915 environment. The rest will come from `global-environment'.
1917 The frame-local environment is stored in the 'environment frame
1918 parameter. See `frame-with-environment'. */);
1919 Vlocal_environment_variables
= Qt
;
1922 /* arch-tag: 769b8045-1df7-4d2b-8968-e3fb49017f95
1923 (do not change this comment) */