home *** CD-ROM | disk | FTP | other *** search
/ Freelog 30 / Freelog030.iso / Palm / Comptebon / Src / CompteBon.c < prev   
C/C++ Source or Header  |  2000-08-20  |  21KB  |  768 lines

  1. /***********************************************************************
  2.  *
  3.  * Copyright (c) Pierre TOUZEAU.
  4.  * All rights reserved.
  5.  *
  6.  * PROJECT:  CompteBon
  7.  * FILE:     CompteBon.c
  8.  * AUTHOR:   Pierre TOUZEAU  08 Aout 2000
  9.  *
  10.  * DECLARER: Starter
  11.  *
  12.  * DESCRIPTION:
  13.  *      
  14.  *
  15.  **********************************************************************/
  16. #include <Pilot.h>
  17. #include <SysEvtMgr.h>
  18. #include <MemoryMgr.h>
  19.  
  20.  
  21. #ifdef    TARGET_FRENCH
  22. #include "CompteBon-FR-Rsc.c"
  23. #include "CompteBon-FR_res.h"
  24. #endif
  25.  
  26. #ifdef    TARGET_ENGLISH
  27. #include "CompteBon-EN-Rsc.c"
  28. #include "CompteBon-EN_res.h"
  29. #endif
  30.  
  31.  
  32. /***********************************************************************
  33.  *
  34.  *   Entry Points
  35.  *
  36.  ***********************************************************************/
  37.  
  38.  
  39. /***********************************************************************
  40.  *
  41.  *   Internal Structures
  42.  *
  43.  ***********************************************************************/
  44. typedef struct 
  45.     {
  46.     Byte replaceme;
  47.     } StarterPreferenceType;
  48.  
  49. typedef struct 
  50.     {
  51.     Byte replaceme;
  52.     } StarterAppInfoType;
  53.  
  54. typedef StarterAppInfoType* StarterAppInfoPtr;
  55.  
  56.  
  57. /***********************************************************************
  58.  *
  59.  *   Global variables
  60.  *
  61.  ***********************************************************************/
  62. //static Boolean HideSecretRecords;
  63.  
  64. #define NbValListInit    14
  65. #define MaxLenResult    512
  66.  
  67. CharPtr InitResultFieldStr;
  68.  
  69. static int dta1[7] = {0,1,7,12,16,19,21};
  70. static int dta2[7] = {0,6,11,15,18,20,21};
  71. static char* ListInit[NbValListInit] = {
  72.  "1","2","3","4","5","6","7","8","9","10","25","50","75","100" };
  73.  
  74. static char car[]="+-*/";
  75.  
  76.  
  77. Int16 TabInit[2][24];
  78.  
  79. char TabLabel[6][5];
  80.  
  81. CharPtr ResultStrValue[2];
  82. CharPtr alertStr1;
  83. CharPtr alertStr2;
  84.  
  85. Int16    paramValues[6];
  86.  
  87. UInt16 TabCtl[6] = {
  88.         MainVar1PopTrigger,
  89.         MainVar2PopTrigger,
  90.         MainVar3PopTrigger,
  91.         MainVar4PopTrigger,
  92.         MainVar5PopTrigger,
  93.         MainVar6PopTrigger
  94.         };
  95.  
  96. /***********************************************************************
  97.  *
  98.  *   Internal Constants
  99.  *
  100.  ***********************************************************************/
  101. #define appFileCreator                    'strt'
  102. #define appVersionNum              0x01
  103. #define appPrefID                  0x00
  104. #define appPrefVersionNum          0x01
  105.  
  106.  
  107. // Define the minimum OS version we support
  108. #define ourMinVersion    sysMakeROMVersion(2,0,0,sysROMStageRelease,0)
  109.  
  110.  
  111. /***********************************************************************
  112.  *
  113.  *   Internal Functions
  114.  *
  115.  ***********************************************************************/
  116.  Int16 abs (Int16 a)
  117.  {
  118.    return (a>0 ? a:-a);
  119.  }
  120.  
  121. /***********************************************************************
  122.  *
  123.  * FUNCTION:    RomVersionCompatible
  124.  *
  125.  * DESCRIPTION: This routine checks that a ROM version is meet your
  126.  *              minimum requirement.
  127.  *
  128.  * PARAMETERS:  requiredVersion - minimum rom version required
  129.  *                                (see sysFtrNumROMVersion in SystemMgr.h 
  130.  *                                for format)
  131.  *              launchFlags     - flags that indicate if the application 
  132.  *                                UI is initialized.
  133.  *
  134.  * RETURNED:    error code or zero if rom is compatible
  135.  *
  136.  * REVISION HISTORY:
  137.  *
  138.  ***********************************************************************/
  139. static Err RomVersionCompatible(DWord requiredVersion, Word launchFlags)
  140. {
  141.     DWord romVersion;
  142.  
  143.     // See if we're on in minimum required version of the ROM or later.
  144.     FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
  145.     if (romVersion < requiredVersion)
  146.         {
  147.         if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
  148.             (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
  149.             {
  150.             FrmAlert (RomIncompatibleAlert);
  151.         
  152.             // Pilot 1.0 will continuously relaunch this app unless we switch to 
  153.             // another safe one.
  154.             if (romVersion < sysMakeROMVersion(2,0,0,sysROMStageRelease,0))
  155.                 AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
  156.             }
  157.         
  158.         return (sysErrRomIncompatible);
  159.         }
  160.  
  161.     return (0);
  162. }
  163.  
  164. /***********************************************************************
  165.  *
  166.  * FUNCTION:    GetObjectPtr
  167.  *
  168.  * DESCRIPTION: This routine returns a pointer to an object in the
  169.  *              form FormP or in the current form if FormP is NULL.
  170.  *
  171.  * PARAMETERS:  ObjectId - id of the object to search
  172.  *
  173.  * RETURNED:    VoidPtr
  174.  *
  175.  * REVISION HISTORY:
  176.  *
  177.  *
  178.  ***********************************************************************/
  179. VoidPtr GetObjectPtr( FormPtr formP, Word objectID)
  180. {
  181.     FormPtr frmP;
  182.  
  183.     if ( formP != NULL )
  184.         frmP = formP;
  185.     else
  186.         frmP = FrmGetActiveForm();
  187.         
  188.     return FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, objectID ) );
  189.  
  190. }    // GetObjectPtr
  191.  
  192.  
  193. /***********************************************************************
  194.  *
  195.  * FUNCTION:    SetNewTextInField
  196.  *
  197.  * DESCRIPTION: This routine modify the text in a field.
  198.  *
  199.  * PARAMETERS:  frm - pointer to the form (Active form if NULL).
  200.  *                oid - Object field Index in the form
  201.  *                str - String to place in the field
  202.  * RETURNED:    nothing
  203.  *
  204.  * REVISION HISTORY:
  205.  *
  206.  *
  207.  ***********************************************************************/
  208. void SetNewTextInField(FormPtr frm, UInt16 oid, char* str)
  209. {
  210.     VoidPtr    ObjP;
  211.     Handle TextH;
  212.     Handle NewTextH;
  213.     char* TextP;
  214.  
  215.     if (frm == NULL)
  216.         frm = FrmGetActiveForm();
  217.  
  218.  
  219.     // get the index of the Field control
  220.     ObjP = GetObjectPtr( frm, oid );
  221.     // get the Mem TextHandle of the Field to set it
  222.     TextH = FldGetTextHandle (ObjP);
  223.     // Cut the link between the field and the TextHandle in order to
  224.     // avoid sync problem (you type & your code both modify the values?)
  225.     FldSetTextHandle (ObjP, NULL);
  226.     
  227.     // Follow the line !
  228.     // Allocate new one, then Lock, then Modify, then Unlock...
  229.     NewTextH = MemHandleNew (StrLen(str)+1);
  230.     TextP = MemHandleLock (NewTextH);
  231.     StrCopy (TextP, str);
  232.     MemHandleUnlock (NewTextH);
  233.     // and then put it back by
  234.     // Re-establish the link between the text handle and the field
  235.     FldSetTextHandle (ObjP, NewTextH);
  236.     // Update the field
  237.     FldDrawField (ObjP);
  238.     
  239.     // free the old TextHandle
  240.     if (TextH != NULL)
  241.         MemHandleFree( TextH);
  242.  
  243. }
  244.  
  245.  
  246. /***********************************************************************
  247.  *
  248.  * FUNCTION:    Compte     (count or compute in french...)
  249.  *
  250.  * DESCRIPTION: This routine compute the solution of the problem :
  251.  *     How to obtain the RESULT with 6 number combined with + - * /  ?
  252.  *
  253.  * PARAMETERS:  6 input numbers and cible (french word for target).
  254.  *              and result the string answer
  255.  * RETURNED:    void
  256.  *
  257.  * REVISION HISTORY:
  258.  *
  259.  *
  260.  ***********************************************************************/
  261. void Compte(CharPtr result, Int16 param[6], Int16 cible)
  262. {
  263.     Int16 nb[22],res[22],tot[22],best,delta,new,diff,a,b;
  264.     Int16 i,j,k,n,o,p,q,op[6],p1[7],p2[7],deb[7],fin[7];
  265.     char tmpresult[MaxLenResult];
  266.  
  267. // TAKE CARE ! nb array begins at 1 !!! (historical reason, i suppose...)
  268. for(i=0; i<6; i++) nb[i+1] = param[i];
  269. for (i=0; i<8 ;i++) {deb[i]=dta1[i];fin[i]=dta2[i];};
  270. // Bubble sort for input parameters
  271. j=0;
  272. while (j==0)
  273.    {for (i=1,j=1;i<6;i++)
  274.        {if ((p=nb[i])<(q=nb[i+1])) {nb[i]=q;nb[i+1]=p;j=0;}  }
  275.    }
  276.  
  277. // StrPrintF(tmpresult,"%3d %3d %3d %3d %3d %3d",nb[1],nb[2],nb[3],nb[4],nb[5],nb[6]);
  278. // FrmCustomAlert (DisplayMsgAlert,"Variables d'entrΘe :",tmpresult," Proc Compte()");
  279.  
  280. /****** appel de la fonction de calcul ***********************/
  281. /****** procedure COMPTE pour jeu ****************************/
  282. delta =1000;
  283.  n=1;
  284.  op[1]=0;p1[1]=deb[1];p2[1]=p1[1]+1;
  285.  while (n)
  286.     {while (p1[n] < fin[n])
  287.       {while (p2[n] <= fin[n])
  288.         {while (op[n] <4)
  289.           { o=op[n]++; p=p1[n]; q=p2[n]; a=nb[p]; b=nb[q];
  290.             switch (o)
  291.             { case 0 : new=a+b; break;
  292.               case 1 : if (a==b) goto pop; else new=a-b; break;
  293.               case 2 : if (a==1 || b==1) goto pop; else new=a*b;break;
  294.               case 3 : if (b==1) goto pop; else new=a/b;
  295.                        if (new*b != a ) goto pop;
  296.               default: break;
  297.             }
  298.           diff=abs(cible-new); tot[n]=new;
  299.           if (diff < delta)
  300.             {i=1; j=1; res[1]=n;
  301.               while (i<n)
  302.                 {res[++j]=nb[p1[i]];   res[++j]=nb[p2[i]];
  303.                  res[++j]=op[i]-1;     res[++j]=tot[i++]; }
  304.               res[j+1]=a;    res[j+2]=b;
  305.               res[j+3]=o;    res[j+4]=new;
  306.               best=new;      delta=diff;
  307.               if (diff==0) goto retour;
  308.             }
  309.           if (n<5)
  310.             {i=deb[n+1];
  311.              for (k=deb[n]; k<=fin[n]; k++)
  312.                   if (k!=p && k!=q)
  313.                     {if (new>nb[k]) {nb[i++]=new; new= -1;}
  314.                      nb[i++]=nb[k];
  315.                     }
  316.              if (new>0)  nb[i]=new;
  317.              op[++n]=0;  p1[n]=deb[n];
  318.              p2[n]=p1[n]+1;
  319.             }
  320.           pop:;
  321.          }
  322.        p2[n]++;
  323.        op[n]=0;
  324.       }
  325.      p1[n]++;
  326.      p2[n]=p1[n]+1;
  327.      op[n]=0;
  328.     }
  329.    n=n-1;
  330.   }
  331.  retour:;
  332.  
  333. /****** impression des resultats du calcul de COMPTE *********/
  334. /*    for(i=0;i<23;i++)printf("res=%d",res[i]);    */
  335. n=res[1];
  336. p=(cible==best)? 1 : 0;
  337. StrPrintF(result,"%s %d\n",ResultStrValue[p],best);
  338. //StrPrintF(tmpresult,"%s %3d %3d %3d %3d %3d %3d",blanc,nb[1],nb[2],nb[3],nb[4],nb[5],nb[6]);
  339. //StrNCat(result, tmpresult, MaxLenResult);
  340. for (i=1;i<=n;i++)
  341.    {a=res[i*4-2];b=res[i*4-1];
  342.     o=res[i*4];new=res[i*4+1];
  343.         k=a;p=b;
  344.     for (j=1,q=0;j<=i+6;j++)
  345.        { if(a==nb[j] && nb[j] !=0 && q<2) {a=-1;q++;nb[j]=0;}
  346.          if(b==nb[j] && nb[j] !=0 && q<2) {b=-1;q++;nb[j]=0;}
  347.        }
  348.     nb[i+6]=new;
  349.     StrPrintF(tmpresult,"\n%3d %c%3d =",k,car[o],p);
  350.     StrNCat(result, tmpresult, MaxLenResult);
  351.     //for (k=0; s[k]; k++) { 
  352.     //    StrPrintF(tmpresult,"%c",s[k]);
  353.     //    StrNCat(result, tmpresult, MaxLenResult);
  354.     //    }
  355.     StrPrintF(tmpresult," %3d ",new);
  356.     StrNCat(result, tmpresult, MaxLenResult);
  357.    }
  358.  }    // Compte
  359.  
  360.  
  361. /***********************************************************************
  362.  *
  363.  * FUNCTION:    MainFormInit
  364.  *
  365.  * DESCRIPTION: This routine initializes the MainForm form.
  366.  *
  367.  * PARAMETERS:  frm - pointer to the MainForm form.
  368.  *
  369.  * RETURNED:    nothing
  370.  *
  371.  * REVISION HISTORY:
  372.  *
  373.  *
  374.  ***********************************************************************/
  375. static void MainFormInit(FormPtr frmP)
  376. {
  377.     VoidPtr    ObjP;
  378.     CharPtr    initstr;
  379.     int i;
  380.     
  381. // About the global init of array TabInit
  382. for ( i=0; i<24 ; i++ ) TabInit[0][i] = 0;
  383. for ( i=0; i<10 ; i++ ) TabInit[1][i] = TabInit[1][i+10] = i+1;
  384.     TabInit[1][20] = 25;
  385.     TabInit[1][21] = 50;
  386.     TabInit[1][22] = 75;
  387.     TabInit[1][23] =100;
  388.  
  389. // About the List Object
  390.     // get the index of the List control
  391.     ObjP = GetObjectPtr( frmP, MainListNumList );
  392.     // Set the items text to the list
  393.        LstSetListChoices(ObjP, ListInit, NbValListInit);
  394.  
  395. // About the Total Field Object
  396.     SetNewTextInField (frmP, MainTotalField, "888");
  397.  
  398.  
  399. // Get resource string for About alert
  400.     alertStr1 = MemHandleLock (DmGetResource (strRsc, AlertBody1String));
  401.     alertStr2 = MemHandleLock (DmGetResource (strRsc, AlertBody2String));
  402.  
  403. // Get the resource string for the Result Field Object during computing
  404.     InitResultFieldStr = MemHandleLock (DmGetResource (strRsc, InitResultString));
  405.  
  406. // Get resource string for Result string "The count is ..right : "
  407.     ResultStrValue[0] = MemHandleLock (DmGetResource (strRsc, BadResultString));
  408.     ResultStrValue[1] = MemHandleLock (DmGetResource (strRsc, GoodResultString));
  409.  
  410. // About the Result Field Object
  411.     initstr = MemHandleLock (DmGetResource (strRsc, HelpResultFieldString));
  412.     SetNewTextInField (frmP, MainResultField, initstr);
  413.  
  414. }
  415.  
  416.  
  417. /***********************************************************************
  418.  *
  419.  * FUNCTION:    MainFormDoCommand
  420.  *
  421.  * DESCRIPTION: This routine performs the menu command specified.
  422.  *
  423.  * PARAMETERS:  command  - menu item id
  424.  *
  425.  * RETURNED:    nothing
  426.  *
  427.  * REVISION HISTORY:
  428.  *
  429.  *
  430.  ***********************************************************************/
  431. static Boolean MainFormDoCommand(Word command)
  432. {
  433.     Boolean handled = false;
  434.  
  435.     switch (command)
  436.         {
  437. #ifdef    TARGET_FRENCH
  438.         case MainOptionsAusujetduCompteestbon :
  439. #endif
  440. #ifdef    TARGET_ENGLISH
  441.         case MainOptionsAbouttheCountisright :
  442. #endif
  443.             MenuEraseStatus (0);
  444.             FrmCustomAlert (DisplayMsgAlert,alertStr1,alertStr2,
  445.             "pierre.touzeau@wanadoo.fr");
  446.             //AbtShowAbout (appFileCreator);
  447.             handled = true;
  448.             break;
  449.  
  450.         }
  451.     return handled;
  452. }
  453.  
  454.  
  455. /***********************************************************************
  456.  *
  457.  * FUNCTION:    MainFormHandleEvent
  458.  *
  459.  * DESCRIPTION: This routine is the event handler for the 
  460.  *              "MainForm" of this application.
  461.  *
  462.  * PARAMETERS:  eventP  - a pointer to an EventType structure
  463.  *
  464.  * RETURNED:    true if the event has handle and should not be passed
  465.  *              to a higher level handler.
  466.  *
  467.  * REVISION HISTORY:
  468.  *
  469.  *
  470.  ***********************************************************************/
  471. static Boolean MainFormHandleEvent(EventPtr eventP)
  472. {
  473.     Boolean handled = false;
  474.     FormPtr frmP=NULL;
  475.     char    tmp[MaxLenResult];
  476.     int        i, rnd, tabparam[6];
  477.  
  478.  
  479.     switch (eventP->eType) 
  480.         {
  481.         case menuEvent:
  482.             return MainFormDoCommand(eventP->data.menu.itemID);
  483.  
  484.         case frmOpenEvent:
  485.             frmP = FrmGetActiveForm();
  486.             MainFormInit( frmP);
  487.             FrmDrawForm ( frmP);
  488.             handled = true;
  489.             break;
  490.         case ctlSelectEvent:
  491.             {
  492.                    ControlPtr    CtlP;
  493.                    FieldPtr    FldP;
  494.                 //handled = true;    //assume we'll handle it
  495.                 switch (eventP->data.ctlSelect.controlID)
  496.                     {
  497.                         case MainRandomTargetButton:
  498.                         // We randomly choose a new target(>100) and set the field
  499.                             rnd = 0;
  500.                             while (rnd<100)
  501.                                 rnd = SysRandom(0) % 999;
  502.                             StrPrintF(tmp,"%3d",rnd);
  503.                             SetNewTextInField (frmP, MainTotalField, tmp);
  504.                             handled = true;    //assume we'll handle it
  505.                             break;
  506.                         case MainRandomParamButton:
  507.                         // We compute the 6 params ramdomly,we choose value in the TabInit array
  508.                         // each value can only be choosed 1 time. we lit up and control the flag
  509.                         // stored in position [0] in the tabinit array.
  510.                         // When value ok, then we print the label in PopupTrigger control, we
  511.                         // already prepaped a 6 value array (TabCtl) containing the index of Ctl
  512.                             for (i=0; i<6; i++)
  513.                             {
  514.                                 tabparam[i] = SysRandom (0) % 23 ;
  515.                                 if ( TabInit[0][tabparam[i]]==0 )
  516.                                     {
  517.                                         TabInit[0][ tabparam[i] ]++;
  518.                                         paramValues[i] = TabInit[1][ tabparam[i]];
  519.                                         StrPrintF(TabLabel[i],"%d",paramValues[i]);
  520.                                         CtlP = GetObjectPtr( frmP, TabCtl[i] );
  521.                                         CtlSetLabel( CtlP, TabLabel[i]);
  522.                                         //StrPrintF(tmp,"paramValues[%d]=%3d",i,paramValues[i]);
  523.                                         //FrmCustomAlert (DisplayMsgAlert,"Variables d'entrΘe :",tmp," Evnt Tirage");
  524.                                     }
  525.                                     else
  526.                                         i--;
  527.                             }                            
  528.  
  529.                             handled = true;    //assume we'll handle it
  530.                             break;
  531.                         case MainCalculButton:
  532.                             // first, we clear the result field
  533.                             SetNewTextInField (frmP, MainResultField, InitResultFieldStr);
  534.  
  535.                             // then we  prepare the input values for Compute procedure
  536.                             // (we get the index of the popup control and set the array value)
  537.                             for (i=0; i<6; i++)
  538.                             {
  539.                                 CtlP = GetObjectPtr( frmP, TabCtl[i] );
  540.                                 paramValues[i] = StrAToI( CtlGetLabel(CtlP) );
  541.                             }
  542.                             FldP = GetObjectPtr( frmP, MainTotalField );
  543.                             rnd = StrAToI( FldGetTextPtr(FldP));
  544.                             
  545.                             Compte(tmp, paramValues, rnd);
  546.  
  547.                             SetNewTextInField (frmP, MainResultField, tmp);
  548.                                 
  549.                             handled = true;    //assume we'll handle it
  550.                             break;
  551.                     }
  552.             } // end case ctlSelectEvent
  553.         default:
  554.             break;
  555.         
  556.         }
  557.     
  558.     return handled;
  559. }
  560.  
  561.  
  562. /***********************************************************************
  563.  *
  564.  * FUNCTION:    AppHandleEvent
  565.  *
  566.  * DESCRIPTION: This routine loads form resources and set the event
  567.  *              handler for the form loaded.
  568.  *
  569.  * PARAMETERS:  event  - a pointer to an EventType structure
  570.  *
  571.  * RETURNED:    true if the event has handle and should not be passed
  572.  *              to a higher level handler.
  573.  *
  574.  * REVISION HISTORY:
  575.  *
  576.  *
  577.  ***********************************************************************/
  578. static Boolean AppHandleEvent( EventPtr eventP)
  579. {
  580.     Word formId;
  581.     FormPtr frmP;
  582.  
  583.  
  584.     if (eventP->eType == frmLoadEvent)
  585.         {
  586.         // Load the form resource.
  587.         formId = eventP->data.frmLoad.formID;
  588.         frmP = FrmInitForm(formId);
  589.         FrmSetActiveForm(frmP);
  590.  
  591.         // Set the event handler for the form.  The handler of the currently
  592.         // active form is called by FrmHandleEvent each time is receives an
  593.         // event.
  594.         switch (formId)
  595.             {
  596.             case MainForm:
  597.                 FrmSetEventHandler(frmP, MainFormHandleEvent);
  598.                 break;
  599.  
  600.             default:
  601. //                ErrFatalDisplay("Invalid Form Load Event");
  602.                 break;
  603.  
  604.             }
  605.         return true;
  606.         }
  607.     
  608.     return false;
  609. }
  610.  
  611.  
  612. /***********************************************************************
  613.  *
  614.  * FUNCTION:    AppEventLoop
  615.  *
  616.  * DESCRIPTION: This routine is the event loop for the application.  
  617.  *
  618.  * PARAMETERS:  nothing
  619.  *
  620.  * RETURNED:    nothing
  621.  *
  622.  * REVISION HISTORY:
  623.  *
  624.  *
  625.  ***********************************************************************/
  626. static void AppEventLoop(void)
  627. {
  628.     Word error;
  629.     EventType event;
  630.  
  631.  
  632.     do {
  633.         EvtGetEvent(&event, evtWaitForever);
  634.         
  635.         
  636.         if (! SysHandleEvent(&event))
  637.             if (! MenuHandleEvent(0, &event, &error))
  638.                 if (! AppHandleEvent(&event))
  639.                     FrmDispatchEvent(&event);
  640.  
  641.     } while (event.eType != appStopEvent);
  642. }
  643.  
  644.  
  645. /***********************************************************************
  646.  *
  647.  * FUNCTION:     AppStart
  648.  *
  649.  * DESCRIPTION:  Get the current application's preferences.
  650.  *
  651.  * PARAMETERS:   nothing
  652.  *
  653.  * RETURNED:     Err value 0 if nothing went wrong
  654.  *
  655.  * REVISION HISTORY:
  656.  *
  657.  *
  658.  ***********************************************************************/
  659. static Err AppStart(void)
  660. {
  661.     StarterPreferenceType prefs;
  662.     Word prefsSize;
  663.  
  664.  
  665.     // Read the saved preferences / saved-state information.
  666.     prefsSize = sizeof(StarterPreferenceType);
  667.     if (PrefGetAppPreferences(appFileCreator, appPrefID, &prefs, &prefsSize, true) != 
  668.         noPreferenceFound)
  669.         {
  670.         }
  671.     
  672.    return 0;
  673. }
  674.  
  675.  
  676. /***********************************************************************
  677.  *
  678.  * FUNCTION:    AppStop
  679.  *
  680.  * DESCRIPTION: Save the current state of the application.
  681.  *
  682.  * PARAMETERS:  nothing
  683.  *
  684.  * RETURNED:    nothing
  685.  *
  686.  * REVISION HISTORY:
  687.  *
  688.  *
  689.  ***********************************************************************/
  690. static void AppStop(void)
  691. {
  692.    StarterPreferenceType prefs;
  693.    
  694.    
  695.     // Write the saved preferences / saved-state information.  This data 
  696.     // will be backed up during a HotSync.
  697.     PrefSetAppPreferences (appFileCreator, appPrefID, appPrefVersionNum, 
  698.         &prefs, sizeof (prefs), true);
  699. }
  700.  
  701.  
  702.  
  703. /***********************************************************************
  704.  *
  705.  * FUNCTION:    StarterPilotMain
  706.  *
  707.  * DESCRIPTION: This is the main entry point for the application.
  708.  * PARAMETERS:  cmd - word value specifying the launch code. 
  709.  *              cmdPB - pointer to a structure that is associated with the launch code. 
  710.  *              launchFlags -  word value providing extra information about the launch.
  711.  *
  712.  * RETURNED:    Result of launch
  713.  *
  714.  * REVISION HISTORY:
  715.  *
  716.  *
  717.  ***********************************************************************/
  718. static DWord StarterPilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
  719. {
  720.     Err error;
  721.  
  722.  
  723.     error = RomVersionCompatible (ourMinVersion, launchFlags);
  724.     if (error) return (error);
  725.  
  726.  
  727.     switch (cmd)
  728.         {
  729.         case sysAppLaunchCmdNormalLaunch:
  730.             error = AppStart();
  731.             if (error) 
  732.                 return error;
  733.                 
  734.             FrmGotoForm(MainForm);
  735.             AppEventLoop();
  736.             AppStop();
  737.             break;
  738.  
  739.         default:
  740.             break;
  741.  
  742.         }
  743.     
  744.     return 0;
  745. }
  746.  
  747.  
  748. /***********************************************************************
  749.  *
  750.  * FUNCTION:    PilotMain
  751.  *
  752.  * DESCRIPTION: This is the main entry point for the application.
  753.  *
  754.  * PARAMETERS:  cmd - word value specifying the launch code. 
  755.  *              cmdPB - pointer to a structure that is associated with the launch code. 
  756.  *              launchFlags -  word value providing extra information about the launch.
  757.  * RETURNED:    Result of launch
  758.  *
  759.  * REVISION HISTORY:
  760.  *
  761.  *
  762.  ***********************************************************************/
  763. DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags)
  764. {
  765.     return StarterPilotMain(cmd, cmdPBP, launchFlags);
  766. }
  767.  
  768.