home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / misc / make.lzh / ENVFETCH.C < prev    next >
Text File  |  1986-01-19  |  1KB  |  51 lines

  1. #define CPEEK(off,seg) ((unsigned char) peek (off, seg))
  2.  
  3. /*
  4.  * env_fetch (name, envseg, dest)
  5.  *
  6.  *    Search environment at segment address for variable named and
  7.  *    if found store value of variable at dest.  Return true (nonzero)
  8.  *    if found.
  9.  */
  10.  
  11. env_fetch (name, envseg, dest)
  12. char *name, *dest;
  13. unsigned int envseg;
  14. {
  15. unsigned int
  16.     envoff;
  17.  
  18. char
  19.     c,
  20.     *dp,
  21.     leftpart[132];
  22.  
  23. envoff = 0;                /* starting environment offset */
  24. dp = leftpart;
  25. while (1)
  26.     {
  27.     c = CPEEK (envoff++, envseg);
  28.     switch (c)
  29.     {
  30.     case '=':
  31.             *dp = 0;            /* make ASCIZ */
  32.             if (strcmp (leftpart, "COMSPEC") == 0)
  33.                 {
  34.         dp = dest;
  35.         while (*dp++ = CPEEK (envoff++, envseg));
  36.                 return (1);
  37.                 };
  38.             while (CPEEK (envoff++, envseg));    /* skip to end */
  39.         dp = leftpart;        /* reset destination pointer */
  40.         break;
  41.     case 0:
  42.         if (CPEEK (envoff + 1, envseg) == 0)
  43.         return (0);
  44.         dp = leftpart;
  45.         break;
  46.     default:
  47.         *dp++ = c;
  48.     };
  49.     };
  50. }
  51.