Add usage(), minor code cleanups
[remotetop.git] / rtop.c
diff --git a/rtop.c b/rtop.c
index c204aaf..410e5c6 100644 (file)
--- a/rtop.c
+++ b/rtop.c
 #include "tmalloc.h"
 #include "top.h"
 
+void
+usage() {
+       fputs(
+                "Copyright (c) 2004-2007 Teodor Sigaev <teodor@sigaev.ru>. All rights reserved.\n"
+                "rtop - read collected load of remote servers\n"
+                "./rtop [-D] -h HOST [-p PORT]\n"
+                "  -D      - debug mode\n"
+                "  -h HOST - server\n"
+                "  -p PRT  - server's port\n",
+                stdout
+       );
+       exit(1);
+}
+
 int
 main( int argc, char *argv[] ) {
        int ch;
        int debug=0;
-       char *host="127.0.0.1";
+       char *host=NULL;
        int port=TOPD_SERVER_DEFAULT_PORT;
        int i;
 
@@ -71,14 +85,15 @@ main( int argc, char *argv[] ) {
                                port=atoi(optarg);
                                break;
                        default:
+                               usage();
                                return 1;
                }
        }
 
-        if ( debug )
-                opentlog( TL_OPEN_STDERR,  TL_DEBUG, NULL);
-        else
-                opentlog( TL_OPEN_SYSLOG, TL_INFO, NULL);
+       if (!host)
+               usage();
+
+       opentlog( TL_OPEN_STDERR,  (debug) ? TL_DEBUG : TL_INFO, NULL);
 
        TC_fillConnection(&cs, host, port);
        cs.buf = (char*)pmsg;