home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Final Chance 1.1.1 / source / init code ƒ / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.5 KB  |  116 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        init.c
  4.  
  5. Purpose:    This module handles INIT initialization and installation of
  6.             the dialog resources in memory (for use on shutdown).
  7.             
  8.  
  9. Final Chance -=- a "do you really want to do this?" dialog on shutdown
  10. Copyright ©1993-4, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "init.h"
  30. #include "main.h"
  31. #include "notify.h"
  32. #include "ShutDown.h"
  33.  
  34. Handle            initHandle;            /* handle to main init code */
  35.  
  36. void __GetA4(void)
  37. {
  38.     asm {
  39.         bsr.s    @1
  40.         dc.l    0            ;  store A4 here
  41. @1        move.l    (sp)+,a1
  42.     }
  43. }
  44.  
  45. /* this be the init startup install routine thing */
  46. void main(void)
  47. {
  48.     THz                saveZone;
  49.     
  50.     RememberA0();    /* assume A0 has the address of the start of the code */
  51.     SetUpA4();
  52.     
  53.     saveZone=GetZone();
  54.     SetZone(SysZone);
  55.     
  56.     asm
  57.     {
  58.         movea.l            a4, a0
  59.         RecoverHandle
  60.         move.l            a0, initHandle
  61.     }
  62.     if (MemError())
  63.     {
  64.         StartupError();
  65.     }
  66.     else
  67.     {
  68.         HLock(initHandle);
  69.         HNoPurge(initHandle);
  70.         
  71.         if (DoSetup())
  72.             StartupGood();
  73.         else
  74.             StartupError();
  75.     }
  76.     
  77.     SetZone(saveZone);
  78.     
  79.     RestoreA4();
  80. }
  81.  
  82. Boolean DoSetup(void)
  83. {
  84.     unsigned long    temp;
  85.     Handle            tempHandle;
  86.     unsigned int    totalNumberOfQuotes;
  87.     
  88.     gChanceDlog=gChanceDitl=tempHandle=0L;
  89.     
  90.     gChanceDlog=(DialogTHndl)GetResource('DLOG', 128);
  91.     if (gChanceDlog==0L)
  92.         return FALSE;
  93.     gChanceDitl=GetResource('DITL', 128);
  94.     if (gChanceDitl==0L)
  95.         return FALSE;
  96.     
  97.     tempHandle=GetResource('STR#', 128);
  98.     if (tempHandle==0L)
  99.         return FALSE;
  100.     
  101.     totalNumberOfQuotes=*((unsigned int*)(*tempHandle));
  102.     ReleaseResource(tempHandle);
  103.     if (totalNumberOfQuotes==0)
  104.         return FALSE;
  105.     
  106.     GetDateTime(&temp);
  107.     GetIndString(gTheQuote, 128, (temp%totalNumberOfQuotes)+1);
  108.     
  109.     DetachResource(gChanceDlog);
  110.     DetachResource(gChanceDitl);
  111.     
  112.     ShutDwnInstall((ProcPtr)&FinalChance, sdOnDrivers+sdOnPowerOff);
  113.     
  114.     return TRUE;
  115. }
  116.