comparison src/callproc.c @ 493:8b101799ff37

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Tue, 14 Jan 1992 08:05:08 +0000
parents 350065270fc8
children c3e1fe268e78
comparison
equal deleted inserted replaced
492:7d92947cce7d 493:8b101799ff37
59 59
60 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory; 60 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory;
61 61
62 Lisp_Object Vshell_file_name; 62 Lisp_Object Vshell_file_name;
63 63
64 #ifndef MAINTAIN_ENVIRONMENT
65 /* List of strings to append to front of environment of
66 all subprocesses when they are started. */
67
68 Lisp_Object Vprocess_environment; 64 Lisp_Object Vprocess_environment;
69 #endif
70 65
71 /* True iff we are about to fork off a synchronous process or if we 66 /* True iff we are about to fork off a synchronous process or if we
72 are waiting for it. */ 67 are waiting for it. */
73 int synch_process_alive; 68 int synch_process_alive;
74 69
121 #if 0 116 #if 0
122 int mask; 117 int mask;
123 #endif 118 #endif
124 CHECK_STRING (args[0], 0); 119 CHECK_STRING (args[0], 0);
125 120
126 if (nargs <= 1 || NULL (args[1])) 121 if (nargs <= 1 || NILP (args[1]))
127 args[1] = build_string ("/dev/null"); 122 args[1] = build_string ("/dev/null");
128 else 123 else
129 args[1] = Fexpand_file_name (args[1], current_buffer->directory); 124 args[1] = Fexpand_file_name (args[1], current_buffer->directory);
130 125
131 CHECK_STRING (args[1], 1); 126 CHECK_STRING (args[1], 1);
162 { 157 {
163 report_file_error ("Opening process input file", Fcons (args[1], Qnil)); 158 report_file_error ("Opening process input file", Fcons (args[1], Qnil));
164 } 159 }
165 /* Search for program; barf if not found. */ 160 /* Search for program; barf if not found. */
166 openp (Vexec_path, args[0], "", &path, 1); 161 openp (Vexec_path, args[0], "", &path, 1);
167 if (NULL (path)) 162 if (NILP (path))
168 { 163 {
169 close (filefd); 164 close (filefd);
170 report_file_error ("Searching for program", Fcons (args[0], Qnil)); 165 report_file_error ("Searching for program", Fcons (args[0], Qnil));
171 } 166 }
172 new_argv[0] = XSTRING (path)->data; 167 new_argv[0] = XSTRING (path)->data;
187 Protect it from permanent change. */ 182 Protect it from permanent change. */
188 register char **save_environ = environ; 183 register char **save_environ = environ;
189 register int fd1 = fd[1]; 184 register int fd1 = fd[1];
190 char **env; 185 char **env;
191 186
192 #ifdef MAINTAIN_ENVIRONMENT
193 env = (char **) alloca (size_of_current_environ ());
194 get_current_environ (env);
195 #else
196 env = environ; 187 env = environ;
197 #endif /* MAINTAIN_ENVIRONMENT */
198 188
199 #if 0 /* Some systems don't have sigblock. */ 189 #if 0 /* Some systems don't have sigblock. */
200 mask = sigblock (sigmask (SIGCHLD)); 190 mask = sigblock (sigmask (SIGCHLD));
201 #endif 191 #endif
202 192
258 register int nread; 248 register int nread;
259 249
260 while ((nread = read (fd[0], buf, sizeof buf)) > 0) 250 while ((nread = read (fd[0], buf, sizeof buf)) > 0)
261 { 251 {
262 immediate_quit = 0; 252 immediate_quit = 0;
263 if (!NULL (buffer)) 253 if (!NILP (buffer))
264 insert (buf, nread); 254 insert (buf, nread);
265 if (!NULL (display) && INTERACTIVE) 255 if (!NILP (display) && INTERACTIVE)
266 redisplay_preserve_echo_area (); 256 redisplay_preserve_echo_area ();
267 immediate_quit = 1; 257 immediate_quit = 1;
268 QUIT; 258 QUIT;
269 } 259 }
270 } 260 }
322 start = args[0]; 312 start = args[0];
323 end = args[1]; 313 end = args[1];
324 Fwrite_region (start, end, filename_string, Qnil, Qlambda); 314 Fwrite_region (start, end, filename_string, Qnil, Qlambda);
325 record_unwind_protect (delete_temp_file, filename_string); 315 record_unwind_protect (delete_temp_file, filename_string);
326 316
327 if (!NULL (args[3])) 317 if (!NILP (args[3]))
328 Fdelete_region (start, end); 318 Fdelete_region (start, end);
329 319
330 args[3] = filename_string; 320 args[3] = filename_string;
331 Fcall_process (nargs - 2, args + 2); 321 Fcall_process (nargs - 2, args + 2);
332 322
385 if (chdir (temp) < 0) 375 if (chdir (temp) < 0)
386 report_file_error ("In chdir", 376 report_file_error ("In chdir",
387 Fcons (current_buffer->directory, Qnil)); 377 Fcons (current_buffer->directory, Qnil));
388 } 378 }
389 379
390 #ifndef MAINTAIN_ENVIRONMENT
391 /* Set `env' to a vector of the strings in Vprocess_environment. */ 380 /* Set `env' to a vector of the strings in Vprocess_environment. */
392 { 381 {
393 register Lisp_Object tem; 382 register Lisp_Object tem;
394 register char **new_env; 383 register char **new_env;
395 register int new_length; 384 register int new_length;
410 && XTYPE (XCONS (tem)->car) == Lisp_String); 399 && XTYPE (XCONS (tem)->car) == Lisp_String);
411 tem = XCONS (tem)->cdr) 400 tem = XCONS (tem)->cdr)
412 *new_env++ = (char *) XSTRING (XCONS (tem)->car)->data; 401 *new_env++ = (char *) XSTRING (XCONS (tem)->car)->data;
413 *new_env = 0; 402 *new_env = 0;
414 } 403 }
415 #endif /* Not MAINTAIN_ENVIRONMENT */
416 404
417 close (0); 405 close (0);
418 close (1); 406 close (1);
419 close (2); 407 close (2);
420 408
440 write (1, "Couldn't exec the program ", 26); 428 write (1, "Couldn't exec the program ", 26);
441 write (1, new_argv[0], strlen (new_argv[0])); 429 write (1, new_argv[0], strlen (new_argv[0]));
442 _exit (1); 430 _exit (1);
443 } 431 }
444 432
433 static int
434 getenv_internal (var, varlen, value, valuelen)
435 char *var;
436 int varlen;
437 char **value;
438 int **valuelen;
439 {
440 Lisp_Object scan;
441
442 for (scan = Vprocess_environment; CONSP (scan); scan = XCONS (scan)->cdr)
443 {
444 Lisp_Object entry = XCONS (scan)->car;
445
446 if (XTYPE (entry) == Lisp_String
447 && XSTRING (entry)->size > varlen
448 && XSTRING (entry)->data[varlen] == '='
449 && ! bcmp (XSTRING (entry)->data, var, varlen))
450 {
451 *value = XSTRING (entry)->data + (varlen + 1);
452 *valuelen = XSTRING (entry)->size - (varlen + 1);
453 return 1;
454 }
455 }
456
457 return 0;
458 }
459
460 DEFUN ("getenv", Fgetenv, Sgetenv, 1, 2, 0,
461 "Return the value of environment variable VAR, as a string.\n\
462 VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
463 This function consults the variable ``process-environment'' for its value.")
464 (var)
465 Lisp_Object var;
466 {
467 char *value;
468 int valuelen;
469
470 CHECK_STRING (var, 0);
471 if (getenv_internal (XSTRING (var)->data, XSTRING (var)->size,
472 &value, &valuelen))
473 return make_string (value, valuelen);
474 else
475 return Qnil;
476 }
477
478 /* A version of getenv that consults process_environment, easily
479 callable from C. */
480 char *
481 egetenv (var)
482 {
483 char *value;
484 int valuelen;
485
486 if (getenv_internal (var, strlen (var), &value, &valuelen))
487 return value;
488 else
489 return 0;
490 }
491
445 #endif /* not VMS */ 492 #endif /* not VMS */
446 493
447 init_callproc () 494 init_callproc ()
448 { 495 {
449 register char * sh; 496 register char * sh;
475 } 522 }
476 523
477 #ifdef VMS 524 #ifdef VMS
478 Vshell_file_name = build_string ("*dcl*"); 525 Vshell_file_name = build_string ("*dcl*");
479 #else 526 #else
480 sh = (char *) egetenv ("SHELL"); 527 sh = (char *) getenv ("SHELL");
481 Vshell_file_name = build_string (sh ? sh : "/bin/sh"); 528 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
482 #endif 529 #endif
483 530
484 #ifndef MAINTAIN_ENVIRONMENT
485 /* The equivalent of this operation was done
486 in init_environ in environ.c if MAINTAIN_ENVIRONMENT */
487 Vprocess_environment = Qnil; 531 Vprocess_environment = Qnil;
488 #ifndef CANNOT_DUMP 532 #ifndef CANNOT_DUMP
489 if (initialized) 533 if (initialized)
490 #endif 534 #endif
491 for (envp = environ; *envp; envp++) 535 for (envp = environ; *envp; envp++)
492 Vprocess_environment = Fcons (build_string (*envp), 536 Vprocess_environment = Fcons (build_string (*envp),
493 Vprocess_environment); 537 Vprocess_environment);
494 #endif /* MAINTAIN_ENVIRONMENT */
495 } 538 }
496 539
497 syms_of_callproc () 540 syms_of_callproc ()
498 { 541 {
499 DEFVAR_LISP ("shell-file-name", &Vshell_file_name, 542 DEFVAR_LISP ("shell-file-name", &Vshell_file_name,
510 553
511 DEFVAR_LISP ("data-directory", &Vdata_directory, 554 DEFVAR_LISP ("data-directory", &Vdata_directory,
512 "Directory of architecture-independent files that come with GNU Emacs,\n\ 555 "Directory of architecture-independent files that come with GNU Emacs,\n\
513 intended for Emacs to use."); 556 intended for Emacs to use.");
514 557
515 #ifndef MAINTAIN_ENVIRONMENT
516 DEFVAR_LISP ("process-environment", &Vprocess_environment, 558 DEFVAR_LISP ("process-environment", &Vprocess_environment,
517 "List of strings to append to environment of subprocesses that are started.\n\ 559 "List of environment variables for subprocesses to inherit.\n\
518 Each string should have the format ENVVARNAME=VALUE."); 560 Each element should be a string of the form ENVVARNAME=VALUE.\n\
519 #endif 561 The environment which Emacs inherits is placed in this variable\n\
562 when Emacs starts.");
520 563
521 #ifndef VMS 564 #ifndef VMS
522 defsubr (&Scall_process); 565 defsubr (&Scall_process);
523 #endif 566 #endif
567 defsubr (&Sgetenv);
524 defsubr (&Scall_process_region); 568 defsubr (&Scall_process_region);
525 } 569 }