Skip to content
Snippets Groups Projects
Commit 3a82cb92 authored by Vishnu Menon's avatar Vishnu Menon :bulb:
Browse files

clean lines

parent aa5c78f5
No related branches found
No related tags found
No related merge requests found
#include "../lib/jsmn/jsmn.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// my everlasting commitment to ridding code of magic numbers :)
#define MEMORY_SIZE 65535
......@@ -12,8 +15,7 @@ int sp, fp = MEMORY_SIZE;
int img, but, lab, tab = 0; // renaming these too
int main(int argc, char* argv[])
{
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Error: Did not specify file.");
......@@ -33,7 +35,26 @@ int main(int argc, char* argv[])
char buffer[BUFFER_SIZE];
while(fgets(buffer, BUFFER_SIZE-1, executable) != NULL) {
printf("%s", buffer);
char instruction_set[BUFFER_SIZE];
// cleanup for easier jsmm parsing
// first line has a weird header
int header = (buffer[0] == 'v') ? strlen("var tape='") : 0;
// make sure the brackets are valid in the context of this line
for (int i = header; buffer[i] != 0; i++) {
instruction_set[i-header] = buffer[i];
if (buffer[i] == '\\' && header > 0) {
instruction_set[i - header] = 0;
instruction_set[i - header - 1] = ']';
} else if (buffer[i] == '\\' || buffer[i] == '\'') {
instruction_set[i - header] = 0;
instruction_set[i - header - 1] = 0;
}
}
printf("%s\n", instruction_set);
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment