SCOUG-Programming Mailing List Archives
Return to [ 17 |
November |
1998 ]
>> Next Message >>
Content Type: text/plain
This is my final code. It passed all my tests. Feel free to swipe it.
If anybody wants the procedures this one uses ("OpenInputFile" etc.),
just ask.
- Peter Skye
/*-----------------------------------------------------------------------------
/ The FileToStem subroutine reads a text file into a stem variable.
Each line
/ of the file becomes an individual stem.
/ To call:
/ _FileToStem = 'A.' / * Specify the stem variable to use. * /
/ rc = FileToStem(FILENAME)
/ -or-
/ call FileToStem FILENAME
/ On return:
/ The stem variable whose name is in _FileToStem contains the text
lines
/ from FILENAME.
/ rc contains 0 if successful or a non-zero error code if
unsuccessful.
/----------------------------------------------------------------------------*/
FileToStem: procedure expose _FileToStem (_FileToStem) /* expose
_FileToStem
and the variable name which it
contains */
/* Verify the number of parameters. */
if ParamCountError(1,1,arg(),"FileToStem(filename)") = 1 then return 1
/* Verify the stem variable name. */
_FileToStem = strip(_FileToStem)
if _FileToStem = '' then return 2
if substr(_FileToStem,length(_FileToStem),1) \= '.' then return 3 /*
Force
programmer to supply the trailing
".". */
if datatype(_FileToStem,'Symbol') = 0 then return 4
/* Verify the file name. */
if arg(1) = '' then return 5
if FileMissing(arg(1)) then return 6
/* Open the file. */
call OpenInputFile arg(1)
/* Put the file lines into the stem variable. */
index = 0
do while EndOfFile(arg(1)) \= 1
index = index + 1
interpret _FileToStem||index' = linein(arg(1))'
end
interpret _FileToStem'0 = index'
/* Completion. */
call CloseInputFile(arg(1))
return 0
=====================================================
To unsubscribe from this list, send an email message
to "steward@scoug.com". In the body of the message,
put the command "unsubscribe scoug-programming".
For problems, contact the list owner at
"rollin@scoug.com".
=====================================================
>> Next Message >>
Return to [ 17 |
November |
1998 ]
The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA 92799-6904, USA
Copyright 2001 the Southern California OS/2 User Group. ALL RIGHTS
RESERVED.
SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group.
OS/2, Workplace Shell, and IBM are registered trademarks of International
Business Machines Corporation.
All other trademarks remain the property of their respective owners.
|