aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-09-25 10:28:19 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-09-25 10:28:19 -0700
commitf0ba90f7e5e42a5da600eee43aaf6630e92565f0 (patch)
tree4f526042af3dba6407f2f379b053902f9dd06939
parent3b21d884fbcb3c994931278129bec8dea76bb777 (diff)
parse C1|C2 in headers; properly fixes fcntl
-rwxr-xr-xemscripten.py23
-rw-r--r--tests/fcntl/output.txt4
-rw-r--r--tests/fcntl/src.c4
3 files changed, 18 insertions, 13 deletions
diff --git a/emscripten.py b/emscripten.py
index 85ae0cab..c103af87 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -175,9 +175,8 @@ def main(args):
header = os.path.join(include_root, header)
for line in open(header, 'r'):
line = line.replace('\t', ' ')
- m = re.match('^ *#define +(?P<name>[-\w_.]+) +(?P<value>[-\w_.]+).*', line)
+ m = re.match('^ *#define +(?P<name>[-\w_.]+) +\(?(?P<value>[-\w_.|]+)\)?.*', line)
if m:
- #print 'define!', m.groups()
defines[m.group('name')] = m.group('value')
m = re.match('^ *#include *["<](?P<name>[\w_.-/]+)[">].*', line)
if m:
@@ -193,25 +192,31 @@ def main(args):
if found: break
#assert found, 'Could not find header: ' + m.group('name')
if len(defines) > 0:
- #print 'zz defines pre: ', defines
def lookup(value):
try:
while not unicode(value).isnumeric():
value = defines[value]
return value
except:
- try:
- value = eval(value)
- return value
- except:
- return None
+ pass
+ try: # 0x300 etc.
+ value = eval(value)
+ return value
+ except:
+ pass
+ try: # CONST1|CONST2
+ parts = map(lookup, value.split('|'))
+ value = reduce(lambda a, b: a|b, map(eval, parts))
+ return value
+ except:
+ pass
+ return None
for key, value in defines.items():
value = lookup(value)
if value is not None:
defines[key] = str(value)
else:
del defines[key]
- #print 'zz defines post: ', defines
settings['C_DEFINES'] = defines
# Compile the assembly to Javascript.
diff --git a/tests/fcntl/output.txt b/tests/fcntl/output.txt
index 17f662d0..1ed740e7 100644
--- a/tests/fcntl/output.txt
+++ b/tests/fcntl/output.txt
@@ -13,13 +13,13 @@ errno: 0
F_SETFD: 0
errno: 0
-F_GETFL: 0
+F_GETFL: 1
errno: 0
F_SETFL: 0
errno: 0
-F_GETFL/2: 0x8
+F_GETFL/2: 1
errno: 0
F_GETLK: 0
diff --git a/tests/fcntl/src.c b/tests/fcntl/src.c
index 94d6f3c2..5b40ec79 100644
--- a/tests/fcntl/src.c
+++ b/tests/fcntl/src.c
@@ -30,7 +30,7 @@ int main() {
printf("\n");
errno = 0;
- printf("F_GETFL: %d\n", fcntl(f, F_GETFL)); // XXX is the result in output correct?
+ printf("F_GETFL: %d\n", fcntl(f, F_GETFL) == O_RDWR);
printf("errno: %d\n", errno);
printf("\n");
errno = 0;
@@ -40,7 +40,7 @@ int main() {
printf("\n");
errno = 0;
- printf("F_GETFL/2: %#x\n", fcntl(f, F_GETFL)); // XXX is the result in output correct?
+ printf("F_GETFL/2: %d\n", fcntl(f, F_GETFL) == (O_RDWR | O_APPEND));
printf("errno: %d\n", errno);
printf("\n");
errno = 0;