1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
/* Allan CORNET */
/* INRIA 2005 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <windows.h>
#include <Winuser.h>
#include "..\version.h"
#include "wgnuplib.h"
#include "printf.h"
#include "winmain.h"
#include "wcommon.h"
#include "Messages.h"
#include "Warnings.h"
#include "Errors.h"
/*-----------------------------------------------------------------------------------*/
extern void Xputchar ();
extern int getdiary();
extern void diary_nnl(char *str,int *n);
extern BOOL IsWindowInterface(void);
extern LPTW GetTextWinScilab(void);
/*-----------------------------------------------------------------------------------*/
int MyPutCh (int ch)
{
return TextPutCh (&textwin, (BYTE) ch);
}
/*-----------------------------------------------------------------------------------*/
int MyGetCh (void)
{
return TextGetCh (&textwin);
}
/*-----------------------------------------------------------------------------------*/
char * MyFGetS (char *str, unsigned int size, FILE * file)
{
char FAR *p;
if (isterm (file))
{
p = TextGetS (&textwin, str, size);
if (p != (char FAR *) NULL)
return str;
return (char *) NULL;
}
return fgets (str, size, file);
}
/*-----------------------------------------------------------------------------------*/
int MyFPutC (int ch, FILE * file)
{
if (isterm (file))
{
MyPutCh ((BYTE) ch);
TextMessage ();
return ch;
}
return fputc (ch, file);
}
/*-----------------------------------------------------------------------------------*/
int MyFPutS (char *str, FILE * file)
{
if (isterm (file))
{
TextPutS (&textwin, str);
TextMessage ();
return (*str); /* different from Borland library */
}
return fputs (str, file);
}
/*-----------------------------------------------------------------------------------*/
/** synonym for scilab but without the \n **/
void Scistring (char *str)
{
int i;
C2F (xscion) (&i);
if (i == 0)
fprintf (stdout, "%s", str);
else
{
TextPutS (&textwin, str);
MyPutCh ('\n');
}
}
/*-----------------------------------------------------------------------------------*/
void sciprint (char *fmt,...)
{
int i, count, lstr;
char buf[MAXPRINTF];
va_list args;
va_start (args, fmt);
/* next three lines added for diary SS */
count = vsprintf (buf, fmt, args);
lstr = strlen (buf);
C2F (xscion) (&i);
if (i == 0)
{
/*count = vfprintf(stdout, fmt, args ); */
printf ("%s", buf);
}
else
{
/*count = vsprintf(buf,fmt,args); SS */
TextPutS (&textwin, buf);
}
if (getdiary()) diary_nnl(buf,&lstr);
va_end (args);
/** return count; **/
}
/*-----------------------------------------------------------------------------------*/
/*---------------------------------------------------
* the same but no diary record
*---------------------------------------------------*/
void sciprint_nd (char *fmt,...)
{
int i, count, lstr;
char buf[MAXPRINTF];
va_list args;
va_start (args, fmt);
/* next three lines added for diary SS */
count = vsprintf (buf, fmt, args);
lstr = strlen (buf);
C2F (xscion) (&i);
if (i == 0)
{
/*count = vfprintf(stdout, fmt, args ); */
printf ("%s", buf);
}
else
{
/*count = vsprintf(buf,fmt,args); SS */
TextPutS (&textwin, buf);
}
va_end (args);
/** return count; **/
}
/*-----------------------------------------------------------------------------------*/
/*---------------------------------------------------
* as sciprint but with an added first argument
* which is ignored (used in do_printf)
*---------------------------------------------------*/
int sciprint2 (int iv, char *fmt,...)
{
int i, count,lstr;
va_list ap;
char s_buf[1024];
va_start (ap, fmt);
/* next three lines added for diary SS */
count = vsprintf (s_buf, fmt, ap);
lstr = strlen (s_buf);
C2F (xscion) (&i);
if (i == 0)
{
count = vfprintf (stdout, fmt, ap);
}
else
{
/* count = vsprintf (s_buf, fmt, ap); SS */
TextPutS (&textwin, s_buf);
}
if (getdiary()) diary_nnl(s_buf,&lstr);
va_end (ap);
return count;
}
/*-----------------------------------------------------------------------------------*/
size_t MyFWrite (const void *ptr, size_t size, size_t n, FILE * file)
{
if (isterm (file))
{
int i;
for (i = 0; i < (int) n; i++)
TextPutCh (&textwin, ((BYTE *) ptr)[i]);
TextMessage ();
return n;
}
return fwrite (ptr, size, n, file);
}
/*-----------------------------------------------------------------------------------*/
size_t MyFRead (void *ptr, size_t size, size_t n, FILE * file)
{
if (isterm (file))
{
int i;
for (i = 0; i < (int) n; i++)
((BYTE *) ptr)[i] = TextGetChE (&textwin);
TextMessage ();
return n;
}
return fread (ptr, size, n, file);
}
/*-----------------------------------------------------------------------------------*/
/* I/O Function for scilab : this function are used when Xscilab is on */
/*-----------------------------------------------------------------------------------*/
void Xputchar (char c)
{
MyPutCh ((int) c);
}
/*-----------------------------------------------------------------------------------*/
void Xputstring (char *str,int n)
{
int i;
for (i = 0; i < n; i++) Xputchar (str[i]);
}
/*-----------------------------------------------------------------------------------*/
void C2F (xscisncr) (char *str,integer *n,integer dummy)
{
Xputstring (str, *n);
}
/*-----------------------------------------------------------------------------------*/
void C2F (xscistring) (char *str,int *n,long int dummy)
{
Xputstring (str, *n);
Xputstring ("\r\n", 2);
}
/*-----------------------------------------------------------------------------------*/
void C2F (xscimore) (int *n)
{
int n1, ln;
*n = 0;
ln = strlen (MORESTR);
Xputstring (MORESTR, ln);
n1 = TextGetCh (&textwin);
if (n1 == 'n')
{
*n = 1;
Xputstring ("\r\n", 2);
}
else
{
if (IsWindowInterface())
{
#define NOTEXT 0xF0
int X=0,Y=0;
int i = 0;
LPTW lptw=GetTextWinScilab();
X=lptw->CursorPos.x-strlen(MORESTR);
Y=lptw->CursorPos.y;
if (Y>0)
{
i=(Y)*lptw->ScreenSize.x;
_fmemset(lptw->ScreenBuffer + i, ' ', lptw->ScreenSize.x);
_fmemset(lptw->AttrBuffer + i, NOTEXT,lptw->ScreenSize.x);
TextGotoXY (lptw, X,Y);
InvalidateRect (lptw->hWndText, NULL, TRUE);
}
}
}
TextMessage ();
}
/*-----------------------------------------------------------------------------------*/
/* I/O Function for C routines : test for xscion */
void Scisncr (char *str)
{
int i;
integer lstr;
C2F (xscion) (&i);
if (i == 0)
fprintf (stdout, "%s", str);
else
{
lstr = strlen (str);
C2F (xscisncr) (str, &lstr, 0L);
}
}
/*-----------------------------------------------------------------------------------*/
|