~ubuntu-branches/ubuntu/wily/octave-miscellaneous/wily

« back to all changes in this revision

Viewing changes to inst/asci.m

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Weber
  • Date: 2008-11-30 23:39:44 UTC
  • mto: (5.1.1 experimental) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20081130233944-e2o8pmafecjq09me
Tags: upstream-1.0.7
ImportĀ upstreamĀ versionĀ 1.0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%# Copyright (C) 2008, Thomas Treichl <treichl@users.sourceforge.net>
 
2
%#
 
3
%# This program is free software; you can redistribute it and/or modify
 
4
%# it under the terms of the GNU General Public License as published by
 
5
%# the Free Software Foundation; either version 2 of the License, or
 
6
%# (at your option) any later version.
 
7
%#
 
8
%# This program is distributed in the hope that it will be useful,
 
9
%# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
%# GNU General Public License for more details.
 
12
%#
 
13
%# You should have received a copy of the GNU General Public License
 
14
%# along with this program; if not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
%# -*- texinfo -*-
 
17
%# @deftypefn {Function} {[@var{string}] =} asci ([@var{columns}])
 
18
%# If this function is called without any input argument and without any output argument then print a nice ASCI-table (excluding special characters with hexcode 0x00 to 0x20) on screen with four columns per default. If this function is called with one output argument then return an ASCI-table string and don't print anything on screen. Finally, if this function is called with one input argument of type scalar then either print (no output argument) or return (one output argument) an ASCI-table with a number of columns given in @var{columns}.
 
19
%#
 
20
%# For example,
 
21
%# @example
 
22
%# A = asci (3);
 
23
%# disp (A);
 
24
%# @end example
 
25
%# @end deftypefn
 
26
 
 
27
function [varargout] = asci (varargin)
 
28
 
 
29
  %# Check number and types of input arguments
 
30
  if (nargin == 0)
 
31
    vcol = 4;
 
32
  elseif (isnumeric (varargin{1}) && \
 
33
          isequal (size (varargin{1}), [1, 1]))
 
34
    vcol = floor (varargin{1});
 
35
  else
 
36
    print_usage ();
 
37
  endif
 
38
 
 
39
  %# First char is #32 (0x20) and last char is #128 (0x80)
 
40
  vtab = "";
 
41
  voff = floor ((128 - 32) / vcol);
 
42
 
 
43
  %# Print a first row for the and underline that row
 
44
  for vcnt = 1:vcol
 
45
    vtab = sprintf ("%s Dec Hex Chr ", vtab);
 
46
  endfor
 
47
  vtab = sprintf ("%s\n", vtab);
 
48
 
 
49
  for vcnt = 1:vcol
 
50
    vtab = sprintf ("%s-------------", vtab);
 
51
  endfor
 
52
  vtab = sprintf ("%s\n", vtab);
 
53
 
 
54
  %# Create the lines and columns of the asci table
 
55
  for vpos = 32:(32+voff)
 
56
    for vcnt = 1:vcol
 
57
      vact = (vcnt-1)*voff+vpos;
 
58
      vstr = {num2str(vact), dec2hex(vact), char(vact)};
 
59
      for vctn = 1:length (vstr)
 
60
        vtab = sprintf ("%s %3s", vtab, vstr{vctn});
 
61
      endfor
 
62
      vtab = sprintf ("%s ", vtab);
 
63
    endfor
 
64
    vtab = sprintf ("%s\n", vtab);
 
65
  endfor
 
66
  vtab = sprintf ("%s\n", vtab);
 
67
 
 
68
  %# Print table to screen or return it to output argument
 
69
  if (nargout == 0)
 
70
    printf ("%s", vtab);
 
71
  elseif (nargout == 1)
 
72
    varargout{1} = vtab;
 
73
  endif
 
74
endfunction
 
75
 
 
76
%!test
 
77
%!  A = asci ();
 
78
%!test
 
79
%!  A = asci (2);
 
80
 
 
81
%# Local Variables: ***
 
82
%# mode: octave ***
 
83
%# End: ***
 
 
b'\\ No newline at end of file'