comparison src/process.c @ 5125:b5df3737028a ben-lisp-object

merge
author Ben Wing <ben@xemacs.org>
date Wed, 24 Feb 2010 01:58:04 -0600
parents 623d57b7fbe8 ae48681c47fa
children a9c41067dd88
comparison
equal deleted inserted replaced
5124:623d57b7fbe8 5125:b5df3737028a
1 /* Asynchronous subprocess control for XEmacs. 1 /* Asynchronous subprocess control for XEmacs.
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995 2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 Copyright (C) 1995 Sun Microsystems, Inc. 4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 1995, 1996, 2001, 2002, 2004, 2005 Ben Wing. 5 Copyright (C) 1995, 1996, 2001, 2002, 2004, 2005, 2010 Ben Wing.
6 6
7 This file is part of XEmacs. 7 This file is part of XEmacs.
8 8
9 XEmacs is free software; you can redistribute it and/or modify it 9 XEmacs is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the 10 under the terms of the GNU General Public License as published by the
143 #include "process-slots.h" 143 #include "process-slots.h"
144 return Qnil; 144 return Qnil;
145 } 145 }
146 146
147 static void 147 static void
148 print_process (Lisp_Object object, Lisp_Object printcharfun, int escapeflag) 148 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
149 { 149 {
150 Lisp_Process *process = XPROCESS (object); 150 Lisp_Process *process = XPROCESS (obj);
151 151
152 if (print_readably) 152 if (print_readably)
153 printing_unreadable_object ("#<process %s>", XSTRING_DATA (process->name)); 153 printing_unreadable_lcrecord (obj, XSTRING_DATA (process->name));
154 154
155 if (!escapeflag) 155 if (!escapeflag)
156 { 156 {
157 print_internal (process->name, printcharfun, 0); 157 print_internal (process->name, printcharfun, 0);
158 } 158 }
159 else 159 else
160 { 160 {
161 int netp = network_connection_p (object); 161 int netp = network_connection_p (obj);
162 write_c_string (printcharfun, 162 write_ascstring (printcharfun,
163 netp ? GETTEXT ("#<network connection ") : 163 netp ? GETTEXT ("#<network connection ") :
164 GETTEXT ("#<process ")); 164 GETTEXT ("#<process "));
165 print_internal (process->name, printcharfun, 1); 165 print_internal (process->name, printcharfun, 1);
166 write_c_string (printcharfun, (netp ? " " : " pid ")); 166 write_ascstring (printcharfun, (netp ? " " : " pid "));
167 print_internal (process->pid, printcharfun, 1); 167 print_internal (process->pid, printcharfun, 1);
168 write_fmt_string_lisp (printcharfun, " state:%S", 1, process->status_symbol); 168 write_fmt_string_lisp (printcharfun, " state:%S", 1, process->status_symbol);
169 MAYBE_PROCMETH (print_process_data, (process, printcharfun)); 169 MAYBE_PROCMETH (print_process_data, (process, printcharfun));
170 write_c_string (printcharfun, ">"); 170 write_ascstring (printcharfun, ">");
171 } 171 }
172 } 172 }
173 173
174 #ifdef HAVE_WINDOW_SYSTEM 174 #ifdef HAVE_WINDOW_SYSTEM
175 extern void debug_process_finalization (Lisp_Process *p); 175 extern void debug_process_finalization (Lisp_Process *p);
186 #endif /* HAVE_WINDOW_SYSTEM */ 186 #endif /* HAVE_WINDOW_SYSTEM */
187 187
188 if (p->process_data) 188 if (p->process_data)
189 { 189 {
190 MAYBE_PROCMETH (finalize_process_data, (p)); 190 MAYBE_PROCMETH (finalize_process_data, (p));
191 xfree (p->process_data, void *); 191 xfree (p->process_data);
192 } 192 }
193 } 193 }
194 194
195 DEFINE_NODUMP_LISP_OBJECT ("process", process, 195 DEFINE_NODUMP_LISP_OBJECT ("process", process,
196 mark_process, print_process, finalize_process, 196 mark_process, print_process, finalize_process,
225 assert (usid != USID_ERROR && usid != USID_DONTHASH); 225 assert (usid != USID_ERROR && usid != USID_DONTHASH);
226 226
227 if (gethash ((const void*)usid, usid_to_process, &vval)) 227 if (gethash ((const void*)usid, usid_to_process, &vval))
228 { 228 {
229 Lisp_Object process; 229 Lisp_Object process;
230 process = VOID_TO_LISP (vval); 230 process = GET_LISP_FROM_VOID (vval);
231 return XPROCESS (process); 231 return XPROCESS (process);
232 } 232 }
233 else 233 else
234 return 0; 234 return 0;
235 } 235 }
447 /************************************************************************/ 447 /************************************************************************/
448 /* creating a process */ 448 /* creating a process */
449 /************************************************************************/ 449 /************************************************************************/
450 450
451 DOESNT_RETURN 451 DOESNT_RETURN
452 report_process_error (const char *string, Lisp_Object data) 452 report_process_error (const Ascbyte *reason, Lisp_Object data)
453 { 453 {
454 report_error_with_errno (Qprocess_error, string, data); 454 report_error_with_errno (Qprocess_error, reason, data);
455 } 455 }
456 456
457 DOESNT_RETURN 457 DOESNT_RETURN
458 report_network_error (const char *string, Lisp_Object data) 458 report_network_error (const Ascbyte *reason, Lisp_Object data)
459 { 459 {
460 report_error_with_errno (Qnetwork_error, string, data); 460 report_error_with_errno (Qnetwork_error, reason, data);
461 } 461 }
462 462
463 Lisp_Object 463 Lisp_Object
464 make_process_internal (Lisp_Object name) 464 make_process_internal (Lisp_Object name)
465 { 465 {
473 473
474 /* If name is already in use, modify it until it is unused. */ 474 /* If name is already in use, modify it until it is unused. */
475 name1 = name; 475 name1 = name;
476 for (i = 1; ; i++) 476 for (i = 1; ; i++)
477 { 477 {
478 char suffix[10]; 478 Ascbyte suffix[10];
479 Lisp_Object tem = Fget_process (name1); 479 Lisp_Object tem = Fget_process (name1);
480 if (NILP (tem)) 480 if (NILP (tem))
481 break; 481 break;
482 sprintf (suffix, "<%d>", i); 482 sprintf (suffix, "<%d>", i);
483 name1 = concat2 (name, build_string (suffix)); 483 name1 = concat2 (name, build_ascstring (suffix));
484 } 484 }
485 name = name1; 485 name = name1;
486 p->name = name; 486 p->name = name;
487 487
488 p->mark = Fmake_marker (); 488 p->mark = Fmake_marker ();
552 552
553 if (in_usid != USID_DONTHASH) 553 if (in_usid != USID_DONTHASH)
554 { 554 {
555 Lisp_Object process = Qnil; 555 Lisp_Object process = Qnil;
556 process = wrap_process (p); 556 process = wrap_process (p);
557 puthash ((const void*) in_usid, LISP_TO_VOID (process), usid_to_process); 557 puthash ((const void*) in_usid, STORE_LISP_IN_VOID (process), usid_to_process);
558 } 558 }
559 559
560 if (err_usid != USID_DONTHASH) 560 if (err_usid != USID_DONTHASH)
561 { 561 {
562 Lisp_Object process = Qnil; 562 Lisp_Object process = Qnil;
563 process = wrap_process (p); 563 process = wrap_process (p);
564 puthash ((const void*) err_usid, LISP_TO_VOID (process), 564 puthash ((const void*) err_usid, STORE_LISP_IN_VOID (process),
565 usid_to_process); 565 usid_to_process);
566 } 566 }
567 567
568 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, err, flags)); 568 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, err, flags));
569 569
738 ending, e.g. .exe */ 738 ending, e.g. .exe */
739 struct gcpro ngcpro1; 739 struct gcpro ngcpro1;
740 740
741 tem = Qnil; 741 tem = Qnil;
742 NGCPRO1 (tem); 742 NGCPRO1 (tem);
743 locate_file (list1 (build_string ("")), program, Vlisp_EXEC_SUFFIXES, 743 locate_file (list1 (build_ascstring ("")), program, Vlisp_EXEC_SUFFIXES,
744 &tem, X_OK); 744 &tem, X_OK);
745 if (NILP (tem)) 745 if (NILP (tem))
746 signal_error (Qprocess_error, "Searching for program", program); 746 signal_error (Qprocess_error, "Searching for program", program);
747 program = tem; 747 program = tem;
748 NUNGCPRO; 748 NUNGCPRO;
1562 int coredump = p->core_dumped; 1562 int coredump = p->core_dumped;
1563 Lisp_Object string, string2; 1563 Lisp_Object string, string2;
1564 1564
1565 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop)) 1565 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
1566 { 1566 {
1567 string = build_string (signal_name (code)); 1567 string = build_cistring (signal_name (code));
1568 if (coredump) 1568 if (coredump)
1569 string2 = build_msg_string (" (core dumped)\n"); 1569 string2 = build_msg_string (" (core dumped)\n");
1570 else 1570 else
1571 string2 = build_string ("\n"); 1571 string2 = build_ascstring ("\n");
1572 set_string_char (string, 0, 1572 set_string_char (string, 0,
1573 DOWNCASE (0, string_ichar (string, 0))); 1573 DOWNCASE (0, string_ichar (string, 0)));
1574 return concat2 (string, string2); 1574 return concat2 (string, string2);
1575 } 1575 }
1576 else if (EQ (symbol, Qexit)) 1576 else if (EQ (symbol, Qexit))
1579 return build_msg_string ("finished\n"); 1579 return build_msg_string ("finished\n");
1580 string = Fnumber_to_string (make_int (code)); 1580 string = Fnumber_to_string (make_int (code));
1581 if (coredump) 1581 if (coredump)
1582 string2 = build_msg_string (" (core dumped)\n"); 1582 string2 = build_msg_string (" (core dumped)\n");
1583 else 1583 else
1584 string2 = build_string ("\n"); 1584 string2 = build_ascstring ("\n");
1585 return concat2 (build_msg_string ("exited abnormally with code "), 1585 return concat2 (build_msg_string ("exited abnormally with code "),
1586 concat2 (string, string2)); 1586 concat2 (string, string2));
1587 } 1587 }
1588 else 1588 else
1589 return Fcopy_sequence (Fsymbol_name (symbol)); 1589 return Fcopy_sequence (Fsymbol_name (symbol));
1688 { 1688 {
1689 struct gcpro ngcpro1; 1689 struct gcpro ngcpro1;
1690 int spec = process_setup_for_insertion (process, 0); 1690 int spec = process_setup_for_insertion (process, 0);
1691 1691
1692 NGCPRO1 (process); 1692 NGCPRO1 (process);
1693 buffer_insert_c_string (current_buffer, "\nProcess "); 1693 buffer_insert_ascstring (current_buffer, "\nProcess ");
1694 Finsert (1, &p->name); 1694 Finsert (1, &p->name);
1695 buffer_insert_c_string (current_buffer, " "); 1695 buffer_insert_ascstring (current_buffer, " ");
1696 Finsert (1, &msg); 1696 Finsert (1, &msg);
1697 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)), 1697 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
1698 p->buffer); 1698 p->buffer);
1699 1699
1700 unbind_to (spec); 1700 unbind_to (spec);
2300 && ! memcmp (XSTRING_DATA (entry), var, varlen) 2300 && ! memcmp (XSTRING_DATA (entry), var, varlen)
2301 #endif /* not WIN32_NATIVE */ 2301 #endif /* not WIN32_NATIVE */
2302 ) 2302 )
2303 { 2303 {
2304 XCAR (scan) = concat3 (make_string (var, varlen), 2304 XCAR (scan) = concat3 (make_string (var, varlen),
2305 build_string ("="), 2305 build_ascstring ("="),
2306 make_string (value, valuelen)); 2306 make_string (value, valuelen));
2307 return; 2307 return;
2308 } 2308 }
2309 } 2309 }
2310 2310
2311 Vprocess_environment = Fcons (concat3 (make_string (var, varlen), 2311 Vprocess_environment = Fcons (concat3 (make_string (var, varlen),
2312 build_string ("="), 2312 build_ascstring ("="),
2313 make_string (value, valuelen)), 2313 make_string (value, valuelen)),
2314 Vprocess_environment); 2314 Vprocess_environment);
2315 } 2315 }
2316 2316
2317 /* NOTE: 2317 /* NOTE:
2340 VAR is a string, the name of the variable. 2340 VAR is a string, the name of the variable.
2341 When invoked interactively, prints the value in the echo area. 2341 When invoked interactively, prints the value in the echo area.
2342 */ 2342 */
2343 (var, interactivep)) 2343 (var, interactivep))
2344 { 2344 {
2345 Ibyte *value; 2345 Ibyte *value = NULL;
2346 Bytecount valuelen; 2346 Bytecount valuelen;
2347 Lisp_Object v = Qnil; 2347 Lisp_Object v = Qnil;
2348 struct gcpro gcpro1; 2348 struct gcpro gcpro1;
2349 2349
2350 CHECK_STRING (var); 2350 CHECK_STRING (var);
2426 Vprocess_environment = Qnil; 2426 Vprocess_environment = Qnil;
2427 #ifdef WIN32_NATIVE 2427 #ifdef WIN32_NATIVE
2428 _wgetenv (L""); /* force initialization of _wenviron */ 2428 _wgetenv (L""); /* force initialization of _wenviron */
2429 for (envp = (Extbyte **) _wenviron; envp && *envp; envp++) 2429 for (envp = (Extbyte **) _wenviron; envp && *envp; envp++)
2430 Vprocess_environment = 2430 Vprocess_environment =
2431 Fcons (build_ext_string (*envp, Qmswindows_unicode), 2431 Fcons (build_extstring (*envp, Qmswindows_unicode),
2432 Vprocess_environment); 2432 Vprocess_environment);
2433 #else 2433 #else
2434 for (envp = environ; envp && *envp; envp++) 2434 for (envp = environ; envp && *envp; envp++)
2435 Vprocess_environment = 2435 Vprocess_environment =
2436 Fcons (build_ext_string (*envp, Qnative), Vprocess_environment); 2436 Fcons (build_extstring (*envp, Qenvironment_variable_encoding),
2437 Vprocess_environment);
2437 #endif 2438 #endif
2438 /* This gets set back to 0 in disksave_object_finalization() */ 2439 /* This gets set back to 0 in disksave_object_finalization() */
2439 env_initted = 1; 2440 env_initted = 1;
2440 } 2441 }
2441 2442
2470 2471
2471 if (!egetenv ("SHELL")) 2472 if (!egetenv ("SHELL"))
2472 { 2473 {
2473 Ibyte *faux_var = alloca_ibytes (7 + qxestrlen (shell)); 2474 Ibyte *faux_var = alloca_ibytes (7 + qxestrlen (shell));
2474 qxesprintf (faux_var, "SHELL=%s", shell); 2475 qxesprintf (faux_var, "SHELL=%s", shell);
2475 Vprocess_environment = Fcons (build_intstring (faux_var), 2476 Vprocess_environment = Fcons (build_istring (faux_var),
2476 Vprocess_environment); 2477 Vprocess_environment);
2477 } 2478 }
2478 #endif /* 0 */ 2479 #endif /* 0 */
2479 2480
2480 Vshell_file_name = build_intstring (shell); 2481 Vshell_file_name = build_istring (shell);
2481 } 2482 }
2482 } 2483 }
2483 2484
2484 void 2485 void
2485 syms_of_process (void) 2486 syms_of_process (void)
2596 it sends a non-ending stream of zero bytes. It's used most often along 2597 it sends a non-ending stream of zero bytes. It's used most often along
2597 with memory-mapping. We don't provide a Lisp variable for this because 2598 with memory-mapping. We don't provide a Lisp variable for this because
2598 the operations needing this are lower level than what ELisp programs 2599 the operations needing this are lower level than what ELisp programs
2599 typically do, and in any case no equivalent exists under native MS Windows. 2600 typically do, and in any case no equivalent exists under native MS Windows.
2600 */ ); 2601 */ );
2601 Vnull_device = build_string (NULL_DEVICE); 2602 Vnull_device = build_ascstring (NULL_DEVICE);
2602 2603
2603 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /* 2604 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
2604 Control type of device used to communicate with subprocesses. 2605 Control type of device used to communicate with subprocesses.
2605 Values are nil to use a pipe, or t or `pty' to use a pty. 2606 Values are nil to use a pipe, or t or `pty' to use a pty.
2606 The value has no effect if the system has no ptys or if all ptys are busy: 2607 The value has no effect if the system has no ptys or if all ptys are busy:
2676 Each element should be a string of the form ENVVARNAME=VALUE. 2677 Each element should be a string of the form ENVVARNAME=VALUE.
2677 The environment which Emacs inherits is placed in this variable 2678 The environment which Emacs inherits is placed in this variable
2678 when Emacs starts. 2679 when Emacs starts.
2679 */ ); 2680 */ );
2680 2681
2681 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES); 2682 Vlisp_EXEC_SUFFIXES = build_ascstring (EXEC_SUFFIXES);
2682 staticpro (&Vlisp_EXEC_SUFFIXES); 2683 staticpro (&Vlisp_EXEC_SUFFIXES);
2683 } 2684 }