Browse Source

Allow for access to local strings by ref.
Added bcc-configuration file
- configuration-class for simple access to config files
- bcc.conf.default as template for individual bcc.conf-configuration files

woollybah 11 years ago
parent
commit
b2b66b252d
6 changed files with 191 additions and 19 deletions
  1. 159 0
      base.configmap.bmx
  2. 11 17
      bcc.bmx
  3. 6 0
      bcc.conf.default
  4. 1 1
      ctranslator.bmx
  5. 13 0
      options.bmx
  6. 1 1
      toker.bmx

+ 159 - 0
base.configmap.bmx

@@ -0,0 +1,159 @@
+Rem
+	===========================================================
+	BASIC CONFIGURATION MAP
+	===========================================================
+
+	Code contains an class to hold certain key->value pairs.
+
+End Rem
+SuperStrict
+
+Import BRL.Map
+Import BRL.FileSystem
+
+Type TConfigMap
+	Field values:TMap = CreateMap()
+	Field fileUri:String = ""
+
+
+	Method Init:TConfigMap( configFile:String="" )
+		If configFile <> "" Then LoadFromFile(configFile)
+
+		Return Self
+	End Method
+
+
+	'clear all key->value pairs
+	Method Reset:Int()
+		values.Clear()
+		Return True
+	End Method
+
+
+	'create another configMap with the same values
+	Method Copy:TConfigMap()
+		Local copyObj:TConfigMap = New TConfigMap
+
+		'copy values
+		For Local key:String = EachIn values.Keys()
+			copyObj.Add(key, Get(key))
+		Next
+		Return copyObj
+	End Method
+
+
+	'create a merged configMap of all given configurations (eg. base + extension)
+	Function CreateMerged:TConfigMap( configs:TConfigMap[], reversed:Int = False )
+		If configs.length = 0 Then Return Null
+
+		If reversed
+			Local newConfigs:TConfigMap[]
+			For Local i:Int = 1 To configs.length
+				newConfigs :+ [configs[configs.length - i]]
+			Next
+			configs = newConfigs
+		EndIf
+
+
+		Local result:TConfigMap = configs[0].copy()
+		For Local i:Int = 1 To configs.length-1
+			'overwrite values or add new if not existing
+			For Local key:String = EachIn configs[i].values.Keys()
+				Local value:Object = configs[i].Get(key)
+				If value Then result.Add(key, value)
+			Next
+		Next
+		Return result
+	End Function
+
+	'try to load the configuration from a file
+	Method LoadFromFile:Int( fileUri:String )
+		'skip resetting and loading if the file is not existing
+		If FileSize(fileUri) < 0 Then Return False
+
+		Self.fileUri = fileUri
+
+		'remove old values
+		Reset()
+
+		Local file:TStream = ReadFile(fileUri)
+		If Not file
+			'RuntimeError("ERROR: could not open file ~q"+fileUri+"~q for reading.")
+			Print "ERROR: could not open file ~q"+fileUri+"~q for reading."
+			Return False
+		EndIf
+
+		Local line:String = ""
+		Local splitPos:Int = 0
+		Local key:String, value:String
+		While Not Eof(file)
+			line = ReadLine(file)
+
+			'skip #comments
+			If line.Trim().Find("#") = 0 Then Continue
+
+			'find first "=" (later ones could come from arguments/params)
+			splitPos = line.Find("=")
+			'no splitter means no assignment
+			If splitPos < 0 Then Continue
+
+			key = line[..splitPos].Trim()
+			value = line[splitPos+1..].Trim()
+
+			Add(key, value)
+		Wend
+
+		file.Close()
+		Return True
+	End Method
+
+
+	Method ToString:String()
+		Local result:String = "TConfigMap"+"~n"
+		result :+ "-> file: "+Self.fileUri+"~n"
+		result :+ "-> keys:"+"~n"
+		For Local key:String = EachIn values.Keys()
+			result :+ "  -> "+key+" : "+String(values.ValueForKey(key))+"~n"
+		Next
+		Return result
+	End Method
+
+
+	Method Add:TConfigMap( key:String, data:Object )
+		values.insert(key, data)
+		Return Self
+	End Method
+
+
+	Method AddString:TConfigMap( key:String, data:String )
+		Add(key, Object(data))
+		Return Self
+	End Method
+
+
+	Method AddNumber:TConfigMap( key:String, data:Float )
+		Add( key, Object( String(data) ) )
+		Return Self
+	End Method
+
+
+	Method Get:Object( key:String, defaultValue:Object=Null )
+		Local result:Object = values.ValueForKey(key)
+		If result Then Return result
+		Return defaultValue
+	End Method
+
+
+	Method GetString:String( key:String, defaultValue:String=Null )
+		Local result:Object = Get(key)
+		If result Then Return String( result )
+		Return defaultValue
+	End Method
+
+
+	Method GetInt:Int( key:String, defaultValue:Int = Null )
+		Local result:Object = Get(key)
+		If result Then Return Int( Float( String( result ) ) )
+		Return defaultValue
+	End Method
+End Type

+ 11 - 17
bcc.bmx

@@ -4,12 +4,6 @@ Framework brl.StandardIO
 
 Import "ctranslator.bmx"
 
-?macos
-putenv_("BMXPATH=/Users/brucey/Documents/programming/BlitzMax_NG")
-?linux
-putenv_("BMXPATH=/home/brucey/000_programming/BlitzMaxTestArea")
-?
-
 Local args:String[] = ParseArgs(AppArgs[1..])
 
 If args.length = 0 Then
@@ -50,7 +44,7 @@ SaveSource(opt_filepath, trans, mung)
 
 
 Function SaveInterface(file:String, trans:TCTranslator, mung:String)
-	
+
 	Local path:String
 
 	If opt_buildtype = BUILDTYPE_MODULE Then
@@ -62,14 +56,14 @@ Function SaveInterface(file:String, trans:TCTranslator, mung:String)
 			' file interface
 			path = OutputFilePath(file, mung, "i")
 		End If
-		
+
 	Else
-	
+
 		' file interface
 		path = OutputFilePath(file, mung, "i")
-		
+
 	End If
-	
+
 	SaveText(trans.JoinLines("interface"), path)
 
 End Function
@@ -77,27 +71,27 @@ End Function
 Function SaveHeader(file:String, trans:TCTranslator, mung:String)
 
 	Local path:String = OutputFilePath(file, mung, "h")
-	
+
 	Local header:String = BuildHeaderName(path).ToUpper().Replace(".", "_")
 	Local text:String = HeaderComment()
 	text :+ "#ifndef " + header + "~n"
 	text :+ "#define " + header + "~n~n"
-	
+
 	If opt_buildtype = BUILDTYPE_MODULE And opt_modulename = "brl.blitz" Then
 		text :+ "#include <brl.mod/blitz.mod/blitz.h>~n"
 	End If
-	
+
 	text :+ trans.JoinLines("head")
 	text :+ "~n~n#endif~n"
 
 	SaveText(text, path)
-	
+
 End Function
 
 Function SaveSource(file:String, trans:TCTranslator, mung:String)
 
 	Local path:String = OutputFilePath(file, mung, "c")
-	
+
 	SaveText(trans.JoinLines("source"), path)
-	
+
 End Function

+ 6 - 0
bcc.conf.default

@@ -0,0 +1,6 @@
+#copy this file as "bcc.conf" next to your bcc-binary
+#
+#uncomment the following lines and adjust paths as needed
+#
+
+#BMXPATH=YOUR/PATH/TO/BLITZMAX

+ 1 - 1
ctranslator.bmx

@@ -512,7 +512,7 @@ Type TCTranslator Extends TTranslator
 		Local t_index$=expr.index.Trans()
 		
 		If TStringType( expr.expr.exprType ) Then
-			Return t_expr + "->buf[" + t_index + "]" 
+			Return Bra(t_expr) + "->buf[" + t_index + "]" 
 			'Return "(BBINT)"+t_expr+"["+t_index+"]"
 		End If
 		

+ 13 - 0
options.bmx

@@ -1,5 +1,7 @@
 SuperStrict
 
+Import "base.configmap.bmx"
+
 Const version:String = "0.10"
 
 Const BUILDTYPE_APP:Int = 0
@@ -74,6 +76,8 @@ Function ParseArgs:String[](args:String[])
 
 	DefaultOptions()
 	
+	CheckConfig()
+	
 	Local count:Int
 
 	While count < args.length
@@ -166,3 +170,12 @@ Function DefaultOptions()
 ?
 End Function
 
+Function CheckConfig()
+
+	Local config:TConfigMap = New TConfigMap.Init("bcc.conf")
+	
+	If config.GetString("BMXPATH") <> ""
+		putenv_("BMXPATH="+config.GetString("BMXPATH_MACOS"))
+	EndIf
+
+End Function

+ 1 - 1
toker.bmx

@@ -21,7 +21,7 @@ Type TToker
 
 	Const _keywords$=";"+ ..
 	"strict;superstrict;"+ ..
-	"public;private;property;"+ ..
+	"public;private;"+ ..
 	"short;int;float;double;long;string;array;object;ptr;var;varptr;mod;continue;exit;"+ ..
 	"include;import;module;extern;framework;"+ ..
 	"new;self;super;eachin;true;false;null;not;"+ ..