Skip to content
shell_prompt.c 1.05 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
** shell_prompt.c for 42sh in /home/seblu
**
** Made by Seblu
** Login   <seblu@epita.fr>
**
** Started on  Sun Jul 30 02:27:59 2006 Seblu
** Last update Fri Aug 25 08:18:07 2006 Seblu
Seblu's avatar
Seblu committed
*/

#include <stdio.h>
Seblu's avatar
Seblu committed
#include <string.h>
#include "shell.h"
#include "../common/macro.h"
Seblu's avatar
Seblu committed

/*!
** Return a prompt given by PS1, PS2, PS4 or the default if not set
**
** @param type
**
** @return
*/
const char *get_prompt(te_prompt pty)
  static char prompt[80];
Seblu's avatar
Seblu committed
  //fixme
  if (pty == PROMPT_PS1) {
Seblu's avatar
Seblu committed
    strncpy(prompt, shell->name, 78);
    strcpy(prompt + strlen(shell->name), "$ ");
  }
  else if (pty == PROMPT_PS2)
Seblu's avatar
Seblu committed
    strcpy(prompt, "> ");
  else if (pty == PROMPT_PS4)
Seblu's avatar
Seblu committed
    return strcpy(prompt, "");
  return prompt;

//todo gestion des variables !
void show_prompt(te_prompt pty)
{
  if (!isinteractive())
    return;
  char *prompt;
  switch (pty) {
  case PROMPT_PS1:
    prompt = "42sh ";
    break;
  case PROMPT_PS2:
    prompt = "> ";
    break;
  case PROMPT_PS4:
    prompt = "+";
    break;
  }
  fflush(stderr);
  fprintf(stderr, "%s", prompt);
  fflush(stderr);
}