コード例 #1
0
ファイル: practica4.c プロジェクト: Mithrandir0x/so2
RBTree *import_database()
{
  ProgressPtr process_file;
  FilePathList *list;
  char path[80];
  RBTree *tree;
  
  tree = malloc(sizeof(RBTree));
  list = malloc(sizeof(FilePathList));
  
  // For each file indicated by the file specified by argument, it will parse
  // its content, searching for words, and it will store them in the global
  // structure.
  process_file = ^(FilePathItem *item, int total_files){
      HashList hl;
      int result;

      printf("Reading file [%s] with id [%d/%d]\n", item->path, item->id + 1, total_files);
      
      hl_initialize(&hl, HASH_LIST_SIZE);
      
      result = create_local_structure(&hl, item->path);
      if ( result == 0 )
      {
          update_global_structure(tree, &hl, item->id);
          hl_free(&hl);
      }
  };
  
  cfg_init(list);

  printf("Mode multifil\n");

  printf("Nom del fitxer de configuració: ");
  scanf("%s", path);
  flush();
  
  cfg_import_config(path, list);
  //cfg_print(list);

  if ( list->size == 0 )
  {
    cfg_free(list);
    free(tree);
    return NULL;
  }

  initTree(tree, list->size);
  cfg_mt_iterate(list, process_file, 32);
  
  cfg_free(list);

  return tree;
}
コード例 #2
0
ファイル: main.c プロジェクト: Devination/Kha
int main( int argc, char *argv[] ) {
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );
	if( argc == 1 ) {
		printf("HLVM %d.%d.%d (c)2015 Haxe Foundation\n  Usage : hl <file>\n",HL_VERSION/100,(HL_VERSION/10)%10,HL_VERSION%10);
		return 1;
	}
	hl_global_init();
	{
		hl_code *code;
		hl_module *m;
		const char *file = argv[1];
		FILE *f = fopen(file,"rb");
		int pos, size;
		char *fdata;
		if( f == NULL ) {
			printf("File not found '%s'\n",file);
			return 1;
		}
		fseek(f, 0, SEEK_END);
		size = (int)ftell(f);
		fseek(f, 0, SEEK_SET);
		fdata = (char*)malloc(size);
		pos = 0;
		while( pos < size ) {
			int r = (int)fread(fdata + pos, 1, size-pos, f);
			if( r <= 0 ) {
				printf("Failed to read '%s'\n",file);
				return 2;
			}
			pos += r;
		}
		fclose(f);
		code = hl_code_read((unsigned char*)fdata, size);
		free(fdata);
		if( code == NULL )
			return 3;
		m = hl_module_alloc(code);
		if( m == NULL )
			return 4;
		if( !hl_module_init(m) )
			return 5;
		hl_callback(m->functions_ptrs[m->code->entrypoint],0,NULL);
		hl_module_free(m);
		hl_free(&code->alloc);
	}
	hl_global_free();
	return 0;
}
コード例 #3
0
ファイル: practica4.c プロジェクト: Mithrandir0x/so2
RBTree *import_database()
{
  ProgressPtr process_file;
  FilePathScheduler scheduler;
  FilePathList *list;
  char path[80];
  RBTree *tree;
  
  tree = malloc(sizeof(RBTree));
  list = malloc(sizeof(FilePathList));
  
  // For each file indicated by the file specified by argument, it will parse
  // its content, searching for words, and it will store them in the global
  // structure.
  process_file = ^(FilePathItem *item, int total_files){
      HashList hl;
      int result;

      printf("Reading file [%s] with id [%d]\n", item->path, item->id + 1);
      
      hl_initialize(&hl, HASH_LIST_SIZE);
      
      result = create_local_structure(&hl, item->path);
      if ( result == 0 )
      {
          update_global_structure(tree, &hl, item->id);
          hl_free(&hl);
      }
  };

  scheduler = ^(FilePathList *list, FilePathList **tasks, int n_threads){
    int i;

    int total_files_per_thread = ceil(list->size / n_threads) + 1;

    printf("Total files per thread [%d]\n", total_files_per_thread);

    ProgressPtr add_file_to_list = ^(FilePathItem *item, int total_files){
      int j = item->id % n_threads;
      //printf("Task [%d] File [%3d/%3d]\n", j + 1, item->id, total_files);
      cfg_insert_file_path(tasks[j], item->id, item->size, item->path);
    };

    for ( i = 0 ; i < n_threads ; i++ )
    {
      cfg_init_pr(tasks[i], total_files_per_thread);
    }

    cfg_iterate(list, add_file_to_list);
  };
  
  cfg_init(list);

  printf("Mode multifil amb planificació\n");

  printf("Nom del fitxer de configuració: ");
  scanf("%s", path);
  flush();
  
  cfg_import_config(path, list);
  //cfg_print(list);

  if ( list->size == 0 )
  {
    cfg_free(list);
    free(tree);
    return NULL;
  }

  initTree(tree, list->size);
  cfg_sch_mt_iterate(list, process_file, scheduler, 32);
  
  cfg_free(list);

  return tree;
}
コード例 #4
0
ファイル: hash-list.c プロジェクト: Mithrandir0x/so2
/**
 * Empty the hash-list and initialize it again.
 *
 * @param hl A hash-list structure
 */
void hl_clear(HashList *hl)
{
  int hl_size = hl->size;
  hl_free(hl);
  hl_initialize(hl, hl_size);
}