DEADSOFTWARE

replaced some var args to constref args
[d2df-sdl.git] / src / shared / conbuf.pas
index 751f39ad06596afbfec3df125271b2c30ca19f8f..4bb1bea0af8b0e8620f580785347a117bdb0c037 100644 (file)
@@ -1,4 +1,20 @@
-{$MODE OBJFPC}
+(* Copyright (C)  DooM 2D:Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE a_modes.inc}
+{.$MODE OBJFPC}
 unit conbuf;
 
 interface
@@ -11,10 +27,10 @@ function cbufLastChange (): LongWord;
 
 function cbufWalkStart (): LongWord;
 function cbufWalkEnd (pos: LongWord): LongWord;
-procedure cbufPrev (var pos: LongWord);
-procedure cbufNext (var pos: LongWord);
+procedure cbufPrev (var pos: LongWord); inline;
+procedure cbufNext (var pos: LongWord); inline;
 
-function cbufAt (const pos: LongWord): Char;
+function cbufAt (const pos: LongWord): Char; inline;
 
 // get last line
 procedure cbufLastLine (var sp: LongWord; var ep: LongWord);
@@ -23,6 +39,9 @@ function cbufLineUp (var sp: LongWord; var ep: LongWord): Boolean;
 
 procedure cbufClear ();
 
+var
+  conbufDumpToStdOut: Boolean = false;
+
 
 implementation
 
@@ -45,6 +64,9 @@ function cbufLastChange (): LongWord; begin result := changeCount; end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
+var
+  needCon: Boolean = true;
+
 procedure cbufPutChars (buf: PChar; count: Integer);
 var
   np: LongWord;
@@ -52,6 +74,15 @@ var
 begin
   if count > 0 then
   begin
+    if conbufDumpToStdOut then
+    begin
+      for np := 0 to count-1 do
+      begin
+        if needCon then begin write(stdout, 'CON: '); needCon := false; end;
+        write(stdout, buf[np]);
+        needCon := (buf[np] = #10);
+      end;
+    end;
     Inc(changeCount);
     if changeCount = 0 then changeCount := 1;
     while count > 0 do
@@ -87,10 +118,10 @@ end;
 // warning! don't modify conbuf while the range is active!
 function cbufWalkStart (): LongWord; begin result := cbuftail; end;
 function cbufWalkEnd (pos: LongWord): LongWord; begin result := cbufhead; end;
-procedure cbufPrev (var pos: LongWord); begin pos := (pos+ConBufSize-1) mod ConBufSize; end;
-procedure cbufNext (var pos: LongWord); begin pos := (pos+1) mod ConBufSize; end;
+procedure cbufPrev (var pos: LongWord); inline; begin pos := (pos+ConBufSize-1) mod ConBufSize; end;
+procedure cbufNext (var pos: LongWord); inline; begin pos := (pos+1) mod ConBufSize; end;
 
-function cbufAt (const pos: LongWord): Char; begin result := cbuf[pos mod ConBufSize]; end;
+function cbufAt (const pos: LongWord): Char; inline; begin result := cbuf[pos mod ConBufSize]; end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //