1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 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 188 189 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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/*
* language.c: code for the Localization support.
*
* See Copyright for the status of this software.
*
* $Id: language.c,v 1.31 2010/10/05 14:36:54 hany Exp $
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "rpm2html.h"
#include "rpmdata.h"
#include "html.h"
char *localizedStrings[] = {
".html", /* HTML files suffix */
"Generated by",
"index.html",
"Groups.html",
"ByDate.html",
"ByName.html",
"Vendors.html",
"Distribs.html",
"Welcome to the RPM repository on",
"<p>\n\
<strong>rpm2html</strong> automatically generates Web pages describing a set of\n\
<a href=\"http://www.rpm.org/\">RPM</a> packages.</p>\n\
<p>\n\
<a href=\"http://rpmfind.net/linux/rpm2html/rpmfind.html\">\n\
The Rpmfind tool</a> allows automate the search of packages from\n\
the RPM Database or maintain your system up-to-date in a more automated way.\n\
<p>\n\
The goals of rpm2html are also to identify the dependencies between\n\
various packages and to find the package(s) providing the resources\n\
needed to install a given package. Every package is analyzed to\n\
retrieve its dependencies and the resources it offers. These\n\
relationships are expressed using hyperlinks in the generated\n\
pages. Finding the package providing the resource you need is just a\n\
matter of a few clicks!</p>\n\
<p>Check the <a href=\"http://rpmfind.net/linux/rpm2html/faq.html\">FAQ</a>\n\
in case of problems with rpm2html or rpmfind.\n\
<p>\n\
The proper working of the rpm2html tools requires the package maintainer\n\
to properly comment their RPM(s), if you maintain packages, make sure\n\
that the information are provided adequately (URL, email, ...).</p>\n\
<p>Learn how to <a href=\"http://rpmfind.net/linux/rpm2html/mirror.html\">\n\
build your own mirror</a> of this site. <B><FONT COLOR=\"#FF0000\">\n\
<FONT SIZE=\"+2\">Do not try to mirror it with a Web copy tool</FONT>\n\
</FONT></B></p>\n",
"This archive hosts %d RPMs representing %d MBytes of data",
"On this machine %d RPMs are installed representing %d MBytes of data",
"The list of ",
"RPM indexed by category",
"RPM indexed by date of creation",
"RPM indexed by name",
"RPM indexed by maintainer",
"RPM indexed by distribution",
"RPM indexed by date of installation",
"Repository for sources",
"Local mirror",
"Mirrors",
"Generation took",
"seconds",
"Welcome to the RPM description of",
"From",
"Name",
"Distribution",
"Version",
"Vendor",
"Release",
"Build date",
"Install date",
"Group",
"Build host",
"Size",
"Source RPM",
"Packager",
"Url",
"Summary",
"Provides",
"Requires",
"Copyright",
"Files",
"No Filelist in the Package !",
"No summary !",
"RPM resource",
"Provided by",
"index by Group",
"RPM of Group",
"index by Distribution",
"RPM of Distribution",
"index by Vendor",
"RPM shipped by",
"index by creation date",
"index by installation date",
"RPMs less than three days old",
"RPMs less than one week old",
"RPMs less than two weeks old",
"RPMs less than one month old",
"RPMs more than 1 months old",
"RPMs installed less than three days ago",
"RPMs installed less than one week ago",
"RPMs installed less than two weeks ago",
"RPMs installed less than one month ago",
"RPMs installed more than 1 months ago",
"index by Name",
"No description !",
"Unknown",
"None",
"unknown/group",
"unknown.host",
"Index",
"Packages beginning with letter",
"Warning: this package does not export valid resources lists",
"Try to pick another",
"More",
"Changelog",
"Sub Directories",
"Tree.html",
"Browse the distribution tree",
"<form action=\"%s/search.php?query=\" enctype=\"application/x-www-form-urlencoded\" method=\"GET\">\n\
<input name=\"query\" type=\"TEXT\" size=\"40\" value=\"\">\n\
<input name=submit type=submit value=\"Search ...\">\n\
</form>\n",
"Signatures",
"<p>Available as <a href=\"rdf\">an rdf channel</a></p>\n"
};
#define NB_STRINGS (sizeof(localizedStrings)/sizeof(char *))
/****************************************************************
* *
* The language file parser *
* *
****************************************************************/
/*
* A few macro needed to help building the parser
*/
#define IS_BLANK(ptr) \
(((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
((*(ptr)) == '\n') || ((*(ptr)) == '\r'))
#define SKIP_BLANK(ptr) \
{ while (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
((*(ptr)) == '\n') || ((*(ptr)) == '\r')) ptr++; }
#define GOTO_EQL(ptr) \
{ while (((*(ptr)) != '\0') && ((*(ptr)) != '=') && \
((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
#define GOTO_EOL(ptr) \
{ while (((*(ptr)) != '\0') && \
((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
/*
* parse a language file
*/
int readLanguageFile(char *filename)
{
FILE *input;
char *str;
char line[1000];
char buffer[50000];
int currentString;
int len;
input = fopen(filename, "r");
if (input == NULL) {
fprintf(stderr, "Cannot read language from %s :\n", filename);
perror("fopen failed");
return -1;
}
/*
* all the localized strings are filled in one after the other.
*/
buffer[0] = '\0';
currentString = 0;
while (1) {
/*
* read one line
*/
if (fgets(&line[0], sizeof(line) - 1, input) == NULL)
break;
str = &line[0];
line[sizeof(line) - 1] = '\0';
len = strlen(line);
if ((len > 0) && (line[len - 1] == '\n'))
line[len - 1] = '\0';
SKIP_BLANK(str)
/*
* Comment starts with a semicolumn.
*/
if (*str == ';')
continue;
/*
* an empty line is a field separator.
*/
if (*str == '\0') {
if (buffer[0] != '\0') {
/*
* Check for localizedStrings overflow.
*/
if (currentString >= NB_STRINGS) {
fprintf(stderr,
"File %s contains too many localized messages (%d expected)\n",
filename, NB_STRINGS);
break;
}
/*
* the last paragraph correspond to the new localized
* string. Replace the old one and reset the buffer.
*/
localizedStrings[currentString] = xmlStrdup(buffer);
currentString++;
buffer[0] = '\0';
}
continue;
}
/*
* Aggregate the current line to the buffer.
*/
if (buffer[0] == '\0')
strcpy(buffer, line);
else {
/*
* this is a multiline text field
*/
strcat(buffer, "\n");
strcat(buffer, line);
}
}
fclose(input);
return (0);
}
/*
* dump the internal set of string to an external language file.
*/
int writeLanguageFile(char *filename)
{
FILE *output;
int currentString;
output = fopen(filename, "w");
if (output == NULL) {
fprintf(stderr, "Cannot write language to %s :\n", filename);
perror("fopen failed");
return -1;
}
fprintf(output, ";\n; Automatically generated %s %s language file\n;\n",
RPM2HTML_NAME, RPM2HTML_VER);
for (currentString = 0; currentString < NB_STRINGS; currentString++) {
fprintf(output, "%s\n\n", localizedStrings[currentString]);
}
fclose(output);
return (0);
}
|