Esempio n. 1
0
int main(int argc, char *argv[]) {
	LIBXML_TEST_VERSION

	// xmlTextReaderPtr reader = xmlReaderForFile("/run/media/svartalf/storage/wikipedia/ruwiki-20140706-pages-meta-history1.xml", NULL, 0);
	xmlTextReaderPtr reader = xmlReaderForFile("/tmp/test.xml", NULL, 0);

	FILE *output = fopen("/tmp/output.bin", "w");
	output_write_header(output);

	Revision *rev = revision_create();

	int result = xmlTextReaderRead(reader);
	while (result == 1) {
		processNode(reader, rev);
		result = xmlTextReaderRead(reader);

		if (revision_filled(rev)) {
			output_write_row(output, rev);
			revision_clear(rev);
		}

	}

	output_close(output);

	xmlFreeTextReader(reader);
	if (result != 0) {
		fprintf(stderr, "failed to parse: %d\n", result);
	}
	xmlCleanupParser();

	return 0;

}
Esempio n. 2
0
int main(int argc, char *argv[]) {

  FILE* quantization_fileHandle;
  FILE* input_fileHandle;

  if(argc !=5){
    printf("Usage: Filename, input PGM file, quantization file, qscale, output file\n");
    return(0);
  }

  else{
    quantization_fileHandle = fopen(argv[2], "r");
    input_fileHandle = fopen(argv[1], "rb"); // Not sure if this needs to be rb
    qvalue = atof(argv[3]);
    output_fileHandle = fopen(argv[4], "w");
  }

  if(quantization_fileHandle == NULL || input_fileHandle == NULL || output_fileHandle == NULL){
    printf("Could not open file");
    return 0;
  }

  memset(quant_matrix, 0, 64);

  int i, j;
  for(i = 0; i < 8; i+=1){
    for(j = 0; j < 8; j+=1){
      fscanf(quantization_fileHandle, "%d", &quant_matrix[i][j]);
      quant_matrix[i][j] *= qvalue; //This quantizes the quantization matrix,
                                    //would need this done later
    }
  }

  fclose(quantization_fileHandle);

  //print_8x8_matrix(quant_matrix);

  char type [3];
  int max_value = 0;
  
  fscanf(input_fileHandle, "%s", &type); //Should be P5
  fscanf(input_fileHandle, "%d", &x_size); //Size of photo in x
  fscanf(input_fileHandle, "%d", &y_size); //Size of photo in y
  fscanf(input_fileHandle, "%d", &max_value);//To gather item after the sizes

  int endline = fgetc(input_fileHandle); //Gets the last endline character
  endline++; // removes compiler warning of unused variable
  //printf("file type: %s x size: %d   y size: %d  max value: %d\n\n",type, x_size, y_size, max_value);

  int **input_matrix = (int**) malloc(sizeof(int*) * y_size);

  for(i = 0; i < y_size; i+=1){
    input_matrix[i]= (int*) malloc(sizeof(int) * x_size);
  }
 
  //Fill the matrix with values from the image
  for(i = 0; i < y_size; i += 1){
    for(j = 0; j < x_size; j += 1){
      input_matrix[i][j] = fgetc(input_fileHandle);
    }
  }
  //printf("Input matrix\n");
  //print_matrix(input_matrix, x_size, y_size);

  output_write_header(output_fileHandle); //Write the header to the output file
  break_into_macroblocks(input_matrix); //Start the processing of the file

  /*  Used to test that the zigzag reorder is working correct
  int test_matrix [8][8];
  memset(test_matrix, 0, 64);
  for(i = 0; i < 8; i++){
    for(j = 0; j < 8; j++){
      test_matrix[i][j] = (i*8 + j);
    }
  }
  
  printf("Test matrix, 0-63: \n");
  print_8x8_matrix(test_matrix);
  */

  //printf("Count: %d\n", count);
  fclose(output_fileHandle);

 return 0;
}