xref: /illumos-gate/usr/src/tools/onbld/Checks/SpellCheck.py (revision f3a07f941f1be263a48a040c059edbcb722cf436)
171af3be3SCody Peter Mello#
271af3be3SCody Peter Mello# CDDL HEADER START
371af3be3SCody Peter Mello#
471af3be3SCody Peter Mello# The contents of this file are subject to the terms of the
571af3be3SCody Peter Mello# Common Development and Distribution License (the "License").
671af3be3SCody Peter Mello# You may not use this file except in compliance with the License.
771af3be3SCody Peter Mello#
871af3be3SCody Peter Mello# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
971af3be3SCody Peter Mello# or http://www.opensolaris.org/os/licensing.
1071af3be3SCody Peter Mello# See the License for the specific language governing permissions
1171af3be3SCody Peter Mello# and limitations under the License.
1271af3be3SCody Peter Mello#
1371af3be3SCody Peter Mello# When distributing Covered Code, include this CDDL HEADER in each
1471af3be3SCody Peter Mello# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1571af3be3SCody Peter Mello# If applicable, add the following below this CDDL HEADER, with the
1671af3be3SCody Peter Mello# fields enclosed by brackets "[]" replaced with your own identifying
1771af3be3SCody Peter Mello# information: Portions Copyright [yyyy] [name of copyright owner]
1871af3be3SCody Peter Mello#
1971af3be3SCody Peter Mello# CDDL HEADER END
2071af3be3SCody Peter Mello#
2171af3be3SCody Peter Mello
2271af3be3SCody Peter Mello#
2371af3be3SCody Peter Mello# Copyright 2016 Joyent, Inc.
2471af3be3SCody Peter Mello#
2571af3be3SCody Peter Mello
2671af3be3SCody Peter Melloimport re, sys
2771af3be3SCody Peter Mello
2871af3be3SCody Peter MellospellMsg = '%s: Line %d contains "%s", a common misspelling of "%s"\n'
2971af3be3SCody Peter MelloaltMsg = '%s: Lined %d contains "%s"; please use "%s" instead for consistency with other documentation\n'
3071af3be3SCody Peter Mello
3171af3be3SCody Peter Mellomisspellings = {
3271af3be3SCody Peter Mello	'absense': 'absence',
3371af3be3SCody Peter Mello	'accessable': 'accessible',
3471af3be3SCody Peter Mello	'accomodate': 'accommodate',
3571af3be3SCody Peter Mello	'accomodation': 'accommodation',
3671af3be3SCody Peter Mello	'accross': 'across',
3771af3be3SCody Peter Mello	'acheive': 'achieve',
3871af3be3SCody Peter Mello	'addional': 'additional',
3971af3be3SCody Peter Mello	'addres': 'address',
4071af3be3SCody Peter Mello	'admininistrative': 'administrative',
4171af3be3SCody Peter Mello	'adminstered': 'administered',
4271af3be3SCody Peter Mello	'adminstrate': 'administrate',
4371af3be3SCody Peter Mello	'adminstration': 'administration',
4471af3be3SCody Peter Mello	'adminstrative': 'administrative',
4571af3be3SCody Peter Mello	'adminstrator': 'administrator',
4671af3be3SCody Peter Mello	'admissability': 'admissibility',
4771af3be3SCody Peter Mello	'adress': 'address',
4871af3be3SCody Peter Mello	'adressable': 'addressable',
4971af3be3SCody Peter Mello	'adressed': 'addressed',
5071af3be3SCody Peter Mello	'adressing': 'addressing, dressing',
5171af3be3SCody Peter Mello	'aginst': 'against',
5271af3be3SCody Peter Mello	'agression': 'aggression',
5371af3be3SCody Peter Mello	'agressive': 'aggressive',
5471af3be3SCody Peter Mello	'alot': 'a lot, allot',
5571af3be3SCody Peter Mello	'and and': 'and',
5671af3be3SCody Peter Mello	'apparantly': 'apparently',
5771af3be3SCody Peter Mello	'appearence': 'appearance',
5871af3be3SCody Peter Mello	'arguement': 'argument',
5971af3be3SCody Peter Mello	'assasination': 'assassination',
6071af3be3SCody Peter Mello	'auxilliary': 'auxiliary',
6171af3be3SCody Peter Mello	'basicly': 'basically',
6271af3be3SCody Peter Mello	'begining': 'beginning',
6371af3be3SCody Peter Mello	'belive': 'believe',
6471af3be3SCody Peter Mello	'beteen': 'between',
6571af3be3SCody Peter Mello	'betwen': 'between',
6671af3be3SCody Peter Mello	'beween': 'between',
6771af3be3SCody Peter Mello	'bewteen': 'between',
6871af3be3SCody Peter Mello	'bizzare': 'bizarre',
6971af3be3SCody Peter Mello	'buisness': 'business',
7071af3be3SCody Peter Mello	'calender': 'calendar',
7171af3be3SCody Peter Mello	'cemetary': 'cemetery',
7271af3be3SCody Peter Mello	'chauffer': 'chauffeur',
7371af3be3SCody Peter Mello	'collegue': 'colleague',
7471af3be3SCody Peter Mello	'comming': 'coming',
7571af3be3SCody Peter Mello	'commited': 'committed',
7671af3be3SCody Peter Mello	'commitee': 'committee',
7771af3be3SCody Peter Mello	'commiting': 'committing',
7871af3be3SCody Peter Mello	'comparision': 'comparison',
7971af3be3SCody Peter Mello	'comparisions': 'comparisons',
8071af3be3SCody Peter Mello	'compatability': 'compatibility',
8171af3be3SCody Peter Mello	'compatable': 'compatible',
8271af3be3SCody Peter Mello	'compatablity': 'compatibility',
8371af3be3SCody Peter Mello	'compatiable': 'compatible',
8471af3be3SCody Peter Mello	'compatiblity': 'compatibility',
8571af3be3SCody Peter Mello	'completly': 'completely',
8671af3be3SCody Peter Mello	'concious': 'conscious',
8771af3be3SCody Peter Mello	'condidtion': 'condition',
8871af3be3SCody Peter Mello	'conected': 'connected',
8971af3be3SCody Peter Mello	'conjuction': 'conjunction',
9071af3be3SCody Peter Mello	'continous': 'continuous',
9171af3be3SCody Peter Mello	'curiousity': 'curiosity',
9271af3be3SCody Peter Mello	'deamon': 'daemon',
9371af3be3SCody Peter Mello	'definately': 'definitely',
9471af3be3SCody Peter Mello	'desireable': 'desirable',
9571af3be3SCody Peter Mello	'diffrent': 'different',
9671af3be3SCody Peter Mello	'dilemna': 'dilemma',
9771af3be3SCody Peter Mello	'dissapear': 'disappear',
9871af3be3SCody Peter Mello	'dissapoint': 'disappoint',
9971af3be3SCody Peter Mello	'ecstacy': 'ecstasy',
10071af3be3SCody Peter Mello	'embarass': 'embarrass',
10171af3be3SCody Peter Mello	'enviroment': 'environment',
10271af3be3SCody Peter Mello	'exept': 'except',
10371af3be3SCody Peter Mello	'existance': 'existence',
10471af3be3SCody Peter Mello	'familar': 'familiar',
10571af3be3SCody Peter Mello	'finaly': 'finally',
10671af3be3SCody Peter Mello	'folowing': 'following',
10771af3be3SCody Peter Mello	'foriegn': 'foreign',
10871af3be3SCody Peter Mello	'forseeable': 'foreseeable',
10971af3be3SCody Peter Mello	'fourty': 'forty',
11071af3be3SCody Peter Mello	'foward': 'forward',
11171af3be3SCody Peter Mello	'freind': 'friend',
11271af3be3SCody Peter Mello	'futher': 'further',
11371af3be3SCody Peter Mello	'gaurd': 'guard',
11471af3be3SCody Peter Mello	'glamourous': 'glamorous',
11571af3be3SCody Peter Mello	'goverment': 'government',
11671af3be3SCody Peter Mello	'happend': 'happened',
11771af3be3SCody Peter Mello	'harrassment': 'harassment',
11871af3be3SCody Peter Mello	'hierachical': 'hierarchical',
11971af3be3SCody Peter Mello	'hierachies': 'hierarchies',
12071af3be3SCody Peter Mello	'hierachy': 'hierarchy',
12171af3be3SCody Peter Mello	'hierarcical': 'hierarchical',
12271af3be3SCody Peter Mello	'hierarcy': 'hierarchy',
12371af3be3SCody Peter Mello	'honourary': 'honorary',
12471af3be3SCody Peter Mello	'humourous': 'humorous',
12571af3be3SCody Peter Mello	'idiosyncracy': 'idiosyncrasy',
12671af3be3SCody Peter Mello	'immediatly': 'immediately',
12771af3be3SCody Peter Mello	'inaccessable': 'inaccessible',
12871af3be3SCody Peter Mello	'inbetween': 'between',
12971af3be3SCody Peter Mello	'incidently': 'incidentally',
13071af3be3SCody Peter Mello	'independant': 'independent',
13171af3be3SCody Peter Mello	'infomation': 'information',
13271af3be3SCody Peter Mello	'interupt': 'interrupt',
13371af3be3SCody Peter Mello	'intial': 'initial',
13471af3be3SCody Peter Mello	'intially': 'initially',
13571af3be3SCody Peter Mello	'irresistable': 'irresistible',
13671af3be3SCody Peter Mello	'jist': 'gist',
13771af3be3SCody Peter Mello	'knowlege': 'knowledge',
13871af3be3SCody Peter Mello	'lenght': 'length',
13971af3be3SCody Peter Mello	'liase': 'liaise',
14071af3be3SCody Peter Mello	'liason': 'liaison',
14171af3be3SCody Peter Mello	'libary': 'library',
14271af3be3SCody Peter Mello	'maching': 'machine, marching, matching',
14371af3be3SCody Peter Mello	'millenia': 'millennia',
14471af3be3SCody Peter Mello	'millenium': 'millennium',
14571af3be3SCody Peter Mello	'neccessary': 'necessary',
14671af3be3SCody Peter Mello	'negotation': 'negotiation',
14771af3be3SCody Peter Mello	'nontheless': 'nonetheless',
14871af3be3SCody Peter Mello	'noticable': 'noticeable',
14971af3be3SCody Peter Mello	'occassion': 'occasion',
15071af3be3SCody Peter Mello	'occassional': 'occasional',
15171af3be3SCody Peter Mello	'occassionally': 'occasionally',
15271af3be3SCody Peter Mello	'occurance': 'occurrence',
15371af3be3SCody Peter Mello	'occured': 'occurred',
15471af3be3SCody Peter Mello	'occurence': 'occurrence',
15571af3be3SCody Peter Mello	'occuring': 'occurring',
15671af3be3SCody Peter Mello	'ommision': 'omission',
15771af3be3SCody Peter Mello	'orginal': 'original',
15871af3be3SCody Peter Mello	'orginally': 'originally',
15971af3be3SCody Peter Mello	'pavillion': 'pavilion',
16071af3be3SCody Peter Mello	'peice': 'piece',
16171af3be3SCody Peter Mello	'persistant': 'persistent',
16271af3be3SCody Peter Mello	'politican': 'politician',
16371af3be3SCody Peter Mello	'posession': 'possession',
16471af3be3SCody Peter Mello	'possiblity': 'possibility',
16571af3be3SCody Peter Mello	'preceed': 'precede',
16671af3be3SCody Peter Mello	'preceeded': 'preceded',
16771af3be3SCody Peter Mello	'preceeding': 'preceding',
16871af3be3SCody Peter Mello	'preceeds': 'precedes',
16971af3be3SCody Peter Mello	'prefered': 'preferred',
17071af3be3SCody Peter Mello	'prefering': 'preferring',
17171af3be3SCody Peter Mello	'presense': 'presence',
17271af3be3SCody Peter Mello	'proces': 'process',
17371af3be3SCody Peter Mello	'propoganda': 'propaganda',
17471af3be3SCody Peter Mello	'psuedo': 'pseudo',
17571af3be3SCody Peter Mello	'publically': 'publicly',
17671af3be3SCody Peter Mello	'realy': 'really',
17771af3be3SCody Peter Mello	'reciept': 'receipt',
17871af3be3SCody Peter Mello	'recieve': 'receive',
17971af3be3SCody Peter Mello	'recieved': 'received',
18071af3be3SCody Peter Mello	'reciever': 'receiver',
18171af3be3SCody Peter Mello	'recievers': 'receivers',
18271af3be3SCody Peter Mello	'recieves': 'receives',
18371af3be3SCody Peter Mello	'recieving': 'receiving',
18471af3be3SCody Peter Mello	'recomend': 'recommend',
18571af3be3SCody Peter Mello	'recomended': 'recommended',
18671af3be3SCody Peter Mello	'recomending': 'recommending',
18771af3be3SCody Peter Mello	'recomends': 'recommends',
18871af3be3SCody Peter Mello	'recurse': 'recur',
18971af3be3SCody Peter Mello	'recurses': 'recurs',
19071af3be3SCody Peter Mello	'recursing': 'recurring',
19171af3be3SCody Peter Mello	'refered': 'referred',
19271af3be3SCody Peter Mello	'refering': 'referring',
19371af3be3SCody Peter Mello	'religous': 'religious',
19471af3be3SCody Peter Mello	'rember': 'remember',
19571af3be3SCody Peter Mello	'remeber': 'remember',
19671af3be3SCody Peter Mello	'repetion': 'repetition',
19771af3be3SCody Peter Mello	'reponsible': 'responsible',
19871af3be3SCody Peter Mello	'resistence': 'resistance',
19971af3be3SCody Peter Mello	'retreive': 'retrieve',
20071af3be3SCody Peter Mello	'seige': 'siege',
20171af3be3SCody Peter Mello	'sence': 'since',
20271af3be3SCody Peter Mello	'seperate': 'separate',
20371af3be3SCody Peter Mello	'seperated': 'separated',
20471af3be3SCody Peter Mello	'seperately': 'separately',
20571af3be3SCody Peter Mello	'seperates': 'separates',
20671af3be3SCody Peter Mello	'similiar': 'similar',
20771af3be3SCody Peter Mello	'somwhere': 'somewhere',
20871af3be3SCody Peter Mello	'sould': 'could, should, sold, soul',
20971af3be3SCody Peter Mello	'sturcture': 'structure',
21071af3be3SCody Peter Mello	'succesful': 'successful',
21171af3be3SCody Peter Mello	'succesfully': 'successfully',
21271af3be3SCody Peter Mello	'successfull': 'successful',
21371af3be3SCody Peter Mello	'sucessful': 'successful',
21471af3be3SCody Peter Mello	'supercede': 'supersede',
21571af3be3SCody Peter Mello	'supress': 'suppress',
21671af3be3SCody Peter Mello	'supressed': 'suppressed',
21771af3be3SCody Peter Mello	'suprise': 'surprise',
21871af3be3SCody Peter Mello	'suprisingly': 'surprisingly',
21971af3be3SCody Peter Mello	'sytem': 'system',
22071af3be3SCody Peter Mello	'tendancy': 'tendency',
22171af3be3SCody Peter Mello	'the the': 'the',
22271af3be3SCody Peter Mello	'the these': 'these',
22371af3be3SCody Peter Mello	'therefor': 'therefore',
22471af3be3SCody Peter Mello	'threshhold': 'threshold',
22571af3be3SCody Peter Mello	'tolerence': 'tolerance',
22671af3be3SCody Peter Mello	'tommorow': 'tomorrow',
22771af3be3SCody Peter Mello	'tommorrow': 'tomorrow',
22871af3be3SCody Peter Mello	'tounge': 'tongue',
22971af3be3SCody Peter Mello	'tranformed': 'transformed',
23071af3be3SCody Peter Mello	'transfered': 'transferred',
23171af3be3SCody Peter Mello	'truely': 'truly',
23271af3be3SCody Peter Mello	'trustworthyness': 'trustworthiness',
23371af3be3SCody Peter Mello	'unforseen': 'unforeseen',
23471af3be3SCody Peter Mello	'unfortunatly': 'unfortunately',
23571af3be3SCody Peter Mello	'unsuccessfull': 'unsuccessful',
23671af3be3SCody Peter Mello	'untill': 'until',
23771af3be3SCody Peter Mello	'upto': 'up to',
23871af3be3SCody Peter Mello	'whereever': 'wherever',
23971af3be3SCody Peter Mello	'wich': 'which',
24071af3be3SCody Peter Mello	'wierd': 'weird',
24171af3be3SCody Peter Mello	'wtih': 'with',
24271af3be3SCody Peter Mello}
24371af3be3SCody Peter Mello
24471af3be3SCody Peter Melloalternates = {
245*f3a07f94SCody Peter Mello	'parseable': 'parsable',
2461b2031a9SCody Peter Mello	'sub-command': 'subcommand',
2471b2031a9SCody Peter Mello	'sub-commands': 'subcommands',
248831b40b1SCody Peter Mello	'writeable': 'writable'
24971af3be3SCody Peter Mello}
25071af3be3SCody Peter Mello
25171af3be3SCody Peter MellomisspellingREs = []
25271af3be3SCody Peter MelloalternateREs = []
25371af3be3SCody Peter Mello
25471af3be3SCody Peter Mellofor misspelling, correct in misspellings.iteritems():
25571af3be3SCody Peter Mello	regex = re.compile(r'\b%s\b' % (misspelling), re.IGNORECASE)
25671af3be3SCody Peter Mello	entry = (regex, misspelling, correct)
25771af3be3SCody Peter Mello	misspellingREs.append(entry)
25871af3be3SCody Peter Mello
25971af3be3SCody Peter Mellofor alternate, correct in alternates.iteritems():
26071af3be3SCody Peter Mello	regex = re.compile(r'\b%s\b' % (alternate), re.IGNORECASE)
26171af3be3SCody Peter Mello	entry = (regex, alternate, correct)
26271af3be3SCody Peter Mello	alternateREs.append(entry)
26371af3be3SCody Peter Mello
26471af3be3SCody Peter Mellodef check(errmsg, output, filename, line, lineno, entry):
26571af3be3SCody Peter Mello	if entry[0].search(line):
26671af3be3SCody Peter Mello		output.write(errmsg % (filename, lineno, entry[1], entry[2]))
26771af3be3SCody Peter Mello		return 1
26871af3be3SCody Peter Mello	else:
26971af3be3SCody Peter Mello		return 0
27071af3be3SCody Peter Mello
27171af3be3SCody Peter Mellodef spellcheck(fh, filename=None, output=sys.stderr, **opts):
27271af3be3SCody Peter Mello	lineno = 1
27371af3be3SCody Peter Mello	ret = 0
27471af3be3SCody Peter Mello
27571af3be3SCody Peter Mello	if not filename:
27671af3be3SCody Peter Mello		filename = fh.name
27771af3be3SCody Peter Mello
27871af3be3SCody Peter Mello	fh.seek(0)
27971af3be3SCody Peter Mello	for line in fh:
28071af3be3SCody Peter Mello		for entry in misspellingREs:
28171af3be3SCody Peter Mello			ret |= check(spellMsg, output, filename, line,
28271af3be3SCody Peter Mello			    lineno, entry)
28371af3be3SCody Peter Mello		for entry in alternateREs:
28471af3be3SCody Peter Mello			ret |= check(altMsg, output, filename, line,
28571af3be3SCody Peter Mello			    lineno, entry)
28671af3be3SCody Peter Mello		lineno += 1
28771af3be3SCody Peter Mello
28871af3be3SCody Peter Mello	return ret
289