Commit 290bb77a authored by Seblu's avatar Seblu

travail a la banque postale pendant les pauses repas

parent b8d1083f
Sebastien LUTTRINGER
Sébastien LUTTRINGER <seblu@seblu.net>
This diff is collapsed.
......@@ -61,4 +61,4 @@ do_group: 'do' compound_list 'done'
case_clause: case_item (';;' (\n)* case_item)* [;;]
case_item: ['('] WORD ('|' WORD)* ')' ( ('\n')* | compound_list )
\ No newline at end of file
case_item: ['('] WORD ('|' WORD)* ')' ( ('\n')* | compound_list )
......@@ -77,9 +77,9 @@ bin_PROGRAMS= 42sh
CLEANFILES= *~ \#*\#
EXTRA_DIST = AUTHORS README TODO
EXTRA_DIST = AUTHORS README TODO doc
.PHONY: tar doc re
.PHONY: tar doc man re
tar: distcheck
......@@ -87,3 +87,6 @@ re: clean all
doc:
cd $(srcdir)/doc && $(MAKE) doc
man:
cd $(srcdir)/doc && $(MAKE) man
......@@ -2,11 +2,25 @@
-- Voir probleme de syntax que j'accepte lorsque un EOF apparait avant une quote
fermante. Le token est valide alors que sous bash non. faire un test avant.
Maintenant il renvoie EOF a la place du token.
-- verifier toto \2>sex fonctionne.
-- verifier toto \2>sex fonctionne avec la substituion.
- Parser
-- aliases
-- history
- Option
-- voir probleme de non initialisation envoye par valgrind a chaque tour de boucle
\ No newline at end of file
-- voir probleme de non initialisation envoye par valgrind a chaque tour de boucle
- Exec
-- case
-- gestion des variables $0..$n
- Builtin
-- break
-- continue
-- export
- Glob
-- arithmetique
-- quoting
-- command substitution
\ No newline at end of file
#!/bin/sh
## bootstrap for 42sh in /home/seblu/devel/c/42sh
## bootstrap for 42sh
##
## Made by Seblu
## Login <seblu@epita.fr>
##
## Started on Sun Jul 16 19:43:53 2006 Seblu
## Last update Sun Jul 16 19:44:01 2006 Seblu
## Last update Thu Nov 23 14:44:19 2006 seblu
##
# Failures do matter.
......@@ -16,6 +16,3 @@ set -x
# install the GNU Build System.
autoreconf -i -f -v
# FIXME: autoheader does not obey --force.
find . -name 'config.h.in' | xargs touch
\ No newline at end of file
......@@ -128,6 +128,7 @@ AC_CONFIG_HEADERS([config.h])
# define Autoconf config files
AC_CONFIG_FILES([
Makefile
doc/Makefile
])
AC_OUTPUT
EXTRA_DIST=doxyfile 42sh.man
.PHONY: doc man
doc:
doxygen doxyfile
man:
groff 42sh.man -man -T ascii > manual.txt
groff 42sh.man -man -T ps | ps2pdf - manual.pdf
CLEANFILES=html *~
This diff is collapsed.
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Thu Nov 16 17:18:24 2006 seblu
** Last update Fri Nov 17 12:43:05 2006 seblu
** Last update Thu Nov 23 11:23:49 2006 seblu
*/
#include <assert.h>
......@@ -37,7 +37,7 @@ int builtin_alias(char *argv[])
ret = show_alias(carg) || ret;
else {
*equal = 0;
alias_add(shell->alias, strdup(carg), strdup(equal + 1));
alias_add(shell->alias, carg, equal + 1);
*equal = '=';
}
}
......
......@@ -5,17 +5,19 @@
** Login <seblu@epita.fr>
**
** Started on Thu May 11 09:32:30 2006 Seblu
** Last update Fri Nov 17 12:57:32 2006 seblu
** Last update Thu Nov 23 11:02:52 2006 seblu
*/
#include <stdio.h>
#include <assert.h>
#include "../shell/shell.h"
int builtin_set(char *argv[])
int builtin_set(char *argv[])
{
assert(argv);
fprintf(stderr, "%s: set: not yet implemeted.\n", shell->name);
argv = argv;
return 1;
assert(argv && argv[0]);
if (argv[1] == NULL)
for (size_t i = 0; i < shell->var->count; ++i)
printf("%s='%s'\n", shell->var->table[i].name,
shell->var->table[i].value);
return 0;
}
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Sat Apr 8 07:38:48 2006 Seblu
** Last update Fri Nov 17 14:08:10 2006 seblu
** Last update Thu Nov 23 11:28:39 2006 seblu
*/
#include <unistd.h>
......@@ -53,7 +53,7 @@ void exec_cmd(s_cmd_node *cmd)
if (cmd->prefix) exec_prefix(cmd->prefix, 0);
return;
}
if (is_a_function(shell->func, cmd->argv[0]))
if (func_exist(shell->func, cmd->argv[0]))
exec_function(cmd->argv);
else if (is_a_builtin(cmd->argv[0]))
shell->status = get_builtin(cmd->argv[0])(cmd->argv);
......@@ -71,7 +71,7 @@ void exec_piped_cmd(s_cmd_node *cmd)
if (cmd->prefix) exec_prefix(cmd->prefix, 0);
return;
}
if (is_a_function(shell->func, cmd->argv[0]))
if (func_exist(shell->func, cmd->argv[0]))
exec_function(cmd->argv);
else if (is_a_builtin(cmd->argv[0]))
shell->status = get_builtin(cmd->argv[0])(cmd->argv);
......@@ -126,11 +126,12 @@ static void exec_prefix(char **prefix, int glob)
for (int i = 0; prefix[i]; ++i) {
if (!(value = strchr(prefix[i], '=')))
assert(0);
*value++ = 0;
if (glob)
setenv2(prefix[i], value, !0);
*value = 0;
if (glob || getenv(prefix[i]) != NULL)
setenv2(prefix[i], value + 1, !0);
else
var_add(shell->var, prefix[i], value, !0);
var_add(shell->var, prefix[i], value + 1);
*value = '=';
}
}
......
......@@ -5,15 +5,16 @@
** Login <seblu@epita.fr>
**
** Started on Sat Mar 25 15:27:20 2006 Seblu
** Last update Fri Nov 17 14:27:00 2006 seblu
** Last update Thu Nov 23 14:38:27 2006 seblu
*/
#include "exec.h"
void exec_for(s_for_node *node)
{
assert(node);
//FIXME: code it
assert(0);
node = node;
assert(node && node->varname);
for (int i = 0; node->values[i]; ++i) {
var_add(shell->var, node->varname, node->values[i]);
exec_node(node->exec);
}
}
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Wed Aug 2 00:56:07 2006 Seblu
** Last update Fri Nov 17 15:53:35 2006 seblu
** Last update Thu Nov 23 14:24:39 2006 seblu
*/
#include <stdio.h>
......@@ -151,9 +151,9 @@ static s_ast_node *regnode(s_parser *parser, s_ast_node *node)
static void parse_error(s_parser *parser, s_token t)
{
if (t.id == TOK_EOF)
fprintf(stderr, "%s: syntax error: unexpected end of file\n", shell->name);
fprintf(stderr, "%s: syntax error: unexpected end of file.\n", shell->name);
else
fprintf(stderr, "%s: syntax error near unexpected token `%s'\n",
fprintf(stderr, "%s: syntax error near unexpected token `%s'.\n",
shell->name, t.str);
parser->error = 1;
shell->status = ERROR_PARSE;
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Wed Aug 23 00:39:17 2006 Seblu
** Last update Thu Nov 16 18:58:49 2006 seblu
** Last update Thu Nov 23 11:24:39 2006 seblu
*/
#include <string.h>
......@@ -30,7 +30,7 @@ s_alias *alias_init(void)
return new;
}
int alias_add(s_alias *alias, char *name, char *value)
int alias_add(s_alias *alias, const char *name, const char *value)
{
int ret;
......@@ -41,8 +41,8 @@ int alias_add(s_alias *alias, char *name, char *value)
alias->size += ALIAS_PADDING;
secrealloc(alias->table, alias->table, alias->size * sizeof (s_alias_item));
}
alias->table[alias->count - 1].name = name;
alias->table[alias->count - 1].value = value;
alias->table[alias->count - 1].name = strdup(name);
alias->table[alias->count - 1].value = strdup(value);
return ret;
}
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Wed Aug 23 00:32:09 2006 Seblu
** Last update Thu Nov 16 17:53:46 2006 seblu
** Last update Thu Nov 23 11:24:08 2006 seblu
*/
#ifndef ALIAS_H_
......@@ -45,7 +45,7 @@ s_alias *alias_init(void);
** @param name new alias name
** @param value new alias value
*/
int alias_add(s_alias *alias, char *name, char *value);
int alias_add(s_alias *alias, const char *name, const char *value);
/*!
** Remove an alias into an alias database
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Tue Nov 14 14:52:39 2006 seblu
** Last update Thu Nov 16 17:40:11 2006 seblu
** Last update Thu Nov 23 11:38:33 2006 seblu
*/
/*
......@@ -36,7 +36,7 @@ s_func *func_init(void)
return new;
}
int is_a_function(s_func *func, const char *name)
int func_exist(s_func *func, const char *name)
{
assert(func && name);
for (register size_t i = 0; i < func->count; ++i)
......@@ -47,10 +47,16 @@ int is_a_function(s_func *func, const char *name)
int func_add(s_func *func, char *name, s_ast_node *body)
{
int ret;
assert(func && name);
ret = func_del(func, name);
//check for add or update
for (register size_t i = 0; i < func->count; ++i)
if (!strcmp(name, func->table[i].name)) {
//update time
ast_destruct(func->table[i].body);
func->table[i].body = body;
return 1;
}
//add time
++func->count;
if (func->size < func->count) {
func->size += FUNC_PADDING;
......@@ -58,7 +64,7 @@ int func_add(s_func *func, char *name, s_ast_node *body)
}
func->table[func->count - 1].name = name;
func->table[func->count - 1].body = body;
return ret;
return 0;
}
int func_del(s_func *func, const char *name)
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Tue Nov 14 14:52:22 2006 seblu
** Last update Thu Nov 16 17:02:27 2006 seblu
** Last update Thu Nov 23 11:26:57 2006 seblu
*/
#ifndef FUNC_H_
......@@ -47,13 +47,16 @@ s_func *func_init(void);
**
** @return boolean existance
*/
int is_a_function(s_func *func, const char *name);
int func_exist(s_func *func, const char *name);
/*!
** Add a function. @var name and @var body are not copied.
** Add a function.
** @warning @var name and @var body are not copied.
** Not free/modify it after adding function.
** Return a boolean which explain if function @var name
** has been deleted before insertion.
** Think to delete reference in the tree, his destruction
** will destroy @var name and @var body.
**
** @param func func struct
** @param name func name
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Tue Nov 14 13:55:46 2006 seblu
** Last update Fri Nov 17 13:11:10 2006 seblu
** Last update Thu Nov 23 11:35:56 2006 seblu
*/
#include <string.h>
......@@ -15,9 +15,9 @@
#include "../common/macro.h"
#include "../common/function.h"
s_var *var_init(void)
s_var *var_init(void)
{
s_var *var;
s_var *var;
secmalloc(var, sizeof (s_var));
var->count = 0;
......@@ -26,13 +26,40 @@ s_var *var_init(void)
return var;
}
const char *var_get(const s_var *var, const char *name)
int var_add(s_var *var, const char *name, const char *value)
{
const char *res;
assert(var && name && value);
//check for add or update
for (register size_t i = 0; i < var->count; ++i)
if (!strcmp(name, var->table[i].name)) {
//update time
free(var->table[i].value);
var->table[i].value = strdup(value);
return 1;
}
//add time
++var->count;
if (var->size < var->count) {
var->size += VAR_PADDING;
secrealloc(var->table, var->table, var->size * sizeof (s_var_item));
}
var->table[var->count - 1].name = strdup(name);
var->table[var->count - 1].value = strdup(value);
return 0;
}
int var_exist(s_var *var, const char *name)
{
assert(var && name);
for (register size_t i = 0; i < var->count; ++i)
if (!strcmp(name, var->table[i].name))
return 1;
return 0;
}
const char *var_get(const s_var *var, const char *name)
{
assert(name && var);
if ((res = getenv(name)))
return res;
for (size_t i = 0; i < var->count; ++i) {
if (!(var->table[i].name))
continue;
......@@ -42,103 +69,22 @@ const char *var_get(const s_var *var, const char *name)
return NULL;
}
void var_add(s_var *var,
char *name,
char *value,
int overwrite)
int var_del(s_var *var, const char *name)
{
assert(0); var = var; name = value; overwrite = overwrite;
/* size_t i; */
/* int pos = -1; */
/* if (getenv(name)) { */
/* setenv2(name, value, overwrite); */
/* return; */
/* } */
/* for (i = 0; i < var->count; ++i) */
/* { */
/* if (!(var->table[i].name)) */
/* pos = i; */
/* else */
/* if (!strcmp(var->table[i].name, name)) */
/* break; */
/* } */
/* if (i < var->count) */
/* set_exist_var(var, value, overwrite, i); */
/* else */
/* if (pos != -1) */
/* set_non_exist_var(var, value, name, pos); */
/* else */
/* add_var(var, name, value); */
}
register size_t i;
int var_del(s_var *var, const char *name)
{
assert(var && name);
var = var; name = name;
/* if (getenv(name)) { */
/* var_unsetenv(name); */
/* return 0; */
/* } */
/* for (i = 0; i < var->len_var; ++i) */
/* { */
/* if (!(var->tab_var[i].name)) */
/* continue; */
/* if (!strcmp(var->tab_var[i].name, name)) */
/* { */
/* free(var->tab_var[i].name); */
/* free(var->tab_var[i].value); */
/* var->tab_var[i].name = NULL; */
/* var->tab_var[i].value = NULL; */
/* return 0; */
/* } */
/* } */
return 1;
}
/* static void add_var(struct s_var *var, */
/* const char *name, */
/* const char *value) */
/* { */
/* struct s_local_var *new_buff; */
/* if (var->len_var >= var->size) */
/* { */
/* var->size += 50; */
/* secrealloc(new_buff, var->tab_var, sizeof (struct s_local_var) * var->size); */
/* free(var->tab_var); */
/* var->tab_var = new_buff; */
/* } */
/* secstrdup(var->tab_var[var->len_var].name, name); */
/* secstrdup(var->tab_var[var->len_var].value, value); */
/* ++var->len_var; */
/* } */
/* static void set_exist_var(struct s_var *var, */
/* const char *value, */
/* char perm, */
/* unsigned int i) */
/* { */
/* if (!perm) */
/* return; */
/* free(var->tab_var[i].value); */
/* secstrdup(var->tab_var[i].value, value); */
/* } */
/* static void set_non_exist_var(struct s_var *var, */
/* const char *value, */
/* const char *name, */
/* unsigned int i) */
/* { */
/* secstrdup(var->tab_var[i].name, name); */
/* secstrdup(var->tab_var[i].value, value); */
/* } */
void var_print(const s_var *var)
{
for (size_t i = 0; i < var->count; ++i) {
if (!(var->table[i].name))
continue;
printf("%s=%s\n", var->table[i].name, var->table[i].value);
for (i = 0; i < var->count; ++i)
if (!strcmp(name, var->table[i].name))
break;
if (i >= var->count)
return 0;
free(var->table[i].name);
free(var->table[i].value);
var->table[i] = var->table[--var->count];
if (var->size - var->count > 2 * VAR_PADDING) {
var->size -= VAR_PADDING;
secrealloc(var->table, var->table, var->size * sizeof (s_var_item));
}
return 1;
}
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Tue Nov 14 13:54:14 2006 seblu
** Last update Fri Nov 17 13:11:08 2006 seblu
** Last update Thu Nov 23 11:41:04 2006 seblu
*/
#ifndef VAR_H_
......@@ -13,7 +13,10 @@
# include <stddef.h>
enum { VAR_DEFAULT_SIZE = 25 };
enum {
VAR_DEFAULT_SIZE = 25,
VAR_PADDING = 10,
};
typedef struct var_item
{
......@@ -51,20 +54,25 @@ s_var *var_init(void);
*/
const char *var_get(const s_var *var, const char *name);
void var_add(s_var *var,
char *name,
char *value,
int overwrite);
int var_del(s_var *var, const char *name);
/*!
** Print all variables on standard output
** Add a variable to a variable contener
**
** @param var contener of variable
** @param name variable name to add
** @param value variable value to add
**
** @param var var struct
** @return true if variable already exist else false
*/
void var_print(const s_var *var);
int var_add(s_var *var, const char *name, const char *value);
/*!
** Delete a variable from a variable contener
**
** @param var contener name
** @param name variable to destroy
**
** @return boolean del success (i.e. if exist or not)
*/
int var_del(s_var *var, const char *name);
#endif /* ! VAR_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment