Annotation of rpm2html/html.c, revision 1.16

1.1       veillard    1: /*
                      2:  * html.c: code concerning the dump as an HTML base.
                      3:  *
1.13      veillard    4:  * Copyright (c) 1997 Daniel Veillard <veillard@apocalypse.org>
1.10      veillard    5:  * See COPYING for the status of this software.
1.1       veillard    6:  *
1.16    ! veillard    7:  * $Id: html.c,v 1.15 1997/11/17 05:54:00 veillard Exp $
1.1       veillard    8:  */
                      9: 
1.10      veillard   10: #include <config.h>
1.1       veillard   11: #include <sys/types.h>
                     12: #include <sys/stat.h>
1.10      veillard   13: #ifdef HAVE_FCNTL_H
1.1       veillard   14: #include <fcntl.h>
1.10      veillard   15: #endif
1.1       veillard   16: #include <stdio.h>
                     17: #include <stdlib.h>
                     18: #include <string.h>
1.10      veillard   19: #ifdef HAVE_UNISTD_H
1.1       veillard   20: #include <unistd.h>
1.10      veillard   21: #endif
1.1       veillard   22: #include <time.h>
1.16    ! veillard   23: #include <errno.h>
1.1       veillard   24: 
1.4       veillard   25: #include "rpm2html.h"
1.1       veillard   26: #include "rpmdata.h"
                     27: #include "html.h"
1.14      veillard   28: #include "language.h"
1.1       veillard   29: 
                     30: /*
                     31:  * Global variables concerning the dump environment
                     32:  */
                     33: 
                     34: static char buf[500];
                     35: 
                     36: /*
1.2       veillard   37:  * Transformation function from group to filename.
1.1       veillard   38:  */
                     39: 
                     40: char *groupName(char *group) {
                     41:     static char gbuf[500];
                     42:     char *cur = gbuf;
                     43: 
                     44:     while (*group != '\0') {
1.2       veillard   45:         if ((*group == '/') || (*group == ' ')) {
1.1       veillard   46:            *cur++ = '_';
                     47:            group ++;
                     48:        } else *cur++ = *group++;
                     49:     }
1.14      veillard   50:     strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
1.1       veillard   51:     return(gbuf);
                     52: }
                     53: 
                     54: /*
1.2       veillard   55:  * Transformation function from group to filename.
                     56:  */
                     57: 
                     58: char *distribName(char *distrib) {
                     59:     static char dbuf[500];
                     60:     char *cur = dbuf;
                     61: 
                     62:     while (*distrib != '\0') {
                     63:         if ((*distrib == '/') || (*distrib == ' ')) {
                     64:            *cur++ = '_';
                     65:            distrib ++;
                     66:        } else *cur++ = *distrib++;
                     67:     }
1.14      veillard   68:     strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
1.2       veillard   69:     return(dbuf);
                     70: }
                     71: 
                     72: /*
                     73:  * Transformation function from vendor to filename.
                     74:  */
                     75: 
                     76: char *vendorName(char *vendor) {
                     77:     static char vbuf[500];
                     78:     char *cur = vbuf;
                     79: 
                     80:     while (*vendor != '\0') {
                     81:         if ((*vendor == '/') || (*vendor == ' ')) {
                     82:            *cur++ = '_';
                     83:            vendor ++;
                     84:        } else *cur++ = *vendor++;
                     85:     }
1.14      veillard   86:     strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
1.2       veillard   87:     return(vbuf);
                     88: }
                     89: 
                     90: /*
1.3       veillard   91:  * Transformation function from ressource to filename.
                     92:  */
                     93: 
                     94: char *ressourceName(char *ressource) {
                     95:     static char rbuf[500];
                     96:     char *cur = rbuf;
                     97: 
                     98:     while (*ressource != '\0') {
                     99:         if ((*ressource == '/') || (*ressource == ' ')) {
                    100:            *cur++ = '_';
                    101:            ressource ++;
                    102:        } else *cur++ = *ressource++;
                    103:     }
1.14      veillard  104:     strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
1.3       veillard  105:     return(rbuf);
                    106: }
                    107: 
                    108: /*
1.4       veillard  109:  * Generate an HTML header
                    110:  */
                    111: 
1.11      veillard  112: void generateHtmlHeader(FILE *html, char *title, char *color) {
1.4       veillard  113:     fprintf(html, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n");
1.6       veillard  114:     fprintf(html, "<html>\n<head>\n<title>%s</title>\n", title);
1.4       veillard  115:     fprintf(html, "<meta name=\"GENERATOR\" content=\"%s %s\">\n",
1.6       veillard  116:             rpm2html_name, rpm2html_ver);
1.11      veillard  117:     if (color == NULL)
                    118:         fprintf(html, "</head>\n<body bgcolor=\"#ffffff\">\n");
                    119:     else 
                    120:         fprintf(html, "</head>\n<body bgcolor=\"%s\">\n", color);
1.4       veillard  121: }
                    122: 
                    123: /*
                    124:  * Generate an HTML footer
                    125:  */
                    126: 
                    127: void generateHtmlFooter(FILE *html) {
                    128:     struct tm * tstruct;
                    129:     time_t current_time;
                    130: 
                    131:     current_time = time(NULL);
                    132:     tstruct = localtime(&current_time);
                    133: 
                    134:     fprintf(html, "<hr>\n");
1.14      veillard  135:     fprintf(html, "<p>%s <a href=\"%s\">%s %s</a>\n",
                    136:             localizedStrings[LANG_GENERATED],
                    137:            rpm2html_url, rpm2html_name, rpm2html_ver);
1.4       veillard  138:     fprintf(html, "<p><a href=\"mailto:%s\">%s</a>, %s\n",
1.6       veillard  139:             rpm2html_mail, rpm2html_maint, asctime(tstruct));
1.4       veillard  140:     fprintf(html, "</body>\n</html>\n");
                    141: }
                    142: 
1.15      veillard  143: /*
                    144:  * Generate a line in a table for a RPM.
                    145:  */
                    146: 
                    147: void generateHtmlRpmRow(FILE *html, rpmDataPtr cur) {
                    148:     fprintf(html, "<tr><td bgcolor=\"%s\">",
                    149:            cur->dir->color);
                    150:     fprintf(html, "<a href=\"%s-%s-%s.html\">",
                    151:            cur->name, cur->version, cur->release);
                    152:     fprintf(html, "%s-%s-%s</a></td>\n",
                    153:            cur->name, cur->version, cur->release);
                    154:     fprintf(html, "<td bgcolor=\"%s\">%s</td></tr>\n",
                    155:             cur->dir->color, cur->summary);
                    156: }
                    157: 
                    158: /*
                    159:  * Generate a color indicator
                    160:  */
                    161: 
                    162: void generateColorIndicator(FILE *html) {
                    163:     int nb = 0;
                    164:     rpmDirPtr dir = dirList;
                    165: 
                    166:     fprintf(html, "<table align=\"center\"><tbody>\n<tr>\n");
                    167:     while (dir != NULL) {
                    168:         if ((nb > 0) && ((nb % 3) == 0))
                    169:            fprintf(html, "</tr><tr>\n");
                    170:         fprintf(html, "<td bgcolor=\"%s\">", dir->color);
                    171:        if (dir->name != NULL)
                    172:            fprintf(html, "%s</td>", dir->name);
                    173:        else
                    174:            fprintf(html, "%s</td>", dir->urls[0]);
                    175:        dir = dir->next;
                    176:     }
                    177:     fprintf(html, "</tr>\n</tbody></table>\n");
                    178: }
                    179: 
1.13      veillard  180: void dumpIndex(time_t start_time, int installed) {
1.9       veillard  181:     int i;
                    182:     FILE *html;
                    183:     char host[200];
                    184:     rpmDirPtr cur = dirList;
1.13      veillard  185: 
1.9       veillard  186:     gethostname(host, sizeof(host));
                    187: 
                    188: #ifdef DEBUG
1.14      veillard  189:     printf("Dumping %s/%s\n", rpm2html_dir, localizedStrings[LANG_INDEX_HTML]);
1.9       veillard  190: #endif
1.14      veillard  191:     sprintf(buf, "%s/%s", rpm2html_dir, localizedStrings[LANG_INDEX_HTML]);
1.9       veillard  192: 
                    193:     html = fopen(buf, "w");
                    194:     if (html == NULL) {
                    195:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    196:                buf, strerror(errno));
                    197:         return;
                    198:     }
                    199: 
                    200: 
1.15      veillard  201:     if (installed) {
                    202:        sprintf(buf, "%s %s", localizedStrings[LANG_WELCOME_INSTALL], host);
                    203:        generateHtmlHeader(html, buf, NULL);
                    204:        fprintf(html, "<h1 align=center>%s %s</h1>\n",
                    205:                localizedStrings[LANG_WELCOME_INSTALL], host);
                    206:     } else {
                    207:        sprintf(buf, "%s %s", localizedStrings[LANG_WELCOME_REPOSITORY], host);
                    208:        generateHtmlHeader(html, buf, NULL);
                    209:        fprintf(html, "<h1 align=center>%s %s</h1>\n",
                    210:                localizedStrings[LANG_WELCOME_REPOSITORY], host);
                    211:     }
1.9       veillard  212: 
1.14      veillard  213:     fprintf(html, "%s\n", localizedStrings[LANG_RPM2HTML_INTRO]);
                    214:     fprintf(html, "<h3>");
                    215:     if (installed)
                    216:        fprintf(html, localizedStrings[LANG_INSTALLED_STATS],
                    217:                rpm2html_install_files, rpm2html_install_size / (1024 * 1024));
                    218:     else
                    219:        fprintf(html, localizedStrings[LANG_STATS],
                    220:                rpm2html_files, rpm2html_size / (1024 * 1024));
                    221:     fprintf(html, "</h3>\n");
                    222:     fprintf(html, "<ul>\n");
                    223:     fprintf(html, "<li>\n%s <a href=\"%s\">%s</a>\n",
                    224:             localizedStrings[LANG_LIST],
                    225:            localizedStrings[LANG_GROUP_HTML],
                    226:            localizedStrings[LANG_INDEX_GROUP]);
                    227:     fprintf(html, "<li>\n%s <a href=\"%s\">%s</a>\n",
                    228:             localizedStrings[LANG_LIST],
                    229:            localizedStrings[LANG_BYDATE_HTML],
                    230:            localizedStrings[LANG_INDEX_CREATION]);
                    231:     fprintf(html, "<li>\n%s <a href=\"%s\">%s</a>\n",
                    232:             localizedStrings[LANG_LIST],
                    233:            localizedStrings[LANG_BYNAME_HTML],
                    234:            localizedStrings[LANG_INDEX_NAME]);
                    235:     fprintf(html, "<li>\n%s <a href=\"%s\">%s</a>\n",
                    236:             localizedStrings[LANG_LIST],
                    237:            localizedStrings[LANG_VENDOR_HTML],
                    238:            localizedStrings[LANG_INDEX_VENDOR]);
                    239:     fprintf(html, "<li>\n%s <a href=\"%s\">%s</a>\n",
                    240:             localizedStrings[LANG_LIST],
                    241:            localizedStrings[LANG_DISTRIB_HTML],
                    242:            localizedStrings[LANG_INDEX_DISTRIB]);
                    243:     fprintf(html, "</ul>\n");
1.9       veillard  244: 
                    245:     while (cur != NULL) {
1.15      veillard  246:        fprintf(html, "<table><tbody bgcolor=\"%s\">\n<tr>\n",
                    247:                cur->color);
1.9       veillard  248:         if (cur->name == NULL)
1.15      veillard  249:            fprintf(html, "<td bgcolor=\"%s\" colspan=2><a href=\"%s\">%s</a></td>\n",
                    250:                    cur->color, cur->ftp, cur->ftp);
1.9       veillard  251:        else
1.15      veillard  252:            fprintf(html, "<td bgcolor=\"%s\" colspan=2><a href=\"%s\">%s</a></td>\n",
                    253:                    cur->color, cur->ftp, cur->name);
                    254:        fprintf(html, "</tr>\n");
1.9       veillard  255:        if ((cur->ftpsrc != NULL) && (strcmp(cur->ftp, cur->ftpsrc)))
1.15      veillard  256:            fprintf(html, 
                    257:                "<tr><td bgcolor=\"%s\">%s:</td><td bgcolor=\"%s\"><a href=\"%s\">%s</a></td></tr>\n",
                    258:                cur->color, localizedStrings[LANG_SOURCES_REPOSITORY],
                    259:                cur->color, cur->ftpsrc, cur->ftpsrc);
                    260:        fprintf(html,
                    261:            "<tr><td bgcolor=\"%s\">%s:</td><td bgcolor=\"%s\"><a href=\"%s\">%s</a></td></tr>\n",
                    262:            cur->color, localizedStrings[LANG_LOCAL_MIRROR],
                    263:            cur->color, cur->urls[0], cur->urls[0]);
1.9       veillard  264:        if (cur->nb_urls > 1) {
1.15      veillard  265:            fprintf(html, "<tr><td bgcolor=\"%s\" colspan=2>%s</td></tr>\n",
                    266:                    cur->color, localizedStrings[LANG_MIRRORS]);
                    267:            for (i = 1;i < cur->nb_urls;i++) {
                    268:                fprintf(html,
                    269:                    "<tr><td bgcolor=\"%s\" colspan=2><a href=\"%s\">%s</a></td></tr>\n",
                    270:                    cur->color, cur->urls[i], cur->urls[i]);
1.9       veillard  271:            }
                    272:        }
1.15      veillard  273:        fprintf(html, "</tbody></table>\n");
1.9       veillard  274:        cur = cur->next;
1.15      veillard  275:        if (cur != NULL) fprintf(html, "<p></p>\n");
1.9       veillard  276:     }
                    277: 
1.14      veillard  278:     fprintf(html, "<p>%s %d %s</p>\n",
                    279:             localizedStrings[LANG_GENERATION_TIME],
                    280:             (int) (time(NULL) - start_time),
                    281:             localizedStrings[LANG_SECONDS]);
1.9       veillard  282:     generateHtmlFooter(html);
                    283:     fclose(html);
                    284: }
                    285: 
1.4       veillard  286: /*
1.1       veillard  287:  * Dump an RPM block as an HTML file.
                    288:  */
                    289: 
                    290: void dumpRpmHtml(rpmDataPtr rpm) {
                    291:     struct tm * tstruct;
1.8       veillard  292:     rpmDirPtr dir = rpm->dir;
1.13      veillard  293:     int installed = dir->installbase;
1.1       veillard  294:     FILE *html;
1.3       veillard  295:     int i;
1.1       veillard  296: 
                    297: #ifdef DEBUG
1.6       veillard  298:     printf("Dumping %s/%s-%s-%s.html\n", rpm2html_dir,
1.1       veillard  299:            rpm->name, rpm->version, rpm->release);
                    300: #endif
1.6       veillard  301:     sprintf(buf, "%s/%s-%s-%s.html", rpm2html_dir,
1.1       veillard  302:             rpm->name, rpm->version, rpm->release);
                    303: 
                    304:     html = fopen(buf, "w");
                    305:     if (html == NULL) {
                    306:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    307:                buf, strerror(errno));
                    308:         return;
                    309:     }
1.4       veillard  310:     sprintf(buf, "%s-%s-%s RPM", rpm->name, rpm->version, rpm->release);
1.11      veillard  311:     generateHtmlHeader(html, buf, dir->color);
1.1       veillard  312:     if (rpm->arch) {
                    313:        fprintf(html, "<h1 align=center><a href=\"%s/%s-%s-%s.%s.rpm\">\n",
1.8       veillard  314:             dir->urls[0], rpm->name, rpm->version, rpm->release, rpm->arch);
1.1       veillard  315:        fprintf(html, "%s-%s-%s RPM for %s</a></h1>\n",
                    316:             rpm->name, rpm->version, rpm->release, rpm->arch);
                    317:     } else {
                    318:        fprintf(html, "<h1 align=center><a href=\"%s/%s-%s-%s.rpm\">\n",
1.8       veillard  319:             dir->urls[0], rpm->name, rpm->version, rpm->release);
1.1       veillard  320:        fprintf(html, "%s-%s-%s RPM</a></h1>\n",
                    321:             rpm->name, rpm->version, rpm->release);
                    322:     }
1.8       veillard  323:     if (dir->name) {
1.14      veillard  324:         fprintf(html, "<h3 align=center>%s <a href=\"%s\">%s</a></h3>\n",
                    325:                localizedStrings[LANG_FROM],
1.8       veillard  326:                dir->ftp, dir->name);
                    327:     }
1.1       veillard  328:     fprintf(html, "<table align=center border=5 cellspacing=5 cellpadding=5>");
                    329:     fprintf(html, "<tbody>\n");
1.14      veillard  330:     fprintf(html, "<tr><td>%s: %s</td>\n",
                    331:            localizedStrings[LANG_NAME],
1.2       veillard  332:             rpm->name);
1.14      veillard  333:     fprintf(html, "<td>%s: <a href=\"%s\">%s</a></td></tr>\n",
                    334:            localizedStrings[LANG_DISTRIBUTION],
1.2       veillard  335:             distribName(rpm->distribution), rpm->distribution);
1.14      veillard  336:     fprintf(html, "<tr><td>%s: %s</td>\n",
                    337:            localizedStrings[LANG_VERSION],
1.2       veillard  338:             rpm->version);
1.14      veillard  339:     fprintf(html, "<td>%s: <a href=\"%s\">%s</a></td></tr>\n",
                    340:            localizedStrings[LANG_VENDOR],
1.2       veillard  341:             vendorName(rpm->vendor), rpm->vendor);
1.1       veillard  342:     tstruct = localtime(&(rpm->date));
1.10      veillard  343: #ifdef HAVE_STRFTIME
1.1       veillard  344:     strftime(buf, sizeof(buf) - 1, "%c", tstruct);
1.10      veillard  345: #else
                    346: #error "no strftime, please check !"
                    347: #endif
1.14      veillard  348:     if (installed) {
                    349:        fprintf(html, "<tr><td>%s: %s</td>\n<td>%s: %s</td></tr>\n",
                    350:                localizedStrings[LANG_RELEASE],
                    351:                rpm->release,
                    352:                localizedStrings[LANG_INSTALL_DATE],
                    353:                buf);
                    354:     } else {
                    355:        fprintf(html, "<tr><td>%s: %s</td>\n<td>%s: %s</td></tr>\n",
                    356:                localizedStrings[LANG_RELEASE],
                    357:                rpm->release,
                    358:                localizedStrings[LANG_BUILD_DATE],
                    359:                buf);
                    360:     }
                    361:     fprintf(html, "<tr><td>%s: <a href=\"%s\">%s</a></td>\n",
                    362:            localizedStrings[LANG_GROUP],
1.1       veillard  363:             groupName(rpm->group), rpm->group);
1.14      veillard  364:     fprintf(html, "<td>%s: %s</td></tr>\n",
                    365:            localizedStrings[LANG_BUILD_HOST], rpm->host);
                    366:     fprintf(html, "<tr><td>%s: %d</td>\n",
                    367:            localizedStrings[LANG_SIZE],
1.8       veillard  368:             rpm->size);
                    369:     if (dir->ftpsrc) {
1.14      veillard  370:        fprintf(html, "<td>%s: <a href=\"%s/%s\">%s</a></td></tr>\n",
                    371:                localizedStrings[LANG_RPM_SRC],
1.8       veillard  372:                dir->ftpsrc, rpm->srcrpm, rpm->srcrpm);
                    373:     } else {
1.14      veillard  374:        fprintf(html, "<td>%s: %s</td></tr>\n",
                    375:                localizedStrings[LANG_RPM_SRC],
1.8       veillard  376:                rpm->srcrpm);
                    377:     }
                    378:     if (rpm->packager) {
                    379:         char *email = extractEMail(rpm->packager);
                    380:        if (email == NULL)
1.14      veillard  381:            fprintf(html, "<tr><td colspan=\"2\">%s: %s</td></tr>\n",
                    382:                    localizedStrings[LANG_PACKAGER],
1.8       veillard  383:                    rpm->packager);
                    384:         else
1.14      veillard  385:            fprintf(html, "<tr><td colspan=\"2\">%s: <a href=\"mailto:%s\">%s</a></td></tr>\n",
                    386:                    localizedStrings[LANG_PACKAGER],
1.8       veillard  387:                    email, rpm->packager);
                    388:     }
                    389:     if (rpm->url)
1.14      veillard  390:        fprintf(html, "<tr><td colspan=\"2\">%s: <a href=\"%s\">%s</a></td></tr>\n",
                    391:                localizedStrings[LANG_URL],
1.8       veillard  392:                rpm->url, rpm->url);
1.14      veillard  393:     fprintf(html, "<tr><td colspan=\"2\">%s: %s</td></tr>\n",
                    394:            localizedStrings[LANG_SUMMARY],
1.1       veillard  395:             rpm->summary);
                    396:     fprintf(html, "</tbody>\n</table>\n");
1.4       veillard  397:     fprintf(html, "<pre>%s\n</pre>\n", rpm->description);
1.3       veillard  398:     if (rpm->nb_ressources > 0) {
1.14      veillard  399:        fprintf(html, "<h3>%s</h3>\n",
                    400:            localizedStrings[LANG_PROVIDE]);
1.3       veillard  401:        fprintf(html, "<ul>\n");
                    402:        for (i = 0;i < rpm->nb_ressources;i++) {
                    403:            fprintf(html, "<li><a href=\"%s\">%s</a>\n",
                    404:                   ressourceName(rpm->ressources[i]->name),
                    405:                   rpm->ressources[i]->name);
                    406:        }
                    407:        if (i >= MAX_RESS)
                    408:            fprintf(html, "<li>...</a>\n");
                    409:        fprintf(html, "</ul>\n");
                    410:     }
                    411:     if (rpm->nb_requires > 0) {
1.14      veillard  412:        fprintf(html, "<h3>%s</h3>\n",
                    413:            localizedStrings[LANG_REQUIRE]);
1.3       veillard  414:        fprintf(html, "<ul>\n");
                    415:        for (i = 0;i < rpm->nb_requires;i++) {
                    416:            fprintf(html, "<li><a href=\"%s\">%s</a>\n",
                    417:                   ressourceName(rpm->requires[i]->name),
                    418:                   rpm->requires[i]->name);
                    419:        }
                    420:        if (i >= MAX_REQU)
                    421:            fprintf(html, "<li>...</a>\n");
                    422:        fprintf(html, "</ul>\n");
                    423:     }
1.8       veillard  424:     if (rpm->copyright) {
1.14      veillard  425:        fprintf(html, "<h3>%s</h3>\n",
                    426:            localizedStrings[LANG_COPYRIGHT]);
1.8       veillard  427:        fprintf(html, "<pre>%s\n</pre>\n", rpm->copyright);
                    428:     }
1.14      veillard  429:     fprintf(html, "<h3>%s</h3>\n",
                    430:        localizedStrings[LANG_FILES]);
1.8       veillard  431:     if (rpm->filelist == NULL) 
1.14      veillard  432:        fprintf(html, "<bold>%s</bold>\n",
                    433:             localizedStrings[LANG_NO_FILES]);
1.8       veillard  434:     else
                    435:        fprintf(html, "<pre>%s\n</pre>\n", rpm->filelist);
1.3       veillard  436:     
1.4       veillard  437:     generateHtmlFooter(html);
1.3       veillard  438:     fclose(html);
                    439: }
                    440: 
                    441: /*
                    442:  * Dump a ressource block as an HTML file.
                    443:  */
                    444: 
1.13      veillard  445: void dumpRessHtml(rpmRessPtr ress, int installed) {
1.3       veillard  446:     rpmDataPtr rpm;
                    447:     FILE *html;
                    448:     int i;
                    449: 
                    450: #ifdef DEBUG
1.6       veillard  451:     printf("Dumping %s/%s\n", rpm2html_dir,
1.3       veillard  452:            ressourceName(ress->name));
                    453: #endif
1.6       veillard  454:     sprintf(buf, "%s/%s", rpm2html_dir,
1.3       veillard  455:            ressourceName(ress->name));
                    456: 
                    457:     html = fopen(buf, "w");
                    458:     if (html == NULL) {
                    459:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    460:                buf, strerror(errno));
                    461:         return;
                    462:     }
1.14      veillard  463:     sprintf(buf, "%s %s",
                    464:         localizedStrings[LANG_RPM_RESSOURCE], ress->name);
1.11      veillard  465:     generateHtmlHeader(html, buf, NULL);
1.14      veillard  466:     fprintf(html, "<h1 align=center>%s %s</h1>\n",
                    467:         localizedStrings[LANG_RPM_RESSOURCE], ress->name);
                    468:     fprintf(html, "<h3>%s</h3>\n",
                    469:         localizedStrings[LANG_PROVIDED_BY]);
1.3       veillard  470:     fprintf(html, "<ul>\n");
                    471:     for (i = 0;i < ress->nb_provider;i++) {
                    472:         rpm = ress->provider[i];
                    473:        fprintf(html, "<li><a href=\"%s-%s-%s.html\">",
                    474:                    rpm->name, rpm->version, rpm->release);
                    475:        fprintf(html, "%s-%s-%s</a></li>\n",
                    476:                    rpm->name, rpm->version, rpm->release);
                    477:     }
                    478:     if (i >= MAX_PROVIDE)
                    479:         fprintf(html, "<li>...</a>\n");
                    480:     fprintf(html, "</ul>\n");
1.1       veillard  481:     
1.4       veillard  482:     generateHtmlFooter(html);
1.1       veillard  483:     fclose(html);
                    484: }
                    485: 
                    486: /*
                    487:  * Dump all RPM blocks in the HTML files.
1.8       veillard  488:  * Not used anymore there are dumped are they are parsed
                    489:  * to minimize memory requirements
1.13      veillard  490: void dumpAllRpmHtml(int installed) {
                    491:     rpmDataPtr cur;
                    492: 
                    493:     if (installed) cur = rpmInstalledList;
                    494:     else cur = rpmList;
1.1       veillard  495: 
                    496:     while (cur != NULL) {
                    497:         dumpRpmHtml(cur);
                    498:        cur = cur->next;
                    499:     }
                    500: }
1.8       veillard  501:  */
1.1       veillard  502: 
                    503: /*
1.3       veillard  504:  * Dump all RPM blocks in the HTML files.
                    505:  */
1.13      veillard  506: void dumpAllRessHtml(int installed) {
                    507:     rpmRessPtr cur;
                    508: 
                    509:     if (installed) cur = ressInstalledList;
                    510:     else cur = ressList;
1.3       veillard  511: 
                    512:     while (cur != NULL) {
1.13      veillard  513:         dumpRessHtml(cur, installed);
1.3       veillard  514:        cur = cur->next;
                    515:     }
                    516: }
                    517: 
                    518: /*
1.1       veillard  519:  * Dump the Groups HTML files.
                    520:  * One expect that the RPM files have been sorted by group.
                    521:  */
1.13      veillard  522: void dumpRpmGroups(int installed) {
1.1       veillard  523:     FILE *Groups;
                    524:     FILE *currentGroup = NULL;
1.13      veillard  525:     rpmDataPtr cur, prev = NULL;
1.1       veillard  526: 
1.13      veillard  527:     if (installed) cur = rpmInstalledList;
                    528:     else cur = rpmList;
                    529:     
1.1       veillard  530: #ifdef DEBUG
1.14      veillard  531:     printf("Dumping %s/%s\n", rpm2html_dir,
                    532:            localizedStrings[LANG_GROUP_HTML]);
1.1       veillard  533: #endif
1.14      veillard  534:     sprintf(buf, "%s/%s", rpm2html_dir,
                    535:            localizedStrings[LANG_GROUP_HTML]);
1.1       veillard  536: 
                    537:     Groups = fopen(buf, "w");
                    538:     if (Groups == NULL) {
                    539:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    540:                buf, strerror(errno));
                    541:         return;
                    542:     }
1.14      veillard  543:     generateHtmlHeader(Groups, localizedStrings[LANG_SORTED_BY_GROUP], NULL);
                    544:     fprintf(Groups, "<h1 align=center>%s</h1>\n",
                    545:         localizedStrings[LANG_SORTED_BY_GROUP]);
1.1       veillard  546:     fprintf(Groups, "<ul>\n");
                    547: 
                    548:     while (cur != NULL) {
1.9       veillard  549:         if ((cur->group != NULL) && (strlen(cur->group) > 0)) {
1.1       veillard  550:            if ((prev == NULL) || (strcasecmp(prev->group, cur->group))) {
                    551:                if (currentGroup != NULL) {
                    552:                    /* one need to close the current group list */
1.15      veillard  553:                    fprintf(currentGroup,"</tbody></table>\n");
1.4       veillard  554:                    generateHtmlFooter(currentGroup);
1.1       veillard  555:                    fclose(currentGroup);
                    556:                }
                    557: 
                    558:                /* Add the current group in the Group list */
                    559:                fprintf(Groups, "<li><a href=\"%s\">%s</a></li>\n",
                    560:                        groupName(cur->group), cur->group);
                    561: 
                    562:                /* open the new HTML group file */
                    563: #ifdef DEBUG
1.6       veillard  564:                printf("Dumping %s/%s\n", rpm2html_dir, groupName(cur->group));
1.1       veillard  565: #endif
1.6       veillard  566:                sprintf(buf, "%s/%s", rpm2html_dir, groupName(cur->group));
1.1       veillard  567: 
                    568:                currentGroup = fopen(buf, "w");
                    569:                if (currentGroup == NULL) {
                    570:                    fprintf(stderr, "Couldn't save to file %s: %s\n",
                    571:                            buf, strerror(errno));
                    572:                    return;
                    573:                }
1.14      veillard  574:                 sprintf(buf, "%s %s", localizedStrings[LANG_OF_GROUP],
                    575:                        cur->group);
1.11      veillard  576:                 generateHtmlHeader(currentGroup, buf, NULL);
1.1       veillard  577:                fprintf(currentGroup,
1.14      veillard  578:                  "<h1 align=center>%s %s</h1>\n",
                    579:                     localizedStrings[LANG_OF_GROUP], cur->group);
1.15      veillard  580:                if (!installed) generateColorIndicator(currentGroup);
                    581:                fprintf(currentGroup,"<table><tbody>\n");
1.1       veillard  582:            }
1.15      veillard  583:            generateHtmlRpmRow(currentGroup, cur);
1.1       veillard  584:        }
                    585:        prev = cur;
                    586:        cur = cur->next;
                    587:     }
                    588:     if (currentGroup != NULL) {
                    589:        /* one need to close the current group list */
1.4       veillard  590:        generateHtmlFooter(currentGroup);
1.1       veillard  591:        fclose(currentGroup);
                    592:     }
                    593:     fprintf(Groups, "</ul>\n");
1.4       veillard  594:     generateHtmlFooter(Groups);
1.1       veillard  595:     fclose(Groups);
                    596: }
                    597: 
                    598: /*
1.2       veillard  599:  * Dump the Distribs HTML files.
                    600:  * One expect that the RPM files have been sorted by distribution.
1.1       veillard  601:  */
1.13      veillard  602: void dumpRpmDistribs(int installed) {
1.2       veillard  603:     FILE *Distribs;
                    604:     FILE *currentDistrib = NULL;
1.13      veillard  605:     rpmDataPtr cur, prev = NULL;
                    606: 
                    607:     if (installed) cur = rpmInstalledList;
                    608:     else cur = rpmList;
1.2       veillard  609: 
                    610: #ifdef DEBUG
1.14      veillard  611:     printf("Dumping %s/%s\n", rpm2html_dir, localizedStrings[LANG_DISTRIB_HTML]);
1.2       veillard  612: #endif
1.14      veillard  613:     sprintf(buf, "%s/%s", rpm2html_dir, localizedStrings[LANG_DISTRIB_HTML]);
1.2       veillard  614: 
                    615:     Distribs = fopen(buf, "w");
                    616:     if (Distribs == NULL) {
                    617:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    618:                buf, strerror(errno));
                    619:         return;
                    620:     }
1.14      veillard  621:     generateHtmlHeader(Distribs,
                    622:         localizedStrings[LANG_SORTED_BY_DISTRIB], NULL);
                    623:     fprintf(Distribs, "<h1 align=center>%s</h1>\n",
                    624:         localizedStrings[LANG_SORTED_BY_DISTRIB]);
1.2       veillard  625:     fprintf(Distribs, "<ul>\n");
                    626: 
                    627:     while (cur != NULL) {
1.9       veillard  628:         if ((cur->distribution != NULL) && (strlen(cur->distribution) > 0)) {
1.2       veillard  629:            if ((prev == NULL) || (strcasecmp(prev->distribution, cur->distribution))) {
                    630:                if (currentDistrib != NULL) {
                    631:                    /* one need to close the current distribution list */
1.15      veillard  632:                    fprintf(currentDistrib,"</tbody></table>\n");
1.4       veillard  633:                    generateHtmlFooter(currentDistrib);
1.2       veillard  634:                    fclose(currentDistrib);
                    635:                }
                    636: 
                    637:                /* Add the current distribution in the Distrib list */
                    638:                fprintf(Distribs, "<li><a href=\"%s\">%s</a></li>\n",
                    639:                        distribName(cur->distribution), cur->distribution);
                    640: 
                    641:                /* open the new HTML distribution file */
                    642: #ifdef DEBUG
1.6       veillard  643:                printf("Dumping %s/%s\n", rpm2html_dir, distribName(cur->distribution));
1.2       veillard  644: #endif
1.6       veillard  645:                sprintf(buf, "%s/%s", rpm2html_dir, distribName(cur->distribution));
1.2       veillard  646: 
                    647:                currentDistrib = fopen(buf, "w");
                    648:                if (currentDistrib == NULL) {
                    649:                    fprintf(stderr, "Couldn't save to file %s: %s\n",
                    650:                            buf, strerror(errno));
                    651:                    return;
                    652:                }
1.14      veillard  653:                 sprintf(buf, "%s %s",
                    654:                    localizedStrings[LANG_OF_DISTRIB], cur->distribution);
1.11      veillard  655:                 generateHtmlHeader(currentDistrib, buf, NULL);
1.2       veillard  656:                fprintf(currentDistrib,
1.14      veillard  657:                  "<h1 align=center>%s %s</h1>\n",
                    658:                  localizedStrings[LANG_OF_DISTRIB],
1.3       veillard  659:                  cur->distribution);
1.15      veillard  660:                if (!installed) generateColorIndicator(currentDistrib);
                    661:                fprintf(currentDistrib,"<table><tbody>\n");
1.2       veillard  662:            }
1.15      veillard  663:            generateHtmlRpmRow(currentDistrib, cur);
1.2       veillard  664:        }
                    665:        prev = cur;
                    666:        cur = cur->next;
                    667:     }
                    668:     if (currentDistrib != NULL) {
                    669:        /* one need to close the current distribution list */
1.4       veillard  670:        generateHtmlFooter(currentDistrib);
1.2       veillard  671:        fclose(currentDistrib);
                    672:     }
                    673:     fprintf(Distribs, "</ul>\n");
1.4       veillard  674:     generateHtmlFooter(Distribs);
1.2       veillard  675:     fclose(Distribs);
1.1       veillard  676: }
                    677: 
                    678: /*
                    679:  * Dump the Vendors HTML files.
                    680:  * One expect that the RPM files have been sorted by vendors.
                    681:  */
1.13      veillard  682: void dumpRpmVendors(int installed) {
1.2       veillard  683:     FILE *Vendors;
                    684:     FILE *currentVendor = NULL;
1.13      veillard  685:     rpmDataPtr cur, prev = NULL;
                    686: 
                    687:     if (installed) cur = rpmInstalledList;
                    688:     else cur = rpmList;
1.2       veillard  689: 
                    690: #ifdef DEBUG
1.14      veillard  691:     printf("Dumping %s/%s\n", rpm2html_dir, localizedStrings[LANG_VENDOR_HTML]);
1.2       veillard  692: #endif
1.14      veillard  693:     sprintf(buf, "%s/%s", rpm2html_dir, localizedStrings[LANG_VENDOR_HTML]);
1.2       veillard  694: 
                    695:     Vendors = fopen(buf, "w");
                    696:     if (Vendors == NULL) {
                    697:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    698:                buf, strerror(errno));
                    699:         return;
                    700:     }
1.14      veillard  701:     generateHtmlHeader(Vendors, localizedStrings[LANG_SORTED_BY_VENDOR], NULL);
                    702:     fprintf(Vendors, "<h1 align=center>%s</h1>\n",
                    703:         localizedStrings[LANG_SORTED_BY_VENDOR]);
1.2       veillard  704:     fprintf(Vendors, "<ul>\n");
                    705: 
                    706:     while (cur != NULL) {
1.9       veillard  707:         if ((cur->vendor != NULL) && (strlen(cur->vendor) > 0)) {
1.2       veillard  708:            if ((prev == NULL) || (strcasecmp(prev->vendor, cur->vendor))) {
                    709:                if (currentVendor != NULL) {
                    710:                    /* one need to close the current vendor list */
1.15      veillard  711:                    fprintf(currentVendor,"</tbody></table>\n");
1.4       veillard  712:                    generateHtmlFooter(currentVendor);
1.2       veillard  713:                    fclose(currentVendor);
                    714:                }
                    715: 
                    716:                /* Add the current vendor in the Vendor list */
                    717:                fprintf(Vendors, "<li><a href=\"%s\">%s</a></li>\n",
                    718:                        vendorName(cur->vendor), cur->vendor);
                    719: 
                    720:                /* open the new HTML vendor file */
                    721: #ifdef DEBUG
1.6       veillard  722:                printf("Dumping %s/%s\n", rpm2html_dir, vendorName(cur->vendor));
1.2       veillard  723: #endif
1.6       veillard  724:                sprintf(buf, "%s/%s", rpm2html_dir, vendorName(cur->vendor));
1.2       veillard  725: 
                    726:                currentVendor = fopen(buf, "w");
                    727:                if (currentVendor == NULL) {
                    728:                    fprintf(stderr, "Couldn't save to file %s: %s\n",
                    729:                            buf, strerror(errno));
                    730:                    return;
                    731:                }
1.14      veillard  732:                 sprintf(buf, "%s %s", localizedStrings[LANG_OF_VENDOR],
                    733:                    cur->vendor);
1.11      veillard  734:                 generateHtmlHeader(currentVendor, buf, NULL);
1.2       veillard  735:                fprintf(currentVendor,
1.14      veillard  736:                  "<h1 align=center>%s %s</h1>\n",
                    737:                  localizedStrings[LANG_OF_VENDOR], cur->vendor);
1.15      veillard  738:                if (!installed) generateColorIndicator(currentVendor);
                    739:                fprintf(currentVendor,"<table><tbody>\n");
1.2       veillard  740:            }
1.15      veillard  741:            generateHtmlRpmRow(currentVendor, cur);
1.2       veillard  742:        }
                    743:        prev = cur;
                    744:        cur = cur->next;
                    745:     }
                    746:     if (currentVendor != NULL) {
                    747:        /* one need to close the current vendor list */
1.4       veillard  748:        generateHtmlFooter(currentVendor);
1.2       veillard  749:        fclose(currentVendor);
                    750:     }
                    751:     fprintf(Vendors, "</ul>\n");
1.4       veillard  752:     generateHtmlFooter(Vendors);
1.2       veillard  753:     fclose(Vendors);
                    754: }
                    755: 
                    756: /*
                    757:  * Dump the RPM by Date HTML file.
                    758:  * One expect that the RPM files have been sorted by date.
                    759:  */
1.13      veillard  760: void dumpRpmByDate(int installed) {
1.2       veillard  761:     FILE *ByDate;
1.13      veillard  762:     rpmDataPtr cur;
1.2       veillard  763:     time_t current_time = time(NULL);
                    764: 
1.13      veillard  765:     if (installed) cur = rpmInstalledList;
                    766:     else cur = rpmList;
                    767: 
1.2       veillard  768: #ifdef DEBUG
1.14      veillard  769:     printf("Dumping %s/%s\n", rpm2html_dir, localizedStrings[LANG_BYDATE_HTML]);
1.2       veillard  770: #endif
1.14      veillard  771:     sprintf(buf, "%s/%s", rpm2html_dir, localizedStrings[LANG_BYDATE_HTML]);
1.2       veillard  772: 
                    773:     ByDate = fopen(buf, "w");
                    774:     if (ByDate == NULL) {
                    775:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    776:                buf, strerror(errno));
                    777:         return;
                    778:     }
1.14      veillard  779:     if (installed) {
                    780:        generateHtmlHeader(ByDate, localizedStrings[LANG_SORTED_BY_IDATE], NULL);
                    781:        fprintf(ByDate, "<h1 align=center>%s</h1>\n",
                    782:            localizedStrings[LANG_SORTED_BY_IDATE]);
                    783:     } else {
                    784:        generateHtmlHeader(ByDate, localizedStrings[LANG_SORTED_BY_CDATE], NULL);
                    785:        fprintf(ByDate, "<h1 align=center>%s</h1>\n",
                    786:            localizedStrings[LANG_SORTED_BY_CDATE]);
                    787:     }
1.2       veillard  788: 
                    789:     /*
                    790:      * First dump RPMs less than 3 days old.
                    791:      */
1.15      veillard  792:     if (!installed) generateColorIndicator(ByDate);
1.14      veillard  793:     if (installed)
                    794:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_I_LESS_3D_OLD]);
                    795:     else
                    796:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_LESS_3D_OLD]);
1.15      veillard  797:     fprintf(ByDate, "<table><body>\n");
1.2       veillard  798:     while ((cur != NULL) && ((current_time - cur->date) < (3 * 24 * 60 * 60))) {
1.15      veillard  799:        generateHtmlRpmRow(ByDate, cur);
1.2       veillard  800:        cur = cur->next;
                    801:     }
1.15      veillard  802:     fprintf(ByDate, "</body></table>\n");
1.2       veillard  803: 
                    804:     /*
                    805:      * Then dump RPMs less than one week old.
                    806:      */
1.14      veillard  807:     if (installed)
                    808:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_I_LESS_1W_OLD]);
                    809:     else
                    810:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_LESS_1W_OLD]);
1.15      veillard  811:     fprintf(ByDate, "<table><body>\n");
1.2       veillard  812:     while ((cur != NULL) && ((current_time - cur->date) < (7 * 24 * 60 * 60))) {
1.15      veillard  813:        generateHtmlRpmRow(ByDate, cur);
1.2       veillard  814:        cur = cur->next;
                    815:     }
1.15      veillard  816:     fprintf(ByDate, "</body></table>\n");
1.2       veillard  817: 
                    818:     /*
                    819:      * Then dump RPMs less than two weeks old.
                    820:      */
1.14      veillard  821:     if (installed)
                    822:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_I_LESS_2W_OLD]);
                    823:     else
                    824:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_LESS_2W_OLD]);
1.15      veillard  825:     fprintf(ByDate, "<table><body>\n");
1.2       veillard  826:     while ((cur != NULL) && ((current_time - cur->date) < (14 * 24 * 60 * 60))) {
1.15      veillard  827:        generateHtmlRpmRow(ByDate, cur);
1.2       veillard  828:        cur = cur->next;
                    829:     }
1.15      veillard  830:     fprintf(ByDate, "</body></table>\n");
1.2       veillard  831: 
                    832:     /*
                    833:      * Then dump RPMs less than one month old.
                    834:      */
1.14      veillard  835:     if (installed)
                    836:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_I_LESS_1M_OLD]);
                    837:     else
                    838:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_LESS_1M_OLD]);
1.15      veillard  839:     fprintf(ByDate, "<table><body>\n");
1.2       veillard  840:     while ((cur != NULL) && ((current_time - cur->date) < (30 * 24 * 60 * 60))) {
1.15      veillard  841:        generateHtmlRpmRow(ByDate, cur);
1.2       veillard  842:        cur = cur->next;
                    843:     }
1.15      veillard  844:     fprintf(ByDate, "</body></table>\n");
1.2       veillard  845: 
                    846:     /*
                    847:      * Then dump RPMs more than one month old.
                    848:      */
1.14      veillard  849:     if (installed)
                    850:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_I_MORE_1M_OLD]);
                    851:     else
                    852:        fprintf(ByDate, "<h2>%s</h2>\n", localizedStrings[LANG_MORE_1M_OLD]);
1.15      veillard  853:     fprintf(ByDate, "<table><body>\n");
1.2       veillard  854:     while (cur != NULL) {
1.15      veillard  855:        generateHtmlRpmRow(ByDate, cur);
1.2       veillard  856:        cur = cur->next;
                    857:     }
1.15      veillard  858:     fprintf(ByDate, "</body></table>\n");
1.2       veillard  859: 
1.4       veillard  860:     generateHtmlFooter(ByDate);
1.2       veillard  861:     fclose(ByDate);
1.9       veillard  862: }
                    863: 
                    864: /*
                    865:  * Dump the RPM by Name HTML file.
                    866:  * One expect that the RPM files have been sorted by name.
                    867:  */
1.13      veillard  868: void dumpRpmByName(int installed) {
1.9       veillard  869:     FILE *ByName;
1.13      veillard  870:     rpmDataPtr cur;
                    871: 
                    872:     if (installed) cur = rpmInstalledList;
                    873:     else cur = rpmList;
1.9       veillard  874: 
                    875: #ifdef DEBUG
1.14      veillard  876:     printf("Dumping %s/%s\n", rpm2html_dir, localizedStrings[LANG_BYNAME_HTML]);
1.9       veillard  877: #endif
1.14      veillard  878:     sprintf(buf, "%s/%s", rpm2html_dir, localizedStrings[LANG_BYNAME_HTML]);
1.9       veillard  879: 
                    880:     ByName = fopen(buf, "w");
                    881:     if (ByName == NULL) {
                    882:         fprintf(stderr, "Couldn't save to file %s: %s\n",
                    883:                buf, strerror(errno));
                    884:         return;
                    885:     }
1.14      veillard  886:     generateHtmlHeader(ByName, localizedStrings[LANG_SORTED_BY_NAME], NULL);
                    887:     fprintf(ByName, "<h1 align=center>%s</h1>\n",
                    888:         localizedStrings[LANG_SORTED_BY_NAME]);
1.9       veillard  889: 
1.15      veillard  890:     if (!installed) generateColorIndicator(ByName);
                    891:     fprintf(ByName, "<table><body>\n");
1.9       veillard  892:     while (cur != NULL) {
1.15      veillard  893:        generateHtmlRpmRow(ByName, cur);
1.9       veillard  894:        cur = cur->next;
                    895:     }
1.15      veillard  896:     fprintf(ByName, "</body></table>\n");
1.9       veillard  897: 
                    898:     generateHtmlFooter(ByName);
                    899:     fclose(ByName);
1.1       veillard  900: }

Webmaster