Пример #1
0
int			get_color(t_ray ray, t_scene sc)
{
	t_inter		inter;
	t_objlist	*lst;
	int			color;
	t_func		funct[5];

	instance_funct(funct);
	lst = sc.lst;
	inter.dist = NULL;
	inter.info = NULL;
	while (lst)
	{
		funct[lst->obj](&inter, lst->e, ray, sc.light);
		lst = lst->next;
	}
	if (inter.dist == NULL)
		return (0);
	else
	{
		color = get_color_inter(inter, sc.lst);
		free(inter.dist);
		free_info(&inter);
		return (color);
	}
}
Пример #2
0
static void destroy(void)
{
	if (db_hdl) {
		/* close DB connection */
		dr_dbf.close(db_hdl);
		db_hdl = NULL;
	}

	/* destroy data */
	if (cluster_list) {
		if (*cluster_list)
			free_info(*cluster_list);
		shm_free(cluster_list);
		cluster_list = NULL;
	}

	/* destroy lock */
	if (cl_list_lock) {
		lock_destroy_rw(cl_list_lock);
		cl_list_lock = NULL;
	}

	/* free generic message receiving events events */
	gen_rcv_evs_destroy();
}
Пример #3
0
void			int_quad(t_inter *pt, void *e, t_ray ray, t_light *light)
{
	t_quad		quad;
	double		t;
	t_vec		inter;

	quad = *((t_quad *)e);
	t = get_dist(ray, quad);
	if (t < 0)
		return ;
	if (pt->dist == NULL || *(pt->dist) > t)
	{
		if (pt->dist == NULL)
			pt->dist = malloc(sizeof(double));
		free_info(pt);
		*(pt->dist) = t;
		inter = get_inter(ray, t);
		pt->normal = get_normal_quad(inter, quad);
		if (scalar_prod(pt->normal, ray.dir) > 0)
			pt->normal = mult_scalar(pt->normal, -1);
		pt->refl = get_refl(ray, pt->normal);
		pt->color = quad.color;
		pt->inter = inter;
		get_info(pt, light, inter);
	}
}
Пример #4
0
void	close_main(s_game		*game,
		   s_sound		*sounds,
		   s_perso		**persos)
{
  int	i = 0;

  for (i = 0; i < 32; i++)
    {
      SDL_FreeSurface(persos[1]->anim[i]);
      SDL_FreeSurface(persos[2]->anim[i]);
    }
  for (i = 0; i < 7; i++)
    SDL_FreeSurface(game->fire[i]);
  Mix_FreeChunk(sounds->bomb);
  Mix_FreeChunk(sounds->planted);
  Mix_FreeMusic(sounds->music);
  free(sounds);
  for (i = 0; i < game->max_players; i++)
    free(persos[i]);
  free_info(game->info);
  TTF_CloseFont(game->font);
  TTF_CloseFont(game->font_num);
  TTF_Quit();
  Mix_CloseAudio();
  SDL_Quit();
  free_grid(game);
  if (game->custom_mus)
    free(game->custom_mus);
  free(game);
}
Пример #5
0
static struct mi_root* clusterer_reload(struct mi_root* root, void *param)
{
	cluster_info_t *new_info;
	cluster_info_t *old_info;

	if (!db_mode) {
		LM_ERR("Running in non-DB mode\n");
		return init_mi_tree(400, "Non-DB mode", 11);
	}

	if (load_db_info(&dr_dbf, db_hdl, &db_table, &new_info) != 0) {
		LM_ERR("Failed to load info from DB\n");
		return init_mi_tree(500, "Failed to reload", 16);
	}

	lock_start_write(cl_list_lock);
	old_info = *cluster_list;
	*cluster_list = new_info;
	lock_stop_write(cl_list_lock);

	if (old_info)
		free_info(old_info);

	LM_INFO("Reloaded DB info\n");

	return init_mi_tree(200, MI_SSTR(MI_OK));
}
Пример #6
0
int
tc_api_task_uninit(tc_api_task task)
{
	if (task->last_info != NULL)
		free_info(task->last_info);
	opts_free(task->opts);
	free_safe_mem(task);

	return TC_OK;
}
Пример #7
0
void free_info(wifi_info *head)
{
	int i;
	if (head != NULL) {
		free_info(head->next);
		for (i = 0; i < 5; i++) {
			free(head->info_array[i]);
		}
		free(head);
	}
}
Пример #8
0
static void free_emulinfo(emul_info_t *cl)
{
  definition_t *def, *sibling;

  for (def=cl->subdefs; def!=NULL; def=sibling) {
    sibling = DEF_SIBLING(def);
    free_info(def->predtyp, (char *)def->code.intinfo);
    checkdealloc_TYPE(definition_t, def);
  }
  checkdealloc_FLEXIBLE_S(emul_info_t, objsize, cl);
}
Пример #9
0
mi_response_t *clusterer_reload(const mi_params_t *params,
								struct mi_handler *async_hdl)
{
	cluster_info_t *new_info;
	cluster_info_t *old_info;

	if (!db_mode) {
		LM_ERR("Running in non-DB mode\n");
		return init_mi_error(400, MI_SSTR("Non-DB mode"));
	}

	if (load_db_info(&dr_dbf, db_hdl, &db_table, &new_info) != 0) {
		LM_ERR("Failed to load info from DB\n");
		return init_mi_error(500, MI_SSTR("Failed to reload"));
	}

	lock_start_write(cl_list_lock);
	if (preserve_reg_caps(new_info) < 0) {
		lock_stop_write(cl_list_lock);
		LM_ERR("Failed to preserve registered capabilities\n");

		if (new_info)
			free_info(new_info);

		return init_mi_error(500, "Failed to reload", 16);
	}
	old_info = *cluster_list;
	*cluster_list = new_info;
	lock_stop_write(cl_list_lock);

	if (old_info)
		free_info(old_info);

	LM_INFO("Reloaded DB info\n");

	/* check if the cluster IDs in the the sharing tag list are valid */
	shtag_validate_list();

	return init_mi_result_ok();
}
Пример #10
0
int	parse_args(int ac, char **av, t_info *info)
{
  if (ac != 5 && ac != 7)
    {
      print_usage(av[0]);
      free_info(info);
      return (-1);
    }
  info->team_name = av[2];
  info->host = (ac == 7 ? av[6] : DEFAULT_HOST);
  info->port = atoi(av[4]);
  return (0);
}
Пример #11
0
int	main(int ac, char **av)
{
  t_info	*info;

  info = init();
  parse_args(ac, av, info);
  if (info == 0)
    usage_server();
  info->zone = create_world(info);
  add_server(info);
  server_get(info);
  free_info(info);
  return (0);
}
Пример #12
0
int
map_volume(struct tcplay_opts *opts)
{
	struct tcplay_info *info;
	int error;

	info = info_map_common(opts, NULL);

	if (info == NULL)
		return -1;

	if ((error = dm_setup(opts->map_name, info)) != 0) {
		tc_log(1, "Could not set up mapping %s\n", opts->map_name);
		free_info(info);
		return -1;
	}

	if (opts->interactive)
		printf("All ok!\n");

	free_info(info);

	return 0;
}
Пример #13
0
/*
 * fetch table struct from cache.
 */
static struct PgqTableInfo *find_table_info(Relation rel)
{
	struct PgqTableInfo *entry;
	bool found = false;

	init_module();

	entry = hash_search(tbl_cache_map, &rel->rd_id, HASH_ENTER, &found);
	if (!found || entry->invalid) {
		if (found)
			free_info(entry);
		fill_tbl_info(rel, entry);
	}

	return entry;
}
Пример #14
0
int close_target()
{
   if( target_elf ) {
      free_elf(target_elf);
      target_elf = NULL;
   }
#ifdef USE_COMMANDS
   if( target_info ) {
      if( save_info ) 
         xmlelf_write_info( target_info );
      free_info( target_info );
      target_info = NULL;
   }
#endif /* USE_COMMANDS */

   if( do_disasm )
      disasm_finish();
   return(0);
}
Пример #15
0
int
info_volume(struct tcplay_opts *opts)
{
	struct tcplay_info *info;

	info = info_map_common(opts, NULL);

	if (info != NULL) {
		if (opts->interactive)
			print_info(info);

		free_info(info);

		return 0;
		/* NOT REACHED */
	}

	return -1;
}
Пример #16
0
int open_target_info( elf_t * elf )
{
   char * infoname;
   size_t size;
   if(!elf->name) error_ret("null elf name",-1);

   /* XXX: always save in current dir?  */

   size = strlen(elf->name) + strlen(INFO_EXT) + 4;
   infoname = malloc( size );
   snprintf( infoname ,  size-1  , "%s.%s" , elf->name , INFO_EXT );

   if( target_info )
      free_info( target_info );

   if(!(target_info = new_xmlelf( elf , infoname ) ) ){
      free(infoname);
      error_ret("can't get xmlelf",-1);
   }
   free(infoname);
}
Пример #17
0
Файл: su.c Проект: Sp1l/heimdal
static struct passwd*
dup_info(const struct passwd *pwd)
{
    struct passwd *info;

    info = malloc(sizeof(*info));
    if(info == NULL)
	return NULL;
    info->pw_name = strdup(pwd->pw_name);
    info->pw_passwd = strdup(pwd->pw_passwd);
    info->pw_uid = pwd->pw_uid;
    info->pw_gid = pwd->pw_gid;
    info->pw_dir = strdup(pwd->pw_dir);
    info->pw_shell = strdup(pwd->pw_shell);
    if(info->pw_name == NULL || info->pw_passwd == NULL ||
       info->pw_dir == NULL || info->pw_shell == NULL) {
	free_info (info);
	return NULL;
    }
    return info;
}
Пример #18
0
int
info_mapped_volume(struct tcplay_opts *opts)
{
	struct tcplay_info *info;

	info = dm_info_map(opts->map_name);
	if (info != NULL) {
		if (opts->interactive)
			print_info(info);

		free_info(info);

		return 0;
		/* NOT REACHED */
	} else if (opts->interactive) {
		tc_log(1, "Could not retrieve information about mapped "
		    "volume %s. Does it exist?\n", opts->map_name);
	}

	return -1;
}
Пример #19
0
static int myth_readlink(const char *path, char *buf, size_t size)
{
	struct path_info info;
	int n;
	int i;
	cmyth_conn_t control;
	cmyth_proglist_t list;
	int count;
	struct myth_conn *mc;

	debug("%s(): path '%s' size %lld\n", __FUNCTION__, path,
	      (long long)size);

	memset(&info, 0, sizeof(info));
	if (lookup_path(path, &info) < 0) {
		return -ENOENT;
	}

	if (strcmp(info.dir, "all") != 0) {
		free_info(&info);
		return -ENOENT;
	}

	pthread_mutex_lock(&mutex);

	if ((i=lookup_server(info.host)) < 0) {
		free_info(&info);
		pthread_mutex_unlock(&mutex);
		return -ENOENT;
	}

	control = ref_hold(conn[i].control);

	if (conn[i].list == NULL) {
		list = cmyth_proglist_get_all_recorded(control);
		conn[i].list = list;
		parse_progs(conn+i);
	} else {
		list = conn[i].list;
	}

	mc = conn+i;

	list = ref_hold(list);

	pthread_mutex_unlock(&mutex);

	count = cmyth_proglist_get_count(list);

	for (i=0; i<count; i++) {
		cmyth_proginfo_t prog;
		char tmp[512];
		char *t, *s, *pn;

		prog = cmyth_proglist_get_item(list, i);
		t = cmyth_proginfo_title(prog);
		s = cmyth_proginfo_subtitle(prog);
		pn = cmyth_proginfo_pathname(prog);

		if (mc->progs[i].suffix == 0) {
			snprintf(tmp, sizeof(tmp), "%s - %s.nuv", t, s);
		} else {
			snprintf(tmp, sizeof(tmp), "%s - %s (%d).nuv", t, s,
				 mc->progs[i].suffix);
		}

		if (strcmp(tmp, info.file) == 0) {
			snprintf(tmp, sizeof(tmp), "../files%s", pn);

			memset(buf, 0, size);

			n = (strlen(tmp) > size) ? size : strlen(tmp);
			strncpy(buf, tmp, n);

			debug("%s(): link '%s' %d bytes\n", __FUNCTION__,
			      tmp, n);

			ref_release(t);
			ref_release(s);
			ref_release(pn);
			ref_release(prog);
			ref_release(control);
			ref_release(list);

			free_info(&info);

			return 0;
		}

		ref_release(t);
		ref_release(s);
		ref_release(pn);
		ref_release(prog);
	}

	ref_release(control);
	ref_release(list);

	free_info(&info);

	return -ENOENT;
}
Пример #20
0
static int
get_info(efi_guid_t *guid, uint64_t hw_inst, update_info **info)
{
	efi_guid_t varguid = FWUPDATE_GUID;
	char *varname = NULL;
	char *guidstr = NULL;
	int rc;
	update_info *local;
	int error;

	rc = efi_guid_to_str(guid, &guidstr);
	if (rc < 0)
		return -1;
	guidstr = onstack(guidstr, strlen(guidstr)+1);

	rc = asprintf(&varname, "fwupdate-%s-%"PRIx64, guidstr, hw_inst);
	if (rc < 0)
		return -1;
	varname = onstack(varname, strlen(varname)+1);

	uint8_t *data = NULL;
	size_t data_size = 0;
	uint32_t attributes;

	rc = efi_get_variable(varguid, varname, &data, &data_size, &attributes);
	if (rc < 0) {
		if (errno != ENOENT)
			return -1;
		local = calloc(1, sizeof (*local));
		if (!local)
			return -1;

		local->update_info_version = UPDATE_INFO_VERSION;
		local->guid = *guid;
		local->hw_inst = hw_inst;

		local->dp_ptr = calloc(1, 1024);
		if (!local->dp_ptr) {
alloc_err:
			error = errno;
			free_info(local);
			errno = error;
			return -1;
		}

		ssize_t sz;
		sz = efidp_make_end_entire((uint8_t *)local->dp_ptr, 1024);
		if (sz < 0) {
			rc = sz;
			goto alloc_err;
		}
		*info = local;
		return 0;
	}

	/* If our size is wrong, or our data is otherwise bad, try to delete
	 * the variable and create a new one. */
	if (data_size < sizeof (*local) || !data) {
		if (data)
			free(data);
get_err:
		rc = efi_del_variable(varguid, varname);
		if (rc < 0)
			return -1;
		return get_info(guid, hw_inst, info);
	}
	local = (update_info *)data;

	if (local->update_info_version != UPDATE_INFO_VERSION)
		goto get_err;

	ssize_t sz = efidp_size((efidp)local->dp);
	if (sz < 0) {
		free(data);
		errno = EINVAL;
		return -1;
	}

	efidp_header *dp = malloc((size_t)sz);
	if (!dp) {
		free(data);
		errno = ENOMEM;
		return -1;
	}

	memcpy(dp, local->dp, (size_t)sz);
	local->dp_ptr = dp;

	*info = local;
	return 0;
}
Пример #21
0
void cleanup_angband(void)
{
	int i;

    delete_notes_file();

	/* Free the macros */
	macro_free();

	/* Free the macro triggers */
	macro_trigger_free();

	/* Free the allocation tables */
	FREE(alloc_ego_table);
	FREE(alloc_feat_table);
	FREE(alloc_race_table);
	FREE(alloc_kind_table);

	if (store)
	{
		/* Free the store inventories */
		for (i = 0; i < MAX_STORES; i++)
		{
			/* Get the store */
			store_type *st_ptr = &store[i];

			/* Free the store inventory */
			FREE(st_ptr->stock);
		}
	}

	/* Free the stores */
	FREE(store);

	event_remove_all_handlers();

	/* free the buttons */
	button_free();

	/* Free the player inventory */
	FREE(inventory);

	/*Clean the Autoinscribe*/
	autoinscribe_clean();

	/* Free the lore, monster, effects, and object lists */
	FREE(l_list);
	FREE(f_l_list);
	FREE(a_l_list);
	FREE(mon_list);
	FREE(o_list);
	FREE(x_list);

#ifdef MONSTER_SMELL

	/* Flow arrays */
	FREE(cave_when);

#endif /* MONSTER_SMELL */

	/* Free the cave */
	FREE(cave_o_idx);
	FREE(cave_m_idx);
	FREE(cave_x_idx);
	FREE(cave_feat);
	FREE(cave_info);

	/* Prepare monster movement array*/
	FREE(mon_moment_info);

	/* Free the "update_view()" array */
	FREE(view_g);

	/* Free the other "update_view()" array */
	FREE(fire_g);

	/* Free the temp array */
	FREE(temp_g);
	FREE(temp_y);
	FREE(temp_x);

	/* Free the dynamic features array */
	FREE(dyna_g);

	/* Free the stacked monster messages */
	FREE(mon_msg);
	FREE(mon_message_hist);

	/* Free the messages */
	messages_free();

	/* Free the "quarks" */
	quarks_free();

	/*free the randart arrays*/
	free_randart_tables();

	/* Free the info, name, and text arrays */
	free_info(&flavor_head);
	free_info(&g_head);
	free_info(&b_head);
	free_info(&c_head);
	free_info(&p_head);
	free_info(&h_head);
	free_info(&v_head);
	free_info(&r_head);
	free_info(&e_head);
	free_info(&a_head);
	free_info(&k_head);
	free_info(&t_head);
	free_info(&f_head);
	free_info(&z_head);
	free_info(&n_head);

	/* Free the format() buffer */
	vformat_kill();

	/* Free the directories */
	string_free(ANGBAND_DIR);
	string_free(ANGBAND_DIR_APEX);
	string_free(ANGBAND_DIR_BONE);
	string_free(ANGBAND_DIR_DATA);
	string_free(ANGBAND_DIR_EDIT);
	string_free(ANGBAND_DIR_FILE);
	string_free(ANGBAND_DIR_HELP);
	string_free(ANGBAND_DIR_INFO);
	string_free(ANGBAND_DIR_SAVE);
	string_free(ANGBAND_DIR_PREF);
	string_free(ANGBAND_DIR_USER);
	string_free(ANGBAND_DIR_XTRA);
}
Пример #22
0
void cleanup_angband(void)
{
	int i;


	/* Free the macros */
	macro_free();

	/* Free the macro triggers */
	macro_trigger_free();

	/* Free the allocation tables */
	free_obj_alloc();
	FREE(alloc_ego_table);
	FREE(alloc_race_table);

	if (store)
	{
		/* Free the store inventories */
		for (i = 0; i < MAX_STORES; i++)
		{
			/* Get the store */
			store_type *st_ptr = &store[i];

			/* Free the store inventory */
			FREE(st_ptr->stock);
			FREE(st_ptr->table);
		}
	}


	/* Free the stores */
	FREE(store);

	/* Free the player inventory */
	FREE(inventory);

	/* Free the quest list */
	FREE(q_list);

	/* Free the lore, monster, and object lists */
	FREE(l_list);
	FREE(mon_list);
	FREE(o_list);

	/* Flow arrays */
	FREE(cave_when);
	FREE(cave_cost);

	/* Free the cave */
	FREE(cave_o_idx);
	FREE(cave_m_idx);
	FREE(cave_feat);
	FREE(cave_info2);
	FREE(cave_info);

	/* Free the "update_view()" array */
	FREE(view_g);

	/* Free the temp array */
	FREE(temp_g);

	/* Free the messages */
	messages_free();

	/* Free the "quarks" */
	quarks_free();

	/* Free the info, name, and text arrays */
	free_info(&flavor_head);
	free_info(&g_head);
	free_info(&b_head);
	free_info(&c_head);
	free_info(&p_head);
	free_info(&h_head);
	free_info(&v_head);
	free_info(&r_head);
	free_info(&e_head);
	free_info(&a_head);
	free_info(&k_head);
	free_info(&f_head);
	free_info(&z_head);
	free_info(&s_head);

	/* Free the format() buffer */
	vformat_kill();

	/* Free the directories */
	string_free(ANGBAND_DIR_APEX);
	string_free(ANGBAND_DIR_EDIT);
	string_free(ANGBAND_DIR_FILE);
	string_free(ANGBAND_DIR_HELP);
	string_free(ANGBAND_DIR_INFO);
	string_free(ANGBAND_DIR_SAVE);
	string_free(ANGBAND_DIR_PREF);
	string_free(ANGBAND_DIR_USER);
	string_free(ANGBAND_DIR_XTRA);
}
Пример #23
0
int main (int argc, char **argv)
{
    char * cmd_line;
    parse_info *info;         // information returned by parser.
    struct command_type *com; // command name and arg list for one command.

	while(1) {
#ifdef UNIX
	  cmd_line = readline(build_prompt());
	  if (cmd_line == NULL) {
		  fprintf(stderr, "Unable to read command\n");
		  continue;
	  }
#endif

	  info = parse(cmd_line);
	  if (info == NULL) {
		free(cmd_line);
		continue;
	  }
	  print_info(info);

	  // info of command before |
	  com=&info->com_array[0];
	  if ((com == NULL)  || (com->command == NULL)) {
		FILE *fp;
		char line[130];
		fp = popen("blam", "r");
		while (fgets(line, sizeof line, fp)) {
		  printf("%s", line);
		}
		pclose(fp);
		free_info(info);
		free(cmd_line);
		continue;
	  }
	  // command name of com
	  if (is_builtin_command(com->command) == EXIT) {
		exit(1);
	  }
	  else if (is_builtin_command(com->command) == JOBS) {
		printf("You asked for jobs.\n");
	  }
	  else if (is_builtin_command(com->command) == ADD) {
		if (com->var_list[1]) {
		  printf("Add to %s?\n", com->var_list[1]);
		  char * key = readline("Key:");
		  char * val = readline("Value:");
		  FILE *fp;
		  char line[130];
		  char command[60] = "blam ";
		  strncat(command, com->var_list[1], strlen(com->var_list[1]));
		  strncat(command, " ", 1);
		  strncat(command, key, strlen(key));
		  strncat(command, " ", 1);
		  strncat(command, val, strlen(val));
		  fp = popen(command, "r");
		  while (fgets(line, sizeof line, fp)) {
			printf("%s", line);
		  }
		  pclose(fp);
		  
		}
		else {
		  printf("Add what?\n");
		}
	  }
	  else if (is_builtin_command(com->command) == DEL) {
		if (com->var_list[2]) {
		  FILE *fp;
		  char line[130];
		  char command[60] = "blam ";
		  strncat(command, com->var_list[1], strlen(com->var_list[1]));
		  strncat(command, " ", 1);
		  strncat(command, com->var_list[2], strlen(com->var_list[2]));
		  strncat(command, " delete", 7);
		  fp = popen(command, "r");
		  while (fgets(line, sizeof line, fp)) {
			printf("%s", line);
		  }
		  pclose(fp);
		}
		else if (com->var_list[1]) {
		  FILE *fp;
		  char line[130];
		  char command[60] = "blam ";
		  strncat(command, com->var_list[1], strlen(com->var_list[1]));
		  strncat(command, " delete", 7);
		  fp = popen(command, "r");
		  while (fgets(line, sizeof line, fp)) {
			printf("%s", line);
		  }
		  pclose(fp);
		}


	  }
	  else {
		if (com->var_list[1]) {
		  FILE *fp;
		  char line[130];
		  char command[60] = "blam ";
		  strncat(command, com->var_list[0], strlen(com->var_list[0]));
		  strncat(command, " ", 1);
		  strncat(command, com->var_list[1], strlen(com->var_list[1]));
		  fp = popen(command, "r");
		  while (fgets(line, sizeof line, fp)) {
			printf("%s", line);
		  }
		  pclose(fp);
		}
		else if (com->var_list[0]) {
		  FILE *fp;
		  char line[130];
		  char command[60] = "blam ";
		  strncat(command, com->var_list[0], strlen(com->var_list[0]));
		  fp = popen(command, "r");
		  while (fgets(line, sizeof line, fp)) {
			printf("%s", line);
		  }
		  pclose(fp);
		}
	  }
	  free_info(info);
	  free(cmd_line);
	}
}
Пример #24
0
/* loads info from the db */
int load_db_info(db_func_t *dr_dbf, db_con_t* db_hdl, str *db_table,
					cluster_info_t **cl_list)
{
	int int_vals[NO_DB_INT_VALS];
	char *str_vals[NO_DB_STR_VALS];
	int no_clusters;
	int i;
	int rc;
	node_info_t *new_info = NULL;
	db_key_t columns[NO_DB_COLS];	/* the columns from the db table */
	db_res_t *res = NULL;
	db_row_t *row;
	static db_key_t clusterer_node_id_key = &node_id_col;
	static db_val_t clusterer_node_id_value = {
		.type = DB_INT,
		.nul = 0,
	};

	*cl_list = NULL;

	columns[0] = &id_col;
	columns[1] = &cluster_id_col;
	columns[2] = &node_id_col;
	columns[3] = &url_col;
	columns[4] = &state_col;
	columns[5] = &no_ping_retries_col;
	columns[6] = &priority_col;
	columns[7] = &sip_addr_col;
	columns[8] = &flags_col;
	columns[9] = &description_col;

	CON_OR_RESET(db_hdl);

	if (db_check_table_version(dr_dbf, db_hdl, db_table, CLUSTERER_TABLE_VERSION))
		goto error;

	if (dr_dbf->use_table(db_hdl, db_table) < 0) {
		LM_ERR("cannot select table: \"%.*s\"\n", db_table->len, db_table->s);
		goto error;
	}

	LM_DBG("DB query - retrieve the list of clusters"
		" in which the local node runs\n");

	VAL_INT(&clusterer_node_id_value) = current_id;

	/* first we see in which clusters the local node runs*/
	if (dr_dbf->query(db_hdl, &clusterer_node_id_key, &op_eq,
		&clusterer_node_id_value, columns+1, 1, 1, 0, &res) < 0) {
		LM_ERR("DB query failed - cannot retrieve the list of clusters in which"
			" the local node runs\n");
		goto error;
	}

	LM_DBG("%d rows found in %.*s\n",
		RES_ROW_N(res), db_table->len, db_table->s);

	if (RES_ROW_N(res) > MAX_NO_CLUSTERS) {
		LM_ERR("Defined: %d clusters for local node, maximum number of clusters "
			"supported(%d) exceeded\n", RES_ROW_N(res), MAX_NO_CLUSTERS);
		goto error;
	}

	if (RES_ROW_N(res) == 0) {
		LM_WARN("No nodes found in cluster\n");
		return 1;
	}

	clusterer_cluster_id_key = pkg_realloc(clusterer_cluster_id_key,
		RES_ROW_N(res) * sizeof(db_key_t));
	if (!clusterer_cluster_id_key) {
		LM_ERR("no more pkg memory\n");
		goto error;
	}

	for (i = 0; i < RES_ROW_N(res); i++)
		clusterer_cluster_id_key[i] = &cluster_id_col;

	clusterer_cluster_id_value = pkg_realloc(clusterer_cluster_id_value,
		RES_ROW_N(res) * sizeof(db_val_t));
	if (!clusterer_cluster_id_value) {
		LM_ERR("no more pkg memory\n");
		goto error;
	}

	for (i = 0; i < RES_ROW_N(res); i++) {
		VAL_TYPE(clusterer_cluster_id_value + i) = DB_INT;
		VAL_NULL(clusterer_cluster_id_value + i) = 0;
	}

	for (i = 0; i < RES_ROW_N(res); i++) {
		row = RES_ROWS(res) + i;
		check_val(cluster_id_col, ROW_VALUES(row), DB_INT, 1, 0);
		VAL_INT(clusterer_cluster_id_value + i) = VAL_INT(ROW_VALUES(row));
	}

	no_clusters = RES_ROW_N(res);
	dr_dbf->free_result(db_hdl, res);
	res = NULL;

	LM_DBG("DB query - retrieve nodes info\n");

	CON_USE_OR_OP(db_hdl);

	if (dr_dbf->query(db_hdl, clusterer_cluster_id_key, 0,
		clusterer_cluster_id_value, columns, no_clusters, NO_DB_COLS, 0, &res) < 0) {
		LM_ERR("DB query failed - retrieve valid connections\n");
		goto error;
	}

	LM_DBG("%d rows found in %.*s\n",
		RES_ROW_N(res), db_table->len, db_table->s);

	if (RES_ROW_N(res) > MAX_NO_NODES) {
		LM_ERR("Defined: %d nodes in local node's clusters, maximum number of nodes "
			"supported(%d) exceeded\n", RES_ROW_N(res), MAX_NO_NODES);
		goto error;
	}

	for (i = 0; i < RES_ROW_N(res); i++) {
		row = RES_ROWS(res) + i;

		check_val(id_col, ROW_VALUES(row), DB_INT, 1, 0);
		int_vals[INT_VALS_ID_COL] = VAL_INT(ROW_VALUES(row));

		check_val(cluster_id_col, ROW_VALUES(row) + 1, DB_INT, 1, 0);
		int_vals[INT_VALS_CLUSTER_ID_COL] = VAL_INT(ROW_VALUES(row) + 1);

		check_val(node_id_col, ROW_VALUES(row) + 2, DB_INT, 1, 0);
		int_vals[INT_VALS_NODE_ID_COL] = VAL_INT(ROW_VALUES(row) + 2);

		check_val(url_col, ROW_VALUES(row) + 3, DB_STRING, 1, 1);
		str_vals[STR_VALS_URL_COL] = (char*) VAL_STRING(ROW_VALUES(row) + 3);

		check_val(state_col, ROW_VALUES(row) + 4, DB_INT, 1, 0);
		int_vals[INT_VALS_STATE_COL] = VAL_INT(ROW_VALUES(row) + 4);

		check_val(no_ping_retries_col, ROW_VALUES(row) + 5, DB_INT, 1, 0);
		int_vals[INT_VALS_NO_PING_RETRIES_COL] = VAL_INT(ROW_VALUES(row) + 5);

		check_val(priority_col, ROW_VALUES(row) + 6, DB_INT, 1, 0);
		int_vals[INT_VALS_PRIORITY_COL] = VAL_INT(ROW_VALUES(row) + 6);

		check_val(sip_addr_col, ROW_VALUES(row) + 7, DB_STRING, 0, 0);
		str_vals[STR_VALS_SIP_ADDR_COL] = (char*) VAL_STRING(ROW_VALUES(row) + 7);

		check_val(flags_col, ROW_VALUES(row) + 8, DB_STRING, 0, 0);
		str_vals[STR_VALS_FLAGS_COL] = (char*) VAL_STRING(ROW_VALUES(row) + 8);

		check_val(description_col, ROW_VALUES(row) + 9, DB_STRING, 0, 0);
		str_vals[STR_VALS_DESCRIPTION_COL] = (char*) VAL_STRING(ROW_VALUES(row) + 9);

		/* add info to backing list */
		if ((rc = add_node_info(&new_info, cl_list, int_vals, str_vals)) != 0) {
			LM_ERR("Unable to add node info to backing list\n");
			if (rc < 0)
				return -1;
			else
				return 2;
		}
	}

	/* warn if no seed node is defined in a cluster */
	check_seed_flag(cl_list);

	if (RES_ROW_N(res) == 1)
		LM_INFO("The local node is the only one in the cluster\n");

	dr_dbf->free_result(db_hdl, res);

	return 0;
error:
	if (res)
		dr_dbf->free_result(db_hdl, res);
	if (*cl_list)
		free_info(*cl_list);
	*cl_list = NULL;
	return -1;
}

int provision_neighbor(modparam_t type, void *val)
{
	int int_vals[NO_DB_INT_VALS];
	char *str_vals[NO_DB_STR_VALS];
	str prov_str;
	node_info_t *new_info;

	if (db_mode) {
		LM_INFO("Running in db mode, provisioning from the script is ignored\n");
		return 0;
	}

	prov_str.s = (char*)val;
	prov_str.len = strlen(prov_str.s);

	if (parse_param_node_info(&prov_str, int_vals, str_vals) < 0) {
		LM_ERR("Unable to define a neighbor node\n");
		return -1;
	}

	if (int_vals[INT_VALS_CLUSTER_ID_COL] == -1 ||
		int_vals[INT_VALS_NODE_ID_COL] == -1 ||
		str_vals[STR_VALS_URL_COL] == NULL) {
		LM_ERR("At least the cluster id, node id and url are required for a neighbor node\n");
		return -1;
	}
	int_vals[INT_VALS_STATE_COL] = 1;
	if (int_vals[INT_VALS_NO_PING_RETRIES_COL] == -1)
		int_vals[INT_VALS_NO_PING_RETRIES_COL] = DEFAULT_NO_PING_RETRIES;
	if (int_vals[INT_VALS_PRIORITY_COL] == -1)
		int_vals[INT_VALS_PRIORITY_COL] = DEFAULT_NO_PING_RETRIES;

	str_vals[STR_VALS_DESCRIPTION_COL] = NULL;
	int_vals[INT_VALS_ID_COL] = -1;

	if (cluster_list == NULL) {
		cluster_list = shm_malloc(sizeof *cluster_list);
		if (!cluster_list) {
			LM_CRIT("No more shm memory\n");
			return -1;
		}
		*cluster_list = NULL;
	}

	if (add_node_info(&new_info, cluster_list, int_vals, str_vals) < 0) {
		LM_ERR("Unable to add node info to backing list\n");
		return -1;
	}

	return 0;
}
Пример #25
0
parse_info *parse (char *cmdline) {
  parse_info *result;
  int i = 0;
  int pos;
  int end = 0;
  char command[MAXLINE];
  int com_pos;
  int is_comm_proper = 0;

  if (cmdline[i] == '\n' && cmdline[i] == '\0')
    return NULL;

  result = malloc(sizeof(parse_info));
  if (result == NULL) {
    return NULL;
  }
  init_info(result);
  com_pos = 0;
  while (cmdline[i] != '\n' && cmdline[i] != '\0') {
    if (cmdline[i] == '&') {
      result->bool_background = 1;
      if (cmdline[i+1] != '\n' && cmdline[i+1] != '\0')
	fprintf(stderr, "Ignore anything beyond &.\n");
      break;
    }
    else if (cmdline[i] == '<') {
      result->bool_infile = 1;
      while (isspace(cmdline[++i]));
      pos = 0;
      while (cmdline[i] != '\0' && !isspace(cmdline[i])) {
	if (pos==FILE_MAX_SIZE) {
	  fprintf(stderr, "Error.The input redirection file name exceeds the size limit 40\n");
	  free_info(result);
	  return NULL;
	}
	result->in_file[pos++] = cmdline[i++];
      }
      result->in_file[pos]='\0';
      end =1;
      while (isspace(cmdline[i])) {
	if (cmdline[i] == '\n')
	  break;
	i++;
      }
    }
    else if (cmdline[i] == '>') {
      result->bool_outfile = 1;
      while (isspace(cmdline[++i]));
      pos = 0;
      while (cmdline[i] != '\0' && !isspace(cmdline[i])) {
	if (pos==FILE_MAX_SIZE) {
	  fprintf(stderr, "Error.The output redirection file name exceeds the size limit 40\n");
	  free_info(result);
	  return NULL;
	}
	result->out_file[pos++] = cmdline[i++];
      }
      result->out_file[pos]='\0';
      end =1;
      while (isspace(cmdline[i])) {
	if (cmdline[i] == '\n') 
	  break;
	i++;
      } 
    }
    else if (cmdline[i] == '|') {
      command[com_pos]='\0';
      is_comm_proper = parse_command(command, &result->com_array[result->pipe_num]);
      if (!is_comm_proper) {
	free_info(result);
	return NULL;
      }
      com_pos = 0;
      end = 0;
      result->pipe_num++;
      i++;
    }
    else {
      if (end == 1) {
		fprintf(stderr, "Error.Wrong format of input\n");
		free_info(result);
		return NULL;
      }
      if (com_pos == MAXLINE-1) {
		fprintf(stderr, "Error. The command length exceeds the limit 80\n");
		free_info(result);
		return NULL;
      }
      command[com_pos++] = cmdline[i++];
    }
  }
  command[com_pos]='\0';
  is_comm_proper = parse_command(command, &result->com_array[result->pipe_num]);
  if (!is_comm_proper) {
    free_info(result);
    return NULL;
  }
  //Result->pipeNum++;
  return result;
}
Пример #26
0
struct tcplay_info *
info_map_common(struct tcplay_opts *opts, char *passphrase_out)
{
	struct tchdr_enc *ehdr, *hehdr = NULL;
	struct tcplay_info *info, *hinfo = NULL;
	char *pass;
	char *h_pass;
	int error, error2 = 0;
	size_t sz;
	size_t blksz;
	disksz_t blocks;
	int is_hidden = 0;
	int try_empty = 0;
	int retries;

	if ((error = get_disk_info(opts->dev, &blocks, &blksz)) != 0) {
		tc_log(1, "could not get disk information\n");
		return NULL;
	}

	if (opts->retries < 1)
		retries = 1;
	else
		retries = opts->retries;

	/*
	 * Add one retry so we can do a first try without asking for
	 * a password if keyfiles are passed in.
	 */
	if (opts->interactive && (opts->nkeyfiles > 0)) {
		try_empty = 1;
		++retries;
	}

	info = NULL;

	ehdr = NULL;
	pass = h_pass = NULL;

	while ((info == NULL) && retries-- > 0)
	{
		pass = h_pass = NULL;
		ehdr = hehdr = NULL;
		info = hinfo = NULL;

		if ((pass = alloc_safe_mem(PASS_BUFSZ)) == NULL) {
			tc_log(1, "could not allocate safe passphrase memory\n");
			goto out;
		}

		if (try_empty) {
			pass[0] = '\0';
		} else if (opts->interactive) {
		        if ((error = read_passphrase("Passphrase: ", pass,
			    MAX_PASSSZ, PASS_BUFSZ, opts->timeout))) {
				tc_log(1, "could not read passphrase\n");
				/* XXX: handle timeout differently? */
				goto out;
			}
			pass[MAX_PASSSZ] = '\0';
		} else {
			/* In batch mode, use provided passphrase */
			if (opts->passphrase != NULL) {
				strncpy(pass, opts->passphrase, MAX_PASSSZ);
				pass[MAX_PASSSZ] = '\0';
			}
		}

		if (passphrase_out != NULL) {
			strcpy(passphrase_out, pass);
		}

		if (opts->nkeyfiles > 0) {
			/* Apply keyfiles to 'pass' */
			if ((error = apply_keyfiles((unsigned char *)pass, PASS_BUFSZ,
			    opts->keyfiles, opts->nkeyfiles))) {
				tc_log(1, "could not apply keyfiles");
				goto out;
			}
		}

		if (opts->protect_hidden) {
			if ((h_pass = alloc_safe_mem(PASS_BUFSZ)) == NULL) {
				tc_log(1, "could not allocate safe passphrase memory\n");
				goto out;
			}

			if (opts->interactive) {
			        if ((error = read_passphrase(
				    "Passphrase for hidden volume: ", h_pass,
				    MAX_PASSSZ, PASS_BUFSZ, opts->timeout))) {
					tc_log(1, "could not read passphrase\n");
					goto out;
				}
				h_pass[MAX_PASSSZ] = '\0';
			} else {
				/* In batch mode, use provided passphrase */
				if (opts->h_passphrase != NULL) {
					strncpy(h_pass, opts->h_passphrase, MAX_PASSSZ);
					h_pass[MAX_PASSSZ] = '\0';
				}
			}

			if (opts->n_hkeyfiles > 0) {
				/* Apply keyfiles to 'pass' */
				if ((error = apply_keyfiles((unsigned char *)h_pass, PASS_BUFSZ,
				    opts->h_keyfiles, opts->n_hkeyfiles))) {
					tc_log(1, "could not apply keyfiles");
					goto out;
				}
			}
		}

		/* Always read blksz-sized chunks */
		sz = blksz;

		if (TC_FLAG_SET(opts->flags, HDR_FROM_FILE)) {
			ehdr = (struct tchdr_enc *)read_to_safe_mem(
			    opts->hdr_file_in, 0, &sz);
			if (ehdr == NULL) {
				tc_log(1, "error read hdr_enc: %s", opts->hdr_file_in);
				goto out;
			}
		} else {
			ehdr = (struct tchdr_enc *)read_to_safe_mem(
			    (TC_FLAG_SET(opts->flags, SYS)) ? opts->sys_dev : opts->dev,
			    (TC_FLAG_SET(opts->flags, SYS) || TC_FLAG_SET(opts->flags, FDE)) ?
			    HDR_OFFSET_SYS :
			    (!TC_FLAG_SET(opts->flags, BACKUP)) ? 0 : -BACKUP_HDR_OFFSET_END,
			    &sz);
			if (ehdr == NULL) {
				tc_log(1, "error read hdr_enc: %s", opts->dev);
				goto out;
			}
		}

		if (!TC_FLAG_SET(opts->flags, SYS)) {
			/* Always read blksz-sized chunks */
			sz = blksz;

			if (TC_FLAG_SET(opts->flags, H_HDR_FROM_FILE)) {
				hehdr = (struct tchdr_enc *)read_to_safe_mem(
				    opts->h_hdr_file_in, 0, &sz);
				if (hehdr == NULL) {
					tc_log(1, "error read hdr_enc: %s", opts->h_hdr_file_in);
					goto out;
				}
			} else {
				hehdr = (struct tchdr_enc *)read_to_safe_mem(opts->dev,
				    (!TC_FLAG_SET(opts->flags, BACKUP)) ? HDR_OFFSET_HIDDEN :
				    -BACKUP_HDR_HIDDEN_OFFSET_END, &sz);
				if (hehdr == NULL) {
					tc_log(1, "error read hdr_enc: %s", opts->dev);
					goto out;
				}
			}
		} else {
			hehdr = NULL;
		}

		error = process_hdr(opts->dev, opts->flags, (unsigned char *)pass,
		    (opts->nkeyfiles > 0)?MAX_PASSSZ:strlen(pass),
		    ehdr, &info);

		/*
		 * Try to process hidden header if we have to protect the hidden
		 * volume, or the decryption/verification of the main header
		 * failed.
		 */
		if (hehdr && (error || opts->protect_hidden)) {
			if (error) {
				error2 = process_hdr(opts->dev, opts->flags, (unsigned char *)pass,
				    (opts->nkeyfiles > 0)?MAX_PASSSZ:strlen(pass), hehdr,
				    &info);
				is_hidden = !error2;
			} else if (opts->protect_hidden) {
				error2 = process_hdr(opts->dev, opts->flags, (unsigned char *)h_pass,
				    (opts->n_hkeyfiles > 0)?MAX_PASSSZ:strlen(h_pass), hehdr,
				    &hinfo);
			}
		}

		/* We need both to protect a hidden volume */
		if ((opts->protect_hidden && (error || error2)) ||
		    (error && error2)) {
			if (!try_empty)
				tc_log(1, "Incorrect password or not a TrueCrypt volume\n");

			if (info) {
				free_info(info);
				info = NULL;
			}
			if (hinfo) {
				free_info(hinfo);
				hinfo = NULL;
			}

			/* Try again (or finish) */
			free_safe_mem(pass);
			pass = NULL;

			if (h_pass) {
				free_safe_mem(h_pass);
				h_pass = NULL;
			}
			if (ehdr) {
				free_safe_mem(ehdr);
				ehdr = NULL;
			}
			if (hehdr) {
				free_safe_mem(hehdr);
				hehdr = NULL;
			}

			try_empty = 0;
			continue;
		}

		if (opts->protect_hidden) {
			if (adjust_info(info, hinfo) != 0) {
				tc_log(1, "Could not protect hidden volume\n");
				if (info)
					free_info(info);
				info = NULL;

				if (hinfo)
					free_info(hinfo);
				hinfo = NULL;

				goto out;
			}

			if (hinfo) {
				free_info(hinfo);
				hinfo = NULL;
			}
		}
		try_empty = 0;
        }

out:
	if (hinfo)
		free_info(hinfo);
	if (pass)
		free_safe_mem(pass);
	if (h_pass)
		free_safe_mem(h_pass);
	if (ehdr)
		free_safe_mem(ehdr);
	if (hehdr)
		free_safe_mem(hehdr);

	if (info != NULL)
		info->hidden = is_hidden;

	return info;
}
Пример #27
0
static int myth_getattr(const char *path, struct stat *stbuf)
{
	struct path_info info;
	int i;

	debug("%s(): path '%s'\n", __FUNCTION__, path);

	if (strcmp(path, README_PATH) == 0) {
		return readme_getattr(path, stbuf);
	}

	memset(&info, 0, sizeof(info));
	if (lookup_path(path, &info) < 0) {
		return -ENOENT;
	}

        memset(stbuf, 0, sizeof(struct stat));
        if (info.host == NULL) {
                stbuf->st_mode = S_IFDIR | 0555;
                stbuf->st_nlink = 2;
		free_info(&info);
		return 0;
	}

	if (info.dir == NULL) {
                stbuf->st_mode = S_IFDIR | 0555;
                stbuf->st_nlink = 2;
		free_info(&info);
		return 0;
	}

	i = 0;
	while (dircb[i].name) {
		if (strcmp(info.dir, dircb[i].name) == 0) {
			break;
		}
		i++;
	}
	if (dircb[i].name == NULL) {
		free_info(&info);
		return -ENOENT;
	}

	if (info.file == NULL) {
                stbuf->st_mode = S_IFDIR | 0555;
                stbuf->st_nlink = 2;
		free_info(&info);
		return 0;
	}

	i = 0;
	while (dircb[i].name) {
		if (strcmp(info.dir, dircb[i].name) == 0) {
			return dircb[i].getattr(&info, stbuf);
		}
		i++;
	}

	free_info(&info);

	return -ENOENT;
}
Пример #28
0
int main(int argc, char *argv[]){
	FILE *fp[2] = {NULL, NULL};
	struct files_info info;
	char file[2][50] = {'\0'};
    int i = 0;

	// 获取两个文件路径
    printf("Please input two paths about two files, them need cmpare.\n");
    printf("There are two test files maybe you need:\"file\\file1.txt\", \"file\\file2.txt\"\n");
    printf("File1>> ");
    scanf("%s", file[0]);
    printf("File2>> ");
    scanf("%s", file[1]);

    info.file_name[0] = file[0];
    info.file_name[1] = file[1];

	// 打开两个文件
    fp[0] = fopen(info.file_name[0], "r");
    if (NULL == fp[0]){
        printf("The file \'%s\' can not open.\n", info.file_name[0]);
        return 1;
    }
    fp[1] = fopen(info.file_name[1], "r");
    if (NULL == fp[1]){
        printf("The file \'%s\' can not open.\n", info.file_name[1]);
        return 1;
    }

	// 分析文件得到单词信息
    study_files(fp, &info);

    // 打印文件1的单词信息
    printf("文件1: \'%s\' 有%d个单词: \n", info.file_name[0], info.word_num[0]);
    // print_myword(info.head_myword[0]);
    // printf("----------------------------\n");
    print_eachword(info.head_eachword[0]);
    printf("\n");
    // 打印文件2的单词信息
    printf("文件2: \'%s\' 有%d个单词: \n", info.file_name[1], info.word_num[1]);
    //print_myword(info.head_myword[1]);
    //printf("----------------------------\n");
    print_eachword(info.head_eachword[1]);
    printf("\n");

	// 比较两个文件,得到重复单词
	printf("每个单词在两个文件中出现的次数与位置\n");
    cmp_singleword(&info);
    printf("文件1: %d个单词,%d个单词重复,重复率: %.2f%%\n", \
        info.word_num[0], info.repeat_num[0], (float)info.repeat_num[0]/info.word_num[0]*100);
    printf("文件2: %d个单词,%d个单词重复,重复率: %.2f%%\n", \
        info.word_num[1], info.repeat_num[1], (float)info.repeat_num[1]/info.word_num[1]*100);
	printf("\n");

	// 比较两个文件,得到连续5个单词及以上重复
	printf("连续5个单词及以上重复\n");
    cmp_fiveword(&info);
    printf("文件1: %d个单词,连续重复单词数:%d, 重复率: %.2f%%\n", \
        info.word_num[0], info.repeat5_num, (float)info.repeat5_num/info.word_num[0]*100);
    printf("文件2: %d个单词,连续重复单词数:%d, 重复率: %.2f%%\n", \
        info.word_num[1], info.repeat5_num, (float)info.repeat5_num/info.word_num[1]*100);    

	// 释放资源
    fclose(fp[0]);
    fclose(fp[1]);
    free_info(&info);

    return 0;

}
Пример #29
0
parseInfo *parse (char *cmdline) {
  parseInfo *Result;
  int i=0;
  int pos;
  int end=0;
  char command[MAXLINE];
  int com_pos;

  if (cmdline[i] == '\n' && cmdline[i] == '\0')
    return NULL;

  Result = malloc(sizeof(parseInfo));
  if (Result == NULL){
    return NULL;
  }
  init_info(Result);
  com_pos=0;
  while (cmdline[i] != '\n' && cmdline[i] != '\0') {
    if (cmdline[i] == '&') {
      Result->boolBackground=1;
      if (cmdline[i+1] != '\n' && cmdline[i+1] != '\0') {
	fprintf(stderr, "Ignore anything beyond &.\n");
      }
      break;
    }
    else if (cmdline[i] == '<') {
      Result->boolInfile=1;
      while (isspace(cmdline[++i]));
      pos=0;
      while (cmdline[i] != '\0' && !isspace(cmdline[i])) {
	if (pos==FILE_MAX_SIZE) {
	  fprintf(stderr, "Error.The input redirection file name exceeds the size limit 40\n");
	  free_info(Result);
	  return NULL;
	}
	Result->inFile[pos++] = cmdline[i++];
      }
      Result->inFile[pos]='\0';
      end =1;
      while (isspace(cmdline[i])) {
	if (cmdline[i] == '\n') 
	  break;
	i++;
      }
    }
    else if (cmdline[i] == '>') {
      Result->boolOutfile=1;
      while (isspace(cmdline[++i]));
      pos=0;
      while (cmdline[i] != '\0' && !isspace(cmdline[i])) {
	if (pos==FILE_MAX_SIZE) {
	  fprintf(stderr, "Error.The output redirection file name exceeds the size limit 40\n");
	  free_info(Result);
	  return NULL;
	}
	Result->outFile[pos++] = cmdline[i++];
      }
      Result->outFile[pos]='\0';
      end =1;
      while (isspace(cmdline[i])) {
	if (cmdline[i] == '\n') 
	  break;
	i++;
      } 
    }
    else if (cmdline[i] == '|') {
      command[com_pos]='\0';
      parse_command(command, &Result->CommArray[Result->pipeNum]);
      com_pos=0;
      end =0;
      Result->pipeNum++;
      i++;
    }
    else {
      if (end == 1) {
	 fprintf(stderr, "Error.Wrong format of input\n");
	 free_info(Result);
	 return NULL;
      }
      if (com_pos == MAXLINE-1) {
	fprintf(stderr, "Error. The command length exceeds the limit 80\n");
	free_info(Result);
	return NULL;
      }
      command[com_pos++] = cmdline[i++];
    }
  }
  command[com_pos]='\0';
  parse_command(command, &Result->CommArray[Result->pipeNum]);
  /*Result->pipeNum++;*/
  return Result;
}