/// <summary>Adds a species ID name to the project.</summary> private InpErrorCodes AddSpecies(string[] tok) { if (tok.Length < 2) { return(InpErrorCodes.ERR_ITEMS); } InpErrorCodes errcode = CheckId(tok[1]); if (errcode != 0) { return(errcode); } if (_project.MSXproj_addObject( ObjectTypes.SPECIES, tok[1], _msx.Nobjects[(int)ObjectTypes.SPECIES] + 1) < 0) { errcode = (InpErrorCodes)101; } else { _msx.Nobjects[(int)ObjectTypes.SPECIES]++; } return(errcode); }
private static void WriteInpErrMsg(InpErrorCodes errcode, string sect, string line, int lineCount) { if (errcode >= InpErrorCodes.INP_ERR_LAST || errcode <= InpErrorCodes.INP_ERR_FIRST) { Console.Error.WriteLine("Error Code = {0}", (int)errcode); } else { Console.Error.WriteLine( "{0} at line {1} of {2}] section:", inpErrorTxt[errcode - InpErrorCodes.INP_ERR_FIRST], lineCount, sect); } }
/// <summary>Adds an intermediate expression term ID name to the project.</summary> private InpErrorCodes AddTerm(string[] id) { InpErrorCodes errcode = CheckId(id[0]); if (errcode == 0) { if (_project.MSXproj_addObject( ObjectTypes.TERM, id[0], _msx.Nobjects[(int)ObjectTypes.TERM] + 1) < 0) { errcode = (InpErrorCodes)101; } else { _msx.Nobjects[(int)ObjectTypes.TERM]++; } } return(errcode); }
/// <summary>Adds a coefficient ID name to the project.</summary> private InpErrorCodes AddCoeff(string[] tok) { ObjectTypes k; // determine the type of coeff. if (tok.Length < 2) { return(InpErrorCodes.ERR_ITEMS); } if (Utilities.MSXutils_match(tok[0], "PARAM")) { k = ObjectTypes.PARAMETER; } else if (Utilities.MSXutils_match(tok[0], "CONST")) { k = ObjectTypes.CONSTANT; } else { return(InpErrorCodes.ERR_KEYWORD); } // check for valid id name InpErrorCodes errcode = CheckId(tok[1]); if (errcode != 0) { return(errcode); } if (_project.MSXproj_addObject(k, tok[1], _msx.Nobjects[(int)k] + 1) < 0) { errcode = (InpErrorCodes)101; } else { _msx.Nobjects[(int)k]++; } return(errcode); }
/// <summary>Adds a time pattern ID name to the project.</summary> private InpErrorCodes AddPattern(string[] tok) { InpErrorCodes errcode = 0; // A time pattern can span several lines if (_project.MSXproj_findObject(ObjectTypes.PATTERN, tok[0]) <= 0) { if (_project.MSXproj_addObject( ObjectTypes.PATTERN, tok[0], _msx.Nobjects[(int)ObjectTypes.PATTERN] + 1) < 0) { errcode = (InpErrorCodes)101; } else { _msx.Nobjects[(int)ObjectTypes.PATTERN]++; } } return(errcode); }
/// <summary>Reads multi-species input file to determine number of system objects.</summary> public ErrorCodeType CountMsxObjects(TextReader reader) { SectionType sect = (SectionType)(-1); // input data sections InpErrorCodes errcode = 0; // error code int errsum = 0; // number of errors found long lineCount = 0; //BufferedReader reader = (BufferedReader)MSX.MsxFile.getFileIO(); for (;;) { string line; // line from input data file try { line = reader.ReadLine(); } catch (IOException) { break; } if (line == null) { break; } errcode = 0; line = line.Trim(); lineCount++; int comentPosition = line.IndexOf(';'); if (comentPosition != -1) { line = line.Substring(0, comentPosition); } if (string.IsNullOrEmpty(line)) { continue; } string[] tok = line.Split((char[])null, StringSplitOptions.RemoveEmptyEntries); if (tok.Length == 0 || !string.IsNullOrEmpty(tok[0]) && tok[0][0] == ';') { continue; } SectionType sectTemp; if (GetNewSection(tok[0], Constants.MsxSectWords, out sectTemp) != 0) { sect = sectTemp; continue; } if (sect == SectionType.s_SPECIES) { errcode = AddSpecies(tok); } if (sect == SectionType.s_COEFF) { errcode = AddCoeff(tok); } if (sect == SectionType.s_TERM) { errcode = AddTerm(tok); } if (sect == SectionType.s_PATTERN) { errcode = AddPattern(tok); } if (errcode != 0) { WriteInpErrMsg(errcode, Constants.MsxSectWords[(int)sect], line, (int)lineCount); errsum++; if (errsum >= MAXERRS) { break; } } } //return error code if (errsum > 0) { return(ErrorCodeType.ERR_MSX_INPUT); } return((ErrorCodeType)errcode); }