Exemple #1
0
void goto_convertt::new_name(symbolt &symbol)
{
  // rename it
  get_new_name(symbol, ns);

  // store in context
  context.add(symbol);
}
static gboolean
append_dir(GtkTreeStore* store, GtkTreeIter* parent_iter,
	GFile* dir, const char* encoding)
{
    GtkTreeIter iter;
    GFileInfo* info;
    GFileEnumerator* e;
    gboolean success_all = TRUE;

    e = g_file_enumerate_children(dir,
	    G_FILE_ATTRIBUTE_STANDARD_NAME ","
	    G_FILE_ATTRIBUTE_STANDARD_TYPE,
	    G_FILE_QUERY_INFO_NONE, NULL, NULL);
    if (e == NULL)
	return success_all;

    info = g_file_enumerator_next_file(e, NULL, NULL);
    while (info != NULL) {
	const char* name = g_file_info_get_name(info);
	char* display_name = get_display_name(name);
	char* new_name = get_new_name(name, encoding);
	GFileType ftype;

	file_list_model_append(store, &iter, parent_iter,
		NULL, name, display_name, new_name);

	if (new_name == NULL)
	    success_all = FALSE;

	ftype = g_file_info_get_file_type(info);
	if (ftype == G_FILE_TYPE_DIRECTORY) {
	    gboolean res;
	    GFile* child = g_file_get_child(dir, name);
	    res = append_dir(store, &iter, child, encoding);
	    g_object_unref(child);
	    if (!res)
		success_all = FALSE;
	}

	g_object_unref(info);
	g_free(display_name);
	g_free(new_name);
	
	info = g_file_enumerator_next_file(e, NULL, NULL);
    }
    g_object_unref(e);

    return success_all;
}
Exemple #3
0
static void
adjust_names(union tree *trp,
		 struct db_i *dbip,
		 Tcl_HashTable *name_tbl,
		 Tcl_HashTable *used_names_tbl,
		 struct ged_concat_data *cc_data)
{
    char *new_name;

    if (trp == NULL) {
	return;
    }

    switch (trp->tr_op) {
	case OP_DB_LEAF:
	    new_name = get_new_name(trp->tr_l.tl_name, dbip,
					name_tbl, used_names_tbl, cc_data);
	    if (new_name) {
		bu_free(trp->tr_l.tl_name, "leaf name");
		trp->tr_l.tl_name = bu_strdup(new_name);
	    }
	    break;
	case OP_UNION:
	case OP_INTERSECT:
	case OP_SUBTRACT:
	case OP_XOR:
	    adjust_names(trp->tr_b.tb_left, dbip,
			     name_tbl, used_names_tbl, cc_data);
	    adjust_names(trp->tr_b.tb_right, dbip,
			     name_tbl, used_names_tbl, cc_data);
	    break;
	case OP_NOT:
	case OP_GUARD:
	case OP_XNOP:
	    adjust_names(trp->tr_b.tb_left, dbip,
			     name_tbl, used_names_tbl, cc_data);
	    break;
    }
}
Exemple #4
0
int		assemble(int fd_src, char *name)
{
    int		fd_dest;
    char		*new_name;
    header_t	header;
    t_parser	parser;

    if ((new_name = get_new_name(name)) == NULL)
        return (1);
    if ((fd_dest = open(new_name, O_WRONLY | O_CREAT | O_TRUNC, 00600)) == -1)
    {
        my_putstr_err("Can't create the .cor file", 2);
        return (1);
    }
    if (parse_file(fd_src, &parser, fd_dest, &header) == 1)
        return (1);
    free(new_name);
    if (close(fd_dest) == -1)
        return (1);
    if (close(fd_src) == -1)
        return (1);
    return (0);
}
static gboolean
update_new_name_in_a_row(GtkTreeStore* store, GtkTreeIter* iter, const char* encoding)
{
    char* old_name;
    char* new_name;
    gboolean res;

    old_name = NULL;
    gtk_tree_model_get(GTK_TREE_MODEL(store), iter,
	    FILE_COLUMN_NAME, &old_name, -1);

    new_name = get_new_name(old_name, encoding);
    if (new_name != NULL) {
	gtk_tree_store_set(store, iter, FILE_COLUMN_NEW_NAME, new_name, -1);
	g_free(new_name);
	res = TRUE;
    } else {
	gtk_tree_store_set(store, iter, FILE_COLUMN_NEW_NAME, "", -1);
	res = FALSE;
    }
    g_free(old_name);

    return res;
}
/** Release an open file
 *
 * Release is called when there are no more references to an open
 * file: all file descriptors are closed and all memory mappings
 * are unmapped.
 *
 * For every open() call there will be exactly one release() call
 * with the same flags and file descriptor.  It is possible to
 * have a file opened more than once, in which case only the last
 * release will mean, that no more reads/writes will happen on the
 * file.  The return value of release is ignored.
 *
 * Changed in version 2.2
 */
int cloudfs_release(const char *path, struct fuse_file_info *fi)
{
  static int count;
  char new_name[MAX_NAME_LENGTH];
  char symlink_name[MAX_NAME_LENGTH];
  char buf[MAX_BUFFER_SIZE];
  char fpath[PATH_MAX];
  char symlink_path[PATH_MAX];
  char file_to_link[PATH_MAX];
  char new_hdd_path[PATH_MAX];
  char attr_file_name[PATH_MAX];
  char temp[PATH_MAX];
  int retstat = 0;
  int fd;
  int temp_fd;
  int n;
  struct stat file_attributes; 

  d_printf("\ncloudfs_release(path=\"%s\", fi=0x%08x)\n",  path, fi);
  //    log_fi(fi);


  //Read file attributes to get size of file
  fstat(fi->fh,&file_attributes);
  d_printf("Size of file is %d\n",file_attributes.st_size);

  //Open given file
  cloudfs_fullpath(fpath,path);
  if ((temp_fd = open(fpath,O_RDONLY)) < 0 )
    cloudfs_error("Problem opening original file\n");
  //Check if file is greater than threshold . 
  //If yes then write the file to hdd with name large<static counter>
  //Delete the original file from ssd and create a symlink to new file
  //in hdd  
  if (file_attributes.st_size > state_.threshold) {

    strcpy(new_hdd_path,path);
    get_new_name(new_hdd_path); //File's new name in HDD will have * instead of /
    strcpy(fpath, state_.hdd_path);
    strncat(fpath,new_hdd_path, PATH_MAX); 
    strncpy(file_to_link,fpath,PATH_MAX); //Full name of new file is what 
    //our symlink will point to
    fd = open(fpath,O_CREAT|O_RDWR,FILE_MODE);  //Getting new fd of file
    if (fd < 0){ 
      d_printf("Failed to open %s\n",fpath);
      retstat = cloudfs_error("cloudfs_create create error in HDD");
    }

    while ( (n = read(temp_fd,buf,4096))> 0 ) {
      write(fd,buf,n);              
    }

    //Close new file made
    close(fd);        

    //Create hidden attribute file  
    get_hidden_file_name(path,temp);
    strcpy(attr_file_name,temp);
    cloudfs_fullpath(fpath,path);
    append_to_end(fpath,attr_file_name);
    fd = open(fpath,O_CREAT|O_RDWR,FILE_MODE);  //Getting fd of hidden file
    d_printf("Making hidden file %s\n",fpath);
    if (fd < 0){ 
      d_printf("Failed to open %s\n",fpath);
      retstat = cloudfs_error("cloudfs_create create error of hidden attribute file");
    }   
    //Store attributes of migrated file in 
    //extended attributes of hidden attribute file
    set_extended_attributes(fpath,&file_attributes);


    close(fd);  //Close fd of hidden attribute file


    //Closing fd of original file and deleting
    //from SSD  
    if ((retstat = close(temp_fd)) < 0)
      cloudfs_error("Error closing original file\n");
    if ((retstat = close(fi->fh)) < 0)
      cloudfs_error("Error closing original file\n");

    cloudfs_fullpath(fpath,path);
    d_printf("Trying to delete file %s\n",fpath);
    if( remove(fpath) < 0 )
      cloudfs_error("Can't remove the file \n");


    //Creating symlink
    cloudfs_fullpath(fpath,path);
    strcpy(symlink_name,fpath);
    fd = symlink(file_to_link,fpath);  //Getting new fd of file
    if (fd < 0){ 
      d_printf("Failed to make symlink %s\n",fpath);
    }  


    return retstat;

  }
  // We need to close the file.  Had we allocated any resources
  // (buffers etc) we'd need to free them here as well.
  else {
    if ((retstat = close(temp_fd)) < 0)
      cloudfs_error("Error closing original file\n");
    if ((retstat = close(fi->fh)) < 0)
      cloudfs_error("Error closing original file\n");
    return retstat;
  }


}
static gboolean
repair_dialog_on_idle_update(GtkDialog* dialog)
{
    GtkTreeIter iter;
    GtkTreeIter* parent_iter;
    char* name;
    char* display_name;
    char* new_name;
    GFile* file;
    GFileType ftype;
    UpdateContext* context;
    gint n;
    int i;

    context = repair_dialog_get_update_context(dialog);

    if (context == NULL) {
	return FALSE;
    }

    for (i = 0; i < 500; i++) {
	if (context->file_stack == NULL) {
	    repair_dialog_set_update_context(dialog, NULL);
	    repair_dialog_on_update_end(dialog, context->success_all);
	    update_context_free(context);
	    return FALSE;
	}

	file = context->file_stack->data;

	if (context->enum_stack != NULL) {
	    GFileInfo* info;
	    GFileEnumerator* e;

	    parent_iter = context->iter_stack->data;
	    e = context->enum_stack->data;

	    info = g_file_enumerator_next_file(e, NULL, NULL);
	    if (info != NULL) {
		const char* name_const;
		name_const = g_file_info_get_name(info);
		display_name = get_display_name(name_const);
		new_name = get_new_name(name_const, context->encoding);

		file_list_model_append(context->store, &iter, parent_iter,
			NULL, name_const, display_name, new_name);
		if (new_name == NULL)
		    context->success_all = FALSE;

		ftype = g_file_info_get_file_type(info);
		if (ftype == G_FILE_TYPE_DIRECTORY) {
		    GFile* child;
		    GFileEnumerator* child_e;
		    GtkTreeIter* tmp_iter;

		    tmp_iter = gtk_tree_iter_copy(&iter);
		    child = g_file_get_child(file, name_const);
		    child_e = g_file_enumerate_children(child,
			    G_FILE_ATTRIBUTE_STANDARD_NAME ","
			    G_FILE_ATTRIBUTE_STANDARD_TYPE,
			    G_FILE_QUERY_INFO_NONE, NULL, NULL);
		    
		    update_context_push(context, child, tmp_iter, child_e);
		}

		g_object_unref(info);
		g_free(display_name);
		g_free(new_name);

		n = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(context->store), parent_iter);
		if (n == 1) {
		    GtkTreePath* path;
		    path = gtk_tree_model_get_path(GTK_TREE_MODEL(context->store), parent_iter);
		    gtk_tree_view_expand_row(context->treeview, path, FALSE);
		    gtk_tree_path_free(path);
		}
	    } else {
		g_object_unref(file);
		gtk_tree_iter_free(parent_iter);
		g_object_unref(e);
		update_context_pop(context);
	    }
	} else {
	    context->file_stack = g_slist_delete_link(context->file_stack, context->file_stack);

	    name = g_file_get_basename(file);
	    display_name = get_display_name(name);
	    new_name = get_new_name(name, context->encoding);

	    file_list_model_append(context->store, &iter, NULL,
		    file, name, display_name, new_name);

	    if (new_name == NULL)
		context->success_all = FALSE;

	    if (context->include_subdir) {
		ftype = g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL);
		if (ftype == G_FILE_TYPE_DIRECTORY) {
		    GtkTreeIter* tmp_iter;
		    GFileEnumerator* e;

		    tmp_iter = gtk_tree_iter_copy(&iter);
		    e = g_file_enumerate_children(file,
			    G_FILE_ATTRIBUTE_STANDARD_NAME ","
			    G_FILE_ATTRIBUTE_STANDARD_TYPE,
			    G_FILE_QUERY_INFO_NONE, NULL, NULL);

		    update_context_push(context, file, tmp_iter, e);
		}
	    }

	    g_free(name);
	    g_free(display_name);
	    g_free(new_name);
	}
    }

    return TRUE;
}
static void
repair_dialog_update_file_list_model(GtkDialog* dialog, gboolean async)
{
    GtkTreeStore* store;
    GtkTreeView* treeview;
    GSList* files;
    gboolean include_subdir;
    GtkComboBox* combobox;
    UpdateContext* context;
    gboolean success_all = TRUE;

    store = repair_dialog_get_file_list_model(dialog);
    files = repair_dialog_get_file_list(dialog);
    treeview = repair_dialog_get_file_list_view(dialog);
    include_subdir = repair_dialog_get_include_subdir_flag(dialog);

    combobox = repair_dialog_get_encoding_combo_box(dialog);
    gtk_widget_set_sensitive(GTK_WIDGET(combobox), FALSE);

    gtk_tree_store_clear(store);

    if (async) {
	context = repair_dialog_get_update_context(dialog);
	if (context != NULL) {
	    g_idle_remove_by_data(dialog);
	    update_context_free(context);
	}

	context = update_context_new();
	context->dialog = dialog;
	context->treeview = treeview;
	context->store = store;
	context->file_stack = g_slist_copy(files);
	context->encoding = repair_dialog_get_current_encoding(dialog);
	context->include_subdir = include_subdir;

	g_slist_foreach(context->file_stack, (GFunc)g_object_ref, NULL);

	repair_dialog_set_update_context(dialog, context);

	g_idle_add((GSourceFunc)repair_dialog_on_idle_update, dialog);
    } else {
	char* encoding = repair_dialog_get_current_encoding(dialog);

	while (files != NULL) {
	    GtkTreeIter iter;
	    char* name;
	    char* display_name;
	    char* new_name;
	    GFile* file;

	    file = files->data;
	    name = g_file_get_basename(file);
	    display_name = get_display_name(name);
	    new_name = get_new_name(name, encoding);

	    file_list_model_append(store, &iter, NULL,
		    file, name, display_name, new_name);
	    if (new_name == NULL)
		success_all = FALSE;
	    
	    if (include_subdir) {
		GFileType file_type;
		file_type = g_file_query_file_type(file,
			G_FILE_QUERY_INFO_NONE, NULL);
		if (file_type == G_FILE_TYPE_DIRECTORY) {
		    gboolean res;
		    res = append_dir(store, &iter, file, encoding);
		    if (!res)
			success_all = FALSE;
		}
	    }

	    g_free(name);
	    g_free(display_name);
	    g_free(new_name);

	    files = g_slist_next(files);
	}

	gtk_tree_view_expand_all(treeview);
	g_free(encoding);

	repair_dialog_on_update_end(dialog, success_all);
    }
}
/// \par parameters: expression dest, to be dereferenced under given guard,
/// and given mode
/// \return returns pointer after dereferencing
exprt value_set_dereferencet::dereference(
  const exprt &pointer,
  const guardt &guard,
  const modet mode)
{
  if(pointer.type().id()!=ID_pointer)
    throw "dereference expected pointer type, but got "+
          pointer.type().pretty();

  // we may get ifs due to recursive calls
  if(pointer.id()==ID_if)
  {
    const if_exprt &if_expr=to_if_expr(pointer);
    // push down the if
    guardt true_guard=guard;
    guardt false_guard=guard;

    true_guard.add(if_expr.cond());
    false_guard.add(not_exprt(if_expr.cond()));

    exprt true_case=dereference(if_expr.true_case(), true_guard, mode);
    exprt false_case=dereference(if_expr.false_case(), false_guard, mode);

    return if_exprt(if_expr.cond(), true_case, false_case);
  }

  // type of the object
  const typet &type=pointer.type().subtype();

  #if 0
  std::cout << "DEREF: " << from_expr(ns, "", pointer) << '\n';
  #endif

  // collect objects the pointer may point to
  value_setst::valuest points_to_set;

  dereference_callback.get_value_set(pointer, points_to_set);

  #if 0
  for(value_setst::valuest::const_iterator
      it=points_to_set.begin();
      it!=points_to_set.end();
      it++)
    std::cout << "P: " << from_expr(ns, "", *it) << '\n';
  #endif

  // get the values of these

  std::list<valuet> values;

  for(value_setst::valuest::const_iterator
      it=points_to_set.begin();
      it!=points_to_set.end();
      it++)
  {
    valuet value=build_reference_to(*it, mode, pointer, guard);

    #if 0
    std::cout << "V: " << from_expr(ns, "", value.pointer_guard) << " --> ";
    std::cout << from_expr(ns, "", value.value) << '\n';
    #endif

    values.push_back(value);
  }

  // can this fail?
  bool may_fail;

  if(values.empty())
  {
    invalid_pointer(pointer, guard);
    may_fail=true;
  }
  else
  {
    may_fail=false;
    for(std::list<valuet>::const_iterator
        it=values.begin();
        it!=values.end();
        it++)
      if(it->value.is_nil())
        may_fail=true;
  }

  if(may_fail)
  {
    // first see if we have a "failed object" for this pointer

    const symbolt *failed_symbol;
    exprt failure_value;

    if(dereference_callback.has_failed_symbol(
         pointer, failed_symbol))
    {
      // yes!
      failure_value=failed_symbol->symbol_expr();
      failure_value.set(ID_C_invalid_object, true);
    }
    else
    {
      // else: produce new symbol

      symbolt symbol;
      symbol.name="symex::invalid_object"+std::to_string(invalid_counter++);
      symbol.base_name="invalid_object";
      symbol.type=type;

      // make it a lvalue, so we can assign to it
      symbol.is_lvalue=true;

      get_new_name(symbol, ns);

      failure_value=symbol.symbol_expr();
      failure_value.set(ID_C_invalid_object, true);

      new_symbol_table.move(symbol);
    }

    valuet value;
    value.value=failure_value;
    value.pointer_guard=true_exprt();
    values.push_front(value);
  }

  // now build big case split, but we only do "good" objects

  exprt value=nil_exprt();

  for(std::list<valuet>::const_iterator
      it=values.begin();
      it!=values.end();
      it++)
  {
    if(it->value.is_not_nil())
    {
      if(value.is_nil()) // first?
        value=it->value;
      else
        value=if_exprt(it->pointer_guard, it->value, value);
    }
  }

  #if 0
  std::cout << "R: " << from_expr(ns, "", value) << "\n\n";
  #endif

  return value;
}
Exemple #10
0
/// automated variable renaming
/// \par parameters: symbol to be renamed, namespace
/// \return new symbol
void get_new_name(symbolt &symbol, const namespacet &ns)
{
  get_new_name(symbol.name, ns);
}
Exemple #11
0
static int
copy_object(struct ged *gedp,
	    struct directory *input_dp,
	    struct db_i *input_dbip,
	    struct db_i *curr_dbip,
	    Tcl_HashTable *name_tbl,
	    Tcl_HashTable *used_names_tbl,
	    struct ged_concat_data *cc_data)
{
    struct rt_db_internal ip;
    struct rt_extrude_internal *extr;
    struct rt_dsp_internal *dsp;
    struct rt_comb_internal *comb;
    struct directory *new_dp;
    char *new_name;

    if (rt_db_get_internal(&ip, input_dp, input_dbip, NULL, &rt_uniresource) < 0) {
	bu_vls_printf(gedp->ged_result_str,
		      "Failed to get internal form of object (%s) - aborting!!!\n",
		      input_dp->d_namep);
	return GED_ERROR;
    }

    if (ip.idb_major_type == DB5_MAJORTYPE_BRLCAD) {
	/* adjust names of referenced object in any object that reference other objects */
	switch (ip.idb_minor_type) {
	    case DB5_MINORTYPE_BRLCAD_COMBINATION:
		comb = (struct rt_comb_internal *)ip.idb_ptr;
		RT_CK_COMB(comb);
		adjust_names(comb->tree, curr_dbip, name_tbl, used_names_tbl, cc_data);
		break;
	    case DB5_MINORTYPE_BRLCAD_EXTRUDE:
		extr = (struct rt_extrude_internal *)ip.idb_ptr;
		RT_EXTRUDE_CK_MAGIC(extr);

		new_name = get_new_name(extr->sketch_name, curr_dbip, name_tbl, used_names_tbl, cc_data);
		if (new_name) {
		    bu_free(extr->sketch_name, "sketch name");
		    extr->sketch_name = bu_strdup(new_name);
		}
		break;
	    case DB5_MINORTYPE_BRLCAD_DSP:
		dsp = (struct rt_dsp_internal *)ip.idb_ptr;
		RT_DSP_CK_MAGIC(dsp);

		if (dsp->dsp_datasrc == RT_DSP_SRC_OBJ) {
		    /* This dsp references a database object, may need to change its name */
		    new_name = get_new_name(bu_vls_addr(&dsp->dsp_name), curr_dbip,
						name_tbl, used_names_tbl, cc_data);
		    if (new_name) {
			bu_vls_free(&dsp->dsp_name);
			bu_vls_strcpy(&dsp->dsp_name, new_name);
		    }
		}
		break;
	}
    }

    new_name = get_new_name(input_dp->d_namep, curr_dbip, name_tbl, used_names_tbl, cc_data);
    if (!new_name) {
	new_name = input_dp->d_namep;
    }
    if ((new_dp = db_diradd(curr_dbip, new_name, RT_DIR_PHONY_ADDR, 0, input_dp->d_flags,
			    (void *)&input_dp->d_minor_type)) == RT_DIR_NULL) {
	bu_vls_printf(gedp->ged_result_str,
		      "Failed to add new object name (%s) to directory - aborting!!\n",
		      new_name);
	return GED_ERROR;
    }

    if (rt_db_put_internal(new_dp, curr_dbip, &ip, &rt_uniresource) < 0) {
	bu_vls_printf(gedp->ged_result_str,
		      "Failed to write new object (%s) to database - aborting!!\n",
		      new_name);
	return GED_ERROR;
    }

    return GED_OK;
}
Exemple #12
0
void goto_symext::new_name(symbolt &symbol)
{
  get_new_name(symbol, ns);
  new_symbol_table.add(symbol);
}