# include "pantasks.h"

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

  int status;
  char command[1024];
  IOBuffer buffer;

  if (argc != 2) {
    gprint (GP_ERR, "USAGE: controller jobstack (jobstack)\n");
    gprint (GP_ERR, "       (jobstack) : pending, busy, exit, crash, hung, done\n");
    return (FALSE);
  }

  /* check if controller is running */
  status = CheckControllerStatus ();
  if (!status) {
    gprint (GP_LOG, "controller is not active\n");
    return (TRUE);
  }

  // XXX this has an error?  test this out...
  sprintf (command, "jobstack %s", argv[1]);
  InitIOBuffer (&buffer, 0x100);

  SerialThreadLock ();
  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
  SerialThreadUnlock ();

  if (status) {
    gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);
  } else {
    gprint (GP_LOG, "controller is not communicating\n");
  }
  FreeIOBuffer (&buffer);
  return (TRUE);
}
