Skip to content
shell_init.c 1.87 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
Seblu's avatar
Seblu committed
** shell_init.c for 42sh
Seblu's avatar
Seblu committed
**
** Made by Seblu
** Login   <seblu@epita.fr>
**
** Started on  Sun Jul 16 20:11:09 2006 Seblu
** Last update Fri Aug 25 03:50:14 2006 Seblu
Seblu's avatar
Seblu committed
*/

#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
Seblu's avatar
Seblu committed
#include "shell.h"
Seblu's avatar
Seblu committed
#include "../option/option.h"
#include "../common/macro.h"
Seblu's avatar
Seblu committed
#include "../common/common.h"
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed

/* static int		pwd_isgood(); */
/* static void		set_default_option(struct s_opt *); */
Seblu's avatar
Seblu committed

/*!
Seblu's avatar
Seblu committed
** Create shell structure
Seblu's avatar
Seblu committed
**
Seblu's avatar
Seblu committed
** @return the new shell structure
Seblu's avatar
Seblu committed
*/
Seblu's avatar
Seblu committed
ts_shell		*shell_init(const char *argv0)
Seblu's avatar
Seblu committed
{
Seblu's avatar
Seblu committed
  ts_shell		*new;
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  secmalloc(new, sizeof (ts_shell));
Seblu's avatar
Seblu committed
/*   new->vars = NULL; */
Seblu's avatar
Seblu committed
/*   new->funcs = NULL; */
/*   new->history = NULL; */
Seblu's avatar
Seblu committed
  new->aliases = alias_init();
  new->options = option_init();
Seblu's avatar
Seblu committed
/*   if (!pwd_isgood()) */
/*   { */
/*      var_setenv("PWD", (tmp = var_getcwd()), 1); */
/*      free(tmp); */
/*   } */
/*   var_unsetenv("OLDPWD"); */
Seblu's avatar
Seblu committed
  new->name = basename(argv0);
  new->status = 0;
Seblu's avatar
Seblu committed
  return new;
}

/*!
** Default sh option
**
*/
Seblu's avatar
Seblu committed
/* static void		set_default_option(struct s_opt *opt) */
/* { */
/*   opt_unset("xpg_echo", opt); */
/*   opt_unset("dotglob", opt); */
/*   opt_unset("extglob", opt); */
/*   opt_unset("nocaseglob", opt); */
/*   opt_unset("expand_aliases", opt); */
/*   opt_unset("bonus", opt); */
/*   opt_unset("readline", opt); */
/* } */
Seblu's avatar
Seblu committed

/*!
** Check if pwd, if set on the current directory
**
** @return bool satus
*/
Seblu's avatar
Seblu committed
/* static int		pwd_isgood() */
/* { */
/*    char			*pwd; */
/*    struct stat		s_pwd; */
/*    ino_t		ino_pwd; */
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
/*    pwd = getenv("PWD"); */
/*    if (stat(pwd, &s_pwd) == -1) */
/*       return 0; */
/*    ino_pwd = s_pwd.st_ino; */
/*    pwd = var_getcwd(); */
/*    if (stat(pwd, &s_pwd) == -1) */
/*    { */
/*       perror("42sh"); */
/*       exit(1); */
/*    } */
/*    free(pwd); */
/*    return ino_pwd == s_pwd.st_ino; */
/* } */