📄 publib.h
字号:
#include <unistd.h>#include <sys/stat.h>#include <sys/types.h>#include <errno.h>#include <fcntl.h>#include <malloc.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#ifndef NULL#define NULL (void *)0#endif#ifndef smch_t#define smch_t unsigned short #endif#ifndef _PUBLIB_HEADER_#define _PUBLIB_HEADER_/*Define a structure containing file useful infomation*********/typedef struct Fileinfo{ char pPath[256]; /*file name*/ /* FILE * pFile; *******/ char * pStr; /*file content pointer*/ size_t nLen; /*file length*/ }Fileinfo;/*Get file info through the file nameintput: the non-NULL string pStr is the file nameoutput: value-result variable pInfo points to the file info structreturn: 0 indicate successful, else error happened**********/int GetFileInfo(char * pStr, Fileinfo * pInfo);/*Put every character to a memory of fixed size * Here we assume 2 bytes is enough for any encode method * In the process, we can construct the lookup table for each string; * we assume prime number of 1333 is a good candidate for the number of common characters * * input: * pOrgStr: the string may contain differnt encode characters. * orgLen: the length * * output: * **ppTranStr: transfered string with each elements consumming the same memory * pTranLen: value-result variable for the length of the transfered string * lookup[1333]: lookup table for 1333 character * * return: 0 is ok; -1 is wrong**********/int TransferString(char * pOrgStr, const size_t orgLen, smch_t ** ppTranStr, size_t * pTranLen);typedef struct CharIndex{ smch_t smch; size_t * location; size_t memLen; size_t memUse; struct CharIndex * pNext;}CharIndex;/* Consruct a index for a string. Then it is easy to locate each kinds of character * Input: * pConStr: point to element * nLen: size of element * nIdxLen: Index length * output: * *ppIndexArray: to record the index information * return: 0 is ok, else return -1 * * I think it is better to let nIdxLen to be a prime number between 1000 to 6000**********/int IndexCharForStr(smch_t * pConStr, const size_t nStrLen, CharIndex ** ppIndexArray, const size_t nIdxLen);/* Get the positions for a character * Input: * ppIndexArray: the character index array * nIdxLen: the array length * output: * ppListPos: the list beginning position * pListLen: list length * return: * 0 is ok, -1 indicates failure * ********************/int GetCharPosList(const smch_t smch, CharIndex ** ppIndexArray, const size_t nIdxLen, size_t ** ppListPos, size_t * pListLen);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -