(********************************************************************)
(*                                                                  *)
(*  kbd_act.s7i   Generate code for console keyboard actions.       *)
(*  Copyright (C) 1990 - 1994, 2004 - 2014  Thomas Mertes           *)
(*                                                                  *)
(*  This file is part of the Seed7 compiler.                        *)
(*                                                                  *)
(*  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 2 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, write to the           *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


const ACTION: KBD_GETC        is action "KBD_GETC";
const ACTION: KBD_GETS        is action "KBD_GETS";
const ACTION: KBD_INPUT_READY is action "KBD_INPUT_READY";
const ACTION: KBD_LINE_READ   is action "KBD_LINE_READ";
const ACTION: KBD_RAW_GETC    is action "KBD_RAW_GETC";
const ACTION: KBD_WORD_READ   is action "KBD_WORD_READ";


const proc: kbd_prototypes (inout file: c_prog) is func

  begin
    declareExtern(c_prog, "charType    kbdGetc (void);");
    declareExtern(c_prog, "striType    kbdGets (intType);");
    declareExtern(c_prog, "boolType    kbdInputReady (void);");
    declareExtern(c_prog, "striType    kbdLineRead (charType *);");
    declareExtern(c_prog, "charType    kbdRawGetc (void);");
    declareExtern(c_prog, "striType    kbdWordRead (charType *);");
  end func;


const proc: process (KBD_GETC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "kbdGetc()";
  end func;


const proc: process (KBD_GETS, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "kbdGets(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


const proc: process (KBD_INPUT_READY, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "kbdInputReady()";
  end func;


const proc: process (KBD_LINE_READ, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "kbdLineRead(&(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= "))";
  end func;


const proc: process (KBD_RAW_GETC, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    c_expr.expr &:= "kbdRawGetc()";
  end func;


const proc: process (KBD_WORD_READ, in reference: function,
    in ref_list: params, inout expr_type: c_expr) is func

  begin
    prepare_stri_result(c_expr);
    c_expr.result_expr := "kbdWordRead(&(";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= "))";
  end func;