System.TermInfo.Database.Database C# (CSharp) Method

Database() private method

Initializes the database instance.
private Database ( string term, byte data ) : System.Collections.Generic
term string The name of the terminal.
data byte The data from the terminfo file.
return System.Collections.Generic
            private Database(string term, byte[] data)
            {
                _term = term;
                _data = data;

                // See "man term" for the file format.
                if (ReadInt16(data, 0) != 0x11A) // magic number octal 0432
                {
                    throw new InvalidOperationException(SR.IO_TermInfoInvalid);
                }

                _nameSectionNumBytes = ReadInt16(data, 2);
                _boolSectionNumBytes = ReadInt16(data, 4);
                _numberSectionNumShorts = ReadInt16(data, 6);
                _stringSectionNumOffsets = ReadInt16(data, 8);
                _stringTableNumBytes = ReadInt16(data, 10);
                if (_nameSectionNumBytes < 0 ||
                    _boolSectionNumBytes < 0 ||
                    _numberSectionNumShorts < 0 ||
                    _stringSectionNumOffsets < 0 ||
                    _stringTableNumBytes < 0)
                {
                    throw new InvalidOperationException(SR.IO_TermInfoInvalid);
                }

                // In addition to the main section of bools, numbers, and strings, there is also
                // an "extended" section.  This section contains additional entries that don't
                // have well-known indices, and are instead named mappings.  As such, we parse
                // all of this data now rather than on each request, as the mapping is fairly complicated.
                // This function relies on the data stored above, so it's the last thing we run.
                // (Note that the extended section also includes other Booleans and numbers, but we don't
                // have any need for those now, so we don't parse them.)
                int extendedBeginning = RoundUpToEven(StringsTableOffset + _stringTableNumBytes);
                _extendedStrings = ParseExtendedStrings(data, extendedBeginning) ?? new Dictionary<string, string>();
            }