home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / BBS_UTIL / BFE3100P.ZIP / BFE3100P.EXE / DOCS / SCRIPT.DOC < prev    next >
Text File  |  1994-03-12  |  22KB  |  691 lines

  1. ─────────────────────────────────────────────────────────────────────────────
  2.      ▄   ▄▄▄ ▄▄▄     ▄▄▄ ▄▄▄ ▄▄▄ ▄ ▄▄▄  ▄      ▄▄▄ ▄ ▄ ▄▄▄  ▄  ▄▄▄ ▄▄▄
  3.      █▄▄ █▄  █▄█     █▄▄ █   █ ▀ █ █▄█ ▀█▀     █▄▄ ▐▄▌ █▄▄ ▀█▀ █▄█ ▌█▐
  4.      █▄█ █   █▄▄     ▄▄█ █▄▄ █   █ █    █▄     ▄▄█  █  ▄▄█  █▄ █▄▄ ▌ ▐
  5.  
  6. ─────────────────────────────────────────────────────────────────────────────
  7.  
  8.                         INTRODUCTION AND OVERVIEW
  9.  
  10. BFE/Script is the name of the internal script processor in BFE.  Through the
  11. use of this system, users are able to "code" their own BFE scripts, and call
  12. them from their BFE menus.  Most users will not have a need for BFE/Script,
  13. as BFE alone provides quite an arsenal of tools to construct your frontend
  14. system.  However, for those who like to tinker with internals and the like,
  15. BFE/Script will prove to be a tremendous addition to your system.
  16.  
  17. In appearance, BFE/Script code is remarkably similar to the C language,
  18. although C is a much more powerful platform.  In fact, the entire BFE system
  19. was authored in C, while BFE/Script is but a user interface to the BFE
  20. internals.  If you are a C programmer, or have dabbled in C, then you should
  21. have no problems at all with BFE/Script.  Non-programmers should be sure to
  22. read over this section in its entirety, and study the sample scripts which
  23. are included in the BFE distribution archive.
  24.  
  25. Current features and constructs of BFE/Script include:
  26.  
  27.          - Access to internal BFE functions such as sysop paging, etc.
  28.          - Parameterized functions with local variables
  29.          - Function Recursion
  30.          - Global variables
  31.          - Keywords: if, do-while, while, for, and return.
  32.          - Numeric and character variable types
  33.          - Operators: +, -, *, /, %, <, >, <=, >=, ==, !=, unary +/-
  34.          - Functions which return integers
  35.          - BFE/Script is completely case-insensitive (unlike C!)
  36.  
  37. More BFE/Script functions and procedures will be added in future releases.
  38. Should you have any suggestions on possible additions to this unique feature
  39. of BFE, please contact us!
  40.  
  41.  
  42.                 SCRIPT SYNTAX RULES AND CODING BASICS
  43.  
  44. As we mentioned earlier, BFE/Script is very similar to C, at least in the
  45. general appearance of its code.  While this section is not meant to teach C,
  46. many of the rules will apply to both C and BFE/Script.  You may find it
  47. helpful to pick up an introductory C programming book in order to hone your
  48. BFE/Script skills.
  49.  
  50. All of your scripts should be edited with your favorite ASCII text editor,
  51. such as Q-Edit, TED, DOS-Edit, etc.
  52.  
  53. Your BFE/Scripts are composed of functions, and calls to these functions.
  54. Each of your functions must be completed enclosed in a "code-block".  For
  55. example:
  56.  
  57.          printmessage()
  58.          {
  59.            putsnl("Welcome to my first BFE script!");
  60.          }
  61.  
  62. In the above example, the function "printmessage" is a user-defined function,
  63. consisting of nothing more than a call to "putsnl" (put string with a CR/LF
  64. pair).  There are two very essential concepts about the above.  The first
  65. being the two curly braces which separate the function name, in this case,
  66. putmessage(), and the actual function contents, the call to putsnl().
  67.  
  68. The second item of interest is the semi-colon following the call to putsnl().
  69. This signifies the end of the current function call.  Let's take a look at
  70. another small example:
  71.  
  72.          /* My first BFE Script! */
  73.  
  74.          main() {
  75.            clearscreen();
  76.            printmessage();
  77.          }
  78.  
  79.          printmessage()
  80.          {
  81.            putsnl("Welcome to my first BFE script!");
  82.            putsnl("Press any key to return to BFE!");
  83.            getkey();
  84.          }
  85.  
  86. In this example, we have expanded on our original printmessage() example.
  87. In actuality, the original example we discussed is not complete!  Each of
  88. your BFE scripts *must* contain a function called "main".  This function is
  89. used as the starting point of the script.
  90.  
  91. In the above example, you will also notice the placement of the two curly
  92. braces in the function main(), is a bit different from that of the function
  93. printmessage().  Like C, BFE/Script is a free-format language, to an extent.
  94. Spacing and line order doesn't matter.  As long as the constructs are
  95. present.
  96.  
  97. In the above example, BFE/Script would start processing in the function
  98. main(), with consists of nothing more than a call to printmessage().  When
  99. printmessage() is executed, the two calls to putsnl() would display the text
  100. to the user.  The call to getkey() would simply wait for a keypress from the
  101. user.  At that point, control is returned to main().  Since main() has no
  102. more processing left, BFE/Script in turn returns control back to BFE.
  103.  
  104. Let's take a look at the use of user-defined variables, as these will play an
  105. important role in even the most primitive of scripts.  Currently, BFE
  106. supports two types of variables, character and numeric.  Additional, more
  107. advanced data types (such as floating point and string), will be introduced
  108. in a later release of the package.
  109.  
  110. To define a user-defined variable, use the following construct:
  111.  
  112.                  <type> <identifier>
  113.  
  114. Here are a few examples:
  115.  
  116.                                int x,y,z;
  117.  
  118. The above example creates three (3) numeric variables (integers) called x, y,
  119. and z.  (Note the ability to separate variable definitions of the same type
  120. with a comma!  You cannot mix more than one type like this).
  121.  
  122.                                char key;
  123.                                char a,b,c;
  124.  
  125. Similarly, the above examples generate character variables, called "key", a,
  126. b, and c.
  127.  
  128. All variables (unlike C) are automatically initialized to zero.  To set a
  129. variable's value, simply use the "=" operator:
  130.  
  131.          x = 10;
  132.          y=1;
  133.          key = 'A';
  134.  
  135. Variables declared inside of a function block are "local" to that function,
  136. and are not available in any other function!  These "local" variables are
  137. also re-initialized on each call to the owning function.  Similarly, any
  138. variables declared outside of any function are declared as "global" variables
  139. and are available anywhere in the script, in any function.  Global variables
  140. retain their values unless explicitly changed.
  141.  
  142. Another extremely powerful feature of BFE/Script is the ability to pass
  143. values to and from functions.  This is known as "parameterized functions".
  144. Perhaps another example is in order:
  145.  
  146.          main()
  147.          {
  148.            int x,y,z;
  149.            char t;
  150.            clearscreen();
  151.            puts("Enter a number: ");
  152.            x = getnum();
  153.  
  154.            ShowNumber(x);
  155.          }
  156.  
  157.          ShowNumber(int z)
  158.          {
  159.            puts("X is equal to: ");
  160.            print(z);
  161.            putsnl("Press any key to exit!");
  162.            getkey();
  163.          }
  164.  
  165. In this particular example, starting in the main() function, the user is
  166. prompted to enter a number.  This number is then passed to the ShowNumber()
  167. function, where the number is displayed.  This is also a great example of
  168. local variables, as the variable "z" is local to the ShowNumber() function,
  169. even though it will end up with the same value as the main() function's local
  170. variable "x".
  171.  
  172. Easy, isn't it?  Great!  Now that we have variables under our belt, let's
  173. discuss some of the conditional keywords which BFE/Script makes use of.
  174.  
  175.          dumb_function() {
  176.             int x;
  177.  
  178.             x = getnum();
  179.  
  180.             if(x < 10) {
  181.               putsnl("Number is less than 10!");
  182.             }
  183.  
  184.             if(x == 10) {
  185.               putsnl("Number is equal to 10!");
  186.             }
  187.  
  188.             if(x > 10) {
  189.               putsnl("Number is greater than 10!");
  190.             }
  191.          }
  192.  
  193. In the above function, we declare a local variable called "x".  We then set
  194. this variable equal to the value returned by the getnum() function (the
  195. getnum() function simply queries the user for a numeric value).  We then put
  196. the contents of "x" through a series of tests, using the "if" keyword.
  197. Simple, eh?
  198.  
  199.          dumb_function2() {
  200.            int x;
  201.  
  202.            for(x=1; x<11; x=x+1) {
  203.              print(x);
  204.            }
  205.          }
  206.  
  207. The above example uses a "for" loop to display the numbers 1 through 10.
  208.  
  209.          dumb_function3() {
  210.            int x;
  211.            x = 1;
  212.            while(x <= 10) {
  213.              print(x);
  214.              x = x + 1;
  215.            }
  216.          }
  217.  
  218. This example does the same thing, only instead of the "if" loop, we use a
  219. "while" loop.
  220.  
  221.          dumb_function4() {
  222.            int x;
  223.  
  224.            do {
  225.               print(x);
  226.            } while(x <= 10);
  227.          }
  228.  
  229. In the above example, we use a modified version of the "while" loop, known as
  230. the "do-while" loop.  Simple, isn't it?
  231.  
  232. Ah, but what would code be without comments?  BFE/Script implements the C-
  233. style "slash-asterisk" comment.
  234.  
  235.          /* This is my first script! */
  236.  
  237. Anything which falls in between the /* and the */ is ignored by BFE/Script
  238. and treated as a comment.  Comments may span several lines:
  239.  
  240.          /* This is my first script!
  241.                  Enjoy!
  242.          */
  243.  
  244. or how about:
  245.  
  246.          /* This is my first script!
  247.  
  248.                  Enjoy it! */
  249.  
  250. On a final note, all items contained in a BFE script are case-insensitive. In
  251. other words GETKEY() is the same as getkey() or GeTkEy().
  252.  
  253. That's about all of the help I can provide at this point.  As this feature
  254. expands to new horizons as BFE progresses, the documentation on it will
  255. inherently get better.  Trust me!  Feel free to post your scripts in the
  256. SPHINX echo should you require assistance.  Now, let's move on to the actual
  257. function calls contained with the scripting system.
  258.  
  259.  
  260.                         SCRIPT FUNCTION REFERENCE
  261.  
  262. ADDTIME();
  263.  
  264.          Adds the passed numeric value to the user's total remaining time
  265.          online.
  266.  
  267.          Example: /* This adds 5 minutes to the user's time */
  268.                   addtime(5);
  269.  
  270.  
  271. CENTERMSG();
  272.  
  273.          Centers the passed text string on the current line.
  274.  
  275.          Example: centermsg("Welcome to this script!");
  276.  
  277.  
  278. CHANGEEXITSCRIPT();
  279.  
  280.          Changes the global exit script to the passed script file name.
  281.  
  282.          Example: ChangeExitScript("NEWEXIT.SCR");
  283.  
  284.  
  285. CHECKANSI();
  286.  
  287.          Returns TRUE if the user is in ANSI graphics mode, or FALSE if
  288.          the user is in standard ASCII/TTY mode.
  289.  
  290.          Example:
  291.                   ShowGraphicsMode() {
  292.                       int ansi;
  293.  
  294.                       ansi = checkansi();
  295.  
  296.                       if(ansi) {
  297.                         centermsg("Graphics Mode: ANSI");
  298.                       } else {
  299.                         centermsg("Graphics Mode: ASCII");
  300.                       }
  301.                   }
  302.  
  303. CHECKRIP();
  304.  
  305.          Returns TRUE if the user is in RIP graphics mode, or FALSE if
  306.          the user is not.
  307.  
  308. CHECKACCESS();
  309.         
  310.          Returns the current user's security level.
  311.          
  312.          Example:  int access;
  313.                    access = CheckAccess();
  314.                    puts("Current security level is: ");
  315.                    print(access);
  316.                    putsnl(" ");
  317.  
  318. CHECKBAUD();
  319.  
  320.          Returns user's current baud rate.
  321.          
  322. CHECKNODE();
  323.  
  324.          Returns the current BFE node number.
  325.  
  326. CLEARSCREEN();
  327.  
  328.          Clears the screen both remotely and locally.
  329.  
  330.          Example: clearscreen();
  331.  
  332.  
  333. DISPLAYFILE();
  334.  
  335.          Displays an ANSI/ASCII/AVATAR/RIP file to the user.  See the section
  336.          on the type "D" menu option for more details on how BFE displays
  337.          external files!
  338.  
  339.          Examples: Displayfile("WELCOME");
  340.                    Displayfile("WELCOME.TXT");
  341.  
  342. DOWNLOADFILE();
  343.  
  344.          Initiates a download session for the passed file.
  345.  
  346.          Examples: Downloadfile("MASTER.ZIP");
  347.                    Downloadfile("C:\FILES\MASTER.ZIP");
  348.  
  349.  
  350. DOWNLOADLIST();
  351.  
  352.          Allows the user to browse a BFE-style FILES.BBS file, and download
  353.          files from the list.  Functions exactly as its menu type counterpart.
  354.          Simply pass the path that the FILES.BBS resides in.  The filename
  355.          FILES.BBS is assumed at this time.
  356.  
  357.          Examples: DownloadList("C:\BFE\NEWFILES");
  358.                    DownloadList("C:\SUPPORT\BETAFILE");
  359.  
  360. ERROR();
  361.  
  362.          Displays a BFE-style error message.
  363.  
  364.          Example: Error("Your error message goes here!");
  365.  
  366.  
  367. ERRORLEVELLOW();
  368.  
  369.          Exits the current script and BFE with an errorlevel.  DTR is lowered.
  370.          (Hangs up on user!)
  371.  
  372.          Example: errorlevellow("100");
  373.  
  374. ERRORLEVELHI();
  375.  
  376.          Exits the current script and BFE with an errorlevel.  DTR is left
  377.          high.  (Doesn't hang up on user!)
  378.  
  379.          Example: errorlevelhi("100");
  380.                        
  381. ESTABLISHGATEWAY();
  382.  
  383.          This function will establish a gateway session, without the user
  384.          having to actually log in.  This is *extremely* handy if you wish
  385.          to shield the user from the UNIX login prompts, or if you wish to
  386.          write BFE script files which perform automated logins and tasks.
  387.          The only argument you need to pass is the gateway port.  To see this
  388.          function in action, see the SENDFILE.SCR script file in the sample
  389.          SCRIPTS subdirectory included with the BFE distribution archive.
  390.          This script performs an automated login, and simple file transfer.
  391.  
  392.          Example: EstablishGateway(1);
  393.  
  394. FLASHFILE();
  395.  
  396.           Displays a ANS/ASC/AVT/RIP file with no page pausing.
  397.  
  398. GATEWAY();
  399.  
  400.          Initiates a BFE "gateway" from one serial port to another.  This is
  401.          used primarily to pass a BFE caller from a DOS environment to a
  402.          UNIX environment, with BFE's gateway feature acting as the mediator.
  403.          See the GATEWAY.DOC file for more information on this feature.
  404.  
  405.          Example: gateway(1, 1);
  406.  
  407. GETKEY();
  408.  
  409.          Gets a keystroke from the keyboard and returns the value.
  410.  
  411.          Example:  char key;
  412.                    key = getkey();
  413.  
  414. GETNUM();
  415.  
  416.          Gets and returns a numeric value from the user.
  417.  
  418.          Example: int x;
  419.                   x = getnum();
  420.  
  421.  
  422. GETRANDOM();
  423.  
  424.          Returns a random number from 0 to the passed numeric value.
  425.  
  426.          Example:  /* Get a number from 1 to 100 */
  427.                    int x;
  428.                    x = getrandom(100);
  429.                    x = x + 1
  430.  
  431. GETSCRBUF();
  432.  
  433.          Loads the internal script input buffer with a line of user input.
  434.          This value may be substituted in some function calls via a special
  435.          "%B" macro.  Returns 0 is no input, 1 otherwise.
  436.  
  437.          Example: /* Simple example with no error checking! */
  438.                   puts("Enter a filename: ");
  439.                   GetScrBuf();
  440.                   RunExternal("dsz sz %B");
  441.                   
  442. GOODBYE();
  443.  
  444.          Hangs up on the user and exits BFE with an errorlevel of 255.
  445.  
  446.          Example: Goodbye();
  447.  
  448. IFEXIST();
  449.  
  450.          Returns TRUE if the passed filename exists (no wildcards allowed!)
  451.  
  452.          Example:
  453.                  main() {
  454.                    int x;
  455.  
  456.                    x = ifexist("C:\AUTOEXEC.BAT");
  457.  
  458.                    if(x) {
  459.                      putsnl("AUTOEXEC.BAT exists!");
  460.                    }
  461.                    if(x==0) {
  462.                      putsnl("Error locating AUTOEXEC.BAT!");
  463.                    }
  464.                  }
  465.  
  466. LEAVEMSGSDM();
  467.  
  468.          Places the user in BFE/Edit using the passed message area number.
  469.          The message area templates are configurable in BFE/Setup.
  470.          The "SDM" portion of this command stands for "Star-dot-MSG", or
  471.          "*.MSG", which is the fidonet standard.
  472.  
  473.          Examples: leavemsgsdm(1);
  474.                    leavemsgsdm(8);
  475.  
  476.  
  477. LEAVEMSGSQ();
  478.  
  479.          Places the user in BFE/Edit using the passed message area number.
  480.          The "SQ" portion of this command stands for "Squish", as this
  481.          function utilizes Scott Dudley's Squish message base format.
  482.  
  483.          Examples: leavemsgsq(1);
  484.                    leavemsgsq(8);
  485.  
  486. MAKEDORINFO();
  487.  
  488.          Creates a DORINFO?.DEF dropfile in the passed directory.
  489.  
  490.          Example: makedorinfo("C:\BBS\MYDOOR");
  491.  
  492.  
  493. MAKEDOORSYS();
  494.  
  495.          Creates a DOOR.SYS dropfile in the passed directory.
  496.  
  497.          Example: makedoorsys("C:\BBS\MYDOOR");
  498.  
  499.  
  500. MAKESFDOORS();
  501.  
  502.          Creates a SFDOORS.DAT dropfile in the passed directory.
  503.  
  504.          Example: makesfdoors("C:\BBS\MYDOOR");
  505.  
  506. MENU();
  507.  
  508.          Queries the user for a response.  All valid keystrokes are passed as
  509.          a parameter.  MENU() returns the first valid keystroke.
  510.  
  511.          Example: char key;
  512.  
  513.                   putsnl("1 - Option 1");
  514.                   putsnl("2 - Option 2");
  515.                   putsnl("Q - Quit this script");
  516.                   key = menu("12Qq");
  517.  
  518. MENULINE();
  519.  
  520.          Displays line of text and hotkey, similar to the way BFE handles
  521.          its default internal menus.  (Text mode only, no RIP!)
  522.  
  523.          Example:
  524.                  clearscreen();
  525.                  centermsg("Welcome to BFE!");
  526.                  menuline("Go to WildCAT!", "1");
  527.                  menuline("Go to Maximus", "2");
  528.                  menuline("Goodbye", "G");
  529.                  menu("12PG");
  530.  
  531. OS_SHELL();
  532.  
  533.          Performs a remote (or local) shell to the contents of COMPSEC.
  534.  
  535.          Example: os_shell();
  536.  
  537.  
  538. PAGE();
  539.  
  540.          Initiates a page to the sysop.  All hour restrictions are valid!
  541.  
  542.          Example: page();
  543.  
  544. PAGENOW();
  545.  
  546.          Initiates a page to the sysop.  All hour restrictions are IGNORED!
  547.  
  548.          Example: pagenow();
  549.  
  550. PASSWORD();
  551.  
  552.          Accepts a password from the user, and compares it to the password
  553.          which is passed to the function.  Returns TRUE on success, or FALSE
  554.          if the passwords did not match.
  555.  
  556.          Example:
  557.                  secret_page() {
  558.                    int x;
  559.                    x = password("SECRET");
  560.                    if(x) {
  561.                      pagenow();
  562.                    }
  563.                  }
  564.  
  565.  
  566. PLAYMUSIC();
  567.  
  568.          Plays an ANSI music string on the remote speaker only.
  569.  
  570.          Example: PlayMusic("MBT120L4MFMNO4");
  571.  
  572.  
  573. PRINT();
  574.  
  575.          Used to display numeric values.
  576.  
  577.          Example: int x;
  578.                   x = getnum();
  579.                   print(x);
  580.  
  581. PUTCH();
  582.  
  583.          Puts a single character to the display.
  584.  
  585.          Example: putch('*');
  586.  
  587.  
  588. PUTS();
  589.  
  590.          Puts a string to the display (no carriage return/linefeed!).
  591.  
  592.          Examples: puts("Testing!");
  593.                    puts("!|*|");         /* Clear RIP screen! */
  594.  
  595.  
  596. PUTSNL();
  597.  
  598.          Puts a string to the display, and appends a carriage return/linefeed.
  599.          PUTSNL is short for "put string with a CR/LF pair".
  600.  
  601.          Example: putsnl("Testing again!");
  602.  
  603.  
  604. RUNEXTERNAL();
  605.  
  606.          Runs an external process.  All "process" macros (%p, %s, %t, %n)
  607.          are available.
  608.  
  609.          Examples: runexternal("DOOR.EXE -p%p -s19200 -t%t -n%n");
  610.                    runexternal("COMMAND.COM /C del dorinfo1.def");
  611.  
  612.  
  613. SETCOLOR();
  614.  
  615.          Sets the current text attribute.  The following color codes format
  616.          table is used:
  617.  
  618.             {Bright} {Flashing} [Foreground Color] on [Background Color]
  619.  
  620.          Where foreground and background colors are one of:
  621.  
  622.            Black
  623.            Blue
  624.            Green
  625.            Cyan
  626.            Red
  627.            Magenta
  628.            Yellow / Brown
  629.            White / Grey
  630.  
  631.          Examples: setcolor("bright white on black");
  632.                    setcolor("flashing bright yellow on blue");
  633.  
  634. SUBTIME();
  635.  
  636.          Subtracts the passed numeric value to the user's total remaining
  637.          time online.
  638.  
  639.          Example: /* This subtracts 5 minutes to the user's time */
  640.                   subtime(5);
  641.  
  642.  
  643. TOGGLEANSI();
  644.  
  645.          Toggles ANSI graphics on and off.
  646.  
  647.          Example: toggleansi();
  648.  
  649.  
  650. TRANSMIT2GATEWAY();
  651.  
  652.          Transmits a command string through an enabled serial gateway port.
  653.          This will be used most prevalently during UNIX gateway sessions.
  654.          This function can be run in one of two methods:  PASSIVE mode or
  655.          ACTIVE mode (similar to the two corresponding menu types).  The
  656.          first argument to the function is the actual command string, and
  657.          the second argument is the "mode" to run in (0=PASSIVE, 1=ACTIVE).
  658.          PASSIVE mode will simply gate the command to the server through
  659.          the gateway port, and will *immediately* return to the calling
  660.          script.  In ACTIVE mode, the user will remain in the gateway
  661.          session, until the RETURN2BFE server command is returned to BFE
  662.          by your application.
  663.  
  664.          Examples:  /* Run the mail command ACTIVELY */
  665.                     Transmit2Gateway("mail", 1);
  666.  
  667.                     /* Write a message to the console PASSIVELY */
  668.                     Transmit2Gateway("write root tty01 < /etc/motd", 0);
  669.  
  670. UPLOADFILE();
  671.  
  672.          Initiates an upload from the user.
  673.  
  674.          Example: Uploadfile();
  675.  
  676.  
  677. WAIT();
  678.  
  679.          Forces BFE to "pause" for the passed number of milliseconds.
  680.  
  681.          Example: /* Pause for 5 seconds */
  682.                   wait(5000);
  683.  
  684.  
  685. WRITELOG();
  686.  
  687.          Used for logging information from BFE/Script.
  688.  
  689.          Example: writelog("This is a test!");
  690.  
  691.