1/* Copyright (c) 1997-2021
2   Ewgenij Gawrilow, Michael Joswig, and the polymake team
3   Technische Universität Berlin, Germany
4   https://polymake.org
5
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version: http://www.gnu.org/licenses/gpl.txt.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15--------------------------------------------------------------------------------
16*/
17
18#include "polymake/perl/Ext.h"
19
20// this value is not defined in perl headers,
21// it has to be picked from toke.c when line_continued() stops working after a perl upgrade
22#define LEX_NORMAL 10
23
24MODULE = Polymake::Core::Shell          PACKAGE = Polymake::Core::Shell
25
26PROTOTYPES: DISABLE
27
28void line_continued()
29PPCODE:
30{
31   dTARGET;
32   if (PL_parser->yyerrstatus) {
33      // error message pending parser recovery
34      PUSHi(-1);
35   } else if (PL_parser->lex_brackets == 0 && PL_parser->lex_state == LEX_NORMAL && PL_parser->expect == XSTATE) {
36      PUSHi(0);
37   } else {
38      int l = CopLINE(&PL_compiling);
39      for (const char* b = PL_parser->bufptr; b < PL_parser->bufend; ++b) {
40         if (*b == '\n') {
41            // will consume the linebreak as soon as the next line is received
42            ++l;  break;
43         }
44      }
45      PUSHi(l);
46   }
47}
48
49BOOT:
50if (PL_DBgv) {
51   CvNODEBUG_on(get_cv("Polymake::Core::Shell::line_continued", FALSE));
52}
53
54=pod
55// Local Variables:
56// mode:C++
57// c-basic-offset:3
58// indent-tabs-mode:nil
59// End:
60=cut
61