コード例 #1
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;
}
コード例 #2
0
ファイル: z-LibraryPNG.c プロジェクト: masterzdran/semestre3
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;
}