/* * This is our [ini] type file parser. */ int parse_jobs_ini(char *file, int is_buf, int stonewall_flag) { unsigned int global; struct thread_data *td; char *string, *name; FILE *f; char *p; int ret = 0, stonewall; int first_sect = 1; int skip_fgets = 0; int inside_skip = 0; char **opts; int i, alloc_opts, num_opts; if (is_buf) f = NULL; else { if (!strcmp(file, "-")) f = stdin; else f = fopen(file, "r"); if (!f) { perror("fopen job file"); return 1; } } string = malloc(4096); /* * it's really 256 + small bit, 280 should suffice */ name = malloc(280); memset(name, 0, 280); alloc_opts = 8; opts = malloc(sizeof(char *) * alloc_opts); num_opts = 0; stonewall = stonewall_flag; do { /* * if skip_fgets is set, we already have loaded a line we * haven't handled. */ if (!skip_fgets) { if (is_buf) p = strsep(&file, "\n"); else p = fgets(string, 4096, f); if (!p) break; } skip_fgets = 0; strip_blank_front(&p); strip_blank_end(p); if (is_empty_or_comment(p)) continue; if (sscanf(p, "[%255[^\n]]", name) != 1) { if (inside_skip) continue; log_err("fio: option <%s> outside of [] job section\n", p); break; } name[strlen(name) - 1] = '\0'; if (skip_this_section(name)) { inside_skip = 1; continue; } else inside_skip = 0; global = !strncmp(name, "global", 6); if (dump_cmdline) { if (first_sect) log_info("fio "); if (!global) log_info("--name=%s ", name); first_sect = 0; } td = get_new_job(global, &def_thread, 0); if (!td) { ret = 1; break; } /* * Seperate multiple job files by a stonewall */ if (!global && stonewall) { td->o.stonewall = stonewall; stonewall = 0; } num_opts = 0; memset(opts, 0, alloc_opts * sizeof(char *)); while (1) { if (is_buf) p = strsep(&file, "\n"); else p = fgets(string, 4096, f); if (!p) break; if (is_empty_or_comment(p)) continue; strip_blank_front(&p); /* * new section, break out and make sure we don't * fgets() a new line at the top. */ if (p[0] == '[') { skip_fgets = 1; break; } strip_blank_end(p); if (num_opts == alloc_opts) { alloc_opts <<= 1; opts = realloc(opts, alloc_opts * sizeof(char *)); } opts[num_opts] = strdup(p); num_opts++; } ret = fio_options_parse(td, opts, num_opts); if (!ret) { if (dump_cmdline) for (i = 0; i < num_opts; i++) log_info("--%s ", opts[i]); ret = add_job(td, name, 0); } else { log_err("fio: job %s dropped\n", name); put_job(td); } for (i = 0; i < num_opts; i++) free(opts[i]); num_opts = 0; } while (!ret); if (dump_cmdline) log_info("\n"); i = 0; while (i < nr_job_sections) { free(job_sections[i]); i++; } for (i = 0; i < num_opts; i++) free(opts[i]); free(string); free(name); free(opts); if (!is_buf && f != stdin) fclose(f); return ret; }
/* * Description: Executes the second transition * Input: 1. Input file handle * 2. Name of input file * 3. Code length in memory word * 4. Data length in memory word */ void second_transition_execute(FILE* pFile, char* file_name_without_extension, unsigned int previous_transition_ic, unsigned int previous_transition_dc) { compiler_output_files output_files; int line_number = 0; /* Creates transition first data */ transition_data* transition = create_transition_data(); if (transition == NULL) { return; } /* Create ob file */ output_files.ob_file = create_output_file(file_name_without_extension, CODE_FILE_EXT); if (output_files.ob_file == NULL) { return; } output_files.entry_file = NULL; output_files.extern_file = NULL; /* Write first line to ob file */ write_code_and_data_size_to_output_file(previous_transition_ic, previous_transition_dc, output_files.ob_file); /* Step 1 - Initializes IC to zero*/ transition->IC = 0; /* Reads all code lines */ while (!feof(pFile) && !transition->is_runtimer_error) { char line[MAX_LINE_LENGTH]; line_number++; /* Step 2 - Read next line*/ if (fgets(line, MAX_LINE_LENGTH + 1, pFile)) { /* This isn't an empty line or a comment */ if (!is_empty_or_comment(line)) { transition->current_line_information = create_line_info(file_name_without_extension, line_number, line); /* Process line */ if (transition->current_line_information != NULL) { second_transition_process_line(transition, &output_files); free(transition->current_line_information); } else { transition->is_runtimer_error = true; } } } } /* No error has occurred */ if (!transition->is_runtimer_error && !transition->is_compiler_error) { /* Write data initialization section into ob file */ write_data_to_output_file(output_files.ob_file); /* Close files */ if (output_files.ob_file != NULL) { fclose(output_files.ob_file); } if (output_files.extern_file != NULL) { fclose(output_files.extern_file); } if (output_files.entry_file != NULL) { fclose(output_files.entry_file); } } else { /* Close and delete file */ if (output_files.ob_file != NULL) { char* full_name = allocate_string(strlen(file_name_without_extension) + strlen(CODE_FILE_EXT)); fclose(output_files.ob_file); if (full_name != NULL) { strcpy(full_name, file_name_without_extension); strcat(full_name, CODE_FILE_EXT); remove(full_name); free(full_name); } else { print_runtime_error("Couldn't delete compilation files"); } } /* Close and delete file */ if (output_files.extern_file != NULL) { char* full_name = allocate_string(strlen(file_name_without_extension) + strlen(EXTERN_FILE_EXT)); fclose(output_files.extern_file); if (full_name != NULL) { strcpy(full_name, file_name_without_extension); strcat(full_name, EXTERN_FILE_EXT); remove(full_name); free(full_name); } else { print_runtime_error("Couldn't delete compilation files"); } } /* Close and delete file */ if (output_files.entry_file != NULL) { char* full_name = allocate_string(strlen(file_name_without_extension) + strlen(ENTRY_FILE_EXT)); fclose(output_files.entry_file); if (full_name != NULL) { strcpy(full_name, file_name_without_extension); strcat(full_name, ENTRY_FILE_EXT); remove(full_name); free(full_name); } else { print_runtime_error("Couldn't delete compilation files"); } } } }