1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Allan CORNET
4  * Copyright (C) 2008 - INRIA - Sylvestre LEDRU (Detection of the term size)
5  *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  */
16 /*--------------------------------------------------------------------------*/
17 
18 #include "machine.h"
19 
20 /* for getenv() */
21 #ifdef HAVE_STDLIB_H
22 #include <stdlib.h>
23 #endif
24 
25 #ifndef _MSC_VER
26 
27 #  if defined(HAVE_CURSES_H)
28 #    include <curses.h>
29 #  elif defined(HAVE_NCURSES_H)
30 #    include <ncurses.h>
31 #  endif
32 
33 
34 #ifdef HAVE_TERMCAP_H
35 #include <termcap.h>
36 #endif
37 
38 #ifndef HAVE_TERMCAP_H
39 #ifdef HAVE_TERM_H
40 #include <term.h>
41 #endif
42 #endif
43 
44 #endif /* !defined(_MSC_VER) */
45 
46 #include "scilines.h"
47 #include "core_math.h"
48 #ifdef _MSC_VER
49 #include "../../../windows_tools/src/c/scilab_windows/console.h"
50 #endif
51 #include "configvariable_interface.h"
52 /*--------------------------------------------------------------------------*/
53 #define DEFAULT_NUMBERS_LINES 28
54 #define DEFAULT_NUMBERS_COLUMNS 80
55 #define MIN_NUMBERS_LINES 0
56 #define MIN_NUMBERS_COLUMNS 10
57 /*--------------------------------------------------------------------------*/
scilines(int nblines,int nbcolumns)58 int scilines(int nblines, int nbcolumns)
59 {
60     setConsoleLines(nblines);
61     setConsoleWidth(nbcolumns);
62     return 0;
63 }
64 /*--------------------------------------------------------------------------*/
scilinesdefault(void)65 int scilinesdefault(void)
66 {
67 #ifndef _MSC_VER
68 
69     char tc_buf[1024];       /* holds termcap buffer */
70     if (tgetent(tc_buf, getenv("TERM")) == 1)
71     {
72         setConsoleLines(tgetnum("li")); /* retrieve from the term info the number
73 										of lines */
74         setConsoleWidth(tgetnum("co")); /* And the number of columns */
75     }
76     else
77     {
78         /* Haven't been able to detect the terminal */
79         setConsoleLines(DEFAULT_NUMBERS_LINES);
80         setConsoleWidth(DEFAULT_NUMBERS_COLUMNS);
81     }
82 
83 #else
84     if ( (getScilabMode() != SCILAB_STD) && (getScilabMode() != SCILAB_API) )
85     {
86         /* -NW or -NWNI mode */
87         int X = getXConsoleScreenSize();
88         int Y = getYConsoleScreenSize();
89 
90         if (X < DEFAULT_NUMBERS_COLUMNS)
91         {
92             X = DEFAULT_NUMBERS_COLUMNS;
93         }
94         if (Y < DEFAULT_NUMBERS_LINES)
95         {
96             Y = DEFAULT_NUMBERS_LINES;
97         }
98         setConsoleWidth(X);
99         setConsoleLines(Y);
100     }
101     else
102     {
103         setConsoleLines(DEFAULT_NUMBERS_LINES);
104         setConsoleWidth(DEFAULT_NUMBERS_COLUMNS);
105     }
106 #endif
107     return 0;
108 }
109 /*--------------------------------------------------------------------------*/
C2F(scilines)110 int C2F(scilines)(int *nblines, int *nbcolumns)
111 {
112     return scilines(*nblines, *nbcolumns);
113 }
114 /*--------------------------------------------------------------------------*/
C2F(scilinesdefault)115 int C2F(scilinesdefault)(void)
116 {
117     return scilinesdefault();
118 }
119 /*--------------------------------------------------------------------------*/
120