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

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/msdos/RCS/runargv.c,v 1.1 91/05/06 15:25:32 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:25:32  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. #if ! defined(_MSC_VER)
  54.    extern char **environ;
  55. #endif
  56.    int status;
  57.    char **argv;
  58.  
  59.    argv = Pack_argv( group, shell, cmd );
  60.    _add_child(target, ignore);
  61.    status = spawnvpe(P_WAIT, *argv, argv, environ);
  62.    if( status == -1 ) Error("%s: %s", argv[0], strerror(errno));
  63.    _finished_child(status);
  64.    if( last && !Doing_bang ) Update_time_stamp( target );
  65.  
  66.    return( 0 );
  67. }
  68.  
  69.  
  70. PUBLIC void
  71. Clean_up_processes()
  72. {
  73.    _abort_flg = TRUE;
  74.    _finished_child(-1);
  75. }
  76.  
  77.  
  78. PUBLIC int
  79. Wait_for_child( abort_flg, pid )
  80. int abort_flg;
  81. int pid;
  82. {
  83.    return(1);
  84. }
  85.  
  86.  
  87. static int     _valid = -1;
  88. static CELLPTR _tg;
  89. static int     _ignore;
  90.  
  91. static void
  92. _add_child( target, ignore )
  93. CELLPTR target;
  94. int    ignore;
  95. {
  96.    _tg = target;
  97.    _ignore = ignore;
  98.    _valid = 0;
  99.  
  100.    Current_target = NIL(CELL);
  101. }
  102.  
  103.  
  104. static void
  105. _finished_child(status)
  106. int    status;
  107. {
  108.    if( _valid == -1 ) return;
  109.    Unlink_temp_files( _tg );
  110.    _valid = -1;
  111.    Handle_result( status, _ignore, _abort_flg, _tg );
  112. }
  113.