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