Ejemplo n.º 1
0
//-------------------------------------------------------------------
// FileName::dir_copy
//-------------------------------------------------------------------
void FileName::dir_copy(const String &strDest, bool bCreateDir, mode_t modeDir, uid_t uid, gid_t gid) throw( Exception )
{
  FileName fnDst;

  // Create destination path
  fnDst.set(strDest);
  fnDst.mkdir(modeDir, uid, gid);

  if( bCreateDir )
  {
    // Create source directory name inside destination path
    fnDst.set(strDest + dir_name() + SEP_PATH);
    fnDst.mkdir(modeDir, uid, gid);
  }

  if( !fnDst.is_path_name() )
    throw BadPathException(PSZ(String::str_format(ERR_BAD_DEST_PATH, PSZ(fnDst.full_name()))),
                           "FileName::dir_copy");

  // Recursively copying sub-directories
  FileEnum dirEnum(full_name(), FileEnum::ENUM_DIR);
  while( dirEnum.find() )
    dirEnum.dir_copy(fnDst.path(), true, modeDir, uid, gid);

  // Copying directory files
  FileEnum fileEnum(full_name(), FileEnum::ENUM_FILE);
  while( fileEnum.find() )
    // Copy with metadata
    fileEnum.copy(fnDst.path(), true);
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------
// FileName::is_empty_dir
//-------------------------------------------------------------------
bool FileName::is_empty_dir() const
{
  FileEnum dirEnum(full_name(), FileEnum::ENUM_DIR );
  FileEnum fileEnum(full_name(), FileEnum::ENUM_FILE);
  
  if( !dirEnum.find() && !fileEnum.find() )
	return true;
  return false;
}
Ejemplo n.º 3
0
DSN_API void dsn_perf_counter_remove(dsn_handle_t handle)
{
    auto sptr = reinterpret_cast<dsn::perf_counter*>(handle);
    if (dsn::perf_counters::instance().remove_counter(sptr->full_name()))
        sptr->release_ref();
    else
    {
        dwarn("cannot remove counter %s as it is not found in our repo", sptr->full_name());
    }
}
Ejemplo n.º 4
0
//----------------------------------------------------------------------------
// FileName::remove
//----------------------------------------------------------------------------
void FileName::remove() throw( Exception )
{
  if( !m_strFile.empty() )
  {
    if( unlink(PSZ(full_name())) )
    {
      String strErr = String::str_format(ERR_CANNOT_REMOVE_FILE, PSZ(full_name()));
      ThrowExceptionFromErrno(PSZ(strErr), "FileName::remove");
    }
  }
}
Ejemplo n.º 5
0
FileSystem::namelist_type FileSystem::get_list(const std::string &dir_name,
                                               int type_flag)
{
  namelist_type  result;
  std::string    path(normalize_path(dir_name));
  DIR           *dp;
  struct dirent *entry;
  struct stat    statbuf;
  
  // Scan the directory.
  if ((dp = opendir(path.c_str())) != NULL) {
    while ((entry = readdir(dp)) != NULL) {

      // If the current name is dot or dotdot, ignore it.
      if (strcmp(entry->d_name, "." ) == 0 ||
          strcmp(entry->d_name, "..") == 0) continue;

      // If the current name is that of a file, add it to the result.
      std::string full_name(path + "/" + entry->d_name);
      if (stat(full_name.c_str(), &statbuf) != -1) {
        if (type_flag == 0 && S_ISREG(statbuf.st_mode)) {
          result.push_back(entry->d_name);
        }
        if (type_flag == 1 && S_ISDIR(statbuf.st_mode)) {
          result.push_back(entry->d_name);
        }
      }
    }
    closedir(dp);
  }

  return result;
}
Ejemplo n.º 6
0
void BrowserNode::unconsistent_removed(const char * what, BrowserNode * newone) {
  UnconsistencyDeletedMsg += QString("<li>") + what + QString(" <i>") +
    quote(full_name()) + QString("</i> and <i>") + 
      quote(newone->full_name()) + QString("</i></li>\n");

  // deletion managed elsewhere
}
Ejemplo n.º 7
0
// Return dereferenced name.  Only if type() == Pointer.
string DispValue::dereferenced_name() const
{
    switch (mytype)
    {
    case Pointer:
    {
	string f = full_name();
	if (f.contains('/', 0))
	    f = f.from(2);	// Skip /FMT expressions

	return deref(f);
    }

    case Simple:
    case Text:
    case Array:
    case Sequence:
    case List:
    case Struct:
    case Reference:
	return "";

    case UnknownType:
	assert(0);
	abort();
    }

    return "";
}
Ejemplo n.º 8
0
  Object* CompiledMethod::jit_now(STATE) {
    return Qfalse;
#ifdef ENABLE_LLVM
    if(backend_method_ == NULL) {
      internalize(state);
    }

    if(state->shared.config.jit_show_compiling) {
      std::cout << "[[[ JIT compiling " << full_name(state)->c_str() << " ]]]\n";
    }

    LLVMState* ls = LLVMState::get(state);

    jit::Compiler jit;
    jit.compile_method(ls, this, backend_method_);

    if(jit.generate_function(ls)) {
      backend_method_->set_jitted(jit.llvm_function(),
                                  jit.code_bytes(), jit.function_pointer());
      return Qtrue;
    }
#endif

    return Qfalse;
  }
Ejemplo n.º 9
0
//-------------------------------------------------------------------
// FileName::recursive_chmod_dir
//-------------------------------------------------------------------
void FileName::recursive_chmod_dir(mode_t mode) throw( Exception )
{
  if( !path_exist() )
  { // File doesn't exists
    String strErr = String::str_format(ERR_DIR_NOT_FOUND, PSZ(full_name()));
    throw FileNotFoundException(PSZ(strErr), "FileName::recursive_chmod_dir");
  }

  // Recursively change rights on sub-directories
  FileEnum dirEnum(full_name(), FileEnum::ENUM_DIR);
  while( dirEnum.find() )
    dirEnum.recursive_chmod_dir(mode);

  // Change mode to directory itself
  chmod(mode);
}
Ejemplo n.º 10
0
void CodClassInstCanvas::save(QTextStream & st, bool ref, QString & warning) const {
  if (ref)
    st << "classinstance_ref " << get_ident() << " // "
      << full_name();
  else if (browser_node->get_type() == UmlClass) {
    nl_indent(st);
    st << "classinstance " << get_ident() << ' ';
    browser_node->save(st, TRUE, warning);
    nl_indent(st);
    ClassInstCanvas::save(st);
    st << " name ";
    save_string(iname, st);
    st << ' ';
    save_xyz(st, this, " xyz");
  }
  else {
    nl_indent(st);
    st << "classinstancecanvas " << get_ident() << ' ';
    browser_node->save(st, TRUE, warning);

    indent(+1);
    nl_indent(st);
    save_xyz(st, this, "xyz");
    ClassInstCanvas::save(st);
    save_stereotype_property(st, warning);    
    indent(-1);
    
    nl_indent(st);
    st << "end";
  }
}
Ejemplo n.º 11
0
 Statement* Expand::operator()(Mixin_Call* c)
 {
   string full_name(c->name() + "[m]");
   if (!env->has(full_name)) {
     error("no mixin named " + c->name(), c->path(), c->position(), backtrace);
   }
   Definition* def = static_cast<Definition*>((*env)[full_name]);
   Block* body = def->block();
   Parameters* params = def->parameters();
   Arguments* args = static_cast<Arguments*>(c->arguments()
                                              ->perform(eval->with(env, backtrace)));
   Backtrace here(backtrace, c->path(), c->position(), ", in mixin `" + c->name() + "`");
   backtrace = &here;
   Env new_env;
   new_env.link(def->environment());
   if (c->block()) {
     // represent mixin content blocks as thunks/closures
     Definition* thunk = new (ctx.mem) Definition(c->path(),
                                                  c->position(),
                                                  "@content",
                                                  new (ctx.mem) Parameters(c->path(), c->position()),
                                                  c->block(),
                                                  Definition::MIXIN);
     thunk->environment(env);
     new_env.current_frame()["@content[m]"] = thunk;
   }
   bind("mixin " + c->name(), params, args, ctx, &new_env, eval);
   Env* old_env = env;
   env = &new_env;
   append_block(body);
   env = old_env;
   backtrace = here.parent;
   return 0;
 }
Ejemplo n.º 12
0
// Update values from VALUE.  Set WAS_CHANGED iff value changed; Set
// WAS_INITIALIZED iff type changed.  If TYPE is given, use TYPE as
// type instead of inferring it.  Note: THIS can no more be referenced
// after calling this function; use the returned value instead.
DispValue *DispValue::update(string& value, 
			     bool& was_changed, bool& was_initialized,
			     DispValueType given_type)
{
    DispValue *source = parse(0, 0, value, 
			      full_name(), name(), given_type);

    if (background(value.length()))
    {
	// Aborted while parsing - use SOURCE instead of original
	DispValue *ret = source->link();
	ret->changed = was_changed = was_initialized = true;

	// Have the new DispValue take over the plotter
	if (ret->plotter() == 0)
	{
	    ret->_plotter = plotter();
	    _plotter = 0;
	}

	unlink();
	return ret;
    }

    DispValue *dv = update(source, was_changed, was_initialized);

    if (was_changed || was_initialized)
	dv->clear_cached_box();

    source->unlink();

    return dv;
}
Ejemplo n.º 13
0
	symbol *symbol_table::lookup(const string &name, uint16_t offset) {
		auto _symbol = lookup_table.find(full_name(name, offset));
		if (_symbol == lookup_table.end()) {
			throw undefined_symbol_error(name);
		}
		return &_symbol->second;
	}
Ejemplo n.º 14
0
// If the name has the form (PREFIX)(INDEX)(SUFFIX), return INDEX
string DispValue::index(const string& prefix, const string& suffix) const
{
    string idx = full_name();
    idx = idx.from(int(prefix.length()));
    idx = idx.before(int(idx.length() - suffix.length()));
    strip_space(idx);

    return idx;
}
Ejemplo n.º 15
0
perf_counter_ptr perf_counters::get_app_counter(const char *section,
                                                const char *name,
                                                dsn_perf_counter_type_t flags,
                                                const char *dsptr,
                                                bool create_if_not_exist)
{
    auto cnode = dsn::task::get_current_node2();
    dassert(cnode != nullptr, "cannot get current service node!");
    return get_global_counter(cnode->full_name(), section, name, flags, dsptr, create_if_not_exist);
}
Ejemplo n.º 16
0
//-------------------------------------------------------------------
// File::save
//-------------------------------------------------------------------
void File::save(const String &strContent) throw(Exception)
{
  // Open destination file
  FILE *fi = fopen(PSZ(full_name()), "wb");
  if( NULL == fi )
  {
    String strErr = String::str_format(ERR_OPEN_FILE, PSZ(full_name()));
    throw Exception("FILE_ERROR", PSZ(strErr), "File::Load");
  }

  // Write text content
  int iRc = fputs(PSZ(strContent), fi);
  if( EOF == iRc )
  {
    String strErr;
    strErr.printf("Cannot write in file '%s'", PSZ(full_name()));
    throw Exception("FILE_ERROR", PSZ(strErr), "File::Save");
  }
  fclose(fi);
}
Ejemplo n.º 17
0
bool BrowserRelation::undelete(bool, QString & warning, QString & renamed)
{
    if (! deletedp())
        return FALSE;

    if (def->get_start_class()->deletedp() ||
        def->get_end_class()->deletedp()) {
        if (def->is_a(this))
            warning += QString("<li><b>") + quote(def->get_name(this)) + "</b> " + TR("from") + " <b>" +
                       def->get_start_class()->full_name() +
                       "</b> " + TR("to") + " <b>" + def->get_end_class()->full_name() + "</b>\n";
        else
            warning += QString("<li><b>") + def->get_name(this) + "</b> " + TR("from") + " <b>" +
                       def->get_end_class()->full_name() +
                       "</b> " + TR("to") + " <b>" + quote(def->get_start_class()->full_name()) + "</b>\n";

        return FALSE;
    }
    else {
        switch (get_type()) {
        case UmlGeneralisation:
        case UmlRealize:
            if (!def->get_start_class()->check_inherit(def->get_end_class()).isEmpty()) {
                warning += QString("<li><b>") + quote(def->get_name(this)) + "</b> "
                           + TR("because <b>%1</b> cannot (or already) inherit on <b>%2</b>",
                                def->get_start_class()->full_name(),
                                def->get_end_class()->full_name())
                           + "\n";
                return FALSE;
            }

            break;

        default:
            break;
        }
    }

    if (def->undelete(warning, renamed, this, is_deleted)) {
        renamed += QString("<li><b>") + full_name() + "</b>\n";
        modified();
    }

    if (RelationData::isa_inherit(get_type()) &&
        !strcmp(def->get_start_class()->get_data()->get_stereotype(), "stereotype") &&
        !strcmp(def->get_end_class()->get_data()->get_stereotype(), "stereotype"))
        ProfiledStereotypes::recompute(TRUE);

    package_modified();
    repaint();

    return TRUE;
}
Ejemplo n.º 18
0
void video_manager::begin_recording_mng(const char *name, uint32_t index, screen_device *screen)
{
	// stop any existing recording
	end_recording_mng(index);

	mng_info_t &info = m_mngs[index];

	// reset the state
	info.m_mng_frame = 0;
	info.m_mng_next_frame_time = machine().time();

	// create a new movie file and start recording
	info.m_mng_file = std::make_unique<emu_file>(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
	osd_file::error filerr;
	if (name != nullptr)
	{
		std::string full_name(name);

		if (index > 0)
		{
			char name_buf[256] = { 0 };
			snprintf(name_buf, 256, "%s%d", name, index);
			full_name = name_buf;
		}

		filerr = info.m_mng_file->open(full_name.c_str());
	}
	else
	{
		filerr = open_next(*info.m_mng_file, "mng");
	}

	if (filerr == osd_file::error::NONE)
	{
		// start the capture
		int rate = int(screen->frame_period().as_hz());
		png_error pngerr = mng_capture_start(*info.m_mng_file, m_snap_bitmap, rate);
		if (pngerr != PNGERR_NONE)
		{
			osd_printf_error("Error capturing MNG, png_error=%d\n", pngerr);
			return end_recording_mng(index);
		}

		// compute the frame time
		info.m_mng_frame_period = attotime::from_hz(rate);
	}
	else
	{
		osd_printf_error("Error creating MNG, osd_file::error=%d\n", int(filerr));
		info.m_mng_file.reset();
	}
}
Ejemplo n.º 19
0
void BrowserNode::unconsistent_fixed(const char * what, BrowserNode * newone) {  
  UnconsistencyFixedMsg += QString("<li>") + what + QString(" <i>") +
    quote(full_name()) + QString("</i> and <i>") + 
      quote(newone->full_name()) + QString("</i></li>\n");

  BrowserNode * bn = this;

  while (bn->get_type() != UmlPackage)
    bn = (BrowserNode *) bn->parent();

  if (ModifiedPackages.findRef(bn) == -1)
    ModifiedPackages.append(bn);
}
Ejemplo n.º 20
0
	static inline std::string _hlp_build_name(
		Full /*full*/,
		Local /*local*/,
		std::string& /*left*/,
		std::string& /*right*/,
		std::string& /*extent*/,
		std::string& /*arg*/
	)
	{
		if(Local::value) return local_name();
		else if(Full::value) return full_name();
		else return base_name();
	}
Ejemplo n.º 21
0
//-------------------------------------------------------------------
// FileName::recursive_chown
//-------------------------------------------------------------------
void FileName::recursive_chown(uid_t uid, gid_t gid) throw( Exception )
{
  if( !path_exist() )
  { // File doesn't exists
    String strErr = String::str_format(ERR_DIR_NOT_FOUND, PSZ(full_name()));
    throw FileNotFoundException(PSZ(strErr), "FileName::recursive_chmod");
  }

  // Recursively change rights on sub-directories
  FileEnum dirEnum(full_name(), FileEnum::ENUM_DIR);
  while( dirEnum.find() )
    dirEnum.recursive_chmod(uid, gid);

  // Change mode on files
  FileEnum fileEnum(full_name(), FileEnum::ENUM_FILE);
  while( fileEnum.find() )
    // Copy with metadata
    fileEnum.chown(uid, gid);

  // Change mode to directory itself
  chown(uid, gid);
}
Ejemplo n.º 22
0
	void symbol_table::add_label(const label &label, uint16_t offset) {
		string name = full_name(label.name, offset);

		symbol::symbol_type type = symbol::symbol_type::GLOBAL_LABEL;
		if (label.type == label_type::LOCAL) {
			type = symbol::symbol_type::LOCAL_LABEL;
		}

		auto existing_symbol = lookup_table.find(name);
		if (existing_symbol != lookup_table.end()) {
			throw duplicate_symbol_error(name, existing_symbol->second.location);
		}

		add_symbol(symbol(label.location, type, name, offset));
	}
Ejemplo n.º 23
0
//-------------------------------------------------------------------
// File::load(MemBuf)
//-------------------------------------------------------------------
void File::load(MemBuf *pBuf) throw(Exception)
{
  // Open source file
  FILE *fi = fopen(PSZ(full_name()), "r");
  if( NULL == fi )
  {
    String strErr = String::str_format(ERR_OPEN_FILE, PSZ(full_name()));
    throw Exception("FILE_ERROR", PSZ(strErr), "File::Load");
  }

  // Buffer
  pBuf->set_len(size()+1);

  // Read
  long lSize = size();
  long lReaded = fread(pBuf->buf(), 1, lSize, fi);
  if( ferror(fi) || lSize != lReaded )
  {
    String strErr = String::str_format(ERR_READING_FILE, PSZ(full_name()));
    throw Exception("FILE_ERROR", PSZ(strErr), "File::Load");
  }
  memset(pBuf->buf() + lSize, 0, 1);
  fclose(fi);
}
Ejemplo n.º 24
0
void DispValue::plot() const
{
    int ndim = can_plot();
    if (ndim == 0)
	return;

    if (plotter() == 0)
    {
	string title = make_title(full_name());
	MUTABLE_THIS(DispValue *)->_plotter = new_plotter(title, CONST_CAST(DispValue *,this));
	if (plotter() == 0)
	    return;

	plotter()->addHandler(Died, PlotterDiedHP, (void *)this);
    }
Ejemplo n.º 25
0
void BrowserNode::delete_it() {
  if (! deletedp()) {
    if (UndefinedNodePackage == 0) {
      // not during a read
      QString warning;
    
      if (!delete_internal(warning)) {
	warning = full_name() + TR(" cannot be deleted because :") + warning;
	
	warn(warning);
      }
      else {
	// mark modified to not delete the associated file(s)
	// on exit if no save was done before
	is_modified = TRUE;
      }
      
      if (BrowserSearchDialog::get() != 0)
	BrowserSearchDialog::get()->update();
      
      if (ReferenceDialog::get() != 0)
	ReferenceDialog::get()->update();
    }
    else {
      // during a read : no check
      is_deleted = TRUE;
      if (is_marked) {
	marked_list.removeRef(this);
	is_marked = FALSE;
      }
      if (is_writable())
	package_modified();
      
      if (get_data() != 0)
	get_data()->delete_it();
      
      // delete the sub elts
      Q3ListViewItem * child;
      
      for (child = firstChild(); child != 0; child = child->nextSibling())
	if (! ((BrowserNode *) child)->deletedp())
	  ((BrowserNode *) child)->delete_it();
      
      setOpen(FALSE);      
      must_be_deleted();
    }
  }
}
Ejemplo n.º 26
0
  Object* CompiledMethod::jit_soon(STATE) {
#ifdef ENABLE_LLVM
    if(backend_method_ == NULL) {
      formalize(state, false);
    }

    if(state->shared.config.jit_show_compiling) {
      std::cout << "[[[ JIT queueing " << full_name(state)->c_str() << " ]]]\n";
    }

    LLVMState::get(state)->compile_soon(state, this);
    return Qtrue;
#else
    return Qfalse;
#endif
  }
Ejemplo n.º 27
0
int conf_read(const char *fname, char *buf, int sz)
{
	char fnbuf[512];

	FILE *f = fopen(full_name(fname, fnbuf, sizeof(fnbuf)), "r");
	if (f == NULL) {
		return errno;
	}

	fgets(buf, sz, f);
	buf[strlen(buf)-1] = '\0';
	fclose(f);

	return 0;

}
Ejemplo n.º 28
0
void find_full_path(const char *filename, char *fullname)
{
    if (full_name(filename)) {
	strncpy(fullname, filename, STRMAX);
	fullname[STRMAX - 1] = 0;
	return;
    }
    if (!getcwd(fullname, STRMAX)) {
	/* something is really wrong. Pretend we found a
	   cwd that will not match anything */
	goto error;
    }
    /* see if we need a separator (probably) */
    int len = strlen(fullname);
    if (!file_sep(fullname[len - 1])) {
	fullname[len++] = '/';
	if (len >= STRMAX) goto error; 
    }
    /* append filename to fullname */
    strncpy(fullname + len, filename, STRMAX - len);
    fullname[STRMAX - 1] = 0; /* just in case of overflow */
    /* if windows, replace \ with / to simplify the rest */
    char *loc = fullname;
    if (os_pathchar != '/') {
        while ((loc = index(loc, os_pathchar))) {
	    *loc = '/';
	}
    }
    /* strip out .. and . */
    while ((loc = strstr(fullname, "/.."))) {
	/* back up to separator */
	if (loc == fullname) goto error;
	char *loc2 = loc - 1;
	while (*loc2 != '/') {
	    loc2--;
	    if (loc2 <= fullname) goto error;
	}
	/* now loc2 points to /parent/.., and loc points to /.. */
	/* copy from beyond /.. to loc2 */
	memmove(loc2, loc, strlen(loc) + 1);
    }
    return;
  error:
    strcpy(fullname, "//////");
    return;
}
Ejemplo n.º 29
0
bool BrowserNode::undelete(bool rec, QString & warning, QString & renamed) {
  bool result;
  
  if (deletedp()) {
    // undelete the node
    QString s = name;
    bool ren = FALSE;
    
    while (((BrowserNode *)parent())
	   ->wrong_child_name(s, get_type(),
			      allow_spaces(), allow_empty())) {
      s = "_" + s;
      ren = TRUE;
    }
    
    is_deleted = FALSE;
    is_modified = TRUE;
    get_data()->undelete(warning, renamed);
    
    if (ren) {
      set_name(s);
      renamed += QString("<li><b>") + full_name() + "</b>\n";
    }
    
    result = TRUE;
    package_modified();
  }
  else 
    result = FALSE;
    
  if (rec) {
    // undelete the sub elts
    Q3ListViewItem * child;
    
    for (child = firstChild(); child != 0; child = child->nextSibling())
      result |= ((BrowserNode *) child)->undelete(rec, warning, renamed);
  }
  
  if (result)
    repaint();
  
  return result;
}
Ejemplo n.º 30
0
bool node::call_method(int id, base_stream &out,
		       const std::vector<std::string> &args) {
	switch (id) {
	case node_method_enable:
	case node_method_disable:
		return enable_several(args, id == node_method_enable);
	case node_method_no:
		return exec_negate(out, args);
	case node_method_show_properties:
		{
			std::string fname = m_parent ? full_name() : std::string();
			for (properties::const_iterator i = m_properties.begin();
					i != m_properties.end(); ++i) {
				if (!fname.empty())
					out.write(fname.c_str()).write(".");
				out.write(i->first.c_str()).write(" = ");
				if (i->second.is_property()) {
					i->second.output_value(out);
					if (i->second.is_readonly())
						out.write(" [readonly]");
				} else if (i->second.is_child()) {
					out.xprintf("<node %s>", i->second.get_node()->name());
				} else if (i->second.is_method()) {
					if (i->second.is_readonly())
						out.write("<info-method ");
					else
						out.write("<method ");
					out.xprintf("%s>", i->second.get_method_info()->name);
				}

				out.newl();
			}

			return true;
		}
	}

	return false;
}