Annotation of rpm2html/language.c, revision 1.25
1.1 veillard 1: /*
2: * language.c: code for the Localization support.
3: *
1.13 veillard 4: * See Copyright for the status of this software.
1.1 veillard 5: *
1.25 ! veillard 6: * $Id: language.c,v 1.24 2000/07/22 13:57:45 veillard Exp $
1.1 veillard 7: */
8:
9: #include <config.h>
10: #include <stdio.h>
11: #include <stdlib.h>
12: #include <string.h>
13: #ifdef HAVE_UNISTD_H
14: #include <unistd.h>
15: #endif
16:
17: #include "rpm2html.h"
18: #include "rpmdata.h"
19: #include "html.h"
20:
21: char *localizedStrings[] = {
22: ".html", /* HTML files suffix */
23: "Generated by",
24: "index.html",
25: "Groups.html",
26: "ByDate.html",
27: "ByName.html",
28: "Vendors.html",
29: "Distribs.html",
30: "Welcome to the RPM repository on",
31: "<p>\n\
1.12 veillard 32: <strong>rpm2html</strong> automatically generates Web pages describing a set of\n\
1.1 veillard 33: <a href=\"http://www.rpm.org/\">RPM</a> packages.</p>\n\
1.14 veillard 34: <p>\n\
1.24 veillard 35: <a href=\"http://rpmfind.net/linux/rpm2html/rpmfind.html\">\n\
36: The Rpmfind tool</a> allows automate the search of packages from\n\
37: the RPM Database or maintain your system up-to-date in a more automated way.\n\
1.1 veillard 38: <p>\n\
1.7 veillard 39: The goals of rpm2html are also to identify the dependencies between\n\
40: various packages and to find the package(s) providing the resources\n\
41: needed to install a given package. Every package is analyzed to\n\
42: retrieve its dependencies and the resources it offers. These\n\
43: relationships are expressed using hyperlinks in the generated\n\
44: pages. Finding the package providing the resource you need is just a\n\
45: matter of a few clicks!</p>\n\
1.24 veillard 46: <p>Check the <a href=\"http://rpmfind.net/linux/rpm2html/faq.html\">FAQ</a>\n\
47: in case of problems with rpm2html or rpmfind.\n\
1.1 veillard 48: <p>\n\
1.24 veillard 49: The proper working of the rpm2html tools requires the package maintainer\n\
50: to properly comment their RPM(s), if you maintain packages, make sure\n\
51: that the informations are provided adequately (URL, email, ...).</p>\n\
52: <p>Learn how to <a href=\"http://rpmfind.net/linux/rpm2html/mirror.html\">\n\
1.17 veillard 53: build your own mirror</a> of this site. <B><FONT COLOR=\"#FF0000\">\n\
1.24 veillard 54: <FONT SIZE=\"+2\">Do not try to mirror it with a Web copy tool</FONT>\n\
1.19 daniel 55: </FONT></B></p>\n",
1.1 veillard 56: "This archive hosts %d RPMs representing %d MBytes of data",
57: "On this machine %d RPMs are installed representing %d MBytes of data",
58: "The list of ",
59: "RPM indexed by category",
60: "RPM indexed by date of creation",
61: "RPM indexed by name",
62: "RPM indexed by maintainer",
63: "RPM indexed by distribution",
64: "RPM indexed by date of installation",
65: "Repository for sources",
66: "Local mirror",
67: "Mirrors",
68: "Generation took",
69: "seconds",
70: "Welcome to the RPM description of",
71: "From",
72: "Name",
73: "Distribution",
74: "Version",
75: "Vendor",
76: "Release",
77: "Build date",
78: "Install date",
79: "Group",
80: "Build host",
81: "Size",
82: "Source RPM",
83: "Packager",
84: "Url",
85: "Summary",
86: "Provides",
87: "Requires",
88: "Copyright",
89: "Files",
90: "No Filelist in the Package !",
91: "No summary !",
1.4 veillard 92: "RPM resource",
1.1 veillard 93: "Provided by",
1.20 daniel 94: "index by Group",
1.1 veillard 95: "RPM of Group",
1.20 daniel 96: "index by Distribution",
1.1 veillard 97: "RPM of Distribution",
1.20 daniel 98: "index by Vendor",
1.1 veillard 99: "RPM shipped by",
1.20 daniel 100: "index by creation date",
101: "index by installation date",
1.1 veillard 102: "RPMs less than three days old",
103: "RPMs less than one week old",
104: "RPMs less than two weeks old",
105: "RPMs less than one month old",
106: "RPMs more than 1 months old",
107: "RPMs installed less than three days ago",
108: "RPMs installed less than one week ago",
109: "RPMs installed less than two weeks ago",
110: "RPMs installed less than one month ago",
111: "RPMs installed more than 1 months ago",
1.20 daniel 112: "index by Name",
1.1 veillard 113: "No description !",
114: "Unknown",
115: "None",
116: "unknown/group",
1.2 veillard 117: "unknown.host",
1.3 veillard 118: "Index",
1.5 veillard 119: "Packages beginning with letter",
120: "Warning: this package does not export valid resources lists",
121: "Try to pick another",
1.6 veillard 122: "More",
1.8 veillard 123: "Changelog",
1.9 veillard 124: "Sub Directories",
1.10 veillard 125: "Tree.html",
1.25 ! veillard 126: "Browse the distribution tree",
! 127: "<form action=\"%s/search.php?query=\" enctype=\"multipart/form-data\" method=\"GET\">\n\
! 128: <input name=\"query\" type=\"TEXT\" size=\"40\" value=\"\">\n\
! 129: <input name=submit type=submit value=\"Search ...\">\n\
! 130: </form>\n"
1.1 veillard 131: };
132:
133: #define NB_STRINGS (sizeof(localizedStrings)/sizeof(char *))
134:
135: /****************************************************************
136: * *
137: * The language file parser *
138: * *
139: ****************************************************************/
140:
141: /*
142: * A few macro needed to help building the parser
143: */
144:
145: #define IS_BLANK(ptr) \
146: (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
147: ((*(ptr)) == '\n') || ((*(ptr)) == '\r'))
148: #define SKIP_BLANK(ptr) \
149: { while (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
150: ((*(ptr)) == '\n') || ((*(ptr)) == '\r')) ptr++; }
151: #define GOTO_EQL(ptr) \
152: { while (((*(ptr)) != '\0') && ((*(ptr)) != '=') && \
153: ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
154: #define GOTO_EOL(ptr) \
155: { while (((*(ptr)) != '\0') && \
156: ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
157:
158:
159: /*
160: * parse a language file
161: */
162: int readLanguageFile(char *filename)
163: {
164: FILE *input;
165: char *str;
166: char line[1000];
167: char buffer[50000];
168: int currentString;
169: int len;
170:
171: input = fopen(filename, "r");
172: if (input == NULL) {
173: fprintf(stderr, "Cannot read language from %s :\n", filename);
174: perror("fopen failed");
175: return -1;
176: }
177:
178: /*
179: * all the localized strings are filled in one after the other.
180: */
181: buffer[0] = '\0';
182: currentString = 0;
183:
184: while (1) {
185: /*
186: * read one line
187: */
188: if (fgets(&line[0], sizeof(line) - 1, input) == NULL)
189: break;
190:
191: str = &line[0];
192: line[sizeof(line) - 1] = '\0';
193: len = strlen(line);
194: if ((len > 0) && (line[len - 1] == '\n'))
195: line[len - 1] = '\0';
196: SKIP_BLANK(str)
197:
198: /*
199: * Comment starts with a semicolumn.
200: */
201: if (*str == ';')
202: continue;
203:
204: /*
205: * an empty line is a field separator.
206: */
207: if (*str == '\0') {
208: if (buffer[0] != '\0') {
209: /*
210: * Check for localizedStrings overflow.
211: */
212: if (currentString >= NB_STRINGS) {
213: fprintf(stderr,
214: "File %s contains too many localized messages (%d expected)\n",
215: filename, NB_STRINGS);
216: break;
217: }
218:
219: /*
220: * the last paragraph correspond to the new localized
221: * string. Replace the old one and reset the buffer.
222: */
1.21 daniel 223: localizedStrings[currentString] = debugStrdup(buffer);
1.1 veillard 224: currentString++;
225: buffer[0] = '\0';
226: }
227: continue;
228: }
229:
230: /*
231: * Aggregate the current line to the buffer.
232: */
233: if (buffer[0] == '\0')
234: strcpy(buffer, line);
235: else {
236: /*
237: * this is a multiline text field
238: */
239: strcat(buffer, "\n");
240: strcat(buffer, line);
241: }
242: }
243:
244: fclose(input);
245: return (0);
246: }
247:
248: /*
249: * dump the internal set of string to an external language file.
250: */
251: int writeLanguageFile(char *filename)
252: {
253: FILE *output;
254: int currentString;
255:
256: output = fopen(filename, "w");
257: if (output == NULL) {
258: fprintf(stderr, "Cannot write language to %s :\n", filename);
259: perror("fopen failed");
260: return -1;
261: }
262: fprintf(output, ";\n; Automatically generated %s %s language file\n;\n",
263: RPM2HTML_NAME, RPM2HTML_VER);
264: for (currentString = 0; currentString < NB_STRINGS; currentString++) {
265: fprintf(output, "%s\n\n", localizedStrings[currentString]);
266: }
267: fclose(output);
268: return (0);
269: }
270:
Webmaster