diff src/noffle.c @ 88:1fcdced0246e noffle

[svn] Move posting code to post.c, add command line posting
author bears
date Thu, 18 May 2000 13:17:23 +0100
parents adf0af5152f7
children 0428aed4f9d0
line wrap: on
line diff
--- a/src/noffle.c	Thu May 18 13:11:05 2000 +0100
+++ b/src/noffle.c	Thu May 18 13:17:23 2000 +0100
@@ -10,7 +10,7 @@
   received for some seconds (to allow multiple clients connect at the same
   time).
 
-  $Id: noffle.c 67 2000-05-12 17:19:38Z enz $
+  $Id: noffle.c 100 2000-05-18 12:17:23Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -38,6 +38,7 @@
 #include "online.h"
 #include "outgoing.h"
 #include "over.h"
+#include "post.h"
 #include "pseudo.h"
 #include "util.h"
 #include "server.h"
@@ -172,6 +173,33 @@
         }
 }
 
+static Bool
+doPost( Bool localOnly )
+{
+    Str line;
+    DynStr *s;
+    Bool res;
+    
+
+    s = new_DynStr( 10000 );
+    while ( fgets( line, MAXCHAR, stdin ) != NULL )
+	DynStr_app( s, line );
+
+    res = TRUE;
+    if ( ! Post_open( DynStr_str( s ) ) )
+    {
+	fprintf( stderr, "Post failed: Malformed article.\n" );
+	res = FALSE;
+    }
+    else if ( ! Post_post( localOnly ) )
+    {
+	fprintf( stderr, "Post failed: Can't post to group.\n" );
+	res = FALSE;
+    }
+    Post_close();
+    return res;
+}
+
 static void
 doQuery( void )
 {
@@ -498,6 +526,8 @@
       " -m | --modify post <grp> (y|n)   Modify posting status of a local group\n"
       " -n | --online                    Switch to online mode\n"
       " -o | --offline                   Switch to offline mode\n"
+      " -p | --post all                  Post article on stdin to all groups\n"
+      " -p | --post local                Post article on stdin to local groups\n"
       " -q | --query groups              Get group list from server\n"
       " -q | --query desc                Get group descriptions from server\n"
       " -q | --query times               Get group creation times from server\n"
@@ -619,6 +649,7 @@
         { "modify",           required_argument, NULL, 'm' },
         { "offline",          no_argument,       NULL, 'o' },
         { "online",           no_argument,       NULL, 'n' },
+        { "post",             required_argument, NULL, 'p' },
         { "query",            required_argument, NULL, 'q' },
         { "server",           no_argument,       NULL, 'r' },
         { "requested",        no_argument,       NULL, 'R' },
@@ -637,7 +668,7 @@
     signal( SIGINT, logSignal );
     signal( SIGTERM, logSignal );
     signal( SIGPIPE, logSignal );
-    c = getopt_long( argc, argv, "a:c:C:dD:efghlm:onq:rRs:S:t:u:v",
+    c = getopt_long( argc, argv, "a:c:C:dD:efghlm:onp:q:rRs:S:t:u:v",
                      longOptions, NULL );
     if ( ! initNoffle( c != 'r' ) )
         return EXIT_FAILURE;
@@ -724,6 +755,28 @@
         else
             Online_set( FALSE );
         break;
+    case 'p':
+        if ( ! optarg )
+        {
+            fprintf( stderr, "Option -p needs argument.\n" );
+            result = EXIT_FAILURE;
+        }
+        else
+        {
+	    Bool local;
+	    
+	    local = FALSE;
+            if ( strcmp( optarg, "local" ) == 0 )
+                local = TRUE;
+            else if ( strcmp( optarg, "all" ) != 0 )
+            {
+                fprintf( stderr, "Unknown argument -p %s\n", optarg );
+                result = EXIT_FAILURE;
+            }
+            if ( ! doPost( local ) )
+		result = EXIT_FAILURE;
+        }
+        break;
     case 'q':
         if ( ! optarg )
         {