]> ToastFreeware Gitweb - gregoa/bti.git/blobdiff - bti.c
remove Makefile and fix git-release script
[gregoa/bti.git] / bti.c
diff --git a/bti.c b/bti.c
index 71a2d81f838d15211a2ecb60289d860f90bd690a..2ae7b4c213ba02b23ec8c2cfa8547d54003ec552 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -16,6 +16,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
+#define _GNU_SOURCE
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -35,7 +37,6 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <pcre.h>
-#include "bti_version.h"
 
 
 #define zalloc(size)   calloc(size, 1)
@@ -43,7 +44,8 @@
 #define dbg(format, arg...)                                            \
        do {                                                            \
                if (debug)                                              \
-                       printf("%s: " format , __func__ , ## arg);      \
+                       fprintf(stdout, "bti: %s: " format , __func__ , \
+                               ## arg);                                \
        } while (0)
 
 
@@ -75,6 +77,7 @@ struct session {
        int bash;
        int shrink_urls;
        int dry_run;
+       int page;
        enum host host;
        enum action action;
 };
@@ -88,7 +91,7 @@ struct bti_curl_buffer {
 static void display_help(void)
 {
        fprintf(stdout, "bti - send tweet to twitter or identi.ca\n");
-       fprintf(stdout, "Version: " BTI_VERSION "\n");
+       fprintf(stdout, "Version: " VERSION "\n");
        fprintf(stdout, "Usage:\n");
        fprintf(stdout, "  bti [options]\n");
        fprintf(stdout, "options are:\n");
@@ -102,15 +105,17 @@ static void display_help(void)
        fprintf(stdout, "  --host HOST\n");
        fprintf(stdout, "  --logfile logfile\n");
        fprintf(stdout, "  --shrink-urls\n");
+       fprintf(stdout, "  --page PAGENUMBER\n");
        fprintf(stdout, "  --bash\n");
        fprintf(stdout, "  --debug\n");
+       fprintf(stdout, "  --dry-run\n");
        fprintf(stdout, "  --version\n");
        fprintf(stdout, "  --help\n");
 }
 
 static void display_version(void)
 {
-       fprintf(stdout, "bti - version %s\n", BTI_VERSION);
+       fprintf(stdout, "bti - version %s\n", VERSION);
 }
 
 static struct session *session_alloc(void)
@@ -349,12 +354,12 @@ static int send_request(struct session *session)
                         session->account, session->password);
                switch (session->host) {
                case HOST_TWITTER:
-                       curl_easy_setopt(curl, CURLOPT_URL,
-                                        twitter_friends_url);
+                       sprintf(user_url, "%s?page=%d", twitter_friends_url, session->page);
+                       curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                case HOST_IDENTICA:
-                       curl_easy_setopt(curl, CURLOPT_URL,
-                                        identica_friends_url);
+                       sprintf(user_url, "%s?page=%d", identica_friends_url, session->page);
+                       curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                }
                curl_easy_setopt(curl, CURLOPT_USERPWD, user_password);
@@ -363,13 +368,11 @@ static int send_request(struct session *session)
        case ACTION_USER:
                switch (session->host) {
                case HOST_TWITTER:
-                       sprintf(user_url, "%s%s.xml", twitter_user_url,
-                               session->user);
+                       sprintf(user_url, "%s%s.xml?page=%d", twitter_user_url, session->user, session->page);
                        curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                case HOST_IDENTICA:
-                       sprintf(user_url, "%s%s.xml", identica_user_url,
-                               session->user);
+                       sprintf(user_url, "%s%s.xml?page=%d", identica_user_url, session->user, session->page);
                        curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                }
@@ -380,12 +383,12 @@ static int send_request(struct session *session)
                         session->account, session->password);
                switch (session->host) {
                case HOST_TWITTER:
-                       curl_easy_setopt(curl, CURLOPT_URL,
-                                        twitter_replies_url);
+                       sprintf(user_url, "%s?page=%d", twitter_replies_url, session->page);
+                       curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                case HOST_IDENTICA:
-                       curl_easy_setopt(curl, CURLOPT_URL,
-                                        identica_replies_url);
+                       sprintf(user_url, "%s?page=%d", identica_replies_url, session->page);
+                       curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                }
                curl_easy_setopt(curl, CURLOPT_USERPWD, user_password);
@@ -394,12 +397,12 @@ static int send_request(struct session *session)
        case ACTION_PUBLIC:
                switch (session->host) {
                case HOST_TWITTER:
-                       curl_easy_setopt(curl, CURLOPT_URL,
-                                        twitter_public_url);
+                       sprintf(user_url, "%s?page=%d", twitter_public_url, session->page);
+                       curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                case HOST_IDENTICA:
-                       curl_easy_setopt(curl, CURLOPT_URL,
-                                        identica_public_url);
+                       sprintf(user_url, "%s?page=%d", identica_public_url, session->page);
+                       curl_easy_setopt(curl, CURLOPT_URL, user_url);
                        break;
                }
 
@@ -921,6 +924,7 @@ int main(int argc, char *argv[], char *envp[])
                { "help", 0, NULL, 'h' },
                { "bash", 0, NULL, 'b' },
                { "dry-run", 0, NULL, 'n' },
+               { "page", 1, NULL, 'g' },
                { "version", 0, NULL, 'v' },
                { }
        };
@@ -931,6 +935,7 @@ int main(int argc, char *argv[], char *envp[])
        int option;
        char *http_proxy;
        time_t t;
+       int page_nr;
 
        debug = 0;
        rl_bind_key('\t', rl_insert);
@@ -963,7 +968,7 @@ int main(int argc, char *argv[], char *envp[])
        parse_configfile(session);
 
        while (1) {
-               option = getopt_long_only(argc, argv, "dqe:p:P:H:a:A:u:h",
+               option = getopt_long_only(argc, argv, "dqe:p:P:H:a:A:u:hg:sn",
                                          options, NULL);
                if (option == -1)
                        break;
@@ -977,6 +982,11 @@ int main(int argc, char *argv[], char *envp[])
                        session->account = strdup(optarg);
                        dbg("account = %s\n", session->account);
                        break;
+               case 'g':
+                       page_nr = atoi(optarg);
+                       dbg("page = %d\n", page_nr);
+                       session->page = page_nr;
+                       break;
                case 'p':
                        if (session->password)
                                free(session->password);
@@ -1044,6 +1054,13 @@ int main(int argc, char *argv[], char *envp[])
                }
        }
 
+       /*
+        * Show the version to make it easier to determine what
+        * is going on here
+        */
+       if (debug)
+               display_version();
+
        if (session->action == ACTION_UNKNOWN) {
                fprintf(stderr, "Unknown action, valid actions are:\n");
                fprintf(stderr, "'update', 'friends', 'public', "
@@ -1076,7 +1093,7 @@ int main(int argc, char *argv[], char *envp[])
 
                session->tweet = zalloc(strlen(tweet) + 10);
                if (session->bash)
-                       sprintf(session->tweet, "$ %s", tweet);
+                       sprintf(session->tweet, "%c %s", getuid() ? '$' : '#', tweet);
                else
                        sprintf(session->tweet, "%s", tweet);
 
@@ -1087,6 +1104,8 @@ int main(int argc, char *argv[], char *envp[])
        if (!session->user)
                session->user = strdup(session->account);
 
+       if (session->page == 0)
+               session->page = 1;
        dbg("account = %s\n", session->account);
        dbg("password = %s\n", session->password);
        dbg("host = %d\n", session->host);