Esempio n. 1
0
int get_catalog_file(struct domainbinding *binding, I18N_STRING catalog_file)
{
	int rc = I18N_SUCCESS;
	I18N_STRING locale;
	if ((rc = get_locale(locale)) == I18N_SUCCESS)
	{
		I18N_STRING separator;
		get_separator(separator);
		char *domain = textdomain(NULL);

		safe_strncpy(catalog_file, I18N_STRING_LEN, binding->path, I18N_STRING_LEN);

		safe_strncat(catalog_file, I18N_STRING_LEN, separator, I18N_STRING_LEN);

		safe_strncat(catalog_file, I18N_STRING_LEN, locale, I18N_STRING_LEN);

		safe_strncat(catalog_file, I18N_STRING_LEN, separator, I18N_STRING_LEN);

		safe_strncat(catalog_file, I18N_STRING_LEN, messages, I18N_STRING_LEN);

		safe_strncat(catalog_file, I18N_STRING_LEN, separator, I18N_STRING_LEN);

		safe_strncat(catalog_file, I18N_STRING_LEN, domain, I18N_STRING_LEN);

		safe_strncat(catalog_file, I18N_STRING_LEN, ".mo", I18N_STRING_LEN);

	}
	return rc;
}
Esempio n. 2
0
static void
do_ForEachFile(
	const Fchar *fn,
	void (*proc)(const Fchar *, const char *, const struct stat *),
	int max_depth
) {
	Fchar fname[MAX_FILE_NAME_LENGTH];
	Fchar separator;

	Fnamecpy(fname, (!fn || !*fn) ? str2Fname(".") : fn);
	separator = get_separator(fname);
	if (!separator) {
		(*proc)(fname, "both / and \\ used as separators", 0);
		return;
	}

	clean_name(fname, separator);
	do_FEF(fname, proc, -1, (struct ino_link *)0, separator, max_depth);
}
Esempio n. 3
0
int get_catalog_file(struct domainbinding *binding, I18N_STRING catalog_file)
{
	int rc = I18N_SUCCESS;
	I18N_STRING locale;

	get_locale(locale);
	char *separator = get_separator();

	safe_strncpy(catalog_file, I18N_STRING_LEN, binding->path, I18N_STRING_LEN);

	safe_strncat(catalog_file, I18N_STRING_LEN, separator, I18N_STRING_LEN);

	safe_strncat(catalog_file, I18N_STRING_LEN, "lang", I18N_STRING_LEN);

	safe_strncat(catalog_file, I18N_STRING_LEN, separator, I18N_STRING_LEN);

	safe_strncat(catalog_file, I18N_STRING_LEN, locale, safe_strnlen(locale, I18N_STRING_LEN));

	safe_strncat(catalog_file, I18N_STRING_LEN, ".mo", I18N_STRING_LEN);

	return rc;
}
Esempio n. 4
0
GSList* get_menu_data(gboolean show_search, gboolean show_run, gboolean show_places, gboolean show_logout, char* file_manager, char*logout)
{
  /*FIXME... I'm leaking a bit of memory here */

  Menu_list_item * dir_item;
  GSList*  data = NULL;
  GMenuTree *  menu_tree;
  const char * menu_file[] = {"gnomecc.menu", "preferences.menu", "settings.menu", NULL};//
  GMenuTreeDirectory *root;
  int i;

  if (!gnome_vfs_initialized())
    gnome_vfs_init();

  G_file_manager = file_manager;

  menu_tree = gmenu_tree_lookup("applications.menu", GMENU_TREE_FLAGS_NONE);

  if (menu_tree)
  {
    root = gmenu_tree_get_root_directory(menu_tree);

    if (root)
    {
      fill_er_up(root, &data);
      gmenu_tree_item_unref(root);
    }
  }


  data = g_slist_prepend(data, get_blank());

  data = g_slist_append(data, get_separator());

  menu_tree = gmenu_tree_lookup("gnomecc.menu", GMENU_TREE_FLAGS_NONE);

  if (menu_tree)
  {
    root = gmenu_tree_get_root_directory(menu_tree);

    if (root)
    {
      dir_item = g_malloc(sizeof(Menu_list_item));
      dir_item->item_type = MENU_ITEM_DIRECTORY;
      dir_item->name = g_strdup("Control Centre");
      dir_item->comment = g_strdup("Gnome Control Centre");
      dir_item->null = NULL;
      dir_item->sublist = NULL;
      dir_item->icon = g_strdup("gnome-control-center");
      data = g_slist_append(data, dir_item);

      fill_er_up(root, &dir_item->sublist);
      dir_item->sublist = g_slist_prepend(dir_item->sublist, get_blank());
      dir_item->sublist = g_slist_append(dir_item->sublist, get_blank());
      gmenu_tree_item_unref(root);
    }
  }

  menu_tree = gmenu_tree_lookup("settings.menu", GMENU_TREE_FLAGS_NONE);

  if (menu_tree)
  {
    root = gmenu_tree_get_root_directory(menu_tree);

    if (root)
    {
      dir_item = g_malloc(sizeof(Menu_list_item));
      dir_item->item_type = MENU_ITEM_DIRECTORY;
      dir_item->name = g_strdup("Settings");
      dir_item->comment = g_strdup("System Settings");
      dir_item->sublist = NULL;
      dir_item->null = NULL;
      dir_item->icon = g_strdup("gnome-settings");
      data = g_slist_append(data, dir_item);

      fill_er_up(root, &dir_item->sublist);
      dir_item->sublist = g_slist_prepend(dir_item->sublist, get_blank());
      dir_item->sublist = g_slist_append(dir_item->sublist, get_blank());
      gmenu_tree_item_unref(root);
    }
  }

  data = g_slist_append(data, get_separator());


  if (show_places)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_DIRECTORY;
    dir_item->name = g_strdup("Places");
    dir_item->icon = g_strdup("bookmark");
    dir_item->comment = g_strdup("Your special places :-)");
    dir_item->sublist = NULL;
    dir_item->monitor = monitor_places;
    data = g_slist_append(data, dir_item);
    update_places(&dir_item->sublist, file_manager);
  }

  if (show_search)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_SEARCH;
    dir_item->name = g_strdup("Find:");
    dir_item->icon = g_strdup("stock_search");
    dir_item->comment = g_strdup("Search");
    dir_item->sublist = NULL;
    dir_item->search_entry = NULL;
    data = g_slist_append(data, dir_item);
  }

  if (show_run)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_RUN;
    dir_item->name = g_strdup("Run:");
    dir_item->icon = g_strdup("exec");
    dir_item->comment = g_strdup("Run a program");
    dir_item->sublist = NULL;
    dir_item->search_entry = NULL;
    data = g_slist_append(data, dir_item);

  }



  if (show_logout)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_ENTRY;
    dir_item->name = g_strdup("Logout...");
    dir_item->icon = g_strdup("gnome-logout");
    dir_item->exec = g_strdup(logout);
    dir_item->desktop = g_strdup("");
    dir_item->comment = g_strdup("Logout and related activities.");
    dir_item->sublist = NULL;
    data = g_slist_append(data, dir_item);

  }

  data = g_slist_append(data, get_blank());

  return data;
}
Esempio n. 5
0
static void update_places(Menu_list_item **p, char* file_manager)
{
  static GnomeVFSVolumeMonitor* vfsvolumes = NULL;
  Menu_list_item * sublist = *p;
  Menu_list_item * item;


  sublist = g_slist_append(sublist, get_blank());


  item = g_malloc(sizeof(Menu_list_item));
  item->item_type = MENU_ITEM_ENTRY;
  item->name = g_strdup("Home");
  item->icon = g_strdup("stock_home");
  const char *homedir = g_getenv("HOME");

  if (!homedir)
    homedir = g_get_home_dir();

  item->exec = g_strdup_printf("%s %s", file_manager, homedir);

  item->comment = g_strdup("Your Home Directory");

  item->desktop = g_strdup("");

  sublist = g_slist_append(sublist, item);

  item = g_malloc(sizeof(Menu_list_item));

  item->item_type = MENU_ITEM_ENTRY;

  item->name = g_strdup("File System");

  item->icon = g_strdup("stock_folder");

  item->exec = g_strdup_printf("%s /", file_manager);

  item->comment = g_strdup("Root File System");

  item->desktop = g_strdup("");

  sublist = g_slist_append(sublist, item);

//mount monitor
  if (!vfsvolumes)
  {
    vfsvolumes = gnome_vfs_get_volume_monitor();
    g_signal_connect(G_OBJECT(vfsvolumes), "volume-mounted", G_CALLBACK(_vfs_changed_v_m), NULL);
    g_signal_connect(G_OBJECT(vfsvolumes), "volume-unmounted", G_CALLBACK(_vfs_changed_v_u), NULL);
    g_signal_connect(G_OBJECT(vfsvolumes), "drive-disconnected" , G_CALLBACK(_vfs_changed_d_d), NULL);
    g_signal_connect(G_OBJECT(vfsvolumes), "drive-connected", G_CALLBACK(_vfs_changed_d_c), NULL);
  }

  GList *connected = gnome_vfs_volume_monitor_get_connected_drives(vfsvolumes);

  if (connected)
    g_list_foreach(connected, _fillin_connected, &sublist);

  g_list_free(connected);


  sublist = g_slist_append(sublist, get_separator());

/*bookmarks*/
  FILE* handle;

  gchar *  filename = g_strdup_printf("%s/.gtk-bookmarks", homedir);

  handle = g_fopen(filename, "r");

  if (handle)
  {
    char * line = NULL;
    size_t  len = 0;

    while (getline(&line, &len, handle) != -1)
    {
      gchar ** tokens;
      tokens = g_strsplit(line, " ", 2);

      if (tokens)
      {
        if (tokens[0])
        {
          gchar * shell_quoted;
          g_strstrip(tokens[0]);
          item = g_malloc(sizeof(Menu_list_item));
          item->item_type = MENU_ITEM_ENTRY;

          if (tokens[1])
          {
            g_strstrip(tokens[1]);
            item->name = g_strdup(tokens[1]);
          }
          else
          {
            item->name = urldecode(g_path_get_basename(tokens[0]), NULL);
          }

          item->icon = g_strdup("stock_folder");

          shell_quoted = g_shell_quote(tokens[0]);
          item->exec = g_strdup_printf("%s %s", file_manager, shell_quoted);
          item->comment = urldecode(g_strdup(shell_quoted),NULL);
          g_free(shell_quoted);
          item->desktop = g_strdup("");
          sublist = g_slist_append(sublist, item);

        }

      }

      g_strfreev(tokens);

      free(line);

      line = NULL;
    }

    fclose(handle);

    g_free(filename);
  }
  else
  {
    printf("Unable to open bookmark file: %s/.gtk-bookmarks\n", homedir);
  }
  sublist = g_slist_append(sublist, get_blank());

  *p = sublist;
}
Esempio n. 6
0
readstat_error_t readstat_parse_csv(readstat_parser_t *parser, const char *path, const char *jsonpath, struct csv_metadata* md, void *user_ctx) {
    readstat_error_t retval = READSTAT_OK;
    readstat_io_t *io = parser->io;
    size_t file_size = 0;
    size_t bytes_read;
    struct csv_parser csvparser;
    struct csv_parser *p = &csvparser;
    char buf[BUFSIZ];
    size_t* column_width = md->column_width;
    md->pass = column_width ? 2 : 1;
    md->open_row = 0;
    md->columns = 0;
    md->_rows = md->rows;
    md->rows = 0;
    md->parser = parser;
    md->user_ctx = user_ctx;
    md->json_md = NULL;

    if ((md->json_md = get_json_metadata(jsonpath)) == NULL) {
        fprintf(stderr, "Could not get JSON metadata\n");
        retval = READSTAT_ERROR_PARSE;
        goto cleanup;
    }

    if (io->open(path, io->io_ctx) == -1) {
        retval = READSTAT_ERROR_OPEN;
        goto cleanup;
    }

    file_size = io->seek(0, READSTAT_SEEK_END, io->io_ctx);
    if (file_size == -1) {
        retval = READSTAT_ERROR_SEEK;
        goto cleanup;
    }

    if (io->seek(0, READSTAT_SEEK_SET, io->io_ctx) == -1) {
        retval = READSTAT_ERROR_SEEK;
        goto cleanup;
    }

    if (csv_init(p, CSV_APPEND_NULL) != 0)
    {
        retval = READSTAT_ERROR_OPEN;
        goto cleanup;
    }
    unsigned char sep = get_separator(md->json_md);
    csv_set_delim(p, sep);
    
    while ((bytes_read = io->read(buf, sizeof(buf), io->io_ctx)) > 0)
    {
        if (csv_parse(p, buf, bytes_read, csv_metadata_cell, csv_metadata_row, md) != bytes_read)
        {
            fprintf(stderr, "Error while parsing file: %s\n", csv_strerror(csv_error(p)));
            retval = READSTAT_ERROR_PARSE;
            goto cleanup;
        }
    }
    csv_fini(p, csv_metadata_cell, csv_metadata_row, md);
    if (!md->open_row) {
        md->rows--;
    }
    if (parser->info_handler && md->pass == 1) {
        parser->info_handler(md->rows, md->_columns, user_ctx);
    }

cleanup:
    if (md->variables) {
        free(md->variables);
        md->variables = NULL;
    }
    if (md->is_date) {
        free(md->is_date);
        md->is_date = NULL;
    }
    if (md->json_md) {
        free_json_metadata(md->json_md);
        md->json_md = NULL;
    }
    csv_free(p);
    io->close(io->io_ctx);
    return retval;
}