#ifndef COMMAND_H_ASDLFKAJSDFLKJADS
#define COMMAND_H_ASDLFKAJSDFLKJADS

#ifdef UNIX

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>

#else

#include <windows.h>

#endif

#include "history.h"

enum builtin {NOT_BUILTIN,JOBS,HISTORY,CD,EXIT,KILL,HELP,FG,BG,STOP,LDIR};

struct command {
  const char *cmdLine;
  char *cmdCopy;
  int argc;
  char * const *argv;
  int runInForeground;
#ifdef UNIX
  pid_t pid;
#else
  PROCESS_INFORMATION pi;
#endif
  const char *outputfn,*inputfn;
};

struct command *commandAlloc();

void commandDump(struct command *cc);

void builtinCommandExec(enum builtin whichBuiltIn, struct command *cc, struct history *h);

int commandSplit(struct command *cc);

enum builtin testBuiltin(struct command *cc);

void commandFree(struct command *self);

#ifdef UNIX
void redirectIO(struct command *cc, const char *argv0);
#endif

const char *commandGetCookedCmdLine(struct command *cc);

int commandExecChild(struct command *cc,const char *argv0);
int commandExecBuiltinChild(struct command *cc,enum builtin b,
    struct history *h,const char *argv0);

void commandExec(struct command *cc,const char *argv0,struct history *h);

#endif /* command_h */
