Loading src/Makefile.am +2 −2 Original line number Diff line number Diff line Loading @@ -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 \ Loading src/parser/getln.c→src/parser/getline.c +9 −9 Original line number Diff line number Diff line /* ** 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 Loading Loading @@ -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; Loading @@ -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; } Loading src/parser/getln.h→src/parser/getline.h +51 −0 Original line number Diff line number Diff line Loading @@ -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 ! Loading @@ -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 src/parser/lexer.c +19 −19 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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" Loading Loading @@ -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}, Loading @@ -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. Loading @@ -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 Loading Loading @@ -168,7 +168,7 @@ 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; Loading Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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; } Loading @@ -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) Loading Loading @@ -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)) { Loading @@ -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; Loading src/parser/parser.c +2 −2 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -15,7 +15,7 @@ #include "parser.h" #include "../common/macro.h" #include "../shell/shell.h" #include "getln.h" #include "getline.h" /* ** ============ Loading Loading
src/Makefile.am +2 −2 Original line number Diff line number Diff line Loading @@ -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 \ Loading
src/parser/getln.c→src/parser/getline.c +9 −9 Original line number Diff line number Diff line /* ** 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 Loading Loading @@ -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; Loading @@ -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; } Loading
src/parser/getln.h→src/parser/getline.h +51 −0 Original line number Diff line number Diff line Loading @@ -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 ! Loading @@ -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
src/parser/lexer.c +19 −19 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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" Loading Loading @@ -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}, Loading @@ -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. Loading @@ -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 Loading Loading @@ -168,7 +168,7 @@ 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; Loading Loading @@ -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; Loading Loading @@ -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; } Loading Loading @@ -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; } Loading @@ -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) Loading Loading @@ -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)) { Loading @@ -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; Loading
src/parser/parser.c +2 −2 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -15,7 +15,7 @@ #include "parser.h" #include "../common/macro.h" #include "../shell/shell.h" #include "getln.h" #include "getline.h" /* ** ============ Loading