map < unsigned int, ustring > resource_get_books(const ustring & templatefile)
{
  map < unsigned int, ustring > books;
  GKeyFile *keyfile = g_key_file_new();
  if (g_key_file_load_from_file(keyfile, templatefile.c_str(), G_KEY_FILE_NONE, NULL)) {
    vector < unsigned int >ids = books_type_to_ids(btUnknown);
    for (unsigned int i = 0; i < ids.size(); i++) {
      ustring english_name = books_id_to_english(ids[i]);
      gchar *value;
      value = g_key_file_get_string(keyfile, resource_template_books_group(), english_name.c_str(), NULL);
      if (value) {
        books[i] = value;
        g_free(value);
      }
    }
    g_key_file_free(keyfile);
  }
  return books;
}
Exemple #2
0
ReadText::ReadText(const ustring & file, bool silent, bool trimming)
{
  // Reads the text and stores it line by line, trimmed, into "lines".
  // If "silent" is true, then no exception will be thrown in case of an error.
  // The lines will be trimmed if "trimming" is true.
  ifstream in(file.c_str());
  if (!in) {
    if (!silent) {
      cerr << _("Error opening file ") << file << endl;
      throw;
    }
    return;
  }
  string s;
  while (getline(in, s)) {
    if (trimming)
      s = trim(s);
    lines.push_back(s);
  }
}
 inline void operator() (ustring name, Dual2<R> &result, const Dual2<S> &s,
                         const S &sp,
                         ShaderGlobals *sg, const NoiseParams *opt) const {
     if (name == Strings::uperlin || name == Strings::noise) {
         PeriodicNoise noise;
         noise(result, s, sp);
     } else if (name == Strings::perlin || name == Strings::snoise) {
         PeriodicSNoise snoise;
         snoise(result, s, sp);
     } else if (name == Strings::cell) {
         PeriodicCellNoise cellnoise;
         cellnoise(result.val(), s.val(), sp);
         result.clear_d();
     } else if (name == Strings::gabor) {
         GaborPNoise gnoise;
         gnoise (name, result, s, sp, sg, opt);
     } else {
         ((ShadingContext *)sg->context)->error ("Unknown noise type \"%s\"", name.c_str());
     }
 }
void EditorActionChangeParagraphStyle::set_style (const ustring& style)
{
  // Define the work area.
  GtkTextIter startiter;
  gtk_text_buffer_get_start_iter (paragraph->textbuffer, &startiter);
  GtkTextIter enditer;
  gtk_text_buffer_get_end_iter (paragraph->textbuffer, &enditer);
  // Apply the style in such a way that the paragraph style is always applied first, 
  // then after that the character styles.
  vector <ustring> current_character_styles = get_character_styles_between_iterators (startiter, enditer);
  gtk_text_buffer_remove_all_tags (paragraph->textbuffer, &startiter, &enditer);
  gtk_text_buffer_apply_tag_by_name (paragraph->textbuffer, style.c_str(), &startiter, &enditer);
  for (unsigned int i = 0; i < current_character_styles.size(); i++) {
    if (!current_character_styles[i].empty()) {
      gtk_text_buffer_get_iter_at_offset (paragraph->textbuffer, &startiter, i);
      enditer = startiter;
      gtk_text_iter_forward_char (&enditer);
      gtk_text_buffer_apply_tag_by_name (paragraph->textbuffer, current_character_styles[i].c_str(), &startiter, &enditer);
    }
  }
}
YesNoAlwaysDialog::YesNoAlwaysDialog(const ustring& message, bool default_yes)
{
  gtkbuilder = gtk_builder_new ();
  gtk_builder_add_from_file (gtkbuilder, gw_build_filename (Directories->get_package_data(), "gtkbuilder.yesnoalwaysdialog.xml").c_str(), NULL);

  dialog = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "dialog"));

  label = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "label"));
  gtk_label_set_text (GTK_LABEL (label), message.c_str());

  checkbutton = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "checkbutton"));

  // Add the buttons. In the standard question dialog, the Yes is at the right, then the No following to the left.
  gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_NO, GTK_RESPONSE_NO);
  gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_YES, GTK_RESPONSE_YES);
  
  if (default_yes)
    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
  else
    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO);
}
Exemple #6
0
	bool WinGroups::cache_by_user(const ustring& name, const ustring& dom)
	{
		// Cache groups that contains USER "name".
		const DWORD dwLevel = 0, dwPrefMaxLen = MAX_PREFERRED_LENGTH, dwFlags = LG_INCLUDE_INDIRECT;
		DWORD dwEntriesRead = 0, dwTotalEntries = 0;
		NET_API_STATUS nStatus;
		clear();
		m_dom = dom;
		LPGROUP_USERS_INFO_0 info = nullptr;
		nStatus = ::NetUserGetLocalGroups(m_dom.c_str(), name.c_str(), dwLevel, dwFlags, (PBYTE*)&info, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries);
		if (nStatus == NERR_Success || nStatus == ERROR_MORE_DATA) {
			for (DWORD i = 0; i < dwEntriesRead; ++i) {
				GroupInfo gtmp;
				gtmp.name = info[i].grui0_name;
				gtmp.comm = Group::get_comm(info[i].grui0_name);
				push_back(gtmp);
			}
			::NetApiBufferFree(info);
		}
		return (NERR_Success == nStatus);
	}
Exemple #7
0
bool windowsoutpost_telnet(const ustring & hostname)
// This makes a connection with the Outpost on "host" and then disconnects again.
// It returns true if this worked out.
{
  bool success = false;
  struct sockaddr_in address;
  struct hostent *host;
  int sock;
  host = gethostbyname(hostname.c_str());
  if (host) {
#ifdef WIN32
    if ((sock = socket(PF_INET, SOCK_STREAM, 0)) != SOCKET_ERROR)
#else
    if ((sock = socket(PF_INET, SOCK_STREAM, 0)) >= 0)
#endif
    {
      address.sin_family = AF_INET;
      memcpy(&address.sin_addr, host->h_addr_list[0], sizeof(address.sin_addr));
#ifdef WIN32
      WSAHtons(sock, 51515, &address.sin_port);
      if (connect(sock, (struct sockaddr *)&address, sizeof(address)) == SOCKET_ERROR)
#else
      address.sin_port = htons(51515);
      if (connect(sock, (struct sockaddr *)&address, sizeof(address)))
#endif
      {
        ; // success = false;
      } else {
        success = true;
      }
#ifdef WIN32
      closesocket(sock);
#else
      close(sock);
#endif
    }
  }
  return success;
}
Exemple #8
0
void AudioOpenAL::scan_music_dir (const ustring& path,
        vector<MusicFile>& files, MusicType type) {
    double len;
    ustring file_path;
    MusicFile entry;

    logger.fineln ("searching %s for music files", path.c_str ());
    try {

        Dir dir (path);

        for (DirIterator it = dir.begin (); it != dir.end (); it++) {
            if ((*it)[0] == '.')
                continue;

            file_path = path + (*it);

            MplayerDecoder dec;
            len = dec.get_length (file_path);

            if (len <= 0)
                continue;
            if (type == MT_GameShort && len > 150) {
                continue;
            }
            if (type == MT_GameLong && len <= 150) {
                continue;
            }

            logger.fineln ("found music file %s", file_path.c_str ());
            entry.filename = file_path;
            entry.played = false;
            files.push_back (entry);
        }

    } catch (FileError) {
    }
}
std::string
OSLCompilerImpl::retrieve_source (ustring filename, int line)
{
    // If we don't already have the file open, open it
    if (filename != m_last_sourcefile) {
        // If we have another file open, close that one
        if (m_sourcefile)
            fclose (m_sourcefile);
        m_last_sourcefile = filename;
        m_sourcefile = fopen (filename.c_str(), "r");
        if (! m_sourcefile) {
            m_last_sourcefile = ustring();
            return "<not found>";
        }
    }

    // If we want something *before* the last line read in the open file,
    // rewind to the beginning.
    if (m_last_sourceline > line) {
        rewind (m_sourcefile);
        m_last_sourceline = 0;
    }

    // Now read lines up to and including the file we want.
    char buf[10240];
    while (m_last_sourceline < line) {
        if (fgets (buf, sizeof(buf), m_sourcefile))
            ++m_last_sourceline;
        else
            break;
    }

    // strip trailing newline
    if (buf[strlen(buf)-1] == '\n')
        buf[strlen(buf)-1] = '\0';

    return std::string (buf);
}
Exemple #10
0
	bool WinUsers::cache_by_group(const ustring& group, const ustring& dom) {
		// Cache members of group "name".
		const DWORD dwLevel = 1, dwPrefMaxLen = MAX_PREFERRED_LENGTH;
		DWORD dwEntriesRead = 0, dwTotalEntries = 0;
		ULONG_PTR dwResumeHandle = 0;
		NET_API_STATUS nStatus;
		clear();
		m_group = group;
		m_dom = dom;
		do {
			PLOCALGROUP_MEMBERS_INFO_1 info = nullptr;
			nStatus = ::NetLocalGroupGetMembers(m_dom.c_str(), group.c_str(), dwLevel, (PBYTE*) &info,
			                                    dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, &dwResumeHandle);
			if (NERR_Success == nStatus || ERROR_MORE_DATA == nStatus) {
				PLOCALGROUP_MEMBERS_INFO_1 ptr = info;
				for (DWORD i = 0; i < dwEntriesRead && ptr; ++i, ++ptr) {
					push_back(UserInfo(UserBuf(ptr->lgrmi1_name).data()));
				}
				::NetApiBufferFree(info);
			}
		} while (ERROR_MORE_DATA == nStatus);
		return (NERR_Success == nStatus);
	}
ustring CheckMatchingPairs::get_context(ustring & line, unsigned int offset)
// Returns the context at offset: A couple of words before and after.
{
  // Result.
  ustring returnvalue;
  // Load text into buffer.
  GtkTextBuffer *textbuffer;
  textbuffer = gtk_text_buffer_new(NULL);
  gtk_text_buffer_set_text(textbuffer, line.c_str(), -1);
  // Iterators.  
  GtkTextIter iter1;
  GtkTextIter iter2;
  // Find boundaries of context to return.
  gtk_text_buffer_get_iter_at_offset(textbuffer, &iter1, offset);
  iter2 = iter1;
  gtk_text_iter_backward_word_starts(&iter1, 2);
  gtk_text_iter_forward_word_ends(&iter2, 2);
  return gtk_text_iter_get_text(&iter1, &iter2);
  // Free memory
  g_object_unref(textbuffer);
  // Give us the result.
  return returnvalue;
}
Exemple #12
0
bool ColorSpaceManager::colorspace_is_data(ustring colorspace)
{
  if (colorspace == u_colorspace_auto || colorspace == u_colorspace_raw ||
      colorspace == u_colorspace_srgb) {
    return false;
  }

#ifdef WITH_OCIO
  OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
  if (!config) {
    return false;
  }

  try {
    OCIO::ConstColorSpaceRcPtr space = config->getColorSpace(colorspace.c_str());
    return space && space->isData();
  }
  catch (OCIO::Exception &) {
    return false;
  }
#else
  return false;
#endif
}
Exemple #13
0
bool mechon_mamre_copyright(const ustring & inputfile)
// Returns true is a file has "Copyright" and "Mechon Mamre" in it.
{
  // Read the file.
  gchar *contents;
  gsize length;
  GError *error = NULL;
  if (!g_file_get_contents(inputfile.c_str(), &contents, &length, &error)) {
    gw_critical(error->message);
    g_error_free(error);
    return false;
  }
  // Search for the signature.
  char *mechonmamre = g_strstr_len(contents, 400, _("Mechon Mamre"));
  if (mechonmamre) {
    mechonmamre = g_strstr_len(contents, 400, _("Copyright"));
  }
  // Free memory and return result.
  g_free(contents);
  if (mechonmamre)
    return true;
  else
    return false;
}
int
RendererServices::pointcloud_search (ShaderGlobals *sg,
                                     ustring filename, const OSL::Vec3 &center,
                                     float radius, int max_points, bool sort,
                                     size_t *out_indices,
                                     float *out_distances, int derivs_offset)
{
#if USE_PARTIO
    if (! filename)
        return 0;
    PointCloud *pc = PointCloud::get(filename);
    if (pc == NULL) { // The file failed to load
        sg->context->shadingsys().error ("pointcloud_search: could not open \"%s\"", filename.c_str());
        return 0;
    }
    spin_lock lock (pc->m_mutex);
    Partio::ParticlesDataMutable *cloud = pc->m_partio_cloud;
    if (cloud == NULL) { // The file failed to load
        sg->context->shadingsys().error ("pointcloud_search: could not open \"%s\"", filename.c_str());
        return 0;
    }

    // Early exit if the pointcloud contains no particles.
    if (cloud->numParticles() == 0)
       return 0;

    // If we need derivs of the distances, we'll need access to the 
    // found point's positions.
    Partio::ParticleAttribute *pos_attr = NULL;
    if (derivs_offset) {
        pos_attr = pc->m_attributes[u_position].get();
        if (! pos_attr)
            return 0;   // No "position" attribute -- fail
    }

    ASSERT (sizeof(size_t) == sizeof(Partio::ParticleIndex) &&
            "Only will work if Partio ParticleIndex is the size of a size_t");
    // FIXME -- if anybody cares about an architecture in which that is not
    // the case, we can easily allocate local space to retrieve the indices,
    // then copy them back to the caller's indices.

    Partio::ParticleIndex *indices = (Partio::ParticleIndex *)out_indices;
    float *dist2 = out_distances;
    if (! dist2)  // If not supplied, allocate our own
        dist2 = (float *)sg->context->alloc_scratch (max_points*sizeof(float), sizeof(float));

    float finalRadius;
    int count = cloud->findNPoints (&center[0], max_points, radius,
                                    indices, dist2, &finalRadius);

    // If sorting, allocate some temp space and sort the distances and
    // indices at the same time.
    if (sort && count > 1) {
        SortedPointRecord *sorted = (SortedPointRecord *) sg->context->alloc_scratch (count * sizeof(SortedPointRecord), sizeof(SortedPointRecord));
        for (int i = 0;  i < count;  ++i)
            sorted[i] = SortedPointRecord (dist2[i], indices[i]);
        std::sort (sorted, sorted+count, SortedPointCompare());
        for (int i = 0;  i < count;  ++i) {
            dist2[i] = sorted[i].first;
            indices[i] = sorted[i].second;
        }
    }

    if (out_distances) {
        // Convert the squared distances to straight distances
        for (int i = 0; i < count; ++i)
            out_distances[i] = sqrtf(dist2[i]);

        if (derivs_offset) {
            // We are going to need the positions if we need to compute
            // distance derivs
            OSL::Vec3 *positions = (OSL::Vec3 *) sg->context->alloc_scratch (sizeof(OSL::Vec3) * count, sizeof(float));
            cloud->data (*pos_attr, count, indices, true, (void *)positions);
            const OSL::Vec3 &dCdx = (&center)[1];
            const OSL::Vec3 &dCdy = (&center)[2];
            float *d_distance_dx = out_distances + derivs_offset;
            float *d_distance_dy = out_distances + derivs_offset * 2;
            for (int i = 0; i < count; ++i) {
                d_distance_dx[i] = 1.0f / out_distances[i] *
                                        ((center.x - positions[i].x) * dCdx.x +
                                         (center.y - positions[i].y) * dCdx.y +
                                         (center.z - positions[i].z) * dCdx.z);
                d_distance_dy[i] = 1.0f / out_distances[i] *
                                        ((center.x - positions[i].x) * dCdy.x +
                                         (center.y - positions[i].y) * dCdy.y +
                                         (center.z - positions[i].z) * dCdy.z);
            }
        }
    }
    return count;
#else
    return 0;
#endif
}
Exemple #15
0
		HANDLE Facade::Open(const ustring& path, ACCESS_MASK access, DWORD share, PSECURITY_ATTRIBUTES sa, DWORD creat, DWORD flags)
		{
//			LogTrace(L"'%s', 0x%08X, 0x%08X, %p\n", path.c_str(), access, share, sa);
			return CheckHandleErr(::CreateFileW(path.c_str(), access, share, sa, creat, flags, nullptr));
		}
Exemple #16
0
bool search_in_bibledit_word_boundaries_match(const ustring & text, const ustring & searchword, bool matchbeginning, bool matchending, bool globbing)
// Does the word boundary matching.
{
  /*
     Deal with matching the start of a word and/or of the end.

     There are four cases here.
     1. Match word start only.
     2. Match word end only.
     3. Both match start end end of a word, which implies "whole word".
     4. No matching at all.

     Boundary resolution is handled by pango_break(). Textual boundaries such 
     as word boundaries and line boundaries are determined for each item.
     In most cases a general algorithm suffices for this process, but in some
     cases a language module will override the generic algorithm with a more
     specific one.
     It seems to be easier programming to use GtkTextIter and GtkTextBuffer,
     rather than pango_break() directly.
   */

  // Whether the word matches.
  bool match = false;

  // Textbuffer for determining word boundaries.
  GtkTextBuffer *textbuffer = gtk_text_buffer_new(NULL);
  gtk_text_buffer_set_text(textbuffer, text.c_str(), -1);

  // Iterators needed.
  GtkTextIter startiter;
  GtkTextIter enditer;

  // Store segments of text to compare against.
  vector < ustring > segments;

  // Deal with case one: Match word start only.  
  if (matchbeginning && !matchending) {
    // Create a patternword for the glob-style pattern matching.
    ustring patternword = searchword + "*";
    // Collect all strings starting with a word.
    gtk_text_buffer_get_start_iter(textbuffer, &startiter);
    gtk_text_buffer_get_end_iter(textbuffer, &enditer);
    while (gtk_text_iter_forward_word_end(&startiter)) {
      gtk_text_iter_backward_word_start(&startiter);
      segments.push_back(gtk_text_iter_get_text(&startiter, &enditer));
      gtk_text_iter_forward_word_end(&startiter);
    }
    // See whether the word is in it.
    for (unsigned int i2 = 0; i2 < segments.size(); i2++) {
      if (globbing) {
        // Glob-style pattern matching.
        if (g_pattern_match_simple(patternword.c_str(), segments[i2].c_str())) {
          match = true;
          break;
        }
      } else {
        // Straight compare.
        if (segments[i2].find(searchword) == 0) {
          match = true;
          break;
        }
      }
    }
  }
  // Deal with case two: Match word end only.  
  if (!matchbeginning && matchending) {
    // Create a patternword for the glob-style pattern matching.
    ustring patternword = "*" + searchword;
    // Collect all strings ending with a word.
    gtk_text_buffer_get_start_iter(textbuffer, &startiter);
    gtk_text_buffer_get_start_iter(textbuffer, &enditer);
    while (gtk_text_iter_forward_word_end(&enditer)) {
      segments.push_back(gtk_text_iter_get_text(&startiter, &enditer));
    }
    // See whether the word is in it.
    for (unsigned int i2 = 0; i2 < segments.size(); i2++) {
      if (globbing) {
        // Glob-style pattern matching.
        if (g_pattern_match_simple(patternword.c_str(), segments[i2].c_str())) {
          match = true;
          break;
        }
      } else {
        // Straight compare.
        size_t matchposition;
        matchposition = segments[i2].length() - searchword.length();
        // Negative match positions cause a false match. Solve that here.
        matchposition = CLAMP(matchposition, 0, 99999999);
        if (segments[i2].find(searchword) == matchposition) {
          match = true;
          break;
        }
      }
    }
  }
  // Deal with case three: Match both word start and end.  
  // Interpreted as "match whole word".
  if (matchbeginning && matchending) {
    // Create a patternword for the glob-style pattern matching.
    ustring patternword = searchword;
    // Collect all whole words.
    gtk_text_buffer_get_start_iter(textbuffer, &enditer);
    while (gtk_text_iter_forward_word_end(&enditer)) {
      startiter = enditer;
      gtk_text_iter_backward_word_start(&startiter);
      segments.push_back(gtk_text_iter_get_text(&startiter, &enditer));
    }
    // See whether the word is in it.
    for (unsigned int i2 = 0; i2 < segments.size(); i2++) {
      if (globbing) {
        // Glob-style pattern matching.
        if (g_pattern_match_simple(patternword.c_str(), segments[i2].c_str())) {
          match = true;
          break;
        }
      } else {
        // Straight compare.
        if (segments[i2] == searchword) {
          match = true;
          break;
        }
      }
    }
  }
  // Case four: Nothing to test, so set found to true.
  if (!matchbeginning && !matchending)
    match = true;

  // Free memory.
  g_object_unref(textbuffer);

  // Return whether match.
  return match;
}
Exemple #17
0
void LuaInstance::pushStack( const ustring& value ) {
    pushStack( value.c_str() );
}
Exemple #18
0
	Node node(const ustring& name)
	{
		LogTrace2(L"('%s')", name.c_str());
		return simstd::make_shared<ImplNodeEx>(name);
	}
Exemple #19
0
 bool operator < ( const DebugResult &rhs ) const
 {
     return name.c_str() < rhs.name.c_str();
 }
Exemple #20
0
	void User::set_script(const ustring& name, const ustring& in, const ustring& dom) {
		const DWORD level = 1009;
		USER_INFO_1009 info;
		info.usri1009_script_path = const_cast<PWSTR>(in.c_str());
		set_info(name, dom, level, &info);
	}
Exemple #21
0
	void WinUsers::add(const ustring& name, const ustring& pass) {
		User::add(name, pass);
		push_back(UserInfo(UserBuf(name).data()));
		if (!m_group.empty())
			Group::add_member(m_group, Sid(name.c_str()));
	}
Exemple #22
0
		void set(const ustring& name, const ustring& dom = ustring()) {
			CheckApiError(::NetUserSetInfo(dom.c_str(), name.c_str(), 3, (PBYTE)info, nullptr));
		}
int
RendererServices::pointcloud_get (ShaderGlobals *sg,
                                  ustring filename, size_t *indices, int count,
                                  ustring attr_name, TypeDesc attr_type,
                                  void *out_data)
{
#if USE_PARTIO
    if (! count)
        return 1;  // always succeed if not asking for any data

    PointCloud *pc = PointCloud::get(filename);
    if (pc == NULL) { // The file failed to load
        sg->context->shadingsys().error ("pointcloud_get: could not open \"%s\"", filename.c_str());
        return 0;
    }
    spin_lock lock (pc->m_mutex);
    Partio::ParticlesDataMutable *cloud = pc->m_partio_cloud;
    if (cloud == NULL) { // The file failed to load
        sg->context->shadingsys().error ("pointcloud_get: could not open \"%s\"", filename.c_str());
        return 0;
    }

    // lookup the ParticleAttribute pointer needed for a query
    Partio::ParticleAttribute *attr = pc->m_attributes[attr_name].get();
    if (! attr) {
        sg->context->shadingsys().error ("Accessing unexisting attribute %s in pointcloud \"%s\"", attr_name.c_str(), filename.c_str());
        return 0;
    }

    // Now make sure that types are compatible
    TypeDesc element_type = attr_type.elementtype ();
    int attr_partio_type = 0;

    // Convert the OSL (OIIO) type to the equivalent Partio type
    if (element_type == TypeDesc::TypeFloat)
        attr_partio_type = Partio::FLOAT;
    else if (element_type == TypeDesc::TypeInt)
        attr_partio_type = Partio::INT;
    else if (element_type == TypeDesc::TypeColor  || element_type == TypeDesc::TypePoint ||
             element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal)
        attr_partio_type = Partio::VECTOR;
    else {
        // error ("Unsupported attribute type %s for pointcloud query in attribute %s",
        //       element_type.c_str(), attr_name.c_str());
        return 0;
    }

    // Finally check for some equivalent types like float3 and vector
    if (!compatiblePartioType(attr, attr_partio_type)) {
        sg->context->shadingsys().error ("Type of attribute \"%s\" : %s[%d] not compatible with OSL's %s in \"%s\" pointcloud",
                    attr_name.c_str(), partioTypeString(attr), attr->count,
                    element_type.c_str(), filename.c_str());
        return 0;
    }

    ASSERT (sizeof(size_t) == sizeof(Partio::ParticleIndex) &&
            "Only will work if Partio ParticleIndex is the size of a size_t");
    // FIXME -- if anybody cares about an architecture in which that is not
    // the case, we can easily allocate local space to retrieve the indices,
    // then copy them back to the caller's indices.

    // Actual data query
    cloud->data (*attr, count, (Partio::ParticleIndex *)indices,
                 true, out_data);
    return 1;
#else
    return 0;
#endif
}
Exemple #24
0
 bool operator < ( const ustring &rhs ) const
 {
     return name.c_str() < rhs.c_str();
 }
Exemple #25
0
	const wchar_t* ImplNodeEx::name() const noexcept
	{
		return name_.c_str();
	}
Exemple #26
0
void WebkitBrowser::go_to(const ustring & url)
{
  webkit_web_view_open (WEBKIT_WEB_VIEW(webview), url.c_str());
}
Exemple #27
0
	Node node(const ustring& name, const Node& parent)
	{
		LogTrace2(L"('%s', '%s')", name.c_str(), parent ? parent->name() : L"");
		return simstd::make_shared<ImplNodeEx>(name, parent);
	}
Exemple #28
0
		UserBuf(const ustring& name, const ustring& dom = ustring()) {
			CheckApiError(::NetUserGetInfo(dom.c_str(), name.c_str(), 3, (PBYTE*)&info));
		}
Exemple #29
0
ustring script_filter(const ustring & scriptname, bool straightthrough, const ustring & inputfile, const ustring & outputfile)
/*
 Runs the filter "scriptname".
 Input text in "inputfile", and the output text goes in "outputfile".
 If everything is okay, it returns nothing.
 If there were errors, it returns these.
 */
{
  // Remove any previous output.
  unlink(outputfile.c_str());
  unlink(script_temporal_error_file().c_str());

  // Handle straight through.
  if (straightthrough) {
    unix_cp(inputfile, outputfile);
    return "";
  }
  // Get the filename and the type of the script.
  ScriptType scripttype;
  ustring scriptfile = script_get_path(scriptname, &scripttype, true);

  // If the rules file does not exist, or the script is of an unknown type, pass it straight through.
  if (!g_file_test(scriptfile.c_str(), G_FILE_TEST_IS_REGULAR) || (scripttype == stEnd)) {
    unix_cp(inputfile, outputfile);
    gw_warning(_("Error in script ") + scriptname);
    return "";
  }
  // Encode the input usfm file.
  ustring encodedinputfile = script_temporal_input_file();
  if (inputfile != encodedinputfile) {
    unix_cp(inputfile, encodedinputfile);
  }
  script_encode_usfm_file(encodedinputfile);

  // Run filter.
  ustring command;
  ustring error;
  switch (scripttype) {
  case stSed:
    {
      command.append(script_sed_binary());
      command.append(" -f");
      command.append(shell_quote_space(scriptfile));
      command.append("<");
      command.append(shell_quote_space(encodedinputfile));
      command.append(">");
      command.append(shell_quote_space(outputfile));
      break;
    }
  case stTECkit:
    {
      command.append(script_teckit_txtconverter());
      command.append(" -i");
      command.append(shell_quote_space(encodedinputfile));
      command.append(" -o");
      command.append(shell_quote_space(outputfile));
      command.append(" -t");
      command.append(shell_quote_space(scriptfile));
      command.append(" -nobom");
      break;
    }
  case stFree:
    {
      // Text of the script.
      ustring scriptdata;
      {
        // Read script.
        gchar *contents;
        g_file_get_contents(scriptfile.c_str(), &contents, NULL, NULL);
        if (contents) {
          scriptdata = contents;
          g_free(contents);
        } else {
          error = _("Can't read script file");
          gw_warning(error);
          return error;
        }
      }
      // Check for and insert the input filename.
      if (scriptdata.find(script_free_input_identifier()) == string::npos) {
        error = _("Can't find where to put input file");
        gw_warning(error);
        return error;
      }
      replace_text(scriptdata, script_free_input_identifier(), shell_quote_space(encodedinputfile));
      // Check for and insert the output filename.
      if (scriptdata.find(script_free_output_identifier()) == string::npos) {
        error = _("Can't find where to put output file");
        gw_warning(error);
        return error;
      }
      replace_text(scriptdata, script_free_output_identifier(), shell_quote_space(outputfile));
      // Write temporal script.
      g_file_set_contents(script_temporal_script_file().c_str(), scriptdata.c_str(), -1, NULL);
      // Assemble command to run.
      command.append("sh");
      command.append(shell_quote_space(script_temporal_script_file()));
      break;
    }
  case stEnd:
    {
      break;
    }
  }

  // Add the error file to the command, and run it.
  command.append(" 2> ");
  command.append(script_temporal_error_file());
  int result = system(command.c_str()); // This one is too unpredictable to be used with GwSpawn.

  // The filters are so much beyond any control that we never can be sure that 
  // their output is in the UTF-8 encoding.
  // Sed would give UTF-8, but as TECkit can also give legacy encodings.
  // We can't know what free scripts will do, it could be anything.
  // So here check the UTF-8 encoding. 
  // If UTF-8 validation fails, we copy the input straight to the output.
  {
    gchar *contents;
    g_file_get_contents(outputfile.c_str(), &contents, NULL, NULL);
    if (contents) {
      if (!g_utf8_validate(contents, -1, NULL)) {
        unix_cp(inputfile, outputfile);
        error = _("UTF-8 validation failure");
        gw_warning(error);
      }
      g_free(contents);
      if (!error.empty())
        return error;
    }
  }

  // Decode the output file.
  script_decode_usfm_file(outputfile);

  // Handle OK.
  if (result == 0)
    return "";

  // Handle error.
  gchar *contents;
  g_file_get_contents(script_temporal_error_file().c_str(), &contents, NULL, NULL);
  if (contents) {
    error = contents;
    g_free(contents);
    gw_warning(error);
  }
  return error;
}
Exemple #30
0
 bool operator < ( const UserData &rhs ) const
 {
     return name.c_str() < rhs.name.c_str();
 }