<commit_before>
/**
 * @file
 * @author  <NAME> <EMAIL>
 * @version 0.1
 *
 * @section LICENSE
 * Copyright (c) 2011, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * The names of its contributors may not be used to endorse or promote
      products derived from this software without specific prior written
      permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL WILLEM-HENDRIK THIART BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <assert.h>

#include <fcntl.h>

#include <getopt.h>

#include "block.h"
#include "bt.h"
#include "bt_main.h"
#include "bt_tracker_client.h"
#include "torrentfile_reader.h"
#include "readfile.h"
#include "config.h"

#define PROGRAM_NAME "bt"

/**
 * The bounded network interface for net communications */
char __cfg_bound_iface[32];

#include <sys/time.h>

static void __log(void *udata, void *src, char *buf)
{
    char stamp[32];
    int fd = (unsigned long) udata;
    struct timeval tv;

    gettimeofday(&tv, NULL);
    sprintf(stamp, "%d,%0.2f,", (int) tv.tv_sec, (float) tv.tv_usec / 100000);
    write(fd, stamp, strlen(stamp));
    write(fd, buf, strlen(buf));
}

static void __usage(int status)
{
#if 0
    if (status != EXIT_SUCCESS)
        fprintf(stderr, ("Try `%s --help' for more information.\n"),
                PROGRAM_NAME);
    else
#endif
    {
        printf("\
Usage: %s [OPTION]... TORRENT_FILE\n", PROGRAM_NAME);
        fputs(("\
Download torrent indicated by TORRENT_FILE. \n\n\
Mandatory arguments to long options are mandatory for short options too. \n\
  -i, --using-interface        network interface to use \n\
  -e, --verify-download        check downloaded files and quit \n\
  -t, --torrent_file_report_only    only report the contents of the torrent file \n\
  -b                                                    \n "), stdout);
        exit(status);
    }
}

static struct option const long_opts[] = {
    { "archive", no_argument, NULL, 'a'},
//  {" backup ", optional_argument, NULL, 'b'},
    { "using-interface", required_argument, NULL, 'i'},
    { "verify-download", no_argument, NULL, 'e'},
    { "shutdown-when-complete", no_argument, NULL, 's'},
    { "pwp_listen_port", required_argument, NULL, 'p'},
    { "torrent_file_report_only", required_argument, NULL, 't'},
    { NULL, 0, NULL, 0}
};

typedef struct {
    void* bt;

} torrent_reader_t;

int cb_event(void* udata, const char* key)
{
    printf("%s\n");

    return 1;
}

int cb_event_str(void* udata, const char* key, const char* val, int len)
{
    printf("%s %.*s\n", key, len, val);

    return 1;
}

int cb_event_int(void* udata, const char* key, int val)
{
    printf("%s %d\n", key, val);

    return 1;
}

void __read_torrent_file(void* bt, char* torrent_file)
{
    torrent_reader_t r;
    void* tf;
    int len;
    char* metainfo;

    memset(&r, 0, sizeof(torrent_reader_t));
    tf = tfr_new(cb_event, cb_event_str, cb_event_int, &r);
    metainfo = read_file(torrent_file,&len);
    tfr_read_metainfo(tf, metainfo, len);
}

int main(int argc, char **argv)
{
    char c;
    int o_verify_download, o_shutdown_when_complete, o_torrent_file_report_only;
    void *bt;
    char *str;
    //int status;
    config_t* cfg;

    o_verify_download = 0;
    o_shutdown_when_complete = 0;
    o_torrent_file_report_only = 0;

    bt = bt_client_new();
    cfg = bt_client_get_config(bt);
    //status = config_read(cfg, "yabtc", "config");

    // setlocale(LC_ALL, " ");
    //  atexit (close_stdin);

    while ((c = getopt_long(argc, argv, "esi:p:", long_opts, NULL)) != -1)
    {
        switch (c)
        {
        case 's':
            o_shutdown_when_complete = 1;
            break;

        case 'p':
            config_set_va(cfg,"pwp_listen_port","%.*s",strlen(optarg), optarg);
            break;

        case 't':
            config_set_va(cfg,"torrent_file","%.*s",strlen(optarg), optarg);
            o_torrent_file_report_only = 1;
            break;

        case 'i':
            strcpy(__cfg_bound_iface, optarg);
            break;

        case 'e':
            o_verify_download = 1;
            break;

        default:
            __usage(EXIT_FAILURE);<commit_msg>=bounded iface option<commit_after>
/**
 * @file
 * @author  <NAME> <EMAIL>
 * @version 0.1
 *
 * @section LICENSE
 * Copyright (c) 2011, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * The names of its contributors may not be used to endorse or promote
      products derived from this software without specific prior written
      permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL WILLEM-HENDRIK THIART BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <assert.h>

#include <fcntl.h>

#include <getopt.h>

#include "block.h"
#include "bt.h"
#include "bt_main.h"
#include "bt_tracker_client.h"
#include "torrentfile_reader.h"
#include "readfile.h"
#include "config.h"

#define PROGRAM_NAME "bt"


#include <sys/time.h>

static void __log(void *udata, void *src, char *buf)
{
    char stamp[32];
    int fd = (unsigned long) udata;
    struct timeval tv;

    gettimeofday(&tv, NULL);
    sprintf(stamp, "%d,%0.2f,", (int) tv.tv_sec, (float) tv.tv_usec / 100000);
    write(fd, stamp, strlen(stamp));
    write(fd, buf, strlen(buf));
}

static void __usage(int status)
{
#if 0
    if (status != EXIT_SUCCESS)
        fprintf(stderr, ("Try `%s --help' for more information.\n"),
                PROGRAM_NAME);
    else
#endif
    {
        printf("\
Usage: %s [OPTION]... TORRENT_FILE\n", PROGRAM_NAME);
        fputs(("\
Download torrent indicated by TORRENT_FILE. \n\n\
Mandatory arguments to long options are mandatory for short options too. \n\
  -i, --using-interface        network interface to use \n\
  -e, --verify-download        check downloaded files and quit \n\
  -t, --torrent_file_report_only    only report the contents of the torrent file \n\
  -b                                                    \n "), stdout);
        exit(status);
    }
}

static struct option const long_opts[] = {
    { "archive", no_argument, NULL, 'a'},
//  {" backup ", optional_argument, NULL, 'b'},
    /* The bounded network interface for net communications */
    { "using-interface", required_argument, NULL, 'i'},
    { "verify-download", no_argument, NULL, 'e'},
    { "shutdown-when-complete", no_argument, NULL, 's'},
    { "pwp_listen_port", required_argument, NULL, 'p'},
    { "torrent_file_report_only", required_argument, NULL, 't'},
    { NULL, 0, NULL, 0}
};

typedef struct {
    void* bt;

} torrent_reader_t;

int cb_event(void* udata, const char* key)
{
    printf("%s\n");

    return 1;
}

int cb_event_str(void* udata, const char* key, const char* val, int len)
{
    printf("%s %.*s\n", key, len, val);

    return 1;
}

int cb_event_int(void* udata, const char* key, int val)
{
    printf("%s %d\n", key, val);

    return 1;
}

void __read_torrent_file(void* bt, char* torrent_file)
{
    torrent_reader_t r;
    void* tf;
    int len;
    char* metainfo;

    memset(&r, 0, sizeof(torrent_reader_t));
    tf = tfr_new(cb_event, cb_event_str, cb_event_int, &r);
    metainfo = read_file(torrent_file,&len);
    tfr_read_metainfo(tf, metainfo, len);
}

int main(int argc, char **argv)
{
    char c;
    int o_verify_download, o_shutdown_when_complete, o_torrent_file_report_only;
    void *bt;
    char *str;
    //int status;
    config_t* cfg;

    o_verify_download = 0;
    o_shutdown_when_complete = 0;
    o_torrent_file_report_only = 0;

    bt = bt_client_new();
    cfg = bt_client_get_config(bt);
    //status = config_read(cfg, "yabtc", "config");

    // setlocale(LC_ALL, " ");
    //  atexit (close_stdin);

    while ((c = getopt_long(argc, argv, "esi:p:", long_opts, NULL)) != -1)
    {
        switch (c)
        {
        case 's':
            o_shutdown_when_complete = 1;
            break;
        case 'p':
            config_set_va(cfg,"pwp_listen_port","%.*s",strlen(optarg), optarg);
            break;
        case 't':
            config_set_va(cfg,"torrent_file","%.*s",strlen(optarg), optarg);
            o_torrent_file_report_only = 1;
            break;
        case 'i':
            config_set_va(cfg,"bounded_iface","%.*s",strlen(optarg), optarg);
            break;
        case 'e':
            o_verify_download = 1;
            break;

        default:
            __usage(EXIT_FAILURE);
{'fraction_non_alphanumeric': 0.11595555970497619, 'fraction_numerical': 0.005788441788815236, 'mean_word_length': 3.0514372163388805, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6452160', 'n_tokens_mistral': 3607, 'n_tokens_neox': 3430, 'n_words': 1103}