2023-03-13 19:55:10 +01:00
|
|
|
"""
|
|
|
|
line_len - checker for vxnorm
|
|
|
|
|
|
|
|
This file does not expose an explicite VxChecker object declaration to avoid
|
|
|
|
dependencies handling, you just need to provide:
|
|
|
|
======================= ===============================================
|
|
|
|
parse_file() Parse the source file
|
|
|
|
======================= ===============================================
|
|
|
|
"""
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Public
|
|
|
|
#---
|
|
|
|
|
2023-03-17 18:25:35 +01:00
|
|
|
def parse_file(checker, mfile, _):
|
2023-03-13 19:55:10 +01:00
|
|
|
""" parse the mapped file
|
|
|
|
|
|
|
|
The file is mapped using mmap() and seeked through offset 0 to avoid too
|
|
|
|
many I/O operations with classical file primitive.
|
|
|
|
|
|
|
|
@args
|
|
|
|
> checker (VxChecker) - current checker instance for this file
|
|
|
|
> mfile (mmap) - mmap instance of the file, seeked at 0
|
|
|
|
> pathname (str) - file pathname
|
|
|
|
|
|
|
|
@return
|
|
|
|
> Nothing
|
|
|
|
"""
|
|
|
|
counter = 0
|
2023-04-06 18:40:46 +02:00
|
|
|
checker.select_rule('linelen')
|
2023-03-17 18:25:35 +01:00
|
|
|
for line in mfile.getlines():
|
2023-03-13 19:55:10 +01:00
|
|
|
counter += 1
|
2023-03-17 18:25:35 +01:00
|
|
|
if len(line) <= 80 or line[0] == '#':
|
2023-03-13 19:55:10 +01:00
|
|
|
continue
|
2023-04-06 18:40:46 +02:00
|
|
|
checker.notify(f"{counter}", f"too long line ({len(line)}/80)")
|