diff --git a/src/Makefile.am b/src/Makefile.am index 8b1afb61106c3be7be43581fcfe4a2a13532d8e6..31b0f50753eeae3b044e31fa83de65a0669e29f0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/parser/getln.c b/src/parser/getline.c similarity index 80% rename from src/parser/getln.c rename to src/parser/getline.c index fad97785050bb9e5b8104888554f4ac334f6dbbc..049dd7e60a01dbb5d0d5a1dce05cde7200495123 100644 --- a/src/parser/getln.c +++ b/src/parser/getline.c @@ -1,18 +1,18 @@ /* -** getln.c for 42sh +** getline.c for 42sh ** ** Made by Seblu ** Login ** ** 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 #include #include #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; } diff --git a/src/parser/getline.h b/src/parser/getline.h new file mode 100644 index 0000000000000000000000000000000000000000..a7b91c0bd6cf99bebf9e5559e0ba29c10600ae3b --- /dev/null +++ b/src/parser/getline.h @@ -0,0 +1,51 @@ +/* +** getln.h for 42sh +** +** Made by Seblu +** Login +** +** Started on Wed Aug 2 01:06:25 2006 Seblu +** Last update Tue Aug 29 02:20:16 2006 Seblu +*/ + +#ifndef GETLINE_H_ +# define GETLINE_H_ + +# define GETLINE_BUF_SIZE 1024 + +typedef struct getline +{ + int fd; + char data[GETLINE_BUF_SIZE]; + unsigned offset; + int size; +} s_getline; + +/*! +** Read a line from fd. This read is bufferised ! +** +** @param buf struct getln +** +** @return malloced readded line +*/ +char *getline(s_getline *buf); + +/*! +** Correctly close an getline struct and if @arg closefd is true +** close the fd of getline struct +** +** @param buf structure getline to close +** @param closefd if true (!0), close fd of getline struct +*/ +void getline_close(s_getline *buf, int closefd); + +/*! +** Create a getline struct associed with @arg fd +** +** @param fd fd associed with struct +** +** @return new struct +*/ +s_getline *getline_open(int fd); + +#endif diff --git a/src/parser/getln.h b/src/parser/getln.h deleted file mode 100644 index 0670566b36dfcf0d5961c6e45f8020f96feae934..0000000000000000000000000000000000000000 --- a/src/parser/getln.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -** getln.h for 42sh -** -** Made by Seblu -** Login -** -** Started on Wed Aug 2 01:06:25 2006 Seblu -** Last update Mon Aug 28 22:56:28 2006 Seblu -*/ - -#ifndef GETLN_H_ -# define GETLN_H_ - -# define GETLN_BUF_SIZE 1024 - -typedef struct getln -{ - int fd; - char data[GETLN_BUF_SIZE]; - unsigned offset; - int size; -} s_getln; - -/*! -** Read a line from fd. This read is bufferised ! -** -** @param buf struct getln -** -** @return malloced readded line -*/ -char *getln(s_getln *buf); - -/*! -** Correctly close an getln struct and if @arg closefd is true -** close the fd of getln struct -** -** @param buf structure getln to close -** @param closefd if true (!0), close fd of getln struct -*/ -void getln_close(s_getln *buf, int closefd); - -/*! -** Create a getln struct associed with @arg fd -** -** @param fd fd associed with struct -** -** @return new struct -*/ -s_getln *getln_open(int fd); - -#endif diff --git a/src/parser/lexer.c b/src/parser/lexer.c index af2a1f74a14cddeeaa6c3e94ad5c1363ac5b17a7..de30c6ce7eb97ad07684668ab58e23f9945186ee 100644 --- a/src/parser/lexer.c +++ b/src/parser/lexer.c @@ -5,7 +5,7 @@ ** Login ** ** 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 @@ -14,7 +14,7 @@ #include #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; diff --git a/src/parser/parser.c b/src/parser/parser.c index d60bb0e2ca9f95490642e81c18ac3d9ecaafc4a5..9ec6aa367ad67ebfe05c4d964bf5fdee6163b299 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -5,7 +5,7 @@ ** Login ** ** 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 @@ -15,7 +15,7 @@ #include "parser.h" #include "../common/macro.h" #include "../shell/shell.h" -#include "getln.h" +#include "getline.h" /* ** ============ diff --git a/src/parser/parser.h b/src/parser/parser.h index 54fca506cb31871db35fd3323f44c830a1cd329a..9d74fcb9be49df9f8b5574cec71bd1b503b7972e 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -5,7 +5,7 @@ ** Login ** ** 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 @@ -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 diff --git a/src/shell/shell_getopt.c b/src/shell/shell_getopt.c deleted file mode 100644 index 0ce03095b4ab6954b8961f28edde1e57548199a7..0000000000000000000000000000000000000000 --- a/src/shell/shell_getopt.c +++ /dev/null @@ -1,22 +0,0 @@ -/* -** shell_getopt.c -** -** Made by Seblu -** Login -** -** Started on Sun Jul 30 02:24:42 2006 Seblu -** Last update Sun Jul 30 02:53:05 2006 Seblu -*/ - -#include -#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]); - } -}