The Forum is up for sale: XeNTaX Forum looking for new owner

Help in converting text file.

Coders and would-be coders alike, this is the place to talk about programming.
Xela
VIP member
VIP member
Posts: 225
Joined: Sun Jul 31, 2005 4:12 am
Been thanked: 1 time

Help in converting text file.

Post by Xela »

Here is another request for help or advice I submit to this community. I am trying to addopt 3rd party utylity program for one major flight simulator to needs of another. Here is the sample of output and input required.
OUTPUT FROM 1st PROGRAM

[Macro]
Name=BoxBuilding1
X=6.4
Y=7
Rotation=180
File=D:\Leung Software\FS Scenery Creator\Macros\PARKING.API
V1=10000
V2=100
Param0=1.92
Param1=1.92

[Macro]
Name=BoxBuilding2
X=110
Y=37
Rotation=180
File=D:\Leung Software\FS Scenery Creator\Macros\PARKING.API
V1=10000
V2=100
Param0=2.56
Param1=2.56

[Macro]
Name=BoxBuilding3
X=114
Y=37
Rotation=180
File=D:\Leung Software\FS Scenery Creator\Macros\PARKING.API
V1=10000
V2=100
Param0=2.56
Param1=2.56

*************************************************************
INPUT FOR 2ndPROGRAM

[city1.bmp]
ObjectCount=3

Object000.TypeName=BoxBuilding1
Object000.MapClass=0
Object000.Chance=100
Object000.PositionX=6.400000
Object000.PositionY=7.000000
Object000.Angle=180.000000

Object001.TypeName=BoxBuilding2
Object001.MapClass=0
Object001.Chance=100
Object001.PositionX=110.000000
Object001.PositionY=37.000000
Object001.Angle=180.000000

Object002.TypeName=BoxBuilding3
Object002.MapClass=0
Object002.Chance=100
Object002.PositionX=114.000000
Object002.PositionY=37.000000
Object002.Angle=180.000000
Some of the lines are simply redundant, some needs to be reformated and slightly changed, or added. All can be done with "find and replace " of any word processor, however I was wondering if more automatic approach could be devised. I can write line by line required changes.
Deniz Oezmen
VIP member
VIP member
Posts: 185
Joined: Mon Aug 28, 2006 2:07 pm
Has thanked: 1 time
Been thanked: 14 times
Contact:

Post by Deniz Oezmen »

If the number of files you want to convert is big enough to justify the effort, you could always write a lexer/parser combination that reads the data structures of the first file and outputs the reformatted information to the second file.

Judging from what you posted, this should not be very hard to do -- the format is line-based and doesn't seem to be nested in any difficult way.

Can you specify exactly what needs to be converted to what? And from where do you get the additional information that is not stored in the first file?
Xela
VIP member
VIP member
Posts: 225
Joined: Sun Jul 31, 2005 4:12 am
Been thanked: 1 time

Post by Xela »

Something like this.......

Code: Select all

OUTPUT FROM 1st PROGRAM	               DESIRED INPUT FOR 2nd PROGRAM


ADD:[name of texture.bmp]
ADD:ObjectCount=total number of lines /6
[Macro]	DELETE this line
Name=BoxBuilding1		                REPLACE: Name with Object%.TypeName  
ADD:Object%.MapClass=0
ADD:Object%.Chance=100
X=6.4				REPLACE: X with Object%.PositionX  
Y=7				REPLACE: Y with Object%.PositionY  
Rotation=180			REPLACE: Rotation with Object%Angle  
File=D:\Leung Softwre\FS………	                DELETE this line
V1=10000			                DELETE this line
V2=100				DELETE this line
Param0=1.92			DELETE this line
Param1=1.92			DELETE this line


[Macro]				DELETE this line
Name=BoxBuilding2		                REPLACE: Name with Object%.TypeName  
ADD:Object%.MapClass=0
ADD:Object%.Chance=100
X=110				REPLACE: X with Object%.PositionX  
Y=37				REPLACE: Y with Object%.PositionY  
Rotation=180			REPLACE: Rotation with Object%Angle  
File=D:\Leung Softwre\FS………	                DELETE this line
V1=10000			                DELETE this line
V2=100				DELETE this line
Param0=2.56			DELETE this line
Param1=2.56			DELETE this line


[Macro]				DELETE this line
Name=BoxBuilding3		                REPLACE: Name with Object%.TypeName  
ADD:Object%.MapClass=0
ADD:Object%.Chance=100
X=114				REPLACE: X with Object%.PositionX  
Y=37				REPLACE: Y with Object%.PositionY  
Rotation=180			REPLACE: Rotation with Object%Angle  
File=D:\Leung Softwre\FS………	                DELETE this line
V1=10000			                DELETE this line
V2=100				DELETE this line
Param0=2.56			DELETE this line
Param1=2.56			DELETE this line
	




DESIRED INPUT	
[city1.bmp]	
ObjectCount=3	

Object000.TypeName=BoxBuilding1	
Object000.MapClass=0
Object000.Chance=100
Object000.PositionX=6.400000
Object000.PositionY=7.000000
Object000.Angle=180.000000

Object001.TypeName=BoxBuilding2
Object001.MapClass=0
Object001.Chance=100
Object001.PositionX=110.000000
Object001.PositionY=37.000000
Object001.Angle=180.000000

Object002.TypeName=BoxBuilding3
Object002.MapClass=0
Object002.Chance=100
Object002.PositionX=114.000000
Object002.PositionY=37.000000
Object002.Angle=180.000000
Sorry for this little chaotic format.
bored
beginner
Posts: 28
Joined: Sun Mar 12, 2006 9:03 pm
Been thanked: 1 time

Post by bored »

I've created a quick and dirty parser for you. I'll mail it to your hotmail....
Deniz Oezmen
VIP member
VIP member
Posts: 185
Joined: Mon Aug 28, 2006 2:07 pm
Has thanked: 1 time
Been thanked: 14 times
Contact:

Post by Deniz Oezmen »

Well, this program is not pretty ... but it should hopefully work.

I've assumed there are no negative values as positions given; else a slight change might be necessary.

[Edit: Well, the change would only be cosmetical. There might be odd warnings if a value is equal to -1.0, but the file will nevertheless be converted correctly.]
You do not have the required permissions to view the files attached to this post.
Xela
VIP member
VIP member
Posts: 225
Joined: Sun Jul 31, 2005 4:12 am
Been thanked: 1 time

Post by Xela »

Thank you BOTH very, very much. As soon as I can catch some time I will try those converter/parsers. :D
Deniz Oezmen
VIP member
VIP member
Posts: 185
Joined: Mon Aug 28, 2006 2:07 pm
Has thanked: 1 time
Been thanked: 14 times
Contact:

Post by Deniz Oezmen »

You're welcome. Don't forget to post your results. ;-)
Xela
VIP member
VIP member
Posts: 225
Joined: Sun Jul 31, 2005 4:12 am
Been thanked: 1 time

Post by Xela »

Thank you for your quick assistance.Thanks a milion. :D
The results are in: PERFECT :!: I understand that this works only in DOS box, but NP.

I will play with it little more, but so far so good. Perhaps just this one: in converted file there are empty lines separating each entry. My fault - but can they be deleted?
Deniz Oezmen
VIP member
VIP member
Posts: 185
Joined: Mon Aug 28, 2006 2:07 pm
Has thanked: 1 time
Been thanked: 14 times
Contact:

Post by Deniz Oezmen »

Xela wrote:Thank you for your quick assistance.Thanks a milion. :D
The results are in: PERFECT :!:
Nice to hear that it works. :-)
Xela wrote:I understand that this works only in DOS box, but NP.
A command-line version was the easiest thing to do -- however, adding a simple GUI would be no problem. If you tell me what you need ...
Xela wrote:I will play with it little more, but so far so good. Perhaps just this one: in converted file there are empty lines separating each entry. My fault - but can they be deleted?
Sure, no problem. Try the attachment ...

[Edit: trying once again to attach this file ...]
You do not have the required permissions to view the files attached to this post.
Last edited by Deniz Oezmen on Sat Sep 16, 2006 9:06 am, edited 1 time in total.
bored
beginner
Posts: 28
Joined: Sun Mar 12, 2006 9:03 pm
Been thanked: 1 time

Post by bored »

Wow Xela...What are the chances of finding two people to help you within a couple of hours?

Anyway, I've downloaded Deniz's solution and it's far more elegant than mine..so please delete all traces of the file I sent you... preferably without trying it out. :D
Xela
VIP member
VIP member
Posts: 225
Joined: Sun Jul 31, 2005 4:12 am
Been thanked: 1 time

Post by Xela »

It is pretty unbelievable that what I thought was quite a task, was so promptly and kindly attended by BOTH of you. And both with exactly same result - WORKING and exactly ehat I wanted. Many , many thanks.
Rahly
VVIP member
VVIP member
Posts: 412
Joined: Thu Aug 05, 2004 10:17 am
Been thanked: 1 time

Post by Rahly »

You really need to get rid of Win9x, Dos boxes are so 1990 :-D. Live in the now, with NT's command prompts.
"By nature men are alike. Through practice they have become far apart." Confucius (Analect 17:2)
Rahly
VVIP member
VVIP member
Posts: 412
Joined: Thu Aug 05, 2004 10:17 am
Been thanked: 1 time

Post by Rahly »

You really need to get away from Win9x, Dos boxes are so 1990s. Installed w2k or xp, and get the superb command prompt.
"By nature men are alike. Through practice they have become far apart." Confucius (Analect 17:2)
Rahly
VVIP member
VVIP member
Posts: 412
Joined: Thu Aug 05, 2004 10:17 am
Been thanked: 1 time

Post by Rahly »

You really need to get away from Win9x, Dos boxes are so 1990s. Installed w2k or xp, and get the superb command prompt.
"By nature men are alike. Through practice they have become far apart." Confucius (Analect 17:2)
Xela
VIP member
VIP member
Posts: 225
Joined: Sun Jul 31, 2005 4:12 am
Been thanked: 1 time

Post by Xela »

Dos boxes are so 1990
You cannot imagine how much I would give to be able to move time back and live again in 1990. Wouldn't you? :wink:
Post Reply