home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DMAKE38C.ZIP / TOS / RUNARGV.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  3KB  |  116 lines

  1. /* RCS      -- $Header: /u2/dvadura/src/generic/dmake/src/tos/runargv.c,v 1.1 1992/01/24 03:27:13 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  1992/01/24  03:27:13  dvadura
  31.  * dmake Version 3.8, Initial revision
  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.    char path[MAX_PATH_LEN+1];
  56.  
  57.    argv = Pack_argv( group, shell, cmd );
  58.    _add_child(target, ignore);
  59.  
  60.    /* save and restore current working directory across a spawn call */
  61.    strcpy(path, Get_current_dir());
  62.    status = spawnvp(P_WAIT, *argv, argv);
  63.    Set_dir(path);
  64.  
  65.    if( status == -1 ) Error("%s: %s", argv[0], strerror(errno));
  66.    _finished_child(status);
  67.    if( last && !Doing_bang ) Update_time_stamp( target );
  68.  
  69.    return( 0 );
  70. }
  71.  
  72.  
  73. PUBLIC void
  74. Clean_up_processes()
  75. {
  76.    _abort_flg = TRUE;
  77.    _finished_child(-1);
  78. }
  79.  
  80.  
  81. PUBLIC int
  82. Wait_for_child( abort_flg, pid )
  83. int abort_flg;
  84. int pid;
  85. {
  86.    return(1);
  87. }
  88.  
  89.  
  90. static int     _valid = -1;
  91. static CELLPTR _tg;
  92. static int     _ignore;
  93.  
  94. static void
  95. _add_child( target, ignore )
  96. CELLPTR target;
  97. int    ignore;
  98. {
  99.    _tg = target;
  100.    _ignore = ignore;
  101.    _valid = 0;
  102.  
  103.    Current_target = NIL(CELL);
  104. }
  105.  
  106.  
  107. static void
  108. _finished_child(status)
  109. int    status;
  110. {
  111.    if( _valid == -1 ) return;
  112.    Unlink_temp_files( _tg );
  113.    _valid = -1;
  114.    Handle_result( status, _ignore, _abort_flg, _tg );
  115. }
  116.