<commit_before>/*
 * IceWM
 *
 * Copyright (C) 1997-2001 <NAME>
 */
#include "config.h"
#include "yfull.h"
#include "ypixbuf.h"
#include "ypaint.h"
#include "yicon.h"
#include "yapp.h"
#include "sysdep.h"
#include "prefs.h"
#include "yprefs.h"
#include "wmprog.h" // !!! remove this

#include "intl.h"

#ifndef LITE

static bool didInit = false;
static ref<YResourcePaths> iconPaths;

void initIcons() {
    if (!didInit) {
        didInit = true;
        iconPaths = YResourcePaths::subdirs("icons/");
    }
}


YIcon::YIcon(upath filename):
    fSmall(null), fLarge(null), fHuge(null),
    loadedS(false), loadedL(false), loadedH(false),
    fPath(filename), fCached(false)
{
}

YIcon::YIcon(ref<YImage> small, ref<YImage> large, ref<YImage> huge) :
    fSmall(small), fLarge(large), fHuge(huge),
    loadedS(small != null), loadedL(large != null), loadedH(huge != null),
    fPath(NULL), fCached(false)
{
}

YIcon::~YIcon() {
    fHuge = null;
    fLarge = null;
    fSmall = null;
}

static upath joinPath(upath dir, upath name) {
    if (dir == null)
        return name;

    if (name.isAbsolute())
        return name;

    return dir.relative(name);
}

upath YIcon::findIcon(upath dir, upath base, unsigned size) {
    char icons_size[1024];
    upath fullpath;

    fullpath = joinPath(dir, base);
    if (fullpath.fileExists())
        return fullpath;

    sprintf(icons_size, "%s_%dx%d.xpm", cstring(base.path()).c_str(), size, size);
    fullpath = joinPath(dir, icons_size);
    if (fullpath.fileExists())
        return fullpath;

    fullpath = joinPath(dir, base.addExtension(".xpm"));
    if (fullpath.fileExists())
        return fullpath;

    fullpath = joinPath(dir, base.addExtension(".png"));
    if (fullpath.fileExists())
        return fullpath;

    return 0;
}

upath YIcon::findIcon(int size) {
    cstring cs(fPath.path());
    initIcons();

    if (iconPath != 0 && iconPath[0] != 0) {
        for (char const *p = iconPath, *q = iconPath; *q; q = p) {
            while (*p && *p != PATHSEP) p++;

            unsigned len(p - q);
            if (*p) ++p;

            upath path = upath(newstr(q, len));

            upath fullpath = findIcon(path.path(), fPath, size);
            if (fullpath != null) {
                return fullpath;
            }
        }<commit_msg> applied icewm.svg.patch from archlinux<commit_after>/*
 * IceWM
 *
 * Copyright (C) 1997-2001 <NAME>
 */
#include "config.h"
#include "yfull.h"
#include "ypixbuf.h"
#include "ypaint.h"
#include "yicon.h"
#include "yapp.h"
#include "sysdep.h"
#include "prefs.h"
#include "yprefs.h"
#include "wmprog.h" // !!! remove this

#include "intl.h"

#ifndef LITE

static bool didInit = false;
static ref<YResourcePaths> iconPaths;

void initIcons() {
    if (!didInit) {
        didInit = true;
        iconPaths = YResourcePaths::subdirs("icons/");
    }
}


YIcon::YIcon(upath filename):
    fSmall(null), fLarge(null), fHuge(null),
    loadedS(false), loadedL(false), loadedH(false),
    fPath(filename), fCached(false)
{
}

YIcon::YIcon(ref<YImage> small, ref<YImage> large, ref<YImage> huge) :
    fSmall(small), fLarge(large), fHuge(huge),
    loadedS(small != null), loadedL(large != null), loadedH(huge != null),
    fPath(NULL), fCached(false)
{
}

YIcon::~YIcon() {
    fHuge = null;
    fLarge = null;
    fSmall = null;
}

static upath joinPath(upath dir, upath name) {
    if (dir == null)
        return name;

    if (name.isAbsolute())
        return name;

    return dir.relative(name);
}

upath YIcon::findIcon(upath dir, upath base, unsigned size) {
    char icons_size[1024];
    upath fullpath;

    fullpath = joinPath(dir, base);
    if (fullpath.fileExists())
        return fullpath;

    sprintf(icons_size, "%s_%dx%d.xpm", cstring(base.path()).c_str(), size, size);
    fullpath = joinPath(dir, icons_size);
    if (fullpath.fileExists())
        return fullpath;

    fullpath = joinPath(dir, base.addExtension(".xpm"));
    if (fullpath.fileExists())
        return fullpath;

    fullpath = joinPath(dir, base.addExtension(".png"));
    if (fullpath.fileExists())
        return fullpath;

    fullpath = joinPath(dir, base.addExtension(".svg"));
    if (fullpath.fileExists())
        return fullpath;

    return 0;
}

upath YIcon::findIcon(int size) {
    cstring cs(fPath.path());
    initIcons();

    if (iconPath != 0 && iconPath[0] != 0) {
        for (char const *p = iconPath, *q = iconPath; *q; q = p) {
            while (*p && *p != PATHSEP) p++;

            unsigned len(p - q);
            if (*p) ++p;

            upath path = upath(newstr(q, len));

            upath fullpath = findIcon(path.path(), fPath, size);
            if (fullpath != null) {
                return fullpath;
            }
        }
{'fraction_non_alphanumeric': 0.15916736753574431, 'fraction_numerical': 0.00672834314550042, 'mean_word_length': 2.870626525630594, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3771795', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1675, 'n_words': 391}