Exemplo n.º 1
0
GLOBAL(void)jinit_compress_master(j_compress_ptr cinfo)
{
  /* Initialize master control (includes parameter checking/processing) */
  jinit_c_master_control(cinfo);

  /* Preprocessing */

  #ifndef JPEG_ENC_OPT
    /* Forward DCT */
    #ifndef DBUG_pk0157s
      jinit_forward_dct(cinfo);
    #endif 
  #endif 
  /* Entropy encoding: either Huffman or arithmetic coding. */

  #ifndef JPEG_ENC_OPT  //bmy 04.12.29 jpeg_enc_opt +    
    jinit_huff_encoder(cinfo);
  #endif //bmy 04.12.29 jpeg_enc_opt +  

  /* Need a full-image coefficient buffer in any multi-pass mode. */
  jinit_c_coef_controller(cinfo);



  /* We can now tell the memory manager to allocate virtual arrays. */
  // realize_virt_arrays ((j_common_ptr) cinfo);

  /* Write the datastream header (SOI) immediately.
   * Frame and scan headers are postponed till later.
   * This lets application insert special markers after the SOI.
   */
  write_file_header(cinfo);
}
Exemplo n.º 2
0
int	analyse_dir(DIR *dir, int tar, t_count *count, char *path)
{
  char		*full_path;
  struct dirent	*directory;
  static int	loop = 0;
  int		is_directory;

  if (++loop && loop >= 40000 && write(2, "Too many files\n", 15) > -2)
    return (0);
  if ((full_path = NULL) == 0 &&
      ((directory = readdir(dir)) == NULL || path == NULL))
    return (0);
  if (strcmp(directory->d_name, "..") == 0 ||
      strcmp(directory->d_name, ".") == 0)
    return (analyse_dir(dir, tar, count, path));
  if ((is_directory = is_dir(directory->d_name, path)) == -1 ||
      ((full_path = set_fullpath(directory->d_name, path, full_path))) == NULL)
    return (0);
  if (is_directory == 0)
    write_file_header(full_path, tar, count);
  else if (is_directory == 1)
    write_dir_header(full_path, tar, count);
  if (path != NULL && directory != NULL)
    return (analyse_dir(dir, tar, count, path));
  return (0);
}
Exemplo n.º 3
0
int file_msg_logger::open(const char* filename)
{
  fd_mut.lock();
  if(fd != -1) {
    ERROR("file already open\n");
    fd_mut.unlock();
    return -1;
  }
  
  fd = ::open(filename,O_WRONLY | O_CREAT | O_APPEND,
	      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if(fd < 0) {
    ERROR("could not open file '%s': %s", filename, strerror(errno));
    fd_mut.unlock();
    return -1;
  }

  // need not to work for 100% (the access will not to be locked if opened from
  // another logger instance)
  off_t pos = lseek(fd, 0, SEEK_END);
  if (pos == 0) write_file_header();

  fd_mut.unlock();
  return 0;
}
Exemplo n.º 4
0
/*Func: opt_q()
 * If the -q has been specified, this function is called
 * Read from file in argv[n]; n is filecount[lq|cq]
 * Format the input and put the info. in temp file
 * Read from temp into arch
 */
void opt_q(int argc, char **argv,int arch, int *filecount, int *fcalled, file *info){
	int tempfile = 0;
	for((*fcalled) = 0; (*fcalled)<filecount[1];++(*fcalled)){
		tempfile = 0;
		read_header(argc,argv,filecount, 0, fcalled,info );
		tempfile = create_tempfile();
		write_file_header(tempfile, info);
		write_file_content(tempfile, info);
		all_in_arch(tempfile,arch,fcalled ,info);
		close(tempfile);
	}
	(*fcalled)=0;
	return ;
}
Exemplo n.º 5
0
void CompressList(LPCSTR in_name, xr_vector<char*>* list, xr_vector<char*>* fl_list, BOOL bFast, BOOL make_pack, LPCSTR copy_path)
{
	if (!list->empty() && in_name && in_name[0]){
		string256		caption;

		VERIFY			('\\'!=in_name[xr_strlen(in_name)-1]);
		string_path		tgt_folder;
		_splitpath		(in_name,0,0,tgt_folder,0);

		int pack_num	= 0;
		if (make_pack)
			OpenPack	(tgt_folder,pack_num++);

		for (u32 it=0; it<fl_list->size(); it++)
			write_file_header	((*fl_list)[it],0,0,0,0);

		c_heap			= xr_alloc<u8> (LZO1X_999_MEM_COMPRESS);
		//***main process***: BEGIN
		for (u32 it=0; it<list->size(); it++){
			sprintf				(caption,"Compress files: %d/%d - %d%%",it,list->size(),(it*100)/list->size());
			SetWindowText		(GetConsoleWindow(),caption);
			printf				("\n%-80s   ",(*list)[it]);
			if (make_pack){
				if (fs->tell()>XRP_MAX_SIZE){
					ClosePack	();
					OpenPack	(tgt_folder,pack_num++);
				}
				Compress		((*list)[it],in_name,bFast);
			}
			if (copy_path && copy_path[0]){
				string_path		src_fn, dst_fn; 
				strconcat		(sizeof(src_fn),src_fn,in_name,"\\",(*list)[it]);
				strconcat		(sizeof(dst_fn),dst_fn,copy_path,tgt_folder,"\\",(*list)[it]);
				printf			(" + COPY");
				int age			= FS.get_file_age(src_fn);
				FS.file_copy	(src_fn,dst_fn);
				FS.set_file_age	(dst_fn,age);
			}
		}
		if (make_pack)
			ClosePack			();

		xr_free					(c_heap);
		//***main process***: END
	} else {
		Msg						("ERROR: folder not found.");
	}
}
void XMLFileBenchmarkListener::begin_suite(
    const BenchmarkSuite&   benchmark_suite)
{
    if (!impl->m_has_header)
    {
        write_file_header();
        impl->m_has_header = true;
    }

    fprintf(
        impl->m_file,
        "%s<benchmarksuite name=\"%s\">\n",
        impl->m_indenter.c_str(),
        benchmark_suite.get_name());

    ++impl->m_indenter;
}
Exemplo n.º 7
0
void
output_table(FILE *fp)
{
	int i;
	int table_position;

	write_file_header(fp);

	fprintf (fp,
			 "int _XfeNumCommands = %d;\n", num_commands);

	fprintf (fp,
			 "int _XfeCommandIndices[] = {\n");

	table_position = 0;
	for (i = 0; i < num_commands; i ++)
		{
			fprintf (fp, "\t%d,", table_position);
			if (i % 4 == 0) fprintf (fp, "\n");
			table_position += strlen(commands[i].string) + 1;
		}

	fprintf (fp,
			 "};\n");

	fprintf (fp, 
			 "char _XfeCommands[] = \n");

	table_position = 0;
	for (i = 0; i < num_commands; i ++)
		{
			fprintf (fp, "\t/* %10d */ \"%s\\0\"\n", table_position, commands[i].string);

			table_position += strlen(commands[i].string) + 1;
		}

	/* write out the closing semicolon. */
	fprintf (fp, ";\n");
	fclose(fp);
}
Exemplo n.º 8
0
void
output_header(FILE *fp)
{
	int table_position;
	int i;

	write_file_header(fp);

	fprintf (fp, "extern char _XfeCommands[];\n");
	fprintf (fp, "extern int _XfeNumCommands;\n");
	fprintf (fp, "extern int _XfeCommandIndices[];\n");

	table_position = 0;
	for (i = 0; i < num_commands; i ++)
		{
			fprintf (fp, "#define %s ((char*)&_XfeCommands[ %d ])\n", commands[i].command, table_position);
			
			table_position += strlen(commands[i].string) + 1;
		}

	fclose(fp);
}
Exemplo n.º 9
0
void xrCompressor::PerformWork()
{
	if (!files_list->empty() && target_name.size())
	{
		string256		caption;

		int pack_num	= 0;
		OpenPack		(target_name.c_str(), pack_num++);

		for (u32 it=0; it<folders_list->size(); it++)
			write_file_header	((*folders_list)[it],0,0,0,0);

		if(!bStoreFiles)
			c_heap			= xr_alloc<u8> (LZO1X_999_MEM_COMPRESS);

		for (u32 it=0; it<files_list->size(); it++)
		{
			xr_sprintf				(caption,"Compress files: %d/%d - %d%%",it,files_list->size(),(it*100)/files_list->size());
			SetWindowText		(GetConsoleWindow(),caption);
			printf				("\n%-80s   ",(*files_list)[it]);

			if (fs_pack_writer->tell()>XRP_MAX_SIZE)
			{
				ClosePack		();
				OpenPack		(target_name.c_str(), pack_num++);
			}
			CompressOne			((*files_list)[it]);
		}
		ClosePack				();

		if(!bStoreFiles)
			xr_free				(c_heap);
	}else 
	{
		Msg						("ERROR: folder not found.");
	}
}
int main(int argc, char *argv[]){

  void *this_arte_packet;
  this_arte_packet = malloc(MAX_PACKET_BYTES);

  int sourcename;
  packetType_t sourcetype;
  int ok_packet;
  int packet_count = 0;
  char blank_data[MAX_PACKET_BYTES];
  
  //this_arte_packet = (void *)&(blank_data[0]);

  char input_filename[200], output_filename[200];

  init_filenames(argc, argv, 
		 input_filename, output_filename, 
		 &sourcename, &sourcetype);

  printf("sourcename:%d sourcetype:%c spike_sourcetype:%c\n", 
	 sourcename, sourcetype, NETCOM_UDP_SPIKE);


    if(this_arte_packet == NULL){
    printf("Memory error, sorry :[\n");
    exit(1);
  }

  in_f = fopen(input_filename, "rb");
  out_f = fopen(output_filename, "wb");

  if(in_f == NULL)
    printf("Bad in file: %s\n", input_filename);
  if(out_f == NULL)
    printf("Bad out_file: %s\n", output_filename);
  
  if(in_f == NULL || out_f == NULL)
    exit(1);

  ok_packet = false;
  while(!ok_packet & (feof(in_f) == 0) ){
    ok_packet = get_next_packet(this_arte_packet, sourcename, sourcetype);
  }
  printf("finished looking...\n");  fflush(stdout);

  write_file_header(this_arte_packet, argc, argv, sourcetype);
  
  printf("Finished writing file header.\n"); fflush(stdout);
  
  if( sourcetype == NETCOM_UDP_SPIKE){
    spike_net_t* test_spike = (spike_net_t*)this_arte_packet;
    printf("test before first write_mwl: name:%d n_chans:%d\n", 
	   test_spike->name, test_spike->n_chans);
  }
  
  write_mwl(this_arte_packet, sourcetype);
  
  printf("Finished writing first packet with write_mwl.\n"); fflush(stdout);

  if( sourcetype == NETCOM_UDP_SPIKE){
    spike_net_t* test_spike = (spike_net_t*)this_arte_packet;
    printf("test before loop: name:%d n_chans:%d\n", 
	   test_spike->name, test_spike->n_chans);
  }
  
  if(true){
    
    while( feof(in_f) == 0){
      ok_packet = get_next_packet(this_arte_packet, sourcename, sourcetype);
      if(verbose){
	if (ok_packet){
	  printf("This packet was ok:\n");}
	else {
	  printf("This packet was not ok:\n");}
	
	print_packet(this_arte_packet, sourcetype);
      }
      
      if(ok_packet){
	
	fflush(out_f);
	//printf("in loop...\n");
	if( sourcetype == NETCOM_UDP_SPIKE){
	  spike_net_t* test_spike = (spike_net_t*)this_arte_packet;
	  //printf("test before write_mwl in loop: name:%d n_chans:%d\n", 
	  //	 test_spike->name, test_spike->n_chans);
	}
	
   	write_mwl(this_arte_packet, sourcetype);
	packet_count++;
      }
      interactive_wait("message1\n");
    }
    
  } // end if(true)
    //free(this_arte_packet);

  printf("finished. Wrote %d packet(s)\n", packet_count);
  exit(0);
  
}
Exemplo n.º 11
0
void xrCompressor::CompressOne(LPCSTR path)
{
	filesTOTAL		++;

	if (testSKIP(path))	
	{
		filesSKIP	++;
		printf		(" - a SKIP");
		Msg			("%-80s   - SKIP",path);
		return;
	}

	string_path		fn;				
	strconcat		(sizeof(fn), fn, target_name.c_str(), "\\", path);

	if (::GetFileAttributes(fn)==u32(-1))
	{
		filesSKIP	++;
		printf		(" - CAN'T OPEN");
		Msg			("%-80s   - CAN'T OPEN",path);
		return;
	}

	IReader*		src				=	FS.r_open	(fn);
	if (0==src)
	{
		filesSKIP	++;
		printf		(" - CAN'T OPEN");
		Msg			("%-80s   - CAN'T OPEN",path);
		return;
	}

	bytesSRC						+=	src->length	();
	u32			c_crc32				=	crc32		(src->pointer(),src->length());
	u32			c_ptr				=	0;
	u32			c_size_real			=	0;
	u32			c_size_compressed	=	0;
	u32			a_tests				=	0;

	ALIAS*		A					=	testALIAS	(src,c_crc32,a_tests);
	printf							("%3da ",a_tests);
	if(A) 
	{
		filesALIAS			++;
		printf				("ALIAS");
		Msg					("%-80s   - ALIAS (%s)",path,A->path);

		// Alias found
		c_ptr				= A->c_ptr;
		c_size_real			= A->c_size_real;
		c_size_compressed	= A->c_size_compressed;
	} else 
	{
		if (testVFS(path))	
		{
			filesVFS			++;

			// Write into BaseFS
			c_ptr				= fs_pack_writer->tell	();
			c_size_real			= src->length();
			c_size_compressed	= src->length();
			fs_pack_writer->w	(src->pointer(),c_size_real);
			printf				("VFS");
			Msg					("%-80s   - VFS",path);
		} else 
		{ //if(testVFS(path))
			// Compress into BaseFS
			c_ptr				=	fs_pack_writer->tell();
			c_size_real			=	src->length();
			if (0!=c_size_real)
			{
				u32 c_size_max		=	rtc_csize		(src->length());
				u8*	c_data			=	xr_alloc<u8>	(c_size_max);

				t_compress.Begin	();

				c_size_compressed	= c_size_max;
				if (bFast)
				{		
					R_ASSERT(LZO_E_OK == lzo1x_1_compress	((u8*)src->pointer(),c_size_real,c_data,&c_size_compressed,c_heap));
				}else
				{
					R_ASSERT(LZO_E_OK == lzo1x_999_compress	((u8*)src->pointer(),c_size_real,c_data,&c_size_compressed,c_heap));
				}

				t_compress.End		();

				if ((c_size_compressed+16) >= c_size_real)
				{
					// Failed to compress - revert to VFS
					filesVFS			++;
					c_size_compressed	= c_size_real;
					fs_pack_writer->w	(src->pointer(),c_size_real);
					printf				("VFS (R)");
					Msg					("%-80s   - VFS (R)",path);
				} else 
				{
					// Compressed OK - optimize
					if (!bFast)
					{
						u8*		c_out	= xr_alloc<u8>	(c_size_real);
						u32		c_orig	= c_size_real;
						R_ASSERT		(LZO_E_OK	== lzo1x_optimize	(c_data,c_size_compressed,c_out,&c_orig, NULL));
						R_ASSERT		(c_orig		== c_size_real		);
						xr_free			(c_out);
					}//bFast
					fs_pack_writer->w	(c_data,c_size_compressed);
					printf				("%3.1f%%",	100.f*float(c_size_compressed)/float(src->length()));
					Msg					("%-80s   - OK (%3.1f%%)",path,100.f*float(c_size_compressed)/float(src->length()));
				}

				// cleanup
				xr_free		(c_data);
			}else
			{ //0!=c_size_real
				filesVFS				++;
				c_size_compressed		= c_size_real;
				printf					("VFS (R)");
				Msg						("%-80s   - EMPTY FILE",path);
			}
		}//test VFS
	} //(A)

	// Write description
	write_file_header		(path,c_crc32,c_ptr,c_size_real,c_size_compressed);

	if (0==A)	
	{
		// Register for future aliasing
		ALIAS				R;
		R.path				= xr_strdup	(fn);
		R.crc				= c_crc32;
		R.c_ptr				= c_ptr;
		R.c_size_real		= c_size_real;
		R.c_size_compressed	= c_size_compressed;
		aliases.insert		(mk_pair(R.c_size_real,R));
	}

	FS.r_close	(src);
}
Exemplo n.º 12
0
static int make_bmp_from_file(state *s, char *input)
{
  char *o1, *o2, *output = (char *)malloc(sizeof(char) * PATH_MAX);

  if (s->verbose)
    print_status ("%s: Processing %s", __progname, input);

  if ((o1 = strdup(input)) == NULL)
    {
      perror(__progname);
      return TRUE;
    }

  o2 = basename(o1);
  snprintf(output, PATH_MAX, "%s.bmp", o2);
  // We don't free o2 as it's statically allocated 
  free(o1);

  if ((s->in_handle = fopen(input,"rb")) == NULL)
    {
      free(output);
      perror(input);
      return TRUE;
    }

  snprintf(s->input_fn,PATH_MAX,"%s", input);

  if ((s->out_handle = fopen(output,"wb")) == NULL)
    {
      fclose(s->in_handle);
      perror(output);
      free(output);
      return TRUE;
    }

  if (find_file_size(input, s->in_handle, &s->input_length))
    return TRUE;

  s->image_height = (s->input_length / s->image_width);
  if (s->input_length % s->image_width != 0)
    s->image_height++;

  if (write_file_header(s))
    return TRUE;

  if (write_file_info(s))
    return TRUE;

  if (s->orientation == ORIENTATION_VERTICAL) {
    if (write_vertical_file(s)) {
      perror(output);
    }
  } else {
    write_horizontal_file(s);
  }

  if (s->verbose)
    print_status ("%s: Done.", __progname);

  fclose(s->in_handle);
  fclose(s->out_handle);
  free(output);

  return FALSE;
}
Exemplo n.º 13
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);
}