FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot/src/gpexecute.c at 5.5 · gnuplot/gnuplot · GitHub
gnuplot
gnuplot
Repository navigation
Code
Pull requests
2
(2)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot
/
src
/
gpexecute.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
270 lines (246 loc) · 7.26 KB
Breadcrumbs
gnuplot
/
src
/
gpexecute.c
Copy path
File metadata and controls
270 lines (246 loc) · 7.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/* GNUPLOT - gpexecute.c */
/*[
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/*
* AUTHORS
*
* Original Software (October 1999 - January 2000):
* Pieter-Tjerk de Boer <ptdeboer@cs.utwente.nl>
* Petr Mikulik <mikulik@physics.muni.cz>
* Johannes Zellner <johannes@zellner.org>
*/
#include
"gpexecute.h"
#include
"stdfn.h"
#ifdef
OS2_IPC
# include
<stdio.h>
#endif
#ifdef
PIPE_IPC
# include
<unistd.h>
/* open(), write() */
# include
<stdlib.h>
# include
<assert.h>
# include
<errno.h>
int
pipe_died
=
0
;
#endif
/* PIPE_IPC */
#ifdef
WIN_IPC
# include
<stdlib.h>
# include
<assert.h>
# include
"mouse.h"
/* do_event() */
#endif
#if
defined(
PIPE_IPC
)
/* || defined(WIN_IPC) */
static
gpe_fifo_t
*
gpe_init
(
void
);
static
void
gpe_push
(
gpe_fifo_t
*
*
base
,
struct
gp_event_t
*
ge
);
static
struct
gp_event_t
*
gpe_front
(
gpe_fifo_t
*
*
base
);
static
int
gpe_pop
(
gpe_fifo_t
*
*
base
);
#endif
/* PIPE_IPC || WIN_IPC */
/*
* gp_execute functions
*/
#ifdef
OS2_IPC
char
mouseShareMemName
[
40
];
PVOID
input_from_PM_Terminal
;
/* pointer to shared memory for storing the command to be executed */
HEV
semInputReady
=
0
;
/* handle to event semaphore (post an event to gnuplot that the shared
memory contains a command to be executed) */
BOOL
pausing
=
FALSE;
/* avoid passing data back to gnuplot in `pause' mode */
/* gplt_x11.c */
ULONG
ppidGnu
=
0
;
/*
* Let the command in the shared memory be executed.
*/
void
gp_post_shared_mem
()
{
APIRET
rc
;
if
(
semInputReady
==
0
) {
/* but it must be open for the first time */
char
semInputReadyName
[
40
];
sprintf
(
semInputReadyName
,
"\\SEM32\\GP%i_Input_Ready"
, (
int
)
ppidGnu
);
DosOpenEventSem
(
semInputReadyName
,
&
semInputReady
);
}
rc
=
DosPostEventSem
(
semInputReady
);
DosSleep
(
10
);
/* dirty trick: wait a little bit; otherwise problems to
* distinguish mouse button down and up, for instance
* (info sent to shared memory was too fast; maybe a blocking
* semaphore would help, but no fun to implement it...)
*/
}
/* Copy the command (given by the input string) to the shared memory
* and let gnuplot execute it.
* If this routine is called during a 'pause', then the command is
* ignored (shared memory is cleared). Needed for actions launched by a
* hotkey.
* Firstly, the command is copied from shared memory to clipboard
* if this option is set on.
* Secondly, gnuplot is informed that shared memory contains a command
* by posting semInputReady event semaphore.
*
* OS/2 specific: if (!s), then the command has been already sprintf'ed to
* the shared memory.
*/
void
gp_execute
(
char
*
s
)
{
if
(
input_from_PM_Terminal
==
NULL
)
return
;
if
(
s
)
/* copy the command to shared memory */
strcpy
(
input_from_PM_Terminal
,
s
);
if
(((
char
*
)
input_from_PM_Terminal
)[
0
]
==
0
)
return
;
#if
0
if
(
pausing
) {
/* no communication during pause */
/* DosBeep(440,111); */
((
char
*
)
input_from_PM_Terminal
)[
0
]
=
0
;
return
;
}
#endif
gp_post_shared_mem
();
}
#endif
/* OS2_IPC */
#if
defined(
PIPE_IPC
)
/* || defined(WIN_IPC) */
int
buffered_output_pending
=
0
;
static
gpe_fifo_t
*
gpe_init
()
{
gpe_fifo_t
*
base
=
malloc
(
sizeof
(
gpe_fifo_t
));
/* fprintf(stderr, "(gpe_init) \n"); */
assert
(
base
);
base
->
next
=
(
gpe_fifo_t
*
)
0
;
base
->
prev
=
(
gpe_fifo_t
*
)
0
;
return
base
;
}
static
void
gpe_push
(
gpe_fifo_t
*
*
base
,
struct
gp_event_t
*
ge
)
{
buffered_output_pending
++
;
if
((
*
base
)
->
prev
) {
gpe_fifo_t
*
new
=
malloc
(
sizeof
(
gpe_fifo_t
));
/* fprintf(stderr, "(gpe_push) \n"); */
assert
(
new
);
(
*
base
)
->
prev
->
next
=
new
;
new
->
prev
=
(
*
base
)
->
prev
;
(
*
base
)
->
prev
=
new
;
new
->
next
=
(
gpe_fifo_t
*
)
0
;
}
else
{
/* first element, this is the case, if the pipe isn't clogged */
(
*
base
)
->
next
=
(
gpe_fifo_t
*
)
0
;
/* tail */
(
*
base
)
->
prev
=
(
*
base
);
/* points to itself */
}
(
*
base
)
->
prev
->
ge
=
*
ge
;
}
static
struct
gp_event_t
*
gpe_front
(
gpe_fifo_t
*
*
base
)
{
return
&
((
*
base
)
->
ge
);
}
static
int
gpe_pop
(
gpe_fifo_t
*
*
base
)
{
buffered_output_pending
--
;
if
((
*
base
)
->
prev
==
(
*
base
)) {
(
*
base
)
->
prev
=
(
gpe_fifo_t
*
)
0
;
return
0
;
}
else
{
gpe_fifo_t
*
save
=
*
base
;
/* fprintf(stderr, "(gpe_pop) \n"); */
(
*
base
)
->
next
->
prev
=
(
*
base
)
->
prev
;
(
*
base
)
=
(
*
base
)
->
next
;
free
(
save
);
return
1
;
}
}
#endif
/* PIPE_IPC || WIN_IPC */
#ifdef
PIPE_IPC
RETSIGTYPE
pipe_died_handler
(
int
signum
)
{
(
void
)
signum
;
/* avoid -Wunused warning. */
/* fprintf(stderr, "\n*******(pipe_died_handler)*******\n"); */
close
(
1
);
pipe_died
=
1
;
}
#endif
/* PIPE_IPC */
void
gp_exec_event
(
char
type
,
int
mx
,
int
my
,
int
par1
,
int
par2
,
int
winid
)
{
struct
gp_event_t
ge
;
#if
defined(
PIPE_IPC
)
/* || defined(WIN_IPC) */
static
struct
gpe_fifo_t
*
base
=
(
gpe_fifo_t
*
)
0
;
#endif
ge
.
type
=
type
;
ge
.
mx
=
mx
;
ge
.
my
=
my
;
ge
.
par1
=
par1
;
ge
.
par2
=
par2
;
ge
.
winid
=
winid
;
#ifdef
PIPE_IPC
if
(
pipe_died
)
return
;
#endif
/* HBB 20010218: commented this out for WIN_IPC. We don't actually use the stack,
* there */
#if
defined(
PIPE_IPC
)
/* || defined(WIN_IPC) */
if
(!
base
) {
base
=
gpe_init
();
}
if
(
GE_pending
!=
type
) {
gpe_push
(
&
base
,
&
ge
);
}
else
if
(!
buffered_output_pending
) {
return
;
}
#endif
#ifdef
WIN_IPC
do_event
(
&
ge
);
return
;
#endif
#ifdef
PIPE_IPC
do
{
int
status
=
write
(
1
,
gpe_front
(
&
base
),
sizeof
(
ge
));
if
(
-1
==
status
) {
switch
(
errno
) {
case
EAGAIN
:
/* do nothing */
FPRINTF
((
stderr
,
"(gp_exec_event) EAGAIN\n"
));
break
;
default
:
FPRINTF
((
stderr
,
"(gp_exec_event) errno = %d\n"
,
errno
));
break
;
}
break
;
}
}
while
(
gpe_pop
(
&
base
));
#endif
/* PIPE_IPC */
#ifdef
OS2_IPC
/* OS/2 communication via shared memory; coded according to gp_execute() */
if
(
input_from_PM_Terminal
==
NULL
)
return
;
((
char
*
)
input_from_PM_Terminal
)[
0
]
=
'%'
;
/* flag that passing gp_event_t */
memcpy
(((
char
*
)
input_from_PM_Terminal
)
+
1
,
&
ge
,
sizeof
(
ge
));
/* copy the command to shared memory */
gp_post_shared_mem
();
#endif
}
Back
|
FazBrowse Home
|
New Git URL