]> ToastFreeware Gitweb - gregoa/bti.git/blobdiff - bti.c
minor coding style cleanup.
[gregoa/bti.git] / bti.c
diff --git a/bti.c b/bti.c
index 285fdfadc7471063a1d6bfd7a2135c47edefb065..201d56fc0858d292896fbec02af510259a1df90b 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -83,6 +83,7 @@ struct session {
        char *hosturl;
        char *hostname;
        int bash;
+       int interactive;
        int shrink_urls;
        int dry_run;
        int page;
@@ -143,7 +144,8 @@ static char *get_string(const char *name)
        if (!fgets(string, 999, stdin))
                return NULL;
        temp = strchr(string, '\n');
-       *temp = '\0';
+       if (temp)
+               *temp = '\0';
        return string;
 }
 
@@ -172,8 +174,11 @@ static void session_readline_init(struct session *session)
        int (*bind_key)(int, void *);
        void (*insert)(void);
 
-       /* default to internal function if we can't find anything */
+       /* default to internal function if we can't or won't find anything */
        session->readline = get_string;
+       if (!isatty(0))
+               return;
+       session->interactive = 1;
 
        tmp = malloc(strlen(libpath)+1);
        if (!tmp)
@@ -185,7 +190,8 @@ static void session_readline_init(struct session *session)
                        *next++ = 0;
                if (*cp == 0)
                        continue;
-               if ((handle = dlopen(cp, RTLD_NOW))) {
+               handle = dlopen(cp, RTLD_NOW);
+               if (handle) {
                        dbg("Using %s for readline library\n", cp);
                        break;
                }
@@ -745,7 +751,8 @@ static char *get_string_from_stdin(void)
        if (!fgets(string, 999, stdin))
                return NULL;
        temp = strchr(string, '\n');
-       *temp = '\0';
+       if (temp)
+               *temp = '\0';
        return string;
 }
 
@@ -1245,7 +1252,7 @@ int main(int argc, char *argv[], char *envp[])
        }
 
        if (session->action == ACTION_UPDATE) {
-               if (session->bash)
+               if (session->bash || !session->interactive)
                        tweet = get_string_from_stdin();
                else
                        tweet = session->readline("tweet: ");