Exemplo n.º 1
0
/* ---------------------------------------------------------------------
 * Callback when the menu item is clicked.
 * ---------------------------------------------------------------------
 */
static void
menu_item_activate(guint key_id)
{
	GtkWidget* dialog;
	GtkWidget* dialog_new = NULL;
	GtkWidget* dialog_entry;
	GtkTreeModel* completion_list;
	GeanyDocument* current_doc = document_get_current();
	gchar *chosen_path;
	const gchar *chosen_file;
	gint response;

	log_func();

	if(current_doc == NULL || current_doc->file_name == NULL || current_doc->file_name[0] == '\0')
		return;
		
	/* Build current directory listing */
	directory_ref = g_path_get_dirname(current_doc->file_name);
	completion_list = build_file_list(directory_ref, "");

	/* Create the user dialog and get response */
	dialog_entry = create_dialog(&dialog, completion_list);
	response = gtk_dialog_run(GTK_DIALOG(dialog));

	/* Filename */
	chosen_file = gtk_entry_get_text(GTK_ENTRY(dialog_entry));
	/* Path + Filename */
	chosen_path = g_build_filename(directory_ref, chosen_file, NULL);

	if ( response == GTK_RESPONSE_ACCEPT )
	{
		log_debug("Trying to open: %s", chosen_path);
		if ( ! g_file_test(chosen_path, G_FILE_TEST_EXISTS) )
		{
			log_debug("File not found.");

			dialog_new = gtk_message_dialog_new(GTK_WINDOW(geany_data->main_widgets->window),
													GTK_DIALOG_MODAL,
													GTK_MESSAGE_QUESTION,
													GTK_BUTTONS_OK_CANCEL,
													_("%s not found, create it?"), chosen_file);
			gtk_window_set_title(GTK_WINDOW(dialog_new), "Geany");
			if(gtk_dialog_run(GTK_DIALOG(dialog_new)) == GTK_RESPONSE_OK)
			{
				document_new_file(chosen_path, current_doc->file_type, NULL);
				document_set_text_changed(document_get_current(), TRUE);
			}
			gtk_widget_destroy(dialog_new);
		}
		else
			document_open_file(chosen_path, FALSE, NULL, NULL);
	}

	/* Freeing memory */
	gtk_widget_destroy(dialog);
	g_free(directory_ref);
	g_object_unref (completion_list);
}
Exemplo n.º 2
0
/**
 * @brief Called by Geany before unloading the plugin
 * @param void 
 * @return void
 * 
 */
void plugin_cleanup(void)
{
	log_func();

	/* Cleanup the features */
	goto_file_cleanup();
	switch_head_impl_cleanup();
}
Exemplo n.º 3
0
/* ---------------------------------------------------------------------
 * Called by Geany to initialize the plugin.
 * Note: data is the same as geany_data.
 * ---------------------------------------------------------------------
 */
void plugin_init(GeanyData *data)
{
	log_func();

	/* Initialize the features */
	switch_head_impl_init();
	goto_file_init();
}
Exemplo n.º 4
0
Conn::callbacks_map_type::iterator Conn::invokeCallback(Conn::callbacks_map_type::iterator &it, RequestResult &&req_res) try {
	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u invokeCallback sync=%u res.code=%u", ep.address().to_string().c_str(), ep.port(), it->first, req_res.code);

	callbacks_map_type::iterator ret_it;
	auto timer_and_cb = std::move(it->second); //Move to reduce inc/dec of shared_ptrs
	ret_it = callbacks_map.erase(it);
	if( likely(timer_and_cb.first && req_res.code!=CB_TIMEOUT) )
		timer_and_cb.first->cancel();

	if( likely(timer_and_cb.second) )
		//Post in separate job to avoid call in current coroutine and/or other shitty accidents
		io.post( boost::bind(std::move(timer_and_cb.second), std::forward<RequestResult>(req_res)) );
	return ret_it;
} catch(std::exception &e) {
	log_func("[iproto_conn] %s:%u invokeCallback uncatched exception: %s", ep.address().to_string().c_str(), ep.port(), e.what() );
	abort(); //It's your guilt
}
Exemplo n.º 5
0
void Conn::dismissCallbacks(CB_Result res) {
	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u dismissCallbacks", ep.address().to_string().c_str(), ep.port());
	ping_timer.cancel();
	for(auto it=callbacks_map.begin(); it!=callbacks_map.end(); ) {
		it = invokeCallback(it, RequestResult(res));
	}
	callbacks_map.clear();
}
Exemplo n.º 6
0
bool Conn::GentleShutdown() {
	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u GentleShutdown", ep.address().to_string().c_str(), ep.port());

	if( callbacks_map.empty() && !write_is_active ) {
		Shutdown();
		return true;
	}
	return false;
}
Exemplo n.º 7
0
bool Conn::Write(Packet &&pkt, callbacks_func_type &&cb) {
	auto timer = std::make_shared< boost::asio::deadline_timer >(io);
	timer->expires_from_now( boost::posix_time::milliseconds(read_timeout) );
	timer->async_wait( boost::bind(&Conn::onTimeout, shared_from_this(), boost::asio::placeholders::error, pkt.hdr.sync, timer) );

	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u: sending packet sync=%u", ep.address().to_string().c_str(), ep.port(), pkt.hdr.sync);
	callbacks_map[pkt.hdr.sync] = std::make_pair(std::move(timer), std::forward<callbacks_func_type>(cb));
	return dropPacketWrite( std::forward<Packet>(pkt) );
}
Exemplo n.º 8
0
/**
 * @brief Called by Geany to initialize the plugin.
 * @note data is the same as geany_data.
 */
void plugin_init(GeanyData *data)
{
	log_func();

	/* Load configuration */
	load_configuration();
	/* Initialize the features */
	switch_head_impl_init();
	goto_file_init();
}
Exemplo n.º 9
0
void Conn::beginConnect() {
	write_is_active=false;
	ping_timer.cancel();
	//Limit connection time
	timer.expires_from_now( boost::posix_time::milliseconds(connect_timeout) );
	timer.async_wait( boost::bind(&Conn::reconnectByTimer, shared_from_this(), boost::asio::placeholders::error) );

	sock.async_connect( ep, boost::bind(&Conn::onConnect, shared_from_this(), boost::asio::placeholders::error) );
	if( LOG_DEBUG )
		log_func("[iproto_conn] Connecting to %s:%d", ep.address().to_string().c_str(), ep.port() );
}
Exemplo n.º 10
0
void Conn::pingCb(RequestResult res) {
	if( unlikely(res.code != CB_OK) ) {
		//Reconnect
		log_func("[iproto_conn] %s:%u ping failed, code %u", ep.address().to_string().c_str(), ep.port(), res.code);
		if( res.code == CB_TIMEOUT ) {
			reconnect();
			return;
		}
	}
	ping_timer.expires_from_now( boost::posix_time::milliseconds(300) );
	ping_timer.async_wait( boost::bind(&Conn::setupPing, shared_from_this(), boost::asio::placeholders::error) );
}
Exemplo n.º 11
0
static int log_add(IL_FUNCTION_T func, char* data, int len, char* fmt)
{
  #define MAXSTR 500
  char str[MAXSTR+1];
  int strlen, nbytes;
  char prefix[50];
  unsigned long  j;
  static unsigned long jstart = 0;

  if(jstart == 0)
	jstart = jiffies;

  j = jiffies - jstart;
  sprintf(prefix, "%04lu.%02lu %s", (j / HZ), (j % HZ), fmt);
  
  strlen = log_func(str, func, data, len, prefix);
  sprintf(str + strlen, "\n");
  strlen += 1;
  //  delay_msec(1);
  VC_PRINTK( IlcsTrace, "%s", str );
  //  printk(KERN_ERR"%s", str);   
  
  if(down_interruptible(&vc_ilcsg.omxlog_lock))
	return -1;

  nbytes = min(VC03_OMXLOG_MAX - vc_ilcsg.omxlog_windex, strlen);
  memcpy(vc_ilcsg.omxlog + vc_ilcsg.omxlog_windex, str, nbytes);

  if(vc_ilcsg.omxlog_windex < vc_ilcsg.omxlog_rindex)
	{
	  vc_ilcsg.omxlog_windex += nbytes;
	  if(vc_ilcsg.omxlog_windex >= (vc_ilcsg.omxlog_rindex - 1))		
		{
		  vc_ilcsg.omxlog_rindex = (vc_ilcsg.omxlog_windex + 1) % VC03_OMXLOG_MAX;
		}
	}
  else
	{	  
	  vc_ilcsg.omxlog_windex += nbytes;
	}
  
  if(nbytes < strlen)
	{
	  vc_assert(vc_ilcsg.omxlog_windex >= VC03_OMXLOG_MAX);
	  memcpy(vc_ilcsg.omxlog + 0, str + nbytes, strlen - nbytes);
	  vc_ilcsg.omxlog_windex = strlen - nbytes;
	  vc_ilcsg.omxlog_rindex = max(vc_ilcsg.omxlog_rindex, vc_ilcsg.omxlog_windex + 1);
	}
  
  up(&vc_ilcsg.omxlog_lock);
  return 0;
}
Exemplo n.º 12
0
bool Conn::dropPacketWrite(Packet &&pkt) {
	write_queue.push_back( pkt.data );
	pkt.data=nullptr;
	write_queue_len++;

	if( unlikely(checkConnect()) ) {
		log_func("[iproto_conn] %s:%u dropPacketWrite deferred (no connect)", ep.address().to_string().c_str(), ep.port());
		return false;
	}

	ensureWriteBuffer( boost::system::error_code() );
	return true;
}
/**
  * @brief  This is the code that gets called when the processor receives an 
  *         unexpected interrupt.  This simply enters an infinite loop, 
  *         preserving the system state for examination by a debugger.
  * @param  None
  * @retval None  
  */
static void Default_Handler(void)
{
  /* Go into an infinite loop. */
	int i;

	static char buffer[64];
	snprintf(buffer, 64,"SOMETHING WRONG IN TASK: %s \r\n", pcTaskGetTaskName(NULL) );
	log_func(buffer);
	for( ;; );
  while (1)
  {

  }
}
Exemplo n.º 14
0
/* this function will output a message using the
 * caller provided function
 */
void
_gnutls_log (int level, const char *fmt, ...)
{
  va_list args;
  char str[MAX_LOG_SIZE];
  void (*log_func) (int, const char *) = _gnutls_log_func;

  if (_gnutls_log_func == NULL)
    return;

  va_start (args, fmt);
  vsnprintf (str, MAX_LOG_SIZE - 1, fmt, args);	/* Flawfinder: ignore */
  va_end (args);

  log_func (level, str);
}
Exemplo n.º 15
0
/**
 * @brief 	Callback for removing a language in the configuration dialog
 * @param 	button	the button, not used here
 * @param	data	gtktreeview where to act
 * 
 * @return	void
 * 
 */
static void
on_configure_remove_language(GtkWidget* button, gpointer data)
{
	GtkTreeView* tree_view = (GtkTreeView*)data;
	GtkTreeSelection *selection;
	GtkTreeIter tree_iter;

	log_func();
	
	selection = gtk_tree_view_get_selection (tree_view);

	if ( ! gtk_tree_selection_get_selected(selection, NULL, &tree_iter) ) {
		log_debug("Delete without selection!");
		return;
	}
	/* Remove the element */
	gtk_list_store_remove(list_store, &tree_iter);
}
Exemplo n.º 16
0
GtkWidget *plugin_configure(GtkDialog *dialog)
{
	GtkWidget *vbox;

	log_func();

	vbox = gtk_vbox_new(FALSE, 6);

	/* Switch header/implementation widget */
	gtk_box_pack_start(GTK_BOX(vbox), config_widget(), TRUE, TRUE, 0);

	gtk_widget_show_all(vbox);

	/* Connect a callback for when the user clicks a dialog button */
	g_signal_connect(dialog, "response", G_CALLBACK(on_configure_response), NULL);

	return vbox;
}
Exemplo n.º 17
0
Arquivo: data.c Projeto: amumu/nokuno
static __inline data_t
rand_normal()
{
    static data_t next;
    static int dup = 0;
    data_t t, u;

    if (dup) {
        dup = 0;
        return next;
    }
    else {
        t = sigma*sqrt_func(-2.0*log_func(1.0-rand_regular()));
        u = 2.0*pi*rand_regular();

        dup = 1;
        next = m+t*sin_func(u);
        return m+t*cos_func(u);
    }
}
Exemplo n.º 18
0
/* ---------------------------------------------------------------------
 * Callback when the menu item is clicked.
 * ---------------------------------------------------------------------
 */
static void
menu_item_activate(guint key_id)
{
	log_func();

	/* TODO */

	GtkWidget *dialog = gtk_message_dialog_new(
		GTK_WINDOW(geany->main_widgets->window),
		GTK_DIALOG_DESTROY_WITH_PARENT,
		GTK_MESSAGE_INFO,
		GTK_BUTTONS_OK,
		"Open by name : TODO");

	gtk_window_set_title(GTK_WINDOW(dialog), "Goto file...");

	gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
		_("(From the %s plugin)"), geany_plugin->info->name);

	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
}
Exemplo n.º 19
0
 /**
 * @brief 	Callback for adding a language in the configuration dialog
 * @param 	button	the button, not used here
 * @param	data	gtktreeview where to act
 * 
 * @return	void
 * 
 */
static void
on_configure_add_language(GtkWidget* button, gpointer data)
{
	GtkWidget* tree_view = (GtkWidget*)data;
	GtkTreeIter tree_iter;
	GtkTreePath *path;
	GtkTreeViewColumn* column = NULL;
	gint nb_lines;

	log_func();

	/* Add a line */
	gtk_list_store_append(list_store, &tree_iter);

	/* and give the focus to it */
	nb_lines = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store), NULL);
	path = gtk_tree_path_new_from_indices(nb_lines-1, -1);
	column = gtk_tree_view_get_column(GTK_TREE_VIEW(tree_view), 0);
	gtk_tree_view_set_cursor(GTK_TREE_VIEW(tree_view), path, column, TRUE);

	gtk_tree_path_free(path);
}
Exemplo n.º 20
0
/* ---------------------------------------------------------------------
 *  Cleanup
 * ---------------------------------------------------------------------
 */
void
switch_head_impl_cleanup()
{
	GSList* iter = NULL;

	log_func();

	gtk_widget_destroy(menu_item);

	for(iter = languages ; iter != NULL ; iter = iter->next)
	{
		Language* lang = (Language*)(iter->data);

		g_slist_foreach(lang->head_extensions, (GFunc)(&g_free), NULL);	/* free the data */
		g_slist_free(lang->head_extensions);	/* free the list */

		g_slist_foreach(lang->impl_extensions, (GFunc)(&g_free), NULL);
		g_slist_free(lang->impl_extensions);
	}

	g_slist_free(languages);
}
Exemplo n.º 21
0
void
g_logv (const gchar   *log_domain,
	GLogLevelFlags log_level,
	const gchar   *format,
	va_list	       args1)
{
  gboolean was_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
  gboolean was_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
  gint i;

  log_level &= G_LOG_LEVEL_MASK;
  if (!log_level)
    return;

  for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
    {
      register GLogLevelFlags test_level;

      test_level = 1 << i;
      if (log_level & test_level)
	{
	  guint depth = GPOINTER_TO_UINT (g_private_get (g_log_depth));
	  GLogDomain *domain;
	  GLogFunc log_func;
	  GLogLevelFlags domain_fatal_mask;
	  gpointer data = NULL;
          gboolean masquerade_fatal = FALSE;

	  if (was_fatal)
	    test_level |= G_LOG_FLAG_FATAL;
	  if (was_recursion)
	    test_level |= G_LOG_FLAG_RECURSION;

	  /* check recursion and lookup handler */
	  g_mutex_lock (g_messages_lock);
	  domain = g_log_find_domain_L (log_domain ? log_domain : "");
	  if (depth)
	    test_level |= G_LOG_FLAG_RECURSION;
	  depth++;
	  domain_fatal_mask = domain ? domain->fatal_mask : G_LOG_FATAL_MASK;
	  if ((domain_fatal_mask | g_log_always_fatal) & test_level)
	    test_level |= G_LOG_FLAG_FATAL;
	  if (test_level & G_LOG_FLAG_RECURSION)
	    log_func = _g_log_fallback_handler;
	  else
	    log_func = g_log_domain_get_handler_L (domain, test_level, &data);
	  domain = NULL;
	  g_mutex_unlock (g_messages_lock);

	  g_private_set (g_log_depth, GUINT_TO_POINTER (depth));

	  /* had to defer debug initialization until we can keep track of recursion */
	  if (!(test_level & G_LOG_FLAG_RECURSION) && !_g_debug_initialized)
	    {
	      GLogLevelFlags orig_test_level = test_level;

	      _g_debug_init ();
	      if ((domain_fatal_mask | g_log_always_fatal) & test_level)
		test_level |= G_LOG_FLAG_FATAL;
	      if (test_level != orig_test_level)
		{
		  /* need a relookup, not nice, but not too bad either */
		  g_mutex_lock (g_messages_lock);
		  domain = g_log_find_domain_L (log_domain ? log_domain : "");
		  log_func = g_log_domain_get_handler_L (domain, test_level, &data);
		  domain = NULL;
		  g_mutex_unlock (g_messages_lock);
		}
	    }

	  if (test_level & G_LOG_FLAG_RECURSION)
	    {
	      /* we use a stack buffer of fixed size, since we're likely
	       * in an out-of-memory situation
	       */
	      gchar buffer[1025];
              gsize size;
              va_list args2;

              G_VA_COPY (args2, args1);
	      size = _g_vsnprintf (buffer, 1024, format, args2);
              va_end (args2);

	      log_func (log_domain, test_level, buffer, data);
	    }
	  else
	    {
	      gchar *msg;
              va_list args2;

              G_VA_COPY (args2, args1);
              msg = g_strdup_vprintf (format, args2);
              va_end (args2);

	      log_func (log_domain, test_level, msg, data);

              if ((test_level & G_LOG_FLAG_FATAL)
                && !(test_level & G_LOG_LEVEL_ERROR))
                {
                  masquerade_fatal = fatal_log_func
                    && !fatal_log_func (log_domain, test_level, msg, data);
                }

	      g_free (msg);
	    }

	 gchar *locale_msg2 = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);

              MessageBox (NULL, locale_msg2, L"G_LOGV",
                          MB_ICONERROR|MB_SETFOREGROUND);

	  if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
            {
#ifdef G_OS_WIN32
	      gchar *locale_msg = g_locale_from_utf8 (fatal_msg_buf, -1, NULL, NULL, NULL);
	      
	      MessageBox (NULL, locale_msg, NULL,
			  MB_ICONERROR|MB_SETFOREGROUND);
#ifndef G_PLATFORM_WIN32_CE
	      if (IsDebuggerPresent () && !(test_level & G_LOG_FLAG_RECURSION))
		G_BREAKPOINT ();
	      else
		abort ();
#else
		abort ();
#endif


#else
#if defined (G_ENABLE_DEBUG) && defined (SIGTRAP)
	      if (!(test_level & G_LOG_FLAG_RECURSION))
		G_BREAKPOINT ();
	      else
		abort ();
#else /* !G_ENABLE_DEBUG || !SIGTRAP */
	      abort ();
#endif /* !G_ENABLE_DEBUG || !SIGTRAP */
#endif /* !G_OS_WIN32 */
	    }
	  
	  depth--;
	  g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
	}
    }
}
Exemplo n.º 22
0
/* ----- Finally, the configuration widget ----- */
GtkWidget*
switch_head_impl_config_widget()
{
	GtkWidget *frame, *vbox, *tree_view;
	GtkWidget *hbox_buttons, *add_button, *remove_button;
	GtkListStore *list_store;
	GtkTreeViewColumn *column;
	GtkCellRenderer *cell_renderer;

	GSList *iter_lang;

	log_func();

	/* Frame, which is the returned widget */
	frame = gtk_frame_new(_("Switch header/implementation"));

	/* Main VBox */
	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(frame), vbox);

	/* ======= Extensions list ======= */

	/* Add a list containing the extensions for each language (headers / implementations) */
	/* - create the GtkListStore */
	list_store = gtk_list_store_new(NB_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);

	/* - fill the GtkListStore with the extensions of the languages */
	for(iter_lang = languages ; iter_lang != NULL ; iter_lang = iter_lang->next)
		add_language(list_store, (Language*)(iter_lang->data));

	/* - create the GtkTreeView */
	tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store));

	/* - add the columns */
	/* -> headers : */
	cell_renderer = gtk_cell_renderer_text_new();
	g_object_set(G_OBJECT(cell_renderer), "editable", TRUE, NULL);
	g_signal_connect(G_OBJECT(cell_renderer), "edited", G_CALLBACK(on_configure_cell_edited), GINT_TO_POINTER(COLUMN_HEAD));
	column = gtk_tree_view_column_new_with_attributes(	_("Headers extensions"), cell_renderer,
														"text", COLUMN_HEAD,
														NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);

	/* -> implementations : */
	cell_renderer = gtk_cell_renderer_text_new();
	g_object_set(G_OBJECT(cell_renderer), "editable", TRUE, NULL);
	g_signal_connect(G_OBJECT(cell_renderer), "edited", G_CALLBACK(on_configure_cell_edited), GINT_TO_POINTER(COLUMN_IMPL));
	column = gtk_tree_view_column_new_with_attributes(	_("Implementations extensions"), cell_renderer,
														"text", COLUMN_IMPL,
														NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);


	/* - finally add the GtkTreeView to the frame's vbox */
	gtk_box_pack_start(GTK_BOX(vbox), tree_view, TRUE, TRUE, 6);


	/* ========= Buttons ======== */

	/* HBox */
	hbox_buttons = gtk_hbox_new(FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox_buttons, FALSE, FALSE, 0);

	/* Add the "add" button to the frame's hbox */
	add_button = gtk_button_new_from_stock(GTK_STOCK_ADD);
	g_signal_connect(G_OBJECT(add_button), "clicked", G_CALLBACK(on_configure_add_language), tree_view);
	gtk_box_pack_start(GTK_BOX(hbox_buttons), add_button, FALSE, FALSE, 0);

	/* Add the "remove" button to the frame's hbox */
	remove_button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
	gtk_widget_set_sensitive(remove_button, FALSE);	/* TODO ! */
	g_signal_connect(G_OBJECT(remove_button), "clicked", G_CALLBACK(on_configure_remove_language), tree_view);
	gtk_box_pack_start(GTK_BOX(hbox_buttons), remove_button, FALSE, FALSE, 0);

	return frame;
}
Exemplo n.º 23
0
/* ---------------------------------------------------------------------
 *  Callback when the menu item is clicked.
 * ---------------------------------------------------------------------
 */
static void
menu_item_activate(guint key_id)
{
	GeanyDocument* current_doc = document_get_current();
	GeanyDocument* new_doc = NULL;
	guint nb_documents = geany->documents_array->len;

	gchar* extension = NULL;	/* e.g. : "hpp" */

	GSList* p_extensions_to_test = NULL;	/* e.g. : ["cpp", "cxx", ...] */

	GSList* filenames_to_test = NULL;	/* e.g. : ["f.cpp", "f.cxx", ...] */

	GSList* iter_lang = NULL;
	GSList* iter_ext = NULL;
	GSList* iter_filename = NULL;
	gint i=0;

	gchar* dirname = NULL;
	gchar* basename = NULL;
	gchar* basename_no_extension = NULL;

	gchar* p_str = NULL;	/* Local variables, used as temporary buffers */
	gchar* p_str2 = NULL;

	log_func();
	log_debug("current_doc->file_name == %s", current_doc->file_name);
	log_debug("geany->documents_array->len == %d", geany->documents_array->len);

	if(current_doc != NULL && current_doc->file_name != NULL && current_doc->file_name[0] != '\0')
	{
		/* Get the basename, e.g. : "/home/me/file.cpp" -> "file.cpp" */
		basename = g_path_get_basename(current_doc->file_name);

		if(g_utf8_strlen(basename, -1) < 2)
			goto free_mem;

		log_debug("basename == %s", basename);

		/* Get the extension , e.g. : "cpp" */
		extension = get_extension(basename);

		if(extension == NULL || g_utf8_strlen(extension, -1) == 0)
			goto free_mem;

		log_debug("extension == %s", extension);

		/* Get the basename without any extension */
		basename_no_extension = copy_and_remove_extension(basename);
		if(basename_no_extension == NULL || g_utf8_strlen(basename_no_extension, -1) == 0)
			goto free_mem;

		/* Identify the language and whether the file is a header or an implementation. */
		/* For each recognized language : */
		for(iter_lang = languages ; iter_lang != NULL ; iter_lang = iter_lang->next)
		{
			Language* lang = (Language*)(iter_lang->data);

			/* Test the headers : */
			if(g_slist_find_custom(lang->head_extensions, extension, (GCompareFunc)(&compare_strings)) != NULL)
			{
				p_extensions_to_test = lang->impl_extensions;
				break;
			}

			/* Test the implementations : */
			else if(g_slist_find_custom(lang->impl_extensions, extension, (GCompareFunc)(&compare_strings)) != NULL)
			{
				p_extensions_to_test = lang->head_extensions;
				break;
			}
		}

		if(p_extensions_to_test == NULL)
			goto free_mem;

#ifdef CODE_NAVIGATION_DEBUG
		log_debug("extension known !");
		log_debug("p_extensions_to_test : ");
		g_slist_foreach(p_extensions_to_test, (GFunc)(&log_debug), NULL);
#endif

		/* Build a list of filenames to test : */
		filenames_to_test = NULL;
		for(iter_ext = p_extensions_to_test ; iter_ext != NULL ; iter_ext = iter_ext->next)
		{
			p_str = g_strdup_printf("%s.%s", basename_no_extension, (const gchar*)(iter_ext->data));
			filenames_to_test = g_slist_prepend(filenames_to_test, p_str);
		}

		filenames_to_test = g_slist_reverse(filenames_to_test);

#ifdef CODE_NAVIGATION_DEBUG
		log_debug("filenames to test :");
		g_slist_foreach(filenames_to_test, (GFunc)(&log_debug), NULL);
#endif

		/* First : look for a corresponding file in the opened files.
		 * If found, open it. */
		for(i=0 ; i < nb_documents ; i++)
		{
			new_doc = document_index(i);

			for(iter_filename = filenames_to_test ; iter_filename != NULL ; iter_filename = iter_filename->next)
			{
				p_str = g_path_get_basename(new_doc->file_name);

				log_debug("comparing \"%s\" and \"%s\"", (const gchar*)(iter_filename->data), p_str);
				if(utils_str_equal((const gchar*)(iter_filename->data), p_str))
				{
					log_debug("FOUND !");
					g_free(p_str);

					p_str = g_locale_from_utf8(new_doc->file_name, -1, NULL, NULL, NULL);
					document_open_file(p_str, FALSE, NULL, NULL);
					g_free(p_str);
					goto free_mem;
				}
				g_free(p_str);
			}
		}

		/* Second : if not found, look for a corresponding file in the same directory.
		 * If found, open it.
		 */
		/* -> compute dirname */
		dirname = g_path_get_dirname(current_doc->real_path);
		if(dirname == NULL)
			goto free_mem;

		log_debug("dirname == \"%s\"", dirname);

		/* -> try all the extensions we should test */
		for(iter_ext = p_extensions_to_test ; iter_ext != NULL ; iter_ext = iter_ext->next)
		{
			p_str = g_strdup_printf(	"%s" G_DIR_SEPARATOR_S "%s.%s",
										dirname, basename_no_extension, (const gchar*)(iter_ext->data));

			p_str2 = g_locale_from_utf8(p_str, -1, NULL, NULL, NULL);
			g_free(p_str);

			log_debug("trying to open the file \"%s\"\n", p_str2);

			/* Try without read-only and in read-only mode */
			if(	document_open_file(p_str2, FALSE, NULL, NULL) != NULL ||
				document_open_file(p_str2, TRUE, NULL, NULL) != NULL)
			{
				g_free(p_str2);
				goto free_mem;
			}
			g_free(p_str2);
		}

		/* Third : if not found, ask the user if he wants to create it or not. */
		{
			p_str = g_strdup_printf("%s.%s", basename_no_extension, (const gchar*)(p_extensions_to_test->data));

			GtkWidget* dialog = gtk_message_dialog_new(	GTK_WINDOW(geany_data->main_widgets->window),
														GTK_DIALOG_MODAL,
														GTK_MESSAGE_QUESTION,
														GTK_BUTTONS_OK_CANCEL,
														_("%s not found, create it?"), p_str);
			gtk_window_set_title(GTK_WINDOW(dialog), "Geany");
			if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
			{
				p_str2 = g_strdup_printf(	"%s" G_DIR_SEPARATOR_S "%s", dirname, p_str);

				document_new_file(p_str2, current_doc->file_type, NULL);
				document_set_text_changed(document_get_current(), TRUE);

				g_free(p_str2);
			}

			log_debug("DESTROY");

			gtk_widget_destroy(dialog);

			g_free(p_str);
		}

		/* Free the memory */
free_mem:
		g_slist_foreach(filenames_to_test, (GFunc)(&g_free), NULL);
		g_free(dirname);
		g_free(basename_no_extension);
		g_free(extension);
		g_free(basename);
	}
}
Exemplo n.º 24
0
Arquivo: data.c Projeto: amumu/nokuno
static __inline data_t
rand_laplace()
{
    return rand_func()%2 ? mu-b*log_func(1.0-rand_regular())
           : mu+b*log_func(1.0-rand_regular());
}
Exemplo n.º 25
0
static void
gdkrecord_event_handler (GdkEvent *event,
                         gpointer  data)
{
    EventLogFunc log_func = NULL;
    gdouble      begin,
                 end;

    switch (event->type) {
    case GDK_EXPOSE:
        log_func = LOG_FUNC (gdkrecord_event_expose);
        break;
    case GDK_VISIBILITY_NOTIFY:
        log_func = LOG_FUNC (gdkrecord_event_visibility);
        break;
    case GDK_WINDOW_STATE:
        log_func = LOG_FUNC (gdkrecord_event_window_state);
        break;
    case GDK_LEAVE_NOTIFY:
    case GDK_ENTER_NOTIFY:
        log_func = LOG_FUNC (gdkrecord_event_crossing);
        break;
    case GDK_BUTTON_PRESS:
    case GDK_2BUTTON_PRESS:
    case GDK_3BUTTON_PRESS:
    case GDK_BUTTON_RELEASE:
        log_func = LOG_FUNC (gdkrecord_event_button);
        break;
    case GDK_MAP:
        log_func = LOG_FUNC (gdkrecord_event_map);
        break;
    case GDK_UNMAP:
        log_func = LOG_FUNC (gdkrecord_event_unmap);
        break;
    case GDK_KEY_PRESS:
    case GDK_KEY_RELEASE:
        log_func = LOG_FUNC (gdkrecord_event_key);
        break;
    case GDK_CLIENT_EVENT:
    case GDK_SELECTION_CLEAR:
    case GDK_SELECTION_REQUEST:
    case GDK_SELECTION_NOTIFY:
    case GDK_PROXIMITY_IN:
    case GDK_PROXIMITY_OUT:
    case GDK_DRAG_ENTER:
    case GDK_DRAG_LEAVE:
    case GDK_DRAG_MOTION:
    case GDK_DRAG_STATUS:
    case GDK_DROP_START:
    case GDK_DROP_FINISHED:
    case GDK_DELETE:
    case GDK_DESTROY:
    case GDK_MOTION_NOTIFY:
    case GDK_FOCUS_CHANGE:
    case GDK_CONFIGURE:
    case GDK_PROPERTY_NOTIFY:
    case GDK_NO_EXPOSE:
    case GDK_SCROLL:
    case GDK_SETTING:
    case GDK_OWNER_CHANGE:
    case GDK_GRAB_BROKEN:
    case GDK_DAMAGE:
    default:
        break;
    }

    begin = g_timer_elapsed (timer, NULL);
    gtk_main_do_event (event);
    end = g_timer_elapsed (timer, NULL);

    if (G_LIKELY (log_func))
        log_func (event, begin, end);
}
Exemplo n.º 26
0
Arquivo: data.c Projeto: amumu/nokuno
static __inline data_t
rand_exponential()
{
    return -(log_func(1.0-rand_regular())/lambda_exp);
}
void
g_logv (const gchar    *log_domain,
	GLogLevelFlags	log_level,
	const gchar    *format,
	va_list	        args1)
{
  va_list args2;
  gchar buffer[1025];
  register gint i;
  
  log_level &= G_LOG_LEVEL_MASK;
  if (!log_level)
    return;
  
  /* we use a stack buffer of fixed size, because we might get called
   * recursively.
   */
  G_VA_COPY (args2, args1);
  if (g_printf_string_upper_bound (format, args1) < 1024)
    vsprintf (buffer, format, args2);
  else
    {
      /* since we might be out of memory, we can't use g_vsnprintf(). */
#ifdef  HAVE_VSNPRINTF
      vsnprintf (buffer, 1024, format, args2);
#else	/* !HAVE_VSNPRINTF */
      /* we are out of luck here */
      strncpy (buffer, format, 1024);
#endif	/* !HAVE_VSNPRINTF */
      buffer[1024] = 0;
    }
  va_end (args2);
  
  for (i = g_bit_nth_msf (log_level, -1); i >= 0; i = g_bit_nth_msf (log_level, i))
    {
      register GLogLevelFlags test_level;
      
      test_level = 1 << i;
      if (log_level & test_level)
	{
	  guint depth = GPOINTER_TO_UINT (g_private_get (g_log_depth));
	  GLogDomain *domain;
	  GLogFunc log_func;
	  gpointer data = NULL;
	  
	  domain = g_log_find_domain (log_domain ? log_domain : "");
	  
	  if (depth)
	    test_level |= G_LOG_FLAG_RECURSION;
	  
	  depth++;
	  g_private_set (g_log_depth, GUINT_TO_POINTER (depth));

	  g_mutex_lock (g_messages_lock);
	  if ((((domain ? domain->fatal_mask : G_LOG_FATAL_MASK) | 
		g_log_always_fatal) & test_level) != 0)
	    test_level |= G_LOG_FLAG_FATAL;  
	  g_mutex_unlock (g_messages_lock);

	  log_func = g_log_domain_get_handler (domain, test_level, &data);
	  log_func (log_domain, test_level, buffer, data);
	  
	  /* *domain can be cluttered now */
	  
	  if (test_level & G_LOG_FLAG_FATAL)
	    abort ();
	  
	  depth--;
	  g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
	}
    }
}
Exemplo n.º 28
0
void Conn::Shutdown() {
	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u shutdown", ep.address().to_string().c_str(), ep.port());
	close();
	dismissCallbacks(CB_ERR);
}
Exemplo n.º 29
0
/**
 * @brief 	Callback called when validating the configuration of the plug-in
 * @param 	dialog 		the parent dialog, not very interesting here
 * @param 	response	OK/Cancel/Apply user action
 * @param 	user_data	NULL
 * 
 * @return void
 * 
 */
static void
on_configure_response(GtkDialog* dialog, gint response, gpointer user_data)
{
	gsize i=0;

	GKeyFile *config = NULL;
	gchar *config_filename = NULL;
	gchar *config_dir = NULL;
	gchar *data;

	gsize list_len, empty_lines;
	gchar** head_list = NULL;
	gchar** impl_list = NULL;
	
	GtkTreeIter iter;

	log_func();

	if(response != GTK_RESPONSE_OK && response != GTK_RESPONSE_APPLY)
		return;
	
	/* Write the settings into a file, using GLib's GKeyFile API.
	 * File name :
	 * geany->app->configdir G_DIR_SEPARATOR_S "plugins" G_DIR_SEPARATOR_S 
	 * "codenav" G_DIR_SEPARATOR_S "codenav.conf"
	 * e.g. this could be: ~/.config/geany/plugins/codenav/codenav.conf
	 */

	/* Open the GKeyFile */
	config 	        = g_key_file_new();
	config_filename = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
								"plugins", G_DIR_SEPARATOR_S, "codenav", 
								G_DIR_SEPARATOR_S, "codenav.conf", NULL);
	config_dir      = g_path_get_dirname(config_filename);
	
	/* Allocate the list */
	list_len = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(list_store), NULL);
	impl_list = g_malloc0( sizeof(gchar**) * list_len);
	head_list = g_malloc0( sizeof(gchar**) * list_len);
	
	empty_lines = 0;
	
	if ( list_len > 0 ) {
		// Get the first item
		gtk_tree_model_iter_children (GTK_TREE_MODEL(list_store),&iter,NULL);
	
		
		do {		/* forall elements in list... */
						
			gtk_tree_model_get (GTK_TREE_MODEL(list_store),&iter,
									COLUMN_IMPL,&impl_list[i], -1);
			gtk_tree_model_get (GTK_TREE_MODEL(list_store),&iter,
									COLUMN_HEAD,&head_list[i], -1);
									
			/* If one field is empty, ignore this line (it will be replaces
			   at next execution) */ 
			if ( strlen(impl_list[i])==0 || strlen(head_list[i])==0 )
				empty_lines++;
			else
				i++;
		} while ( gtk_tree_model_iter_next(GTK_TREE_MODEL(list_store), &iter) );
	}
	
	/* write lists */
	g_key_file_set_string_list(config, "switch_head_impl", "implementations_list", 
								(const gchar * const*)impl_list, list_len - empty_lines);
	g_key_file_set_string_list(config, "switch_head_impl", "headers_list", 
								(const gchar * const*)head_list, list_len - empty_lines);
	
	/* Try to create directory if not exists */
	if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0)
	{
		dialogs_show_msgbox(GTK_MESSAGE_ERROR,
			_("Plugin configuration directory could not be created."));
	}
	else
	{
		/* write config to file */
		data = g_key_file_to_data(config, NULL, NULL);
		utils_write_file(config_filename, data);
		g_free(data);
	}

	/* Replace the current (runtime) languages list */
	fill_languages_list((const gchar**)impl_list, (const gchar**)head_list, list_len - empty_lines);
	
	/* Freeing memory */
	for ( i=0; i < list_len; i++ ) {
		g_free(impl_list[i]);
		g_free(head_list[i]);
	}
	g_free(impl_list);
	g_free(head_list);
	
	g_free(config_dir);
	g_free(config_filename);
	g_key_file_free(config);

}
Exemplo n.º 30
0
void Conn::reconnect() {
	close();
	if( LOG_DEBUG )
		log_func("[iproto_conn] %s:%u reconnect", ep.address().to_string().c_str(), ep.port());
	beginConnect();
}