Commit f3f51117 authored by Seblu's avatar Seblu

renommage divers

parent 018ce926
......@@ -32,8 +32,8 @@ bin_PROGRAMS=42sh
exec/exec_node.c \
parser/alias.h \
parser/alias.c \
parser/getln.h \
parser/getln.c \
parser/getline.h \
parser/getline.c \
parser/parser.h \
parser/parser.c \
parser/lexer.c \
......
/*
** getln.c for 42sh
** getline.c for 42sh
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** Started on Wed Aug 2 01:25:01 2006 Seblu
** Last update Mon Aug 28 22:55:18 2006 Seblu
** Last update Tue Aug 29 02:20:32 2006 Seblu
*/
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "../common/macro.h"
#include "getln.h"
#include "getline.h"
/*!
** Secure layer over strlen
......@@ -40,25 +40,25 @@ static void buf_str(char **str, char *append, unsigned n)
(*str)[ln + n] = 0;
}
s_getln *getln_open(int fd)
s_getline *getline_open(int fd)
{
s_getln *new_buf;
s_getline *new_buf;
secmalloc(new_buf, sizeof (s_getln));
secmalloc(new_buf, sizeof (s_getline));
new_buf->fd = fd;
new_buf->size = 0;
new_buf->offset = 0;
return new_buf;
}
void getln_close(s_getln *buf, int closefd)
void getline_close(s_getline *buf, int closefd)
{
if (closefd)
close(buf->fd);
free(buf);
}
char *getln(s_getln *buf)
char *getline(s_getline *buf)
{
char *string = NULL;
int i;
......@@ -77,7 +77,7 @@ char *getln(s_getln *buf)
if (buf->size - buf->offset > 0)
buf_str(&string, buf->data + buf->offset, buf->size - buf->offset);
buf->offset = 0;
buf->size = read(buf->fd, buf->data, GETLN_BUF_SIZE);
buf->size = read(buf->fd, buf->data, GETLINE_BUF_SIZE);
if (buf->size < 0)
buf->size = 0;
}
......
......@@ -5,21 +5,21 @@
** Login <seblu@epita.fr>
**
** Started on Wed Aug 2 01:06:25 2006 Seblu
** Last update Mon Aug 28 22:56:28 2006 Seblu
** Last update Tue Aug 29 02:20:16 2006 Seblu
*/
#ifndef GETLN_H_
# define GETLN_H_
#ifndef GETLINE_H_
# define GETLINE_H_
# define GETLN_BUF_SIZE 1024
# define GETLINE_BUF_SIZE 1024
typedef struct getln
typedef struct getline
{
int fd;
char data[GETLN_BUF_SIZE];
char data[GETLINE_BUF_SIZE];
unsigned offset;
int size;
} s_getln;
} s_getline;
/*!
** Read a line from fd. This read is bufferised !
......@@ -28,24 +28,24 @@ typedef struct getln
**
** @return malloced readded line
*/
char *getln(s_getln *buf);
char *getline(s_getline *buf);
/*!
** Correctly close an getln struct and if @arg closefd is true
** close the fd of getln struct
** Correctly close an getline struct and if @arg closefd is true
** close the fd of getline struct
**
** @param buf structure getln to close
** @param closefd if true (!0), close fd of getln struct
** @param buf structure getline to close
** @param closefd if true (!0), close fd of getline struct
*/
void getln_close(s_getln *buf, int closefd);
void getline_close(s_getline *buf, int closefd);
/*!
** Create a getln struct associed with @arg fd
** Create a getline struct associed with @arg fd
**
** @param fd fd associed with struct
**
** @return new struct
*/
s_getln *getln_open(int fd);
s_getline *getline_open(int fd);
#endif
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Sun Jul 30 04:36:53 2006 Seblu
** Last update Tue Aug 29 00:29:37 2006 Seblu
** Last update Tue Aug 29 02:33:06 2006 Seblu
*/
#include <stdio.h>
......@@ -14,7 +14,7 @@
#include <assert.h>
#include "parser.h"
#include "../shell/shell.h"
#include "getln.h"
#include "getline.h"
#include "../common/common.h"
#include "../common/macro.h"
......@@ -33,7 +33,7 @@
*/
// Order is very important for correct recognition !
static const s_token operators[] =
static const s_token operators[] =
{
{TOK_NEWLINE, "\n", 1},
{TOK_AND, "&&", 2},
......@@ -54,15 +54,15 @@ static const s_token operators[] =
{TOK_NONE, NULL, 0}
};
typedef struct s_quote
typedef struct quote
{
const char *start;
const size_t lenstart;
const char *stop;
const size_t lenstop;
} ts_quote;
} s_quote;
static const ts_quote quotes[] =
static const s_quote quotes[] =
{
{"\"", 1, "\"", 1},
{"'", 1, "'", 1},
......@@ -84,7 +84,7 @@ static const ts_quote quotes[] =
**
** @return true (!0) if a quote is found, else false (0)
*/
static int is_quote_start(const char *buf, size_t *buf_pos, const ts_quote **quote);
static int is_quote_start(const char *buf, size_t *buf_pos, const s_quote **quote);
/*!
** Check if @arg buf + *buf_pos point on the stop of quote sequence.
......@@ -97,7 +97,7 @@ static int is_quote_start(const char *buf, size_t *buf_pos, const ts_quote **quo
**
** @return true (!0) if a quote is found, else false (0)
*/
static int is_quote_stop(const char *buf, size_t *buf_pos, const ts_quote *quote);
static int is_quote_stop(const char *buf, size_t *buf_pos, const s_quote *quote);
/*!
** Return a predicat about c is a separator
......@@ -163,12 +163,12 @@ static void token_set(s_token *token, e_tokenid id, const char *s);
** ===========
*/
s_lexer *lexer_init(int fd)
s_lexer *lexer_init(int fd)
{
s_lexer *new;
secmalloc(new, sizeof (s_lexer));
new->stream = getln_open(fd);
new->stream = getline_open(fd);
new->buf = NULL;
new->buf_size = new->buf_pos = 0;
new->token.id = TOK_NONE;
......@@ -178,14 +178,14 @@ s_lexer *lexer_init(int fd)
return new;
}
s_token lexer_lookahead(s_lexer *lexer)
s_token lexer_lookahead(s_lexer *lexer)
{
if (lexer->token.id == TOK_NONE)
lexer_eattoken(lexer);
return lexer->token;
}
s_token lexer_gettoken(s_lexer *lexer)
s_token lexer_gettoken(s_lexer *lexer)
{
s_token buf;
......@@ -197,7 +197,7 @@ s_token lexer_gettoken(s_lexer *lexer)
return buf;
}
s_token lexer_getheredoc(s_lexer *lexer, const char *delim)
s_token lexer_getheredoc(s_lexer *lexer, const char *delim)
{
s_token token;
char *buf = NULL;
......@@ -209,7 +209,7 @@ s_token lexer_getheredoc(s_lexer *lexer, const char *delim)
}
show_prompt(PROMPT_PS2);
do {
line = getln(lexer->stream);
line = getline(lexer->stream);
if (line == NULL) {
lexer->eof = 1;
break;
......@@ -240,7 +240,7 @@ static void lexer_eattoken(s_lexer *lexer)
lexer->buf_size = 0;
}
//read a line if buf is empty
if (!lexer->buf_size && !lexer->eof && (lexer->buf = getln(lexer->stream))) {
if (!lexer->buf_size && !lexer->eof && (lexer->buf = getline(lexer->stream))) {
lexer->buf_size = strlen(lexer->buf);
lexer->buf_pos = 0;
}
......@@ -268,7 +268,7 @@ static int lexer_eatline(s_lexer *lexer)
//show incomplet recognition prompt
show_prompt(PROMPT_PS2);
//retrieve a new line
if (!(buf2 = getln(lexer->stream))) {
if (!(buf2 = getline(lexer->stream))) {
lexer->eof = 1;
return 0;
}
......@@ -285,7 +285,7 @@ static int lexer_cut(s_lexer *lexer)
size_t *buf_pos = &lexer->buf_pos, token_start, token_pos;
int end_found = 0;
char backed = 0, quoted = 0;
const ts_quote*quote;
const s_quote*quote;
// Rationale: Search begin of token
//eat separators (" ",\t, \v)
......@@ -339,7 +339,7 @@ static int is_operator(const char *buf, size_t *buf_pos, s_token *token)
return 0;
}
static int is_quote_start(const char *buf, size_t *buf_pos, const ts_quote **quote)
static int is_quote_start(const char *buf, size_t *buf_pos, const s_quote **quote)
{
for (register int i = 0; quotes[i].start; ++i)
if (!strncmp(buf + *buf_pos, quotes[i].start, quotes[i].lenstart)) {
......@@ -351,7 +351,7 @@ static int is_quote_start(const char *buf, size_t *buf_pos, const ts_quote **quo
return 0;
}
static int is_quote_stop(const char *buf, size_t *buf_pos, const ts_quote *quote)
static int is_quote_stop(const char *buf, size_t *buf_pos, const s_quote *quote)
{
if (!strncmp(buf + *buf_pos, quote->stop, quote->lenstop)) {
*buf_pos += quote->lenstop - 1;
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Wed Aug 2 00:56:07 2006 Seblu
** Last update Tue Aug 29 01:02:02 2006 Seblu
** Last update Tue Aug 29 02:28:28 2006 Seblu
*/
#include <stdio.h>
......@@ -15,7 +15,7 @@
#include "parser.h"
#include "../common/macro.h"
#include "../shell/shell.h"
#include "getln.h"
#include "getline.h"
/*
** ============
......
......@@ -5,7 +5,7 @@
** Login <seblu@epita.fr>
**
** Started on Wed Aug 2 00:49:50 2006 Seblu
** Last update Tue Aug 29 00:24:16 2006 Seblu
** Last update Tue Aug 29 02:28:08 2006 Seblu
*/
#include <setjmp.h>
......@@ -14,7 +14,7 @@
#ifndef PARSER_H_
# define PARSER_H_
# include "getln.h"
# include "getline.h"
// Define is parser or lexer is run for DEBBUGING
#define DEBUG_PARSER 1
......@@ -78,7 +78,7 @@ typedef struct lexer
char *buf;
size_t buf_size; //without \0
size_t buf_pos;
s_getln *stream;
s_getline *stream;
} s_lexer;
typedef struct parser
......
/*
** shell_getopt.c
**
** Made by Seblu
** Login <seblu@epita.fr>
**
** Started on Sun Jul 30 02:24:42 2006 Seblu
** Last update Sun Jul 30 02:53:05 2006 Seblu
*/
#include <stdio.h>
#include "shell.h"
void shell_getopt(int argc, char *argv[])
{
if (argc == 1)
return;
for (int i = 1; i < argc; ++i)
{
printf("Argument %d: %s\n", argc, argv[i]);
}
}
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