Re: [cc65] Common macros for dirent.d_type

From: Oliver Schmidt <ol.sc1web.de>
Date: 2012-06-26 16:25:08
Hi Shawn,

> The Atari *does* have subdirectories, so there may be a d_type field there
> (or should be?)

That depends on what is to be archived with the whole opendir()
thingy. Here's my (as always lengthy) take...

It's about cross-target directory access. There are two primary usecases:


1. Find potential candidates for open() / fopen()

If all return values from readdir() are (at least potential)
candidates for open() / fopen() then there's no real need for a d_type
field. However for the sake of easy cross-target programming there
should be a _DE_ISREG() that always returns true.

I understand that i.e. on CBMs not all "regular" files are equal
(http://www.cc65.org/snapshot-doc/funcref-53.html) but at least that's
the general idea.


2. Find potential candidates for opendir()

When starting to think about this you inevitably need to think about
the parameter for your initial call to opendir(). I presume we agree
that "." is the lowest common denominator. Looking at the Apple II,
Atari and CBM code this is fortunately true :-) For the Lynx I can't
find an opendir() implementation ?!?

Anything beyond "." seems to be problematic. I personally would claim
that the return value of getcwd() is _AS-IS_ a valid parameter for
opendir(). I implemented it that way for the Apple II. Looking at the
Atari and CBM initcwd code I can't tell what's the approach there.

If we would agree on the getcwd() idea than we could extend it and
claim that any return value from readdir() with _DE_ISDIR() being true
is _AS-IS_ a valid parameter for chdir() - this implies that chdir()
works with relative paths. As you may guess by now I implemented it
that way for the Apple II.

With these things in place one could already implement a cross-target
directoy tree traversal without fiddling with directory separators and
alike:

==========

dodir() {
  char thisdir[FILENAME_MAX];

  getcwd(thisdir, sizeof(thisdir));

  opendir(thisdir);  // no prefix or postfix or <you name it>
  while(...) {
    e = readdir(...);
    if (_DE_ISDIR(e->d_type)) {
      chdir(e->d_name);  // no prefix or postfix or <you name it>
      dodir();  // recursion
    }
  }
  closedir();

  chdir(thisdir);
}

==========

If we would agree on this then the "only" thing missing would be to
set the initial directory to something "outside" the current directory
on program startup. While I'm open for any discussion I presume that
our targets (and ideas ;-) are just too different to get something
cross-target done.

I'd be by the way willing to write a cc65 sample program along the
lines of the pseudo code above if there should be at least two targets
it could run on (one being the Apple II). Here's already a similiar
one (specific for the Apple II):
http://wiki.cc65.org/doku.php?id=cc65:apple2:files

Regards,
Oliver
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Jun 26 16:25:27 2012

This archive was generated by hypermail 2.1.8 : 2012-06-26 16:25:31 CEST