コード例 #1
0
        public TGINI()
        {
            var g = this;

            //fmt.Println("Init new GINI variable")
            //fmt.Printf("before %s\n",g.vars)
            //g.init = true
            //g.vars = map[string] string{ }
            //g.lists = make([][]string,0)
            //g.listpointer = map[string]int{ }
            //g.lists = map[string] []string{}
            //g.lists = map[string] qll.StringList{}
            //fmt.Printf("after %s\n",g.vars)
            GINI.DBGChat("TGINI class created");
        }
コード例 #2
0
        // Parses the lines of a text-based GINI file into the GINI data
        // Please note this method is for merging data purposes, if you don't
        // want to merge, use the regular functions ;)
        public void ParseLines(string[] l)
        {
            // this entire function has been translated from BlitzMax, however the [OLD] tag has been removed. (it was deprecated anyway).
            //g.init1st()
            //lst:=make([]string,0)
            var lst = new List <string>();
            //var lst //qll.StringList
            var tag      = "";
            var tagsplit = new string[0];
            //tagparam:=make([] string,0)
            var tline      = "";
            var cmd        = "";
            var para       = "";
            var pos        = 0;
            var line       = "";
            var listkeys   = new string[0];
            var linenumber = 0;// Not present in BMax, but required in go, and makes it even easier of debugging too :P (And for C# I made a different loop function JUST for the ocassion).

            for (linenumber = 0; linenumber < l.Length; linenumber++)
            {
                line = l[linenumber];
                if (line != "")
                {
                    if (qstr.Left(qstr.MyTrim(line), 1) == "[" && qstr.Right(qstr.MyTrim(line), 1) == "]")
                    {
                        var wTag = qstr.Mid(qstr.MyTrim(line), 2, qstr.Len(qstr.MyTrim(line)) - 2);
                        if (wTag.ToUpper() == "OLD")
                        {
                            throw new Exception($"[OLD] has been removed in the Go and C# versions of GINI! (line #{linenumber})");
                            //fmt.Printf("ERROR! The [old] tag is NOT supported in this Go version of GINI (and in the original BlitzMax version it's deprecated) in line %d", linenumber)
                            //return
                        }
                        tagsplit = wTag.Split(':');
                        tag      = tagsplit[0].ToUpper();
                        if (tagsplit[0].ToUpper() == "LIST")
                        {
                            if (tagsplit[0].Length < 2)
                            {
                                throw new Exception($"ERROR! Incorrectly defined list in line #{linenumber}");
                                //return;
                            }
                            //lst = qll.CreateStringList() //make([] string,0)
                            //                    lst = len(g.lists) //[]string{}
                            //g.lists = append(g.lists,[]string{})
                            var templist = new List <string>();
                            lst      = templist;
                            listkeys = tagsplit[1].Split(',');
                            foreach (string K in listkeys)
                            {
                                //'ini.clist(UnIniString(K))
                                //fmt.Printf("Creating list: %s\n",K)
                                //g.lists[strings.ToUpper(UnIniString(K))] = lst
                                //g.listpointer[strings.ToUpper(UnIniString(K))] = lst
                                lists[K.ToUpper()] = templist;
                            } //Next
                              //'lst=ini.list(UnIniString(K))
                        }     //EndIf
                    }
                    else
                    {
                        switch (tag)   //Select tag
                        {
                        case "REM":
                        case "LIC":     // This for full compatibility with MKL in the future.
                            break;

                        case "SYS":
                        case "SYSTEM":
                            tline = qstr.MyTrim(line);
                            pos   = tline.IndexOf(' ', 0);   //tline.find(" ")
                            if (pos <= -1)
                            {
                                pos = tline.Length;
                            }
                            cmd  = qstr.Left(tline, pos).ToUpper();
                            para = qstr.Mid(tline, pos, tline.Length - pos);
                            //cmd  = strings.ToUpper(tline[:pos])
                            //para = tline[pos + 1:]
                            switch (cmd)
                            {
                            case "IMPORT":
                            case "INCLUDE":
                                //pos = strings.IndexAny(para,"/") //para.find("/")<0

                                /*
                                 * ?win32
                                 * pos = pos And Chr(para[1])<>":"
                                 * pos = pos And para.find("\")
                                 * ?
                                 */
                                /*
                                 * if pos>0 {
                                 *  para=filepath(String(file))+"/"+para
                                 * }
                                 */
                                /*
                                 * ?debug
                                 * Print "Including: "+para
                                 * ?
                                 */
                                //g.ReadFile(para) //LoadIni para,ini
                                Console.WriteLine($"Line {linenumber} -- WARNING\nNo support yet for file inclusion or importing\n");
                                break;

                            default:
                                throw new Exception($"System command {cmd} not understood: {tline} in line #{linenumber}\n");
                            }     //End Select
                            break;

                        case "VARS":
                            if (line.IndexOf('=') < 0)
                            {
                                Console.WriteLine($"Warning! Invalid var definition: {line} in line #{linenumber} \t=> {line}\n");
                            }
                            else
                            {
                                //tagsplit=line.split("=")
                                var temppos = line.IndexOf('=');
                                tagsplit    = new string[2];
                                tagsplit[0] = qstr.Left(line, temppos);
                                tagsplit[1] = qstr.Right(line, line.Length - temppos - 1);
                                D(GINI.UnIniString(GINI.UnIniString(tagsplit[0])), GINI.UnIniString(tagsplit[1]));
                            }     //EndIf
                            break;

                        case "LIST":
                            //g.lists[lst] = append(g.lists[lst], UnIniString(line)) //ListAddLast lst,uninistring(line)
                            lst.Add(GINI.UnIniString(line).Trim());
                            break;

                        case "CALL":
                            Console.WriteLine($"WARNING! I cannot execute line {linenumber} as the [CALL] block is not supported in C#\n");
                            break;

                        default:
                            throw new Exception($"ERROR! Unknown tag: {tag} (line #{linenumber}:{line})\n");
                        } //End Select
                    }     //EndIf
                }         //EndIf
            }             // Next
        }                 //End Function