Skip to content
builtin.c 1.03 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
** builtin.c for 42sh
**
** Made by Seblu
** Login   <seblu@epita.fr>
**
** Started on  Tue Apr 11 00:22:44 2006 Seblu
Seblu's avatar
Seblu committed
** Last update Sun Nov 12 19:56:53 2006 Seblu
Seblu's avatar
Seblu committed
*/

#include <string.h>
#include "builtin.h"

Seblu's avatar
Seblu committed
enum { BUILTIN_COUNT = 7 };
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
typedef int (*f_builtin)(char *argv[]);
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
struct builtin_table
{
  const char *name;
  f_builtin func;
};
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
static struct builtin_table builtin_table[BUILTIN_COUNT] =
Seblu's avatar
Seblu committed
  {
Seblu's avatar
Seblu committed
    {"cd", NULL}, //builtin_cd},
    {"echo", NULL}, //builtin_echo},
    {"exit", builtin_exit},
    {"shopt", NULL}, //builtin_shopt},
    {"source", NULL}, //builtin_source},
    {"unset", NULL}, //builtin_unset},
    {"export", NULL}, //builtin_export}
Seblu's avatar
Seblu committed
  };

Seblu's avatar
Seblu committed
int		is_a_builtin(const char *name)
Seblu's avatar
Seblu committed
{
  register int	i;

Seblu's avatar
Seblu committed
  for (i = 0; i < BUILTIN_COUNT; ++i)
    if (!strcmp(name, builtin_table[i].name))
Seblu's avatar
Seblu committed
      return 1;
  return 0;
}

Seblu's avatar
Seblu committed
int		exec_builtin(s_cmd_node *cmd)
Seblu's avatar
Seblu committed
{
  register int	i;

Seblu's avatar
Seblu committed
  for (i = 0; i < BUILTIN_COUNT; ++i)
    if (!strcmp(cmd->argv[0], builtin_table[i].name))
      return builtin_table[i].func(cmd->argv);
Seblu's avatar
Seblu committed
  return 0;
}