"Fossies" - the Fresh Open Source Software Archive

Member "rpm2html-1.11.2/rpm2html.c" (9 Nov 2010, 7064 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 "rpm2html.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * rpm2html.c : Application to generate an HTML view of an ensemble
    3  *              of RPM packages.
    4  *
    5  * See Copyright for the status of this software.
    6  *
    7  * $Id: rpm2html.c,v 1.49 2007/04/01 13:37:34 hany Exp $
    8  */
    9 
   10 #include <config.h>
   11 #include <sys/types.h>
   12 #include <sys/stat.h>
   13 #ifdef HAVE_FCNTL_H
   14 #include <fcntl.h>
   15 #endif
   16 #include <stdio.h>
   17 #include <stdlib.h>
   18 #include <string.h>
   19 #ifdef HAVE_UNISTD_H
   20 #include <unistd.h>
   21 #endif
   22 #include <time.h>
   23 
   24 #include <ctype.h>
   25 #include <errno.h>
   26 #include <rpm/rpmlib.h>
   27 
   28 #include "rpm2html.h"
   29 #include "rpmdata.h"
   30 #include "html.h"
   31 #include "rdf.h"
   32 #include <libxml/tree.h>
   33 #include "language.h"
   34 #ifdef WITH_SQL
   35 #include "sql.h"
   36 #endif
   37 
   38 void usage(const char *argv0) {
   39     fprintf(stderr, "%s %s : Web page generator for RPM packages\n",
   40         RPM2HTML_NAME, RPM2HTML_VER);
   41     fprintf(stderr, 
   42  "usage : %s [-q/-v] [--nosql] [-force] [-lang msgfile] configfile1 [configfile2 ...]\n",
   43             argv0);
   44     fprintf(stderr, "   or   %s [-dumplang msgfile]\n", argv0);
   45     exit(1);
   46 }
   47 
   48 int main(int argc, char *argv[]) {
   49     rpmDataPtr list = NULL;
   50     int i;
   51     time_t start_time;
   52     int nb_config_files = 0;
   53     char host[200];
   54     int mask;
   55     const char *dist = NULL;
   56     const char *dir = NULL;
   57 
   58     start_time = time(NULL);
   59     gethostname(host, sizeof(host));
   60     currentTime = time(NULL);
   61     rpm2html_rpm2html_thishost = &host[0];
   62 
   63     xmlKeepBlanksDefault(0);
   64 
   65     rpmReadConfigFiles(NULL, NULL);
   66 
   67     /*
   68      * Ensure that all files and directories created a world readable !
   69      */
   70     mask = umask(022);
   71 
   72     for (i = 1; i < argc ; i++) {
   73         if (argv[i][0] == '-') {
   74         char *ptr = argv[i];
   75         while (*ptr == '-') ptr++;
   76         if (!strcmp(ptr, "lang")) {
   77         i++;
   78         if (i >= argc) break;
   79         readLanguageFile(argv[i]);
   80         } else if (!strcmp(ptr, "dumplang")) {
   81         i++;
   82         if (i >= argc) break;
   83         writeLanguageFile(ptr);
   84         return(0);
   85         } else if (!strcmp(ptr, "nosql")) {
   86         rpm2html_no_sql++;
   87         } else if (!strcmp(ptr, "force")) {
   88         force++;
   89         } else if (!strcmp(ptr, "cleanup")) {
   90 #ifdef WITH_SQL
   91         if (init_sql(NULL, "rpmfind", NULL, NULL) < 0) {
   92             exit(1);
   93         }
   94         sql_check_packages();
   95 #endif
   96         exit(0);
   97         } else if (!strcmp(ptr, "dir")) {
   98         i++;
   99         if (i >= argc) break;
  100         dir = argv[i];
  101         } else if (!strcmp(ptr, "dist")) {
  102         i++;
  103         if (i >= argc) break;
  104         dist = argv[i];
  105         } else if (!strcmp(ptr, "v")) {
  106         rpm2htmlVerbose++;
  107         } else if (!strcmp(ptr, "q")) {
  108         rpm2htmlVerbose = 0;
  109         } else {
  110             fprintf(stderr, "Unknown option: %s\n", argv[i]);
  111         usage(argv[0]);
  112         }
  113     } else {
  114 #ifdef WITH_SQL
  115         if (init_sql(NULL, "rpmfind", NULL, NULL) < 0) {
  116         exit(1);
  117         }
  118 #else
  119         rpm2html_no_sql = 1;
  120 #endif
  121         if (readConfigFile(argv[i]) >= 0) {
  122             if (rpm2html_dump_html != 0) {
  123                 dumpDirIcon();
  124 #ifdef HAVE_LIBTEMPLATE
  125                 initTemplateEngine(rpm2html_html_template);
  126 #endif
  127                 }
  128 
  129         /*
  130          * A config file has been found and parsed.
  131          * Scan the directories, dump the results
  132          * and reinitialize.
  133          */
  134             nb_config_files++;
  135         if ((dist == NULL) && (dir == NULL)) {
  136             /*
  137              * Full reindex and regeneration of the cross-index
  138              * pages.
  139              */
  140             list = rpmDirScanAll();
  141             if (rpm2html_dump_html != 0) {
  142             if (rpm2html_files != 0) {
  143                 dumpAllRessHtml(0);
  144                 rpmNameSort(&list, 0);
  145                 dumpRpmByName(rpmSoftwareList, 0);
  146                 rpmDistribSort(&list, 0);
  147                 dumpRpmByDistribs(list, 0);
  148                 rpmGroupSort(&list, 0);
  149                 dumpRpmByGroups(rpmSoftwareList, 0);
  150                 rpmVendorSort(&list, 0);
  151                 dumpRpmByVendors(list, 0);
  152                 rpmDateSort(&list, 0);
  153                 dumpRpmByDate(list, 0);
  154                 dumpIndex(start_time, 0);
  155             }
  156             if (rpm2html_install_files != 0) {
  157                 dumpAllRessHtml(1);
  158                 rpmNameSort(&list, 1);
  159                 dumpRpmByName(rpmSoftwareList, 1);
  160                 rpmDistribSort(&list, 1);
  161                 dumpRpmByDistribs(list, 1);
  162                 rpmGroupSort(&list, 1);
  163                 dumpRpmByGroups(rpmSoftwareList, 1);
  164                 rpmVendorSort(&list, 1);
  165                 dumpRpmByVendors(list, 1);
  166                 rpmDateSort(&list, 1);
  167                 dumpRpmByDate(list, 1);
  168                 dumpIndex(start_time, 1);
  169             }
  170             }
  171             if (rpm2html_no_sql) {
  172             if (rpm2html_dump_rdf_resources) {
  173                 dumpAllResRdf();
  174                 dumpAproposRdf();
  175                 dumpDistListRdf();
  176                 rpmDirCleanupAll();
  177             }
  178             }
  179 #ifdef WITH_SQL
  180             else
  181             sql_check_packages();
  182 #endif
  183         } else if (dir != NULL) {
  184             printf("rpm2html: indexing %s\n", dir);
  185             rpmDirScanOneDir(dir);
  186         } else {
  187             rpmDirScanOneDist(dist);
  188         }
  189         if (rpm2htmlVerbose) {
  190            printf(
  191    "To see the result of the indexing point your Web browser to:\n");         
  192            if (rpm2html_rpm2html_thishost == NULL)
  193                printf("\thttp://localhost%s/\n", rpm2html_url);
  194            else    
  195                printf("\thttp://%s%s/\n", rpm2html_rpm2html_thishost,
  196                       rpm2html_url);
  197         }
  198                 reinitialize();
  199             }
  200     }
  201     }
  202 
  203     /*
  204      * reset the umask
  205      */
  206     umask(mask);
  207 
  208 #ifdef WITH_SQL
  209     if ((!rpm2html_no_sql) && (nb_config_files == 0)) {
  210     if (readConfigSql() >= 0) {
  211         if (rpm2html_dump_html != 0) {
  212             dumpDirIcon();
  213 #ifdef HAVE_LIBTEMPLATE
  214             initTemplateEngine(rpm2html_html_template);
  215 #endif
  216             }
  217 
  218         /*
  219          * A config file has been found and parsed.
  220          * Scan the directories, dump the results
  221          * and reinitialize.
  222          */
  223         nb_config_files++;
  224         if (dist == NULL) {
  225         list = rpmDirScanAll();
  226         if (rpm2html_dump_html != 0) {
  227             if (rpm2html_files != 0) {
  228             dumpAllRessHtml(0);
  229             rpmNameSort(&list, 0);
  230             dumpRpmByName(rpmSoftwareList, 0);   /* Modif. by A. Gibert */
  231             rpmDistribSort(&list, 0);
  232             dumpRpmByDistribs(list, 0);
  233             rpmGroupSort(&list, 0);
  234             dumpRpmByGroups(rpmSoftwareList, 0);   /* Modif. by A. Gibert */
  235             rpmVendorSort(&list, 0);
  236             dumpRpmByVendors(list, 0);
  237             rpmDateSort(&list, 0);
  238             dumpRpmByDate(list, 0);
  239             dumpIndex(start_time, 0);
  240             }
  241             if (rpm2html_install_files != 0) {
  242             dumpAllRessHtml(1);
  243             rpmNameSort(&list, 1);
  244             dumpRpmByName(rpmSoftwareList, 1);   /* Modif. by A. Gibert */
  245             rpmDistribSort(&list, 1);
  246             dumpRpmByDistribs(list, 1);
  247             rpmGroupSort(&list, 1);
  248             dumpRpmByGroups(rpmSoftwareList, 1);   /* Modif. by A. Gibert */
  249             rpmVendorSort(&list, 1);
  250             dumpRpmByVendors(list, 1);
  251             rpmDateSort(&list, 1);
  252             dumpRpmByDate(list, 1);
  253             dumpIndex(start_time, 1);
  254             }
  255         }
  256         sql_check_packages();
  257         } else {
  258         rpmDirScanOneDist(dist);
  259         }
  260         if (rpm2htmlVerbose) {
  261            printf(
  262 "To see the result of the indexing point your Web browser to:\n");        
  263            if (rpm2html_rpm2html_thishost == NULL)
  264            printf("\thttp://localhost%s/\n", rpm2html_url);
  265            else    
  266            printf("\thttp://%s%s/\n", rpm2html_rpm2html_thishost,
  267               rpm2html_url);
  268         }
  269         reinitialize();
  270     }
  271     }
  272 #endif
  273     if ((rpm2html_no_sql) && (nb_config_files == 0))
  274     usage(argv[0]);
  275     xmlMemoryDump();
  276 
  277 #ifdef WITH_SQL
  278     if (!rpm2html_no_sql) {
  279     close_sql();
  280     sqlListsCleanup();
  281     }
  282 #endif
  283     return(0);
  284 }
  285