Ejemplo n.º 1
0
int packfrm(uchar *data, size_t len,
            uchar **pack_data, size_t *pack_len)
{
  int error;
  size_t org_len, comp_len, blob_len;
  uchar *blob;
  DBUG_ENTER("packfrm");
  DBUG_PRINT("enter", ("data: 0x%lx  len: %lu", (long) data, (ulong) len));

  error= 1;
  org_len= len;
  if (my_compress((uchar*)data, &org_len, &comp_len))
    goto err;

  DBUG_PRINT("info", ("org_len: %lu  comp_len: %lu", (ulong) org_len,
                      (ulong) comp_len));
  DBUG_DUMP("compressed", data, org_len);

  error= 2;
  blob_len= BLOB_HEADER + org_len;
  if (!(blob= (uchar*) my_malloc(blob_len,MYF(MY_WME))))
    goto err;

  /* Store compressed blob in machine independent format */
  int4store(blob, 1);
  int4store(blob+4, (uint32) len);
  int4store(blob+8, (uint32) org_len);          /* compressed length */

  /* Copy frm data into blob, already in machine independent format */
  memcpy(blob+BLOB_HEADER, data, org_len);

  *pack_data= blob;
  *pack_len=  blob_len;
  error= 0;

  DBUG_PRINT("exit", ("pack_data: 0x%lx  pack_len: %lu",
                      (long) *pack_data, (ulong) *pack_len));
err:
  DBUG_RETURN(error);

}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
	my_log_init(MESSAGE, "logs.txt");
	if(argc < 2)
	{
		my_log(ERROR, "Input file name hasn't been found.");
		return 0;
	}

	char file_name[256] = {0};
	strcpy(file_name, argv[1]);

	char* file_type = NULL;
	char dot = '.';
	file_type = strtok(argv[1], &dot);

	if(strcmp(file_type, file_name))
	{
		file_type = strtok(NULL, &dot);
	}

	int rezult = 0;
	if(strcmp(file_type, "mgz"))
	{
		rezult = my_compress(file_name);
		my_log(MESSAGE, "File %s was compressed with result: %s", file_name, rezult == 0 ? "failed" : "success");
	}
	else
	{
		rezult = my_decompress(file_name);
		my_log(MESSAGE, "File %s was decompressed with result: %s", file_name, rezult == 0 ? "failed" : "success");
	}

	my_log_end();
	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    int ret=0;
    myArgs myargs;
	myFilter myfilter;
	header fhp;
    char * outputfile=0;
    FILE *sourceFile;
    FILE *destinationFile;
    
    
    if(argc == 1){
		progUsage(argv[0]);
		return UNSUCCESS;
	}

	init_Args(&myargs);
	ret=parseArgs(&myargs,argc,argv);
    if (ret == false) {
		progUsage(argv[0]);
		return UNSUCCESS;
	}
    
	
	if (myargs.destination == NULL){
		ret=newOutputFile(&myargs,outputfile);
		if (ret == false){
			return UNSUCCESS;
		}
		myargs.destParsed=true;
	}

	/**
	 * Recolher dados para a operacao de filtragem
	 **/
	myfilter.sourceName=myargs.source;
	myfilter.type=myargs.filter;
	if (myargs.action == compress_action){
		myfilter.nbrChars=processFileHeader(myfilter.sourceName,&fhp);
		myfilter.bpp=(fhp.magicValue>3 ? 3:1);
		myfilter.lineSize=fhp.imageWidth*myfilter.bpp;
		myfilter.firstLine=true;
	}
	/**
	 * Processamento do ficheiro
	 **/
	sourceFile=fopen(myargs.source,"rb");
	destinationFile=fopen(myargs.destination,"wr");
	SET_BINARY_MODE(sourceFile);
	SET_BINARY_MODE(destinationFile);


	printf("Processing file: %s into %s ...", myargs.source,myargs.destination);
	if (myargs.action == compress_action){
		ret = my_compress(sourceFile,destinationFile, myargs.compressLevel, myfilter);
	}else{
		ret = my_decompress(sourceFile, destinationFile, myfilter);
	}
	if (ret != Z_OK){
			printf("--- :::  ERROR. File not processed!\n");
			my_errors(ret);
			if(myargs.destParsed){
				cleanNewFileName(outputfile);
			}
			
			return UNSUCCESS;
	}
	printf(" ::: DONE File successufly processed!\n");


	if(myargs.destParsed){
		cleanNewFileName(outputfile);
	}
	return ret;
}