Annotation of rpm2html/language.c, revision 1.19

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

Webmaster