home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / AppleScript / Additions / Wild 1.0.1 / project / C sources / parm.c < prev    next >
Encoding:
Text File  |  1994-05-09  |  20.5 KB  |  716 lines  |  [TEXT/KAHL]

  1. //    parm.c        process parameters of wildcard AppleScript extension
  2. //
  3. //    93/11/17    File created
  4. //    93/12/08    *** released Wild 0.1.0 ***
  5. //    93/12/09    moved common files to the THINK C Folder
  6. //    94/01/24    removed the licensing mechanism with NO_LICENCE
  7. //    94/01/24    *** released Wild 1.0.0 ***
  8. //    94/05/09    Totally removed the licensing mechanism and added the GNU comments
  9. //
  10. //--------------------------------------------------------------------------------------------------
  11. //  Copyright © 1993, 1994 by Rainbow Hill Pty Ltd.
  12. //
  13. //    This program is free software; you can redistribute it and/or modify it under the terms of
  14. //    the GNU General Public License as published by the Free Software Foundation; either version 2
  15. //    of the License, or any later version.
  16. //
  17. //    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  18. //    without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. //    See the GNU General Public License for more details.
  20. //
  21. //    You should have received a copy of the GNU General Public License along with this program;
  22. //    if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. //
  24.  
  25. //---------------------------- Apple includes
  26. #include <AppleEvents.h>
  27. #include <Errors.h>
  28. #include <Folders.h>
  29.  
  30. //---------------------------- C includes
  31. #include <string.h>
  32.  
  33. //---------------------------- other includes
  34. #include "wild.h"
  35. #include "parm.h"
  36.  
  37. //---------------------------- constant definitions
  38. #define DUMMY_ERROR_STRING    0
  39.  
  40. //---------------------------- type definitions
  41.  
  42. // structure to pass parameters to/from local functions
  43. struct args_struct {
  44.     AppleEvent    *event;            // --> AE
  45.     short        parNameCode;    // --> string number in the parameter names STR# resource
  46.     AEKeyword    parID;            // --> parameter ID specified in the 'aete' resource
  47.     Ptr            result;            // <-- value of the parameter
  48.     Boolean        *doFlag;        // <-- value of the enable flag (when the parm itself is not a flag)
  49.     char        *errMess;        // <-- error message
  50.     };
  51. typedef struct args_struct args_t;
  52.  
  53. //---------------------------- function prototypes
  54.  
  55. // doDialog accepts input parameters from the user
  56. static OSErr doDialog(wild_parm_t *, char *);    // parms, errMess
  57.  
  58. // fillDialog fills in the dialog with the parameter values
  59. static void fillDialog(Handle *, wild_parm_t *);
  60.  
  61. // getFlag extracts a Boolean from the AE
  62. // it assumes that value is initialised to its default before executing the function
  63. static OSErr getFlag(args_t *);
  64.  
  65. // getOneChar extracts the first character of a string from the AE
  66. // it assumes that value and doFlag are initialised to their defaults before executing the function
  67. static OSErr getOneChar(args_t *);
  68.  
  69. // getOSType extracts up to four characters from the AE
  70. // the enabling flag always defaults to false
  71. // the parameter itself has no default
  72. static OSErr getOSType(args_t *);
  73.  
  74. // getString extracts a string from the AE
  75. // it ignores the enabling flag and returns the empty string as default
  76. static OSErr getString(args_t *);
  77.  
  78. // setError sets up an error string
  79. static void setError(
  80.                     char *,            // <-- here it returns the error string
  81.                     short,            // --> string number in the parameter names STR# resource
  82.                     short            // --> string number in the error messages STR# resource
  83.                     );
  84.  
  85. //*************************************************************************************** parm_get
  86. OSErr parm_get(
  87.                 AppleEvent        *event,        // --> AE to process
  88.                 wild_parm_t        *parms,        // <-- parms
  89.                 char            *errMess    // <-- error message
  90.                 ) {
  91.  
  92.     OSErr            retVal;
  93.     args_t            args;
  94.     unsigned char    pStr[WILD_nameLength];
  95.  
  96.     // initialise arguments common to all functions
  97.     args.event = event;
  98.     args.errMess = errMess;
  99.  
  100.     // attempt to retrieve the long wildcard
  101.     parms->doLong = WILD_doLongDef;
  102.     parms->longW = WILD_longDef;
  103.     args.parNameCode = WILD_longName;
  104.     args.parID = WILD_kAElong;
  105.     args.result = (Ptr)&parms->longW;
  106.     args.doFlag = &parms->doLong;
  107.     retVal = getOneChar(&args);
  108.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  109.     if (parms->longW == ':') {
  110.         retVal = bdNamErr;
  111.         setError(errMess, WILD_longName, WILD_badWildErrStr);
  112.         goto DONE_LBL;                                                                    // --->
  113.         }
  114.  
  115.     // attempt to retrieve the short wildcard
  116.     parms->doShort = WILD_doShortDef;
  117.     parms->shortW = WILD_shortDef;
  118.     args.parNameCode = WILD_shortName;
  119.     args.parID = WILD_kAEshort;
  120.     args.result = (Ptr)&parms->shortW;
  121.     args.doFlag = &parms->doShort;
  122.     retVal = getOneChar(&args);
  123.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  124.     if (parms->shortW == ':') {
  125.         retVal = bdNamErr;
  126.         setError(errMess, WILD_shortName, WILD_badWildErrStr);
  127.         goto DONE_LBL;                                                                    // --->
  128.         }
  129.  
  130.     // attempt to retrieve the creator
  131.     args.parNameCode = WILD_creatorName;
  132.     args.parID = WILD_kAEcreator;
  133.     args.result = (Ptr)&parms->creator;
  134.     args.doFlag = &parms->doCreator;
  135.     retVal = getOSType(&args);
  136.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  137.  
  138.     // attempt to retrieve the file type
  139.     args.parNameCode = WILD_typeName;
  140.     args.parID = WILD_kAEtype;
  141.     args.result = (Ptr)&parms->type;
  142.     args.doFlag = &parms->doType;
  143.     retVal = getOSType(&args);
  144.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  145.  
  146.     // attempt to retrieve the files flag
  147.     parms->files = WILD_filesDef;
  148.     args.parNameCode = WILD_filesName;
  149.     args.parID = WILD_kAEfiles;
  150.     args.result = (Ptr)&parms->files;
  151.     retVal = getFlag(&args);
  152.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  153.  
  154.     // attempt to retrieve the folders flag
  155.     parms->folders = WILD_foldersDef;
  156.     args.parNameCode = WILD_foldersName;
  157.     args.parID = WILD_kAEfolders;
  158.     args.result = (Ptr)&parms->folders;
  159.     retVal = getFlag(&args);
  160.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  161.  
  162.     // attempt to retrieve the case sensitive flag
  163.     parms->caseS = WILD_caseDef;
  164.     args.parNameCode = WILD_caseName;
  165.     args.parID = WILD_kAEcase;
  166.     args.result = (Ptr)&parms->caseS;
  167.     retVal = getFlag(&args);
  168.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  169.  
  170.     // attempt to retrieve the selection string
  171.     args.parNameCode = WILD_onlyName;
  172.     args.parID = WILD_kAEonly;
  173.     args.result = (Ptr)parms->only;
  174.     retVal = getString(&args);
  175.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  176.  
  177.     // attempt to retrieve the dialog flag
  178.     parms->doDialog = WILD_dialogDef;
  179.     args.parNameCode = WILD_dlogName;
  180.     args.parID = WILD_kAEdialog;
  181.     args.result = (Ptr)&parms->doDialog;
  182.     retVal = getFlag(&args);
  183.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  184.  
  185.     if (parms->doDialog) retVal = doDialog(parms, errMess);
  186.     if (retVal != noErr) goto DONE_LBL;                                                    // --->
  187.  
  188.     // when not case sensitive, convert wildcards, creator, file type, and selection to upper case
  189.     if (parms->caseS == false) {
  190.         pStr[0] = 1;
  191.         if (parms->doLong) {
  192.             pStr[1] = parms->longW;
  193.             UprString(pStr, true);
  194.             parms->longW = pStr[1];
  195.             }
  196.         if (parms->doShort) {
  197.             pStr[1] = parms->shortW;
  198.             UprString(pStr, true);
  199.             parms->shortW = pStr[1];
  200.             }
  201.  
  202.         pStr[0] = 4;
  203.         if (parms->doCreator) {
  204.             memcpy((void *)&pStr[1], (const void *)&parms->creator, 4);
  205.             UprString(pStr, true);
  206.             memcpy((void *)&parms->creator, (const void *)&pStr[1], 4);
  207.             }
  208.         if (parms->doType) {
  209.             memcpy((void *)&pStr[1], (const void *)&parms->type, 4);
  210.             UprString(pStr, true);
  211.             memcpy((void *)&parms->type, (const void *)&pStr[1], 4);
  212.             }
  213.  
  214.         if (parms->only[0] != '\0') {
  215.             pStr[0] = strlen(parms->only);
  216.             memcpy((void *)&pStr[1], (const void *)parms->only, (Size)pStr[0]);
  217.             UprString(pStr, true);
  218.             memcpy((void *)parms->only, (const void *)&pStr[1], (Size)pStr[0]);
  219.             }
  220.         }
  221.  
  222. DONE_LBL:
  223.  
  224.     return (retVal);
  225.     } // parm_get
  226.  
  227.  
  228. //--------------------------------------------------------------------------------------- doDialog
  229. static OSErr doDialog(wild_parm_t *parms, char *errMess) {
  230.  
  231.     OSErr            retVal;
  232.     DialogPtr        dlogPtr;
  233.     short            dlogItemNo;
  234.     short            dlogItemType;
  235.     Rect            dlogItemBox;
  236.     char            dlogStr[256];
  237.     Handle            dlogItemHdl[WILD_dlogItemArraySize];
  238.     short            kItem;
  239.     wild_parm_t        tempParms;
  240.     short            k;
  241.     short            j;
  242.  
  243.     retVal = noErr;
  244.  
  245.     // display the dialog with the current values
  246.     dlogPtr = GetNewDialog(WILD_dlogRsrc, nil, (Ptr)-1L);
  247.  
  248.     // get all the item handles to speed up the dialog handling
  249.     for (kItem = 1; kItem <= WILD_dlogItemArraySize; kItem++) {
  250.         GetDItem(dlogPtr, kItem, &dlogItemType, &dlogItemHdl[kItem], &dlogItemBox);
  251.         }
  252.  
  253.     // fill in the dialog with the original values
  254.     fillDialog(dlogItemHdl, parms);
  255.  
  256.     // highlight
  257.     SelIText(dlogPtr, WILD_dlogOnlyNo, 0, 32767);
  258.  
  259.     // keep updating the values until the user is satisfied or gives up
  260.     do {
  261.         ModalDialog(nil, &dlogItemNo);
  262.  
  263.         switch (dlogItemNo) {
  264.  
  265.             case WILD_dlogRestoreNo:
  266.                 fillDialog(dlogItemHdl, parms);
  267.                 break;
  268.  
  269.             case WILD_dlogDefaultNo:
  270.                 tempParms.files = WILD_filesDef;
  271.                 tempParms.folders = WILD_foldersDef;
  272.                 tempParms.caseS = WILD_caseDef;
  273.                 tempParms.doLong = WILD_doLongDef;
  274.                 tempParms.doShort = WILD_doShortDef;
  275.                 tempParms.doCreator = false;
  276.                 tempParms.doType = false;
  277.                 tempParms.longW = WILD_longDef;
  278.                 tempParms.shortW = WILD_shortDef;
  279.                 tempParms.only[0] = '\0';
  280.                 fillDialog(dlogItemHdl, &tempParms);
  281.                 break;
  282.  
  283.             case WILD_dlogDoCreatorNo:
  284.             case WILD_dlogDoTypeNo:
  285.             case WILD_dlogDoLongNo:
  286.             case WILD_dlogDoShortNo:
  287.             case WILD_dlogFilesNo:
  288.             case WILD_dlogFoldersNo:
  289.             case WILD_dlogCaseNo:
  290.                 SetCtlValue(
  291.                             (ControlHandle)dlogItemHdl[dlogItemNo],
  292.                             1 - GetCtlValue((ControlHandle)dlogItemHdl[dlogItemNo])
  293.                             );
  294.                 break;
  295.  
  296.             case WILD_dlogCreatorNo:
  297.             case WILD_dlogTypeNo:
  298.                 GetIText(dlogItemHdl[dlogItemNo], dlogStr);
  299.                 if (dlogStr[0] > 4) {
  300.                     dlogStr[0] = 4;
  301.                     SetIText(dlogItemHdl[dlogItemNo], dlogStr);
  302.                     }
  303.                 break;
  304.  
  305.             case WILD_dlogLongNo:
  306.             case WILD_dlogShortNo:
  307.                 GetIText(dlogItemHdl[dlogItemNo], dlogStr);
  308.                 if (dlogStr[0] > 1) {
  309.                     dlogStr[0] = 1;
  310.                     SetIText(dlogItemHdl[dlogItemNo], dlogStr);
  311.                     }
  312.                 break;
  313.  
  314.             case WILD_dlogCopyrightNo:
  315.             case WILD_dlogIconNo:
  316.             case WILD_dlogOkNo:
  317.             case WILD_dlogStopNo:
  318.             case WILD_dlogOnlyNo:
  319.             case WILD_dlogOnlyNameNo:
  320.             default:
  321.                 break;
  322.             }
  323.         } while (dlogItemNo != WILD_dlogOkNo && dlogItemNo != WILD_dlogStopNo);
  324.  
  325.     // decide whether to abort the whole operation or to return the new setting
  326.     if (dlogItemNo == WILD_dlogStopNo) {
  327.         retVal = userCanceledErr;
  328.         }
  329.     else {
  330.         retVal = noErr;
  331.  
  332.         // copy the flags from the dialog to the parameter structure ...
  333.         parms->doCreator = GetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoCreatorNo]);
  334.         parms->doType = GetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoTypeNo]);
  335.         parms->doLong = GetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoLongNo]);
  336.         parms->doShort = GetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoShortNo]);
  337.         parms->files = GetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogFilesNo]);
  338.         parms->folders = GetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogFoldersNo]);
  339.         parms->caseS = GetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogCaseNo]);
  340.  
  341.         // ... the creator ...
  342.         GetIText(dlogItemHdl[WILD_dlogCreatorNo], dlogStr);
  343.         k = dlogStr[0];
  344.         for (j = 0; j < k; j++) dlogStr[j] = dlogStr[j + 1];    // move to word boundary
  345.         for (; j < 4; j++) dlogStr[j] = WILD_defOSchar;
  346.         parms->creator = *(OSType *)dlogStr;
  347.  
  348.         // ... the file type ...
  349.         GetIText(dlogItemHdl[WILD_dlogTypeNo], dlogStr);
  350.         k = dlogStr[0];
  351.         for (j = 0; j < k; j++) dlogStr[j] = dlogStr[j + 1];    // move to word boundary
  352.         for (; j < 4; j++) dlogStr[j] = WILD_defOSchar;
  353.         parms->type = *(OSType *)dlogStr;
  354.  
  355.         // ... wildcard characters ...
  356.         GetIText(dlogItemHdl[WILD_dlogLongNo], dlogStr);
  357.         parms->longW = dlogStr[1];
  358.         GetIText(dlogItemHdl[WILD_dlogShortNo], dlogStr);
  359.         parms->shortW = dlogStr[1];
  360.  
  361.         // ... and the selection
  362.         GetIText(dlogItemHdl[WILD_dlogOnlyNo], dlogStr);
  363.         memcpy((void *)parms->only, (const void *)&dlogStr[1], (Size)dlogStr[0]);
  364.         parms->only[dlogStr[0]] = '\0';
  365.  
  366.         // check the consistency of the input
  367.         if (parms->doCreator == true  &&  parms->creator == 0L) {
  368.             retVal = errAEWrongDataType;
  369.             setError(errMess, WILD_creatorName, WILD_noStringErrStr);
  370.             }
  371.         if (parms->doType == true  &&  parms->type == 0L) {
  372.             retVal = errAEWrongDataType;
  373.             setError(errMess, WILD_typeName, WILD_noStringErrStr);
  374.             }
  375.         }
  376.  
  377.     // make the DITL resource purgeable and get rid of the whole dialog
  378.     DisposDialog(dlogPtr);
  379.  
  380. RETURN_LBL:
  381.  
  382.     return (retVal);
  383.     } // doDialog
  384.  
  385. //--------------------------------------------------------------------------------------- fillDialog
  386. static void fillDialog(Handle *dlogItemHdl, wild_parm_t *values) {
  387.     char    aChar;
  388.     char    pStr[WILD_nameLength];
  389.  
  390.     // update the simple flags of the dialog
  391.     SetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogFilesNo], values->files);
  392.     SetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogFoldersNo], values->folders);
  393.     SetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogCaseNo], values->caseS);
  394.  
  395.     // update the long wildcard of the dialog
  396.     SetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoLongNo], values->doLong);
  397.     if (values->doLong)
  398.         pStr[1] = values->longW;
  399.     else
  400.         pStr[1] = WILD_longDef;
  401.     pStr[0] = 1;
  402.     SetIText(dlogItemHdl[WILD_dlogLongNo], pStr);
  403.  
  404.     // update the short wildcard of the dialog
  405.     SetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoShortNo], values->doShort);
  406.     if (values->doShort)
  407.         aChar = values->shortW;
  408.     else
  409.         aChar = WILD_shortDef;
  410.     pStr[0] = 1;
  411.     pStr[1] = aChar;            // keep 'aChar' for creator and file type
  412.     SetIText(dlogItemHdl[WILD_dlogShortNo], pStr);
  413.  
  414.     // update the creator of the dialog
  415.     SetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoCreatorNo], values->doCreator);
  416.     if (values->doCreator) {
  417.         memcpy((void *)&pStr[1], (const void *)&values->creator, 4);
  418.         }
  419.     else {
  420.         pStr[1] = aChar;
  421.         pStr[2] = aChar;
  422.         pStr[3] = aChar;
  423.         pStr[4] = aChar;
  424.         }
  425.     pStr[0] = 4;
  426.     SetIText(dlogItemHdl[WILD_dlogCreatorNo], pStr);
  427.  
  428.     // update the file type of the dialog
  429.     SetCtlValue((ControlHandle)dlogItemHdl[WILD_dlogDoTypeNo], values->doType);
  430.     if (values->doType) {
  431.         memcpy((void *)&pStr[1], (const void *)&values->type, 4);
  432.         }
  433.     else {
  434.         pStr[1] = aChar;
  435.         pStr[2] = aChar;
  436.         pStr[3] = aChar;
  437.         pStr[4] = aChar;
  438.         }
  439.     pStr[0] = 4;
  440.     SetIText(dlogItemHdl[WILD_dlogTypeNo], pStr);
  441.  
  442.     // update the selection of the dialog
  443.     if (values->only[0] == '\0') {
  444.         pStr[0] = '\0';
  445.         }
  446.     else {
  447.         pStr[0] = strlen(values->only);
  448.         memcpy((void *)&pStr[1], (const void *)values->only, (Size)pStr[0]);
  449.         }
  450.     SetIText(dlogItemHdl[WILD_dlogOnlyNo], pStr);
  451.  
  452.     } // fillDialog
  453.  
  454. //--------------------------------------------------------------------------------------- getFlag
  455. static OSErr getFlag(args_t *args) {
  456.     OSErr            retVal;
  457.     DescType        typeCode;
  458.     Size            actualSize;
  459.     OSType            fourBytes;
  460.  
  461.     retVal = AEGetParamPtr(
  462.                         args->event,
  463.                         args->parID,
  464.                         typeWildCard,
  465.                         &typeCode,
  466.                         (Ptr)&fourBytes,
  467.                         (Size)4,
  468.                         &actualSize
  469.                         );
  470.     if (retVal == noErr) {
  471.         if (typeCode == typeTrue) {
  472.             *(Boolean *)args->result = true;
  473.             }
  474.         else if (typeCode == typeFalse) {
  475.             *(Boolean *)args->result = false;
  476.             }
  477.         else {
  478.             retVal = errAEWrongDataType;
  479.             setError(args->errMess, args->parNameCode, WILD_wrongDataErrStr);
  480.             goto DONE_LBL;                                                                // --->
  481.             }
  482.         }
  483.     else if (retVal == errAEDescNotFound) {
  484.  
  485.         // keep the default
  486.         retVal = noErr;
  487.         }
  488.     else {
  489.  
  490.         // there was a problem
  491.         setError(args->errMess, args->parNameCode, DUMMY_ERROR_STRING);
  492.         goto DONE_LBL;                                                                    // --->
  493.         }
  494.  
  495. DONE_LBL:
  496.  
  497.     return (retVal);
  498.     } // getFlag
  499.  
  500. //--------------------------------------------------------------------------------------- getOneChar
  501. static OSErr getOneChar(args_t *args) {
  502.     OSErr            retVal;
  503.     DescType        typeCode;
  504.     Size            actualSize;
  505.     char            aChar;
  506.  
  507.     retVal = AEGetParamPtr(
  508.                         args->event,
  509.                         args->parID,
  510.                         typeWildCard,
  511.                         &typeCode,
  512.                         (Ptr)&aChar,
  513.                         (Size)1,
  514.                         &actualSize
  515.                         );
  516.     if (retVal == noErr) {
  517.         if (actualSize == 0) {
  518.             if (typeCode == typeTrue) {
  519.  
  520.                 // enable the default wildcarding character
  521.                 *args->doFlag = true;
  522.                 }
  523.             else if (typeCode == typeFalse) {
  524.                 *args->doFlag = false;
  525.                 }
  526.             else {
  527.                 retVal = errAEWrongDataType;
  528.                 setError(args->errMess, args->parNameCode, WILD_wrongDataErrStr);
  529.                 goto DONE_LBL;                                                            // --->
  530.                 }
  531.             }
  532.         else if (typeCode != typeChar && typeCode != typeStyledText && typeCode != typeIntlText) {        
  533.             retVal = errAEWrongDataType;
  534.             setError(args->errMess, args->parNameCode, WILD_wrongDataErrStr);
  535.             goto DONE_LBL;                                                                // --->
  536.             }
  537.         else {
  538.  
  539.             // the user typed the parameter name followed by a value
  540.             *args->doFlag = true;
  541.             *(char *)args->result = aChar;
  542.             }
  543.         }
  544.     else if (retVal == errAEDescNotFound) {
  545.  
  546.         // keep the default
  547.         retVal = noErr;
  548.         }
  549.     else {
  550.  
  551.         // there was a problem
  552.         setError(args->errMess, args->parNameCode, DUMMY_ERROR_STRING);
  553.         goto DONE_LBL;                                                                    // --->
  554.         }
  555.  
  556. DONE_LBL:
  557.  
  558.     return (retVal);
  559.     } // getOneChar
  560.  
  561. //--------------------------------------------------------------------------------------- getOSType
  562. static OSErr getOSType(args_t *args) {
  563.     OSErr            retVal;
  564.     DescType        typeCode;
  565.     Size            actualSize;
  566.     OSType            fourBytes;
  567.  
  568.     retVal = AEGetParamPtr(
  569.                         args->event,
  570.                         args->parID,
  571.                         typeWildCard,
  572.                         &typeCode,
  573.                         (Ptr)&fourBytes,
  574.                         (Size)4,
  575.                         &actualSize
  576.                         );
  577.     if (retVal == noErr) {
  578.         if (actualSize == 0) {
  579.             if (typeCode == typeTrue) {
  580.  
  581.                 // the user typed 'with ...'
  582.                 retVal = errAEWrongDataType;
  583.                 setError(args->errMess, args->parNameCode, WILD_noStringErrStr);
  584.                 goto DONE_LBL;                                                            // --->
  585.                 }
  586.             else if (typeCode == typeFalse) {
  587.                 *args->doFlag = false;
  588.                 }
  589.             else {
  590.                 retVal = errAEWrongDataType;
  591.                 setError(args->errMess, args->parNameCode, WILD_wrongDataErrStr);
  592.                 goto DONE_LBL;                                                            // --->
  593.                 }
  594.             }
  595.         else if (typeCode != typeChar && typeCode != typeStyledText && typeCode != typeIntlText) {        
  596.             retVal = errAEWrongDataType;
  597.             setError(args->errMess, args->parNameCode, WILD_wrongDataErrStr);
  598.             goto DONE_LBL;                                                                // --->
  599.             }
  600.         else {
  601.  
  602.             // the user typed: creator "..."
  603.             *args->doFlag = true;
  604.             *(OSType *)args->result = fourBytes;
  605.             while (actualSize < 4) ((char *)args->result)[actualSize++] = WILD_defOSchar;
  606.             }
  607.         }
  608.     else if (retVal == errAEDescNotFound) {
  609.  
  610.         // set the default which is always false
  611.         retVal = noErr;
  612.         *args->doFlag = false;
  613.         }
  614.     else {
  615.  
  616.         // there was a problem
  617.         setError(args->errMess, args->parNameCode, DUMMY_ERROR_STRING);
  618.         goto DONE_LBL;                                                                    // --->
  619.         }
  620.  
  621. DONE_LBL:
  622.  
  623.     return (retVal);
  624.     } // getOSType
  625.  
  626. //--------------------------------------------------------------------------------------- getString
  627. static OSErr getString(args_t *args) {
  628.     OSErr            retVal;
  629.     DescType        typeCode;
  630.     Size            actualSize;
  631.     char            aChar;
  632.  
  633.     retVal = AEGetParamPtr(
  634.                         args->event,
  635.                         args->parID,
  636.                         typeWildCard,
  637.                         &typeCode,
  638.                         args->result,
  639.                         (Size)WILD_maxFilenameLen,
  640.                         &actualSize
  641.                         );
  642.     if (retVal == noErr) {
  643.  
  644.         // we only accept two possibilities:
  645.         //        1.    we actually read something and it is of a text type (the user typed "par string")
  646.         //                then we terminate the result with a '\0'
  647.         //        2.    we read nothing but the type is typeFalse (the user typed "without par")
  648.         //                then we are done, because the result was set to '\0' at the beginning
  649.         if (
  650.                     actualSize != 0
  651.                     &&
  652.                     (typeCode == typeChar || typeCode == typeStyledText || typeCode == typeIntlText)
  653.                 ) {
  654.  
  655.             // the user typed the parameter name followed by a value
  656.             args->result[actualSize] = '\0';
  657.             }
  658.         else {
  659.  
  660.             args->result[0] = '\0';
  661.  
  662.             if (actualSize != 0  ||  typeCode != typeFalse) {
  663.  
  664.                 // the user typed something that we cannot accept
  665.                 retVal = errAEWrongDataType;
  666.                 setError(args->errMess, args->parNameCode, WILD_wrongDataErrStr);
  667.                 goto DONE_LBL;                                                            // --->
  668.                 }
  669.             } // either actualSize was zero or the parameter was not of a text type
  670.         } // we successfully got a parameter
  671.     else {
  672.  
  673.         args->result[0] = '\0';
  674.  
  675.         if (retVal == errAEDescNotFound) {
  676.  
  677.             // we did not get a parameter at all
  678.             retVal = noErr;
  679.             }
  680.         else {
  681.  
  682.             // there was a problem
  683.             setError(args->errMess, args->parNameCode, DUMMY_ERROR_STRING);
  684.             goto DONE_LBL;                                                                // --->
  685.             }
  686.         } // we didn't get a parameter successfully
  687.  
  688. DONE_LBL:
  689.  
  690.     return (retVal);
  691.     } // getString
  692.  
  693. //--------------------------------------------------------------------------------------- setError
  694. static void setError(
  695.                     char    *where,            // <-- here it returns the error string
  696.                     short    kPar,            // --> string number in the parameter names STR# resource
  697.                     short    kMess            // --> string number in the error messages STR# resource
  698.                     ) {
  699.     short    k;
  700.     char    es[256];
  701.  
  702.     GetIndString(es, WILD_parmNamesRsrc, kPar);
  703.     k = es[0];
  704.     strncpy(where, (const char *)&es[1], (Size)k);
  705.     if (kMess == DUMMY_ERROR_STRING) {
  706.         where[k] = '\0';
  707.         }
  708.     else {
  709.         where[k++] = ':';
  710.         where[k++] = ' ';
  711.         GetIndString(es, WILD_errMessRsrc, kMess);
  712.         strncpy(&where[k], (const char *)&es[1], (Size)es[0]);
  713.         where[k + es[0]] = '\0';
  714.         }
  715.     } // setError
  716.