📄 toolbox.h
字号:
/*============================================================================*//* L a b W i n d o w s / C V I *//*----------------------------------------------------------------------------*//* Copyright (c) National Instruments 1987-1996. All Rights Reserved. *//*----------------------------------------------------------------------------*//* *//* Title: toolbox.h *//* Purpose: provides commonly useful functions *//* *//*============================================================================*/#ifndef TOOLBOX_HEADER#define TOOLBOX_HEADER#include <userint.h>#include <ansi_c.h>#ifdef __cplusplus extern "C" {#endif /********************/ /* MACROS: */ /********************/#ifndef TRUE#define TRUE 1#endif#ifndef FALSE#define FALSE 0#endif#ifndef NULL#define NULL 0#endif#ifndef Max#define Max(a,b) ((a) > (b) ? (a) : (b))#endif#ifndef Min#define Min(a,b) ((a) < (b) ? (a) : (b))#endif#ifndef ABS_VAL#define ABS_VAL(a) ((a) < 0 ? (-(a)) : (a))#endif#ifndef Assert#define Assert(passed) DoAssert((int)(passed), __FILE__, __LINE__, 0)#endif#ifndef AssertMsg#define AssertMsg(passed, msg) DoAssert((int)(passed), __FILE__, __LINE__, msg)#endif#ifndef UNUSED#ifdef _CVI_#define UNUSED(a)#else#define UNUSED(a) switch((int)&a){default:break;} /* bypass bogus warnings on external compilers */#endif#endif#ifndef CAT4CHARS#define CAT4CHARS(c1,c2,c3,c4) (((int)(unsigned char)(c1)<<24)|((int)(unsigned char)(c2)<<16)|((int)(unsigned char)(c3)<<8)|((int)(unsigned char)(c4)))#endif/* The errChk and nullChk macros are useful for implementing a consistent error handling system. These can macros can be place around function calls to force an automatic jump to a function's error handling code when an error occurs. This is analogous to exception handling, and is even easier to use. These macros make the following assumptions: 1) The following local declaration of an error code variable is made in every function in which they are used: int error = 0; 2) Every function in which they are used contains a goto label named Error which precedes the error handling code for the function. 3) Every function call or error code enclosed in a errChk() macro is assumed to return an integer which, if negative, is the code for the error which occured. If the value is zero or positive then the error checking macros have no effect. Every function call or value enclosed in a nullChk() macro is assummed to return a non-zero value if no error occurred, or a zero value if an "Out Of Memory" error occurred (nullChk() is useful for malloc, calloc, and similar resource allocation functions).*/#ifndef errChk#define errChk(fCall) if (error = (fCall), error < 0) \{goto Error;} else#endif#ifndef nullChk#define nullChk(fCall) if ((fCall) == 0) \{error = UIEOutOfMemory; goto Error;} else#endif#define EVENT_MOUSE_MOVE 14000 /* see EnableMouseEvents() */#define EVENT_RIGHT_MOUSE_UP 14001#define EVENT_LEFT_MOUSE_UP 14002 /*****************/ /* enums: */ /*****************/typedef enum { ToolErr_CouldNotOpenFileForReading = -5001, ToolErr_ErrorReadingFile = -5002, ToolErr_CouldNotFindUnusedTempFileName = -5003, ToolErr_CouldNotCreateTempFile = -5004, ToolErr_IncorrectFileFormat = -5005, ToolErr_UnexpectedEndOfFile = -5006, ToolErr_InvalidIntNumber = -5021, ToolErr_InvalidUIntNumber = -5022, ToolErr_InvalidDoubleNumber = -5023, ToolErr_InvalidBooleanValue = -5024, ToolErr_MissingSection = -5025, ToolErr_MissingItem = -5026, ToolErr_UnRecognizedValue = -5027, ToolErr_OperationInProgress = -5050, ToolErr_TooManyItems = -5051, ToolErr_DuplicateItemOrValue = -5052, ToolErr_PanelNotAChildOfCorrectPanel = -5060 } ToolError; /********************/ /* Functions: */ /********************/ /*** Miscellaneous ***/typedef void (CVICALLBACK * DelayedCallbackFunc)(void *callbackData);double CVIFUNC Pin(double value, double low, double high);void CVIFUNC DoAssert(int passed, char *fileName, int line, char *msg);void CVIFUNC SwapBlock(void *block1, void *block2, int numBytes);double CVIFUNC Random(double minimum, double maximum);void CVIFUNC SetRandomSeed(unsigned long seed);void CVIFUNC StartPCSound(unsigned int frequency);void CVIFUNC StopPCSound(void);void CVIFUNC TransposeData(void *data, int dataType, int numPoints, int numChannels);void CVIFUNC ConvertArrayType(void * sourceArray, int sourceDataType, void * targetArray, int targetDataType, int numberOfPoints);int CVIFUNC SetBOLE(int on);int CVIFUNC PostDelayedCall(DelayedCallbackFunc callback, void *callbackData, double delay);char * CVIFUNC GetToolboxErrorString(int errorCode);char * CVIFUNC GetGeneralErrorString(int errorCode);int CVIFUNC InternationalTime(char timeString[], int bufferSize);int CVIFUNC InternationalDate(char dateString[], int bufferSize);int CVIFUNC InternationalFileTime(char filePath[], char timeString[], int bufferSize);int CVIFUNC InternationalFileDate(char filePath[], char dateString[], int bufferSize);int CVIFUNC GetFileCLibTime(char filePath[], time_t *time);int CVIFUNC RegisterExistence(void *objectPtr); /* no function panel yet */int CVIFUNC ObjectExists(void *objectPtr); /* no function panel yet */void CVIFUNC DeRegisterExistence(void *objectPtr); /* no function panel yet */int CVIFUNC FindClosestColorInTable (int color, int *table, int tableSize); int CVIFUNC RoundToNextMultiple(int number, int multiple); /* no function panel yet */char * CVIFUNC FindFileDotPosition (char *pathString); /* no function panel yet */char * CVIFUNC FindFileExtension(char *pathString); /* no function panel yet */char * CVIFUNC FindFileName(char *pathString); /* no function panel yet */ /*** Floating Point Comparisons With Tolerance ***/#define FP_CompareEpsilon 0.00000001 /* a small amount: used for floating point comparisons */int CVIFUNC FP_Compare(double a, double b);int CVIFUNC FP_EQ(double a, double b); /* no function panel */int CVIFUNC FP_GT(double a, double b); /* no function panel */int CVIFUNC FP_GE(double a, double b); /* no function panel */int CVIFUNC FP_LT(double a, double b); /* no function panel */int CVIFUNC FP_LE(double a, double b); /* no function panel */int CVIFUNC ConvertDataToText(const unsigned char *dataPtr, long dataSize, unsigned char **textPtr);int CVIFUNC ConvertTextToData(const unsigned char *textPtr, long *dataSize, unsigned char **dataPtr); /*** String Functions ***/int CVIFUNC AppendString(char **string, char *stringToAdd, int lengthToAdd);char * CVIFUNC StrDup(char *stringToDuplicate);char * CVIFUNC StrDupWithoutSurrWhiteSpace (char *string);char * CVIFUNC SkipWhiteSpace (char *string);char * CVIFUNC SkipNonWhiteSpace (char *string);void CVIFUNC StringCopyMax(char *dest, char *source, int destBufferSize);void CVIFUNC RemoveSurroundingWhiteSpace(char string[]);int CVIFUNC HasNonWhiteSpace (char *s);int CVIFUNC StrICmp (char *s1, char *s2);int CVIFUNC StrICmpWithoutSurrWhiteSpace (char *s1, char *s2);int CVIFUNC StrToInt (char *str, int *n);int CVIFUNC StrToUInt (char *str, unsigned int *n);int CVIFUNC SpliceCommaSeparatedList(char *list1, char *list2, char **splicedList); /* no function panel */char * CVIFUNC StringInsert(char *destinationString, char *stringToInsert, int destinationBufferSize); /* no function panel */int CVIFUNC AcceleratorEscapeCodeLocation(char *text); /* no function panel */void CVIFUNC RemoveAcceleratorEscapeCode(char *text); /* no function panel */ /*** File Functions ***/#if defined(_NI_mswin_) #define FILE_SEPARATOR "\\" #define LINE_TERMINATOR "\r\n" #define LINE_TERMINATOR_LEN 2#elif defined(_NI_unix_) #define FILE_SEPARATOR "/" #define LINE_TERMINATOR "\n" #define LINE_TERMINATOR_LEN 1#elif defined(_NI_mac_) #define FILE_SEPARATOR ":" #define LINE_TERMINATOR "\r" #define LINE_TERMINATOR_LEN 1#endifint CVIFUNC GetFileWritability (char pathName[], int *isWritable);int CVIFUNC CreateAndOpenTemporaryFile (char *pathName, char *prefix, char *extension, char *openModeString, char tempPathName[], FILE **tempFile);void CVIFUNC RemoveFileIfExists (char pathName[]);int CVIFUNC DeleteAndRename (char srcPathName[], char destPathName[]);int CVIFUNC FileExists(char *pathName, int *fileSize);int CVIFUNC WriteStringToFile (FILE *stream, char *string);void CVIFUNC ChangeFileNameExtension(char *fileName, char *newFileName, char *extension); /* no function panel yet */void CVIFUNC ChangeBaseFileName(char *pathString, char *newPathString, char *baseName); /* no function panel yet */int CVIFUNC IsAbsolutePath(char *pathString); /* no function panel yet */char * CVIFUNC SkipDriveName(char *pathString); /* no function panel yet */int CVIFUNC FindBytesInFile(FILE *file, void *bytesToFind, int numBytesToFind, int *offset, int *position); /* no function panel yet */int CVIFUNC WriteByteToFile(FILE *file, char byte, int numTimes); /* no function panel yet */int CVIFUNC ReadStringFromBinaryFile(FILE *file, char **string, int maxCharactersToRead, int *endOfFile, int *maxCharactersRead); /* no function panel yet */int CVIFUNC ReadLineFromBinaryFile(FILE *file, char **string, int maxCharactersToRead, int *endOfFile, int *maxCharactersRead); /* no function panel yet */int CVIFUNC BinaryFileSize(FILE *file, int *size); /*** Searching, Sorting, Comparison ***/typedef int (CVICALLBACK * CompareFunction)(void *item, void *itemOrArray); /* Typedef for ansi compatible comparison function */int CVICALLBACK ShortCompare(void *a, void *b);int CVICALLBACK IntCompare(void *a, void *b);int CVICALLBACK FloatCompare(void *a, void *b);int CVICALLBACK DoubleCompare(void *a, void *b);int CVICALLBACK CStringCompare(void *a, void *b);int CVIFUNC BinSearch(void *array, int numElements, int elementSize, void *itemPtr, CompareFunction compareFunction);void CVIFUNC HeapSort(void *array, int numElements, int elementSize, CompareFunction compareFunction);void CVIFUNC InsertionSort(void *array, int numElements, int elementSize, CompareFunction compareFunction); /*** Memory Block Handles ***/typedef void **Handle;Handle CVIFUNC NewHandle(unsigned int numBytes);void CVIFUNC DisposeHandle(Handle handle);unsigned int CVIFUNC GetHandleSize(Handle handle);int CVIFUNC SetHandleSize(Handle handle, unsigned int newSize);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -