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

📄 cole.c

📁 excel to html
💻 C
📖 第 1 页 / 共 3 页
字号:
/*   cole - A free C OLE library.   Copyright 1998, 1999  Roberto Arturo Tena Sanchez   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *//*   Arturo Tena <arturo@directmail.org> */#if !(defined( __BORLANDC__ ) || defined( __WIN32__ ))#include "config.h"#include "cole.h"#else#include "cole.h.in"#endif#include "internal.h"#include <stdlib.h>/** * cole_perror: * @s: string to print before the error message. It can be NULL. * @colerrno: error value of which a message will be printed. * * Prints a message on the standard error output, describing the error * @colerrno, preceding it with the string @s, a semicolon and a space. * It handles COLE_EERRNO value too, calling perror(3). */voidcole_perror (const char *s, COLERRNO colerrno){	if (s != NULL) fprintf (stderr, "%s: ", s);	switch (colerrno) {	case COLE_EMEMORY:	case COLE_ECLOSEFILE:	case COLE_EWRITE:	case COLE_EREMOVE:	case COLE_ETMPNAM:	case COLE_ESEEK:	case COLE_EERRNO:		perror ("cole");		break;	case COLE_EOPENFILE:		fprintf (stderr, "cole - Cannot open the file\n");		break;	case COLE_ENOFILESYSTEM:		fprintf (stderr, "cole - The file is not a OLE2 file\n");		break;	case COLE_EINVALIDFILESYSTEM:		fprintf (stderr, "cole - The file has a short OLE2 header or it is not really an OLE2 file.\n");		break;	case COLE_EISNOTDIR:		fprintf (stderr, "cole - The OLE2 entry is not a substorage object\n");		break;	case COLE_EISNOTFILE:		fprintf (stderr, "cole - The substorage object is not valid\n");		break;	case COLE_EFILENOTFOUND:		fprintf (stderr, "cole - OLE2 object not found\n");		break;	case COLE_EOF:		fprintf (stderr, "cole - End of stream object has been reached\n");		break;	case COLE_EMEMBERISNOTDIR:		fprintf (stderr, "cole - The OLE2 object searched for is not "			 "a substorage object\n");		break;	case COLE_EBROKENFILENAME:		fprintf (stderr, "cole - Illegal OLE object name\n");		break;	case COLE_EFILENAMEISNOTFILE:		fprintf (stderr, "cole - The OLE2 object is not a stream\n");		break;	case COLE_EFSEEKDELTA:		fprintf (stderr, "cole - The seek offset is an illegal value\n");		break;	case COLE_EFSEEKFLAG:		fprintf (stderr, "cole - The Seek Flag is not valid\n");		break;	case COLE_EREAD:		fprintf (stderr, "cole - Short read length returned...the file is probably corrupted\n");		break;	case COLE_EUNKNOWN:		fprintf (stderr, "cole - An unknown error ocurred in the cole libary (might be a bug)\n");		break;	default:		fprintf (stderr, "cole - An unknown error %d ocurred in the cole libabry (might be a bug)\n",			 colerrno);		break;	}}/** * cole_mount: * @filename: name of the file with the filesystem. * @colerrno: error value (COLE_EMEMORY, COLE_EOPENFILE, COLE_ENOFILESYSTEM, * 			   COLE_EINVALIDFILESYSTEM, COLE_EUNKNOWN). * * Mounts the filesystem which is in @filename. * * Returns: a filesystem in success, or NULL in other case. */COLEFS *cole_mount (char *filename, COLERRNO *colerrno){	COLEFS * ret;	ret = (COLEFS *)malloc (sizeof (COLEFS));	if (ret == NULL) {		if (colerrno != NULL) *colerrno = COLE_EMEMORY;		return NULL;	}	switch (__OLEdecode (filename, &ret->tree, &ret->root, &ret->BDepot,				&ret->SDepot, &ret->sbfile, &ret->sbfilename,				&ret->file, 0)) {	case 0:		/* success */		break;	case 10:		if (colerrno != NULL) *colerrno = COLE_EMEMORY;		free (ret);		return NULL;	case 7:	case 4:		if (colerrno != NULL) *colerrno = COLE_EOPENFILE;		free (ret);		return NULL;	case 8:	case 9:		if (colerrno != NULL) *colerrno = COLE_ENOFILESYSTEM;		free (ret);		return NULL;	case 5:		if (colerrno != NULL) *colerrno = COLE_EINVALIDFILESYSTEM;		free (ret);		return NULL;	default:		if (colerrno != NULL) *colerrno = COLE_EUNKNOWN;		free (ret);		return NULL;	}	return ret;}/** * cole_umount: * @colefilesystem: filesystem to umount. * @colerrno: error value (COLE_ECLOSEFILE, COLE_EREMOVE). * * Umounts the filesystem @colefilesystem. * * Returns: zero in success, no zero in other case. */intcole_umount (COLEFS *colefilesystem, COLERRNO *colerrno){	int ret;	ret = 0;	free (colefilesystem->BDepot);	free (colefilesystem->tree);	if (fclose (colefilesystem->file) && !ret) {		if (colerrno != NULL) *colerrno = COLE_ECLOSEFILE;		ret = 1;	}	if (colefilesystem->SDepot != NULL) {		free (colefilesystem->SDepot);		/* may no exist SDepot because there are not small files */		/* assert (colefilesystem->sbfile != NULL); */		/* assert (colefilesystem->sbfilename != NULL); */		if (fclose (colefilesystem->sbfile) && !ret) {			if (colerrno != NULL) *colerrno = COLE_ECLOSEFILE;			ret = 1;		}#if defined(__WIN32__) || (__BORLANDC__)		if (remove (colefilesystem->sbfilename) && !ret) {			if (colerrno != NULL) *colerrno = COLE_EREMOVE;			ret = 1;		}#endif		free (colefilesystem->sbfilename);	}	free (colefilesystem);	return ret;}/** * cole_print_tree: * @colefilesystem: filesystem of which the tree will be printed. * @colerrno: error value (errors from call cole_recurse_tree()). * * Prints on the standard output the tree of files and directories contained * in @colefilesystem. * Currently this call always success. * * Returns: zero in success, no zero in other case. */static COLE_RECURSE_DIR_FUNC __cole_print_tree_indir;static COLE_RECURSE_DIR_FUNC __cole_print_tree_outdir;static COLE_RECURSE_DIR_FUNC __cole_print_tree_inroot;static COLE_RECURSE_DIRENT_FUNC __cole_print_tree_indirentry;int cole_print_tree (COLEFS *colefilesystem, COLERRNO *colerrno){	long level;	level = 1;	if (cole_recurse_tree (colefilesystem, &level,			       __cole_print_tree_inroot,			       __cole_print_tree_indirentry,			       __cole_print_tree_indir,			       __cole_print_tree_outdir, NULL, colerrno)) {		return 1;	}	return 0;}static int__cole_print_tree_indir(COLEDIR *cd, void *info, COLERRNO *colerrno){/* * ATTENTION: if you modify this function so it modifies colerrno: * 	Modify colerrno comment in the functions that call it, *	ie. cole_print_tree(). */	(*((long*)info))++;	return 0;}static int__cole_print_tree_outdir(COLEDIR *cd, void *info, COLERRNO *colerrno){/* * ATTENTION: if you modify this function so it modifies colerrno: * 	Modify colerrno comment in the functions that call it, *	ie. cole_print_tree(). */	(*((long*)info))--;	return 0;}static int__cole_print_tree_inroot(COLEDIR *cd, void *info, COLERRNO *colerrno){/* * ATTENTION: if you modify this function so it modifies colerrno: * 	Modify colerrno comment in the functions that call it, *	ie. cole_print_tree(). */	char *entry_name;	printf ("DIR ");	printf (" %7u", cole_dir_getsize (cd));	printf (" %08lx-%08lx %08lx-%08lx",		cole_dir_getdays1 (cd),		cole_dir_getsec1 (cd),		cole_dir_getdays2 (cd),		cole_dir_getsec2 (cd));	entry_name = cole_dir_getname (cd);	if (!isprint ((int)entry_name[0]))		printf (" '\\x%02x%s'\n", entry_name[0], entry_name+1);	else		printf (" '%s'\n", entry_name);	return 0;}static int__cole_print_tree_indirentry(COLEDIRENT *cde, void *info, COLERRNO *colerrno){/* * ATTENTION: if you modify this function so it modifies colerrno: * 	Modify colerrno comment in the functions that call it, *	ie. cole_print_tree(). */	char *entry_name;	long level;	long i;	level = *((long*)info);	for (i = 0; i < level; i++) {		if (i == level - 1)			printf ("\\--");		else			printf ("|  ");	}	if (cole_direntry_isdir (cde))		printf ("DIR ");	else if (cole_direntry_isfile (cde))		printf ("FILE");	else		printf ("????");	printf (" %7u", cole_direntry_getsize (cde));	printf (" %08lx-%08lx %08lx-%08lx",		cole_direntry_getdays1 (cde),		cole_direntry_getsec1 (cde),		cole_direntry_getdays2 (cde),		cole_direntry_getsec2 (cde));	entry_name = cole_direntry_getname (cde);	if (!isprint ((int)entry_name[0]))		printf (" '\\x%02x%s'\n", entry_name[0], entry_name+1);	else		printf (" '%s'\n", entry_name);	return 0;}/** * cole_opendir_rootdir: * @colefilesystem: filesystem of which the root directory will be opened. * @colerrno: error value (COLE_EMEMORY). * * Opens the root directory of the filesystem @colefilesystem as directory. * * Returns: a directory in success, or NULL in other case. */COLEDIR *cole_opendir_rootdir (COLEFS *colefilesystem, COLERRNO *colerrno){	COLEDIR *ret;	ret = (COLEDIR *)malloc (sizeof (COLEDIR));	if (ret == NULL) {		if (colerrno != NULL) *colerrno = COLE_EMEMORY;		return NULL;	}	ret->fs = colefilesystem;	ret->entry = ret->fs->root;	ret->visited_entry.dir = ret;	ret->visited_entry.entry = ret->fs->tree[ ret->entry ].dir;	return ret;}/** * cole_opendir_direntry: * @coledirentry: directory entry to be opened as directory. * @colerrno: error value (COLE_EISNOTDIR, COLE_EMEMORY). * * Opens a directory entry as directory. * * Returns: a directory in success, or NULL in other case. */COLEDIR *cole_opendir_direntry (COLEDIRENT *coledirentry, COLERRNO *colerrno){	COLEDIR *ret;	if (!cole_direntry_isdir (coledirentry)) {		if (colerrno != NULL) *colerrno = COLE_EISNOTDIR;		return NULL;	}	ret = (COLEDIR *)malloc (sizeof (COLEDIR));	if (ret == NULL) {		if (colerrno != NULL) *colerrno = COLE_EMEMORY;		return NULL;	}	ret->fs = coledirentry->dir->fs;	ret->entry = coledirentry->entry;	ret->visited_entry.dir = ret;	ret->visited_entry.entry = ret->fs->tree[ ret->entry ].dir;	return ret;}/** * cole_closedir: * @coledir: directory to be closed. * @colerrno: error value (). * * Closes the directory @coledir. * Currently this call always success. * * Returns: zero in success, no zero in other case. */int

⌨️ 快捷键说明

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