const char* scan_dir::next_file(bool full /* = false */) { if (scan_ == NULL) return NULL; const char* file = acl_scan_dir_next_file(scan_); if (file == NULL || *file == 0) return NULL; if (!full) return file; const char* path = curr_path(); if (path == NULL) return NULL; if (file_buf_ == NULL) file_buf_ = NEW string(256); #ifdef ACL_WINDOWS file_buf_->format("%s%c%s", path, PATH_SEP_C, file); #else if (*path == '/' && *(path + 1) == 0) file_buf_->format("%s%s", path, file); else file_buf_->format("%s%c%s", path, PATH_SEP_C, file); #endif return file_buf_->c_str(); }
int CGb2Utf8::TransformPath(CString *path_from, CString *path_to) { ACL_SCAN_DIR *scan_src; //, *scan_dst; const char *path = path_from->GetString(); scan_src = acl_scan_dir_open(path, 1); if (scan_src == NULL) { CString msg; msg.Format("Open src path %s error", path_from->GetString()); MessageBox(NULL, msg, "Open path", 0); return (-1); } //scan_dst = acl_scan_dir_open(to.GetString(), 1); //if (scan_dst == NULL) { // MessageBox(NULL, "Open path", "Open dst path error", 0); // return (-1); //} while (1) { const char *fName; CString fPath; fName = acl_scan_dir_next_file(scan_src); if (fName == NULL) break; fPath = acl_scan_dir_path(scan_src); fPath += "\\"; fPath += fName; TransformFile(fPath.GetString(), NULL); } acl_scan_dir_close(scan_src); return (0); }
void* CDelBOM::RunThread(void *arg) { CDelBOM* pDel = (CDelBOM*) arg; ACL_SCAN_DIR *scan = acl_scan_dir_open(pDel->m_sPath.GetString(), 1); if (scan == NULL) { CString msg; msg.Format("Open path %s error", pDel->m_sPath.GetString()); MessageBox(NULL, msg, "Open path", 0); ::PostMessage(pDel->m_hWnd, pDel->m_nMsgDeleted, 0, 0); return NULL; } while (true) { const char* pFile = acl_scan_dir_next_file(scan); if (pFile == NULL) break; // 过滤掉非纯文本的文件 if (acl_strrncasecmp(pFile, ".c", 2) && acl_strrncasecmp(pFile, ".cpp", 4) && acl_strrncasecmp(pFile, ".cxx", 4) && acl_strrncasecmp(pFile, ".h", 2) && acl_strrncasecmp(pFile, ".hpp", 4) && acl_strrncasecmp(pFile, ".hxx", 4) && acl_strrncasecmp(pFile, ".java", 5) && acl_strrncasecmp(pFile, ".txt", 4) && acl_strrncasecmp(pFile, ".php", 4) && acl_strrncasecmp(pFile, ".html", 5) && acl_strrncasecmp(pFile, ".js", 3) && acl_strrncasecmp(pFile, ".css", 4) && acl_strrncasecmp(pFile, ".d", 2) && acl_strrncasecmp(pFile, ".py", 3) && acl_strrncasecmp(pFile, ".perl", 5) && acl_strrncasecmp(pFile, ".cs", 3) && acl_strrncasecmp(pFile, ".as", 3)) { acl_msg_info(">>skip file: %s", pFile); continue; } CString filePath = acl_scan_dir_path(scan); filePath += "\\"; filePath += pFile; if (pDel->DeleteBOM(filePath) == true) acl_msg_info(">>modify file %s", filePath.GetString()); else acl_msg_info(">>skip file %s", filePath.GetString()); } acl_scan_dir_close(scan); ::PostMessage(pDel->m_hWnd, pDel->m_nMsgDeleted, 0, 0); acl_msg_info(">>scan over, msg: %d", pDel->m_nMsgDeleted); return NULL; }
queue_file* queue_manager::scan_next() { if (m_scanDir == NULL) logger_fatal("call scan_open first!"); queue_file* fp = NULL; string filePath; while (1) { // 扫描下一个磁盘文件 const char* fileName = acl_scan_dir_next_file(m_scanDir); if (fileName == NULL) return NULL; string partName, extName; if (parse_fileName(fileName, &partName, &extName) == false) continue; // 如果该队列文件已经存在于内存队列中则跳过 if (busy(partName.c_str())) continue; const char* path = acl_scan_dir_path(m_scanDir); if (path == NULL) { logger_error("acl_scan_dir_path error for %s", fileName); continue; } filePath.clear(); filePath << path << PATH_SEP << fileName; fp = NEW queue_file; // 从磁盘打开已经存在的队列文件 if (fp->open(filePath.c_str()) == false) { logger_error("open %s error(%s)", filePath.c_str(), acl_last_serror()); delete fp; fp = NULL; continue; } if (cache_add(fp) == false) { logger_error("file(%s) locked", filePath.c_str()); delete fp; fp = NULL; continue; } else break; } return fp; }
static int zdb_dat_scan_path(ZDB *db, const char *path, int (*walk_fn)(ZDB_DAT_STORE *store)) { const char *myname = "zdb_dat_scan_path"; ZDB_DAT_STORE *store; ACL_SCAN_DIR *scan; const char *fname; char pathbuf[256]; int ret = 0; scan = acl_scan_dir_open(path, 1); if (scan == NULL) { acl_msg_error("%s(%d): open dir %s error(%s)", myname, __LINE__, path, acl_last_serror()); return (-1); } while (1) { fname = acl_scan_dir_next_file(scan); if (fname == NULL) { acl_msg_info("%s(%d): scan over for %s", myname, __LINE__, path); break; } if (strrncasecmp(fname, ".dat", 4) != 0) { acl_msg_info("%s(%d): skip %s/%s", myname, __LINE__, acl_scan_dir_path(scan), fname); continue; } snprintf(pathbuf, sizeof(pathbuf), "%s/%s", acl_scan_dir_path(scan), fname); store = zdb_dat_store_open(db, pathbuf); if (store == NULL) { acl_msg_error("%s(%d): open file(%s) error(%s)", myname, __LINE__, pathbuf, acl_last_serror()); break; } ret = walk_fn(store); zdb_dat_store_close(store); if (ret < 0) { acl_msg_error("%s(%d): walk_fn ret: %d, break", myname, __LINE__, ret); break; } } acl_scan_dir_close(scan); return (ret); }
int zdb_key_walk(ZDB *db, int (*walk_fn)(ZDB_KEY_STORE*)) { const char *myname = "zdb_key_walk"; ZDB_KEY_STORE *store; ACL_SCAN_DIR *scan = NULL; const char *fname; char pathbuf[256]; int ret = 0; scan = acl_scan_dir_open(db->key_path, 1); if (scan == NULL) { acl_msg_error("%s: open dir %s error(%s)", myname, db->key_path, acl_last_serror()); return (-1); } while (1) { fname = acl_scan_dir_next_file(scan); if (fname == NULL) { acl_msg_info("%s: scan over for %s\n", myname, db->key_path); break; } if (strrncasecmp(fname, ".key", 4) != 0) { acl_msg_info("%s: skip %s/%s\n", myname, acl_scan_dir_path(scan), fname); continue; } snprintf(pathbuf, sizeof(pathbuf), "%s/%s", acl_scan_dir_path(scan), fname); store = zdb_key_store_open2(db, pathbuf); if (store == NULL) { acl_msg_error("%s: open file(%s) error(%s)", myname, pathbuf, acl_last_serror()); ret = -1; break; } ret = walk_fn(store); zdb_key_store_close(store); if (ret < 0) break; } acl_scan_dir_close(scan); return (ret); }
static void scan_dir(const char *src_path, int to_fmt) { ACL_SCAN_DIR *scan; const char *filename, *path, *ptr; char filepath[1024], fmt_buf[32], info[32]; int n; #define CP ACL_SAFE_STRNCPY switch (to_fmt) { case FMT_UNIX: CP(info, "UNIX", sizeof(info)); CP(fmt_buf, "\n", sizeof(fmt_buf)); break; case FMT_DOS: CP(info, "DOS", sizeof(info)); CP(fmt_buf, "\r\n", sizeof(fmt_buf)); break; case FMT_MAC: CP(info, "MAC", sizeof(info)); CP(fmt_buf, "\r", sizeof(fmt_buf)); break; default: acl_msg_fatal("unknown fmt(%d)", to_fmt); } scan = acl_scan_dir_open(src_path, 1); if (scan == NULL) acl_msg_fatal("open path(%s, %s)", src_path, strerror(errno)); n = 0; while (1) { filename = acl_scan_dir_next_file(scan); if (filename == NULL) break; if (strlen(filename) < 3) continue; ptr = strchr(filename, '.'); if (ptr == NULL) continue; ptr++; if (strcasecmp(ptr, "c") != 0 && strcasecmp(ptr, "h") != 0 && strcasecmp(ptr, "cpp") != 0 && strcasecmp(ptr, "hpp") != 0) continue; path = acl_scan_dir_path(scan); if (path == NULL) acl_msg_fatal("file(%s) no path", filename); snprintf(filepath, sizeof(filepath), "%s/%s", path, filename); printf("filepath:%s\r\n", filepath); fmt_change(filepath, fmt_buf); n++; } acl_scan_dir_close(scan); printf(">>> At last, %d files were changed to %s format\r\n" ">>> total_c_line: %d lines, total_h_line: %d, " "total_cpp_line: %d, total_hpp_line: %d\r\n", n, info, __total_c_line, __total_h_line, __total_cpp_line, __total_hpp_line); }