| 39 | } |
| 40 | |
| 41 | static int load_objs(acl::diff_manager& manager, const char* filepath, |
| 42 | std::vector<acl::diff_object*>& new_objs) |
| 43 | { |
| 44 | acl::ifstream in; |
| 45 | |
| 46 | // 以只读方式打开数据文件 |
| 47 | if (in.open_read(filepath) == false) |
| 48 | { |
| 49 | printf("open %s error %s\r\n", filepath, acl::last_serror()); |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | // 从比较器中获得内存池对象,以便于下面分配内存 |
| 54 | acl::dbuf_guard& dbuf = manager.get_dbuf(); |
| 55 | int linenum = 0; |
| 56 | acl::string line; |
| 57 | |
| 58 | int nobjs = 0; |
| 59 | |
| 60 | while (!in.eof()) |
| 61 | { |
| 62 | line.clear(); |
| 63 | |
| 64 | // 从文件中读取一行数据 |
| 65 | if (in.gets(line) == false) |
| 66 | break; |
| 67 | |
| 68 | linenum++; |
| 69 | |
| 70 | // 分析该行数据,提取 key 和 value 值 |
| 71 | char* key = line.c_str(); |
| 72 | char* val = strrchr(key, '|'); |
| 73 | |
| 74 | // 检查数据的有效性 |
| 75 | if (val == NULL || val == key || *(val + 1) == 0) |
| 76 | { |
| 77 | printf("invalid line: %s in %s, linenum: %d\r\n", |
| 78 | key, filepath, linenum); |
| 79 | continue; |
| 80 | } |
| 81 | *val++ = 0; |
| 82 | |
| 83 | // 创建 diff 对象,并置入对象集合中 |
| 84 | mail_object* obj = new (dbuf.dbuf_alloc(sizeof(mail_object))) |
| 85 | mail_object(manager, key, val); |
| 86 | new_objs.push_back(obj); |
| 87 | nobjs++; |
| 88 | } |
| 89 | |
| 90 | return nobjs; |
| 91 | } |
| 92 | |
| 93 | static bool check_diff(const char* new_file, const char* old_file, |
| 94 | const DIFF_RES* res = NULL) |
no test coverage detected
searching dependent graphs…