예제 #1
0
파일: dirtree.c 프로젝트: gentoo/pornview
void
dirtree_refresh_node (DirTree * dt, GtkCTreeNode * node)
{
    DirTreeNode *dirnode = NULL;
    gint    has_subdirs;
    gboolean expanded;

    dirnode = gtk_ctree_node_get_row_data (GTK_CTREE (dt), node);

    has_subdirs = tree_is_subdirs (dirnode->path, dt->show_dotfile);

    if (has_subdirs && GTK_CTREE_ROW (node)->expanded == 1)
	expanded = TRUE;
    else
	expanded = FALSE;

    if (has_subdirs)
	gtk_ctree_set_node_info (GTK_CTREE (dt), node,
				 g_basename (dirnode->path), CTREE_SPACING,
				 folder_pixmap, folder_mask, ofolder_pixmap,
				 ofolder_mask, FALSE, expanded);
    else
	gtk_ctree_set_node_info (GTK_CTREE (dt), node,
				 g_basename (dirnode->path), CTREE_SPACING,
				 folder_pixmap, folder_mask, ofolder_pixmap,
				 ofolder_mask, TRUE, expanded);
}
예제 #2
0
파일: thumbview.c 프로젝트: gentoo/pornview
static GtkWidget *
create_scripts_submenu (ThumbView * tv)
{
    GtkWidget *menu;
    GtkWidget *menu_item;
    GList  *tmplist = NULL, *filelist = NULL, *list;
    gchar **dirs;
    gint    i, flags;

    menu = gtk_menu_new ();

    dirs = g_strsplit (conf.scripts_search_dir_list, ",", -1);
    if (!dirs)
	return NULL;

    flags = 0 | GETDIR_FOLLOW_SYMLINK;
    for (i = 0; dirs[i]; i++)
    {
	if (!*dirs || !isdir (dirs[i]))
	    continue;
	get_dir (dirs[i], flags, &tmplist, NULL);
	filelist = g_list_concat (filelist, tmplist);
    }
    g_strfreev (dirs);

    for (list = filelist; list; list = g_list_next (list))
    {
	gchar  *filename = list->data;
	gchar  *label;

	if (!filename || !*filename || !isexecutable (filename))
	    continue;

	if (conf.scripts_show_dialog)
	    label = g_strconcat (g_basename (filename), "...", NULL);
	else
	    label = g_strdup (g_basename (filename));

	menu_item = gtk_menu_item_new_with_label (label);
	gtk_object_set_data_full (GTK_OBJECT (menu_item),
				  "script",
				  g_strdup (filename),
				  (GtkDestroyNotify) g_free);
	gtk_signal_connect (GTK_OBJECT (menu_item),
			    "activate",
			    GTK_SIGNAL_FUNC (cb_open_image_by_script), tv);
	gtk_menu_append (GTK_MENU (menu), menu_item);
	gtk_widget_show (menu_item);

	g_free (label);
    }

    g_list_foreach (filelist, (GFunc) g_free, NULL);
    g_list_free (filelist);

    return menu;
}
예제 #3
0
파일: tag.c 프로젝트: LordJZ/libflac
/*
 * Function flac_format_song_title (tag, filename)
 *
 *    Create song title according to `tag' and/or `filename' and
 *    return it.  The title must be subsequently freed using g_free().
 *
 */
char *flac_format_song_title(char *filename)
{
	char *ret = NULL;
	TitleInput *input = NULL;
	FLAC__StreamMetadata *tags;
	char *title, *artist, *performer, *album, *date, *tracknumber, *genre, *description;

	FLAC_plugin__tags_get(filename, &tags);

	title       = local__getfield(tags, "TITLE");
	artist      = local__getfield(tags, "ARTIST");
	performer   = local__getfield(tags, "PERFORMER");
	album       = local__getfield(tags, "ALBUM");
	date        = local__getfield(tags, "DATE");
	tracknumber = local__getfield(tags, "TRACKNUMBER");
	genre       = local__getfield(tags, "GENRE");
	description = local__getfield(tags, "DESCRIPTION");

	XMMS_NEW_TITLEINPUT(input);

	input->performer = local__getstr(artist);
	if(!input->performer)
		input->performer = local__getstr(performer);
	input->album_name = local__getstr(album);
	input->track_name = local__getstr(title);
	input->track_number = local__getnum(tracknumber);
	input->year = local__getnum(date);
	input->genre = local__getstr(genre);
	input->comment = local__getstr(description);

	input->file_name = g_basename(filename);
	input->file_path = filename;
	input->file_ext = local__extname(filename);
	ret = xmms_get_titlestring(flac_cfg.title.tag_override ? flac_cfg.title.tag_format : xmms_get_gentitle_format(), input);
	g_free(input);

	if (!ret) {
		/*
		 * Format according to filename.
		 */
		ret = g_strdup(g_basename(filename));
		if (local__extname(ret) != NULL)
			*(local__extname(ret) - 1) = '\0';	/* removes period */
	}

	FLAC_plugin__tags_destroy(&tags);
	local__safe_free(title);
	local__safe_free(artist);
	local__safe_free(performer);
	local__safe_free(album);
	local__safe_free(date);
	local__safe_free(tracknumber);
	local__safe_free(genre);
	local__safe_free(description);
	return ret;
}
예제 #4
0
static void
notify_func (GConfClient *client, guint cnxn_id, GConfEntry *entry,
	     gpointer user_data)
{
	GnocamApplet *a = GNOCAM_APPLET (user_data);
	GnocamAppletCam *c;
	const gchar *b = g_basename (entry->key);
	gchar *id;

	if (!strcmp (entry->key, "/desktop/gnome/cameras")) return;

	g_message ("Key: '%s'", entry->key);
	if (!entry->value) {
		c = g_hash_table_lookup (a->priv->cameras, entry->key);
		if (c) {
			gtk_object_destroy (GTK_OBJECT (c));
			g_hash_table_remove (a->priv->cameras, entry->key);
		}
	} else {
		if (strcmp (b, "name") && strcmp (b, "manufacturer") &&
		    strcmp (b, "model") && strcmp (b, "port")) return;
		
		id = g_path_get_dirname (entry->key);
		c = g_hash_table_lookup (a->priv->cameras, id);
		if (!c) c = gnocam_applet_add_cam (a, id);
		g_object_set (c, b, gconf_value_get_string (entry->value),
			      NULL);
		g_free (id);
	}
}
예제 #5
0
파일: uri.c 프로젝트: azuwis/mpd
/* suffixes should be ascii only characters */
const char *
uri_get_suffix(const char *uri)
{
	const char *dot = strrchr(g_basename(uri), '.');

	return dot != NULL ? dot + 1 : NULL;
}
예제 #6
0
/* 
 * shows only the file name instead of a full path
 */
static void on_render_filename(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *tree_model,
	GtkTreeIter *iter, gpointer data)
{
	GtkTreePath *tpath = gtk_tree_model_get_path(model, iter);
	
	if (1 != gtk_tree_path_get_depth(tpath))
	{
		gchar *path = NULL;
		gtk_tree_model_get(model, iter, S_FILEPATH, &path, -1);

		const gchar *name = path ? g_basename(path) : NULL;
		g_object_set(cell, "text", name ? name : path, NULL);

		if (path)
		{
			g_free(path);
		}
	}
	else
	{
		g_object_set(cell, "text", "", NULL);
	}

	gtk_tree_path_free(tpath);
}
예제 #7
0
static gchar *prettyTitle(const gchar *path)
{
  const gchar *name  = g_basename(path);
  gchar *title = g_strconcat("Gnome Layout Sample - ", name, NULL);

  return title;
}
예제 #8
0
struct dirent*
gwin_readdir (DIR *dir)
{
  static struct dirent result;

  g_return_val_if_fail (dir != NULL, NULL);

  if (dir->just_opened)
    dir->just_opened = FALSE;
  else
    {
      if (!FindNextFile ((HANDLE) dir->find_file_handle,
			 (LPWIN32_FIND_DATA) dir->find_file_data))
	{
	  int error = GetLastError ();

	  switch (error)
	    {
	    case ERROR_NO_MORE_FILES:
	      return NULL;
	    default:
	      errno = EIO;
	      return NULL;
	    }
	}
    }
  strcpy (result.d_name, g_basename (((LPWIN32_FIND_DATA) dir->find_file_data)->cFileName));

  return &result;
}
예제 #9
0
파일: icon.c 프로젝트: atsampson/rox-filer
/* Sets, unsets or changes the pathname and name for an icon.
 * Updates icons_hash and (re)stats the item.
 * If name is NULL then gets the leafname from pathname.
 * If pathname is NULL, frees everything.
 */
void icon_set_path(Icon *icon, const char *pathname, const char *name)
{
	if (icon->path)
	{
		icon_unhash_path(icon);
		icon->src_path = NULL;
		icon->path = NULL;

		diritem_free(icon->item);
		icon->item = NULL;
	}

	if (pathname)
	{
		if (g_utf8_validate(pathname, -1, NULL))
			icon->src_path = g_strdup(pathname);
		else
			icon->src_path = to_utf8(pathname);
		icon->path = expand_path(icon->src_path);

		icon_hash_path(icon);

		if (!name)
			name = g_basename(icon->src_path);

		icon->item = diritem_new(name);
		diritem_restat(icon->path, icon->item, NULL);
	}
}
예제 #10
0
파일: browser.c 프로젝트: gentoo/pornview
void
browser_select_dir (gchar * path)
{
    gchar  *title;
    char    buf[PATH_MAX];

    if (!strcmp (browser->last_path->str, path))
	return;

#ifdef ENABLE_MOVIE
    videoplay_clear ();
#endif
    comment_view_clear (commentview);
    thumbview_stop ();
    imageview_stop ();

    viewtype_set (VIEWTYPE_IMAGEVIEW);

    g_string_assign (browser->last_path, path);
    g_string_assign (browser->current_path, path);

    thumbview_clear ();

    file_list_create (browser->filelist, path);

    title = g_strconcat ("PornView - ", g_basename (path), NULL);
    gtk_window_set_title (GTK_WINDOW (browser->window), title);
    g_free (title);

    snprintf (buf, PATH_MAX, "  %d", browser->filelist->num);
    gtk_statusbar_pop (GTK_STATUSBAR (BROWSER_STATUS_DIR), 1);
    gtk_statusbar_push (GTK_STATUSBAR (BROWSER_STATUS_DIR), 1, buf);

    thumbview_add (browser->filelist);
}
예제 #11
0
bs_file_info_t*
hdfs_list_dir(struct back_storage * storage,const char * dir_path,uint32_t* num_entries){
	//HLOG_DEBUG("hdfs -- enter func %s", __func__);
    char full_path[256];
    build_hdfs_path(full_path,storage->dir,storage->fs_name,dir_path);
    int num;
    hdfsFileInfo *hinfos  = hdfsListDirectory((hdfsFS)storage->fs_handler,full_path,&num);
    if(NULL == hinfos){
	   //HLOG_ERROR("hdfsListDirectory error");
       return NULL; 
    }
    hdfsFileInfo *hinfo = hinfos;
    bs_file_info_t *infos = (bs_file_info_t*)g_malloc0(sizeof(bs_file_info_t)*8192);
    if (NULL == infos) {
	    //HLOG_ERROR("Allocate Error!");
	    return NULL;
    }
    bs_file_info_t *info = infos;
    int i;
    for(i=0;i<num;i++){
        strcpy((char *) info->name, (const char *) g_basename(hinfo->mName));
        info->is_dir = 0;//?
        info->size =   hinfo->mSize;
        info->lmtime = hinfo->mLastMod;
        info++;
        hinfo++;
    }
    free(hinfos);
    *num_entries = num;
	//HLOG_DEBUG("hdfs -- leave func %s", __func__);
    return infos;
}
예제 #12
0
gchar* my_basename(const gchar *file_name){
#ifdef USE_GTK2
  return(g_path_get_basename(file_name));
#else
  return(g_basename(file_name));
#endif
}
예제 #13
0
파일: botnet.c 프로젝트: svn2github/irssi
int botnet_send_file(BOTNET_REC *botnet, const char *target, const char *fname)
{
	GNode *node;
	GString *str;
	char buffer[1024];
	int f, len;

	node = bot_find_path(botnet, target);
	if (node == NULL) {
		g_warning("Can't find route for target %s", target);
		return FALSE;
	}

	f = open(fname, O_RDONLY);
	if (f == -1) return FALSE;

	str = g_string_new(NULL);

	g_string_sprintf(str, "%s %s FILE %s", botnet->nick, target, g_basename(fname));
	bot_send_cmd(node->data, str->str);

	while ((len = read(f, buffer, sizeof(buffer)/2-2)) > 0) {
		escape_buffer(buffer, len);

		g_string_sprintf(str, "%s %s FILE %s", botnet->nick, target, buffer);
		bot_send_cmd(node->data, str->str);
	}

	g_string_sprintf(str, "%s %s FILE", botnet->nick, target);
	bot_send_cmd(node->data, str->str);
	g_string_free(str, TRUE);

	close(f);
	return TRUE;
}
예제 #14
0
static gchar *
gen_context(const char *file_name,
            const char *file_path)
{
    struct stat st;
    gsize size = 0;
    MsnContextHeader header;
    gchar *u8 = NULL;
    guchar *base;
    guchar *n;
    gchar *ret;
    gunichar2 *uni = NULL;
    glong currentChar = 0;
    glong uni_len = 0;
    gsize len;

    if (g_stat(file_path, &st) == 0)
        size = st.st_size;

    if(!file_name) {
        u8 = purple_utf8_try_convert(g_basename(file_path));
        file_name = u8;
    }

    uni = g_utf8_to_utf16(file_name, -1, NULL, &uni_len, NULL);

    if(u8) {
        g_free(u8);
        file_name = NULL;
        u8 = NULL;
    }

    len = sizeof(MsnContextHeader) + MAX_FILE_NAME_LEN + 4;

    header.length = GUINT32_TO_LE(len);
    header.unk1 = GUINT32_TO_LE(2);
    header.file_size = GUINT32_TO_LE(size);
    header.unk2 = GUINT32_TO_LE(0);
    header.unk3 = GUINT32_TO_LE(0);

    base = g_malloc(len + 1);
    n = base;

    memcpy(n, &header, sizeof(MsnContextHeader));
    n += sizeof(MsnContextHeader);

    memset(n, 0x00, MAX_FILE_NAME_LEN);
    for(currentChar = 0; currentChar < uni_len; currentChar++) {
        *((gunichar2 *)n + currentChar) = GUINT16_TO_LE(uni[currentChar]);
    }
    n += MAX_FILE_NAME_LEN;

    memset(n, 0xFF, 4);
    n += 4;

    g_free(uni);
    ret = purple_base64_encode(base, len);
    g_free(base);
    return ret;
}
예제 #15
0
static void mimeview_drag_data_get(GtkWidget	    *widget,
				   GdkDragContext   *drag_context,
				   GtkSelectionData *selection_data,
				   guint	     info,
				   guint	     time,
				   MimeView	    *mimeview)
{
	gchar *filename, *uriname;
	MimeInfo *partinfo;

	if (!mimeview->opened) return;
	if (!mimeview->file) return;

	partinfo = mimeview_get_selected_part(mimeview);
	if (!partinfo) return;

	filename = g_basename(get_part_name(partinfo));
	if (*filename == '\0') return;

	filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
			       filename, NULL);

	if (procmime_get_part(filename, partinfo) < 0)
		alertpanel_error
			(_("Can't save the part of multipart message."));

	uriname = g_strconcat("file://", filename, NULL);
	gtk_selection_data_set(selection_data, selection_data->target, 8,
			       uriname, strlen(uriname));

	g_free(uriname);
	g_free(filename);
}
예제 #16
0
static char *script_file_get_name(const char *path)
{
	char *name;

        name = g_strdup(g_basename(path));
	script_fix_name(name);
        return name;
}
예제 #17
0
파일: log.c 프로젝트: eisnerd/rox-filer
/* Record a message in the log.
 * paths is the list of items being processed, if any
 * path is a single path (if only one is being processed)
 * paths and path may both be given (e.g. for copying or moving)
 */
void log_info_paths(const gchar *message, GList *paths, const gchar *path)
{
	GtkTreeIter iter;
	char timestamp[32];
	time_t t;
	struct tm *now;
	char *actual_message = NULL;
	int n_paths;

	if (!message)
		message = "(no log message!)";

	t = time(NULL);
	now = localtime(&t);

	if (now == NULL || !strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M", now))
	{
		g_warning("Failed to generate timestamp!");
		strcpy(timestamp, "ERROR");
	}

	gtk_tree_store_append(log, &iter, NULL);

	n_paths = g_list_length(paths);

	if (path == NULL && n_paths == 1)
	{
		/* Promote the single item to the main path */
		path = paths->data;
		paths = NULL;
		n_paths = 0;
	}

	if (n_paths == 1)
		actual_message = g_strdup_printf(_("%s '%s'"), message, g_basename((char *) paths->data));
	else if (n_paths > 1)
		actual_message = g_strdup_printf(_("%s on %d items"), message, n_paths);

	gtk_tree_store_set(log, &iter,
			TIMESTAMP, timestamp,
			DIRECTORY, path,
			MESSAGE, actual_message ? actual_message : message,
			-1);

	while (paths)
	{
		GtkTreeIter child_iter;
		gtk_tree_store_append(log, &child_iter, &iter);
		gtk_tree_store_set(log, &child_iter,
				MESSAGE, _("Item"),
				DIRECTORY, paths->data,
				-1);
		paths = paths->next;
	}

	g_free(actual_message);
}
static void
on_directory_changed (GFileMonitor     *file_monitor,
		      GFile            *file,
		      GFile            *other_file,
		      GFileMonitorEvent event_type,
		      gpointer          user_data)
{
  WebappMonitor *monitor = (WebappMonitor *) user_data;

  g_debug ("%s called", G_STRFUNC);

  if (event_type == G_FILE_MONITOR_EVENT_CREATED) {
     GError *error = NULL;
     gchar *contents;
     gsize len;
     const gchar *file_path = g_file_get_path (file);

     if (!g_str_has_prefix (g_basename (file_path), "chrome-"))
       return;

     if (g_file_get_contents (file_path, &contents, &len, &error)) {
       gchar *tmp = contents;
       const gchar *shebang = "#!/usr/bin/env xdg-open";

       g_debug ("Old contents = %s\n", contents);

       /* Read 1st line */
       if (g_str_has_prefix (contents, shebang)) {
	 tmp += strlen (shebang);
	 if (*tmp == '[') {
	   GString *new_contents = g_string_new (shebang);

	   new_contents = g_string_append (new_contents, "\n");
	   new_contents = g_string_append (new_contents, tmp);

	   if (!g_file_set_contents (file_path, new_contents->str, new_contents->len, &error)) {
	     g_warning ("Could not write %s file: %s", file_path, error->message);
	     g_error_free (error);
	   } else {
	     g_debug ("New contents: %s\n", new_contents->str);
	     retrieve_highres_icon (monitor, new_contents->str);
	   }

	   g_string_free (new_contents, TRUE);
	 }
       } else
	 retrieve_highres_icon (monitor, contents);

       g_free (contents);

     } else {
       g_warning ("Could not read %s file: %s", file_path, error->message);
       g_error_free (error);
     }
  }
}
예제 #19
0
/*
 * ============================================================================
 * Parse directory and filename from full export file specification.
 * Enter:  ctl      Export control data.
 *         fileSpec File spec.
 * ============================================================================
 */
void exporthtml_parse_filespec( ExportHtmlCtl *ctl, gchar *fileSpec ) {
	gchar *t;

	ctl->fileHtml =
		mgu_replace_string( ctl->fileHtml, g_basename( fileSpec ) );
	t = g_dirname( fileSpec );
	ctl->dirOutput = mgu_replace_string( ctl->dirOutput, t );
	g_free( t );
	ctl->path = mgu_replace_string( ctl->path, fileSpec );
}
예제 #20
0
파일: dcc-get.c 프로젝트: svn2github/irssi
char *dcc_get_download_path(const char *fname)
{
	char *str, *downpath;

	downpath = convert_home(settings_get_str("dcc_download_path"));
	str = g_strconcat(downpath, G_DIR_SEPARATOR_S, g_basename(fname), NULL);
	g_free(downpath);

	return str;
}
예제 #21
0
gint display_properties_dbox(const char *filename)
{
	GtkBuilder *builder;
	GtkWidget *dbox;
	GtkWidget *text;
	GError* error = NULL;
	gint result;
	guint hid;

	builder = gtk_builder_new();
	if (!gtk_builder_add_from_file (builder, tilp_paths_build_builder("manpage.ui"), &error))
	{
		g_warning (_("Couldn't load builder file: %s\n"), error->message);
		g_error_free (error);
		return NULL; // THIS RETURNS !
	}
	gtk_builder_connect_signals(builder, NULL);

	dbox = gtk_builder_get_object(builder, "manpage_dbox");
	text = gtk_builder_get_object(builder, "textview1");
	txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));

	hid = g_log_set_handler("tifiles", G_LOG_LEVEL_INFO, new_log_handler, NULL);
	tifiles_file_display(filename);	
	g_log_remove_handler("tifiles", hid);

	{
		PangoFontDescription *font_desc;
		GtkWidget *view = text;

		font_desc = pango_font_description_from_string ("Courier");
		gtk_widget_modify_font (view, font_desc);
		pango_font_description_free (font_desc);
	}

	gtk_window_set_title(GTK_WINDOW(dbox), g_basename(filename));
	gtk_widget_show(dbox);

	result = gtk_dialog_run(GTK_DIALOG(dbox));
	switch (result) 
	{
	case GTK_RESPONSE_OK:
		break;
	default:
		break;
	}

	gtk_widget_destroy(dbox);

	return 0;
}
예제 #22
0
파일: images.c 프로젝트: debrouxl/tiemu
/*
  	This function loads an image.
*/
int ti68k_load_image(const char *filename)
{
	IMG_INFO *img = &img_infos;
  	FILE *f;  	
  	int err;

	// Clear infos
	memset(img, 0, sizeof(IMG_INFO));

	// No filename, exits
	if(!strcmp(g_basename(filename), ""))
	   return ERR_CANT_OPEN;

	// Load infos
	err = ti68k_get_img_infos(filename, img);
  	if(err)
    {
      	printl(0, _("Unable to get informations on image: %s\n"), filename);
      	return err;
    }
	ti68k_display_img_infos(img);
	
	// Open file
	f = fopen(filename, "rb");
	if(f == NULL)
    {
      	fprintf(stderr, "Unable to open this file: <%s>\n", filename);
      	return ERR_CANT_OPEN;
    }

	// Read pure data
    fseek(f, img->header_size, SEEK_SET);
	img->data = malloc(img->size + 4);
	if(img->data == NULL)
		return ERR_MALLOC;
    fread(img->data, 1, img->size, f);

#if 1
	{
		HW_PARM_BLOCK hwblock;

		ti68k_get_hw_param_block(img->data, img->rom_base, &hwblock);
        ti68k_display_hw_param_block(&hwblock);
	}
#endif
 
  	img_loaded = 1;
	img_changed = 1;

  	return 0;
}
예제 #23
0
int
main (int argc, char *argv[])
{
  GError *error=NULL;
  Itdb_iTunesDB *itdb;
  gchar *infile = NULL;
  gchar *outfile = NULL;

  if (argc >= 2)
      infile = argv[1];
  if (argc >= 3)
      outfile = argv[2];

  if (infile == 0)
  {
      printf ("Usage: %s <infile> [<outfile>]\n",  g_basename(argv[0]));
      exit (0);
  }

  itdb = itdb_parse_file (infile, &error);
  printf ("%p\n", itdb);

  if (error)
  {
      if (error->message)
	  puts (error->message);
      g_error_free (error);
      error = NULL;
  }

  if (itdb)
  {
      printf ("tracks: %d\n", g_list_length (itdb->tracks));
      printf ("playlists: %d\n", g_list_length (itdb->playlists));

      if (outfile)
	  itdb_write_file (itdb, outfile, &error);
      if (error)
      {
	  if (error->message)
	      puts (error->message);
	  g_error_free (error);
	  error = NULL;
      }
  }

  itdb_free (itdb);

  return 0;
}
예제 #24
0
GList *filename_complete(const char *path)
{
        GList *list;
	DIR *dirp;
	struct dirent *dp;
	char *realpath, *dir, *basename, *name;
	int len;

	g_return_val_if_fail(path != NULL, NULL);

	list = NULL;

	/* get directory part of the path - expand ~/ */
	realpath = convert_home(path);
	dir = g_dirname(realpath);
	g_free(realpath);

	/* open directory for reading */
	dirp = opendir(dir);
	g_free(dir);
	if (dirp == NULL) return NULL;

	dir = g_dirname(path);
	if (*dir == G_DIR_SEPARATOR && dir[1] == '\0')
		*dir = '\0'; /* completing file in root directory */
	basename = g_basename(path);
	len = strlen(basename);

	/* add all files in directory to completion list */
	while ((dp = readdir(dirp)) != NULL) {
		if (dp->d_name[0] == '.') {
			if (dp->d_name[1] == '\0' ||
			    (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
				continue; /* skip . and .. */

			if (basename[0] != '.')
				continue;
		}

		if (len == 0 || strncmp(dp->d_name, basename, len) == 0) {
			name = g_strdup_printf("%s"G_DIR_SEPARATOR_S"%s", dir, dp->d_name);
			list = list_add_file(list, name);
			g_free(name);
		}
	}
	closedir(dirp);

	g_free(dir);
        return list;
}
예제 #25
0
/* suffixes should be ascii only characters */
const char *
uri_get_suffix(const char *uri)
{
	const char *suffix = strrchr(g_basename(uri), '.');
	if (suffix == NULL)
		return NULL;

	++suffix;

	if (strchr(suffix, '/') != NULL)
		return NULL;

	return suffix;
}
예제 #26
0
/*
 * Return a pointer to the start of the base filename of path
 */
const char *
xpidl_basename(const char * path)
{
    const char * result = g_basename(path);
    /* 
     *If this is windows then we'll handle either / or \ as a separator
     * g_basename only handles \ for windows
     */
#if defined(XP_WIN32)
    const char * slash = strrchr(path, '/');
    /* If we found a slash and its after the current default OS separator */
    if (slash != NULL && (slash > result))
        result = slash + 1;
#endif
    return result;
}
예제 #27
0
파일: images.c 프로젝트: debrouxl/tiemu
/*
	Try to get some information on the ROM dump:
	- size
	- ROM base address
	- FLASH/EPROM
	- soft version
	- calc type
*/
int ti68k_get_img_infos(const char *filename, IMG_INFO *ri)
{
	FILE *f;

	// No filename, exits
	if(!strcmp(g_basename(filename), ""))
	   return ERR_CANT_OPEN;

	// Check file
	if(!ti68k_is_a_img_file(filename))
	{
		tiemu_warning("Images must have '.img' extension (%s).\n",
			filename);
		return ERR_CANT_OPEN;
	}
	
	// Open dest file
  	f = fopen(filename, "rb");
  	if(f == NULL)
    {
      	tiemu_warning("Unable to open this file: <%s>\n", filename);
      	return ERR_CANT_OPEN;
    }
    
    // Read header
    if (fread(ri, sizeof(IMG_INFO), 1, f) < 1)
    {
      tiemu_warning("Failed to read from file: <%s>\n", filename);
      fclose(f);
      return ERR_CANT_OPEN;
    }

    if(strcmp(ri->signature, IMG_SIGN) || ri->size > 4*MB)
    {
      tiemu_warning("Bad image: <%s>\n", filename);
      return ERR_INVALID_UPGRADE;
    }

    // Close file
    if (fclose(f))
    {
      tiemu_warning("Failed to close file: <%s>\n", filename);
      return ERR_CANT_OPEN;
    }
    
    return 0;
}
예제 #28
0
unsigned int osync_testsuite_selected(Suite *s, int argc, char **argv,
		struct osync_testcase_s *tc)
{
	int i, j, n=0;
	/* Also argv[0]! for symlink-ed calls */
	for (i=0; argc > i; i++) {
		for (j=0; tc[j].name; j++) {
			if (strcmp(g_basename(argv[i]), tc[j].name))
					continue;

			create_case(s, tc[j].name, tc[j].func);
			n++;
		}
	}

	return n;
}
예제 #29
0
파일: skinops.c 프로젝트: debrouxl/tiemu
int
load_skin(const char *path)
{
  FILE *fp = NULL;
  char buf[17];
  int ret = 0;

  fp = fopen(path, "rb");

  if (fp == NULL)
    {
      return -1;
    }

  /*
   * Determine the type of skin being loaded
   */

  fread(buf, 16, 1, fp);
  
  if (buf[0] == 'V') /* VTi skin, string is only 8 bytes long */
    buf[7] = 0;

  if (strncmp(buf, "VTIv2.1", 7) == 0)
    ret = load_skin_old_vti(fp);
  else if (strncmp(buf, "VTIv2.5", 7) == 0)
    ret = load_skin_vti(fp);
  else
    ret = load_skin_tiemu(fp);

  fclose(fp);

  if (ret != 0)
    return ret;

  set_calc_keymap();

  sbar_print(_("Loaded %s (image size : %d x %d, skin version : %s)"),
	     g_basename(path), skin_infos.width, skin_infos.height, buf);
  
  skin_infos.skin_path = strdup(path);
  
  return ret;
}
예제 #30
0
static void
thumbalbum_append_thumb_frame (GimvThumbView *tv, GimvThumb *thumb,
                               const gchar *dest_mode)
{
   ThumbViewData *tv_data;
   const gchar *filename;
   gchar *label;
   GdkPixmap *pixmap = NULL;
   GdkBitmap *mask = NULL;
   gint pos;
   guint idx;

   g_return_if_fail (GIMV_IS_THUMB_VIEW (tv));
   g_return_if_fail (GIMV_IS_THUMB (thumb));

   tv_data = g_object_get_data (G_OBJECT (tv), THUMBALBUM_LABEL);
   g_return_if_fail (tv_data);

   pos = g_list_index (tv->thumblist, thumb);

   filename = g_basename(gimv_image_info_get_path (thumb->info));

   if (!strcmp (dest_mode, THUMBALBUM3_LABEL)) {
      label = album_create_label_str (thumb);
   } else {
      label = gimv_filename_to_internal (filename);
   }

   idx = gimv_zalbum_insert (GIMV_ZALBUM (tv_data->album), pos, label);
   g_free (label);

   gimv_zalbum_set_cell_data (GIMV_ZALBUM (tv_data->album), idx, thumb);

   thumbalbum_set_selection (tv, thumb, thumb->selected);

   if (!strcmp (THUMBALBUM2_LABEL, dest_mode)) {
      gimv_thumb_get_icon (thumb, &pixmap, &mask);
   } else {
      gimv_thumb_get_thumb (thumb, &pixmap, &mask);
   }

   if (pixmap)
      gimv_zalbum_set_pixmap (GIMV_ZALBUM (tv_data->album), idx, pixmap, mask);
}