home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Workfile:: Template.c $
- * $Revision:: 2 $
- *
- * $Author:: Buck Rogers $
- * $Modtime:: 08.10.1997 02:02 Uhr $
- *
- * $History:: Template.c $
- *
- * ***************** Version 2 *****************
- * User: Buck Rogers Date: 08.10.1997 Time: 02:02 Uhr
- * Updated in $/BSNG/Plugins/BSNG SDK/BSNG Template
- * changed lf to cr in list generation so Mac compatible output is created
- *
- * ***************** Version 1 *****************
- * User: Buck Rogers Date: 06.10.1997 Time: 06:25 Uhr
- * Created in $/BSNG/Plugins/BSNG SDK/BSNG Template
- * Adding subproject 'BSNG Template' to '$/BSNG/Plugins/BSNG SDK'
- *
- * $NoKeywords:: $
- */
-
-
- #include <MixedMode.h>
- #include <A4Stuff.h>
-
- #include "standard utils.h"
- #include "UltraU.h"
- #include "BSNG API.h"
-
-
- /* don't touch this __procinfo definition or the calls from native code will crash the machine */
-
- ProcInfoType __procinfo = kThinkCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(BSNGParamBlockPtr)));
-
-
- /* function prototypes for ANSI C */
-
- static void DoInit(BSNGParamBlockPtr inData);
- static Boolean DoValidate(BSNGParamBlockPtr inData);
- static void DoCalc(BSNGParamBlockPtr inData);
- static void DoRandomCalc(BSNGParamBlockPtr inData);
- static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData);
- static void DoItemHit(BSNGParamBlockPtr inData);
- static void DoCleanup(BSNGParamBlockPtr inData);
- void main(BSNGParamBlockPtr inData);
-
-
- /* here is where the fun starts :-) */
-
- static void DoInit(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
- StringPtr item6 = inData->itemValue[kItemValue6];
- StringPtr item7 = inData->itemValue[kItemValue7];
- StringPtr item8 = inData->itemValue[kItemValue8];
- StringPtr item9 = inData->itemValue[kItemValue9];
- StringPtr item10 = inData->itemValue[kItemValue10];
-
-
- /* Initialize the Ultra Random Number generator (optional, use MacOS random functions otherwise) */
-
- Ultra_seed1 = inData->randSeed1;
- Ultra_seed2 = inData->randSeed2;
- Ultra_Init();
-
- /* Give the BSNG App the informations if your plugin can do random calculations and if it can write
- to the serial number list */
-
- inData->wantsRandomButton = true;
- inData->canAddToSNList = true;
-
- /* Initialize the EditFields with initial default values (optional, they are empty otherwise) */
- /* if you create a name-based generator please make sure that you copy the name, company and/or numCopies */
- /* values into the corrosponding fields */
-
- /* not name-based example
- BlockMoveData("\p12345678", item1, 9);
- BlockMoveData("\p23456789", item2, 9);
- BlockMoveData("\p34567890", item3, 9);
- item4[0] = 0;
- */
-
-
- /* name-based example
- BlockMoveData(inData->name, item1, inData->name[0] + 1);
- BlockMoveData(inData->company, item2, inData->company[0] + 1);
- BlockMoveData(inData->numCopies, item3, inData->numCopies[0] + 1);
- item4[0] = 0;
- */
-
- /* Tell the BSNG App if the initialisation was successful (it was in our case) */
-
- inData->error = errExtNoErr;
- inData->errorInItem = 0;
- } /* DoInit */
-
-
- static Boolean DoValidate(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
- StringPtr item6 = inData->itemValue[kItemValue6];
- StringPtr item7 = inData->itemValue[kItemValue7];
- StringPtr item8 = inData->itemValue[kItemValue8];
- StringPtr item9 = inData->itemValue[kItemValue9];
- StringPtr item10 = inData->itemValue[kItemValue10];
- Boolean error = false;
-
-
- /* we do some simple checks here if the edit fields are not empty or not longer than 8 characters, additionally we could
- also check if the values are really only numbers, but I skipped that because the input filter for the edit fileds
- was set to integer anyway (defined in Constructor) */
-
- if ((item1[0] < 1) || (item1[0] > 8))
- {
- /* if something was wrong in the input tell the BSNG App what edit field contained wrong values */
-
- inData->errorInItem = kEditItem1;
- error = true;
- }
- else if ((item2[0] < 1) || (item2[0] > 8))
- {
- inData->errorInItem = kEditItem2;
- error = true;
- }
-
- if (error)
- {
- inData->error = errExtIncorrectValue;
- return (false);
- }
-
- inData->error = errExtNoErr;
-
- return (true);
- } /* DoValidate */
-
-
- static void DoCalc(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
- StringPtr item6 = inData->itemValue[kItemValue6];
- StringPtr item7 = inData->itemValue[kItemValue7];
- StringPtr item8 = inData->itemValue[kItemValue8];
- StringPtr item9 = inData->itemValue[kItemValue9];
- StringPtr item10 = inData->itemValue[kItemValue10];
-
-
- /* do your calculations here */
-
- ZeroScrap();
- /*
- PutScrap(result, 'TEXT', &(result[1]));
- */
- } /* DoCalc */
-
-
- static void DoRandomCalc(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
- StringPtr item6 = inData->itemValue[kItemValue6];
- StringPtr item7 = inData->itemValue[kItemValue7];
- StringPtr item8 = inData->itemValue[kItemValue8];
- StringPtr item9 = inData->itemValue[kItemValue9];
- StringPtr item10 = inData->itemValue[kItemValue10];
-
-
- /* prepare random calculations here */
-
- DoCalc(inData);
- } /* DoRandomCalc */
-
-
- static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
- StringPtr item6 = inData->itemValue[kItemValue6];
- StringPtr item7 = inData->itemValue[kItemValue7];
- StringPtr item8 = inData->itemValue[kItemValue8];
- StringPtr item9 = inData->itemValue[kItemValue9];
- StringPtr item10 = inData->itemValue[kItemValue10];
-
- long count = 0L;
- short i = 0;
- OSErr err = noErr;
-
-
- /* write your header to the number list */
-
- count = 24L;
- err = FSWrite(inData->outputRefNum, &count, "<Your plugin name here>\r");
-
- /* return false if an error occured, the creation of list will then be completly aborted */
-
- if (err != noErr)
- {
- return (false);
- }
-
- count = 24L;
- err = FSWrite(inData->outputRefNum, &count, "=======================\r");
-
- if (err != noErr)
- {
- return (false);
- }
-
- /* create numOfListNumbers random serial numbers and write them to the list */
- /* if you create a name-based generator please make sure that you create at least one number */
- /* using the name, company and/or numCopies informations. You could create more name-based numbers */
- /* by using your own name/company database */
-
- for (i = 0; i < inData->numOfListNumbers; i++)
- {
- DoRandomCalc(inData);
-
- /* write results to list here */
- }
-
- /* don't forget this last newline */
-
- count = 1L;
- err = FSWrite(inData->outputRefNum, &count, "\r");
-
- if (err != noErr)
- {
- return (false);
- }
-
- return (true);
- } /* DoAddRandomsToList */
-
-
- static void DoItemHit(BSNGParamBlockPtr inData)
- {
- switch (inData->itemMessage)
- {
- case (300000):
-
- /* the "About this plugin" button was pressed, do whatever you want, I just display a small Alert here */
-
- NoteAlert(1000, nil);
- break;
-
- default:
- break;
- }
- } /* DoItemHit */
-
-
- static void DoCleanup(BSNGParamBlockPtr inData)
- {
- #pragma unused (inData)
-
- /* we didn't allocate any memory in DoInit, so we can leave this empty, otherwise it would be a VERY good idea
- to deallocate/dispose etc. everything we allocated during our work. If you don't do that we have a nice memory leak */
-
- } /* DoCleanup */
-
-
- void main(BSNGParamBlockPtr inData)
- {
- #if (!GENERATINGPOWERPC)
- EnterCodeResource();
- #endif
-
- /* the message dispatcher */
-
- switch(inData->theMessage)
- {
- case (msgExtInit):
- DoInit(inData);
- break;
-
- case (msgExtCalcHit):
-
- if (DoValidate(inData))
- {
- DoCalc(inData);
- }
-
- break;
-
- case (msgExtRandomHit):
- DoRandomCalc(inData);
- break;
-
- case (msgExtCreateRandom):
-
- /* report to the BSNG App if your list entry was written ok or if we had an error */
-
- if (DoAddRandomsToList(inData))
- {
- inData->error = errExtNoErr;
- }
- else
- {
- inData->error = errExtWritingToList;
- }
-
- break;
-
- case (msgExtItemHit):
- DoItemHit(inData);
- break;
-
- case (msgExtCleanup):
- DoCleanup(inData);
- break;
-
- default:
- break;
- }
-
- #if (!GENERATINGPOWERPC)
- ExitCodeResource();
- #endif
- } /* main */
-