Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #764

Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples

From "Bill Buckels" <bbuckels@mts.net>
Newsgroups comp.sys.apple2.programmer
Subject Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples
Date 2013-07-24 10:19 -0500
Organization Aioe.org NNTP Server
Message-ID <ksor9f$j1$1@speranza.aioe.org> (permalink)
References <ks1pdv$pji$1@speranza.aioe.org> <962b3d52-d74d-428f-8d46-888e2945aac7@googlegroups.com>

Show all headers | View raw


Marco <mverpelli@libero.it> wrote:
> Fine job as usual. May I ask for the source code of findopen, findnext and 
> findclose used in lm.c ?

Hi Marco,

All the source code for my routines for this compiler is in the AppleX 
distribution from the Aztec C website. I updated this a little earlier this 
year, except some of the stuff that I am currently working on. Download the 
latest compiler distribution:

http://www.aztecmuseum.ca/AppleX.zip

I would love to post all my source code right here:)

Here's ff.c - I hope it doesn't get truncated, but this is complicated 
somewhat. The reference material is all in AppleX as well as many comments 
and other demos that make all things clear. In particular look at the code 
in AppleX/PROGRAMS/LISTDIR and also in some of the slideshows... the volume 
directory in ProDOS 8 is the key here... My parody of the file find routines 
from the Microsoft C and Turbo C environments is just to wrap this stuff...

x--- snip --x

#include <stdio.h>
#include <prodir.h>

/* internal - for information call 411 */
int findcount(cnt)
int cnt;
{
 static int fcount = 0;

 if (cnt != 411) fcount = cnt;

 return fcount;
}

/* internal - for information call 411 */
int findhandle(fh)
int fh;
{
 static int fhandle = -1;

 if (fh != 411) fhandle = fh;

 return fhandle;
}


/* closes a ProDOS directory after calling findnext */
int findclose()
{
 int fh = findhandle(411);
 if (fh != -1) {
  close(fh);
  findhandle(-1);
 }
 findcount(0);
}


/* opens a ProDOS directory prior to calling findnext

   arg - path - if null uses current directory

   closes prior open directory if any.

   if successful

   - sets findhandle for findfirst
   - sets findcount for findfirst
   - returns a valid file handle

   otherwise closes directory if open and returns error

 */

int findopen(path)
char *path;
{
 char pathname[64], buf[43];
    struct fileinfo pathinfo;
    int fh = -1;

    findclose();

    if (NULL == path) {
  if (getprefix (pathname) == -1)return -1;
 }
 else strcpy(pathname,path);

 if (getfinfo (pathname, &pathinfo) == -1) return -2;
 if (pathinfo.file_type != 15) return -3;

    if ((fh = open (pathname, 0, 0)) < 0)return -4;

 if (read (fh, buf, 43) < 43) {
  close (fh);
  return -5;
 }

    findhandle(fh);
 findcount(1);

return fh;

}


/* args - input - filetype - a valid ProDOS filetype - if 0 any filetype 
will be returned.
          input - ext - extension without the dot - if null any extension 
will be returned.

          input, output - filename - char[16] - must not be null
                        - filefind structure - must not be null

          returns 0 if successful
          returns -1 if done (directory is closed when done)
          returns -2 if directory has not been opened prior to calling
*/

int findnext(filetype, ext, filename, ff)
int filetype;
char *ext, *filename;
struct filefind *ff;
{


 char buf[16];
 int fh, count, i, j, filelength;

    fh = findhandle(411);
    if (fh < 0) return -2;

    count = findcount(411);
    filename[0] = 0;

    if (NULL != ext) {
    for (i = 0; ext[i] != 0; i++) ext[i] = toupper(ext[i]);
 }


    for (;;) {

        if (read (fh,ff,39) < 39) break;
        if (ff->type == 0) break;

        count++;
        findcount(count);

        if (count == 13)
        {
         read (fh,buf,5);
            count = 0;
            findcount(count);;
        }


        filelength = (ff->length & 0xf);

        if (filelength != 0)
        {

            if (filetype == 0 || (filetype == (int)ff->type)) {

    if (NULL == ext) {
                 strncpy(filename, ff->name, filelength);
                 filename[filelength] = 0;
     return 0;
    }
    j = -1;
    for (i = 0; i < filelength; i++) {
       if (j > -1) {
        buf[j] = toupper(ff->name[i]);
        j++;
        buf[j] = 0;
       }
       if (ff->name[i] == '.') j = 0;
    }
    if (j != -1) {
        for (i = 0; ext[i] != 0; i++) {
      if (ext[i] == '?') continue;
      if (ext[i] != buf[i]) {
       j = -1;
       break;
      };
     }

    }
    if (j!= -1) {
                 strncpy(filename, ff->name, filelength);
                 filename[filelength] = 0;
     return 0;

    }
    }
        }
 }

    close (fh);
    findhandle(-1);
    findcount(0);
    ff->name[0] = 0;
    ff->length = 0;
    ff->type = 0;


 return -1;
}

Back to comp.sys.apple2.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Announce: Aztec C Shell Utilities including No Slot Clock Examples "Bill Buckels" <bbuckels@mts.net> - 2013-07-15 16:26 -0500
  Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples mverpelli@libero.it - 2013-07-24 04:35 -0700
    Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples "Bill Buckels" <bbuckels@mts.net> - 2013-07-24 10:19 -0500
    Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples "Bill Buckels" <bbuckels@mts.net> - 2013-07-24 10:32 -0500
      Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples mverpelli@libero.it - 2013-07-24 09:01 -0700
    Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples "Bill Buckels" <bbuckels@mts.net> - 2013-07-25 20:05 -0500
      Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples mverpelli@libero.it - 2013-07-26 01:43 -0700
        Re: Announce: Aztec C Shell Utilities including No Slot Clock Examples "Bill Buckels" <bbuckels@mts.net> - 2013-07-26 05:12 -0500

csiph-web