FreeBASIC  0.91.0
io_printpad.c
Go to the documentation of this file.
1 /* print functions */
2 
3 #include "fb.h"
4 
5 #define FB_PRINT_BUFFER_SIZE 2048
6 
7 static void fb_hPrintPadEx ( FB_FILE *handle, int mask, int current_x, int new_x )
8 {
9 #ifdef FB_NATIVE_TAB
10  FB_PRINT_EX(handle, "\t", 1, mask);
11 
12 #else
13  char tab_char_buffer[FB_TAB_WIDTH+1];
14  if (new_x <= current_x) {
15  FB_PRINT_EX(handle, FB_NEWLINE, sizeof(FB_NEWLINE)-1, mask);
16  } else {
17  size_t count = new_x - current_x;
18  memset(tab_char_buffer, 32, count);
19  /* the terminating NUL shouldn't be required but it makes
20  * debugging easier */
21  tab_char_buffer[count] = 0;
22  FB_PRINT_EX(handle, tab_char_buffer, count, mask);
23  }
24 #endif
25 }
26 
27 /*:::::*/
28 void fb_PrintPadEx ( FB_FILE *handle, int mask )
29 {
30 #ifdef FB_NATIVE_TAB
31  FB_PRINT_EX(handle, "\t", 1, mask);
32 
33 #else
34  FB_FILE *tmp_handle;
35  int old_x;
36  int new_x;
37 
39 
40  tmp_handle = FB_HANDLE_DEREF(handle);
41 
42  old_x = tmp_handle->line_length + 1;
43  new_x = old_x + FB_TAB_WIDTH - 1;
44  new_x /= FB_TAB_WIDTH;
45  new_x *= FB_TAB_WIDTH;
46  new_x += 1;
47  if (tmp_handle->width!=0) {
48  unsigned dev_width = tmp_handle->width;
49  if (new_x > (dev_width - FB_TAB_WIDTH)) {
50  new_x = 1;
51  }
52  }
53  fb_hPrintPadEx(handle, mask, old_x, new_x);
54 #endif
55 }
56 
57 /*:::::*/
58 FBCALL void fb_PrintPad ( int fnum, int mask )
59 {
60  fb_PrintPadEx( FB_FILE_TO_HANDLE(fnum), mask );
61 }