[comp.sys.atari.st] A ghost in the house

stdnet@stag.UUCP (07/02/88)

From: thelake!steve@stag.UUCP (Steve Yelvington)


I compiled a directory lister with Mark Johnson C, version 2.0. 
It works just fine, but at the end of the directory, it prints out a 
message on the console: "(no more files)".

This message is nowhere to be found in my program or in the MJC library.
So I figure that either it is coming from GEMdos, or I have a friendly ghost.
I want it to go away.

One of the local programmers (John Osawa, author of the Schizo desk
accessory) tried my code with Mark Williams C and got no such message.
He suggested that MJC's startup code may throw a switch, and mentioned
something about Perror. I thumbed through "Atari ST Application 
Programming" (Pollack and Weber), but found no references to Perror.
It's not in osbind.h. I found nothing like it in the MJC startup routines,
either.

So: What is Perror? How do I shut off this message?


 _____________________________________________________________________
 | thelake!steve@stag.UUCP is...                                     |
 | Steve Yelvington/1392 Brandlwood Rd./White Bear Lake MN 55110 USA |
 ---------------------------------------------------------------------

stdnet@stag.UUCP (07/08/88)

From: dynasoft!john@stag.UUCP (John Stanley)


  This normaly would have been sent as a personal email response,
but since it effects all users of Mark Johnson's C (MJC) compiler
I decided to post this to the net.

---

Hi Steve!

In comp.sys.atari.st, thelake!steve@stag.UUCP (Steve Yelvington) writes:
 >
 >I compiled a directory lister with Mark Johnson C, version 2.0. 
 >It works just fine, but at the end of the directory, it prints out a 
 >message on the console: "(no more files)".
 >
 >This message is nowhere to be found in my program or in the MJC library.
 >So I figure that either it is coming from GEMdos, or I have a friendly
 >ghost.  I want it to go away.

  Steve, I guess you could say I'm the "friendly ghost".  :)

  The message you mentioned is one of the standard error code
messages in my JSH command shell.  I'm assuming you're using JSH?

  When a stand alone program returns a negative exit code, JSH
interprets it as one of the standard GEM/BIOS/XBIOS error codes and
prints out a message.  My guess is that you exit the program by just
falling thru the bottom brace in main() rather than issuing a
return(0) or exit(0).

  What happens then is a standard ambiguity/problem with the C
language.  Many textbook programing examples show a main() procedure
that just ends.  But, some also show the program using return(n) at
the end of the program to return some positive condition code or
negative error code.  Unfortunately, there is -no- way to implement
the standard crt0() function (the startup code that actualy calls
main() -and- the code which determines what exit value to return to
the system) in such a way that it can tell if you return() or just
end out of main().  (Note: some compilers actualy force a phantom
return(0) at the end of main to avoid this problem...)

  In MJC, this means that if you don't use exit or return at the end
of main(), your program will 'return' to crt0() with whatever happens
to be in the r0/d0 register at the time.  In your case, this happens
to be the return code from the Fsnext gemdos call which ended your
directory scan.

  Asside note:  I disagree with the implementation of the startup
code that MJC uses, but I can easily see how Mark came to the
conclusions he did about how it should be written.

  The -only- universaly acceptable way to write C main() functions is
to use return(0) or exit(0) as a normal termination, and to use
exit(n) to return an error or result code number to the system.  If
you just fall thru to the bottom brace, or if you try using return(n)
with anything but 0, your program is not portable and will fail in
various ways depending on the compiler and/or system.

 >One of the local programmers (John Osawa, author of the Schizo desk
 >accessory) tried my code with Mark Williams C and got no such message.
 >He suggested that MJC's startup code may throw a switch, and mentioned
 >something about Perror. I thumbed through "Atari ST Application 
 >Programming" (Pollack and Weber), but found no references to Perror.
 >It's not in osbind.h. I found nothing like it in the MJC startup routines,
 >either.

  To the best of my knowledge, the MWC crt0() code totaly ignores the
return value from main() and requires that any return value other
than zero be returned using exit(n).

 >
 >So: What is Perror? How do I shut off this message?
 >

  Excelent programmer that he is, John Osawa is taking a long shot
guess and, in this case, missing...  Perror (a standard C function)
has nothing to do with your phantom so I'll skip it for the moment.
To avoid this problem, just exit your main() routine using return(0)
or exit(0).

---
John Stanley (dynasoft!john@stag.UUCP)
Software Consultant / Dynasoft Systems

leo@philmds.UUCP (Leo de Wit) (07/08/88)

In article <511@stag.UUCP> stdnet@stag.UUCP writes:
>From: thelake!steve@stag.UUCP (Steve Yelvington)
>
>
>I compiled a directory lister with Mark Johnson C, version 2.0. 
>It works just fine, but at the end of the directory, it prints out a 
>message on the console: "(no more files)".
>
>This message is nowhere to be found in my program or in the MJC library.
>So I figure that either it is coming from GEMdos, or I have a friendly ghost.
>I want it to go away.
>
>One of the local programmers (John Osawa, author of the Schizo desk
>accessory) tried my code with Mark Williams C and got no such message.
>He suggested that MJC's startup code may throw a switch, and mentioned
>something about Perror. I thumbed through "Atari ST Application 
>Programming" (Pollack and Weber), but found no references to Perror.
>It's not in osbind.h. I found nothing like it in the MJC startup routines,
>either.
>
>So: What is Perror? How do I shut off this message?

In Unix the function perror() prints out its string argument, followed
by a colon and an error message. This error message is from an array
(something like char *sys_errlist[]; but you don't have to declare it)
and is indexed into by the global int errno, which contains the last
O.S. error encountered.  Probably your Perror behaves just like this -
maybe it is in the startup code with which MJC C binaries are linked
and activated when the last error encountered is non-zero (just
guessing). Most likely the GEMDOS calls Fsfirst and Fsnext are used
to scan a directory; when Fsnext fails at last - no more files that
satisfy the spec - it returns -49. I suggest you check the global
ints like errno (maybe there's also an oserr), print them out after
the directory scan. One of them will most likely contain -49.

To shut off this message you have two options: just set errno to
0 before exiting (or the global int that is 'responsible') or if
you dislike the 'automatic' Perror (I would) you could patch the
startup code with NOP's on the relevant place(s).

extern int errno;

     errno = 0; /* and then leave main() or do exit() */

Hope this helps...

                  Leo.

rho@hound-dog.cs.unlv.edu (Roy H. Ogawa) (07/14/88)

In article <515@stag.UUCP> stdnet@stag.UUCP writes:
>In comp.sys.atari.st, thelake!steve@stag.UUCP (Steve Yelvington) writes:
> >
> >I compiled a directory lister with Mark Johnson C, version 2.0. 
> >It works just fine, but at the end of the directory, it prints out a 
> >message on the console: "(no more files)".
> >
> >This message is nowhere to be found in my program or in the MJC library.
> >So I figure that either it is coming from GEMdos, or I have a friendly
> >ghost.  I want it to go away.
>
>  Steve, I guess you could say I'm the "friendly ghost".  :)
>
>  The message you mentioned is one of the standard error code
>messages in my JSH command shell.  I'm assuming you're using JSH?

 . . . explanation of the problem and solution . . .

>
> >One of the local programmers (John Osawa, author of the Schizo desk
> >accessory) tried my code with Mark Williams C and got no such message.
> >He suggested that MJC's startup code may throw a switch, and mentioned
> >something about Perror. I thumbed through "Atari ST Application 
> >Programming" (Pollack and Weber), but found no references to Perror.
> >It's not in osbind.h. I found nothing like it in the MJC startup routines,
> >either.
>
>  To the best of my knowledge, the MWC crt0() code totaly ignores the
>return value from main() and requires that any return value other
>than zero be returned using exit(n).
>
> >
> >So: What is Perror? How do I shut off this message?
> >
>
>  Excelent programmer that he is, John Osawa is taking a long shot
>guess and, in this case, missing...  Perror (a standard C function)
>has nothing to do with your phantom so I'll skip it for the moment.
>To avoid this problem, just exit your main() routine using return(0)
>or exit(0).


Ok guys <grin>.  There is just *so* much that I can stand my name taken
error.  It's JOHN OGAWA <grin>.  Of course, the *really* funny thing about
all of this is that all 3 of us, Steve, John, and I, live in Minneapolis,
and are on some of the same BBSs <grin>.
	John was right, I was taking a stab in the dark, guessing that MJC
had a call to Perror (or some such routine) built into its TOS call handlers.
But, all's well that ends well.
	Er, please DO NOT REPLY TO THIS ACCOUNT.  I will never see it.  In
fact, until I find a USENET-accessable account, I will never see any replies.
	I *am* working on Schizo v1.5, for those who are interested.  It is
taking a long time because my research is getting in the way.  I will ask
someone to post it here if and when it is completed (maybe by one of the two
kind fellow Minneapoleans above).  If I can get it going, it will have a
non-GEM-dependant corner clock, and resolution-sensitive DESKTOP.INF reading
abilities.

Thanks much,

John Ogawa
Institute of Child Development
University of Minnesota
51 E. River Rd.
Minneapolis, MN   55455


PS>  If someone *really* needs to get a hold of me, write to the above
USmail address.  Or actually, if you can find a way, write email to:
	lxw6035@ux.acss.umn.edu
or some such domain-name.  It is a dumb, USENET-less, blind-mail machine,
 that *is* on BITNET supposedly, though you could've fooled me <grin>.