#ifndef JOBS_H
#define JOBS_H

#ifdef UNIX

#include <sys/types.h>
#include <signal.h>
#else

#include <windows.h>

#endif


#ifdef UNIX

struct job{
  pid_t pid;
  const char* command;
  int jobid;
  int status;  /*  0 - Running, 1 - Stopped, 2 - Exited, 3 - Done */
  struct job *nextjob;
};

extern struct command *ccForeground;
#else

struct job{
  PROCESS_INFORMATION pid;
  const char* command;
  int jobid;
  int status;  /*  0 - Running, 1 - Stopped, 2 - Exited, 3 - Done */
  struct job *nextjob;
};

#endif

//joblist always points to the top of the joblist.
//it is NULL if the list is empty.

struct job *joblist;

//addJob will insert job into the list whenever there
//is a hole for the jobid.
#ifdef UNIX
int addJob(pid_t pid, const char* command); 
int addStoppedJob(pid_t pid, const char* command);
#else
int addJob(PROCESS_INFORMATION pid, const char* command);
#endif

//remove the job with the specified jobid from the job list

int removeJobs(void);

//it returns 1 if it's called from printJobStatus and the
//status of that job did change to exit. So that it can
//be removed from the job list.
//opt==0 if it's called from printJobStatus 
int printOneJob(struct job *jobs, int opt);
//print out status of jobs that has a different status

int printJobStatus();

int jobs(int argc, char * const argv[]);

#endif
 
