Пример #1
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         Define d = (Define)listBox1.Items[listBox1.SelectedIndex];
         label1.Text = d.name;
         label2.Text = "Defined in: " + d.location + " : " + d.line;
         label3.Text = "Value: " + d.value;
         label4.Text = "References: " + d.references.Count();
         listBox2.Items.Clear();
         foreach (String s in d.references)
         {
             listBox2.Items.Add(s);
         }
     }
     catch (Exception ex) { Console.WriteLine("ERROR HERE: " + ex.Message); }
 }
Пример #2
0
        //DEFINES
        public void searchFileForDefines(String fileName)
        {
            filessearched++;
            FileInfo      f     = new FileInfo(fileName);
            List <String> lines = new List <String>();
            List <String> lines_without_comments = new List <String>();

            mainform.label5.Text = "Files searched: " + filessearched + "; Defines found: " + defines.Count() + "; References found: " + totalreferences + "; Errorous defines: " + errordefines;
            mainform.label5.Refresh();

            //This code segment reads the file and stores it into the lines variable.
            using (var reader = File.OpenText(fileName))
            {
                try
                {
                    String s;
                    while (true)
                    {
                        s = reader.ReadLine();
                        lines.Add(s);
                        s = s.Trim(' ');
                        if (s == "")
                        {
                            continue;
                        }
                    }
                }
                catch { }
                reader.Close();
            }

            mainform.listBox1.Items.Add("ATTEMPTING: " + fileName);
            lines_without_comments = remove_comments(lines);

            /*TextWriter tw = new StreamWriter(fileName);
             * foreach (String s in lines_without_comments)
             * {
             *  tw.WriteLine(s);
             * }
             * tw.Close();
             * mainform.listBox1.Items.Add("REWRITE: "+fileName);*/

            try
            {
                for (int i = 0; i < lines_without_comments.Count; i++)
                {
                    String line = lines_without_comments[i];

                    if (!(line is string))
                    {
                        continue;
                    }

                    //Console.WriteLine("LINE: " + line);

                    foreach (Define define in defines)
                    {
                        if (line.IndexOf(define.name) >= 0)
                        {
                            define.references.Add(fileName + " : " + i);
                            totalreferences++;
                        }
                    }

                    if (line.ToLower().IndexOf("#define") >= 0)
                    {
                        line = line.Trim();
                        line = line.Replace('\t', ' ');
                        //Console.WriteLine("LINE = "+line);
                        String[] slist = line.Split(' ');
                        if (slist.Length >= 3)
                        {
                            //slist[0] has the value of "#define"
                            String name  = slist[1];
                            String value = slist[2];

                            for (int j = 3; j < slist.Length; j++)
                            {
                                value += " " + slist[j];
                                //Console.WriteLine("LISTITEM["+j+"] = "+slist[j]);
                            }

                            value = value.Trim();

                            String comment = "";

                            if (value.IndexOf("//") >= 0)
                            {
                                comment = value.Substring(value.IndexOf("//"));
                                value   = value.Substring(0, value.IndexOf("//"));
                            }

                            comment = comment.Trim();
                            value   = value.Trim();

                            Define d = new Define(fileName, i, name, value, comment);
                            defines.Add(d);
                            mainform.listBox1.Items.Add(d);
                            mainform.listBox1.Refresh();
                        }
                        else
                        {
                            Define d = new Define(fileName, i, "ERROR ERROR", "Something went wrong here", line);
                            errordefines++;
                            defines.Add(d);
                            mainform.listBox1.Items.Add(d);
                            mainform.listBox1.Refresh();
                        }
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                MessageBox.Show("Exception: " + e.Message + " | " + e.ToString());
            }
        }
Пример #3
0
        //DEFINES
        public void searchFileForDefines(String fileName)
        {
            filessearched++;
            FileInfo f = new FileInfo(fileName);
            List<String> lines = new List<String>();
            List<String> lines_without_comments = new List<String>();

            mainform.label5.Text = "Files searched: " + filessearched + "; Defines found: " + defines.Count() + "; References found: " + totalreferences + "; Errorous defines: " + errordefines;
            mainform.label5.Refresh();

            //This code segment reads the file and stores it into the lines variable.
            using (var reader = File.OpenText(fileName))
            {
                try
                {
                    String s;
                    while (true)
                    {
                        s = reader.ReadLine();
                        lines.Add(s);
                        s = s.Trim(' ');
                        if (s == "") { continue; }
                    }
                }
                catch { }
                reader.Close();
            }

            mainform.listBox1.Items.Add("ATTEMPTING: " + fileName);
            lines_without_comments = remove_comments(lines);

            /*TextWriter tw = new StreamWriter(fileName);
            foreach (String s in lines_without_comments)
            {
                tw.WriteLine(s);
            }
            tw.Close();
            mainform.listBox1.Items.Add("REWRITE: "+fileName);*/

            try
            {
                for (int i = 0; i < lines_without_comments.Count; i++)
                {
                    String line = lines_without_comments[i];

                    if (!(line is string))
                        continue;

                    //Console.WriteLine("LINE: " + line);

                    foreach (Define define in defines)
                    {

                        if (line.IndexOf(define.name) >= 0)
                        {
                            define.references.Add(fileName + " : " + i);
                            totalreferences++;
                        }
                    }

                    if( line.ToLower().IndexOf("#define") >= 0 )
                    {
                        line = line.Trim();
                        line = line.Replace('\t', ' ');
                        //Console.WriteLine("LINE = "+line);
                        String[] slist = line.Split(' ');
                        if(slist.Length >= 3){
                            //slist[0] has the value of "#define"
                            String name = slist[1];
                            String value = slist[2];

                            for (int j = 3; j < slist.Length; j++)
                            {
                                value += " " + slist[j];
                                //Console.WriteLine("LISTITEM["+j+"] = "+slist[j]);
                            }

                            value = value.Trim();

                            String comment = "";

                            if (value.IndexOf("//") >= 0)
                            {
                                comment = value.Substring(value.IndexOf("//"));
                                value = value.Substring(0, value.IndexOf("//"));
                            }

                            comment = comment.Trim();
                            value = value.Trim();
                        
                            Define d = new Define(fileName,i,name,value,comment);
                            defines.Add(d);
                            mainform.listBox1.Items.Add(d);
                            mainform.listBox1.Refresh();
                        }else{
                            Define d = new Define(fileName, i, "ERROR ERROR", "Something went wrong here", line);
                            errordefines++;
                            defines.Add(d);
                            mainform.listBox1.Items.Add(d);
                            mainform.listBox1.Refresh();
                        }
                    }
                }
            }
            catch (Exception e) { 
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                MessageBox.Show("Exception: " + e.Message + " | " + e.ToString());
            }
        }