2010-06-16 14:27:24 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2012-2014 Mnemosyne LLC
|
2010-06-16 14:27:24 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2010-06-16 14:27:24 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
#include <stdio.h> /* fprintf () */
|
|
|
|
#include <string.h> /* strlen (), strstr (), strcmp () */
|
2011-03-16 18:04:23 +00:00
|
|
|
#include <stdlib.h> /* EXIT_FAILURE */
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2010-12-20 02:07:51 +00:00
|
|
|
#include <event2/buffer.h>
|
2010-06-16 14:27:24 +00:00
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/tr-getopt.h>
|
|
|
|
#include <libtransmission/utils.h>
|
2012-12-14 04:34:42 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2010-08-08 22:53:24 +00:00
|
|
|
#include <libtransmission/version.h>
|
2010-06-16 14:27:24 +00:00
|
|
|
|
|
|
|
#define MY_NAME "transmission-edit"
|
|
|
|
|
2010-08-08 22:53:24 +00:00
|
|
|
static int fileCount = 0;
|
2011-03-22 15:19:54 +00:00
|
|
|
static bool showVersion = false;
|
2010-08-08 22:53:24 +00:00
|
|
|
static const char ** files = NULL;
|
|
|
|
static const char * add = NULL;
|
|
|
|
static const char * deleteme = NULL;
|
|
|
|
static const char * replace[2] = { NULL, NULL };
|
2010-06-16 14:27:24 +00:00
|
|
|
|
|
|
|
static tr_option options[] =
|
|
|
|
{
|
|
|
|
{ 'a', "add", "Add a tracker's announce URL", "a", 1, "<url>" },
|
|
|
|
{ 'd', "delete", "Delete a tracker's announce URL", "d", 1, "<url>" },
|
|
|
|
{ 'r', "replace", "Search and replace a substring in the announce URLs", "r", 1, "<old> <new>" },
|
2010-08-08 22:53:24 +00:00
|
|
|
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
|
2010-06-16 14:27:24 +00:00
|
|
|
{ 0, NULL, NULL, NULL, 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
2012-12-05 17:29:46 +00:00
|
|
|
getUsage (void)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2013-01-22 18:59:39 +00:00
|
|
|
return "Usage: " MY_NAME " [options] torrent-file(s)";
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-12-05 17:29:46 +00:00
|
|
|
parseCommandLine (int argc, const char ** argv)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
int c;
|
|
|
|
const char * optarg;
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
while ((c = tr_getopt (getUsage (), argc, argv, options, &optarg)))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
switch (c)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
case 'a':
|
|
|
|
add = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
deleteme = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
replace[0] = optarg;
|
|
|
|
c = tr_getopt (getUsage (), argc, argv, options, &optarg);
|
|
|
|
if (c != TR_OPT_UNK)
|
|
|
|
return 1;
|
|
|
|
replace[1] = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
showVersion = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_OPT_UNK:
|
|
|
|
files[fileCount++] = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return 0;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static bool
|
2012-12-14 04:34:42 +00:00
|
|
|
removeURL (tr_variant * metainfo, const char * url)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * str;
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * announce_list;
|
2012-12-05 17:29:46 +00:00
|
|
|
bool changed = false;
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
if (tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL) && !strcmp (str, url))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("\tRemoved \"%s\" from \"announce\"\n", str);
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_variantDictRemove (metainfo, TR_KEY_announce);
|
2012-12-05 17:29:46 +00:00
|
|
|
changed = true;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
if (tr_variantDictFindList (metainfo, TR_KEY_announce_list, &announce_list))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * tier;
|
2012-12-05 17:29:46 +00:00
|
|
|
int tierIndex = 0;
|
2012-12-14 04:34:42 +00:00
|
|
|
while ((tier = tr_variantListChild (announce_list, tierIndex)))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * node;
|
2012-12-05 17:29:46 +00:00
|
|
|
int nodeIndex = 0;
|
2012-12-14 04:34:42 +00:00
|
|
|
while ((node = tr_variantListChild (tier, nodeIndex)))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
if (tr_variantGetStr (node, &str, NULL) && !strcmp (str, url))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, (tierIndex+1));
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantListRemove (tier, nodeIndex);
|
2012-12-05 17:29:46 +00:00
|
|
|
changed = true;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
else ++nodeIndex;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
if (tr_variantListSize (tier) == 0)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("\tNo URLs left in tier #%d... removing tier\n", (tierIndex+1));
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantListRemove (announce_list, tierIndex);
|
2012-12-05 17:29:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++tierIndex;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
if (tr_variantListSize (announce_list) == 0)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("\tNo tiers left... removing announce-list\n");
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_variantDictRemove (metainfo, TR_KEY_announce_list);
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
/* if we removed the "announce" field and there's still another track left,
|
|
|
|
* use it as the "announce" field */
|
2012-12-22 20:35:19 +00:00
|
|
|
if (changed && !tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * tier;
|
|
|
|
tr_variant * node;
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
if ((tier = tr_variantListChild (announce_list, 0)))
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
if ((node = tr_variantListChild (tier, 0)))
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
if (tr_variantGetStr (node, &str, NULL))
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_variantDictAddStr (metainfo, TR_KEY_announce, str);
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("\tAdded \"%s\" to announce\n", str);
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return changed;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char*
|
2012-12-05 17:29:46 +00:00
|
|
|
replaceSubstr (const char * str, const char * in, const char * out)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
char * walk;
|
|
|
|
struct evbuffer * buf = evbuffer_new ();
|
|
|
|
const size_t inlen = strlen (in);
|
|
|
|
const size_t outlen = strlen (out);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
while ((walk = strstr (str, in)))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
evbuffer_add (buf, str, walk-str);
|
|
|
|
evbuffer_add (buf, out, outlen);
|
|
|
|
str = walk + inlen;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
evbuffer_add (buf, str, strlen (str));
|
2011-01-30 16:40:11 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return evbuffer_free_to_str (buf);
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static bool
|
2012-12-14 04:34:42 +00:00
|
|
|
replaceURL (tr_variant * metainfo, const char * in, const char * out)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * str;
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * announce_list;
|
2012-12-05 17:29:46 +00:00
|
|
|
bool changed = false;
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
if (tr_variantDictFindStr (metainfo, TR_KEY_announce, &str, NULL) && strstr (str, in))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
char * newstr = replaceSubstr (str, in, out);
|
|
|
|
printf ("\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr);
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_variantDictAddStr (metainfo, TR_KEY_announce, newstr);
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_free (newstr);
|
|
|
|
changed = true;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
if (tr_variantDictFindList (metainfo, TR_KEY_announce_list, &announce_list))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * tier;
|
2012-12-05 17:29:46 +00:00
|
|
|
int tierCount = 0;
|
2012-12-14 04:34:42 +00:00
|
|
|
while ((tier = tr_variantListChild (announce_list, tierCount++)))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * node;
|
2012-12-05 17:29:46 +00:00
|
|
|
int nodeCount = 0;
|
2012-12-14 04:34:42 +00:00
|
|
|
while ((node = tr_variantListChild (tier, nodeCount++)))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
if (tr_variantGetStr (node, &str, NULL) && strstr (str, in))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
char * newstr = replaceSubstr (str, in, out);
|
|
|
|
printf ("\tReplaced in \"announce-list\" tier %d: \"%s\" --> \"%s\"\n", tierCount, str, newstr);
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantFree (node);
|
|
|
|
tr_variantInitStr (node, newstr, -1);
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_free (newstr);
|
|
|
|
changed = true;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return changed;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 04:21:45 +00:00
|
|
|
static bool
|
2012-12-14 04:34:42 +00:00
|
|
|
announce_list_has_url (tr_variant * announce_list, const char * url)
|
2011-09-07 04:21:45 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * tier;
|
2012-12-05 17:29:46 +00:00
|
|
|
int tierCount = 0;
|
2012-12-14 04:34:42 +00:00
|
|
|
while ((tier = tr_variantListChild (announce_list, tierCount++)))
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * node;
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * str;
|
|
|
|
int nodeCount = 0;
|
2012-12-14 04:34:42 +00:00
|
|
|
while ((node = tr_variantListChild (tier, nodeCount++)))
|
|
|
|
if (tr_variantGetStr (node, &str, NULL) && !strcmp (str, url))
|
2012-12-05 17:29:46 +00:00
|
|
|
return true;
|
2011-09-07 04:21:45 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
|
|
|
|
return false;
|
2011-09-07 04:21:45 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static bool
|
2012-12-14 04:34:42 +00:00
|
|
|
addURL (tr_variant * metainfo, const char * url)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * announce = NULL;
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * announce_list = NULL;
|
2012-12-05 17:29:46 +00:00
|
|
|
bool changed = false;
|
2012-12-22 20:35:19 +00:00
|
|
|
const bool had_announce = tr_variantDictFindStr (metainfo, TR_KEY_announce, &announce, NULL);
|
|
|
|
const bool had_announce_list = tr_variantDictFindList (metainfo, TR_KEY_announce_list, &announce_list);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (!had_announce && !had_announce_list)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
/* this new tracker is the only one, so add it to "announce"... */
|
|
|
|
printf ("\tAdded \"%s\" in \"announce\"\n", url);
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_variantDictAddStr (metainfo, TR_KEY_announce, url);
|
2012-12-05 17:29:46 +00:00
|
|
|
changed = true;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
2012-12-05 17:29:46 +00:00
|
|
|
else
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
if (!had_announce_list)
|
2011-09-07 04:21:45 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
announce_list = tr_variantDictAddList (metainfo, TR_KEY_announce_list, 2);
|
2012-02-03 16:44:07 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (had_announce)
|
2011-09-07 04:21:45 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
/* we're moving from an 'announce' to an 'announce-list',
|
|
|
|
* so copy the old announce URL to the list */
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * tier = tr_variantListAddList (announce_list, 1);
|
|
|
|
tr_variantListAddStr (tier, announce);
|
2012-12-05 17:29:46 +00:00
|
|
|
changed = true;
|
2011-09-07 04:21:45 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
/* If the user-specified URL isn't in the announce list yet, add it */
|
|
|
|
if (!announce_list_has_url (announce_list, url))
|
2011-09-07 04:21:45 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant * tier = tr_variantListAddList (announce_list, 1);
|
|
|
|
tr_variantListAddStr (tier, url);
|
2013-09-08 17:32:09 +00:00
|
|
|
printf ("\tAdded \"%s\" to \"announce-list\" tier %"TR_PRIuSIZE"\n", url, tr_variantListSize (announce_list));
|
2012-12-05 17:29:46 +00:00
|
|
|
changed = true;
|
2011-09-07 04:21:45 +00:00
|
|
|
}
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return changed;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-12-05 17:29:46 +00:00
|
|
|
main (int argc, char * argv[])
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
int i;
|
|
|
|
int changedCount = 0;
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2014-09-21 18:06:28 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
tr_win32_make_args_utf8 (&argc, &argv);
|
|
|
|
#endif
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
files = tr_new0 (const char*, argc);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2013-01-25 23:34:20 +00:00
|
|
|
tr_logSetLevel (TR_LOG_ERROR);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (parseCommandLine (argc, (const char**)argv))
|
|
|
|
return EXIT_FAILURE;
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (showVersion)
|
2010-08-08 22:53:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
fprintf (stderr, MY_NAME" "LONG_VERSION_STRING"\n");
|
|
|
|
return EXIT_SUCCESS;
|
2010-08-08 22:53:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (fileCount < 1)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
fprintf (stderr, "ERROR: No torrent files specified.\n");
|
|
|
|
tr_getopt_usage (MY_NAME, getUsage (), options);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
return EXIT_FAILURE;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (!add && !deleteme && !replace[0])
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
fprintf (stderr, "ERROR: Must specify -a, -d or -r\n");
|
|
|
|
tr_getopt_usage (MY_NAME, getUsage (), options);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
return EXIT_FAILURE;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
for (i=0; i<fileCount; ++i)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant top;
|
2012-12-05 17:29:46 +00:00
|
|
|
bool changed = false;
|
|
|
|
const char * filename = files[i];
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("%s\n", filename);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
if (tr_variantFromFile (&top, TR_VARIANT_FMT_BENC, filename))
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("\tError reading file\n");
|
|
|
|
continue;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (deleteme != NULL)
|
|
|
|
changed |= removeURL (&top, deleteme);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (add != NULL)
|
|
|
|
changed = addURL (&top, add);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (replace[0] && replace[1])
|
|
|
|
changed |= replaceURL (&top, replace[0], replace[1]);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (changed)
|
2010-06-16 14:27:24 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
++changedCount;
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantToFile (&top, TR_VARIANT_FMT_BENC, filename);
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantFree (&top);
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
printf ("Changed %d files\n", changedCount);
|
2010-06-16 14:27:24 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_free (files);
|
|
|
|
return EXIT_SUCCESS;
|
2010-06-16 14:27:24 +00:00
|
|
|
}
|