コード例 #1
0
ファイル: call.c プロジェクト: aquashift/86Duino_DuinOS
int cmd_call(char *param)
{
/*
 * Perform CALL command.
 *
 * Allocate a new batch context and add it to the current chain.
 * Call parsecommandline passing in our param string
 * If No batch file was opened then remove our newly allocted
 * context block.
 */

	struct bcontext *n = newBatchContext();
	int ec;

	if (n == 0) {
		/* Not in a batch file */
		return 1;
	}

	optS = optN = 0;

	if((ec = leadOptions(&param, opt_call, 0)) != E_None)
		return ec;

	if(swapOnExec != ERROR) {
		if(optS)
			swapOnExec = TRUE;
		if(optN)
			swapOnExec = FALSE;
	}

	parsecommandline(param, FALSE);
	if(swapOnExec != ERROR)
		swapOnExec = FALSE;

	if (bc->bfile == 0
	 && bc->bfnam == 0) {    /* Wasn't a batch file so remove context */
		bc = bc->prev;
		free(n);
	}

	return 0;
}
コード例 #2
0
ファイル: batch.c プロジェクト: TijmenW/FreeDOS
int batch(char *fullname, char *firstword, char *param)
{
  /*
   * Start batch file execution
   *
   * The firstword parameter is the full filename of the batch file.
   */

   assert(fullname);
   assert(firstword);
   assert(param);

  if ((fullname = dfnexpand(fullname, 0)) == 0)
  {
    error_out_of_memory();
    return 1;
  }

  dprintf(("batch ('%s', '%s', '%s')\n", fullname, firstword,
           param));

  while (bc && bc->forvar)      /* Kill any and all FOR contexts */
    exit_batch();

  if (bc == 0)               /* No current batch file, create new context */
  {
    if (!newBatchContext()) {
    	free(fullname);
      return 1;
    }
  }
  else
  {                             /* Then we are transferring to another batch */
    struct bcontext *q;
    int echo;

    clearBatchContext(bc);

    q = bc->prev;               /* preserve context chain intact */
    echo = bc->echo;            /* preserve former ECHO state */
    /* if the _current_ ECHO state would be preserved,
       the following case would forget about the
       ECHO state on the interactive command line:
       === File BATCH1.BAT
       @echo off
       batch2
       === File BATCH2.BAT
       @echo off
       ===
       The transfer to BATCH2 would destroy BTACH1's
       context and therefore the original ECHO state.
       because BATCH2 is called with ECHO OFF, this
       state would be preserved as the command line's
       ECHO state */
    initBatchContext(bc);
    bc->prev = q;
    bc->echo = echo;
  }

  bc->bfnam = fullname;         /* already duplicated */
  if(0 == (bc->bfirst = strdup(firstword))
   || !setBatchParams(param)) {	 /* out of memory condition */
  	exit_batch();		/* clear this erroreous batch context */
  	return 1;
  }

  return 0;
}
コード例 #3
0
ファイル: for.c プロジェクト: TijmenW/FreeDOS
int cmd_for(char *param)
{
	/*
	 * Perform FOR command.
	 *
	 * First check syntax is correct : FOR %v IN ( <list> ) DO <command>
	 *   v must be alphabetic, <command> must not be empty.
	 *
	 * If all is correct build a new bcontext structure which preserves
	 *   the necessary information so that readbatchline can expand
	 *   each the command prototype for each list element.
	 *
	 * You might look on a FOR as being a called batch file with one line
	 *   per list element.
	 */

	char *pp;
	char var;

	assert(param);

	/* Check that first element is % then an alpha char followed by space */

	if(*param != '%' || !isalpha(param[1]) || !isspace(param[2])) {
		displayString(TEXT_ERROR_BAD_VERABLE);
		return 1;
	}

	var = param[1];               /* Save FOR var name */
	param = ltrim(param + 2);   /* skip whitespaces */

	/* Check next element is 'IN' */

	if(!matchtok(param, "in")) {
		displayString(TEXT_ERROR_IN_MISSING);
		return 1;
	}

	/* Folowed by a '(', find also matching ')' */

	if(*param != '(' || 0 == (pp = strchr(param, ')'))) {
		displayString(TEXT_ERROR_MISSING_PARENTHESES);
		return 1;
	}

	*pp = '\0';
	param++;                      /* param now points at null terminated list */

	pp = ltrim(pp + 1);

	/* Check DO follows */

	if(!matchtok(pp, "do")) {
		displayString(TEXT_ERROR_DO_MISSING);
		return 1;
	}

	/* Check that command tail is not empty */

	if(*pp == '\0') {
		displayString(TEXT_ERROR_NO_COMMAND_AFTER_DO);
		return 1;
	}

	/* OK all is correct, build a bcontext.... */

	{
		struct bcontext *new = newBatchContext();

		if(!new)
			return 1;

		if((bc->forproto = strdup(pp)) == 0) {
			error_out_of_memory();
			exit_batch();   /* remove the newly created batch context */
			return 1;
		}

		if(!setBatchParams(param)) { /* Split out list */
			exit_batch();
			return 1;
		}

		bc->forvar = var;
		bc->shiftlevel = 1;     /* skip %0 <=> filename */
	}

	return 0;
}