public static void Write(sizebuf_t buf, byte[] data) { var length = data.Length; //memcpy(SZ_GetSpace(buf, length), data, length); Array.Copy(data, 0, buf.data, SZ.GetSpace(buf, length), length); }
// public static void Print(sizebuf_t buf, string data) { Com.dprintln("SZ.print():<" + data + ">"); var length = data.Length; var str = Lib.stringToBytes(data); if (buf.cursize != 0) { if (buf.data[buf.cursize - 1] != 0) { //memcpy( SZ_GetSpace(buf, len), data, len); // no trailing 0 Array.Copy(str, 0, buf.data, SZ.GetSpace(buf, length + 1), length); } else { Array.Copy(str, 0, buf.data, SZ.GetSpace(buf, length) - 1, length); //memcpy(SZ_GetSpace(buf, len - 1) - 1, data, len); // write over trailing 0 } } else { // first print. Array.Copy(str, 0, buf.data, SZ.GetSpace(buf, length), length); } //memcpy(SZ_GetSpace(buf, len), data, len); buf.data[buf.cursize - 1] = 0; }
/** Ask for the pointer using sizebuf_t.cursize (RST) */ public static int GetSpace(sizebuf_t buf, int length) { int oldsize; if (buf.cursize + length > buf.maxsize) { if (!buf.allowoverflow) { Com.Error(Defines.ERR_FATAL, "SZ_GetSpace: overflow without allowoverflow set"); } if (length > buf.maxsize) { Com.Error(Defines.ERR_FATAL, "SZ_GetSpace: " + length + " is > full buffer size"); } Com.Printf("SZ_GetSpace: overflow\n"); SZ.Clear(buf); buf.overflowed = true; } oldsize = buf.cursize; buf.cursize += length; return(oldsize); }
public static void WriteShort(sizebuf_t sb, int c) { var i = SZ.GetSpace(sb, 2); sb.data[i++] = (byte)(c & 0xff); sb.data[i] = (byte)(((uint)c >> 8) & 0xFF); }
//ok. public static void WriteInt(sizebuf_t sb, int c) { var i = SZ.GetSpace(sb, 4); sb.data[i++] = (byte)(c & 0xff); sb.data[i++] = (byte)(((uint)c >> 8) & 0xff); sb.data[i++] = (byte)(((uint)c >> 16) & 0xff); sb.data[i++] = (byte)(((uint)c >> 24) & 0xff); }
/** * @param text */ public static void AddText(string text) { var l = text.Length; if (Globals.cmd_text.cursize + l >= Globals.cmd_text.maxsize) { Com.Printf("Cbuf_AddText: overflow\n"); return; } SZ.Write(Globals.cmd_text, Lib.stringToBytes(text), l); }
// had a bug, now its ok. public static void WriteString(sizebuf_t sb, string s) { var x = s; if (s == null) { x = ""; } SZ.Write(sb, Lib.stringToBytes(x)); MSG.WriteByte(sb, 0); //Com.dprintln("MSG.WriteString:" + s.replace('\0', '@')); }
public static void InsertText(string text) { var templen = 0; // copy off any commands still remaining in the exec buffer templen = Globals.cmd_text.cursize; if (templen != 0) { Array.Copy(Globals.cmd_text.data, 0, Cbuf.tmp, 0, templen); SZ.Clear(Globals.cmd_text); } // add the entire text of the file Cbuf.AddText(text); // add the copied off data if (templen != 0) { SZ.Write(Globals.cmd_text, Cbuf.tmp, templen); } }
public static void Write(sizebuf_t buf, byte[] data, int offset, int length) { Array.Copy(data, offset, buf.data, SZ.GetSpace(buf, length), length); }
//ok. public static void WriteByte(sizebuf_t sb, int c) { sb.data[SZ.GetSpace(sb, 1)] = (byte)(c & 0xFF); }
/** * */ public static void Init() { SZ.Init(Globals.cmd_text, Globals.cmd_text_buf, Globals.cmd_text_buf.Length); }