⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tclmacfcmd.c

📁 linux系统下的音频通信
💻 C
📖 第 1 页 / 共 3 页
字号:
    char *dirName;    OSErr err;    int argc;    char **argv;    long d;    Tcl_DString buffer;            *pathExistsPtr = false;    *pathIsDirectoryPtr = false;        Tcl_DStringInit(&buffer);    Tcl_SplitPath(path, &argc, &argv);    if (argc == 1) {        dirName = ":";    } else {        dirName = Tcl_JoinPath(argc - 1, argv, &buffer);    }    err = FSpLocationFromPath(strlen(dirName), dirName, dirSpecPtr);    Tcl_DStringFree(&buffer);    ckfree((char *) argv);    if (err == noErr) {        err = FSpLocationFromPath(strlen(path), path, pathSpecPtr);        if (err == noErr) {            *pathExistsPtr = true;            err = FSpGetDirectoryID(pathSpecPtr, &d, pathIsDirectoryPtr);        } else if (err == fnfErr) {            err = noErr;        }    }    return err;}/* *------------------------------------------------------------------------- * * FSpGetFLockCompat -- * *	Determines if there exists a software lock on the specified *	file.  The software lock could prevent the file from being  *	renamed or moved. * * Results: *	Standard macintosh error code.   * * Side effects: *	None. * * *------------------------------------------------------------------------- */ OSErrFSpGetFLockCompat(    const FSSpec *specPtr,	/* File to query. */    Boolean *lockedPtr)		/* Set to true if file is locked, false    				 * if it isn't or there was an error reading    				 * specified file. */{    CInfoPBRec pb;    OSErr err;        pb.hFileInfo.ioVRefNum = specPtr->vRefNum;    pb.hFileInfo.ioDirID = specPtr->parID;    pb.hFileInfo.ioNamePtr = (StringPtr) specPtr->name;    pb.hFileInfo.ioFDirIndex = 0;        err = PBGetCatInfoSync(&pb);    if ((err == noErr) && (pb.hFileInfo.ioFlAttrib & 0x01)) {        *lockedPtr = true;    } else {        *lockedPtr = false;    }    return err;}    /* *---------------------------------------------------------------------- * * Pstrequal -- * *      Pascal string compare.  * * Results: *      Returns 1 if strings equal, 0 otherwise. * * Side effects: *      None. *       *---------------------------------------------------------------------- */static int Pstrequal (    ConstStr255Param stringA,	/* Pascal string A */    ConstStr255Param stringB)   /* Pascal string B */{    int i, len;        len = *stringA;    for (i = 0; i <= len; i++) {        if (*stringA++ != *stringB++) {            return 0;        }    }    return 1;}    /* *---------------------------------------------------------------------- * * GetFileFinderAttributes -- * *	Returns a Tcl_Obj containing the value of a file attribute *	which is part of the FInfo record. Which attribute is controlled *	by objIndex. * * Results: *      Returns a standard TCL error. If the return value is TCL_OK, *	the new creator or file type object is put into attributePtrPtr. *	The object will have ref count 0. If there is an error, *	attributePtrPtr is not touched. * * Side effects: *      A new object is allocated if the file is valid. *       *---------------------------------------------------------------------- */static intGetFileFinderAttributes(    Tcl_Interp *interp,		/* The interp to report errors with. */    int objIndex,		/* The index of the attribute option. */    char *fileName,		/* The name of the file. */    Tcl_Obj **attributePtrPtr)	/* A pointer to return the object with. */{    OSErr err;    FSSpec fileSpec;    FInfo finfo;        err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec);        if (err == noErr) {    	err = FSpGetFInfo(&fileSpec, &finfo);    }        if (err == noErr) {    	switch (objIndex) {    	    case MAC_CREATOR_ATTRIBUTE:    	    	*attributePtrPtr = Tcl_NewOSTypeObj(finfo.fdCreator);    	    	break;    	    case MAC_HIDDEN_ATTRIBUTE:    	    	*attributePtrPtr = Tcl_NewBooleanObj(finfo.fdFlags    	    		& kIsInvisible);    	    	break;    	    case MAC_TYPE_ATTRIBUTE:    	    	*attributePtrPtr = Tcl_NewOSTypeObj(finfo.fdType);    	    	break;    	}    } else if (err == fnfErr) {    	long dirID;    	Boolean isDirectory = 0;    	    	err = FSpGetDirectoryID(&fileSpec, &dirID, &isDirectory);    	if ((err == noErr) && isDirectory) {    	    if (objIndex == MAC_HIDDEN_ATTRIBUTE) {    	    	*attributePtrPtr = Tcl_NewBooleanObj(0);    	    } else {    	    	*attributePtrPtr = Tcl_NewOSTypeObj('Fldr');    	    }    	}    }        if (err != noErr) {    	errno = TclMacOSErrorToPosixError(err);    	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),     		"couldn't get attributes for file \"", fileName, "\": ",    		Tcl_PosixError(interp), (char *) NULL);    	return TCL_ERROR;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * GetFileReadOnly -- * *	Returns a Tcl_Obj containing a Boolean value indicating whether *	or not the file is read-only. The object will have ref count 0. *	This procedure just checks the Finder attributes; it does not *	check AppleShare sharing attributes. * * Results: *      Returns a standard TCL error. If the return value is TCL_OK, *	the new creator type object is put into readOnlyPtrPtr. *	If there is an error, readOnlyPtrPtr is not touched. * * Side effects: *      A new object is allocated if the file is valid. *       *---------------------------------------------------------------------- */static intGetFileReadOnly(    Tcl_Interp *interp,		/* The interp to report errors with. */    int objIndex,		/* The index of the attribute. */    char *fileName,		/* The name of the file. */    Tcl_Obj **readOnlyPtrPtr)	/* A pointer to return the object with. */{    OSErr err;    FSSpec fileSpec;    CInfoPBRec paramBlock;        err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec);        if (err == noErr) {    	if (err == noErr) {    	    paramBlock.hFileInfo.ioCompletion = NULL;    	    paramBlock.hFileInfo.ioNamePtr = fileSpec.name;    	    paramBlock.hFileInfo.ioVRefNum = fileSpec.vRefNum;    	    paramBlock.hFileInfo.ioFDirIndex = 0;    	    paramBlock.hFileInfo.ioDirID = fileSpec.parID;    	    err = PBGetCatInfo(&paramBlock, 0);    	    if (err == noErr) {    	        	    	/*    	    	 * For some unknown reason, the Mac does not give    	    	 * symbols for the bits in the ioFlAttrib field.    	    	 * 1 -> locked.    	    	 */    	        	    	*readOnlyPtrPtr = Tcl_NewBooleanObj(    	    		paramBlock.hFileInfo.ioFlAttrib & 1);    	    }    	}    }    if (err != noErr) {    	errno = TclMacOSErrorToPosixError(err);    	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),     		"couldn't get attributes for file \"", fileName, "\": ",    		Tcl_PosixError(interp), (char *) NULL);    	return TCL_ERROR;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * SetFileFinderAttributes -- * *	Sets the file to the creator or file type given by attributePtr. *	objIndex determines whether the creator or file type is set. * * Results: *	Returns a standard TCL error. * * Side effects: *      The file's attribute is set. *       *---------------------------------------------------------------------- */static intSetFileFinderAttributes(    Tcl_Interp *interp,		/* The interp to report errors with. */    int objIndex,		/* The index of the attribute. */    char *fileName,		/* The name of the file. */    Tcl_Obj *attributePtr)	/* The command line object. */{    OSErr err;    FSSpec fileSpec;    FInfo finfo;        err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec);        if (err == noErr) {    	err = FSpGetFInfo(&fileSpec, &finfo);    }        if (err == noErr) {    	switch (objIndex) {    	    case MAC_CREATOR_ATTRIBUTE:    	    	if (Tcl_GetOSTypeFromObj(interp, attributePtr,    	    		&finfo.fdCreator) != TCL_OK) {    	    	    return TCL_ERROR;    	    	}    	    	break;    	    case MAC_HIDDEN_ATTRIBUTE: {    	    	int hidden;    	    	    	    	if (Tcl_GetBooleanFromObj(interp, attributePtr, &hidden)    	    		!= TCL_OK) {    	    	    return TCL_ERROR;    	    	}    	    	if (hidden) {    	    	    finfo.fdFlags |= kIsInvisible;    	    	} else {    	    	    finfo.fdFlags &= ~kIsInvisible;    	    	}    	    	break;    	    }    	    case MAC_TYPE_ATTRIBUTE:    	    	if (Tcl_GetOSTypeFromObj(interp, attributePtr,    	    		&finfo.fdType) != TCL_OK) {    	    	    return TCL_ERROR;    	    	}    	    	break;    	}    	err = FSpSetFInfo(&fileSpec, &finfo);    } else if (err == fnfErr) {    	long dirID;    	Boolean isDirectory = 0;    	    	err = FSpGetDirectoryID(&fileSpec, &dirID, &isDirectory);    	if ((err == noErr) && isDirectory) {    	    Tcl_Obj *resultPtr = Tcl_GetObjResult(interp);    	    Tcl_AppendStringsToObj(resultPtr, "cannot set ",    	    	    tclpFileAttrStrings[objIndex], ": \"",    	    	    fileName, "\" is a directory", (char *) NULL);    	    return TCL_ERROR;    	}    }        if (err != noErr) {    	errno = TclMacOSErrorToPosixError(err);    	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),     		"couldn't set attributes for file \"", fileName, "\": ",    		Tcl_PosixError(interp), (char *) NULL);    	return TCL_ERROR;    }    return TCL_OK;}/* *---------------------------------------------------------------------- * * SetFileReadOnly -- * *	Sets the file to be read-only according to the Boolean value *	given by hiddenPtr. * * Results: *	Returns a standard TCL error. * * Side effects: *      The file's attribute is set. *       *---------------------------------------------------------------------- */static intSetFileReadOnly(    Tcl_Interp *interp,		/* The interp to report errors with. */    int objIndex,		/* The index of the attribute. */    char *fileName,		/* The name of the file. */    Tcl_Obj *readOnlyPtr)	/* The command line object. */{    OSErr err;    FSSpec fileSpec;    HParamBlockRec paramBlock;    int hidden;        err = FSpLocationFromPath(strlen(fileName), fileName, &fileSpec);        if (err == noErr) {    	if (Tcl_GetBooleanFromObj(interp, readOnlyPtr, &hidden) != TCL_OK) {    	    return TCL_ERROR;    	}        	paramBlock.fileParam.ioCompletion = NULL;    	paramBlock.fileParam.ioNamePtr = fileSpec.name;    	paramBlock.fileParam.ioVRefNum = fileSpec.vRefNum;    	paramBlock.fileParam.ioDirID = fileSpec.parID;    	if (hidden) {    	    err = PBHSetFLock(&paramBlock, 0);    	} else {    	    err = PBHRstFLock(&paramBlock, 0);    	}    }        if (err == fnfErr) {    	long dirID;    	Boolean isDirectory = 0;    	err = FSpGetDirectoryID(&fileSpec, &dirID, &isDirectory);    	if ((err == noErr) && isDirectory) {    	    Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),    	    	    "cannot set a directory to read-only when File Sharing is turned off",    	    	    (char *) NULL);    	    return TCL_ERROR;    	} else {    	    err = fnfErr;    	}    }        if (err != noErr) {    	errno = TclMacOSErrorToPosixError(err);    	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),     		"couldn't set attributes for file \"", fileName, "\": ",    		Tcl_PosixError(interp), (char *) NULL);    	return TCL_ERROR;    }    return TCL_OK;}/* *--------------------------------------------------------------------------- * * TclpListVolumes -- * *	Lists the currently mounted volumes * * Results: *	A standard Tcl result.  Will always be TCL_OK, since there is no way *	that this command can fail.  Also, the interpreter's result is set to  *	the list of volumes. * * Side effects: *	None * *--------------------------------------------------------------------------- */intTclpListVolumes( 		Tcl_Interp *interp)    /* Interpreter to which to pass the volume list */{    HParamBlockRec pb;    Str255 name;    OSErr theError = noErr;    Tcl_Obj *resultPtr, *elemPtr;    short volIndex = 1;    resultPtr = Tcl_NewObj();            /*     * We use two facts:     * 1) The Mac volumes are enumerated by the ioVolIndex parameter of     * the HParamBlockRec.  They run through the integers contiguously,      * starting at 1.       * 2) PBHGetVInfoSync returns an error when you ask for a volume index     * that does not exist.     *      */            while ( 1 ) {        pb.volumeParam.ioNamePtr = (StringPtr) & name;        pb.volumeParam.ioVolIndex = volIndex;                        theError = PBHGetVInfoSync(&pb);        if ( theError != noErr ) {            break;        }                        elemPtr = Tcl_NewStringObj((char *) name + 1, (int) name[0]);        Tcl_AppendToObj(elemPtr, ":", 1);        Tcl_ListObjAppendElement(interp, resultPtr, elemPtr);                        volIndex++;                 }            Tcl_SetObjResult(interp, resultPtr);    return TCL_OK;      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -