Delete the system-independent include of stdlib.h
[bpt/emacs.git] / src / callproc.c
1 /* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
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.
10
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.
15
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. */
20
21
22 #include <signal.h>
23 #include <errno.h>
24
25 #include <config.h>
26 #include <stdio.h>
27
28 extern int errno;
29 extern char *strerror ();
30
31 /* Define SIGCHLD as an alias for SIGCLD. */
32
33 #if !defined (SIGCHLD) && defined (SIGCLD)
34 #define SIGCHLD SIGCLD
35 #endif /* SIGCLD */
36
37 #include <sys/types.h>
38
39 #include <sys/file.h>
40 #ifdef USG5
41 #define INCLUDED_FCNTL
42 #include <fcntl.h>
43 #endif
44
45 #ifdef WINDOWSNT
46 #define NOMINMAX
47 #include <windows.h>
48 #include <stdlib.h> /* for proper declaration of environ */
49 #include <fcntl.h>
50 #include "w32.h"
51 #define _P_NOWAIT 1 /* from process.h */
52 #endif
53
54 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
55 #define INCLUDED_FCNTL
56 #include <fcntl.h>
57 #include <sys/stat.h>
58 #include <sys/param.h>
59 #include <errno.h>
60 #endif /* MSDOS */
61
62 #ifndef O_RDONLY
63 #define O_RDONLY 0
64 #endif
65
66 #ifndef O_WRONLY
67 #define O_WRONLY 1
68 #endif
69
70 #include "lisp.h"
71 #include "commands.h"
72 #include "buffer.h"
73 #include "charset.h"
74 #include "ccl.h"
75 #include "coding.h"
76 #include <epaths.h>
77 #include "process.h"
78 #include "syssignal.h"
79 #include "systty.h"
80
81 #ifdef MSDOS
82 #include "msdos.h"
83 #endif
84
85 #ifdef VMS
86 extern noshare char **environ;
87 #else
88 extern char **environ;
89 #endif
90
91 #define max(a, b) ((a) > (b) ? (a) : (b))
92
93 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory, Vdoc_directory;
94 Lisp_Object Vconfigure_info_directory;
95 Lisp_Object Vtemp_file_name_pattern;
96
97 Lisp_Object Vshell_file_name;
98
99 Lisp_Object Vprocess_environment;
100
101 #ifdef DOS_NT
102 Lisp_Object Qbuffer_file_type;
103 #endif /* DOS_NT */
104
105 /* True iff we are about to fork off a synchronous process or if we
106 are waiting for it. */
107 int synch_process_alive;
108
109 /* Nonzero => this is a string explaining death of synchronous subprocess. */
110 char *synch_process_death;
111
112 /* If synch_process_death is zero,
113 this is exit code of synchronous subprocess. */
114 int synch_process_retcode;
115
116 extern Lisp_Object Vdoc_file_name;
117
118 extern Lisp_Object Vfile_name_coding_system, Vdefault_file_name_coding_system;
119 \f
120 /* Clean up when exiting Fcall_process.
121 On MSDOS, delete the temporary file on any kind of termination.
122 On Unix, kill the process and any children on termination by signal. */
123
124 /* Nonzero if this is termination due to exit. */
125 static int call_process_exited;
126
127 #ifndef VMS /* VMS version is in vmsproc.c. */
128
129 static Lisp_Object
130 call_process_kill (fdpid)
131 Lisp_Object fdpid;
132 {
133 close (XFASTINT (Fcar (fdpid)));
134 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL);
135 synch_process_alive = 0;
136 return Qnil;
137 }
138
139 Lisp_Object
140 call_process_cleanup (fdpid)
141 Lisp_Object fdpid;
142 {
143 #ifdef MSDOS
144 /* for MSDOS fdpid is really (fd . tempfile) */
145 register Lisp_Object file;
146 file = Fcdr (fdpid);
147 close (XFASTINT (Fcar (fdpid)));
148 if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0)
149 unlink (XSTRING (file)->data);
150 #else /* not MSDOS */
151 register int pid = XFASTINT (Fcdr (fdpid));
152
153
154 if (call_process_exited)
155 {
156 close (XFASTINT (Fcar (fdpid)));
157 return Qnil;
158 }
159
160 if (EMACS_KILLPG (pid, SIGINT) == 0)
161 {
162 int count = specpdl_ptr - specpdl;
163 record_unwind_protect (call_process_kill, fdpid);
164 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
165 immediate_quit = 1;
166 QUIT;
167 wait_for_termination (pid);
168 immediate_quit = 0;
169 specpdl_ptr = specpdl + count; /* Discard the unwind protect. */
170 message1 ("Waiting for process to die...done");
171 }
172 synch_process_alive = 0;
173 close (XFASTINT (Fcar (fdpid)));
174 #endif /* not MSDOS */
175 return Qnil;
176 }
177
178 DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
179 "Call PROGRAM synchronously in separate process.\n\
180 The remaining arguments are optional.\n\
181 The program's input comes from file INFILE (nil means `/dev/null').\n\
182 Insert output in BUFFER before point; t means current buffer;\n\
183 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
184 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
185 REAL-BUFFER says what to do with standard output, as above,\n\
186 while STDERR-FILE says what to do with standard error in the child.\n\
187 STDERR-FILE may be nil (discard standard error output),\n\
188 t (mix it with ordinary output), or a file name string.\n\
189 \n\
190 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
191 Remaining arguments are strings passed as command arguments to PROGRAM.\n\
192 \n\
193 If BUFFER is 0, `call-process' returns immediately with value nil.\n\
194 Otherwise it waits for PROGRAM to terminate\n\
195 and returns a numeric exit status or a signal description string.\n\
196 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
197 (nargs, args)
198 int nargs;
199 register Lisp_Object *args;
200 {
201 Lisp_Object infile, buffer, current_dir, display, path;
202 int fd[2];
203 int filefd;
204 register int pid;
205 char buf[16384];
206 char *bufptr = buf;
207 int bufsize = 16384;
208 int count = specpdl_ptr - specpdl;
209
210 register unsigned char **new_argv
211 = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *));
212 struct buffer *old = current_buffer;
213 /* File to use for stderr in the child.
214 t means use same as standard output. */
215 Lisp_Object error_file;
216 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
217 char *outf, *tempfile;
218 int outfilefd;
219 #endif
220 #if 0
221 int mask;
222 #endif
223 struct coding_system process_coding; /* coding-system of process output */
224 struct coding_system argument_coding; /* coding-system of arguments */
225 /* Set to the return value of Ffind_operation_coding_system. */
226 Lisp_Object coding_systems;
227
228 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
229 coding_systems = Qt;
230
231 CHECK_STRING (args[0], 0);
232
233 error_file = Qt;
234
235 #ifndef subprocesses
236 /* Without asynchronous processes we cannot have BUFFER == 0. */
237 if (nargs >= 3
238 && (INTEGERP (CONSP (args[2]) ? XCAR (args[2]) : args[2])))
239 error ("Operating system cannot handle asynchronous subprocesses");
240 #endif /* subprocesses */
241
242 /* Decide the coding-system for giving arguments. */
243 {
244 Lisp_Object val, *args2;
245 int i;
246
247 /* If arguments are supplied, we may have to encode them. */
248 if (nargs >= 5)
249 {
250 int must_encode = 0;
251
252 for (i = 4; i < nargs; i++)
253 CHECK_STRING (args[i], i);
254
255 for (i = 4; i < nargs; i++)
256 if (STRING_MULTIBYTE (args[i]))
257 must_encode = 1;
258
259 if (!NILP (Vcoding_system_for_write))
260 val = Vcoding_system_for_write;
261 else if (! must_encode)
262 val = Qnil;
263 else
264 {
265 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
266 args2[0] = Qcall_process;
267 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
268 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
269 if (CONSP (coding_systems))
270 val = XCONS (coding_systems)->cdr;
271 else if (CONSP (Vdefault_process_coding_system))
272 val = XCONS (Vdefault_process_coding_system)->cdr;
273 else
274 val = Qnil;
275 }
276 setup_coding_system (Fcheck_coding_system (val), &argument_coding);
277 }
278 }
279
280 if (nargs >= 2 && ! NILP (args[1]))
281 {
282 infile = Fexpand_file_name (args[1], current_buffer->directory);
283 CHECK_STRING (infile, 1);
284 }
285 else
286 infile = build_string (NULL_DEVICE);
287
288 if (nargs >= 3)
289 {
290 buffer = args[2];
291
292 /* If BUFFER is a list, its meaning is
293 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
294 if (CONSP (buffer))
295 {
296 if (CONSP (XCONS (buffer)->cdr))
297 {
298 Lisp_Object stderr_file;
299 stderr_file = XCONS (XCONS (buffer)->cdr)->car;
300
301 if (NILP (stderr_file) || EQ (Qt, stderr_file))
302 error_file = stderr_file;
303 else
304 error_file = Fexpand_file_name (stderr_file, Qnil);
305 }
306
307 buffer = XCONS (buffer)->car;
308 }
309
310 if (!(EQ (buffer, Qnil)
311 || EQ (buffer, Qt)
312 || INTEGERP (buffer)))
313 {
314 Lisp_Object spec_buffer;
315 spec_buffer = buffer;
316 buffer = Fget_buffer_create (buffer);
317 /* Mention the buffer name for a better error message. */
318 if (NILP (buffer))
319 CHECK_BUFFER (spec_buffer, 2);
320 CHECK_BUFFER (buffer, 2);
321 }
322 }
323 else
324 buffer = Qnil;
325
326 /* Make sure that the child will be able to chdir to the current
327 buffer's current directory, or its unhandled equivalent. We
328 can't just have the child check for an error when it does the
329 chdir, since it's in a vfork.
330
331 We have to GCPRO around this because Fexpand_file_name,
332 Funhandled_file_name_directory, and Ffile_accessible_directory_p
333 might call a file name handling function. The argument list is
334 protected by the caller, so all we really have to worry about is
335 buffer. */
336 {
337 struct gcpro gcpro1, gcpro2, gcpro3;
338
339 current_dir = current_buffer->directory;
340
341 GCPRO3 (infile, buffer, current_dir);
342
343 current_dir
344 = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
345 Qnil);
346 if (NILP (Ffile_accessible_directory_p (current_dir)))
347 report_file_error ("Setting current directory",
348 Fcons (current_buffer->directory, Qnil));
349
350 UNGCPRO;
351 }
352
353 display = nargs >= 4 ? args[3] : Qnil;
354
355 filefd = open (XSTRING (infile)->data, O_RDONLY, 0);
356 if (filefd < 0)
357 {
358 report_file_error ("Opening process input file", Fcons (infile, Qnil));
359 }
360 /* Search for program; barf if not found. */
361 {
362 struct gcpro gcpro1;
363
364 GCPRO1 (current_dir);
365 openp (Vexec_path, args[0], EXEC_SUFFIXES, &path, 1);
366 UNGCPRO;
367 }
368 if (NILP (path))
369 {
370 close (filefd);
371 report_file_error ("Searching for program", Fcons (args[0], Qnil));
372 }
373 new_argv[0] = XSTRING (path)->data;
374 if (nargs > 4)
375 {
376 register int i;
377
378 if (! CODING_REQUIRE_ENCODING (&argument_coding))
379 {
380 for (i = 4; i < nargs; i++)
381 new_argv[i - 3] = XSTRING (args[i])->data;
382 }
383 else
384 {
385 /* We must encode the arguments. */
386 struct gcpro gcpro1, gcpro2, gcpro3;
387
388 GCPRO3 (infile, buffer, current_dir);
389 for (i = 4; i < nargs; i++)
390 {
391 int size = encoding_buffer_size (&argument_coding,
392 STRING_BYTES (XSTRING (args[i])));
393 unsigned char *dummy1 = (unsigned char *) alloca (size);
394 int dummy;
395
396 /* The Irix 4.0 compiler barfs if we eliminate dummy. */
397 new_argv[i - 3] = dummy1;
398 argument_coding.mode |= CODING_MODE_LAST_BLOCK;
399 encode_coding (&argument_coding,
400 XSTRING (args[i])->data,
401 new_argv[i - 3],
402 STRING_BYTES (XSTRING (args[i])),
403 size);
404 new_argv[i - 3][argument_coding.produced] = 0;
405 /* We have to initialize CCL program status again. */
406 if (argument_coding.type == coding_type_ccl)
407 setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil);
408 }
409 UNGCPRO;
410 }
411 new_argv[nargs - 3] = 0;
412 }
413 else
414 new_argv[1] = 0;
415
416 #ifdef MSDOS /* MW, July 1993 */
417 if ((outf = egetenv ("TMPDIR")))
418 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
419 else
420 {
421 tempfile = alloca (20);
422 *tempfile = '\0';
423 }
424 dostounix_filename (tempfile);
425 if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
426 strcat (tempfile, "/");
427 strcat (tempfile, "detmp.XXX");
428 mktemp (tempfile);
429
430 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
431 if (outfilefd < 0)
432 {
433 close (filefd);
434 report_file_error ("Opening process output file",
435 Fcons (build_string (tempfile), Qnil));
436 }
437 fd[0] = filefd;
438 fd[1] = outfilefd;
439 #endif /* MSDOS */
440
441 if (INTEGERP (buffer))
442 fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1;
443 else
444 {
445 #ifndef MSDOS
446 pipe (fd);
447 #endif
448 #if 0
449 /* Replaced by close_process_descs */
450 set_exclusive_use (fd[0]);
451 #endif
452 }
453
454 {
455 /* child_setup must clobber environ in systems with true vfork.
456 Protect it from permanent change. */
457 register char **save_environ = environ;
458 register int fd1 = fd[1];
459 int fd_error = fd1;
460
461 #if 0 /* Some systems don't have sigblock. */
462 mask = sigblock (sigmask (SIGCHLD));
463 #endif
464
465 /* Record that we're about to create a synchronous process. */
466 synch_process_alive = 1;
467
468 /* These vars record information from process termination.
469 Clear them now before process can possibly terminate,
470 to avoid timing error if process terminates soon. */
471 synch_process_death = 0;
472 synch_process_retcode = 0;
473
474 if (NILP (error_file))
475 fd_error = open (NULL_DEVICE, O_WRONLY);
476 else if (STRINGP (error_file))
477 {
478 #ifdef DOS_NT
479 fd_error = open (XSTRING (error_file)->data,
480 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
481 S_IREAD | S_IWRITE);
482 #else /* not DOS_NT */
483 fd_error = creat (XSTRING (error_file)->data, 0666);
484 #endif /* not DOS_NT */
485 }
486
487 if (fd_error < 0)
488 {
489 close (filefd);
490 if (fd[0] != filefd)
491 close (fd[0]);
492 if (fd1 >= 0)
493 close (fd1);
494 #ifdef MSDOS
495 unlink (tempfile);
496 #endif
497 report_file_error ("Cannot redirect stderr",
498 Fcons ((NILP (error_file)
499 ? build_string (NULL_DEVICE) : error_file),
500 Qnil));
501 }
502
503 current_dir = ENCODE_FILE (current_dir);
504
505 #ifdef MSDOS /* MW, July 1993 */
506 /* Note that on MSDOS `child_setup' actually returns the child process
507 exit status, not its PID, so we assign it to `synch_process_retcode'
508 below. */
509 pid = child_setup (filefd, outfilefd, fd_error, (char **) new_argv,
510 0, current_dir);
511
512 /* Record that the synchronous process exited and note its
513 termination status. */
514 synch_process_alive = 0;
515 synch_process_retcode = pid;
516 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
517 synch_process_death = strerror (errno);
518
519 close (outfilefd);
520 if (fd_error != outfilefd)
521 close (fd_error);
522 fd1 = -1; /* No harm in closing that one! */
523 /* Since CRLF is converted to LF within `decode_coding', we can
524 always open a file with binary mode. */
525 fd[0] = open (tempfile, O_BINARY);
526 if (fd[0] < 0)
527 {
528 unlink (tempfile);
529 close (filefd);
530 report_file_error ("Cannot re-open temporary file", Qnil);
531 }
532 #else /* not MSDOS */
533 #ifdef WINDOWSNT
534 pid = child_setup (filefd, fd1, fd_error, (char **) new_argv,
535 0, current_dir);
536 #else /* not WINDOWSNT */
537 pid = vfork ();
538
539 if (pid == 0)
540 {
541 if (fd[0] >= 0)
542 close (fd[0]);
543 #ifdef HAVE_SETSID
544 setsid ();
545 #endif
546 #if defined (USG) && !defined (BSD_PGRPS)
547 setpgrp ();
548 #else
549 setpgrp (pid, pid);
550 #endif /* USG */
551 child_setup (filefd, fd1, fd_error, (char **) new_argv,
552 0, current_dir);
553 }
554 #endif /* not WINDOWSNT */
555
556 /* The MSDOS case did this already. */
557 if (fd_error >= 0)
558 close (fd_error);
559 #endif /* not MSDOS */
560
561 environ = save_environ;
562
563 /* Close most of our fd's, but not fd[0]
564 since we will use that to read input from. */
565 close (filefd);
566 if (fd1 >= 0 && fd1 != fd_error)
567 close (fd1);
568 }
569
570 if (pid < 0)
571 {
572 if (fd[0] >= 0)
573 close (fd[0]);
574 report_file_error ("Doing vfork", Qnil);
575 }
576
577 if (INTEGERP (buffer))
578 {
579 if (fd[0] >= 0)
580 close (fd[0]);
581 #ifndef subprocesses
582 /* If Emacs has been built with asynchronous subprocess support,
583 we don't need to do this, I think because it will then have
584 the facilities for handling SIGCHLD. */
585 wait_without_blocking ();
586 #endif /* subprocesses */
587 return Qnil;
588 }
589
590 /* Enable sending signal if user quits below. */
591 call_process_exited = 0;
592
593 #ifdef MSDOS
594 /* MSDOS needs different cleanup information. */
595 record_unwind_protect (call_process_cleanup,
596 Fcons (make_number (fd[0]), build_string (tempfile)));
597 #else
598 record_unwind_protect (call_process_cleanup,
599 Fcons (make_number (fd[0]), make_number (pid)));
600 #endif /* not MSDOS */
601
602
603 if (BUFFERP (buffer))
604 Fset_buffer (buffer);
605
606 if (NILP (buffer))
607 {
608 /* If BUFFER is nil, we must read process output once and then
609 discard it, so setup coding system but with nil. */
610 setup_coding_system (Qnil, &process_coding);
611 }
612 else
613 {
614 Lisp_Object val, *args2;
615
616 val = Qnil;
617 if (!NILP (Vcoding_system_for_read))
618 val = Vcoding_system_for_read;
619 else
620 {
621 if (EQ (coding_systems, Qt))
622 {
623 int i;
624
625 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
626 args2[0] = Qcall_process;
627 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
628 coding_systems
629 = Ffind_operation_coding_system (nargs + 1, args2);
630 }
631 if (CONSP (coding_systems))
632 val = XCONS (coding_systems)->car;
633 else if (CONSP (Vdefault_process_coding_system))
634 val = XCONS (Vdefault_process_coding_system)->car;
635 else
636 val = Qnil;
637 }
638 setup_coding_system (Fcheck_coding_system (val), &process_coding);
639 /* In unibyte mode, character code conversion should not take
640 place but EOL conversion should. So, setup raw-text or one
641 of the subsidiary according to the information just setup. */
642 if (NILP (current_buffer->enable_multibyte_characters)
643 && !NILP (val))
644 setup_raw_text_coding_system (&process_coding);
645 }
646
647 immediate_quit = 1;
648 QUIT;
649
650 {
651 register int nread;
652 int first = 1;
653 int total_read = 0;
654 int carryover = 0;
655 int display_on_the_fly = !NILP (display) && INTERACTIVE;
656 struct coding_system saved_coding;
657
658 saved_coding = process_coding;
659
660 while (1)
661 {
662 /* Repeatedly read until we've filled as much as possible
663 of the buffer size we have. But don't read
664 less than 1024--save that for the next bufferful. */
665 nread = carryover;
666 while (nread < bufsize - 1024)
667 {
668 int this_read = read (fd[0], bufptr + nread, bufsize - nread);
669
670 if (this_read < 0)
671 goto give_up;
672
673 if (this_read == 0)
674 {
675 process_coding.mode |= CODING_MODE_LAST_BLOCK;
676 break;
677 }
678
679 nread += this_read;
680 total_read += this_read;
681
682 if (display_on_the_fly)
683 break;
684 }
685
686 /* Now NREAD is the total amount of data in the buffer. */
687 immediate_quit = 0;
688
689 if (!NILP (buffer))
690 {
691 if (process_coding.type == coding_type_no_conversion)
692 insert (bufptr, nread);
693 else
694 { /* We have to decode the input. */
695 int size = decoding_buffer_size (&process_coding, nread);
696 char *decoding_buf = (char *) xmalloc (size);
697
698 decode_coding (&process_coding, bufptr, decoding_buf,
699 nread, size);
700 if (display_on_the_fly
701 && saved_coding.type == coding_type_undecided
702 && process_coding.type != coding_type_undecided)
703 {
704 /* We have detected some coding system. But,
705 there's a possibility that the detection was
706 done by insufficient data. So, we give up
707 displaying on the fly. */
708 xfree (decoding_buf);
709 display_on_the_fly = 0;
710 process_coding = saved_coding;
711 carryover = nread;
712 continue;
713 }
714 if (process_coding.produced > 0)
715 insert (decoding_buf, process_coding.produced);
716 xfree (decoding_buf);
717 carryover = nread - process_coding.consumed;
718 if (carryover > 0)
719 {
720 /* As CARRYOVER should not be that large, we had
721 better avoid overhead of bcopy. */
722 char *p = bufptr + process_coding.consumed;
723 char *pend = p + carryover;
724 char *dst = bufptr;
725
726 while (p < pend) *dst++ = *p++;
727 }
728 }
729 }
730 if (process_coding.mode & CODING_MODE_LAST_BLOCK)
731 {
732 if (carryover > 0)
733 insert (bufptr, carryover);
734 break;
735 }
736
737 /* Make the buffer bigger as we continue to read more data,
738 but not past 64k. */
739 if (bufsize < 64 * 1024 && total_read > 32 * bufsize)
740 {
741 bufsize *= 2;
742 bufptr = (char *) alloca (bufsize);
743 }
744
745 if (!NILP (display) && INTERACTIVE)
746 {
747 if (first)
748 prepare_menu_bars ();
749 first = 0;
750 redisplay_preserve_echo_area ();
751 }
752 immediate_quit = 1;
753 QUIT;
754 }
755 give_up: ;
756
757 Vlast_coding_system_used = process_coding.symbol;
758
759 /* If the caller required, let the buffer inherit the
760 coding-system used to decode the process output. */
761 if (inherit_process_coding_system)
762 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
763 make_number (total_read));
764 }
765
766 /* Wait for it to terminate, unless it already has. */
767 wait_for_termination (pid);
768
769 immediate_quit = 0;
770
771 set_buffer_internal (old);
772
773 /* Don't kill any children that the subprocess may have left behind
774 when exiting. */
775 call_process_exited = 1;
776
777 unbind_to (count, Qnil);
778
779 if (synch_process_death)
780 return build_string (synch_process_death);
781 return make_number (synch_process_retcode);
782 }
783 #endif
784 \f
785 static Lisp_Object
786 delete_temp_file (name)
787 Lisp_Object name;
788 {
789 /* Use Fdelete_file (indirectly) because that runs a file name handler.
790 We did that when writing the file, so we should do so when deleting. */
791 internal_delete_file (name);
792 }
793
794 DEFUN ("call-process-region", Fcall_process_region, Scall_process_region,
795 3, MANY, 0,
796 "Send text from START to END to a synchronous process running PROGRAM.\n\
797 The remaining arguments are optional.\n\
798 Delete the text if fourth arg DELETE is non-nil.\n\
799 \n\
800 Insert output in BUFFER before point; t means current buffer;\n\
801 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
802 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
803 REAL-BUFFER says what to do with standard output, as above,\n\
804 while STDERR-FILE says what to do with standard error in the child.\n\
805 STDERR-FILE may be nil (discard standard error output),\n\
806 t (mix it with ordinary output), or a file name string.\n\
807 \n\
808 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
809 Remaining args are passed to PROGRAM at startup as command args.\n\
810 \n\
811 If BUFFER is nil, `call-process-region' returns immediately with value nil.\n\
812 Otherwise it waits for PROGRAM to terminate\n\
813 and returns a numeric exit status or a signal description string.\n\
814 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
815 (nargs, args)
816 int nargs;
817 register Lisp_Object *args;
818 {
819 struct gcpro gcpro1;
820 Lisp_Object filename_string;
821 register Lisp_Object start, end;
822 int count = specpdl_ptr - specpdl;
823 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
824 Lisp_Object coding_systems;
825 Lisp_Object val, *args2;
826 int i;
827 #ifdef DOS_NT
828 char *tempfile;
829 char *outf = '\0';
830
831 if ((outf = egetenv ("TMPDIR"))
832 || (outf = egetenv ("TMP"))
833 || (outf = egetenv ("TEMP")))
834 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
835 else
836 {
837 tempfile = alloca (20);
838 *tempfile = '\0';
839 }
840 if (!IS_DIRECTORY_SEP (tempfile[strlen (tempfile) - 1]))
841 strcat (tempfile, "/");
842 if ('/' == DIRECTORY_SEP)
843 dostounix_filename (tempfile);
844 else
845 unixtodos_filename (tempfile);
846 #ifdef WINDOWSNT
847 strcat (tempfile, "emXXXXXX");
848 #else
849 strcat (tempfile, "detmp.XXX");
850 #endif
851 #else /* not DOS_NT */
852 char *tempfile = (char *) alloca (STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
853 bcopy (XSTRING (Vtemp_file_name_pattern)->data, tempfile,
854 STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
855 #endif /* not DOS_NT */
856
857 coding_systems = Qt;
858
859 mktemp (tempfile);
860
861 filename_string = build_string (tempfile);
862 GCPRO1 (filename_string);
863 start = args[0];
864 end = args[1];
865 /* Decide coding-system of the contents of the temporary file. */
866 if (!NILP (Vcoding_system_for_write))
867 val = Vcoding_system_for_write;
868 else if (NILP (current_buffer->enable_multibyte_characters))
869 val = Qnil;
870 else
871 {
872 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
873 args2[0] = Qcall_process_region;
874 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
875 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
876 if (CONSP (coding_systems))
877 val = XCONS (coding_systems)->cdr;
878 else if (CONSP (Vdefault_process_coding_system))
879 val = XCONS (Vdefault_process_coding_system)->cdr;
880 else
881 val = Qnil;
882 }
883
884 {
885 int count1 = specpdl_ptr - specpdl;
886
887 specbind (intern ("coding-system-for-write"), val);
888 Fwrite_region (start, end, filename_string, Qnil, Qlambda, Qnil, Qnil);
889
890 unbind_to (count1, Qnil);
891 }
892
893 /* Note that Fcall_process takes care of binding
894 coding-system-for-read. */
895
896 record_unwind_protect (delete_temp_file, filename_string);
897
898 if (nargs > 3 && !NILP (args[3]))
899 Fdelete_region (start, end);
900
901 if (nargs > 3)
902 {
903 args += 2;
904 nargs -= 2;
905 }
906 else
907 {
908 args[0] = args[2];
909 nargs = 2;
910 }
911 args[1] = filename_string;
912
913 RETURN_UNGCPRO (unbind_to (count, Fcall_process (nargs, args)));
914 }
915 \f
916 #ifndef VMS /* VMS version is in vmsproc.c. */
917
918 static int relocate_fd ();
919
920 /* This is the last thing run in a newly forked inferior
921 either synchronous or asynchronous.
922 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
923 Initialize inferior's priority, pgrp, connected dir and environment.
924 then exec another program based on new_argv.
925
926 This function may change environ for the superior process.
927 Therefore, the superior process must save and restore the value
928 of environ around the vfork and the call to this function.
929
930 SET_PGRP is nonzero if we should put the subprocess into a separate
931 process group.
932
933 CURRENT_DIR is an elisp string giving the path of the current
934 directory the subprocess should have. Since we can't really signal
935 a decent error from within the child, this should be verified as an
936 executable directory by the parent. */
937
938 int
939 child_setup (in, out, err, new_argv, set_pgrp, current_dir)
940 int in, out, err;
941 register char **new_argv;
942 int set_pgrp;
943 Lisp_Object current_dir;
944 {
945 char **env;
946 char *pwd_var;
947 #ifdef WINDOWSNT
948 int cpid;
949 HANDLE handles[3];
950 #endif /* WINDOWSNT */
951
952 int pid = getpid ();
953
954 #ifdef SET_EMACS_PRIORITY
955 {
956 extern int emacs_priority;
957
958 if (emacs_priority < 0)
959 nice (- emacs_priority);
960 }
961 #endif
962
963 #ifdef subprocesses
964 /* Close Emacs's descriptors that this process should not have. */
965 close_process_descs ();
966 #endif
967 /* DOS_NT isn't in a vfork, so if we are in the middle of load-file,
968 we will lose if we call close_load_descs here. */
969 #ifndef DOS_NT
970 close_load_descs ();
971 #endif
972
973 /* Note that use of alloca is always safe here. It's obvious for systems
974 that do not have true vfork or that have true (stack) alloca.
975 If using vfork and C_ALLOCA it is safe because that changes
976 the superior's static variables as if the superior had done alloca
977 and will be cleaned up in the usual way. */
978 {
979 register char *temp;
980 register int i;
981
982 i = STRING_BYTES (XSTRING (current_dir));
983 pwd_var = (char *) alloca (i + 6);
984 temp = pwd_var + 4;
985 bcopy ("PWD=", pwd_var, 4);
986 bcopy (XSTRING (current_dir)->data, temp, i);
987 if (!IS_DIRECTORY_SEP (temp[i - 1])) temp[i++] = DIRECTORY_SEP;
988 temp[i] = 0;
989
990 #ifndef DOS_NT
991 /* We can't signal an Elisp error here; we're in a vfork. Since
992 the callers check the current directory before forking, this
993 should only return an error if the directory's permissions
994 are changed between the check and this chdir, but we should
995 at least check. */
996 if (chdir (temp) < 0)
997 _exit (errno);
998 #endif
999
1000 #ifdef DOS_NT
1001 /* Get past the drive letter, so that d:/ is left alone. */
1002 if (i > 2 && IS_DEVICE_SEP (temp[1]) && IS_DIRECTORY_SEP (temp[2]))
1003 {
1004 temp += 2;
1005 i -= 2;
1006 }
1007 #endif
1008
1009 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1010 while (i > 2 && IS_DIRECTORY_SEP (temp[i - 1]))
1011 temp[--i] = 0;
1012 }
1013
1014 /* Set `env' to a vector of the strings in Vprocess_environment. */
1015 {
1016 register Lisp_Object tem;
1017 register char **new_env;
1018 register int new_length;
1019
1020 new_length = 0;
1021 for (tem = Vprocess_environment;
1022 CONSP (tem) && STRINGP (XCONS (tem)->car);
1023 tem = XCONS (tem)->cdr)
1024 new_length++;
1025
1026 /* new_length + 2 to include PWD and terminating 0. */
1027 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
1028
1029 /* If we have a PWD envvar, pass one down,
1030 but with corrected value. */
1031 if (getenv ("PWD"))
1032 *new_env++ = pwd_var;
1033
1034 /* Copy the Vprocess_environment strings into new_env. */
1035 for (tem = Vprocess_environment;
1036 CONSP (tem) && STRINGP (XCONS (tem)->car);
1037 tem = XCONS (tem)->cdr)
1038 {
1039 char **ep = env;
1040 char *string = (char *) XSTRING (XCONS (tem)->car)->data;
1041 /* See if this string duplicates any string already in the env.
1042 If so, don't put it in.
1043 When an env var has multiple definitions,
1044 we keep the definition that comes first in process-environment. */
1045 for (; ep != new_env; ep++)
1046 {
1047 char *p = *ep, *q = string;
1048 while (1)
1049 {
1050 if (*q == 0)
1051 /* The string is malformed; might as well drop it. */
1052 goto duplicate;
1053 if (*q != *p)
1054 break;
1055 if (*q == '=')
1056 goto duplicate;
1057 p++, q++;
1058 }
1059 }
1060 *new_env++ = string;
1061 duplicate: ;
1062 }
1063 *new_env = 0;
1064 }
1065 #ifdef WINDOWSNT
1066 prepare_standard_handles (in, out, err, handles);
1067 set_process_dir (XSTRING (current_dir)->data);
1068 #else /* not WINDOWSNT */
1069 /* Make sure that in, out, and err are not actually already in
1070 descriptors zero, one, or two; this could happen if Emacs is
1071 started with its standard in, out, or error closed, as might
1072 happen under X. */
1073 {
1074 int oin = in, oout = out;
1075
1076 /* We have to avoid relocating the same descriptor twice! */
1077
1078 in = relocate_fd (in, 3);
1079
1080 if (out == oin)
1081 out = in;
1082 else
1083 out = relocate_fd (out, 3);
1084
1085 if (err == oin)
1086 err = in;
1087 else if (err == oout)
1088 err = out;
1089 else
1090 err = relocate_fd (err, 3);
1091 }
1092
1093 #ifndef MSDOS
1094 close (0);
1095 close (1);
1096 close (2);
1097
1098 dup2 (in, 0);
1099 dup2 (out, 1);
1100 dup2 (err, 2);
1101 close (in);
1102 close (out);
1103 close (err);
1104 #endif /* not MSDOS */
1105 #endif /* not WINDOWSNT */
1106
1107 #if defined(USG) && !defined(BSD_PGRPS)
1108 #ifndef SETPGRP_RELEASES_CTTY
1109 setpgrp (); /* No arguments but equivalent in this case */
1110 #endif
1111 #else
1112 setpgrp (pid, pid);
1113 #endif /* USG */
1114 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
1115 EMACS_SET_TTY_PGRP (0, &pid);
1116
1117 #ifdef vipc
1118 something missing here;
1119 #endif /* vipc */
1120
1121 #ifdef MSDOS
1122 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env);
1123 if (pid == -1)
1124 /* An error occurred while trying to run the subprocess. */
1125 report_file_error ("Spawning child process", Qnil);
1126 return pid;
1127 #else /* not MSDOS */
1128 #ifdef WINDOWSNT
1129 /* Spawn the child. (See ntproc.c:Spawnve). */
1130 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
1131 reset_standard_handles (in, out, err, handles);
1132 if (cpid == -1)
1133 /* An error occurred while trying to spawn the process. */
1134 report_file_error ("Spawning child process", Qnil);
1135 return cpid;
1136 #else /* not WINDOWSNT */
1137 /* execvp does not accept an environment arg so the only way
1138 to pass this environment is to set environ. Our caller
1139 is responsible for restoring the ambient value of environ. */
1140 environ = env;
1141 execvp (new_argv[0], new_argv);
1142
1143 write (1, "Can't exec program: ", 20);
1144 write (1, new_argv[0], strlen (new_argv[0]));
1145 write (1, "\n", 1);
1146 _exit (1);
1147 #endif /* not WINDOWSNT */
1148 #endif /* not MSDOS */
1149 }
1150
1151 /* Move the file descriptor FD so that its number is not less than MINFD.
1152 If the file descriptor is moved at all, the original is freed. */
1153 static int
1154 relocate_fd (fd, minfd)
1155 int fd, minfd;
1156 {
1157 if (fd >= minfd)
1158 return fd;
1159 else
1160 {
1161 int new = dup (fd);
1162 if (new == -1)
1163 {
1164 char *message1 = "Error while setting up child: ";
1165 char *errmessage = strerror (errno);
1166 char *message2 = "\n";
1167 write (2, message1, strlen (message1));
1168 write (2, errmessage, strlen (errmessage));
1169 write (2, message2, strlen (message2));
1170 _exit (1);
1171 }
1172 /* Note that we hold the original FD open while we recurse,
1173 to guarantee we'll get a new FD if we need it. */
1174 new = relocate_fd (new, minfd);
1175 close (fd);
1176 return new;
1177 }
1178 }
1179
1180 static int
1181 getenv_internal (var, varlen, value, valuelen)
1182 char *var;
1183 int varlen;
1184 char **value;
1185 int *valuelen;
1186 {
1187 Lisp_Object scan;
1188
1189 for (scan = Vprocess_environment; CONSP (scan); scan = XCONS (scan)->cdr)
1190 {
1191 Lisp_Object entry;
1192
1193 entry = XCONS (scan)->car;
1194 if (STRINGP (entry)
1195 && STRING_BYTES (XSTRING (entry)) > varlen
1196 && XSTRING (entry)->data[varlen] == '='
1197 #ifdef WINDOWSNT
1198 /* NT environment variables are case insensitive. */
1199 && ! strnicmp (XSTRING (entry)->data, var, varlen)
1200 #else /* not WINDOWSNT */
1201 && ! bcmp (XSTRING (entry)->data, var, varlen)
1202 #endif /* not WINDOWSNT */
1203 )
1204 {
1205 *value = (char *) XSTRING (entry)->data + (varlen + 1);
1206 *valuelen = STRING_BYTES (XSTRING (entry)) - (varlen + 1);
1207 return 1;
1208 }
1209 }
1210
1211 return 0;
1212 }
1213
1214 DEFUN ("getenv", Fgetenv, Sgetenv, 1, 1, 0,
1215 "Return the value of environment variable VAR, as a string.\n\
1216 VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
1217 This function consults the variable ``process-environment'' for its value.")
1218 (var)
1219 Lisp_Object var;
1220 {
1221 char *value;
1222 int valuelen;
1223
1224 CHECK_STRING (var, 0);
1225 if (getenv_internal (XSTRING (var)->data, STRING_BYTES (XSTRING (var)),
1226 &value, &valuelen))
1227 return make_string (value, valuelen);
1228 else
1229 return Qnil;
1230 }
1231
1232 /* A version of getenv that consults process_environment, easily
1233 callable from C. */
1234 char *
1235 egetenv (var)
1236 char *var;
1237 {
1238 char *value;
1239 int valuelen;
1240
1241 if (getenv_internal (var, strlen (var), &value, &valuelen))
1242 return value;
1243 else
1244 return 0;
1245 }
1246
1247 #endif /* not VMS */
1248 \f
1249 /* This is run before init_cmdargs. */
1250
1251 void
1252 init_callproc_1 ()
1253 {
1254 char *data_dir = egetenv ("EMACSDATA");
1255 char *doc_dir = egetenv ("EMACSDOC");
1256
1257 Vdata_directory
1258 = Ffile_name_as_directory (build_string (data_dir ? data_dir
1259 : PATH_DATA));
1260 Vdoc_directory
1261 = Ffile_name_as_directory (build_string (doc_dir ? doc_dir
1262 : PATH_DOC));
1263
1264 /* Check the EMACSPATH environment variable, defaulting to the
1265 PATH_EXEC path from epaths.h. */
1266 Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
1267 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
1268 Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
1269 }
1270
1271 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1272
1273 void
1274 init_callproc ()
1275 {
1276 char *data_dir = egetenv ("EMACSDATA");
1277
1278 register char * sh;
1279 Lisp_Object tempdir;
1280
1281 if (!NILP (Vinstallation_directory))
1282 {
1283 /* Add to the path the lib-src subdir of the installation dir. */
1284 Lisp_Object tem;
1285 tem = Fexpand_file_name (build_string ("lib-src"),
1286 Vinstallation_directory);
1287 #ifndef DOS_NT
1288 /* MSDOS uses wrapped binaries, so don't do this. */
1289 if (NILP (Fmember (tem, Vexec_path)))
1290 Vexec_path = nconc2 (Vexec_path, Fcons (tem, Qnil));
1291
1292 Vexec_directory = Ffile_name_as_directory (tem);
1293 #endif /* not DOS_NT */
1294
1295 /* Maybe use ../etc as well as ../lib-src. */
1296 if (data_dir == 0)
1297 {
1298 tem = Fexpand_file_name (build_string ("etc"),
1299 Vinstallation_directory);
1300 Vdoc_directory = Ffile_name_as_directory (tem);
1301 }
1302 }
1303
1304 /* Look for the files that should be in etc. We don't use
1305 Vinstallation_directory, because these files are never installed
1306 near the executable, and they are never in the build
1307 directory when that's different from the source directory.
1308
1309 Instead, if these files are not in the nominal place, we try the
1310 source directory. */
1311 if (data_dir == 0)
1312 {
1313 Lisp_Object tem, tem1, newdir;
1314
1315 tem = Fexpand_file_name (build_string ("GNU"), Vdata_directory);
1316 tem1 = Ffile_exists_p (tem);
1317 if (NILP (tem1))
1318 {
1319 newdir = Fexpand_file_name (build_string ("../etc/"),
1320 build_string (PATH_DUMPLOADSEARCH));
1321 tem = Fexpand_file_name (build_string ("GNU"), newdir);
1322 tem1 = Ffile_exists_p (tem);
1323 if (!NILP (tem1))
1324 Vdata_directory = newdir;
1325 }
1326 }
1327
1328 #ifndef CANNOT_DUMP
1329 if (initialized)
1330 #endif
1331 {
1332 tempdir = Fdirectory_file_name (Vexec_directory);
1333 if (access (XSTRING (tempdir)->data, 0) < 0)
1334 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n",
1335 Vexec_directory);
1336 }
1337
1338 tempdir = Fdirectory_file_name (Vdata_directory);
1339 if (access (XSTRING (tempdir)->data, 0) < 0)
1340 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n",
1341 Vdata_directory);
1342
1343 #ifdef VMS
1344 Vshell_file_name = build_string ("*dcl*");
1345 #else
1346 sh = (char *) getenv ("SHELL");
1347 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
1348 #endif
1349
1350 #ifdef VMS
1351 Vtemp_file_name_pattern = build_string ("tmp:emacsXXXXXX.");
1352 #else
1353 if (getenv ("TMPDIR"))
1354 {
1355 char *dir = getenv ("TMPDIR");
1356 Vtemp_file_name_pattern
1357 = Fexpand_file_name (build_string ("emacsXXXXXX"),
1358 build_string (dir));
1359 }
1360 else
1361 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX");
1362 #endif
1363 }
1364
1365 void
1366 set_process_environment ()
1367 {
1368 register char **envp;
1369
1370 Vprocess_environment = Qnil;
1371 #ifndef CANNOT_DUMP
1372 if (initialized)
1373 #endif
1374 for (envp = environ; *envp; envp++)
1375 Vprocess_environment = Fcons (build_string (*envp),
1376 Vprocess_environment);
1377 }
1378
1379 void
1380 syms_of_callproc ()
1381 {
1382 #ifdef DOS_NT
1383 Qbuffer_file_type = intern ("buffer-file-type");
1384 staticpro (&Qbuffer_file_type);
1385 #endif /* DOS_NT */
1386
1387 DEFVAR_LISP ("shell-file-name", &Vshell_file_name,
1388 "*File name to load inferior shells from.\n\
1389 Initialized from the SHELL environment variable.");
1390
1391 DEFVAR_LISP ("exec-path", &Vexec_path,
1392 "*List of directories to search programs to run in subprocesses.\n\
1393 Each element is a string (directory name) or nil (try default directory).");
1394
1395 DEFVAR_LISP ("exec-directory", &Vexec_directory,
1396 "Directory for executables for Emacs to invoke.\n\
1397 More generally, this includes any architecture-dependent files\n\
1398 that are built and installed from the Emacs distribution.");
1399
1400 DEFVAR_LISP ("data-directory", &Vdata_directory,
1401 "Directory of machine-independent files that come with GNU Emacs.\n\
1402 These are files intended for Emacs to use while it runs.");
1403
1404 DEFVAR_LISP ("doc-directory", &Vdoc_directory,
1405 "Directory containing the DOC file that comes with GNU Emacs.\n\
1406 This is usually the same as data-directory.");
1407
1408 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory,
1409 "For internal use by the build procedure only.\n\
1410 This is the name of the directory in which the build procedure installed\n\
1411 Emacs's info files; the default value for Info-default-directory-list\n\
1412 includes this.");
1413 Vconfigure_info_directory = build_string (PATH_INFO);
1414
1415 DEFVAR_LISP ("temp-file-name-pattern", &Vtemp_file_name_pattern,
1416 "Pattern for making names for temporary files.\n\
1417 This is used by `call-process-region'.");
1418 /* This variable is initialized in init_callproc. */
1419
1420 DEFVAR_LISP ("process-environment", &Vprocess_environment,
1421 "List of environment variables for subprocesses to inherit.\n\
1422 Each element should be a string of the form ENVVARNAME=VALUE.\n\
1423 The environment which Emacs inherits is placed in this variable\n\
1424 when Emacs starts.");
1425
1426 #ifndef VMS
1427 defsubr (&Scall_process);
1428 defsubr (&Sgetenv);
1429 #endif
1430 defsubr (&Scall_process_region);
1431 }