00001
00002
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 #include <stdarg.h>
00007 #include <windows.h>
00008 #include <windowsx.h>
00009 #include <Winuser.h>
00010 #include "wgnuplib.h"
00011 #include "printf.h"
00012 #include "winmain.h"
00013 #include "wcommon.h"
00014
00015 #include "Messages.h"
00016 #include "Warnings.h"
00017 #include "Errors.h"
00018
00019
00020
00021 extern int PutString(char *Str);
00022 extern void Xputchar ();
00023 extern int getdiary();
00024 extern void diary_nnl(char *str,int *n);
00025 extern BOOL IsWindowInterface(void);
00026 extern LPTW GetTextWinScilab(void);
00027
00028 int MyPutCh (int ch)
00029 {
00030 char Str[1];
00031 Str[0]=ch;
00032
00033 return TextPutCh (&textwin, (BYTE) ch);
00034 }
00035
00036 int MyGetCh (void)
00037 {
00038 return TextGetCh (&textwin);
00039 }
00040
00041 char * MyFGetS (char *str, unsigned int size, FILE * file)
00042 {
00043 char FAR *p;
00044 if (isterm (file))
00045 {
00046 p = TextGetS (&textwin, str, size);
00047 if (p != (char FAR *) NULL)
00048 return str;
00049 return (char *) NULL;
00050 }
00051 return fgets (str, size, file);
00052 }
00053
00054 int MyFPutC (int ch, FILE * file)
00055 {
00056 if (isterm (file))
00057 {
00058 MyPutCh ((BYTE) ch);
00059 TextMessage ();
00060 return ch;
00061 }
00062 return fputc (ch, file);
00063 }
00064
00065 int MyFPutS (char *str, FILE * file)
00066 {
00067 if (isterm (file))
00068 {
00069 TextPutS (&textwin, str);
00070 PutString(str);
00071
00072 TextMessage ();
00073 return (*str);
00074 }
00075 return fputs (str, file);
00076 }
00077
00079 void Scistring (char *str)
00080 {
00081 int i;
00082 C2F (xscion) (&i);
00083 if (i == 0)
00084 fprintf (stdout, "%s", str);
00085 else
00086 {
00087 TextPutS (&textwin, str);
00088 PutString(str);
00089 PutString("\n");
00090 MyPutCh ('\n');
00091 }
00092 }
00093
00094
00095
00096
00097 void sciprint_nd (char *fmt,...)
00098 {
00099 int i, count, lstr;
00100 char buf[MAXPRINTF];
00101 va_list args;
00102 va_start (args, fmt);
00103
00104
00105 count = _vsnprintf (buf,MAXPRINTF-1, fmt, args);
00106 if (count == -1)
00107 {
00108 buf[MAXPRINTF-1]='\0';
00109 }
00110 lstr = strlen (buf);
00111
00112 C2F (xscion) (&i);
00113 if (i == 0)
00114 {
00115
00116 printf ("%s", buf);
00117 }
00118 else
00119 {
00120
00121 TextPutS (&textwin, buf);
00122 PutString(buf);
00123 }
00124 va_end (args);
00126 }
00127
00128 size_t MyFWrite (const void *ptr, size_t size, size_t n, FILE * file)
00129 {
00130 if (isterm (file))
00131 {
00132 int i;
00133 for (i = 0; i < (int) n; i++)
00134 TextPutCh (&textwin, ((BYTE *) ptr)[i]);
00135 TextMessage ();
00136 return n;
00137 }
00138 return fwrite (ptr, size, n, file);
00139 }
00140
00141 size_t MyFRead (void *ptr, size_t size, size_t n, FILE * file)
00142 {
00143 if (isterm (file))
00144 {
00145 int i;
00146 for (i = 0; i < (int) n; i++)
00147 ((BYTE *) ptr)[i] = TextGetChE (&textwin);
00148 TextMessage ();
00149 return n;
00150 }
00151 return fread (ptr, size, n, file);
00152 }
00153
00154
00155
00156 void Xputchar (char c)
00157 {
00158 MyPutCh ((int) c);
00159
00160 }
00161
00162 void Xputstring (char *str,int n)
00163 {
00164 int i;
00165
00166 PutString(str);
00167 for (i = 0; i < n; i++) Xputchar (str[i]);
00168 }
00169
00170 void C2F (xscisncr) (char *str,integer *n,integer dummy)
00171 {
00172 Xputstring (str, *n);
00173 }
00174
00175 void C2F (xscistring) (char *str,int *n,long int dummy)
00176 {
00177 Xputstring (str, *n);
00178 Xputstring ("\r\n", 2);
00179 }
00180
00181 void C2F (xscimore) (int *n)
00182 {
00183 int n1, ln;
00184 *n = 0;
00185 ln = strlen (MORESTR);
00186 Xputstring (MORESTR, ln);
00187 n1 = TextGetCh (&textwin);
00188 if (n1 == 'n')
00189 {
00190 *n = 1;
00191 Xputstring ("\r\n", 2);
00192 }
00193 else
00194 {
00195 if (IsWindowInterface())
00196 {
00197 #define NOTEXT 0xF0
00198 int X=0,Y=0;
00199 int i = 0;
00200 LPTW lptw=GetTextWinScilab();
00201
00202 X=lptw->CursorPos.x-strlen(MORESTR);
00203 Y=lptw->CursorPos.y;
00204 if (Y>0)
00205 {
00206 i=(Y)*lptw->ScreenSize.x;
00207
00208 _fmemset(lptw->ScreenBuffer + i, ' ', lptw->ScreenSize.x);
00209 _fmemset(lptw->AttrBuffer + i, NOTEXT,lptw->ScreenSize.x);
00210
00211 TextGotoXY (lptw, X,Y);
00212 InvalidateRect (lptw->hWndText, NULL, TRUE);
00213 }
00214 }
00215
00216 }
00217
00218 TextMessage ();
00219 }
00220
00221
00222 void Scisncr (char *str)
00223 {
00224 int i;
00225 integer lstr;
00226 C2F (xscion) (&i);
00227 if (i == 0)
00228 fprintf (stdout, "%s", str);
00229 else
00230 {
00231 lstr = strlen (str);
00232 C2F (xscisncr) (str, &lstr, 0L);
00233 }
00234 }
00235