Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

working with text (fseek) 2

Status
Not open for further replies.

Kophein

MIS
Joined
Aug 6, 2002
Messages
3
Location
RO
I want to open a text file, extract some data, and export that data to another text file (an AutoCAD script). For that I will need to insert some commands before each piece of data I extracted, create a new line, and continue with the operation.
More specific, the original file looks like this:
Code:
Here goes the header... some info about the program
that generated this file.

     useless information
     p01 point: 12345.12345,54321.54321, more useless data
     p02 point: 56789.56789,98765.98765, more useless data
     useless information
end of file
I want it to look like this:
Code:
; --- HEADER ---
filedia 0
cmddia 0
; --- BODY ---
_open
"c:\drawing.DWG"
_point Point: 12345.12345,54321.54321
save
_point Point: 56789.56789,98765.98765
save
; --- FOOTER ---
filedia 1
cmddia 1
quit
So I want to extract the data between ":" and the first "," and from the first "," to the second "," and insert them into a text file.

Now how the heck do I do that?
If you have done that already, please send me something to reverse engineer, or please tell me the syntax. Thank you!

Dorel Octavian Cionvica
 
Here's an example. It's untested but you'll get the basic sytax and can play some more with it:

Code:
STORE 0 TO InFile, OutFile, nResult
InFile = FOPEN('InFile')
IF InFile < 0
   *... error stuff
ENDIF

OutFile = FCREATE(&quot;c:\drawing.DWG&quot;)  &&... overwrite mode
IF OutFile < 0
   *... error stuff
ENDIF   

*... FPUTS() returns # bytes written, it can be checked if you want.
*... write header etc
=FPUTS(OutFile, &quot;; --- HEADER ---&quot;)
=FPUTS(OutFile, &quot;filedia 0&quot;)
*... and so on

STORE '' TO tmpstr, OutStr
STORE 0 TO p1Start, p1End, p2Start, p2End

DO WHILE !FEOF(InFile)
   tmpstr = FGETS(InFile)
   IF 'point:' $ tmpstr
      p1Start = AT(&quot;:&quot;, tmpstr) + 2  &&... location of &quot;:&quot; + 2
      p1End   = AT(&quot;,&quot;) - 1          &&... 1st occurence of &quot;,&quot;, back up 1
      p2Start = AT(&quot;,&quot;) + 1          &&... same thing, only advance 1
      p2End   = AT(&quot;,&quot;, 2) - 1       &&... second occurence of &quot;,&quot;
   
      *...  assign to vars to debug easier.  Can be changed late if 
      *...   desired to on command [FPUTS(OutFile, &quot;_point Point....)]

      *... First point here 
      OutStr = &quot;_point Point: &quot;
      OutStr = OutStr + ;
         SUBSTR(tmpstr, p1Start, p1End) + &quot;,&quot;  &&... easier to debug this way
      =FPUTS(OutFile, OutStr)         &&... write it out

      OutStr = &quot;_point Point: &quot;
      OutStr = OutStr + ;
         SUBSTR(tmpstr, p2Start, p2End)
      =FPUTS(OutFile, OutStr)
      
      *... whatever else here      
   ENDIF
   *... Footer data here....
ENDDO   
[code]
 Dave S.
 
Dorel,
Actually, I wouldn't use FSEEK() at all. I'd just open the file (FOPEN), read records with FGETS() and check for &quot; point: &quot; (or whatever else might be an acceptable descriminator), and then just parse the point data from this line. It appears that the rest of the output is constant that you can FPUTS() into another FOPENed file.

Look at the $ operator for checking and the AT() function for your &quot;parsing&quot; - there is sample code in the help file for all these functions.

Rick
 
Thanks guys!
DSummZZZ, I'll try that right now. 10x.
rgbean, the source file is not as constant as I exemplified there. The &quot;P01 point:&quot; may turn into &quot;STLP:&quot;. And that's why I'll have to check the file row by row for those few discriminators. Thanks anyway, I'll try it too. Dorel Octavian Cionvica
REL Syspro Constanta, Romania
E-Mail: doc@relsys.ro
Tel: +40722291994
 
Well Since the Drawing.dwg file seems to be a space delimited file, I'd would do it this way

lcValid = 'PO1,P02,STPL,etc'
create a dbf,
Append from drawing.dwg sdf
delete all for alltrim(field(1)) $ lcValid = .f.
copy the required fields back out to a file.

David W. Grewe
Dave@internationalbid.com
 
dgrewe, the &quot;drawing.dwg&quot; file is nothing more than a drawing in AutoCAD. I wanted to insert some points in this file by using a script. I know the syntax for the script, but I needed a program to automatically generate that script for me using the data in another file (&quot;leika.idx&quot;).
FoxPro2.6 was only one of the possible programs to use for this, so I had to try to get some help from here. Thank you all. I used some of your ideas. Dorel Octavian Cionvica
REL Syspro Constanta, Romania
E-Mail: doc@relsys.ro
Tel: +40722291994
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top