コード例 #1
0
PsychError MODULEVersion(void) 
{
	int i;
	PsychAuthorDescriptorType   *author;
    const char *versionFieldNames[]={"version", "major", "minor", "point", "build", "date", "time", "module", "project", "os", "language", "authors"};
    const char *authorFiledNames[]={"first", "middle", "last", "initials", "email", "url"};
    char 	*versionString;
    int		buildNumber;
    int 	numVersionFieldDimensions=1, numVersionFieldNames=12, numAuthorFieldNames=6, numAuthors;
    PsychGenericScriptType	*versionStructArray, *authorStructArray;
    //we ignore the usual usage help strings and create our own based on the module name. MODULEVersion() is for use by any Psychtoolbox module. 
    char useString[256], synopsisString[256], *moduleName;
    char useStringP1[]="struct=";
    char useStringP2[]="('Version')";
    char synopsisStringP1[]="return the version of ";
    char synopsisStringP2[]=" in a struct";
    
    
    //for generic usage we modifiy at runtiome the help string to replace "Screen" with the name of this module.
    moduleName=PsychGetModuleName();
    useString[0]='\0';
    strcat(useString, useStringP1);
    strcat(useString, moduleName);
    strcat(useString, useStringP2);
    synopsisString[0]='\0';
    strcat(synopsisString, synopsisStringP1);
    strcat(synopsisString, moduleName);
    strcat(synopsisString, synopsisStringP2);
   
    PsychPushHelp(useString, synopsisString, seeAlsoString);
    if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};

    //check to see if the user supplied superfluous arguments
    PsychErrorExit(PsychCapNumOutputArgs(1));
    PsychErrorExit(PsychCapNumInputArgs(0));
    
    //get the build and version string
    buildNumber=PsychGetBuildNumber();
    versionString=PsychGetVersionString();

    //create a structure and populate it.
    PsychAllocOutStructArray(1, FALSE, numVersionFieldDimensions, numVersionFieldNames, versionFieldNames, &versionStructArray);
    PsychSetStructArrayStringElement("version", 0, versionString, versionStructArray);
    PsychSetStructArrayDoubleElement("major", 0, (double)PsychGetMajorVersionNumber(), versionStructArray);
    PsychSetStructArrayDoubleElement("minor", 0, (double)PsychGetMinorVersionNumber(), versionStructArray);
    PsychSetStructArrayDoubleElement("point", 0, (double)PsychGetPointVersionNumber(), versionStructArray);
    PsychSetStructArrayDoubleElement("build", 0, buildNumber, versionStructArray);
    PsychSetStructArrayStringElement("date", 0, PsychGetBuildDate(), versionStructArray);
    PsychSetStructArrayStringElement("time", 0, PsychGetBuildTime(), versionStructArray);
    PsychSetStructArrayStringElement("module", 0, moduleName, versionStructArray);
    PsychSetStructArrayStringElement("project", 0, PSYCHTOOLBOX_PROJECT_NAME, versionStructArray);
    PsychSetStructArrayStringElement("os", 0, PSYCHTOOLBOX_OS_NAME, versionStructArray);
    PsychSetStructArrayStringElement("language", 0, PSYCHTOOLBOX_SCRIPTING_LANGUAGE_NAME, versionStructArray);

	numAuthors=PsychGetNumModuleAuthors();
    PsychAllocOutStructArray(-1, FALSE, numAuthors, numAuthorFieldNames, authorFiledNames, &authorStructArray);
	for(i=0;i<numAuthors;i++){
		GetModuleAuthorDescriptorFromIndex(i, &author);
		PsychSetStructArrayStringElement("first", i, author->firstName, authorStructArray);
		PsychSetStructArrayStringElement("middle", i, author->middleName, authorStructArray);
		PsychSetStructArrayStringElement("last", i, author->lastName, authorStructArray);
		PsychSetStructArrayStringElement("initials", i, author->initials, authorStructArray);
		PsychSetStructArrayStringElement("email", i, author->email, authorStructArray);
		PsychSetStructArrayStringElement("url", i, author->url, authorStructArray);
	}
    PsychSetStructArrayStructElement("authors",0, authorStructArray, versionStructArray);

    return(PsychError_none);	
}
コード例 #2
0
/*
    If there is no error then just return().  If there is an error then
    print the function name which should have been pushed using PsychPushHelp.
    and also print the string describing the type of error and then return
    control to the scripting environment.

    extraErrorString can provide addional debugging info.

    TO DO:
    See "to do" list above.  This could be improved to print more specific error
    information, for example whith an invalid argument it could print which argument
    was invalid or which was missing.

    PsychErrorExitMsg should be renamed PsychErrorExitC and accept another argument which
    is the string naming the file or function where the error occurred. A macro named PsychErrorExitMsg
    should be provided which calls PsychErrorExitMsg and plugs in the ANSI predifined macros giving the
    file and function where the error occurred.  PsychErrorExitC only prints that if the error type
    is internal.

*/
void PsychErrorExitC(PsychError error,
                     const char *extraErrorString,
                     int lineNum,
                     const char *funcName,
                     const char *fileName)
{
    char *functionName;
    PsychArgDescriptorType *specified, *received;
    int i, numTypes;
    const char *typeStrings[PsychArgType_NUMTYPES];

    // This function must be implemented by the scripting glue and allows to
    // process the error in some frontend specific way, e.g., set exception
    // state, or simply ignore it:
    PsychProcessErrorInScripting(error, extraErrorString ? extraErrorString : errorStringsERROR[error]);

    //if the error is type none then just return
    if(error==PsychError_none)
        return;

    //if the error is an internal error then display copious info
    if(!usageErrorFlagsERROR[error]){
        printf("INTERNAL PSYCHTOOLBOX ERROR\n");
        printf("\terror:                %s\n",errorNameStringsERROR[error]);
        printf("\tgeneral description:  %s\n",errorStringsERROR[error]);
        if(extraErrorString != NULL)
            printf("\tspecific description: %s\n",extraErrorString);
        printf("\tmodule name:          %s\n",PsychGetModuleName());
        printf("\tsubfunction call:     %s\n",PsychGetFunctionName());
        printf("\tfile name:            %s\n",fileName);
        printf("\tfunction name:        %s\n",funcName);
        printf("\tline number:          %d\n",lineNum);
        PsychErrMsgTxt(NULL);  //exit the module
    }else{
        //if the error is usage error then
        functionName = PsychGetFunctionName();
        printf("Error in function %s: ",functionName);
        printf("\t%s\n",errorStringsERROR[error]);
        if(extraErrorString !=NULL)
            printf("%s\n",extraErrorString);
        //attempts to fetch or return arguments cache descriptions of the the desired
        //and returned values in static variables.  If attempts to set or retrieve an
        //argument resulted in an error value PsychError_invalidArg_*, then we can retrieve that info
        //about the specified and desired argument to generate a detailed error message.
        if(error == PsychError_invalidArg_absent || error == PsychError_invalidArg_extra || error == PsychError_invalidArg_type || error == PsychError_invalidArg_size){
            PsychGetArgDescriptor(&specified, &received);
            if(specified != NULL && received != NULL){  //why would these be null ?
                //for specified
                printf("\tDiscrepancy between a specified and supplied argument:\n");
                printf("\t\tSpecified Argument Description:\n");
                printf("\t\t\tdirection: %s\n", (specified->direction==PsychArgIn) ? "Input" : "Output");  //input  or output
                printf("\t\t\tposition: %d\n", specified->position);  //position
                printf("\t\t\tpresence:");
                switch(specified->isThere){
                    case kPsychArgAbsent: printf("forbidden");break;
                    case kPsychArgPresent: printf("required");break;
                    case kPsychArgFixed: printf("fixed");break;
                }
                printf("\n");

                printf("\t\t\tformats allowed:\n");
                numTypes=PsychDecomposeArgFormat(specified->type, typeStrings);
                for(i=0;i<numTypes;i++)
                    printf("\t\t\t\t%s\n",typeStrings[i]);

                printf("\t\t\tminimum M: %s\n", int2str(specified->mDimMin));
                printf("\t\t\tmaximum M: %s\n", (specified->mDimMax==kPsychUnboundedArraySize) ? "unbounded" : int2str(specified->mDimMax));
                printf("\t\t\tminimum N: %s\n", int2str(specified->nDimMin));
                printf("\t\t\tmaximum N: %s\n", (specified->nDimMax==kPsychUnboundedArraySize) ? "unbounded" : int2str(specified->nDimMax));
                printf("\t\t\tminimum P: %s\n", int2str(specified->pDimMin));
                printf("\t\t\tmaximum P: %s\n", (specified->pDimMax==kPsychUnboundedArraySize) ? "unbounded" : int2str(specified->pDimMax));

                //For received
                printf("\t\tProvided Argument Description:\n");
                printf("\t\t\tdirection: %s\n", (received->direction== PsychArgIn) ? "Input" : "Output");  //input  or output
                printf("\t\t\tposition: %d\n", received->position);  //position
                printf("\t\t\tpresence: ");
                switch(received->isThere){
                    case kPsychArgAbsent: printf("absent\n");break;
                    case kPsychArgPresent: printf("present\n");break;
                    case kPsychArgFixed: printf("fixed\n");break;
                }
                if(received->isThere!=kPsychArgAbsent && received->direction==PsychArgIn){
                    printf("\t\t\tformat:");

                    numTypes=PsychDecomposeArgFormat(received->type, typeStrings); //there should only be one, but check for bugs
                    for(i=0;i<numTypes;i++)
                        printf("%s\n",typeStrings[i]);
                    printf("\t\t\t number of dimensions: %d\n", received->numDims);
                    printf("\t\t\t\t M: %s\n", int2str(received->mDimMin));
                    printf("\t\t\t\t N: %s\n", int2str(received->nDimMin));
                    printf("\t\t\t\t P: %s\n", int2str(received->pDimMin));
                }
            }
        }
        PsychGiveUsageExit();
    }
}