Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@

# Debug files
*.dSYM/

# Coisas IntelliJ
.idea/

# Coisas MacOS
./DS_Store
.DS_Store
2 changes: 1 addition & 1 deletion NovoMontadorLinux/Montador_Ultimo_Beta_64Kb/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "montador.h"

/* Versao do montador */
#define VERSAO "1.1"
#define VERSAO "1.2"

/* Arquivos de entrada e saida */
FILE *in;
Expand Down
2 changes: 1 addition & 1 deletion NovoMontadorLinux/Montador_Ultimo_Beta_64Kb/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FILES = montador.c parser.c structs.c
OBJS = $(FILES:.c=.o)
NAME_FLAG = -o
LINK_FLAG = -g
COMP_FLAG = -march=native -03 -g
COMP_FLAGS = -march=native -O3 -g
NAME = montador

all: main.o $(OBJS)
Expand Down
42 changes: 41 additions & 1 deletion NovoMontadorLinux/Montador_Ultimo_Beta_64Kb/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,47 @@ void CarregaPrograma(char *nome)
in = fopen(nome,"r");
if (in == NULL) parser_Abort("Nao foi possivel carregar o arquivo de programa.");

line_count=parser_CountLines();
// Vai para o fim do arquivo
if (fseek(in, 0, SEEK_END) != 0) {
parser_Abort("Erro ao buscar o fim do arquivo.\n");
}

long size = ftell(in);
if (size == 0) {
parser_Abort("Arquivo vazio.\n");
}

// Volta para o último byte
if (fseek(in, -1, SEEK_END) != 0) {
parser_Abort("Erro ao buscar o último byte do arquivo.\n");
}

int last_char = fgetc(in); // Lê o último caractere

if (last_char != '\n') {
fclose(in);

// Abre para leitura e escrita
in = fopen(nome, "a"); // modo append: evita sobrescrever
if (in == NULL) {
parser_Abort("Não foi possível abrir o arquivo em modo append.\n");
}

if (fputc('\n', in) == EOF) {
parser_Abort("Erro ao escrever nova linha no fim do arquivo.\n");
}

fclose(in);
}

// Reabre para leitura normal
in = fopen(nome, "r");
if (in == NULL) {
parser_Abort("Não foi possível reabrir o arquivo em modo leitura.\n");
}

line_count = parser_CountLines();

progr_buffer = (char**) malloc(line_count*sizeof(char*));
fseek(in,0L,SEEK_SET);
parser_LoadProgram();
Expand Down