#include "dir.gif.h"
void dumpDirIcon(void) {
char path[500];
char *content;
int fd;
/* struct stat *buf; !!!!!! */
if (!rpm2html_dump_html) return;
createDirectory(rpm2html_dir);
sprintf(path, "%s/dir.gif", rpm2html_dir);
content = read_data_buffer();
if ((fd = creat(path, 0644)) < 0) {
fprintf(stderr, "creat() failed on %s\n", path);
return;
}
write(fd, content, data_buffer_size);
close(fd);
}
/*
* checkDate : check whether the last modification time of a file
* is anterior to a given time
*/
int checkDate(const char *filename, time_t stamp) {
struct stat buf;
if (force) return(0);
if ((stat(filename, &buf)) != 0) {
return(0);
}
return(buf.st_mtime > stamp);
}
/*
* Transformation function from rpm to filename.
*/
char *rpmName(rpmDataPtr cur) {
static char rbuf[500];
if (cur->arch != NULL)
sprintf(rbuf, "%s-%s-%s.%s",
cur->name, cur->version, cur->release, cur->arch);
else
sprintf(rbuf, "%s-%s-%s",
cur->name, cur->version, cur->release);
return(rbuf);
}
/*
* Transformation function from rpm to Software name.
*/
char *rpmSoftwareName(rpmDataPtr cur) {
static char rbuf[500];
sprintf(rbuf, "%s-%s-%s",
cur->name, cur->version, cur->release);
return(rbuf);
}
/*
* Transformation function from group to filename.
*/
char *groupName(char *group) {
static char gbuf[500];
char *cur = gbuf;
while (*group != '\0') {
if ((*group == '/') || (*group == ' ')) {
*cur++ = '_';
group ++;
} else *cur++ = *group++;
}
strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
return(gbuf);
}
/*
* Transformation function from group to filename.
*/
char *distribName(char *distrib) {
static char dbuf[500];
char *cur = dbuf;
while (*distrib != '\0') {
if ((*distrib == '/') || (*distrib == ' ')) {
*cur++ = '_';
distrib ++;
} else *cur++ = *distrib++;
}
strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
return(dbuf);
}
/*
* Generate a full directory path.
*/
void fullPathName(char *buf, rpmDirPtr dir, char *subdir, char *filename) {
if (dir == NULL) {
sprintf(buf, "%s/%s", rpm2html_dir, filename);
} else {
if (subdir == NULL)
sprintf(buf, "%s/%s", dir->dir, filename);
else
sprintf(buf, "%s/%s/%s", dir->dir, subdir, filename);
}
}
/*
* Generate a full directory path plus ditinguish with a letter.
*/
void fullPathNameLr(char *buf, rpmDirPtr dir, char *subdir,
char *filename, char letter) {
if (dir == NULL) {
sprintf(buf, "%s/%c%s", rpm2html_dir, letter, filename);
} else {
if (subdir == NULL)
sprintf(buf, "%s/%c%s", dir->dir, letter, filename);
else
sprintf(buf, "%s/%s/%c%s", dir->dir, subdir, letter, filename);
}
}
/*
* Generate a full directory path plus ditinguish with a number.
*/
void fullPathNameNr(char *buf, rpmDirPtr dir, char *subdir,
char *filename, int number) {
if (dir == NULL) {
sprintf(buf, "%s/%d%s", rpm2html_dir, number, filename);
} else {
if (subdir == NULL)
sprintf(buf, "%s/%d%s", dir->dir, number, filename);
else
sprintf(buf, "%s/%s/%d%s", dir->dir, subdir, number, filename);
}
}
/*
* Transformation function from vendor to filename.
*/
char *vendorName(char *vendor) {
static char vbuf[500];
char *cur = vbuf;
while (*vendor != '\0') {
if ((*vendor == '/') || (*vendor == ' ')) {
*cur++ = '_';
vendor ++;
} else *cur++ = *vendor++;
}
strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
return(vbuf);
}
/*
* Transformation function from resource to filename.
*/
char *resourceName(char *resource) {
static char rbuf[500];
char *cur = rbuf;
while (*resource != '\0') {
if ((*resource == '/') || (*resource == ' ')) {
*cur++ = '_';
resource ++;
} else *cur++ = *resource++;
}
strcpy(cur, localizedStrings[LANG_HTML_SUFFIX]);
return(rbuf);
}
/*
* Generate an HTML header
*/
void generateHtmlHeader(FILE *html, char *title, char *color) {
fprintf(html, "\n");
fprintf(html, "\n\n%s\n", title);
fprintf(html, "\n",
rpm2html_rpm2html_name, rpm2html_rpm2html_ver);
if (color == NULL)
fprintf(html, "\n\n");
else
fprintf(html, "\n\n", color);
}
/*
* Generate an HTML footer
*/
void generateHtmlFooter(FILE *html) {
struct tm * tstruct;
time_t current_time;
current_time = time(NULL);
tstruct = localtime(¤t_time);
fprintf(html, "
\n");
fprintf(html, "%s %s %s\n",
localizedStrings[LANG_GENERATED],
rpm2html_rpm2html_url, rpm2html_rpm2html_name,
rpm2html_rpm2html_ver);
fprintf(html, "
%s, %s\n",
rpm2html_mail, rpm2html_maint, asctime(tstruct));
fprintf(html, "\n\n");
}
/*
* Generate a the opening anchor tag for a package
*/
void generateHtmlRpmAnchor(FILE *html, rpmDataPtr cur) {
if ((cur->dir->subdir != NULL) && (cur->dir->subdir[0] != '\0')) {
/*
* More than one mirror, there is an HTML subdir
*/
if ((cur->subdir != NULL) && (cur->subdir[0] != '\0')) {
if (cur->dir->url)
fprintf(html, "",
cur->dir->url, cur->dir->subdir,
cur->subdir, rpmName(cur));
else
fprintf(html, "",
cur->subdir, cur->dir->subdir, rpmName(cur));
} else {
if (cur->dir->url)
fprintf(html, "",
cur->dir->url, cur->dir->subdir, rpmName(cur));
else
fprintf(html, "",
cur->dir->subdir, rpmName(cur));
}
} else {
/*
* Only one mirror, no HTML subdir
*/
if ((cur->subdir != NULL) && (cur->subdir[0] != '\0')) {
if (cur->dir->url)
fprintf(html, "",
cur->dir->url, cur->subdir, rpmName(cur));
else
fprintf(html, "",
cur->subdir, rpmName(cur));
} else {
if (cur->dir->url)
fprintf(html, "",
cur->dir->url, rpmName(cur));
else
fprintf(html, "",
rpmName(cur));
}
}
}
/*
* Generate a line in a table for a RPM.
*/
void generateHtmlRpmRow(FILE *html, rpmDataPtr cur) {
static char buf[500];
struct tm * tstruct;
tstruct = localtime(&(cur->date));
#ifdef HAVE_STRFTIME
strftime(buf, sizeof(buf) - 1, "%c", tstruct);
#else
#error "no strftime, please check !"
#endif
fprintf(html, "",
cur->dir->color, PACKAGE_FIELD_WIDTH);
generateHtmlRpmAnchor(html, cur);
fprintf(html, "%s | \n", rpmName(cur));
fprintf(html, "%s | \n",
cur->dir->color, DESCRIPTION_FIELD_WIDTH,
convertHTML(cur->summary));
fprintf(html, "%s |
\n", buf);
}
/*
* Generate a line in a table for an RPM software and all it's architectures.
*/
void generateHtmlRpmArchRow(FILE *html, rpmDataPtr cur) {
rpmDataPtr tmp;
fprintf(html, "", PACKAGE_FIELD_WIDTH);
fprintf(html, "%s | \n", rpmSoftwareName(cur));
fprintf(html, "%s | \n",
DESCRIPTION_FIELD_WIDTH, convertHTML(cur->summary));
/* dump the archs list */
tmp = cur;
while (tmp != NULL) {
fprintf(html, "",
tmp->dir->color, SYSTEM_FIELD_WIDTH);
generateHtmlRpmAnchor(html, tmp);
fprintf(html, "%s/%s", tmp->os, tmp->arch);
fprintf(html, " | ");
tmp = tmp->nextArch;
}
fprintf(html, "\n
\n");
}
/*
* Generate the Links for the main pages
*/
void generateLinks(FILE *html, int installed) {
int i;
fprintf(html, "
\n");
fprintf(html, "\n\n");
fprintf(html, "%s | \n",
rpm2html_url, localizedStrings[LANG_INDEX_HTML],
localizedStrings[LANG_INDEX]);
fprintf(html, "%s | \n",
rpm2html_url, localizedStrings[LANG_GROUP_HTML],
localizedStrings[LANG_SORTED_BY_GROUP]);
fprintf(html, "%s | \n",
rpm2html_url, localizedStrings[LANG_DISTRIB_HTML],
localizedStrings[LANG_SORTED_BY_DISTRIB]);
fprintf(html, "%s | \n",
rpm2html_url, localizedStrings[LANG_VENDOR_HTML],
localizedStrings[LANG_SORTED_BY_VENDOR]);
if (installed)
fprintf(html, "%s | \n",
rpm2html_url, localizedStrings[LANG_BYDATE_HTML],
localizedStrings[LANG_SORTED_BY_IDATE]);
else
fprintf(html, "%s | \n",
rpm2html_url, localizedStrings[LANG_BYDATE_HTML],
localizedStrings[LANG_SORTED_BY_CDATE]);
fprintf(html, "%s | \n",
rpm2html_url, localizedStrings[LANG_BYNAME_HTML],
localizedStrings[LANG_SORTED_BY_NAME]);
for (i = 0;i < rpm2html_nb_extra_headers;i++) {
if ((*rpm2html_headers_url[i] == '/') ||
(!strncmp(rpm2html_headers_url[i], "http://", 7)) ||
(!strncmp(rpm2html_headers_url[i], "ftp://", 6)) ||
(!strncmp(rpm2html_headers_url[i], "mailto", 6)))
fprintf(html, "%s | \n",
rpm2html_headers_url[i], rpm2html_headers_name[i]);
else
fprintf(html, "%s | \n",
rpm2html_url, rpm2html_headers_url[i],
rpm2html_headers_name[i]);
}
fprintf(html, "
\n
\n");
}
/*
* Generate a color indicator
*/
void generateColorIndicator(FILE *html) {
int nb = 0;
rpmDirPtr dir = dirList;
fprintf(html, "\n\n");
while (dir != NULL) {
if (strcasecmp(dir->color, "#ffffff")) {
if ((nb > 0) && ((nb % MAX_COLOR_PER_LINE) == 0))
fprintf(html, "
\n");
fprintf(html, "", dir->color);
if (dir->name != NULL)
fprintf(html, "%s | ", dir->name);
else if (dir->mirrors[0] != NULL)
fprintf(html, "%s", dir->mirrors[0]);
else
fprintf(html, "%s", dir->ftp);
nb++;
}
dir = dir->next;
}
fprintf(html, "
\n
\n");
}
/*
* Dump a subtree in an HTML page with all the links
*/
void generateHtmlTree(FILE *html, rpmSubdirPtr tree, int level, int full) {
int i;
if ((tree->nb_subdirs > 0) || (tree->parent != NULL)) {
if (level == 0)
fprintf(html, "%s
\n", localizedStrings[LANG_SUBDIRS]);
if (tree->color)
fprintf(html, "\n",
tree->color);
else
fprintf(html, "\n");
if ((level == 0) && (tree->parent != NULL)) {
if (tree->parent->htmlpath[0] != '\0') {
fprintf(html, "",
rpm2html_url, tree->parent->htmlpath);
} else {
fprintf(html, "", rpm2html_url);
}
fprintf(html,
"",
rpm2html_url);
fprintf(html, " ..
\n");
}
for (i = 0;i < tree->nb_subdirs;i++) {
fprintf(html, "",
rpm2html_url, tree->subdirs[i]->htmlpath);
fprintf(html,
"",
rpm2html_url);
fprintf(html, " %s
\n", tree->subdirs[i]->name);
if (full)
generateHtmlTree(html, tree->subdirs[i], level + 1, full);
}
fprintf(html, "
\n");
}
}
/*
* Dump the parent names in an HTML page with all the links
*/
void generateHtmlParentsNames(FILE *html, rpmSubdirPtr tree) {
int i, j, k;
rpmSubdirPtr parent;
if (tree->parent == NULL) return;
/*
* get the tree depth.
*/
i = 0;
parent = tree->parent;
while ((parent != NULL) && (parent->parent != NULL)) {
i++;
parent = parent->parent;
}
/*
* Dump each level in the parent tree.
*/
for (j = i; j >= 0;j--) {
parent = tree;
for (k = 0;k < j;k++) parent = parent->parent;
if (parent->htmlpath[0] != '\0') {
fprintf(html, "",
rpm2html_url, parent->htmlpath);
} else {
fprintf(html, "", rpm2html_url);
}
fprintf(html, "%s\n", parent->name);
if (j != 0) fprintf(html, " / ");
}
}
/*
* Dump the whole index for a full complete config file.
*/
void dumpIndex(time_t start_time, int installed) {
int i;
FILE *html;
rpmDirPtr cur = dirList;
if (!rpm2html_dump_html) return;
if (verbose > 1) {
printf("Dumping %s/%s\n", rpm2html_dir, localizedStrings[LANG_INDEX_HTML]);
}
sprintf(buf, "%s/%s", rpm2html_dir, localizedStrings[LANG_INDEX_HTML]);
html = fopen(buf, "w");
if (html == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
if (installed) {
sprintf(buf, "%s %s", localizedStrings[LANG_WELCOME_INSTALL],
rpm2html_host);
generateHtmlHeader(html, buf, NULL);
generateLinks(html, installed);
fprintf(html, "%s %s
\n",
localizedStrings[LANG_WELCOME_INSTALL], rpm2html_host);
} else {
sprintf(buf, "%s %s", localizedStrings[LANG_WELCOME_REPOSITORY],
rpm2html_host);
generateHtmlHeader(html, buf, NULL);
generateLinks(html, installed);
fprintf(html, "%s %s
\n",
localizedStrings[LANG_WELCOME_REPOSITORY], rpm2html_host);
}
fprintf(html, "%s\n", localizedStrings[LANG_RPM2HTML_INTRO]);
if (rpm2html_install_files != 0) {
fprintf(html, "");
fprintf(html, localizedStrings[LANG_INSTALLED_STATS],
rpm2html_install_files, rpm2html_install_size / 1024);
fprintf(html, "
\n");
}
if (rpm2html_files != 0) {
fprintf(html, "");
fprintf(html, localizedStrings[LANG_STATS],
rpm2html_files, rpm2html_size / 1024);
fprintf(html, "
\n");
}
fprintf(html, "\n");
fprintf(html, "- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_GROUP_HTML],
localizedStrings[LANG_INDEX_GROUP]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_BYDATE_HTML],
localizedStrings[LANG_INDEX_CREATION]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_BYNAME_HTML],
localizedStrings[LANG_INDEX_NAME]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_VENDOR_HTML],
localizedStrings[LANG_INDEX_VENDOR]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_DISTRIB_HTML],
localizedStrings[LANG_INDEX_DISTRIB]);
fprintf(html, "
\n");
generateHtmlTree(html, dirTree, 0, 0);
while (cur != NULL) {
fprintf(html, "\n\n",
cur->color);
if (cur->name == NULL)
fprintf(html, "%s | \n",
cur->color, cur->ftp, cur->ftp);
else
fprintf(html, "%s | \n",
cur->color, cur->ftp, cur->name);
fprintf(html, "
\n");
if ((cur->ftpsrc != NULL) && (strcmp(cur->ftp, cur->ftpsrc)))
fprintf(html,
"%s: | %s |
\n",
cur->color, localizedStrings[LANG_SOURCES_REPOSITORY],
cur->color, cur->ftpsrc, cur->ftpsrc);
if (cur->nb_mirrors > 0)
fprintf(html,
"%s: | %s |
\n",
cur->color, localizedStrings[LANG_LOCAL_MIRROR],
cur->color, cur->mirrors[0], cur->mirrors[0]);
if (cur->nb_mirrors > 1) {
fprintf(html, "%s |
\n",
cur->color, localizedStrings[LANG_MIRRORS]);
for (i = 1;i < cur->nb_mirrors;i++) {
fprintf(html,
"%s |
\n",
cur->color, cur->mirrors[i], cur->mirrors[i]);
}
}
fprintf(html, "
\n");
cur = cur->next;
if (cur != NULL) fprintf(html, "\n");
}
fprintf(html, "%s %d %s
\n",
localizedStrings[LANG_GENERATION_TIME],
(int) (time(NULL) - start_time),
localizedStrings[LANG_SECONDS]);
generateHtmlFooter(html);
fclose(html);
}
/*
* Dump an RPM block as an HTML file.
*/
void dumpRpmHtml(rpmDataPtr rpm, rpmSubdirPtr tree) {
struct tm * tstruct;
rpmDirPtr dir = rpm->dir;
int installed = dir->installbase;
FILE *html;
int i;
if (!rpm2html_dump_html) return;
if ((dir->subdir != NULL) && (dir->subdir[0] != '\0')) {
if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0'))
sprintf(buf, "%s/%s/%s/%s.html", dir->dir, dir->subdir,
rpm->subdir, rpmName(rpm));
else
sprintf(buf, "%s/%s/%s.html", dir->dir, dir->subdir, rpmName(rpm));
} else {
if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0'))
sprintf(buf, "%s/%s/%s.html", dir->dir, rpm->subdir, rpmName(rpm));
else
sprintf(buf, "%s/%s.html", dir->dir, rpmName(rpm));
}
if (checkDate(buf, rpm->stamp)) return;
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
html = fopen(buf, "w");
if (html == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s RPM", rpmName(rpm));
generateHtmlHeader(html, buf, NULL);
generateLinks(html, installed);
if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0')) {
if (dir->mirrors[0] != NULL)
fprintf(html, "", dir->color);
fprintf(html, "\n");
fprintf(html, "%s: %s | \n",
localizedStrings[LANG_NAME],
rpm->name);
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_DISTRIBUTION], rpm2html_url,
distribName(rpm->distribution), convertHTML(rpm->distribution));
fprintf(html, "%s: %s | \n",
localizedStrings[LANG_VERSION],
rpm->version);
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_VENDOR], rpm2html_url,
vendorName(rpm->vendor), convertHTML(rpm->vendor));
tstruct = localtime(&(rpm->date));
#ifdef HAVE_STRFTIME
strftime(buf, sizeof(buf) - 1, "%c", tstruct);
#else
#error "no strftime, please check !"
#endif
if (installed) {
fprintf(html, "%s: %s | \n%s: %s |
\n",
localizedStrings[LANG_RELEASE],
rpm->release,
localizedStrings[LANG_INSTALL_DATE],
buf);
} else {
fprintf(html, "%s: %s | \n%s: %s |
\n",
localizedStrings[LANG_RELEASE],
rpm->release,
localizedStrings[LANG_BUILD_DATE],
buf);
}
if (rpm2html_url != NULL)
fprintf(html, "%s: %s | \n",
localizedStrings[LANG_GROUP], rpm2html_url,
groupName(rpm->group), convertHTML(rpm->group));
else
fprintf(html, "
%s: %s | \n",
localizedStrings[LANG_GROUP],
groupName(rpm->group), convertHTML(rpm->group));
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_BUILD_HOST], rpm->host);
fprintf(html, "%s: %d | \n",
localizedStrings[LANG_SIZE],
rpm->size);
if (dir->ftpsrc) {
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_RPM_SRC],
dir->ftpsrc, rpm->srcrpm, rpm->srcrpm);
} else {
fprintf(html, "%s: %s | \n",
localizedStrings[LANG_RPM_SRC],
rpm->srcrpm);
}
if (rpm->packager) {
char *email = extractEMail(rpm->packager);
if (email == NULL)
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_PACKAGER],
convertHTML(rpm->packager));
else
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_PACKAGER],
email, convertHTML(rpm->packager));
}
if (rpm->url)
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_URL],
rpm->url, rpm->url);
fprintf(html, "%s: %s |
\n",
localizedStrings[LANG_SUMMARY],
convertHTML(rpm->summary));
fprintf(html, "\n
\n");
fprintf(html, "%s\n
\n", convertHTML(rpm->description));
if ((rpm->nb_resources + rpm->nb_requires < 2) &&
(!strstr(rpm->name, "lib"))) {
if (verbose > 1)
fprintf(stderr, "Resource lists problem : %s\n", rpmName(rpm));
fprintf(html, "%s
\n",
localizedStrings[LANG_WARNING_RESOURCES]);
fprintf(html, "%s
\n",
rpm2html_url, resourceName(rpm->name),
localizedStrings[LANG_CHOOSE_ANOTHER]);
}
if (rpm->nb_resources > 0) {
fprintf(html, "%s
\n",
localizedStrings[LANG_PROVIDE]);
fprintf(html, "\n");
for (i = 0;i < rpm->nb_resources;i++) {
if (rpm2html_url != NULL)
fprintf(html, "- %s\n",
rpm2html_url, resourceName(rpm->resources[i]->name),
rpm->resources[i]->name);
else
fprintf(html, "
- %s\n",
resourceName(rpm->resources[i]->name),
rpm->resources[i]->name);
}
if (i >= MAX_RES)
fprintf(html, "
- %s\n", localizedStrings[LANG_MORE]);
fprintf(html, "
\n");
}
if (rpm->nb_requires > 0) {
fprintf(html, "%s
\n",
localizedStrings[LANG_REQUIRE]);
fprintf(html, "\n");
for (i = 0;i < rpm->nb_requires;i++) {
if (rpm2html_url != NULL)
fprintf(html, "- %s\n",
rpm2html_url, resourceName(rpm->requires[i]->name),
rpm->requires[i]->name);
else
fprintf(html, "
- %s\n",
resourceName(rpm->requires[i]->name),
rpm->requires[i]->name);
}
if (i >= MAX_REQU)
fprintf(html, "
- ...\n");
fprintf(html, "
\n");
}
if (rpm->copyright) {
fprintf(html, "%s
\n",
localizedStrings[LANG_COPYRIGHT]);
fprintf(html, "%s\n
\n", convertHTML(rpm->copyright));
}
if (rpm->changelog) {
fprintf(html, "%s
\n",
localizedStrings[LANG_CHANGELOG]);
fprintf(html, "%s\n
\n", convertHTML(rpm->changelog));
}
fprintf(html, "%s
\n",
localizedStrings[LANG_FILES]);
if (rpm->filelist == NULL)
fprintf(html, "%s\n",
localizedStrings[LANG_NO_FILES]);
else
fprintf(html, "%s\n
\n", rpm->filelist);
generateHtmlFooter(html);
fclose(html);
}
/*
* Dump a resource block as an HTML file.
*/
void dumpRessHtml(rpmRessPtr ress, int installed) {
rpmDataPtr rpm;
FILE *html;
int i;
if (!rpm2html_dump_html) return;
sprintf(buf, "%s/%s", rpm2html_dir,
resourceName(ress->name));
if (checkDate(buf, ress->stamp)) return;
if (verbose > 1) {
printf("Dumping %s/%s\n", rpm2html_dir,
resourceName(ress->name));
}
html = fopen(buf, "w");
if (html == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s %s",
localizedStrings[LANG_RPM_RESOURCE], ress->name);
generateHtmlHeader(html, buf, NULL);
generateLinks(html, installed);
generateColorIndicator(html);
fprintf(html, "%s %s
\n",
localizedStrings[LANG_RPM_RESOURCE], ress->name);
fprintf(html, "%s
\n",
localizedStrings[LANG_PROVIDED_BY]);
fprintf(html, "\n");
for (i = 0;i < ress->nb_provider;i++) {
rpm = ress->provider[i];
generateHtmlRpmRow(html, rpm);
}
fprintf(html, "
\n");
generateHtmlFooter(html);
fclose(html);
}
/*
* Dump all RPM blocks in the HTML files.
*/
void dumpAllRessHtml(int installed) {
rpmRessPtr cur;
if (!rpm2html_dump_html) return;
if (installed) cur = ressInstalledList;
else cur = ressList;
while (cur != NULL) {
dumpRessHtml(cur, installed);
cur = cur->next;
}
}
/*
* Dump the Groups of all HTML files.
* One expect that the RPM files have been sorted by group.
*/
void dumpDirRpmByGroups(rpmDataPtr list, rpmDirPtr dir,
char *subdir, int installed) {
FILE *Groups;
FILE *currentGroup = NULL;
rpmDataPtr cur, prev = NULL;
int count = 0;
int pcount = 0;
if (!rpm2html_dump_html) return;
cur = list;
fullPathName(buf, dir, subdir, localizedStrings[LANG_GROUP_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
Groups = fopen(buf, "w");
if (Groups == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
generateHtmlHeader(Groups, localizedStrings[LANG_SORTED_BY_GROUP], NULL);
generateLinks(Groups, installed);
fprintf(Groups, "%s
\n",
localizedStrings[LANG_SORTED_BY_GROUP]);
fprintf(Groups, "\n");
while (cur != NULL) {
if ((cur->group != NULL) && (strlen(cur->group) > 0)) {
if ((prev == NULL) || (strcasecmp(prev->group, cur->group))) {
if (pcount != 0)
fprintf(Groups, " (%d)\n", pcount);
pcount = 0;
if (currentGroup != NULL) {
/* one need to close the current group list */
fprintf(currentGroup,"\n");
generateHtmlFooter(currentGroup);
fclose(currentGroup);
}
/* Add the current group in the Group list */
fprintf(Groups, "- %s",
groupName(cur->group), convertHTML(cur->group));
/* open the new HTML group file */
fullPathName(buf, dir, subdir, groupName(cur->group));
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
currentGroup = fopen(buf, "w");
if (currentGroup == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s %s", localizedStrings[LANG_OF_GROUP],
convertHTML(cur->group));
generateHtmlHeader(currentGroup, buf, NULL);
generateLinks(currentGroup, installed);
fprintf(currentGroup,
"
%s %s
\n",
localizedStrings[LANG_OF_GROUP], convertHTML(cur->group));
generateColorIndicator(currentGroup);
fprintf(currentGroup,"\n");
count = 0;
}
generateHtmlRpmArchRow(currentGroup, cur);
count++;
pcount++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(currentGroup, "
\n\n");
}
prev = cur;
if ((dir == NULL) && (subdir == NULL))
cur = cur->nextSoft;
else
cur = cur->next;
}
/*
* finish the last group line.
*/
if (pcount != 0)
fprintf(Groups, " (%d)\n", pcount);
if (currentGroup != NULL) {
/* one need to close the current group list */
fprintf(currentGroup,"
\n");
generateHtmlFooter(currentGroup);
fclose(currentGroup);
}
fprintf(Groups, "
\n");
generateHtmlFooter(Groups);
fclose(Groups);
}
/*
* Dump the full set of RPM by Group HTML file.
* One expect that the RPM files have been sorted by groups.
*/
void dumpRpmByGroups(rpmDataPtr list, int installed) {
if (!rpm2html_dump_html) return;
dumpDirRpmByGroups(list, NULL, NULL, installed);
}
/*
* Dump the Distribs HTML files.
* One expect that the RPM files have been sorted by distribution.
*/
void dumpDirRpmByDistribs(rpmDataPtr list, rpmDirPtr dir,
char *subdir, int installed) {
FILE *Distribs;
FILE *currentDistrib = NULL;
rpmDataPtr cur, prev = NULL;
int count = 0;
int pcount = 0;
if (!rpm2html_dump_html) return;
cur = list;
fullPathName(buf, dir, subdir, localizedStrings[LANG_DISTRIB_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
Distribs = fopen(buf, "w");
if (Distribs == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
generateHtmlHeader(Distribs,
localizedStrings[LANG_SORTED_BY_DISTRIB], NULL);
generateLinks(Distribs, installed);
fprintf(Distribs, "%s
\n",
localizedStrings[LANG_SORTED_BY_DISTRIB]);
fprintf(Distribs, "\n");
while (cur != NULL) {
if ((cur->distribution != NULL) && (strlen(cur->distribution) > 0)) {
if ((prev == NULL) || (strcasecmp(prev->distribution, cur->distribution))) {
if (pcount != 0)
fprintf(Distribs, " (%d)\n", pcount);
pcount = 0;
if (currentDistrib != NULL) {
/* one need to close the current distribution list */
fprintf(currentDistrib,"\n");
generateHtmlFooter(currentDistrib);
fclose(currentDistrib);
}
/* Add the current distribution in the Distrib list */
fprintf(Distribs, "- %s",
distribName(cur->distribution),
convertHTML(cur->distribution));
/* open the new HTML distribution file */
fullPathName(buf, dir, subdir, distribName(cur->distribution));
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
currentDistrib = fopen(buf, "w");
if (currentDistrib == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s %s",
localizedStrings[LANG_OF_DISTRIB],
convertHTML(cur->distribution));
generateHtmlHeader(currentDistrib, buf, NULL);
generateLinks(currentDistrib, installed);
fprintf(currentDistrib,
"
%s %s
\n",
localizedStrings[LANG_OF_DISTRIB],
convertHTML(cur->distribution));
if (!installed) generateColorIndicator(currentDistrib);
fprintf(currentDistrib,"\n");
count = 0;
}
generateHtmlRpmRow(currentDistrib, cur);
count++;
pcount++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(currentDistrib, "
\n\n");
}
prev = cur;
cur = cur->next;
}
/*
* finish the last group line.
*/
if (pcount != 0)
fprintf(Distribs, " (%d)\n", pcount);
if (currentDistrib != NULL) {
/* one need to close the current distribution list */
fprintf(currentDistrib,"
\n");
generateHtmlFooter(currentDistrib);
fclose(currentDistrib);
}
fprintf(Distribs, "
\n");
generateHtmlFooter(Distribs);
fclose(Distribs);
}
/*
* Dump the full set of RPM by Distribution HTML file.
* One expect that the RPM files have been sorted by distributions.
*/
void dumpRpmByDistribs(rpmDataPtr list, int installed) {
if (!rpm2html_dump_html) return;
dumpDirRpmByDistribs(list, NULL, NULL, installed);
}
/*
* Dump the Vendors HTML files.
* One expect that the RPM files have been sorted by vendors.
*/
void dumpDirRpmByVendors(rpmDataPtr list, rpmDirPtr dir,
char *subdir, int installed) {
FILE *Vendors;
FILE *currentVendor = NULL;
rpmDataPtr cur, prev = NULL;
int count = 0;
int pcount = 0;
if (!rpm2html_dump_html) return;
cur = list;
fullPathName(buf, dir, subdir, localizedStrings[LANG_VENDOR_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
Vendors = fopen(buf, "w");
if (Vendors == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
generateHtmlHeader(Vendors, localizedStrings[LANG_SORTED_BY_VENDOR], NULL);
generateLinks(Vendors, installed);
fprintf(Vendors, "%s
\n",
localizedStrings[LANG_SORTED_BY_VENDOR]);
fprintf(Vendors, "\n");
while (cur != NULL) {
if ((cur->vendor != NULL) && (strlen(cur->vendor) > 0)) {
if ((prev == NULL) || (strcasecmp(prev->vendor, cur->vendor))) {
if (pcount != 0)
fprintf(Vendors, " (%d)\n", pcount);
pcount = 0;
if (currentVendor != NULL) {
/* one need to close the current vendor list */
fprintf(currentVendor,"\n");
generateHtmlFooter(currentVendor);
fclose(currentVendor);
}
/* Add the current vendor in the Vendor list */
fprintf(Vendors, "- %s",
vendorName(cur->vendor), convertHTML(cur->vendor));
/* open the new HTML vendor file */
fullPathName(buf, dir, subdir, vendorName(cur->vendor));
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
currentVendor = fopen(buf, "w");
if (currentVendor == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s %s", localizedStrings[LANG_OF_VENDOR],
convertHTML(cur->vendor));
generateHtmlHeader(currentVendor, buf, NULL);
generateLinks(currentVendor, installed);
fprintf(currentVendor,
"
%s %s
\n",
localizedStrings[LANG_OF_VENDOR], convertHTML(cur->vendor));
if (!installed) generateColorIndicator(currentVendor);
fprintf(currentVendor,"\n");
count = 0;
}
generateHtmlRpmRow(currentVendor, cur);
count++;
pcount++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(currentVendor, "
\n\n");
}
prev = cur;
cur = cur->next;
}
/*
* finish the last group line.
*/
if (pcount != 0)
fprintf(Vendors, " (%d)\n", pcount);
if (currentVendor != NULL) {
/* one need to close the current vendor list */
fprintf(currentVendor,"
\n");
generateHtmlFooter(currentVendor);
fclose(currentVendor);
}
fprintf(Vendors, "
\n");
generateHtmlFooter(Vendors);
fclose(Vendors);
}
/*
* Dump the full set of RPM by Vendor HTML file.
* One expect that the RPM files have been sorted by vendors.
*/
void dumpRpmByVendors(rpmDataPtr list, int installed) {
if (!rpm2html_dump_html) return;
dumpDirRpmByVendors(list, NULL, NULL, installed);
}
/*
* Dump the RPM by Date HTML file.
* One expect that the RPM files have been sorted by date.
*/
void dumpDirRpmByDate(rpmDataPtr list, rpmDirPtr dir,
char *subdir, int installed) {
FILE *ByDate;
rpmDataPtr cur;
time_t current_time = time(NULL);
int count = 0;
int page = 1;
if (!rpm2html_dump_html) return;
cur = list;
fullPathName(buf, dir, subdir, localizedStrings[LANG_BYDATE_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByDate = fopen(buf, "w");
if (ByDate == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
if (installed) {
generateHtmlHeader(ByDate, localizedStrings[LANG_SORTED_BY_IDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_IDATE]);
} else {
generateHtmlHeader(ByDate, localizedStrings[LANG_SORTED_BY_CDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_CDATE]);
}
/*
* Skip all the RPMs with date in the futur :-(
*/
while ((cur != NULL) && ((cur->date < 0) || (current_time < cur->date))) {
if (verbose > 1) {
fprintf(stderr, "dropping %s, date %d > current time %d\n",
rpmSoftwareName(cur), cur->date, current_time);
}
cur = cur->next;
}
/*
* First dump RPMs less than 3 days old.
*/
if (!installed) generateColorIndicator(ByDate);
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_3D_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_3D_OLD]);
fprintf(ByDate, "\n");
while ((cur != NULL) && ((current_time - cur->date) < (3 * 24 * 60 * 60))) {
generateHtmlRpmRow(ByDate, cur);
cur = cur->next;
count++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(ByDate, "
\n\n");
if (count > MAX_PAGE_LENGHT) {
count = 0;
fprintf(ByDate, "
\n");
fprintf(ByDate, "...\n",
page, localizedStrings[LANG_BYDATE_HTML]);
generateHtmlFooter(ByDate);
fclose(ByDate);
fullPathName(buf, dir, subdir, localizedStrings[LANG_BYDATE_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByDate = fopen(buf, "w");
if (ByDate == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
if (installed) {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_IDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_IDATE]);
} else {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_CDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_CDATE]);
}
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_3D_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_3D_OLD]);
fprintf(ByDate, "\n");
}
}
fprintf(ByDate, "
\n");
/*
* Then dump RPMs less than one week old.
*/
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_1W_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_1W_OLD]);
fprintf(ByDate, "\n");
while ((cur != NULL) && ((current_time - cur->date) < (7 * 24 * 60 * 60))) {
generateHtmlRpmRow(ByDate, cur);
cur = cur->next;
count++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(ByDate, "
\n\n");
if (count > MAX_PAGE_LENGHT) {
count = 0;
fprintf(ByDate, "
\n");
fprintf(ByDate, "...\n",
page, localizedStrings[LANG_BYDATE_HTML]);
generateHtmlFooter(ByDate);
fclose(ByDate);
fullPathName(buf, dir, subdir, localizedStrings[LANG_BYDATE_HTML]);
fullPathNameNr(buf, dir, subdir,
localizedStrings[LANG_BYDATE_HTML], page++);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByDate = fopen(buf, "w");
if (ByDate == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
if (installed) {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_IDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_IDATE]);
} else {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_CDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_CDATE]);
}
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_1W_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_1W_OLD]);
fprintf(ByDate, "\n");
}
}
fprintf(ByDate, "
\n");
/*
* Then dump RPMs less than two weeks old.
*/
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_2W_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_2W_OLD]);
fprintf(ByDate, "\n");
while ((cur != NULL) && ((current_time - cur->date) < (14 * 24 * 60 * 60))) {
generateHtmlRpmRow(ByDate, cur);
cur = cur->next;
count++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(ByDate, "
\n\n");
if (count > MAX_PAGE_LENGHT) {
count = 0;
fprintf(ByDate, "
\n");
fprintf(ByDate, "...\n",
page, localizedStrings[LANG_BYDATE_HTML]);
generateHtmlFooter(ByDate);
fclose(ByDate);
fullPathNameNr(buf, dir, subdir,
localizedStrings[LANG_BYDATE_HTML], page++);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByDate = fopen(buf, "w");
if (ByDate == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
if (installed) {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_IDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_IDATE]);
} else {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_CDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_CDATE]);
}
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_2W_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_2W_OLD]);
fprintf(ByDate, "\n");
}
}
fprintf(ByDate, "
\n");
/*
* Then dump RPMs less than one month old.
*/
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_1M_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_1M_OLD]);
fprintf(ByDate, "\n");
while ((cur != NULL) && ((current_time - cur->date) < (30 * 24 * 60 * 60))) {
generateHtmlRpmRow(ByDate, cur);
cur = cur->next;
count++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(ByDate, "
\n\n");
if (count > MAX_PAGE_LENGHT) {
count = 0;
fprintf(ByDate, "
\n");
fprintf(ByDate, "...\n",
page, localizedStrings[LANG_BYDATE_HTML]);
generateHtmlFooter(ByDate);
fclose(ByDate);
fullPathNameNr(buf, dir, subdir,
localizedStrings[LANG_BYDATE_HTML], page++);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByDate = fopen(buf, "w");
if (ByDate == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
if (installed) {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_IDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_IDATE]);
} else {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_CDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_CDATE]);
}
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_LESS_1M_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_LESS_1M_OLD]);
fprintf(ByDate, "\n");
}
}
fprintf(ByDate, "
\n");
/*
* Then dump RPMs more than one month old.
*/
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_MORE_1M_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_MORE_1M_OLD]);
fprintf(ByDate, "\n");
while (cur != NULL) {
generateHtmlRpmRow(ByDate, cur);
cur = cur->next;
count++;
if ((count % MAX_TABLE_LENGHT) == 0)
fprintf(ByDate, "
\n\n");
if (count > MAX_PAGE_LENGHT) {
count = 0;
fprintf(ByDate, "
\n");
fprintf(ByDate, "...\n",
page, localizedStrings[LANG_BYDATE_HTML]);
generateHtmlFooter(ByDate);
fclose(ByDate);
fullPathNameNr(buf, dir, subdir,
localizedStrings[LANG_BYDATE_HTML], page++);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByDate = fopen(buf, "w");
if (ByDate == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
if (installed) {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_IDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_IDATE]);
} else {
generateHtmlHeader(ByDate,
localizedStrings[LANG_SORTED_BY_CDATE], NULL);
generateLinks(ByDate, installed);
fprintf(ByDate, "%s
\n",
localizedStrings[LANG_SORTED_BY_CDATE]);
}
if (installed)
fprintf(ByDate, "%s
\n", localizedStrings[LANG_I_MORE_1M_OLD]);
else
fprintf(ByDate, "%s
\n", localizedStrings[LANG_MORE_1M_OLD]);
fprintf(ByDate, "\n");
}
}
fprintf(ByDate, "
\n");
generateHtmlFooter(ByDate);
fclose(ByDate);
}
/*
* Dump the full set of RPM by Date HTML file.
* One expect that the RPM files have been sorted by date.
*/
void dumpRpmByDate(rpmDataPtr list, int installed) {
if (!rpm2html_dump_html) return;
dumpDirRpmByDate(list, NULL, NULL, installed);
}
/*
* Dump the RPM in a flat list sorted by Name.
* One expect that the RPM files have been sorted by name.
*/
void dumpDirRpmByNameFlat(rpmDataPtr list, rpmDirPtr dir,
char *subdir, int installed) {
FILE *ByName;
rpmDataPtr cur;
if (!rpm2html_dump_html) return;
cur = list;
fullPathName(buf, dir, subdir, localizedStrings[LANG_BYNAME_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByName = fopen(buf, "w");
if (ByName == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
generateHtmlHeader(ByName, localizedStrings[LANG_SORTED_BY_NAME], NULL);
generateLinks(ByName, installed);
fprintf(ByName, "%s
\n",
localizedStrings[LANG_SORTED_BY_NAME]);
if (!installed) generateColorIndicator(ByName);
fprintf(ByName, "\n");
while (cur != NULL) {
generateHtmlRpmArchRow(ByName, cur);
if ((dir == NULL) && (subdir == NULL))
cur = cur->nextSoft;
else
cur = cur->next;
}
fprintf(ByName, "
\n");
generateHtmlFooter(ByName);
fclose(ByName);
}
/*
* Dump the RPM in a subtree by Name HTML file.
* One expect that the RPM files have been sorted by name.
*/
void dumpDirRpmByName(rpmDataPtr list, rpmDirPtr dir,
char *subdir, int installed) {
FILE *ByName;
FILE *CurrName = NULL;
rpmDataPtr cur;
int i = 0;
char last_letter = '\0', letter;
if (!rpm2html_dump_html) return;
if ((dir == NULL) && (subdir == NULL))
for (cur = list; cur != NULL; cur = cur->nextSoft) i++;
else
for (cur = list; cur != NULL; cur = cur->next) i++;
if (i < MAX_NAME_LIST_LENGHT) {
dumpDirRpmByNameFlat(list, dir, subdir, installed);
return;
}
i = 0;
cur = list;
fullPathName(buf, dir, subdir, localizedStrings[LANG_BYNAME_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
ByName = fopen(buf, "w");
if (ByName == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
generateHtmlHeader(ByName, localizedStrings[LANG_SORTED_BY_NAME], NULL);
generateLinks(ByName, installed);
fprintf(ByName, "%s
\n",
localizedStrings[LANG_SORTED_BY_NAME]);
while (cur != NULL) {
letter = toupper(cur->name[0]);
if (letter != last_letter) {
if (CurrName != NULL) {
/*
* Finish the previous file.
*/
fprintf(CurrName, "\n");
generateHtmlFooter(CurrName);
fclose(CurrName);
}
if (i != 0)
fprintf(ByName, "%d %s %c
\n",
last_letter, localizedStrings[LANG_BYNAME_HTML],
i, localizedStrings[LANG_BEGINNING_LETTER],
last_letter);
fullPathNameLr(buf, dir, subdir,
localizedStrings[LANG_BYNAME_HTML], letter);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
CurrName = fopen(buf, "w");
if (CurrName == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s %c", localizedStrings[LANG_BEGINNING_LETTER],
letter);
generateHtmlHeader(CurrName, buf, NULL);
generateLinks(CurrName, installed);
fprintf(CurrName, "%s
\n", buf);
if (!installed) generateColorIndicator(CurrName);
fprintf(CurrName, "\n");
i = 0;
}
i++;
if ((i % MAX_TABLE_LENGHT) == 0)
fprintf(CurrName, "
\n\n");
last_letter = letter;
generateHtmlRpmArchRow(CurrName, cur);
if ((dir == NULL) && (subdir == NULL))
cur = cur->nextSoft;
else
cur = cur->next;
}
if (i != 0)
fprintf(ByName, "%d %s %c
\n",
last_letter, localizedStrings[LANG_BYNAME_HTML],
i, localizedStrings[LANG_BEGINNING_LETTER],
last_letter);
if (CurrName != NULL) {
/*
* Finish the previous file.
*/
fprintf(CurrName, "
\n");
generateHtmlFooter(CurrName);
fclose(CurrName);
}
generateHtmlFooter(ByName);
fclose(ByName);
}
/*
* Dump the full set of RPM by Name HTML file.
* One expect that the RPM files have been sorted by name.
*/
void dumpRpmByName(rpmDataPtr list, int installed) {
if (!rpm2html_dump_html) return;
dumpDirRpmByName(list, NULL, NULL, installed);
}
/*
* Dump the index for a directory and its subdirectories.
*/
rpmDataPtr dumpDirIndex(rpmDirPtr dir, rpmSubdirPtr tree, rpmDataPtr list) {
FILE *html;
if (!rpm2html_dump_html) return(list);
if (tree->htmlpath[0] != '\0')
sprintf(buf, "%s/%s/%s", rpm2html_dir, tree->htmlpath,
localizedStrings[LANG_INDEX_HTML]);
else
sprintf(buf, "%s/%s", rpm2html_dir,
localizedStrings[LANG_INDEX_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
html = fopen(buf, "w");
if (html == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return(list);
}
if (tree->htmlpath[0] != '\0')
sprintf(buf, "%s : %s", dir->name, tree->htmlpath);
else
sprintf(buf, "%s", dir->name);
generateHtmlHeader(html, buf, NULL);
generateLinks(html, 1);
fprintf(html, "%s
\n", buf);
fprintf(html, "\n");
fprintf(html, "- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_GROUP_HTML],
localizedStrings[LANG_INDEX_GROUP]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_BYDATE_HTML],
localizedStrings[LANG_INDEX_CREATION]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_BYNAME_HTML],
localizedStrings[LANG_INDEX_NAME]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_VENDOR_HTML],
localizedStrings[LANG_INDEX_VENDOR]);
fprintf(html, "
- \n%s %s\n",
localizedStrings[LANG_LIST],
localizedStrings[LANG_DISTRIB_HTML],
localizedStrings[LANG_INDEX_DISTRIB]);
fprintf(html, "
\n\n");
generateHtmlTree(html, tree, 0, 1);
generateHtmlFooter(html);
fclose(html);
list = rpmDistribSort(list, 0);
dumpDirRpmByDistribs(list, dir, tree->htmlpath, 0);
list = rpmGroupSort(list, 0);
dumpDirRpmByGroups(list, dir, tree->htmlpath, 0);
list = rpmVendorSort(list, 0);
dumpDirRpmByVendors(list, dir, tree->htmlpath, 0);
list = rpmDateSort(list, 0);
dumpDirRpmByDate(list, dir, tree->htmlpath, 0);
list = rpmNameSort(list, 0);
dumpDirRpmByName(list, dir, tree->htmlpath, 0);
return(list);
}
/*
* Dump a real tree subdir.
*/
void rpmDumpHtmlRealTree(FILE *html, rpmDirPtr dir, rpmRealDirPtr tree,
char *buffer, int index) {
FILE *subdir;
char buf[1000];
int has_subdir = 0;
int has_file = 0;
int i;
if (!rpm2html_dump_html) return;
if (dir->subdir)
sprintf(buf, "%s/%s/%s%s", rpm2html_dir,
dir->subdir, buffer,
localizedStrings[LANG_TREE_HTML]);
else
sprintf(buf, "%s/%s%s", rpm2html_dir, buffer,
localizedStrings[LANG_TREE_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
subdir = fopen(buf, "w");
if (subdir == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s : %s", dir->name, buffer);
generateHtmlHeader(subdir, buf, NULL);
generateLinks(subdir, 1);
fprintf(subdir, "%s
\n", buf);
for (i = 0;i < tree->nb_elem;i++) {
if (tree->flags[i] & RPM_ELEM_DIRECTORY) {
if (!has_subdir)
fprintf(html, "\n");
has_subdir++;
fprintf(html, "- %s\n",
buffer, tree->names[i],
localizedStrings[LANG_TREE_HTML], tree->names[i]);
sprintf(&buffer[index], "%s_", tree->names[i]);
rpmDumpHtmlRealTree(html, dir, tree->elems[i],
buffer, strlen(buffer));
buffer[index] = '\0';
if (!has_file)
fprintf(subdir, "
\n");
has_file++;
fprintf(subdir, "- ",
buffer, tree->names[i],
localizedStrings[LANG_TREE_HTML]);
fprintf(subdir,
"",
rpm2html_url);
fprintf(subdir, " %s\n", tree->names[i]);
} else {
if (!has_file)
fprintf(subdir, "
\n");
has_file++;
fprintf(subdir, "- ");
generateHtmlRpmAnchor(subdir, tree->elems[i]);
fprintf(subdir, "%s\n", tree->names[i]);
}
}
if (has_subdir)
fprintf(html, "
\n");
if (has_file)
fprintf(subdir, "
\n");
generateHtmlFooter(subdir);
fclose(subdir);
}
/*
* Dump a real tree root.
*/
void rpmDumpHtmlRealRoot(rpmDirPtr dir) {
FILE *html;
char buf[1000];
rpmRealDirPtr tree;
if (!rpm2html_dump_html) return;
if (dir == NULL) return;
tree = dir->root;
if (tree == NULL) return;
if (dir->subdir)
sprintf(buf, "%s/%s/%s", rpm2html_dir,
dir->subdir, localizedStrings[LANG_TREE_HTML]);
else
sprintf(buf, "%s/%s", rpm2html_dir,
localizedStrings[LANG_TREE_HTML]);
if (verbose > 1) {
printf("Dumping %s\n", buf);
}
html = fopen(buf, "w");
if (html == NULL) {
fprintf(stderr, "Couldn't save to file %s: %s\n",
buf, strerror(errno));
return;
}
sprintf(buf, "%s", dir->name);
generateHtmlHeader(html, buf, NULL);
generateLinks(html, 1);
fprintf(html, "%s
\n", buf);
buf[0] = 0;
rpmDumpHtmlRealTree(html, dir, tree, buf, 0);
generateHtmlFooter(html);
fclose(html);
}