Exemple #1
0
static gboolean
sweep_dir_exists (char * pathname)
{
  struct stat statbuf;
  char buf[512];

  gchar * dirname;

  dirname = g_dirname (pathname);

  if (dirname && strcmp (dirname, "") && stat (dirname, &statbuf) == -1) {
    switch (errno) {
    case ENOENT:
      snprintf (buf, sizeof (buf), _("%s does not exist."), dirname);
      info_dialog_new (_("Directory does not exist"), NULL, buf);
      g_free (dirname);
      return FALSE;
      break;
    default:
      break;
    }
  }

  /* dirname is either NULL, "" or an existing directory */

  return TRUE;
}
Exemple #2
0
static void autolog_log(void *server, const char *target)
{
    LOG_REC *log;
    char *fname, *dir, *str;

    log = log_find_item(target);
    if (log != NULL) return;

    fname = parse_special_string(autolog_path, server, NULL, target, NULL);
    if (log_find(fname) == NULL) {
        str = convert_home(fname);
        dir = g_dirname(str);
        g_free(str);

        mkdir(dir, LOG_DIR_CREATE_MODE);
        g_free(dir);

        log = log_create_rec(fname, autolog_level, target);
        if (log != NULL) {
            log->temp = TRUE;
            log_update(log);
            log_start_logging(log);
        }
    }
    g_free(fname);
}
static void prefs_spelling_btn_aspell_path_clicked_cb(GtkWidget *widget,
						     gpointer data)
{
	SpellingPage *spelling = (SpellingPage *) data;
	gchar *file_path;
	GtkWidget *new_menu;

	file_path = filesel_select_file(_("Select dictionaries location"),
					prefs_common.aspell_path);
	if (file_path != NULL) {
		gchar *tmp_path, *tmp;

		tmp_path = g_dirname(file_path);
		tmp = g_strdup_printf("%s%s", tmp_path, G_DIR_SEPARATOR_S);
		g_free(tmp_path);

		new_menu = gtkaspell_dictionary_option_menu_new(tmp);
		gtk_option_menu_set_menu(GTK_OPTION_MENU(spelling->optmenu_dictionary),
					 new_menu);

		gtk_entry_set_text(GTK_ENTRY(spelling->entry_aspell_path), tmp);
		/* select first one */
		gtk_option_menu_set_history(GTK_OPTION_MENU(
					spelling->optmenu_dictionary), 0);
	
		g_free(tmp);

	}
}
Exemple #4
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 );
}
Exemple #5
0
/**
 * Menu callback: Save the selected attachment
 * \param mimeview Current display
 */
static void mimeview_save_as(MimeView *mimeview)
{
	gchar *filename;
	gchar *filepath = NULL;
	gchar *filedir = NULL;
	MimeInfo *partinfo;
	gchar *partname = NULL;

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

	partinfo = mimeview_get_selected_part(mimeview);
	if (!partinfo) { 
		partinfo = (MimeInfo *) gtk_object_get_data
			(GTK_OBJECT(mimeview->popupmenu),
			 "pop_partinfo");
		gtk_object_set_data(GTK_OBJECT(mimeview->popupmenu),
				    "pop_partinfo", NULL);
	}			 
	g_return_if_fail(partinfo != NULL);
	
	if (get_part_name(partinfo) == NULL) {
		return;
	}

	partname = g_strdup(get_part_name(partinfo));
	subst_for_filename(partname);

	if (prefs_common.attach_save_dir)
		filepath = g_strconcat(prefs_common.attach_save_dir,
				       G_DIR_SEPARATOR_S, partname, NULL);
	else
		filepath = g_strdup(partname);

	g_free(partname);

	filename = filesel_select_file(_("Save as"), filepath);
	if (!filename) {
		g_free(filepath);
		return;
	}

	mimeview_write_part(filename, partinfo);

	filedir = g_dirname(filename);
	if (filedir && strcmp(filedir, ".")) {
		if (prefs_common.attach_save_dir)
			g_free(prefs_common.attach_save_dir);
		prefs_common.attach_save_dir = g_strdup(filedir);
	}

	g_free(filedir);
	g_free(filepath);
}
Exemple #6
0
int log_start_logging(LOG_REC *log)
{
	char *dir;

	g_return_val_if_fail(log != NULL, FALSE);

	if (log->handle != -1)
		return TRUE;

	/* Append/create log file */
	g_free_not_null(log->real_fname);
	log->real_fname = log_filename(log);

	if (log->real_fname != NULL &&
	    strcmp(log->real_fname, log->fname) != 0) {
		/* path may contain variables (%time, $vars),
		   make sure the directory is created */
		dir = g_dirname(log->real_fname);
		mkpath(dir, log_dir_create_mode);
		g_free(dir);
	}

	log->handle = log->real_fname == NULL ? -1 :
		open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
		     log_file_create_mode);
	if (log->handle == -1) {
		signal_emit("log create failed", 1, log);
		log->failed = TRUE;
		return FALSE;
	}
#ifdef HAVE_FCNTL
        memset(&lock, 0, sizeof(lock));
	lock.l_type = F_WRLCK;
	if (fcntl(log->handle, F_SETLK, &lock) == -1 && errno == EACCES) {
		close(log->handle);
		log->handle = -1;
		signal_emit("log locked", 1, log);
		log->failed = TRUE;
		return FALSE;
	}
#endif
	lseek(log->handle, 0, SEEK_END);

	log->opened = log->last = time(NULL);
	log_write_timestamp(log->handle,
			    settings_get_str("log_open_string"),
			    "\n", log->last);

	signal_emit("log started", 1, log);
	log->failed = FALSE;
	return TRUE;
}
Exemple #7
0
/*! \brief changes the current page in toplevel
 *  \par Function Description
 *  Changes the current page in \a toplevel to the page \a p_new.
 *
 *  \param toplevel  The TOPLEVEL object
 *  \param p_new     The PAGE to go to
 */
void s_page_goto (TOPLEVEL *toplevel, PAGE *p_new) 
{
  gchar *dirname;

  toplevel->page_current = p_new;

  dirname = g_dirname (p_new->page_filename);
  if (chdir (dirname)) {
    /* An error occured with chdir */
#warning FIXME: What do we do?
  }
  g_free (dirname);

}
Exemple #8
0
gboolean mape_config_file_serialise(MapeConfigFile* file,
                                    GError** error)
{
	gchar* dir;
	gchar* content;
	gchar* temp;
	gsize i;

	int dir_result;
	gboolean cont_result;

	dir = g_dirname(file->file_path);
	dir_result = g_mkdir_with_parents(dir, 0755);

	g_free(dir);
	if(dir_result == -1)
	{
		g_set_error(
			error,
			g_quark_from_static_string("MAPE_CONFIG_FILE_ERROR"),
			errno,
			"%s",
			g_strerror(errno)
		);

		return FALSE;
	}

	content = g_strdup("");
	for(i = 0; i < file->entry_count; ++ i)
	{
		temp = g_strconcat(
			content,
			file->entries[i].key,
			"=",
			file->entries[i].value,
			"\n",
			NULL
		);

		g_free(content);
		content = temp;
	}

	cont_result = g_file_set_contents(file->file_path, content, -1, error);
	g_free(content);

	return(cont_result);
}
Exemple #9
0
void save_settings(Preferences *pref)
{
	gchar *path;
	gchar *dir;
	GKeyFile* key;
	GError *err = NULL;
	gchar *data;
	gsize data_len = 0;
	GtkWidget *dialog;

	path = get_config_path();
	dir = g_dirname(path);
	
	key = g_key_file_new();
	g_key_file_load_from_file(key, path, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
	
	g_key_file_set_integer(key, "core", "backend", pref->backend);
	g_key_file_set_string(key, "core", "download_dir", pref->download_dir);
	g_key_file_set_integer(key, "core", "max_concurrent_downloads", pref->max_concurrent_downloads);
	g_key_file_set_boolean(key, "core", "use_schedule", pref->use_schedule);
	g_key_file_set_integer(key, "core", "start_time_hour", pref->start_time_hour);
	g_key_file_set_integer(key, "core", "start_time_minute", pref->start_time_minute);
	g_key_file_set_integer(key, "core", "end_time_hour", pref->end_time_hour);
	g_key_file_set_integer(key, "core", "end_time_minute", pref->end_time_minute);
	
	data = g_key_file_to_data(key, &data_len, &err);
	if (err) {
		dialog = gtk_message_dialog_new (GTK_WINDOW(g_GAria2),
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_MESSAGE_ERROR,
                                  GTK_BUTTONS_CLOSE,
                                  "Error: %s", err->message);
 		gtk_dialog_run (GTK_DIALOG (dialog));
 		gtk_widget_destroy (dialog);
		g_error_free(err);
	}
	
	if (!g_file_test(dir, G_FILE_TEST_EXISTS)) {
		g_mkdir_with_parents(dir, 0700);
	}
	g_file_set_contents(path, data, data_len, NULL);
	
	g_free(data);
	g_free(path);
	g_free(dir);
	g_key_file_free(key);
}
Exemple #10
0
static void autolog_open(SERVER_REC *server, const char *server_tag,
			 const char *target)
{
	LOG_REC *log;
	char *fname, *dir, *fixed_target, *params;

	log = logs_find_item(LOG_ITEM_TARGET, target, server_tag, NULL);
	if (log != NULL && !log->failed) {
		log_start_logging(log);
		return;
	}

	/* '/' -> '_' - don't even accidentally try to log to
	   #../../../file if you happen to join to such channel..

	   '%' -> '%%' - so strftime() won't mess with them */
	fixed_target = escape_target(target);
	if (CHAT_PROTOCOL(server)->case_insensitive)
		g_strdown(fixed_target);

        /* $0 = target, $1 = server tag */
        params = g_strconcat(fixed_target, " ", server_tag, NULL);
	g_free(fixed_target);

	fname = parse_special_string(autolog_path, server, NULL,
				     params, NULL, 0);
	g_free(params);

	if (log_find(fname) == NULL) {
		log = log_create_rec(fname, autolog_level);
                if (!settings_get_bool("autolog_colors"))
			log->colorizer = log_colorizer_strip;
		log_item_add(log, LOG_ITEM_TARGET, target, server_tag);

		dir = g_dirname(log->real_fname);
		mkpath(dir, log_dir_create_mode);
		g_free(dir);

		log->temp = TRUE;
		log_update(log);
		log_start_logging(log);
	}
	g_free(fname);
}
Exemple #11
0
static void rename_file(const char *old_path, const char *new_name, gboolean showBox)
{
	char *new_path;
	char *dir;
	int res;

	dir = g_dirname(old_path);
	new_path = fu_join_path(dir, new_name);
	free(dir);

	if (fu_exists(new_path)) {
		int button;
		button = message_box(w_main, _("File Exists"), 
				     _("A file with this name already exists.\nDo you want to overwrite it?"), 
				     GTK_BUTTONS_YES_NO, GTK_RESPONSE_NO);
		if (button == GTK_RESPONSE_NO) {
			free(new_path);
			return;
		}
	}

	res = rename(old_path, new_path);
	if (res != 0) {
		int save_errno = errno;
		GString *msg = g_string_sized_new(256);

		g_string_printf(msg, _("Error renaming file:\n%s (%d)"), strerror(save_errno), save_errno);
		
		if(showBox)
			message_box(w_main, _("Error Renaming File"), msg->str, GTK_BUTTONS_OK, GTK_RESPONSE_OK);
		else {
			sb_clear();
			sb_printf(msg->str);
		}

		g_string_free(msg, TRUE);
	}
	else {
		fl_refresh(TRUE);
	}

	free(new_path);
}
Exemple #12
0
void maintainr_config_save (MaintainrConfig *conf)
{
	gchar *path;
	gchar *data;
	FILE *file;
	GList *iter;

	path = conf_file_path ();

	if (access (path, F_OK) != 0) {
		data = g_dirname (path);
		g_mkdir_with_parents (data, 0744);
		g_free (data);
	}

	file = fopen (path, "w");
	if (file != NULL) {
		fprintf (file, "<maintainr>\n\n");

		fprintf (file, "<application>\n");
		fprintf (file, "<windowx>%d</windowx>\n", conf->priv->window_x);
		fprintf (file, "<windowy>%d</windowy>\n", conf->priv->window_y);
		fprintf (file, "<windowwidth>%d</windowwidth>\n", conf->priv->window_width);
		fprintf (file, "<windowheight>%d</windowheight>\n", conf->priv->window_height);
		fprintf (file, "</application>\n");

		for (iter = conf->priv->projects; iter; iter = iter->next) {
			data = maintainr_projectconf_write (iter->data);
			fprintf (file, "%s\n", data);
			g_free (data);
		}

		fprintf (file, "\n</maintainr>\n");
		fclose (file);
	}
	else {
		g_warning ("Unable to save configuration on file %s: %s", path, strerror (errno));
	}

	g_free (path);
}
Exemple #13
0
GList *filename_complete(const char *path, const char *default_path)
{
        GList *list;
	DIR *dirp;
	struct dirent *dp;
	const char *basename;
	char *realpath, *dir, *name;
	int len;

	g_return_val_if_fail(path != NULL, NULL);

	list = NULL;

	/* get directory part of the path - expand ~/ */
	realpath = convert_home(path);
	if (USE_DEFAULT_PATH(realpath, default_path)) {
                g_free(realpath);
		realpath = g_strconcat(default_path, G_DIR_SEPARATOR_S,
				       path, NULL);
	}

	/* open directory for reading */
	dir = g_dirname(realpath);
	dirp = opendir(dir);
	g_free(dir);
        g_free(realpath);

	if (dirp == NULL)
		return NULL;

	dir = g_dirname(path);
	if (*dir == G_DIR_SEPARATOR && dir[1] == '\0') {
                /* completing file in root directory */
		*dir = '\0';
	} else if (IS_CURRENT_DIR(dir) && !IS_CURRENT_DIR(path)) {
		/* completing file in default_path
		   (path not set, and leave it that way) */
		g_free_and_null(dir);
	}

	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 = dir == NULL ? g_strdup(dp->d_name) :
				g_strdup_printf("%s"G_DIR_SEPARATOR_S"%s", dir, dp->d_name);
			list = list_add_file(list, name, default_path);
			g_free(name);
		}
	}
	closedir(dirp);

	g_free_not_null(dir);
        return list;
}
Exemple #14
0
int
main (int argc, char *argv[])
{
  int cnt;
  const char *p;
  char arg[128];
  
#ifdef __WIN32__
  HMODULE hModule;
  char *sBuffer;
  DWORD dWord;
  char *dirname;
  char *base_dir;
  char *pixmap_dir;
  char *locale_dir;
  
  // Init the path for the Windows version by getting the 
  // executable location.
  hModule = GetModuleHandle("skinedit.exe");
  sBuffer = (char *) malloc(4096 * sizeof(char));
  dWord = GetModuleFileName(hModule, sBuffer, 4096);
  dirname = g_dirname(sBuffer);
  base_dir = g_strconcat(dirname, "\\", NULL);
  g_free(dirname);
  free(sBuffer);
  
  pixmap_dir = g_strconcat(base_dir, "pixmaps\\", NULL);
  locale_dir = g_strconcat(base_dir, "locale\\", NULL);
#endif

#ifdef ENABLE_NLS
#ifndef __WIN32__
  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#else
  bindtextdomain(PACKAGE, locale_dir);
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif
#endif

  gtk_set_locale ();
  gtk_init (&argc, &argv);

#ifndef __WIN32__
  add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
#else
  add_pixmap_directory (pixmap_dir);
#endif

  signal(SIGINT, signal_handler);

  fprintf(stdout, _("SkinEdit v%s, (C) 2002-2003 Julien BLACHE <*****@*****.**>\n"), VERSION);
  fprintf(stdout, _("                  2004-2005 Romain Lievin <*****@*****.**>\n"));
  fprintf(stdout, "\n");
  fprintf(stdout, _("This program is free software; you can redistribute it and/or modify\n"));
  fprintf(stdout, _("it under the terms of the GNU General Public License as published by\n"));
  fprintf(stdout, _("the Free Software Foundation; version 2 of the License\n"));
  fprintf(stdout, _("This program is distributed in the hope that it will be useful,\n"));
  fprintf(stdout, _("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"));
  fprintf(stdout, _("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"));
  fprintf(stdout, _("GNU General Public License for more details.\n"));

  gtk_widget_show (main_wnd = create_main_window());

  sbar_print(_("Skinedit v%s -- Supported formats : TiEmu v2.00 (R/W), VTiv2.1 (R/W), VTiv2.5 (R/W)"), VERSION);

    // scan command line
    for (cnt = 1; cnt < argc; cnt++) {
      
      // get argument
      p = argv[cnt];
      if (*p == '-') {
	// argument
	p++;
      } else {
	// filename
	if(load_skin(p) == 0)
	  skin_infos.changed = 1;
      }
      
      strcpy(arg, p);
      
      if (strexact(arg, "-help") || strexact(arg, "h"))
	help();
      if (strexact(arg, "-version") || strexact(arg, "v"))
	exit(0);
    }
    
    gtk_main ();
    return 0;
}
Exemple #15
0
/*! \brief Opens the schematic file with fine-grained control over behaviour.
 *  \par Function Description
 *  Opens the schematic file and carries out a number of actions
 *  depending on the \a flags set.  If #F_OPEN_RC is set, executes
 *  configuration files found in the target directory.  If
 *  #F_OPEN_CHECK_BACKUP is set, warns user if a backup is found for
 *  the file being loaded, and possibly prompts user for whether to
 *  load the backup instead.  If #F_OPEN_RESTORE_CWD is set, does not
 *  change the working directory to that of the file being loaded.
 *
 *  \param [in,out] toplevel  The TOPLEVEL object to load the schematic into.
 *  \param [in]     filename   A character string containing the file name
 *                             to open.
 *  \param [in]     flags      Combination of #FOpenFlags values.
 *  \param [in,out] err  #GError structure for error reporting, or
 *                       NULL to disable error reporting
 *
 *  \return 0 on failure, 1 on success.
 */
int f_open_flags(TOPLEVEL *toplevel, PAGE *page,
                 const gchar *filename,
                 const gint flags, GError **err)
{
  int opened=FALSE;
  char *full_filename = NULL;
  char *full_rcfilename = NULL;
  char *file_directory = NULL;
  char *saved_cwd = NULL;
  char *backup_filename = NULL;
  char load_backup_file = 0;
  GError *tmp_err = NULL;

  /* has the head been freed yet? */
  /* probably not hack PAGE */

  set_window(toplevel, page,
             toplevel->init_left, toplevel->init_right,
             toplevel->init_top,  toplevel->init_bottom);


  /* Cache the cwd so we can restore it later. */
  if (flags & F_OPEN_RESTORE_CWD) {
    saved_cwd = g_get_current_dir();
  }

  /* get full, absolute path to file */
  full_filename = f_normalize_filename (filename, &tmp_err);
  if (full_filename == NULL) {
    g_set_error (err, G_FILE_ERROR, tmp_err->code,
                 _("Cannot find file %s: %s"),
                 filename, tmp_err->message);
    g_error_free(tmp_err);
    return 0;
  }

  /* write full, absolute filename into page->page_filename */
  g_free(page->page_filename);
  page->page_filename = g_strdup(full_filename);

  /* Before we open the page, let's load the corresponding gafrc. */
  /* First cd into file's directory. */
  file_directory = g_dirname (full_filename);

  if (file_directory) { 
    if (chdir (file_directory)) {
      /* Error occurred with chdir */
#warning FIXME: What do we do?
    }
  }

  /* Now open RC and process file */
  if (flags & F_OPEN_RC) {
    full_rcfilename = g_build_filename (file_directory, "gafrc", NULL);
    g_rc_parse_file (toplevel, full_rcfilename, &tmp_err);
    if (tmp_err != NULL) {
      /* Config files are allowed to be missing or skipped; check for
       * this. */
      if (!g_error_matches (tmp_err, G_FILE_ERROR, G_FILE_ERROR_NOENT) &&
          !g_error_matches (tmp_err, EDA_ERROR, EDA_ERROR_RC_TWICE)) {
        s_log_message ("%s\n", tmp_err->message);
      }
      g_error_free (tmp_err);
      tmp_err = NULL;
    }
  }

  g_free (file_directory);

  if (flags & F_OPEN_CHECK_BACKUP) {
    /* Check if there is a newer autosave backup file */
    GString *message;
    gboolean active_backup = f_has_active_autosave (full_filename, &tmp_err);
    backup_filename = f_get_autosave_filename (full_filename);

    if (tmp_err != NULL) g_warning ("%s\n", tmp_err->message);
    if (active_backup) {
      message = g_string_new ("");
      g_string_append_printf(message, _("\nWARNING: Found an autosave backup file:\n  %s.\n\n"), backup_filename);
      if (tmp_err != NULL) {
        g_string_append(message, _("I could not guess if it is newer, so you have to do it manually.\n"));
      } else {
        g_string_append(message, _("The backup copy is newer than the schematic, so it seems you should load it instead of the original file.\n"));
      }
      g_string_append (message, _("Gschem usually makes backup copies automatically, and this situation happens when it crashed or it was forced to exit abruptly.\n"));
      if (toplevel->load_newer_backup_func == NULL) {
        g_warning ("%s", message->str);
        g_warning (_("\nRun gschem and correct the situation.\n\n"));
      } else {
        /* Ask the user if load the backup or the original file */
        if (toplevel->load_newer_backup_func
            (toplevel->load_newer_backup_data, message)) {
          /* Load the backup file */
          load_backup_file = 1;
        }
      }
      g_string_free (message, TRUE);
    }
    if (tmp_err != NULL) g_error_free (tmp_err);
  }

  /* Now that we have set the current directory and read
   * the RC file, it's time to read in the file. */
  if (load_backup_file == 1) {
    /* Load the backup file */
    s_page_append_list (toplevel, page,
                        o_read (toplevel, NULL, backup_filename, &tmp_err));
  } else {
    /* Load the original file */
    s_page_append_list (toplevel, page,
                        o_read (toplevel, NULL, full_filename, &tmp_err));
  }

  if (tmp_err == NULL)
    opened = TRUE;
  else
    g_propagate_error (err, tmp_err);

  if (load_backup_file == 0) {
    /* If it's not the backup file */
    page->CHANGED=0; /* added 4/7/98 */
  } else {
    /* We are loading the backup file, so gschem should ask
       the user if save it or not when closing the page. */
    page->CHANGED=1;
  }

  g_free(full_filename);
  g_free(full_rcfilename);
  g_free (backup_filename);

  /* Reset the directory to the value it had when f_open was
   * called. */
  if (flags & F_OPEN_RESTORE_CWD) {
    if (chdir (saved_cwd)) {
      /* Error occurred with chdir */
#warning FIXME: What do we do?
    }
    g_free(saved_cwd);
  }

  return opened;
}
Exemple #16
0
/* Returns a NodeInfo struct for the given node */
const struct NodeInfo *
get_node_info( GNode *node )
{
	static struct NodeInfo ninfo = {
		NULL,	/* name */
		NULL,	/* prefix */
		NULL,	/* size */
		NULL,	/* size_abbr */
		NULL,	/* size_alloc */
		NULL,	/* size_alloc_abbr */
		NULL,	/* user_name */
		NULL,	/* group_name */
		NULL,	/* atime */
		NULL,	/* mtime */
		NULL,	/* ctime */
		NULL,	/* subtree_size */
		NULL,	/* subtree_size_abbr */
		NULL,	/* file_type_desc */
		NULL,	/* target */
		NULL	/* abstarget */
	};
	struct passwd *pw;
	struct group *gr;
	static char blank[] = "-";
	const char *absname;
	const char *cstr;
	char *str;

	absname = node_absname( node );

	/* Name */
	if (strlen( NODE_DESC(node)->name ) > 0)
		cstr = NODE_DESC(node)->name;
	else
		cstr = _("/. (root)");
	ninfo.name = xstrredup( ninfo.name, cstr );
	/* Prefix */
	str = g_dirname( absname );
	if (!strcmp( str, "/" )) {
		g_free( str );
		str = g_strdup( _("/. (root)") );
	}
	ninfo.prefix = xstrredup( ninfo.prefix, str );
	g_free( str );

	/* Size */
	ninfo.size = xstrredup( ninfo.size, i64toa( NODE_DESC(node)->size ) );
	ninfo.size_abbr = xstrredup( ninfo.size_abbr, abbrev_size( NODE_DESC(node)->size ) );
	/* Allocation size */
	ninfo.size_alloc = xstrredup( ninfo.size_alloc, i64toa( NODE_DESC(node)->size_alloc ) );
	ninfo.size_alloc_abbr = xstrredup( ninfo.size_alloc_abbr, abbrev_size( NODE_DESC(node)->size_alloc ) );

	/* User name */
	pw = getpwuid( NODE_DESC(node)->user_id );
	if (pw == NULL)
		cstr = _("Unknown");
	else
		cstr = pw->pw_name;
	ninfo.user_name = xstrredup( ninfo.user_name, cstr );
	/* Group name */
	gr = getgrgid( NODE_DESC(node)->group_id );
	if (gr == NULL)
		cstr = _("Unknown");
	else
		cstr = gr->gr_name;
	ninfo.group_name = xstrredup( ninfo.group_name, cstr );

	/* Timestamps - remember to strip ctime's trailing newlines */
	ninfo.atime = xstrredup( ninfo.atime, ctime( &NODE_DESC(node)->atime ) );
        ninfo.atime[strlen( ninfo.atime ) - 1] = '\0';
	ninfo.mtime = xstrredup( ninfo.mtime, ctime( &NODE_DESC(node)->mtime ) );
        ninfo.mtime[strlen( ninfo.mtime ) - 1] = '\0';
	ninfo.ctime = xstrredup( ninfo.ctime, ctime( &NODE_DESC(node)->ctime ) );
	ninfo.ctime[strlen( ninfo.ctime ) - 1] = '\0';

	/* For directories: subtree size */
	if (NODE_DESC(node)->type == NODE_DIRECTORY) {
		ninfo.subtree_size = xstrredup( ninfo.subtree_size, i64toa( DIR_NODE_DESC(node)->subtree.size ) );
		ninfo.subtree_size_abbr = xstrredup( ninfo.subtree_size_abbr, abbrev_size( DIR_NODE_DESC(node)->subtree.size ) );
	}
	else {
		ninfo.subtree_size = xstrredup( ninfo.subtree_size, blank );
		ninfo.subtree_size_abbr = xstrredup( ninfo.subtree_size_abbr, blank );
	}

	/* For regular files: file type description */
	if (NODE_DESC(node)->type == NODE_REGFILE)
		ninfo.file_type_desc = get_file_type_desc( absname );
	else
		ninfo.file_type_desc = blank;

	/* For symbolic links: target name(s) */
	if (NODE_DESC(node)->type == NODE_SYMLINK) {
		ninfo.target = read_symlink( absname );
		str = g_dirname( absname );
		ninfo.abstarget = absname_merge( str, ninfo.target );
		g_free( str );
	}
	else {
		ninfo.target = blank;
		ninfo.abstarget = blank;
	}

	return &ninfo;
}
Exemple #17
0
void
sample_save_as_cb(GtkWidget * widget, gpointer data)
{
  GtkWidget *dialog;
  gint win_width, win_height;
  sw_view * view = (sw_view *)data;
  sw_sample * sample;
  GtkWidget * save_options;
  GtkWidget * frame;
  GtkWidget * hbox;
  GtkWidget * label;
  GtkWidget * option_menu;
  GtkWidget * save_menu;
  struct stat statbuf;
  gchar *filename;
  gint retval;

  save_as_data * sd;

  char buf[512];

  win_width = gdk_screen_width () / 2;
  win_height = gdk_screen_height () / 2;

  sample = view->sample;

  dialog = gtk_file_chooser_dialog_new (_("Sweep: Save file"),
				      GTK_WINDOW(view->window),
				      GTK_FILE_CHOOSER_ACTION_SAVE,
				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
				      NULL);


  //gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
  attach_window_close_accel(GTK_WINDOW(dialog));
  sweep_set_window_icon (GTK_WINDOW(dialog));

  save_options = gtk_hbox_new (TRUE, 1);

  frame = gtk_frame_new (_("Save Options"));
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
  gtk_box_pack_start (GTK_BOX (save_options), frame, TRUE, TRUE, 4);

  hbox = gtk_hbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
  gtk_container_add (GTK_CONTAINER (frame), hbox);
  gtk_widget_show (hbox);

  label = gtk_label_new (_("Determine File Type:"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  option_menu = gtk_option_menu_new ();
  gtk_box_pack_start (GTK_BOX (hbox), option_menu, TRUE, TRUE, 0);
  gtk_widget_show (option_menu);

  save_menu = create_save_menu (sample);
  gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), save_menu);

  gtk_widget_show (frame);

  /* pack the containing save_options hbox into the save-dialog */
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
		    save_options, FALSE, FALSE, 0);

  gtk_widget_show (save_options);

  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
  gtk_widget_set_size_request (dialog, win_width, win_height);

  if (strcmp (g_path_get_dirname(sample->pathname), ".") == 0) {
    char last_save [512];

    prefs_get_string (LAST_SAVE_KEY, last_save, sizeof (last_save), "");

    if (last_save [0]) {
      gchar * last_save_dir = g_dirname (last_save);

	  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),
				      last_save_dir);
      gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog),
				      sample->pathname);

      g_free (last_save_dir);
    }
  } else {
     retval =  gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog),
				    sample->pathname);
        /* FIXME: bug (local only?) causes gtk_file_chooser_set_filename
           to fail silently in some cases*/
        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
        //printf("filename pre: %s\n", filename);
        //printf("sample->pathname: %s\n", sample->pathname);

  }

  retval = gtk_dialog_run (GTK_DIALOG (dialog));

  filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  //printf("filename post: %s\n", filename);
  sample = view->sample;
  sd = g_malloc (sizeof (save_as_data));
  sd->sample = sample;
  sd->pathname = filename;

  if (retval == GTK_RESPONSE_ACCEPT) {

    if (!sweep_dir_exists (filename)) {
      g_free (sd);
      g_free (filename);
      return;
    }

    if (stat (filename, &statbuf) == -1) {
      switch (errno) {
      case ENOENT:
        /* If it doesn't exist, it's ok to save as */
        overwrite_ok_cb (NULL, sd);
        break;
      default:
        sweep_perror (errno, filename);
        break;
      }
    } else {
      /* file exists */

      if (access(filename, W_OK) == -1) {
        sweep_perror (errno, _("You are not allowed to write to\n%s"), filename);
      } else {
        snprintf (buf, sizeof (buf), _("%s exists. Overwrite?"), filename);

        question_dialog_new (sample, _("File exists"), buf,
		  	   _("Overwrite"), _("Don't overwrite"),
			     G_CALLBACK (overwrite_ok_cb), sd, G_CALLBACK (overwrite_cancel_cb), sd,
			     SWEEP_EDIT_MODE_META);
      }
    }
    /* FIXME: wrapped this due to the above gtk_file_chooser_set_filename problem */
    } else if (sd->pathname != NULL) {
      gchar msg [1024];

      snprintf (msg, sizeof (msg), _("Save as %s cancelled"), g_path_get_basename (sd->pathname));
      sample_set_tmp_message (sd->sample, msg);
    } else {

    g_free (sd);
    g_free (filename);
    }
  gtk_widget_destroy (dialog);


}
Exemple #18
0
static void init_win32_paths(void)
{
	char *home_dir = NULL;
	HMODULE hModule;
	DWORD dWord;
	char *dirname;
	char *sBuffer;

	// Init the path for the Windows version by getting the 
	// executable location.
	hModule = GetModuleHandle("tilp.exe");
	sBuffer = (char *) malloc(4096 * sizeof(char));
	dWord = GetModuleFileName(hModule, sBuffer, 4096);
    dirname = g_dirname(sBuffer);
	
    // MinGW Option, allows Windows Users to run on a Linux File Hierarhcy
	#ifdef __MINGW32__
	  #define MINGW_REL "share\\tilp2"
	  
	  char *basename;
	  basename = g_path_get_basename(dirname);
	  
      // Will replace /target/bin with /target/share/tilp2 in MinGW/MSYS
      if ((strlen(basename) == 3) && !g_strcasecmp(basename, "bin"))
      {
          gchar *token;
          dirname = g_realloc(dirname, strlen(dirname) + strlen(MINGW_REL) + 1);
          token = dirname + strlen(dirname) - 3;
          strcpy(token, MINGW_REL);
      }
    #endif
    
    inst_paths.base_dir = g_strconcat(dirname, "\\", NULL);
	g_free(dirname);
	free(sBuffer);

	inst_paths.pixmap_dir =
	    g_strconcat(inst_paths.base_dir, "pixmaps\\", NULL);
	inst_paths.icon_dir =
	    g_strconcat(inst_paths.base_dir, "icons\\", NULL);
	inst_paths.help_dir =
	    g_strconcat(inst_paths.base_dir, "help\\", NULL);
	inst_paths.manpage_dir =
	    g_strconcat(inst_paths.base_dir, "", NULL);
	inst_paths.glade_dir =
	    g_strconcat(inst_paths.base_dir, "glade\\", NULL);
	#ifdef __MINGW32__
	inst_paths.home_dir = g_get_current_dir();
	#else
	if((g_win32_get_windows_version() & 255) > 5)
	{
		// Windows Vista
		inst_paths.home_dir = 
			g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, "Documents", G_DIR_SEPARATOR_S, _("My TI Files"), NULL);
		g_mkdir(inst_paths.home_dir, 0);
	}
	else
	{
		// Windows XP
		inst_paths.home_dir = g_strconcat(inst_paths.base_dir, "My TI files\\", NULL);
		g_mkdir(inst_paths.home_dir, 0);
	}
	#endif

#ifdef ENABLE_NLS
	inst_paths.locale_dir =
	    g_strconcat(inst_paths.base_dir, "locale\\", NULL);
#endif				/*  */
}
Exemple #19
0
Package*
parse_package_file (const char *path, gboolean ignore_requires,
		    gboolean ignore_private_libs,
		    gboolean ignore_requires_private)
{
  FILE *f;
  Package *pkg;
  GString *str;
  gboolean one_line = FALSE;
  
  f = fopen (path, "r");

  if (f == NULL)
    {
      verbose_error ("Failed to open '%s': %s\n",
                     path, strerror (errno));
      
      return NULL;
    }

  debug_spew ("Parsing package file '%s'\n", path);
  
  pkg = g_new0 (Package, 1);

  if (path)
    {
      pkg->pcfiledir = g_dirname (path);
    }
  else
    {
      debug_spew ("No pcfiledir determined for package\n");
      pkg->pcfiledir = g_strdup ("???????");
    }
  
  str = g_string_new ("");

  while (read_one_line (f, str))
    {
      one_line = TRUE;
      
      parse_line (pkg, str->str, path, ignore_requires, ignore_private_libs,
		  ignore_requires_private);

      g_string_truncate (str, 0);
    }

  if (!one_line)
    verbose_error ("Package file '%s' appears to be empty\n",
                   path);
  g_string_free (str, TRUE);
  fclose(f);

  /* make ->requires_private include a copy of the public requires too */
  pkg->requires_private = g_slist_concat(g_slist_copy (pkg->requires),
					 pkg->requires_private);
  
  pkg->requires = g_slist_reverse (pkg->requires);
  
  pkg->requires_private = g_slist_reverse (pkg->requires_private);

  pkg->I_cflags = g_slist_reverse (pkg->I_cflags);
  pkg->other_cflags = g_slist_reverse (pkg->other_cflags);

  pkg->l_libs = g_slist_reverse (pkg->l_libs);
  pkg->L_libs = g_slist_reverse (pkg->L_libs);
  pkg->other_libs = g_slist_reverse (pkg->other_libs);
  
  return pkg;
}
Exemple #20
0
int
main (int   argc,
      char *argv[])
{
  GList *list, *t;
  GSList *slist, *st;
  GHashTable *hash_table;
  GMemChunk *mem_chunk;
  GStringChunk *string_chunk;
  GTimer *timer;
  gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
  gchar *string;

  gchar *mem[10000], *tmp_string = NULL, *tmp_string_2;
  gint i, j;
  GArray *garray;
  GPtrArray *gparray;
  GByteArray *gbarray;
  GString *string1, *string2;
  GTree *tree;
  char chars[62];
  GRelation *relation;
  GTuples *tuples;
  gint data [1024];
  struct {
    gchar *filename;
    gchar *dirname;
  } dirname_checks[] = {
#ifndef NATIVE_WIN32
    { "/", "/" },
    { "////", "/" },
    { ".////", "." },
    { ".", "." },
    { "..", "." },
    { "../", ".." },
    { "..////", ".." },
    { "", "." },
    { "a/b", "a" },
    { "a/b/", "a/b" },
    { "c///", "c" },
#else
    { "\\", "\\" },
    { ".\\\\\\\\", "." },
    { ".", "." },
    { "..", "." },
    { "..\\", ".." },
    { "..\\\\\\\\", ".." },
    { "", "." },
    { "a\\b", "a" },
    { "a\\b\\", "a\\b" },
    { "c\\\\\\", "c" },
#endif
  };
  guint n_dirname_checks = sizeof (dirname_checks) / sizeof (dirname_checks[0]);
  guint16 gu16t1 = 0x44afU, gu16t2 = 0xaf44U;
  guint32 gu32t1 = 0x02a7f109U, gu32t2 = 0x09f1a702U;
#ifdef G_HAVE_GINT64
  guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
	  gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
#endif

  g_print ("TestGLib v%u.%u.%u (i:%u b:%u)\n",
	   glib_major_version,
	   glib_minor_version,
	   glib_micro_version,
	   glib_interface_age,
	   glib_binary_age);

  string = g_get_current_dir ();
  g_print ("cwd: %s\n", string);
  g_free (string);
  g_print ("user: %s\n", g_get_user_name ());
  g_print ("real: %s\n", g_get_real_name ());
  g_print ("home: %s\n", g_get_home_dir ());
  g_print ("tmp-dir: %s\n", g_get_tmp_dir ());

  /* type sizes */
  g_print ("checking size of gint8: %d", (int)sizeof (gint8));
  TEST (NULL, sizeof (gint8) == 1);
  g_print ("\nchecking size of gint16: %d", (int)sizeof (gint16));
  TEST (NULL, sizeof (gint16) == 2);
  g_print ("\nchecking size of gint32: %d", (int)sizeof (gint32));
  TEST (NULL, sizeof (gint32) == 4);
#ifdef	G_HAVE_GINT64
  g_print ("\nchecking size of gint64: %d", (int)sizeof (gint64));
  TEST (NULL, sizeof (gint64) == 8);
#endif	/* G_HAVE_GINT64 */
  g_print ("\n");

  g_print ("checking g_dirname()...");
  for (i = 0; i < n_dirname_checks; i++)
    {
      gchar *dirname;

      dirname = g_dirname (dirname_checks[i].filename);
      if (strcmp (dirname, dirname_checks[i].dirname) != 0)
	{
	  g_print ("\nfailed for \"%s\"==\"%s\" (returned: \"%s\")\n",
		   dirname_checks[i].filename,
		   dirname_checks[i].dirname,
		   dirname);
	  n_dirname_checks = 0;
	}
      g_free (dirname);
    }
  if (n_dirname_checks)
    g_print ("ok\n");

  g_print ("checking doubly linked lists...");

  list = NULL;
  for (i = 0; i < 10; i++)
    list = g_list_append (list, &nums[i]);
  list = g_list_reverse (list);

  for (i = 0; i < 10; i++)
    {
      t = g_list_nth (list, i);
      if (*((gint*) t->data) != (9 - i))
	g_error ("Regular insert failed");
    }

  for (i = 0; i < 10; i++)
    if(g_list_position(list, g_list_nth (list, i)) != i)
      g_error("g_list_position does not seem to be the inverse of g_list_nth\n");

  g_list_free (list);
  list = NULL;

  for (i = 0; i < 10; i++)
    list = g_list_insert_sorted (list, &morenums[i], my_list_compare_one);

  /*
  g_print("\n");
  g_list_foreach (list, my_list_print, NULL);
  */

  for (i = 0; i < 10; i++)
    {
      t = g_list_nth (list, i);
      if (*((gint*) t->data) != i)
         g_error ("Sorted insert failed");
    }

  g_list_free (list);
  list = NULL;

  for (i = 0; i < 10; i++)
    list = g_list_insert_sorted (list, &morenums[i], my_list_compare_two);

  /*
  g_print("\n");
  g_list_foreach (list, my_list_print, NULL);
  */

  for (i = 0; i < 10; i++)
    {
      t = g_list_nth (list, i);
      if (*((gint*) t->data) != (9 - i))
         g_error ("Sorted insert failed");
    }

  g_list_free (list);
  list = NULL;

  for (i = 0; i < 10; i++)
    list = g_list_prepend (list, &morenums[i]);

  list = g_list_sort (list, my_list_compare_two);

  /*
  g_print("\n");
  g_list_foreach (list, my_list_print, NULL);
  */

  for (i = 0; i < 10; i++)
    {
      t = g_list_nth (list, i);
      if (*((gint*) t->data) != (9 - i))
         g_error ("Merge sort failed");
    }

  g_list_free (list);

  g_print ("ok\n");


  g_print ("checking singly linked lists...");

  slist = NULL;
  for (i = 0; i < 10; i++)
    slist = g_slist_append (slist, &nums[i]);
  slist = g_slist_reverse (slist);

  for (i = 0; i < 10; i++)
    {
      st = g_slist_nth (slist, i);
      if (*((gint*) st->data) != (9 - i))
	g_error ("failed");
    }

  g_slist_free (slist);
  slist = NULL;

  for (i = 0; i < 10; i++)
    slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_one);

  /*
  g_print("\n");
  g_slist_foreach (slist, my_list_print, NULL);
  */

  for (i = 0; i < 10; i++)
    {
      st = g_slist_nth (slist, i);
      if (*((gint*) st->data) != i)
         g_error ("Sorted insert failed");
    }

  g_slist_free(slist);
  slist = NULL;

  for (i = 0; i < 10; i++)
    slist = g_slist_insert_sorted (slist, &morenums[i], my_list_compare_two);

  /*
  g_print("\n");
  g_slist_foreach (slist, my_list_print, NULL);
  */

  for (i = 0; i < 10; i++)
    {
      st = g_slist_nth (slist, i);
      if (*((gint*) st->data) != (9 - i))
         g_error("Sorted insert failed");
    }

  g_slist_free(slist);
  slist = NULL;

  for (i = 0; i < 10; i++)
    slist = g_slist_prepend (slist, &morenums[i]);

  slist = g_slist_sort (slist, my_list_compare_two);

  /*
  g_print("\n");
  g_slist_foreach (slist, my_list_print, NULL);
  */

  for (i = 0; i < 10; i++)
    {
      st = g_slist_nth (slist, i);
      if (*((gint*) st->data) != (9 - i))
         g_error("Sorted insert failed");
    }

  g_slist_free(slist);

  g_print ("ok\n");


  g_print ("checking binary trees...\n");

  tree = g_tree_new (my_compare);
  i = 0;
  for (j = 0; j < 10; j++, i++)
    {
      chars[i] = '0' + j;
      g_tree_insert (tree, &chars[i], &chars[i]);
    }
  for (j = 0; j < 26; j++, i++)
    {
      chars[i] = 'A' + j;
      g_tree_insert (tree, &chars[i], &chars[i]);
    }
  for (j = 0; j < 26; j++, i++)
    {
      chars[i] = 'a' + j;
      g_tree_insert (tree, &chars[i], &chars[i]);
    }

  g_print ("tree height: %d\n", g_tree_height (tree));
  g_print ("tree nnodes: %d\n", g_tree_nnodes (tree));

  g_print ("tree: ");
  g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL);
  g_print ("\n");

  for (i = 0; i < 10; i++)
    g_tree_remove (tree, &chars[i]);

  g_print ("tree height: %d\n", g_tree_height (tree));
  g_print ("tree nnodes: %d\n", g_tree_nnodes (tree));

  g_print ("tree: ");
  g_tree_traverse (tree, my_traverse, G_IN_ORDER, NULL);
  g_print ("\n");

  g_print ("ok\n");


  /* check n-way trees */
  g_node_test ();

  g_print ("checking mem chunks...");

  mem_chunk = g_mem_chunk_new ("test mem chunk", 50, 100, G_ALLOC_AND_FREE);

  for (i = 0; i < 10000; i++)
    {
      mem[i] = g_chunk_new (gchar, mem_chunk);

      for (j = 0; j < 50; j++)
	mem[i][j] = i * j;
    }

  for (i = 0; i < 10000; i++)
    {
      g_mem_chunk_free (mem_chunk, mem[i]);
    }

  g_print ("ok\n");


  g_print ("checking hash tables...");

  hash_table = g_hash_table_new (my_hash, my_hash_compare);
  for (i = 0; i < 10000; i++)
    {
      array[i] = i;
      g_hash_table_insert (hash_table, &array[i], &array[i]);
    }
  g_hash_table_foreach (hash_table, my_hash_callback, NULL);

  for (i = 0; i < 10000; i++)
    if (array[i] == 0)
      g_print ("%d\n", i);

  for (i = 0; i < 10000; i++)
    g_hash_table_remove (hash_table, &array[i]);

  for (i = 0; i < 10000; i++)
    {
      array[i] = i;
      g_hash_table_insert (hash_table, &array[i], &array[i]);
    }

  if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 ||
      g_hash_table_size (hash_table) != 5000)
    g_print ("bad!\n");

  g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);


  g_hash_table_destroy (hash_table);

  g_print ("ok\n");


  g_print ("checking string chunks...");

  string_chunk = g_string_chunk_new (1024);

  for (i = 0; i < 100000; i ++)
    {
      tmp_string = g_string_chunk_insert (string_chunk, "hi pete");

      if (strcmp ("hi pete", tmp_string) != 0)
	g_error ("string chunks are broken.\n");
    }

  tmp_string_2 = g_string_chunk_insert_const (string_chunk, tmp_string);

  g_assert (tmp_string_2 != tmp_string &&
	    strcmp(tmp_string_2, tmp_string) == 0);

  tmp_string = g_string_chunk_insert_const (string_chunk, tmp_string);

  g_assert (tmp_string_2 == tmp_string);

  g_string_chunk_free (string_chunk);

  g_print ("ok\n");


  g_print ("checking arrays...");

  garray = g_array_new (FALSE, FALSE, sizeof (gint));
  for (i = 0; i < 10000; i++)
    g_array_append_val (garray, i);

  for (i = 0; i < 10000; i++)
    if (g_array_index (garray, gint, i) != i)
      g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), i);

  g_array_free (garray, TRUE);

  garray = g_array_new (FALSE, FALSE, sizeof (gint));
  for (i = 0; i < 100; i++)
    g_array_prepend_val (garray, i);

  for (i = 0; i < 100; i++)
    if (g_array_index (garray, gint, i) != (100 - i - 1))
      g_print ("uh oh: %d ( %d )\n", g_array_index (garray, gint, i), 100 - i - 1);

  g_array_free (garray, TRUE);

  g_print ("ok\n");


  g_print ("checking strings...");

  string1 = g_string_new ("hi pete!");
  string2 = g_string_new ("");

  g_assert (strcmp ("hi pete!", string1->str) == 0);

  for (i = 0; i < 10000; i++)
    g_string_append_c (string1, 'a'+(i%26));

#if !(defined (_MSC_VER) || defined (__LCC__))
  /* MSVC and LCC use the same run-time C library, which doesn't like
     the %10000.10000f format... */
  g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%10000.10000f",
		    "this pete guy sure is a wuss, like he's the number ",
		    1,
		    " wuss.  everyone agrees.\n",
		    string1->str,
		    10, 666, 15, 15, 666.666666666, 666.666666666);
#else
  g_string_sprintf (string2, "%s|%0100d|%s|%s|%0*d|%*.*f|%100.100f",
		    "this pete guy sure is a wuss, like he's the number ",
		    1,
		    " wuss.  everyone agrees.\n",
		    string1->str,
		    10, 666, 15, 15, 666.666666666, 666.666666666);
#endif

  g_print ("string2 length = %d...\n", string2->len);
  string2->str[70] = '\0';
  g_print ("first 70 chars:\n%s\n", string2->str);
  string2->str[141] = '\0';
  g_print ("next 70 chars:\n%s\n", string2->str+71);
  string2->str[212] = '\0';
  g_print ("and next 70:\n%s\n", string2->str+142);
  g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70);

  g_print ("ok\n");

  g_print ("checking timers...\n");

  timer = g_timer_new ();
  g_print ("  spinning for 3 seconds...\n");

  g_timer_start (timer);
  while (g_timer_elapsed (timer, NULL) < 3)
    ;

  g_timer_stop (timer);
  g_timer_destroy (timer);

  g_print ("ok\n");

  g_print ("checking g_strcasecmp...");
  g_assert (g_strcasecmp ("FroboZZ", "frobozz") == 0);
  g_assert (g_strcasecmp ("frobozz", "frobozz") == 0);
  g_assert (g_strcasecmp ("frobozz", "FROBOZZ") == 0);
  g_assert (g_strcasecmp ("FROBOZZ", "froboz") != 0);
  g_assert (g_strcasecmp ("", "") == 0);
  g_assert (g_strcasecmp ("!#%&/()", "!#%&/()") == 0);
  g_assert (g_strcasecmp ("a", "b") < 0);
  g_assert (g_strcasecmp ("a", "B") < 0);
  g_assert (g_strcasecmp ("A", "b") < 0);
  g_assert (g_strcasecmp ("A", "B") < 0);
  g_assert (g_strcasecmp ("b", "a") > 0);
  g_assert (g_strcasecmp ("b", "A") > 0);
  g_assert (g_strcasecmp ("B", "a") > 0);
  g_assert (g_strcasecmp ("B", "A") > 0);

  g_print ("ok\n");

  g_print ("checking g_strdup...");
  g_assert(g_strdup(NULL) == NULL);
  string = g_strdup(GLIB_TEST_STRING);
  g_assert(string != NULL);
  g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
  g_free(string);

  g_print ("ok\n");

  g_print ("checking g_strconcat...");
  string = g_strconcat(GLIB_TEST_STRING, NULL);
  g_assert(string != NULL);
  g_assert(strcmp(string, GLIB_TEST_STRING) == 0);
  g_free(string);
  string = g_strconcat(GLIB_TEST_STRING, GLIB_TEST_STRING,
  		       GLIB_TEST_STRING, NULL);
  g_assert(string != NULL);
  g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
  			  GLIB_TEST_STRING) == 0);
  g_free(string);

  g_print ("ok\n");

  g_print ("checking g_strdup_printf...");
  string = g_strdup_printf ("%05d %-5s", 21, "test");
  g_assert (string != NULL);
  g_assert (strcmp(string, "00021 test ") == 0);
  g_free (string);

  g_print ("ok\n");

  /* g_debug (argv[0]); */

  /* Relation tests */

  g_print ("checking relations...");

  relation = g_relation_new (2);

  g_relation_index (relation, 0, g_int_hash, g_int_equal);
  g_relation_index (relation, 1, g_int_hash, g_int_equal);

  for (i = 0; i < 1024; i += 1)
    data[i] = i;

  for (i = 1; i < 1023; i += 1)
    {
      g_relation_insert (relation, data + i, data + i + 1);
      g_relation_insert (relation, data + i, data + i - 1);
    }

  for (i = 2; i < 1022; i += 1)
    {
      g_assert (! g_relation_exists (relation, data + i, data + i));
      g_assert (! g_relation_exists (relation, data + i, data + i + 2));
      g_assert (! g_relation_exists (relation, data + i, data + i - 2));
    }

  for (i = 1; i < 1023; i += 1)
    {
      g_assert (g_relation_exists (relation, data + i, data + i + 1));
      g_assert (g_relation_exists (relation, data + i, data + i - 1));
    }

  for (i = 2; i < 1022; i += 1)
    {
      g_assert (g_relation_count (relation, data + i, 0) == 2);
      g_assert (g_relation_count (relation, data + i, 1) == 2);
    }

  g_assert (g_relation_count (relation, data, 0) == 0);

  g_assert (g_relation_count (relation, data + 42, 0) == 2);
  g_assert (g_relation_count (relation, data + 43, 1) == 2);
  g_assert (g_relation_count (relation, data + 41, 1) == 2);
  g_relation_delete (relation, data + 42, 0);
  g_assert (g_relation_count (relation, data + 42, 0) == 0);
  g_assert (g_relation_count (relation, data + 43, 1) == 1);
  g_assert (g_relation_count (relation, data + 41, 1) == 1);

  tuples = g_relation_select (relation, data + 200, 0);

  g_assert (tuples->len == 2);

#if 0
  for (i = 0; i < tuples->len; i += 1)
    {
      printf ("%d %d\n",
	      *(gint*) g_tuples_index (tuples, i, 0),
	      *(gint*) g_tuples_index (tuples, i, 1));
    }
#endif

  g_assert (g_relation_exists (relation, data + 300, data + 301));
  g_relation_delete (relation, data + 300, 0);
  g_assert (!g_relation_exists (relation, data + 300, data + 301));

  g_tuples_destroy (tuples);

  g_relation_destroy (relation);

  relation = NULL;

  g_print ("ok\n");

  g_print ("checking pointer arrays...");

  gparray = g_ptr_array_new ();
  for (i = 0; i < 10000; i++)
    g_ptr_array_add (gparray, GINT_TO_POINTER (i));

  for (i = 0; i < 10000; i++)
    if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
      g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));

  g_ptr_array_free (gparray, TRUE);

  g_print ("ok\n");


  g_print ("checking byte arrays...");

  gbarray = g_byte_array_new ();
  for (i = 0; i < 10000; i++)
    g_byte_array_append (gbarray, (guint8*) "abcd", 4);

  for (i = 0; i < 10000; i++)
    {
      g_assert (gbarray->data[4*i] == 'a');
      g_assert (gbarray->data[4*i+1] == 'b');
      g_assert (gbarray->data[4*i+2] == 'c');
      g_assert (gbarray->data[4*i+3] == 'd');
    }

  g_byte_array_free (gbarray, TRUE);
  g_print ("ok\n");

  g_printerr ("g_log tests:");
  g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345);
  g_message ("the next warning is a test:");
  string = NULL;
  g_print (string);

  g_print ("checking endian macros (host is ");
#if G_BYTE_ORDER == G_BIG_ENDIAN
  g_print ("big endian)...");
#else
  g_print ("little endian)...");
#endif
  g_assert (GUINT16_SWAP_LE_BE (gu16t1) == gu16t2);
  g_assert (GUINT32_SWAP_LE_BE (gu32t1) == gu32t2);
#ifdef G_HAVE_GINT64
  g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);
#endif
  g_print ("ok\n");

  return 0;
}
Exemple #21
0
static void update_tree_view(const GEList *file_list)
{
	gchar *last_file = "";
	gchar *aux;
	GtkTreeIter tree_iter;
	GList *i;
	//GtkStyleContext *style;

  	//style = gtk_widget_get_style_context(GTK_WIDGET(tv_files));
	//if (style == NULL)
	///	g_error("Couldn't get style context for widget tv_files");

	//gtk_style_context_get_background_color(style, GTK_STATE_FLAG_INSENSITIVE, &outColor);
	//gtk_style_context_get_property(style, GTK_STYLE_PROPERTY_BACKGROUND_COLOR, GTK_STATE_FLAG_INSENSITIVE, &value);
	//strColor = gdk_rgba_to_string(&outColor);


	gtk_tree_view_set_model(tv_files, NULL);

	gtk_list_store_clear(store_files);

	i = g_elist_first(file_list);
	while (i) {
		if (!fu_compare_file_paths(last_file, i->data)) {
			char *dirname = g_dirname(i->data);
			aux = str_filename_to_utf8(dirname,
						   _("(dir name could not be converted to UTF8)"));
			gtk_list_store_append(store_files, &tree_iter);


			gtk_list_store_set(store_files, &tree_iter, 
					   0, pix_folder,
					   1, aux,
					   2, NULL,
					   3, TRUE,
					   4, NULL,
					   5, FALSE,
					   -1);
			g_free(dirname);
			g_free(aux);
		}
		aux = str_filename_to_utf8(fu_last_n_path_components(i->data, 1),
					   _("(file name could not be converted to UTF8)"));
		gtk_list_store_append(store_files, &tree_iter);
		gtk_list_store_set(store_files, &tree_iter, 
				   0, pix_file,
				   1, aux,
				   2, NULL,
				   3, FALSE,
				   4, i->data,
				   5, TRUE,
				   -1);
		g_free(aux);

		last_file = i->data;
		i = g_list_next(i);
	}
	gtk_tree_view_set_model(tv_files, GTK_TREE_MODEL(store_files));

	update_file_count();
}