#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef UNIX
#define NUMOFCOMMANDS 9
#else
#define NUMOFCOMMANDS 7
#endif

const char  general[] = 
"sigspec: the name or the index of a signal, i.e., SIGTERM, or term, or TERM, or 15\n"
"jobspec: the jobid or processid or the string which is prefix of the command line \n"
"         as long as it is not ambiguous \n"
"command: a built in command, such as cd, jobs, kill, etc\n";

const char * commandusage[NUMOFCOMMANDS] = {
  "jobs\n",
  "history\n",
  "cd [pathname]\n",
  "exit\n",
#ifdef UNIX
  "kill [-sigspec] jobspec0 [jobspec1 ...]\n"
  "kill -l [sigspec ...]\n",
#else
  "kill [-sigspec] jobspec0 [jobspec1 ...]\n",
#endif
  "help [command ...]\n",
#ifdef UNIX
  "fg jobspec\n",
  "bg jobspec\n",
  "stop jobspec\n",
#else
  "ldir [pathname]\n"
#endif
};

void helpOneCommand(const char * command){
  if (strcmp(command, "jobs") == 0){
    printf("%s", commandusage[0]);
  }
  else if (strcmp(command, "history") == 0){
    printf("%s", commandusage[1]);
  }
  else if (strcmp(command, "cd") == 0){
    printf("%s", commandusage[2]);
  }
  else if (strcmp(command, "exit") == 0){
    printf("%s", commandusage[3]);
  }
  else if (strcmp(command, "kill") == 0){
    printf("%s", commandusage[4]);
  }
  else if (strcmp(command, "help") == 0){
    printf("%s", commandusage[5]);
  }
#ifdef UNIX
  else if (strcmp(command, "fg") == 0){
    printf("%s", commandusage[6]);
  }
  else if (strcmp(command, "bg") == 0){
    printf("%s", commandusage[7]);
  }
  else if (strcmp(command, "stop") == 0){
    printf("%s", commandusage[8]);
  }
#else
  else if (strcmp(command, "ldir") == 0){
    printf("%s", commandusage[6]);
  }
#endif

}

int help(int argc, char * const argv []) {
  int i;
  if (argc == 1){
    printf("%s", general);
    for (i = 0; i < NUMOFCOMMANDS; i++){
      printf("%s", commandusage[i]);
    }
  }
  else{
    printf("%s", general);
    for (i = 1; i< argc; i++){
      helpOneCommand(argv[i]);
    }
  }
  
  return 0;
}

