Subj : BAJA Programming 101.1
To   : All
From : PistolGrip
Date : Sat Oct 20 2001 07:15 pm

###############################################################################
### PistolGrip's BAJA Examples
###############################################################################
### Note:  This file is an example only, it is by no means supposed to work or
###        or do anything other than hopefully help some people get started
###        with BAJA programming.  This code is not tested or thought-out very
###        well, it is only intended to show some basic concepts and common
###        tasks useful when coding custom modules.
###
###        Pistolgrip
###############################################################################
### Required Include Files for SBBS Definitions, and our File I/O Functions
###############################################################################
!include sbbsdefs.inc
!include file_io.inc
###############################################################################
### Defines Global or Constant Variables
###############################################################################
!define USER _USERON.ALIAS
!define MAXIMUM_VALUE 100
###############################################################################
### Define our Integer variables
###############################################################################
int cfg_file
int max_value
int access_lvl

###############################################################################
### Define our String variables
###############################################################################
str reg_name

###############################################################################
###
### When executing a BAJA module the command line arguments
### (for example "MYMOD.BIN MAINTENANCE")
### are available from the default String variable named 'str' in BAJA.
###
###############################################################################
### Copies the command line arguments for use later.
###############################################################################
truncsp str
copy cmd_line str
strupr cmd_line
###############################################################################
### Used for debugging
###############################################################################
#printf "%sp" cmd_line

###############################################################################
### Two things to notice about this next section:
### 1.) The "%n" in the path is a Synchronet Command Line Specifier that is
###     translated into your NODE directory as configured in SCFG.  Refer to
###     the Sysop Documentation appendix section on these, they are helpful
###     to the BAJA programmer.
### 2.) The forward slashes "/" in the path. This ensures Linux compatibility
###
###############################################################################
### Open our modules config file for reading
###############################################################################
fopen cfg_file O_RDONLY "%n../baja/mymod/mymod.cfg"
  if_false
    print "\r\n\r\nnError Loading Configuration File - MYMOD.CFG"
    return
  end_if
###############################################################################
### Now we'll read our config file one line at a time and set the appropriate
### variables to the correct values for our CONFIG.
###############################################################################
fread_line cfg_file reg_name
truncsp reg_name
###############################################################################
###
### Note: On these next two lines read-in, we read in a string value and then
###       convert it to an integer when we use the copy command.
###
fread_line cfg_file str
truncsp str
copy max_value str

fread_line cfg_file str
truncsp str
copy access_lvl str
###############################################################################
### Close our config file  (IMPORTANT)
###############################################################################
fclose cfg_file
###############################################################################
### Note: You can use this technique to fairly easily create complex
###       configuration and customization options of your programs.
###############################################################################

###############################################################################
### Here's were we will see what argurments were passed to module upon exec.
###############################################################################
compare cmd_line "maintenance"
if_true
  goto maintenance
end_if

###############################################################################
###############################################################################
###
### Main Entry Point
###
###############################################################################
###############################################################################
compare _USERON.LEVEL access_lvl
 if_less
    print "\r\nSorry, your access is insufficient for this program.\1p"
    return
  end_if

### More stuff here for your program

return
###############################################################################
##### End Main Program Section
###############################################################################

###############################################################################
###############################################################################
### This is where we go if called with the maintenance parameter
###############################################################################
:maintenance

### More stuff here for your program

return
###############################################################################
###############################################################################
### End of Sample BAJA Source
###############################################################################

---
� Synchronet � WasteLand BBS � telnet://wasteland.darktech.org