/* If null is passed then we return the base function, otherwise we return the named subfuction or NULL if we can't find it. Also we store a pointer to the current function name string or set that pointer to NULL if we are returning the project base function. */ PsychFunctionPtr PsychGetProjectFunction(char *command) { int i; //return the project base function if(command==NULL){ currentFunctionNameREGISTER = NULL; return(baseFunctionREGISTER); } // See if help is being requested if (command[strlen(command)-1] == '?') { PsychSetGiveHelp(); command[strlen(command)-1]=0; }else PsychClearGiveHelp(); //lookup the function in the table for(i=0;i<numFunctionsREGISTER;i++){ if(PsychMatch(functionTableREGISTER[i].name, command)){ currentFunctionNameREGISTER = functionTableREGISTER[i].name; return(functionTableREGISTER[i].function); } } // Unknown command. return NULL; }
/* This function is called by the special subfunction 'DescribeModuleFunctionsHelper'. * It returns the full table of registered subfunction names as an array. * Useful for automatic documentation generators... * */ PsychError PsychDescribeModuleFunctions(void) { static char useString[] = "subfunctionNames = Modulename('DescribeModuleFunctionsHelper' [, mode] [, subfunctionName]);"; static char synopsisString[] = "Return a cell array of strings naming all subfunctions supported by this module if " "the optional 'subfunctionName' argument is omitted. If 'subfunctionName' is a " "string with a valid subfunction name for the module, and 'mode' is 1, return a 3 element cell " "array of strings which describe the detailed syntax, help and see also strings " "for that function - the text you'd get for Modulename('subfunctionName?'); "; static char seeAlsoString[] = ""; char* subfname; int i; PsychGenericScriptType *cellVector; PsychFunctionPtr fcn; //all subfunctions should have these two lines. PsychPushHelp(useString, synopsisString, seeAlsoString); if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}; // Check for valid number of arguments PsychErrorExit(PsychCapNumInputArgs(2)); PsychErrorExit(PsychCapNumOutputArgs(1)); PsychCopyInIntegerArg(1, FALSE, &i); subfname = NULL; PsychAllocInCharArg(2, FALSE, &subfname); if (subfname) { // Find named subfunction in functin table: fcn = PsychGetProjectFunction(subfname); if (fcn) { // This will trigger the subfunction 'fcn' to execute its PsychGiveHelp() method, then // return. PsychGiveHelp() will return the help text to Runtime as cell array of strings, // instead of printing to runtimes console: PsychSetGiveHelp(); PsychOneShotReturnHelp(); (*fcn)(); PsychClearGiveHelp(); } } else { // Generate a cell array to return PsychAllocOutCellVector(1, FALSE, numFunctionsREGISTER, &cellVector); for(i=0; i < numFunctionsREGISTER; i++) PsychSetCellVectorStringElement(i, functionTableREGISTER[i].name, cellVector); } return(PsychError_none); }