News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Template?

Started by jckl, April 20, 2006, 03:27:16 AM

Previous topic - Next topic

jckl

I am writing a program that will convert one file type to another. I have run into a problem though and cant seem to think of a way to make it work with what i know in masm so far. I am looking here to see if anyone can lead me in a direction to getting this done. Let me try to explain what i am doing and what i need now.

The 2 file types are .bms and .mis. I need to read info from the .bms and format it the .mis format. The format of the .mis is kinda like a visual basic form. In the files there are items. The number of items varys so what i need is something like a template that can be used over and over. What i was doung is reading the file then formating the text for the mis and storing it in memory to be written after i obtain all the data i need. I have tried using wsprintf but the line must be null terminated and unless i fill all sections at once i get a crash. This is ok for some stuff but my items contain 27 options. That would require i have 27 strings to store data in temporarily. I would perfer not go this route. So below ill show the structure of the items to be stored in the .mis file. Ill put %s where it would be expecting a string.

begin item #
  type_id %s
  name %s
  id %s
  position %s
  facing %s
  team %s
  map_symbol %s
  bmsi_attributes %s
  group_id %s
  waypoint_id %s
  wpnumber %s
  wpdistance %s
  ttoolindex    %s
  alert_state %s
  waccuracy1 %s
  waccuracy2 %s
  perception2 %s
  perfectionist2 %s
  shoottimer %s
  movetimer %s
  crouchtimer %s
  attention    %s
  advancetimer %s
  max_attack_distance %s
  edistances %s
  gen_string %s
  color_override %s
end item

I have also created a struc with this but still i run into the problem of the string needing to be terminated or using all the buffers at once. I thought about maybe using terminated chars and then stripping the null chars right before storing it in memory but i figured this may not be the best route and may or may not work.

If anyone knows a better way to make this work then please point me in the right direction.

Thanks..

Tedd

wsprintf is limited in the length of the string it outputs, so I would avoid using it in this way - outputing quite large 'lists' with long fields. Do it one line/element at a time.
But since it's all strings, there's little point in using wsprintf at all - you can just print the strings one after the other (concatenate.)

I would generally go about this by gathering all of the fields (from the .bms) in memory and then output the filled-in template afterward. But, of course, storing numerous strings of unknown length can be such a waste, since you have to allow lots of extra space for each string.
However, you can be a little more clever than that :toothy

So, what you do is allocate a nice biiiig buffer in which to store all of your strings. While you don't know the exact length this needs to be, you should have a fair idea of the maximum size - so allocate more than this and you're safe :wink
Now, for storing your strings, simply copy them into this buffer one after the other, keeping the null-terminators to separate them. Presumably they won't be in the correct order to simply spit them out into the .mis file, so you'll have to keep an index of where each string starts. So you want to allocate an extra 27 dwords for this, and place them at the start of the biiig buffer. The string pointers can then be stored in this index in their correct order.
Finally, when you've finished processing the .bms file, you can write out the .mis by simply taking each line, along with the string from its corresponding index entry, and sticking them together :bg

Good enough?
No snowflake in an avalanche feels responsible.

jckl

well the longest string i have is maxed at 256 because the limits of the .bms file. I allocate space for the storing the info to the .mis file already but on the second idea you have there i could allocate a second buffer and go that route maybe. Ill have to play around tring one buffer and two to see what i get. I also thought about just having them all seperate and then once i fill %s i could just add that line to my temp .mis buffer but thats more than i wanted to do lol. Anyways ill play and see what i can do. Thanks for the ideas...