check transfer  0.1
Check data transfer for SDAccell OpenCL application
table_engine_console.cpp
Go to the documentation of this file.
1 
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 #if defined(__linux__)
6 #include <string.h>
7 #include <signal.h>
8 #include <unistd.h>
9 #include <sys/ioctl.h>
10 #include <time.h>
11 #include <termios.h>
12 #include <stdarg.h>
13 #include <vector>
14 #endif
15 
16 #include "table_engine_console.h"
17 //#include "gipcy.h"
18 
19 //-----------------------------------------------------------------------------
20 #if defined(__linux__)
21 static const char* te[] = { "┌", "┐", "└", "┘", "─", "│", "├", "┤","┼", "┬", "┴" };
22 #endif
23 //-----------------------------------------------------------------------------
24 
26 {
28 #if defined(__linux__)
29  rows.clear();
30  m_C = m_R = 0;
31  WC = CELL_WIDTH;
32  HC = CELL_HEIGHT;
33  WCL = 25;
34 #else
35 #endif
36 }
37 
38 //-----------------------------------------------------------------------------
39 
41 {
42 #if defined(__linux__)
43 #else
44 #endif
45 }
46 
47 //-----------------------------------------------------------------------------
48 
49 int TableEngineConsole::CreateTable(const char *pColumnName[], unsigned nCount, unsigned isTStudio)
50 {
51 #if defined(__linux__)
52  get_screen(&WS, &HS);
53  get_pos(&XC, &YC);
54 
55  if(HS-YC < 20) {
56  system("clear");
57  YC = 1;
58  }
59 
60  m_C = nCount;
61  m_R = 1;
62 
63  for(int i=0; i<m_R; i++) {
64 
65  row_t row;
66 
67  for(unsigned j=0; j<nCount; j++) {
68 
69  cell_t c;
70 
71  c.row = i;
72  c.col = j;
73  c.x = XC + j*WC;
74  c.y = YC + i*HC;
75 
76  cell_draw(c.x, c.y, WC, HC);
77 
78  row.c.push_back(c);
79  }
80 
81  row.num = i;
82  rows.push_back(row);
83  }
84 
85  cell_draw_fix();
86 
87  for(unsigned i=0; i<nCount; i++) {
88  SetValueTable(0, i, "%s", pColumnName[i]);
89  }
90 
92  return 0;
93 #else
94 #endif
95 }
96 
97 //-----------------------------------------------------------------------------
98 
100 {
101  if( 0==flagTableCreate )
102  return 0;
103 
104 #if defined(__linux__)
105  row_t new_row;
106  row_t& last_row = rows.at(rows.size()-1);
107 
108  new_row.num = last_row.num+1;
109  for(int j=0; j<m_C; j++) {
110 
111  cell_t c;
112 
113  c.row = new_row.num;
114  c.col = j;
115  c.x = XC + c.col*WC;
116  c.y = YC + c.row*HC;
117 
118  cell_draw(c.x, c.y, WC, HC);
119 
120  new_row.c.push_back(c);
121  }
122 
123  m_R++;
124 
125  rows.push_back(new_row);
126 
127  cell_draw_fix();
128 #else
129 #endif
130  return rows.size()-1;
131 }
132 
133 //-----------------------------------------------------------------------------
134 
135 int TableEngineConsole::SetValueTable(unsigned nRow, unsigned nColumn, const char *fmt, ...)
136 {
137 #if defined(__linux__)
138  cell_t& c = get_cell(nRow, nColumn);
139  gotoxy(c.x+2, c.y+1);
140  va_list argptr;
141  va_start(argptr, fmt);
142  char msg[32];
143  vsprintf(msg, fmt, argptr);
144  printf("%s\n", msg);
145 #endif
146  return 0;
147 }
148 
149 //-----------------------------------------------------------------------------
150 
151 //int TableEngineConsole::SetValueTable(unsigned nRow, unsigned nColumn, const char *pVal)
152 //{
153 //#if defined(__linux__)
154 // SetValueTable(nRow, nColumn, "%s", pVal);
155 //#else
156 //#endif
157 // return 0;
158 //}
159 
160 //-----------------------------------------------------------------------------
161 
162 int TableEngineConsole::SetValueTable(unsigned nRow, unsigned nColumn, signed nVal, const char* format)
163 {
164 #if defined(__linux__)
165  SetValueTable(nRow, nColumn, format, nVal);
166 #else
167 #endif
168  return 0;
169 }
170 
171 //-----------------------------------------------------------------------------
172 
173 int TableEngineConsole::SetValueTable(unsigned nRow, unsigned nColumn, unsigned nVal, const char *format)
174 {
175 #if defined(__linux__)
176  SetValueTable(nRow, nColumn, format, nVal);
177 #else
178 #endif
179  return 0;
180 }
181 
182 //-----------------------------------------------------------------------------
183 
184 int TableEngineConsole::SetValueTable(unsigned nRow, unsigned nColumn, float dVal, const char *format)
185 {
186 #if defined(__linux__)
187  SetValueTable(nRow, nColumn, format, dVal);
188 #else
189 #endif
190  return 0;
191 }
192 
193 //-----------------------------------------------------------------------------
194 
196 {
197 #if defined(__linux__)
198 #else
199 #endif
200 }
201 
202 //-----------------------------------------------------------------------------
203 
205 {
206 #if defined(__linux__)
207 #else
208 #endif
209 }
210 
211 //-----------------------------------------------------------------------------
212 
214 {
215 #if defined(__linux__)
216 #else
217 #endif
218 }
219 
220 //-----------------------------------------------------------------------------
221 
223 {
224 #if defined(__linux__)
225  get_pos(&X, &Y);
226 #else
227 #endif
228 }
229 
230 //-----------------------------------------------------------------------------
231 
233 {
234 #if defined(__linux__)
235  gotoxy(X, Y);
236 #endif
237 }
238 
239 //-----------------------------------------------------------------------------
240 
241 #if defined(__linux__)
242 
243 cell_t& TableEngineConsole::get_cell(int row, int col)
244 {
245  return rows.at(row).c.at(col);
246 }
247 
248 //------------------------------------------------------------------------------
249 
250 void TableEngineConsole::cell_draw(int x, int y, int w, int h)
251 {
252  int i=0;
253 
254  //set_display_atrib(B_BLUE);
255 
256  gotoxy(x,y);
257  puts(te[0]);
258 
259  gotoxy(x+w,y);
260  puts(te[1]);
261 
262  gotoxy(x,y+h);
263  puts(te[2]);
264 
265  gotoxy(x+w,y+h);
266  puts(te[3]);
267 
268  for(i=1; i<w; i++) {
269  gotoxy(x+i,y);
270  puts(te[4]);
271  gotoxy(x+i,y+h);
272  puts(te[4]);
273  }
274 
275  for(i=1; i<h; i++) {
276  gotoxy(x,y+i);
277  puts(te[5]);
278  gotoxy(x+w,y+i);
279  puts(te[5]);
280  }
281 }
282 
283 //------------------------------------------------------------------------------
284 
285 void TableEngineConsole::cell_draw_fix()
286 {
287  for(int col=0; col<m_C+1; col++) {
288 
289  for(int row=0; row<m_R+1; row++) {
290 
291  int x = XC + col*WC;
292  int y = YC + row*HC;
293 
294  gotoxy(x, y);
295 
296  if((row==0) && (col != 0) && (col != m_C))
297  puts(te[9]);
298  if((row==m_R) && (col != 0) && (col != m_C))
299  puts(te[10]);
300  if((col && row) && (col != m_C) && (row != m_R))
301  puts(te[8]);
302  if((col==0) & (row != 0) && (row != m_R))
303  puts(te[6]);
304  if((col==m_C) & (row != 0) && (row != m_R))
305  puts(te[7]);
306  }
307  }
308 
309  gotoxy(1, YC+m_R*HC+1);
310 }
311 
312 //------------------------------------------------------------------------------
313 
314 int TableEngineConsole::get_pos(int *X, int *Y)
315 {
316  int res = 0;
317  char buf[16];
318  char cmd[]="\033[6n";
319  struct termios save,raw;
320  setvbuf(stdout, NULL, _IONBF, 0);
321  tcgetattr(0,&save);
322  cfmakeraw(&raw); tcsetattr(0,TCSANOW,&raw);
323  if (isatty(fileno(stdin)))
324  {
325  int res = 0;
326  write(1,cmd,sizeof(cmd));
327  res = read (0 ,buf ,sizeof(buf));
328  if(res <= 0)
329  return -1;
330  Y[0] = atoi(&buf[2]);
331  if(Y[0]>=10)
332  X[0] = atoi(&buf[5]);
333  else
334  X[0] = atoi(&buf[4]);
335  //printf("\nX = %d Y = %d\n", Y[0], X[0]);
336  } else {
337  res = -1;
338  }
339  tcsetattr(0,TCSANOW,&save);
340  return res;
341 }
342 
343 //------------------------------------------------------------------------------
344 
345 int TableEngineConsole::get_screen(int *W, int *H)
346 {
347  struct winsize ws = { 0, 0, 0, 0 };
348  if(ioctl(fileno(stdout), TIOCGWINSZ, &ws) == -1) {
349  return -1;
350  }
351  //printf("TIOCGWINSZ: %d %d %d %d\n", ws.ws_row, ws.ws_col, ws.ws_xpixel, ws.ws_ypixel);
352  W[0] = ws.ws_col;
353  H[0] = ws.ws_row;
354  return 0;
355 }
356 
357 #endif
358 
359 //-----------------------------------------------------------------------------
int col
Definition: term_table.h:56
void SetConsolePos(int X, int Y)
#define CELL_HEIGHT
Definition: term_table.h:37
int num
Definition: term_table.h:67
void GetConsolePos(int &X, int &Y)
std::vector< cell_t > c
Definition: term_table.h:68
#define CELL_WIDTH
Definition: term_table.h:36
int CreateTable(const char *pColumnName[], unsigned nCount, unsigned isTStudio)
int row
Definition: term_table.h:55
int SetValueTable(unsigned nRow, unsigned nColumn, const char *fmt,...)
int y
Definition: term_table.h:54
#define gotoxy(x, y)
Definition: term_table.h:43
int x
Definition: term_table.h:53