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

📄 wrfile.c

📁 harvest是一个下载html网页得机器人
💻 C
📖 第 1 页 / 共 2 页
字号:
#if defined(TYPES_H) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__bsdi__)#include <sys/types.h>#endif /* TYPES_H */#include <sys/stat.h>#include <ctype.h>#include <stdio.h>#include "machdr.h"#include "wrfile.h"#include "wrfileopt.h"#include "../util/util.h"#ifdef AUFSPLUS#include "../util/curtime.h"#define AUFS#endif /* AUFSPLUS */#ifdef AUFS#include "aufs.h"#define APPLESHARE#endif /* AUFS */#ifdef APPLEDOUBLE#include "appledouble.h"#include "../util/curtime.h"#define APPLESHARE#endif /* APPLEDOUBLE */#define TEXT 0#define DATA 1#define RSRC 2#define FULL 3#define MACB 4#define FORK 5#define APSH 6#define MACS 7#define UNIX 8#ifdef SCAN#define MACI 9#endif /* SCAN */extern char *malloc();extern char *realloc();extern char *strcpy();extern char *strncpy();extern char *strcat();extern void exit();#ifdef UNDEF /* Do not declare sprintf; not portable (but lint will complain) */char *sprintf();#endif /* UNDEF */#ifdef AUFSstatic void check_aufs();static void aufs_namings();static void wr_aufs_info();#endif /* AUFS */#ifdef APPLEDOUBLEstatic void check_appledouble();static void appledouble_namings();static void wr_appledouble_info();#endif /* APPLEDOUBLE */#ifdef APPLESHAREstatic void mk_share_name();#endif /* APPLESHARE */#ifndef BSD/* all those stupid differences! */#include <memory.h>#define bcopy(src,dest,length)	memcpy((dest),(src),(length))#define bzero(block,length)	memset((block),0,(length))#endif /* BSD */#define INFO_FORK	1#define RSRC_FORK	2#define DATA_FORK	3static char f_info[I_NAMELEN];static char f_data[I_NAMELEN*3];static char f_rsrc[I_NAMELEN];static char f_text[I_NAMELEN];static char f_unix[I_NAMELEN];static char f_bin[I_NAMELEN];static char f_folder[] = ".foldername";static char share_name[256];#ifdef APPLESHAREstatic char hex[] = "0123456789abcdef";#endif /* APPLESHARE */#ifdef AUFSstatic char infodir[] = ".finderinfo";static char rsrcdir[] = ".resource";#define INFOSZ	sizeof(infodir)#define RSRCSZ	sizeof(rsrcdir)static char f_info_aufs[I_NAMELEN*3+INFOSZ];static char f_rsrc_aufs[I_NAMELEN*3+RSRCSZ];#endif /* AUFS */#ifdef APPLEDOUBLEstatic char infodir[] = ".AppleDouble";#define INFOSZ	sizeof(infodir)static char f_info_appledouble[I_NAMELEN*3+INFOSZ];#endif /* APPLEDOUBLE */static int mode = MACB;static int mode_restricted = 0;static int mode_s_restricted = 0;char *out_buffer, *out_ptr;static char init_buffer[128];static char *buffer = &(init_buffer[0]);static char *rbuffer = NULL, *dbuffer = NULL;static char *ptr;static unsigned long rsz, dsz, totsize, maxsize;void define_name(text)char *text;{    (void)sprintf(f_info, "%s.info", text);    (void)sprintf(f_rsrc, "%s.rsrc", text);    (void)sprintf(f_data, "%s.data", text);    (void)sprintf(f_text, "%s.text", text);    (void)sprintf(f_bin, "%s.bin", text);    (void)sprintf(f_unix, "%s", text);#ifdef APPLESHARE/* Do not do namestuffing here.  We want to base again on the information in   the info header, so this is delayed*/#endif /* APPLESHARE */}void start_info(info, rsize, dsize)char *info;unsigned long rsize, dsize;{    int rs, ds;    rsz = rsize;    dsz = dsize;    rs = (((rsz + 127) >> 7) << 7);    ds = (((dsz + 127) >> 7) << 7);    totsize = rs + ds + 128;    if(buffer == &(init_buffer[0])) {	buffer = (char *)malloc((unsigned)totsize);    } else if(maxsize < totsize) {	buffer = (char *)realloc(buffer, (unsigned)totsize);    }    maxsize = totsize;    if(buffer == NULL) {	(void)fprintf(stderr, "Insufficient memory, aborting\n");	exit(1);    }    dbuffer = buffer + 128;    rbuffer = dbuffer + ds;    (void)bzero(buffer, (int)totsize);    ptr = buffer;    bcopy(info, ptr, 128);#ifdef AUFS/* Now we do filenaming etc. */    if(mode == APSH) {	aufs_namings();    }#endif /* AUFS */#ifdef APPLEDOUBLE/* Now we do filenaming etc. */    if(mode == APSH) {	appledouble_namings();    }#endif /* APPLEDOUBLE */}void start_rsrc(){    out_buffer = out_ptr = rbuffer;}void start_data(){    out_buffer = out_ptr = dbuffer;}void end_file(){    FILE *fp;    int i, c;    buffer[I_FLAGOFF] &= (~INITED_MASK);    switch(mode) {    case FULL:    case FORK:	fp = fopen(f_info, "w");	if(fp == NULL) {	    perror(f_info);	    exit(1);	}	(void)fwrite(buffer, 1, 128, fp);	(void)fclose(fp);	if(rsz != 0 || mode == FULL) {	    fp = fopen(f_rsrc, "w");	    if(fp == NULL) {		perror(f_rsrc);		exit(1);	    }	    (void)fwrite(rbuffer, 1, (int)rsz, fp);	    (void)fclose(fp);	}	if(dsz != 0 || mode == FULL) {	    fp = fopen(f_data, "w");	    if(fp == NULL) {		perror(f_data);		exit(1);	    }	    (void)fwrite(dbuffer, 1, (int)dsz, fp);	    (void)fclose(fp);	}	break;    case RSRC:	fp = fopen(f_rsrc, "w");	if(fp == NULL) {	    perror(f_rsrc);	    exit(1);	}	(void)fwrite(rbuffer, 1, (int)rsz, fp);	(void)fclose(fp);	break;    case DATA:	fp = fopen(f_data, "w");	if(fp == NULL) {	    perror(f_data);	    exit(1);	}	(void)fwrite(dbuffer, 1, (int)dsz, fp);	(void)fclose(fp);	break;    case TEXT:	fp = fopen(f_text, "w");	if(fp == NULL) {	    perror(f_data);	    exit(1);	}	for(i = 0; i < dsz; i++) {	    c = dbuffer[i];	    if(c == '\012' || c == '\015') {		dbuffer[i] = '\027' -c;	    }	}	(void)fwrite(dbuffer, 1, (int)dsz, fp);	(void)fclose(fp);	break;    case UNIX:	fp = fopen(f_unix, "w");	if(fp == NULL) {	    perror(f_data);	    exit(1);	}	for(i = 0; i < dsz; i++) {	    c = dbuffer[i];	    if(c == '\012' || c == '\015') {		dbuffer[i] = '\027' -c;	    }	}	(void)fwrite(dbuffer, 1, (int)dsz, fp);	(void)fclose(fp);	break;    case MACB:	fp = fopen(f_bin, "w");	if(fp == NULL) {	    perror(f_bin);	    exit(1);	}	if(buffer[I_FLAGOFF + 1] & PROTCT_MASK) {	    buffer[I_LOCKOFF] = 1;	}	buffer[I_FLAGOFF + 1] = 0;	buffer[I_LOCKOFF + 1] = 0;	(void)fwrite(buffer, 1, (int)totsize, fp);	(void)fclose(fp);	break;    case MACS:#ifdef SCAN    case MACI:#endif /* SCAN */	if(buffer[I_FLAGOFF + 1] & PROTCT_MASK) {	    buffer[I_LOCKOFF] = 1;	}	buffer[I_FLAGOFF + 1] = 0;	buffer[I_LOCKOFF + 1] = 0;	(void)fwrite(buffer, 1, (int)totsize, stdout);	break;#ifdef AUFS    case APSH:	fp = fopen(f_info_aufs, "w");	if(fp == NULL) {	    perror(f_info_aufs);	    exit(1);	}	wr_aufs_info(fp);	(void) fclose(fp);	fp = fopen(f_rsrc_aufs, "w");	if(fp == NULL) {	    perror(f_rsrc_aufs);	    exit(1);	}	(void)fwrite(rbuffer, 1, (int)rsz, fp);	(void)fclose(fp);	fp = fopen(f_data, "w");	if(fp == NULL) {	    perror(f_data);	    exit(1);	}	(void)fwrite(dbuffer, 1, (int)dsz, fp);	(void)fclose(fp);	break;#endif /* AUFS */#ifdef APPLEDOUBLE    case APSH:	fp = fopen(f_info_appledouble, "w");	if(fp == NULL) {	    perror(f_info_appledouble);	    exit(1);	}	wr_appledouble_info(fp);	(void)fwrite(rbuffer, 1, (int)rsz, fp);	(void)fclose(fp);	fp = fopen(f_data, "w");	if(fp == NULL) {	    perror(f_data);	    exit(1);	}	(void)fwrite(dbuffer, 1, (int)dsz, fp);	(void)fclose(fp);	break;#endif /* APPLEDOUBLE */    }}#ifdef SCANvoid do_idf(name, kind)char *name;int kind;{    int n;    if(mode != MACI) {	return;    }    n = strlen(name);    (void)bzero(buffer, INFOBYTES);    buffer[I_NAMEOFF + 1] = kind;    put4(buffer + I_DLENOFF, (unsigned long)n);    (void)fwrite(buffer, 1, INFOBYTES, stdout);    if(n != 0) {	(void)fwrite(name, 1, n, stdout);	n = (((n + 127) >> 7) << 7) - n;	while(n-- > 0) {	    (void)fputc(0, stdout);	}    }}#endif /* SCAN */void do_mkdir(name, header)char *name, *header;{struct stat sbuf;FILE *fp;#ifdef NOMKDIRchar command[21]; /* Systems without mkdir system call but more than 14		     char file names?  Ridiculous! */int sysreturn;#endif /* MKDIR */#ifdef APPLESHAREchar dirinfo[I_NAMELEN*3+INFOSZ+10];#endif /* APPLESHARE */#ifndef SCAN    if(mode == MACS) {#else /* SCAN */    if(mode == MACS || mode == MACI) {#endif /* SCAN */        header[I_NAMEOFF] |= 0x80;	(void)fwrite(header, 1, INFOBYTES, stdout);	header[I_NAMEOFF] &= 0x7f;	return;    }#ifdef APPLESHARE    if(mode == APSH) {	(void)bcopy(header, buffer, INFOBYTES);	mk_share_name();    } else {	(void)strcpy(share_name, name);    }#else /* APPLESHARE */    (void)strcpy(share_name, name);#endif /* APPLESHARE */    if(stat(share_name, &sbuf) == -1) {  /* directory doesn't exist */#ifndef NOMKDIR	if(mkdir(share_name, 0777) == -1) {	    (void)fprintf(stderr, "Can't create subdirectory %s\n", share_name);	    exit(1);	}#else /* NOMKDIR */	sprintf(command, "mkdir %s", share_name);	if((sysreturn = system(command)) != 0) {	    (void)fprintf(stderr, "Can't create subdirectory %s\n", share_name);	    exit(sysreturn);	}#endif /* NOMKDIR */    } else {		/* something exists with this name */	if((sbuf.st_mode & S_IFMT) != S_IFDIR) {	    (void)fprintf(stderr, "Directory name %s already in use\n",		share_name);	    exit(1);	}    }    (void)chdir(share_name);#ifdef APPLESHARE#ifdef AUFS    if(mode == APSH) {	if(stat(rsrcdir, &sbuf) == -1) {  /* directory doesn't exist */	    if(mkdir(rsrcdir, 0777) == -1) {	 	(void)fprintf(stderr, "Can't create subdirectory %s\n",			rsrcdir);	 	exit(1);	    }	} else {	    if((sbuf.st_mode & S_IFMT) != S_IFDIR) {		(void)fprintf(stderr, "Directory name %s already in use\n",			rsrcdir);		exit(1);	    }

⌨️ 快捷键说明

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