diff --git a/App/lib/VCache.vp b/App/lib/VCache.vp index 96a75c1..1d45696 100644 --- a/App/lib/VCache.vp +++ b/App/lib/VCache.vp @@ -90,11 +90,9 @@ def CacheDisp(Idx: int) -> str: # ============================================================ def CacheFind(ExeAnsi: str) -> int: - i: int = 0 - while i < Cache_Count: + for i in range(Cache_Count): if string.strcmp(Cache_Exe[i], ExeAnsi) == 0: return i - i += 1 return -1 @@ -131,10 +129,8 @@ def RemoveAt(Idx: int) -> int: # 清空内存表(释放全部字段副本)。用于每轮开始前的"重读 cache.json"。 def ClearCache(): global Cache_Count - j: int = 0 - while j < Cache_Count: + for j in range(Cache_Count): FreeEntry(j) - j += 1 Cache_Count = 0 diff --git a/App/lib/VCli.vp b/App/lib/VCli.vp index a493d6f..0743961 100644 --- a/App/lib/VCli.vp +++ b/App/lib/VCli.vp @@ -179,13 +179,11 @@ def WatchVerbose() -> int: # ver 子命令专用:ver 不解析开关(目标路径固定在 sys._argv[2]), # 只要 argv 中出现 --verbose 即视为要求详细日志(argv 起点与 scan 一致,从下标 2 扫)。 def HasVerbose() -> int: - i: int = 2 - while i < sys._argc: + for i in range(2, sys._argc): A: str = sys._argv[i] if A is not None: if string.strcmp(A, "--verbose") == 0: return 1 - i += 1 return 0 diff --git a/App/lib/VDirs.vp b/App/lib/VDirs.vp index 16a6742..854527a 100644 --- a/App/lib/VDirs.vp +++ b/App/lib/VDirs.vp @@ -119,11 +119,9 @@ def AddCommonDirForce(Path: str) -> int: global Common_Dir_Count if Path is None: return 0 - i: int = 0 - while i < Common_Dir_Count: + for i in range(Common_Dir_Count): if string.strcmp(Common_Directory[i], Path) == 0: return 0 - i += 1 if Common_Dir_Count >= COMMON_DIR_CAPACITY: VLog.LogFmt1(" 警告: 常用目录表已满 (%d),已忽略该条\n", sizet(COMMON_DIR_CAPACITY)) return 0 @@ -153,8 +151,7 @@ def AddFixedDriveProgramFiles() -> int: VLog.LogFmt1(" 警告: GetLogicalDrives 失败 (win32 err=%u)\n", wb.GetLastError()) return 0 Added: int = 0 - Letter: int = 0 - while Letter < 26: + for Letter in range(26): if (Mask & (uint32(1) << uint32(Letter))) != 0: Root: bytes = _mbuddy.alloc(DRIVE_ROOT_CAP) if Root is not None: @@ -176,7 +173,6 @@ def AddFixedDriveProgramFiles() -> int: string.strcpy(Pfx, r"Q:\Program Files (x86)") Pfx[0] = char(65 + Letter) Added += AddCommonDir(str(Pfx)) - Letter += 1 return Added @@ -272,10 +268,8 @@ def PrintCommonDirs() -> int: if Common_Dir_Count <= 0: VLog.VerboseStr(" (表为空)\n") return 1 - i: int = 0 - while i < Common_Dir_Count: + for i in range(Common_Dir_Count): VLog.VerboseFmtIS(" [%d] %s\n", sizet(i), Common_Directory[i]) - i += 1 VLog.VerboseFmt1(" 合计 %d 个常用目录\n", sizet(Common_Dir_Count)) return 0 @@ -291,12 +285,10 @@ def BuildTable() -> int: VLog.VerboseFmt1(" 目录表来源: 自动表 (%u 条)\n", sizet(Common_Dir_Count)) else: # 强制替换:完全不做自动构建,表 = --path 序列(保序;去重由 AddCommonDirForce) - i: int = 0 - while i < Override_Count: + for i in range(Override_Count): if VFs.PathIsDir(Override_Dir[i]) == 0: VLog.LogFmtS1(" 警告: --path 不存在或非目录,跳过: %s\n", Override_Dir[i]) else: AddCommonDirForce(Override_Dir[i]) - i += 1 VLog.VerboseFmt1(" 目录表来源: 覆盖表 (%u 条)\n", sizet(Common_Dir_Count)) return PrintCommonDirs() diff --git a/App/lib/VFs.vp b/App/lib/VFs.vp index 02a7462..f3caf89 100644 --- a/App/lib/VFs.vp +++ b/App/lib/VFs.vp @@ -73,10 +73,8 @@ def CopyRaw(Dst: bytes, Cap: int, Src: str) -> int: if n + 1 > sizet(Cap): Dst[0] = 0 return 0 - i: sizet = 0 - while i < n: + for i in range(n): Dst[i] = Src[i] - i += 1 Dst[n] = 0 return 1 @@ -90,10 +88,8 @@ def DupStr(S: str) -> str: b: bytes = _mbuddy.alloc(n + 1) if b is None: return None - i: sizet = 0 - while i < n: + for i in range(n): b[i] = S[i] - i += 1 b[n] = 0 return str(b) @@ -142,11 +138,9 @@ def JoinPath(Out: bytes, Cap: int, Parent: str, Child: str) -> int: if need_sep != 0: Out[i] = '\\' i += 1 - j: sizet = 0 - while j < cl: + for j in range(cl): Out[i] = Child[j] i += 1 - j += 1 Out[i] = 0 return 1 diff --git a/App/lib/VGuard.vp b/App/lib/VGuard.vp index c40d6d7..e4f420d 100644 --- a/App/lib/VGuard.vp +++ b/App/lib/VGuard.vp @@ -657,8 +657,7 @@ def ParseOkOne(Buf: bytes, Len: int) -> int: if Buf is None or Len <= 0: return 0 ub: BYTEPTR = BYTEPTR(Buf) - i: int = 0 - while i < Len: + for i in range(Len): if int(ub[i]) == 34: # '"' KeyPos: int = 0 if i == 0: @@ -689,7 +688,6 @@ def ParseOkOne(Buf: bytes, Len: int) -> int: nx: int = int(ub[j + 1]) if nx < 48 or nx > 57: # 后随非数字 ⇒ 值恰为 1 return 1 - i += 1 return 0 @@ -1049,10 +1047,8 @@ def GuardPumpStream(hIn: wb.HANDLE, Kind: int) -> int: if Br == 0: return GUARD_PUMP_EOF ub: BYTEPTR = BYTEPTR(Guard_Chunk) - i: int = 0 - while i < int(Br): + for i in range(int(Br)): GuardPendPut(int(ub[i])) # ③ 先整批入队(Br <= N <= GUARD_PEND_CAP) - i += 1 if GuardFeedPending() != 0: # ③ 再喂 FIFO;剩余字节留给下次调用 return 1 return 0 diff --git a/App/lib/VJson.vp b/App/lib/VJson.vp index 44e9dfa..872d203 100644 --- a/App/lib/VJson.vp +++ b/App/lib/VJson.vp @@ -128,10 +128,8 @@ def JWrite(S: str) -> int: n: sizet = string.strlen(S) if sizet(Json_Len) + n + 1 > sizet(JSON_BUF_CAP): return 0 - i: sizet = 0 - while i < n: + for i in range(n): Json_Buf[Json_Len + int(i)] = S[i] - i += 1 Json_Len += int(n) Json_Buf[Json_Len] = 0 return 1 @@ -224,8 +222,7 @@ def EmitJson() -> int: Count: int = 0 if JWrite("[") == 0: return 0 - i: int = 0 - while i < VCache.CacheCount(): + for i in range(VCache.CacheCount()): # 条目级回收:工作池峰值 = 单条(节点 + 字符串副本 + 库的 4096 字节输出缓冲) Json_Pool.reset() Txt: str = BuildEntry(i) @@ -244,7 +241,6 @@ def EmitJson() -> int: JWrite(",") JWrite(Txt) Count += 1 - i += 1 if JWrite("]") == 0: Truncated = 1 if JWrite("\n") == 0: diff --git a/App/lib/VPe.vp b/App/lib/VPe.vp index 6d0671f..1cbfe02 100644 --- a/App/lib/VPe.vp +++ b/App/lib/VPe.vp @@ -102,10 +102,8 @@ def ReadU32(Buf: BYTEPTR, Off: int) -> uint32: # 复制 8 字节节名并补 NUL,写入 Out(调用方保证 >=9 字节) def CopySectionName(Buf: BYTEPTR, Off: int, Out: bytes): - k: int = 0 - while k < 8: + for k in range(8): Out[k] = Buf[Off + k] - k += 1 Out[8] = 0 @@ -200,14 +198,12 @@ def ParsePeHead(Buf: bytes, Got: sizet, OutArch: bytes, ArchCap: int) -> int: if sizet(sec_off) + sizet(nsec) * sizet(SEC_ENTRY_SIZE) > Got: Pe_DbgLastRc = 6 return 6 # 节表超出头部窗口(极端多节 PE,跳过) - i: int = 0 - while i < int(nsec): + for i in range(int(nsec)): entry: int = sec_off + i * SEC_ENTRY_SIZE if string.strncmp(str(Buf + entry + SEC_NAME_OFF), VERSION_SECTION, 8) == 0: Pe_RawPtr = ReadU32(ub, entry + SEC_RAWPTR_OFF) Pe_RawSize = ReadU32(ub, entry + SEC_RAWSIZE_OFF) return 0 - i += 1 Pe_DbgLastRc = 7 return 7 @@ -403,15 +399,13 @@ def Phase1VersionSection(Target: str) -> int: found: int = 0 raw_ptr: uint32 = 0 raw_size: uint32 = 0 - i: int = 0 - while i < int(nsec): + for i in range(int(nsec)): entry: int = sec_off + i * SEC_ENTRY_SIZE if string.strncmp(str(buf + entry + SEC_NAME_OFF), VERSION_SECTION, 8) == 0: found = 1 raw_size = ReadU32(ub, entry + SEC_RAWSIZE_OFF) raw_ptr = ReadU32(ub, entry + SEC_RAWPTR_OFF) break - i += 1 if found == 0: VLog.LogFmtS1(" 未找到 %s 节\n", VERSION_SECTION) @@ -419,11 +413,9 @@ def Phase1VersionSection(Target: str) -> int: VLog.LogStr(" 实际节名:\n") name8: bytes = stdlib.malloc(9) if name8 is not None: - j: int = 0 - while j < int(nsec): + for j in range(int(nsec)): CopySectionName(ub, sec_off + j * SEC_ENTRY_SIZE, name8) VLog.LogFmtS1(" %s\n", str(name8)) - j += 1 stdlib.free(t.CPtr(name8)) stdlib.free(t.CPtr(buf)) return 1 diff --git a/App/lib/VScan.vp b/App/lib/VScan.vp index d78e49a..db92b1f 100644 --- a/App/lib/VScan.vp +++ b/App/lib/VScan.vp @@ -459,8 +459,7 @@ def RunScanRound(CachePath: str, RoundIdx: int) -> int: VGuard.PollIpc() Revalidated: int = RevalidateDiscovered() Dirs: int = 0 - k: int = 0 - while k < VDirs.DirCount(): + for k in range(VDirs.DirCount()): AnsiDir: bytes = _mbuddy.alloc(VFs.PATH_BUF_CAP) if AnsiDir is not None: VFs.Utf8ToAnsi(VDirs.DirAt(k), AnsiDir, VFs.PATH_BUF_CAP) @@ -475,7 +474,6 @@ def RunScanRound(CachePath: str, RoundIdx: int) -> int: # 逐条回显属过程细节,仅在 --verbose 时给出(--path 的显式告警在 VDirs.BuildTable) VLog.VerboseFmtS1(" 跳过(不存在或非目录): %s\n", str(AnsiDir)) _mbuddy.free(t.CPtr(AnsiDir)) - k += 1 # 本轮被 PE/.PRVERSN 过滤掉的候选:前 REJECT_LOG_MAX 条已在 HandleCandidate 逐条打印, # 这里只补一行汇总(不逐条重打)——逐条与汇总均属过程细节,仅 --verbose 时给出 @@ -599,8 +597,7 @@ def RunSearchPathsQuery() -> int: Ansi: bytes = _mbuddy.alloc(VFs.PATH_BUF_CAP) if Ansi is None: VLog.LogStr(" 警告: 查询缓冲分配失败,仅列出路径(不标注是否会被扫盘跳过)\n") - i: int = 0 - while i < N: + for i in range(N): Path: str = VDirs.DirAt(i) Skip: int = 0 # 1=扫盘时会跳过;Ansi 不可用时保持 0(不标注) if Ansi is not None: @@ -611,7 +608,6 @@ def RunSearchPathsQuery() -> int: VLog.LogFmtIS(" [search] [%u] %s (不存在或非目录,扫盘时会跳过)\n", sizet(i), Path) else: VLog.LogFmtIS(" [search] [%u] %s\n", sizet(i), Path) - i += 1 if Ansi is not None: _mbuddy.free(t.CPtr(Ansi)) VLog.LogFmt1(" [search] 合计 %u 条;未扫盘、未读写缓存,查询到此结束\n", sizet(N))