home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / ENVIRON.TXT < prev    next >
Text File  |  1991-10-03  |  4KB  |  64 lines

  1. Q. Why was only the DOS batch file and "Stuff-key-buffer method"
  2.    (SETENVAR.C) included in the original SNIPPETS?
  3.  
  4.  
  5. A. The reason that I only included the "batch&stuff" method in my SNIPPETS
  6.    collection is simply that it's the *only* method you can rely on if your
  7.    program is going to be distributed. Quite simply, there is *NO* safe,
  8.    documented way under DOS to set an environment variable in the master
  9.    environment block - period! By back-tracking PSPs or MCBs, you can try
  10.    to locate the master environment and change it. You can also try to use
  11.    Int 2Eh, the command processor's "back door". But all of these methods
  12.    suffer from several shortcomings:
  13.  
  14. 1)  Someone using the program might be using 4DOS, COMMAND PLUS, or some other
  15.     COMMAND.COM replacement. These don't always do things the same way as
  16.     COMMAND.COM and the diferences can cause you to crash, roll, & burn! For
  17.     example, several COMMAND.COM replacements allow the master environment
  18.     block to be located in extended, expanded, or high memory. In such a case,
  19.     backtracking PSPs or MCBs is less than useless, they're guranteed to
  20.     yield undefined errors.
  21.  
  22. 2)  Int 2Eh seems to be the most universally supported, but cannot be used in
  23.     a program invoked from a batch file. The book, "Undocumented DOS" details
  24.     some procedures for making an Int 2Eh call safer but, again, these
  25.     techniques rely on implementation features of COMMAND.COM which might not
  26.     be available in alternate command processors.
  27.  
  28. 3)  Even if everything else is safe, you still need a way of error trapping in
  29.     case your new environment variable might overwrite the end of the
  30.     available master envirnment block. This error trapping in inherent in
  31.     COMMAND.COM and alternate command processors (one reason why using the
  32.     Int 2Eh back door is potentially the safest way to try), but if you try to
  33.     modify things manually, you're on your own. If you do overwrite the end of
  34.     the master environment block, you'll have automatically corrupted your MCB
  35.     chain and possibly set yourself up for some *really* nasty surprises!
  36.  
  37. 4)  Finally, there's the very fundamental question of which environment block
  38.     really is the master? Say you're in your comm program and hit the "shell
  39.     to DOS" key. A secondary copy of the command processor, be it COMMAND.COM
  40.     or whatever, is spawned and you're off and running. If you now run your
  41.     program from this secondary DOS shell, is its environment block the master
  42.     or is it the one from which you ran your comm program? Worse yet,
  43.     depending on how you set up CONFIG.SYS, the secondary shell may have a
  44.     considerably smaller environment block than the original. Despite having
  45.     set the "/E:" switch, your secondary shell will likely only have an
  46.     environment block whose size is equal to the current block size rounded
  47.     up to the next paragraph boundry. If you trace PSPs, you'll find the
  48.     secondary shell which you stand a good chance of over-running due to the
  49.     difference in the block size. If you trace MCBs, you'll find the real
  50.     master block, but then your changes will have disappered when you return
  51.     to your comm program, defeating the purpose of your program in the first
  52.     place. 
  53.  
  54.    The inability to alter a parent program's environment block isn't a DOS
  55.    exclusive, BTW - it's an inheritance from Unix where the same limitation
  56.    applies.
  57.  
  58.    Finally, SNIPPETS now includes several of these alternate unsafe ways of
  59.    setting the master environment. INT2E.ASM & CCOMCALL.C together provide
  60.    access to the DOS command processor back door, GLBL_ENV.C provides means
  61.    for TC/TC++/BC++ and MSC/QC programmers to modify the master environment
  62.    by backtracking PSP pointers, and MCB_ENV.C serves the same purpose only
  63.    using the MCB tracking method.
  64.