get rid of integer type (=> int) ... really useles except for Fortran fan (but just...
[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  * Copyright (C) 2008-2008 - INRIA - Bruno JOFRET
6  *
7  * This file must be used under the terms of the CeCILL.
8  * This source file is licensed as described in the file COPYING, which
9  * you should have received as part of this distribution.  The terms
10  * are also available at
11  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12  *
13  */
14
15 /*--------------------------------------------------------------------------*/
16 /* sciprint_full function */
17 /*--------------------------------------------------------------------------*/
18 /* sciprint geared towards long strings (>MAXPRINTF) */
19 /* the long string is splitted in elements of length equal to the number of columns  */
20 /* from lines()                                                                      */
21 /*--------------------------------------------------------------------------*/
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "sciprint_full.h"
26 #include "sciprint.h"
27 #include "MALLOC.h"
28 #include "localization.h"
29 #include "../../shell/includes/scilines.h"
30 /*--------------------------------------------------------------------------*/
31 #ifdef _MSC_VER
32 #define vsnprintf _vsnprintf
33 #endif
34 /*--------------------------------------------------------------------------*/
35 /* MAXCHARSSCIPRINT_FULL is for sciprint_full - more than this gets truncated */
36 #define MAXCHARSSCIPRINT_FULL 5000
37 /*--------------------------------------------------------------------------*/
38 void sciprint_full(char *fmt,...)
39 {
40         int lstr;
41         va_list ap;
42         char *s_buf=NULL;
43         char *split_s_buf=NULL;
44         int count=0;
45         int p_s=0;
46         static int colwidth;
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 = getColumnsSize();
57
58         split_s_buf=MALLOC(sizeof(char)*(colwidth+1));
59         if (split_s_buf == (char *) 0)
60         {
61                 sciprint(_("%s: No more memory.\n"),"sciprint_full");
62                 return;
63         }
64
65         va_start(ap,fmt);
66
67 #if defined(linux) || defined(_MSC_VER)
68         count = vsnprintf (s_buf,MAXCHARSSCIPRINT_FULL-1, fmt, ap );
69         if (count == -1)
70         {
71                 s_buf[MAXCHARSSCIPRINT_FULL-1]='\0';
72         }
73 #else
74         (void )vsprintf(s_buf, fmt, ap );
75 #endif
76
77         va_end(ap);
78
79         lstr=(int) strlen(s_buf);
80
81         if (lstr<colwidth)
82         {
83                 sciprint("%s",s_buf);
84         }
85         else
86         {
87                 strncpy(split_s_buf,s_buf+p_s,colwidth-1);
88                 split_s_buf[colwidth]='\0';
89                 p_s=p_s+colwidth-1;
90                 sciprint("%s",split_s_buf);
91                 sciprint("\n");
92                 while (p_s+colwidth-1<(int)lstr)
93                 {
94                         strncpy(split_s_buf,s_buf+p_s,colwidth-1);
95                         split_s_buf[colwidth]='\0';
96                         p_s=p_s+colwidth-1;
97                         sciprint(_("  (cont'd) %s\n"),split_s_buf);
98                 }
99                 strncpy(split_s_buf,s_buf+p_s,lstr-p_s);
100                 split_s_buf[lstr-p_s]='\0';
101                 sciprint(_("     (end) %s\n"),split_s_buf);
102         }
103
104         if (s_buf){FREE(s_buf);s_buf=NULL;}
105         if (split_s_buf){FREE(split_s_buf);split_s_buf=NULL;}
106
107 }
108 /*--------------------------------------------------------------------------*/