Created
April 4, 2014 10:02
-
-
Save tailhook/9971606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jinja2 | |
data = { | |
"EINVAL": "Invalid value", | |
"EMFILE": "Too many open files", | |
"EINTR": "Interrupted by a signal" | |
} | |
with open('errno.h', 'wt') as f: | |
f.write(jinja2.Template(""" | |
{% set errnum = 1 %} | |
{% for name in root %} | |
#define {{ name }} {{ errnum }} | |
{%- set errnum = errnum + 1 %} | |
{%- endfor %} | |
""").render(root=data)) | |
with open('strerror.c', 'wt') as f: | |
f.write(jinja2.Template(""" | |
#include <errno.h> | |
char *strerror(int errnum) { | |
switch(errnum) { | |
{%- for name, text in root.items() %} | |
case {{ name }}: | |
return "{{ text }}"; | |
{%- endfor %} | |
default: | |
return "Unknown error"; | |
} | |
} | |
""").render(root=data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment