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