


    i was trying to make a list of all message bases, using mpy in mystic 
    bbs. mystic has a built in function to get info from a msg. base, 
    using its id number called getmbaseid(). the logic thing to do, to get 
    a list of all bases is to make a loop and call the function, starting 
    with a msg.base id of one/1 and increasing that index (id) number, 
    until you get a False result, meaning that there is no msg.base with 
    that index number... right?
    
    well... no... if the function doesn't find a msg.base with a specific 
    index, this doesn't mean that, there are no more bases in the 
    record... it only means, that for some reason, that particular 
    msg.base id, is missing/deleted. 
    
    the next logical thing would be, to make the loop, to search for... 
    let say... 100 bases... and store those results. again, wrong... cause 
    this may lead to other problematic cases... so the best way... i 
    think... is to make the following.
    
    from the records.112 file, we get the record type of the mbases.dat 
    file and count the bytes. we want to know how many bytes is a record.
    
    I HOPE YOU HAVE ALL READY READ AND LEARNED ABOUT BYTE COUNTING, FROM 
    AN ARTICLE IN A PREVIOUS ISSUE... RIGHT? >:|
    
    for mystic bbs a43, the record size is 768 bytes. next, we get the 
    filesize of the mbases.dat file and divide it with this number. the 
    result will give us the exact number of msg.bases the file has stored.
    
    mystic bbs, when you delete a msg.base, deleted the record of it 
    completely so we are sure that sizeof(mbases.dat) / record_size equals 
    to number of msg.bases.
    
    now we have a number, that we can use in our loop and get all the info 
    we want. lets see the function and explain. the code is for mpy/python 
    2.7
    
#record size    
mbase_size = 768

#global vars to store bases. 
mbases = []
mbasesid = []

def getmbases():
  global mbases
  global mbasesid
  #clear the lists
  del mbases[:]
  del mbasesid[:]
  
  #get configuration settings from mystic bbs
  cfg = getcfg()
  
  #find the number of msg.bases we have by dividing the file size of the 
  #file mbases.dat with the record size
  basecount = os.path.getsize(cfg["data"]+"mbases.dat") // mbase_size
  
  #initialize loop count
  i = 1
  #get info for first base... i hope you have one at least :)
  mb = getmbaseid(int(i))
  
  #loop until we reach the "magic number"
  while not shutdown() and i < basecount:
    #if we did get info about a msg base, store info into our lists.
    if mb is not None:
      mbases.append(mb["name"])
      mbasesid.append(mb["id"])
    i +=1
    mb = getmbaseid(int(i))
    
    finito!!! now the two lists, have the name and id of all the lists in 
    the bbs. 
    
    you can configure the function to store what ever info you want. below 
    is the clean code for copy/paste.
    
    =======================================================================    
    
mbase_size = 768
mbases = []
mbasesid = []

def getmbases():
  global mbases
  global mbasesid
  del mbases[:]
  del mbasesid[:]
  cfg = getcfg()
  
  basecount = os.path.getsize(cfg["data"]+"mbases.dat") // mbase_size
  i = 1
  mb = getmbaseid(int(i))
  while not shutdown() and i < basecount:
    if mb is not None:
      mbases.append(mb["name"])
      mbasesid.append(mb["id"])
    i +=1
    mb = getmbaseid(int(i))    
    
    
    


  <<< null e-magazine x008 (text edition) >>>    
      ____  _____          _____   _____           http://github.com/xqtr/null
  ___/.   \/    /_________/.   /__/.   /__jp!_          andr01d.zapto.org:9999
 //_       \    .   /         /   \   /    _//                   agency.bbs.nz
   /____/\____/    /    /__________________\                          d1st.org
              \________/                        