#include <stdio.h>
#include <stdlib.h>

int main(void) {
	printf("%s\n", "hello");
	
	printf("%s\n\n", "lets run block a");
	asmParser("PATH/TO/FILE.TXT", "a"); // replace PATH with  the location of your assembly text file
	
	printf("%s\n\n", "lets run block 1");
	asmParser("PATH/TO/FILE.TXT", "a"); // replace PATH with  the location of your assembly text file
	
	printf("%s\n\n", "done.");
	return(1);
};

int asmParser(char* fileLoc, char* blockName) {
	FILE *theFile = fopen(fileLoc, "r");

	if (theFile != NULL) {
		char theLine[50];
		int doASM = 0;
		
		// loop for each line
		while (!feof(theFile)) {
			fgets(theLine, 50, theFile);
			
			if ((strstr(theLine, "startblock") != NULL) && (strstr(theLine, blockName) != NULL)) { // found start of block, begin execution
				doASM = 1;
			} else if ((strstr(theLine, "endblock") != NULL) && (strstr(theLine, blockName) != NULL)) {  // found end of block, terminate
				doASM = 0;
				return(1);
			} else {
				if (doASM == 1) {
					// format command for asm()
					strcat(theLine, "\n\t");
					
					// execute command
					asm(theLine);
					//printf("%s\n", theLine); // used for testing
				}
			}
		}
		
		return(2); // didn't find "endblock" call, terminate
	} else {
		fclose(theFile);
		printf("%s\n", "File open fail.");
		
		return(0); // didn't find file, terminate
	}
};