diff options
| author | Richard M. Stallman | 1994-01-08 09:21:13 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-01-08 09:21:13 +0000 |
| commit | 7e6c2178ef8c158c5625bc460240482377659e6a (patch) | |
| tree | 69577af9b03e28aa68cfa8f32ee47caeab98c604 /src | |
| parent | 3680bdc6ffed16f2dd713552f8e9d40abf544f8b (diff) | |
| download | emacs-7e6c2178ef8c158c5625bc460240482377659e6a.tar.gz emacs-7e6c2178ef8c158c5625bc460240482377659e6a.zip | |
(syms_of_callproc) [MSDOS]: New lisp variable: binary-process.
(init_callproc) [MSDOS]: Initialize binary-process.
[MSDOS]: Declare binary-process.
[MSDOS]: Include <fcntl.h>, <sys/stat.h>, <sys/param.h>,
and <errno.h> needed for the next changes.
(Fcall_process) [MSDOS]: Create temporary file for process output.
Run the subprocess using `run_msdos_command' instead of forking.
Arrange for cleanup to erase temporary file.
(Fcall_process) [not subprocesses]: Barf if zero buffer argument.
(call_process_cleanup) [MSDOS]: Close and erase temporary file
instead of the pid-stuff.
(Fcall_process_region) [MSDOS]: Create temporary file in $TMP or $TEMP.
(Fchild_setup) [MSDOS]: #if 0, as it is not used.
Diffstat (limited to 'src')
| -rw-r--r-- | src/callproc.c | 120 |
1 files changed, 115 insertions, 5 deletions
diff --git a/src/callproc.c b/src/callproc.c index 36f0d866ee3..174ffa214d4 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -41,6 +41,13 @@ extern char *sys_errlist[]; | |||
| 41 | #include <fcntl.h> | 41 | #include <fcntl.h> |
| 42 | #endif | 42 | #endif |
| 43 | 43 | ||
| 44 | #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ | ||
| 45 | #include <fcntl.h> | ||
| 46 | #include <sys/stat.h> | ||
| 47 | #include <sys/param.h> | ||
| 48 | #include <errno.h> | ||
| 49 | #endif /* MSDOS */ | ||
| 50 | |||
| 44 | #ifndef O_RDONLY | 51 | #ifndef O_RDONLY |
| 45 | #define O_RDONLY 0 | 52 | #define O_RDONLY 0 |
| 46 | #endif | 53 | #endif |
| @@ -65,6 +72,10 @@ extern char **environ; | |||
| 65 | 72 | ||
| 66 | #define max(a, b) ((a) > (b) ? (a) : (b)) | 73 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
| 67 | 74 | ||
| 75 | #ifdef MSDOS | ||
| 76 | Lisp_Object Vbinary_process; | ||
| 77 | #endif | ||
| 78 | |||
| 68 | Lisp_Object Vexec_path, Vexec_directory, Vdata_directory; | 79 | Lisp_Object Vexec_path, Vexec_directory, Vdata_directory; |
| 69 | Lisp_Object Vconfigure_info_directory; | 80 | Lisp_Object Vconfigure_info_directory; |
| 70 | 81 | ||
| @@ -101,6 +112,13 @@ Lisp_Object | |||
| 101 | call_process_cleanup (fdpid) | 112 | call_process_cleanup (fdpid) |
| 102 | Lisp_Object fdpid; | 113 | Lisp_Object fdpid; |
| 103 | { | 114 | { |
| 115 | #ifdef MSDOS | ||
| 116 | /* for MSDOS fdpid is really (fd . tempfile) */ | ||
| 117 | register Lisp_Object file = Fcdr (fdpid); | ||
| 118 | close (XFASTINT (Fcar (fdpid))); | ||
| 119 | if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0) | ||
| 120 | unlink (XSTRING (file)->data); | ||
| 121 | #else /* not MSDOS */ | ||
| 104 | register int pid = XFASTINT (Fcdr (fdpid)); | 122 | register int pid = XFASTINT (Fcdr (fdpid)); |
| 105 | 123 | ||
| 106 | if (EMACS_KILLPG (pid, SIGINT) == 0) | 124 | if (EMACS_KILLPG (pid, SIGINT) == 0) |
| @@ -117,6 +135,7 @@ call_process_cleanup (fdpid) | |||
| 117 | } | 135 | } |
| 118 | synch_process_alive = 0; | 136 | synch_process_alive = 0; |
| 119 | close (XFASTINT (Fcar (fdpid))); | 137 | close (XFASTINT (Fcar (fdpid))); |
| 138 | #endif /* not MSDOS */ | ||
| 120 | return Qnil; | 139 | return Qnil; |
| 121 | } | 140 | } |
| 122 | 141 | ||
| @@ -144,11 +163,21 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.") | |||
| 144 | register unsigned char **new_argv | 163 | register unsigned char **new_argv |
| 145 | = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *)); | 164 | = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *)); |
| 146 | struct buffer *old = current_buffer; | 165 | struct buffer *old = current_buffer; |
| 166 | #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ | ||
| 167 | char *outf, *tempfile; | ||
| 168 | int outfilefd; | ||
| 169 | #endif | ||
| 147 | #if 0 | 170 | #if 0 |
| 148 | int mask; | 171 | int mask; |
| 149 | #endif | 172 | #endif |
| 150 | CHECK_STRING (args[0], 0); | 173 | CHECK_STRING (args[0], 0); |
| 151 | 174 | ||
| 175 | #ifndef subprocesses | ||
| 176 | /* Without asynchronous processes we cannot have BUFFER == 0. */ | ||
| 177 | if (nargs >= 3 && XTYPE (args[2]) == Lisp_Int) | ||
| 178 | error ("Operating system cannot handle asynchronous subprocesses"); | ||
| 179 | #endif /* subprocesses */ | ||
| 180 | |||
| 152 | if (nargs >= 2 && ! NILP (args[1])) | 181 | if (nargs >= 2 && ! NILP (args[1])) |
| 153 | { | 182 | { |
| 154 | infile = Fexpand_file_name (args[1], current_buffer->directory); | 183 | infile = Fexpand_file_name (args[1], current_buffer->directory); |
| @@ -228,11 +257,41 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.") | |||
| 228 | } | 257 | } |
| 229 | new_argv[0] = XSTRING (path)->data; | 258 | new_argv[0] = XSTRING (path)->data; |
| 230 | 259 | ||
| 260 | #ifdef MSDOS /* MW, July 1993 */ | ||
| 261 | /* These vars record information from process termination. | ||
| 262 | Clear them now before process can possibly terminate, | ||
| 263 | to avoid timing error if process terminates soon. */ | ||
| 264 | synch_process_death = 0; | ||
| 265 | synch_process_retcode = 0; | ||
| 266 | |||
| 267 | if ((outf = egetenv ("TMP")) || (outf = egetenv ("TEMP"))) | ||
| 268 | strcpy (tempfile = alloca (strlen (outf) + 20), outf); | ||
| 269 | else | ||
| 270 | { | ||
| 271 | tempfile = alloca (20); | ||
| 272 | *tempfile = '\0'; | ||
| 273 | } | ||
| 274 | dostounix_filename (tempfile); | ||
| 275 | if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/') | ||
| 276 | strcat (tempfile, "/"); | ||
| 277 | strcat (tempfile, "detmp.XXX"); | ||
| 278 | mktemp (tempfile); | ||
| 279 | |||
| 280 | outfilefd = creat (tempfile, S_IREAD | S_IWRITE); | ||
| 281 | if (outfilefd < 0) | ||
| 282 | { | ||
| 283 | close (filefd); | ||
| 284 | report_file_error ("Opening process output file", Fcons (tempfile, Qnil)); | ||
| 285 | } | ||
| 286 | #endif | ||
| 287 | |||
| 231 | if (XTYPE (buffer) == Lisp_Int) | 288 | if (XTYPE (buffer) == Lisp_Int) |
| 232 | fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1; | 289 | fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1; |
| 233 | else | 290 | else |
| 234 | { | 291 | { |
| 292 | #ifndef MSDOS | ||
| 235 | pipe (fd); | 293 | pipe (fd); |
| 294 | #endif | ||
| 236 | #if 0 | 295 | #if 0 |
| 237 | /* Replaced by close_process_descs */ | 296 | /* Replaced by close_process_descs */ |
| 238 | set_exclusive_use (fd[0]); | 297 | set_exclusive_use (fd[0]); |
| @@ -258,6 +317,17 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.") | |||
| 258 | synch_process_death = 0; | 317 | synch_process_death = 0; |
| 259 | synch_process_retcode = 0; | 318 | synch_process_retcode = 0; |
| 260 | 319 | ||
| 320 | #ifdef MSDOS /* MW, July 1993 */ | ||
| 321 | pid = run_msdos_command (new_argv, current_dir, filefd, outfilefd); | ||
| 322 | close (outfilefd); | ||
| 323 | fd1 = -1; /* No harm in closing that one! */ | ||
| 324 | fd[0] = open (tempfile, NILP (Vbinary_process) ? O_TEXT : O_BINARY); | ||
| 325 | if (fd[0] < 0) | ||
| 326 | { | ||
| 327 | unlink (tempfile); | ||
| 328 | report_file_error ("Cannot re-open temporary file", Qnil); | ||
| 329 | } | ||
| 330 | #else /* not MSDOS */ | ||
| 261 | pid = vfork (); | 331 | pid = vfork (); |
| 262 | 332 | ||
| 263 | if (pid == 0) | 333 | if (pid == 0) |
| @@ -271,6 +341,7 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.") | |||
| 271 | #endif /* USG */ | 341 | #endif /* USG */ |
| 272 | child_setup (filefd, fd1, fd1, new_argv, 0, current_dir); | 342 | child_setup (filefd, fd1, fd1, new_argv, 0, current_dir); |
| 273 | } | 343 | } |
| 344 | #endif /* not MSDOS */ | ||
| 274 | 345 | ||
| 275 | #if 0 | 346 | #if 0 |
| 276 | /* Tell SIGCHLD handler to look for this pid. */ | 347 | /* Tell SIGCHLD handler to look for this pid. */ |
| @@ -282,7 +353,8 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.") | |||
| 282 | environ = save_environ; | 353 | environ = save_environ; |
| 283 | 354 | ||
| 284 | close (filefd); | 355 | close (filefd); |
| 285 | close (fd1); | 356 | if (fd1 >= 0) |
| 357 | close (fd1); | ||
| 286 | } | 358 | } |
| 287 | 359 | ||
| 288 | if (pid < 0) | 360 | if (pid < 0) |
| @@ -302,8 +374,14 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.") | |||
| 302 | return Qnil; | 374 | return Qnil; |
| 303 | } | 375 | } |
| 304 | 376 | ||
| 377 | #ifdef MSDOS | ||
| 378 | /* MSDOS needs different cleanup information. */ | ||
| 379 | record_unwind_protect (call_process_cleanup, | ||
| 380 | Fcons (make_number (fd[0]), build_string (tempfile))); | ||
| 381 | #else | ||
| 305 | record_unwind_protect (call_process_cleanup, | 382 | record_unwind_protect (call_process_cleanup, |
| 306 | Fcons (make_number (fd[0]), make_number (pid))); | 383 | Fcons (make_number (fd[0]), make_number (pid))); |
| 384 | #endif /* not MSDOS */ | ||
| 307 | 385 | ||
| 308 | 386 | ||
| 309 | if (XTYPE (buffer) == Lisp_Buffer) | 387 | if (XTYPE (buffer) == Lisp_Buffer) |
| @@ -372,14 +450,35 @@ If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.") | |||
| 372 | register Lisp_Object *args; | 450 | register Lisp_Object *args; |
| 373 | { | 451 | { |
| 374 | register Lisp_Object filename_string, start, end; | 452 | register Lisp_Object filename_string, start, end; |
| 453 | #ifdef MSDOS | ||
| 454 | char *tempfile; | ||
| 455 | #else | ||
| 375 | char tempfile[20]; | 456 | char tempfile[20]; |
| 457 | #endif | ||
| 376 | int count = specpdl_ptr - specpdl; | 458 | int count = specpdl_ptr - specpdl; |
| 459 | #ifdef MSDOS | ||
| 460 | char *outf = '\0'; | ||
| 461 | |||
| 462 | if ((outf = egetenv ("TMP")) || (outf = egetenv ("TEMP"))) | ||
| 463 | strcpy (tempfile = alloca (strlen (outf) + 20), outf); | ||
| 464 | else | ||
| 465 | { | ||
| 466 | tempfile = alloca (20); | ||
| 467 | *tempfile = '\0'; | ||
| 468 | } | ||
| 469 | dostounix_filename (tempfile); | ||
| 470 | if (tempfile[strlen (tempfile) - 1] != '/') | ||
| 471 | strcat (tempfile, "/"); | ||
| 472 | strcat (tempfile, "detmp.XXX"); | ||
| 473 | #else /* not MSDOS */ | ||
| 377 | 474 | ||
| 378 | #ifdef VMS | 475 | #ifdef VMS |
| 379 | strcpy (tempfile, "tmp:emacsXXXXXX."); | 476 | strcpy (tempfile, "tmp:emacsXXXXXX."); |
| 380 | #else | 477 | #else |
| 381 | strcpy (tempfile, "/tmp/emacsXXXXXX"); | 478 | strcpy (tempfile, "/tmp/emacsXXXXXX"); |
| 382 | #endif | 479 | #endif |
| 480 | #endif /* not MSDOS */ | ||
| 481 | |||
| 383 | mktemp (tempfile); | 482 | mktemp (tempfile); |
| 384 | 483 | ||
| 385 | filename_string = build_string (tempfile); | 484 | filename_string = build_string (tempfile); |
| @@ -424,9 +523,13 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 424 | int set_pgrp; | 523 | int set_pgrp; |
| 425 | Lisp_Object current_dir; | 524 | Lisp_Object current_dir; |
| 426 | { | 525 | { |
| 526 | #ifdef MSDOS | ||
| 527 | /* The MSDOS port of gcc cannot fork, vfork, ... so we must call system | ||
| 528 | instead. */ | ||
| 529 | #else /* not MSDOS */ | ||
| 427 | char **env; | 530 | char **env; |
| 428 | 531 | ||
| 429 | register int pid = getpid(); | 532 | register int pid = getpid (); |
| 430 | 533 | ||
| 431 | { | 534 | { |
| 432 | extern int emacs_priority; | 535 | extern int emacs_priority; |
| @@ -514,7 +617,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 514 | 617 | ||
| 515 | /* Make sure that in, out, and err are not actually already in | 618 | /* Make sure that in, out, and err are not actually already in |
| 516 | descriptors zero, one, or two; this could happen if Emacs is | 619 | descriptors zero, one, or two; this could happen if Emacs is |
| 517 | started with its standard in, our, or error closed, as might | 620 | started with its standard in, out, or error closed, as might |
| 518 | happen under X. */ | 621 | happen under X. */ |
| 519 | in = relocate_fd (in, 3); | 622 | in = relocate_fd (in, 3); |
| 520 | out = relocate_fd (out, 3); | 623 | out = relocate_fd (out, 3); |
| @@ -554,6 +657,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 554 | write (1, "Couldn't exec the program ", 26); | 657 | write (1, "Couldn't exec the program ", 26); |
| 555 | write (1, new_argv[0], strlen (new_argv[0])); | 658 | write (1, new_argv[0], strlen (new_argv[0])); |
| 556 | _exit (1); | 659 | _exit (1); |
| 660 | #endif /* not MSDOS */ | ||
| 557 | } | 661 | } |
| 558 | 662 | ||
| 559 | /* Move the file descriptor FD so that its number is not less than MIN. | 663 | /* Move the file descriptor FD so that its number is not less than MIN. |
| @@ -647,13 +751,13 @@ egetenv (var) | |||
| 647 | #endif /* not VMS */ | 751 | #endif /* not VMS */ |
| 648 | 752 | ||
| 649 | /* This is run before init_cmdargs. */ | 753 | /* This is run before init_cmdargs. */ |
| 650 | 754 | ||
| 651 | init_callproc_1 () | 755 | init_callproc_1 () |
| 652 | { | 756 | { |
| 653 | char *data_dir = egetenv ("EMACSDATA"); | 757 | char *data_dir = egetenv ("EMACSDATA"); |
| 654 | 758 | ||
| 655 | Vdata_directory | 759 | Vdata_directory |
| 656 | = Ffile_name_as_directory (build_string (data_dir ? data_dir | 760 | = Ffile_name_as_directory (build_string (data_dir ? data_dir |
| 657 | : PATH_DATA)); | 761 | : PATH_DATA)); |
| 658 | 762 | ||
| 659 | /* Check the EMACSPATH environment variable, defaulting to the | 763 | /* Check the EMACSPATH environment variable, defaulting to the |
| @@ -739,6 +843,12 @@ set_process_environment () | |||
| 739 | 843 | ||
| 740 | syms_of_callproc () | 844 | syms_of_callproc () |
| 741 | { | 845 | { |
| 846 | #ifdef MSDOS | ||
| 847 | DEFVAR_LISP ("binary-process", &Vbinary_process, | ||
| 848 | "*If non-nil then new subprocesses are assumed to produce binary output."); | ||
| 849 | Vbinary_process = Qnil; | ||
| 850 | #endif | ||
| 851 | |||
| 742 | DEFVAR_LISP ("shell-file-name", &Vshell_file_name, | 852 | DEFVAR_LISP ("shell-file-name", &Vshell_file_name, |
| 743 | "*File name to load inferior shells from.\n\ | 853 | "*File name to load inferior shells from.\n\ |
| 744 | Initialized from the SHELL environment variable."); | 854 | Initialized from the SHELL environment variable."); |