#!/usr/bin/python


"""
This catches a comma that is followed by another character than a space, for
example "a,b,c", which should be "a, b, c". It is a little complex because it
should not catch commas in string constants or character constants.
"""

error_msg = "A space is mandatory after '*' or '&' in access type declaration."

strip_comments_and_strings = True
regexp = r"""^([^/#]|/([^/\"']|\"([^\"]|\\\")*\"|'(\\[\'0nt]|[^\'])')|\"([^\"\]|\\\"|\\[^\"])*\"|'(\\[\'0nt]|[^\'])')*((([_a-zA-Z0-9]a|[^a])n|[^n])d|(((([_a-zA-Z0-9]e|[^e])l|[^l])s|[^st])|((((([_a-zA-Z0-9]d|[^d])e|[^e])l|[^l])e|[^e])t|[^st]))e|((((([_a-zA-Z0-9]r|[^r])e|[^e])t|[^t])u|[^u])r|[^r])n|([_a-zA-Z0-9]o|[^o])r|(([_a-zA-Z0-9]n|[^n])o|[^o])t|[^	 denrt\"([{,;.:=|&<>?!*\+-]) *[&*][_a-zA-Z0-9]"""

forbidden = [
    "bool f(const char *name) {",
    "bool f(char const *name) {",
    "	fdelete *ptr;",
    "	f_delete *ptr;",
    "	f9delete *ptr;",
    "	greturn *ptr;",
    "	g_return *ptr;",
    "	g8return *ptr;",
    "	gnot *buffer;",
    "	g_not *buffer;",
    "	g7not *buffer;",
    "	hand *buffer;",
    "	h_and *buffer;",
    "	h6and *buffer;",
    "	ior *buffer;",
    "	i_or *buffer;",
    "	i9or *buffer;"
]

allowed = [
    "bool f(char const * name) {",
    "bool f(char * name) {",
    "bool f(char * const name) {",
    '	"       *HIGHLY EXERIMENTAL*\n",',
    "	delete *ptr;",
    "	delete  *ptr;",
    "	return *ptr;",
    "	return   *ptr;",
    "	return *ptr;",
    "	return    *ptr;",
    "	and *buffer;",
    "	and     *buffer;",
    "	or *buffer;",
    "	or      *buffer;",
    "case 0: *p = *q;",
    "case 0:       *p = *q;",
    "//  this is *allowed*",
    "	//  this is *also* allowed",
    'char * ptr = "this *is* allowed";',
    "	a = b - &map[0];",
    "#define TOOLBAR_BUTTON_COMMON_PARAMETERS &m_toolbar, 0, 0, 34U, 34U, PIC2",
    "	void call() {if (_fn) (_obj->*_fn)();}",
    "		(_callback_argument_this.*_callback_function)();",
    "		if (!*ppgrid) {",
    "			return **i.current;",
    "void MiniMap::toggle(Layers const button) {*m_view.m_flags ^= button;}",
    "		m_loaded_obj[&object] = false;",
    "				++*digit_to_increment;",
    "			if (fname == extension) {*p = '\0'; break;} else *p = *fname;"
]
