Esempio n. 1
0
void
btree_traverse(btree tree, btree_traverse_mode flag,
               btree_node_callback btree_node_visit)
{
        /* callback variable to invoke real function */
        btree_traverse_callback traverse_func = BTREE_TRAVERSE_TABLE[flag];
        /* now it's time to invoke traverse function */
        traverse_func(tree, btree_node_visit);
}
/**
 * A generic traversal function.
 */
void
db_traverse_subtree(union tree *tp,
		    void (*traverse_func) (struct directory *, struct db_traverse *),
		    struct db_traverse *dtp)
{
    struct directory *dp;

    if (!tp)
	return;

    RT_CK_DB_TRAVERSE(dtp);
    RT_CHECK_DBI(dtp->dbip);
    RT_CK_TREE(tp);
    if (dtp->resp) {
	RT_CK_RESOURCE(dtp->resp);
    }

    switch (tp->tr_op) {

	case OP_DB_LEAF:
	    if ((dp=db_lookup(dtp->dbip, tp->tr_l.tl_name, LOOKUP_NOISY)) == RT_DIR_NULL)
		return;
	    traverse_func(dp, dtp);
	    break;

	case OP_UNION:
	case OP_INTERSECT:
	case OP_SUBTRACT:
	case OP_XOR:
	    db_traverse_subtree(tp->tr_b.tb_left, traverse_func, dtp);
	    db_traverse_subtree(tp->tr_b.tb_right, traverse_func, dtp);
	    break;
	default:
	    bu_log("db_functree_subtree: unrecognized operator %d\n", tp->tr_op);
	    bu_bomb("db_functree_subtree: unrecognized operator\n");
    }
}
Esempio n. 3
0
gboolean
ol_traverse_dir (const char *dirname,
                 gboolean recursive,
                 gboolean (*traverse_func) (const char *path,
                                            const char *filename,
                                            gpointer userdata),
                 gpointer userdata)
{
  ol_assert_ret (dirname != NULL, FALSE);
  ol_assert_ret (traverse_func != NULL, FALSE);
  GError *error = NULL;
  GDir *dir = g_dir_open (dirname, 0, &error);
  if (!dir)
  {
    ol_error ("Cannot open directory %s: %s\n", dirname, error->message);
    return FALSE;
  }
  const gchar *filename = NULL;
  while ((filename = g_dir_read_name (dir)) != NULL)
  {
    if (!traverse_func (dirname, filename, userdata))
      return FALSE;
    if (recursive)
    {
      gchar *filepath = g_build_path (G_DIR_SEPARATOR_S,
                                      dirname, filename, NULL);
      if (g_file_test (filepath, G_FILE_TEST_IS_DIR))
        if (!ol_traverse_dir (filepath, recursive, traverse_func, userdata))
        {
          g_free (filepath);
          return FALSE;
        }
      g_free (filepath);
    }
  }
  return TRUE;
}