Sheerpower®
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 'some_file.xxx' 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.

FORMAT:


  all_of_file$ = fileinfo$('some_file.xxx', 'contents') 

Example 6-176 FILEINFO$ Function - CONTENTS

 all_of_file$ = fileinfo$('sheerpower:sheerpower.ini', 'contents') 
 print all_of_file$ 
 end
 
! the specified file contents will display in the console window when the program 
! is run: 
 
 
[license] 
LicenseKey=F0CE-2E43-7583-3130-3030-3030-3131-0003-873F-000A 
Username=non-commercial 
EmailAddress=non-commercial 
 

Example 6-177 Copy a File With FILEINFO$ CONTENTS

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

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') 
 
 
c:\sheerpower\samples\cdplayer.spsrc 

Example 6-179 FINDFILE$ Function

  do
    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 
  loop
  end
 
 
File specification? sheerpower:samples\client.*  <---- type this in 
c:\sheerpower\samples\client.ars 
c:\sheerpower\samples\client.def 
c:\sheerpower\samples\client.fdl 
c:\sheerpower\samples\client.str 
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 
end 
 
 
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
  end
  
  
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 
  use
    print 'The error was: '; systext$(_status)
  end when
  end
 
 
 
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$ = '' 
  
  do 
    input menu test_menu$, default the_default$: ans$ 
    if  _exit  then exit do
    message 'Menu path was', _string
    the_default$ = _string
  loop
  end
 
 
+------------------------------------------------------------------------------+ 
|  FILE      |   EDIT      |   PARAGRAPH   |   OPTIONS   |   EXIT             | 
+--------------------------------------------+---OPTIONS---+-------------------+ 
                                             |  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

  try_it 
  stop
  routine try_it 
    when exception in
      open #1: name 'xx.yy' 
    use
      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

  try_it 
  stop
  routine try_it 
    when exception in
      open #1: name 'xx.yy' 
    use
      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$

or

SYSTEXT$[(int_expr)]

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