mirror of
				https://github.com/thornAvery/jep-hack.git
				synced 2025-11-04 21:01:01 +13:00 
			
		
		
		
	Build Bug Fix! Probably. Back up your shit if you've not been getting that bug
Noticed something seemed to be acting up with scan_includes when checking if the bug was present on cygwin, which it was for me, so I went to check to see if there was an update to it for vanilla pokecrystal and YEP - Updated scan_includes.c to the current version present in pokecrystal, seems to fix bugs preventing some people from building.
This commit is contained in:
		
							parent
							
								
									67790a0e73
								
							
						
					
					
						commit
						844aa6d766
					
				| 
						 | 
					@ -3,6 +3,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "common.h"
 | 
					#include "common.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <ctype.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void parse_args(int argc, char *argv[], bool *strict) {
 | 
					void parse_args(int argc, char *argv[], bool *strict) {
 | 
				
			||||||
	struct option long_options[] = {
 | 
						struct option long_options[] = {
 | 
				
			||||||
		{"strict", no_argument, 0, 's'},
 | 
							{"strict", no_argument, 0, 's'},
 | 
				
			||||||
| 
						 | 
					@ -40,31 +42,47 @@ void scan_file(const char *filename, bool strict) {
 | 
				
			||||||
	fclose(f);
 | 
						fclose(f);
 | 
				
			||||||
	contents[size] = '\0';
 | 
						contents[size] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (char *ptr = contents; ptr && ptr - contents < size; ptr++) {
 | 
						for (char *ptr = contents; ptr && ptr < contents + size; ptr++) {
 | 
				
			||||||
		bool is_incbin = false, is_include = false;
 | 
							ptr = strpbrk(ptr, ";\"Ii");
 | 
				
			||||||
 | 
							if (!ptr) {
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		switch (*ptr) {
 | 
							switch (*ptr) {
 | 
				
			||||||
		case ';':
 | 
							case ';':
 | 
				
			||||||
			ptr = strchr(ptr, '\n');
 | 
								// Skip comments until the end of the line
 | 
				
			||||||
			if (!ptr) {
 | 
								ptr += strcspn(ptr + 1, "\r\n");
 | 
				
			||||||
				fprintf(stderr, "%s: no newline at end of file\n", filename);
 | 
								if (*ptr) {
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			break;
 | 
					 | 
				
			||||||
		case '"':
 | 
					 | 
				
			||||||
			ptr++;
 | 
					 | 
				
			||||||
			ptr = strchr(ptr, '"');
 | 
					 | 
				
			||||||
			if (ptr) {
 | 
					 | 
				
			||||||
				ptr++;
 | 
									ptr++;
 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				fprintf(stderr, "%s: unterminated string\n", filename);
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							case '"':
 | 
				
			||||||
 | 
								// Skip string literal until the closing quote
 | 
				
			||||||
 | 
								ptr += strcspn(ptr + 1, "\"");
 | 
				
			||||||
 | 
								if (*ptr) {
 | 
				
			||||||
 | 
									ptr++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case 'I':
 | 
							case 'I':
 | 
				
			||||||
		case 'i':
 | 
							case 'i':
 | 
				
			||||||
			is_incbin = !strncmp(ptr, "INCBIN", 6) || !strncmp(ptr, "incbin", 6);
 | 
								/* empty statement between the label and the variable declaration */;
 | 
				
			||||||
			is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7);
 | 
								// Check that an INCLUDE/INCBIN starts as its own token
 | 
				
			||||||
 | 
								char before = ptr > contents ? *(ptr - 1) : '\n';
 | 
				
			||||||
 | 
								if (!isspace((unsigned)before) && before != ':') {
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								bool is_incbin = !strncmp(ptr, "INCBIN", 6) || !strncmp(ptr, "incbin", 6);
 | 
				
			||||||
 | 
								bool is_include = !strncmp(ptr, "INCLUDE", 7) || !strncmp(ptr, "include", 7);
 | 
				
			||||||
			if (is_incbin || is_include) {
 | 
								if (is_incbin || is_include) {
 | 
				
			||||||
				ptr = strchr(ptr, '"');
 | 
									// Check that an INCLUDE/INCBIN ends as its own token
 | 
				
			||||||
				if (ptr) {
 | 
									ptr += is_include ? 7 : 6;
 | 
				
			||||||
 | 
									if (!isspace((unsigned)*ptr) && *ptr != '"') {
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									ptr += strspn(ptr, " \t");
 | 
				
			||||||
 | 
									if (*ptr == '"') {
 | 
				
			||||||
 | 
										// Print the file path and recursively scan INCLUDEs
 | 
				
			||||||
					ptr++;
 | 
										ptr++;
 | 
				
			||||||
					char *include_path = ptr;
 | 
										char *include_path = ptr;
 | 
				
			||||||
					size_t length = strcspn(ptr, "\"");
 | 
										size_t length = strcspn(ptr, "\"");
 | 
				
			||||||
| 
						 | 
					@ -74,6 +92,12 @@ void scan_file(const char *filename, bool strict) {
 | 
				
			||||||
					if (is_include) {
 | 
										if (is_include) {
 | 
				
			||||||
						scan_file(include_path, strict);
 | 
											scan_file(include_path, strict);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										fprintf(stderr, "%s: no file path after INC%s\n", filename, is_include ? "LUDE" : "BIN");
 | 
				
			||||||
 | 
										// Continue to process a comment
 | 
				
			||||||
 | 
										if (*ptr == ';') {
 | 
				
			||||||
 | 
											ptr--;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue