FreeMat: TYPE Type Contents of File or Function

FreeMat

- Main Page
- Related Pages

TYPE Type Contents of File or Function

Section: Input/Ouput Functions

# Usage

Displays the contents of a file or a function to the screen or console. The syntax for its use is

       type filename
       type('filename')

or

       type function
       type('function')

in which case the function named `'function.m'` will be displayed.

# Example

Here we use `type` to display the contents of itself

    --> type('type')
    % DOCBLOCK io_type

    function type(filename)
    fp = fopen(filename,'r');
    if (fp == -1)
      f = which(filename);
      if (isempty(f)), return; end
      filename = f;
      fp = fopen(filename,'r');
    end
    if (fp == -1), return; end
    while (~feof(fp))
      printf('%s',fgetline(fp));
    end
    fclose(fp);