示例#1
0
ASTfunction_declaration::ASTfunction_declaration (OSLCompilerImpl *comp,
                             TypeSpec type, ustring name,
                             ASTNode *form, ASTNode *stmts, ASTNode *meta)
    : ASTNode (function_declaration_node, comp, 0, meta, form, stmts),
      m_name(name), m_sym(NULL), m_is_builtin(false)
{
    m_typespec = type;
    Symbol *f = comp->symtab().clash (name);
    if (f && f->symtype() != SymTypeFunction) {
        error ("\"%s\" already declared in this scope as a ", name.c_str(),
               f->typespec().string().c_str());
        // FIXME -- print the file and line of the other definition
        f = NULL;
    }

    // FIXME -- allow multiple function declarations, but only if they
    // aren't the same polymorphic type.

    if (name[0] == '_' && name[1] == '_' && name[2] == '_') {
        error ("\"%s\" : sorry, can't start with three underscores",
               name.c_str());
    }

    m_sym = new FunctionSymbol (name, type, this);
    func()->nextpoly ((FunctionSymbol *)f);
    std::string argcodes = oslcompiler->code_from_type (m_typespec);
    for (ASTNode *arg = form;  arg;  arg = arg->nextptr()) {
        const TypeSpec &t (arg->typespec());
        if (t == TypeSpec() /* UNKNOWN */) {
            m_typespec = TypeDesc::UNKNOWN;
            return;
        }
        argcodes += oslcompiler->code_from_type (t);
        ASSERT (arg->nodetype() == variable_declaration_node);
        ASTvariable_declaration *v = (ASTvariable_declaration *)arg;
        if (v->init())
            v->error ("function parameter '%s' may not have a default initializer.",
                      v->name().c_str());
    }
    func()->argcodes (ustring (argcodes));
    oslcompiler->symtab().insert (m_sym);

    // Typecheck it right now, upon declaration
    typecheck (typespec ());
}
示例#2
0
ustring gw_path_get_dirname(const ustring & filename)
{
  ustring returnvalue;
  gchar *dirname;
  dirname = g_path_get_dirname(filename.c_str());
  returnvalue = dirname;
  g_free(dirname);
  return returnvalue;
}
示例#3
0
ustring gw_path_get_basename(const ustring & filename)
{
  ustring returnvalue;
  gchar *basename;
  basename = g_path_get_basename(filename.c_str());
  returnvalue = basename;
  g_free(basename);
  return returnvalue;
}
示例#4
0
    _size_t_ getMarkedCharPos (ustring ch) {
        _size_t_ mark =
            LettersWithMarks.find (removeAccentFromChar (ch.lowercase ()));

        if (mark != ustring::npos)
            mark %= LettersWithoutMarks.length ();

        return mark;
    }
示例#5
0
static void
time_read_image ()
{
    ImageInput *in = ImageInput::open (input_filename.c_str());
    ASSERT (in);
    in->read_image (TypeDesc::TypeFloat, &buffer[0]);
    in->close ();
    delete in;
}
示例#6
0
void CGlobalRecords::wide2str16(const ustring& str1, u16string& str2)
{
	ustring::const_iterator	cBegin, cEnd;
	size_t len;

	str2.clear();

	len = str1.length();
	str2.reserve(len);

	cBegin	= str1.begin();
	cEnd	= str1.end();

	while(cBegin != cEnd) {
		str2.push_back((unsigned16_t)*cBegin++);
	}
	XL_ASSERT(str2.length() == str1.length());
}
示例#7
0
void DataValue::parsePixbuf(const ustring &text, void *value) {
	gsize size;
	guchar *buf = g_base64_decode(text.c_str(), &size);
	Glib::RefPtr<Gdk::PixbufLoader> loader = Gdk::PixbufLoader::create();
	loader->write(buf, size);
	loader->close();
	(*(TypePixbuf*)value) = loader->get_pixbuf();
	g_free(buf);
}
示例#8
0
  inline ustring ascii_toupper(ustring str)
  {
    ustring ret;
    
    for (ustring::const_iterator it = str.begin();
	 it != str.end();
	 ++it)
    {
      uchar x = *it;
      
      if (x >= 0x61 && x <= 0x7A)
	x -= 0x20;
      
      ret.append(x);
    }
    
    return ret;
  }
示例#9
0
void script_decode_usfm_file(const ustring & filename)
// Decodes a USFM file, that means, puts the original USFM code back.
{
  // Read the file. Bail out if there's no text.
  ustring input;
  {
    gchar *contents;
    g_file_get_contents(filename.c_str(), &contents, NULL, NULL);
    if (!contents)
      return;
    input = contents;
    g_free(contents);
  }
  if (input.empty())
    return;

  // Go through the input, changing usfm codes to their numerical equivalent,
  // and copying data to the output.
  // E.g. "\_105_100" would become "\id".
  ustring output;
  while (!input.empty()) {
    ustring character = input.substr(0, 1);
    input.erase(0, 1);
    output.append(character);
    if (character == "\\") {
      size_t pos = input.find(" ");
      if (pos == string::npos)
        pos = input.length();
      ustring encoded_text = input.substr(0, pos);
      input.erase(0, pos);
      Parse parse(encoded_text, false, "_");
      for (unsigned int i = 0; i < parse.words.size(); i++) {
        gunichar unichar = convert_to_int(parse.words[i]);
        gchar buf[7];
        gint length = g_unichar_to_utf8(unichar, (gchar *) & buf);
        buf[length] = '\0';
        character = buf;
        output.append(character);
      }
    }
  }
  // Write the data back to the file.
  g_file_set_contents(filename.c_str(), output.c_str(), -1, NULL);
}
示例#10
0
ASTvariable_declaration::ASTvariable_declaration (OSLCompilerImpl *comp,
                                                  const TypeSpec &type,
                                                  ustring name, ASTNode *init,
                                                  bool isparam, bool ismeta,
                                                  bool isoutput, bool initlist)
    : ASTNode (variable_declaration_node, comp, 0, init, NULL /* meta */),
      m_name(name), m_sym(NULL), 
      m_isparam(isparam), m_isoutput(isoutput), m_ismetadata(ismeta),
      m_initlist(initlist)
{
    m_typespec = type;
    Symbol *f = comp->symtab().clash (name);
    if (f) {
        std::string e = Strutil::format ("\"%s\" already declared in this scope", name.c_str());
        if (f->node()) {
            boost::filesystem::path p(f->node()->sourcefile().string());
            e += Strutil::format ("\n\t\tprevious declaration was at %s:%d",
                                  p.filename().c_str(), f->node()->sourceline());
        }
        if (f->scope() == 0 && f->symtype() == SymTypeFunction && isparam) {
            // special case: only a warning for param to mask global function
            warning ("%s", e.c_str());
        } else {
            error ("%s", e.c_str());
        }
    }
    if (name[0] == '_' && name[1] == '_' && name[2] == '_') {
        error ("\"%s\" : sorry, can't start with three underscores",
               name.c_str());
    }
    SymType symtype = isparam ? (isoutput ? SymTypeOutputParam : SymTypeParam)
                              : SymTypeLocal;
    m_sym = new Symbol (name, type, symtype, this);
    if (! m_ismetadata)
        oslcompiler->symtab().insert (m_sym);

    // A struct really makes several subvariables
    if (type.is_structure() || type.is_structure_array()) {
        ASSERT (! m_ismetadata);
        // Add the fields as individual declarations
        m_compiler->add_struct_fields (type.structspec(), m_sym->name(),
                                       symtype, type.arraylength(), this);
    }
}
int
Dictionary::dict_find (int nodeID, ustring query)
{
    if (nodeID <= 0 || nodeID >= (int)m_nodes.size())
        return 0;     // invalid node ID

    const Dictionary::Node &node (m_nodes[nodeID]);
    Query q (node.document, nodeID, query);
    QueryMap::iterator qfound = m_cache.find (q);
    if (qfound != m_cache.end()) {
        return qfound->second.valueoffset;
    }

    // Query was not found.  Do the expensive lookup and cache it
    pugi::xpath_node_set matches;
    try {
        matches = node.node.select_nodes (query.c_str());
    }
    catch (const pugi::xpath_exception& e) {
        m_context->error ("Invalid dict_find query '%s': %s",
                          query.c_str(), e.what());
        return 0;
    }

    if (matches.empty()) {
        m_cache[q] = QueryResult (false);  // mark invalid
        return 0;   // Not found
    }
    int firstmatch = (int) m_nodes.size();
    int last = -1;
    for (int i = 0, e = (int)matches.size(); i < e;  ++i) {
        m_nodes.push_back (Node (node.document, matches[i].node()));
        int nodeid = (int) m_nodes.size()-1;
        if (last < 0) {
            // If this is the first match, add a cache entry for it
            m_cache[q] = QueryResult (true /* it's a node */, nodeid);
        } else {
            // If this is a subsequent match, set the last match's 'next'
            m_nodes[last].next = nodeid;
        }
        last = nodeid;
    }
    return firstmatch;
}
示例#12
0
void script_encode_usfm_file(const ustring & filename)
// Encodes a USFM file. The purpose is that the USFM marked are not changed by the script.
// The assumption is that numbers are not affected.
{
  // Read the file. Bail out if there's no text.
  ustring input;
  {
    gchar *contents;
    g_file_get_contents(filename.c_str(), &contents, NULL, NULL);
    if (!contents)
      return;
    input = contents;
    g_free(contents);
  }
  if (input.empty())
    return;

  // Go through the input, changing usfm codes to their numerical equivalent,
  // and copying data to the output.
  // E.g. "\id" would become "\_105_100".
  ustring output;
  bool within_usfm = false;
  for (unsigned int i = 0; i < input.length(); i++) {
    ustring character = input.substr(i, 1);
    if (within_usfm)
      if (character == " ")
        within_usfm = false;
    if (within_usfm) {
      gunichar unichar;
      gunichar *uc;
      uc = g_utf8_to_ucs4_fast(character.c_str(), -1, NULL);
      unichar = *uc;
      g_free(uc);
      character = "_" + convert_to_string(unichar);
    }
    output.append(character);
    if (character == "\\")
      within_usfm = true;
  }

  // Write the data back to the file.
  g_file_set_contents(filename.c_str(), output.c_str(), -1, NULL);
}
示例#13
0
bool
OSOReaderToMaster::parse_file (const std::string &filename)
{
    m_master->m_osofilename = filename;
    m_master->m_maincodebegin = 0;
    m_master->m_maincodeend = 0;
    m_codesection.clear ();
    m_codesym = -1;
    return OSOReader::parse_file (filename) && ! m_errors;
}
示例#14
0
    Accents getAccentFromChar (ustring ch) {
        _size_t_ accent = VowelsWithAccents.find (ch.lowercase ());

        if (accent != ustring::npos)
            accent %= NUMBER_OF_ACCENTS;
        else
            accent = NO_ACCENT;

        return accent;
    }
示例#15
0
void bibleworks_define_parsing_person (ustring& parsing, ustring& definition)
// This looks in the "parsing" whether the person is given. 
// If so, it adds the description to the "definition" and removes the relevant code from the "parsing".
{
  ustring person = parsing.substr (0, 1);
  bool person_found = true;
  if (person == "1") {
    definition.append (" first person");
  } else if (person == "2") {
    definition.append (" second person");
  } else if (person == "3") {
    definition.append (" third person");
  } else {
    person_found = false;
  }
  if (person_found) {
    parsing.erase (0, 1);
  }
}
示例#16
0
bool
OSOReaderToMaster::parse_memory (const std::string &oso)
{
    m_master->m_osofilename = "<none>";
    m_master->m_maincodebegin = 0;
    m_master->m_maincodeend = 0;
    m_codesection.clear ();
    m_codesym = -1;
    return OSOReader::parse_memory (oso) && ! m_errors;
}
void
OSLCompilerImpl::warning (ustring filename, int line, const char *format, ...)
{
    va_list ap;
    va_start (ap, format);
    std::string errmsg = format ? OIIO::Strutil::vformat (format, ap) : "";
    fprintf (stderr, "%s:%d: warning: %s\n", 
             filename.c_str(), line, errmsg.c_str());
    va_end (ap);
}
示例#18
0
void CheckMatchingPairs::check_matched_pairs(ustring & text)
// Checks on matched pairs. Output any problems found.
{
  for (unsigned int i = 0; i < text.length(); i++) {
    // Get the unicode character;
    gunichar unichar;
    unichar = g_utf8_get_char(text.substr(i, 1).c_str());
    // If we found a mirror character, investigate further.
    gunichar mirror;
    if (g_unichar_get_mirror_char(unichar, &mirror)) {
      // Do we ignore this one?
      if (ignores.find(unichar) != ignores.end())
        continue;
      // See whether this one opens or closes a pair.
      if (gopeners.find(unichar) != gopeners.end()) {
        // It opens: Add data.
        MatchingPairOpener opener(text.substr(i, 1), unichar, book, chapter, verse, get_context(text, i));
        openers.push_back(opener);
        continue;
      } else {
        // It closes: check for previously seen opener.
        bool give_message = false;
        if (openers.empty()) {
          give_message = true;
        }
        if (!give_message) {
          if (openers[openers.size() - 1].unichar == mirror) {
            // Remove last one.
            openers.pop_back();
          } else {
            // Flag message.
            give_message = true;
          }
        }
        if (give_message) {
          // Give message;
          message(book, chapter, verse, _("Pair not opened: ") + get_context(text, i));
        }
      }
    }
  }
}
示例#19
0
void Kick(ServerConnection *conn, const ustring& params)
{
    if (params.empty()) {
        throw CommandException(_("/KICK <nick>, kick a user from a channel."));

    } else {
        ustring channel = AppWin->getNotebook().getCurrent()->getName();
        ustring param = channel + " " + params;
        Commands::Kick(conn, param);
    }
}
示例#20
0
	void Services::Filter::set_host(const ustring & host, PCWSTR user, PCWSTR pass)
	{
		LogNoise(L"host: '%s', user: '******'\n", host.c_str(), user);
		Base::shared_ptr<Ext::RemoteConnection> tmp_conn(new Ext::RemoteConnection(host, user, pass));
		Base::shared_ptr<Ext::Service::Manager> tmp_scm(new Ext::Service::Manager(tmp_conn.get(), SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE));
		m_writable = false;

		using std::swap;
		swap(m_scm, tmp_scm);
		swap(m_conn, tmp_conn);
	}
示例#21
0
ASTfunction_call::ASTfunction_call (OSLCompilerImpl *comp, ustring name,
                                    ASTNode *args)
    : ASTNode (function_call_node, comp, 0, args), m_name(name),
      m_argread(~1),      // Default - all args are read except the first
      m_argwrite(1),      // Default - first arg only is written by the op
      m_argtakesderivs(0) // Default - doesn't take derivs
{
    m_sym = comp->symtab().find (name);
    if (! m_sym) {
        error ("function '%s' was not declared in this scope", name.c_str());
        // FIXME -- would be fun to troll through the symtab and try to
        // find the things that almost matched and offer suggestions.
        return;
    }
    if (m_sym->symtype() != SymTypeFunction) {
        error ("'%s' is not a function", name.c_str());
        m_sym = NULL;
        return;
    }
}
示例#22
0
		bool ImplBunch::operator ()(const IStat& stat, Statistics& statistics) const
		{ // return true if skip this item
			LogConsoleDebug2(-1, L"   appply filter [%s, '%s'] on '%s'\n", to_str(type), name.c_str(), stat.name());

			bool matched = true;
			for (auto it = bunch.cbegin(); it != bunch.cend() && matched; ++it) {
				matched = (*it)->operator()(stat, statistics);
			}

			return (type == Type::IncludeOnly && !matched) || (type == Type::ExcludeAll && matched);
		}
示例#23
0
void StringList::loadFromFile(const ustring &fileName)
{
    clear();
    if(file_test(fileName, FILE_TEST_EXISTS)) {
        gchar *cont;
        gsize len;
        g_file_get_contents(fileName.c_str(), &cont, &len, NULL);
        loadFromChar(cont);
        g_free(cont);
    }
}
示例#24
0
	bool HttpBindIP::Assign(const ustring & ip, const ustring & port) {
		u_short	prt = htons(Str::as_uint32(port.c_str()));
		if (is_valid(ip) && prt) {
			sockaddr_in *tmp = (sockaddr_in*)pIpPort;
			tmp->sin_port		= prt;
			tmp->sin_addr.s_addr = inet_addr(utf8(ip).c_str());
			tmp->sin_family		= AF_INET;
			return true;
		}
		return false;
	}
示例#25
0
void Devoice(ServerConnection *conn, const ustring& params)
{
    if (params.empty()) {
        throw CommandException(_("/DEVOICE <nicks>, devoices one or more users in the current channel."));

    } else {
        ustring channel = AppWin->getNotebook().getCurrent()->getName();
        ustring param = channel + " " + params;
        Commands::Devoice(conn, param);
    }
}
示例#26
0
ASTvariable_ref::ASTvariable_ref (OSLCompilerImpl *comp, ustring name)
    : ASTNode (variable_ref_node, comp), m_name(name), m_sym(NULL)
{
    m_sym = comp->symtab().find (name);
    if (! m_sym) {
        error ("'%s' was not declared in this scope", name.c_str());
        // FIXME -- would be fun to troll through the symtab and try to
        // find the things that almost matched and offer suggestions.
        return;
    }
    m_typespec = m_sym->typespec();
}
示例#27
0
ReadFiles::ReadFiles(const ustring & path, const ustring & prefix, const ustring & suffix)
{
  // Reads the regular files in directory "path" that end on "suffix".
  // It does not return directories.
  try {
    GDir *dir = g_dir_open(path.c_str(), 0, NULL);
    const gchar *s;
    vector < ustring > entries;
    while ((s = g_dir_read_name(dir)) != NULL)
      entries.push_back(s);
    g_dir_close(dir);
    for (unsigned int i = 0; i < entries.size(); i++) {
      if (g_str_has_suffix(entries[i].c_str(), suffix.c_str()))
        if (g_str_has_prefix(entries[i].c_str(), prefix.c_str()))
          if (!g_file_test(gw_build_filename(path, entries[i]).c_str(), G_FILE_TEST_IS_DIR))
            files.push_back(entries[i]);
    }
  }
  catch(...) {
  }
}
示例#28
0
文件: mods.cpp 项目: deedrah/nervici
void Mods::scan_mods_dir (const ustring& path, vector<ustring>& files) {
    logger.fineln ("searching for mods in %s", path.c_str ());
    try {
        Dir dir (path);
        for (DirIterator it = dir.begin (); it != dir.end (); it++) {
            if ((*it)[0] == '.')
                continue;
            files.push_back (path + (*it));
        }
    } catch (FileError fe) {
    }
}
示例#29
0
文件: audio.cpp 项目: deedrah/nervici
void AudioOpenAL::scan_sounds_dir (const ustring& path, vector<char>& data) {
    ustring prof_path;
    ustring lower;
    size_t sound_count;

    logger.fineln ("searching %s for sounds", path.c_str ());
    try {
        Dir sound_dir (path);

        for (DirIterator sit = sound_dir.begin (); sit != sound_dir.end (); sit++) {
            if ((*sit)[0] == '.')
                continue;
            SoundProfileImpl* entry;

            prof_path = path + (*sit) + "/";

            entry = new SoundProfileImpl ();
            entry->name = *sit;
            entry->directory = prof_path;

            sound_count = 0;

            try {
                Dir prof_dir (prof_path);

                for (DirIterator pit = prof_dir.begin (); pit
                        != prof_dir.end (); pit++) {
                    if ((*pit)[0] == '.')
                        continue;
                    lower = ustring (*pit).lowercase ();

                    for (int eti = 0; eti < ET_Count; eti++) {
                        if (str_has_prefix (lower, efect_mask[eti])) {
                            sound_count += load_sound (entry, EffectType (eti),
                                    prof_path + (*pit), data);
                        }
                    }

                }

            } catch (FileError) {
            }

            if (sound_count > 0) {
                sound_profiles.push_back (entry);
            } else {
                delete entry;
            }
        }

    } catch (FileError) {
    }
}
示例#30
0
  ustring replace(ustring source, std::map<ustring,ustring>strMap, int offset, int times)
  {
    int total = 0;
    ustring::size_type pos;

    for (std::map<ustring, ustring>::iterator i=strMap.begin(); i!=strMap.end(); ++i)
      {
	ustring fromStr = i->first;
	ustring toStr = i->second;
	pos=offset;
	while ( (pos = source.find(fromStr, pos)) < Glib::ustring::npos)
	  {
	    if ( (times!=0) && (total++>=times) )
	      return source;	// Don't work anymore

	    source.replace(pos, fromStr.length(), toStr);
	    pos+=toStr.size();
	  }
      }
    return source;
  }