summaryrefslogtreecommitdiff
path: root/systems/msdos/tx/src/txcomm.c
blob: f1806e300752d685c3ef9a9a2d2b738d6079658b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "tx.h"

extern int ExpandNames(char *, char *, int);

int ExpandAction(char *action,char **argum,char *notexpand,int limit)
{
  int i ;
  char provis[128] ;

  if ( ! ExpandNames(provis,notexpand,limit) )   
    return 0; /* Exceeded limit */

/* To overcome limits to the size of the environment, we must
   execute the actions by a call to "command", with the /e
   option set to a sufficiently high value */

  strcpy(action,getenv("COMSPEC"));
  strcat(action," /e:");
  strcat(action,ch_env_size); /* size of the environment for child proc */
  strcat(action," /c ");
  strcat(action,provis);

/* The command line is now held in string "action". We must
   parse it to get the arguments. */

  limit = MAX_ARGS ;
  for ( i = 0 ; i < MAX_ARGS ; i++ )
    argum[i] = '\0' ; /* initialize with 0's the pointers */
  
  i = 0 ;
  while ( *action ) {
    for (; *action == ' ' ; action++ ) ; /* skip spaces */
    if ( *action ) {
      if ( !limit )  /* exceeded max number of args */
	return 0;
      limit-- ;
      argum[i++]=action ;    /* new argument */
      /* What follows is a sleek way of putting a '\0' at the
	 end of the substrings */
      for ( ; *action &&
	   ( *action != ' ' || (*action++ = '\0')) ; action++ ) ;
    }
  }
  return i ;   /* Return number of args on successful completion */
}