(********************************************************************)
(*                                                                  *)
(*  drw_act.s7i   Generate code for actions to do graphic output.   *)
(*  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: DRW_ARC                       is action "DRW_ARC";
const ACTION: DRW_ARC2                      is action "DRW_ARC2";
const ACTION: DRW_BACKGROUND                is action "DRW_BACKGROUND";
const ACTION: DRW_BORDER                    is action "DRW_BORDER";
const ACTION: DRW_CAPTURE                   is action "DRW_CAPTURE";
const ACTION: DRW_CIRCLE                    is action "DRW_CIRCLE";
const ACTION: DRW_CLEAR                     is action "DRW_CLEAR";
const ACTION: DRW_CMP                       is action "DRW_CMP";
const ACTION: DRW_COLOR                     is action "DRW_COLOR";
const ACTION: DRW_CONV_POINT_LIST           is action "DRW_CONV_POINT_LIST";
const ACTION: DRW_COPYAREA                  is action "DRW_COPYAREA";
const ACTION: DRW_CPY                       is action "DRW_CPY";
const ACTION: DRW_EQ                        is action "DRW_EQ";
const ACTION: DRW_FARCCHORD                 is action "DRW_FARCCHORD";
const ACTION: DRW_FARCPIESLICE              is action "DRW_FARCPIESLICE";
const ACTION: DRW_FCIRCLE                   is action "DRW_FCIRCLE";
const ACTION: DRW_FELLIPSE                  is action "DRW_FELLIPSE";
const ACTION: DRW_FLUSH                     is action "DRW_FLUSH";
const ACTION: DRW_FPOLY_LINE                is action "DRW_FPOLY_LINE";
const ACTION: DRW_GEN_POINT_LIST            is action "DRW_GEN_POINT_LIST";
const ACTION: DRW_GET_IMAGE_PIXEL           is action "DRW_GET_IMAGE_PIXEL";
const ACTION: DRW_GET_PIXEL                 is action "DRW_GET_PIXEL";
const ACTION: DRW_GET_PIXEL_ARRAY           is action "DRW_GET_PIXEL_ARRAY";
const ACTION: DRW_GET_PIXEL_DATA            is action "DRW_GET_PIXEL_DATA";
const ACTION: DRW_GET_PIXEL_DATA_FROM_ARRAY is action "DRW_GET_PIXEL_DATA_FROM_ARRAY";
const ACTION: DRW_GET_PIXMAP                is action "DRW_GET_PIXMAP";
const ACTION: DRW_GET_PIXMAP_FROM_PIXELS    is action "DRW_GET_PIXMAP_FROM_PIXELS";
const ACTION: DRW_HASHCODE                  is action "DRW_HASHCODE";
const ACTION: DRW_HEIGHT                    is action "DRW_HEIGHT";
const ACTION: DRW_LINE                      is action "DRW_LINE";
const ACTION: DRW_NE                        is action "DRW_NE";
const ACTION: DRW_NEW_PIXMAP                is action "DRW_NEW_PIXMAP";
const ACTION: DRW_OPEN                      is action "DRW_OPEN";
const ACTION: DRW_OPEN_SUB_WINDOW           is action "DRW_OPEN_SUB_WINDOW";
const ACTION: DRW_PARC                      is action "DRW_PARC";
const ACTION: DRW_PCIRCLE                   is action "DRW_PCIRCLE";
const ACTION: DRW_PFARC                     is action "DRW_PFARC";
const ACTION: DRW_PFARCCHORD                is action "DRW_PFARCCHORD";
const ACTION: DRW_PFARCPIESLICE             is action "DRW_PFARCPIESLICE";
const ACTION: DRW_PFCIRCLE                  is action "DRW_PFCIRCLE";
const ACTION: DRW_PFELLIPSE                 is action "DRW_PFELLIPSE";
const ACTION: DRW_PIXEL_TO_RGB              is action "DRW_PIXEL_TO_RGB";
const ACTION: DRW_PLINE                     is action "DRW_PLINE";
const ACTION: DRW_POINT                     is action "DRW_POINT";
const ACTION: DRW_POINTER_XPOS              is action "DRW_POINTER_XPOS";
const ACTION: DRW_POINTER_YPOS              is action "DRW_POINTER_YPOS";
const ACTION: DRW_POLY_LINE                 is action "DRW_POLY_LINE";
const ACTION: DRW_PPOINT                    is action "DRW_PPOINT";
const ACTION: DRW_PRECT                     is action "DRW_PRECT";
const ACTION: DRW_PUT                       is action "DRW_PUT";
const ACTION: DRW_PUT_SCALED                is action "DRW_PUT_SCALED";
const ACTION: DRW_RECT                      is action "DRW_RECT";
const ACTION: DRW_RGBCOL                    is action "DRW_RGBCOL";
const ACTION: DRW_SCREEN_HEIGHT             is action "DRW_SCREEN_HEIGHT";
const ACTION: DRW_SCREEN_WIDTH              is action "DRW_SCREEN_WIDTH";
const ACTION: DRW_SET_CLOSE_ACTION          is action "DRW_SET_CLOSE_ACTION";
const ACTION: DRW_SET_CONTENT               is action "DRW_SET_CONTENT";
const ACTION: DRW_SET_CURSOR_VISIBLE        is action "DRW_SET_CURSOR_VISIBLE";
const ACTION: DRW_SET_POINTER_POS           is action "DRW_SET_POINTER_POS";
const ACTION: DRW_SET_POS                   is action "DRW_SET_POS";
const ACTION: DRW_SET_SIZE                  is action "DRW_SET_SIZE";
const ACTION: DRW_SET_TRANSPARENT_COLOR     is action "DRW_SET_TRANSPARENT_COLOR";
const ACTION: DRW_SET_WINDOW_NAME           is action "DRW_SET_WINDOW_NAME";
const ACTION: DRW_TEXT                      is action "DRW_TEXT";
const ACTION: DRW_TO_BOTTOM                 is action "DRW_TO_BOTTOM";
const ACTION: DRW_TO_TOP                    is action "DRW_TO_TOP";
const ACTION: DRW_VALUE                     is action "DRW_VALUE";
const ACTION: DRW_WIDTH                     is action "DRW_WIDTH";
const ACTION: DRW_XPOS                      is action "DRW_XPOS";
const ACTION: DRW_YPOS                      is action "DRW_YPOS";

const ACTION: PLT_BSTRING                   is action "PLT_BSTRING";
const ACTION: PLT_CMP                       is action "PLT_CMP";
const ACTION: PLT_CPY                       is action "PLT_CPY";
const ACTION: PLT_EQ                        is action "PLT_EQ";
const ACTION: PLT_HASHCODE                  is action "PLT_HASHCODE";
const ACTION: PLT_NE                        is action "PLT_NE";
const ACTION: PLT_POINT_LIST                is action "PLT_POINT_LIST";
const ACTION: PLT_VALUE                     is action "PLT_VALUE";


const proc: constructRgbMacroPart (in string: colorName, in integer: colorMask,
    inout string: macroBody) is func

  local
    var integer: highestMaskBit is 0;
    var string: macroPart is "";
  begin
    highestMaskBit := succ(log2(colorMask));
    if highestMaskBit > 16 then
      macroPart := "((((unsigned long) (" <& colorName <&
                   ")) << " <& highestMaskBit - 16 <&
                   ") & 0x" <& colorMask radix 16 <& ")";
    elsif highestMaskBit < 16 then
      macroPart := "((((unsigned long) (" <& colorName <&
                   ")) >> " <& 16 - highestMaskBit <&
                   ") & 0x" <& colorMask radix 16 <& ")";
    else
      macroPart := "(((unsigned long) (" <& colorName <&
                   ")) & 0x" <& colorMask radix 16 <& ")";
    end if;
    if macroBody <> "" then
      macroBody &:= " | ";
    end if;
    macroBody &:= macroPart;
  end func;


const func string: defineRgbMacroBody is func

  result
    var string: macroBody is "";
  begin
    constructRgbMacroPart("red",   ccConf.PIXEL_RED_MASK,   macroBody);
    constructRgbMacroPart("green", ccConf.PIXEL_GREEN_MASK, macroBody);
    constructRgbMacroPart("blue",  ccConf.PIXEL_BLUE_MASK,  macroBody);
    if ccConf.PIXEL_ALPHA_MASK <> 0 then
      macroBody := "(" <& macroBody <& ") | 0x" <& ccConf.PIXEL_ALPHA_MASK radix 16;
    end if;
  end func;


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

  begin
    declareExtern(c_prog, "void        drawInit (void);");
    declareExtern(c_prog, "intType     drwPointerXpos (const_winType);");
    declareExtern(c_prog, "intType     drwPointerYpos (const_winType);");
    declareExtern(c_prog, "void        drwArc (const_winType, intType, intType, intType, floatType, floatType);");
    declareExtern(c_prog, "void        drwArc2 (const_winType, intType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwBackground (intType);");
    declareExtern(c_prog, "arrayType   drwBorder (const_winType);");
    declareExtern(c_prog, "winType     drwCapture (intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwCircle (const_winType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwClear (winType, intType);");
    declareExtern(c_prog, "void        drwColor (intType);");
    declareExtern(c_prog, "arrayType   drwConvPointList (const const_bstriType);");
    declareExtern(c_prog, "void        drwCopyArea (const_winType, const_winType, intType, intType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwCpy (winType *const, const winType);");
    declareExtern(c_prog, "void        drwCpyGeneric (genericType *const, const genericType);");
    declareExtern(c_prog, "winType     drwCreate (const winType);");
    declareExtern(c_prog, "genericType drwCreateGeneric (const genericType);");
    declareExtern(c_prog, "void        drwDestr (const winType);");
    declareExtern(c_prog, "void        drwDestrGeneric (const genericType);");
    declareExtern(c_prog, "void        drwFArcChord (const_winType, intType, intType, intType, floatType, floatType);");
    declareExtern(c_prog, "void        drwFArcPieSlice (const_winType, intType, intType, intType, floatType, floatType);");
    declareExtern(c_prog, "void        drwFCircle (const_winType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwFEllipse (const_winType, intType, intType, intType, intType);");
    declareExtern(c_prog, "winType     drwEmpty (void);");
    declareExtern(c_prog, "void        drwFlush (void);");
    declareExtern(c_prog, "bstriType   drwGenPointList (const const_arrayType);");
    declareExtern(c_prog, "intType     drwGetImagePixel (const_bstriType, intType, intType, intType, intType);");
    declareExtern(c_prog, "intType     drwGetPixel (const_winType, intType, intType);");
    declareExtern(c_prog, "arrayType   drwGetPixelArray (const_winType);");
    declareExtern(c_prog, "bstriType   drwGetPixelData (const_winType);");
    declareExtern(c_prog, "bstriType   drwGetPixelDataFromArray (const_arrayType);");
    declareExtern(c_prog, "winType     drwGetPixmap (const_winType, intType, intType, intType, intType);");
    declareExtern(c_prog, "winType     drwGetPixmapFromPixels (const_arrayType);");
    declareExtern(c_prog, "intType     drwHeight (const_winType);");
    declareExtern(c_prog, "winType     drwImage (int32Type *, memSizeType, memSizeType, boolType);");
    declareExtern(c_prog, "void        drwLine (const_winType, intType, intType, intType, intType);");
    declareExtern(c_prog, "winType     drwNewPixmap (intType, intType);");
    declareExtern(c_prog, "winType     drwOpen (intType, intType, intType, intType, const const_striType);");
    declareExtern(c_prog, "winType     drwOpenSubWindow (const_winType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwSetCloseAction (winType, intType);");
    declareExtern(c_prog, "void        drwPArc (const_winType, intType, intType, intType, floatType, floatType, intType);");
    declareExtern(c_prog, "void        drwPCircle (const_winType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwPFArc (const_winType, intType, intType, intType, floatType, floatType, intType, intType);");
    declareExtern(c_prog, "void        drwPFArcChord (const_winType, intType, intType, intType, floatType, floatType, intType);");
    declareExtern(c_prog, "void        drwPFArcPieSlice (const_winType, intType, intType, intType, floatType, floatType, intType);");
    declareExtern(c_prog, "void        drwPFCircle (const_winType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwPFEllipse (const_winType, intType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwPixelToRgb (intType, intType *, intType *, intType *);");
    declareExtern(c_prog, "void        drwPLine (const_winType, intType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwPoint (const_winType, intType, intType);");
    declareExtern(c_prog, "void        drwPPoint (const_winType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwPRect (const_winType, intType, intType, intType, intType, intType);");
    declareExtern(c_prog, "void        drwPolyLine (const_winType, intType, intType, bstriType, intType);");
    declareExtern(c_prog, "void        drwFPolyLine (const_winType, intType, intType, bstriType, intType);");
    declareExtern(c_prog, "void        drwPut (const_winType, intType, intType, const_winType);");
    declareExtern(c_prog, "void        drwPutScaled (const_winType, intType, intType, intType, intType, const_winType);");
    declareExtern(c_prog, "void        drwRect (const_winType, intType, intType, intType, intType);");
    if inlineFunctions and ccConf.PIXEL_RED_MASK   <> 0 and
                           ccConf.PIXEL_GREEN_MASK <> 0 and
                           ccConf.PIXEL_BLUE_MASK  <> 0 then
      if ccConf.RGB_TO_PIXEL_FLAG_NAME = "" then
        writeln(c_prog, "#define drwRgbColor(red, green, blue) " <&
                        "(" <& defineRgbMacroBody <& ")");
      else
        declareExtern(c_prog, "intType     drwRgbColor (intType, intType, intType);");
        writeln(c_prog, "extern int " <& ccConf.RGB_TO_PIXEL_FLAG_NAME <& ";");
        writeln(c_prog, "#define drwRgbColor(red, green, blue) " <&
                        "(" <& ccConf.RGB_TO_PIXEL_FLAG_NAME <& "?(" <&
                        defineRgbMacroBody <& "):(drwRgbColor)(red, green, blue))");
      end if;
    else
      declareExtern(c_prog, "intType     drwRgbColor (intType, intType, intType);");
    end if;
    declareExtern(c_prog, "intType     drwScreenHeight (void);");
    declareExtern(c_prog, "intType     drwScreenWidth (void);");
    declareExtern(c_prog, "void        drwSetContent (const_winType, const_winType);");
    declareExtern(c_prog, "void        drwSetCursorVisible (winType, boolType);");
    declareExtern(c_prog, "void        drwSetPointerPos (const_winType, intType, intType);");
    declareExtern(c_prog, "void        drwSetPos (const_winType, intType, intType);");
    declareExtern(c_prog, "void        drwSetSize (winType, intType, intType);");
    declareExtern(c_prog, "void        drwSetTransparentColor (winType, intType);");
    declareExtern(c_prog, "void        drwSetWindowName (winType, const const_striType);");
    declareExtern(c_prog, "void        drwText (const_winType, intType, intType, const const_striType, intType, intType);");
    declareExtern(c_prog, "void        drwToBottom (const_winType);");
    declareExtern(c_prog, "void        drwToTop (const_winType);");
    declareExtern(c_prog, "winType     drwValue (const const_objRefType);");
    declareExtern(c_prog, "intType     drwWidth (const_winType);");
    declareExtern(c_prog, "intType     drwXPos (const_winType);");
    declareExtern(c_prog, "intType     drwYPos (const_winType);");

    declareExtern(c_prog, "bstriType   pltAlign (const const_bstriType);");
    declareExtern(c_prog, "bstriType   pltValue (const const_objRefType);");
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwArc(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwArc2(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwBackground(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  local
    var type: result_type is void;
  begin
    result_type := resultType(getType(function));
    prepare_typed_result(result_type, c_expr);
    c_expr.result_expr := "drwBorder(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "drwCapture(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwCircle(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwClear(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    c_expr.expr &:= "ptrCmp(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwColor(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  local
    var type: result_type is void;
  begin
    result_type := resultType(getType(function));
    prepare_typed_result(result_type, c_expr);
    c_expr.result_expr := "drwConvPointList(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwCopyArea(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[7], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[8], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  local
    var expr_type: statement is expr_type.value;
    var expr_type: c_param1 is expr_type.value;
    var expr_type: c_param3 is expr_type.value;
  begin
    statement.temp_num := c_expr.temp_num;
    prepareAnyParamTemporarys(params[1], c_param1, statement);
    c_param3.demand := ASSIGN_RESULT;
    prepareAnyParamTemporarys(params[3], c_param3, statement);
    if c_param3.result_expr <> "" then
      statement.temp_decls &:= "winType new_win;\n";
      statement.expr &:= "new_win=";
      statement.expr &:= c_param3.result_expr;
      statement.expr &:= ";\n";
      if isNormalVariable(params[1]) then
        statement.expr &:= "drwDestr(";
        statement.expr &:= c_param1.expr;
        statement.expr &:= ");\n";
        statement.expr &:= c_param1.expr;
        statement.expr &:= "=new_win;\n";
      else
        statement.temp_decls &:= "winType *win_ptr=&(";
        statement.temp_decls &:= c_param1.expr;
        statement.temp_decls &:= ");\n";
        statement.expr &:= "drwDestr(*win_ptr);\n";
        statement.expr &:= "*win_ptr=new_win;\n";
      end if;
    else
      statement.expr &:= "drwCpy(&(";
      statement.expr &:= c_param1.expr;
      statement.expr &:= "), ";
      statement.expr &:= c_param3.expr;
      statement.expr &:= ");\n";
    end if;
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


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

  begin
    c_expr.expr &:= "(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ") == (";
    getAnyParamToExpr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwFArcChord(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwFArcPieSlice(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwFCircle(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwFEllipse(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwFlush();\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwFPolyLine(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    prepare_bstri_result(c_expr);
    c_expr.result_expr &:= "drwGenPointList(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    c_expr.expr &:= "drwGetImagePixel(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    c_expr.expr &:= "drwGetPixel(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  local
    var type: result_type is void;
  begin
    result_type := resultType(getType(function));
    prepare_typed_result(result_type, c_expr);
    c_expr.result_expr := "drwGetPixelArray(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    prepare_bstri_result(c_expr);
    c_expr.result_expr := "drwGetPixelData(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    prepare_bstri_result(c_expr);
    c_expr.result_expr := "drwGetPixelDataFromArray(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "drwGetPixmap(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "drwGetPixmapFromPixels(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    c_expr.expr &:= "(intType)(((memSizeType)(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ")) >> 6)";
  end func;


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

  begin
    c_expr.expr &:= "drwHeight(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwLine(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    c_expr.expr &:= "(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ") != (";
    getAnyParamToExpr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "drwNewPixmap(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "drwOpen(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getAnyParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    prepare_win_result(c_expr);
    c_expr.result_expr := "drwOpenSubWindow(";
    getAnyParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[2], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[3], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[4], c_expr);
    c_expr.result_expr &:= ", ";
    getStdParamToResultExpr(params[5], c_expr);
    c_expr.result_expr &:= ")";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPArc(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[7], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPCircle(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPFArc(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[7], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[8], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPFArcChord(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[7], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPFArcPieSlice(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[7], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPFCircle(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPFEllipse(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


const proc: assignColorOfPixel (in string: pixelName,
    in reference: colorDestination, in integer: colorMask,
    inout expr_type: c_expr) is func

  local
    var integer: highestMaskBit is 0;
  begin
    process_expr(colorDestination, c_expr);
    c_expr.expr &:= " = (intType)(";
    highestMaskBit := succ(log2(colorMask));
    if highestMaskBit > 16 then
      c_expr.expr &:= "((uintType)(";
      c_expr.expr &:= pixelName;
      c_expr.expr &:= ") & 0x";
      c_expr.expr &:= colorMask radix 16;
      c_expr.expr &:= ") >> ";
      c_expr.expr &:= str(highestMaskBit - 16);
    elsif highestMaskBit < 16 then
      c_expr.expr &:= "((uintType)(";
      c_expr.expr &:= pixelName;
      c_expr.expr &:= ") & 0x";
      c_expr.expr &:= colorMask radix 16;
      c_expr.expr &:= ") << ";
      c_expr.expr &:= str(16 - highestMaskBit);
    else
      c_expr.expr &:= "(uintType)(";
      c_expr.expr &:= pixelName;
      c_expr.expr &:= ") & 0x";
      c_expr.expr &:= colorMask radix 16;
    end if;
    c_expr.expr &:= ");\n";
  end func;


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

  local
    var expr_type: statement is expr_type.value;
    var string: pixelName is "";
  begin
    if inlineFunctions and ccConf.PIXEL_RED_MASK   <> 0 and
                           ccConf.PIXEL_GREEN_MASK <> 0 and
                           ccConf.PIXEL_BLUE_MASK  <> 0 then
      incr(countInlinedFunctions);
      if ccConf.RGB_TO_PIXEL_FLAG_NAME <> "" then
        statement.expr &:= "if (";
        statement.expr &:= ccConf.RGB_TO_PIXEL_FLAG_NAME;
        statement.expr &:= ") {\n";
      end if;
      if isNormalVariable(params[1]) then
        pixelName := normalVariable(params[1], statement);
      else
        incr(statement.temp_num);
        pixelName := "pixel_" & str(statement.temp_num);
        statement.temp_decls &:= "uintType ";
        statement.temp_decls &:= pixelName;
        statement.temp_decls &:= ";\n";
        statement.expr &:= pixelName;
        statement.expr &:= "=(uintType)(";
        process_expr(params[1], statement);
        statement.expr &:= ");\n";
      end if;
      assignColorOfPixel(pixelName, params[2], ccConf.PIXEL_RED_MASK,   statement);
      assignColorOfPixel(pixelName, params[3], ccConf.PIXEL_GREEN_MASK, statement);
      assignColorOfPixel(pixelName, params[4], ccConf.PIXEL_BLUE_MASK,  statement);
      if ccConf.RGB_TO_PIXEL_FLAG_NAME <> "" then
        statement.expr &:= "} else {\n";
        statement.expr &:= "drwPixelToRgb(";
        statement.expr &:= pixelName;
        statement.expr &:= ", &(";
        process_expr(params[2], statement);
        statement.expr &:= "), &(";
        process_expr(params[3], statement);
        statement.expr &:= "), &(";
        process_expr(params[4], statement);
        statement.expr &:= "));\n";
        statement.expr &:= "}\n";
      end if;
      doLocalDeclsOfStatement(statement, c_expr);
    else
      setDiagnosticLine(c_expr);
      c_expr.expr &:= "drwPixelToRgb(";
      process_expr(params[1], c_expr);
      c_expr.expr &:= ", &(";
      process_expr(params[2], c_expr);
      c_expr.expr &:= "), &(";
      process_expr(params[3], c_expr);
      c_expr.expr &:= "), &(";
      process_expr(params[4], c_expr);
      c_expr.expr &:= "));\n";
    end if;
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPLine(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPoint(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    c_expr.expr &:= "drwPointerXpos(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    c_expr.expr &:= "drwPointerYpos(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPolyLine(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPPoint(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPRect(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPut(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[4], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwPutScaled(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwRect(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    c_expr.expr &:= "drwRgbColor(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ")";
  end func;


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

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


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

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


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetCloseAction(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetContent(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetCursorVisible(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetPointerPos(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetPos(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetSize(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetTransparentColor(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwSetWindowName(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[2], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwText(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[2], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[3], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[4], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[5], c_expr);
    c_expr.expr &:= ", ";
    process_expr(params[6], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwToBottom(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    setDiagnosticLine(c_expr);
    c_expr.expr &:= "drwToTop(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ");\n";
  end func;


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

  begin
    c_expr.expr &:= "drwValue(";
    process_expr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    c_expr.expr &:= "drwWidth(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    c_expr.expr &:= "drwXPos(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    c_expr.expr &:= "drwYPos(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  begin
    process_expr(params[1], c_expr);
  end func;


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

  begin
    c_expr.expr &:= "bstCmp(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ", ";
    getAnyParamToExpr(params[2], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  local
    var expr_type: statement is expr_type.value;
    var expr_type: c_param1 is expr_type.value;
    var expr_type: c_param3 is expr_type.value;
  begin
    statement.temp_num := c_expr.temp_num;
    prepareAnyParamTemporarys(params[1], c_param1, statement);
    c_param3.demand := ASSIGN_RESULT;
    prepareAnyParamTemporarys(params[3], c_param3, statement);
    if c_param3.result_expr <> "" then
      statement.temp_decls &:= "bstriType new_bstri;\n";
      statement.expr &:= "new_bstri=";
      statement.expr &:= c_param3.result_expr;
      statement.expr &:= ";\n";
      if isNormalVariable(params[1]) then
        statement.expr &:= "bstDestr(";
        statement.expr &:= c_param1.expr;
        statement.expr &:= ");\n";
        statement.expr &:= c_param1.expr;
        statement.expr &:= "=new_bstri;\n";
      else
        statement.temp_decls &:= "bstriType *bstri_ptr=&(";
        statement.temp_decls &:= c_param1.expr;
        statement.temp_decls &:= ");\n";
        statement.expr &:= "bstDestr(*bstri_ptr);\n";
        statement.expr &:= "*bstri_ptr=new_bstri;\n";
      end if;
    else
      statement.expr &:= "bstCpy(&(";
      statement.expr &:= c_param1.expr;
      statement.expr &:= "), ";
      statement.expr &:= c_param3.expr;
      statement.expr &:= ");\n";
    end if;
    doLocalDeclsOfStatement(statement, c_expr);
  end func;


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

  local
    var string: bstri_a_name is "";
    var string: bstri_b_name is "";
  begin
    c_expr.expr &:= "(";
    bstri_a_name := getParameterAsVariable("const_bstriType", "tmp_a_", params[1], c_expr);
    bstri_b_name := getParameterAsVariable("const_bstriType", "tmp_b_", params[3], c_expr);
    (* Formula used: (a->size==b->size&&memcmp(a->mem,b->mem,
                     a->size*sizeof(unsigned char))==0) *)
    c_expr.expr &:= bstri_a_name;
    c_expr.expr &:= "->size==";
    c_expr.expr &:= bstri_b_name;
    c_expr.expr &:= "->size&&memcmp(";
    c_expr.expr &:= bstri_a_name;
    c_expr.expr &:= "->mem,";
    c_expr.expr &:= bstri_b_name;
    c_expr.expr &:= "->mem,";
    c_expr.expr &:= bstri_a_name;
    c_expr.expr &:= "->size*sizeof(unsigned char))==0)";
  end func;


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

  begin
    c_expr.expr &:= "bstHashCode(";
    getAnyParamToExpr(params[1], c_expr);
    c_expr.expr &:= ")";
  end func;


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

  local
    var string: bstri_a_name is "";
    var string: bstri_b_name is "";
  begin
    c_expr.expr &:= "(";
    bstri_a_name := getParameterAsVariable("const_bstriType", "tmp_a_", params[1], c_expr);
    bstri_b_name := getParameterAsVariable("const_bstriType", "tmp_b_", params[3], c_expr);
    (* Formula used: (a->size!=b->size||memcmp(a->mem,b->mem,
                     a->size*sizeof(unsigned char))!=0) *)
    c_expr.expr &:= bstri_a_name;
    c_expr.expr &:= "->size!=";
    c_expr.expr &:= bstri_b_name;
    c_expr.expr &:= "->size||memcmp(";
    c_expr.expr &:= bstri_a_name;
    c_expr.expr &:= "->mem,";
    c_expr.expr &:= bstri_b_name;
    c_expr.expr &:= "->mem,";
    c_expr.expr &:= bstri_a_name;
    c_expr.expr &:= "->size*sizeof(unsigned char))!=0)";
  end func;


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

  begin
    process_expr(params[1], c_expr);
  end func;


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

  begin
    prepare_bstri_result(c_expr);
    c_expr.result_expr := "pltValue(";
    getStdParamToResultExpr(params[1], c_expr);
    c_expr.result_expr &:= ")";
  end func;