Update of localization ...
[scilab.git] / scilab / modules / output_stream / src / c / sciprint_full.c
1 /*--------------------------------------------------------------------------*/
2 /* Francois VOGEL  sciprint_full function */
3 /*--------------------------------------------------------------------------*/
4 /* sciprint geared towards long strings (>MAXPRINTF) */
5 /* the long string is splitted in elements of length equal to the number of columns  */
6 /* from lines()                                                                      */
7 /*--------------------------------------------------------------------------*/
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "sciprint_full.h"
12 #include "sciprint.h"
13 #include "MALLOC.h"
14 #include "localization.h"
15 #include "../../shell/includes/scilines.h"
16 /*--------------------------------------------------------------------------*/
17 #ifdef _MSC_VER
18 #define vsnprintf _vsnprintf
19 #endif
20 /*--------------------------------------------------------------------------*/
21 /* MAXCHARSSCIPRINT_FULL is for sciprint_full - more than this gets truncated */
22 #define MAXCHARSSCIPRINT_FULL 5000  
23 /*--------------------------------------------------------------------------*/
24 void sciprint_full(char *fmt,...) 
25 {
26         integer lstr;
27         va_list ap;
28         char *s_buf=NULL;
29         char *split_s_buf=NULL;
30         int count=0;
31         int p_s=0;
32         static integer colwidth;
33         char *MSG;
34
35         s_buf=MALLOC(sizeof(char)*(MAXCHARSSCIPRINT_FULL+1));
36         if (s_buf == (char *) 0)
37         {
38                 sciprint(_("sciprint_full : No more memory.\n"));
39                 return;
40         }
41
42         /* number of columns as set by command lines() */
43         colwidth = getLinesSize();
44         /* clamp to a minimum: value is arbitrary */
45         if (colwidth < 20) {colwidth=20;}
46         /* clamp to a maximum: value is selected so that each line fits in a single console line */
47         /* this is needed because computation of the lines() value in ON_WND_TEXT_WM_SIZE is not */
48         /* consistent with the limit before a carriage return occurs in TextPutStr - this latter */
49         /* limit uses lptw->ScreenSize, which is set to x=120,y=80 at init and apparently never  */
50         /* changed on window resizing                                                            */
51         if (colwidth > 109) {colwidth=109;}
52
53         split_s_buf=MALLOC(sizeof(char)*(colwidth+1));
54         if (split_s_buf == (char *) 0)
55         {
56                 sciprint(_("sciprint_full : No more memory.\n"));
57                 return;
58         }
59
60         va_start(ap,fmt);
61
62 #if defined(linux) || defined(_MSC_VER)
63         count = vsnprintf (s_buf,MAXCHARSSCIPRINT_FULL-1, fmt, ap );
64         if (count == -1)
65         {
66                 s_buf[MAXCHARSSCIPRINT_FULL-1]='\0';
67         }
68 #else
69         (void )vsprintf(s_buf, fmt, ap );
70 #endif
71
72         va_end(ap);
73
74         lstr=(integer)strlen(s_buf);
75
76         if (lstr<colwidth)
77         {
78                 sciprint("%s",s_buf);
79         } 
80         else 
81         {
82                 strncpy(split_s_buf,s_buf+p_s,colwidth-1);
83                 split_s_buf[colwidth]='\0';
84                 p_s=p_s+colwidth-1;
85                 sciprint("%s",split_s_buf);
86                 sciprint("\n");
87                 while (p_s+colwidth-1<(int)lstr) 
88                 {
89                         strncpy(split_s_buf,s_buf+p_s,colwidth-1);
90                         split_s_buf[colwidth]='\0';
91                         p_s=p_s+colwidth-1;
92                         MSG=_("  (cont'd) %s");
93                         if (MSG)
94                         {
95                                 sciprint(MSG,split_s_buf);
96                                 sciprint("\n");
97                         }
98                         if (MSG) {FREE(MSG);MSG=NULL;}
99                 }
100                 strncpy(split_s_buf,s_buf+p_s,lstr-p_s);
101                 split_s_buf[lstr-p_s]='\0';
102                 MSG=_("     (end) %s");
103                 if (MSG)
104                 {
105                         sciprint(MSG,split_s_buf);
106                         sciprint("\n");
107                 }
108                 if (MSG) {FREE(MSG);MSG=NULL;}
109         }
110
111         if (s_buf){FREE(s_buf);s_buf=NULL;}
112         if (split_s_buf){FREE(split_s_buf);split_s_buf=NULL;}
113
114 }
115 /*--------------------------------------------------------------------------*/