From:	HENRY::IN%"info-vax-request%kl.sri.com%kl.sri.com%csnet-relay.CSNET%relay.cs.net@RCA.COM" 14-JUN-1987 14:33
To:	info-vax@kl.sri.com
Subj:	Re: .. and VMS .DIR file entries

In article <2405@usceast.UUCP>, still@usceast.UUCP (Bert Still) writes:
> 
> 	I have 2 (possibly) strange questions for netland. The first concerns
> the VAX-C run-time library. Listed in the VAX-C manual are references to some
> ... 
> 	The second question concerns VMS directories. I have perused the
> "orange manuals" for the last two weeks looking for something that describes
> the VMS directory files' organization. So far, by dumping the contents of
> ...

The following more or less works, but there are still some problems
and I am posting this hoping someone can fill in some of the blanks.

Yes, I know there are routines like lib$find_file() to do this work,
but I needed something faster.

The highest-version entries are
  ???
  ??? I don't recall exactly what these were
  ???
  1 byte containing name length
  name-length bytes containing the name
  sometimes a null byte
  2 bytes - version number
  3 bytes of unknown (to me) information
  3 null bytes

The lower-version entries are
  2 bytes - version number
  3 bytes of unknown (to me) information
  3 null bytes
  
/* -------------------------------------------------------------------- */

/* readdir
     Read the next directory entry and return its string name.
     I used fopen() and fclose() in place of opendir() and
     closedir().
*/
char *readdir(dp)
FILE *dp;
{
  int ch, i, len, ver;
  char *p;
  static char temp[8];
  static char dirname[MAXNAMLEN + 1];

  ch = fgetc(dp);
  ver = (fgetc(dp) << 8) + ch;
  if ((ch = fgetc(dp)) == EOF) return 0;
  if (ch == 0) {  /* higher-version entry */
    len = fgetc(dp);
    for (i = 0; i < len; i++) {
      ch = fgetc(dp);
      dirname[i] = isprint(ch) ? tolower(ch) : '?';
    }
    dirname[i] = ';';
    dirname[i + 1] = '\0';
    while ((ch = fgetc(dp)) == 0)
      ;
    ver = (fgetc(dp) << 8) + ch;
    sprintf(temp, "%d", ver);
    strcat(dirname, temp);
    fread(temp, 1, 6, dp); /* skip over unknown stuff */
    }
  else {  /* lower-version entry */
    fread(temp, 1, 5, dp); /* skip over unknown stuff */
    sprintf(temp, "%d", ver);
    p = strrchr(dirname, ';');
    strcpy(p + 1, temp);
  }

  return dirname;

}  /* readdir */

/* -------------------------------------------------------------------- */
-- 
Robert J. Drabek
Department of Computer Science
University of Arizona
Tucson, AZ  85721
