From d41b533008cce91db247b152f3d4727596eea62a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 3 Jul 2016 19:41:56 +0200 Subject: [PATCH] Add #ifdef to preprocessor --- mt2obj.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mt2obj.py b/mt2obj.py index 0090ee2..624b023 100755 --- a/mt2obj.py +++ b/mt2obj.py @@ -74,6 +74,16 @@ def pp_process(ctx, line): else: ctx[0]['if_state'] = 2 # ignore current lines, expecting #else or #endif return None + elif line.startswith('#ifdef'): #e.g.: #ifdef name + tmp = line.split(' ') + if len(tmp) < 2: + raise Exception('Missing something..') + tmp = tmp[1] + if tmp in ctx[1].keys(): + ctx[0]['if_state'] = 1 # don't ignore current lines, expecting #else or #endif + else: + ctx[0]['if_state'] = 2 # ignore current lines, expecting #else or #endif + return None elif line.startswith('#else') and ctx[0]['if_state'] == 1: ctx[0]['if_state'] = 4 # ignore current lines, expecting #endif elif line.startswith('#else') and ctx[0]['if_state'] == 2: