Kai.Buerhoop@arbi.informatik.uni-oldenburg.de (Kai Buerhoop) (05/01/91)
How can I change the prompt-string from within a program? I tried, using turbo-c's getenv("PROMPT"), which returns a pointer to that place in the memory, where the prompt-string is stored (which is okay). But seemingly, DOS creates a copy of the environment table, and the getenv returns a pointer to the copied env-table. So, when the program ends, DOS gets its old env-table, and all changes were futile. :(= So, how to change the original environment table? Any solutions welcome (c, mod2 or assembler, please). Thanx in advance. Kai -- +--------------------------------------------------------------------------+ | Kai L. Buerhoop, Brandsweg 29b, 2900 Oldenburg, FRG | | Kai.Buerhoop@arbi.informatik.uni-oldenburg.de | +--------------------------------------------------------------------------+ | How can I tell, that the past isn't a fiction designed to account for the| |discrepancy between my immediate physical sensations and my state of mind?| +----------------------------(D.Adams)-------------------------------------+
campbell@cutmcvax.cs.curtin.edu.au (Trevor George Campbell CC361) (05/06/91)
Kai.Buerhoop@arbi.informatik.uni-oldenburg.de (Kai Buerhoop) writes: >How can I change the prompt-string from within a program? >I tried, using turbo-c's getenv("PROMPT"), which returns a pointer >to that place in the memory, where the prompt-string is stored >(which is okay). >But seemingly, DOS creates a copy of the environment table, and the >getenv returns a pointer to the copied env-table. >So, when the program ends, DOS gets its old env-table, and all changes >were futile. :(= Correct..... Check out Interrupt 21h Function 4Ch (EXEC) and you will see what happens.... If you are using Dos 4, try the command 'mem /debug' this will display the contents of memory (addresses, program names, length..etc) if you have several (or even 1) TSR loaded then you will notice entries like... address prog. name length ????? xxxxx COMMAND xxxxx Environment xxxxx COMMAND xxxxx Program xxxxx MEM xxxxx Environment xxxxx MEM xxxxx Program from this you can see that mem (the program you just run) has it's own copy of the environment), just as you suspected.... >So, how to change the original environment table? with great difficulty...... you need to use an undocumented (i think) function to find the address of the first MCB (Memory Control Block)... From this you chain through the list (like a linked list) checking if the first 8 bytes of the memory location are COMSPEC=... this will mean that you have an environment block. The REAL (ie: the one DOS uses) will usually (? always) be the first. The MCB contains the length of the block of memory. Given this you need to check the environment block for two NULL bytes (ie: 00 00 hex) one after the other, if this is encountered before the end of the block of memory, (ie: there is still sufficient memory in the block) then you need to copy all of the environment variables after PROMPT= out of the way, change PROMPT= to the new string, and then copy all of the other variables back after PROMPT=. It's NOT easy to do, however i understand that it CAN be done... It basically is just like the problem of trying to return ANY environment variable to DOS.. If you are not detered by the difficulty of doing it then there is a good book by ABACUS called PC SYSTEMS PROGRAMMING FOR DEVELOPERS, it gives the source code (in C and Pascal) to display the Memory Control Blocks and what they contain (ie: environment, program, data or unknown...) Hope this Helps..... Trevor alias <**<TOMCAT>**>
mike@idca.tds.philips.nl (Mike Corrall) (05/07/91)
Dr Dobbs Journal, Dec 1988, contained an article about listing MCB's; it used the undocumented feature mentioned. I entered the source and use the program regularly if I run into memory allocation problems. Hope this helps, Mike. -- ---------- Mike Corrall Voxnet: +31 55 43 2579 Faxnet: +31 55 43 2070 UUCP: ... !mcsun!philapd!mike Internet: mike@idca.tds.philips.nl [879.1.1.13] Papernet: PLG9i, Philips Information Systems, PO Box 245, NL-7300 AL Apeldoorn They said: Smile, things could get worse. So I smiled, and sure enough ...