next up previous
Next: Import a specific type Up: Package Storage in the Previous: Initialize the module

char *DirectoryFor(char *pkg, int len)

DirectoryFor seeks the directory corresponding to the package in each of the directories specified by the given paths:

char *DirectoryFor(char *pkg, int len)[4]:
{ DefTableKeyList l;

  if (!pkg || *pkg == '\0') {
    char cwd[MAX_PATH+1];

    if (!getcwd(cwd, MAX_PATH+1)) {
      (void)perror(cwd);
      return;
    }

    return StringTable(MakeName(cwd));
  }

  for (l = PackageDirectories;
       l != NULLDefTableKeyList;
       l = TailDefTableKeyList(l)) {
    char *clpv;
    struct stat data;
    int i;

    clpv = StringTable(GetClpValue(HeadDefTableKeyList(l),0));
    obstack_grow(Csm_obstk, clpv, strlen(clpv));
    obstack_1grow(Csm_obstk,'/');

    for (i = 0; i < len; i++) {
      obstack_1grow(Csm_obstk, pkg[i] == '.' ? '/' : pkg[i]);
    }
    CsmStrPtr = (char *)obstack_copy0(Csm_obstk, "/", 1);

    if (!stat(CsmStrPtr, &data) && S_ISDIR(data.st_mode))
      return StringTable(MakeName(CsmStrPtr));

    obstack_free(Csm_obstk, CsmStrPtr);
  }

  return NULL;
}
This macro is invoked in definition 9.



2008-09-11