Exemple #1
0
static void dest_change_dir(Dest_Data *dd, const gchar *path, gint retain_name)
{
	gchar *old_name = NULL;
	gint s = 0;

	if (retain_name)
		{
		const gchar *buf = gtk_entry_get_text(GTK_ENTRY(dd->entry));
		if (!isdir(buf))
			{
			if (path && strcmp(path, "/") == 0)
				{
				old_name = g_strdup(filename_from_path(buf));
				}
			else
				{
				old_name = g_strconcat("/", filename_from_path(buf), NULL);
				s = 1;
				}
			}
		}

	gtk_entry_set_text(GTK_ENTRY(dd->entry), path);

	dest_populate(dd, path);

	/* remember filename */
	if (old_name)
		{
		gint pos = -1;
		gtk_editable_insert_text(GTK_EDITABLE(dd->entry), old_name, -1, &pos);
		gtk_editable_select_region(GTK_EDITABLE(dd->entry), strlen(path) + s, strlen(path) + strlen(old_name));
		g_free(old_name);
		}
}
Exemple #2
0
GList *path_list_filter(GList *list, gint is_dir_list)
{
	GList *work;

	if (!is_dir_list && file_filter_disable && show_dot_files) return list;

	work = list;
	while (work)
		{
		gchar *name = work->data;
		const gchar *base;

		base = filename_from_path(name);

		if ((!show_dot_files && ishidden(base)) ||
		    (!is_dir_list && !filter_name_exists(base)) ||
		    (is_dir_list && base[0] == '.' && (strcmp(base, GQVIEW_CACHE_LOCAL_THUMB) == 0 ||
						       strcmp(base, GQVIEW_CACHE_LOCAL_METADATA) == 0)) )
			{
			GList *link = work;
			work = work->next;
			list = g_list_remove_link(list, link);
			g_free(name);
			g_list_free(link);
			}
		else
			{
			work = work->next;
			}
		}

	return list;
}
gchar *unique_filename_simple(const gchar *path)
{
	gchar *unique;
	const gchar *name;
	const gchar *ext;

	if (!path) return NULL;

	name = filename_from_path(path);
	if (!name) return NULL;

	ext = extension_from_path(name);

	if (!ext)
		{
		unique = unique_filename(path, NULL, "_", TRUE);
		}
	else
		{
		gchar *base;

		base = remove_extension_from_path(path);
		unique = unique_filename(base, ext, "_", TRUE);
		g_free(base);
		}

	return unique;
}
Exemple #4
0
static void dest_change_dir(Dest_Data *dd, const gchar *path, gboolean retain_name)
{
	const gchar *old_name = NULL;
	gchar *full_path;
	gchar *new_directory;

	if (retain_name)
		{
		const gchar *buf = gtk_entry_get_text(GTK_ENTRY(dd->entry));

		if (!isdir(buf)) old_name = filename_from_path(buf);
		}

	full_path = g_build_filename(path, old_name, NULL);
	if (old_name)
		new_directory = g_path_get_dirname(full_path);
	else
		new_directory = g_strdup(full_path);

	gtk_entry_set_text(GTK_ENTRY(dd->entry), full_path);

	dest_populate(dd, new_directory);
	g_free(new_directory);

	if (old_name)
		{
		gchar *basename = g_path_get_basename(full_path);

		gtk_editable_select_region(GTK_EDITABLE(dd->entry), strlen(full_path) - strlen(basename), strlen(full_path));
		g_free(basename);
		}

	g_free(full_path);
}
Exemple #5
0
void tab_completion_iter_menu_items(GtkWidget *widget, gpointer data)
{
	TabCompData *td = data;
	GtkWidget *child;

	if (!gtk_widget_get_visible(widget)) return;

	child = gtk_bin_get_child(GTK_BIN(widget));
	if (GTK_IS_LABEL(child)) {
		const gchar *text = gtk_label_get_text(GTK_LABEL(child));
		const gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(td->entry));
		const gchar *prefix = filename_from_path(entry_text);
		guint prefix_len = strlen(prefix);

		if (strlen(text) < prefix_len || strncmp(text, prefix, prefix_len))
			{
			/* Hide menu items not matching */
			gtk_widget_hide(widget);
			}
		else
			{
			/* Count how many choices are left in the menu */
			td->choices++;
			}
	}
}
Exemple #6
0
static void layout_path_entry_tab_cb(const gchar *path, gpointer data)
{
	LayoutWindow *lw = data;
	gchar *buf;
	gchar *base;

	buf = g_strdup(path);
	parse_out_relatives(buf);
	base = remove_level_from_path(buf);

	if (isdir(buf))
		{
		if ((!lw->path || strcmp(lw->path, buf) != 0) && layout_set_path(lw, buf))
			{
			gint pos = -1;
			/* put the '/' back, if we are in tab completion for a dir and result was path change */
			gtk_editable_insert_text(GTK_EDITABLE(lw->path_entry), "/", -1, &pos);
			gtk_editable_set_position(GTK_EDITABLE(lw->path_entry),
						  strlen(gtk_entry_get_text(GTK_ENTRY(lw->path_entry))));
			}
		}
	else if (lw->path && strcmp(lw->path, base) == 0)
		{
		layout_list_scroll_to_subpart(lw, filename_from_path(buf));
		}

	g_free(base);
	g_free(buf);
}
Exemple #7
0
//zarafaclient-6.20-1234.msi
//zarafaclient-*.*-*.msi
bool GetLatestVersionAtServer(char *szUpdatePath, unsigned int ulTrackid, ClientVersion *lpLatestVersion)
{
	ClientVersion tempVersion = {0};
	ClientVersion latestVersion = {0};
	std::string strFileStart = "zarafaclient-";

	bool bRet = false;

	if (szUpdatePath == NULL)
		goto exit;

	try {
		bfs::path updatesdir = szUpdatePath;
		if (!bfs::exists(updatesdir)) {
			g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Unable to open client_update_path directory", ulTrackid);
			goto exit;
		}

		bfs::directory_iterator update_last;
		for (bfs::directory_iterator update(updatesdir); update != update_last; update++) {
			const bfs::file_type file_type = update->status().type();
			if (file_type != bfs::regular_file && file_type != bfs::symlink_file) {
				continue;
			}

			const std::string strFilename = filename_from_path(update->path());
			if (!ba::starts_with(strFilename, strFileStart)) {
				g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: trackid: 0x%08X, Ignoring file %s for client update", ulTrackid, strFilename.c_str());
				continue;
			}

			g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, Update Name: %s", ulTrackid, strFilename.c_str());

			const char *pTemp = strFilename.c_str() + strFileStart.length();
			if (!GetVersionFromMSIName(pTemp, &tempVersion))
			{
				g_lpLogger->Log(EC_LOGLEVEL_WARNING, "Client update: trackid: 0x%08X, Failed in getting version from string '%s'", ulTrackid, pTemp);
				continue;
			}

			// first time, latestVersion will be 0, so always older
			if (CompareVersions(latestVersion, tempVersion) < 0) {
				bRet = true;
				latestVersion = tempVersion;
			}
		}
	} catch (const bfs::filesystem_error &e) {
		g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, Boost exception during certificate validation: %s", ulTrackid, e.what());
	} catch (const std::exception &e) {
		g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, STD exception during certificate validation: %s", ulTrackid, e.what());
	}

	if (bRet)
		*lpLatestVersion = latestVersion;

exit:
	return bRet;
}
Exemple #8
0
gchar  *
cache_get_location (CacheType type, const gchar * source, gint include_name,
		    const gchar * ext, mode_t * mode)
{
    gchar  *path = NULL;
    gchar  *base;
    gchar  *name = NULL;

    if (!source)
	return NULL;

    base = remove_level_from_path (source);

    if (include_name)
    {
	name = g_strconcat ("/", filename_from_path (source), NULL);
    }
    else
    {
	ext = NULL;
    }

    if (type == CACHE_THUMBS)
    {
	if (conf.enable_thumb_dirs && access (base, W_OK) == 0)
	{
	    path =
		g_strconcat (base, "/", PORNVIEW_CACHE_DIR, name, ext, NULL);
	    if (mode)
		*mode = 0775;
	}

	if (!path)
	{
	    path =
		g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_THUMBS, base,
			     name, ext, NULL);
	    if (mode)
		*mode = 0755;
	}
    }
    else
    {
	path =
	    g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_COMMENTS, base,
			 name, ext, NULL);
	if (mode)
	    *mode = 0755;
    }

    g_free (base);

    if (name)
	g_free (name);

    return path;
}
Exemple #9
0
static gchar *cache_build_path_local(const gchar *source, const gchar *cache_local, const gchar *cache_ext)
{
	gchar *path;
	gchar *base = remove_level_from_path(source);
	gchar *name = g_strconcat(filename_from_path(source), cache_ext, NULL);
	path = g_build_filename(base, cache_local, name, NULL);
	g_free(name);
	g_free(base);
	
	return path;
}
Exemple #10
0
static void thumb_std_maint_move_validate_cb(const gchar *path, gint valid, gpointer data)
{
	TMaintMove *tm = data;
	GdkPixbuf *pixbuf;

	pixbuf = thumb_loader_std_get_pixbuf(tm->tl, FALSE);
	if (pixbuf)
		{
		const gchar *uri;
		const gchar *mtime_str;

		uri = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_URI);
		mtime_str = gdk_pixbuf_get_option(pixbuf, THUMB_MARKER_MTIME);

		if (uri && mtime_str && strcmp(uri, tm->source_uri) == 0)
			{
			gchar *pathl;

			/* The validation utility abuses ThumbLoader, and we
			 * abuse the utility just to load the thumbnail,
			 * but the loader needs to look sane for the save to complete.
			 */

			tm->tl->cache_enable = TRUE;
			tm->tl->cache_hit = FALSE;
			tm->tl->cache_local = FALSE;

			g_free(tm->tl->source_path);
			tm->tl->source_path = g_strdup(tm->dest);
			tm->tl->source_mtime = strtol(mtime_str, NULL, 10);

			pathl = path_from_utf8(tm->tl->source_path);
			g_free(tm->tl->thumb_uri);
			tm->tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
			tm->tl->local_uri = filename_from_path(tm->tl->thumb_uri);
			g_free(pathl);

			g_free(tm->tl->thumb_path);
			tm->tl->thumb_path = NULL;
			tm->tl->thumb_path_local = FALSE;

			if (debug) printf("thumb move attempting save:\n");

			thumb_loader_std_save(tm->tl, pixbuf);
			}

		if (debug) printf("thumb move unlink: %s\n", tm->thumb_path);
		unlink_file(tm->thumb_path);
		}

	thumb_std_maint_move_step(tm);
}
Exemple #11
0
FileData *file_data_new(const gchar *path, struct stat *st)
{
	FileData *fd;

	fd = g_new0(FileData, 1);
	fd->path = path_to_utf8(path);
	fd->name = filename_from_path(fd->path);
	fd->size = st->st_size;
	fd->date = st->st_mtime;
	fd->pixbuf = NULL;

	return fd;
}
Exemple #12
0
gint thumb_loader_std_start(ThumbLoaderStd *tl, const gchar *path)
{
	static gchar *thumb_cache = NULL;
	struct stat st;

	if (!tl || !path) return FALSE;

	thumb_loader_std_reset(tl);

	if (!stat_utf8(path, &st)) return FALSE;

	tl->source_path = g_strdup(path);
	tl->source_mtime = st.st_mtime;
	tl->source_size = st.st_size;
	tl->source_mode = st.st_mode;

	if (!thumb_cache) thumb_cache = g_strconcat(homedir(), "/", THUMB_FOLDER, NULL);
	if (strncmp(tl->source_path, thumb_cache, strlen(thumb_cache)) != 0)
		{
		gchar *pathl;

		pathl = path_from_utf8(path);
		tl->thumb_uri = g_filename_to_uri(pathl, NULL, NULL);
		tl->local_uri = filename_from_path(tl->thumb_uri);
		g_free(pathl);
		}

	if (tl->cache_enable)
		{
		gint found;

		tl->thumb_path = thumb_loader_std_cache_path(tl, FALSE, NULL, FALSE);
		tl->thumb_path_local = FALSE;

		found = isfile(tl->thumb_path);
		if (found && thumb_loader_std_setup(tl, tl->thumb_path)) return TRUE;

		if (thumb_loader_std_fail_check(tl)) return FALSE;

		return thumb_loader_std_next_source(tl, found);
		}

	if (!thumb_loader_std_setup(tl, tl->source_path))
		{
		thumb_loader_std_save(tl, NULL);
		return FALSE;
		}

	return TRUE;
}
Exemple #13
0
static void thumb_std_maint_remove_one(const gchar *source, const gchar *uri, gint local,
				       const gchar *subfolder)
{
	gchar *thumb_path;

	thumb_path = thumb_std_cache_path(source,
					  (local) ? filename_from_path(uri) : uri,
					  local, subfolder);
	if (isfile(thumb_path))
		{
		if (debug) printf("thumb removing: %s\n", thumb_path);
		unlink_file(thumb_path);
		}
	g_free(thumb_path);
}
Exemple #14
0
static void
cb_file_util_move_multiple_ok (GenericDialog * gd, gpointer data)
{
    FileDataMult *fdm = data;

    fdm->confirmed = TRUE;

    if (fdm->rename_auto)
    {
	gchar  *buf;

	buf = unique_filename_simple (fdm->dest);
	if (buf)
	{
	    g_free (fdm->dest);
	    fdm->dest = buf;
	}
	else
	{
	    /*
	     * unique failed? well, return to the overwrite prompt :( 
	     */
	    fdm->confirmed = FALSE;
	}
    }
    else if (fdm->rename)
    {
	const gchar *name;

	name = gtk_entry_get_text (GTK_ENTRY (fdm->rename_entry));

	if (strlen (name) == 0 ||
	    strcmp (name, filename_from_path (fdm->source)) == 0)
	{
	    fdm->confirmed = FALSE;
	}
	else
	{
	    g_free (fdm->dest);
	    fdm->dest = concat_dir_and_file (fdm->dest_base, name);
	    fdm->confirmed = !isname (fdm->dest);
	}
    }

    gtk_widget_hide (gd->dialog);

    file_util_move_multiple (fdm);
}
Exemple #15
0
static  gint
thumb_loader_mark_failure (ThumbLoader * tl)
{
    gchar  *cache_dir;
    gint    success = FALSE;
    mode_t  mode = 0755;

    if (!tl)
	return FALSE;

    cache_dir =
	cache_get_location (CACHE_THUMBS, tl->path, FALSE, NULL, &mode);

    if (cache_ensure_dir_exists (cache_dir, mode))
    {
	gchar  *cache_path;
	FILE   *f;

	cache_path =
	    g_strconcat (cache_dir, "/", filename_from_path (tl->path),
			 PORNVIEW_CACHE_THUMB_EXT, NULL);

	f = fopen (cache_path, "w");
	if (f)
	{
	    struct utimbuf ut;

	    fclose (f);

	    ut.actime = ut.modtime = filetime (tl->path);
	    if (ut.modtime > 0)
	    {
		utime (cache_path, &ut);
	    }

	    success = TRUE;
	}

	g_free (cache_path);
    }

    g_free (cache_dir);
    return success;
}
Exemple #16
0
FileData *file_data_new_simple(const gchar *path)
{
	FileData *fd;
	struct stat st;

	fd = g_new0(FileData, 1);
	fd->path = g_strdup(path);
	fd->name = filename_from_path(fd->path);

	if (stat_utf8(fd->path, &st))
		{
		fd->size = st.st_size;
		fd->date = st.st_mtime;
		}

	fd->pixbuf = NULL;

	return fd;
}
Exemple #17
0
static  gint
thumb_loader_save_to_cache (ThumbLoader * tl)
{
    gchar  *cache_dir;
    gint    success = FALSE;
    mode_t  mode = 0755;

    if (!tl || !tl->pixbuf)
	return FALSE;

    cache_dir =
	cache_get_location (CACHE_THUMBS, tl->path, FALSE, NULL, &mode);

    if (cache_ensure_dir_exists (cache_dir, mode))
    {
	gchar  *cache_path;

	cache_path =
	    g_strconcat (cache_dir, "/", filename_from_path (tl->path),
			 PORNVIEW_CACHE_THUMB_EXT, NULL);

	success = pixbuf_to_file_as_png (tl->pixbuf, cache_path);
	if (success)
	{
	    struct utimbuf ut;
	    /*
	     * set thumb time to that of source file 
	     */

	    ut.actime = ut.modtime = filetime (tl->path);
	    if (ut.modtime > 0)
	    {
		utime (cache_path, &ut);
	    }
	}

	g_free (cache_path);
    }

    g_free (cache_dir);

    return success;
}
static int
process_url(int pl_id, const char *path, time_t mtime, int extinf, struct media_file_info *mfi)
{
  char virtual_path[PATH_MAX];
  char *pos;
  int ret;

  if (extinf)
    DPRINTF(E_INFO, L_SCAN, "Playlist has EXTINF metadata, artist is '%s', title is '%s'\n", mfi->artist, mfi->title);

  mfi->id = db_file_id_bypath(path);
  mfi->path = strdup(path);

  pos = strchr(path, '#');
  if (pos)
    mfi->fname = strdup(pos+1);
  else
    mfi->fname = strdup(filename_from_path(mfi->path));

  mfi->data_kind = DATA_KIND_HTTP;
  mfi->time_modified = mtime;
  mfi->directory_id = DIR_HTTP;

  ret = scan_metadata_ffmpeg(path, mfi);
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Playlist URL '%s' is unavailable for probe/metadata, assuming MP3 encoding\n", path);
      mfi->type = strdup("mp3");
      mfi->codectype = strdup("mpeg");
      mfi->description = strdup("MPEG audio file");
    }

  if (!mfi->title)
    mfi->title = strdup(mfi->fname);

  snprintf(virtual_path, sizeof(virtual_path), "/%s", mfi->path);
  mfi->virtual_path = strdup(virtual_path);

  library_add_media(mfi);

  return db_pl_add_item_bypath(pl_id, path);
}
Exemple #19
0
CollectionData *collection_new(const gchar *path)
{
	CollectionData *cd;
	static gint untitled_counter = 0;

	cd = g_new0(CollectionData, 1);

	cd->ref = 1;	/* starts with a ref of 1 */
	cd->sort_method = SORT_NONE;
	cd->window_w = COLLECT_DEF_WIDTH;
	cd->window_h = COLLECT_DEF_HEIGHT;
	cd->existence = g_hash_table_new(NULL, NULL);

	if (path)
		{
		cd->path = g_strdup(path);
		cd->name = g_strdup(filename_from_path(cd->path));
		/* load it */
		}
	else
		{
		if (untitled_counter == 0)
			{
			cd->name = g_strdup(_("Untitled"));
			}
		else
			{
			cd->name = g_strdup_printf(_("Untitled (%d)"), untitled_counter + 1);
			}

		untitled_counter++;
		}

	file_data_register_notify_func(collection_notify_cb, cd, NOTIFY_PRIORITY_MEDIUM);


	collection_list = g_list_append(collection_list, cd);

	return cd;
}
Exemple #20
0
gint pan_is_ignored(const gchar *s, gint ignore_symlinks)
{
	struct stat st;
	const gchar *n;

	if (!lstat_utf8(s, &st)) return TRUE;

#if 0
	/* normal filesystems have directories with some size or block allocation,
	 * special filesystems (like linux /proc) set both to zero.
	 * enable this check if you enable listing the root "/" folder
	 */
	if (st.st_size == 0 && st.st_blocks == 0) return TRUE;
#endif

	if (S_ISLNK(st.st_mode) && (ignore_symlinks || pan_is_link_loop(s))) return TRUE;

	n = filename_from_path(s);
	if (n && strcmp(n, GQVIEW_RC_DIR) == 0) return TRUE;

	return FALSE;
}
Exemple #21
0
static void info_window_sync(InfoData *id, const gchar *path)
{

	if (!path) return;

	gtk_entry_set_text(GTK_ENTRY(id->name_entry), filename_from_path(path));

	if (id->label_count)
		{
		gchar *buf;
		buf = g_strdup_printf(_("Image %d of %d"),
				      g_list_index(id->list, (gpointer)path) + 1,
				      g_list_length(id->list));
		gtk_label_set_text(GTK_LABEL(id->label_count), buf);
		g_free(buf);
		}

	info_tabs_sync(id, FALSE);

	id->updated = FALSE;
	image_change_path(id->image, path, 0.0);
}
Exemple #22
0
gchar *cache_get_location(CacheType type, const gchar *source, gint include_name, mode_t *mode)
{
	gchar *path = NULL;
	gchar *base;
	gchar *name = NULL;
	const gchar *cache_rc;
	const gchar *cache_local;
	const gchar *cache_ext;

	if (!source) return NULL;

	cache_path_parts(type, &cache_rc, &cache_local, &cache_ext);

	base = remove_level_from_path(source);
	if (include_name)
		{
		name = g_strconcat(filename_from_path(source), cache_ext, NULL);
		}

	if (((type != CACHE_TYPE_METADATA && type != CACHE_TYPE_XMP_METADATA && options->thumbnails.cache_into_dirs) ||
	     ((type == CACHE_TYPE_METADATA || type == CACHE_TYPE_XMP_METADATA) && options->metadata.enable_metadata_dirs)) &&
	    access_file(base, W_OK))
		{
		path = g_build_filename(base, cache_local, name, NULL);
		if (mode) *mode = 0775;
		}

	if (!path)
		{
		path = g_build_filename(cache_rc, base, name, NULL);
		if (mode) *mode = 0755;
		}

	g_free(base);
	if (name) g_free(name);

	return path;
}
Exemple #23
0
gboolean editor_read_desktop_file(const gchar *path)
{
	GKeyFile *key_file;
	EditorDescription *editor;
	gchar *extensions;
	gchar *type;
	const gchar *key = filename_from_path(path);
	gchar **categories, **only_show_in, **not_show_in;
	gchar *try_exec;
	GtkTreeIter iter;
	gboolean category_geeqie = FALSE;

	if (g_hash_table_lookup(editors, key)) return FALSE; /* the file found earlier wins */

	key_file = g_key_file_new();
	if (!g_key_file_load_from_file(key_file, path, 0, NULL))
		{
		g_key_file_free(key_file);
		return FALSE;
		}

	type = g_key_file_get_string(key_file, DESKTOP_GROUP, "Type", NULL);
	if (!type || strcmp(type, "Application") != 0)
		{
		/* We only consider desktop entries of Application type */
		g_key_file_free(key_file);
		g_free(type);
		return FALSE;
		}
	g_free(type);

	editor = g_new0(EditorDescription, 1);

	editor->key = g_strdup(key);
	editor->file = g_strdup(path);

	g_hash_table_insert(editors, editor->key, editor);

	if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Hidden", NULL)
	    || g_key_file_get_boolean(key_file, DESKTOP_GROUP, "NoDisplay", NULL))
	    	{
	    	editor->hidden = TRUE;
		}

	categories = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "Categories", NULL, NULL);
	if (categories)
		{
		gboolean found = FALSE;
		gint i;
		for (i = 0; categories[i]; i++)
			{
			/* IMHO "Graphics" is exactly the category that we are interested in, so this does not have to be configurable */
			if (strcmp(categories[i], "Graphics") == 0)
				{
				found = TRUE;
				}
			if (strcmp(categories[i], "X-Geeqie") == 0)
				{
				found = TRUE;
				category_geeqie = TRUE;
				break;
				}
			}
		if (!found) editor->ignored = TRUE;
		g_strfreev(categories);
		}
	else
		{
		editor->ignored = TRUE;
		}

	only_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "OnlyShowIn", NULL, NULL);
	if (only_show_in)
		{
		gboolean found = FALSE;
		gint i;
		for (i = 0; only_show_in[i]; i++)
			if (strcmp(only_show_in[i], "X-Geeqie") == 0)
				{
				found = TRUE;
				break;
				}
		if (!found) editor->ignored = TRUE;
		g_strfreev(only_show_in);
		}

	not_show_in = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "NotShowIn", NULL, NULL);
	if (not_show_in)
		{
		gboolean found = FALSE;
		gint i;
		for (i = 0; not_show_in[i]; i++)
			if (strcmp(not_show_in[i], "X-Geeqie") == 0)
				{
				found = TRUE;
				break;
				}
		if (found) editor->ignored = TRUE;
		g_strfreev(not_show_in);
		}


	try_exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "TryExec", NULL);
	if (try_exec && !editor->hidden && !editor->ignored)
		{
		gchar *try_exec_res = g_find_program_in_path(try_exec);
		if (!try_exec_res) editor->hidden = TRUE;
		g_free(try_exec_res);
		g_free(try_exec);
		}

	if (editor->ignored)
		{
		/* ignored editors will be deleted, no need to parse the rest */
		g_key_file_free(key_file);
		return TRUE;
		}

	editor->name = g_key_file_get_locale_string(key_file, DESKTOP_GROUP, "Name", NULL, NULL);
	editor->icon = g_key_file_get_string(key_file, DESKTOP_GROUP, "Icon", NULL);

	/* Icon key can be either a full path (absolute with file name extension) or an icon name (without extension) */
	if (editor->icon && !g_path_is_absolute(editor->icon))
		{
		gchar *ext = strrchr(editor->icon, '.');

		if (ext && strlen(ext) == 4 &&
		    (!strcmp(ext, ".png") || !strcmp(ext, ".xpm") || !strcmp(ext, ".svg")))
			{
			log_printf(_("Desktop file '%s' should not include extension in Icon key: '%s'\n"),
				   editor->file, editor->icon);

			// drop extension
			*ext = '\0';
			}
		}
	if (editor->icon && !register_theme_icon_as_stock(editor->key, editor->icon))
		{
		g_free(editor->icon);
		editor->icon = NULL;
		}

	editor->exec = g_key_file_get_string(key_file, DESKTOP_GROUP, "Exec", NULL);

	editor->menu_path = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-Menu-Path", NULL);
	if (!editor->menu_path) editor->menu_path = g_strdup("PluginsMenu");

	editor->hotkey = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-Hotkey", NULL);

	editor->comment = g_key_file_get_string(key_file, DESKTOP_GROUP, "Comment", NULL);

	extensions = g_key_file_get_string(key_file, DESKTOP_GROUP, "X-Geeqie-File-Extensions", NULL);
	if (extensions)
		editor->ext_list = filter_to_list(extensions);
	else
		{
		gchar **mime_types = g_key_file_get_string_list(key_file, DESKTOP_GROUP, "MimeType", NULL, NULL);
		if (mime_types)
			{
			editor->ext_list = editor_mime_types_to_extensions(mime_types);
			g_strfreev(mime_types);
			if (!editor->ext_list) editor->hidden = TRUE;
			}
		}

	if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Keep-Fullscreen", NULL)) editor->flags |= EDITOR_KEEP_FS;
	if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Verbose", NULL)) editor->flags |= EDITOR_VERBOSE;
	if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Verbose-Multi", NULL)) editor->flags |= EDITOR_VERBOSE_MULTI;
	if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "X-Geeqie-Filter", NULL)) editor->flags |= EDITOR_DEST;
	if (g_key_file_get_boolean(key_file, DESKTOP_GROUP, "Terminal", NULL)) editor->flags |= EDITOR_TERMINAL;

	editor->flags |= editor_command_parse(editor, NULL, FALSE, NULL);

	if ((editor->flags & EDITOR_NO_PARAM) && !category_geeqie) editor->hidden = TRUE;

	g_key_file_free(key_file);

	if (editor->ignored) return TRUE;

	gtk_list_store_append(desktop_file_list, &iter);
	gtk_list_store_set(desktop_file_list, &iter,
			   DESKTOP_FILE_COLUMN_KEY, key,
			   DESKTOP_FILE_COLUMN_NAME, editor->name,
			   DESKTOP_FILE_COLUMN_HIDDEN, editor->hidden ? _("yes") : _("no"),
			   DESKTOP_FILE_COLUMN_WRITABLE, access_file(path, W_OK),
			   DESKTOP_FILE_COLUMN_PATH, path, -1);

	return TRUE;
}
Exemple #24
0
static gint collection_save_private(CollectionData *cd, const gchar *path)
{
	FILE *f;
	GList *work;
	gchar *tmp_path;
	gchar *pathl;
	mode_t save_mask;

	if (!path && !cd->path) return FALSE;

	if (!path)
		{
		path = cd->path;
		}

	tmp_path = unique_filename(path, ".tmp", "_", 3);
	if (!tmp_path) return FALSE;

	pathl = path_from_utf8(tmp_path);
	save_mask = umask(0077);
	f = fopen(pathl, "w");
	umask(save_mask);
	g_free(pathl);

	if (!f)
		{
		/* file open failed */
		printf("failed to open collection (write) \"%s\"\n", tmp_path);
		g_free(tmp_path);
		return FALSE;
		}

	fprintf(f, "%s collection\n", GQVIEW_COLLECTION_MARKER);
	fprintf(f, "#created with GQview version %s\n", VERSION);

	collection_update_geometry(cd);
	if (cd->window_read)
		{
		fprintf(f, "#geometry: %d %d %d %d\n", cd->window_x, cd->window_y, cd->window_w, cd->window_h);
		}

	work = cd->list;
	while (work)
		{
		CollectInfo *ci = work->data;
		if (fprintf(f, "\"%s\"\n", ci->path) < 0)
			{
			fclose(f);
			printf("Error writing to %s\n", tmp_path);
			unlink_file(tmp_path);
			g_free(tmp_path);
			return FALSE;
			}
		work = work->next;
		}

	fprintf(f, "#end\n");

	fclose(f);

	copy_file_attributes(path, tmp_path, TRUE, FALSE);
	if (!rename_file(tmp_path, path))
		{
		printf("collection save unable to rename %s to %s\n", tmp_path, path);
		unlink_file(tmp_path);
		g_free(tmp_path);
		return FALSE;
		}

	g_free(tmp_path);

	if (!cd->path || strcmp(path, cd->path) != 0)
		{
		gchar *buf = cd->path;
		cd->path = g_strdup(path);
		path = cd->path;
		g_free(buf);

		g_free(cd->name);
		cd->name = g_strdup(filename_from_path(cd->path));

		collection_path_changed(cd);
		}

	cd->changed = FALSE;

	return TRUE;
}
Exemple #25
0
static void
file_util_move_multiple (FileDataMult * fdm)
{
    while (fdm->dest || fdm->source_next)
    {
	if (!fdm->dest)
	{
	    GList  *work = fdm->source_next;
	    fdm->source = work->data;
	    fdm->dest =
		concat_dir_and_file (fdm->dest_base,
				     filename_from_path (fdm->source));
	    fdm->source_next = work->next;
	}

	if (fdm->dest && fdm->source && strcmp (fdm->dest, fdm->source) == 0)
	{
	    GenericDialog *gd;
	    const gchar *title;
	    gchar  *text;

	    if (fdm->progress)
	    {
		gtk_grab_remove (fdm->progress);
		gtk_widget_destroy (fdm->progress);
		fdm->progress = NULL;
		fdm->cancel = FALSE;
	    }

	    if (fdm->copy)
	    {
		title = _("Source to copy matches destination");
		text =
		    g_strdup_printf (_
				     ("Unable to copy file:\n%s\nto itself."),
				     fdm->dest);
	    }
	    else
	    {
		title = _("Source to move matches destination");
		text =
		    g_strdup_printf (_
				     ("Unable to move file:\n%s\nto itself."),
				     fdm->dest);
	    }

	    gd = file_util_gen_dlg (title, text, "PornView", "dlg_confirm",
				    TRUE, cb_file_util_move_multiple_cancel,
				    fdm);
	    g_free (text);
	    generic_dialog_add (gd, _("Continue"),
				cb_file_util_move_multiple_skip, TRUE);

	    gtk_widget_show (gd->dialog);
	    return;
	}
	else if (isfile (fdm->dest) && !fdm->confirmed && !fdm->confirm_all
		 && !fdm->skip)
	{
	    GenericDialog *gd;
	    gchar  *text;

	    GtkWidget *hbox;

	    if (fdm->progress)
	    {
		gtk_grab_remove (fdm->progress);
		gtk_widget_destroy (fdm->progress);
		fdm->progress = NULL;
		fdm->cancel = FALSE;
	    }

	    text =
		g_strdup_printf (_("Overwrite file:\n %s\n with:\n %s"),
				 fdm->dest, fdm->source);
	    gd = file_util_gen_dlg (_("Overwrite file"), text, "PornView",
				    "dlg_confirm", TRUE,
				    cb_file_util_move_multiple_cancel, fdm);
	    g_free (text);

	    generic_dialog_add (gd, _("Yes"), cb_file_util_move_multiple_ok,
				TRUE);
	    fdm->yes_all_button =
		generic_dialog_add (gd, _("Yes to all"),
				    cb_file_util_move_multiple_all, FALSE);
	    generic_dialog_add (gd, _("Skip"),
				cb_file_util_move_multiple_skip, FALSE);
	    generic_dialog_add (gd, _("Skip all"),
				cb_file_util_move_multiple_skip_all, FALSE);
	    generic_dialog_add_images (gd, fdm->dest, fdm->source);

	    /*
	     * rename option 
	     */

	    fdm->rename = FALSE;
	    fdm->rename_all = FALSE;
	    fdm->rename_auto = FALSE;

	    hbox = gtk_hbox_new (FALSE, 5);
	    gtk_box_pack_start (GTK_BOX (gd->vbox), hbox, FALSE, FALSE, 0);
	    gtk_widget_show (hbox);

	    fdm->rename_auto_box =
		gtk_check_button_new_with_label (_("Auto rename"));
	    gtk_signal_connect (GTK_OBJECT (fdm->rename_auto_box), "clicked",
				GTK_SIGNAL_FUNC
				(cb_file_util_move_multiple_rename_auto), gd);
	    gtk_box_pack_start (GTK_BOX (hbox), fdm->rename_auto_box, FALSE,
				FALSE, 0);
	    gtk_widget_show (fdm->rename_auto_box);

	    hbox = gtk_hbox_new (FALSE, 5);
	    gtk_box_pack_start (GTK_BOX (gd->vbox), hbox, FALSE, FALSE, 0);
	    gtk_widget_show (hbox);

	    fdm->rename_box = gtk_check_button_new_with_label (_("Rename"));
	    gtk_signal_connect (GTK_OBJECT (fdm->rename_box), "clicked",
				GTK_SIGNAL_FUNC
				(cb_file_util_move_multiple_rename), gd);
	    gtk_box_pack_start (GTK_BOX (hbox), fdm->rename_box, FALSE, FALSE,
				0);
	    gtk_widget_show (fdm->rename_box);

	    fdm->rename_entry = gtk_entry_new ();
	    gtk_entry_set_text (GTK_ENTRY (fdm->rename_entry),
				filename_from_path (fdm->dest));
	    gtk_widget_set_sensitive (fdm->rename_entry, FALSE);
	    gtk_box_pack_start (GTK_BOX (hbox), fdm->rename_entry, TRUE, TRUE,
				0);
	    gtk_widget_show (fdm->rename_entry);

	    gtk_widget_show (gd->dialog);
	    return;
	}
	else
	{
	    gint    success = FALSE;
	    if (fdm->skip)
	    {
		success = TRUE;
		if (!fdm->confirm_all)
		    fdm->skip = FALSE;
	    }
	    else
	    {
		gint    try = TRUE;

		if (fdm->confirm_all && fdm->rename_all && isfile (fdm->dest))
		{
		    gchar  *buf;
		    buf = unique_filename_simple (fdm->dest);
		    if (buf)
		    {
			g_free (fdm->dest);
			fdm->dest = buf;
		    }
		    else
		    {
			try = FALSE;
		    }
		}

		if (try)
		{
		    if (!fdm->progress)
			fdm->progress =
			    dialog_progress_create (_("Pornview - copy/move"),
						    _(" "), &fdm->cancel, 300,
						    -1);
		    gtk_grab_add (fdm->progress);


		    if (fdm->copy)
		    {
			gfloat  c;
			c = (gfloat) fdm->count / (gfloat) fdm->length;
			dialog_progress_update (fdm->progress,
						_("PornView - copy"),
						g_basename (fdm->source),
						_(" "), c);

			if (fdm->cancel)
			    break;
			success = copy_file (fdm->source, fdm->dest);
			fdm->count++;
		    }
		    else
		    {
			gfloat  c;

			c = (gfloat) fdm->count / (gfloat) fdm->length;
			dialog_progress_update (fdm->progress,
						_("PornView - move"),
						g_basename (fdm->source),
						_(" "), c);

			if (fdm->cancel)
			    break;

			while (gtk_events_pending ())
			    gtk_main_iteration ();

			fdm->count++;

			if (move_file (fdm->source, fdm->dest))
			{
			    success = TRUE;
			    file_maint_moved (fdm->source, fdm->dest,
					      fdm->source_list);

			}
		    }
		}
	    }
	    if (!success)
	    {
		GenericDialog *gd;
		const gchar *title;
		gchar  *text;

		if (fdm->progress)
		{
		    gtk_grab_remove (fdm->progress);
		    gtk_widget_destroy (fdm->progress);
		    fdm->progress = NULL;
		    fdm->cancel = FALSE;
		}

		if (fdm->copy)
		{
		    title = _("Error copying file");
		    text =
			g_strdup_printf (_
					 ("Unable to copy file:\n%sto:\n%s\n during multiple file copy."),
					 fdm->source, fdm->dest);
		}
		else
		{
		    title = _("Error moving file");
		    text =
			g_strdup_printf (_
					 ("Unable to move file:\n%sto:\n%s\n during multiple file move."),
					 fdm->source, fdm->dest);
		}
		gd = file_util_gen_dlg (title, text, "PornView",
					"dlg_confirm", TRUE,
					cb_file_util_move_multiple_cancel,
					fdm);
		g_free (text);

		generic_dialog_add (gd, _("Continue"),
				    cb_file_util_move_multiple_skip, TRUE);

		gtk_widget_show (gd->dialog);
		return;
	    }
	    fdm->confirmed = FALSE;
	    g_free (fdm->dest);
	    fdm->dest = NULL;
	}
    }
Exemple #26
0
/* ---- program entry ---------------------------
*/
int main( int argc, cstr argv[] )
{
	double start = now();

// options:
	uint verbose     = 1;	// 0=off, 1=default, 2=verbose
	uint outputstyle = 'b';	// 0=none, 'b'=binary, 'x'=intel hex, 's'=motorola s-records
	uint liststyle   = 1;	// 0=none, 1=plain, 2=with objcode, 4=with label listing, 6=both, 8=clock cycles
	bool clean		 = no;
	bool ixcbr2		 = no;
	bool ixcbxh		 = no;
	bool targetZ80	 = no;
	bool target8080	 = no;
	bool targetZ180  = no;
	bool asm8080	 = no;
	bool dotnames    = no;
	bool reqcolon    = no;
	bool casefold    = no;
	bool flatops	 = no;
	bool compare     = no;
	bool selftest    = no;
	bool cgi_mode	 = no;
	uint maxerrors   = 30;
// filepaths:
	cstr inputfile  = NULL;
	cstr outputfile = NULL;	// or dir
	cstr listfile   = NULL;	// or dir
	cstr tempdir    = NULL;
	cstr c_compiler = NULL;
	cstr c_includes	= NULL;
	cstr libraries	= NULL;

//	eval arguments:
	for(int i=1; i<argc; )
	{
		cptr s = argv[i++];

		if(s[0] != '-')
		{
			if(!inputfile)  { inputfile = s; continue; }
			// if outfile is not prefixed with -o then it must be the last argument:
			if(!outputfile && i==argc) { outputfile = s; continue; }
			if(!listfile)   { listfile = s; continue; }
			goto h;
		}

		if(s[1]=='-')
		{
			if(eq(s,"--clean"))    { clean = yes;     continue; }
			if(eq(s,"--bin"))	   { outputstyle='b'; continue; }
			if(eq(s,"--hex"))	   { outputstyle='x'; continue; }
			if(eq(s,"--s19"))	   { outputstyle='s'; continue; }
			if(eq(s,"--opcodes"))  { liststyle |= 2;  continue; }
			if(eq(s,"--labels"))   { liststyle |= 4;  continue; }
			if(eq(s,"--cycles"))   { liststyle |= 8;  continue; }
			if(eq(s,"--ixcbr2"))   { ixcbr2 = 1;      continue; }
			if(eq(s,"--ixcbxh"))   { ixcbxh = 1;      continue; }
			if(eq(s,"--z80"))      { targetZ80 = 1;   continue; }
			if(eq(s,"--8080"))     { target8080 = 1;  continue; }
			if(eq(s,"--asm8080"))  { asm8080 = 1;     continue; }
			if(eq(s,"--z180"))     { targetZ180 = 1;  continue; }
			if(eq(s,"--dotnames")) { dotnames = 1;    continue; }
			if(eq(s,"--reqcolon")) { reqcolon = 1;    continue; }
			if(eq(s,"--casefold")) { casefold = 1;    continue; }
			if(eq(s,"--flatops"))  { flatops = 1;     continue; }
			if(eq(s,"--compare"))  { compare = 1;     continue; }
			if(eq(s,"--test"))     { selftest = 1;    continue; }
			if(eq(s,"--cgi"))      { cgi_mode = 1;    continue; }
			if(startswith(s,"--maxerrors="))
				{
					char* ep; ulong n = strtoul(s+12,&ep,10);
					if(*ep||n==0||n>999) goto h;
					maxerrors = (uint)n; continue;
				}
			goto h;
		}

		while(char c = *++s)
		{
			switch(c)
			{
			case 'e': compare = 1; continue;
			case 'T': selftest = 1; continue;
			case 'u': liststyle |= 2; continue;
			case 'w': liststyle |= 4; continue;
			case 'y': liststyle |= 8; continue;
			case 's': outputstyle=c; continue;
			case 'x': outputstyle=c; continue;
			case 'b': outputstyle=c; continue;
			case 'z': clean=yes; continue;
			case 'g': cgi_mode=yes; continue;

			case 'v': if(*(s+1)>='0' && *(s+1)<='3') verbose = *++s - '0'; else ++verbose; continue;

			case 'i': if(inputfile  || i==argc) goto h; else inputfile  = argv[i++]; continue;
			case 'o': if(*(s+1)=='0') { outputstyle = 0; ++s; continue; }
					  if(outputfile || i==argc) goto h; else outputfile = argv[i++]; continue;
			case 'l': if(*(s+1)=='0') { liststyle = 0; ++s; continue; }
					  if(listfile   || i==argc) goto h; else listfile   = argv[i++]; continue;

			case 'I': if(c_includes || i==argc) goto h; else c_includes = argv[i++]; continue;
			case 'L': if(libraries|| i==argc) goto h; else libraries= argv[i++]; continue;
			case 'c': if(c_compiler || i==argc) goto h; else c_compiler = argv[i++]; continue;
			case 't': if(tempdir    || i==argc) goto h; else tempdir    = argv[i++]; continue;
			default:  goto h;
			}
		}
	}

	if(selftest)
	{
		// assemble a bunch of sources from the $PROJECT/Test/ directory
		// and compare them to old versions found in the original/ subdirectories.

		// if no path to the $PROJECT directory is given, then the current working directory is used.
		// all expected sources and original output files must be in place and match.
		cstr zasm = argv[0];
		cstr testdir = fullpath( inputfile ? inputfile : outputfile ? outputfile : "./" );
		if(errno==ok && lastchar(testdir)!='/') errno = ENOTDIR;
		if(errno)
		{
			if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", testdir, strerror(errno));
			return 1;
		}

		// if compiler was given, then it will be checked by the recursively called main()
		// else: no c compiler given: try to use scdd from $PROJECT/sdcc/bin/
		if(!c_compiler)
        {
			#ifdef _BSD
				c_compiler = catstr(testdir,"sdcc/bin/sdcc");
			#endif
			#ifdef _LINUX
				c_compiler = catstr(testdir,"sdcc/bin-Linux32/sdcc");
			#endif
			if(!is_file(c_compiler) || !is_executable(c_compiler))
				c_compiler = NULL;		// passing "-c" + NULL should not crash main()
		}

		uint errors = 0;
		char opt[] = "-v0e"; opt[2] += verbose;

		change_working_dir(catstr(testdir,"Test/ZXSP/"));
		{
			cstr a[] = { zasm, opt, "template_o.asm", "original/" };
			errors += main(NELEM(a),a);

			a[2] = "template_p.asm";
			errors += main(NELEM(a),a);

			a[2] = "template_ace.asm";
			errors += main(NELEM(a),a);

			a[2] = "template_tap.asm";
			errors += main(NELEM(a),a);

			a[2] = "template_z80.asm";
			errors += main(NELEM(a),a);

			a[2] = "template_sna.asm";
			errors += main(NELEM(a),a);

			a[2] = "mouse.asm";
			errors += main(NELEM(a),a);

			cstr b[] = { zasm, opt, "-c", c_compiler, "template_rom_with_c_code.asm", "original/" };
			errors += main(NELEM(b),b);
		}

		change_working_dir(catstr(testdir,"Test/Z80/"));
		{
			cstr a[] = { zasm, opt, "ZX Spectrum Rom/zx82.asm", "original/" };
			errors += main(NELEM(a),a);

			cstr c[] = { zasm,  opt, "--casefold", "CAMEL80-12/camel80.asm", "original/" };
			errors += main(NELEM(c),c);

			cstr d[] = { zasm, opt, "monitor_32k.asm", "original/" };
			errors += main(NELEM(d),d);

			cstr e[] = { zasm, opt, "allsrc.asm", "original/" };
			errors += main(NELEM(e),e);

			cstr f[] = { zasm, opt, "basic.asm", "original/" };
			errors += main(NELEM(f),f);

			cstr g[] = { zasm, opt, "MS-Basic.asm", "original/" };
			errors += main(NELEM(g),g);

			cstr h[] = { zasm, opt, "--reqcolon", "5bsort018.asm", "original/" };
			errors += main(NELEM(h),h);

			cstr i[] = { zasm, opt, "64#4+016.asm", "original/" };
			errors += main(NELEM(i),i);

			cstr j[] = { zasm, opt, "--8080", "CPM22.asm", "original/" };
			errors += main(NELEM(j),j);

			cstr k[] = { zasm, opt, "EMUF/EMUF.asm", "original/" };
			errors += main(NELEM(k),k);

			cstr l[] = { zasm, opt, "G007_MON_source_recreation.asm", "original/" };
			errors += main(NELEM(l),l);

			cstr n[] = { zasm, opt, "--reqcolon", "Hello World.asm", "original/" };
			errors += main(NELEM(n),n);

			cstr o[] = { zasm, opt, "--8080", "m80b.asm", "original/" };
			errors += main(NELEM(o),o);

			cstr p[] = { zasm, opt, "monitor_32k.asm", "original/" };
			errors += main(NELEM(p),p);

			cstr q[] = { zasm, opt, "MS-Basic.asm", "original/" };
			errors += main(NELEM(q),q);

			cstr r[] = { zasm, opt, "mybios4_mod.asm", "original/" };
			errors += main(NELEM(r),r);

			cstr s[] = { zasm, opt, "--dotnames", "--reqcolon", "OpenSE Basic/opense.asm", "original/" };
			errors += main(NELEM(s),s);

			cstr b[] = { zasm, opt, "ZX Spectrum Rom/sc178.asm", "original/" };
			errors += main(NELEM(b),b);

			cstr m[] = { zasm, opt, "test z80 cpu - prelim.asm", "original/" };
			errors += main(NELEM(m),m);

			cstr t[] = { zasm, opt, "--reqcolon", "VZ200 RS232 Terminal/VZ RS232.asm", "original/" };
			errors += main(NELEM(t),t);

			cstr u[] = { zasm, opt, "wmfw/wmfw2_5_orig.asm", "original/" };
			errors += main(NELEM(u),u);

			cstr v[] = { zasm, opt, "z80mon.asm", "original/" };
			errors += main(NELEM(v),v);

			cstr w[] = { zasm, opt, "z80sourc.asm", "original/" };
			errors += main(NELEM(w),w);

			cstr x[] = { zasm, opt, "--reqcolon", "zx81v2.asm", "original/" };
			errors += main(NELEM(x),x);

			cstr y[] = { zasm, opt, "--ixcbr2", "zasm-test-opcodes.asm", "original/" };
			errors += main(NELEM(y),y);
		}

		change_working_dir(catstr(testdir,"Test/8080/"));
		{
			cstr a[] = { zasm, opt, "--asm8080", "--reqcolon", "Altair8800_Monitor.asm", "original/" };
			errors += main(NELEM(a),a);

			cstr b[] = { zasm, opt, "8080PRE.asm", "original/" };
			errors += main(NELEM(b),b);

			cstr y[] = { zasm, opt, "zasm-test-opcodes.asm", "original/" };
			errors += main(NELEM(y),y);
		}

		change_working_dir(catstr(testdir,"Test/Z180/"));
		{
			cstr a[] = { zasm, opt, "--z180", "first.asm", "original/" };
			errors += main(NELEM(a),a);

			cstr b[] = { zasm, opt, "--z180", "counter master.asm", "original/" };
			errors += main(NELEM(b),b);

			cstr y[] = { zasm, opt, "zasm-test-opcodes.asm", "original/" };
			errors += main(NELEM(y),y);
		}

		if(verbose)
		{
			fprintf(stderr, "\ntotal time: %3.4f sec.\n", now()-start);
			if(errors>1) fprintf(stderr, "\nzasm: %u errors\n\n", errors);
			else fprintf(stderr, errors ? "\nzasm: 1 error\n\n" : "zasm: no errors\n");
		}
		return errors>0;
	}

// check options:
	if(targetZ180)			  targetZ80  = yes;		// implied
	if(asm8080 && !targetZ80) target8080 = yes;		// only implied   if not --Z80 set
	if(!target8080)			  targetZ80  = yes;		// default to Z80 if not --8080 or --asm8080 set

	if(asm8080 && targetZ180)
	{
		fprintf(stderr,"--> %s\nzasm: 1 error\n", "the 8080 assembler does not support Z180 opcodes.");
		return 1;
	}

	if(target8080 && targetZ80)
	{
		fprintf(stderr,"--> %s\nzasm: 1 error\n", "--8080 and --z80|--z180 are mutually exclusive.");
		return 1;
	}

	if(ixcbr2 || ixcbxh)
	{
		if(target8080)
		{
			fprintf(stderr,"--> %s\nzasm: 1 error\n", "i8080 has no index registers and no prefix 0xCB instructions.");
			return 1;
		}

		if(targetZ180)
		{
			fprintf(stderr,"--> %s\nzasm: 1 error\n", "no --ixcb… allowed: the Z180 traps illegal instructions");
			return 1;
		}

		if(asm8080)
		{
			fprintf(stderr,"--> %s\nzasm: 1 error\n", "the 8080 assembler does not support illegal opcodes.");
			return 1;
		}

		if(ixcbr2 && ixcbxh)
		{
			fprintf(stderr,"--> %s\nzasm: 1 error\n", "--ixcbr2 and --ixcbxh are mutually exclusive.");
			return 1;
		}
	}


// check source file:
	if(!inputfile)
	{
		h: fprintf(stderr, help, version, compiledatestr(), _PLATFORM);
		return 1;
	}
	inputfile = fullpath(inputfile,no);
	if(errno)
	{
		if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", inputfile, strerror(errno));
		return 1;
	}
	if(!is_file(inputfile))
	{
		if(verbose) fprintf(stderr, "--> %s: not a regular file\nzasm: 1 error\n", inputfile);
		return 1;
	}

// check output file or dir:
	if(!outputfile) outputfile = directory_from_path(inputfile);
	outputfile = fullpath(outputfile);
	if(errno && errno!=ENOENT)
	{
		if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", outputfile, strerror(errno));
		return 1;
	}

// check list file or dir:
	if(!listfile) listfile = directory_from_path(outputfile);
	listfile = fullpath(listfile);
	if(errno && errno!=ENOENT)
	{
		if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", listfile, strerror(errno));
		return 1;
	}

// check temp dir:
	if(!tempdir) tempdir = directory_from_path(outputfile);
	tempdir = fullpath(tempdir);
	if(errno && errno!=ENOENT)
	{
		if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", tempdir, strerror(errno));
		return 1;
	}
	if(lastchar(tempdir)!='/')
	{
		if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", tempdir, strerror(ENOTDIR));
		return 1;
	}

// check c_includes path:
	if(c_includes)
	{
		c_includes = fullpath(c_includes);
		if(errno==ok && lastchar(c_includes)!='/') errno = ENOTDIR;
		if(errno)
		{
			if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", c_includes, strerror(errno));
			return 1;
		}
	}

// check c_libraries path:
	if(libraries)
	{
		libraries = fullpath(libraries);
		if(errno==ok && lastchar(libraries)!='/') errno = ENOTDIR;
		if(errno)
		{
			if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", libraries, strerror(errno));
			return 1;
		}
	}

// check cc_path:
	if(c_compiler)
	{
		if(c_compiler[0]!='/')
		{
			cstr s = quick_fullpath(c_compiler);
			if(is_file(s))
				c_compiler = s;
			else
			{
				Array<str> ss;
				split(ss, getenv("PATH"), ':');
				for(uint i=0; i<ss.count(); i++)
				{
					s = catstr(ss[i],"/",c_compiler);
					if(is_file(s)) { c_compiler = s; break; }
				}
			}
		}

		c_compiler = fullpath(c_compiler);
		if(errno)
		{
			if(verbose) fprintf(stderr, "--> %s: %s\nzasm: 1 error\n", c_compiler, strerror(errno));
			return 1;
		}
		if(!is_file(c_compiler))
		{
			if(verbose) fprintf(stderr, "--> %s: not a regular file\nzasm: 1 error\n", c_compiler);
			return 1;
		}
		if(!is_executable(c_compiler))
		{
			if(verbose) fprintf(stderr, "--> %s: not executable\nzasm: 1 error\n", c_compiler);
			return 1;
		}
	}

// DO IT!
	Z80Assembler ass;
	ass.verbose = verbose;
	ass.ixcbr2_enabled = ixcbr2;
	ass.ixcbxh_enabled = ixcbxh;
	ass.target_8080    = target8080;
	ass.target_z80     = targetZ80;
	ass.target_z180    = targetZ180;
	ass.asm8080    = asm8080;
	ass.require_colon  = reqcolon;
	ass.allow_dotnames = dotnames;
	ass.casefold= casefold;
	ass.flat_operators = flatops;
	ass.max_errors     = maxerrors;
	ass.compare_to_old = compare;
	ass.cgi_mode	   = cgi_mode;
	if(c_includes) ass.c_includes = c_includes;
	if(libraries) ass.stdlib_dir  = libraries;
	if(c_compiler) ass.c_compiler = c_compiler;
	ass.assembleFile( inputfile, outputfile, listfile, tempdir, liststyle, outputstyle, clean );

	uint errors = ass.errors.count();

	if(verbose)		// show errors on stderr:
	{
		cstr current_file = NULL;
		for(uint i=0; i<errors; i++)
		{
			Error const& e = ass.errors[i];
			SourceLine* sourceline = e.sourceline;
			if(!sourceline)
			{
				if(current_file) fprintf(stderr,"\n"); current_file=NULL; fprintf(stderr,"--> %s\n",e.text);
				continue;
			}

			cstr filename = sourceline->sourcefile;
			if(filename!=current_file)				// note: compare pointers!
			{
				current_file = filename;
				fprintf(stderr, "\nin file %s:\n", filename_from_path(filename));
			}

			cstr linenumber = numstr(sourceline->sourcelinenumber+1);
			fprintf(stderr, "%s: %s\n", linenumber, sourceline->text);
			fprintf(stderr, "%s%s^ %s\n", spacestr(strlen(linenumber)+2), sourceline->whitestr(), e.text);
		}

		fprintf(stderr, "assemble: %u lines\n", ass.source.count());
		fprintf(stderr, "time: %3.4f sec.\n", now()-start);
		if(errors>1) fprintf(stderr, "\nzasm: %u errors\n\n", errors);
		else fprintf(stderr, errors ? "\nzasm: 1 error\n\n" : "zasm: no errors\n");
	}

	return errors>0;	// 0=ok, 1=errors
}
Exemple #27
0
static void
generic_dialog_add_images (GenericDialog * gd, const gchar * path1,
			   const gchar * path2)
{
    ImageWindow *iw;
    GtkWidget *hbox = NULL;
    GtkWidget *vbox;
    GtkWidget *sep;
    GtkWidget *label;

    if (!path1)
	return;

    sep = gtk_hseparator_new ();
    gtk_box_pack_start (GTK_BOX (gd->vbox), sep, FALSE, FALSE, 5);
    gtk_widget_show (sep);

    if (path2)
    {
	hbox = gtk_hbox_new (TRUE, 5);
	gtk_box_pack_start (GTK_BOX (gd->vbox), hbox, TRUE, TRUE, 0);
	gtk_widget_show (hbox);
    }

    /*
     * image 1 
     */

    vbox = gtk_vbox_new (FALSE, 0);
    if (hbox)
    {
	gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
    }
    else
    {
	gtk_box_pack_start (GTK_BOX (gd->vbox), vbox, TRUE, TRUE, 0);
    }
    gtk_widget_show (vbox);

    iw = image_new (TRUE);
    gtk_widget_set_usize (iw->widget, DIALOG_DEF_IMAGE_DIM_X,
			  DIALOG_DEF_IMAGE_DIM_Y);
    gtk_box_pack_start (GTK_BOX (vbox), iw->widget, TRUE, TRUE, 0);
    image_set_path (iw, path1);
    gtk_widget_show (iw->widget);

    label = gtk_label_new (filename_from_path (path1));
    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
    gtk_widget_show (label);

    /*
     * image 2 
     */

    if (hbox && path2)
    {
	vbox = gtk_vbox_new (FALSE, 0);
	gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
	gtk_widget_show (vbox);

	iw = image_new (TRUE);
	gtk_widget_set_usize (iw->widget, DIALOG_DEF_IMAGE_DIM_X,
			      DIALOG_DEF_IMAGE_DIM_Y);
	gtk_box_pack_start (GTK_BOX (vbox), iw->widget, TRUE, TRUE, 0);
	image_set_path (iw, path2);
	gtk_widget_show (iw->widget);

	label = gtk_label_new (filename_from_path (path2));
	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
	gtk_widget_show (label);
    }
}
Exemple #28
0
static gboolean collection_save_private(CollectionData *cd, const gchar *path)
{
	SecureSaveInfo *ssi;
	GList *work;
	gchar *pathl;

	if (!path && !cd->path) return FALSE;

	if (!path)
		{
		path = cd->path;
		}


	pathl = path_from_utf8(path);
	ssi = secure_open(pathl);
	g_free(pathl);
	if (!ssi)
		{
		log_printf(_("failed to open collection (write) \"%s\"\n"), path);
		return FALSE;
		}

	secure_fprintf(ssi, "%s collection\n", GQ_COLLECTION_MARKER);
	secure_fprintf(ssi, "#created with %s version %s\n", GQ_APPNAME, VERSION);

	collection_update_geometry(cd);
	if (cd->window_read)
		{
		secure_fprintf(ssi, "#geometry: %d %d %d %d\n", cd->window_x, cd->window_y, cd->window_w, cd->window_h);
		}

	work = cd->list;
	while (work && secsave_errno == SS_ERR_NONE)
		{
		CollectInfo *ci = work->data;
		secure_fprintf(ssi, "\"%s\"\n", ci->fd->path);
		work = work->next;
		}

	secure_fprintf(ssi, "#end\n");

	if (secure_close(ssi))
		{
		log_printf(_("error saving collection file: %s\nerror: %s\n"), path,
			    secsave_strerror(secsave_errno));
		return FALSE;
		}

	if (!cd->path || strcmp(path, cd->path) != 0)
		{
		gchar *buf = cd->path;
		cd->path = g_strdup(path);
		path = cd->path;
		g_free(buf);

		g_free(cd->name);
		cd->name = g_strdup(filename_from_path(cd->path));

		collection_path_changed(cd);
		}

	cd->changed = FALSE;

	return TRUE;
}
void
scan_playlist(const char *file, time_t mtime, int dir_id)
{
  FILE *fp;
  struct media_file_info mfi;
  struct playlist_info *pli;
  struct stat sb;
  char buf[PATH_MAX];
  char *path;
  const char *filename;
  char *ptr;
  size_t len;
  int extinf;
  int pl_id;
  int pl_format;
  int ntracks;
  int nadded;
  int ret;

  ptr = strrchr(file, '.');
  if (!ptr)
    return;

  if (strcasecmp(ptr, ".m3u") == 0)
    pl_format = PLAYLIST_M3U;
  else if (strcasecmp(ptr, ".pls") == 0)
    pl_format = PLAYLIST_PLS;
  else
    return;

  filename = filename_from_path(file);

  /* Fetch or create playlist */
  pli = db_pl_fetch_bypath(file);
  if (pli)
    {
      db_pl_ping(pli->id);

      if (mtime && (pli->db_timestamp >= mtime))
	{
	  DPRINTF(E_LOG, L_SCAN, "Unchanged playlist found, not processing '%s'\n", file);

	  // Protect this playlist's radio stations from purge after scan
	  db_pl_ping_items_bymatch("http://", pli->id);
	  free_pli(pli, 0);
	  return;
	}

      DPRINTF(E_LOG, L_SCAN, "Modified playlist found, processing '%s'\n", file);

      pl_id = pli->id;
      db_pl_clear_items(pl_id);
    }
  else
    {
      DPRINTF(E_LOG, L_SCAN, "New playlist found, processing '%s'\n", file);

      CHECK_NULL(L_SCAN, pli = calloc(1, sizeof(struct playlist_info)));

      pli->type = PL_PLAIN;

      /* Get only the basename, to be used as the playlist title */
      pli->title = strip_extension(filename);

      pli->path = strdup(file);
      snprintf(buf, sizeof(buf), "/file:%s", file);
      pli->virtual_path = strip_extension(buf);

      pli->directory_id = dir_id;

      ret = db_pl_add(pli, &pl_id);
      if (ret < 0)
	{
	  DPRINTF(E_LOG, L_SCAN, "Error adding playlist '%s'\n", file);

	  free_pli(pli, 0);
	  return;
	}

      DPRINTF(E_INFO, L_SCAN, "Added new playlist as id %d\n", pl_id);
    }

  free_pli(pli, 0);

  ret = stat(file, &sb);
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not stat() '%s': %s\n", file, strerror(errno));
      return;
    }

  fp = fopen(file, "r");
  if (!fp)
    {
      DPRINTF(E_LOG, L_SCAN, "Could not open playlist '%s': %s\n", file, strerror(errno));
      return;
    }

  db_transaction_begin();

  extinf = 0;
  memset(&mfi, 0, sizeof(struct media_file_info));
  ntracks = 0;
  nadded = 0;

  while (fgets(buf, sizeof(buf), fp) != NULL)
    {
      len = strlen(buf);

      /* rtrim and check that length is sane (ignore blank lines) */
      while ((len > 0) && isspace(buf[len - 1]))
	{
	  len--;
	  buf[len] = '\0';
	}
      if (len < 1)
	continue;

      /* Saves metadata in mfi if EXTINF metadata line */
      if ((pl_format == PLAYLIST_M3U) && extinf_get(buf, &mfi, &extinf))
	continue;

      /* For pls files we are only interested in the part after the FileX= entry */
      path = NULL;
      if ((pl_format == PLAYLIST_PLS) && (strncasecmp(buf, "file", strlen("file")) == 0))
	path = strchr(buf, '=') + 1;
      else if (pl_format == PLAYLIST_M3U)
	path = buf;

      if (!path)
	continue;

      /* Check that first char is sane for a path */
      if ((!isalnum(path[0])) && (path[0] != '/') && (path[0] != '.'))
	continue;

      /* Check if line is an URL, will be added to library, otherwise it should already be there */
      if (strncasecmp(path, "http://", 7) == 0)
	ret = process_url(pl_id, path, sb.st_mtime, extinf, &mfi);
      else
	ret = process_regular_file(pl_id, path);

      ntracks++;
      if (ntracks % 200 == 0)
	{
	  DPRINTF(E_LOG, L_SCAN, "Processed %d items...\n", ntracks);
	  db_transaction_end();
	  db_transaction_begin();
	}

      if (ret == 0)
	nadded++;

      /* Clean up in preparation for next item */
      extinf = 0;
      free_mfi(&mfi, 1);
    }

  db_transaction_end();

  /* We had some extinf that we never got to use, free it now */
  if (extinf)
    free_mfi(&mfi, 1);

  if (!feof(fp))
    DPRINTF(E_LOG, L_SCAN, "Error reading playlist '%s' (only added %d tracks): %s\n", file, nadded, strerror(errno));
  else
    DPRINTF(E_LOG, L_SCAN, "Done processing playlist, added/modified %d items\n", nadded);

  fclose(fp);
}
static int
process_regular_file(int pl_id, char *path)
{
  struct query_params qp;
  char filter[PATH_MAX];
  const char *a;
  const char *b;
  char *dbpath;
  char *winner;
  int score;
  int i;
  int ret;

  // Playlist might be from Windows so we change backslash to forward slash
  for (i = 0; i < strlen(path); i++)
    {
      if (path[i] == '\\')
	path[i] = '/';
    }

  ret = db_snprintf(filter, sizeof(filter), "f.fname = '%q' COLLATE NOCASE", filename_from_path(path));
  if (ret < 0)
    {
      DPRINTF(E_LOG, L_SCAN, "Path in playlist is too long: '%s'\n", path);
      return -1;
    }

  memset(&qp, 0, sizeof(struct query_params));

  qp.type = Q_BROWSE_PATH;
  qp.sort = S_NONE;
  qp.filter = filter;

  ret = db_query_start(&qp);
  if (ret < 0)
    {
      db_query_end(&qp);
      return -1;
    }

  winner = NULL;
  score = 0;
  while ((db_query_fetch_string(&qp, &dbpath) == 0) && dbpath)
    {
      if (qp.results == 1)
	{
	  winner = strdup(dbpath);
	  break;
	}

      for (i = 0, a = NULL, b = NULL; (parent_dir(&a, path) == 0) && (parent_dir(&b, dbpath) == 0) && (strcasecmp(a, b) == 0); i++)
	;

      DPRINTF(E_SPAM, L_SCAN, "Comparison of '%s' and '%s' gave score %d\n", dbpath, path, i);

      if (i > score)
	{
	  free(winner);
	  winner = strdup(dbpath);
	  score = i;
	}
      else if (i == score)
	{
	  free(winner);
	  winner = NULL;
	}
    }

  db_query_end(&qp);

  if (!winner)
    {
      DPRINTF(E_LOG, L_SCAN, "No file in the library matches playlist entry '%s'\n", path);
      return -1;
    }

  DPRINTF(E_DBG, L_SCAN, "Adding '%s' to playlist %d (results %d)\n", winner, pl_id, qp.results);

  db_pl_add_item_bypath(pl_id, winner);
  free(winner);

  return 0;
}