Exemple #1
0
static const char* process_config(void *mconfig,cmd_parms *parms,ngx_pool_t *p,ngx_pool_t *temp_pool){
    
    ngx_int_t rc;
	const char *errval;
    struct ngx_varbuf vb;
    size_t max_len = VARBUF_MAX_LEN;
    
    if(p == temp_pool) max_len = HUGE_STRING_LEN;
    
    ngx_varbuf_init(temp_pool, &vb, VARBUF_INIT_LEN);

    while ((rc = ngx_varbuf_cfg_getline(&vb, parms->config_file, max_len))
           == NGX_OK) {
        errval = process_cmd_line(mconfig,p, temp_pool, vb.buf, parms);

        if (errval!=NULL){

			if(p!=temp_pool) ngx_varbuf_free(&vb);
			
			return errval;
		}
    }

    if(p!=temp_pool) ngx_varbuf_free(&vb);

    return NULL;
}
Exemple #2
0
int main(int argc, char **argv)
{
  state *s = (state *)malloc(sizeof(state));

#ifndef __GLIBC__
  __progname  = strdup(basename(argv[0]));
#endif

  if (s == NULL)
      fatal_error("Unable to allocate state");

  if (initialize_state(s))
    fatal_error("Unable to initialize state");

  if (process_cmd_line(s,argc,argv))
    return EXIT_FAILURE;

  argv += optind;
  argc -= optind;

  /* We must have two files to compare */
  if (argc != 2)
    {
      usage();
      return EXIT_FAILURE;
    }

  if (compare_files(s,*argv,*(argv+1)))
    return EXIT_FAILURE;

  return EXIT_SUCCESS;
}
Exemple #3
0
int main(int argc, char **argv)
{
  state *s = (state *)malloc(sizeof(state));

#ifndef __GLIBC__
  __progname  = strdup(basename(argv[0]));
#endif

  if (initialize_state(s))
    return EXIT_FAILURE;

  if (process_cmd_line(s,argc,argv))
    return EXIT_FAILURE;

  argv += optind;
      
  while (*argv != NULL) {
    make_bmp_from_file(s,*argv);
    ++argv;
  }

  // We don't bother cleaning up the state as we're about to exit. 
  // All of the memory we have
  // allocated is going to be returned to the operating system, so
  // there's no point in our explicitly free'ing it. 
  
  return EXIT_SUCCESS;
}
Exemple #4
0
int main(int argc, char *argv[]) {
    board_t *board = NULL;
    int ret = 0;
    encoder_module_t enc;

    if (argc == 1) {
        print_short_usage();
        return 0;
    }
    if (process_cmd_line(argc, argv) == -1) {
        return -1;
    }

    board_access.verbose = verbose_flag;

    if (anyio_init(&board_access) != 0) {     // init library
        return -1;
    }
    ret = anyio_find_dev(&board_access);      // find board
    if (ret < 0) {
        return -1;
    }
    board = anyio_get_dev(&board_access, 1);  // if found the get board handle
    if (board == NULL) {
        printf("No %s board found\n", board_access.device_name);
        return -1;
    }

    board->open(board);                 // open board for communication
    board->print_info(board);           // print what card it is 
    hm2_read_idrom(&(board->llio.hm2));     // read hostmot2 idrom

    ret = encoder_init(&enc, board, instance, delay);   // init encoder 'instance' module on 'board'
    if (ret < 0) {
        goto fail0;
    }

    while (1) {
        encoder_read(&enc);             // read encoder 
        printf("tsc = %u, raw_counts = %u, velocity = %.2f\n", enc.global_time_stamp, enc.raw_counts, enc.velocity);
        usleep(delay*1000);             // wait delay ms
    }

    encoder_cleanup(&enc);              // cleanup enocder module
    
fail0:
    board->close(board);                // close board communication

    anyio_cleanup(&board_access);             // close library

    return 0;
}
Exemple #5
0
void main_loop(const char** argv)
    {
    map<string, string> params;
    process_cmd_line(argv, params);

    Lab2VitMain mainObj(params);
    while (mainObj.init_utt())
        {
        double logProb = viterbi(mainObj.get_graph(),
            mainObj.get_gmm_probs(), mainObj.get_chart(),
            mainObj.get_label_list(), mainObj.get_acous_wgt(),
            mainObj.do_align());
        mainObj.finish_utt(logProb);
        }
    mainObj.finish();
    }
Exemple #6
0
void main_loop(const char** argv)
    {
    map<string, string> params;
    process_cmd_line(argv, params);

    Lab2TrainMain mainObj(params);
    GmmStats gmmStats(mainObj.get_gmm_set(), params);
    while (mainObj.init_iter())
        {
        gmmStats.clear();
        while (mainObj.init_utt())
            {
            double logProb = gmmStats.update(mainObj.get_gmm_counts(),
                mainObj.get_feats());
            mainObj.finish_utt(logProb);
            }
        mainObj.finish_iter();
        gmmStats.reestimate();
        }
    mainObj.finish();
    }
Exemple #7
0
int main(int argc, char **argv)
{
  int count, status, goal = argc;
  state *s;
  TCHAR *fn, *cwd;

#ifndef __GLIBC__
  __progname  = basename(argv[0]);
#endif

  s = (state *)malloc(sizeof(state));
  if (NULL == s)
    fatal_error("%s: Unable to allocate state variable", __progname);

  if (initialize_state(s))
    fatal_error("%s: Unable to initialize state variable", __progname);

  process_cmd_line(s,argc,argv);

#ifdef _WIN32
  if (prepare_windows_command_line(s))
    fatal_error("%s: Unable to process command line arguments", __progname);
#else
  s->argc = argc;
  s->argv = argv;
#endif

  // Anything left on the command line at this point is a file
  // or directory we're supposed to process. If there's nothing
  // specified, we should tackle standard input 
  if (optind == argc)
  {
    status = process_stdin(s);
  }
  else
  {
    MD5DEEP_ALLOC(TCHAR,fn,PATH_MAX);
    MD5DEEP_ALLOC(TCHAR,cwd,PATH_MAX);
    
    cwd = _tgetcwd(cwd,PATH_MAX);
    if (NULL == cwd)
      fatal_error("%s: %s", __progname, strerror(errno));
  
    count = optind;
  
    // The signature comparsion mode needs to use the command line
    // arguments and argument count. We don't do wildcard expansion
    // on it on Win32 (i.e. where it matters). The setting of 'goal'
    // to the original argc occured at the start of main(), so we just
    // need to update it if we're *not* in signature compare mode.
    if (!(s->mode & mode_sigcompare))
    {
      goal = s->argc;
    }
    
    while (count < goal)
    {
      if (MODE(mode_sigcompare))
	match_load(s,argv[count]);
      else if (MODE(mode_compare_unknown))
	match_compare_unknown(s,argv[count]);
      else
      {
	generate_filename(s,fn,cwd,s->argv[count]);

#ifdef _WIN32
	status = process_win32(s,fn);
#else
	status = process_normal(s,fn);
#endif
      }
      
      ++count;
    }

    // If we processed files, but didn't find anything large enough
    // to be meaningful, we should display a warning message to the user.
    // This happens mostly when people are testing very small files
    // e.g. $ echo "hello world" > foo && ssdeep foo
    if ( ! s->found_meaningful_file && s->processed_file)
    {
      print_error(s,"%s: Did not process files large enough to produce meaningful results", __progname);
    }
  }


  // If the user has requested us to compare signature files, use
  // our existng code to pretty-print directory matching to do the
  // work for us.
  if (s->mode & mode_sigcompare)
    s->mode |= mode_match_pretty;
  if (s->mode & mode_match_pretty)
    match_pretty(s);
  
  return (EXIT_SUCCESS);
}
Exemple #8
0
int main(
    int argc,
    char const* argv[])
{
  YR_COMPILER* compiler;
  YR_RULES* rules;
  FILE* rule_file;
  EXTERNAL* external;

  int pid;
  int i;
  int errors;
  int result;

  THREAD thread[MAX_THREADS];

  if (!process_cmd_line(argc, argv))
    return 0;

  if (argc == 1 || optind == argc)
  {
    show_help();
    return 0;
  }

  yr_initialize();

  result = yr_rules_load(argv[optind], &rules);

  if (result == ERROR_UNSUPPORTED_FILE_VERSION ||
      result == ERROR_CORRUPT_FILE)
  {
    print_scanning_error(result);
    return;
  }

  if (result == ERROR_SUCCESS)
  {
    external = externals_list;

    while (external != NULL)
    {
      switch (external->type)
      {
        case EXTERNAL_TYPE_INTEGER:
          yr_rules_define_integer_variable(
              rules,
              external->name,
              external->integer);
          break;

        case EXTERNAL_TYPE_BOOLEAN:
          yr_rules_define_boolean_variable(
              rules,
              external->name,
              external->boolean);
          break;

        case EXTERNAL_TYPE_STRING:
          yr_rules_define_string_variable(
              rules,
              external->name,
              external->string);
          break;
      }
      external = external->next;
    }
  }
  else
  {
    if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
      return 0;

    external = externals_list;

    while (external != NULL)
    {
      switch (external->type)
      {
        case EXTERNAL_TYPE_INTEGER:
          yr_compiler_define_integer_variable(
              compiler,
              external->name,
              external->integer);
          break;

        case EXTERNAL_TYPE_BOOLEAN:
          yr_compiler_define_boolean_variable(
              compiler,
              external->name,
              external->boolean);
          break;

        case EXTERNAL_TYPE_STRING:
          yr_compiler_define_string_variable(
              compiler,
              external->name,
              external->string);
          break;
      }
      external = external->next;
    }

    compiler->error_report_function = print_compiler_error;
    rule_file = fopen(argv[optind], "r");

    if (rule_file != NULL)
    {
      yr_compiler_push_file_name(compiler, argv[optind]);

      errors = yr_compiler_add_file(compiler, rule_file, NULL);

      fclose(rule_file);

      if (errors == 0)
        yr_compiler_get_rules(compiler, &rules);

      yr_compiler_destroy(compiler);

      if (errors > 0)
      {
        yr_finalize();
        return 0;
      }
    }
    else
    {
      fprintf(stderr, "could not open file: %s\n", argv[optind]);
      return 0;
    }
  }

  mutex_init(&output_mutex);

  if (is_numeric(argv[argc - 1]))
  {
    pid = atoi(argv[argc - 1]);
    result = yr_rules_scan_proc(
        rules,
        pid,
        callback,
        (void*) argv[argc - 1],
        fast_scan,
        timeout);

    if (result != ERROR_SUCCESS)
      print_scanning_error(result);
  }
  else if (is_directory(argv[argc - 1]))
  {
    file_queue_init();

    for (i = 0; i < threads; i++)
    {
      if (create_thread(&thread[i], scanning_thread, (void*) rules) != 0)
        return ERROR_COULD_NOT_CREATE_THREAD;
    }

    scan_dir(
        argv[argc - 1],
        recursive_search,
        rules,
        callback);

    file_queue_finish();

    // Wait for scan threads to finish
    for (i = 0; i < threads; i++)
      thread_join(&thread[i]);

    file_queue_destroy();
  }
  else
  {
    result = yr_rules_scan_file(
        rules,
        argv[argc - 1],
        callback,
        (void*) argv[argc - 1],
        fast_scan,
        timeout);
 
    if (result != ERROR_SUCCESS)
    {
      fprintf(stderr, "Error scanning %s: ", argv[argc - 1]);
      print_scanning_error(result);
    }
  }

  yr_rules_destroy(rules);
  yr_finalize();

  mutex_destroy(&output_mutex);
  cleanup();

  return 1;
}
Exemple #9
0
int main(
    int argc,
    char const* argv[])
{
  int i, result, errors;

  YR_COMPILER* compiler;
  YR_RULES* rules;
  FILE* rule_file;

  yr_initialize();

  if (yr_compiler_create(&compiler) != ERROR_SUCCESS)
  {
    yr_finalize();
    return EXIT_FAILURE;
  }

  if (!process_cmd_line(compiler, argc, argv))
  {
    yr_compiler_destroy(compiler);
    yr_finalize();
    return EXIT_FAILURE;
  }

  if (argc == 1 || optind == argc)
  {
    show_help();
    yr_compiler_destroy(compiler);
    yr_finalize();
    return EXIT_FAILURE;
  }

  compiler->error_report_function = report_error;

  for (i = optind; i < argc - 1; i++)
  {
    rule_file = fopen(argv[i], "r");

    if (rule_file != NULL)
    {
      yr_compiler_push_file_name(compiler, argv[i]);

      errors = yr_compiler_add_file(compiler, rule_file, NULL);

      fclose(rule_file);

      if (errors) // errors during compilation
      {
        yr_compiler_destroy(compiler);
        yr_finalize();
        return EXIT_FAILURE;
      }
    }
    else
    {
      fprintf(stderr, "could not open file: %s\n", argv[i]);
    }
  }

  result = yr_compiler_get_rules(compiler, &rules);

  if (result != ERROR_SUCCESS)
  {
    fprintf(stderr, "error: %d\n", result);
    return EXIT_FAILURE;
  }

  result = yr_rules_save(rules, argv[argc - 1]);

  if (result != ERROR_SUCCESS)
  {
    fprintf(stderr, "error: %d\n", result);
    return EXIT_FAILURE;
  }

  yr_rules_destroy(rules);
  yr_compiler_destroy(compiler);

  yr_finalize();

  return EXIT_SUCCESS;
}
Exemple #10
0
int fpga_init(int argc, char *argv[], int *dev_out) {
	
	int k, r;
	struct cmd_params_t	cmd_p;
	
	unsigned int reg_val;
	
	flag_compare=0;
	flag_rand=0;
	flag_file = 0; 

	if (process_cmd_line(argc, argv, &cmd_p) < 0) {
		return -1;
	}

	printf("\nSearching for RC47 boards\n");

	k = rc47_search_for_boards(pd,rc47);

	if (k<0) {
		fprintf (stderr,"No boards in system!\n\n");
		return 0;
	} else 
	if (k==1)		
	printf("Found %d board\n",k);
	else
	printf("Found %d boards\n",k);


	rc47_print_device_info(k,rc47);


	if (cmd_p.board >= k) {
		fprintf (stderr,"Invalid selected board number\n");
		return -2;
	} else {
		printf("\nSelected:\n");
		printf("Board number\t:::\t%d\n", cmd_p.board);
	}



	if ((cmd_p.v7 == CS_C0) && (rc47[cmd_p.board].LD_pd != NULL)) {
		pd_ptr = rc47[cmd_p.board].LD_pd;
		printf("Virtex Chip\t:::\t%s\n", "C0");
	} else if ((cmd_p.v7 == CS_C1) && (rc47[cmd_p.board].LU_pd != NULL)) {
		pd_ptr = rc47[cmd_p.board].LU_pd;
		printf("Virtex Chip\t:::\t%s\n", "C1");
	} else if ((cmd_p.v7 == CS_C2) && (rc47[cmd_p.board].RD_pd != NULL)) {
		pd_ptr = rc47[cmd_p.board].RD_pd;
		printf("Virtex Chip\t:::\t%s\n", "C2");
	} else if ((cmd_p.v7 == CS_C3) && (rc47[cmd_p.board].RU_pd != NULL)) {
		pd_ptr = rc47[cmd_p.board].RU_pd;
		printf("Virtex Chip\t:::\t%s\n", "C3");
	} else {
		fprintf (stderr,"Invalid selected virtex chip\n");
		return -2;
	}




	// open pcie device

	do_and_test(RD_OpenDevice,(pd_ptr));		

	int dev = pd_ptr->intfd;


	// reset user part
	if (fpga_user_reset(dev) < 0)
	return -1;
	
	if (fpga_release_user_reset(dev) < 0) 
	return -1; 		

	if (fpga_wait_for_ddr_init(dev) < 0)
	return -1;
	else
	printf("Init DDR OK!\n"); 
	
	
	// set interconnection 
	RD_ReadDeviceReg32m(dev, CNTRL_BAR, 0x4, reg_val);
	
	reg_val |= (1<<5);
	
	RD_WriteDeviceReg32m(dev, CNTRL_BAR, 0x4, reg_val);
	



	/////////////////////////////////////set all counters to zero///////////////////
	
	RD_WriteDeviceReg32m(dev, CNTRL_BAR, MasterMemRdTotalCnt, 0);
	RD_WriteDeviceReg32m(dev, CNTRL_BAR, FifoMemRdTotalCnt, 0);
	RD_WriteDeviceReg32m(dev, CNTRL_BAR, FifoMemWrTotalCnt, 0);
	RD_WriteDeviceReg32m(dev, CNTRL_BAR, MasterMemWrTotalCnt, 0);
	
	///////////////////////////////////////////////////////////////////////////////
	
	*dev_out = dev; 
	

	if (create_page_alligned_buffer(SIZE_BYTE, &wr_buf, &wr_buf_free)) {
		fprintf (stderr,"Error memory allocation for wr_buf\n");
		return -1;
	}

	if (create_page_alligned_buffer(SIZE_BYTE, &rd_buf, &rd_buf_free)) {
		fprintf (stderr,"Error memory allocation for rd_buf\n");
		return -1;
	}	

	return 0;
}
Exemple #11
0
static void init_compiler (int	 argc,
			   char *argv[])
{
   extern void	init_lex (void);
   extern void	init_msg_processing (char *[]);
   extern void	init_src_input (void);
   extern void	init_type (void);
   extern void	process_cmd_line (int, char *[]);
   extern void	init_cond_comp(void);
   extern void	enter_predefined_macros(void);
   extern void	init_parse_prog_unit(void);
   extern void	init_PDGCS (void);
   extern void	set_up_token_tables(void);
   extern void  sgi_cmd_line(int *argc, char **argv[]);
   extern char *operator_str[];
   extern void	verify_semantic_tbls(void);

   	  int	idx;


   TRACE (Func_Entry, "init_compiler", NULL);

   init_date_time_info ();		/* set compilation data and time      */
   init_msg_processing (argv);		/* initialize for messages.  Must     */
					/* preceed process_cmd_line.	      */

# ifdef _DEBUG
   check_defines_compatibility();	/* Is the compiler built correctly?   */
   check_enums_for_change();	        /* Some enums must not be changed.    */
# endif

# if 0
   check_license();
# endif

   /* allocate memory for data structures required across compilation units.  */
   /* These must preceed process_cmd_line.                                    */

   TBL_ALLOC (global_line_tbl);
   TBL_ALLOC (global_name_tbl);
   TBL_ALLOC (global_attr_tbl);
   TBL_ALLOC (global_type_tbl);
   TBL_ALLOC (global_bounds_tbl);
   TBL_ALLOC (global_ir_tbl);
   TBL_ALLOC (global_ir_list_tbl);
   TBL_ALLOC (global_sh_tbl);
   TBL_ALLOC (file_path_tbl);
   TBL_ALLOC (str_pool);

   init_release_level ();		/* Set up release_level from system   */

   str_pool[0].name_long	= 0;
   str_pool[1].name_long	= 0;
   str_pool[2].name_long	= LARGE_WORD_FOR_TBL_SRCH;
   str_pool_idx			= 2;

   TBL_REALLOC_CK(global_name_tbl, 2);
   CLEAR_TBL_NTRY(global_name_tbl, 1);
   CLEAR_TBL_NTRY(global_name_tbl, 2);
   GN_NAME_IDX(1)	= 1;
   GN_NAME_LEN(1)	= HOST_BYTES_PER_WORD;
   GN_NAME_IDX(2)	= 2;
   GN_NAME_LEN(2)	= HOST_BYTES_PER_WORD;

   /* Initialize the bounds table for deferred shape arrays */

   TBL_REALLOC_CK(global_bounds_tbl, 7);

   for (idx = BD_DEFERRED_1_IDX; idx <= BD_DEFERRED_7_IDX; idx++) {
      CLEAR_TBL_NTRY(global_bounds_tbl, idx);
      GB_ARRAY_CLASS(idx)	= Deferred_Shape;
      GB_RANK(idx)		= idx;
   }

   /* Initialize the conditional compilation tables.  It must be done before  */
   /* the command line processing because of the -D and -U options.           */

   init_cond_comp ();

   get_machine_chars();

   set_up_token_tables();

   /* The following routines sets things such as target_ieee, target_triton   */
   /* two_word_fcd, word_byte_size ect...                                     */

   set_compile_info_for_target();


   comp_phase = Cmdline_Parsing;

   cif_name[0] = NULL_CHAR;

   assembly_listing_file[0] = NULL_CHAR;

   debug_file_name[0] = NULL_CHAR;

# if (defined(_TARGET_OS_IRIX) || defined(_TARGET_OS_LINUX))
   /* sgi_cmd_line does some option manipulation, process SGI specific        */
   /* command line options, and strips out things that the front-end doesn't  */
   /* need to see.                                                            */

   sgi_cmd_line (&argc,&argv);
# endif


   process_cmd_line (argc, argv);	/* pass input args		      */


# if defined(_INTEGER_1_AND_2)

   if (on_off_flags.integer_1_and_2) {
      bit_size_tbl[Integer_1] = 8;
      bit_size_tbl[Integer_2] = 16;
      bit_size_tbl[Logical_1] = 8;
      bit_size_tbl[Logical_2] = 16;

      storage_bit_size_tbl[Integer_1] = 8;
      storage_bit_size_tbl[Integer_2] = 16;
      storage_bit_size_tbl[Logical_1] = 8;
      storage_bit_size_tbl[Logical_2] = 16;

      storage_bit_prec_tbl[Integer_1] = 8;
      storage_bit_prec_tbl[Integer_2] = 16;
      storage_bit_prec_tbl[Logical_1] = 8;
      storage_bit_prec_tbl[Logical_2] = 16;

      stride_mult_unit_in_bits[Integer_1] = 8;
      stride_mult_unit_in_bits[Integer_2] = 16;
      stride_mult_unit_in_bits[Logical_1] = 8;
      stride_mult_unit_in_bits[Logical_2] = 16;

      linear_to_arith[Integer_1] = AR_Int_8_S;
      linear_to_arith[Integer_2] = AR_Int_16_S;

      input_arith_type[Integer_1] = AR_Int_8_U;
      input_arith_type[Integer_2] = AR_Int_16_U;

      strcpy(arith_type_string[Integer_1], "AR_Int_8_U");
      strcpy(arith_type_string[Integer_2], "AR_Int_16_U");
   }
# endif

   comp_phase = Pass1_Parsing;

   /* only -V info requested */

   if (argc == 2 && cmd_line_flags.verify_option) {
      print_id_line();
      exit_compiler(RC_OKAY);
   }

   if (num_errors != 0) {		/* command line errors	      */
      PRINTMSG(0, 912, Log_Summary, 0, num_errors);
      exit_compiler(RC_USER_ERROR);
   }

   /* Call init_cif even if the user did NOT request Compiler Information     */
   /* File (CIF) output because the CIF is used for messaging.		      */
   
   init_cif(comp_date_time, release_level);

   some_scp_in_err	= FALSE;
   clearing_blk_stk	= FALSE;

   init_type();
        
   make_table_changes ();

   init_sytb ();		 /* Must be before src_input for err msgs */


   /* Enter conditional compilation predefined macros.  This must happen      */
   /* after process_cmd_line because it calls GETPMC (and the information     */
   /* from GETPMC is needed to set the predefined macros that depend on the   */
   /* target machine).  This call must also happen after target_triton and    */
   /* target_ieee have been set so that we can get _CRAYIEEE set correctly.   */
   /* And finally, this call must come before init_src_input because that     */
   /* procedure gets the first source line - which could be a conditional     */
   /* compilation directive.					              */

   enter_predefined_macros();

   /* Must do the first call here so that tables needed by conditional        */
   /* compilation are set up.						      */

   init_parse_prog_unit();	

   init_src_input();

   if (on_off_flags.preprocess_only) {
      preprocess_only_driver();
      issue_deferred_msgs();

      TRACE (Func_Exit, "init_compiler", NULL);

      return;
   }

   init_lex ();

   max_field_len = (long) sbrk(0);	/* Keep track of memory usage         */

# if defined(_HOST_OS_MAX)
   max_field_len &= (1 << 32) - 1;
# endif


   /* Pathological case:  The file is empty.  At least an END statement must  */
   /* be present to constitute a valid Fortran program.                       */

   if (LA_CH_CLASS == Ch_Class_EOF) {
      PRINTMSG(0, 1391, Log_Warning, 0, src_file);
      issue_deferred_msgs();
   }


# ifdef _NAME_SUBSTITUTION_INLINING
   if (!dump_flags.preinline)
# endif
      init_PDGCS();

# ifdef _DEBUG
   verify_semantic_tbls();	/* Make sure flags and messages agree. */

   if (strcmp(operator_str[The_Last_Opr], "The_Last_Opr") != 0) {
      PRINTMSG(1, 689, Internal, 0);
   }
# endif

   TRACE (Func_Exit, "init_compiler", NULL);

   return;
 
}  /* init_compiler */
Exemple #12
0
int main(int argc, char const* argv[])
{
	int i, pid, errors;
	YARA_CONTEXT* context;
	FILE* rule_file;
	TAG* tag;
	TAG* next_tag;
	
	yr_init();
			
	context = yr_create_context();
	
	if (context == NULL) 
		return 0;
		
	if (!process_cmd_line(context, argc, argv))
	{
	    yr_destroy_context(context);
		return 0;
	}	
		
	if (argc == 1 || ((optind == argc) && (! compile_only)))
	{
	    yr_destroy_context(context);
		show_help();
		return 0;
	}

	context->error_report_function = report_error;	
			
	for (i = optind; i < (compile_only ? argc : argc - 1); i++)
	{
		rule_file = fopen(argv[i], "r");
		
		if (rule_file != NULL)
		{
			yr_push_file_name(context, argv[i]);
			            			
			errors = yr_compile_file(rule_file, context);
			
			fclose(rule_file);
			
			if (errors) /* errors during compilation */
			{
				yr_destroy_context(context);				
				return 2;
			}
		}
		else
		{
			fprintf(stderr, "could not open file: %s\n", argv[i]);
            if (compile_only)
                return 2;
		}
	}

	if (optind == (compile_only ? argc : argc - 1))  /* no rule files, read rules from stdin */
	{
		yr_push_file_name(context, "stdin");
		
		errors = yr_compile_file(stdin, context);
			
		if (errors > 0) /* errors during compilation */
		{
			yr_destroy_context(context);				
			return 0;
		}		
	}

    if (compile_only)
    {
        printf("syntax check OK\n");
        return 0;
    }
			
	if (is_numeric(argv[argc - 1]))
    {
        pid = atoi(argv[argc - 1]);

        switch (i = yr_scan_proc(pid, context, callback, (void*) argv[argc - 1]))
        {
            case ERROR_SUCCESS:
                break;
            case ERROR_COULD_NOT_ATTACH_TO_PROCESS:
                fprintf(stderr, "can not attach to process (try running as root)\n");
                break;
            case ERROR_INSUFICIENT_MEMORY:
                fprintf(stderr, "not enough memory\n");
                break;
            default:
                fprintf(stderr, "internal error: %d\n", i);
                break;     
        }
    }
	else if (is_directory(argv[argc - 1]))
	{
		scan_dir(argv[argc - 1], recursive_search, context, callback);
	}
	else		
	{
		yr_scan_file(argv[argc - 1], context, callback, (void*) argv[argc - 1]);
	}
	
	yr_destroy_context(context);
	
	/* free tag list allocated by process_cmd_line */
	
	tag = specified_tags_list;
	
	while(tag != NULL)
	{
		next_tag = tag->next;
		free(tag);
		tag = next_tag;
	}
	
	return 1;
}
void main_loop(const char** argv)
    {
    //  Process command line arguments.
    map<string, string> params;
    process_cmd_line(argv, params);
    bool verbose = get_bool_param(params, "verbose");

    //  Load feature files for templates.
    //  Get template label from matrix name.
    vector<string> templateLabelList;
    vector<matrix<double> > templateMatList;
    ifstream templateStrm(
        get_required_string_param(params, "template_file").c_str());
    while (templateStrm.peek() != EOF)
        {
        templateMatList.push_back(matrix<double>());
        string labelStr = read_float_matrix(templateStrm,
            templateMatList.back());
        templateLabelList.push_back(labelStr);
        }
    templateStrm.close();
    if (templateMatList.empty())
        throw runtime_error("No templates supplied.");

    //  Load correct label for each feature file, if present.
    vector<string> featLabelList;
    string labelFile = get_string_param(params, "feat_label_list");
    if (!labelFile.empty())
        read_string_list(labelFile, featLabelList);

    //  The main loop.
    ifstream featStrm(
        get_required_string_param(params, "feat_file").c_str());
    matrix<double> feats;
    unsigned templCnt = templateLabelList.size();
    unsigned uttCnt = 0;
    unsigned correctCnt = 0;
    while (featStrm.peek() != EOF)
        {
        int uttIdx = uttCnt++;
        string idStr = read_float_matrix(featStrm, feats);

        //  Find closest template.
        int bestTempl = -1;
        double bestScore = DBL_MAX;
        for (unsigned templIdx = 0; templIdx < templCnt; ++templIdx)
            {
            if (feats.size2() != templateMatList[templIdx].size2())
                throw runtime_error("Mismatch in test/template feature dim.");
            double curScore = compute_distance(feats,
                templateMatList[templIdx]);
            if (verbose)
                cout << format("  %s: %.3f") % templateLabelList[templIdx] %
                    curScore << endl;
            if (curScore < bestScore)
                bestScore = curScore, bestTempl = templIdx;
            }
        if (bestTempl < 0)
            throw runtime_error("No alignments found in DTW.");

        string hypLabel = (bestTempl >= 0) ? templateLabelList[bestTempl] : "";
        if (!featLabelList.empty())
            {
            //  If have reference labels, print ref and hyp classes.
            if (uttIdx >= (int) featLabelList.size())
                throw runtime_error("Mismatch in number of utterances "
                    "and labels.");
            string refLabel = featLabelList[uttIdx];
            cout << format("Reference: %s, Hyp: %s, Correct: %d") %
                refLabel % hypLabel % (hypLabel == refLabel) << endl;
            if (hypLabel == refLabel)
                ++correctCnt;
            }
        else
            //  If don't have reference labels, just print hyp class.
            cout << hypLabel << " (" << idStr << ")" << endl;
        }
    featStrm.close();
    if (!featLabelList.empty())
        {
        //  If have reference labels, print accuracy.
        unsigned errCnt = uttCnt - correctCnt;
        cout << format("Accuracy: %.2f%% (%d/%d), Error rate: %.2f%% (%d/%d)")
            % (100.0 * correctCnt / uttCnt) % correctCnt % uttCnt %
            (100.0 * errCnt / uttCnt) % errCnt % uttCnt << endl;
        }
    }
Exemple #14
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
    INITCOMMONCONTROLSEX ctrls;
	HACCEL haccel;
	static char *class_name="DB_UTIL_CLASS";
	int first_instance=TRUE;
	int debug=0;

	first_instance=set_single_instance(TRUE);

	ghinstance=hInstance;
	init_ini_file();

#ifdef _DEBUG
	debug=1;
#else
	get_ini_value("SETTINGS","DEBUG",&debug);
#endif
	if(debug!=0){
		open_console();
	}

	{
		int val=0;
		get_ini_value("SETTINGS","SINGLE_INSTANCE",&val);
		if(val && (!first_instance)){
			COPYDATASTRUCT cd={0};
			HWND hdbutil;
			cd.cbData=nCmdShow;
			cd.cbData=strlen(lpCmdLine)+1;
			cd.lpData=lpCmdLine;
			hdbutil=FindWindow("DB_UTIL_CLASS",NULL);
			if(hdbutil!=0){
				int sw;
				SendMessage(hdbutil,WM_COPYDATA,hInstance,&cd);
				if (IsZoomed(hdbutil))
					sw=SW_MAXIMIZE;
				else if(IsIconic(hdbutil))
					sw=SW_RESTORE;
				else
					sw=SW_SHOW;
				ShowWindow(hdbutil,sw);
				SetForegroundWindow(hdbutil);
			}
			return TRUE;
		}
		set_single_instance(val);
	}
	init_mdi_stuff();

	LoadLibrary("RICHED20.DLL");
	LoadLibrary("Msftedit.dll");

	ctrls.dwSize=sizeof(ctrls);
    ctrls.dwICC = ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES|ICC_BAR_CLASSES;
	InitCommonControlsEx(&ctrls);
	
	InitializeCriticalSection(&mutex);

	start_worker_thread();
	start_intellisense_thread();

	setup_mdi_classes(ghinstance);
	
	ghmenu=LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
	ghmainframe=create_mainwindow(&WndProc,ghmenu,hInstance,class_name,"DB_UTIL");

	ShowWindow(ghmainframe,nCmdShow);
	UpdateWindow(ghmainframe);

	haccel=LoadAccelerators(ghinstance,MAKEINTRESOURCE(IDR_ACCELERATOR1));

	process_cmd_line(lpCmdLine);

    while(GetMessage(&msg,NULL,0,0)){
		if(!custom_dispatch(&msg))
		if(!TranslateMDISysAccel(ghmdiclient, &msg) && !TranslateAccelerator(ghmainframe,haccel,&msg)){
			TranslateMessage(&msg);
			//if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_NOTIFY)
			if(FALSE)
			if(msg.message!=0x118&&msg.message!=WM_NCHITTEST&&msg.message!=WM_SETCURSOR&&msg.message!=WM_ENTERIDLE&&msg.message!=WM_NCMOUSEMOVE&&msg.message!=WM_MOUSEFIRST)
			{
				static DWORD tick=0;
				if((GetTickCount()-tick)>500)
					printf("--\n");
				printf("x");
				print_msg(msg.message,msg.lParam,msg.wParam,msg.hwnd);
				tick=GetTickCount();
			}
			DispatchMessage(&msg);
		}
    }
	DeleteCriticalSection(&mutex);
    return msg.wParam;
	
}
Exemple #15
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	static HWND last_focus=0;
	if(FALSE)
	//if(msg!=WM_MOUSEFIRST&&msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_NOTIFY)
	if(msg!=WM_NCHITTEST&&msg!=WM_SETCURSOR&&msg!=WM_ENTERIDLE&&msg!=WM_MOUSEMOVE&&msg!=WM_NCMOUSEMOVE)
	{
		static DWORD tick=0;
		if((GetTickCount()-tick)>500)
			printf("--\n");
		print_msg(msg,lparam,wparam,hwnd);
		tick=GetTickCount();
	}
    switch(msg)
    {
	case WM_MENUSELECT:
		break;
	case WM_CREATE:
		{
			RECT rect={0};
			extern int keep_closed,trim_trailing,left_justify;
			get_ini_value("SETTINGS","KEEP_CLOSED",&keep_closed);
			get_ini_value("SETTINGS","TRIM_TRAILING",&trim_trailing);
			get_ini_value("SETTINGS","LEFT_JUSTIFY",&left_justify);
			load_icon(hwnd);

			load_window_size(hwnd,"MAIN_WINDOW");

			GetClientRect(hwnd,&rect);
			get_ini_value("SETTINGS","TREE_WIDTH",&tree_width);
			if(tree_width>rect.right-10 || tree_width<10){
				tree_width=rect.right/4;
				if(tree_width<12)
					tree_width=12;
			}

			ghmdiclient=create_mdiclient(hwnd,ghmenu,ghinstance);
			ghdbview=create_dbview(hwnd,ghinstance);
			ghstatusbar=CreateStatusWindow(WS_CHILD|WS_VISIBLE,"ready",hwnd,IDC_STATUS);
			create_status_bar_parts(hwnd,ghstatusbar);

			resize_main_window(hwnd,tree_width);
		}
		break;
	case WM_DROPFILES:
		process_drop(hwnd,wparam);
		break;
	case WM_COPYDATA:
		if(lparam!=0){
			COPYDATASTRUCT *cd=lparam;
			process_cmd_line(cd->lpData);
		}
		break;
	case WM_USER:
		debug_window_focus(lparam,"WM_USER");
		switch(wparam){
		case IDC_TREEVIEW:
			if(lparam!=0)
				SetFocus(lparam);
			break;
		case IDC_MDI_LISTVIEW:
			if(lparam!=0){
				last_focus=lparam;
				SetFocus(lparam);
			}
			break;
		case IDC_LV_EDIT:
			if(lparam!=0)
				last_focus=lparam;
			break;
		}
		break;
	case WM_USER+1:
		debug_window_focus(last_focus,"WMUSER+1");
		if(last_focus!=0)
			SetFocus(last_focus);
		break;
	case WM_NCACTIVATE:
		debug_window_focus(last_focus,"NCACTIVATE wparam=%08X",wparam);
		if(wparam==0){
			last_focus=GetFocus();
		}
		else{
			PostMessage(hwnd,WM_USER+1,0,0);
		}
		break;
	case WM_ACTIVATEAPP: //close any tooltip on app switch
		debug_window_focus(last_focus,"ACTIVATEAPP wparam=%08X",wparam);
		if(wparam){
			PostMessage(hwnd,WM_USER+1,0,0);
		}
		break;
	case WM_KILLFOCUS:
	case WM_RBUTTONDOWN:
	case WM_LBUTTONUP:
		if(main_drag){
			ReleaseCapture();
			main_drag=FALSE;
			write_ini_value("SETTINGS","TREE_WIDTH",tree_width);
		}
		break;
	case WM_LBUTTONDOWN:
		{
			int x=LOWORD(lparam);
			if(x>=(tree_width-10) && x<(tree_width+10)){
				SetCapture(hwnd);
				SetCursor(LoadCursor(NULL,IDC_SIZEWE));
				main_drag=TRUE;
			}
		}
		break;
	case WM_MOUSEFIRST:
		{
			int x=LOWORD(lparam);
			if(x>=(tree_width-10) && x<(tree_width+10))
				SetCursor(LoadCursor(NULL,IDC_SIZEWE));
			if(main_drag){
				RECT rect;
				GetClientRect(ghmainframe,&rect);
				if(x>10 && x<rect.right-10){
					tree_width=x;
					resize_main_window(hwnd,tree_width);
				}
			}
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam)){
		case IDM_OPEN:
			if((GetKeyState(VK_SHIFT)&0x8000) || GetKeyState(VK_CONTROL)&0x8000)
				task_open_db("");
			else{
				if(does_key_exist("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources","Journal"))
					task_open_db("UID=dba;PWD=sql;DSN=Journal");
				else
					task_open_db("");
			}
			break;
		case IDM_CLOSE:
			{
			HANDLE hroot=0;
			if(tree_find_focused_root(&hroot)){
				char str[MAX_PATH]={0};
				tree_get_db_table(hroot,str,sizeof(str),0,0,0);
				if(str[0]!=0){
					set_status_bar_text(ghstatusbar,0,"closing %s",str);
					task_close_db(str);
				}
			}
			else
				set_status_bar_text(ghstatusbar,0,"select a DB");
			}
			break;
		case IDM_SETTINGS:
			DialogBox(ghinstance,MAKEINTRESOURCE(IDD_SETTINGS),hwnd,settings_proc);
			break;
		case IDM_RECENT:
			DialogBox(ghinstance,MAKEINTRESOURCE(IDD_RECENT),hwnd,recent_proc);
			break;
		case IDM_STOP_THREAD:
			{
				int click=MessageBox(hwnd,"Are you sure you want to terminate the task?","Warning",MB_OKCANCEL|MB_SYSTEMMODAL);
				if(click==IDOK){
					terminate_worker_thread();
					stop_thread_menu(FALSE);
				}
			}
			break;
		case IDM_QUERY:
			task_new_query();
			break;
		case IDC_EXECUTE_SQL:
			task_execute_query(NULL);
			break;
		case IDM_TILE_DIALOG:
			tile_select_dialog(hwnd);
			break;
		case IDM_WINDOW_TILE:
			mdi_tile_windows_vert();
			break;
		case IDM_WINDOW_CASCADE:
			mdi_cascade_win_vert();
			break;
		case IDM_WINDOW_LRTILE:
			mdi_tile_windows_horo();
			break;
		case IDM_REFRESH_ALL:
			refresh_all_dialog(hwnd);
			break;
		case IDM_REORDER:
			reorder_win_dialog(hwnd);
			break;
		}
		break;
	case WM_SIZE:
		resize_main_window(hwnd,tree_width);
		create_status_bar_parts(ghmainframe,ghstatusbar);
		return 0;
		break;
	case WM_QUERYENDSESSION:
		return 1; //ok to end session
		break;
	case WM_ENDSESSION:
		if(wparam){
			if(!(GetKeyState(VK_SHIFT)&0x8000))
				save_window_size(hwnd,"MAIN_WINDOW");
		}
		return 0;
	case WM_CLOSE:
        break;
	case WM_DESTROY:
		if(!(GetKeyState(VK_SHIFT)&0x8000))
			save_window_size(hwnd,"MAIN_WINDOW");
		PostQuitMessage(0);
        break;
    }
	return DefFrameProc(hwnd, ghmdiclient, msg, wparam, lparam);
}
Exemple #16
0
int main(int argc, char *argv[]) {
    int ret = 0;

    if (argc == 1) {
        print_short_usage();
        return 0;
    }
    if (process_cmd_line(argc, argv) == -1)
        return -1;

    if (info_flag == 1) {
        anyio_bitfile_print_info(bitfile_name, 1);
    } else if (device_flag == 1) {
        board_t *board = NULL;

        access.verbose = verbose_flag;
        access.recover = recover_flag;
        access.address = addr_flag;

        if (anyio_init(&access) != 0)
            exit(1);
        ret = anyio_find_dev(&access);
        if (ret < 0) {
            return -1;
        }
        board = anyio_get_dev(&access, 1);
        if (board == NULL) {
            printf("No %s board found\n", access.device_name);
            return -1;
        }

        board->open(board);

        if (readhmid_flag == 1) {
            anyio_dev_print_hm2_info(board, xml_flag);
        } else if (sserial_flag == 1) {
            anyio_dev_print_sserial_info(board);
        } else if (rpo_flag == 1) {
            u32 data;

            board->llio.read(&(board->llio), rpo_addr, &data, sizeof(u32));
            printf("%08X\n", data);
        } else if (wpo_flag == 1) {
            board->llio.write(&(board->llio), wpo_addr, &wpo_data, sizeof(u32));
        } else if (set_flag == 1) {
            ret = anyio_dev_set_remote_ip(board, lbp16_set_ip_addr);
        } else if (write_flag == 1) {
            ret = anyio_dev_write_flash(board, bitfile_name, fallback_flag);
            if (reload_flag == 1) {
                ret = anyio_dev_reload(board, fallback_flag);
                if (ret == -1) {
                    printf("\nYou must power cycle the hardware to load a new firmware.\n");
                }
            } else {
                printf("\nYou must power cycle the hardware or use the --reload command to load a new firmware.\n");
            }
        } else if (verify_flag == 1) {
            ret = anyio_dev_verify_flash(board, bitfile_name, fallback_flag);
        } else if (program_flag == 1) {
            ret = anyio_dev_program_fpga(board, bitfile_name);
        } else if (reload_flag == 1) {
            anyio_dev_reload(board, fallback_flag);
        } else if (reset_flag == 1) {
            anyio_dev_reset(board);
        } else {
           board->print_info(board);
        }
        board->close(board);
        anyio_cleanup(&access);
    } else {
        printf("No action requested. Please specify at least --device or --info.\n");
    }
    return ret;
}