[comp.sys.amiga.tech] Programmer's Guide To The Amiga

rap@peck.ardent.com (Rob Peck) (10/07/89)

In article <SHADOW.89Oct6035540@pawl.rpi.edu> shadow@pawl.rpi.edu (Deven T. Corzine) writes:
>On 29 Sep 89 04:53:18 GMT, cmcmanis%pepper@Sun.COM (Chuck McManis) said:
>cmcmanis> Do we have to tell you everything ? :-) In truth the
>cmcmanis> learning curve on the Amiga is fairly steep and getting to
>cmcmanis> that "ah-hah!" point can be agonizingly slow.
>Unfortunately true.  :-(
>But it's worth it.  :-)


I would like to think that my Programmer's Guide To The Amiga, from
SYBEX, would somehow ease the learning curve, (removing SOME of the
so-called agony) but it is incredibly difficult and frustrating to
know that most people STILL don't even know that the book exists!!


/* Begin slings-and-arrows-of-outrageous-fortune-mode */

Case in point... though I repeatedly call and write the various mail
order firms, most of them still list only the Mortimore SYBEX books,
namely the Amiga Programmers Handbook which contains relatively NO
examples, or the Abacus books which, though improving, I don't believe
are nearly as well constructed as the Programmer's Guide.  The
Guide also offers a companion diskette that is Lattice and Manx
compatible, AND now a separate TDI, M2S, and Benchmark translation
is also available, allowing Modula-2 programmers to use a primarily
C book to learn to program the Amiga in Modula-2.  

And even those mail order dealers who CARRY the book mislist the title
as "Amiga Programming Guide", right along with their Mortimore SYBEX titles.
Perhaps if there is another reprint of the book, I should ask that SYBEX
change the title to something like "The Ultimate Guide To Programming
In C For The Amiga, VOLUME I."  At least then the title would be
different enough that the dealers could not get it confused.  (sigh)
And if there is enough recognition, finally, for it, I can get support
from my publisher (or some other publisher) to do a VOLUME II.

Another case -- the publisher of AX magazine has been requesting for
some time that I do an article for them.  I have just been too busy
on other things for that, as of late, though I was considering it.
But YESTERDAY, I got the latest issue of their magazine and the
paper part of the mag has an article that tells people how to get
started programming in C.  It recommends the RKM's and a book called
"Inside the Amiga with C", a book for which all of the waits are
encoded as:

		for(i=0; i<1000000; i++)
			;

By comparison, the Programmers Guide To The Amiga is properly multitasking
compatible for everything.  All examples (and there are PLENTY OF THEM)
free the memory that they use.  And there is an entire chapter on
working with AmigaDOS functions (not fopen(), fread(), but the DIRECT
AmigaDOS calls, such as Examine(), ExNext and so on.  This is, to 
my knowledge, the ONLY book that has such examples.  Even the darn
Bantam AmigaDOS manual did not have any source code examples that
called AmigaDOS.

FORTUNATELY, Lattice and Manx both list the Programmer's Guide in their
list of recommended reading.  And Manx chose to use one of the examples
directly from the book as the demo for its symbolic debugger (with
my permission).  NO, there were no bugs in the example as printed. :-)
Just that it did something useful.

SYBEX has been very responsive to changes that were necessary.  The
book, now in its fifth printing, includes all errata that were brought
to my attention so it should be pretty trouble free now.  And of
course the examples on disk include both the errata fixes as well
as the errata-files posted over the past two years to Usenet so that
folks could fix their earlier printed editions.

I recently received yet another small piece of errata, and have posted
it here for your use.  I'll be sending it on to SYBEX as usual for
inclusion in the next printing.  Hope you get some use out of it.

==================================================== 
Errata #5 for the Programmer's Guide To The Amiga
Affects all versions from printing 1-5
	(look on copyright page at the bottom,
	 the printing number is the last digit
	 in the sequence   10 9 8 7 6 5 etc.)
====================================================


For those who have a need for a recursive directory descent program,
I offer here a modified version of the example program from listing 2.8 of
the Programmer's Guide To The Amiga.    This program duplicates the
action of DIR OPT A, and shows how file locks and CurrentDir's
are used; and how one determines if something is a file or a
directory so as to walk the directory tree looking for something
(could be used as the basis for a FIND program, for example).

This cleaned up version will go into the next printing (6th, I think)
of the Programmer's Guide.  This program differs from that printed
in the following ways:

1. Locks, although freed eventually, were not being freed at the
same level at which they had been obtained.  This version makes the
getting and freeing of locks more consistent.

2. If a directory foo had a file named foo, opta would attempt to
cd to that file-as-directory.  This was a bug waiting to bite, but
neither I, nor any of my earlier users had noticed it.

3. Adds reading a command line parameter to define which directory
should be listed in an OPT A fashion.  This should have been done
to begin with, and I am very glad to have it.

I wish to thank Peter Cherna, "Working for, but not officially
representing Commodore." for submitting this modified version.
It is, as I understand, something that will help the Amiga community
but should not be construed as recommended or endorsed by Commodore.

Well, -->I<-- appreciate it anyhow.  Thanks, Peter.


Rob Peck


/*
 *	opta.c
 *
 *	Recursively search the current or specified directory, and
 *	report the files and directories found therein.
 *
 *	Based on opta.c, from Rob Peck's Programmer's Guide to the Amiga,
 *	but with bugs fixed.
 */

#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <exec/memory.h>

#include <proto/all.h>

/*  [ this was tested using Lattice 5.02 ] */

struct DosLibrary *DOSBase;

/*  Note that a DOS lock is a BPTR to a FileLock, and I presume should
    be declared as such (or as a ULONG).  Certainly not a FileLock,
    because one can't get away with lock->fl_Volume) */

void followthread(BPTR lock, int tab_level);


main(argc, argv)

    int argc;
    char *argv[];

    {
    BPTR lock, oldlock;

    DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0L);
    /*  Lock the current or specified directory: */
    lock = Lock(argc > 1 ? argv[1] : "", ACCESS_READ);

    if (lock)
	{
	/*  Move into desired directory: */
	oldlock = CurrentDir(lock);
	followthread(lock, 0);
	/*  Move back to original directory: */
	CurrentDir(oldlock);
	/*  UnLock the directory we Locked: */
	UnLock(lock);
	}
    else
	{
	if (argc > 1)
	    printf("Couldn't lock %s.\n", argv[1]);
	else
	    printf("Couldn't lock current directory.\n");
	}
    printf("\n");

    CloseLibrary((struct Library *)DOSBase);
    }

/*  Now follow the thread... might hit a directory, might hit a file. */
/*  If a directory, list it and then follow it down (recursively). */
/*  If hit a file, list it and proceed to the end. */

void followthread(lock, tab_level)

    BPTR lock;
    int tab_level;

    {
    struct FileInfoBlock *m;
    BPTR newlock, oldlock;
    int success, i;

    /*  if at the end of the road, don't print anything */
    if (!lock)
	return;

    /*  allocate space for a FileInfoBlock */
    m = (struct FileInfoBlock *)
	AllocMem(sizeof(struct FileInfoBlock), MEMF_CLEAR);

    success = Examine(lock, m);
    if (m->fib_DirEntryType <= 0)
	{
	/*  We don't allow "opta file", only "opta dir" */
	return;
	}

    /*  The first call to Examine fills the FileInfoBlock with information
	about the directory.  If it is called at the root level, it contains
	the volume name of the disk.  Thus, this program is only printing
	the output of ExNext rather than both Examine and ExNext.  If it
	printed both, it would list directory entries twice! */

    while (success = ExNext(lock, m))
	{
	/*  Print what we've got: */
	printf("\n");
	for (i = 0; i < tab_level; i++)
	    printf("\t");
	printf("%ls", m->fib_FileName);
	if (m->fib_DirEntryType > 0)
	    {
	    printf(" [dir]");
	    }

	/*  If we have a directory, then enter it: */
	if (m->fib_DirEntryType > 0)
	    {
	    /*  Since it is a directory, get a lock on it: */
	    newlock = Lock(m->fib_FileName, ACCESS_READ);

	    /*  cd to this directory: */
	    oldlock = CurrentDir(newlock);

	    /*  recursively follow the thread down to the bottom: */
	    followthread(newlock, tab_level+1);

	    /*  cd back to where we used to be: */
	    CurrentDir(oldlock);

	    /*  Unlock the directory we just visited: */
	    if (newlock)
		UnLock(newlock);
	    }
	}
    FreeMem(m, sizeof(struct FileInfoBlock));
    }

==================================================================

Surprised financial note :-( .... last year I spent $1500 to put an ad into
the Commodore Magazine special 5 x 7 insert that is packed in the box with
every machine that is sold.  And another batch-o-bucks for an insert that is
included in Amnews issue #4, and yet another $600 for a half-page
ad in Computer Discount's newspaper-catalog that reaches 135,000
according to their advertising.  Either I need to hire someone to
make the ADs for the Programmers Guide To The Amiga reach out and grab
folks or the people that I am reaching with this technical product are
just not technical (or more probably throw away the advertising without
ever reading it)  [SIGH].  Reflection of that opinion:  most recent royalty
check (6 months) for books sold during the period of the "Ad blitz" = $750.
[ Big Sigh ].  Maybe if I don't advertise, things will pick up.


Rob Peck

		DATAPATH, POBox 1828, Los Gatos, CA 95031

		Offering the Programmer's Guide To The Amiga
		and C or Modula-2 source/object disks, at a
		discount.  Write for details.

dwl10@uts.amdahl.com (Dave Lowrey) (10/07/89)

In article <8548@ardent.UUCP> rap@peck.ardent.com (Rob Peck) writes:
>Refleection of that opinion:  most recent royalty checkty
>(6 months) for books sold during the period of the "Ad blitz" = $750.
>[ Big Sigh ].  Maybe if I don't advertise, things will pick up.
>
Maybe you should get a new publisher! At $24.95 a pop, the book is not
cheap, and just about every Amiga owner I know has a copy!

Methinks you are getting ripped off!

-- 
"What is another word  |  Dave Lowrey    | [The opinions expressed MAY be
 for 'Thesaurus'?"     |  Amdahl Corp.   | those of the author and are not
                       |  Houston, Texas | necessarily those of his
   Steven Wright       |  amdahl!dwl10   | employer]   (`nuff said!)