# include "pantasks.h"

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

  char *endptr = NULL;
  int priority;
  Task *task;

  if (argc != 2) {
    gprint (GP_ERR, "USAGE: nice (priority)\n");
    return (FALSE);
  }

  JobTaskLock();
  task = GetNewTask ();
  if (task == NULL) {
    gprint (GP_ERR, "ERROR: not defining or running a task\n");
    JobTaskUnlock();
    return (FALSE);
  }

  priority = strtol (argv[1], &endptr, 10);
  if (*endptr) goto fail;
  if (priority < 0) goto fail;
  if (priority > 20) goto fail;

  task[0].priority = priority;
  JobTaskUnlock();
  return (TRUE);

fail:
    gprint (GP_ERR, "ERROR: nice (priority) -- priority must be an integer 0 to 20\n");
    return (FALSE);
}
