December 11, 2024, 09:13:18 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


A simple console text parser

Started by Raid, August 10, 2009, 10:04:46 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Raid

August 10, 2009, 10:04:46 PM Last Edit: August 11, 2009, 03:45:22 AM by Larry McCaughn
You can modify it at will. What I use it for is this:
I put a few thousand urls into a program called GetBot.
it saves a log containing all of the urls it visited and if the download was good or didn't work.
My program takes the log, strips out all the invalid connections, removes the Done, from the line and
writes all of the good stuff to another file. Some of the lines had characters well over 255; so I had an opportunity to use the Istring command. Very Nice!

I had very little experience programming in emergence, but I am feeling much more comfortable with the language now.

Edit 11th, 3:40am EST -- Cleaned up my code a little bit. :)

DEF sourcefile$,destinationfile$,sourceaccess$,destinationaccess$:STRING
DEF tempdata$[32767],temp1$[32767]:ISTRING
DEF exitflag, counter as INT
DEF mysource AS FILE
DEF mydestination as FILE

sourceaccess$="R"
destinationaccess$="W"

OPENCONSOLE

Input "Source file: ",sourcefile$
input "Destination: ",destinationfile$

print"I'm going to process the source file for any lines that are Done!"
print"and place those lines into your destination file."
print""

okayflag=openfile(mysource,sourcefile$,sourceaccess$)

if okayflag=1 THEN
print"Problem with source file, correct and try again!"
END
ENDIF

okayflag=openfile(mydestination, destinationfile$, destinationaccess$)

if okayflag=1 THEN
closefile mysource
print"Problem creating destination file, correct and try again!"
END
ENDIF

exitflag=0
print"Working..."
do

okayflag=read mysource,tempdata$
rem print tempdata$
temp1$=left$(tempdata$,5)
if okayflag=-1 THEN
exitflag=1
ENDIF

if temp1$="Done," THEN
counter=counter+1
temp1$=mid$(tempdata$, 6)
rem print temp1$
tempdata$=temp1$
okayflag=write mydestination, tempdata$
ENDIF

if okayflag=-1 THEN
exitflag=1
ENDIF

until exitflag=1
closefile mysource
closefile mydestination
print"Urls extracted: ", counter
CLOSECONSOLE
END

Proudly licensed EBASIC owner since Feb 2009. Network library present!

LarryMc

Raid

When posting code please enclose it using the "#" button above the smiley icons.

It makes it much easier to read.

Thanks

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library