#include <perms.h>
static const int Bytesize = 1;
static const int Wordsize = 4;
int Getenvironment(void);
int Getenvcount(void) {
  int *Arr;
  int Count;
  Arr = &Getenvironment();
  Count = 0;
  while (*Integer(Addr(*Arr) + Wordsize * Count)) Count++;
  return (Count);
}
_imp_string Getenvname(int Index) {
  int I;
  int Eqpos;
  int Len;
  unsigned char *B;
  unsigned char *Src;
  _imp_string S;
  *Length(S) = 0;
  if (0 < Index && Index <= Getenvcount()) {
    B = Byteinteger(*Integer(Addr(Getenvironment()) + Wordsize * (Index - 1)));
    Len = 0;
    while (*Byteinteger(Addr(*B) + Len)) {
      Len++;
      if (Len == -1) {
        Len = 0;
        break;
      }
    }
    Eqpos = 0;
    for (I = 1; I <= Len; I++) {
      Src = Byteinteger(Addr(*B) + Bytesize * (I - 1));
      if ((*Src == '=') && (Eqpos == 0)) Eqpos = I;
      if ((Eqpos == 0) && (*Length(S) < 256)) {
        *Length(S) = *Length(S) + 1;
        *Charno(S, *Length(S)) = *Src;
      }
    }
  }
  return (S);
}
_imp_string Getenv(int Index) {
  int I;
  int Eqpos;
  int Len;
  unsigned char *B;
  unsigned char *Src;
  _imp_string S;
  *Length(S) = 0;
  if (0 < Index && Index <= Getenvcount()) {
    B = Byteinteger(*Integer(Addr(Getenvironment()) + Wordsize * (Index - 1)));
    Len = 0;
    while (*Byteinteger(Addr(*B) + Len)) {
      Len++;
      if (Len == -1) {
        Len = 0;
        break;
      }
    }
    Eqpos = 0;
    for (I = 1; I <= Len; I++) {
      Src = Byteinteger(Addr(*B) + Bytesize * (I - 1));
      if ((Eqpos != 0) && ((Len - Eqpos) < 256)) {
        *Length(S) = *Length(S) + 1;
        *Charno(S, *Length(S)) = *Src;
      }
      if ((*Src == '=') && (Eqpos == 0)) Eqpos = I;
    }
  }
  return (S);
}
int Getenvindex(_imp_string Varname) {
  int I;
  int Count;
  int Index;
  Index = 0;
  Count = Getenvcount();
  I = 1;
  do
    if (Varname == Getenvname(I))
      Index = I;
    else
      I++;
  while ((Index == 0) && (I <= Count));
  return (Index);
}
