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

📄 cole.c

📁 excel to html
💻 C
📖 第 1 页 / 共 3 页
字号:
 * position, backward from the current position, or from the end of the * file, if @direction is COLE_SEEK_SET, COLE_SEEK_BACKWARD, * COLE_SEEK_FORWARD or COLE_SEEK_END, respectively. * The file position indicator will always be <= @colefile->filesize. * If you @delta is such that the previous line would not true, cole_fseek * fails. * * Returns: zero in success, no zero in other case. */intcole_fseek (COLEFILE *colefile, size_t delta, COLE_SEEK_FLAG direction,	    COLERRNO *colerrno){	if ((int)delta < 0) {		if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;		return 1;	}	switch (direction) {	case COLE_SEEK_SET:		if (delta <= colefile->filesize) {			colefile->pos = delta;			return 0;		} else {			if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;			return 1;		}	case COLE_SEEK_END:		if (delta <= colefile->filesize) {			colefile->pos = colefile->filesize - delta;			return 0;		} else {			if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;			return 1;		}	case COLE_SEEK_BACKWARD:		if (delta <= colefile->pos) {			colefile->pos = colefile->pos - delta;			return 0;		} else {			if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;			return 1;		}	case COLE_SEEK_FORWARD:		if (delta <= colefile->filesize - colefile->pos) {			colefile->pos = colefile->pos + delta;			return 0;		} else {			if (colerrno != NULL) *colerrno = COLE_EFSEEKDELTA;			return 1;		}	default:		if (colerrno != NULL) *colerrno = COLE_EFSEEKFLAG;		return 1;	}}/** * cole_frewind: * @colefile: file of which its file position indicator will be rewind. * @colerrno: error value (error from call cole_fseek()). *  * Sets the value of the file position indicator for the file @colefile * in the beginning of the file. * * Returns: zero in success, no zero in other case. */intcole_frewind (COLEFILE *colefile, COLERRNO *colerrno){	if (cole_fseek (colefile, 0, COLE_SEEK_SET, colerrno))		return 1;	return 0;}/** * cole_fsize: * @colefile: file of which its size will be returned. *  * Returns the size in bytes of the file @colefile. */size_tcole_fsize (COLEFILE *colefile){	return colefile->filesize;}/** * cole_feof: * @colefile: file to be tested. * * Tests if the end of file has been reached in @colefile. * * Returns: no zero if the end of file has been reached, zero in other case. */intcole_feof (COLEFILE *colefile){	/* assert ((colefile->pos == colefile->fs->tree[ colefile->entry ].size)	        && feof (colefile->file)); */	return (colefile->pos == colefile->filesize);}/** * cole_recurse_tree: * @colefilesystem: filesystem to recurse. * @info: arbitrary pointer passed to the functions. * @inroot: pointer to the function that is called when start visiting root *          directory. It can be NULL. * @indirentry: pointer to the function that is called when start visiting any * 		directory entry (file or directory). It can be NULL. * @indir: pointer to the function that is called when start visiting a * 	   directory. It can be NULL. * @outdir: pointer to the function that is called when end visiting a * 	    directory. It can be NULL. * @visitdir: pointer to the function that is called to know if visit a * 	      directory. It can be NULL. * @colerrno: error value (errors from calls cole_opendir_rootdir(), * 			   cole_opendir_direntry(), cole_closedir() and *			   inroot, indirentry, indir, and outdir functions). * * Recurse the filesystem @colefilesystem, calling the functions pointed by * @inroot, @indirentry, @indir and @outdirectory when start visiting * root directory, start visiting any directory entry (file or directory), * start visiting a directory or end visiting a directory, respectively. * If @visitdir returns no zero or it's NULL, the directory is visited, * otherwise is not visited. * @info is a arbitrary pointer which is passed to the functions pointed by * @inroot, @indirentry, @indir and @outdirectory: it may be used to share * arbitrary information between them. * * Returns: zero if recursed all the tree, no zero in other case. */static int__cole_recurse_tree (COLEDIR *_cd, long level, void *info,		     COLE_RECURSE_DIR_FUNC *inroot,		     COLE_RECURSE_DIRENT_FUNC *indirentry,		     COLE_RECURSE_DIR_FUNC *indir,			COLE_RECURSE_DIR_FUNC *outdir,		     COLE_RECURSE_VISIT_DIR_FUNC *visitdir,		     COLERRNO *colerrno);intcole_recurse_tree (COLEFS *colefilesystem, void *info,		     COLE_RECURSE_DIR_FUNC *inroot,		     COLE_RECURSE_DIRENT_FUNC *indirentry,		     COLE_RECURSE_DIR_FUNC *indir,		     COLE_RECURSE_DIR_FUNC *outdir,		     COLE_RECURSE_VISIT_DIR_FUNC *visitdir,		     COLERRNO *colerrno){	COLEDIR * cd;	cd = cole_opendir_rootdir (colefilesystem, colerrno);	if (cd == NULL)		return 1;	if (__cole_recurse_tree (cd, 1, info, inroot, indirentry, indir,				 outdir, visitdir, colerrno)) {		cole_closedir (cd, NULL);		/* colerrno is set */		return 1;	}	if (cole_closedir (cd, colerrno)) {		/* colerrno is set */		return 1;	}	return 0;}static int__cole_recurse_tree (COLEDIR *_cd, long level, void *info,		     COLE_RECURSE_DIR_FUNC *inroot,		     COLE_RECURSE_DIRENT_FUNC *indirentry,		     COLE_RECURSE_DIR_FUNC *indir,			COLE_RECURSE_DIR_FUNC *outdir,		     COLE_RECURSE_VISIT_DIR_FUNC *visitdir,		     COLERRNO *colerrno){/* * ATTENTION: if you modify __cole_recurse_tree() so it modifies colerrno * besides in calling inroot, indirentry, indir, outdir, cole_opendir_direntry * or cole_closedir: * 	Modify colerrno comment in the functions that call it, *	ie. cole_recurse_tree(). */	/* ATTENTION: This is a recursive function */	COLEDIRENT * cde;	COLEDIR * cd;	if (level == 1) {		/* The following lines are only executed on Root Entry */		if (inroot != NULL) {			if ( (*inroot) (_cd, info, colerrno) ) {				/* colerrno is set */				return 1;			}		}	}	/* Iterate through childrens */	for (cde = cole_visiteddirentry (_cd); cde != NULL;	     cde = cole_nextdirentry (_cd)) {		if (indirentry != NULL) {			if ( (*indirentry) (cde, info, colerrno) ) {				/* colerrno is set */				return 1;			}		}		/* RECURSIVE CALL */		if (cole_direntry_isdir (cde)) {			cd = cole_opendir_direntry (cde, colerrno);			if (cd == NULL) {				/* colerrno is set */				return 1;			}			if (indir != NULL) {				if ( (*indir) (cd, info, colerrno) ) {					/* colerrno is set */					cole_closedir (cd, NULL);					return 1;				}			}			if ( (visitdir == NULL) || 			     ((*visitdir)(cd, info)) ) {				if (__cole_recurse_tree (cd, level + 1, info,							 inroot, indirentry,							 indir, outdir,							 visitdir, colerrno)) {					/* colerrno is set */					cole_closedir (cd, NULL);					return 1;				}			}			if (outdir != NULL) {				if ( (*outdir) (cd, info, colerrno) ) {					/* colerrno is set */					cole_closedir (cd, NULL);					return 1;				}			}			if (cole_closedir (cd, colerrno)) {				/* colerrno is set */				return 1;			}		}	}	return 0;}/** * cole_locate_filename: * @colefilesystem: filesystem where to locate @filename. * @filename: name of the file or directory to be located. * @info: arbitrary pointer passed to @action. * @action: pointer to the function that is called when founding @filename. * @colerrno: error value (COLE_EUNKNOWN, COLE_EMEMBERISNOTDIR, * 			   COLE_EFILENOTFOUND, COLE_EBROKENFILENAME, errors * 			   from call cole_recurse_tree()). * * Locate the @filename in the filesystem @colefilesystem, calling @action when * it's found. @info is arbitrary pointer passed to @action. * Currently, @filename must begin with a '/' character, it means @filename is * the absolute filename. * * Returns: zero in success, 1  in other case. */struct __cole_locate_filenameinfo {	COLE_LOCATE_ACTION_FUNC *action;	void *info;	char *filename;	char *current;	int visitdir;};static COLE_RECURSE_DIRENT_FUNC __cole_locate_filename_indirentry;static COLE_RECURSE_VISIT_DIR_FUNC __cole_locate_filename_visitdir;intcole_locate_filename (COLEFS *colefilesystem, char *filename,		      void *info,		      COLE_LOCATE_ACTION_FUNC *action,		      COLERRNO *colerrno){	struct __cole_locate_filenameinfo _info;	COLERRNO _colerrno;	/* FIXME allow no absolute paths */	if (filename[0] != '/') {		if (colerrno != NULL) *colerrno = COLE_EBROKENFILENAME;		return 1;	}	_info.action = action;	_info.info = info;	_info.filename = filename;	_info.current = filename + 1;	if (cole_recurse_tree (colefilesystem, &_info, NULL,			   __cole_locate_filename_indirentry, NULL, NULL,			   __cole_locate_filename_visitdir,			   &_colerrno)) {		if (_colerrno == COLE_ELAST+1) {			/* file was found */			return 0;		}		if (colerrno != NULL) *colerrno = _colerrno;		return 1;	}	if (colerrno != NULL) *colerrno = COLE_EFILENOTFOUND;	return 1;}static int__cole_locate_filename_visitdir (COLEDIR *cd, void *info){	return ((struct __cole_locate_filenameinfo *)info)->visitdir;}static int__cole_locate_filename_indirentry (COLEDIRENT *cde, void *_info,				COLERRNO *colerrno){	char *entry_name;	struct __cole_locate_filenameinfo *info;	char *pcurrent;	char *pentry_name;	info = (struct __cole_locate_filenameinfo *)_info;	entry_name = cole_direntry_getname (cde);	for (pcurrent = info->current, pentry_name = entry_name;	     *pcurrent && *pentry_name && *pcurrent != '/';	     pcurrent++, pentry_name++) {		if (*pcurrent != *pentry_name) {			info->visitdir = 0;	/* don't visit this directory */			return 0;		/* don't break recurse */		}	}	switch (*pentry_name) {	case 0:		switch (*pcurrent) {		case '/':			if (!cole_direntry_isdir (cde)) {				if (colerrno != NULL)					*colerrno = COLE_EMEMBERISNOTDIR;				return 1;	/* break recurse */			}			pcurrent++;		/* jump the '/' character */			info->current = pcurrent;			/* check if it's the last component of filename */			if (!(*info->current)) {				/* last component of filename reached */				if (info->action != NULL) {					(*(info->action)) (cde, info->info);				}				if (colerrno != NULL) *colerrno = COLE_ELAST+1;				return 1;               /* break recurse */			}			info->visitdir = 1;	/* visit this directory */			return 0;		/* don't break recurse */		case 0:			/* last component of filename reached */                        if (info->action != NULL) {				(*(info->action)) (cde, info->info);                        }			if (colerrno != NULL) *colerrno = COLE_ELAST+1;			return 1;		/* break recurse */		default:			info->visitdir = 0;	/* don't visit this directory */			return 0;		/* don't break recurse */		}	default:		switch (*pcurrent) {		case 0:			info->visitdir = 0;	/* don't visit this directory */			return 0;		/* don't break recurse */		case '/':			info->visitdir = 0;	/* don't visit this directory */			return 0;		/* don't break recurse */		default:			if (colerrno != NULL) *colerrno = COLE_EUNKNOWN;			return 1;		/* break recurse */		}	}}

⌨️ 快捷键说明

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