# include "basic.h"
# include "scheduler.h"

int task_command (int argc, char **argv) {

  int i;
  char *taskname;
  Task *task;

  if (argc < 2) {
    fprintf (stderr, "USAGE: command <command> <arg>. ..\n");
    fprintf (stderr, "  (define command machine for this task (or 'none'))\n");
    return (FALSE);
  }

  taskname = GetCurrentTask ();
  if (taskname == NULL) {
    fprintf (stderr, "ERROR: not defining or running a task\n");
    return (FALSE);
  }
  task = FindTask (taskname);
  if (task == NULL) {
    fprintf (stderr, "ERROR: current task not found??\n");
    return (FALSE);
  }

  /* free existing memory used by argv */
  if (task[0].argc != 0) {
    for (i = 0; i < task[0].argc; i++) {
      if (task[0].argv[i] != NULL) free (task[0].argv[i]);
    }
    free (task[0].argv);
  }

  /* create new memory for argv */
  task[0].argc = argc - 1;
  ALLOCATE (task[0].argv, char *, MAX (task[0].argc, 1));
  for (i = 0; i < task[0].argc; i++) {
    task[0].argv[i] = strcreate (argv[i+1]);
  }
  return (TRUE);
}


/** 
    careful with this: the command is supposed to be realized 
    for the Job, not the Task (at execution)
    the code is right, but who calls it when needs to be clarified.
 **/

