Beispiel #1
0
        /// <summary>
        /// Generates a human-readable summary of this system definition for display to
        /// the user.
        /// </summary>
        /// <returns>Multi-line string</returns>
        public string GetSummaryString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Description);
            sb.Append("\r\n\r\n");

            sb.AppendFormat(Res.Strings.SETUP_SYSTEM_SUMMARY_FMT, Name, Cpu, Speed);

            if (SymbolFiles.Length > 0)
            {
                sb.Append("\r\n\r\n");
                sb.Append(Res.Strings.INITIAL_SYMBOL_FILES);
                foreach (string str in SymbolFiles)
                {
                    sb.Append("\r\n  ");
                    ExternalFile ef = ExternalFile.CreateFromIdent(str);
                    if (ef == null)
                    {
                        // Shouldn't happen unless somebody botches an edit.
                        sb.Append("[INVALID] " + str);
                    }
                    else
                    {
                        sb.Append(ef.GetInnards());
                    }
                }
            }

            if (ExtensionScripts.Length > 0)
            {
                sb.Append("\r\n\r\n");
                sb.Append(Res.Strings.INITIAL_EXTENSION_SCRIPTS);
                foreach (string str in ExtensionScripts)
                {
                    sb.Append("\r\n  ");
                    ExternalFile ef = ExternalFile.CreateFromIdent(str);
                    if (ef == null)
                    {
                        // Shouldn't happen unless somebody botches an edit.
                        sb.Append("[INVALID] " + str);
                    }
                    else
                    {
                        sb.Append(ef.GetInnards());
                    }
                }
            }

            if (Parameters.Count > 0)
            {
                sb.Append("\r\n\r\n");
                sb.Append(Res.Strings.INITIAL_PARAMETERS);
                foreach (KeyValuePair <string, string> kvp in Parameters)
                {
                    sb.Append("\r\n  ");
                    sb.Append(kvp.Key);
                    sb.Append(" = ");
                    sb.Append(kvp.Value);
                }
            }

            return(sb.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Loads platform symbols.
        /// </summary>
        /// <param name="fileIdent">Relative pathname of file to open.</param>
        /// <param name="projectDir">Full path to project directory.</param>
        /// <param name="report">Report of warnings and errors.</param>
        /// <returns>True on success (no errors), false on failure.</returns>
        public bool LoadFromFile(string fileIdent, string projectDir, out FileLoadReport report)
        {
            // These files shouldn't be enormous.  Do it the easy way.
            report = new FileLoadReport(fileIdent);

            ExternalFile ef = ExternalFile.CreateFromIdent(fileIdent);

            if (ef == null)
            {
                report.Add(FileLoadItem.Type.Error,
                           CommonUtil.Properties.Resources.ERR_FILE_NOT_FOUND + ": " + fileIdent);
                return(false);
            }

            string pathName = ef.GetPathName(projectDir);

            if (pathName == null)
            {
                report.Add(FileLoadItem.Type.Error,
                           Res.Strings.ERR_BAD_IDENT + ": " + fileIdent);
                return(false);
            }
            string[] lines;
            try {
                lines = File.ReadAllLines(pathName);
            } catch (IOException ioe) {
                Debug.WriteLine("Platform symbol load failed: " + ioe);
                report.Add(FileLoadItem.Type.Error,
                           CommonUtil.Properties.Resources.ERR_FILE_NOT_FOUND + ": " + pathName);
                return(false);
            }

            string tag = string.Empty;

            int lineNum = 0;

            foreach (string line in lines)
            {
                lineNum++;      // first line is line 1, says Vim and VisualStudio
                if (string.IsNullOrEmpty(line) || line[0] == ';')
                {
                    // ignore
                }
                else if (line[0] == '*')
                {
                    if (line.StartsWith(TAG_CMD))
                    {
                        tag = ParseTag(line);
                    }
                    else
                    {
                        // Do something clever with *SYNOPSIS?
                        Debug.WriteLine("CMD: " + line);
                    }
                }
                else
                {
                    MatchCollection matches = sNameValueRegex.Matches(line);
                    if (matches.Count == 1)
                    {
                        //Debug.WriteLine("GOT '" + matches[0].Groups[1] + "' " +
                        //    matches[0].Groups[2] + " '" + matches[0].Groups[3] + "'");
                        string label   = matches[0].Groups[1].Value;
                        bool   isConst = (matches[0].Groups[2].Value[0] == '=');
                        string badParseMsg;
                        int    value, numBase;
                        bool   parseOk;
                        if (isConst)
                        {
                            // Allow various numeric options, and preserve the value.
                            parseOk = Asm65.Number.TryParseInt(matches[0].Groups[3].Value,
                                                               out value, out numBase);
                            badParseMsg =
                                CommonUtil.Properties.Resources.ERR_INVALID_NUMERIC_CONSTANT;
                        }
                        else
                        {
                            // Allow things like "05/1000".  Always hex.
                            numBase = 16;
                            parseOk = Asm65.Address.ParseAddress(matches[0].Groups[3].Value,
                                                                 (1 << 24) - 1, out value);
                            badParseMsg = CommonUtil.Properties.Resources.ERR_INVALID_ADDRESS;
                        }
                        if (!parseOk)
                        {
                            report.Add(lineNum, FileLoadItem.NO_COLUMN, FileLoadItem.Type.Warning,
                                       badParseMsg);
                        }
                        else
                        {
                            string comment = matches[0].Groups[4].Value;
                            if (comment.Length > 0)
                            {
                                // remove ';'
                                comment = comment.Substring(1);
                            }
                            FormatDescriptor.SubType subType =
                                FormatDescriptor.GetSubTypeForBase(numBase);
                            DefSymbol symDef = new DefSymbol(label, value, Symbol.Source.Platform,
                                                             isConst ? Symbol.Type.Constant : Symbol.Type.ExternalAddr,
                                                             subType, comment, tag);
                            if (mSymbols.ContainsKey(label))
                            {
                                // This is very easy to do -- just define the same symbol twice
                                // in the same file.  We don't really need to do anything about
                                // it though.
                                Debug.WriteLine("NOTE: stomping previous definition of " + label);
                            }
                            mSymbols[label] = symDef;
                        }
                    }
                    else
                    {
                        report.Add(lineNum, FileLoadItem.NO_COLUMN, FileLoadItem.Type.Warning,
                                   CommonUtil.Properties.Resources.ERR_SYNTAX);
                    }
                }
            }

            return(!report.HasErrors);
        }