#!/usr/bin/python

# Copyright 2012 the Redfish authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
import sys

if (len(sys.argv) == 1) or (sys.argv[1] == "--help") or (sys.argv[1] == "-h"):
    print >>sys.stderr, "generate_terror.py: generate terror.c from errno.h file(s)"
    print >>sys.stderr, ""
    print >>sys.stderr, "usage: generate-terror [errno header files to process]"
    print >>sys.stderr, ("example invocation: %s " +
        "/usr/include/asm-generic/errno-base.h " +
        "/usr/include/asm-generic/errno.h" + 
        " > util/terror.c") % sys.argv[0]
    sys.exit(0)


pat = re.compile('#define[ \t]*([A-Z_]*)[ \t]*([0-9]*)[ \t]*/\* ([^*]*)\*/')

print """/*
 * Copyright 2012 the Redfish authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* NOTE: This file is automatically generated by generate_terror.py.
 * Please do not manually edit it.  Edit the script instead.
 */

#include <errno.h>

#include "util/terror.h"

const char *terror(int err)
{
	if (err < 0)
		err = -err;
	switch (err) {"""

for n in range(1, len(sys.argv)):
    f = open(sys.argv[n], 'r')
    for line in iter(f):
        mat = pat.match(line)
        if (not mat):
            continue
        name = mat.group(1)
        num = mat.group(2)
        desc = mat.group(3)
        desc = desc.rstrip()
        print "	case %s:" % name 
        print "		return \"%s\";" % desc
    f.close()

print """	default:
		break;
	}
	return "unknown error";
}
"""

#!/usr/bin/python

# Copyright 2012 the Redfish authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re
import sys

if (len(sys.argv) == 1) or (sys.argv[1] == "--help") or (sys.argv[1] == "-h"):
    print >>sys.stderr, "generate_terror.py: generate terror.c from errno.h file(s)"
    print >>sys.stderr, ""
    print >>sys.stderr, "usage: generate-terror [errno header files to process]"
    print >>sys.stderr, ("example invocation: %s " +
        "/usr/include/asm-generic/errno-base.h " +
        "/usr/include/asm-generic/errno.h" + 
        " > util/terror.c") % sys.argv[0]
    sys.exit(0)


pat = re.compile('#define[ \t]*([A-Z_]*)[ \t]*([0-9]*)[ \t]*/\* ([^*]*)\*/')

print """/*
 * Copyright 2012 the Redfish authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* NOTE: This file is automatically generated by generate_terror.py.
 * Please do not manually edit it.  Edit the script instead.
 */

#include <errno.h>

#include "util/terror.h"

const char *terror(int err)
{
	if (err < 0)
		err = -err;
	switch (err) {"""

for n in range(1, len(sys.argv)):
    f = open(sys.argv[n], 'r')
    for line in iter(f):
        mat = pat.match(line)
        if (not mat):
            continue
        name = mat.group(1)
        num = mat.group(2)
        desc = mat.group(3)
        desc = desc.rstrip()
        print "	case %s:" % name 
        print "		return \"%s\";" % desc
    f.close()

print """	default:
		break;
	}
	return "unknown error";
}
"""

#!/usr/bin/python # Copyright 2012 the Redfish authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. /*  * Copyright 2012 the Redfish authors  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *     http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */  /* NOTE: This file is automatically generated by generate_terror.py.  * Please do not manually edit it.  Edit the script instead.  */  #include <errno.h>  #include "util/terror.h"  const char *terror(int err) { 	if (err < 0) 		err = -err; 	switch (err) { default: 		break; 	} 	return "unknown error"; }