[Tclresource-commits] Source tclResourceOSX.c,1.14,1.15
Status: Beta
Brought to you by:
bdesgraupes
From: Bernard D. <bde...@us...> - 2004-09-07 10:39:05
|
Update of /cvsroot/tclresource/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26852 Modified Files: tclResourceOSX.c Log Message: Modified error strings Index: tclResourceOSX.c =================================================================== RCS file: /cvsroot/tclresource/Source/tclResourceOSX.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- tclResourceOSX.c 6 Sep 2004 21:40:29 -0000 1.14 +++ tclResourceOSX.c 7 Sep 2004 10:38:48 -0000 1.15 @@ -1,7 +1,7 @@ /* * File : "tclResourceOSX.c" * Created : 2003-09-20 10:13:07 - * Last modification : 2003-10-24 19:37:30 + * Last modification : 2004-09-07 12:23:15 * Author: Bernard Desgraupes * e-mail: <bde...@ea...> * Note: @@ -185,8 +185,17 @@ Tcl_CreateObjCommand(interp, "resource", Tcl_ResourceObjCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); - sprintf(vstr,"%d.%d%c%d\0", TCLRESOURCE_MAJOR, TCLRESOURCE_MINOR, - TCLRESOURCE_STAGE, TCLRESOURCE_SUBMINOR); + // Version numbering + if (TCLRESOURCE_STAGE=='f') { + if (TCLRESOURCE_SUBMINOR) { + sprintf(vstr,"%d.%d.%d\0", TCLRESOURCE_MAJOR, TCLRESOURCE_MINOR, TCLRESOURCE_SUBMINOR); + } else { + sprintf(vstr,"%d.%d\0", TCLRESOURCE_MAJOR, TCLRESOURCE_MINOR); + } + } else { + sprintf(vstr,"%d.%d%c%d\0", TCLRESOURCE_MAJOR, TCLRESOURCE_MINOR, + TCLRESOURCE_STAGE, TCLRESOURCE_SUBMINOR); + } /* Declare the tclResource package. */ if (Tcl_PkgProvide(interp, "resource", vstr) != TCL_OK) { @@ -342,7 +351,7 @@ long theLong; short saveRef, theAttrs; char *resourceId = NULL; - char buffer[16]; + char buffer[128]; OpenResourceFork *resourceRef; Handle resource = NULL; OSErr err; @@ -443,10 +452,9 @@ } if ((resourceId == NULL) && !gotInt) { - Tcl_AppendStringsToObj(resultPtr,"you must specify either ", - "\"-id\" or \"-name\" to get the ", - "attributes of a specified resource", - (char *) NULL); + Tcl_AppendStringsToObj(resultPtr,"you must specify either ", + "-id or -name", + (char *) NULL); return TCL_ERROR; } @@ -466,10 +474,8 @@ result = TCL_ERROR; goto attributesDone; } else if (err != noErr) { - sprintf(buffer, "%12d", err); - Tcl_AppendStringsToObj(resultPtr, "resource error #", - buffer, "occured while trying to find resource", - (char *) NULL); + sprintf(buffer, "resource error %d while trying to find resource", err); + Tcl_AppendStringsToObj(resultPtr, buffer, (char *) NULL); result = TCL_ERROR; goto attributesDone; } @@ -489,10 +495,8 @@ result = TCL_ERROR; goto attributesDone; } else if (err != noErr) { - sprintf(buffer, "%12d", err); - Tcl_AppendStringsToObj(resultPtr, "resource error #", - buffer, "occured while trying to find resource", - (char *) NULL); + sprintf(buffer, "resource error %d while trying to find resource", err); + Tcl_AppendStringsToObj(resultPtr, buffer, (char *) NULL); result = TCL_ERROR; goto attributesDone; } @@ -532,10 +536,8 @@ SetResAttrs(resource, newValue); err = ResError(); if (err != noErr) { - sprintf(buffer, "%12d", err); - Tcl_AppendStringsToObj(resultPtr, - "error ", buffer, " setting resource attributes", - (char *) NULL); + sprintf(buffer, "error %d setting resource attributes", err); + Tcl_AppendStringsToObj(resultPtr, buffer, (char *) NULL); result = TCL_ERROR; goto attributesDone; } @@ -593,6 +595,8 @@ int length; short fileRef; char *stringPtr; + OSErr err; + int result = TCL_OK; if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "resourceRef"); @@ -602,11 +606,16 @@ fileRef = TclMacUnRegisterResourceFork(stringPtr, resultPtr); if (fileRef >= 0) { - CloseResFile(fileRef); - return TCL_OK; - } else { - return TCL_ERROR; + CloseResFile(fileRef); + err = ResError(); + if (err != noErr) { + Tcl_AppendStringsToObj(resultPtr, "couldn't close the resource fork", (char *) NULL); + result = TCL_ERROR; + } + } else { + result = TCL_ERROR; } + return result; } @@ -642,6 +651,7 @@ long theLong; char *resourceId = NULL; OpenResourceFork *resourceRef; + char buffer[128]; Handle resource = NULL; OSErr err; Str255 theName; @@ -705,10 +715,8 @@ } if ((resourceId == NULL) && !gotInt) { - Tcl_AppendStringsToObj(resultPtr,"you must specify either ", - "\"-id\" or \"-name\" or both ", - "to \"resource delete\"", - (char *) NULL); + Tcl_AppendStringsToObj(resultPtr,"you must specify either ", + "-id or -name or both", (char *) NULL); return TCL_ERROR; } @@ -737,12 +745,8 @@ result = TCL_ERROR; goto deleteDone; } else if (err != noErr) { - char buffer[16]; - - sprintf(buffer, "%12d", err); - Tcl_AppendStringsToObj(resultPtr, "resource error #", - buffer, "occured while trying to find resource", - (char *) NULL); + sprintf(buffer, "error %d while trying to find resource", err); + Tcl_AppendStringsToObj(resultPtr, buffer, (char *) NULL); result = TCL_ERROR; goto deleteDone; } @@ -765,22 +769,16 @@ result = TCL_ERROR; goto deleteDone; } else if (err != noErr) { - char buffer[16]; - - sprintf(buffer, "%12d", err); - Tcl_AppendStringsToObj(resultPtr, "resource error #", - buffer, "occured while trying to find resource", - (char *) NULL); + sprintf(buffer, "error %d while trying to find resource", err); + Tcl_AppendStringsToObj(resultPtr, buffer, (char *) NULL); result = TCL_ERROR; goto deleteDone; } if (gotInt) { if (resource != tmpResource) { - Tcl_AppendStringsToObj(resultPtr, - "\"-id\" and \"-name\" ", - "values do not point to the same resource", - (char *) NULL); + Tcl_AppendStringsToObj(resultPtr, "-id and -name ", + "values do not point to the same resource", (char *) NULL); result = TCL_ERROR; goto deleteDone; } @@ -1278,7 +1276,8 @@ SInt8 macPermision; CONST char *str; char *native; - FSSpec fileSpec; + char resultStr[256]; + FSSpec fileSpec; FSRef fileFSRef, parentFSRef; OSErr err; Tcl_DString ds, buffer; @@ -1339,7 +1338,7 @@ Tcl_DStringFree(&buffer); if (!((err == noErr) || (err == fnfErr))) { - Tcl_AppendStringsToObj(resultPtr, "invalid path", (char *) NULL); + Tcl_AppendStringsToObj(resultPtr, "couldn't get file ref from path", (char *) NULL); return TCL_ERROR; } if (isDir) { @@ -1391,6 +1390,7 @@ mode = TclGetOpenMode(interp, stringPtr, &index); if (mode == -1) { /* TODO: TclGetOpenMode doesn't work with Obj commands. */ + Tcl_AppendStringsToObj(resultPtr, "couldn't get open mode for ", stringPtr, (char *) NULL); return TCL_ERROR; } switch (mode & (O_RDONLY | O_WRONLY | O_RDWR)) { @@ -1550,8 +1550,8 @@ return TCL_ERROR; } else { openError: - Tcl_AppendStringsToObj(resultPtr, - "error opening resource file", (char *) NULL); + sprintf(resultStr, "error %d opening resource file", err); + Tcl_AppendStringsToObj(resultPtr, resultStr, (char *) NULL); return TCL_ERROR; } } @@ -1761,7 +1761,7 @@ Tcl_Obj *resultPtr) /* Pointer to store the result. */ { OpenResourceFork *resourceRef; - char buffer[16]; + char buffer[128]; OSErr err; if (objc != 3) { @@ -1779,10 +1779,8 @@ UpdateResFile(resourceRef->fileRef); err = ResError(); if (err != noErr) { - sprintf(buffer, "%12d", err); - Tcl_AppendStringsToObj(resultPtr, - "error ", buffer, " updating resource map", - (char *) NULL); + sprintf(buffer, "error %d updating resource map", err); + Tcl_AppendStringsToObj(resultPtr, buffer, (char *) NULL); return TCL_ERROR; } return TCL_OK; @@ -2050,9 +2048,10 @@ ReleaseResource(resource); err = ResError(); if (err != noErr) { - Tcl_AppendStringsToObj(resultPtr, - "error releasing resource", - (char *) NULL); + Tcl_GetStringFromObj(resultPtr, &length); + if (length == 0) { + Tcl_AppendStringsToObj(resultPtr, "error releasing resource", (char *) NULL); + } result = TCL_ERROR; } } @@ -2612,7 +2611,7 @@ break; } else { if (tokenPtr != NULL) { - Tcl_SetStringObj(tokenPtr, "Resource already open with different permissions.", -1); + Tcl_SetStringObj(tokenPtr, "resource already opened with different permission", -1); } return TCL_ERROR; } @@ -2741,7 +2740,7 @@ if ( resourceRef->flags & TCL_RESOURCE_DONT_CLOSE ) { if (resultPtr != NULL) { Tcl_AppendStringsToObj(resultPtr, - "can't close \"", tokenPtr, "\" resource file", + "not allowed to close \"", tokenPtr, "\" resource file", (char *) NULL); } return -1; |