Esempio n. 1
0
/*Func: opt_x()
 * lseek 8 bytes from the beginning of arc
 * read the file name from argv and ready to search
 * find the file name from CLA
 * read each header file and store it in info strct
 * create a file by using open(info->name,RDWR_0|CREATE_O,0666)
 * set header of a new file 
 * copy and paste the rest of the content from arch (use info->size)
 */
void opt_x(int argc, char **argv,int arch, int *filecount, int *fcalled, file *info){
	char cur_name[16];
	char *null_cur_name;
	char *null_info_name;
	int newfile=0;
	int fbyte_max=120;
	int fbyte=0;
	struct stat archinfo;
	fstat(arch,&archinfo);

	fbyte_max = archinfo.st_size;	

	for((*fcalled) = 0; (*fcalled)<filecount[3];++(*fcalled)){
		fbyte = 0;

		lseek(arch,8,SEEK_SET);
		read_filename(argv,filecount,2,fcalled,info);//get name from CLA
		for(fbyte_max ; fbyte < fbyte_max; fbyte++ ){ 
			//for the end of file	
			read(arch, cur_name,16); //get name of the file from arch

			null_cur_name = null_str(cur_name,16);//turn both of the name into
			null_cur_name = shrt_str(null_cur_name);
			null_info_name = null_str(info->name,16);//null terminated strings
			null_info_name = shrt_str(null_info_name);
			if(!strcmp(null_cur_name, null_info_name)){
				put_header(arch, info);
				remove(null_info_name);
				newfile = open(null_info_name, O_RDWR|O_CREAT,0666);
				info->desc = arch;
				lseek(arch,2,SEEK_CUR);
				write_file_content(newfile, info);
				if(atoi(info->size)%2!=0)
					lseek(arch,1,SEEK_CUR);
				utime(null_info_name, atoi(info->time));
				chmod(null_info_name, strtol(info->mode,NULL,8));
				break;
			}else{
				iter_arch(arch,&fbyte,info);
			}
		}//where the for EOF ends
		if(fbyte>=fbyte_max)
			printf(CY"Warning: File(\"%s\") doesn't documented in archeive.\nThe other file has successfully extract\n"NC,null_info_name);
	}
	/*	printf("info->name: %.16s\n",info->name);
		printf("info->time: %.12s\n",info->time);
		printf("info->uid: %.6s\n",info->uid);
		printf("info->gid: %.6s\n",info->gid);
		printf("info->mode: %.8s\n",info->mode);
		printf("info->size: %.10s\n",info->size);
		*/

	return;
}
Esempio n. 2
0
/*Func: print_mode()
 * print mode in a single line
 */
void print_mode(file *info){
	char *mode = null_str(info->mode,8);
	mode = shrt_str(mode);
	printf( (strtol(mode,NULL,8) & S_IRUSR) ? "r":"-");
	printf( (strtol(mode,NULL,8) & S_IWUSR) ? "w":"-");
	printf( (strtol(mode,NULL,8) & S_IXUSR) ? "x":"-");
	printf( (strtol(mode,NULL,8) & S_IRGRP) ? "r":"-");
	printf( (strtol(mode,NULL,8) & S_IWGRP) ? "w":"-");
	printf( (strtol(mode,NULL,8) & S_IXGRP) ? "x":"-");
	printf( (strtol(mode,NULL,8) & S_IROTH) ? "r":"-");
	printf( (strtol(mode,NULL,8) & S_IWOTH) ? "w":"-");
	printf( (strtol(mode,NULL,8) & S_IXOTH) ? "x":"-");

}
Esempio n. 3
0
void opt_v(int argc, char **argv,int arch, int *filecount, int *fcalled, file *info){
	int fbyte_max=1;
	int fbyte=0;
	char cur_name[16];
	char *null_cur_name;
	char null_time[13];
	struct stat archinfo;
	fstat(arch,&archinfo);

	fbyte_max = archinfo.st_size;
	fbyte = 0;
	lseek(arch,8,SEEK_SET);

	for(fbyte=0; fbyte < fbyte_max; fbyte++){
		read(arch,cur_name,16);
		null_cur_name = null_str(cur_name,16);
		null_cur_name = shrt_str(null_cur_name);
		(fbyte) += 60+atoi(info->size);



		if(fbyte < fbyte_max){
			put_header(arch,info);
			lseek(arch,atoi(info->size)+2,SEEK_CUR);
			print_mode(info);
			printf("%.6s",info->uid);
			printf("/%.6s",info->gid);
			printf("%.10s",info->size);
			//null_time= null_str(info->time,12);
			//null_time= shrt_str(null_time);
			//strftime(null_time,12,"%c",info->time);
			printf("%.12s",info->time);
			printf("%.16s",null_cur_name);
			printf("\n");
			if(atoi(info->size)%2!=0){
				lseek(arch,1,SEEK_CUR);
				(fbyte)++;
			}
		}
	}

}
Esempio n. 4
0
void opt_t(int argc, char **argv,int arch, int *filecount, int *fcalled, file *info){
	int fbyte_max=1;
	int fbyte=0;
	char cur_name[16];
	char *null_cur_name;
	struct stat archinfo;
	fstat(arch,&archinfo);

	fbyte_max = archinfo.st_size;
	fbyte = 0;
	lseek(arch,8,SEEK_SET);

	for(fbyte=0; fbyte < fbyte_max; fbyte++){
		read(arch,cur_name,16);
		null_cur_name = null_str(cur_name,16);
		null_cur_name = shrt_str(null_cur_name);
		iter_arch(arch,&fbyte,info);
		if(fbyte < fbyte_max)
			printf("%.16s\n",null_cur_name);
	}

}
Esempio n. 5
0
/*Func: write_file_header2()
 * write to a file header to a temp file
 * check the error 
 */
void write_file_header2(int tempfile,char* name,file *info){
	char* str=0;
	str = null_str(name,16);
	write(tempfile,str,16);

	str = null_str(info->time,12);
	write(tempfile,str,12);

	str = null_str(info->uid,6);
	write(tempfile,str,6);

	str = null_str(info->gid,6);
	write(tempfile,str,6);

	str = null_str(info->mode,8);
	write(tempfile,str,8);

	str = null_str(info->size,10);
	write(tempfile,str,10);

	write(tempfile,"`\n",2);
	return ;
}
Esempio n. 6
0
/*Func: write_file_header()
 * write to a file header to a temp file
 * check the error 
 */
void write_file_header(int tempfile,file *info){
	//FIXME: Continue here
	char* str=0;
	str = null_str(info->name,16);
	write(tempfile,str,16);

	str = null_str(info->time,12);
	write(tempfile,str,12);

	str = null_str(info->uid,6);
	write(tempfile,str,6);

	str = null_str(info->gid,6);
	write(tempfile,str,6);

	str = null_str(info->mode,8);
	write(tempfile,str,8);

	str = null_str(info->size,10);
	write(tempfile,str,10);

	write(tempfile,"`\n",2);
	return ;
}
Esempio n. 7
0
void opt_d(int argc, char **argv,int *arch, int *filecount, int *fcalled, file *info){
	int fbyte_max=1;
	int fbyte=0;
	int size = 0;
	int tsize = 0;
	int tempfile=0;
	int temparch =0;
	char cur_name[16];
	char *null_cur_name;
	char *null_info_name;
	char *str_buf;
	struct stat archinfo;
	struct stat temparch_info;


	fstat((*arch),&archinfo);

	temparch = open_file("temp_arch",1);

	fbyte_max = archinfo.st_size;
	//for fcalled goes here
	fbyte = 0;
	lseek((*arch),8,SEEK_SET);
	read_filename(argv,filecount,4,fcalled,info);

	for(fbyte=0; fbyte < fbyte_max; ){
		read((*arch),cur_name,16);
		null_cur_name = null_str(cur_name,16);
		null_cur_name = shrt_str(null_cur_name);
		null_info_name= null_str(info->name,16);
		null_info_name = shrt_str(null_info_name);

		(fbyte) += 60+atoi(info->size);

		if(fbyte < fbyte_max){
			if(!strcmp(null_cur_name,null_info_name)){//equal
				iter_arch((*arch), &fbyte, info);
				(fbyte) -= 60+atoi(info->size);
			}else{
				tempfile = 0;
				put_header((*arch), info);
				lseek((*arch),2,SEEK_CUR);

				/*printf("\ninfo->name: %.16s\n",info->name);
				  printf("cur name: %.16s\n",cur_name);
				  printf("info->time: %.12s\n",info->time);
				  printf("info->uid: %.6s\n",info->uid);
				  printf("info->gid: %.6s\n",info->gid);
				  printf("info->mode: %.8s\n",info->mode);
				  printf("info->size: %.10s\n",info->size);
				  */

				//so now the header are read correctly
				//Time to put info in files
				tempfile = create_tempfile();
				write_file_header2(tempfile,cur_name,info);
				info->desc = (*arch);
				write_file_content(tempfile,info);
				all_in_arch(tempfile,temparch,fcalled,info);

				if(tsize%2!=0){
					write(temparch,"\n",1);
				}

				(*fcalled)++;
				close(tempfile);
				if(atoi(info->size)%2!=0)
					lseek((*arch),1,SEEK_CUR);

			}
		}
	}
	//FIXME: the temp_arch has the correct info but when copy to arch itself has wrong info.	
	fstat(temparch,&temparch_info);
	size = temparch_info.st_size;
	printf("temparch.size: %d\n",size);
	str_buf = malloc(sizeof(char)*size);
	read(temparch,str_buf,size);
	//ftruncate((*arch),(sizeof(char))*size);
	lseek((*arch),0,SEEK_SET);
	write((*arch),str_buf,size);
	free(str_buf);
	close(temparch);
	//remove("temp_arch");
}
Esempio n. 8
0
inline
basic_cstring<CharT>::basic_cstring( pointer s )
: m_begin( s ? s : null_str() )
, m_end  ( m_begin + (s ? traits_type::length( s ) : 0 ) )
{
}
Esempio n. 9
0
inline
basic_cstring<CharT>::basic_cstring()
: m_begin( null_str() )
, m_end( m_begin )
{
}
Esempio n. 10
0
void opt_d(int argc, char **argv,int *arch, int *filecount, int *fcalled, file *info){
	int fbyte_max=1;
	int fbyte=0;
	int size = 0;
	int tempfile=0;
	int temparch =0;
	char cur_name[16];
	char *null_cur_name;
	char *null_info_name;
	char *str_buf;
	struct stat archinfo;
	struct stat temparch_info;
	

	fstat((*arch),&archinfo);

	temparch = create_tempfile();
	write(temparch,"!<arch>\n",8);
	fstat(temparch,&temparch_info);

	fbyte_max = archinfo.st_size;
	
	fbyte = 0;
	lseek((*arch),8,SEEK_SET);
	read_filename(argv,filecount,4,fcalled,info);

	for(fbyte=0; fbyte < fbyte_max; fbyte++){
		read((*arch),cur_name,16);
		null_cur_name = null_str(cur_name,16);
		null_cur_name = shrt_str(null_cur_name);
		null_info_name= null_str(info->name,16);
		null_info_name = shrt_str(null_info_name);

		(fbyte) += 60+atoi(info->size);

		if(fbyte < fbyte_max){
			if(!strcmp(null_cur_name,null_info_name)){
				iter_arch((*arch), &fbyte, info);

				if(atoi(info->size)%2!=0){
					lseek((*arch),1,SEEK_CUR);
					(fbyte)++;
				}
			}else{
				read_header(argc, argv, filecount, 4, fcalled, info);
				tempfile = create_tempfile();
				write_file_header(tempfile,info);
				info->desc = (*arch);
				write_file_content(tempfile,info);
				all_in_arch(tempfile,temparch,fcalled,info);
				close(tempfile);
			}
		}
	}

	remove(argv[1]);
	(*arch) = open_file(argv[1],1);
	size = temparch_info.st_size;
	str_buf = malloc(sizeof(char)*size);
	read(temparch,str_buf,size);
	close(temparch);
}