Exemplo n.º 1
0
label_t *add_label (char *name, int value) {
	label_t *new_label;
	define_t *conflict_define;

	if (mode & MODE_CODE_COUNTER) {
		free(name);
		return NULL;
	}

	if (!case_sensitive) {
		char *new_name = strup (name);
		free (name);
		name = new_name;
	}

	if ((conflict_define = search_defines(name))) {
		show_error ("conflicting definition of '%s'", name);
		//if (suppress_errors == false) {
			show_error_prefix (conflict_define->input_file, conflict_define->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_RED);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		//}
		return NULL;
	}
	
	if ((new_label = search_labels (name))) {
		if (value != new_label->value) {
			new_label->value = value;
			show_warning ("redefinition of '%s'", name);
			show_warning_prefix (new_label->input_file, new_label->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_YELLOW);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		}
	} else {
		new_label = (label_t *)malloc (sizeof (label_t));
		
		if (new_label != NULL) {
			new_label->name = name;
			new_label->line_num = line_num;
			new_label->input_file = strdup(curr_input_file);
			new_label->value = value;
			
			hash_insert (label_table, new_label);
		}
		
	}
	return new_label;
}
Exemplo n.º 2
0
static void PrintSPASMError(const LPERRORINSTANCE lpError)
{
    if (mode & MODE_CODE_COUNTER)
    {
        return;
    }

    assert(lpError != NULL);
    if ((lpError->dwErrorCode != SPASM_ERR_SUCCESS) || (lpError->lpszErrorText != NULL))
    {
        WORD orig_attributes = save_console_attributes();
        set_console_attributes(lpError->fIsWarning ? COLOR_YELLOW : COLOR_RED);
        if (lpError->lpszAnnotation != NULL)
        {
            printf("%s\n", lpError->lpszAnnotation);
        }

        printf("%s\n", lpError->lpszErrorText);
#ifdef WINVER
        OutputDebugString(lpError->lpszErrorText);
        OutputDebugString(_T("\n"));
#endif
        restore_console_attributes(orig_attributes);
    }
}
Exemplo n.º 3
0
void show_define (define_t *define) {
	WORD console_attrib = save_console_attributes();
	set_console_attributes (COLOR_BLUE);
	fputs (define->name, stdout);
	if (define->num_args > 0) {
		int i;
		putchar ('(');
		for (i = 0; i < define->num_args; i++) {
			if (i != 0) fputs (", ", stdout);
			fputs (define->args[i], stdout);

		}
		putchar (')');
	}
	if (define->contents != NULL)
	{
		printf (": %s", define->contents);
	}
	putchar ('\n');
	restore_console_attributes(console_attrib);

#ifdef WIN32
	if (define->contents != NULL)
	{
		OutputDebugString(define->contents);
		OutputDebugString("\n");
	}
#endif

}
Exemplo n.º 4
0
void show_fatal_error(const char *text, ...) {
#ifdef WIN32
	WORD attr = save_console_attributes();
	set_console_attributes (COLOR_RED);
#endif

	va_list args;
	if (exit_code < EXIT_FATAL_ERROR) exit_code = EXIT_FATAL_ERROR;

	show_error_prefix(curr_input_file, line_num);
#ifdef WIN32
	OutputDebugString(text);
	OutputDebugString(TEXT("\n"));
#endif

	va_start(args, text);

	vprintf (text, args);
	putchar ('\n');
	error_occurred = true;

#ifdef WIN32
	restore_console_attributes(attr);
#endif
}
Exemplo n.º 5
0
void show_warning_prefix(const char *zcif, int zln) {
#ifdef WIN32
	WORD attr = save_console_attributes();
#endif
	set_console_attributes (COLOR_YELLOW);
	printf ("%s:%d: warning: ", zcif, zln);
#ifdef WIN32
		restore_console_attributes(attr);
#endif
}
Exemplo n.º 6
0
void show_error_prefix(const char *zcif, const int zln) {
	//BuckeyeDude
	//this is temporary till everything is rolled into errors.cpp
	WORD attr = save_console_attributes();
#ifdef _WIN32
	//TCHAR szPrefix[256];
	//sprintf(szPrefix, "%s:%d: error: ", zcif, zln);
	//OutputDebugString(szPrefix);
#endif
	set_console_attributes (COLOR_RED);
	printf ("%s:%d: error: ", zcif, zln);
	restore_console_attributes(attr);
}
Exemplo n.º 7
0
void show_error(const char *text, ...) {
	WORD attr = save_console_attributes();
	va_list args;
	if (exit_code < EXIT_ERRORS) exit_code = EXIT_ERRORS;

	show_error_prefix(curr_input_file, line_num);

	set_console_attributes (COLOR_RED);
	va_start(args, text);
	
	vprintf (text, args); 
	putchar ('\n');
	restore_console_attributes(attr);
}
Exemplo n.º 8
0
void show_warning(const char *text, ...) {
	WORD attr = save_console_attributes();

	va_list args;
	if (exit_code < EXIT_WARNINGS) exit_code = EXIT_WARNINGS;

	show_warning_prefix(curr_input_file, line_num);
#ifdef WIN32
	OutputDebugString(text);
	OutputDebugString(TEXT("\n"));
#endif

	set_console_attributes (COLOR_YELLOW);
	va_start(args, text);

	vprintf (text, args);
	putchar ('\n');
	restore_console_attributes(attr);
}
Exemplo n.º 9
0
char *handle_directive (const char *ptr) {
	static const char *dirs[] = {"db", "dw", "end", "org", "byte", "word", "fill", "block", "addinstr",
		"echo", "error", "list", "nolist", "equ", "show", "option", "seek", "assume", "dl", "long", NULL};
	char name_buf[32];
	int dir;

	//same deal as handle_preop, just with directives instead
	bool valid_directive = false;
	unsigned name_len = 0;
	while (ptr[name_len] != 0 && !isspace(ptr[name_len])) {
		name_len++;
	}

	// If longer than name_buf, it can't be a valid directive.
	if (name_len < sizeof(name_buf)) {
		// Copy string for comparing against
		memcpy(name_buf, ptr, name_len);
		name_buf[name_len] = 0;

		dir = 0;
		while (dirs[dir]) {
			if (!strcasecmp(dirs[dir], name_buf)) {
				valid_directive = true;
				break;
			}
			dir++;
		}
	}

	if (!valid_directive)
		return handle_opcode_or_macro ((char *) ptr - 1);

	ptr = skip_whitespace(&ptr[name_len]);

	switch (dir) {
		case 0: //DB
		case 4: //BYTE
		{
			ptr = parse_emit_string (ptr, ES_BYTE, NULL);
			break;
		}
		case 1: //DW
		case 5: //WORD
		{
			ptr = parse_emit_string (ptr, ES_WORD, NULL);
			break;
		}
		case 18: //DL
		case 19: //LONG
		{
			ptr = parse_emit_string (ptr, ES_LONG, NULL);
			break;
		}
		case 3: //ORG
		{
			int value;
			char value_str[256] = "";
			bool fResult = read_expr(&ptr, value_str, "");
			if (fResult == true)
			{
				if (parse_num(value_str, &value) == true)
				{
					if (value < 0)
					{
						SetLastSPASMError(SPASM_ERR_INVALID_ADDRESS, skip_whitespace(value_str));
					}
					else
					{
						program_counter = value;
					}
				}
			}
			if ((fResult == false) || (strlen(skip_whitespace(value_str)) == 0))
			{
				SetLastSPASMError(SPASM_ERR_VALUE_EXPECTED);
			}
			break;
		}
		case 6: //FILL
		case 7: //BLOCK
		{
			int size, fill_value;
			char szSize[256], szFill[256];
			bool old_listing_on = listing_on;
			//listing_on = false;

			read_expr (&ptr, szSize, ",");
			parse_num (szSize, &size);
			ptr = skip_whitespace (ptr);
			if (*ptr == ',')
				ptr++;

			if (read_expr (&ptr, szFill, "")) {
				//if there's a value to fill the block with, then handle that
				parse_num (szFill, &fill_value);
			} else {
				//otherwise use 0
				fill_value = 0;
			}

			if (size < 0) {
				SetLastSPASMError(SPASM_ERR_SIZE_MUST_BE_POSITIVE, szSize);
				listing_on = old_listing_on;
				break;
			}

			if (fill_value < -128 || fill_value > 255)
			{
				SetLastSPASMWarning(SPASM_WARN_TRUNCATING_8);
			}

			program_counter += size;
			stats_datasize += size;

			while (size-- > 0)
				write_out (fill_value & 0xFF);

			//listing_on = old_listing_on;
			break;
		}
		case 8: //ADDINSTR
		{
			instr *instr = (struct _instr *) malloc (sizeof (struct _instr));
			char word[256];
			int result;
			char *mnemonic;
			size_t i, base = 0, size_left;
			int j;
			opcode *last_opcode = NULL, *curr_opcode = all_opcodes, *new_opcode;

			memset (instr, 0, sizeof (struct _instr));

			// Mnemonic
			if (!read_expr (&ptr, word, " \t")) goto addinstr_fail;
			mnemonic = strdup (word);

			// Args
			if (!read_expr (&ptr, word, " \t")) goto addinstr_fail;
			reduce_string (word);
			instr->args = strdup (word);

			// Instruction data
			if (!read_expr (&ptr, word, " \t")) goto addinstr_fail;
	        conv_hex (word, word + strlen (word), &result);
	        instr->instr_size = strlen (word) / 2;

	        for (j = instr->instr_size - 1; j >= 0; j--)
	        	instr->instr_data[instr->instr_size - j - 1] = (result >> (j * 8)) & 0xFF;


			// Size
			if (!read_expr (&ptr, word, " \t")) goto addinstr_fail;
			if (!parse_num (word, &instr->size)) goto addinstr_fail;

			// Class
			read_expr (&ptr, word, " \t");

			// Extended
			read_expr (&ptr, word, " \t");

			// End data ...
			if (read_expr (&ptr, word, " \t")) {
				int output;
				conv_hex (word, word + strlen (word), &output);
				instr->end_data = (unsigned char) output;
				instr->has_end_data = true;
			}

			size_left = instr->size - instr->instr_size;
			while ((i = strcspn (&instr->args[base], "*")) + base != strlen (instr->args)) {
				switch (size_left - instr->has_end_data) {
					case 2:	((char *) instr->args)[base+i] = '*'; break;
					case 1: ((char *) instr->args)[base+i] = '&'; break;
					default:
						((char *) instr->args)[base+i] = '&'; break;
						//show_error ("Invalid wildcard type in ADDRINSTR");
						//goto addinstr_fail;
						break;
				}
				size_left -= 2;
				base += i + 1;
			}

			new_opcode = (opcode *)  malloc (sizeof (opcode));
			new_opcode->name = mnemonic;
			new_opcode->num_instrs = 1;
			new_opcode->use_count = 0;
			new_opcode->instrs = instr;
			new_opcode->is_added = true;

			while (curr_opcode) {
				if (strcasecmp (mnemonic, curr_opcode->name) == 0)
					break;
				last_opcode = curr_opcode;
				curr_opcode = curr_opcode->next;
			}

			if (curr_opcode == NULL) {
				last_opcode->next = new_opcode;
				new_opcode->next = NULL;
			} else {
				new_opcode->next = curr_opcode;
				if (last_opcode)
					last_opcode->next = new_opcode;
				else
					all_opcodes = new_opcode;
			}

			// You can ignore class, etc
			ptr = skip_to_line_end (ptr);
			break;
addinstr_fail:
			SetLastSPASMError(SPASM_ERR_INVALID_ADDINSTR);
			if (instr && instr->args) free ((void *) instr->args);
			if (instr) free (instr);
			ptr = skip_to_line_end(ptr);
			break;
		}
		case 9: //ECHO
		{
			if (ptr[0] == '>')
			{
				char target_format[2] = "w";
				FILE *echo_target;
				char filename[MAX_PATH];
				char temp_filename[MAX_PATH];
				define_t *define;

				if ((++ptr)[0] == '>')
					target_format[0] = 'a';

				ptr = skip_whitespace (ptr + 1);
				if (is_end_of_code_line (ptr)) {
					SetLastSPASMError(SPASM_ERR_FILENAME_EXPECTED);
					return NULL;
				}

				read_expr (&ptr, filename, " \t");

				// Is the filename given a macro?
				if ((define = search_defines (filename)))
					strncpy (filename, skip_whitespace(define->contents), sizeof (filename));
					
				reduce_string(filename);

				if (is_abs_path(filename)) {
					strncpy(temp_filename, skip_whitespace (filename), sizeof (temp_filename));
				} else {
					strncpy(temp_filename, temp_path, sizeof (temp_filename));
					strncat(temp_filename, "/", sizeof (temp_filename) - 1);
					strncat(temp_filename, skip_whitespace (filename), sizeof (temp_filename) - 1);
				}
				echo_target = fopen (fix_filename (temp_filename), target_format);
				if (echo_target == NULL) {
					SetLastSPASMError(SPASM_ERR_NO_ACCESS, filename);
					return NULL;
				}

				//if the output's redirected to a file, process it now
				WORD orig_attributes = save_console_attributes();
				set_console_attributes (COLOR_GREEN);
				ptr = parse_emit_string (ptr, ES_ECHO, echo_target);
				restore_console_attributes(orig_attributes);
			} else {
				char expr[256];
				read_expr (&ptr, expr, "");

				// If it craps out for some reason, save it for the next pass
				int session = StartSPASMErrorSession();
				parse_emit_string (expr, ES_ECHO, NULL);

				if (IsSPASMErrorSessionFatal(session) == true)
				{
					add_pass_two_output (expr, OUTPUT_ECHO);
				}
				else if (GetSPASMErrorSessionErrorCount(session) > 0)
				{
					WORD orig_attributes = save_console_attributes();
					set_console_attributes(COLOR_GREEN);
					int internal_session = StartSPASMErrorSession();
					parse_emit_string (expr, ES_ECHO, stdout);
					restore_console_attributes(orig_attributes);
					EndSPASMErrorSession(internal_session);

					ReplaySPASMErrorSession(session);
				}
				else
				{
					expand_buf_t *echo = eb_init(256);
					parse_emit_string (expr, ES_FCREATE, echo);

					char *echo_string = eb_extract(echo);
					eb_free(echo);

					char *expanded_string = escape_string(echo_string);
					free(echo_string);

					add_pass_two_output (expanded_string, OUTPUT_ECHO);
					free(expanded_string);
				}
				EndSPASMErrorSession(session);
			}
			break;
		}
		case 10: //ERROR
		{
			expand_buf_t *eb = eb_init(64);
			ptr = parse_emit_string(ptr, ES_FCREATE, eb);

			char *error_str = eb_extract(eb);
			eb_free(eb);

			SetLastSPASMError(SPASM_ERR_CUSTOM, error_str);
			free(error_str);
			break;
		}
		case 11: //LIST
		{
			//if listing was off already, then the listing
			// for the start of this line wouldn't have been
			// written, so make sure the end doesn't get
			// written either
			if (!listing_on)
				listing_for_line_done = true;
			listing_on = true;
			break;
		}
		case 12: //NOLIST
		{
			//if listing is on, then it would've written
			// the starting stuff for this line already,
			// so take that out
			if ((mode & MODE_LIST) && listing_on)
				listing_offset -= 14;
			listing_on = false;
			break;
		}
		case 13: //EQU
		{
			// Finally, a proper .equ!
			int value;
			char value_str[256];

			read_expr (&ptr, value_str, "");
			if (!parse_num (value_str, &value) && parser_forward_ref_err) {
			} else {
				if (last_label == NULL)
					SetLastSPASMError(SPASM_ERR_EQUATE_MISSING_LABEL);
				else
					last_label->value = value;
			}
			break;
		}
		case 14: //SHOW
		{
			char name[256];
			define_t *define;

			//get the name
			read_expr (&ptr, name, "");
			define = search_defines (name);
			if (define == NULL) {
				//if it doesn't exist yet, save it for the second pass
				add_pass_two_output (name, OUTPUT_SHOW);
			} else {
				//otherwise, show it now
				show_define (define);
			}
			break;
		}
		case 15: //OPTION
		{
			char *word = NULL;
			arg_context_t context = ARG_CONTEXT_INITIALIZER;
			while ((word = extract_arg_string(&ptr, &context)) != NULL)
			{
				char name[256], *expr = word;
				char *define_name;
				define_t *define;

				read_expr(&expr, name, "=");
				if (*expr == '=')
				{
					expr++;
				}
				
				if (!(isalpha(name[0]))) {
					SetLastSPASMError(SPASM_ERR_INVALID_OPTION, name);
					return (char *) ptr;
				}
				
				if (is_end_of_code_line (skip_whitespace (expr)))
					expr = strdup ("1");
				else {
					//if (!parse_num (expr, NULL))
					//	return NULL;
					expr = strdup (expr);
				}

				if (strlen (name) == 0) {
					show_error ("Invalid option statement");
					return NULL;
				}

				define_name = (char *) malloc (strlen (name) + 3);
				strcat (strcpy (define_name, "__"), name);

				define = add_define (define_name, NULL);
				set_define (define, expr, -1, false);
				free(expr);
			}
			break;
		}
		case 16: //SEEK
		{
			int value;
			char value_str[256];

			read_expr (&ptr, value_str, "");
			parse_num (value_str, (int *) &value);

			//printf("value_str: %s\npc: %d\n", value_str, program_counter);

			if (value > program_counter && (value - program_counter > output_buf_size - (out_ptr - output_contents)))
				show_fatal_error ("Seek location %d out of bounds", value);
			else if (value < program_counter && (value - (int) program_counter + (out_ptr - output_contents) < 0))
				show_fatal_error ("Seek value %d too small", value);
		
			out_ptr += value - ((int) program_counter);
			//printf("base: %p; ptr: %p\n", output_contents, out_ptr);
			program_counter = value;
			break;
		}
		case 17: //ASSUME
		{
			char args[256];
			read_expr(&ptr, args, "");

			char word[256];
			char *value_str = args;
			read_expr(&value_str, word, "=");

			int value = 1;
			bool success = true;
			if (*value_str == '=') {
				success = parse_num(value_str+1, &value);
			}

			if (!(mode & MODE_EZ80) || strcasecmp(word, "adl") || !success) {
				SetLastSPASMError(SPASM_ERR_INVALID_OPTION, args);
				return (char *)ptr;
			}

			adl_mode = (value != 0);
			break;
		}
	}

	return (char *) ptr;
}
Exemplo n.º 10
0
int main (int argc, char **argv)
{
	int curr_arg = 1;
	bool case_sensitive = false;
	bool is_storage_initialized = false;

	use_colors = true;
	extern WORD user_attributes;
	user_attributes = save_console_attributes ();
	atexit (restore_console_attributes_at_exit);

	//if there aren't enough args, show info
	if (argc < 2) {
		puts ("SPASM-ng Z80 Assembler by Spencer Putt and Don Straney");
		printf ("Version %s (built on %s @ %s)\n", SPASM_NG_VERSION, __DATE__, __TIME__);
#ifdef SPASM_NG_GITREV
		printf ("Git revision %s\n", SPASM_NG_GITREV);
#endif
#ifdef _M_X64
		puts ("64-bit Version");
#endif
#ifdef NO_APPSIGN
		printf ("\nApp signing is NOT available in this build of SPASM.\n");
#endif
		puts ("\nspasm [options] <input file> <output file>\n");
		puts ("Options:\n-E = Assemble eZ80 code\n-T = Generate code listing\n-C = Code counter mode\n-L = Symbol table mode\n-S = Stats mode\n-O = Don't write to output file");
		puts ("-I [directory] = Add include directory\n-A = Labels are cAse-sensitive\n-D<name>[=value] = Create a define 'name' [with 'value']");
		puts ("-N = Don't use colors for messages");
		puts ("-V <Expression> = Pipe expression directly into assembly");

#if defined(_DEBUG) && defined(WIN32)
		if (IsDebuggerPresent())
		{
			system("PAUSE");
		}
#endif
		return EXIT_NORMAL;
	}

	//init stuff
	mode = MODE_NORMAL;
	in_macro = 0;
	
	//otherwise, get any options
	curr_input_file = strdup("Commandline");
	char *starting_input_file = curr_input_file;

	while (curr_arg < argc) {
		if (argv[curr_arg][0] == '-'
#ifdef _WINDOWS
			|| argv[curr_arg][0] == '/'
#endif
			)
		{
			switch (argv[curr_arg][1])
			{
			//args for different modes
			case 'O':
				mode = mode & (~MODE_NORMAL);
				break;
			case 'T':
				mode |= MODE_LIST;
				break;
			case 'C':
				mode |= MODE_CODE_COUNTER;
				break;
			case 'L':
				mode |= MODE_SYMTABLE;
				break;
			case 'S':
				mode |= MODE_STATS;
				break;
			case 'E':
				mode |= MODE_EZ80;
				all_opcodes = opcode_list_ez80;
				break;
			//handle no-colors flag
			case 'N':
				use_colors = false;
				break;
			//handle include files too
			case 'I':
			{
				char *dir, *p;
				//make sure there's another argument after it for the include path
				if (strlen(argv[curr_arg]) > 2) {
					dir = strdup (&argv[curr_arg][2]);
				} else {
					if (curr_arg >= argc - 1) {
						printf ("%s used without include path\n", argv[curr_arg]);
						break;
					}
					
					dir = strdup (argv[++curr_arg]);
				}
				
				for (p = strtok (dir, ";,"); p; p = strtok (NULL, ";,")) {
					include_dirs = list_append (include_dirs, strdup(p));
				}
				free(dir);
				break;
			}
			//and the case-sensitive flag
			case 'A':
				case_sensitive = true;
				break;
			//handle adding defines
			case 'D':
			{
				char name[256];
				char *ptr;
				define_t *define;

				if (!is_storage_initialized)
				{
					init_storage();
					is_storage_initialized = true;
				}

				if (strlen (argv[curr_arg]) > 2) {
					ptr = &argv[curr_arg][2];
				} else {
					if (curr_arg >= argc - 1) {
						printf ("%s used without define name", argv[curr_arg]);
						break;
					}
					
					ptr = argv[++curr_arg];
				}

				read_expr (&ptr, name, "=");

				define = add_define (strdup (name), NULL);
				if (*skip_whitespace (++ptr) != '\0')
					define->contents = strdup (ptr);
				else
					set_define (define, "1", 1, false);
				break;
			}
			case 'V':
			{
				char *line;
				
				//check for something after -V
				if (strlen(argv[curr_arg]) > 2) {
					line = &argv[curr_arg][2];
				} else {
					//if not lets fail
					if (curr_arg >= argc - 1) {
						printf ("%s used without a line to assemble\n", argv[curr_arg]);
						return EXIT_FATAL_ERROR;
					}
					line = argv[++curr_arg];
				}
				
				mode |= MODE_COMMANDLINE;
				curr_input_file = strdup("-v");
				input_contents = (char *) malloc (strlen(line) + 1 + 2);
				output_filename = change_extension (curr_input_file, "bin");
					
				strcpy(input_contents, line);
				strcat(input_contents, "\n");
				break;
			}
			default:
				{
#ifndef _TEST
#ifdef _WINDOWS
					printf ("Unrecognized option %s\n", argv[curr_arg]);
#ifdef SPASM_NG_ENABLE_COM
					FreeConsole();
					return _AtlModule.WinMain(SW_HIDE);
#endif
#endif
#else
					printf ("Unrecognized option %s\n", argv[curr_arg]);
#endif
				}
				
			}

		} else {
			//if it's not a flag, then it must be a filename
			if (curr_input_file && (curr_input_file != starting_input_file) && !output_filename)
				output_filename = strdup(argv[curr_arg]);
			else if ((!curr_input_file) || (curr_input_file == starting_input_file))
				curr_input_file = strdup(argv[curr_arg]);

		}
		curr_arg++;
	}

	// Update case sensitivity settings
	set_case_sensitive (case_sensitive);
	
	//check on filenames
	if (!(mode & MODE_COMMANDLINE) && curr_input_file == starting_input_file) {
		puts ("No input file specified");
		free(starting_input_file);
		return EXIT_FATAL_ERROR;
	}

	if (curr_input_file != starting_input_file) {
		free(starting_input_file);
	}

	if (!output_filename) {
		output_filename = change_extension (curr_input_file, "bin");
	}

	if (!is_storage_initialized)
	{
		init_storage();
		is_storage_initialized = true;
	}
	output_contents = (unsigned char *) malloc(output_buf_size);
	ClearSPASMErrorSessions();

	int error = run_assembly();

	free(output_filename);
	output_filename = NULL;
	if (curr_input_file) {
		free(curr_input_file);
		curr_input_file = NULL;
	}
	if (include_dirs) {
		list_free(include_dirs, true, NULL);
	}

	free(output_contents);
	output_contents = NULL;
	ClearSPASMErrorSessions();
	free_storage();

#ifdef _WINDOWS
	_CrtDumpMemoryLeaks();
	if (IsDebuggerPresent())
	{
		system("PAUSE");
	}
#endif

	return error;
}
Exemplo n.º 11
0
define_t *add_define (char *name, bool *redefined, bool search_local) {
	define_t *define;
	label_t *conflict_label;

	if (strlen(name) == 0) {
		SetLastSPASMError(SPASM_ERR_NAME_EXPECTED);
		free(name);
		return NULL;
	}

	if (!case_sensitive) {
		char *new_name = strup (name);
		free (name);
		name = new_name;
	}
	
	if ((conflict_label = search_labels(name))) {
		show_error ("conflicting definition of '%s'", name);
		//if (suppress_errors == false) {
			show_error_prefix (conflict_label->input_file, conflict_label->line_num);
			WORD attr = save_console_attributes();
			set_console_attributes (COLOR_RED);
			printf ("previous definition of '%s' was here\n", name);
			restore_console_attributes(attr);
		//}
		return NULL;
	}
	
	// handle redefinitions
	if ((define = search_defines (name, search_local))) {
		int curr_arg;

		free (name);
		//define->line_num = line_num;
		//define->input_file = curr_input_file;
		/* Don't clear the contents of the #define, because
		   if it's being redefined references to itself may
		   need to be expanded, which will require the original
		   contents - all handled by set_define */

		for (curr_arg = 0; curr_arg < define->num_args; curr_arg++) {
			if (define->args[curr_arg] != NULL) {
				free(define->args[curr_arg]);
				define->args[curr_arg] = NULL;
			}
		}
		define->num_args = 0;

		if (redefined != NULL)
			*redefined = true;

		return define;
	} 
	
	if (redefined != NULL)
		*redefined = false;

	define = (define_t *) malloc (sizeof (define_t));
	if (define != NULL) {
		int curr_arg;

		define->name = name;
		define->line_num = line_num;
		define->input_file = strdup(curr_input_file);
		define->contents = NULL;
		define->num_args = 0;

		for (curr_arg = 0; curr_arg < MAX_ARGS; curr_arg++)
			define->args[curr_arg] = NULL;

		hash_insert (define_table, define);
	}
	return define;
}
Exemplo n.º 12
0
void show_warning_prefix(const char *zcif, int zln) {
	WORD attr = save_console_attributes();
	set_console_attributes (COLOR_YELLOW);
	printf ("%s:%d: warning: ", zcif, zln);
	restore_console_attributes(attr);
}