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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/* Copyright (C) 1998 Chancelier Jean-Philippe */
/*
* jpc_Xloop.c :
* (1997) : Jean-Philippe Chancelier
*
*/
#include <stdio.h>
#include <stdlib.h>
#ifndef STRICT
#define STRICT
#endif
#include <windows.h>
#include "wgnuplib.h"
#include "wresource.h"
#include "wcommon.h"
#include "../machine.h"
#ifdef WITH_TK
#include "tcl.h"
extern void inittk ();
extern void flushTKEvents ();
#endif
/** do I want a scilab or an xscilab (here it means Windows ) */
int INXscilab = 0;
/** XXXX just to use zzledt1 **/
void
SetXsciOn ()
{
switch_rlgets (1);
INXscilab = 1;
#ifdef WITH_TK
inittk ();
#endif
}
int C2F (xscion) (int *i)
{
*i = INXscilab;
return (0);
}
/*************************************************
* Dealing with Events on the queue when computing in Scilab
* we also try to detect when CTRLC was activated
*************************************************/
extern int INXscilab;
extern TW textwin;
extern HWND HelpModeless; /* the modeless Help Window */
void
TextMessage1 (int ctrlflag)
{
MSG msg;
#ifdef WITH_TK
flushTKEvents ();
#endif
while (PeekMessage (&msg, 0, 0, 0, PM_NOREMOVE))
{
#ifdef WITH_TK
if (Tcl_DoOneEvent (TCL_DONT_WAIT) != 1)
{
#endif
PeekMessage (&msg, 0, 0, 0, PM_REMOVE);
if (ctrlflag == 1)
CtrlCHit (&textwin);
/** test if Modeless help exists **/
if (HelpModeless == 0 || !IsDialogMessage (HelpModeless, &msg))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
#ifdef WITH_TK
}
#endif
}
}
/** function used in wtext.c in function TextGetCh must wait for an event **/
void
TextMessage2 ()
{
MSG msg;
#ifdef WITH_TK
flushTKEvents ();
#endif
GetMessage (&msg, 0, 0, 0);
#ifdef WITH_TK
if (Tcl_DoOneEvent (TCL_DONT_WAIT) != 1)
{
#endif
/** test if Modeless help exists **/
if (HelpModeless == 0 || !IsDialogMessage (HelpModeless, &msg))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
#ifdef WITH_TK
}
#endif
}
int C2F (sxevents) ()
{
if (INXscilab == 1)
{
TextMessage1 (1);
}
return (0);
}
/**********************************************************************
* For Fortran call
**********************************************************************/
static void
strip_blank (source)
char *source;
{
char *p;
p = source;
/* look for end of string */
while (*p != '\0')
p++;
while (p != source)
{
p--;
if (*p != ' ')
break;
*p = '\0';
}
}
/**********************************************************************/
void C2F (winsci) (char *pname, int *nos, int *idisp, char *display,
long int dummy1, long int dummy2)
{
char *argv[10];
int argc = 1;
strip_blank (pname);
argv[0] = pname;
if (*idisp == 1)
{
argv[argc++] = "-display";
strip_blank (display);
argv[argc++] = display;
}
if (*nos == 1)
argv[argc++] = "-ns";
argv[argc++] = "-name";
argv[argc++] = "Scilab";
/* XXXXXX main_sci(argc,argv); */
}
void
sigblock ()
{
}
/**************************************************************************
* Command queue functions
* This function is used to store Scilab command in a queue
* ( the queue is checked in the Scilab Event Loop )
**************************************************************************/
typedef struct commandRec
{
char *command; /* command info one string two integers */
struct commandRec *next;
}
CommandRec, *CommandRecPtr;
static CommandRec *commandQueue = NULL;
/***************************************
* try to execute a command if we are at
* prompt level or add it to the end of command queue
* if flag == 1 a \n is added
***************************************/
int
scig_command_handler_none (char *command)
{
return 0;
};
static Scig_command_handler scig_command_handler = scig_command_handler_none;
Scig_command_handler
set_scig_command_handler (f)
Scig_command_handler f;
{
Scig_command_handler old = scig_command_handler;
scig_command_handler = f;
return old;
}
void
reset_scig_command_handler ()
{
scig_command_handler = scig_command_handler_none;
}
int
StoreCommand (command)
char *command;
{
return (StoreCommand1 (command, 1));
}
int
StoreCommand1 (command, flag)
char *command;
int flag;
{
CommandRec *p, *q, *r;
/* check if handler is using the command */
if (scig_command_handler (command) == 1)
return 0;
if (get_is_reading ())
{
write_scilab (command);
if (flag == 1)
write_scilab ("\n");
return 0;
}
p = (CommandRec *) malloc (sizeof (CommandRec));
if (p == (CommandRec *) 0)
{
sciprint ("send_command : No more memory \r\n");
return (1);
}
p->command = (char *) malloc ((strlen (command) + 1) * sizeof (char));
if (p->command == (char *) 0)
{
sciprint ("send_command : No more memory \r\n");
return (1);
}
strcpy (p->command, command);
p->next = NULL;
if (!commandQueue)
commandQueue = p;
else
{
q = commandQueue;
while ((r = q->next))
q = r;
q->next = p;
}
return (0);
}
/************************************************
* Gets info on the first queue element
* and remove it from the queue
************************************************/
void
GetCommand (str)
char *str;
{
if (commandQueue != NULL)
{
CommandRec *p;
p = commandQueue;
strcpy (str, p->command);
commandQueue = p->next;
FREE (p->command);
FREE (p);
}
}
/************************************************
* Checks if there's something on the
* commandQueue
************************************************/
integer C2F (ismenu) ()
{
if (commandQueue == NULL)
return (0);
else
return (1);
}
/************************************************
* menu/button info for Scilab
************************************************/
int C2F (getmen) (btn_cmd, lb, entry)
integer *entry, *lb;
char *btn_cmd;
{
if (C2F (ismenu) () == 1)
{
GetCommand (btn_cmd);
*lb = strlen (btn_cmd);
}
else
*entry = 0;
return (0);
}
|