summaryrefslogtreecommitdiff
path: root/scripts/check-header-files.py
blob: c6ee32ee7a499809db3bc5c64993dd418c1d9c30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3

#
#   Copyright (C) 2021 Reiko Asakura. All Rights Reserved.
#
#   Vita Development Suite Libraries
#

import sys
from pathlib import Path

import nids

def check_file(base, f):
	mode = f.stat().st_mode

	if mode != 0o100644:
		sys.exit(f'{f} has incorrect permission mode {mode:o}')

	if f.suffix != '.h' or f.stem != Path(f.stem).stem:
		sys.exit(f'{f} has incorrect file name format')

	text = f.read_bytes().decode()

	if '\r' in text:
		sys.exit(f'{f} has carriage return')

	if not text.startswith('/*\n\tVita Development Suite Libraries\n*/'):
		sys.exit(f'{f} has incorrect boilerplate')

	if not text.endswith('\n'):
		sys.exit(f'{f} does not have trailing line feed')

	include_guard = ('#define _VDSUITE_' + f'{f.relative_to(base)}'
		.replace('/', '_')
		.replace('\\', '_')
		.replace('.', '_')
		.upper())

	if include_guard not in text:
		sys.exit(f'{f} has incorrect include guard\n{include_guard}')

nids.iterdir(Path('include'), lambda f: check_file(Path('include'), f))