• File access - BAJA

    From Jim King@VERT/BNB to ALL on Mon Apr 2 11:12:00 2001
    I want to learn more about how to program computers. Baja seems to beãsimple enough yet complex enough at the same time.ããOne aspect that seems inescapable is writing to and reading from aãfile.ããWould someone be willing to write and explain a simple (short) programãthat reads from and writes to a file in Baja?ããUse as many of the file accessing routines found in Baja.ããFrom Baja Docs:ããFOPEN <int_var> <#> <"str" or str_var> FILE_IO.INCã args: handle access path_and_filenameããFREAD <int_var> <any_var> [int_var or #]ã args: handle dest lengthããFCLOSE <int_var>ã args: handleããI just don't have the back ground to use this. I know this is a tallãorder and an in depth discussion prolly wont happen, but some sort ofãthread on this MIGHT help and would certainly be welcomed here andãpossibly by others wishing to learn more.ããã-ãJames King, Coldwater, Mi And that's JIM to you guys! ã Tip of the day: http://setiathome.berkeley.edu ãã---ã þ Synchronet þ Bits-N-Bytes One hell of a BBS 24.241.127.99ã
  • From PistolGrip@VERT/WASTELND to Jim King on Mon Apr 2 14:58:00 2001
    RE: File access - BAJAãBY: Jim King to ALL on Mon Apr 02 2001 06:12 pmãã > Would someone be willing to write and explain a simple (short) programã > that reads from and writes to a file in Baja?ããThis is an example using a binary file.ãã##### START ##############################################################ã!include file_io.incãã# Variable Definitionsãint file_handleãint numberãint number2ãã# Sets a variable to a valueãset number2 25ãã# Open fileãfopen file_handle O_RDWR "%n..\baja\somedir\somefile.dat"ãif_falseã print "\r\n\r\nnError Loading File"ã pauseã returnãend_ifããfread file_handle number 4 # reads 4 bytes from fileãfset_pos file_handle 20 SEEK_CUR # sets file position ahead 20 bytesãfwrite file_handle number2 4 # writes number2 to file with 4 bytesããfclose file_handleã##### END ##############################################################ããHope this helps.ããPGãã---ã þ Synchronet þ WasteLand BBS þ telnet://wasteland.darktech.org ã
  • From Amcleod@VERT to Jim King on Mon Apr 2 12:34:02 2001
    RE: File access - BAJAãBY: Jim King to ALL on Mon Apr 02 2001 06:12 pmãã > Would someone be willing to write and explain a simple (short) programã > that reads from and writes to a file in Baja?ã > ã > Use as many of the file accessing routines found in Baja.ã > ã > From Baja Docs:ã > ã > FOPEN <int_var> <#> <"str" or str_var> FILE_IO.INCã > args: handle access path_and_filenameã > ã > FREAD <int_var> <any_var> [int_var or #]ã > args: handle dest lengthã > ã > FCLOSE <int_var>ã > args: handleããEssentially you have it covered, except: I'd recommend first a program thatãopened the file, WROTE some data and then closed it. You decide what goesãinto the file, what the format is, etc, etc, and you should have a pretty goodãidea what to expect in that file when the program has executed. ããTHEN your SECOND program essentially does the opposite. Open the same file,ãread back the data and display it to confirm that you i) wrote it correctly;ãii) read it back as expected.ããDo you understand the arguments to the commands listed above? ("handle",ã"access", etc) Or do you need someone to run through them with you first?ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Jim King@VERT/BNB to PistolGrip on Mon Apr 2 22:22:00 2001
    RE: File access - BAJAãP>BY: Jim King to ALL on Mon Apr 02 2001 06:12 pmããP> > Would someone be willing to write and explain a simple (short) programãP> > that reads from and writes to a file in Baja?ããP>This is an example using a binary file.ããããP>Hope this helps.ããP>PGããThanks PistolGrip, it's a start.ãã-ãJames King, Coldwater, Mi And that's JIM to you guys! ã Tip of the day: http://setiathome.berkeley.edu ã---ã þ OLXWin 1.00b þ Jesus saves, passes to Moses, up the court, shoots scoresã þ Synchronet þ Bits-N-Bytes One hell of a BBS 24.241.127.99ã
  • From Jim King@VERT/BNB to Amcleod on Mon Apr 2 23:17:00 2001
    RE: File access - BAJAãA>BY: Jim King to ALL on Mon Apr 02 2001 06:12 pmããA> > Would someone be willing to write and explain a simple (short) programãA> > that reads from and writes to a file in Baja?ãA> > ãA> > Use as many of the file accessing routines found in Baja.ãA> > ãA> > From Baja Docs:ãA> > ãA> > FOPEN <int_var> <#> <"str" or str_var> FILE_IO.INCãA> > args: handle access path_and_filenameãA> > ãA> > FREAD <int_var> <any_var> [int_var or #]ãA> > args: handle dest lengthãA> > ãA> > FCLOSE <int_var>ãA> > args: handleããA>Essentially you have it covered, except: I'd recommend first a program thatãA>opened the file, WROTE some data and then closed it. You decide what goesãA>into the file, what the format is, etc, etc, and you should have a pretty goodãA>idea what to expect in that file when the program has executed. ããExactly, the module would be reading from a structured file (ie aãconfig file) to write to another structured file (a batch file)ãIn addition to writing to xtrn.cnf (a file of undetermined structureã:-)ããA>THEN your SECOND program essentially does the opposite. Open the same file,ãA>read back the data and display it to confirm that you i) wrote it correctly;ãA>ii) read it back as expected.ããA>Do you understand the arguments to the commands listed above? ("handle",ãA>"access", etc) Or do you need someone to run through them with you first?ããI have all the Baja Docs printed out however as it was in the twoãyears of Latin class I find I learn fastest with examples.ããI have the basic premise worked out (in my head) and now I am tryingãto translate it into Bajaese. (and in the process learn aboutãprogramming)ããI'm not saying that Baja is the simplest language, just the one withãthe most programmers I know.ããEnough blather...ããPG's examples are helpful, but as I said writing to xtrn.cnf can beãwreckless if I'm not careful. So I need more info on set_posããIt occurred to me to ask the man his self. I got back..ã from \sbbs\cnfs.fmtã total_xtrns 2ã ... xtrn->sec 2ã ... xtrn->name 41ã ... xtrn->code 9ã ... xtrn->ar 41ã ... xtrn->run_ar 41ã ... xtrn->type 1ã ... xtrn->misc 4ã ... xtrn->event 1ã ... xtrn->cost 4ã ... xtrn->cmd 64ã ... xtrn->clean 64ã ... xtrn->path 64ã ... unused 16ããKnowing all this... how would I translate ... say "xtrn->code 9" into aãfread statement? Using "%!\..\crtl\xtrn.cnf" as the source.ããã-ãJames King, Coldwater, Mi And that's JIM to you guys! ã Tip of the day: http://setiathome.berkeley.edu ã---ã þ OLXWin 1.00b þ Press "+" to see another tagline.ã þ Synchronet þ Bits-N-Bytes One hell of a BBS 24.241.127.99ã
  • From Amcleod@VERT to Jim King on Tue Apr 3 01:37:32 2001
    RE: File access - BAJAãBY: Jim King to Amcleod on Tue Apr 03 2001 06:17 amãã > PG's examples are helpful, but as I said writing to xtrn.cnf can beã > wreckless if I'm not careful. So I need more info on set_posã > ã > It occurred to me to ask the man his self. I got back..ã > from \sbbs\cnfs.fmtã > total_xtrns 2ã > ... xtrn->sec 2ã > ... xtrn->name 41ã > ... xtrn->code 9ã > ... xtrn->ar 41ã > ... xtrn->run_ar 41ã > ... xtrn->type 1ã > ... xtrn->misc 4ã > ... xtrn->event 1ã > ... xtrn->cost 4ã > ... xtrn->cmd 64ã > ... xtrn->clean 64ã > ... xtrn->path 64ã > ... unused 16ã > ã > Knowing all this... how would I translate ... say "xtrn->code 9" into aã > fread statement? Using "%!\..\crtl\xtrn.cnf" as the source.ããUhoh!ããYou will need more than this to be going on with, I fear! This is only aã_portion_ of the definition of XTRN.CNF and you need to have it all. ããLet me get back to you later...ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Amcleod@VERT to Jim King on Tue Apr 3 02:21:34 2001
    RE: File access - BAJAãBY: Jim King to Amcleod on Tue Apr 03 2001 06:17 amãã > Knowing all this... how would I translate ... say "xtrn->code 9" into aã > fread statement? Using "%!\..\crtl\xtrn.cnf" as the source.ããOK Jim, here's an example of accessing XTRN.CNF via BAJA. I don't know if itãwill lead you where you want to go or not. But either way, here it is, RAABAãand not particularly well testedãã# We need the standard definitions in "FILE_IO.INC" so...ã!include FILE_IO.INCãã# define some variables we will need laterãint FHnd Offs XProgCt XP_Secãstr FName XP_COde XP_Name XP_Cmdãã# define name of config file (use a copy while debugging!)ãset FName "/sbbs/ctrl/x_xtrn.cnf"ãã# open the file for reading, and get back a unique integer "handle" thatã# allows us to refer to this open file in all subsequent operations. Bombã# if file fails to openãfopen FHnd O_RDONLY FNameãif_falseã print "fopen() failed!\r\n";ã pauseã exitãend_ifãã# Refer to XTRN.CNF section of CNFS.FMT for details on file layout!ã# First two bytes in file is "total_swaps", read this (no error checkingã# from now on; duplicate if_false/end_if from above and change as needed).ãfread FHnd Offs 2ãã# "total_swaps" is followed by that many "swap_cmd" at 64 bytes each,ã# so compute how many bytes must be skipped to come to "External Editors"ã# and reposition file pointer to that offset.ãmul Offs 64ãfset_pos FHnd Offs SEEK_CURãã# Now read "total_xedits". Skip past 41+9+64+64+4+41+16 = 239 timesã# "total_xedits" bytes to get to "External Program Section"ãfread FHnd Offs 2ãmul Offs 239ãfset_pos FHnd Offs SEEK_CURãã# Find out how many "total_xtrnsecs" and compute offset to "Externalã# Program" (41+9+41+16 = 107)ãfread FHnd Offs 2ãmul Offs 107ãfset_pos FHnd Offs SEEK_CURãã# Phew! Finally pointing at "External Programs". How many in total?ãfread FHnd XProgCt 2ãã# This is the top of a loop that will iterate over the list of "Externalã# Programs", processing each one as we go.ã:NextXPãã # If there are ZERO (or less ?!?) "External Programs" left, weã # are finished processing the list and wanna call it quits.ã compare XProgCt 0ã if_less_or_equalã goto WereDoneã end_ifãã # Since we aren't done, print some basic info on the nextã # "External Program".....ãã # Read some data...ã fread FHnd XP_Sec 2ã fread FHnd XP_Name 41ã fread FHnd XP_Code 9ãã # Skip 41+41+1+4+1+4 = 92 bytes we're not interested inã fset_pos FHnd 92 SEEK_CURãã # Read some more dataã fread FHnd XP_Cmd 64ãã # Skip 64+64+16 = 144 remaining (unwanted) bytes for thisã # "External Program"ã fset_pos FHnd 144 SEEK_CURãã # Print out the info we picked up:ã printf "%5ld -- %-8s -- %-40s\r\n" XP_Sec XP_Code XP_Nameã printf " %-64s\r\n\r\n" XP_Cmdãã # Reduce count by one and loooooop!ã sub XProgCt 1ã goto NextXPãã# OK, this is where we come to when there are no more "External Programs"ã# for us to process...ã:WereDoneãprint "We're done!\r\n"ãã# Ok, we're done, so courteously close file before exitingãfclose FHndãã# Sayonara!ãexitããThere you have it; RAABA as promised! Read it through step by step referringãto the CNFS.FMT file (XTRN.CNF section) and you should be able to easily seeãwhat is happening. As usual, programming turns out to be a boring, ste-by-stepãexercise.ããTo make _changes_ to the file, you essentially follow a similar process toãthis: Carefully compute the location of the byte(s) you want to change,ãpossibly reading data and computing offsets to get there. When your fileãpointer is aimed exactly at where you want the data put, then you fwrite() theãexact number of bytes into the file, then reposition the file pointer for theãnext write. You have to open the file Read/Write instead of Read-Only, ofãcourse. Make _sure_ to use a copy of the file when debugging to avoid hosingãyour valuable config data!ã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
  • From Jim King@VERT/BNB to Amcleod on Tue Apr 3 08:46:00 2001
    RE: File access - BAJAãA>BY: Jim King to Amcleod on Tue Apr 03 2001 06:17 amããA> > Knowing all this... how would I translate ... say "xtrn->code 9" into aãA> > fread statement? Using "%!\..\crtl\xtrn.cnf" as the source.ãã[ - Message Saved - ]ããStudy time.ããã-ãJames King, Coldwater, Mi And that's JIM to you guys! ã Tip of the day: http://setiathome.berkeley.edu ã---ã þ OLXWin 1.00b þ Hello, I am part numberã þ Synchronet þ Bits-N-Bytes One hell of a BBS 24.241.127.99ã