Area: Quik_Bas Msg: #400 Date: 02-14-93 19:35 (Public) From: Robert Church To: Coridon Henshaw Subject: Nodelist parser
Hello Coridon! I couldn't get your nodelist parser to work, so I re-wrote it. I'm a lowly QB user, not PDS, so this may be the problem. I don't know which one is faster, like I said, I couldn't get yours to work. Here's what I cam up with: 'NAME: NODELIST.BAS 'FROM: Robert Church@1:105/330.3 'DESC: Nodelist reader DECLARE FUNCTION ExtractAddress$ (Zone%, Net%, Node%) DECLARE SUB PrintNodeListData (X%, Y%, Nodelist AS ANY) ' The following is in the QB example program TOKEN.BAS. ' This babie's a _gem_! DECLARE FUNCTION StrTok$ (Buffer$, Delim$) DEFINT A-Z TYPE AddrType Zone AS INTEGER Region AS INTEGER Net AS INTEGER Node AS INTEGER Pnt AS INTEGER 'forget something? END TYPE TYPE NodelistType Addr AS AddrType Sys AS STRING * 36 Location AS STRING * 36 Sysop AS STRING * 36 Phone AS STRING * 20 BPS AS STRING * 5 Flags AS STRING * 50 END TYPE DIM Nodelist AS NodelistType DIM NodeData$(1 TO 30) OPEN "\POINT\QNODE\NODELIST.043" FOR INPUT AS #1 ' 'Change to match the current nodelist number ' T& = TIMER DO DO LINE INPUT #1, Buffer$ LOOP UNTIL LEN(Buffer$) OR EOF(1) IF LEFT$(Buffer$, 1) <> ";" THEN Word$ = StrTok$(Buffer$, ",") FldNum = 0 DO FldNum = FldNum + 1 NodeData$(FldNum) = Word$ Word$ = StrTok$("", ",") LOOP UNTIL LEN(Word$) = 0 SELECT CASE NodeData$(1) CASE "Zone" Nodelist.Addr.Zone = VAL(NodeData$(2)) Nodelist.Addr.Region = 1 Nodelist.Addr.Net = 1 Nodelist.Addr.Node = 0 Nodelist.Addr.Pnt = 0 AddThis = 1 'a bit kludgy 'makes it so that the rest of the routine 'knows to add one to the rest of the fields CASE "Region" Nodelist.Addr.Region = VAL(NodeData$(2)) Nodelist.Addr.Net = Nodelist.Addr.Region Nodelist.Addr.Node = 0 Nodelist.Addr.Pnt = 0 AddThis = 1 CASE "Host" Nodelist.Addr.Net = VAL(NodeData$(2)) Nodelist.Addr.Node = 0 Nodelist.Addr.Pnt = 0 AddThis = 1 CASE "Down" Nodelist.Addr.Node = VAL(NodeData$(2)) Nodelist.Addr.Pnt = 0 NDF$ = "Down" AddThis = 1 CASE "Hub" Nodelist.Addr.Node = VAL(NodeData$(2)) Nodelist.Addr.Pnt = 0 NDF$ = "Hub" AddThis = 1 CASE "Pvt" Nodelist.Addr.Node = VAL(NodeData$(2)) Nodelist.Addr.Pnt = 0 NDF$ = "Pvt" AddThis = 1 CASE "Pnt" Nodelist.Flags = Nodelist.Flags + ",Pnt" Nodelist.Addr.Pnt = VAL(NodeData$(2)) AddThis = 1 CASE ELSE Nodelist.Addr.Node = VAL(NodeData$(1)) Nodelist.Addr.Pnt = 0 AddThis = 0 END SELECT Nodelist.Sys = NodeData$(2 + AddThis) Nodelist.Location = NodeData$(3 + AddThis) Nodelist.Sysop = NodeData$(4 + AddThis) Nodelist.Phone = NodeData$(5 + AddThis) Nodelist.BPS = NodeData$(6 + AddThis) Ctr = 7 + AddThis DO S$ = NodeData$(Ctr) NDF$ = NDF$ + "," + S$ Ctr = Ctr + 1 LOOP WHILE LEN(S$) > 0 Nodelist.Flags = NDF$ NDF$ = "" 'PrintNodeListData 3, 2, Nodelist 'DO: LOOP UNTIL LEN(INKEY$) END IF LOOP UNTIL EOF(1) PRINT "TIME: "; TIMER - T&; "seconds." FUNCTION ExtractAddress$ (Zone, Net, Node) ExtractAddress$ = RTRIM$(LTRIM$(STR$(Zone))) + ":" + RTRIM$(LTRIM$(STR$(Net))) + "/" + RTRIM$(LTRIM$(STR$(Node))) END FUNCTION SUB PrintNodeListData (X, Y, Nodelist AS NodelistType) LOCATE X, Y PRINT " Address: "; ExtractAddress(Nodelist.Addr.Zone, Nodelist.Addr.Net, Nodelist.Addr.Node); " " PRINT " ĀRegion: "; RTRIM$(LTRIM$(STR$(Nodelist.Addr.Region))) PRINT "System name: "; Nodelist.Sys PRINT " Location: "; Nodelist.Location PRINT " Sysop: "; Nodelist.Sysop PRINT " Phone: "; Nodelist.Phone PRINT " BPS Rate: "; Nodelist.BPS PRINT " Flags: "; Nodelist.Flags END SUB ' TOKEN.BAS ' ' Demonstrates a BASIC version of the strtok C function. ' DECLARE FUNCTION StrTok$ (Source$, Delimiters$) FUNCTION StrTok$ (Srce$, Delim$) STATIC Start%, SaveStr$ ' If first call, make a copy of the string. IF LEN(Srce$) THEN Start% = 1: SaveStr$ = Srce$ END IF Ln% = LEN(SaveStr$) BegPos% = Start% ' Look for start of a token (character that isn't delimiter). WHILE BegPos% <= Ln% AND INSTR(Delim$, MID$(SaveStr$, BegPos%, 1)) <> 0 BegPos% = BegPos% + 1 WEND ' Test for token start found. IF BegPos% > Ln% THEN StrTok$ = "": EXIT FUNCTION END IF ' Find the end of the token. EndPos% = BegPos% WHILE EndPos% <= Ln% AND INSTR(Delim$, MID$(SaveStr$, EndPos%, 1)) = 0 EndPos% = EndPos% + 1 WEND StrTok$ = MID$(SaveStr$, BegPos%, EndPos% - BegPos%) ' Set starting point for search for next token. Start% = EndPos% END FUNCTION I would be willing to take the entire nodelist compiler off of your hands and write a little API for things like keying by sysop, keying by address, etc. I have some ideas for a small nodelist format. Is there any special information you'll need in the nodelist, or is it pretty much standard BBS fare? [-= Rob =-] ...Real programmers drink Jolt! --- timEd/B7 * Origin: -= The Floating Point =- Hillsboro, Oregon, USA, Earth (1:105/330.3)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET