home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / PBAPI10.ZIP / DEMO1.BAS < prev    next >
BASIC Source File  |  1998-02-21  |  19KB  |  498 lines

  1. ' ─────────────────────────────────────────────────────────────────────────
  2. ' Program Title: Demo Program to Show How to read messages from TriBBS
  3. '     Copyright: 1997-98 By Freejack's Software
  4. '        Author: Gary Price
  5. ' Last Modified: 02/21/98
  6. ' ─────────────────────────────────────────────────────────────────────────
  7. '   Description: Program template for PowerBASIC programmers to control
  8. '                exactly how PowerBASIC generates your executables.
  9. ' ─────────────────────────────────────────────────────────────────────────
  10. '         Notes:
  11. ' ─────────────────────────────────────────────────────────────────────────
  12. '       History:
  13. ' ─────────────────────────────────────────────────────────────────────────
  14. $CPU 80386                    ' Requires a 386 system or faster
  15.  
  16. $OPTIMIZE SPEED             ' make fastest possible executable
  17.  
  18. $COMPILE EXE "DEMO1.EXE"   ' compile to an EXE
  19.  
  20. $DEBUG MAP      OFF         ' turn off map file generation
  21. $DEBUG PBDEBUG  OFF         ' don't include pbdebug support in our executable
  22.  
  23. $LIB COM        OFF         ' turn off PowerBASIC's communications library.
  24. $LIB CGA        OFF         ' turn off PowerBASIC's CGA graphics library.
  25. $LIB EGA        OFF         ' turn off PowerBASIC's EGA graphics library.
  26. $LIB VGA        OFF         ' turn off PowerBASIC's VGA graphics library.
  27. $LIB LPT        OFF         ' turn off PowerBASIC's printer support library.
  28. $LIB IPRINT     OFF         ' turn off PowerBASIC's interpreted print library.
  29. $LIB FULLFLOAT  OFF         ' turn off PowerBASIC's floating point support.
  30.  
  31. $ERROR ALL                  ' Set for All Error checks
  32.  
  33. $COM    0                   ' set communications buffer to nothing
  34. $STRING 32                  ' set largest string size at 32k
  35. $STACK  8192                ' let's use a 8k stack
  36. $SOUND  1                   ' smallest music buffer possible
  37.  
  38. $DIM ALL                    ' forces all Varibles and Arrays to be
  39.                             ' pre-dementioned before use.
  40.  
  41. $DYNAMIC                    ' all arrays will be dynamic by default
  42.  
  43. $OPTION CNTLBREAK OFF       ' don't allow Ctrl-Break to exit program
  44.  
  45. DEFINT A-Z                  ' default all variables to integers for maximum
  46.                             ' speed and minimum size
  47. '============================================================================
  48.  
  49. '============================================================================
  50. '                          DECLARATIONS SECTION
  51. '============================================================================
  52. ' ** THIS SECTION IS FOR LINKS AND INCLUDES STATMENTS **
  53.  
  54. $LINK "G:\PB35\TBAPI10\PBAPI10.PBL"    ' ** SET THIS LINE TO YOUR PATH **
  55. $INCLUDE "G:\PB35\TBAPI10\PBAPI10.INC" ' ** SET THIS LINE TO YOUR PATH **
  56.  
  57. '---------------------------------------------------------------------------
  58. ' ** DECLARE LOCAL SUB's BELOW THAT WILL BE USED IN THIS PROGRAM **
  59. '
  60. ' Use this section for any declarations needed to be made other than the
  61. ' MNNNN.HDR API which are located in the MNNNN.INC file.
  62.  
  63. DECLARE SUB MENU()
  64. DECLARE SUB OpenReadHeaderFiles()
  65. DECLARE SUB OpenReadTextFiles()
  66. DECLARE SUB DoMessageHeader()
  67. DECLARE SUB MessPausePrompt()
  68. DECLARE SUB MainMessPrompt()
  69. DECLARE SUB CloseFiles()
  70. DECLARE SUB GetYourMessages()
  71.  
  72. '---------------------------------------------------------------------------
  73. '* DECLARE ALL LOCAL AND SHARED VARIABLES USED IN MAIN PROGRAM BETWEEN SUBS *
  74. '
  75.  DIM ACF                AS SHARED STRING
  76.  DIM ConfName           AS SHARED STRING
  77.  DIM ConfNum            AS SHARED INTEGER
  78.  DIM CRASH              AS SHARED STRING
  79.  DIM DEL                AS SHARED STRING
  80.  DIM ECHO               AS SHARED STRING
  81.  DIM Hashvalue          AS SHARED LONG
  82.  DIM HeaderCounter      AS SHARED INTEGER
  83.  DIM HighestMessage     AS SHARED LONG
  84.  DIM MainMenuPrompt     AS SHARED STRING
  85.  DIM MainPrompt         AS SHARED STRING
  86.  DIM MenuHeaderText     AS SHARED STRING
  87.  DIM MessageNumber      AS SHARED LONG
  88.  DIM NETNAME            AS SHARED STRING
  89.  DIM NewConfNum         AS SHARED INTEGER
  90.  DIM PausePromptNonstop AS SHARED INTEGER
  91.  DIM PausePromptStop    AS SHARED INTEGER
  92.  DIM PER                AS SHARED STRING
  93.  DIM PUB                AS SHARED STRING
  94.  DIM REC                AS SHARED STRING
  95.  DIM RecordNumber       AS SHARED LONG
  96.  DIM REPLY              AS SHARED STRING
  97.  DIM TestFileFlag       AS SHARED INTEGER
  98.  DIM TotalMessConf      AS SHARED INTEGER
  99.  DIM YourMessFlag       AS SHARED INTEGER
  100.  
  101. '----------------------------------------------------------------------------
  102. ' ** SET THIS LINE BELOW TO YOUR TRIBBS MAIN NODE's DIRECTORY **
  103.  
  104. TBNode1sMainDirectory = "E:\TRIBBS"
  105. '============================================================================
  106.  
  107. '============================================================================
  108. '                         ** MAIN PROGRAM BODY **
  109. '============================================================================
  110. ON ERROR GOTO DONE                 ' Set Error Trap to Exit on any Errors
  111.  
  112. Hashvalue = Hashit("Gary Price")   ' Converts name to Hash Value which is
  113.                                    ' needed for "Your Messages"
  114.                                    ' Change to "Your Name" for use with this
  115.                                    ' example
  116.  
  117. ConfNum = 1                        ' Set & Begin Message Conference to #1
  118.  
  119.  MENU          ' Calls and prints Main Menu (SUB)
  120.  
  121.    DO          ' Main DO/LOOP to handle Main Menu Control
  122.      MainMenuPrompt = UCASE$(INKEY$)
  123.        SELECT CASE ASCII(MainMenuPrompt)
  124.          CASE 67    ' For C
  125.             COLOR 15,0:LOCATE 13,1:PRINT "Message Conferenc Range [1 -";STR$(TotalMessConf);"]"
  126.             INPUT "Enter Conference Number: ",NewConfNum
  127.               SELECT CASE NewConfNum
  128.                 CASE 1 TO TotalMessConf
  129.                   ConfNum = NewConfNum
  130.                   MENU
  131.                 CASE ELSE
  132.                   MENU
  133.               END SELECT
  134.          CASE 82    ' For R
  135.             LOCATE,,0                  ' Turn cursor off
  136.             OpenReadHeaderFiles        ' Opens and Reads current Header File
  137.              IF TestFileFlag <> 0 THEN
  138.                OpenReadTextFiles       ' Opens and Start Reading Messages
  139.              END IF
  140.             CloseFiles
  141.             MENU                      ' Calls Menu Sub
  142.          CASE 78    ' For N           ' Needs Users.spm Unit for this Search
  143.          CASE 89    ' For Y
  144.             LOCATE,,0                 ' Turn cursor off
  145.             YourMessFlag = 1          ' Sets Your Message Flag to 1/TRUE
  146.             OpenReadHeaderFiles       ' Opens and Reads current Header File
  147.              IF TestFileFlag <> 0 THEN
  148.                OpenReadTextFiles      ' Opens and Start Reading Your Messages
  149.              END IF
  150.             CloseFiles
  151.             MENU                      ' Calls Menu Sub
  152.        END SELECT
  153.  
  154.    LOOP WHILE MainMenuPrompt <> "G"
  155.  
  156. '============================================================================
  157. DONE:                               ' This label is only used for the exit
  158.                                     ' if we get an ON ERROR
  159.   COLOR 7, 0, 0                     ' Sets exit color to default gray
  160.   CLS SCREEN                        ' Clears the entire screen, homes cursor
  161.   LOCATE 25                         ' Positions Dos Prompt and Cursor on
  162.                                     ' Line 25
  163. END                                  ' End/Exit Program
  164.  
  165. '============================================================================
  166. SUB CloseFiles()
  167.  
  168.  MNNNN_HDR_Close
  169.  MNNNN_TXT_Close
  170.  
  171. END SUB
  172.  
  173. '============================================================================
  174. SUB MENU()
  175.  
  176. RecordNumber   = 1           ' Set/Reset Record Number to 1
  177. MainMenuPrompt = ""          ' Set Main Menu Varible to NULL/Empty
  178. MessageNumber  = 0           ' Set/Reset MessageNumber to NULL/Empty
  179. YourMessFlag   = 0           ' Set/Reset YourMessFlag to 0/FALSE
  180. TestFileFlag   = 0           ' Set/Reset Test OpenHeaderFile Flag
  181.                              ' to 0/False
  182. CLS                             ' Clears the Screen
  183.  
  184. MCONF_DAT_OpenRead(ConfNum)  ' In this section we open Mconf.dat and grab the
  185. ConfName = MCONF_DAT_GetMCN  ' info we need
  186. TotalMessConf = INT(MCONF_DAT_Length)
  187. HighestMessage = MCONF_DAT_GetHMN
  188.  
  189.   NETNAME = MCONF_DAT_GetNWCN   ' This gets all Network Names for this Conf.
  190.    IF NETNAME <> "" THEN
  191.      NETNAME = "<" + NETNAME + ">"
  192.    END IF
  193.  
  194.   IF MCONF_DAT_GetACF = 0 THEN
  195.     ACF = ""
  196.   ELSE
  197.     IF NETNAME = "" THEN
  198.       ACF = "<ALIAS>"
  199.     ELSE
  200.       ACF = " <ALIAS>"
  201.     END IF
  202.   END IF
  203. MCONF_DAT_Close              ' Now we are done with Mconf.dat and close it
  204.  
  205. MenuHeaderText = "Freejack's Place Message Menu"
  206. MenuBox 1, 1, 8, 78, 2, 7, MenuHeaderText
  207. COLOR 15,2: LOCATE  3,5: PRINT "<C>..Change Conference             ";"<R>..Read Messages"
  208. COLOR 15,2: LOCATE  4,5: PRINT "<N>..New Messages                  ";"<Y>..Your Messages"
  209. COLOR 15,2: LOCATE  5,5: PRINT "<G>..Goodye"
  210. COLOR 15,0: LOCATE  9,5: PRINT
  211. COLOR 10,0: LOCATE 10,1: PRINT "Current Conference: ";:COLOR 14,0: _
  212. PRINT ConfName + " ";:COLOR 15,0: PRINT NETNAME + ACF
  213.  
  214. COLOR 15,0: LOCATE 12,1: PRINT "Enter Selection - [C R N Y G]? ";
  215. LOCATE,,1
  216.  
  217. END SUB
  218.  
  219. '============================================================================
  220. SUB OpenReadHeaderFiles()
  221.  
  222.  IF MNNNN_HDR_Open(ConfNum)  = 0 THEN ' Tests MNNNN.HDR File to see if it
  223.                                       ' exists, if true, then open it
  224.    COLOR 12,0:LOCATE 14, 1:PRINT "This Message Conference is Empty!"
  225.    COLOR 15,0:
  226.    DELAY 1
  227.    TestFileFlag = 0
  228.    EXIT SUB
  229.  ELSE
  230.    MNNNN_TXT_Open(ConfNum) ' Opens the Mnnnn.txt for testing
  231.     IF MNNNN_TXT_Length = 0 THEN
  232.       COLOR 12,0:LOCATE 14, 1:PRINT "This Message Conference is Empty!"
  233.       COLOR 15,0:
  234.       DELAY 1
  235.       TestFileFlag = 0
  236.       EXIT SUB
  237.     ELSE
  238.       TestFileFlag = 1
  239.     END IF
  240.  END IF
  241. END SUB
  242.  
  243. '============================================================================
  244. SUB OpenReadTextFiles()
  245.  
  246. DIM Char13Pointer   AS LOCAL INTEGER
  247. DIM LineText        AS LOCAL STRING
  248. DIM LineReturnCount AS LOCAL INTEGER
  249. DIM MessLineCounter AS LOCAL INTEGER
  250. DIM MessText        AS LOCAL STRING
  251. DIM NewMessRecord   AS LOCAL LONG
  252. DIM RecTest         AS LOCAL LONG
  253. DIM ScreenCounter   AS LOCAL INTEGER
  254. DIM TotalTextMess   AS LOCAL INTEGER
  255.  
  256.  MNNNN_TXT_Open(ConfNum)  ' Opens the Mnnnn.txt file for messages to read
  257.  
  258. '----------------------------------------------------------------------------
  259. '*** Main Control Loop for reading Text part of the Messages ***
  260.  
  261. DO
  262.  
  263.   MNNNN_HDR_Read RecordNumber         ' Read in Message Header
  264.                                       ' for Record "n"
  265.    IF YourMessFlag = 1 AND MainPrompt <> CHR$(78) THEN ' For "Your Messages" Control
  266.       IF MainPrompt <> CHR$(45) THEN  ' Test to see if going backwards?
  267.         NewMessRecord = MNNNN_HDR_GetYourNext(Hashvalue, MessageNumber)
  268.          IF NewMessRecord <> -1 THEN  ' This block grabs next "Your Message"
  269.            RecordNumber = NewMessRecord ' & tests to make sure, then puts it
  270.          ELSE                           ' in the RecordNumber Counter
  271.            EXIT DO              ' If No More Your Messages let's bail out
  272.          END IF
  273.       ELSE                      ' If going backwards, then this block handles
  274.        RecTest = RecordNumber   ' a step back and then checks the Hash Values
  275.          FOR RecTest = (RecordNumber -1) TO 1 STEP -1 ' This FOR/NEXT loop does the
  276.           MNNNN_HDR_Read RecTest                 ' step back in messages and
  277.            IF MNNNN_HDR_GetTH = Hashvalue THEN   ' compares hash values
  278.              RecordNumber = RecTest   ' If we have a match, past the
  279.              EXIT FOR                 ' Record Number and exit our loop
  280.            EXIT IF
  281.            ELSE
  282.              MNNNN_HDR_Read RecordNumber ' No more messages backward?
  283.            END IF                        ' Then we reread in current
  284.         NEXT RecTest                     ' "Your Message" again
  285.       END IF
  286.    END IF
  287.  
  288.   MessageNumber = MNNNN_HDR_GetMN            ' Get Current Message Number
  289.  
  290.   DoMessageHeader                            ' Call and Create Message
  291.                                              ' Header Sub
  292.  
  293.   MessText = MNNNN_TXT_Read()    ' Gets the Text Message for the
  294.                                  ' MNNNN_HDR_Read RecordNumber that was
  295.                                  ' called above
  296.  
  297.  
  298.   LineReturnCount = TALLY(MessText, ANY CHR$(13)) ' Tally up the amount of
  299.                                                   ' times CHR$(13) appears
  300.                                                   ' in this message and set
  301.                                                   ' it to a counter
  302.   ScreenCounter = HeaderCounter                   ' Set Screen Counter to
  303.                                                   ' equal lines in our
  304.                                                   ' Header
  305.  
  306.   PausePromptNonstop = 0        ' Set/Reset to 0/FALSE
  307.  
  308.   FOR MessLineCounter = 1 TO LineReturnCount
  309.  
  310.     LineText = EXTRACT$(MessText, CHR$(13))  ' Here we extract each line of
  311.     INCR ScreenCounter                       ' Text from the mainstring
  312.     COLOR 11, 0: PRINT LineText
  313.     Char13Pointer = INSTR(MessText, CHR$(13))
  314.     MessText = MID$(MessText, Char13Pointer + 1)
  315.     LineText = ""
  316.  
  317.     IF PausePromptNonstop = 0 THEN    ' This block controls were the
  318.       IF ScreenCounter => 23 THEN     ' screen should stop during messages
  319.         IF MessLineCounter = LineReturnCount THEN EXIT FOR
  320.           MessPausePrompt
  321.         IF PausePromptStop = 1 THEN EXIT FOR
  322.         ScreenCounter = 0
  323.       END IF
  324.     END IF
  325.  
  326.   NEXT MessLineCounter
  327.  
  328.  MainMessPrompt
  329.  
  330. LOOP WHILE Mainprompt <> "Q"
  331.  
  332. END SUB
  333.  
  334. '============================================================================
  335. SUB MainMessPrompt()  ' This sub handles the end of each message
  336.  
  337. DIM TempNumber       AS LOCAL LONG
  338. DIM NewMessRecord    AS LOCAL LONG
  339.  
  340.  COLOR 12,0:PRINT "========================================================================"
  341.  COLOR 15,0: PRINT "<N>umber, <-> Prev, <+/ENTER> Next, <Q>uit ";
  342.  
  343.    DO
  344.  
  345.      MainPrompt = UCASE$(INKEY$)
  346.        SELECT CASE ASCII(MainPrompt)
  347.          CASE 78      ' For N
  348.             TempNumber = 0
  349.             PRINT
  350.             INPUT "Enter New Message Number";TempNumber
  351.                IF YourMessFlag = 1 THEN
  352.                  NewMessRecord = MNNNN_HDR_GetNext(TempNumber)
  353.                    IF NewMessRecord <> -1 THEN
  354.                     DO WHILE NewMessRecord < MNNNN_HDR_Length
  355.                       MNNNN_HDR_Read NewMessRecord
  356.                       IF MNNNN_HDR_GetTH = Hashvalue THEN ' compares hash values
  357.                         RecordNumber = NewMessRecord
  358.                         MessageNumber = TempNumber
  359.                         EXIT SELECT
  360.                       ELSE
  361.                         NewMessRecord = NewMessRecord + 1
  362.                       END IF
  363.                     LOOP
  364.                   ELSE
  365.                     MainPrompt = "Q"
  366.                    EXIT DO
  367.                   END IF
  368.                ELSE
  369.                  NewMessRecord = MNNNN_HDR_Search(TempNumber)
  370.                  IF NewMessRecord <> -1 THEN
  371.                    RecordNumber = NewMessRecord
  372.                    MessageNumber = TempNumber
  373.                  ELSE
  374.                    NewMessRecord = MNNNN_HDR_GetNext(TempNumber)
  375.                    IF NewMessRecord <> -1 THEN
  376.                      RecordNumber = NewMessRecord
  377.                    END IF
  378.                  END IF
  379.                END IF
  380.          CASE 45      ' For - Key
  381.                IF YourMessFlag <> 1 THEN
  382.                  IF RecordNumber > 1 THEN
  383.                    DECR RecordNumber
  384.                  ELSE
  385.                   MainPrompt = ""
  386.                  END IF
  387.                END IF
  388.          CASE 13, 43  ' For Enter/Return Key, + Key
  389.              NewMessRecord = MNNNN_HDR_GetNext(MessageNumber)
  390.              IF NewMessRecord <> -1 THEN
  391.                RecordNumber = NewMessRecord
  392.              ELSE
  393.                MainPrompt = "Q"
  394.                EXIT DO
  395.              END IF
  396.          CASE 81      ' For Q
  397.              EXIT DO
  398.          CASE ELSE
  399.              MainPrompt = ""
  400.        END SELECT
  401.  
  402.    LOOP WHILE MainPrompt = ""
  403.  
  404.   LOCATE 25,1: PRINT SPACE$(78): LOCATE 25,1
  405.  
  406. END SUB
  407.  
  408. '============================================================================
  409. SUB DoMessageHeader()  ' This sub creates our header for each Message
  410.  
  411.   IF MNNNN_HDR_GetPriMF = 0 THEN
  412.     PUB = "<PUBLIC>"
  413.   ELSE
  414.     PUB = "<PRIVATE>"
  415.   END IF
  416.  
  417.   IF MNNNN_HDR_GetEMF = 0 THEN
  418.     ECHO = ""
  419.   ELSE
  420.     ECHO ="<ECHO>"
  421.   END IF
  422.  
  423.   IF MNNNN_HDR_GetTMF = 0 THEN
  424.     REPLY = ""
  425.   ELSE
  426.     REPLY = "<HAS REPLIES>"
  427.   END IF
  428.  
  429.   IF MNNNN_HDR_GetRMF = 0 THEN
  430.     REC = ""
  431.   ELSE
  432.     REC = "<RECEIVED>"
  433.   END IF
  434.  
  435.   IF MNNNN_HDR_GetDMF = 0 THEN
  436.     DEL = ""
  437.   ELSE
  438.     DEL = "<DELETED>"
  439.   END IF
  440.  
  441.   IF MNNNN_HDR_GetPerMF = 0 THEN
  442.     PER = ""
  443.   ELSE
  444.     PER = "<PERMANENT>"
  445.   END IF
  446.  
  447.   IF MNNNN_HDR_GetCMF = 0 THEN
  448.     CRASH = ""
  449.   ELSE
  450.     CRASH = "<CRASH>"
  451.   END IF
  452.  
  453. HeaderCounter = 8
  454. COLOR 12,0:PRINT "========================================================================"
  455. COLOR 15,0:PRINT PUB + ECHO + REPLY + REC + DEL + PER + CRASH
  456. COLOR 10,0:PRINT "Number  :"; : COLOR 14,0:PRINT MessageNumber;"  of  "; _
  457. HighestMessage; : COLOR 10,0:PRINT "      Date: ";: COLOR 14,0:PRINT MNNNN_HDR_GetDAT
  458. IF MNNNN_HDR_GetNOMTRT <> 0 THEN
  459.  HeaderCounter = 9
  460.  COLOR 10,0: PRINT "Reply To:";:COLOR 14,0:PRINT MNNNN_HDR_GetNOMTRT
  461. END IF
  462. COLOR 10,0:PRINT "Confer  : ";:COLOR 14,0: PRINT ConfName + " ";:COLOR 15,0: PRINT _
  463. NETNAME + LTRIM$(ACF)
  464. COLOR 10,0:PRINT "From    : ";:COLOR 14,0:PRINT MNNNN_HDR_GetFU
  465. COLOR 10,0:PRINT "To      : ";:COLOR 14,0:PRINT MNNNN_HDR_GetTU
  466. COLOR 10,0:PRINT "Subject : ";:COLOR 14,0:PRINT MNNNN_HDR_GetMS
  467. COLOR 12,0:PRINT "------------------------------------------------------------------------"
  468. END SUB
  469.  
  470. '============================================================================
  471. SUB MessPausePrompt() 'If the message is => 23 lines, then this sub is called
  472.  
  473. DIM PausePrompt AS LOCAL STRING
  474.  
  475. PausePromptStop    = 0
  476. PausePromptNonstop = 0
  477.  
  478.  COLOR 15,0: PRINT "<S>top, <N>onstop, <ENTER> for more "
  479.  
  480.    DO
  481.  
  482.      PausePrompt = UCASE$(INKEY$)
  483.        SELECT CASE ASCII(PausePrompt)
  484.          CASE 13      ' For Enter/Return Key
  485.          CASE 83      ' For S
  486.            PausePromptStop = 1
  487.          CASE 78      ' For N
  488.            PausePromptNonstop = 1
  489.          CASE ELSE
  490.            PausePrompt = ""
  491.        END SELECT
  492.  
  493.    LOOP WHILE PausePrompt = ""
  494.  
  495.   LOCATE 24,1: PRINT SPACE$(78): LOCATE 24,1
  496.  
  497. END SUB
  498.