namespace Gettext { using System; using System.IO; class GettextBinaryReader { private bool clear = false; private uint magic = 0; /* switch this to bool as well, to increase speed */ private Stream stream; /* stream we're working with: must support seeking and reading (no way?) */ private uint revision; /* MO file revision, we don't really pay any attention to this [FIXME] */ private uint total; /* total number of strings */ private uint orig; /* offset of table of original strings */ private uint trans; /* offset of table of translations */ private string plurals; /* plural forms definition */ /* Lets read a 4-byte unsigned integer from current position -- not very thread friendly way, we'd need an offset and locking for that */ private uint readint() { byte[] data = new byte[4]; if (this.clear) { uint tmp; int count = this.stream.Read(data, 0, 4); if (count == 0) throw new Exception(); /* EOF, data could not be read, or whatever */ if (this.magic == 0x950412de) { return (uint) (data[0] + (data[1]<<8) + (data[2]<<16) + (data[3]<<24)); } else { /* lets assume that this is so, since clear is ok -- (this.magic == 0xde120495) */ return (uint) (data[3] + (data[2]<<8) + (data[1]<<16) + (data[0]<<24)); } } else { throw new Exception(); /* not a valid MO file */ } } /* Takes a first translation, and extracts value from it. It is in the form of one assignment per line, with identifier separated by semicolon from value. SOMEWHAT INEFFICIENT, but seldom used, so no big deal! */ private string GetHeaderField (string field) { int position, length; if (field.Trim() == "") return String.Empty; if (this.clear) { string header = this.gettext(""); char[] delim = { '\n' }; string[] fields = header.Split(delim); for (int i=0; i