fix: Fixed ALL the code
This commit is contained in:
parent
03c35d5366
commit
97b7240286
10 changed files with 68 additions and 11 deletions
43
.gitignore
vendored
43
.gitignore
vendored
|
|
@ -132,3 +132,46 @@ $RECYCLE.BIN/
|
|||
*.msm
|
||||
*.msp
|
||||
*.lnk
|
||||
|
||||
# Autotools (since it disappeared for some reason)
|
||||
|
||||
Makefile.in
|
||||
/ar-lib
|
||||
/mdate-sh
|
||||
/py-compile
|
||||
/test-driver
|
||||
/ylwrap
|
||||
.deps/
|
||||
.dirstamp
|
||||
|
||||
autom4te.cache
|
||||
/autoscan.log
|
||||
/autoscan-*.log
|
||||
/aclocal.m4
|
||||
/compile
|
||||
/config.cache
|
||||
/config.guess
|
||||
/config.h.in
|
||||
/config.log
|
||||
/config.status
|
||||
/config.sub
|
||||
/configure
|
||||
/configure.scan
|
||||
/depcomp
|
||||
/install-sh
|
||||
/missing
|
||||
/stamp-h1
|
||||
|
||||
/libtool
|
||||
/ltmain.sh
|
||||
.libs/
|
||||
|
||||
/texinfo.tex
|
||||
|
||||
m4/libtool.m4
|
||||
m4/ltoptions.m4
|
||||
m4/ltsugar.m4
|
||||
m4/ltversion.m4
|
||||
m4/lt~obsolete.m4
|
||||
|
||||
Makefile
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ AC_PROG_CC
|
|||
# List Makefiles in subdirectories
|
||||
AC_CONFIG_FILES([
|
||||
src/Makefile
|
||||
src/ast/Makefile
|
||||
src/parser/Makefile
|
||||
src/lexer/Makefile
|
||||
src/io_backend/Makefile
|
||||
|
|
|
|||
|
|
@ -112,12 +112,11 @@ int execution(struct ast *ast)
|
|||
return 0;
|
||||
}
|
||||
case AST_CMD: {
|
||||
struct ast_cmd *cmd = ast->data->ast_cmd; // Cast implicit
|
||||
struct ast_cmd *cmd = ast_get_cmd(ast);
|
||||
return exec_command(cmd); // It's recursive
|
||||
}
|
||||
case AST_IF: {
|
||||
struct ast_if *if_node =
|
||||
ast->data->ast_if; // We cast the union to ast_if
|
||||
struct ast_if *if_node = ast_get_if(ast);
|
||||
int cond = execution(if_node->condition);
|
||||
if (cond == 0) // True
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,18 +11,19 @@ int iob_init(struct iob_context *ctx)
|
|||
|
||||
switch (context.mode)
|
||||
{
|
||||
IOB_MODE_STDIN:
|
||||
case IOB_MODE_STDIN:
|
||||
input = stdin;
|
||||
return 0;
|
||||
|
||||
IOB_MODE_SCRIPT:
|
||||
case IOB_MODE_SCRIPT:
|
||||
if (context.args == NULL)
|
||||
return -2;
|
||||
input = fopen(context.args, "r");
|
||||
if (input == NULL)
|
||||
return -4;
|
||||
return 0;
|
||||
|
||||
IOB_MODE_CMD:
|
||||
case IOB_MODE_CMD:
|
||||
if (context.args != NULL)
|
||||
return -2;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
#include "lexer.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "io_backend/io_backend.h"
|
||||
|
||||
static char *end_last_token;
|
||||
static ssize_t remaining_chars;
|
||||
|
||||
char *new_token(char *begin, size_t size)
|
||||
char *new_token(char *begin, ssize_t size)
|
||||
{
|
||||
char *res = calloc(size + 1, sizeof(char));
|
||||
if (res == NULL)
|
||||
|
|
@ -56,6 +59,7 @@ char *get_token(void)
|
|||
// skip blank char
|
||||
// exit from loop
|
||||
char *token = new_token(stream, i);
|
||||
return token;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
|
@ -64,4 +68,5 @@ char *get_token(void)
|
|||
}
|
||||
|
||||
remaining_chars -= i;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,7 @@
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ struct ast *get_ast()
|
|||
|
||||
struct ast *get_ast_str(char *command)
|
||||
{
|
||||
(void)command;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
lib_LIBRARIES = libutils.a
|
||||
|
||||
libutils_a_SOURCES = \
|
||||
string_utils.c
|
||||
string_utils/string_utils.c \
|
||||
ast/ast.c \
|
||||
lists/lists.c
|
||||
|
||||
libutils_a_CPPFLAGS = -I$(top_srcdir)/src
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
#include "utils/string_utils/string_utils.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
|
||||
ssize_t skip_blanks(char **str)
|
||||
{
|
||||
|
|
@ -7,7 +10,7 @@ ssize_t skip_blanks(char **str)
|
|||
return 0;
|
||||
}
|
||||
ssize_t skipped = 0;
|
||||
while (str[skipped] != '\0' && !isblank(str[skipped]))
|
||||
while (*str[skipped] != '\0' && !isblank(str[skipped]))
|
||||
{
|
||||
skipped++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef STRING_UTILS_H
|
||||
#define STRING_UTILS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/*
|
||||
* @brief: skips blank characters at the beginning of [str].
|
||||
* @return: number of characters skipped.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue