<commit_before>#include "main.h"
#include "Plugin.h"
#include "dlfcn.h"
#include "header.h"

typedef void (*init_imagestack_plugin)(map<string, Operation *> &);

void Plugin::parse(vector<string> args) {
    void *handle = dlopen(args[0].c_str(), RTLD_LAZY);
    assert(handle, "Could not open %s as a shared library\n", args[0].c_str());

    void *function = dlsym(handle, "init_imagestack_plugin");
    assert(function, "Could not find symbol init_imagestack_plugin (with C linkage) in %s\n", args[0].c_str());

    // Pass control to the shared library to inject crap into the operation map
    ((init_imagestack_plugin)function)(operationMap);
}

void Plugin::help() {
    pprintf("-plugin loads a shared object that can add new operations to"
            " ImageStack. It does this by calling the function"
            " init_imagestack_plugin, which should exist in the shared object with"
            " C linkage. To this function it passes the ImageStack operation map,"
            " into which the plugin may inject new operations.\n\n"
            "Usage: ImageStack -plugin foo.so -foo 1 2 3\n");
}

#include "footer.h"
<commit_msg>More helpful error message on plugin load failure<commit_after>#include "main.h"
#include "Plugin.h"
#include "dlfcn.h"
#include "header.h"

typedef void (*init_imagestack_plugin)(map<string, Operation *> &);

void Plugin::parse(vector<string> args) {
    void *handle = dlopen(args[0].c_str(), RTLD_LAZY);
    assert(handle, "Could not open %s as a shared library: %s\n", args[0].c_str(), dlerror());

    void *function = dlsym(handle, "init_imagestack_plugin");
    assert(function, "Could not find symbol init_imagestack_plugin (with C linkage) in %s\n", args[0].c_str());

    // Pass control to the shared library to inject crap into the operation map
    ((init_imagestack_plugin)function)(operationMap);
}

void Plugin::help() {
    pprintf("-plugin loads a shared object that can add new operations to"
            " ImageStack. It does this by calling the function"
            " init_imagestack_plugin, which should exist in the shared object with"
            " C linkage. To this function it passes the ImageStack operation map,"
            " into which the plugin may inject new operations.\n\n"
            "Usage: ImageStack -plugin foo.so -foo 1 2 3\n");
}

#include "footer.h"

{'fraction_non_alphanumeric': 0.11661683041435283, 'fraction_numerical': 0.0051260145237078175, 'mean_word_length': 3.6468253968253967, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5652230', 'n_tokens_mistral': 726, 'n_tokens_neox': 705, 'n_words': 245}