/* * html.c: code concerning the dump as an HTML base. * * See Copyright for the status of this software. * * $Id: html.c,v 1.65 1998/09/03 19:37:19 veillard Exp $ */ #include #include #include #ifdef HAVE_FCNTL_H #include #endif #include #include #include #ifdef HAVE_UNISTD_H #include #endif #include #include #include #include "rpm2html.h" #include "rpmdata.h" #include "html.h" #include "language.h" /* * Global variables concerning the dump environment */ static char buf[500]; /* * The entities list for the extended ASCII charset. */ static char *entities[256] = { NULL, /* 000 */ NULL, /* 001 */ NULL, /* 002 */ NULL, /* 003 */ NULL, /* 004 */ NULL, /* 005 */ NULL, /* 006 */ NULL, /* 007 */ NULL, /* 008 */ NULL, /* 009 */ NULL, /* 010 */ NULL, /* 011 */ NULL, /* 012 */ NULL, /* 013 */ NULL, /* 014 */ NULL, /* 015 */ NULL, /* 016 */ NULL, /* 017 */ NULL, /* 018 */ NULL, /* 019 */ NULL, /* 020 */ NULL, /* 021 */ NULL, /* 022 */ NULL, /* 023 */ NULL, /* 024 */ NULL, /* 025 */ NULL, /* 026 */ NULL, /* 027 */ NULL, /* 028 */ NULL, /* 029 */ NULL, /* 030 */ NULL, /* 031 */ NULL, /* 032 */ NULL, /* 033 */ """, /* 034 */ NULL, /* 035 */ NULL, /* 036 */ NULL, /* 037 */ "&", /* 038 */ NULL, /* 039 */ NULL, /* 040 */ NULL, /* 041 */ NULL, /* 042 */ NULL, /* 043 */ NULL, /* 044 */ NULL, /* 045 */ NULL, /* 046 */ NULL, /* 047 */ NULL, /* 048 */ NULL, /* 049 */ NULL, /* 050 */ NULL, /* 051 */ NULL, /* 052 */ NULL, /* 053 */ NULL, /* 054 */ NULL, /* 055 */ NULL, /* 056 */ NULL, /* 057 */ NULL, /* 058 */ NULL, /* 059 */ "<", /* 060 */ NULL, /* 061 */ ">", /* 062 */ NULL, /* 063 */ NULL, /* 064 */ NULL, /* 065 */ NULL, /* 066 */ NULL, /* 067 */ NULL, /* 068 */ NULL, /* 069 */ NULL, /* 070 */ NULL, /* 071 */ NULL, /* 072 */ NULL, /* 073 */ NULL, /* 074 */ NULL, /* 075 */ NULL, /* 076 */ NULL, /* 077 */ NULL, /* 078 */ NULL, /* 079 */ NULL, /* 080 */ NULL, /* 081 */ NULL, /* 082 */ NULL, /* 083 */ NULL, /* 084 */ NULL, /* 085 */ NULL, /* 086 */ NULL, /* 087 */ NULL, /* 088 */ NULL, /* 089 */ NULL, /* 090 */ NULL, /* 091 */ NULL, /* 092 */ NULL, /* 093 */ NULL, /* 094 */ NULL, /* 095 */ NULL, /* 096 */ NULL, /* 097 */ NULL, /* 098 */ NULL, /* 099 */ NULL, /* 100 */ NULL, /* 101 */ NULL, /* 102 */ NULL, /* 103 */ NULL, /* 104 */ NULL, /* 105 */ NULL, /* 106 */ NULL, /* 107 */ NULL, /* 108 */ NULL, /* 109 */ NULL, /* 110 */ NULL, /* 111 */ NULL, /* 112 */ NULL, /* 113 */ NULL, /* 114 */ NULL, /* 115 */ NULL, /* 116 */ NULL, /* 117 */ NULL, /* 118 */ NULL, /* 119 */ NULL, /* 120 */ NULL, /* 121 */ NULL, /* 122 */ NULL, /* 123 */ NULL, /* 124 */ NULL, /* 125 */ NULL, /* 126 */ NULL, /* 127 */ NULL, /* 128 */ NULL, /* 129 */ NULL, /* 130 */ NULL, /* 131 */ NULL, /* 132 */ NULL, /* 133 */ NULL, /* 134 */ NULL, /* 135 */ NULL, /* 136 */ NULL, /* 137 */ NULL, /* 138 */ NULL, /* 139 */ NULL, /* 140 */ NULL, /* 141 */ NULL, /* 142 */ NULL, /* 143 */ NULL, /* 144 */ NULL, /* 145 */ NULL, /* 146 */ NULL, /* 147 */ NULL, /* 148 */ NULL, /* 149 */ NULL, /* 150 */ NULL, /* 151 */ NULL, /* 152 */ NULL, /* 153 */ NULL, /* 154 */ NULL, /* 155 */ NULL, /* 156 */ NULL, /* 157 */ NULL, /* 158 */ NULL, /* 159 */ " ", /* 160 */ "¡", /* 161 */ "¢", /* 162 */ "£", /* 163 */ "¤", /* 164 */ "¥", /* 165 */ "¦", /* 166 */ "§", /* 167 */ "¨", /* 168 */ "©", /* 169 */ "ª", /* 170 */ "«", /* 171 */ "¬", /* 172 */ "­", /* 173 */ "®", /* 174 */ "¯", /* 175 */ "°", /* 176 */ "±", /* 177 */ "⊃", /* 178 */ "⊃", /* 179 */ "´", /* 180 */ "µ", /* 181 */ "¶", /* 182 */ "·", /* 183 */ "¸", /* 184 */ "⊃", /* 185 */ "º", /* 186 */ "»", /* 187 */ "&frac;", /* 188 */ "&frac;", /* 189 */ "&frac;", /* 190 */ "¿", /* 191 */ "À", /* 192 */ "Á", /* 193 */ "Â", /* 194 */ "Ã", /* 195 */ "Ä", /* 196 */ "Å", /* 197 */ "Æ", /* 198 */ "Ç", /* 199 */ "È", /* 200 */ "É", /* 201 */ "Ê", /* 202 */ "Ë", /* 203 */ "Ì", /* 204 */ "Í", /* 205 */ "Î", /* 206 */ "Ï", /* 207 */ "Ð", /* 208 */ "Ñ", /* 209 */ "Ò", /* 210 */ "Ó", /* 211 */ "Ô", /* 212 */ "Õ", /* 213 */ "Ö", /* 214 */ "×", /* 215 */ "Ø", /* 216 */ "Ù", /* 217 */ "Ú", /* 218 */ "Û", /* 219 */ "Ü", /* 220 */ "Ý", /* 221 */ "Þ", /* 222 */ "ß", /* 223 */ "à", /* 224 */ "á", /* 225 */ "â", /* 226 */ "ã", /* 227 */ "ä", /* 228 */ "å", /* 229 */ "æ", /* 230 */ "ç", /* 231 */ "è", /* 232 */ "é", /* 233 */ "ê", /* 234 */ "ë", /* 235 */ "ì", /* 236 */ "í", /* 237 */ "î", /* 238 */ "ï", /* 239 */ "ð", /* 240 */ "ñ", /* 241 */ "ò", /* 242 */ "ó", /* 243 */ "ô", /* 244 */ "õ", /* 245 */ "ö", /* 246 */ "÷", /* 247 */ "ø", /* 248 */ "ù", /* 249 */ "ú", /* 250 */ "û", /* 251 */ "ü", /* 252 */ "ý", /* 253 */ "þ", /* 254 */ "ÿ" /* 255 */ }; /* * Converting extended ASCII charset to valid HTML text. * The string returned is a shared location. */ char *convertHTML(const char *str) { static unsigned char *buffer = NULL; static int buffer_size = 2000; unsigned char *cur, *end; unsigned char c; if (buffer == NULL) { buffer = (char *) malloc(buffer_size * sizeof(char)); if (buffer == NULL) { perror("malloc failed"); exit(1); } } cur = &buffer[0]; end = &buffer[buffer_size - 20]; while (*str != '\0') { if (cur >= end) { int delta = cur - buffer; buffer_size *= 2; buffer = (char *) realloc(buffer, buffer_size * sizeof(char)); if (buffer == NULL) { perror("malloc failed"); exit(1); } end = &buffer[buffer_size - 20]; cur = &buffer[delta]; } c = (unsigned char) *(str++); if (entities[(unsigned int) c] == NULL) { *(cur++) = c; } else { strcpy(cur, entities[(unsigned int) c]); cur += strlen(entities[(unsigned int) c]); } } *cur = '\0'; return(buffer); } /* * Converting extended ASCII charset to valid HTML text. * A new memory area is allocated for the returned value. */ char *strdupHTML(const char *str) { return(strdup(convertHTML(str))); } /* * createDirectory : create a directory. It does recurse and create the * father dir if needed. */ void createDirectory(const char *dirname) { static char last_dir[2000] = ""; /* * avoid costly syscalls. */ if (!strcmp(last_dir, dirname)) return; if (mkdir(dirname, 0777) != 0) { switch (errno) { #ifdef EEXIST case EEXIST: if (rpm2htmlVerbose > 1) fprintf(stderr, "Directory \"%s\" already exists\n", dirname); return; #endif case ENOENT: { char *father = strdup(dirname); char *cur = &father[strlen(father)]; while (cur > father) { if (*cur == '/') { *cur = '\0'; break; } cur--; } if (cur > father) { createDirectory(father); if (mkdir(dirname, 0777) != 0) { fprintf(stderr, "createDirectory \"%s\" failed\n", dirname); perror("mkdir failed:"); return; } } free(father); break; } default: fprintf(stderr, "createDirectory \"%s\" failed\n", dirname); perror("mkdir failed:"); return; } } else if (rpm2htmlVerbose) fprintf(stderr, "Created directory \"%s\"\n", dirname); } /* * Stuff needed for the icon creation. */ #include #include "dir.gif.h" #include "new.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_dir_gif(); if ((fd = creat(path, 0644)) < 0) { fprintf(stderr, "creat() failed on %s\n", path); return; } write(fd, content, data_buffer_dir_gif_size); close(fd); sprintf(path, "%s/new.gif", rpm2html_dir); content = read_data_buffer_new_gif(); if ((fd = creat(path, 0644)) < 0) { fprintf(stderr, "creat() failed on %s\n", path); return; } write(fd, content, data_buffer_new_gif_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; tstruct = localtime(¤tTime); 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. * Don't list the source RPMs */ void generateHtmlRpmRow(FILE *html, rpmDataPtr cur, int shownew) { static char buf[500]; struct tm * tstruct; if (!strcmp(cur->arch, "src")) return; 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", rpmName(cur)); if ((shownew) && (cur->date > 0) && ((currentTime - cur->date) < (24 * 60 * 60 * 15))) fprintf(html, "\"New\"", rpm2html_url); fprintf(html, "\n%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) { if (strcmp(cur->arch, "src")) { fprintf(html, "", tmp->dir->color, SYSTEM_FIELD_WIDTH); generateHtmlRpmAnchor(html, tmp); fprintf(html, "%s/%s", tmp->os, tmp->arch); if ((currentTime - tmp->date) < (24 * 60 * 60 * 15)) fprintf(html, "\"New\"", rpm2html_url); 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, "\n", rpm2html_url, localizedStrings[LANG_INDEX_HTML], localizedStrings[LANG_INDEX]); fprintf(html, "\n", rpm2html_url, localizedStrings[LANG_GROUP_HTML], localizedStrings[LANG_SORTED_BY_GROUP]); fprintf(html, "\n", rpm2html_url, localizedStrings[LANG_DISTRIB_HTML], localizedStrings[LANG_SORTED_BY_DISTRIB]); fprintf(html, "\n", rpm2html_url, localizedStrings[LANG_VENDOR_HTML], localizedStrings[LANG_SORTED_BY_VENDOR]); if (installed) fprintf(html, "\n", rpm2html_url, localizedStrings[LANG_BYDATE_HTML], localizedStrings[LANG_SORTED_BY_IDATE]); else fprintf(html, "\n", rpm2html_url, localizedStrings[LANG_BYDATE_HTML], localizedStrings[LANG_SORTED_BY_CDATE]); fprintf(html, "\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, "\n", rpm2html_headers_url[i], rpm2html_headers_name[i]); else fprintf(html, "\n", rpm2html_url, rpm2html_headers_url[i], rpm2html_headers_name[i]); } fprintf(html, "\n
%s%s%s%s%s%s%s%s%s
\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->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
", dir->color); if (dir->name != NULL) fprintf(html, "%s
\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, "\"parent-directory\"", rpm2html_url); fprintf(html, " ..

\n"); } for (i = 0;i < tree->nb_subdirs;i++) { fprintf(html, "

", rpm2html_url, tree->subdirs[i]->htmlpath); fprintf(html, "\"sub-directory\"", 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 (rpm2htmlVerbose > 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, "\n", cur->color, cur->ftp, cur->ftp); else fprintf(html, "\n", cur->color, cur->ftp, cur->name); fprintf(html, "\n"); if ((cur->ftpsrc != NULL) && (strcmp(cur->ftp, cur->ftpsrc))) fprintf(html, "\n", cur->color, localizedStrings[LANG_SOURCES_REPOSITORY], cur->color, cur->ftpsrc, cur->ftpsrc); if (cur->nb_mirrors > 0) fprintf(html, "\n", cur->color, localizedStrings[LANG_LOCAL_MIRROR], cur->color, cur->mirrors[0], cur->mirrors[0]); if (cur->nb_mirrors > 1) { fprintf(html, "\n", cur->color, localizedStrings[LANG_MIRRORS]); for (i = 1;i < cur->nb_mirrors;i++) { fprintf(html, "\n", cur->color, cur->mirrors[i], cur->mirrors[i]); } } fprintf(html, "
%s%s
%s:%s
%s:%s
%s
%s
\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; /* * create the directory on the fly if needed. */ if ((dir->subdir != NULL) && (dir->subdir[0] != '\0')) { if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0')) sprintf(buf, "%s/%s/%s", dir->dir, dir->subdir, rpm->subdir); else sprintf(buf, "%s/%s", dir->dir, dir->subdir); } else { if ((rpm->subdir != NULL) && (rpm->subdir[0] != '\0')) sprintf(buf, "%s/%s", dir->dir, rpm->subdir); else sprintf(buf, "%s", dir->dir); } createDirectory(buf); strcat(buf, "/"); strcat(buf, rpmName(rpm)); strcat(buf, ".html"); if (checkDate(buf, rpm->stamp)) return; if (rpm2htmlVerbose > 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, "

\n", dir->mirrors[0], rpm->subdir, rpm->filename); else fprintf(html, "

\n", dir->ftp, rpm->subdir, rpm->filename); } else { if (dir->mirrors[0] != NULL) fprintf(html, "

\n", dir->mirrors[0], rpm->filename); else fprintf(html, "

\n", dir->ftp, rpm->filename); } if (rpm->arch) { if (!strcmp(rpm->arch, "src")) fprintf(html, "%s-%s-%s Source RPM

\n", rpm->name, rpm->version, rpm->release); else fprintf(html, "%s-%s-%s RPM for %s

\n", rpm->name, rpm->version, rpm->release, rpm->arch); } else { fprintf(html, "%s-%s-%s RPM

\n", rpm->name, rpm->version, rpm->release); } if ((tree != NULL) && (tree->parent != NULL)) { fprintf(html, "

%s ", localizedStrings[LANG_FROM]); generateHtmlParentsNames(html, tree); fprintf(html, "

\n"); } else if (dir->name) { fprintf(html, "

%s %s

\n", localizedStrings[LANG_FROM], dir->ftp, dir->name); } fprintf(html, "", dir->color); fprintf(html, "\n"); fprintf(html, "\n", localizedStrings[LANG_NAME], rpm->name); fprintf(html, "\n", localizedStrings[LANG_DISTRIBUTION], rpm2html_url, distribName(rpm->distribution), convertHTML(rpm->distribution)); fprintf(html, "\n", localizedStrings[LANG_VERSION], rpm->version); fprintf(html, "\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, "\n\n", localizedStrings[LANG_RELEASE], rpm->release, localizedStrings[LANG_INSTALL_DATE], buf); } else { fprintf(html, "\n\n", localizedStrings[LANG_RELEASE], rpm->release, localizedStrings[LANG_BUILD_DATE], buf); } if (rpm2html_url != NULL) fprintf(html, "\n", localizedStrings[LANG_GROUP], rpm2html_url, groupName(rpm->group), convertHTML(rpm->group)); else fprintf(html, "\n", localizedStrings[LANG_GROUP], groupName(rpm->group), convertHTML(rpm->group)); fprintf(html, "\n", localizedStrings[LANG_BUILD_HOST], rpm->host); fprintf(html, "\n", localizedStrings[LANG_SIZE], rpm->size); if (dir->ftpsrc) { fprintf(html, "\n", localizedStrings[LANG_RPM_SRC], dir->ftpsrc, rpm->srcrpm, rpm->srcrpm); } else { fprintf(html, "\n", localizedStrings[LANG_RPM_SRC], rpm->srcrpm); } if (rpm->packager) { char *email = extractEMail(rpm->packager); if (email == NULL) fprintf(html, "\n", localizedStrings[LANG_PACKAGER], convertHTML(rpm->packager)); else fprintf(html, "\n", localizedStrings[LANG_PACKAGER], email, convertHTML(rpm->packager)); } if (rpm->url) fprintf(html, "\n", localizedStrings[LANG_URL], rpm->url, rpm->url); fprintf(html, "\n", localizedStrings[LANG_SUMMARY], convertHTML(rpm->summary)); fprintf(html, "\n
%s: %s%s: %s
%s: %s%s: %s
%s: %s%s: %s
%s: %s%s: %s
%s: %s
%s: %s%s: %s
%s: %d%s: %s
%s: %s
%s: %s
%s: %s
%s: %s
%s: %s
\n"); fprintf(html, "
%s\n
\n", convertHTML(rpm->description)); if ((rpm->nb_resources + rpm->nb_requires < 2) && (!strstr(rpm->name, "lib")) && (!strcmp(rpm->arch, "src"))) { if (rpm2htmlVerbose > 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); } 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); } 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 (rpm2htmlVerbose > 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, 1); } 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 (rpm2htmlVerbose > 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"); 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 (rpm2htmlVerbose > 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"); 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 (rpm2htmlVerbose > 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"); 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; int count = 0; int page = 1; if (!rpm2html_dump_html) return; cur = list; fullPathName(buf, dir, subdir, localizedStrings[LANG_BYDATE_HTML]); if (rpm2htmlVerbose > 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) || (currentTime < cur->date))) { if (rpm2htmlVerbose > 1) { fprintf(stderr, "dropping %s, date %d > current time %d\n", rpmSoftwareName(cur), (int) cur->date, (int) currentTime); } 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) && ((currentTime - cur->date) < (3 * 24 * 60 * 60))) { generateHtmlRpmRow(ByDate, cur, 0); 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 (rpm2htmlVerbose > 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) && ((currentTime - cur->date) < (7 * 24 * 60 * 60))) { generateHtmlRpmRow(ByDate, cur, 0); 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 (rpm2htmlVerbose > 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) && ((currentTime - cur->date) < (14 * 24 * 60 * 60))) { generateHtmlRpmRow(ByDate, cur, 0); 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 (rpm2htmlVerbose > 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) && ((currentTime - cur->date) < (30 * 24 * 60 * 60))) { generateHtmlRpmRow(ByDate, cur, 0); 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 (rpm2htmlVerbose > 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, 0); 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 (rpm2htmlVerbose > 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 (rpm2htmlVerbose > 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 (rpm2htmlVerbose > 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 (rpm2htmlVerbose > 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 (rpm2htmlVerbose > 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); if (((tree->rpmpath == NULL) || (tree->rpmpath[0] == '\0')) && (rpm2html_build_tree)) sprintf(buf, "%s", localizedStrings[LANG_TREE_HTML], dir->name); 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]); if (((tree->rpmpath == NULL) || (tree->rpmpath[0] == '\0')) && (rpm2html_build_tree)) fprintf(html, "
  • \n%s\n", localizedStrings[LANG_TREE_HTML], localizedStrings[LANG_BROWSE_TREE]); 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 title with links to parents and whole tree. */ void rpmDumpHtmlRealTreeTitle(FILE *subdir, rpmDirPtr dir, char *buffer) { char buf[3000]; char tmp[1000]; char path[1000]; char loc[200]; int i = 0, j = 0, k = 0; /* indexes for buffer, loc and path resp. */ /* link for the root */ sprintf(buf, "/", localizedStrings[LANG_TREE_HTML]); while (buffer[i] != '\0') { if (buffer[i] == '_') { loc[j] = '\0'; path[k++] = '_'; path[k] = '\0'; sprintf(tmp, " %s/", path, localizedStrings[LANG_TREE_HTML], loc); strcat(buf, tmp); j = 0; } else { loc[j++] = buffer[i]; path[k++] = buffer[i]; } i++; } fprintf(subdir, "

%s : %s

\n", localizedStrings[LANG_TREE_HTML], dir->name, buf); } /* * 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 (rpm2htmlVerbose > 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; } generateHtmlHeader(subdir, buf, NULL); generateLinks(subdir, 1); rpmDumpHtmlRealTreeTitle(subdir, dir, buffer); 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"); 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/Root%s", rpm2html_dir, dir->subdir, localizedStrings[LANG_TREE_HTML]); else sprintf(buf, "%s/Root%s", rpm2html_dir, localizedStrings[LANG_TREE_HTML]); if (rpm2htmlVerbose > 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); }