示例#1
0
文件: ldebug.c 项目: crazii/mameplus
l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
	va_list argp;
	va_start(argp, fmt);
	addinfo(L, luaO_pushvfstring(L, fmt, argp));
	va_end(argp);
	luaG_errormsg(L);
}
示例#2
0
void luaG_runerror_ok (lua_State *L, const char *fmt, ...) {
  //logt("luaG_runerror");
  va_list argp;
  va_start(argp, fmt);
  addinfo(L, luaO_pushvfstring(L, fmt, argp));
  va_end(argp);
  luaG_errormsg(L);
}
示例#3
0
文件: lz78.c 项目: giannix90/lz78
/*--Function for compress file--*/
void 
compress(char * str_in,lz78_compressor * in, struct bitio* file)
{
	char* buf=malloc(16); 
	uint64_t inp=0;
	int father=0;
	int child=0;	
	int go=1;
	uint64_t c=0;
	int flag=0;
	int ret=0;

	struct bitio*file_out=bit_open(in->output_file,1);

	/*After compress i put the info of the file at the beginning of the file*/
	info* ret_info=malloc(sizeof(info));

	/*Put the info at the beginning of the file and return a structure with the info*/
	ret_info=addinfo(file_out,file,in->file_to_compress,0,in->d_max);
	in->number_of_code^=in->number_of_code; //XOR

	reset:

	if(flag==0){
		/*Only for the first character*/
		ret=bit_read(file,(u_int)8,&inp);
		buf[1]=(char)(inp&((1UL<<8)-1));
		//printf("Ric: %X\n",buf[1] & 0xff);
	}


	printf("-----------\n");
	while(go==1){
		

		while(look_up_and_add(father,buf[1],in)==0){//repeat the operation until i don't fint a node =>scroll the tree

			buf[0]=buf[1];		
			father=hash_table[hash(child,(char)(inp&((1UL<<8)-1)))].child_index;
			//printf("Padre: %d\n",father);
			ret=bit_read(file,(u_int)8,&inp);	
			buf[1]=(char)(inp&((1UL<<8)-1));
			//printf("Ric: %X\n",buf[1] & 0xff);
			child=father;
		}

		//printf("Output: %X Char %c\n",father & 0xff,buf[1]);
		bit_write(file_out,16, (int) father);
		in->number_of_code++;
		father=0; 	// restart from the root
		child=0;
		c++;
		if(ret==0)break;
		if(in->counter_child_tree>=in->d_max-1){
			//I need to empty the tree and restart the compressio from the current position
			free(hash_table);
			in->counter_child_tree=0;
			hash_init(6700417,in);
			goto reset;
		};	
	
	}

	flush_out_buffer(file_out);
	//add the SHA-1 of the compressed-file in the header
	
	long old_index=ftell(file_out->f);//save the curren pointer to position of the file
	struct bitio* file_out_rd=bit_open(in->output_file,0);//I re-open the output file but in in read mode this time
	getSHA1(88,in->number_of_code,file_out_rd,ret_info); //I do the SHA-1 over the whole file
	bit_close(file_out_rd);
	fseek(file_out->f,(long)0x40,SEEK_SET); //I write the SHA-1 hash in the correct position
	//printf("SHA-1: ");
	for (int i = 0; i < 20; i ++) {
		bit_write(file_out,(u_int)8*sizeof(unsigned char),(unsigned char)ret_info->sha1[i]);
       // printf(" %2x", (unsigned char)ret_info->sha1[i]);
    }

	bit_write(file_out,(u_int)32,in->number_of_code);

    //printf("\n");
    flush_out_buffer(file_out);

	fseek(file_out->f,old_index,SEEK_SET); // restore the pointer of the file in order to close the file in the rigth way
	//close the file descriptor
	bit_close(file_out);
}