Mercurial > octave
annotate scripts/miscellaneous/computer.m @ 21253:a66a737913b5
allow __have_feature__ to check for ENABLE_ options
* __have_feature__.m: Handle ENABLE_ options.
* mex_demo.c, oct_demo.cc: Update note about octave_config_info.
* toplev.cc (Foctave_config_info): For ENABLE_ options, store logical
values instead of true/false or yes/no strings in struct.
* computer.m: Change use of octave_config_info ("ENABLE_64").
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 12 Feb 2016 16:28:51 -0500 |
parents | e06e600f396a |
children | 1da428cbf401 |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19190
diff
changeset
|
1 ## Copyright (C) 2004-2015 John W. Eaton |
4691 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
4691 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
4691 | 18 |
19 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
20 ## @deftypefn {} {} computer () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
21 ## @deftypefnx {} {@var{c} =} computer () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
22 ## @deftypefnx {} {[@var{c}, @var{maxsize}] =} computer () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
23 ## @deftypefnx {} {[@var{c}, @var{maxsize}, @var{endian}] =} computer () |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20164
diff
changeset
|
24 ## @deftypefnx {} {@var{arch} =} computer ("arch") |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
25 ## Print or return a string of the form @var{cpu}-@var{vendor}-@var{os} that |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 ## identifies the type of computer that Octave is running on. |
19190 | 27 ## |
28 ## If invoked with an output argument, the value is returned instead of | |
29 ## printed. For example: | |
4691 | 30 ## |
31 ## @example | |
32 ## @group | |
33 ## computer () | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
34 ## @print{} i586-pc-linux-gnu |
4691 | 35 ## |
19190 | 36 ## mycomp = computer () |
37 ## @result{} mycomp = "i586-pc-linux-gnu" | |
4691 | 38 ## @end group |
39 ## @end example | |
5427 | 40 ## |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
41 ## If two output arguments are requested, also return the maximum number of |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
42 ## elements for an array. This will depend on whether Octave has been |
19190 | 43 ## compiled with 32-bit or 64-bit index vectors. |
5427 | 44 ## |
20164
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
45 ## If three output arguments are requested, also return the byte order of the |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
46 ## current system as a character (@qcode{"B"} for big-endian or @qcode{"L"} |
df437a52bcaf
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
47 ## for little-endian). |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
48 ## |
19190 | 49 ## If the argument @qcode{"arch"} is specified, return a string indicating the |
50 ## architecture of the computer on which Octave is running. | |
51 ## @seealso{isunix, ismac, ispc} | |
4691 | 52 ## @end deftypefn |
53 | |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
54 function [c, maxsize, endian] = computer (a) |
4691 | 55 |
19190 | 56 if (nargin > 1) |
57 print_usage (); | |
58 elseif (nargin == 1 && ! strcmpi (a, "arch")) | |
59 error ('computer: "arch" is only valid argument'); | |
60 endif | |
61 | |
62 if (nargin == 0) | |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
63 msg = octave_config_info ("canonical_host_type"); |
4691 | 64 |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
65 if (strcmp (msg, "unknown")) |
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
66 msg = "Hi Dave, I'm a HAL-9000"; |
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
67 endif |
4691 | 68 |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
69 if (nargout == 0) |
19190 | 70 disp (msg); |
5427 | 71 else |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
72 c = msg; |
19190 | 73 if (isargout (2)) |
21253
a66a737913b5
allow __have_feature__ to check for ENABLE_ options
John W. Eaton <jwe@octave.org>
parents:
21140
diff
changeset
|
74 if (octave_config_info ("ENABLE_64")) |
19190 | 75 maxsize = 2^63-1; |
76 else | |
77 maxsize = 2^31-1; | |
78 endif | |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
79 endif |
19190 | 80 if (isargout (3)) |
81 if (octave_config_info ("words_big_endian")) | |
82 endian = "B"; | |
83 elseif (octave_config_info ("words_little_endian")) | |
84 endian = "L"; | |
85 else | |
86 endian = "?"; | |
87 endif | |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
88 endif |
5427 | 89 endif |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
90 else |
19190 | 91 ## "arch" argument asked for |
92 tmp = ostrsplit (octave_config_info ("canonical_host_type"), "-"); | |
93 if (numel (tmp) == 4) | |
94 c = sprintf ("%s-%s-%s", tmp{4}, tmp{3}, tmp{1}); | |
95 else | |
96 c = sprintf ("%s-%s", tmp{3}, tmp{1}); | |
97 endif | |
98 | |
4691 | 99 endif |
100 | |
101 endfunction | |
7411 | 102 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
103 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
104 %!assert (ischar (computer ())) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
105 %!assert (computer (), octave_config_info ("canonical_host_type")) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
106 %!assert (ischar (computer ("arch"))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
107 |
19190 | 108 %!error computer (1,2) |
109 %!error <"arch" is only valid argument> computer ("xyz") | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
110 |