home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DMAKE37S.ZIP / DMAKE / TOS / RUNARGV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-06  |  2.5 KB  |  110 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/tos/RCS/runargv.c,v 1.1 91/05/06 15:32:22 dvadura Exp $
  2. -- SYNOPSIS -- run a sub process.
  3. -- 
  4. -- DESCRIPTION
  5. --    Use spawn to run a subprocess.
  6. --
  7. -- AUTHOR
  8. --      Dennis Vadura, dvadura@watdragon.uwaterloo.ca
  9. --      CS DEPT, University of Waterloo, Waterloo, Ont., Canada
  10. --
  11. -- COPYRIGHT
  12. --      Copyright (c) 1990 by Dennis Vadura.  All rights reserved.
  13. -- 
  14. --      This program is free software; you can redistribute it and/or
  15. --      modify it under the terms of the GNU General Public License
  16. --      (version 1), as published by the Free Software Foundation, and
  17. --      found in the file 'LICENSE' included with this distribution.
  18. -- 
  19. --      This program is distributed in the hope that it will be useful,
  20. --      but WITHOUT ANY WARRANTY; without even the implied warrant of
  21. --      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. --      GNU General Public License for more details.
  23. -- 
  24. --      You should have received a copy of the GNU General Public License
  25. --      along with this program;  if not, write to the Free Software
  26. --      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. --
  28. -- LOG
  29. --     $Log:    runargv.c,v $
  30.  * Revision 1.1  91/05/06  15:32:22  dvadura
  31.  * dmake Release Version 3.7
  32.  * 
  33. */
  34.  
  35. #include <process.h>
  36. #include <errno.h>
  37. #include "extern.h"
  38. #include "sysintf.h"
  39.  
  40. static int  _abort_flg = FALSE;
  41. static void _add_child ANSI((CELLPTR, int));
  42. static void _finished_child ANSI((int));
  43.  
  44. PUBLIC int
  45. runargv(target, ignore, group, last, shell, cmd)
  46. CELLPTR target;
  47. int     ignore;
  48. int    group;
  49. int    last;
  50. int    shell;
  51. char    *cmd;
  52. {
  53.    int status;
  54.    char **argv;
  55.  
  56.    argv = Pack_argv( group, shell, cmd );
  57.    _add_child(target, ignore);
  58.    status = spawnvp(P_WAIT, *argv, argv);
  59.    if( status == -1 ) Error("%s: %s", argv[0], strerror(errno));
  60.    _finished_child(status);
  61.    if( last && !Doing_bang ) Update_time_stamp( target );
  62.  
  63.    return( 0 );
  64. }
  65.  
  66.  
  67. PUBLIC void
  68. Clean_up_processes()
  69. {
  70.    _abort_flg = TRUE;
  71.    _finished_child(-1);
  72. }
  73.  
  74.  
  75. PUBLIC int
  76. Wait_for_child( abort_flg, pid )
  77. int abort_flg;
  78. int pid;
  79. {
  80.    return(1);
  81. }
  82.  
  83.  
  84. static int     _valid = -1;
  85. static CELLPTR _tg;
  86. static int     _ignore;
  87.  
  88. static void
  89. _add_child( target, ignore )
  90. CELLPTR target;
  91. int    ignore;
  92. {
  93.    _tg = target;
  94.    _ignore = ignore;
  95.    _valid = 0;
  96.  
  97.    Current_target = NIL(CELL);
  98. }
  99.  
  100.  
  101. static void
  102. _finished_child(status)
  103. int    status;
  104. {
  105.    if( _valid == -1 ) return;
  106.    Unlink_temp_files( _tg );
  107.    _valid = -1;
  108.    Handle_result( status, _ignore, _abort_flg, _tg );
  109. }
  110.