From 8cb4a2b483a217ffb606e65ce41ea52788595f5f Mon Sep 17 00:00:00 2001
From: Yuriy Vostrikov <vostrikov@corp.mail.ru>
Date: Sat, 13 Nov 2010 15:16:47 +0300
Subject: [PATCH] [core] remove cfg.h file hack, tweak scripts/indent

---
 cfg/Makefile                |  9 +++++++--
 include/tarantool.h         |  2 +-
 scripts/custom_types.hs     | 34 ++++++++++++++++++++++++++++++++++
 scripts/indent              |  4 +++-
 scripts/usertypes2indent.pl | 17 -----------------
 5 files changed, 45 insertions(+), 21 deletions(-)
 create mode 100644 scripts/custom_types.hs
 delete mode 100755 scripts/usertypes2indent.pl

diff --git a/cfg/Makefile b/cfg/Makefile
index 72e47d0c08..7ee40468dc 100644
--- a/cfg/Makefile
+++ b/cfg/Makefile
@@ -1,8 +1,14 @@
 obj += cfg/warning.o
 obj += cfg/tarantool_$(module)_cfg.o
 
+$(obj): cfg/tarantool_cfg.h
+.PHONY: cfg/tarantool_cfg.h
+cfg/tarantool_cfg.h: cfg/tarantool_$(module)_cfg.h
+	@mkdir -p cfg
+	@ln -sf $(abspath $<) $@
+
 ifeq ($(HAVE_CONFETTI),1)
-$(obj): cfg/tarantool_$(module)_cfg.h cfg/tarantool_$(module)_cfg.cfg
+cfg/tarantool_$(module)_cfg.h: cfg/tarantool_$(module)_cfg.cfg_tmpl
 cfg/tarantool_$(module)_cfg.cfg_tmpl: cfg/core_cfg.cfg_tmpl $(cfg_tmpl)
 	@mkdir -p $(dir $@)
 	@echo '%{ ' > $@
@@ -13,5 +19,4 @@ cfg/tarantool_$(module)_cfg.cfg_tmpl: cfg/core_cfg.cfg_tmpl $(cfg_tmpl)
 	$(CAT) $^ >> $@
 endif
 
-CFLAGS += -DTARANTOOL_CONFIG='<cfg/tarantool_$(module)_cfg.h>'
 cfg/tarantool_$(module)_cfg.o: CFLAGS += -Wno-unused
diff --git a/include/tarantool.h b/include/tarantool.h
index ff8600b240..0819322611 100644
--- a/include/tarantool.h
+++ b/include/tarantool.h
@@ -30,7 +30,7 @@
 #include <tbuf.h>
 #include <util.h>
 #include <log_io.h>
-#include TARANTOOL_CONFIG
+#include <cfg/tarantool_cfg.h>
 
 struct recovery_state *recovery_state;
 void mod_init(void);
diff --git a/scripts/custom_types.hs b/scripts/custom_types.hs
new file mode 100644
index 0000000000..83b454d254
--- /dev/null
+++ b/scripts/custom_types.hs
@@ -0,0 +1,34 @@
+module Main where
+
+import System
+import qualified Data.Map as M
+import Data.Maybe
+import Language.C
+import Language.C.System.GCC
+import Language.C.Analysis.AstAnalysis
+import Language.C.Analysis.SemRep
+import Language.C.Analysis.TravMonad
+
+main = do
+  args <- getArgs
+  parseFile (head args) (tail args) >>= printGlobalTypes
+
+parseFile :: FilePath -> [String] -> IO CTranslUnit
+parseFile input_file cOpts =
+  do parse_result <- parseCFile (newGCC "gcc") Nothing cOpts input_file
+     case parse_result of
+       Left parse_err -> error (show parse_err)
+       Right ast      -> return ast
+
+printGlobalTypes transUnit = 
+    case runTrav_ (analyseAST transUnit) of
+      Left err -> error (show err)
+      Right (globals, _) -> mapM_ print $ globalTypeNames globals
+
+globalTypeNames g =
+    map identToString $ typeNames ++ sueNames
+    where
+      typeNames = M.keys (gTypeDefs g)
+      sueNames = mapMaybe named (M.keys $ gTags g)
+      named (NamedRef x) = Just x
+      named _ = Nothing
diff --git a/scripts/indent b/scripts/indent
index 420c8da3e7..5080ce6dce 100755
--- a/scripts/indent
+++ b/scripts/indent
@@ -2,6 +2,8 @@
 INDENT=$(which gindent 2>/dev/null || which indent 2>/dev/null)
 [ -z $INDENT ] && echo indent binary not found && exit 1
 
+CPP_FLAGS="-I. -Iinclude -DCORO_ASM -DSTORAGE"
+
 for f in $@
 do
 	PARAM="-npro -kr -i8 -ts8 -ci8 -sob -l100 -ss -ncs -cp1
@@ -19,7 +21,7 @@ do
 			;;
 	esac
 
-	PARAM="$PARAM "$(gcc -E -I. -Iinclude -DSTORAGE -DTARANTOOL_CONFIG='<cfg/tarantool_silverbox_cfg.h>' $f | perl scripts/usertypes2indent.pl)
+	PARAM="$PARAM "$(scripts/custom_types $f $CPP_FLAGS | grep -v '^"_' | sed 's/"//g; s/^/-T /')
 
 	$INDENT $PARAM $f
 done
diff --git a/scripts/usertypes2indent.pl b/scripts/usertypes2indent.pl
deleted file mode 100755
index 512c7d52f4..0000000000
--- a/scripts/usertypes2indent.pl
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/perl -w
-
-use strict;
-
-$/=undef;
-
-$_ = <>;
-
-my $brre;
-
-$brre = qr/(?:[^{}]*|\{(??{$brre})\})*/;
-
-my @a = /typedef\s+(?:(?:enum|struct|union)\s+[^{};]*\{$brre\}\s*|(?:\w+\s+)+)(\w+)[^;{}]*;/g;
-
-foreach (@a) {
-	print "-T $_ ";
-}
-- 
GitLab