void read_files(char *path) { char buf[2048]={0}; int count=0; long long all=0; int save=0; struct Files file; save=init_save("zhoustest.mpg"); fd_open(&file,path); while(1) { count=fd_read(&file,buf,2048); all+=count; if(all>file.File_Size) { count-=4; } do_save(save,buf,count,all); if(count < 2048) { break; } } exit_save(save); fd_close(&file); }
void ccfile_term(void) { unsigned int id; if (!dc_savedtimes) { return; } soundmng_stop(); dc_savedtimes = 0; for (;;) { id = getID(); if (id == 0) break; SaveData_finalize(id); delID(id); } init_save(); soundmng_play(); }
void ccfile_init(void) { CCFILEH cc; cc = fh; for (int i=0; i<DATACACHES; ++i) { cc->name[0] = '\0'; cc->size = 0; cc->id = 0; ZeroMemory(cc->ptr, sizeof(cc->ptr)); cc++; } stc_index = 0; init_save(); }
int main (int argc, char *argv[]) { int rv; /* return value for functionss */ FILE *file_in; /* file for mem RW/addr input */ settings_t settings; /* settings structure */ char line_buffer[64];/* buffer for reading in lines */ mem_rw_t parse_data; save_data_t save_data; init_save(&save_data); /* inits the stats */ init_settings(&settings); /* inits the settings struct */ /* parses the input arguements for the cache set up and run info */ if ((rv = get_settings(&settings, argc, argv)) != RTN_SUCCESS) { if (rv == RTN_PARSE_ERR) { fprintf(stderr, "Error parsing input arguements" "exiting\n"); return rv; } else if (rv == RTN_NO_SET) { fprintf(stderr, "Not all of the settings were" "present or set correctly, exiting\n"); return rv; } else { fprintf(stderr, "Unknown error, exiting\n"); return rv; } } /* sets up the cache array in memory */ if (cache_setup(&settings) == RTN_FAIL) { fprintf(stderr, "Failed to malloc memory, exiting\n"); } /* opens the input file */ if ((file_in = fopen(settings.file_path, "r")) == NULL) { fprintf(stderr, "Can not open input file, exiting\n"); return RTN_FILE_ERR; } /* reads one line from the input */ if(fgets(line_buffer, 64, file_in) == NULL) { fprintf(stderr, "The input file is empty, exiting\n"); return 1; } parse_data.time = 0ull; do { if (sscanf(line_buffer, "%d %d %u", &parse_data.flags, &parse_data.data_len, &parse_data.addr) != 3) { fprintf(stderr, "%llu: could not be parsed" ", skipping\n", parse_data.time + 1ull); continue; /* skip if the data isn't * read correctly */ } if (parse_data.flags == 0) { /* read */ read_cache(&settings, &parse_data, &save_data); parse_data.time++; } else if (parse_data.flags == 1) { /* write */ ; } else { /* error */ fprintf(stderr, "%llu: neither read nor write" ", skipping\n", parse_data.time + 1ull); } fgets(line_buffer, 64, file_in); } while (!feof(file_in)); print_save(&save_data); return 0; }