"Fossies" - the Fresh Open Source Software Archive

Member "rpm2html-1.11.2/sqltools.c" (2 May 2001, 4213 Bytes) of package /linux/privat/rpm2html-1.11.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sqltools.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * sqltools.c: front-end program for MySQL database
    3  */
    4 
    5 #include "config.h"
    6 
    7 #include <stdio.h>
    8 #include <stdlib.h>
    9 #include <sys/types.h>
   10 #include <sys/stat.h>
   11 #ifdef HAVE_FCNTL_H
   12 #include <fcntl.h>
   13 #endif
   14 #include <stdio.h>
   15 #include <stdlib.h>
   16 #include <string.h>
   17 #ifdef HAVE_UNISTD_H
   18 #include <unistd.h>
   19 #endif
   20 /********
   21 #include <rpm/rpmlib.h>
   22  ********/
   23 
   24 #include "rpm2html.h"
   25 #include "rpmdata.h"
   26 #include "sql.h"
   27 
   28 void usage(const char *name) {
   29     printf("%s: usage\n", name);
   30     printf("    config: dump a config file from the database\n");
   31     printf("    stats: show database usage statistics\n");
   32     printf("    reindex: reindex all distro one by one\n");
   33     printf("    check: remove superfluous entries from the database\n");
   34     printf("    vendors: list the registered vendors\n");
   35     printf("    distribs: list the registered distribs\n");
   36     printf("    metadata: list the registered metadata servers\n");
   37     printf("    mirrors: list the registered mirrors\n");
   38     printf("    latests: list the latest packages\n");
   39     printf("    index: regenerates the full index RDF\n");
   40     printf("    add distrib name [vendor [directory [path [url [ urlsrc [description]]]]]]\n");
   41     printf("    add vendor name [url [description]]\n");
   42     printf("    add mirror distrib url\n");
   43     printf("    queries : dump the most requested queries\n");
   44     exit(1);
   45 }
   46 
   47 int main(int argc, char **argv) {
   48     int res;
   49 
   50     if (getenv("DEBUG_SQLTOOLS") == NULL)
   51     rpm2htmlVerbose = 0;
   52     if (argc < 2)
   53         usage(argv[0]);
   54 
   55     if (init_sql(NULL, NULL, NULL, NULL) < 0)
   56     exit(1);
   57 
   58     res = sql_check_tables();
   59     if (res > 0) {
   60     printf("rebuilt %d tables\n", res);
   61     }
   62 
   63     if (!strcmp(argv[1], "vendors"))
   64     sql_show_vendors();
   65     else if (!strcmp(argv[1], "metadata"))
   66     sql_show_metadata();
   67     else if (!strcmp(argv[1], "mirrors"))
   68     sql_show_mirrors();
   69     else if (!strcmp(argv[1], "distribs"))
   70     sql_show_distribs();
   71     else if (!strcmp(argv[1], "config"))
   72     sql_show_config();
   73     else if (!strcmp(argv[1], "stats"))
   74     sql_show_stats();
   75     else if (!strcmp(argv[1], "latests"))
   76     sql_show_latests();
   77     else if (!strcmp(argv[1], "all"))
   78     sql_show_all();
   79     else if (!strcmp(argv[1], "resources"))
   80     sql_show_resources();
   81     else if (!strcmp(argv[1], "check"))
   82     sql_check_packages();
   83     else if (!strcmp(argv[1], "topindex"))
   84     sql_top_index();
   85     else if (!strcmp(argv[1], "index"))
   86     sql_show_index();
   87     else if (!strcmp(argv[1], "reindex"))
   88     sql_reindex();
   89     else if (!strcmp(argv[1], "queries"))
   90     sql_get_top_queries(300);
   91     else if (!strcmp(argv[1], "add")) {
   92     if (argc < 5)
   93         usage(argv[0]);
   94     if (!strcmp(argv[2], "distrib")) {
   95         char *Name = NULL;
   96         char *Path = NULL;
   97         char *Directory = NULL;
   98         char *Vendor = NULL;
   99         char *URL = NULL;
  100         char *URLSrc = NULL;
  101             char *Description = NULL;
  102         char *Color = NULL;
  103         char *Html = NULL;
  104         if ((argc > 3) && (argv[3][0] != 0))
  105         Name = argv[3];
  106         if ((argc > 4) && (argv[4][0] != 0))
  107         Vendor = argv[4];
  108         if ((argc > 5) && (argv[5][0] != 0))
  109         Directory = argv[5];
  110         if ((argc > 6) && (argv[6][0] != 0))
  111         Path = argv[6];
  112         if ((argc > 7) && (argv[7][0] != 0))
  113         URL = argv[7];
  114         if ((argc > 8) && (argv[8][0] != 0))
  115         URLSrc = argv[8];
  116         if ((argc > 9) && (argv[9][0] != 0))
  117         Description = argv[9];
  118         res = sql_add_distrib(Name, Vendor, Directory, Path,
  119                           URL, URLSrc, Description, Color, Html);
  120         printf("updated %d fields\n", res);
  121     } else if (!strcmp(argv[2], "vendor")) {
  122         char *Name = NULL;
  123         char *URL = NULL;
  124             char *Description = NULL;
  125         if ((argc > 3) && (argv[3][0] != 0))
  126         Name = argv[3];
  127         if ((argc > 4) && (argv[4][0] != 0))
  128         URL = argv[4];
  129         if ((argc > 5) && (argv[5][0] != 0))
  130         Description = argv[5];
  131         res = sql_add_vendor(Name, URL, Description);
  132         printf("updated %d fields\n", res);
  133     } else if (!strcmp(argv[2], "mirror")) {
  134         char *Name = NULL;
  135         char *URL = NULL;
  136         if ((argc > 3) && (argv[3][0] != 0))
  137         Name = argv[3];
  138         if ((argc > 4) && (argv[4][0] != 0))
  139         URL = argv[4];
  140         res = sql_add_mirror(Name, URL, 0);
  141         printf("updated %d fields\n", res);
  142     }
  143     }
  144 
  145     if (close_sql() < 0)
  146     return(1);
  147     exit(0);
  148 }
  149