Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!quasi-eli!cs.yale.edu!fischer-michael From: fischer-michael@cs.yale.edu (Michael Fischer) Newsgroups: comp.sys.atari.st.tech Subject: Re: How to write config info into mail .PRG or .ACC file? Message-ID: <25854@cs.yale.edu> Date: 22 Aug 90 01:10:34 GMT References: <3300@syma.sussex.ac.uk> Sender: news@cs.yale.edu Organization: Yale University Computer Science Dept., New Haven, CT 06520-2158 Lines: 40 Nntp-Posting-Host: ginkgo.theory.cs.yale.edu Originator: fischer@ginkgo.CS.Yale.Edu In article <3300@syma.sussex.ac.uk> grahamt@syma.sussex.ac.uk (Graham Thomas) writes: > >My options are either to read from / write to a separate .CFG or .INF >file, which I could do but would rather not (I've incorporated my >resource file info into the main program file and I'd like to keep >everything in a single place if possible), or save the info directly to >the program itself. How is this done? It's easy enough to rewrite bytes in the middle of the .prg file using the Gemdos functions Fseek and Fwrite. Your only problems are to find the file (not so easy) and to figure out which bytes to change. I don't know of a reliable way to find the name and location of the .prg file which is currently running. It will often be in the default directory on the default device (depending on how the program was invoked), but it doesn't have to be. The Pexec that invokes your program probably leaves this information behind in some undocumented memory locations somewhere, but you can't count on that not changing in the future. The second part is easier. Declare all of your configuration variables at the top of your program as static, and initialize them to appropriate default values. This should cause the compiler to place them at the start of the data segment of your program. Information in the header of a .prg file tells the lengths of the text and data segments. Read that information and calculate the position in the .prg file of the start of the data segment. Seek to that position and rewrite your variables. To be on the safe side, put a magic number as the first thing in the data segment and check that it is there before you start writing. This may save you from clobbering the wrong file. Thus, your program might start as follows: static char magic[8] = "myprogxx"; static int width = 85; ... Hope this helps. -- ================================================== | Michael Fischer | ==================================================