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