#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

#include "prompt.h"

int command_count = 1;

void prompt_init ()
{
      char buff[1024];  
      char temp[1024];

      /* find better way to get host, won't be set up 
	from init will it? */
      if (getenv("HOST"))
        {
	  sprintf(buff, "%s", getenv("HOST"));
        }
      else
        {
          sprintf(buff, "fsh");
        }
      sprintf(temp, "%s[!]", buff);
      if (getuid() == 0)
        {
          sprintf(buff, "%s-%s# ", temp, VERSION);
        }
      else
        {
          sprintf(buff, "%s-%s%% ", temp, VERSION);
        }
      sprintf(temp, "PROMPT=%s", buff);

      putenv(temp);
}

void prompt ()
{

    if(interactive)
    {
      char buff[1024];
      int i;
      if(buff = getenv("PROMPT"))
	{
      for (i=0;i<1024;i++)
	{
	  if (buff[i] == '!')
	    {
	      char temp[1024];
	      snprintf(temp1, i, "%s%c", buff, command_count);
	      printf("%s%s", temp, buff[i++]);
	    }
	}
      else
	{
	  printf("fsh% ");
	}
	}
      fflush(stdout);   
    }
}
