3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) Francois Vogel
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
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 */
20 /*--------------------------------------------------------------------------*/
24 #include "sciprint_full.h"
27 #include "localization.h"
28 #include "../../shell/includes/scilines.h"
29 /*--------------------------------------------------------------------------*/
31 #define vsnprintf _vsnprintf
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,...)
42 char *split_s_buf=NULL;
45 static integer colwidth;
48 s_buf=MALLOC(sizeof(char)*(MAXCHARSSCIPRINT_FULL+1));
49 if (s_buf == (char *) 0)
51 sciprint(_("%s: No more memory.\n"),"sciprint_full");
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;}
66 split_s_buf=MALLOC(sizeof(char)*(colwidth+1));
67 if (split_s_buf == (char *) 0)
69 sciprint(_("%s: No more memory.\n"),"sciprint_full");
75 #if defined(linux) || defined(_MSC_VER)
76 count = vsnprintf (s_buf,MAXCHARSSCIPRINT_FULL-1, fmt, ap );
79 s_buf[MAXCHARSSCIPRINT_FULL-1]='\0';
82 (void )vsprintf(s_buf, fmt, ap );
87 lstr=(integer)strlen(s_buf);
95 strncpy(split_s_buf,s_buf+p_s,colwidth-1);
96 split_s_buf[colwidth]='\0';
98 sciprint("%s",split_s_buf);
100 while (p_s+colwidth-1<(int)lstr)
102 strncpy(split_s_buf,s_buf+p_s,colwidth-1);
103 split_s_buf[colwidth]='\0';
105 MSG=_(" (cont'd) %s");
108 sciprint(MSG,split_s_buf);
111 if (MSG) {FREE(MSG);MSG=NULL;}
113 strncpy(split_s_buf,s_buf+p_s,lstr-p_s);
114 split_s_buf[lstr-p_s]='\0';
118 sciprint(MSG,split_s_buf);
121 if (MSG) {FREE(MSG);MSG=NULL;}
124 if (s_buf){FREE(s_buf);s_buf=NULL;}
125 if (split_s_buf){FREE(split_s_buf);split_s_buf=NULL;}
128 /*--------------------------------------------------------------------------*/