Mercurial > hg > octave-nkf
annotate scripts/miscellaneous/computer.m @ 20128:09cb7e1e46d1
miscellaneous/tmpnam.m: fix typo in texinfo header
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Sun, 08 Mar 2015 14:47:13 +0100 |
parents | 4197fc428c7d |
children | df437a52bcaf |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19382
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 -*- | |
19382 | 20 ## @deftypefn {Function File} {} computer () |
21 ## @deftypefnx {Function File} {@var{c} =} computer () | |
22 ## @deftypefnx {Function File} {[@var{c}, @var{maxsize}] =} computer () | |
23 ## @deftypefnx {Function File} {[@var{c}, @var{maxsize}, @var{endian}] =} computer () | |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
24 ## @deftypefnx {Function File} {@var{arch} =} computer ("arch") |
4691 | 25 ## Print or return a string of the form @var{cpu}-@var{vendor}-@var{os} |
19382 | 26 ## that identifies the type of computer that Octave is running on. |
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 ## |
19382 | 36 ## mycomp = computer () |
37 ## @result{} mycomp = "i586-pc-linux-gnu" | |
4691 | 38 ## @end group |
39 ## @end example | |
5427 | 40 ## |
41 ## If two output arguments are requested, also return the maximum number | |
19382 | 42 ## of elements for an array. This will depend on whether Octave has been |
43 ## compiled with 32-bit or 64-bit index vectors. | |
5427 | 44 ## |
45 ## If three output arguments are requested, also return the byte order | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
46 ## of the current system as a character (@qcode{"B"} for big-endian or |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16724
diff
changeset
|
47 ## @qcode{"L"} for little-endian). |
13117
9bebb2322c4e
computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
48 ## |
19382 | 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 |
19382 | 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) |
19382 | 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; |
19382 | 73 if (isargout (2)) |
74 if (strcmp (octave_config_info ("USE_64_BIT_IDX_T"), "true")) | |
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 |
19382 | 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 |
19382 | 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 |
19382 | 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 |