예제 #1
0
파일: gcf-rw.c 프로젝트: hinike/MyDocuments
int main(int argc, char *argv[]){
	char*gcf_name;
	archive_t gcf=NULL;
	RTinitPopt(&argc,&argv,options,1,-1,&gcf_name,NULL,"([-c] <gcf> (<dir>|<file>)*) | (-x <gcf> [<dir>|<pattern>])",
		"Tool for creating and extracting GCF archives\n\nOptions");
	compression_policy_compile(policy);
	if (operation==GCF_EXTRACT) {
		char *out_name=RTinitNextArg();
		archive_t dir;
		if(out_name){
			if(RTinitNextArg()){
				Fatal(1,error,"extraction uses gcf -x <gcf> [<dir>|<pattern>]");
			}
			if (strstr(out_name,"%s")) {
				dir=arch_fmt(out_name,file_input,file_output,blocksize);
			} else {
				dir=arch_dir_create(out_name,blocksize,force?DELETE_ALL:DELETE_NONE);
			}
		} else {
			dir=arch_dir_open(".",blocksize);
		}
		if (is_a_dir(gcf_name)){
			gcf=arch_dir_open(gcf_name,blocksize);
		} else {
			gcf=arch_gcf_read(raf_unistd(gcf_name));
		}
		archive_copy(gcf,"auto",dir,NULL,blocksize);
		arch_close(&dir);
		arch_close(&gcf);
	} else {
		if (operation==GCF_FILE){
			gcf=arch_gcf_create(raf_unistd(gcf_name),blocksize,blocksize*blockcount,0,1);
		} else {
			gcf=arch_dir_create(gcf_name,blocksize,force?DELETE_ALL:DELETE_NONE);
		}
		for(;;){
			char *input_name=RTinitNextArg();
			if (!input_name) break;
			if (is_a_dir(input_name)){
				Warning(info,"copying contents of %s",input_name);
				archive_t dir=arch_dir_open(input_name,blocksize);
				archive_copy(dir,NULL,gcf,get_compression,blocksize);
				arch_close(&dir);
			} else {
				Warning(info,"copying %s",input_name);
				stream_t is=file_input(input_name);
				stream_t os=arch_write(gcf,input_name,get_compression(input_name),1);
				char buf[blocksize];
				for(;;){
					int len=stream_read_max(is,buf,blocksize);
					if (len) stream_write(os,buf,len);
					if(len<blocksize) break;
				}
				stream_close(&is);
				stream_close(&os);	
			}
		}
		arch_close(&gcf);
	}
}
예제 #2
0
파일: gcf-tool.c 프로젝트: Meijuh/ltsmin
static void gcf_extract(){
    char *gcf_name=HREnextArg();
    if (gcf_name==NULL) {
        Abort("missing <gcf archive> argument");
    }
    archive_t arch=arch_gcf_read(raf_unistd(gcf_name));
    archive_t dir;
    if (outputdir) {
        dir=arch_dir_create(outputdir,blocksize,force?DELETE_ALL:DELETE_NONE);
    } else {
        dir=arch_dir_open(".",blocksize);
    }
    char*pattern=HREnextArg();
    do {
        archive_copy(arch,dir,NULL,blocksize,pattern);
    } while((pattern=HREnextArg()));
    arch_close(&dir);
    arch_close(&arch);
}
예제 #3
0
파일: sigmin-lib.c 프로젝트: Meijuh/ltsmin
void lts_write(char *name,lts_t lts,string_set_t filter,int segments){
    int format=lts_guess_format(name);
    lts_type_t ltstype=lts->ltstype;
    switch(format){
    case LTS_IMCA:
        lts_write_imca(name,lts);
        break;
    case LTS_TRA:
        lts_write_tra(name,lts);
        break;
    case LTS_PG:
        lts_write_pg(name,lts);
        break;
    case LTS_DIR:
        if (lts_type_get_state_length(ltstype)==0
            && lts_type_get_state_label_count(ltstype)==0
            && lts_type_get_edge_label_count(ltstype)==1
        ){
            archive_t archive=arch_dir_create(name,65536,DELETE_ALL);
            lts_write_dir(archive,NULL,lts,segments);
            arch_close(&archive);
            break;
        } else // fall through
    default: {
        lts_file_t src=lts_reader(lts,segments,NULL);
        lts_file_t dst;
        if (filter==NULL){
            dst=lts_file_create(name,lts->ltstype,segments,src);
        } else {
            dst=lts_file_create_filter(name,lts->ltstype,filter,segments,src);
        }
        int T=lts_type_get_type_count(lts->ltstype);
        for(int i=0;i<T;i++){
            if (lts->values[i]) lts_file_set_table(dst,i,lts->values[i]);
        }
        lts_file_copy(src,dst);
        lts_file_close(src);
        lts_file_close(dst);
        break;
        }
    }
}
예제 #4
0
파일: gcf-tool.c 프로젝트: Meijuh/ltsmin
static void gcf_decompress(){
    char*source;
    char target[LTSMIN_PATHNAME_MAX];
    while((source=HREnextArg())){
        if (has_extension(source,".gzf")){
            strncpy(target,source,strlen(source)-4);
            target[strlen(source)-4]=0;
            stream_t is=file_input(source);
            stream_t os=file_output(target);
            char *code=DSreadSA(is);
            is=stream_add_code(is,code);
            char buf[blocksize];
            for(;;){
                int len=stream_read_max(is,buf,blocksize);
                if (len) stream_write(os,buf,len);
                if(len<blocksize) break;
            }
            stream_close(&is);
            stream_close(&os);
            if (!keep) recursive_erase(source);
        } else if (has_extension(source,".gcf")||has_extension(source,".zip")){
            strncpy(target,source,strlen(source)-4);
            target[strlen(source)-4]=0;
            archive_t arch_in;
            if (has_extension(source,".gcf")){
                arch_in=arch_gcf_read(raf_unistd(source));
            } else {
                arch_in=arch_zip_read(source,blocksize);
            }
            archive_t arch_out=arch_dir_create(target,blocksize,force?DELETE_ALL:DELETE_NONE);
            archive_copy(arch_in,arch_out,NULL,blocksize,NULL);
            arch_close(&arch_in);
            arch_close(&arch_out);
            if (!keep) recursive_erase(source);
        } else {
            Abort("source %s does not have known extension",source);
        }
    }
}