Skip to content

Commit b3d4aa9

Browse files
committed
added .gitattributes
1 parent f62086b commit b3d4aa9

File tree

2 files changed

+93
-6
lines changed

2 files changed

+93
-6
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.ms linguist-vendored=miniscript

main.c

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,106 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <string.h>
4+
#define LEN 80000
45

6+
// Calcula estimacion del inicio del bucle
7+
int loop(char src[], int pos);
8+
9+
// Busca errores en el codigo
10+
// void checkErrors(char src[], char args[]);
11+
12+
// Interpretador
513
int main(int argc, char *argv[]){
614

7-
// Check if all the needed arguments are provided
8-
if (argc != 2){
9-
fputs("usage: ./brainfuck [path/to/file.bf]\n", stderr);
15+
// Comprueba que los argumentos sean los correctos
16+
if (argc < 2 || argc > 3){
17+
fputs("usage: ./brainfuck [path/to/file.bf] [args]\n", stderr);
1018
return 1;
1119
}
1220

13-
// Get the source code from the file provided and print it
14-
char source[LENGTH]="";
21+
// Obtener el codigo fuente del archivo e imprimirlo
22+
char source[LEN]="";
1523
FILE *file = fopen(argv[1], "r");
16-
printf("Source code: %s\n", fgets(source, LENGTH, file));
24+
if (file == NULL){
25+
printf("\n\nFile \"%s\" was not found.\n", argv[1]);
26+
exit(1);
27+
}
28+
printf("\nSource code:\n %s", fgets(source, LEN, file));
29+
fclose(file);
30+
31+
// Obtiene los argumentos
32+
if (argc == 3){
33+
char args = *argv[1];
34+
printf("\n\nArguments: %s", args);
35+
}
36+
37+
puts("\n\n");
1738

39+
// Busca errores simples (no es 100% necesario para el funcionamiento del programa)
40+
// FIXME:
41+
// checkErrors(source, args);
1842

43+
puts("\n\nCode returned 0");
1944
return 0;
2045
}
46+
47+
int loop(char src[], int pos){
48+
int endLoop;
49+
char item;
50+
for(;;){
51+
item = src[--pos];
52+
if (item == ']'){
53+
endLoop++;
54+
} else if (item == '[' && endLoop != 0){
55+
endLoop--;
56+
} else if (item == '[' && endLoop == 0){
57+
break;
58+
}
59+
}
60+
return pos;
61+
}
62+
63+
// FIXME: Saltan errores que no deberan
64+
/*void checkErrors(char src[], char args[]){
65+
int lpStat, clStat, getInp, err;
66+
for (int i; i != strlen(src); i++){
67+
switch(src[i]){
68+
case('['):
69+
lpStat++;
70+
71+
case(']'):
72+
lpStat--;
73+
74+
case('>'):
75+
clStat++;
76+
77+
case('<'):
78+
clStat--;
79+
80+
case(','):
81+
getInp++;
82+
}
83+
}
84+
85+
if (lpStat != 0){
86+
err += 1;
87+
}
88+
89+
if (clStat < 0){
90+
err += 2;
91+
}
92+
93+
// Si no hay argumentos pero el programa pregunta por ellos o si no hay suficientes argumentos
94+
if (strlen(*argv) == 3){
95+
if (strlen(*argv) < getInp){
96+
err += 4;
97+
}
98+
} else if (getInp != 0){
99+
err += 4;
100+
}
101+
102+
if (err > 0){
103+
printf("\n\nCode returned %i\n", err);
104+
exit(err);
105+
}
106+
}*/

0 commit comments

Comments
 (0)