home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / Mac F2C 1.0 / Mac F2C Libraries / libF77 Sources / getenv_.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-15  |  1.1 KB  |  59 lines  |  [TEXT/KAHL]

  1. #include "f2c.h"
  2.  
  3. /*
  4.  * getenv - f77 subroutine to return environment variables
  5.  *
  6.  * called by:
  7.  *    call getenv (ENV_NAME, char_var)
  8.  * where:
  9.  *    ENV_NAME is the name of an environment variable
  10.  *    char_var is a character variable which will receive
  11.  *        the current value of ENV_NAME, or all blanks
  12.  *        if ENV_NAME is not defined
  13.  */
  14.  
  15. #ifdef KR_headers
  16. VOID getenv_(fname, value, flen, vlen) char *value, *fname; ftnlen vlen, flen;
  17. #else
  18. void getenv_(char *fname, char *value, ftnlen flen, ftnlen vlen)
  19. #endif
  20. {
  21.  
  22. #ifndef MACINTOSH    /* IMT 4Jan93  Macintosh doesn't have any environment variables */
  23.  
  24. extern char **environ;
  25. register char *ep, *fp, *flast;
  26. register char **env = environ;
  27.  
  28. flast = fname + flen;
  29. for(fp = fname ; fp < flast ; ++fp)
  30.     if(*fp == ' ')
  31.         {
  32.         flast = fp;
  33.         break;
  34.         }
  35.  
  36. while (ep = *env++)
  37.     {
  38.     for(fp = fname; fp<flast ; )
  39.         if(*fp++ != *ep++)
  40.             goto endloop;
  41.  
  42.     if(*ep++ == '=') {    /* copy right hand side */
  43.         while( *ep && --vlen>=0 )
  44.             *value++ = *ep++;
  45.  
  46.         goto blank;
  47.         }
  48. endloop: ;
  49.     }
  50.  
  51. blank:
  52.     while( --vlen >= 0 )
  53.         *value++ = ' ';
  54. #else                        /* On Mac just fill it with blanks */
  55.     while( --vlen >= 0 )
  56.         *value++ = ' ';
  57. #endif
  58. }
  59.