Annotation of rpm2html/language.c, revision 1.16
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.16 ! veillard 6: * $Id: language.c,v 1.15 1998/05/26 01:53:56 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.15 veillard 35: <img src=\"new.gif\"><a href=\"http://rufus.w3.org/linux/rpm2html/rpmfind.html\">\n\
1.16 ! veillard 36: Users of Rpmfind</a> (allow to automate the\n\
! 37: search of packages from the RPM Database),\n\
! 38: must upgrade to 0.98 or later version, backward compatibility will be broken\n\
! 39: soon <a href=\"http://rufus.w3.org/linux/rpm2html/download.html\">upgrade ...</a></p>\n\
1.1 veillard 40: <p>\n\
1.7 veillard 41: The goals of rpm2html are also to identify the dependencies between\n\
42: various packages and to find the package(s) providing the resources\n\
43: needed to install a given package. Every package is analyzed to\n\
44: retrieve its dependencies and the resources it offers. These\n\
45: relationships are expressed using hyperlinks in the generated\n\
46: pages. Finding the package providing the resource you need is just a\n\
47: matter of a few clicks!</p>\n\
1.1 veillard 48: <p>\n\
1.7 veillard 49: The ultimate commodity is ensured by indexing this set of pages,\n\
50: allowing the user to find instantaneously the package(s) providing any\n\
51: given functionality (as long as the package maintainer has properly\n\
1.11 veillard 52: commented the RPM).</p>\n\
53: <p>\n\
54: Learn how to <a href=\"http://rufus.w3.org/linux/rpm2html/mirror.html\">\n\
55: build your own mirror</a> of this site.</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",
94: "RPM sorted by Group",
95: "RPM of Group",
96: "RPM sorted by Distribution",
97: "RPM of Distribution",
98: "RPM sorted by Vendor",
99: "RPM shipped by",
100: "RPM sorted by creation date",
101: "RPM sorted by installation date",
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",
112: "RPM sorted by Name",
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",
126: "Browse the distribution tree"
1.1 veillard 127: };
128:
129: #define NB_STRINGS (sizeof(localizedStrings)/sizeof(char *))
130:
131: /****************************************************************
132: * *
133: * The language file parser *
134: * *
135: ****************************************************************/
136:
137: /*
138: * A few macro needed to help building the parser
139: */
140:
141: #define IS_BLANK(ptr) \
142: (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
143: ((*(ptr)) == '\n') || ((*(ptr)) == '\r'))
144: #define SKIP_BLANK(ptr) \
145: { while (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
146: ((*(ptr)) == '\n') || ((*(ptr)) == '\r')) ptr++; }
147: #define GOTO_EQL(ptr) \
148: { while (((*(ptr)) != '\0') && ((*(ptr)) != '=') && \
149: ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
150: #define GOTO_EOL(ptr) \
151: { while (((*(ptr)) != '\0') && \
152: ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
153:
154:
155: /*
156: * parse a language file
157: */
158: int readLanguageFile(char *filename)
159: {
160: FILE *input;
161: char *str;
162: char line[1000];
163: char buffer[50000];
164: int currentString;
165: int len;
166:
167: input = fopen(filename, "r");
168: if (input == NULL) {
169: fprintf(stderr, "Cannot read language from %s :\n", filename);
170: perror("fopen failed");
171: return -1;
172: }
173:
174: /*
175: * all the localized strings are filled in one after the other.
176: */
177: buffer[0] = '\0';
178: currentString = 0;
179:
180: while (1) {
181: /*
182: * read one line
183: */
184: if (fgets(&line[0], sizeof(line) - 1, input) == NULL)
185: break;
186:
187: str = &line[0];
188: line[sizeof(line) - 1] = '\0';
189: len = strlen(line);
190: if ((len > 0) && (line[len - 1] == '\n'))
191: line[len - 1] = '\0';
192: SKIP_BLANK(str)
193:
194: /*
195: * Comment starts with a semicolumn.
196: */
197: if (*str == ';')
198: continue;
199:
200: /*
201: * an empty line is a field separator.
202: */
203: if (*str == '\0') {
204: if (buffer[0] != '\0') {
205: /*
206: * Check for localizedStrings overflow.
207: */
208: if (currentString >= NB_STRINGS) {
209: fprintf(stderr,
210: "File %s contains too many localized messages (%d expected)\n",
211: filename, NB_STRINGS);
212: break;
213: }
214:
215: /*
216: * the last paragraph correspond to the new localized
217: * string. Replace the old one and reset the buffer.
218: */
219: localizedStrings[currentString] = strdup(buffer);
220: currentString++;
221: buffer[0] = '\0';
222: }
223: continue;
224: }
225:
226: /*
227: * Aggregate the current line to the buffer.
228: */
229: if (buffer[0] == '\0')
230: strcpy(buffer, line);
231: else {
232: /*
233: * this is a multiline text field
234: */
235: strcat(buffer, "\n");
236: strcat(buffer, line);
237: }
238: }
239:
240: fclose(input);
241: return (0);
242: }
243:
244: /*
245: * dump the internal set of string to an external language file.
246: */
247: int writeLanguageFile(char *filename)
248: {
249: FILE *output;
250: int currentString;
251:
252: output = fopen(filename, "w");
253: if (output == NULL) {
254: fprintf(stderr, "Cannot write language to %s :\n", filename);
255: perror("fopen failed");
256: return -1;
257: }
258: fprintf(output, ";\n; Automatically generated %s %s language file\n;\n",
259: RPM2HTML_NAME, RPM2HTML_VER);
260: for (currentString = 0; currentString < NB_STRINGS; currentString++) {
261: fprintf(output, "%s\n\n", localizedStrings[currentString]);
262: }
263: fclose(output);
264: return (0);
265: }
266:
Webmaster