A Guide to the Sheerpower Language

Previous Contents Index

6.7.4 FILEINFO$ Contents Option

The CONTENTS option of FILEINFO$ returns the entire contents of the file '' into all_of_file$ (see example below). If the file cannot be found, then returns a null string. A zero-length file will also return a null string.


  all_of_file$ = fileinfo$('', 'contents') 

Example 6-176 FILEINFO$ Function - CONTENTS

 all_of_file$ = fileinfo$('sheerpower:sheerpower.ini', 'contents') 
 print all_of_file$ 
! the specified file contents will display in the console window when the program 
! is run: 

Example 6-177 Copy a File With FILEINFO$ CONTENTS

sourcefile$ = '' 
destfile$   = '' 
contents$   = fileinfo$(sourcefile$, 'contents') 
open file dest_ch: name destfile$, access output, unformatted
print #dest_ch: contents$ 
close #x 

6.7.5 FINDFILE$(str_expr [, int_expr])

Given a file name to find, FINDFILE$ returns the complete file specification of the first file found that matches the name given. If no file is found, the function returns a null string.

FINDFILE$ calls can be nested if the inner call has only one argument (i.e., the file specification, but no index number).

  str_expr The name of the file to search for. This can be just part of the full file specification.
  int_expr Which file specification to return if multiple files are found. This parameter is optional. The default is to return the first file found.
  result The complete file specification of the file found.

Example 6-178 FINDFILE$ Function

  print findfile$('sheerpower:\samples\*.spsrc') 

Example 6-179 FINDFILE$ Function

    line input 'File specification': spec$ 
    if  _exit  then exit do         
    for i = 1 to 9999 
      file$ = findfile$(spec$, i) 
      if  file$ = ''  then exit for 
      print file$ 
    next i 
File specification? sheerpower:samples\client.*  <---- type this in 
File specification? exit 

Example 6-180 FINDFILE$ Function

//tell the length of each file by getting the file data and using len() 
my_path$ = 'c:\sheerpower\*.*' 
for idx = 1 to 19999 
  my_file$ = findfile$(my_path$, idx) 
  if my_file$ = '' then exit for // no more files 
  contents$ = fileinfo$(my_file$, 'contents') 
  print my_file$; ', length '; len(contents$) 
next idx 
c:\sheerpower\sheerpower.ini, length  125 
c:\sheerpower\sp$install_runonce.spsrc, length  1064 
c:\sheerpower\sp4gl.exe, length  6859264 
c:\sheerpower\sp4gl_system_info.txt, length  483 
c:\sheerpower\spdev.exe, length  2027589 
c:\sheerpower\spdev_nonsp.ini, length  1769 
c:\sheerpower\spdev_nonsp_sarcee.ini, length  1769 
c:\sheerpower\spdev_profile_sarcee.ini, length  5779 
c:\sheerpower\spdev_sp4gl.ini, length  10066 
c:\sheerpower\spdev_sp4gl_sarcee.ini, length  10066 
c:\sheerpower\spdev_system_info.txt, length  463 
c:\sheerpower\spdev_tools.ini, length  2418 
c:\sheerpower\spdev_tools_sarcee.ini, length  5485 
c:\sheerpower\test.spsrc, length  87 
c:\sheerpower\yes.wav, length  16048 

6.8 Debugging and Exception Handling Functions

The following are debugging and exception handling functions that Sheerpower performs:

6.8.1 _DEBUG

_DEBUG returns a TRUE or FALSE value. TRUE if DEBUG is on. FALSE if DEBUG is off.

Example 6-181 _DEBUG System Function

  debug on
  if  _debug  then
    print 'I am debugging' 
  end if
  debug off
  if  _debug  then 
    print 'I am still debugging.' 
    else print 'I am no longer debugging.' 
  end if
I am debugging. 
I am no longer debugging. 

6.8.2 _STATUS

_STATUS returns the value given to Sheerpower by the operating system for the last operating system request. It also returns the operating exception number for the last exception that occurred. This function is useful when debugging system level errors. The _STATUS function is often used with the SYSTEXT$ function.

Example 6-182 _STATUS System Function

  when exception in
    open #1: name 'c:\stuff\otherstuff\myfile.txt' 
    close #1 
    print 'The error was: '; systext$(_status)
  end when
The error was: The system cannot find the path specified. 

6.8.3 _STRING

Upon the completion of an INPUT MENU statement, the concept _STRING contains the menu path taken by the user when selecting the menu item. (i.e., "#2;#3" means the 3rd item of the 2nd submenu.)

Example 6-183 _STRING System Function

  line1$       = '%width 12, %menubar, %autovbar ON,' 
  line2$       = 'file = {new, get_file, save, save_as},' 
  line3$       = 'edit = {cut, copy, paste},' 
  line4$       = 'paragraph = {font, alignment, spacing, tabs, headers, footers},' 
  line5$       = 'options = {ruler = {on, off}, side_bar = {on, off},' 
  line6$       = 'view = {enlarged, normal, small}},exit' 
  test_menu$   = line1$ + line2$ + line3$ + line4$ + line5$ + line6$ 
  the_default$ = '' 
    input menu test_menu$, default the_default$: ans$ 
    if  _exit  then exit do
    message 'Menu path was', _string
    the_default$ = _string
|  FILE      |   EDIT      |   PARAGRAPH   |   OPTIONS   |   EXIT             | 
                                             |  RULER    [>| 
                                             |  SIDE_BAR +----VIEW-----+ 
                                             |  VIEW    |  ENLARGED   | 
                                             +-----------|  NORMAL    | 
                                                         |  SMALL      | 
The menu path was:  #4;#3;#2

6.8.4 EXLABEL$

EXLABEL$ returns the routine name and line number executing when the last exception occurred, e.g., DO_INPUT.4

Example 6-184 EXLABEL$ Function

  routine try_it 
    when exception in
      open #1: name 'xx.yy' 
      print 'Open error at '; exlabel$
      print 'Error was: '; extext$(extype)
    end when
  end routine
Open error at TRY_IT.0002 
Error was: File not found 

6.8.5 EXTEXT$[(int_expr)]

EXTEXT$ returns explanatory text associated with a specified exception number. See also the EXLABEL$ function example above.

Example 6-185 EXTEXT$ Function

  print extext$(2001) 
Subscript out of bounds 

6.8.6 EXTYPE

EXTYPE returns the number of the last exception that occurred. It is returned as an integer.

Example 6-186 EXTYPE Function

  routine try_it 
    when exception in
      open #1: name 'xx.yy' 
      print 'Open error at '; exlabel$
      print 'Error was: '; extype
    end when
  end routine
Open error at TRY_IT.0002 
Error was: 7110 

6.8.7 SYSTEXT$



SYSTEXT$ returns the text associated with the operating system status specified. If no int_expr is supplied, Sheerpower returns the text for the last system status. SYSTEXT$ is often used with _STATUS system function.

Example 6-187 SYSTEXT$ Function

  print systext$
The operation completed successfully. 

Previous Next Contents Index