Mercurial > hg > octave-nkf
annotate scripts/plot/util/private/__gnuplot_ginput__.m @ 20410:d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
* NEWS: Announce switch from decimal to octal MODE for mkfifo.
* file-io.cc (convert): Add a FIXME note that this function is repeated in
* syscalls.cc.
* syscalls.cc (convert): New function to convert from one base to another.
* syscalls.cc (Fmkfifo): Change docstring to note that MODE argument is now
octal. Convert MODE from octal to decimal before calling octave_mkfifo().
Add BIST tests.
* __gnuplot_get_var__.m, __gnuplot_ginput__.m: Change instances of MODE
argument in m-files from decimal to octal.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 17 May 2015 10:04:08 -0700 |
parents | 9fc020886ae9 |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19470
diff
changeset
|
1 ## Copyright (C) 2004-2015 Petr Mikulik |
7673 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
19 ## -*- texinfo -*- |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{x}, @var{y}, @var{buttons}] =} __gnuplot_ginput__ (@var{f}, @var{n}) |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
21 ## Undocumented internal function. |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
22 ## @end deftypefn |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
23 |
7673 | 24 ## This is ginput.m implementation for gnuplot and X11. |
25 ## It requires gnuplot 4.1 and later. | |
26 | |
27 ## This file initially bore the copyright statement | |
28 ## Petr Mikulik | |
29 ## History: June 2006; August 2005; June 2004; April 2004 | |
30 ## License: public domain | |
31 | |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
32 function [x, y, button] = __gnuplot_ginput__ (f, n) |
7673 | 33 |
16108
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
34 if (compare_versions (__gnuplot_version__ (), "4.0", "<=")) |
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
35 error ("ginput: version %s of gnuplot not supported", gnuplot_version ()); |
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
36 endif |
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
37 |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
38 ostream = get (f, "__plot_stream__"); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
39 if (numel (ostream) < 1) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
40 error ("ginput: stream to gnuplot not open"); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
41 elseif (ispc ()) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
42 if (numel (ostream) == 1) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
43 error ("ginput: Need mkfifo that is not implemented under Windows"); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
44 endif |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
45 use_mkfifo = false; |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
46 istream = ostream(2); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
47 ostream = ostream(1); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
48 else |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
49 use_mkfifo = true; |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
50 ostream = ostream(1); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
51 endif |
7673 | 52 |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
53 if (nargin == 1) |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
54 x = zeros (100, 1); |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
55 y = zeros (100, 1); |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
56 button = zeros (100, 1); |
7673 | 57 else |
58 x = zeros (n, 1); | |
59 y = zeros (n, 1); | |
60 button = zeros (n, 1); | |
61 endif | |
62 | |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
63 if (use_mkfifo) |
19470
6ca096827123
Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents:
19031
diff
changeset
|
64 gpin_name = tempname (); |
7673 | 65 |
20410
d9f35ceff9e1
Change mkfifo to use an octal argument for MODE (bug #45054).
Rik <rik@octave.org>
parents:
20038
diff
changeset
|
66 [err, msg] = mkfifo (gpin_name, 600); |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
67 |
16108
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
68 if (err) |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
69 error ("ginput: Can not open fifo (%s)", msg); |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
70 endif |
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
71 endif |
7673 | 72 |
73 unwind_protect | |
74 | |
75 k = 0; | |
76 while (true) | |
77 k++; | |
78 | |
79 ## Notes: MOUSE_* can be undefined if user closes gnuplot by "q" | |
80 ## or Alt-F4. Further, this abrupt close also requires the leading | |
81 ## "\n" on the next line. | |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
82 if (use_mkfifo) |
10549 | 83 fprintf (ostream, "set print \"%s\";\n", gpin_name); |
84 fflush (ostream); | |
85 [gpin, err] = fopen (gpin_name, "r"); | |
16108
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
86 if (err) |
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
87 error ("ginput: Can not open FIFO (%s)", msg); |
10549 | 88 endif |
89 fputs (ostream, "pause mouse any;\n\n"); | |
90 fputs (ostream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) print MOUSE_X, MOUSE_Y, MOUSE_KEY; else print \"0 0 -1\"\n"); | |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
91 |
10549 | 92 ## Close output file, to force it to be flushed |
93 fputs (ostream, "set print;\n"); | |
94 fflush (ostream); | |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
95 |
10549 | 96 ## Now read from fifo. |
97 [x(k), y(k), button(k), count] = fscanf (gpin, "%f %f %d", "C"); | |
98 fclose (gpin); | |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
99 else |
16108
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
100 fputs (ostream, "set print \"-\";\n"); |
10549 | 101 fflush (ostream); |
102 fputs (ostream, "pause mouse any;\n\n"); | |
19031
dd34502e5c3c
Use button value 1 for mouse button keypress 1063 (Bug #42489)
John Donoghue
parents:
17744
diff
changeset
|
103 fputs (ostream, "\nif (exists(\"MOUSE_KEY\") && exists(\"MOUSE_X\")) key = (MOUSE_KEY==1063 ? 1 : MOUSE_KEY); print \"OCTAVE: \", MOUSE_X, MOUSE_Y, key; else print \"0 0 -1\"\n"); |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
104 |
10549 | 105 ## Close output file, to force it to be flushed |
106 fputs (ostream, "set print;\n"); | |
107 fflush (ostream); | |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
108 |
10549 | 109 str = {}; |
110 while (isempty (str)) | |
16108
3cce6b4e0f7c
Update gnuplot plotting scripts for faster or more modern synta
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
111 str = fread (istream, "*char")'; |
10549 | 112 if (isempty (str)) |
113 sleep (0.05); | |
114 else | |
12462
e4dbfe3019b1
Use PCRE regular expressions throughout Octave.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
115 str = regexp (str, 'OCTAVE:\s+[-+.\d]+\s+[-+.\d]+\s+\d*', 'match'); |
10549 | 116 endif |
117 fclear (istream); | |
118 endwhile | |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
119 [x(k), y(k), button(k), count] = ... |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
120 sscanf (str{end}(8:end), "%f %f %d", "C"); |
7674
52d8d50e74c1
Add gtext, waitforbuttonpress. Attempt to get ginput working under windows
David Bateman <dbateman@free.fr>
parents:
7673
diff
changeset
|
121 endif |
7673 | 122 |
123 if ([x(k), y(k), button(k)] == [0, 0, -1]) | |
10549 | 124 ## Mousing not active (no plot yet). |
125 break; | |
7673 | 126 endif |
127 | |
16786
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
128 if (button(k) == 0x0D || button(k) == 0x0A) |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
129 ## Stop when hitting a RETURN or ENTER key. |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
130 x(k:end) = []; |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
131 y(k:end) = []; |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
132 button(k:end) = []; |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
133 break; |
7673 | 134 endif |
16786
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
135 if (nargin > 1 && k == n) |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
136 ## Input argument n was given, stop when k == n. |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
137 break; |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
138 endif |
0e75f5412f1e
__gnuplot_ginput__.m: Correctly stop early if <RETURN> key pressed (bug #32178).
Rik <rik@octave.org>
parents:
16108
diff
changeset
|
139 |
7673 | 140 endwhile |
141 | |
142 unwind_protect_cleanup | |
7680
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
143 if (use_mkfifo) |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
144 unlink (gpin_name); |
a0ec02774303
Use popen2 for communication with gnuplot
David Bateman <dbateman@free.fr>
parents:
7674
diff
changeset
|
145 endif |
7673 | 146 end_unwind_protect |
147 | |
148 endfunction | |
149 |