Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!dogie.macc.wisc.edu!uwvax!umn-d-ub!umn-cs!nis!pwcs!stag!daemon From: dal@syntel.mn.org (Dale Schumacher) Newsgroups: comp.sys.atari.st Subject: Re: Did I come from the desktop? Message-ID: <1989Nov29.182253.2681@stag.UUCP> Date: 29 Nov 89 18:22:53 GMT Sender: daemon@stag.UUCP (The devil himself) Organization: Mindtools ST Access Group Lines: 73 [jmw@tasis.utas.oz.au@munnari.oz (John Williams) writes...] > A recent article suggested three possible methods by which a process could > determine whether it was being run from the desktop or from a shell. I'd like > to suggest another method which works for me. I don't suggest that it is > foolproof however. It simply requires moving the basepage ptr up to its parent > until it becomes null. If this requires three iterations then the program > is running from the desktop. Any more and it is running from a shell. Alright, I guess it's time to post this message again (is this the 3rd time now?). The quoted message is mostly correct, but incomplete. The situation is slightly different if you're in the /AUTO/ folder programs at boot-time. I check for the text-base pointer pointing to ROM, as recommended by Alan Pratt @ Atari. The following code (which, like John's code, assumes access to a basepage pointer) uses this "approved" method. I've also included a copy of from dLibs for those who don't know the layout of the basepage structure. /***********************************************************************/ #include #define FROM_AUTO 0 #define FROM_DESKTOP 1 #define FROM_SHELL 2 camefrom() { register BASEPAGE *p = _base; register int n = 0; p = p->p_parent; if((((long) (p->p_tbase)) & 0x800000L) == 0L) return(FROM_SHELL); while(p = p->p_parent) ++n; return((n == 1) ? FROM_AUTO : ((n == 2) ? FROM_DESKTOP : FROM_SHELL)); } /***********************************************************************/ /* * BASEPAGE.H Definition of the basepage structure */ #ifndef BASEP_H #define BASEP_H typedef struct basep { char *p_lowtpa; /* pointer to self (bottom of TPA) */ char *p_hitpa; /* pointer to top of TPA + 1 */ char *p_tbase; /* base of text segment */ long p_tlen; /* length of text segment */ char *p_dbase; /* base of data segment */ long p_dlen; /* length of data segment */ char *p_bbase; /* base of BSS segment */ long p_blen; /* length of BSS segment */ char *p_dta; /* pointer to current DTA */ struct basep *p_parent; /* pointer to parent's basepage */ char *p_reserved; /* reserved for future use */ char *p_env; /* pointer to environment string */ long p_undef[20]; /* scratch area... don't touch */ char p_cmdlin[128]; /* command line image */ } BASEPAGE; extern BASEPAGE *_base; #endif BASEP_H /***********************************************************************/ \\ / Dale Schumacher 399 Beacon Ave. \\ / (alias: Dalnefre') St. Paul, MN 55104-3527 >< ...umn-cs!midgard.mn.org!syntel!dal United States of America / \\ "What is wanted is not the will to believe, but the will to find out, / \\ which is the exact opposite." -Bertrand Russell