/* $Id: Win32TerminalStream,v 1.4 2008/11/30 17:03:57 kiesling Exp $ -*-c-*-*/

/*
  This file is part of ctalk.
  Copyright  2005 - 2008  Robert Kiesling, ctalk@ctalklang.org.
  Permission is granted to copy this software provided that this copyright
  notice is included in all source code modules.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

/*
 *    Win32TerminalStream class.
 *
 *    Console I/O (with DJGPP conio.h) only, and likely to stay 
 *    that way for some time, until we figure out a way to 
 *    implement a genuine fork () call for DJGPP.  Suggestions
 *    by e-mail welcomed.
 */

TerminalStream class Win32TerminalStream;

#ifdef DJGPP
#include <conio.h>
extern unsigned char ScreenAttrib;
#else
#warning Win32TerminalStream class requires DJGPP.
#endif

Win32TerminalStream instanceMethod clear (void) {
  clrscr ();
  methodReturnNULL;
}

Win32TerminalStream instanceMethod screenColor (char *__fgStr, 
						    char *__bgStr) {
  enum COLORS fgval, bgval;

  if (__fgStr == "black") { fgval = BLACK; }
  if (__fgStr == "blue") { fgval = BLUE; }
  if (__fgStr == "green") { fgval = GREEN; }
  if (__fgStr == "cyan") { fgval = CYAN; }
  if (__fgStr == "red") { fgval = RED; }
  if (__fgStr == "magenta") { fgval = MAGENTA; }
  if (__fgStr == "brown") { fgval = BROWN; }
  if (__fgStr == "lightgray") { fgval = LIGHTGRAY; }
  if (__fgStr == "darkgray") { fgval = DARKGRAY; }
  if (__fgStr == "lightblue") { fgval = LIGHTBLUE; }
  if (__fgStr == "lightgreen") { fgval = LIGHTGREEN; }
  if (__fgStr == "lightcyan") { fgval = LIGHTCYAN; }
  if (__fgStr == "lightred") { fgval = LIGHTRED; }
  if (__fgStr == "lightmagenta") { fgval = LIGHTMAGENTA; }
  if (__fgStr == "yellow") { fgval = YELLOW; }
  if (__fgStr == "white") { fgval = WHITE; }

  if (__bgStr == "black") { bgval = BLACK; }
  if (__bgStr == "blue") { bgval = BLUE; }
  if (__bgStr == "green") { bgval = GREEN; }
  if (__bgStr == "cyan") { bgval = CYAN; }
  if (__bgStr == "red") { bgval = RED; }
  if (__bgStr == "magenta") { bgval = MAGENTA; }
  if (__bgStr == "brown") { bgval = BROWN; }
  if (__bgStr == "lightgray") { bgval = LIGHTGRAY; }
  if (__bgStr == "darkgray") { bgval = DARKGRAY; }
  if (__bgStr == "lightblue") { bgval = LIGHTBLUE; }
  if (__bgStr == "lightgreen") { bgval = LIGHTGREEN; }
  if (__bgStr == "lightcyan") { bgval = LIGHTCYAN; }
  if (__bgStr == "lightred") { bgval = LIGHTRED; }
  if (__bgStr == "lightmagenta") { bgval = LIGHTMAGENTA; }
  if (__bgStr == "yellow") { bgval = YELLOW; }
  if (__bgStr == "white") { bgval = WHITE; }

  ScreenAttrib = (bgval << 4) + fgval;

  methodReturnNULL;
}

Win32TerminalStream instanceMethod cGetStr (void) {
  /* Read the fine Texinfo page. */
  char buf[MAXMSG], *bufinput;
  buf[0] = MAXMSG;
  bufinput = cgets (buf);
  methodReturnString (bufinput);
}

Win32TerminalStream instanceMethod cPutStr (char *__str) {
  /*
   *  TO DO - The parser needs to recognize the prototype's
   *  "const char *" arg.  Until then, perform the object
   *  to C translation manually.
   */
  cputs (__ctalkToCCharPtr (ARG(0),1));
  methodReturnNULL;
}

Win32TerminalStream instanceMethod gotoXY (int __x, int __y) {
  gotoxy (__ctalkToCInteger(ARG(1), 1), 
	  __ctalkToCInteger(ARG(0), 1));
  methodReturnNULL;
}

