Author | Jamozed <[email protected]> |
Date | 2021-11-12 02:30:04 |
Commit | af976fa8f6699a9133f89c8fb14b0925040f432d |
Parent | e9c29a96ef41435cd3db50bdccbe7481da96dd5a |
Remove repeated warning when eshrc is absent
Diffstat
M | src/conf.c | | | 1 | + |
M | src/esh.h | | | 17 | +---------------- |
M | src/eval.c | | | 3 | ++- |
M | src/lineread.c | | | 2 | +- |
M | src/main.c | | | 9 | ++++----- |
A | src/parse.h | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 files changed, 66 insertions, 23 deletions
diff --git a/src/conf.c b/src/conf.c index ef2560e..671c647 100644 --- a/src/conf.c +++ b/src/conf.c @@ -41,6 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. size_t conf_histsize = 8192; +/* Currently the "eshrc" function in main.c is used instead of this. */ void confread(void) { char *bp, *fp; register size_t bl; FILE *fi; diff --git a/src/esh.h b/src/esh.h index 9adb654..528deca 100644 --- a/src/esh.h +++ b/src/esh.h @@ -33,31 +33,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #ifndef ESH_ESH_H_SAZDXXFN #define ESH_ESH_H_SAZDXXFN -#include "lex.h" +#include "parse.h" #include "util/array.h" #include "util/util.h" -typedef enum { AK_NULL, AK_COMP, AK_COMM } ast_k; - -typedef struct ast_ *ast; - -struct ast_ { ast_k k; char *s; array c; }; - extern bool Lflag, Pflag; extern int _loop, _ret; -extern char *ast_ks[]; - -extern ast ast_init(void); -extern void ast_free(ast a); - -extern ast parse(lex *l); - extern int execute(ast a); extern void eval(char *src, UINT len); extern void eval_file(const char *file); -extern void ast_debug(ast a); - #endif // ESH_ESH_H_SAZDXXFN diff --git a/src/eval.c b/src/eval.c index 18ddc8d..df9db90 100644 --- a/src/eval.c +++ b/src/eval.c @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include "cll/error.h" +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -58,7 +59,7 @@ extern void eval_file(const char *file) { FILE *fi; char *fb; size_t fl; if (!(fi = fopen((char *)file, "r"))) { - warn("%s: %s", file, serr()); + warn("%s: %s", file, serr()); errno = 0; _ret = WEXITSTATUS(-1); return; } diff --git a/src/lineread.c b/src/lineread.c index e229868..022c21b 100644 --- a/src/lineread.c +++ b/src/lineread.c @@ -142,7 +142,7 @@ static char *lineedit(void) { tcraw(); fputs(l.prompt, stdout); for (register int c; (c = fgetc(stdin));) { - if (errno) { warn("%s", serr()); } + if (errno) { warn("FIXME: %s", serr()); errno = 0; } // printf("%02X\n", c); continue; switch (c) { diff --git a/src/main.c b/src/main.c index 8e0113f..2087ec7 100644 --- a/src/main.c +++ b/src/main.c @@ -31,11 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ /* - FIXME: When the file $XDG_CONFIG_HOME/esh/eshrc does not exist, an error - message is printed every time the shell recieves an input. The shell - should create this file if it does not already exist, but should also - not repeatedly display errors like this anyway. FIXME: Every second press of the delete key prints garbage to the terminal. + TODO: Deduplicate config handling functions, currently there are two. */ #include "esh.h" @@ -46,6 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include "cll/optget.h" #include <sys/stat.h> +#include <unistd.h> #include <errno.h> #include <setjmp.h> @@ -123,7 +121,8 @@ static void eshrc(void) { path = assert_malloc(strlen(dir) + strlen(base) + 1); strcpy(path, dir); strcat(path, base); free(dir); - eval_file(path); free(path); + if (access(path, F_OK) && errno == ENOENT) { errno = 0; } + else { eval_file(path); } free(path); } static void hlp(void) { diff --git a/src/parse.h b/src/parse.h new file mode 100644 index 0000000..3339f5f --- /dev/null +++ b/src/parse.h @@ -0,0 +1,57 @@ +// parse.h +// Parser header file for ESH +// Copyright (C) 2021, Jakob Wakeling +// All rights reserved. + +/* +OMKOV Permissive Licence, version 1.0 + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimers. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimers in the documentation and/or + other materials provided with the distribution. +* Neither the names of the copyright holders, nor the names of its contributors + may be used to endorse or promote products derived from this Software without + specific prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. +*/ + +#ifndef ESH_PARSE_H_R9WJSU27 +#define ESH_PARSE_H_R9WJSU27 + +#include "lex.h" +#include "util/array.h" +#include "util/util.h" + +typedef enum { + AK_NULL, AK_COMP, AK_COMM +} ast_k; + +typedef struct ast_ *ast; + +struct ast_ { ast_k k; char *s; array c; }; + +extern char *ast_ks[]; + +extern ast ast_init(void); +extern void ast_free(ast a); + +extern ast parse(lex *l); + +extern void ast_debug(ast a); + +#endif // ESH_PARSE_H_R9WJSU27