/**********************************************************
 *  FMEV.C - Find Master Environment Variable             *
 *  Jim Kyle, July 7, 1990                                *
 *                                                        *
 *  cl -qc fmev.c -MAmx nxtevar.asm envpkg.asm            *
 **********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char far * nxtevar( char far * vptr );
char far * mstenvp( void );

void main ( int argc, char * argv[] )
{ char far * menv;
  char vname[128], *vdata, tgt[64];
  int tlen;

  menv = mstenvp();
  if (argc < 2)
    { printf("Var to find: ");
      gets( tgt );
    }
  else
    strcpy( tgt, argv[1] );
  tlen = strlen( tgt );

  while ( menv )
    { sprintf(vname, "%Fs", menv );
      if ( vname[tlen] == '=' )
        { vdata = &vname[tlen+1];
          vname[tlen] = '\0';
          if ( stricmp( tgt, vname ) == 0 )
            break;
        }
      menv = nxtevar( menv );
    }

  if ( menv )
    { printf("Found %s at %Fp:\n%s\n", vname, menv, vdata );
      exit(0);
    }
  else
    { printf("%s not found.\n", tgt );
      exit(1);
    }
}
