• HW 100.2

    From Finnigann@VERT/BNB to All on Tue Oct 23 15:20:00 2001
    #1) Open a disk file called INPUT.DAT for reading, halt with an errorã# message if the file is not found or for some reason won't open.ãã!include FILE_IO.INCããFOPEN file O_RDONLY "input.dat"ãã if_falseã print "\r\n\r\nnError Loading Configuration File - Input.Dat"ã returnã end_ifãã#2) Open a disk file called OUTPUT.DAT for writing, creating the fileã# if it doesn't exist, truncate it if it does exist. If it can't beã# opened/created, a) close the input file opened in step 1, b) printã# an error message, c) halt.ããFOPEN file O_CREAT|O_TRUNC "output.dat"ããif_falseã print "\r\n\r\nnError Loading Configuration File - Output.Dat"ã fclose Input.dat"ã returnã print "\r\n\r\nnDue to file error(s) All files closed at this time."ã end_ifããendããã... DOS never says "EXCELLENT command or filename"...ã--- MultiMail/MS-DOS v0.40ã þ Synchronet þ Bits-N-Bytes BBS - One Hellova BBS -- telnet://bnb.dtdns.netã
  • From PistolGrip@VERT/WASTELND to Finnigann on Tue Oct 23 19:10:00 2001
    RE: HW 100.2ãBY: Finnigann to All on Tue Oct 23 2001 10:20 pmãã > !include FILE_IO.INCã > ã > FOPEN file O_RDONLY "input.dat"ã > ã > if_falseã > print "\r\n\r\nnError Loading Configuration File - Input.Dat"ã > returnã > end_ifãã### Everything is fine until the next line. There, you try to open a secondã### file with the same <filehandle> "file" as the input file. You should tryã### to use unique filehandles, especially if you need to open mulitple files.ã ã > FOPEN file O_CREAT|O_TRUNC "output.dat"ã > ã > if_falseã > print "\r\n\r\nnError Loading Configuration File - Output.Dat"ãã### There is also an error on the next line. You are trying to close aã### filename, and not the <filehandle> (ie. file) as fclose function requires.ãã > fclose Input.dat"ã > returnã > print "\r\n\r\nnDue to file error(s) All files closed at this time."ã > end_ifãããNot Bad, "B" :)ããPGãã---ã þ Synchronet þ WasteLand BBS þ telnet://wasteland-bbs.com ã
  • From Amcleod@VERT to Finnigann on Tue Oct 23 23:16:35 2001
    RE: HW 100.2ãBY: Finnigann to All on Tue Oct 23 2001 10:20 pmãã > !include FILE_IO.INCã > ã > FOPEN file O_RDONLY "input.dat"ã > ã > if_falseã > print "\r\n\r\nnError Loading Configuration File - Input.Dat"ã > returnã > end_ifããThis is cool, except I think you should declare the file handle (as an integerãfirst. So, before the FOPEN you need something likeãã INT fileãã > FOPEN file O_CREAT|O_TRUNC "output.dat"ããThis would work fine too, but there is a "gotcha" in there. You are using backãthe same file-handle, so you no longer have access to the INPUT file. Betterãdeclare separate file-handles:ãã INT infh outfhã FOPEN infh O_RDONLY "input.dat"ã . . .ã FOPEN outfh O_CREAT|O_TRUNC "output.dat"ããFrom now on, you make all references to the INPUT file by way of the inputãfile-handle "infh" and reference the OUTPUT file via the output file-handleã"outfh". BTW, you can use any old name for the handles as you see fit. "in"ãand "out", "ifh" and "ofh", "input_file_handle" and "output_file_handle" orãwhatever, so long as it doesn't CLASH with the rest of the language, orãanything else in your program.ãã > if_falseã > print "\r\n\r\nnError Loading Configuration File - Output.Dat"ã > fclose Input.dat"ã > returnã > print "\r\n\r\nnDue to file error(s) All files closed at this time."ã > end_ifã > endããOkay, two things here.ããFirstly, once you have opened a file, you refer to it by the file-handle, notãthe name. So it should beãã FCLOSE infhãã(assuming the change in file-handles recommended above.)ããSecondly, your code executes a RETURN which is followed by a PRINT. The PRINTãis what is called "unreachable code". You never get to do the PRINT becauseãyou always RETURN just before you get to the PRINT. Some compilers will warnãyou about "unreachable code", but I don't know if BAJA.EXE does.ããWhat you need to do is put the PRINT first and _then_ the RETURN.ããKeep it up! Work on the other steps now...ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Finnigann@VERT/BNB to PistolGrip on Wed Oct 24 07:40:00 2001
    PistolGrip wrote to Finnigann <=-ãã Pi> RE: HW 100.2ã Pi> BY: Finnigann to All on Tue Oct 23 2001 10:20 pmãã > !include FILE_IO.INCã >ã > FOPEN file O_RDONLY "input.dat"ã ^^^^ã OKãã >ã > if_falseã > print "\r\n\r\nnError Loading Configuration File - Input.Dat"ã > returnã > end_ifãã Pi> ### Everything is fine until the next line. There, you try to open aã Pi> second ### file with the same <filehandle> "file" as the input file.ã Pi> You should try ### to use unique filehandles, especially if you need toã Pi> open mulitple files.ãã > FOPEN file O_CREAT|O_TRUNC "output.dat"ã >ã > if_falseã > print "\r\n\r\nnError Loading Configuration File - Output.Dat"ãã Pi> ### There is also an error on the next line. You are trying to close aã Pi> ### filename, and not the <filehandle> (ie. file) as fclose functionã Pi> requires.ãã > fclose Input.dat"ã > returnã > print "\r\n\r\nnDue to file error(s) All files closed at this time."ã > end_ifããã Pi> Not Bad, "B" :)ã ãActually it's YOUR B as I cut and pasted heavily from your example.ããSo the 'file' is the handle that BAJA see it as... A varible, assigned inãthe act of opening the input.dat. I need to refer to THAT varible whenãmanipulating INPUT.DAT ('file' was prolly a bad choice in that case).ãMaybe something descriptive would have been a better choice. Likeã'Player_list' or 'Game_scores'ããDitto for output.dat.ããA gray sliver of light...ããã... RAM DISK is NOT an installation procedure!ã--- MultiMail/MS-DOS v0.40ã þ Synchronet þ Bits-N-Bytes BBS - One Hellova BBS -- telnet://bnb.dtdns.netã
  • From Finnigann@VERT/BNB to Amcleod on Wed Oct 24 07:46:00 2001
    Amcleod wrote to Finnigann <=-ãã- - - The other items were addressed in a message to Pistolgrip. - - -ãã Am> Secondly, your code executes a RETURN which is followed by a PRINT.ã Am> The PRINT is what is called "unreachable code". You never get to doã Am> the PRINT because you always RETURN just before you get to the PRINT.ã Am> Some compilers will warn you about "unreachable code", but I don't knowã Am> if BAJA.EXE does.ãã Am> What you need to do is put the PRINT first and _then_ the RETURN.ãã Am> Keep it up! Work on the other steps now...ããOK and thanks to you and PG. I know this has gotta bite, But I learnãfairly fast.ããQuestion: On naming internal file handles, is there a character limit?ãie: no spaces or other characters forbidden. I guess periods and eitherãslash mark or an astricks or question mark or out of bounds too?ããã... As a matter of FACT I DO own the road!ã--- MultiMail/MS-DOS v0.40ã þ Synchronet þ Bits-N-Bytes BBS - One Hellova BBS -- telnet://bnb.dtdns.netã
  • From Digital Man@VERT to Finnigann on Wed Oct 24 10:29:35 2001
    RE: HW 100.2ãBY: Finnigann to Amcleod on Wed Oct 24 2001 02:46 pmãã > Question: On naming internal file handles, is there a character limit?ã > ie: no spaces or other characters forbidden. I guess periods and eitherã > slash mark or an astricks or question mark or out of bounds too?ããAnswer (from http://synchro.net/docs/baja.html#Variables):ããVariable names are not case sensitive and must begin with an alphabeticã character or an underscore (_). Variable names can be any length andã may contain alpha, numeric, and underscore characters only. Theã variable name "str" is reserved to represent the current command stringã and should not be used as a user defined variable name.ãã-Robã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Amcleod@VERT to Finnigann on Wed Oct 24 10:50:42 2001
    RE: HW 100.2ãBY: Finnigann to PistolGrip on Wed Oct 24 2001 02:40 pmãã > So the 'file' is the handle that BAJA see it as... A varible, assigned inã > the act of opening the input.dat. I need to refer to THAT varible whenã > manipulating INPUT.DAT ('file' was prolly a bad choice in that case).ã > Maybe something descriptive would have been a better choice. Likeã > 'Player_list' or 'Game_scores'ããYou've got the gist of it. The file handle is a variable (in BAJA it is anãINT) that you use to refer to the file. The FOPEN command assocuates a file onãdisk, by name, with the file handle. Then, everything else you do to thatãfile, you specify the file handle, rather than the name. ããIf writing a relatively simple program, you can name file handles like "in" andã"out" etc, but you _could_ open MANY files and refer to them at differentãtimes. In that case it is wise to name the handles something that will makeãusing them easier. You might have CfgHnd, UsrHnd, LogHnd, InHnd, OutHnd, andãso forth, all open at once. In languages that allow them, you could have anãARRAY of handles, or even write file handles to a file and read them back laterã(!) for arcane reasons.ããThe main thing to do is avoid mixing them up. You don't want to accidentallyãtry weriting log-file entries to the read-only configuration file, just becauseãyou called them 'abc' and 'xyz' and then got them mixed up in your mind!ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Amcleod@VERT to Finnigann on Wed Oct 24 10:54:22 2001
    RE: HW 100.2ãBY: Finnigann to Amcleod on Wed Oct 24 2001 02:46 pmãã > Question: On naming internal file handles, is there a character limit?ã > ie: no spaces or other characters forbidden. I guess periods and eitherã > slash mark or an astricks or question mark or out of bounds too?ããIn BAJA the file handle is just a common integer, so the naming conventions areãexactly the same as for integers.ããDon't try doing arithmetic with file handles! :) The arithmetic will workãfine, but the files themselves are likely to go to hell very shortlyãthereafter!ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From PistolGrip@VERT/WASTELND to Finnigann on Wed Oct 24 14:20:00 2001
    RE: HW 100.2ãBY: Finnigann to PistolGrip on Wed Oct 24 2001 02:40 pmãã > Pi> Not Bad, "B" :)ã > ã > Actually it's YOUR B as I cut and pasted heavily from your example.ããWell, I don't believe my example included duplicate filehandles :)ãã > So the 'file' is the handle that BAJA see it as... A varible, assigned inã > the act of opening the input.dat. I need to refer to THAT varible whenã > manipulating INPUT.DAT ('file' was prolly a bad choice in that case).ã > Maybe something descriptive would have been a better choice. Likeã > 'Player_list' or 'Game_scores'ããYes, technically I guess the <filehandle> is a variable of type integer thatãpoints to the file. This is how you keep track of which file you are workingãon. Otherwise, it would/could be tedious to do with the filename. There'sãmore to it than that, but you need a way to reference a file.ãã > A gray sliver of light...ãã:=0ããPGãã---ã þ Synchronet þ WasteLand BBS þ telnet://wasteland-bbs.com ã
  • From Finnigann@VERT/BNB to Digital Man on Wed Oct 24 22:18:00 2001
    Digital Man wrote to Finnigann <=-ãã DM> RE: HW 100.2ã DM> BY: Finnigann to Amcleod on Wed Oct 24 2001 02:46 pmãã > Question: On naming internal file handles, is there a character limit?ã > ie: no spaces or other characters forbidden. I guess periods and eitherã > slash mark or an astricks or question mark or out of bounds too?ãã DM> Answer (from http://synchro.net/docs/baja.html#Variables):ãã DM> Variable names are not case sensitive and must begin with an alphabeticã DM> character or an underscore (_). Variable names can be anyã DM> length andã DM> may contain alpha, numeric, and underscore characters only. Theã DM> variable name "str" is reserved to represent the currentã DM> command stringã DM> and should not be used as a user defined variable name.ã ãThanks - and bookmarked.ããã... SBBS: The Best BBS in the World - But no where else.ã--- MultiMail/MS-DOS v0.40ã þ Synchronet þ Bits-N-Bytes BBS - One Hellova BBS -- telnet://bnb.dtdns.netã
  • From Prime@VERT/IQLAND to Amcleod on Tue Sep 19 00:31:00 2000
    RE: HW 100.2ãBY: Amcleod to Finnigann on Wed Oct 24 2001 17:54:00ãã > RE: HW 100.2ã > BY: Finnigann to Amcleod on Wed Oct 24 2001 02:46 pmã > ã > > Question: On naming internal file handles, is there a character limit?ã > > ie: no spaces or other characters forbidden. I guess periods and eitherã > > slash mark or an astricks or question mark or out of bounds too?ã > ã > In BAJA the file handle is just a common integer, so the naming conventions ã > exactly the same as for integers.ã > ã > Don't try doing arithmetic with file handles! :) The arithmetic will workã > fine, but the files themselves are likely to go to hell very shortlyã > thereafter!ããWhat, exactly, _WOULD_ happen if you _did_ do arithmetic with file handles?ããã---ã þ Synchronet þ Viva, le U FAK A P AS Way Type Q! - Remember 9-11ã
  • From Amcleod@VERT to Prime on Thu Dec 6 08:04:08 2001
    RE: HW 100.2ãBY: Prime to Amcleod on Tue Sep 19 2000 07:31 amãã > > Don't try doing arithmetic with file handles! :) The arithmetic will woã > > fine, but the files themselves are likely to go to hell very shortlyã > > thereafter!ã > ã > What, exactly, _WOULD_ happen if you _did_ do arithmetic with file handles?ã > ããWell, handles are just integers, and they can be just about anything. forãinstance they may represent integer indexes into a table of file-control-blocksãso if you added your third and fifth handles you would get the handle of someãfile furthur up the table -- possibkly one never opened -- and the results ofãaccessing that file would be (most likely) a dismal failure with interestingãside-effects. Possibly the the handle is the actuall _address_ of the FCB andãso monkeying with them could give a pointer into some random part of memoryãwhich would again, give interesting and unpredictable side effects if you triedãto use it.ããYou can probably experiment safely with _writing_ the file handle to theãconsole. Open three or four files and print the file handles as integers. Youãmay get a series of integers like 3, 4, 5, 6 for the four filehandles. SO youãadd two to the first file handle and it suddenly becomes the thirdãfilehandle...ã\/sãã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Prime@VERT/IQLAND to Amcleod on Sat Dec 8 06:20:00 2001
    RE: HW 100.2ãBY: Amcleod to Prime on Thu Dec 06 2001 16:04:00ãã > RE: HW 100.2ã > BY: Prime to Amcleod on Tue Sep 19 2000 07:31 amã > ã > > > Don't try doing arithmetic with file handles! :) The arithmetic willã > > > fine, but the files themselves are likely to go to hell very shortlyã > > > thereafter!ã > > ã > > What, exactly, _WOULD_ happen if you _did_ do arithmetic with file handleã > > ã > ã > Well, handles are just integers, and they can be just about anything. forã > instance they may represent integer indexes into a table of file-control-bloã > so if you added your third and fifth handles you would get the handle of somã > file furthur up the table -- possibkly one never opened -- and the results ã > accessing that file would be (most likely) a dismal failure with interestingã > side-effects. Possibly the the handle is the actuall _address_ of the FCB aã > so monkeying with them could give a pointer into some random part of memoryã > which would again, give interesting and unpredictable side effects if you trã > to use it.ã > ã > You can probably experiment safely with _writing_ the file handle to theã > console. Open three or four files and print the file handles as integers. ã > may get a series of integers like 3, 4, 5, 6 for the four filehandles. SO yã > add two to the first file handle and it suddenly becomes the thirdã > filehandle...ã > \/sããJust a thought, but shouldn't there be some mechinism to prevent the accidentalãadding of file handles?ããã---ã þ Synchronet þ Viva, le U FAK A P AS Way Type Q! - Remember 9-11ã
  • From Amcleod@VERT to Prime on Mon Dec 10 07:28:47 2001
    RE: HW 100.2ãBY: Prime to Amcleod on Sat Dec 08 2001 02:20 pmãã > Just a thought, but shouldn't there be some mechinism to prevent the accidenã > adding of file handles?ããWell, that would require the declaration of a new basic type, so that theãcompiler could distinguish between handles and integers and prevent certainãoperatyions on handles that itn otherwise allows on integers.ããThere are different file I/O models that don't use file handles per se. Youãcould use some sort of stream-based I/O like the C/C++ fopen() mechanism thatãopens a stream and returns a pointer to a file-object. ããBut there are _occasionally_ reasons that might cause you to legitimately doãarithmetic to a file handle. Say you wanted to open six files and send data toãeach of them in turn in a round-robin scheme (for whatever reason). Thenã*_IF_* your file handles are simple numeric integers, you could do somethingãthat outputs to the handle and adds one to it (to point to the next file) soãthat each output went to the next file. You would have to check that you wereãat file #6 and reset to #1, but in theory you could do handle-arithmetic. Notãa wise move, though, unless you are very intimate with the internal workings ofãyour compiler and your OS. Dangerous and non-portable. Microsoftian, even!ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Rocko@VERT to Prime on Tue Dec 11 06:28:44 2001
    RE: HW 100.2ãBY: Prime to Amcleod on Sat Dec 08 2001 02:20 pmãã > Just a thought, but shouldn't there be some mechinism to prevent the accidenã > adding of file handles?ãã Oh well not for Perl. Who knows, maybe somebody WANTS to do that.So ãthe Perl methodology continues to pervade our virgin minds.ãã Yes, I'm learning perl at work now. Yes, I wrote a script with an 80+ ãcharacter regular expression. Yes, it felt good. ãã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã