AlcapDAQ  1
Macros | Functions
console.h File Reference

Go to the source code of this file.

Macros

#define ulong   unsigned long
 
#define uint   unsigned int
 
#define ushort   unsigned short
 
#define uchar   unsigned char
 
#define CR   0x0D /* carriage return */
 
#define BLANK   0x20 /* blank */
 
#define ESC   0x1B /* escape */
 
#define BSP   0x08 /* back space */
 
#define TERM_NOT_INIT   FALSE
 
#define TERM_INIT   TRUE
 

Functions

void con_init (void)
 
void con_end (void)
 
void write_log (char *)
 
int con_getch (void)
 
char con_kbhit (void)
 
int con_scanf (char *, void *)
 
int con_printf (char *,...)
 
void gotoxy (int, int)
 
int con_printf_xy (uint, uint, char *,...)
 
void clrscr (void)
 
void clear_line (uint)
 
void delay (int)
 

Macro Definition Documentation

#define BLANK   0x20 /* blank */

Definition at line 72 of file console.h.

#define BSP   0x08 /* back space */

Definition at line 74 of file console.h.

#define CR   0x0D /* carriage return */

Definition at line 71 of file console.h.

#define ESC   0x1B /* escape */

Definition at line 73 of file console.h.

#define TERM_INIT   TRUE

Definition at line 78 of file console.h.

Referenced by con_init().

#define TERM_NOT_INIT   FALSE

Definition at line 77 of file console.h.

#define uchar   unsigned char

Definition at line 63 of file console.h.

Referenced by ViewReadBltData().

#define uint   unsigned int

Definition at line 57 of file console.h.

#define ulong   unsigned long

Definition at line 54 of file console.h.

#define ushort   unsigned short

Definition at line 60 of file console.h.

Referenced by CaenVmeManual(), and ViewReadBltData().

Function Documentation

void clear_line ( uint  )

Definition at line 432 of file console.c.

References gotoxy(), and ocon.

Referenced by CaenVmeIrqCheck(), CaenVmeManual(), CaenVmeRead(), CaenVmeReadBlt(), CaenVmeWrite(), CaenVmeWriteBlt(), and ViewReadBltData().

433 {
434 #ifdef LINUX
435 
436  gotoxy(1, line);
437  clrtoeol();
438 
439 #else
440 
441  COORD coordScreen;
442  CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
443  BOOL bSuccess;
444  DWORD cCharsWritten;
445  DWORD dwLineSize; /* number of character cells in the line to clear */
446  DWORD dwConSize; /* number of character cells in the current buffer */
447 
448  /* information about the specified console screen buffer*/
449  bSuccess = GetConsoleScreenBufferInfo(ocon, &csbi);
450 
451  dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
452  dwLineSize = csbi.dwSize.X;
453 
454  coordScreen.X=0;
455  coordScreen.Y=line-1;
456 
457  /* fill the entire screen with blanks */
458  bSuccess = FillConsoleOutputCharacter(ocon, (TCHAR) ' ',
459  dwLineSize, coordScreen, &cCharsWritten);
460 
461  coordScreen.X=0;
462  coordScreen.Y=csbi.dwCursorPosition.Y;
463 
464  /* set the buffer's attributes */
465  bSuccess = FillConsoleOutputAttribute(ocon, csbi.wAttributes,
466  dwConSize, coordScreen, &cCharsWritten);
467 
468 #endif
469 }
void clrscr ( void  )

Definition at line 388 of file console.c.

References ocon.

Referenced by CaenVmeManual(), con_init(), and ViewReadBltData().

389 {
390 #ifdef LINUX
391 
392  clear();
393  move(0,0);
394  refresh();
395 
396 #else
397 
398  COORD coordScreen = { 0, 0 }; /* home of the cursor */
399  CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
400  BOOL bSuccess;
401  DWORD cCharsWritten;
402  DWORD dwConSize; /* number of character cells in the current buffer */
403 
404  /* information about the specified console screen buffer*/
405  bSuccess = GetConsoleScreenBufferInfo(ocon, &csbi);
406 
407  dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
408 
409  /* fill the entire screen with blanks */
410  bSuccess = FillConsoleOutputCharacter(ocon, (TCHAR) ' ',
411  dwConSize, coordScreen, &cCharsWritten);
412 
413  /* set the buffer's attributes */
414  bSuccess = FillConsoleOutputAttribute(ocon, csbi.wAttributes,
415  dwConSize, coordScreen, &cCharsWritten);
416 
417  /* put the cursor at (0, 0) */
418  bSuccess = SetConsoleCursorPosition(ocon, coordScreen);
419 
420 #endif
421 }
void con_end ( void  )

Definition at line 130 of file console.c.

Referenced by main().

131 {
132 #ifdef LINUX
133 
134  endwin();
135 
136 #endif
137 }
int con_getch ( void  )

Definition at line 173 of file console.c.

References i.

Referenced by CaenVmeManual(), con_kbhit(), and ViewReadBltData().

174 {
175 #ifdef LINUX
176 
177  int i;
178 
179  while( ( i = getch() ) == ERR );
180  return i;
181 
182 #else
183 
184  return _getch();
185 
186 #endif
187 }
void con_init ( void  )

Definition at line 86 of file console.c.

References clrscr(), FALSE, icon, ocon, t_type, and TERM_INIT.

Referenced by main().

87 {
88 #ifdef LINUX
89 
90  initscr();
91  cbreak();
92  noecho();
93  nodelay(stdscr, FALSE);
94  curs_set(FALSE);
95 
96 #else
97 
98  COORD coordScreen = { 0, 0 }; /* home of the cursor */
99  CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
100  BOOL bSuccess;
101  DWORD cCharsWritten;
102  DWORD dwConSize; /* number of character cells in the current buffer */
103 
104 
105  ocon = GetStdHandle(STD_OUTPUT_HANDLE); /* handle for the standard output */
106  icon = GetStdHandle(STD_INPUT_HANDLE); /* handle for the standard input */
107 
108  t_type =TERM_INIT;
109  clrscr(); /* clear the screen */
110 
111  /* information about the specified console screen buffer*/
112  bSuccess = GetConsoleScreenBufferInfo(ocon, &csbi);
113 
114  dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
115 
116  /* set the buffer's attributes */
117  bSuccess = FillConsoleOutputAttribute(ocon, csbi.wAttributes,
118  dwConSize, coordScreen, &cCharsWritten);
119 
120 #endif
121 }
char con_kbhit ( void  )

Definition at line 201 of file console.c.

References c, con_getch(), FALSE, i, and TRUE.

Referenced by CaenVmeIrqCheck(), CaenVmeRead(), CaenVmeReadBlt(), CaenVmeWrite(), CaenVmeWriteBlt(), and con_scanf().

202 {
203 #ifdef LINUX
204 
205  int i, g;
206 
207  nodelay(stdscr, TRUE);
208  i = ( ( g = getch() ) == ERR ? 0 : g );
209  nodelay(stdscr, FALSE);
210 
211  return i;
212 
213 #else
214 
215  char c=0;
216 
217  if(kbhit())
218  c = (char)con_getch();
219  return(c);
220 
221 #endif
222 }
int con_printf ( char *  ,
  ... 
)

Definition at line 276 of file console.c.

References buf, and i.

Referenced by CaenVmeIrqCheck(), CaenVmeManual(), CaenVmeRead(), CaenVmeReadBlt(), CaenVmeWrite(), CaenVmeWriteBlt(), and ViewReadBltData().

277 {
278 #ifdef LINUX
279 
280  va_list marker;
281  int i;
282 
283  va_start(marker,fmt);
284  i = vwprintw(stdscr,fmt,marker);
285  va_end(marker);
286 
287  refresh();
288  return i;
289 
290 #else
291 
292  va_list marker;
293  char buf[256];
294 
295  va_start(marker, fmt); /* Initialize variable arguments. */
296  vsprintf(buf,fmt,marker);
297  va_end(marker); /* Reset variable arguments. */
298 
299  fflush(stdout); /* Empty the output buffer */
300 
301  return _cprintf(buf);
302 
303 #endif
304 }
int con_printf_xy ( uint  ,
uint  ,
char *  ,
  ... 
)

Definition at line 346 of file console.c.

References buf, gotoxy(), and i.

Referenced by CaenVmeIrqCheck(), CaenVmeManual(), CaenVmeRead(), CaenVmeReadBlt(), CaenVmeWrite(), CaenVmeWriteBlt(), and ViewReadBltData().

347 {
348 #ifdef LINUX
349 
350  va_list marker;
351  int i;
352 
353  move(ypos-1, xpos-1);
354  refresh();
355 
356  va_start(marker,fmt);
357  i = vwprintw(stdscr,fmt,marker);
358  va_end(marker);
359 
360  refresh();
361  return i;
362 
363 #else
364 
365  va_list marker;
366  char buf[256];
367 
368  gotoxy(xpos, ypos); /* Set the cursor position */
369 
370  va_start(marker, fmt); /* Initialize variable arguments. */
371  vsprintf(buf,fmt,marker);
372  va_end(marker); /* Reset variable arguments. */
373 
374  fflush(stdout); /* Empty the output buffer */
375 
376  return _cprintf(buf);
377 
378 #endif
379 }
int con_scanf ( char *  ,
void *   
)

Definition at line 237 of file console.c.

References con_kbhit(), and i.

Referenced by CaenVmeIrqCheck(), CaenVmeManual(), CaenVmeWrite(), CaenVmeWriteBlt(), and ViewReadBltData().

238 {
239 #ifdef LINUX
240 
241  int i;
242 
243  echo();
244  i = scanw(fmt,app);
245  refresh();
246  noecho();
247  return i;
248 
249 #else
250 
251  int res;
252 
253  res = _cscanf(fmt, app) ;
254 
255  con_kbhit() ; /* Due to input reading problem */
256 
257  return res;
258 
259 #endif
260 }
void delay ( int  )

Definition at line 480 of file console.c.

481 {
482 #ifdef LINUX
483 
484  usleep(msec*1000);
485 
486 #else
487 
488  Sleep(msec);
489 
490 #endif
491 }
void gotoxy ( int  ,
int   
)

Definition at line 315 of file console.c.

References ocon.

Referenced by CaenVmeIrqCheck(), CaenVmeManual(), CaenVmeRead(), CaenVmeReadBlt(), CaenVmeWrite(), CaenVmeWriteBlt(), clear_line(), and con_printf_xy().

316 {
317 #ifdef LINUX
318 
319  move(y-1, x-1);
320  refresh();
321 
322 #else
323 
324  COORD coord;
325 
326  coord.X = x-1;
327  coord.Y = y-1;
328  SetConsoleCursorPosition(ocon,coord);
329 
330 #endif
331 }
void write_log ( char *  )

Definition at line 148 of file console.c.

References log_file, LOG_FILE_NAME, and printf().

149 {
150  if(log_file == NULL)
151  {
152  log_file = fopen(LOG_FILE_NAME,"w"); /* open log file */
153  if(log_file == NULL)
154  {
155  printf("\n\nCan't open log file\n\n");
156  exit(0);
157  }
158  }
159  fprintf(log_file,"%s\n",msg); /* write the error message in the log file */
160  fflush(stdout); /* empty the output buffer */
161 }