Beispiel #1
0
/* running in print live mode */
void
running_print_live()
{
    int print_num = 1, re_p_hdr = 0;

    collect_record();

    /* print header */
    print_header();

    /* set struct module fields */
    init_module_fields();

    /* skip first record */
    if (collect_record_stat() == 0) {
        do_debug(LOG_INFO, "collect_record_stat warn\n");
    }
    sleep(conf.print_interval);

    /* print live record */
    while (1) {
        collect_record();

        if (!((print_num) % DEFAULT_PRINT_NUM) || re_p_hdr) {
            /* get the header will print every DEFAULT_PRINT_NUM */
            print_header();
            re_p_hdr = 0;
            print_num = 1;
        }

        if (!collect_record_stat()) {
            re_p_hdr = 1;
            continue;
        }

        /* print current time */
        print_current_time();
        print_record();

        print_num++;
        /* sleep every interval */
        sleep(conf.print_interval);
    }
}
Beispiel #2
0
static void do_export(int argc, char **argv)
{
    srld_db db;
    srld_record *rec = NULL;
    srld_iterator it;

    if (argc != 3) usage();
    if (srld_db_open(argv[2], O_RDWR, &db) != SRLD_OK) {
        fprintf(stderr,"open(%s) failed: %s\n", argv[2], strerror(errno));
        exit(errno);
    }
    srld_iterator_init(&db, &it);
    rec = srld_first(&it);
    while (rec) {
        print_record(rec);
        rec = srld_next(&it);
    }
    srld_db_close(&db);
}
Beispiel #3
0
void find_and_print_range( node * root, key_type key_start, key_type key_end, bool verbose) {
	int i;
	std::list<record*> *returned_rec;
	std::list<record*>::const_iterator rec_it;
	returned_rec = new std::list<record*>;
	int num_found = 0;
	record * ptr_to_rec;
	std::cout << "find print_range()";
	find_range( root, key_start, key_end, verbose, returned_rec);
	//ptr_to_rec = returned_rec;
	std::cout << "found: " << std::endl;
	if ((*returned_rec).empty())
		printf("None found.\n");
	else {
		for(rec_it=(*returned_rec).begin();rec_it!=(*returned_rec).end(); ++rec_it) {
			//print_rec(ptr_to_rec);
			print_record(*rec_it);
		}
	}
}
Beispiel #4
0
void print_type_decl(struct type_decl *type_decl)
{
  switch (type_decl->type_def->type_type)
  {
    case enum_type:
      print_enum(type_decl->ident, type_decl->type_def->def.enum_def);
      break;
    case array_type:
      print_array(type_decl->ident, type_decl->type_def->def.array_def);
      break;
    case struct_type:
      print_record(type_decl->ident, type_decl->type_def->def.record_def);
      break;
    case pointer_type:
      print_pointer(type_decl->ident, type_decl->type_def->def.pointer_def);
      break;
    default:
      printf("type not handled yet (in print_type_decl)\n");
  }
}
int _tmain(int argc, _TCHAR* argv[])
{
	FILE *fp = fopen("D:\\MISSION R&D\\C ONLINE COURSE\\FILES SYTEM DATABASE\\FILES SYTEM DATABASE\\dbFile.db","rb+");
	RECORD *result_set = (RECORD*)malloc(1*sizeof(RECORD));
	int iter_loop = SIZE_OF_RECORD;
	printf("ENTER A QUERY: ");
	char *query  = (char*)calloc(1024,sizeof(char));
	gets(query);
	int no_of_records = NO_OF_RECORDS;
	while(iter_loop==SIZE_OF_RECORD)
	{
		printf("ITER LOOP: %d\n",iter_loop);
		RECORD *details = (RECORD*)malloc(iter_loop*sizeof(RECORD));
		fread(details,sizeof(RECORD),iter_loop,fp);
		result_set = classify_processing(query,details,iter_loop,result_set, &result_set_index);
		if(no_of_records - iter_loop > SIZE_OF_RECORD)
		{
			no_of_records-= iter_loop;
			free(details);
			continue;
		}
		else if(!(no_of_records - iter_loop > SIZE_OF_RECORD))
		{
			free(details);
			break;
		}
	}
	iter_loop = no_of_records - iter_loop;
	printf("ITER LOOP: %d\n",iter_loop);
	RECORD *details = (RECORD*)malloc(iter_loop*sizeof(RECORD));
	fread(details,sizeof(RECORD),iter_loop,fp);
	result_set = classify_processing(query,details,iter_loop,result_set, &result_set_index);
	for(int iter_loop=0;iter_loop<result_set_index;iter_loop++)
	{
		print_record(result_set[iter_loop]);
	}
	getchar();
	return 0;
}
int main(int argc, char **argv){
    Buffer_Set buffers;
    File_Data file;
    float *widths_data;
    float *wrap_ys;
    float font_height;
    float max_width;

    void *scratch;
    int scratch_size;
    
    Stats_Log log;
    
    int do_replay = 0;
    char *replay_filename = 0;
    
    if (argc < 2){
        printf("usage: buffer_test <filename> <message> [-h <.hst file>]\n");
        exit(1);
    }
    
    setup();
    
    for (int i = 3; i < argc; ++i){
        if (do_replay){
            replay_filename = argv[i];
            do_replay = 0;
        }
        if (strcmp(argv[i], "-h") == 0){
            if (replay_filename != 0){
                printf("found -h twice, ignoring duplicates\n");
            }
            else{
                do_replay = 1;
            }
        }
    }
    
    do_replay = (replay_filename != 0);
    
    memzero_4tech(buffers);
    
    log.max = 1 << 20;
    log.size = 0;
    log.out = (char*)malloc(log.max);

    log.sec_max = 32;
    log.sec_top = 0;
    log.sections = (Log_Section*)malloc(sizeof(Log_Section)*log.sec_max);

    log.error = 0;

    scratch_size = 1 << 20;
    scratch = malloc(scratch_size);
    
    file = get_file(argv[1]);
    if (!file.data) exit(1);
    widths_data = get_font_data("LiberationSans-Regular.ttf", &font_height);
    max_width = 500.f;
    
    log_begin_section(&log, litstr("which-test"));
    {
        log_write_str(&log, argv[1], (int)strlen(argv[1]));
        log_write_int(&log, file.size);
        log_write_str(&log, argv[2], (int)strlen(argv[2]));
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("file-open"));
    {
        Record_Statistics init_rec, starts_widths_rec, wraps_rec;
    
        initialization_test(&log, &buffers, file, reps, scratch, scratch_size, &init_rec);
        stream_check_test(&buffers, scratch, scratch_size);
    
        measure_starts_widths_test(&log, &buffers, reps, scratch, scratch_size,
                                   &starts_widths_rec, widths_data);
        measure_check_test(&buffers);

        wrap_ys = measure_wraps_test(&log, &buffers, reps, scratch, scratch_size,
                                     &wraps_rec, font_height, max_width);
    
        Time_Record expected_file_open;
        expected_file_open = init_rec.expected + starts_widths_rec.expected + wraps_rec.expected;
    
        printf("average file open:\n");
        print_record(expected_file_open);
        printf("\n");
        log_time_record(&log, litstr("average"), expected_file_open);
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("cursor-seek"));
    {
        Record_Statistics full_cursor;
        Time_Record full_cursor_average;

        log_begin_section(&log, litstr("to-pos"));
        {
            memzero_4tech(full_cursor_average);
            for (int i = 0; i < 5; ++i){
                silence_test();
                int pos = (file.size*i) / 5;
                full_cursor_test(&log, &buffers, pos,
                                 wrap_ys, widths_data, font_height, max_width,
                                 5, scratch, scratch_size, &full_cursor);
                full_cursor_average = full_cursor_average + full_cursor.expected;
            }
            full_cursor_average /= 5;
            printf("average cursor from position:\n");
            print_record(full_cursor_average);
            printf("\n");
            log_time_record(&log, litstr("average"), full_cursor_average);
        }
        log_end_section(&log);

        log_begin_section(&log, litstr("to-line-character"));
        {
            memzero_4tech(full_cursor_average);
            for (int i = 0; i < 5; ++i){
                silence_test();
                int line = (buffers.buffer.line_count*i) / 5;
                full_cursor_line_test(&log, &buffers, line, 20,
                                      wrap_ys, widths_data, font_height, max_width,
                                      5, scratch, scratch_size, &full_cursor);
                full_cursor_average = full_cursor_average + full_cursor.expected;
            }
            full_cursor_average /= 5;
            printf("average cursor from line & character:\n");
            print_record(full_cursor_average);
            printf("\n");
            log_time_record(&log, litstr("average"), full_cursor_average);
        }
        log_end_section(&log);

        log_begin_section(&log, litstr("to-unwrapped-x-y"));
        {
            memzero_4tech(full_cursor_average);
            for (int i = 0; i < 5; ++i){
                silence_test();
                float y = font_height * (buffers.buffer.line_count*i) / 4.f;
                full_cursor_xy_test(&log, &buffers, y, 37.f, 0,
                                    wrap_ys, widths_data, font_height, max_width,
                                    5, scratch, scratch_size, &full_cursor);
                full_cursor_average = full_cursor_average + full_cursor.expected;
            }
            full_cursor_average /= 5;
            printf("average cursor from line & character:\n");
            print_record(full_cursor_average);
            printf("\n");
            log_time_record(&log, litstr("average"), full_cursor_average);
        }
        log_end_section(&log);
        
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("word-seek"));
    {
        Record_Statistics word_seek;

        {
            char word[] = "not-going-to-find-this";
            int word_len = sizeof(word) - 1;
            
            word_seek_test(&log, &buffers, reps, 0, word, word_len, scratch, scratch_size, &word_seek);

        }

        {
            char word[] = "return";
            int word_len = sizeof(word) - 1;
            
            word_seek_test(&log, &buffers, reps, 1, word, word_len, scratch, scratch_size, &word_seek);
        
            printf("average normal word seek:\n");
            print_record(word_seek.expected);
            printf("\n");
        }
    }
    log_end_section(&log);
    
    log_begin_section(&log, litstr("one-hundred-single-edits"));
    {
        Record_Statistics edits;
        insert_bottom_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
        insert_top_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
        delete_bottom_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
        delete_top_test(&log, &buffers, reps, widths_data, 100, scratch, scratch_size, &edits);
    }
    log_end_section(&log);
    
    File_Data replay_file = {};
    Replay replay;
    
    if (do_replay){
        replay_file = get_file(replay_filename);
        prepare_replay(replay_file, &replay);
    }

    if (replay_file.data){
        log_begin_section(&log, litstr("natural-edits"));
        {
            Record_Statistics edits;
            natural_edits_test(&log, &buffers, reps, widths_data, &replay,
                               scratch, scratch_size, &edits);
        }
        log_end_section(&log);
    }
    else{
        printf("skipped natural-edits test\n\n");
    }
    
    log_begin_section(&log, litstr("batch-edit"));
    {
        Buffer_Edit *batch;
        char *str_base;
        int batch_size, str_size;

        batch_size = 1000;
        str_size = 10000;
        batch = (Buffer_Edit*)malloc(sizeof(Buffer_Edit)*batch_size);
        str_base = (char*)malloc(str_size);

        int character_stride;
        character_stride = buffer_size(&buffers.buffer);
        if (character_stride < batch_size * 10){
            batch_size = character_stride / 10;
            character_stride = 10;
        }
        else{
            character_stride = (character_stride / batch_size);
        }

        int p, curs;
        curs = 0;
        p = 0;
        for (int i = 0; i < batch_size; ++i){
            Buffer_Edit edit;
            edit.start = p;
            edit.end = p+8;
            p += character_stride;
            
            edit.str_start = curs;
            if (i & 1){
                edit.len = 9;
                memcpy_4tech(str_base + curs, "123456789", 9);
                curs += 9;
            }
            else{
                edit.len = 7;
                memcpy_4tech(str_base + curs, "abcdefg", 7);
                curs += 7;
            }
            
            batch[i] = edit;
        }
        
        Record_Statistics batch_stats;
        batch_edit_test(&log, &buffers, reps, widths_data, batch, str_base, batch_size,
                        scratch, scratch_size, &batch_stats);
    }
    log_end_section(&log);
    
    log_finish(&log);
    
    return(0);
}
int main(int argc, char *argv[])
{
  /* seed rand */
  struct timeval t1;
  gettimeofday(&t1, NULL);
  srand(t1.tv_usec * t1.tv_sec);

  /* throw out the first couple of outputs */
  for (int i = 0; i < 10; ++i) {
    randnum(10);
  }

  int i = 0;
  int l1;
  int l2;
  int max;
  double percent = 0.0;
  long num_samples = 0;
  unsigned long total = 0;

  kseq_t *seq1;
  kseq_t *seq2;
  kseq_t *seqU;
  gzFile fp1;
  gzFile fp2;
  gzFile fpU;

  char fname_buf[1000];

  if (argc != 8) {
    fprintf(stderr,
            "VERSION: %s\nUsage: %s <1: percent to sample> "
            "<2: number of samples> <3: outdir> "
            "<4: basename for outfiles> "
            "<5: in.1.f{a,q}> <6: in.2.f{a,q}> <7: in.U.f{a,q}>\n",
            VERSION,
            argv[0]);

    return 1;
  }

  percent = strtod(argv[1], NULL);
  num_samples = strtol(argv[2], NULL, 10);

  outf_t *outfiles1[num_samples];
  outf_t *outfiles2[num_samples];
  outf_t *outfilesU[num_samples];
  for (i = 0; i < num_samples; ++i) {
    sprintf(fname_buf,
            "%s/%s.sample_%d.1.fq",
            argv[3],
            argv[4],
            i);
    outfiles1[i] = outf_init(fname_buf);

    sprintf(fname_buf,
            "%s/%s.sample_%d.2.fq",
            argv[3],
            argv[4],
            i);
    outfiles2[i] = outf_init(fname_buf);

    sprintf(fname_buf,
            "%s/%s.sample_%d.U.fq",
            argv[3],
            argv[4],
            i);
    outfilesU[i] = outf_init(fname_buf);
  }


  max = 100 / percent;

  fp1 = gzopen(argv[5], "r");
  fp2 = gzopen(argv[6], "r");
  fpU = gzopen(argv[7], "r");

  if (!fp1) {
    fprintf(stderr,
            "ERROR - could not open %s\n",
            argv[5]);

    return 2;
  }

  if (!fp2) {
    fprintf(stderr,
            "ERROR - could not open %s\n",
            argv[6]);

    return 2;
  }

  if (!fpU) {
    fprintf(stderr,
            "ERROR - could not open %s\n",
            argv[7]);

    return 2;
  }

  seq1 = kseq_init(fp1);
  seq2 = kseq_init(fp2);
  seqU = kseq_init(fpU);

  while ((l1 = kseq_read(seq1)) >= 0) {
    /* TODO: might be faster to read all of one, mark the records
       taken and then read all of the second? */
    l2 = kseq_read(seq2);
    if (l2 < 0) {
      fprintf(stderr,
              "ERROR -- not enough reads in reverse file %s\n",
              argv[3]);
    }

    ++total;
    if (total % 100000 == 0) {
      fprintf(stderr,
              "INFO -- reading paired files: %lu\r",
              total);
    }

    for (i = 0; i < num_samples; ++i) {
      if (randnum(max) == 1) {
        print_record(seq1, outfiles1[i]->fp);
        print_record(seq2, outfiles2[i]->fp);
      }
    }
  }

  total = 0;
  while ((l1 = kseq_read(seqU)) >= 0) {
    ++total;
    if (total % 100000 == 0) {
      fprintf(stderr,
              "INFO -- reading unpaired file: %lu\r",
              total);
    }

    for (i = 0; i < num_samples; ++i) {
      if (randnum(max) == 1) {
        print_record(seqU, outfilesU[i]->fp);
      }
    }
  }

  kseq_destroy(seq1);
  kseq_destroy(seq2);
  kseq_destroy(seqU);

  gzclose(fp1);
  gzclose(fp2);
  gzclose(fpU);

  for (i = 0; i < num_samples; ++i) {
    outf_destroy(outfiles1[i]);
    outf_destroy(outfiles2[i]);
    outf_destroy(outfilesU[i]);
  }

  return 0;
}
static long fbconfig_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = 0;
	void __user *argp = (void __user *)arg;
	DISP_DRV_WRAN("sxk=>run in fbconfig_ioctl**\n");

	switch (cmd) {
	case LCM_GET_ID:
		{
			/* get_lcm_id() need implemented in lcm driver ... */
#if 0
			LCM_DRIVER *lcm = lcm_drv;
			unsigned int lcm_id = lcm->get_lcm_id();
#else
			unsigned int lcm_id = 0;
#endif
			return copy_to_user(argp, &lcm_id, sizeof(lcm_id)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_CONTINU:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(10);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_CONTINU:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_TEST_DSI_CLK:
		{
			LCM_TYPE_FB lcm_fb;
			lcm_fb.clock = lcm_params->dsi.PLL_CLOCK;
			lcm_fb.lcm_type = lcm_params->dsi.mode;
			DISP_DRV_WRAN("fbconfig=>LCM_TEST_DSI_CLK:%d\n", ret);
			return copy_to_user(argp, &lcm_fb, sizeof(lcm_fb)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_CLK:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(11);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_CLK:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_CLK_V2:
		{
			unsigned int ret = 0;
			MIPI_CLK_V2 clock_v2;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(11);
			clock_v2.div1 = ret & 0x00000600;
			clock_v2.div2 = ret & 0x00000180;
			clock_v2.fbk_div = ret & 0x0000007F;
			return copy_to_user(argp, &clock_v2, sizeof(clock_v2)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_SSC:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(9);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_SSC:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_LANE_NUM:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(12);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_LANE_NUM:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_TE:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(13);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_TE:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_TIMING:
		{
			int ret = 0;
			MIPI_TIMING timing;
			if (copy_from_user(&timing, (void __user *)argp, sizeof(timing))) {
				DISP_DRV_WRAN("[MIPI_SET_TIMING]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			}
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(100 + timing.type);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_TIMING:%d\n", ret);
			timing.value = ret;
			return copy_to_user(argp, &timing, sizeof(timing)) ? -EFAULT : 0;
		}
	case DRIVER_IC_CONFIG:
		{
			DISP_DRV_WRAN("sxk=>run in case:DRIVER_IC_CONFIG**\n");
			if (record_list_initialed == 0) {
				record_list_init();
				if (copy_from_user(record_head, (void __user *)arg, sizeof(CONFIG_RECORD))) {
					DISP_DRV_WRAN("sxk=>copy_from_user failed! line:%d\n", __LINE__);
					return -EFAULT;
				}
#if 0
				print_record(record_head);
#endif
				record_list_initialed = 1;
			} else {
				if (copy_from_user(record_tmp, (void __user *)arg, sizeof(CONFIG_RECORD))) {
					DISP_DRV_WRAN("[DRIVER_IC_CONFIG]: copy_from_user failed! line:%d\n", __LINE__);
					return -EFAULT;
				}
#if 0				/* FBCONFIG_DEBUG */
				DISP_DRV_WRAN("sxk=>will print before add to list\n");
				print_record(record_tmp);
#endif
				record_list_add();	/* add new node to list ; */

			}

			return 0;
		}
	case MIPI_SET_CLK:
		{
			unsigned int clk;
			if (copy_from_user(&clk, (void __user *)argp, sizeof(clk))) {
				DISP_DRV_WRAN("[MIPI_SET_CLK]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				fbconfig_disp_set_mipi_clk(clk);
			}
			return 0;
		}
	case MIPI_SET_CLK_V2:
		{
			MIPI_CLK_V2 clk;
			if (copy_from_user(&clk, (void __user *)argp, sizeof(clk))) {
				DISP_DRV_WRAN("[MIPI_SET_CLK]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				unsigned int clk_v2 = 0;
				/* div1_2bits  div2_2bits  fbk_div_7bits */
				clk_v2 = (clk.div1 << 9) | (clk.div2 << 7) | clk.fbk_div;
				fbconfig_disp_set_mipi_clk(clk_v2);
			}
			return 0;
		}
	case MIPI_SET_SSC:
		{
			unsigned int ssc;
			DISP_DRV_WRAN("sxk=>debug.c call set mipi ssc line:%d\n", __LINE__);
			if (copy_from_user(&ssc, (void __user *)argp, sizeof(ssc))) {
				DISP_DRV_WRAN("[MIPI_SET_SSC]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				DISP_DRV_WRAN("sxk=>debug.c call set mipi ssc line:%d\n", __LINE__);
				fbconfig_disp_set_mipi_ssc(ssc);
			}
			return 0;
		}
	case MIPI_SET_LANE:
		{
			unsigned int lane_num;
			if (copy_from_user(&lane_num, (void __user *)argp, sizeof(lane_num))) {
				DISP_DRV_WRAN("[MIPI_SET_LANE]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				fbconfig_disp_set_mipi_lane_num(lane_num);
			}
			return 0;
		}
	case MIPI_SET_TIMING:
		{
			if (!is_early_suspended) {
				MIPI_TIMING timing;
				if (copy_from_user(&timing, (void __user *)argp, sizeof(timing))) {
					DISP_DRV_WRAN("[MIPI_SET_TIMING]: copy_from_user failed! line:%d\n", __LINE__);
					return -EFAULT;
				} else {
					fbconfig_disp_set_mipi_timing(timing);
				}
				return 0;
			} else
				return -EFAULT;
		}
	case TE_SET_ENABLE:
		{
			char enable;
			if (copy_from_user(&enable, (void __user *)argp, sizeof(enable))) {
				DISP_DRV_WRAN("[TE_SET_ENABLE]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				if (fbconfig_if_drv->set_te_enable)
					fbconfig_if_drv->set_te_enable(enable);
			}
			return 0;
		}
	case FB_LAYER_GET_EN:
		{
			FBCONFIG_LAYER_INFO layers;
			fbconfig_get_layer_info(&layers);
			return copy_to_user(argp, &layers, sizeof(layers)) ? -EFAULT : 0;
		}
	case FB_LAYER_GET_SIZE:
		{
			LAYER_H_SIZE tmp;
			int layer_size, enable, height, fmt;
			if (copy_from_user(&tmp, (void __user *)argp, sizeof(LAYER_H_SIZE))) {
				DISP_DRV_WRAN("[TE_SET_ENABLE]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			}
			global_layer_id = tmp.height;
			DISP_DRV_WRAN("sxk==>global_layer_id is %d\n", global_layer_id);
			fbconfig_get_layer_height(global_layer_id, &layer_size, &enable, &height, &fmt);
			if ((layer_size == 0) || (enable == 0) || (height == 0))
				return -2;
			else {
				tmp.height = height;
				tmp.layer_size = layer_size;
				tmp.fmt = DP_COLOR_BITS_PER_PIXEL(fmt);
				return copy_to_user(argp, &tmp, sizeof(tmp)) ? -EFAULT : 0;
			}
		}
	case FB_LAYER_DUMP:
		{
			int layer_size, enable;
			int ret = 0;
			unsigned int kva = 0;
			unsigned int mapped_size = 0;
			unsigned int mva = fbconfig_get_layer_vaddr(global_layer_id, &layer_size, &enable);
			if ((layer_size != 0) && (enable != 0)) {
				DISP_DRV_WRAN("sxk==>FB_LAYER_DUMP==>layer_size is %d   mva is 0x%x\n", layer_size,
					      mva);
				m4u_mva_map_kernel(mva, layer_size, 0, &kva, &mapped_size);
				DISP_DRV_WRAN("sxk==> addr from user space is 0x%x\n", (unsigned int)argp);
				DISP_DRV_WRAN("sxk==> kva is 0x%x   mmaped size is %d\n", kva, mapped_size);
				ret = copy_to_user(argp, (void *)kva, mapped_size) ? -EFAULT : 0;
				m4u_mva_unmap_kernel(mva, mapped_size, kva);
				return ret;
			} else
				return -2;
		}
	case MIPI_SET_CC:
		{
			int enable;
			if (copy_from_user(&enable, (void __user *)argp, sizeof(enable))) {
				DISP_DRV_WRAN("[MIPI_SET_CC]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				if (fbconfig_if_drv->set_continuous_clock)
					fbconfig_if_drv->set_continuous_clock(enable);
			}
			return 0;
		}
	case LCM_GET_ESD:
		{
			ESD_PARA esd_para;
			int i = 0;
			if (copy_from_user(&esd_para, (void __user *)arg, sizeof(esd_para))) {
				DISP_DRV_WRAN("[LCM_GET_ESD]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			}
			esd_check_addr = esd_para.addr;
			esd_check_para_num = esd_para.para_num;
			ret = fbconfig_get_esd_check();
			if ((ret != 0) && (esd_check_buffer != NULL)) {
				kfree(esd_check_buffer);
				return -2;
			} else {
				for (i = 0; i < esd_check_para_num + 6; i++)
					DISP_DRV_WRAN("sxk=>%s, esd_check_buffer[%d]=0x%x\n", __func__, i,
						      esd_check_buffer[i]);
				return 0;
			}
		}
	case LCM_GET_ESD_RET:
		{
			ret =
			    (copy_to_user(argp, (void *)esd_check_buffer, sizeof(char) * (esd_check_para_num + 6)) ?
			     -EFAULT : 0);
			if (esd_check_buffer != NULL) {
				kfree(esd_check_buffer);
				esd_check_buffer = NULL;
			}
			return ret;
		}
	case DRIVER_IC_RESET:
		{
			fbconfig_reset_lcm_setting();
			fbconfig_free_backup_setting();
			return 0;
		}
	default:
		return ret;
	}
}
Beispiel #9
0
/*
 * print mode, print data from tsar.data
 */
void
running_print()
{
    int    print_num = 1, re_p_hdr = 0;
    char   line[LEN_10240] = {0};
    char   filename[LEN_128] = {0};
    long   n_record = 0, s_time;
    FILE  *fp;

    fp = init_running_print();//初始化,找到数据在哪个文件的什么部位。打印头部信息等。

    /* skip first record */
    if (collect_record_stat() == 0) {
        do_debug(LOG_INFO, "collect_record_stat warn\n");
    }
    while (1) {
        if (!fgets(line, LEN_10240, fp)) {
            if (conf.print_file_number <= 0) {
                break;

            } else {//得读取下一个文件了。
                conf.print_file_number = conf.print_file_number - 1;
                memset(filename, 0, sizeof(filename));
                if (conf.print_file_number == 0) {
                    sprintf(filename, "%s", conf.output_file_path);

                } else {
                    sprintf(filename, "%s.%d", conf.output_file_path, conf.print_file_number);
                }
                if (fclose(fp) < 0) {
                    do_debug(LOG_FATAL, "fclose error:%s", strerror(errno));
                }
                fp = fopen(filename, "r");
                if (!fp) {
                    do_debug(LOG_FATAL, "unable to open the log file %s.\n", filename);
                }
                continue;
            }
        }

        int    k = check_time(line);
        if (k == 1) {
            continue;
        }
        if (k == 3) {
            break;
        }

        /* collect data then set mod->summary */
        read_line_to_module_record(line);

        if (!(print_num % DEFAULT_PRINT_NUM) || re_p_hdr) {
            /* get the header will print every DEFAULT_PRINT_NUM */
            print_header();
            re_p_hdr = 0;
            print_num = 1;
        }

        /* exclued the two record have same time */
        if (!(s_time = set_record_time(line))) {
            continue;
        }

        /* reprint header because of n_item's modifing */
        if (!collect_record_stat()) {
            re_p_hdr = 1;
            continue;
        }

        print_record_time(s_time);
        print_record();
        n_record++;
        print_num++;
        memset(line, 0, sizeof(line));
    }

    if (n_record) {
        printf("\n");
        print_tail(TAIL_MAX);
        print_tail(TAIL_MEAN);
        print_tail(TAIL_MIN);
    }

    if (fclose(fp) < 0) {
        do_debug(LOG_FATAL, "fclose error:%s", strerror(errno));
    }
    fp = NULL;
}
static int
ada_val_print_1 (struct type *type, char *valaddr0, int embedded_offset,
		 CORE_ADDR address, struct ui_file *stream, int format,
		 int deref_ref, int recurse, enum val_prettyprint pretty)
{
  unsigned int len;
  int i;
  struct type *elttype;
  unsigned int eltlen;
  LONGEST val;
  char *valaddr = valaddr0 + embedded_offset;

  CHECK_TYPEDEF (type);

  if (ada_is_array_descriptor_type (type) || ada_is_packed_array_type (type))
    {
      int retn;
      struct value *mark = value_mark ();
      struct value *val;
      val = value_from_contents_and_address (type, valaddr, address);
      val = ada_coerce_to_simple_array_ptr (val);
      if (val == NULL)
	{
	  fprintf_filtered (stream, "(null)");
	  retn = 0;
	}
      else
	retn = ada_val_print_1 (VALUE_TYPE (val), VALUE_CONTENTS (val), 0,
				VALUE_ADDRESS (val), stream, format,
				deref_ref, recurse, pretty);
      value_free_to_mark (mark);
      return retn;
    }

  valaddr = ada_aligned_value_addr (type, valaddr);
  embedded_offset -= valaddr - valaddr0 - embedded_offset;
  type = printable_val_type (type, valaddr);

  switch (TYPE_CODE (type))
    {
    default:
      return c_val_print (type, valaddr0, embedded_offset, address, stream,
			  format, deref_ref, recurse, pretty);

    case TYPE_CODE_PTR:
      {
	int ret = c_val_print (type, valaddr0, embedded_offset, address, 
			       stream, format, deref_ref, recurse, pretty);
	if (ada_is_tag_type (type))
	  {
	    struct value *val = 
	      value_from_contents_and_address (type, valaddr, address);
	    const char *name = ada_tag_name (val);
	    if (name != NULL) 
	      fprintf_filtered (stream, " (%s)", name);
	    return 0;
	}
	return ret;
      }

    case TYPE_CODE_INT:
    case TYPE_CODE_RANGE:
      if (ada_is_fixed_point_type (type))
	{
	  LONGEST v = unpack_long (type, valaddr);
	  int len = TYPE_LENGTH (type);

	  fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g",
			    (double) ada_fixed_to_float (type, v));
	  return 0;
	}
      else if (ada_is_vax_floating_type (type))
	{
	  struct value *val =
	    value_from_contents_and_address (type, valaddr, address);
	  struct value *func = ada_vax_float_print_function (type);
	  if (func != 0)
	    {
	      static struct type *parray_of_char = NULL;
	      struct value *printable_val;

	      if (parray_of_char == NULL)
		parray_of_char =
		  make_pointer_type
		  (create_array_type
		   (NULL, builtin_type_char,
		    create_range_type (NULL, builtin_type_int, 0, 32)), NULL);

	      printable_val =
		value_ind (value_cast (parray_of_char,
				       call_function_by_hand (func, 1,
							      &val)));

	      fprintf_filtered (stream, "%s", VALUE_CONTENTS (printable_val));
	      return 0;
	    }
	  /* No special printing function.  Do as best we can.  */
	}
      else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
	{
	  struct type *target_type = TYPE_TARGET_TYPE (type);
	  if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
	    {
	      /* Obscure case of range type that has different length from
	         its base type.  Perform a conversion, or we will get a
	         nonsense value.  Actually, we could use the same
	         code regardless of lengths; I'm just avoiding a cast.  */
	      struct value *v = value_cast (target_type,
					    value_from_contents_and_address
					    (type, valaddr, 0));
	      return ada_val_print_1 (target_type, VALUE_CONTENTS (v), 0, 0,
				      stream, format, 0, recurse + 1, pretty);
	    }
	  else
	    return ada_val_print_1 (TYPE_TARGET_TYPE (type),
				    valaddr0, embedded_offset,
				    address, stream, format, deref_ref,
				    recurse, pretty);
	}
      else
	{
	  format = format ? format : output_format;
	  if (format)
	    {
	      print_scalar_formatted (valaddr, type, format, 0, stream);
	    }
          else if (ada_is_system_address_type (type))
            {
              /* FIXME: We want to print System.Address variables using
                 the same format as for any access type.  But for some
                 reason GNAT encodes the System.Address type as an int,
                 so we have to work-around this deficiency by handling
                 System.Address values as a special case.  */
              fprintf_filtered (stream, "(");
              type_print (type, "", stream, -1);
              fprintf_filtered (stream, ") ");
              print_address_numeric 
		(extract_typed_address (valaddr, builtin_type_void_data_ptr),
                 1, stream);
            }
	  else
	    {
	      val_print_type_code_int (type, valaddr, stream);
	      if (ada_is_character_type (type))
		{
		  fputs_filtered (" ", stream);
		  ada_printchar ((unsigned char) unpack_long (type, valaddr),
				 stream);
		}
	    }
	  return 0;
	}

    case TYPE_CODE_ENUM:
      if (format)
	{
	  print_scalar_formatted (valaddr, type, format, 0, stream);
	  break;
	}
      len = TYPE_NFIELDS (type);
      val = unpack_long (type, valaddr);
      for (i = 0; i < len; i++)
	{
	  QUIT;
	  if (val == TYPE_FIELD_BITPOS (type, i))
	    {
	      break;
	    }
	}
      if (i < len)
	{
	  const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
	  if (name[0] == '\'')
	    fprintf_filtered (stream, "%ld %s", (long) val, name);
	  else
	    fputs_filtered (name, stream);
	}
      else
	{
	  print_longest (stream, 'd', 0, val);
	}
      break;

    case TYPE_CODE_FLT:
      if (format)
	return c_val_print (type, valaddr0, embedded_offset, address, stream,
			    format, deref_ref, recurse, pretty);
      else
	ada_print_floating (valaddr0 + embedded_offset, type, stream);
      break;

    case TYPE_CODE_UNION:
    case TYPE_CODE_STRUCT:
      if (ada_is_bogus_array_descriptor (type))
	{
	  fprintf_filtered (stream, "(...?)");
	  return 0;
	}
      else
	{
	  print_record (type, valaddr, stream, format, recurse, pretty);
	  return 0;
	}

    case TYPE_CODE_ARRAY:
      elttype = TYPE_TARGET_TYPE (type);
      if (elttype == NULL)
	eltlen = 0;
      else
	eltlen = TYPE_LENGTH (elttype);
      /* FIXME: This doesn't deal with non-empty arrays of
	 0-length items (not a typical case!) */
      if (eltlen == 0)
	len = 0;
      else
	len = TYPE_LENGTH (type) / eltlen;

	  /* For an array of chars, print with string syntax.  */
      if (ada_is_string_type (type) && (format == 0 || format == 's'))
	{
	  if (prettyprint_arrays)
	    {
	      print_spaces_filtered (2 + 2 * recurse, stream);
	    }
	  /* If requested, look for the first null char and only print
	     elements up to it.  */
	  if (stop_print_at_null)
	    {
	      int temp_len;

	      /* Look for a NULL char.  */
	      for (temp_len = 0;
		   temp_len < len && temp_len < print_max
		     && char_at (valaddr, temp_len, eltlen) != 0;
		   temp_len += 1);
	      len = temp_len;
	    }

	  printstr (stream, valaddr, len, 0, eltlen);
	}
      else
	{
	  len = 0;
	  fprintf_filtered (stream, "(");
	  print_optional_low_bound (stream, type);
	  if (TYPE_FIELD_BITSIZE (type, 0) > 0)
	    val_print_packed_array_elements (type, valaddr, 0, stream,
					     format, recurse, pretty);
	  else
	    val_print_array_elements (type, valaddr, address, stream,
				      format, deref_ref, recurse,
				      pretty, 0);
	  fprintf_filtered (stream, ")");
	}
      gdb_flush (stream);
      return len;

    case TYPE_CODE_REF:
      elttype = check_typedef (TYPE_TARGET_TYPE (type));
      /* De-reference the reference */
      if (deref_ref)
	{
	  if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
	    {
	      LONGEST deref_val_int = (LONGEST)
		unpack_pointer (lookup_pointer_type (builtin_type_void),
				valaddr);
	      if (deref_val_int != 0)
		{
		  struct value *deref_val =
		    ada_value_ind (value_from_longest
				   (lookup_pointer_type (elttype),
				    deref_val_int));
		  val_print (VALUE_TYPE (deref_val),
			     VALUE_CONTENTS (deref_val), 0,
			     VALUE_ADDRESS (deref_val), stream, format,
			     deref_ref, recurse + 1, pretty);
		}
	      else
		fputs_filtered ("(null)", stream);
	    }
	  else
	    fputs_filtered ("???", stream);
	}
      break;
    }
  gdb_flush (stream);
  return 0;
}
Beispiel #11
0
/**************************
 * PROCESS INPUT VCF FILE *
 **************************/
void vcf2raw(char **filename, char **out_filename, char **cross, int *n_parent1,
             char **parent1, int *n_parent2, char **parent2, double *min_class) {
  // We assume the input file exists (checked in R)
  bcf_sweep_t *in_vcf = bcf_sweep_init(*filename);
  if (in_vcf == NULL) {
    bcf_sweep_destroy(in_vcf);
    error("Could not parse input VCF file.");
  }
  bcf_hdr_t *vcf_hdr = bcf_sweep_hdr(in_vcf);

  // Get reference sequence IDs
  int n_seq = 0;
  const char **seq_names = NULL;
  seq_names = bcf_hdr_seqnames(vcf_hdr, &n_seq);
  if (seq_names == NULL || n_seq == 0) {
    free(seq_names);
    error("Could not correctly parse sequence names in VCF file. Is the input file tabix indexed?\n");
  }
  
  // Map parent names to sample indices
  int idx_parent1[*n_parent1];
  int idx_parent2[*n_parent2];
  get_parents_idx(*n_parent1, idx_parent1, *n_parent2, idx_parent2, vcf_hdr, parent1, parent2);

  // Get progeny sample indices (all samples that are not set as parents)
  int n_samples = bcf_hdr_nsamples(vcf_hdr);
  int n_progeny = n_samples - *n_parent1 - *n_parent2;
  if (n_progeny == 0) {
    error("Input file must contain at least one progeny individual.");
  }
  int idx_progeny[n_progeny];
  int i = 0, s;
  for (s = 0; s < n_samples; s++) {
    if (!is_val_in_arr(s, idx_parent1, *n_parent1)) {
      if (!is_val_in_arr(s, idx_parent2, *n_parent2)) {
        idx_progeny[i++] = s;
      }
    }
  }
  
  // Minimum count to assign parent genotype
  int min_class_parent1 = (int)ceil(*min_class * *n_parent1);
  int min_class_parent2 = (int)ceil(*min_class * *n_parent2);

  // Convert cross type
  int cross_type = get_cross_type(cross);

  // We need to write to a temporary file, because the number of markers in the header is unknown
  FILE *temp_f;
  char temp_filename[] = "tmp_raw_XXXXXX";
  int temp_fd;
  temp_fd = mkstemp(temp_filename);
  if (temp_fd == -1) {
    error("Could not open temporary output file.\n");
  }
  unlink(temp_filename);
  temp_f = fdopen(temp_fd, "w+");
  if (temp_f == NULL) {
    error("Could not open temporary output file.\n");
  }

  // CHROM and POS fields will be placed at the end of the output file
  int marker_count = 0;
  int * chrom = malloc(MAX_VARIANTS * sizeof(int));
  if (chrom == NULL) {
    error("Could not allocate vector.\n");
  }
  int * pos = malloc(MAX_VARIANTS * sizeof(int));
  if (pos == NULL) {
    error("Could not allocate vector.\n");
  }

  // Mapping of VCF genotypes to ONEMAP genotypes
  const char * const D_BC_ref[GT_TYPES_LEN] = { "a", "-", "ab", "-", "-", "-", "-" };
  const char * const D_BC_alt[GT_TYPES_LEN] = { "-", "a", "ab", "-", "-", "-", "-" };
  const char * const RI_ref[GT_TYPES_LEN] = { "a", "b", "-", "-", "-", "-", "-" };
  const char * const RI_alt[GT_TYPES_LEN] = { "b", "a", "-", "-", "-", "-", "-" };
  const char * const B3_F2_ref[GT_TYPES_LEN] = { "a", "b", "ab", "-", "-", "-", "-" };
  const char * const B3_F2_alt[GT_TYPES_LEN] = { "b", "a", "ab", "-", "-", "-", "-" };

  // Scan all records in VCF file and print valid markers to output
  bcf1_t *record;
  int32_t *GTs = NULL;
  int nGT_arr = 0;

  while ((record = bcf_sweep_fwd(in_vcf)) && marker_count < MAX_VARIANTS) {
    // We only consider biallelic SNP and INDEL markers
    int var_type = bcf_get_variant_types(record);
    if ((var_type == VCF_SNP || var_type == VCF_INDEL) && record->n_allele == 2) {
      int nGTs = bcf_get_format_int32(vcf_hdr, record, "GT", &GTs, &nGT_arr);
      // We only consider diploid variants (number of alleles in genotypes == 2)
      nGTs /= n_samples;
      if (nGTs == 2) {

        bcf_fmt_t *fmt_ptr = bcf_get_fmt(vcf_hdr, record, "GT");

        // First, check which parents are heterozygous or homozygous (REF or ALT allele)
        bool is_het_parent1 = false, is_hom_ref_parent1 = false, is_hom_alt_parent1 = false;
        get_consensus_parent_gt(fmt_ptr, *n_parent1, idx_parent1, min_class_parent1, &is_het_parent1,
                                &is_hom_ref_parent1, &is_hom_alt_parent1);
        bool is_het_parent2 = false, is_hom_ref_parent2 = false, is_hom_alt_parent2 = false;
        get_consensus_parent_gt(fmt_ptr, *n_parent2, idx_parent2, min_class_parent2, &is_het_parent2,
                                &is_hom_ref_parent2, &is_hom_alt_parent2);

        // Convert to appropriate marker type
        char marker_type[MARKER_TYPE_LEN];
        int type = get_marker_type(marker_type, cross_type,
                                   is_het_parent1, is_hom_ref_parent1, is_hom_alt_parent1,
                                   is_het_parent2, is_hom_ref_parent2, is_hom_alt_parent2);

        const char * const(*type_ptr)[GT_TYPES_LEN];
        bool valid_marker = true;
        switch(type)
        {
        case marker_B3:
        case marker_F2_ref:
          type_ptr = &B3_F2_ref;
          break;
        case marker_F2_alt:
          type_ptr = &B3_F2_alt;
          break;
        case marker_D_ref:
        case marker_BC_ref:
          type_ptr = &D_BC_ref;
          break;
        case marker_D_alt:
        case marker_BC_alt:
          type_ptr = &D_BC_alt;
          break;
        case marker_RI_ref:
          type_ptr = &RI_ref;
          break;
        case marker_RI_alt:
          type_ptr = &RI_alt;
          break;
        default:
          valid_marker = false;
        }

        if (valid_marker) {
          // Store CHROM and POS fields for valid markers
          chrom[marker_count] = record->rid;
          pos[marker_count] = record->pos + 1;

          // Check if marker name exists; if negative, create one
          char *marker_name = record->d.id;
          if (!strcmp(marker_name, ".")) {
            sprintf(marker_name, "%s.%d", seq_names[chrom[marker_count]], pos[marker_count]);
          }

          // Output variant in ONEMAP format to temporary file
          print_record(temp_f, marker_name, marker_type, fmt_ptr, n_progeny, idx_progeny, type_ptr);

          marker_count++;
        }
      }
    }
  }

  // Write final output file header
  FILE *final_f = fopen(*out_filename, "w");
  if (final_f == NULL) {
    error("Could not open output file.\n");
  }
  fprintf(final_f, "data type %s\n", *cross);
  // The next header line contains the following information: number of individuals, number of markers, 1 for the presence of CHROM information, 1 for the presence of POS information and 0 for the absence of phenotypes (these need to be manually included later)
  fprintf(final_f, "%d %d 1 1 0\n", n_progeny, marker_count);
  // The next header line contains the sample names
  char *cur_sample_name = vcf_hdr->samples[idx_progeny[0]];
  fprintf(final_f, "%s", cur_sample_name);
  for (i = 1; i < n_progeny; i++) {
    cur_sample_name = vcf_hdr->samples[idx_progeny[i]];
    fprintf(final_f, "\t%s", cur_sample_name);
  }
  fprintf(final_f, "\n");
  
  // Copy marker data from temporary file to final file
  rewind(temp_f);
  char buf[BUFSIZ];
  size_t size;
  while ((size = fread(buf, 1, BUFSIZ, temp_f))) {
    fwrite(buf, 1, size, final_f);
  }

  // Write CHROM and POS data to output file
  if (marker_count) {
    fprintf(final_f, "*CHROM\t");
    fprintf(final_f, "%s", seq_names[chrom[0]]);
    for (i = 1; i < marker_count; i++) {
      fprintf(final_f, " %s", seq_names[chrom[i]]);
    }
    fprintf(final_f, "\n*POS\t");
    fprintf(final_f, "%d", pos[0]);
    for (i = 1; i < marker_count; i++) {
      fprintf(final_f, " %d", pos[i]);
    }
  }

  // Clean-up
  free(chrom);
  free(pos);

  free(GTs);
  bcf_sweep_destroy(in_vcf);

  fclose(temp_f);
  close(temp_fd);
  fclose(final_f);
}
Beispiel #12
0
static int select_and_print(DB * db, const char *tname,
			    col_t * cols, int ncol, cond_t * conds, int ncond)
{
	table_t *t;
	cursor_t *cur;
	record_t *r;
	int count;
	int ret = 0;
	int error, xerror;

	if ((t = db_find_table(db, tname)) == NULL) {
		xerrno = ERR_NOTABLE;
		return -1;
	}
	for (int i = 0; i < ncol; i++) {
		int k;
		if ((k = table_find_col(t, cols[i].name)) < 0) {
			xerrno = ERR_NOCOL;
			return -1;
		}
		cols[i].type = t->cols[k].type;
		cols[i].size = t->cols[k].size;
	}

	if (ncol == 0) {
		ncol = t->ncols;
		cols = t->cols;
	}

	int *width;

	if ((width = calloc(ncol, sizeof(int))) == NULL) {
		perror("out of memory");
		return -1;
	}

	for (int i = 0; i < ncol; i++) {
		int k = table_find_col(t, cols[i].name);
		switch (t->cols[k].type) {
		case TYPE_INT:
			width[i] =
			    _max(INT_P_WIDTH, strlen(t->cols[k].name) + 1);
			break;
		case TYPE_FLOAT:
			width[i] =
			    _max(FLOAT_P_WIDTH, strlen(t->cols[k].name) + 1);
			break;
		case TYPE_STRING:
			width[i] =
			    _max(t->cols[k].size, strlen(t->cols[k].name) + 1);
			break;
		}
	}

	if ((cur = select_from(db, tname, conds, ncond)) == NULL) {
		preserve_errno(free(width));
		return -1;
	}

	print_thead(cols, ncol, width);

	count = 0;
	while ((r = select_next(db, cur)) != NULL) {
		print_record(t, cols, ncol, r, width);
		free_record(r);
		count++;
	}
	if (select_error(cur)) {
		error = errno;
		xerror = xerrno;
		ret = -1;
	}
	printf("Total %d %s\n\n", count, count > 1 ? "records" : "record");
	free_cursor(cur);
	free(width);
	errno = error;
	xerrno = xerror;
	return ret;
}
Beispiel #13
0
static int
walk_log(WT_SESSION *session)
{
	WT_CONNECTION *wt_conn2;
	WT_CURSOR *cursor, *cursor2;
	WT_LSN lsn, lsnsave;
	WT_ITEM logrec_key, logrec_value;
	WT_SESSION *session2;
	uint64_t txnid;
	uint32_t fileid, opcount, optype, rectype;
	int first, i, in_txn, ret;

	ret = setup_copy(&wt_conn2, &session2);
	ret = session->open_cursor(session, "log:", NULL, NULL, &cursor);
	ret = session2->open_cursor(session2, uri, NULL, "raw=true", &cursor2);
	i = 0;
	in_txn = 0;
	txnid = 0;
	memset(&lsnsave, 0, sizeof(lsnsave));
	while ((ret = cursor->next(cursor)) == 0) {
		ret = cursor->get_key(cursor, &lsn.file, &lsn.offset, &opcount);
		/*
		 * Save one of the LSNs we get back to search for it
		 * later.  Pick a later one because we want to walk from
		 * that LSN to the end (where the multi-step transaction
		 * was performed).  Just choose the record that is MAX_KEYS.
		 */
		if (++i == MAX_KEYS)
			lsnsave = lsn;
		ret = cursor->get_value(cursor, &txnid, &rectype,
		    &optype, &fileid, &logrec_key, &logrec_value);

		print_record(&lsn, opcount,
		    rectype, optype, txnid, fileid, &logrec_key, &logrec_value);

		/*
		 * If we are in a transaction and this is a new one, end
		 * the previous one.
		 */
		if (in_txn && opcount == 0) {
			ret = session2->commit_transaction(session2, NULL);
			in_txn = 0;
		}

		/*
		 * If the operation is a put, replay it here on the backup
		 * connection.  Note, we cheat by looking only for fileid 1
		 * in this example.  The metadata is fileid 0.
		 */
		if (fileid == 1 && rectype == WT_LOGREC_COMMIT &&
		    optype == WT_LOGOP_ROW_PUT) {
			if (!in_txn) {
				ret = session2->begin_transaction(session2,
				    NULL);
				in_txn = 1;
			}
			cursor2->set_key(cursor2, &logrec_key);
			cursor2->set_value(cursor2, &logrec_value);
			ret = cursor2->insert(cursor2);
		}
	}
	if (in_txn)
		ret = session2->commit_transaction(session2, NULL);

	ret = cursor2->close(cursor2);
	/*
	 * Compare the tables after replay.  They should be identical.
	 */
	if (compare_tables(session, session2))
		printf("compare failed\n");
	ret = session2->close(session2, NULL);
	ret = wt_conn2->close(wt_conn2, NULL);

	ret = cursor->reset(cursor);
	/*! [log cursor set_key] */
	cursor->set_key(cursor, lsnsave.file, lsnsave.offset, 0);
	/*! [log cursor set_key] */
	/*! [log cursor search] */
	ret = cursor->search(cursor);
	/*! [log cursor search] */
	printf("Reset to saved...\n");
	/*
	 * Walk all records starting with this key.
	 */
	first = 1;
	while ((ret = cursor->get_key(cursor,
	    &lsn.file, &lsn.offset, &opcount)) == 0) {
		if (first) {
			first = 0;
			if (lsnsave.file != lsn.file ||
			    lsnsave.offset != lsn.offset) {
				fprintf(stderr,
				    "search returned the wrong LSN\n");
				exit (1);
			}
		}
		ret = cursor->get_value(cursor, &txnid, &rectype,
		    &optype, &fileid, &logrec_key, &logrec_value);

		print_record(&lsn, opcount,
		    rectype, optype, txnid, fileid, &logrec_key, &logrec_value);

		ret = cursor->next(cursor);
		if (ret != 0)
			break;
	}
	ret = cursor->close(cursor);
	return (ret);
}
Beispiel #14
0
int main( void )
{
    int i;
    
    /* holds both command characters */
    char command[ 2 ];
    
    /* set up the three libraries */
    struct Ordered_container* lib_title = OC_create_container( comp_Record_by_title );
    struct Ordered_container* lib_ID    = OC_create_container( comp_Record_by_ID );
    struct Ordered_container* catalog   = OC_create_container( comp_Collection_by_name );
    
    for ( ; ; )
    {
        printf( "\nEnter command: " );
        
        /* load the command chars */
        for ( i = 0 ; i < 2; ++i)
        {
            command[ i ] = get_command_char();
        }
        
        switch ( command[ 0 ] )
        {
            case 'f' :/* find (records only)*/
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        find_record_print( lib_title );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'p' : /* print */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        print_record( lib_ID );
                        break;
                    case 'L':
                        print_containter( lib_title, "Library", "records", (void (*)(void*))print_Record );
                        break;
                    case 'C':
                        /* print_catalog( catalog ); */
                        print_containter( catalog, "Catalog", "collections", (void (*)(void*))print_Collection );
                        break;
                    case 'a': /* allocation */
                        print_allocation( lib_title, lib_ID, catalog );
                        break;
                    case 'c':
                        print_collection_main( catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'm': /* modify (rating only) */
                switch ( command[ 1 ] )
                {
                    case 'r':
                        modify_rating( lib_ID );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'a' : /* add */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        add_record( lib_title, lib_ID );
                        break;
                    case 'c':
                        add_coll( catalog );
                        break;
                    case 'm':
                        add_member( lib_ID , catalog );
                        break;
                    case 'a': /* allocation */
                        /* throw error */
                        print_error_clear( "Unrecognized command!\n");
                        break;
                    default:
                        break;
                }
                break;
            case 'd': /* delete */
                switch ( command[ 1 ] )
                {
                    case 'r' :
                        delete_record( lib_title, lib_ID, catalog );
                        break;
                    case 'c':
                        delete_collection( catalog );
                        break;
                    case 'm':
                         remove_member( lib_ID , catalog );
                        break;
                    case 'a': /* allocation */
                        /* throw error */
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'c': /* clear */
                switch ( command[ 1 ] )
                {
                    case 'L':
                        clear_library( lib_title, lib_ID, catalog, "All records deleted\n" );
                        break;
                    case 'C':
                        clear_container( catalog, ( void(*)(void*) )destroy_Collection, "All collections deleted\n" );
                        break;
                    case 'A':
                        clear_all(lib_title, lib_ID, catalog, "All data deleted\n" );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 's': /* save */
                switch ( command[ 1 ] ) {
                    case 'A':
                        save_all_to_file( lib_title, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'r': /* restore */
                switch ( command[ 1 ] ) {
                    case 'A':
                        load_from_file( lib_title, lib_ID, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
                break;
            case 'q':
                switch ( command[ 1 ] )
                {
                    case 'q':
                        /* clean up memory */
                        quit( lib_title, lib_ID, catalog );
                        break;
                    default:
                        print_error_clear( "Unrecognized command!\n");
                        break;
                }
            default:
                /* throw error for bad input */
                print_error_clear( "Unrecognized command!\n");
                break;
        }
    }
	return 0;
}
Beispiel #15
0
static void process_data(void) {
master_record_t	master_record;
common_record_t *flow_record;
nffile_t		*nffile;
int 		i, done, ret;
#ifdef COMPAT15
int	v1_map_done = 0;
#endif

	// Get the first file handle
	nffile = GetNextFile(NULL, 0, 0);
	if ( !nffile ) {
		LogError("GetNextFile() error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) );
		return;
	}
	if ( nffile == EMPTY_LIST ) {
		LogError("Empty file list. No files to process\n");
		return;
	}

	done = 0;
	while ( !done ) {
		// get next data block from file
		ret = ReadBlock(nffile);

		switch (ret) {
			case NF_CORRUPT:
			case NF_ERROR:
				if ( ret == NF_CORRUPT ) 
					fprintf(stderr, "Skip corrupt data file '%s'\n",GetCurrentFilename());
				else 
					fprintf(stderr, "Read error in file '%s': %s\n",GetCurrentFilename(), strerror(errno) );
				// fall through - get next file in chain
			case NF_EOF: {
				nffile_t *next = GetNextFile(nffile, 0, 0);
				if ( next == EMPTY_LIST ) {
					done = 1;
				}
				if ( next == NULL ) {
					done = 1;
					LogError("Unexpected end of file list\n");
				}
				// else continue with next file
				continue;

				} break; // not really needed
		}

#ifdef COMPAT15
		if ( nffile->block_header->id == DATA_BLOCK_TYPE_1 ) {
			common_record_v1_t *v1_record = (common_record_v1_t *)nffile->buff_ptr;
			// create an extension map for v1 blocks
			if ( v1_map_done == 0 ) {
				extension_map_t *map = malloc(sizeof(extension_map_t) + 2 * sizeof(uint16_t) );
				if ( ! map ) {
					LogError("malloc() allocation error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) );
					exit(255);
				}
				map->type 	= ExtensionMapType;
				map->size 	= sizeof(extension_map_t) + 2 * sizeof(uint16_t);
				if (( map->size & 0x3 ) != 0 ) {
					map->size += 4 - ( map->size & 0x3 );
				}

				map->map_id = INIT_ID;

				map->ex_id[0]  = EX_IO_SNMP_2;
				map->ex_id[1]  = EX_AS_2;
				map->ex_id[2]  = 0;

				map->extension_size  = 0;

				Insert_Extension_Map(&extension_map_list, map);

				v1_map_done = 1;
			}

			// convert the records to v2
			for ( i=0; i < nffile->block_header->NumRecords; i++ ) {
				common_record_t *v2_record = (common_record_t *)v1_record;
				Convert_v1_to_v2((void *)v1_record);
				// now we have a v2 record -> use size of v2_record->size
				v1_record = (common_record_v1_t *)((pointer_addr_t)v1_record + v2_record->size);
			}
			nffile->block_header->id = DATA_BLOCK_TYPE_2;
		}
#endif

		if ( nffile->block_header->id == Large_BLOCK_Type ) {
			// skip
			continue;
		}

		if ( nffile->block_header->id != DATA_BLOCK_TYPE_2 ) {
			fprintf(stderr, "Can't process block type %u. Skip block.\n", nffile->block_header->id);
			continue;
		}

		flow_record = nffile->buff_ptr;
		for ( i=0; i < nffile->block_header->NumRecords; i++ ) {
			char        string[1024];

			switch ( flow_record->type ) {
				case CommonRecordType: {
					uint32_t map_id = flow_record->ext_map;
					generic_exporter_t *exp_info = exporter_list[flow_record->exporter_sysid];
					if ( extension_map_list.slot[map_id] == NULL ) {
						snprintf(string, 1024, "Corrupt data file! No such extension map id: %u. Skip record", flow_record->ext_map );
						string[1023] = '\0';
					} else {
						ExpandRecord_v2( flow_record, extension_map_list.slot[flow_record->ext_map], 
							exp_info ? &(exp_info->info) : NULL, &master_record);

						// update number of flows matching a given map
						extension_map_list.slot[map_id]->ref_count++;
			
						/* 
			 			* insert hier your calls to your processing routine 
			 			* master_record now contains the next flow record as specified in nffile.c
			 			* for example you can print each record:
			 			*
			 			*/
						print_record(&master_record, string);
					}
					printf("%s\n", string);
	
					} break;
				case ExtensionMapType: {
					extension_map_t *map = (extension_map_t *)flow_record;

					if ( Insert_Extension_Map(&extension_map_list, map) ) {
					 	// flush new map
					} // else map already known and flushed

					} break;
				case ExporterRecordType:
				case SamplerRecordype:
						// Silently skip exporter records
					break;
				default: {
					fprintf(stderr, "Skip unknown record type %i\n", flow_record->type);
				}
			}

			// Advance pointer by number of bytes for netflow record
			flow_record = (common_record_t *)((pointer_addr_t)flow_record + flow_record->size);	

		} // for all records

	} // while

	CloseFile(nffile);
	DisposeFile(nffile);

	PackExtensionMapList(&extension_map_list);

} // End of process_data
Beispiel #16
0
int main(int argc, char *argv[])
{
    int i;
    const char *datafile = NULL;
    const char *inputfile = NULL;
    const char *ip = NULL;
    const char *outputfile = NULL;
    const char *format = "CSV";
    const char *field = NULL;
    int noheading = 0;
    IP2Location *dbobj = NULL;
    IP2LocationRecord *record = NULL;
    FILE *fout = stdout;

    field = "ip,countryshort,countrylong,region,city,isp,latitude,longitude,domain,zipcode,timezone,netspeed,iddcode,areacode,weatherstationcode,weatherstationname,mcc,mnc,mobilebrand,elevation,usagetype";

    for (i = 1; i < argc; i++) {
        const char *argvi = argv[i];

        if (strcmp(argvi, "-d") == 0 || strcmp(argvi, "--datafile") == 0) {
            if (i + 1 < argc) {
                datafile = argv[++i];
            }
        } else if (strcmp(argvi, "-i") == 0 || strcmp(argvi, "--inputfile") == 0) {
            if (i + 1 < argc) {
                inputfile = argv[++i];
            }
        } else if (strcmp(argvi, "-p") == 0 || strcmp(argvi, "--ip") == 0) {
            if (i + 1 < argc) {
                ip = argv[++i];
            }
        } else if (strcmp(argvi, "-o") == 0 || strcmp(argvi, "--outputfile") == 0) {
            if (i + 1 < argc) {
                outputfile = argv[++i];
            }
        } else if (strcmp(argvi, "-f") == 0 || strcmp(argvi, "--format") == 0) {
            if (i + 1 < argc) {
                format = argv[++i];
            }
        } else if (strcmp(argvi, "-h") == 0 || strcmp(argvi, "-?") == 0 || strcmp(argvi, "--help") == 0) {
            print_usage(argv[0]);
            return 0;
        } else if (strcmp(argvi, "-v") == 0 || strcmp(argvi, "--version") == 0) {
            print_version();
            return 0;
        } else if (strcmp(argvi, "-e") == 0 || strcmp(argvi, "--field") == 0) {
            if (i + 1 < argc) {
                field = argv[++i];
            }
        } else if (strcmp(argvi, "-n") == 0 || strcmp(argvi, "--noheading") == 0) {
            noheading = 1;
        }
    }

    if (strcmp(format, "CSV") != 0 && strcmp(format, "XML") != 0 && strcmp(format, "TAB") != 0) {
        fprintf(stderr, "Invalid format %s, supported formats: CSV, XML, TAB\n", format);
        exit(-1);
    }

    if (datafile == NULL) {
        fprintf(stderr, "Datafile is absent\n");
        exit(-1);
    }

	if (ip == NULL) {
        fprintf(stderr, "IP address is absent\n");
        exit(-1);
    }
	
    dbobj = IP2Location_open((char *)datafile);
    if (dbobj == NULL) {
        fprintf(stderr, "Failed to open datafile %s\n", datafile);
        exit(-1);
    }

    if (outputfile != NULL) {
        fout = fopen(outputfile, "w");
        if (fout == NULL) {
            fprintf(stderr, "Failed to open outputfile %s\n", outputfile);
            exit(-1);
        }
    }

    if (!noheading) {
        print_header(fout, field, format);
    }

    if (ip != NULL) {
        record = IP2Location_get_all(dbobj, (char *)ip);
        print_record(fout, field, record, format, ip);
        IP2Location_free_record(record);
    }
    if (inputfile != NULL) {
        char *line = NULL;
        size_t n;
        ssize_t len;
        FILE *fin = fopen(inputfile, "r");

        if (fin == NULL) {
            fprintf(stderr, "Failed to open inputfile %s\n", inputfile);
            exit(-1);
        }

        while ((len = getline(&line, &n, fin)) != -1) {
            if (line[len - 1] == '\n') {
                line[--len] = '\0';
            }
            if (line[len - 1] == '\r') {
                line[--len] = '\0';
            }
            record = IP2Location_get_all(dbobj, line);
            print_record(fout, field, record, format, line);
            IP2Location_free_record(record);
        }

        fclose(fin);
    }
    print_footer(fout, field, format);
    IP2Location_close(dbobj);
    // OS will clean-up the rest
    return 0;
}