/* Copyright (c) 1997-2021
   Ewgenij Gawrilow, Michael Joswig, and the polymake team
   Technische Universität Berlin, Germany
   https://polymake.org

   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, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   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.
--------------------------------------------------------------------------------
*/

#include "polymake/perl/Ext.h"

// this value is not defined in perl headers,
// it has to be picked from toke.c when line_continued() stops working after a perl upgrade
#define LEX_NORMAL 10

MODULE = Polymake::Core::Shell          PACKAGE = Polymake::Core::Shell

PROTOTYPES: DISABLE

void line_continued()
PPCODE:
{
   dTARGET;
   if (PL_parser->yyerrstatus) {
      // error message pending parser recovery
      PUSHi(-1);
   } else if (PL_parser->lex_brackets == 0 && PL_parser->lex_state == LEX_NORMAL && PL_parser->expect == XSTATE) {
      PUSHi(0);
   } else {
      int l = CopLINE(&PL_compiling);
      for (const char* b = PL_parser->bufptr; b < PL_parser->bufend; ++b) {
         if (*b == '\n') {
            // will consume the linebreak as soon as the next line is received
            ++l;  break;
         }
      }
      PUSHi(l);
   }
}

BOOT:
if (PL_DBgv) {
   CvNODEBUG_on(get_cv("Polymake::Core::Shell::line_continued", FALSE));
}

=pod
// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
=cut
