Esempio n. 1
0
        void EncodeKeymap(Keymap map, BinaryWriter w)
        {
            int max = 0;

            foreach (KeyValuePair <int, int> kvp in map.Entries)
            {
                if (kvp.Key > max)
                {
                    max = kvp.Key;
                }
            }

            w.Write(max);

            for (int scancode = 0; scancode < max; ++scancode)
            {
                if (map.Entries.ContainsKey(scancode))
                {
                    w.Write((char)map.Entries [scancode]);
                }
                else
                {
                    w.Write((char)0);
                }
            }
        }
Esempio n. 2
0
 public void Decode(out int keymask, out int statebit, out Keymap defaultMap,
                    out Keymap shiftedMap, Stream input)
 {
     using (BinaryReader br = new BinaryReader(input)) {
         keymask    = br.ReadChar();
         statebit   = br.ReadChar();
         defaultMap = DecodeKeymap(br);
         shiftedMap = DecodeKeymap(br);
     }
 }
Esempio n. 3
0
 public void Encode(int keymask, int statebit, Keymap defaultMap,
                    Keymap shiftedMap, Stream output)
 {
     using (BinaryWriter bw = new BinaryWriter(output)) {
         bw.Write((char)keymask);
         bw.Write((char)statebit);
         EncodeKeymap(defaultMap, bw);
         EncodeKeymap(shiftedMap, bw);
     }
 }
Esempio n. 4
0
        Keymap DecodeKeymap(BinaryReader r)
        {
            Keymap map   = new Keymap();
            int    count = r.ReadInt32();

            for (int scancode = 0; scancode < count; ++scancode)
            {
                map.Entries [scancode] = r.ReadChar();
            }

            return(map);
        }
Esempio n. 5
0
        public bool ParseStatement(Tokenizer t)
        {
            bool  err   = false;
            Token token = t.Read();

            if (token == null)
            {
                return(false);
            }

            if (token.Type == TokenType.Alphanumeric)
            {
                switch (token.Text)
                {
                case "keymask":
                    keymask = ReadEqInt(t);
                    break;

                case "statebit":
                    statebit = ReadEqInt(t);
                    break;

                case "default":
                    Console.WriteLine("Parsing `default' keymap...");
                    defaultMap = ReadMap(t);
                    break;

                case "shifted":
                    Console.WriteLine("Parsing `shifted' keymap...");
                    shiftedMap = ReadMap(t);
                    break;

                default:
                    err = true;
                    break;
                }
            }
            else
            {
                err = true;
            }

            if (err)
            {
                throw new UnexpectedTokenException(token, "<unknown>");
            }

            return(true);
        }
Esempio n. 6
0
        Keymap DecodeKeymap(BinaryReader r)
        {
            Keymap map      = new Keymap();
            int    count    = r.ReadInt32();
            int    specConv = (int)SpecialKeys.Control - 129;

            for (int scancode = 0; scancode < count; ++scancode)
            {
                byte value = r.ReadByte();

                if (value > 128)
                {
                    map.Entries [scancode] = (int)value + specConv;
                }
                else
                {
                    map.Entries [scancode] = value;
                }
            }

            return(map);
        }
Esempio n. 7
0
        void EncodeKeymap(Keymap map, BinaryWriter w)
        {
            int max = 0;

            foreach (KeyValuePair <int, int> kvp in map.Entries)
            {
                if (kvp.Key > max)
                {
                    max = kvp.Key;
                }
            }

            w.Write(max);

            for (int scancode = 0; scancode < max; ++scancode)
            {
                int value    = map.Entries [scancode];
                int specConv = 129 - (int)SpecialKeys.Control;

                if (!map.Entries.ContainsKey(scancode))
                {
                    w.Write((byte)0);
                    continue;
                    ;
                }

                if (value > 0xFFFF)
                {
                    value = value + specConv;
                }

                if (value > 255)
                {
                    Console.Error.WriteLine("Warning: key `{0}' is too large", value);
                }

                w.Write((byte)value);
            }
        }
Esempio n. 8
0
        public Keymap ReadMap(Tokenizer t)
        {
            Keymap map = new Keymap();
            Token  tok;

            ReadSectionOpen(t);

            do
            {
                int scancode, key;

                tok = t.Read();

                if (tok == null)
                {
                    throw new UnexpectedEndOfFileException(t, "}");
                }

                if (tok.Text == "}")
                {
                    break;
                }
                else
                {
                    t.PutBack(tok);
                }

                scancode = ReadInt(t);

                key = ReadEqChar(t);
                ReadEnd(t);

                map.Entries [scancode] = key;
            } while (true);

            return(map);
        }
Esempio n. 9
0
		public Keymap ReadMap (Tokenizer t)
		{
			Keymap map = new Keymap ();
			Token tok;

			ReadSectionOpen (t);

			do {
				int scancode, key;

				tok = t.Read ();

				if (tok == null)
					throw new UnexpectedEndOfFileException (t, "}");

				if (tok.Text == "}")
					break;
				else
					t.PutBack (tok);

				scancode = ReadInt (t);

				key = ReadEqChar (t);
				ReadEnd (t);

				map.Entries [scancode] = key;
			} while (true);

			return map;
		}
Esempio n. 10
0
		public bool ParseStatement (Tokenizer t)
		{
			bool err = false;
			Token token = t.Read ();

			if (token == null)
				return false;

			if (token.Type == TokenType.Alphanumeric) {
				switch (token.Text) {
				case "keymask":
					keymask = ReadEqInt (t);
					break;
				case "statebit":
					statebit = ReadEqInt (t);
					break;
				case "default":
					Console.WriteLine ("Parsing `default' keymap...");
					defaultMap = ReadMap (t);
					break;
				case "shifted":
					Console.WriteLine ("Parsing `shifted' keymap...");
					shiftedMap = ReadMap (t);
					break;
				default:
					err = true;
					break;
				}
			} else
				err = true;

			if (err)
				throw new UnexpectedTokenException (token, "<unknown>");

			return true;
		}
Esempio n. 11
0
		public void Decode (out int keymask, out int statebit, out Keymap defaultMap,
				    out Keymap shiftedMap, Stream input)
		{
			using (BinaryReader br = new BinaryReader (input)) {
				keymask = br.ReadChar ();
				statebit = br.ReadChar ();
				defaultMap = DecodeKeymap (br);
				shiftedMap = DecodeKeymap (br);
			}
		}
Esempio n. 12
0
		public void Encode (int keymask, int statebit, Keymap defaultMap,
				    Keymap shiftedMap, Stream output)
		{
			using (BinaryWriter bw = new BinaryWriter (output)) {
				bw.Write ((char) keymask);
				bw.Write ((char) statebit);
				EncodeKeymap (defaultMap, bw);
				EncodeKeymap (shiftedMap, bw);
			}
		}
Esempio n. 13
0
		Keymap DecodeKeymap (BinaryReader r)
		{
			Keymap map = new Keymap ();
			int count = r.ReadInt32 ();

			for (int scancode = 0; scancode < count; ++scancode) {
				map.Entries [scancode] = r.ReadChar ();
			}

			return map;
		}
Esempio n. 14
0
		void EncodeKeymap (Keymap map, BinaryWriter w)
		{
			int max = 0;

			foreach (KeyValuePair<int, int> kvp in map.Entries) {
				if (kvp.Key > max)
					max = kvp.Key;
			}

			w.Write (max);

			for (int scancode = 0; scancode < max; ++scancode) {
				if (map.Entries.ContainsKey (scancode))
					w.Write ((char) map.Entries [scancode]);
				else
					w.Write ((char) 0);
			}
		}
Esempio n. 15
0
		Keymap DecodeKeymap (BinaryReader r)
		{
			Keymap map = new Keymap ();
			int count = r.ReadInt32 ();
			int specConv = (int) SpecialKeys.Control - 129;

			for (int scancode = 0; scancode < count; ++scancode) {
				byte value = r.ReadByte ();

				if (value > 128)
					map.Entries [scancode] = (int) value + specConv;
				else
					map.Entries [scancode] = value;
			}

			return map;
		}
Esempio n. 16
0
		void EncodeKeymap (Keymap map, BinaryWriter w)
		{
			int max = 0;

			foreach (KeyValuePair<int, int> kvp in map.Entries) {
				if (kvp.Key > max)
					max = kvp.Key;
			}

			w.Write (max);

			for (int scancode = 0; scancode < max; ++scancode) {
				int value = map.Entries [scancode];
				int specConv = 129 - (int) SpecialKeys.Control;

				if (!map.Entries.ContainsKey (scancode)) {
					w.Write ((byte) 0);
					continue;
					;
				}

				if (value > 0xFFFF)
					value = value + specConv;

				if (value > 255)
					Console.Error.WriteLine ("Warning: key `{0}' is too large", value);

				w.Write ((byte) value);
			}
		}