annotate scripts/miscellaneous/computer.m @ 17535:c12c688a35ed default tip lyh

Fix warnings
author LYH <lyh.kernel@gmail.com>
date Fri, 27 Sep 2013 17:43:27 +0800
parents bc924baa2c4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
1 ## Copyright (C) 2004-2012 John W. Eaton
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
2 ##
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
4 ##
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5427
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5427
diff changeset
8 ## your option) any later version.
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
9 ##
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
14 ##
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5427
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5427
diff changeset
17 ## <http://www.gnu.org/licenses/>.
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
18
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13117
diff changeset
20 ## @deftypefn {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
21 ## @deftypefnx {Function File} {@var{arch} =} computer ("arch")
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
22 ## Print or return a string of the form @var{cpu}-@var{vendor}-@var{os}
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
23 ## that identifies the kind of computer Octave is running on. If invoked
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
24 ## with an output argument, the value is returned instead of printed. For
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
25 ## example:
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
26 ##
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
27 ## @example
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
28 ## @group
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
29 ## computer ()
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
30 ## @print{} i586-pc-linux-gnu
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
31 ##
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
32 ## x = computer ()
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
33 ## @result{} x = "i586-pc-linux-gnu"
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
34 ## @end group
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
35 ## @end example
5427
a92afe70fb8d [project @ 2005-08-16 19:49:23 by jwe]
jwe
parents: 5307
diff changeset
36 ##
a92afe70fb8d [project @ 2005-08-16 19:49:23 by jwe]
jwe
parents: 5307
diff changeset
37 ## If two output arguments are requested, also return the maximum number
a92afe70fb8d [project @ 2005-08-16 19:49:23 by jwe]
jwe
parents: 5307
diff changeset
38 ## of elements for an array.
a92afe70fb8d [project @ 2005-08-16 19:49:23 by jwe]
jwe
parents: 5307
diff changeset
39 ##
a92afe70fb8d [project @ 2005-08-16 19:49:23 by jwe]
jwe
parents: 5307
diff changeset
40 ## If three output arguments are requested, also return the byte order
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16724
diff changeset
41 ## 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
42 ## @qcode{"L"} for little-endian).
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
43 ##
17289
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16724
diff changeset
44 ## If the argument @qcode{"arch"} is specified, return a string
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
45 ## indicating the architecture of the computer on which Octave is
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
46 ## running.
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
47 ## @end deftypefn
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
48
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
49 function [c, maxsize, endian] = computer (a)
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
50
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
51 if (nargin == 1 && ischar (a) && strcmpi (a, "arch"))
16724
b7667fcb9fbc Substitute ostrsplit() for strsplit().
Ben Abbott <bpabbott@mac.com>
parents: 16403
diff changeset
52 tmp = ostrsplit (octave_config_info ("canonical_host_type"), "-");
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
53 if (numel (tmp) == 4)
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
54 c = sprintf ("%s-%s-%s", tmp{4}, tmp{3}, tmp{1});
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
55 else
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
56 c = sprintf ("%s-%s", tmp{3}, tmp{1});
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
57 endif
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
58 elseif (nargin == 0)
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
59 msg = octave_config_info ("canonical_host_type");
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
60
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
61 if (strcmp (msg, "unknown"))
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
62 msg = "Hi Dave, I'm a HAL-9000";
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
63 endif
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
64
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
65 if (nargout == 0)
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
66 printf ("%s\n", msg);
5427
a92afe70fb8d [project @ 2005-08-16 19:49:23 by jwe]
jwe
parents: 5307
diff changeset
67 else
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
68 c = msg;
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
69 if (strcmp (octave_config_info ("USE_64_BIT_IDX_T"), "true"))
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
70 maxsize = 2^63-1;
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
71 else
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
72 maxsize = 2^31-1;
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
73 endif
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
74 if (octave_config_info ("words_big_endian"))
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
75 endian = "B";
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
76 elseif (octave_config_info ("words_little_endian"))
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
77 endian = "L";
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
78 else
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
79 endian = "?";
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
80 endif
5427
a92afe70fb8d [project @ 2005-08-16 19:49:23 by jwe]
jwe
parents: 5307
diff changeset
81 endif
13117
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
82 else
9bebb2322c4e computer: accept "arch" argument
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
83 print_usage ();
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
84 endif
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
85
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents:
diff changeset
86 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
87
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
88
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
89 %!assert (ischar (computer ()))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
90 %!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
91 %!assert (ischar (computer ("arch")))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
92
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
93 %!error computer (2)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
94