added --debug option
[ppastats.git] / src / main.c
index 4cd5bab..02861ea 100644 (file)
@@ -1,4 +1,4 @@
-/*
+/*a
     Copyright (C) 2011 jeanfi@gmail.com
 
     This program is free software; you can redistribute it and/or modify
 #include <stdio.h>
 #include <string.h>
 
+#include "cache.h"
 #include "html.h"
 #include "lp_ws.h"
 #include "config.h"
+#include "ppastats.h"
 
+int debug;
 static const char *program_name;
 
 static void display_published_binaries(const char *owner, const char *ppa)
@@ -44,15 +47,18 @@ static void display_published_binaries(const char *owner, const char *ppa)
        e_cur = list;
        while (*e_cur) {
                struct binary_package_publishing_history *binary;
-               struct distro_arch_series *dist;
+               const struct distro_arch_series *arch;
+               const struct distro_series *distro;
 
                binary = *e_cur;
-               dist = get_distro_arch_series(binary->distro_arch_series_link);
+               arch = get_distro_arch_series(binary->distro_arch_series_link);
+               distro = get_distro_series(arch->distroseries_link);
 
-               printf("%s %s %s %d\n",
-                      dist->display_name,
+               printf("%s %s %s(%s): %d\n",
                       binary->binary_package_name,
                       binary->binary_package_version,
+                      distro->name,
+                      arch->architecture_tag,
                       get_download_count(binary->self_link));
                e_cur++;
        }
@@ -64,6 +70,7 @@ static struct option long_options[] = {
        {"version", no_argument, 0, 'v'},
        {"help", no_argument, 0, 'h'},
        {"html", no_argument, 0, 't'},
+       {"debug", no_argument, 0, 'd'},
        {0, 0, 0, 0}
 };
 
@@ -80,10 +87,13 @@ There is NO WARRANTY, to the extent permitted by law.\n",
 
 static void print_help()
 {
-       printf("Usage: %s [OPTION]...\n", program_name);
+       printf("Usage: %s [OPTION]... PPA_OWNER PPA_NAME\n", program_name);
 
        puts("ppastats is a command application"
-            " for generating PPA statistics.");
+            " for generating PPA statistics.\n");
+
+       puts("Prints number of downloads for each published packages of a PPA "
+            "or generates an HTML page containing a graph representation.");
 
        puts("");
        puts("Options:");
@@ -114,12 +124,15 @@ int main(int argc, char **argv)
 
        program_name = argv[0];
 
-       while ((optc = getopt_long(argc, argv, "vht", long_options,
+       while ((optc = getopt_long(argc, argv, "vhtd", long_options,
                                   NULL)) != -1) {
                switch (optc) {
                case 't':
                        output_html = 1;
                        break;
+               case 'd':
+                       debug = 1;
+                       break;
                case 'h':
                        print_help();
                        exit(EXIT_SUCCESS);
@@ -146,5 +159,9 @@ int main(int argc, char **argv)
        else
                display_published_binaries(owner, ppa);
 
+       /* for valgrind.... */
+       lp_ws_cleanup();
+       cache_cleanup();
+
        exit(EXIT_SUCCESS);
 }