Explorar el Código

Finish region info parsing.

master
Ben Kurtovic hace 9 años
padre
commit
633351cf14
Se han modificado 3 ficheros con 28 adiciones y 10 borrados
  1. +3
    -2
      src/assembler/parse_util.c
  2. +18
    -1
      src/assembler/preprocessor.c
  3. +7
    -7
      src/util.c

+ 3
- 2
src/assembler/parse_util.c Ver fichero

@@ -15,8 +15,9 @@
*/
bool parse_bool(bool *result, const ASMLine *line, const char *directive, bool auto_val)
{
const char *arg = line->data + (DIRECTIVE_OFFSET(line, directive) + 1);
ssize_t len = line->length - (DIRECTIVE_OFFSET(line, directive) + 1);
size_t offset = DIRECTIVE_OFFSET(line, directive) + 1;
const char *arg = line->data + offset;
ssize_t len = line->length - offset;

if (len <= 0 || len > 5)
return false;


+ 18
- 1
src/assembler/preprocessor.c Ver fichero

@@ -16,6 +16,8 @@
#include "../logging.h"
#include "../util.h"

#define MAX_REGION_SIZE 32

/* Helper defines for preprocess() */

#define SAVE_ARG(line, first, oldval, newval) \
@@ -283,8 +285,23 @@ static ErrorInfo* build_asm_lines(
*/
static bool parse_region_string(uint8_t *result, const ASMLine *line)
{
char buffer[32]; // Longest region ("GG International") is 17 bytes
char buffer[MAX_REGION_SIZE];

size_t offset = DIRECTIVE_OFFSET(line, DIR_ROM_REGION) + 1;
const char *arg = line->data + offset;
ssize_t len = line->length - offset;

if (len <= 2 || len >= MAX_REGION_SIZE + 2) // Account for double quotes
return false;
if (arg[0] != '"' || arg[len - 1] != '"')
return false;

strncpy(buffer, arg + 1, len - 2);
buffer[len - 2] = '\0';

uint8_t code = region_string_to_code(buffer);
if (code)
return (*result = code), true;
return false;
}



+ 7
- 7
src/util.c Ver fichero

@@ -73,19 +73,19 @@ const char* region_code_to_string(uint8_t code)
*/
uint8_t region_string_to_code(const char *name)
{
if (!strcmp(name, "SMS ")) {
if (!strncmp(name, "SMS ", 4)) {
name += 4;
if (strcmp(name, "Japan"))
if (!strcmp(name, "Japan"))
return 3;
if (strcmp(name, "Export"))
if (!strcmp(name, "Export"))
return 4;
} else if (!strcmp(name, "GG ")) {
} else if (!strncmp(name, "GG ", 3)) {
name += 3;
if (strcmp(name, "Japan"))
if (!strcmp(name, "Japan"))
return 5;
if (strcmp(name, "Export"))
if (!strcmp(name, "Export"))
return 6;
if (strcmp(name, "International"))
if (!strcmp(name, "International"))
return 7;
}
return 0;


Cargando…
Cancelar
Guardar