int incbin_file(char *name, int *id, int *swap, int *skip, int *read, struct macro_static **macro) { struct incbin_file_data *ifd; char *in_tmp, *n, *tmp_c; int file_size, q; FILE *f; /* create the full output file name */ if (use_incdir == YES) tmp_c = ext_incdir; else tmp_c = include_dir; if (create_full_name(tmp_c, name) == FAILED) return FAILED; f = fopen(full_name, "rb"); q = 0; if (f == NULL && (tmp_c == NULL || tmp_c[0] == 0)) { sprintf(emsg, "Error opening file \"%s\".\n", name); print_error(emsg, ERROR_INB); return FAILED; } /* if not found in ext_incdir silently try the include directory */ if (f == NULL && use_incdir == YES) { if (create_full_name(include_dir, name) == FAILED) return FAILED; f = fopen(full_name, "rb"); q = 0; if (f == NULL && (include_dir == NULL || include_dir[0] == 0)) { sprintf(emsg, "Error opening file \"%s\".\n", name); print_error(emsg, ERROR_INB); return FAILED; } } /* if failed try to find the file in the current directory */ if (f == NULL) { fprintf(stderr, "%s:%d: ", get_file_name(active_file_info_last->filename_id), active_file_info_last->line_current); fprintf(stderr, "INCBIN_FILE: Could not open \"%s\", trying \"%s\"... ", full_name, name); f = fopen(name, "rb"); q = 1; } if (f == NULL) { fprintf(stderr, "not found.\n"); sprintf(emsg, "Error opening file \"%s\".\n", full_name); print_error(emsg, ERROR_INB); return FAILED; } if (q == 1) { fprintf(stderr, "found.\n"); strcpy(full_name, name); } fseek(f, 0, SEEK_END); file_size = ftell(f); fseek(f, 0, SEEK_SET); ifd = (struct incbin_file_data *)malloc(sizeof(struct incbin_file_data)); n = malloc(sizeof(char) * (strlen(full_name)+1)); in_tmp = (char *)malloc(sizeof(char) * file_size); if (ifd == NULL || n == NULL || in_tmp == NULL) { if (ifd != NULL) free(ifd); if (n != NULL) free(n); if (in_tmp != NULL) free(in_tmp); sprintf(emsg, "Out of memory while allocating data structure for \"%s\".\n", full_name); print_error(emsg, ERROR_INB); return FAILED; } /* read the whole file into a buffer */ fread(in_tmp, 1, file_size, f); fclose(f); /* complete the structure */ ifd->next = NULL; ifd->size = file_size; strcpy(n, full_name); ifd->name = n; ifd->data = in_tmp; /* find the index */ q = 0; if (incbin_file_data_first != NULL) { ifd_tmp = incbin_file_data_first; while (ifd_tmp->next != NULL && strcmp(ifd_tmp->name, full_name) != 0) { ifd_tmp = ifd_tmp->next; q++; } if (ifd_tmp->next == NULL && strcmp(ifd_tmp->name, full_name) != 0) { ifd_tmp->next = ifd; q++; } } else incbin_file_data_first = ifd; *id = q; /* SKIP bytes? */ if (compare_next_token("SKIP", 4) == FAILED) *skip = 0; else { skip_next_token(); inz = input_number(); if (inz != SUCCEEDED) { print_error(".INCBIN needs the amount of skipped bytes.\n", ERROR_DIR); return FAILED; } *skip = d; if (d >= file_size) { sprintf(emsg, "SKIP value (%d) is more than the size (%d) of file \"%s\".\n", d, file_size, full_name); print_error(emsg, ERROR_INB); return FAILED; } } /* READ bytes? */ if (compare_next_token("READ", 4) == FAILED) *read = file_size - *skip; else { skip_next_token(); inz = input_number(); if (inz != SUCCEEDED) { print_error(".INCBIN needs the amount of bytes for reading.\n", ERROR_DIR); return FAILED; } *read = d; if (*skip + *read > file_size) { sprintf(emsg, "Overreading file \"%s\" by %d bytes.\n", full_name, *skip + *read - file_size); print_error(emsg, ERROR_INB); return FAILED; } } /* SWAP bytes? */ if (compare_next_token("SWAP", 4) == FAILED) *swap = 0; else { if ((*read & 1) == 1) { sprintf(emsg, "The read size of file \"%s\" is odd (%d)! Cannot perform SWAP.\n", full_name, *read); print_error(emsg, ERROR_INB); return FAILED; } *swap = 1; skip_next_token(); } /* FSIZE? */ if (compare_next_token("FSIZE", 5) == SUCCEEDED) { skip_next_token(); /* get the definition label */ if (get_next_token() == FAILED) return FAILED; add_a_new_definition(tmp, (double)file_size, NULL, DEFINITION_TYPE_VALUE, 0); } /* FILTER? */ if (compare_next_token("FILTER", 6) == SUCCEEDED) { skip_next_token(); /* get the filter macro name */ if (get_next_token() == FAILED) return FAILED; *macro = macro_get(tmp); if (*macro == NULL) { sprintf(emsg, "No MACRO \"%s\" defined.\n", tmp); print_error(emsg, ERROR_INB); return FAILED; } } else *macro = NULL; return SUCCEEDED; }
static void parse_parent (IAnjutaDebuggerWatch* parent, gchar **buf) { IAnjutaDebuggerDataType type; IAnjutaDebuggerWatch* child; guint idx; gchar *pos; guint i; if (*buf == NULL) return; type = get_type (buf); if (type == IANJUTA_DEBUGGER_NAME_TYPE) { parent->name = get_name (buf); type = get_type (buf); } parent->type = type; switch (parent->type) { case IANJUTA_DEBUGGER_ROOT_TYPE: case IANJUTA_DEBUGGER_UNKNOWN_TYPE: case IANJUTA_DEBUGGER_NAME_TYPE: break; case IANJUTA_DEBUGGER_POINTER_TYPE: case IANJUTA_DEBUGGER_VALUE_TYPE: case IANJUTA_DEBUGGER_REFERENCE_TYPE: parent->value = get_value (buf); break; case IANJUTA_DEBUGGER_ARRAY_TYPE: child = NULL; idx = 0; while (**buf) { *buf = skip_next_token (*buf); if (**buf == '\0') return; if (**buf == '}') { *buf = *buf + 1; return; } if (child == NULL) { parent->children = g_new0 (IAnjutaDebuggerWatch, 1); child = parent->children; } else { child->sibling = g_new0 (IAnjutaDebuggerWatch, 1); child = child->sibling; } child->index = idx; parse_parent (child, buf); if (child->value) { pos = strstr (child->value, " <repeats"); if (pos) { if ((i = atoi (pos + 10))) idx += (i - 1); } } idx++; } break; case IANJUTA_DEBUGGER_STRUCT_TYPE: child = NULL; while (**buf) { *buf = skip_next_token (*buf); if (**buf == '\0') return; if (**buf == '}') { *buf = *buf + 1; return; } if (child == NULL) { parent->children = g_new0 (IAnjutaDebuggerWatch, 1); child = parent->children; } else { child->sibling = g_new0 (IAnjutaDebuggerWatch, 1); child = child->sibling; } parse_parent (child, buf); } return; } }