Beispiel #1
0
static inline gboolean
colors_equal (const gfloat   *col1,
              const gfloat   *col2,
              gint            components,
              gboolean        has_alpha)
{
  if (has_alpha &&
      FLOAT_IS_ZERO (col1[components - 1]) &&
      FLOAT_IS_ZERO (col2[components - 1]))
    {
      return TRUE;
    }
  else
    {
      gint b;

      for (b = 0; b < components; b++)
        {
          if (! FLOAT_EQUAL (col1[b], col2[b]))
            return FALSE;
        }

      return TRUE;
    }
}
Beispiel #2
0
static gint rm_file_cmp_full(const RmFile *file_a, const RmFile *file_b,
                      const RmSession *session) {
    gint result = rm_file_cmp(file_a, file_b);
    if(result != 0) {
        return result;
    }

    if(session->cfg->mtime_window >= 0) {
        gdouble diff = file_a->mtime - file_b->mtime;
        if(FLOAT_IS_ZERO(diff)) {
            return 0;
        }

        return (diff < 0) ? -1 : +1;
    }

    return rm_pp_cmp_orig_criteria(file_a, file_b, session);
}
Beispiel #3
0
static gint rm_file_cmp_split(const RmFile *file_a, const RmFile *file_b,
                       const RmSession *session) {
    gint result = rm_file_cmp(file_a, file_b);
    if(result != 0) {
        return result;
    }

    /* If --mtime-window is specified, we need to check if the mtime is inside
     * the window. The file list was sorted by rm_file_cmp_full by taking the
     * diff of mtimes, therefore we have to define the split criteria
     * differently.
     */
    if(session->cfg->mtime_window >= 0) {
        gdouble diff = file_a->mtime - file_b->mtime;
        if(FLOAT_IS_ZERO(diff - session->cfg->mtime_window) || fabs(diff) < session->cfg->mtime_window) {
            return 0;
        }

        /* Split the group. */
        return (diff < 0) ? -1 : +1;
    }

    return 0;
}
Beispiel #4
0
/* Return:
 *      a negative integer file 'a' outranks 'b',
 *      0 if they are equal,
 *      a positive integer if file 'b' outranks 'a'
 */
int rm_pp_cmp_orig_criteria(const RmFile *a, const RmFile *b, const RmSession *session) {
    if(a->lint_type != b->lint_type) {
        /* "other" lint outranks duplicates and has lower ENUM */
        return a->lint_type - b->lint_type;
    } else if(a->is_symlink != b->is_symlink) {
        return a->is_symlink - b->is_symlink;
    } else if(a->is_prefd != b->is_prefd) {
        return (b->is_prefd - a->is_prefd);
    } else {
        /* Only fill in path if we have a pattern in sort_criteria */
        bool path_needed = (session->pattern_cache->len > 0);
        RM_DEFINE_PATH_IF_NEEDED(a, path_needed);
        RM_DEFINE_PATH_IF_NEEDED(b, path_needed);

        RmCfg *sets = session->cfg;

        for(int i = 0, regex_cursor = 0; sets->sort_criteria[i]; i++) {
            gint64 cmp = 0;
            switch(tolower((unsigned char)sets->sort_criteria[i])) {
            case 'm': {
                gdouble diff = a->mtime - b->mtime;
                if(FLOAT_IS_ZERO(diff)) {
                    cmp = 0;
                }

                cmp = diff;
                break;
            }
            case 'a':
                cmp = g_ascii_strcasecmp(a->folder->basename, b->folder->basename);
                break;
            case 'l':
                cmp = strlen(a->folder->basename) - strlen(b->folder->basename);
                break;
            case 'd':
                cmp = (gint64)a->depth - (gint64)b->depth;
                break;
            case 'h':
                cmp = (gint64)a->link_count - (gint64)b->link_count;
                break;
            case 'o':
                cmp = (gint64)a->outer_link_count - (gint64)b->outer_link_count;
                break;
            case 'p':
                cmp = (gint64)a->path_index - (gint64)b->path_index;
                break;
            case 'x': {
                cmp = rm_pp_cmp_by_regex(
                    g_ptr_array_index(session->pattern_cache, regex_cursor), regex_cursor,
                    (RmPatternBitmask *)&a->pattern_bitmask_basename, a->folder->basename,
                    (RmPatternBitmask *)&b->pattern_bitmask_basename, b->folder->basename);
                regex_cursor++;
                break;
            }
            case 'r':
                cmp = rm_pp_cmp_by_regex(
                    g_ptr_array_index(session->pattern_cache, regex_cursor), regex_cursor,
                    (RmPatternBitmask *)&a->pattern_bitmask_path, a_path,
                    (RmPatternBitmask *)&b->pattern_bitmask_path, b_path);
                regex_cursor++;
                break;
            }
            if(cmp) {
                /* reverse order if uppercase option */
                cmp = cmp * (isupper((unsigned char)sets->sort_criteria[i]) ? -1 : +1);
                return cmp;
            }
        }
        return 0;
    }
}