void focus_out_then_focus_in_with_aux_text_test()
{
    gboolean cleanBufferFocusOut=ibus_chewing_pre_edit_get_property_boolean(engine->icPreEdit, "clean-buffer-focus-out");
    ibus_chewing_engine_set_capabilite(engine, IBUS_CAP_AUXILIARY_TEXT);
    ibus_chewing_engine_focus_in(engine);
    ibus_chewing_engine_enable(engine);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24,
					  0);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24,
					  IBUS_RELEASE_MASK);
    check_output("", "ㄨ", "ㄨ");

    /* focus out should not touch Texts
     */
    printf("########### cleanBufferFocusOut: %d\n", cleanBufferFocusOut);
    ibus_chewing_engine_focus_out(engine);
    g_assert(cleanBufferFocusOut==ibus_chewing_pre_edit_get_property_boolean(engine->icPreEdit, "clean-buffer-focus-out"));
    if (cleanBufferFocusOut){
	check_output("", "", "");
    }else{
	check_output("", "ㄨ", "ㄨ");
    }

    /* all should be clean */
    ibus_chewing_engine_focus_in(engine);
    check_output("", "", "");

    ibus_chewing_pre_edit_clear(engine->icPreEdit);
    check_output("", "", "");
}
Example #2
0
static int
do_test (void)
{
  if  (setenv ("PATH", test_dir, 1) != 0)
    {
      puts ("setenv failed");
      return 1;
    }

  /* First check resulting script run with some arguments results in correct
     output file.  */
  char *args1[] = { fname1, (char*) "1", (char *) "2", (char *) "3", NULL };
  if (run_script (fname1,args1))
    return 1;
  if (check_output ("foo 1 2 3\n"))
    return 1;

  /* Same as before but with an expected empty argument list.  */
  char *args2[] = { fname2, NULL };
  if (run_script (fname2, args2))
    return 1;
  if (check_output ("foo\n"))
    return 1;

  /* Same as before but with an empty argument list.  */
  char *args3[] = { NULL };
  if (run_script (fname2, args3))
    return 1;
  if (check_output ("foo\n"))
    return 1;

  return 0;
}
Example #3
0
/*! Emulate TEST UNIT READY */
static bool
ata_test_unit_ready(ide_device_info *device, ide_qrequest *qrequest)
{
	SHOW_FLOW0(3, "");

	if (!device->infoblock.RMSN_supported
		|| device->infoblock._127_RMSN_support != 1)
		return true;

	// ask device about status		
	device->tf_param_mask = 0;
	device->tf.write.command = IDE_CMD_GET_MEDIA_STATUS;

	if (!send_command(device, qrequest, true, 15, ide_state_sync_waiting))
		return false;

	// bits ide_error_mcr | ide_error_mc | ide_error_wp are also valid
	// but not requested by TUR; ide_error_wp can safely be ignored, but
	// we don't want to loose media change (request) reports
	if (!check_output(device, true,
			ide_error_nm | ide_error_abrt | ide_error_mcr | ide_error_mc,
			false)) {
		// SCSI spec is unclear here: we shouldn't report "media change (request)"
		// but what to do if there is one? anyway - we report them
		;
	}

	return true;
}
Example #4
0
static void toppm(int argc, char *argv[]) 
{
  int err;
  int next_arg;
  int force;
  char *input_filename, *output_filename;
  carmen_map_t map;

  next_arg = handle_options(argc, argv, &force);

  if(argc - next_arg != 3) {
    carmen_warn("\nError: wrong number of parameters.\n");    
    carmen_die("\nUsage: %s toppm <map filename> <ppm filename>\n\n", 
	       argv[0]); 
  }

  input_filename = check_mapfile(argv[next_arg+1]);
  output_filename = check_output(argv[next_arg+2], force);

  if(carmen_map_read_gridmap_chunk(input_filename, &map) < 0) 
    carmen_die("Error: %s did not contain a gridmap.\n", input_filename);
  carmen_map_read_offlimits_chunk_into_map(input_filename, &map);

  err = carmen_map_write_to_ppm(&map, output_filename);
  if (err < 0)
    carmen_die_syserror("Could not write ppm to %s", output_filename);
}
Example #5
0
long cb_passthrough_resampler_output(cubeb_stream * /*stm*/, void * /*user_ptr*/,
                                     const void * input_buffer,
                                     void * output_buffer, long frame_count)
{
  check_output(input_buffer, output_buffer, frame_count);
  return frame_count;
}
void focus_out_then_focus_in_with_aux_text_test()
{
    gboolean cleanBufferFocusOut = ibus_chewing_pre_edit_get_property_boolean
        (engine->icPreEdit, "clean-buffer-focus-out");

    ibus_chewing_pre_edit_save_property_boolean(engine->icPreEdit,
                                                "add-phrase-direction", TRUE);

    ibus_chewing_engine_set_capabilite(engine, IBUS_CAP_AUXILIARY_TEXT);
    ibus_chewing_engine_focus_in(engine);
    ibus_chewing_engine_enable(engine);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24, 0);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine),
                                          'j', 0x24, IBUS_RELEASE_MASK);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '3', 0x04, 0);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine),
                                          '3', 0x04, IBUS_RELEASE_MASK);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), 'j', 0x24, 0);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine),
                                          'j', 0x24, IBUS_RELEASE_MASK);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine), '3', 0x04, 0);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine),
                                          '3', 0x04, IBUS_RELEASE_MASK);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine),
                                          '2', 0x03, IBUS_CONTROL_MASK);
    ibus_chewing_engine_process_key_event(IBUS_ENGINE(engine),
                                          '2', 0x03, IBUS_RELEASE_MASK);
    check_output("", "五五", "已有:五五");

    /* focus out should not touch Texts */
    ibus_chewing_engine_focus_out(engine);
    g_assert(cleanBufferFocusOut == ibus_chewing_pre_edit_get_property_boolean
             (engine->icPreEdit, "clean-buffer-focus-out"));

    if (cleanBufferFocusOut) {
        check_output("", "", "");
    } else {
        check_output("", "五五", "已有:五五");
    }

    /* all should be clean */
    ibus_chewing_engine_focus_in(engine);
    check_output("", "", "");

    ibus_chewing_pre_edit_clear(engine->icPreEdit);
    check_output("", "", "");
}
Example #7
0
static enum handler_return
gpio_keypad_timer_func(struct timer *timer, time_t now, void *arg)
{
    struct gpio_kp *kp = keypad;
    struct gpio_keypad_info *kpinfo = kp->keypad_info;
    int polarity = !!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH);
    int out;
    int gpio;

    out = kp->current_output;
    if (out == kpinfo->noutputs) {
        out = 0;
        kp->some_keys_pressed = 0;
    } else {
        check_output(kp, out, polarity);
        out++;
    }

    kp->current_output = out;
    if (out < kpinfo->noutputs) {
        gpio = kpinfo->output_gpios[out];
        if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE)
            gpio_set(gpio, polarity);
        else
            gpio_config(gpio, polarity ? GPIO_OUTPUT : 0);
        timer_set_oneshot(timer, kpinfo->settle_time,
        gpio_keypad_timer_func, NULL);
        goto done;
    }

    if (/*!kp->use_irq*/ 1 || kp->some_keys_pressed) {
        event_signal(&kp->full_scan, false);
        timer_set_oneshot(timer, kpinfo->poll_time,
        gpio_keypad_timer_func, NULL);
        goto done;
    }

#if 0
    /* No keys are pressed, reenable interrupt */
    for (out = 0; out < kpinfo->noutputs; out++) {
        if (gpio_keypad_flags & GPIOKPF_DRIVE_INACTIVE)
            gpio_set(kpinfo->output_gpios[out], polarity);
        else
            gpio_config(kpinfo->output_gpios[out], polarity ? GPIO_OUTPUT : 0);
    }
    for (in = 0; in < kpinfo->ninputs; in++)
        enable_irq(gpio_to_irq(kpinfo->input_gpios[in]));
    return INT_RESCHEDULE;
#endif

done:
    return INT_RESCHEDULE;
}
Example #8
0
static void strip(int argc, char *argv[])
{
  char *input_filename, *output_filename, *chunk_type;
  carmen_FILE *fp_in, *fp_out;
  int next_arg;
  int force;

  next_arg = handle_options(argc, argv, &force);
  next_arg++;

  if(argc - next_arg != 4) {
    carmen_warn("\nError: wrong number of parameters.\n");    
    carmen_die("\nUsage: %s strip <in map filename> "
	       "<out map filename> <chunk type>\n\n", argv[0]);
  }

  input_filename = check_mapfile(argv[next_arg]);
  output_filename = check_output(argv[next_arg+1], force);
  chunk_type = argv[next_arg+2];

  fp_in = carmen_fopen(input_filename, "r");
  if(fp_in == NULL) 
    carmen_die_syserror("Could not open %s for reading", input_filename);

  fp_out = carmen_fopen(output_filename, "w");
  if(fp_out == NULL) 
    carmen_die_syserror("Could not open %s for writing", output_filename);
  
  if (carmen_strcasecmp(chunk_type, "laserscans") == 0) {
    if (carmen_map_strip(fp_in, fp_out, CARMEN_MAP_LASERSCANS_CHUNK) < 0) 
      carmen_die_syserror("Error: could not strip file");
  }
  else if (carmen_strcasecmp(chunk_type, "gridmap") == 0) {
    if (carmen_map_strip(fp_in, fp_out, CARMEN_MAP_GRIDMAP_CHUNK) < 0) 
      carmen_die_syserror("Error: could not strip file");
  }
  else if (carmen_strcasecmp(chunk_type, "offlimits") == 0) {
    if (carmen_map_strip(fp_in, fp_out, CARMEN_MAP_OFFLIMITS_CHUNK) < 0) 
      carmen_die_syserror("Error: could not strip file");
  }
  else if (carmen_strcasecmp(chunk_type, "expected") == 0) {
    if (carmen_map_strip(fp_in, fp_out, CARMEN_MAP_EXPECTED_CHUNK) < 0) 
      carmen_die_syserror("Error: could not strip file");
  }
  else if (carmen_strcasecmp(chunk_type, "places") == 0) {
    if (carmen_map_strip(fp_in, fp_out, CARMEN_MAP_PLACES_CHUNK) < 0) 
      carmen_die_syserror("Error: could not strip file");
  }

  carmen_fclose(fp_in);
  carmen_fclose(fp_out); 
}
Example #9
0
static void tomap(int argc, char *argv[]) 
{
  int next_arg;
  int force;
  double resolution;
  char *input_filename, *output_filename;
  carmen_map_t *map;
  carmen_FILE *out_fp;
  char buf[1024];

  gtk_init (&argc, &argv);

  next_arg = handle_options(argc, argv, &force);

  if(argc - next_arg != 4) {
    carmen_warn("\nError: wrong number of parameters.\n");    
    carmen_die("\nUsage: %s tomap <resolution> <ppm filename> "
	       "<map filename>\n\n", argv[0]); 
  }

  resolution = (double)atof(argv[next_arg+1]);

  if (resolution == 0) 
    carmen_die("%s translated to a resolution of 0.\n"
		"A positive, non-zero resolution is required.\n", 
		argv[next_arg+1]);
  
  input_filename = argv[next_arg+2];
  if(!carmen_file_exists(input_filename)) 
     carmen_die("Image file %s does not exist.\n", input_filename);

  output_filename = check_output(argv[next_arg+3], force);

  map = carmen_map_imagefile_to_map(input_filename, resolution);

  out_fp = carmen_fopen(output_filename, "w");
  if (carmen_map_write_id(out_fp) < 0)
    carmen_die_syserror("Couldn't write map id to %s", output_filename);

  sprintf(buf, "Created from %s", input_filename);
  if (carmen_map_write_creator_chunk(out_fp, "img_to_map", buf) < 0)
    carmen_die_syserror("Couldn't write creator chunk to %s", output_filename);

  if (carmen_map_write_gridmap_chunk(out_fp, map->map, map->config.x_size,
				     map->config.y_size, 
				     map->config.resolution) < 0)
    carmen_die_syserror("Couldn't write gridmap chunk to %s", output_filename);

  carmen_fclose(out_fp);
}
static void test_output() 
{ 
    check_output(STDOUT_FILENO, "message1-stdout"); 
    check_output(STDOUT_FILENO, "message2-stdout"); 
    check_output(STDERR_FILENO, "message1-stderr"); 
    check_output(STDERR_FILENO, "message2-stderr"); 
    check_output(10, "message1-10"); 
    check_output(10, "message2-10"); 
} 
Example #11
0
int main()
{
    int i;
    float src[N*N];
    float ref_fdct[N*N], ref_idct[N*N];
    float out_fdct[N*N], out_idct[N*N];

    for (i = 0; i < N*N; i++)
        src[i] = random() % 256;

    init_dct();

    fdct_ref(ref_fdct, src);
    fdct(out_fdct, src);
    if (check_output("FDCT", ref_fdct, out_fdct) < 0)
        return 1;

    idct_ref(ref_idct, ref_fdct);
    idct(out_idct, out_fdct);
    if (check_output("IDCT", ref_idct, out_idct) < 0)
        return 1;

    return 0;
}
Example #12
0
int
main(void){
  static float data_out [DATA_LEN] ;
  static float data_in [DATA_LEN] ;

  /* Do safest and most used sample rates first. */
  int sample_rates [] = { 44100, 48000, 32000, 22050, 16000, 96000 } ;
  unsigned k ;
  int errors = 0 ;
  int ch;

  gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);

  for(ch=1;ch<=8;ch++){
    float q=-.05;
    printf("\nTesting %d channel%s\n\n",ch,ch==1?"":"s");
    while(q<1.){
      for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
        char filename [64] ;
        snprintf (filename, sizeof (filename), "vorbis_%dch_q%.1f_%u.ogg", ch,q*10,sample_rates [k]);

        printf ("    %-20s : ", filename);
        fflush (stdout);

        /* Set to know value. */
        set_data_in (data_in, ARRAY_LEN (data_in), 3.141);

        write_vorbis_data_or_die (filename, sample_rates [k], q, data_out, ARRAY_LEN (data_out),ch);
        read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));

        if (check_output (data_in, ARRAY_LEN (data_in), (.15f - .1f*q)) != 0)
          errors ++ ;
        else {
          puts ("ok");
          remove (filename);
        }
      }
      q+=.1;
    }
  }

  if (errors)
    exit (1);
  
  printf("ALL OK\n");

  return 0;
}
Example #13
0
int
main (int argc, char *argv[])
{
  schro_init();

  check_output (SCHRO_WAVELET_DAUBECHIES_9_7, 1);
  check_output (SCHRO_WAVELET_DAUBECHIES_9_7, 0);

  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 1);
  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 0);

  check_output (SCHRO_WAVELET_LE_GALL_5_3, 1);
  check_output (SCHRO_WAVELET_LE_GALL_5_3, 0);

  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 1);
  check_output (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 0);
  
  check_endpoints (SCHRO_WAVELET_DAUBECHIES_9_7, 1);
  check_endpoints (SCHRO_WAVELET_DAUBECHIES_9_7, 0);

  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 1);
  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7, 0);

  check_endpoints (SCHRO_WAVELET_LE_GALL_5_3, 1);
  check_endpoints (SCHRO_WAVELET_LE_GALL_5_3, 0);

  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 1);
  check_endpoints (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7, 0);
  

  check_constant (SCHRO_WAVELET_DAUBECHIES_9_7);
  check_constant (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7);
  check_constant (SCHRO_WAVELET_LE_GALL_5_3);
  check_constant (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7);


  check_random (SCHRO_WAVELET_DAUBECHIES_9_7);
  check_random (SCHRO_WAVELET_DESLAURIERS_DUBUC_9_7);
  check_random (SCHRO_WAVELET_LE_GALL_5_3);
  check_random (SCHRO_WAVELET_DESLAURIERS_DUBUC_13_7);


  return 0;
}
Example #14
0
int
main(int argc, char **argv)
{
	char line[0x100];
	FILE *in = stdin;

	(void) argc;
	process_args(argv);

	errno = 0;
	if (epd_path != NULL) {
		if ((in = fopen(epd_path, "r")) == NULL) {
			perror(epd_path);
			exit(1);
		}
	}
	if (tmpnam(engine_in) == NULL)
		abort();
	if (tmpnam(engine_out) == NULL)
		abort();

	snprintf(engine_command_line, sizeof(engine_command_line),
	    "%s < %s > %s", engine_path, engine_in, engine_out);

	line_no = 1;

	while (fgets(line, sizeof(line), in) != NULL) {
		line[sizeof(line) - 1] = '\0';

		parse_line(line);

		if (node_count_limit == 0)
			node_count_limit = default_node_count_limit;

		if (best_move_count > 0 || avoid_move_count > 0) {
			generate_input();
			if (system(engine_command_line) != 0)
				exit(1);
			check_output();
		}

		++line_no;
	}

	printf("%u / %u\n", success_count, (line_no - 1));
}
Example #15
0
/*!	Load or eject medium
	load = true - load medium
*/
static bool
ata_load_eject(ide_device_info *device, ide_qrequest *qrequest, bool load)
{
	if (load) {
		// ATA doesn't support loading
		set_sense(device, SCSIS_KEY_ILLEGAL_REQUEST, SCSIS_ASC_PARAM_NOT_SUPPORTED);
		return false;
	}

	device->tf_param_mask = 0;
	device->tf.lba.command = IDE_CMD_MEDIA_EJECT;

	if (!send_command(device, qrequest, true, 15, ide_state_sync_waiting))
		return false;

	wait_for_sync(device->bus);

	return check_output(device, true, ide_error_abrt | ide_error_nm, false);
}
Example #16
0
/*! Flush internal device cache */
static bool
ata_flush_cache(ide_device_info *device, ide_qrequest *qrequest)
{
	// we should also ask for FLUSH CACHE support, but everyone denies it
	// (looks like they cheat to gain some performance advantage, but
	//  that's pretty useless: everyone does it...)
	if (!device->infoblock.write_cache_supported)
		return true;

	device->tf_param_mask = 0;
	device->tf.lba.command = device->use_48bits ? IDE_CMD_FLUSH_CACHE_EXT 
		: IDE_CMD_FLUSH_CACHE;

	// spec says that this may take more then 30s, how much more?
	if (!send_command(device, qrequest, true, 60, ide_state_sync_waiting))
		return false;

	wait_for_sync(device->bus);

	return check_output(device, true, ide_error_abrt, false);
}
Example #17
0
int
main(void){
  static float data_out [DATA_LEN] ;
  static float data_in [DATA_LEN] ;

  /* Do safest and most used sample rates first. */
  int sample_rates [] = { 44100, 48000, 32000, 22050, 16000, 96000 } ;
  unsigned k ;
  int errors = 0 ;

  gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);

  for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
        char filename [64] ;
        snprintf (filename, sizeof (filename), "vorbis_%u.ogg", sample_rates [k]);

        printf ("    %-20s : ", filename);
        fflush (stdout);

        /* Set to know value. */
        set_data_in (data_in, ARRAY_LEN (data_in), 3.141);

        write_vorbis_data_or_die (filename, sample_rates [k], data_out, ARRAY_LEN (data_out));
        read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));

        if (check_output (data_in, ARRAY_LEN (data_in)) != 0)
          errors ++ ;
        else {
          puts ("ok");
      remove (filename);
        }
  }

  if (errors)
    exit (1);

  return 0;
}
Example #18
0
static enum handler_return
gpio_keypad_timer_func(struct timer *timer, time_t now, void *arg)
{
	struct gpio_kp *kp = keypad;
	struct gpio_keypad_info *kpinfo = kp->keypad_info;
	int polarity = ! !(kpinfo->flags & GPIOKPF_ACTIVE_HIGH);
	int out;
	int gpio;

	out = kp->current_output;
	if (out == kpinfo->noutputs) {
		out = 0;
		kp->some_keys_pressed = 0;
	} else {
		check_output(kp, out, polarity);
		out++;
	}

	kp->current_output = out;
	if (out < kpinfo->noutputs) {
		gpio = kpinfo->output_gpios[out];

		if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE) {
			gpio_set(gpio, polarity);
		} else {
			gpio_config(gpio, polarity ? GPIO_OUTPUT : 0);
		}
		timer_set_oneshot(timer, kpinfo->settle_time, gpio_keypad_timer_func, NULL);
		goto done;
	} /*else*/
	if (kp->some_keys_pressed || 1) {
		timer_set_oneshot(timer, kpinfo->poll_time, gpio_keypad_timer_func, NULL);
		goto done;
	}
	
done:
	return INT_RESCHEDULE;
}
Example #19
0
int main(int argc, char ** argv)
{
    if (argc < 3) {
        print_usage_and_exit();
    }

    if (!strcmp(argv[1], "-creat")) {
        make_test_file(argv[2]);
    } else if (!strcmp(argv[1], "-check")) {
        check_output(argv[2]);
    } else {

        /* Do the main thing*/

        /* Open fds...*/
        int fd_in = open(argv[1], O_RDONLY);
        fprintf(stderr, "Opening %s... ", argv[1]);
        if (fd_in == -1) {
            perror("open() failed");
            exit(EXIT_FAILURE);
        }
        fprintf(stderr, "success\n");
        int fd_out = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
        fprintf(stderr, "Opening %s... ", argv[2]);
        if (fd_in == -1) {
            perror("open() failed");
            exit(EXIT_FAILURE);
        }
        fprintf(stderr, "success\n");

        /* Sorting procedure :
        *
        *       1. Sequentially read headers from input file and build index-tree
        *          that holds key, size and offset of records in input file.
        *       2. Then, walk the tree in ascending order
        *          and write records described by its nodes into output file
        */

        /*Current read position in file*/
        uint64_t in_position = 0;

        /*Tree top*/
        compact_header_t * tree = NULL;

        /*Total count of records in file (only for logging)*/
        int rec_cnt = 0;

        int fl_break = 0;
        while (!fl_break) {
            int r = do_process_record(fd_in, &in_position, &tree);
            switch (r) {
            case IO_EOF :
                /*file end is reached*/
                fl_break = 1;
                break;
            case IO_ERROR :
                fprintf(stderr, "File read error\n");
                exit(EXIT_FAILURE);
                break;
            case IO_SUCCESS :
                rec_cnt++;
                break;
            default :
                assert(0);
                break;
            }
        }

        fprintf(stderr, "Count of records: %i\n", rec_cnt);
        fprintf(stderr, "Writing sorted file...");
        walk_tree(fd_in, fd_out, tree);
        close(fd_in);
        close(fd_out);
        fprintf(stderr, "done\n");
    }
    return EXIT_SUCCESS;
}
Example #20
0
static void minimize(int argc, char *argv[])
{
  char *input_filename, *output_filename;
  int next_arg;
  carmen_FILE *in_fp, *out_fp;

  int ret_val;
  carmen_map_t map;
  int x_offset, y_offset;
  carmen_offlimits_list_t offlimits_list;
  carmen_map_placelist_t places;
  int force;
  int previous_num_places;

  next_arg = handle_options(argc, argv, &force);
  next_arg++;

  if(argc - next_arg != 2) {
    carmen_warn("\nError: wrong number of parameters.\n");    
    carmen_die("\nUsage: %s minimize <in map filename> <out map filename>\n\n",
	       argv[0]);
  }

  input_filename = check_mapfile(argv[next_arg]);
  output_filename = check_output(argv[next_arg+1], force);

  /*
   * Read the gridmap, places and offlimits chunks and minimize them
   */ 

  if (carmen_map_read_gridmap_chunk(input_filename, &map) < 0) {
    carmen_die_syserror("Couldn't read GRIDMAP_CHUNK from %s", input_filename);
  }

  carmen_warn("Map size was %d x %d, ",map.config.x_size, map.config.y_size);

  carmen_minimize_gridmap(&map, &x_offset, &y_offset);

  carmen_warn("is now %d x %d (offset %d, %d)\n", map.config.x_size, 
	      map.config.y_size, x_offset, y_offset);


  ret_val = carmen_map_chunk_exists(input_filename, 
				    CARMEN_MAP_OFFLIMITS_CHUNK);
  if (ret_val > 0) {
    ret_val = carmen_map_read_offlimits_chunk
      (input_filename, &(offlimits_list.offlimits), 
       &(offlimits_list.list_length));
    if (ret_val < 0)
      carmen_die_syserror("Couldn't read OFFLIMITS_CHUNK in %s",
			  input_filename);

    carmen_minimize_offlimits(&offlimits_list, x_offset*map.config.resolution, 
			      y_offset*map.config.resolution);
  } else
    offlimits_list.list_length = 0;

  ret_val = carmen_map_chunk_exists(input_filename, CARMEN_MAP_PLACES_CHUNK);
  if (ret_val > 0) {
    ret_val = carmen_map_read_places_chunk(input_filename, &places);
    if (ret_val < 0)
      carmen_die_syserror("Couldn't read PLACES_CHUNK in %s", input_filename);

    previous_num_places = places.num_places;
    carmen_minimize_places(&places, x_offset*map.config.resolution, 
			   y_offset*map.config.resolution, 
			   map.config.x_size*map.config.resolution,
			   map.config.y_size*map.config.resolution);
    if (places.num_places < previous_num_places)
      carmen_warn("%d place locations were dropped from the map after "
		  "minimization.\n", previous_num_places-places.num_places);
  } else
    places.num_places = 0;

  /*
   * Pass everything else through untouched, and then write the rotated
   * chunks at the end.
   */


  in_fp = carmen_fopen(input_filename, "r");
  if (in_fp == NULL)
    carmen_die_syserror("Couldn't open %s for reading", input_filename);

  out_fp = carmen_fopen(output_filename, "w");
  if (out_fp == NULL)
    carmen_die_syserror("Couldn't open %s for writing", output_filename);
  
  if (carmen_map_vstrip(in_fp, out_fp, 3, CARMEN_MAP_GRIDMAP_CHUNK,
			CARMEN_MAP_OFFLIMITS_CHUNK, 
			CARMEN_MAP_PLACES_CHUNK) < 0) 
    carmen_die_syserror("Couldn't strip map to %s", output_filename);
  

  if (carmen_map_write_gridmap_chunk(out_fp, map.map, map.config.x_size, 
				     map.config.y_size, 
				     map.config.resolution) < 0)
    carmen_die_syserror("Couldn't write gridmap to %s", output_filename);

  if (offlimits_list.list_length > 0) {
    if (carmen_map_write_offlimits_chunk(out_fp, offlimits_list.offlimits,
					 offlimits_list.list_length) < 0)
      carmen_die_syserror("Couldn't write offlimits list to %s", 
			  output_filename);
  }

  if (places.num_places > 0) {
    if (carmen_map_write_places_chunk(out_fp, places.places,
				      places.num_places) < 0)
      carmen_die_syserror("Couldn't write places list to %s", output_filename);
  }

  carmen_fclose(in_fp);
  carmen_fclose(out_fp);
}
Example #21
0
static void rotate(int argc, char *argv[])
{
  int force;
  char *input_filename, *output_filename;
  int next_arg;

  carmen_FILE *in_fp, *out_fp;
  int ret_val;
  carmen_map_t map;
  int rotation = 0;
  double remain;
  int degrees_angle;
  carmen_offlimits_list_t offlimits_list;
  carmen_map_placelist_t places_list;

  next_arg = handle_options(argc, argv, &force);
  next_arg++;

  if(argc - next_arg != 4) {
    carmen_warn("\nError: wrong number of parameters.\n");    
    carmen_die("\nUsage: %s rotate <rotation in degrees> <in map filename> "
	       "<out map filename>\n\n", argv[0]);
  }

  degrees_angle = (int)(atof(argv[next_arg]) / 90);
  remain = fabs(degrees_angle*90 - atof(argv[next_arg]));
  if (carmen_radians_to_degrees(remain) > 2)
    carmen_die("Rotations only supported in increments of 90 degrees.\n");
  else
    rotation = (int)atof(argv[next_arg]) / 90;

  input_filename = check_mapfile(argv[next_arg+1]);
  output_filename = check_output(argv[next_arg+2], force);

  carmen_warn("Rotating by %d degrees\n", rotation*90);

  /*
   * Read the gridmap, places and offlimits chunks and rotate them
   */ 

  ret_val = carmen_map_chunk_exists(input_filename, CARMEN_MAP_GRIDMAP_CHUNK);
  if (ret_val < 0)    
    carmen_die_syserror("Couldn't check existence of GRIDMAP_CHUNK in %s", 
			input_filename);
  
  if (carmen_map_read_gridmap_chunk(input_filename, &map) < 0)
    carmen_die_syserror("Couldn't read GRIDMAP_CHUNK from %s", input_filename);

  carmen_rotate_gridmap(&map, rotation);

  ret_val = carmen_map_chunk_exists(input_filename, 
				    CARMEN_MAP_OFFLIMITS_CHUNK);
  if (ret_val > 0) {
    ret_val = carmen_map_read_offlimits_chunk
      (input_filename, &(offlimits_list.offlimits), 
       &(offlimits_list.list_length));

    if (ret_val < 0)
      carmen_die_syserror("Couldn't read OFFLIMITS_CHUNK in %s",
			  input_filename);

    carmen_rotate_offlimits(map.config, &offlimits_list, rotation);
  } else
    offlimits_list.list_length = 0;

  ret_val = carmen_map_chunk_exists(input_filename, CARMEN_MAP_PLACES_CHUNK);
  if (ret_val > 0) {
    ret_val = carmen_map_read_places_chunk(input_filename, &places_list);
    if (ret_val < 0)
      carmen_die_syserror("Couldn't read PLACES_CHUNK in %s", input_filename);

    carmen_rotate_places(map.config, &places_list, rotation);
  } else
    places_list.num_places = 0;


  /*
   * Pass everything else through untouched, and then write the rotated
   * chunks at the end.
   */

  in_fp = carmen_fopen(input_filename, "r");
  if (in_fp == NULL)
    carmen_die_syserror("Couldn't open %s for reading", input_filename);

  out_fp = carmen_fopen(output_filename, "w");
  if (out_fp == NULL)
    carmen_die_syserror("Couldn't open %s for writing", output_filename);
  
  if (carmen_map_vstrip(in_fp, out_fp, 3, CARMEN_MAP_GRIDMAP_CHUNK,
			CARMEN_MAP_OFFLIMITS_CHUNK, 
			CARMEN_MAP_PLACES_CHUNK) < 0) 
    carmen_die_syserror("Couldn't strip map to %s", output_filename);

  if (carmen_map_write_gridmap_chunk(out_fp, map.map, map.config.x_size, 
				     map.config.y_size, 
				     map.config.resolution) < 0)
    carmen_die_syserror("Couldn't write gridmap to %s", output_filename);

  if (offlimits_list.list_length > 0) {
    if (carmen_map_write_offlimits_chunk(out_fp, offlimits_list.offlimits,
					 offlimits_list.list_length) < 0)
      carmen_die_syserror("Couldn't write offlimits list to %s", 
			  output_filename);
  }

  if (places_list.num_places > 0) {
    if (carmen_map_write_places_chunk(out_fp, places_list.places, 
				      places_list.num_places) < 0)
      carmen_die_syserror("Couldn't write places list to %s", output_filename);
  }

  carmen_fclose(in_fp);
  carmen_fclose(out_fp);
}
Example #22
0
int main(int argc, char **argv)
{
	double start, end;
	int ret;

	parse_args(argc, argv);

#ifdef STARPU_QUICK_CHECK
	niter /= 10;
#endif

	ret = starpu_init(NULL);
	if (ret == -ENODEV)
		return 77;
	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");

	starpu_cublas_init();

	init_problem_data();
	partition_mult_data();

	if (bound)
		starpu_bound_start(0, 0);

	start = starpu_timing_now();

	unsigned x, y, iter;
	for (iter = 0; iter < niter; iter++)
	{
		for (x = 0; x < nslicesx; x++)
		for (y = 0; y < nslicesy; y++)
		{
			struct starpu_task *task = starpu_task_create();

			task->cl = &cl;

			task->handles[0] = starpu_data_get_sub_data(A_handle, 1, y);
			task->handles[1] = starpu_data_get_sub_data(B_handle, 1, x);
			task->handles[2] = starpu_data_get_sub_data(C_handle, 2, x, y);

			task->flops = 2ULL * (xdim/nslicesx) * (ydim/nslicesy) * zdim;

			ret = starpu_task_submit(task);
			if (ret == -ENODEV)
			{
			     ret = 77;
			     goto enodev;
			}
			STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
		}

		starpu_task_wait_for_all();
	}


	end = starpu_timing_now();

	if (bound)
		starpu_bound_stop();

	double timing = end - start;
	double min, min_int;
	double flops = 2.0*((unsigned long long)niter)*((unsigned long long)xdim)
		           *((unsigned long long)ydim)*((unsigned long long)zdim);

	if (bound)
		starpu_bound_compute(&min, &min_int, 1);

	PRINTF("# x\ty\tz\tms\tGFlops");
	if (bound)
		PRINTF("\tTms\tTGFlops\tTims\tTiGFlops");
	PRINTF("\n");
	PRINTF("%u\t%u\t%u\t%.0f\t%.1f", xdim, ydim, zdim, timing/niter/1000.0, flops/timing/1000.0);
	if (bound)
		PRINTF("\t%.0f\t%.1f\t%.0f\t%.1f", min, flops/min/1000000.0, min_int, flops/min_int/1000000.0);
	PRINTF("\n");

enodev:
	starpu_data_unpartition(C_handle, STARPU_MAIN_RAM);
	starpu_data_unpartition(B_handle, STARPU_MAIN_RAM);
	starpu_data_unpartition(A_handle, STARPU_MAIN_RAM);

	starpu_data_unregister(A_handle);
	starpu_data_unregister(B_handle);
	starpu_data_unregister(C_handle);

	if (check)
		check_output();

	starpu_free(A);
	starpu_free(B);
	starpu_free(C);

	starpu_cublas_shutdown();
	starpu_shutdown();

	return ret;
}
Example #23
0
void add_command(const char* command, command_t source, command_stream_t cs, bool from_make, bool from_subshell){
	int line_count = 0;
	if(from_subshell){}
	int semi_index = -1, andor_index = -1, pipe_index = -1;
	int o_in = -1, c_in = -1;
	bool next_ch_pipe = false;
	bool next_ch_ampe = false;
	bool next_ch_cp = false;
	bool next_ch_semi = false;
	bool isLast = true;
	bool par_valid = true;
	int cmd_len = strlen(command);
	char ch;
	int iter = cmd_len - 1;
	
	//printf("this is the command we are on: %s\n", command);
	while(iter > -1){
		ch = command[iter];
		switch(ch){ //how to deal with redirects???
			    //how to deal with subshells?
			case ';':
				if(next_ch_semi){
					fprintf(stderr, "%d: (iter is %d) Syntax Error with %s\n", LINE+ curr_line_count, iter, command);
					cleanup(cs);
					exit(1);
				}
				if(((!isLast) && semi_index == -1) && !(o_in<iter && iter<c_in)){
					semi_index = iter;
				}
				next_ch_ampe = false;
				next_ch_pipe = false;
				next_ch_cp = false;
				next_ch_semi = true;
				isLast = false;
				par_valid = true;
				break;
			case '&':
				isLast = false;
				next_ch_semi = false;
				if(next_ch_ampe){ par_valid = true; }
				else par_valid = false;

				if(( (andor_index == -1) && next_ch_ampe) && !(o_in<iter && iter<c_in)
						){
					andor_index = iter;
				}
				else {
					next_ch_ampe = true;
				}
				next_ch_pipe = false;
				next_ch_cp = false;
				break;
			case '|':
				next_ch_semi = false;
				par_valid = true;
				isLast = false;
				if(pipe_index == -1  && !(o_in<iter && iter<c_in)){
					pipe_index = iter;
				}
				if(( (andor_index == -1) && next_ch_pipe) && !(o_in<iter && iter<c_in))
					{
					andor_index = iter;
					pipe_index = -1;
				}
				else {
					next_ch_pipe = true;
				}
				next_ch_ampe = false;
				next_ch_cp = false;
				break;
			case '\n':
				if(from_make){
					line_count = line_count + 1;
					 //LINE = LINE + 1;
					  }
				//line_count++;
				isLast = false;
			case ' ':
			case '\t':
				next_ch_ampe = false;
				next_ch_pipe = false;
				break;
			case ')':
				if(!par_valid) { // error
					fprintf(stderr, "%d: Syntax Error\n", LINE);
					cleanup(cs);
					exit(1);
				}
				next_ch_cp = true;
				next_ch_semi = false;
				if(c_in==-1 || (o_in > iter))
				{
					c_in = iter;
					o_in = 0;
					int count_ = 1;
					int k = iter-1;
					for(; k >= 0; k--){
						if(command[k] == ')') count_ = count_ + 1;
						if(command[k] == '(') count_ = count_ - 1;
						if(count_ == 0){ 
							o_in = k;
							break;
						}
					}
				}
				isLast = false;
				next_ch_ampe = false;
				next_ch_pipe = false;
				break;
			case '>':
			case '<':
				next_ch_semi = false;
				isLast = false;
				next_ch_ampe = false;
				next_ch_pipe = false;
				next_ch_cp = false;
				par_valid = true;
				break;

			default:
				next_ch_semi = false;
				isLast = false;
				next_ch_ampe = false;
				next_ch_pipe = false;
				next_ch_cp = false;
				par_valid = false;
				break;
		}	
		iter = iter - 1;
	}
	
	//source = (struct command*) malloc(sizeof(struct command));
	if(source == NULL){ //printf("malloc failed...\n"); 
		return; 
	}

	source->status = -1; //not sure what to do here
	source->input = NULL;
	source->output = NULL;
	
	if(semi_index != -1 && !(o_in<semi_index && semi_index<c_in)){ //semi colon found
		//printf("Above is a SEQUENCE (at position %d) command\n", semi_index);		
		source->type = SEQUENCE_COMMAND;
	
		char leftside[semi_index+1];
		char rightside[cmd_len - semi_index];
		strncpy(leftside, command, semi_index);
		leftside[semi_index] = '\0';
		strncpy(rightside, command + semi_index + 1, cmd_len - semi_index);

		source->u.command[0] = (struct command*) malloc(sizeof(struct command));
		source->u.command[1] = (struct command*) malloc(sizeof(struct command));
		add_command(leftside, source->u.command[0], cs, false, false);
		add_command(rightside, source->u.command[1], cs, false, false);
	}	
	else if(andor_index != -1 && !(o_in<andor_index && andor_index<c_in)){ //and or or found
		//printf("Above is an AND/OR (at position %d) command\n", andor_index);
		if(command[andor_index] == '&'){	
			source->type = AND_COMMAND; 
		}
		else{
			source->type = OR_COMMAND;
		}

		char leftside[andor_index+1];
		char rightside[cmd_len - andor_index - 1];
		strncpy(leftside, command, andor_index);
		leftside[andor_index] = '\0';
		strncpy(rightside, command + andor_index + 2, cmd_len - andor_index - 1);
		//printf("Line:%d, command:%s\n right:%s\n left:%s\n", LINE, command, rightside, leftside);
		//printf("lenth of rightside is: %d", (int)strlen(rightside));
	//	printf("leftside is: %s\n THIS IS AN AND/OR\nrightside is: %s\n", leftside, rightside);
		source->u.command[0] = (struct command*) malloc(sizeof(struct command));
		source->u.command[1] = (struct command*) malloc(sizeof(struct command));
		add_command(leftside, source->u.command[0], cs, false, false);
		add_command(rightside, source->u.command[1], cs, false, false);
	


	}
	else if(pipe_index != -1 && !(o_in<pipe_index && pipe_index<c_in)){ //pipe found
		//printf("Above is a PIPE (at position %d) command\n", pipe_index);
		source->type = PIPE_COMMAND;

		char leftside[pipe_index+1];
		char rightside[cmd_len - pipe_index];
		strncpy(leftside, command, pipe_index);
		leftside[pipe_index] = '\0';
		strncpy(rightside, command + pipe_index + 1, cmd_len - pipe_index);

		source->u.command[0] = (struct command*) malloc(sizeof(struct command));
		source->u.command[1] = (struct command*) malloc(sizeof(struct command));
		add_command(leftside, source->u.command[0], cs, false, false);
		add_command(rightside, source->u.command[1], cs, false, false);
	

	}
	else{
		//printf("Above is a SIMPLE or SUBSHELL command\n");
		if(o_in != -1){
			source->type = SUBSHELL_COMMAND;
			//size_t i;
			int start_ = o_in;
			int finish_ = c_in;
			char temp[strlen(command)];
			bzero(temp, strlen(command));
			strncpy(temp, command + start_ + 1, finish_ - start_ - 1);
			source->u.subshell_command = (command_t) malloc(sizeof(struct command));
			//printf("subshell starts at %d, finishes at %d: %s\n", start_, finish_, temp);
			add_command(temp, source->u.subshell_command, cs, false, true);
		}
		else{
			source->type = SIMPLE_COMMAND;
			source->u.word = NULL;
			//check for validity
		//	printf("command: %s\n", command);
			int err = isValid(command, LINE);
		//	printf("line %d: %s\n", LINE, command);
			if(err!=0 || isBlank(command)) {
				if(err == 0)
				{
					//printf("command: %s\n", command);
					fprintf(stderr, "%d: Syntax Error\n", LINE+curr_line_count);
				}
				else
					fprintf(stderr, "%d: Syntax Error\n", LINE+ curr_line_count);
				cleanup(cs);
				exit(1);
			}
		}

			//find leading whitespace
			int i;
			int wsc_ = 0;
			int len = strlen(command);
			for(i = 0; i < len; i++){
				if( command[i] == ' '  ||
				    command[i] == '\n' ||
				    command[i] == '\t' ){
					wsc_ = wsc_ + 1;	
				}
				else{
					break;
				}
			}
			int rwsc_ = 0;
			if(wsc_ < len){
				for(i = len -1; i >= 0; i--){
					if( command[i] == ' '  ||
					    command[i] == '\n' ||
					    command[i] == '\t' ||
					    command[i] == ';' ){
						rwsc_ = rwsc_ + 1;	
					}
					else{
						break;
					}
				}
			}

			char* str = (char*) malloc(len - wsc_ - rwsc_ + 1);
			bzero(str, len - wsc_ - rwsc_ + 1);
			memcpy(str, command + wsc_, len - wsc_ - rwsc_);
		
			char* input = NULL; 
			char* output = NULL;

  			int in = check_input(str);
  			int out = check_output(str);
  			//!(o_in<in && in<c_in)
  			bool misplacedIO = (in>o_in && in<c_in) || (out>o_in && out<c_in);
			if(in > out && out > 0){
				fprintf(stderr, "%d: Syntax Error\n", LINE);
				cleanup(cs);
				exit(1);
			} 
  			if(in>0 && out>0 && ((c_in < in && c_in < out) || !misplacedIO)) {
  				input = (char*) malloc(out-in);
  				bzero(input, out-in);
  				//remove whitespaces
  				int f_ws = remove_ws(str, in+1, FORWARD);
  				int b_ws = remove_ws(str, out-1, BACKWARD);

      			memcpy(input, str+f_ws, b_ws-f_ws+1);
				source->input = input;

				int ws = remove_ws(str, out+1, FORWARD);
				output = (char*) malloc(strlen(str)-out);
      			memcpy(output, str+ws, strlen(str)-ws);
				source->output = output;
				//create a new command
				if(source->type == SIMPLE_COMMAND) {
					char** new_cmd = (char**)malloc(sizeof(char*));
					*new_cmd = (char*)malloc(in+1);
				  	bzero(*new_cmd, in+1);
				  	ws = remove_ws(str, in-1, BACKWARD);
				    memcpy(*new_cmd, str, ws+1);
				    free(str);
				    source->u.word = new_cmd;
				}
			    //printf("input:%s\n", input);
			    //printf("output:%s\n", output);
  			}
			else if(in > 0 && (c_in < in || !misplacedIO)) {
				input = (char*) malloc(strlen(str)-in);
				bzero(input, strlen(str)-in);
				//remove whitespaces
				int ws = remove_ws(str, in+1, FORWARD);
      			memcpy(input, str+ws, strlen(str)-ws);
				source->input = input;
				//create a new command
				if(source->type == SIMPLE_COMMAND) {
					char** new_cmd = (char**)malloc(sizeof(char*));
					*new_cmd = (char*)malloc(in+1);
				  	bzero(*new_cmd, in+1);
				  	ws = remove_ws(str, in-1, BACKWARD);
				    memcpy(*new_cmd, str, ws+1);
				    free(str);
				    source->u.word = new_cmd;
				}
			    //printf("input:%s\n", input);
			}
			else if(out > 0 && (c_in < out || !misplacedIO)) {
				output = (char*) malloc(strlen(str)-out);
				bzero(output, strlen(str)-out);
				//remove whitespaces
				int ws = remove_ws(str, out+1, FORWARD);
      			memcpy(output, str+ws, strlen(str)-ws);
				source->output = output;
				//create a new command
				if(source->type == SIMPLE_COMMAND) {
					char** new_cmd = (char**)malloc(sizeof(char*));
					*new_cmd = (char*)malloc(out+1);
				  	bzero(*new_cmd, out+1);
				  	ws = remove_ws(str, out-1, BACKWARD);
				    memcpy(*new_cmd, str, ws+1);
				    free(str);
				    source->u.word = new_cmd;
				}
			    //printf("output:%s\n", output);
			}
			else 
			{
				if(source->type == SIMPLE_COMMAND) {
					char** ptr = (char**)malloc(sizeof(char*));
					*ptr = str;
					source->u.word = ptr;
				}
				source->input = NULL;
				source->output = NULL;
				//printf("no input/output\n");
			}

			//printf("command:%s\n", *(source->u.word));
	}
	
	if(from_make){
		LINE = LINE + line_count + 1;
		curr_line_count = 0;
	}
	//
	//free(curr_cmd);
	//
	
}
Example #24
0
const saladstate_t parse_predict_options(int argc, char* argv[], config_t* const config)
{
	assert(argv != NULL);
	assert(config != NULL);

	int option, bs = FALSE;
	while ((option = getopt_long(argc, argv, PREDICT_OPTION_STR, predict_longopts, NULL)) != -1)
	{
		switch (option)
		{
		case 'i':
			config->input = optarg;
			break;

		case 'f':
			config->input_type = as_iomode(optarg);
			break;

		case OPTION_INPUTFILTER:
			config->input_filter = optarg;
			break;

		case OPTION_BATCHSIZE:
		{
			int batch_size = atoi(optarg); // TODO: strtol
			if (batch_size <= 0)
			{
				warn("Illegal batch size specified.");
				// This is not true in case of network data as input. Therefore,
				// we simply suppress this output at this point.
				// warn("Defaulting to: %u\n", (unsigned int) config->batch_size);
			}
			else
			{
				bs = TRUE;
				config->batch_size = batch_size;
			}
			break;
		}
#ifdef GROUPED_INPUT
		case 'g':
			config->group_input = TRUE;
			break;
#endif
#ifdef USE_NETWORK
		case 'p':
			config->pcap_filter = optarg;
			break;
#endif
		case 'o':
			config->output = optarg;
			break;

		case 'b':
			config->bloom = optarg;
			break;

		case OPTION_BBLOOM:
			config->bbloom = optarg;
			break;

		case 'r':
			config->nan = optarg;
			break;

		case 'e':
			config->echo_params = TRUE;
			break;

		case '?':
		case 'h':
			return SALAD_HELP_PREDICT;

		default:
			// In order to catch program argument that correspond to
			// features that were excluded at compile time.
			fprintf(stderr, "invalid option -- '%c'\n", option);
			return SALAD_HELP_PREDICT;
		}
	}

	if (check_input(config, FALSE, bs) == EXIT_FAILURE) return SALAD_EXIT;
	if (check_output(config) == EXIT_FAILURE) return SALAD_EXIT;

	if (config->echo_params)
	{
		// cf. salad_predict_stub
	}
	return SALAD_RUN;
}
Example #25
0
const saladstate_t parse_traininglike_options_ex(int argc, char* argv[], config_t* const config,
		const char *shortopts, const struct option *longopts)
{
	assert(argv != NULL);
	assert(config != NULL);

	int option, bs = FALSE, fo = FALSE;
	while ((option = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
	{
		switch (option)
		{
		case 'i':
			config->input = optarg;
			break;

		case 'f':
			config->input_type = as_iomode(optarg);
			break;

		case OPTION_INPUTFILTER:
			config->input_filter = optarg;
			break;

		case OPTION_BATCHSIZE:
		{
			int batch_size = atoi(optarg); // TODO: strtol
			if (batch_size <= 0)
			{
				warn("Illegal batch size specified.\n");
				// This is not true in case of network data as input. Therefore,
				// we simply suppress this output at this point.
				// warn("Defaulting to: %u\n", (unsigned int) config->batch_size);
			}
			else
			{
				bs = TRUE;
				config->batch_size = batch_size;
			}
			break;
		}
#ifdef USE_NETWORK
		case 'p':
			config->pcap_filter = optarg;
			break;
#endif
		case 'b':
			config->bloom = optarg;
			break;

		case 'u':
			config->update_model = TRUE;
			break;

		case 'o':
			config->output = optarg;
			break;

		case 'n':
		{
			fo = TRUE;
			int ngramLength = atoi(optarg); // TODO: strtol
			if (ngramLength <= 0)
			{
				warn("Illegal n-gram length specified.");
				warn("Defaulting to: %u\n", (unsigned int) config->ngramLength);
			}
			else config->ngramLength = ngramLength;
			break;
		}
		case 'd':
			fo = TRUE;
			config->delimiter = optarg;
			break;

		case 's':
		{
			fo = TRUE;
			int filter_size = atoi(optarg); // TODO: strtol
			if (filter_size <= 0)
			{
				warn("Illegal filter size specified.");
				warn("Defaulting to: %u\n", (unsigned int) config->filter_size);
			}
			else config->filter_size = filter_size;
			break;
		}
		case OPTION_HASHSET:
		{
			fo = TRUE;
			hashset_t hashset = to_hashset(optarg);
			if (hashset == HASHES_UNDEFINED)
			{
				warn("Illegal hash set specified.");
				warn("Defaulting to: %s\n", hashset_to_string(config->hash_set));
			}
			else config->hash_set = hashset;
			break;
		}
		case 'e':
			config->echo_params = TRUE;
			break;

		case '?':
		case 'h':
			return SALAD_HELP_TRAIN;

		default:
			// In order to catch program argument that correspond to
			// features that were excluded at compile time.
			fprintf(stderr, "invalid option -- '%c'\n", option);
			return SALAD_HELP_TRAIN;
		}
	}

	config->transfer_spec = !fo;

	if (check_input(config, TRUE, bs) == EXIT_FAILURE) return SALAD_EXIT;
	if (check_output(config) == EXIT_FAILURE) return SALAD_EXIT;

	if (config->echo_params)
	{
		if (config->update_model && config->transfer_spec) {
			// cf. salad_train_stub
		} else {
			echo_options(config);
		}
	}
	return SALAD_RUN;
}
Example #26
0
File: main.c Project: chwress/salad
const saladstate_t parse_traininglike_options_ex(int argc, char* argv[], config_t* const config,
		const char *shortopts, const struct option *longopts)
{
	assert(argv != NULL);
	assert(config != NULL);

	char* end; // For parsing numbers with strto*
	int conly = FALSE, sonly = FALSE;

	int option, bs = FALSE, fo = FALSE;
	while ((option = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
	{
		switch (option)
		{
		case 'i':
			config->input = optarg;
			break;

		case 'f':
			config->input_type = as_inputmode(optarg);
			break;

		case OPTION_INPUTFILTER:
			config->input_filter = optarg;
			break;

		case OPTION_BATCHSIZE:
		{
			const long long int batch_size = strtoll(optarg, &end, 10);
			if (batch_size <= 0)
			{
				warn("Illegal batch size specified.\n");
				// This is not true in case of network data as input. Therefore,
				// we simply suppress this output at this point.
				// warn("Defaulting to: %u\n", (unsigned int) config->batch_size);
			}
			else
			{
				bs = TRUE;
				config->batch_size = (size_t) MIN(SIZE_MAX, (unsigned long) MAX(0, batch_size));
			}
			break;
		}

#ifdef USE_NETWORK
		case 'p':
			config->pcap_filter = optarg;
			break;

		case OPTION_NETCLIENT:
			conly = TRUE;
			break;

		case OPTION_NETSERVER:
			sonly = TRUE;
			break;
#endif
		case 'b':
			config->bloom = optarg;
			break;

		case 'u':
			config->update_model = TRUE;
			break;

		case 'o':
			config->output = optarg;
			break;

		case 'F':
			config->output_type = as_outputmode(optarg);
			break;

		case 'n':
		{
			fo = TRUE;
			const long long int ngram_length = strtoll(optarg, &end, 10);
			if (ngram_length <= 0)
			{
				warn("Illegal n-gram length specified.");
				warn("Defaulting to: %"ZU"\n", (SIZE_T) config->ngram_length);
			}
			else config->ngram_length = (size_t) MIN(SIZE_MAX, (unsigned long) ngram_length);
			break;
		}
		case 'd':
			fo = TRUE;
			config->delimiter = optarg;
			break;

		case OPTION_BINARY:
			config->binary_ngrams = TRUE;
			break;

		case 's':
		{
			fo = TRUE;
			const long long int filter_size = strtoll(optarg, &end, 10);
			if (filter_size <= 0)
			{
				warn("Illegal filter size specified.");
				warn("Defaulting to: %u\n", (unsigned int) config->filter_size);
			}
			else config->filter_size = (unsigned int) MIN(UINT_MAX, (unsigned long) MAX(0, filter_size));
			break;
		}
		case OPTION_HASHSET:
		{
			fo = TRUE;
			hashset_t hashset = to_hashset(optarg);
			if (hashset == HASHES_UNDEFINED)
			{
				warn("Illegal hash set specified.");
				warn("Defaulting to: %s\n", hashset_to_string(config->hash_set));
			}
			else config->hash_set = hashset;
			break;
		}
		case 'e':
			config->echo_params = TRUE;
			break;

		case 'q':
			log_level = WARNING;
			break;

		case '?':
		case 'h':
			log_level = STATUS;
			return SALAD_HELP_TRAIN;

		default:
			// In order to catch program argument that correspond to
			// features that were excluded at compile time.
			fprintf(stderr, "invalid option -- '%c'\n", option);
			return SALAD_HELP_TRAIN;
		}
	}

	config->transfer_spec = !fo;

	if (config->binary_ngrams && config->ngram_length > MASK_BITSIZE)
	{
		error("When using binary n-grams currently only a maximal");
		error("length of %u bits is supported.", MASK_BITSIZE);
		return SALAD_EXIT;
	}

	if (check_netparams(config, conly, sonly) == EXIT_FAILURE) return SALAD_HELP_TRAIN;
	if (check_input(config, TRUE, bs) == EXIT_FAILURE) return SALAD_EXIT;
	if (check_output(config) == EXIT_FAILURE) return SALAD_EXIT;

	if (config->echo_params)
	{
		if (config->update_model && config->transfer_spec) {
			// cf. salad_train_stub
		} else {
			echo_options(config);
		}
	}
	return SALAD_RUN;
}