annotate scripts/web/web.m @ 33639:65b1cf6aa60a bytecode-interpreter tip

maint: Merge default to bytecode-interpreter
author Arun Giridhar <arungiridhar@gmail.com>
date Mon, 03 Jun 2024 14:38:47 -0400
parents 2e484f9f1f18
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2017-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27806
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
7 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
8 ## This file is part of Octave.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
9 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
13 ## (at your option) any later version.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
14 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
18 ## GNU General Public License for more details.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
19 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
25
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
26 ## -*- texinfo -*-
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
27 ## @deftypefn {} {@var{status} =} web ()
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
28 ## @deftypefnx {} {@var{status} =} web (@var{url})
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
29 ## @deftypefnx {} {@var{status} =} web (@var{url}, @var{option})
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
30 ## @deftypefnx {} {@var{status} =} web (@var{url}, @var{option_1}, @dots{}, @var{option_N})
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
31 ## @deftypefnx {} {[@var{status}, @var{h}, @var{url}] =} web (@dots{})
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
32 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
33 ## Open @var{url} in the default system web browser.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
34 ##
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
35 ## With no arguments given, the address @url{https://www.octave.org} is
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
36 ## opened.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
37 ##
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
38 ## Additional options can be passed for @sc{matlab} compatibility, but are
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
39 ## ignored.
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
40 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
41 ## @itemize @bullet
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
42 ## @item
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
43 ## @samp{-browser} Open @var{url} in the default system browser.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
44 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
45 ## @item
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
46 ## @samp{-new} No effect on the system browser.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
47 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
48 ## @item
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
49 ## @samp{-noaddressbox} No effect on the system browser.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
50 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
51 ## @item
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
52 ## @samp{-notoolbar} No effect on the system browser.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
53 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
54 ## @end itemize
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
55 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
56 ## The return value @var{status} has one of the values:
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
57 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
58 ## @itemize @bullet
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
59 ## @item
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
60 ## @samp{0} Found and opened system browser successfully.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
61 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
62 ## @item
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
63 ## @samp{1} Cannot find the system browser.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
64 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
65 ## @item
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
66 ## @samp{2} System browser found, but an error occurred.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
67 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
68 ## @end itemize
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
69 ##
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
70 ## The return values @var{handle} and @var{url} are currently unimplemented
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
71 ## but given for compatibility.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
72 ##
27806
06af06188403 doc: Add missing DOCSTRINGs to Octave manual.
Rik <rik@octave.org>
parents: 27797
diff changeset
73 ## @seealso{weboptions, webread, webwrite, urlread, urlwrite}
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
74 ## @end deftypefn
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
75
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
76 function [status, h, url] = web (url, varargin)
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
77
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
78 if (nargin == 0)
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
79 url = "https://www.octave.org";
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
80 endif
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
81
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
82 if (! (ischar (url) && isrow (url)))
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
83 error ("web: URL must be a string");
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
84 endif
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
85
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
86 for i = 1:numel (varargin)
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
87 validatestring (varargin{i},
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
88 {"-browser", "-new", "-noaddressbox", "-notoolbar"});
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
89 endfor
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
90
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
91 ## Store text after "text://" to a temporary file and open it.
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
92 if (strncmpi (url, "text://", 7))
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
93 fname = [tempname() ".html"];
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
94 fid = fopen (fname, "w");
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
95 if (fid < 0)
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
96 error ("web: could not open temporary file for text:// content");
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
97 endif
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
98 fprintf (fid, "%s", url(8:end));
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
99 fclose (fid);
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
100 url = ["file://" fname];
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
101 endif
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
102
27148
224ce8329074 web.m: More Matlab compatibility.
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 27147
diff changeset
103 sts = __open_with_system_app__ (url);
224ce8329074 web.m: More Matlab compatibility.
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 27147
diff changeset
104 sts = ifelse (sts == 1, 0, 2);
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
105
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
106 h = []; # Empty handle, as we cannot control an external browser.
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
107
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
108 ## For Matlab compatibility.
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
109 if (any (strcmp (varargin, "-browser")))
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
110 url = [];
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
111 endif
27797
5dcdd5bd46e2 maint: remove trailing spaces from code.
Rik <rik@octave.org>
parents: 27148
diff changeset
112
27148
224ce8329074 web.m: More Matlab compatibility.
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 27147
diff changeset
113 if (nargout > 0)
224ce8329074 web.m: More Matlab compatibility.
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 27147
diff changeset
114 status = sts;
224ce8329074 web.m: More Matlab compatibility.
Guillaume Flandin <guillaume.offline@gmail.com>
parents: 27147
diff changeset
115 endif
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
116
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
117 endfunction
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
118
27147
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
119
f0da934bca61 web.m: Tweaks to new function.
Rik <rik@octave.org>
parents: 27144
diff changeset
120 %!error <URL must be a string> web (1)
27144
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
121 %!error <URL must be a string> web ('')
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
122 %!error <'-invalid_Option' does not match>
3de14d9a2303 Implement new function "web" to open the system web browser.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff changeset
123 %! web ("https://www.octave.org", "-invalid_Option")