fix: Fixed ALL the code
This commit is contained in:
parent
03c35d5366
commit
97b7240286
10 changed files with 68 additions and 11 deletions
|
|
@ -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