예제 #1
0
파일: main.c 프로젝트: tuhaihe/gtkhash
int main(int argc, char **argv)
{
#if ENABLE_NLS
    bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
    textdomain(GETTEXT_PACKAGE);
#endif

    g_thread_init(NULL);
    gdk_threads_init();
    gdk_threads_enter();
    g_atexit(gdk_threads_leave);

    read_opts_preinit(&argc, &argv);

    hash_init();
    g_atexit(hash_deinit);

    gui_init(opts.datadir ? opts.datadir : DATADIR);
    g_atexit(gui_deinit);

    list_init();

    prefs_init();
    g_atexit(prefs_deinit);

    read_opts_postinit();

    gui_run();

    return EXIT_SUCCESS;
}
예제 #2
0
/* All GKrellM plugins must have one global routine named init_plugin()
|  which returns a pointer to a filled in monitor structure.
*/
GkrellmMonitor *
gkrellm_init_plugin() {

#ifdef ENABLE_NLS
   bind_textdomain_codeset(PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */

  style_id = gkrellm_add_meter_style(&plugin_mon, STYLE_NAME);
  plugin_monitor = &plugin_mon;
#ifdef HAVE_LIRC
  gkrellm_radio_lirc_init();
  g_atexit(gkrellm_radio_lirc_exit);
#endif
  g_atexit(exit_func);
  return &plugin_mon;
}
예제 #3
0
void 
seahorse_unix_signal_register (int sig, signal_handler handler)
{
    g_return_if_fail (sig < MAX_SIGNAL);
    g_return_if_fail (handler != NULL);

    /* Setup the signal channel */
    if (signal_channel == NULL) {

        memset (&signal_handlers, 0, sizeof (signal_handlers));
        
        if (pipe (signal_pipe)) {
            g_critical ("can't create signal pipe: %s", strerror (errno));
            return;
        }

        /* Non blocking to prevent deadlock */
        fcntl (signal_pipe[1], F_SETFL, fcntl (signal_pipe[1], F_GETFL) | O_NONBLOCK);

        /* convert the reading end of the pipe into a GIOChannel */
        signal_channel = g_io_channel_unix_new (signal_pipe[0]);
        g_io_channel_set_encoding (signal_channel, NULL, NULL);
        g_io_channel_set_flags (signal_channel, g_io_channel_get_flags (signal_channel) | G_IO_FLAG_NONBLOCK, NULL);

        /* register the reading end with the event loop */
        signal_watch_id = g_io_add_watch (signal_channel, G_IO_IN | G_IO_PRI | G_IO_HUP, deliver_signal, NULL);

        g_atexit (cleanup_signals);
    }

    /* Handle some signals */
    signal (sig, pipe_signals);

    signal_handlers[sig] = handler;
}
예제 #4
0
static void
initialize_categories (void)
{
	gint n_added;

	if (initialized)
		return;

	initialized = TRUE;

	categories_table = g_hash_table_new_full (
		g_str_hash, g_str_equal, g_free,
		(GDestroyNotify) free_category_info);

	g_atexit (finalize_categories);

	n_added = load_categories ();
	if (n_added > 0) {
		g_debug ("Loaded %d categories", n_added);
		save_is_pending = FALSE;
		return;
	}

	n_added = migrate_old_categories ();
	if (n_added > 0) {
		g_debug ("Loaded %d categories", n_added);
		save_categories ();
		return;
	}

	load_default_categories ();
	g_debug ("Loaded default categories");
	save_categories ();
}
void e_pixmaps_update (BonoboUIComponent *uic, EPixmap *pixcache)
{
	static int done_init = 0;
	int i;

	if (!done_init) {
		g_atexit (free_pixmaps);
		done_init = 1;
	}

	if (g_slist_find (inited_arrays, pixcache) == NULL)
		inited_arrays = g_slist_prepend (inited_arrays, pixcache);

	for (i = 0; pixcache [i].path; i++) {
		if (!pixcache [i].pixbuf) {
			GdkPixbuf *pixbuf;

			pixbuf = e_icon_factory_get_icon (pixcache [i].name, pixcache [i].size);
			pixcache [i].pixbuf = bonobo_ui_util_pixbuf_to_xml (pixbuf);
			g_object_unref (pixbuf);
			bonobo_ui_component_set_prop (uic,
				pixcache [i].path, "pixname",
				pixcache [i].pixbuf, NULL);
		} else {
			bonobo_ui_component_set_prop (uic, pixcache [i].path,
						      "pixname",
						      pixcache [i].pixbuf,
						      NULL);
		}
	}
}
예제 #6
0
파일: main.c 프로젝트: bertrandkang/gimp
static void
gimp_init_malloc (void)
{
#ifdef GIMP_GLIB_MEM_PROFILER
  g_mem_set_vtable (glib_mem_profiler_table);
  g_atexit (g_mem_profile);
#endif

#ifdef __GLIBC__
  /* Tweak memory allocation so that memory allocated in chunks >= 4k
   * (64x64 pixel 1bpp tile) gets returned to the system when free()'d.
   *
   * The default value for M_MMAP_THRESHOLD in glibc-2.3 is 128k.
   * This is said to be an empirically derived value that works well
   * in most systems. Lowering it to 4k is thus probably not the ideal
   * solution.
   *
   * An alternative to tuning this parameter would be to use
   * malloc_trim(), for example after releasing a large tile-manager.
   */
#if 0
  mallopt (M_MMAP_THRESHOLD, TILE_WIDTH * TILE_HEIGHT);
#endif
#endif
}
예제 #7
0
파일: .c 프로젝트: pigay/vsg
void vsgprtree_key3@t@_init ()
{
  if (G_UNLIKELY (_bitmasks_number == 0))
    {
      guint8 ks = VSG_PRTREE_KEY3@T@_BITS;
      gint8 i, j;
      @key_type@ mask = ~0;

      while (ks>>(_bitmasks_number+1) != 0) _bitmasks_number++;

      _bitmasks = g_malloc (_bitmasks_number * sizeof (BitMaskData));

      for (i=_bitmasks_number-1; i>=0; i--)
        {
          ks >>= 1; /* ks = 1 << i */
          mask ^= (mask << ks);
          _bitmasks[i].mask = ~ mask;
          _bitmasks[i].base = 1 << (i);
/*           g_printerr ("num=%u offset=%u mask mask=%#@kmod@x\n", */
/*                       i, _bitmasks[i].base, _bitmasks[i].mask); */
        }

      _number_of_sieves[0] = 0;
      _number_of_sieves[1] = 0;
      for (i=0; i<_bitmasks_number; i++)
        {
          for (j=_bitmasks[i].base/2+1; j<=_bitmasks[i].base; j ++)
            {
              _number_of_sieves[j] = i+1;
/*               g_printerr ("powers %d %d\n", j,  _number_of_sieves[j]); */
            }
        }

      g_atexit (_exitfunc);
   }
gint
e_plugin_lib_enable (EPlugin *ep, gint enable)
{
	if (!config_listener) {
		config_listener = eas_account_listener_new ();
		g_atexit ( free_eas_account_listener );
	}

	return 0;
}
예제 #9
0
/* private function */
void aran_solver3d_init ()
{
  static gboolean wasinit = FALSE;

  if (! wasinit)
    {
      wasinit = TRUE;
      g_atexit (aran_solver3d_finalize);
    }
}
예제 #10
0
파일: .c 프로젝트: BackupTheBerlios/vsg-svn
/* private function */
void vsg_matrix3@t@_init ()
{
  static gboolean wasinit = FALSE;

  if (! wasinit)
    {
      wasinit = TRUE;
      g_atexit (vsg_matrix3@t@_finalize);
    }
}
/* Public */
GConfClient *
eel_gconf_client_get_global (void)
{
	if (global_gconf_client == NULL) {
		global_gconf_client = gconf_client_get_default ();
		g_atexit (global_client_free);
	}
	
	return global_gconf_client;
}
예제 #12
0
static void
calendar_config_init (void)
{
	if (config)
		return;

	config = gconf_client_get_default ();
	g_atexit ((GVoidFunc) do_cleanup);

	gconf_client_add_dir (config, CALENDAR_CONFIG_PREFIX, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
}
예제 #13
0
/* errstr may be NULL, this might be called before GTK is initialized */
gboolean
cf_lock( gtr_lockfile_state_t * tr_state, char ** errstr )
{
    char *         path = getLockFilename( );
    const gboolean didLock = lockfile( path, tr_state, errstr );

    if( didLock )
        gl_lockpath = g_strdup( path );
    g_atexit( cf_removelocks );
    g_free( path );
    return didLock;
}
예제 #14
0
파일: .c 프로젝트: pigay/vsg
/* private function */
void vsg_quaternion@t@_init ()
{
#if ! _USE_G_SLICES
  static gboolean wasinit = FALSE;

  if (! wasinit)
    {
      wasinit = TRUE;
      g_atexit (vsg_quaternion@t@_finalize);
    }
#endif /* ! _USE_G_SLICES */
}
예제 #15
0
int main(int argc, char **argv)
{
  guint i;
  eva_set_debug_mem_vtable (argv[0]);
  g_atexit (eva_print_debug_mem_vtable);

  g_malloc (1024);
  for (i = 0; i < 4; i++)
    b();

  return 0;
}
예제 #16
0
파일: vsgpackedmsg.c 프로젝트: pigay/vsg
static inline void _trace_file_open ()
{
  if (_trace_file == NULL)
    {
      gint initted, rk, sz;
      gchar filename[256];
      GTimeVal now;
      const gchar *trace_dir = g_getenv ("VSG_PACKED_MSG_TRACE_DIR");
      gchar *trace_path;

      MPI_Initialized (&initted);
      if (initted != 0)
        {
          MPI_Comm_rank (MPI_COMM_WORLD, &rk);
          MPI_Comm_size (MPI_COMM_WORLD, &sz);
        }
      else
        {
          rk = 0;
          sz = 1;
        }
      _msgid = rk+1;
      _msgid_incr = sz;

      g_sprintf (filename, "vsg-packed-msg-%04d.trace", rk);

      if (trace_dir != NULL)
	trace_path = g_build_filename (trace_dir, filename, NULL);
      else
	trace_path = g_strdup (filename);

/*       g_printerr ("%d : opening trace \"%s\"\n", rk, trace_path); */

      _trace_file = fopen (trace_path, "w");

      g_free (trace_path);

      _trace_comm_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
						NULL, g_free);

      g_get_current_time (&now);
      _timer = g_timer_new ();

      g_fprintf (_trace_file, "opening processor %d: %ld %ld\n", rk, now.tv_sec, now.tv_usec);

      _trace_comm_id (MPI_COMM_WORLD);
      _trace_comm_id (MPI_COMM_SELF);

      g_atexit (_trace_atexit);
    }
}
예제 #17
0
/**
 * vfs_module_init:
 * @method_name: FIXME
 * @args: FIXME
 *
 * FIXME
 *
 * Returns: FIXME
 */
GnomeVFSMethod *vfs_module_init(const char *method_name, const char *args)
{
	GnomeVFSMethod *libntfs_gnomevfs_method_ptr;

	g_return_val_if_fail(method_name != NULL, NULL);
	/* 'args' may be NULL if not supplied. */

	libntfs_gnomevfs_method_ptr = libntfs_gnomevfs_method_init(method_name,
			args);

	g_atexit(vfs_module_shutdown_atexit);

	return libntfs_gnomevfs_method_ptr;
}
예제 #18
0
static void _betal_over_betan_require (guint deg)
{
  aran_spherical_seriesd_beta_require (deg);
 
  if (_betal_over_betan_buffer == NULL)
    {
      _betal_over_betan_buffer = aran_square_bufferd_new (_betal_over_betan_generator, deg);

      g_atexit (_atexit);
    }
  else
    {
      aran_square_bufferd_require (_betal_over_betan_buffer, deg);
    }
}
예제 #19
0
void
__zune_images_init(void)
{
    int i;

    g_atexit(__destroy_images);
    for (i = 0; i < PATTERN_COUNT; i++)
    {
	__patternSpec[i] = zune_imspec_pattern_new(MUII_BACKGROUND + i);
    }

    for (i = 0; i < MPEN_COUNT; i++)
    {
	__penSpec[i] = zune_imspec_muipen_new(i);
    }
}
예제 #20
0
static void _precomputed_translate_vertical_require (guint deg)
{
  aran_spherical_seriesd_beta_require (deg);
  aran_spherical_seriesd_alpha_require (deg+deg);
  _betal_over_betan_require (deg);

  if (_precomputed_translate_vertical_buffer == NULL)
    {
      _precomputed_translate_vertical_buffer = aran_translate_bufferd_new (_precomputed_translate_vertical_generator, deg);

      g_atexit (_atexit2);
    }
  else
    {
      aran_translate_bufferd_require (_precomputed_translate_vertical_buffer, deg);
    }
}
예제 #21
0
/**
 * gconf_bridge_get
 *
 * Returns the #GConfBridge. This is a singleton object.
 *
 * Return value: The #GConfBridge.
 **/
GConfBridge *
gconf_bridge_get (void)
{
        if (bridge)
                return bridge;

        gconf_bridge_install_default_error_handler ();

        bridge = g_new (GConfBridge, 1);

        bridge->client = gconf_client_get_default ();
        bridge->bindings = g_hash_table_new_full (NULL, NULL, NULL,
                                                  (GDestroyNotify) unbind);

        g_atexit (destroy_bridge);

        return bridge;
}
예제 #22
0
int term_init(void)
{
	struct sigaction act;
        int width, height;

	last_fg = last_bg = -1;
	last_attrs = 0;
	vcx = vcy = 0; crealx = crealy = -1;
	vcmove = FALSE; cforcemove = TRUE;
        curs_visible = TRUE;

	current_term = terminfo_core_init(stdin, stdout);
	if (current_term == NULL)
		return FALSE;

	if (term_get_size(&width, &height)) {
                current_term->width = width;
                current_term->height = height;
	}

        /* grab CONT signal */
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = sig_cont;
	sigaction(SIGCONT, &act, NULL);
	sigcont_source = g_source_new(&sigcont_funcs, sizeof(GSource));
	g_source_set_callback(sigcont_source, do_redraw, NULL, NULL);
	g_source_attach(sigcont_source, NULL);

	curs_x = curs_y = 0;
	term_width = current_term->width;
	term_height = current_term->height;
	root_window = term_window_create(0, 0, term_width, term_height);

        term_lines_empty = g_new0(char, term_height);

        term_set_input_type(TERM_TYPE_8BIT);
	term_common_init();
        g_atexit(term_deinit);
        return TRUE;
}
예제 #23
0
void
_clutter_uprof_init (void)
{
  UProfContext *cogl_context;

  _clutter_uprof_context = uprof_context_new ("Clutter");
  uprof_context_link (_clutter_uprof_context, uprof_get_mainloop_context ());
  g_atexit (print_exit_report);

  cogl_context = uprof_find_context ("Cogl");
  if (cogl_context)
    uprof_context_link (_clutter_uprof_context, cogl_context);

  /* We make the report object up-front so we can use uprof-tool
   * to fetch reports at runtime via dbus... */
  clutter_uprof_report = uprof_report_new ("Clutter report");
  uprof_report_add_context (clutter_uprof_report, _clutter_uprof_context);
  uprof_report_set_init_fini_callbacks (clutter_uprof_report,
                                        _clutter_uprof_report_prepare,
                                        _clutter_uprof_report_done,
                                        NULL);
}
예제 #24
0
static Suite *
souphttpsrc_suite (void)
{
  Suite *s;

  TCase *tc_chain, *tc_internet;

  g_type_init ();
  if (!g_thread_supported ())
    g_thread_init (NULL);

  s = suite_create ("souphttpsrc");
  tc_chain = tcase_create ("general");
  tc_internet = tcase_create ("internet");

  suite_add_tcase (s, tc_chain);
  run_server (&http_port, &https_port);
  g_atexit (stop_server);
  tcase_add_test (tc_chain, test_first_buffer_has_offset);
  tcase_add_test (tc_chain, test_redirect_yes);
  tcase_add_test (tc_chain, test_redirect_no);
  tcase_add_test (tc_chain, test_not_found);
  tcase_add_test (tc_chain, test_forbidden);
  tcase_add_test (tc_chain, test_cookies);
  tcase_add_test (tc_chain, test_good_user_basic_auth);
  tcase_add_test (tc_chain, test_bad_user_basic_auth);
  tcase_add_test (tc_chain, test_bad_password_basic_auth);
  tcase_add_test (tc_chain, test_good_user_digest_auth);
  tcase_add_test (tc_chain, test_bad_user_digest_auth);
  tcase_add_test (tc_chain, test_bad_password_digest_auth);
  if (soup_ssl_supported)
    tcase_add_test (tc_chain, test_https);

  suite_add_tcase (s, tc_internet);
  tcase_set_timeout (tc_internet, 250);
  tcase_add_test (tc_internet, test_icy_stream);

  return s;
}
예제 #25
0
파일: main.c 프로젝트: tuhaihe/gtkhash
static void read_opts_preinit(int *argc, char ***argv)
{
    GOptionEntry entries[] = {
        {
            "datadir", 'd', 0, G_OPTION_ARG_FILENAME, &opts.datadir,
            _("Read program data from the specified directory"), _("DIRECTORY")
        },
        {
            "version", 'v', 0, G_OPTION_ARG_NONE, &opts.version,
            _("Show version information"), NULL
        },
        {
            G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opts.files,
            NULL, _("[FILE|URI...]")
        },
        { NULL, 0, 0, 0, NULL, NULL, NULL }
    };

    GOptionContext *context = g_option_context_new(NULL);
    GError *error = NULL;

    g_atexit(free_opts);

    g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
    g_option_context_add_group(context, gtk_get_option_group(false));
    g_option_context_parse(context, argc, argv, &error);
    g_option_context_free(context);

    if (error) {
        g_warning("%s", error->message);
        g_error_free(error);
        exit(EXIT_FAILURE);
    }

    if (opts.version) {
        printf("%s\n", PACKAGE_STRING);
        exit(EXIT_SUCCESS);
    }
}
예제 #26
0
/* Ensures that the configuration values have been read */
static void
ensure_inited (void)
{
	if (inited)
		return;

	inited = TRUE;

	conf_client = gconf_client_get_default ();
	if (!GCONF_IS_CLIENT (conf_client)) {
		inited = FALSE;
		return;
	}

	g_atexit ((GVoidFunc) do_cleanup);

	/* load the sources for calendars and tasks */
	calendar_source_list = e_source_list_new_for_gconf (conf_client,
							    "/apps/evolution/calendar/sources");
	tasks_source_list = e_source_list_new_for_gconf (conf_client,
							 "/apps/evolution/tasks/sources");

}
예제 #27
0
파일: spi_main.c 프로젝트: GNOME/at-spi
/**
 * SPI_init:
 *
 * Connects to the accessibility registry and initializes the SPI.
 *
 * Returns: 0 on success, otherwise an integer error code.  
 **/
int
SPI_init (void)
{
  if (SPI_inited)
    {
      return 1;
    }

  SPI_inited = TRUE;

  CORBA_exception_init (&ev);

  registry = cspi_init ();

  g_atexit (cspi_cleanup);

  /* fprintf (stderr, "registry=%x\n", (int) registry); */

  if ((registry != CORBA_OBJECT_NIL) && (cspi_ping (registry)))
      return 0;
  else
      return 2;
}
예제 #28
0
static gboolean
clutter_backend_egl_post_parse (ClutterBackend  *backend,
                                GError         **error)
{
  ClutterBackendEGL *backend_egl = CLUTTER_BACKEND_EGL (backend);
  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);

  if (clutter_backend_x11_post_parse (backend, error))
    {
      EGLBoolean status;

      backend_egl->edpy =
        eglGetDisplay ((NativeDisplayType) backend_x11->xdpy);

      status = eglInitialize (backend_egl->edpy,
			      &backend_egl->egl_version_major,
			      &backend_egl->egl_version_minor);

      g_atexit (clutter_backend_at_exit);

      if (status != EGL_TRUE)
	{
	  g_set_error (error, CLUTTER_INIT_ERROR,
		       CLUTTER_INIT_ERROR_BACKEND,
		       "Unable to Initialize EGL");
	  return FALSE;
	}

    }

  CLUTTER_NOTE (BACKEND, "EGL Reports version %i.%i",
		backend_egl->egl_version_major,
		backend_egl->egl_version_minor);

  return TRUE;
}
int main(int argc, gchar * argv[])
{
    GtkWidget *vbox, *hbox;
    GtkWidget *button_select, *button_exit;
    char buf[30];
    int initial_type = 0, n, i, height, geometryflag = 0, xposition = 0, yposition = 0, width = 270;
    char *initial_name = NULL , *win_name;
    meter_t *meter;

    bindtextdomain("linuxcnc", EMC2_PO_DIR);
    setlocale(LC_MESSAGES,"");
    setlocale(LC_CTYPE,"");
    textdomain("linuxcnc");

    /* process and remove any GTK specific command line args */
    gtk_init(&argc, &argv);

    /* process my own command line args (if any) here */
    small = 0;
    n = 1;
    while ( argc > n ) {  
        if ( strcmp (argv[n], "-g") == 0 ) {
            /* This sets up the variables for initial position of window*/
            /* The last check is for the optional width request*/
	        geometryflag = 1;
	        n++;
            xposition =  atoi(argv[n]);
            n++;
            yposition =  atoi(argv[n]);
            n++;
            if ( argc > n ){
                strcpy(buf,argv[n]);
                for (i=0; i< strlen(argv[n]); i++) {
                    if (isdigit(buf[i]) == 0) { break; } 
                }
                if (strlen(argv[n]) == i){
                    width =  atoi(argv[n]);
                    n++;
                }
            } 
	    }
        if ((argc > n) && ( strcmp (argv[n], "-s") == 0 )) {
	        small = 1;
	        n++;
        }
        if (argc > n) {
	        /* check for user specified initial probe point */
	            if (strncmp(argv[n], "pin", 3) == 0) {
	                /* initial probe is a pin */
	                initial_type = 0;
	            } else if (strncmp(argv[n], "sig", 3) == 0) {
	                /* initial probe is a signal */
	                initial_type = 1;
	            } else if (strncmp(argv[n], "par", 3) == 0) {
	                /* initial probe is a parameter */
	                initial_type = 2;
	            } else {
	                printf(_("ERROR: '%s' is not a valid probe type\n"), argv[n]);
	                return -1;
	            }
	            n++;
	            if ( argc > n ) {
	                initial_name = argv[n];
                    n++;
	            } else {
	                printf(_("ERROR: no pin/signal/parameter name\n"));
	                return -1;
	            }	
        }     
    }
    if ((initial_name == NULL) && (small == 1)) {
        printf(_("ERROR: -s option requires a probe type and a pin/signal/parameter name\n"));
        return -1;
    }

    /* create a unique module name */
    snprintf(buf, 29, "halmeter-%d", getpid());
    /* connect to the HAL */
    comp_id = hal_init(buf);
    if (comp_id < 0) {
	return -1;
    }
    hal_ready(comp_id);
    /* register an exit function to disconnect from the HAL */
    g_atexit(exit_from_hal);
    /* capture INT (ctrl-C) and TERM signals */
    signal(SIGINT, quit);
    signal(SIGTERM, quit);

    /* create main window, set it's size, and lock the size */
    main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    /* ideally this wouldn't be fixed size in pixels */
    if ( small ) {
	height = 22;
	win_name = initial_name;
    } else {
	height = 80;
	win_name = _("Hal Meter");
    }
    gtk_widget_set_usize(GTK_WIDGET(main_window), width, height);
    gtk_window_set_policy(GTK_WINDOW(main_window), FALSE, FALSE, FALSE);
    /* set main window title */
    gtk_window_set_title(GTK_WINDOW(main_window), win_name);
    /* this makes the application exit when the window is closed */
    gtk_signal_connect(GTK_OBJECT(main_window), "destroy",
	GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

    /* a vbox to hold the displayed value and the pin/sig/param name */
    vbox = gtk_vbox_new(FALSE, 3);
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 2);
    /* add the vbox to the main window */
    gtk_container_add(GTK_CONTAINER(main_window), vbox);
    gtk_widget_show(vbox);

    /* create a meter object */
    meter = meter_new();
    if (meter == NULL) {
    printf("null meter\n");
	exit(-1);
    }

    /* set up for initial probe, if any */
    if (initial_name != NULL) {
	meter->probe->pickname = initial_name;
	meter->probe->listnum = initial_type;
	apply_selection(NULL, meter->probe);
    }

    /* add the meter's value label to the vbox */
    gtk_box_pack_start(GTK_BOX(vbox), meter->value_label, TRUE, TRUE, 0);
    gtk_widget_show(meter->value_label);

    /* add the meter's name label to the vbox */
    if ( !small ) {
	gtk_box_pack_start(GTK_BOX(vbox), meter->name_label, TRUE, TRUE, 0);
	gtk_widget_show(meter->name_label);
    }

    /* arrange for periodic refresh of the value */
    gtk_timeout_add(100, refresh_value, meter);

    /* an hbox to hold the select and exit buttons */
    if ( !small ) {
	hbox = gtk_hbox_new_in_box(FALSE, 0, 0, vbox, FALSE, TRUE, 0);

	/* create the buttons and add them to the hbox */
	button_select = gtk_button_new_with_label(_("_Select"));
	button_exit = gtk_button_new_with_label(_("E_xit"));
	gtk_button_set_use_underline((GtkButton *)button_select, TRUE);
	gtk_button_set_use_underline((GtkButton *)button_exit, TRUE);

	gtk_box_pack_start(GTK_BOX(hbox), button_select, TRUE, TRUE, 4);
	gtk_box_pack_start(GTK_BOX(hbox), button_exit, TRUE, TRUE, 4);

	/* make the application exit when the 'exit' button is clicked */
	gtk_signal_connect(GTK_OBJECT(button_exit), "clicked",
	    GTK_SIGNAL_FUNC(gtk_main_quit), NULL);

	/* activate selection window when the 'select' button is clicked */
	gtk_signal_connect(GTK_OBJECT(button_select), "clicked",
	    GTK_SIGNAL_FUNC(popup_probe_window), meter->probe);

	/* save reference to select button */
	meter->button_select = button_select;

	gtk_widget_show(button_select);
	gtk_widget_show(button_exit);
    }

    /* The interface is now set up so we show the window and
       enter the gtk_main loop. */
    gtk_widget_show(main_window);
    /* If the -g option was invoked: set position */
    if (geometryflag == 1) {
        gtk_window_move(GTK_WINDOW(main_window),xposition,yposition);
    }
    gtk_main();

    return (0);
}
예제 #30
0
/*
 * cmdc() -- command completion function.
 *
 * cmdc takes a char* and returns a GList* of possible completions.
 *
 * Initial version by Travis Hume <*****@*****.**>.
 *
 */
static GList *
cmdc( char *s )
{
   GCompletion        *completion  = NULL;
   GList              *ret_list     = NULL;
   static GHashTable  *path_hash    = NULL;
   static char        *path        = NULL;
   gchar              *path_elem;
   struct stat         buf;
   static gboolean     inited      = FALSE;
   gpointer            hash_key     = NULL;


   /*
    * Only want to build the GCompletion once.  At some point I'd like to add
    * code to refresh the GCompletion, either at a regular interval, or when
    * there is a completion failure, ...
    *
    */
   if(!inited)
   {
      /* Make a local copy of the path variable. Otherwise the path
         environment variable would be modified. */
      path = (char *) malloc(sizeof(char) * (strlen(getenv("PATH")) + 1));
      strcpy(path, getenv("PATH"));
      
      path_hash = g_hash_table_new( g_str_hash, g_str_equal );

      for( path_elem = strtok( path, ":" ); path_elem;
            path_elem = strtok( NULL, ":" ))
      {
         if( stat( path_elem, &buf ))
            continue;

         if( buf.st_mode & S_IFDIR )
         {
            /* keep a hash of processed paths, to avoid reprocessing
             * dupped path entries.
             */
            hash_key = g_hash_table_lookup( path_hash, path_elem );
            if( hash_key )
               continue;   /* duplicate $PATH entry */
            else
            {
               g_hash_table_insert(
                     path_hash, (gpointer)path_elem, (gpointer)path_elem );

               process_dir( path_elem );
            }
         }
      }

      /* atexit() we want to free the completion. */
      g_atexit( cleanup );

      inited = TRUE;
   }

   completion = g_completion_new( NULL );
   g_completion_add_items( completion, path_elements );
   ret_list = g_list_copy( g_completion_complete( completion, s, NULL ));
   g_completion_free( completion );

   return g_list_sort( ret_list, (GCompareFunc)g_list_str_cmp );
}