Annotation of rpm2html/language.c, revision 1.14

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

Webmaster