"Fossies" - the Fresh Open Source Software Archive

Member "rpm2html-1.11.2/language.c" (5 Oct 2010, 7391 Bytes) of package /linux/privat/rpm2html-1.11.2.tar.gz:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "language.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * language.c: code for the Localization support.
    3  *
    4  * See Copyright for the status of this software.
    5  *
    6  * $Id: language.c,v 1.31 2010/10/05 14:36:54 hany Exp $
    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\
   32 <strong>rpm2html</strong> automatically generates Web pages describing a set of\n\
   33 <a href=\"http://www.rpm.org/\">RPM</a> packages.</p>\n\
   34 <p>\n\
   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\
   38 <p>\n\
   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\
   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\
   48 <p>\n\
   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 information are provided adequately (URL, email, ...).</p>\n\
   52 <p>Learn how to <a href=\"http://rpmfind.net/linux/rpm2html/mirror.html\">\n\
   53 build your own mirror</a> of this site. <B><FONT COLOR=\"#FF0000\">\n\
   54 <FONT SIZE=\"+2\">Do not try to mirror it with a Web copy tool</FONT>\n\
   55 </FONT></B></p>\n",
   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 !",
   92     "RPM resource",
   93     "Provided by",
   94     "index by Group",
   95     "RPM of Group",
   96     "index by Distribution",
   97     "RPM of Distribution",
   98     "index by Vendor",
   99     "RPM shipped by",
  100     "index by creation date",
  101     "index 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     "index by Name",
  113     "No description !",
  114     "Unknown",
  115     "None",
  116     "unknown/group",
  117     "unknown.host",
  118     "Index",
  119     "Packages beginning with letter",
  120     "Warning: this package does not export valid resources lists",
  121     "Try to pick another",
  122     "More",
  123     "Changelog",
  124     "Sub Directories",
  125     "Tree.html",
  126     "Browse the distribution tree",
  127     "<form action=\"%s/search.php?query=\" enctype=\"application/x-www-form-urlencoded\" 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",
  131     "Signatures",
  132     "<p>Available as <a href=\"rdf\">an rdf channel</a></p>\n"
  133 };
  134 
  135 #define NB_STRINGS (sizeof(localizedStrings)/sizeof(char *))
  136 
  137 /****************************************************************
  138  *                              *
  139  *      The language file parser            *
  140  *                              *
  141  ****************************************************************/
  142 
  143 /*
  144  * A few macro needed to help building the parser
  145  */
  146 
  147 #define IS_BLANK(ptr) \
  148      (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
  149       ((*(ptr)) == '\n') || ((*(ptr)) == '\r'))
  150 #define SKIP_BLANK(ptr) \
  151      { while (((*(ptr)) == ' ') || ((*(ptr)) == '\b') || \
  152               ((*(ptr)) == '\n') || ((*(ptr)) == '\r')) ptr++; }
  153 #define GOTO_EQL(ptr) \
  154      { while (((*(ptr)) != '\0') && ((*(ptr)) != '=') && \
  155               ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
  156 #define GOTO_EOL(ptr) \
  157      { while (((*(ptr)) != '\0') && \
  158               ((*(ptr)) != '\n') && ((*(ptr)) != '\r')) ptr++; }
  159 
  160 
  161 /*
  162  * parse a language file
  163  */
  164 int readLanguageFile(char *filename)
  165 {
  166     FILE *input;
  167     char *str;
  168     char line[1000];
  169     char buffer[50000];
  170     int currentString;
  171     int len;
  172 
  173     input = fopen(filename, "r");
  174     if (input == NULL) {
  175     fprintf(stderr, "Cannot read language from %s :\n", filename);
  176     perror("fopen failed");
  177     return -1;
  178     }
  179 
  180     /*
  181      * all the localized strings are filled in one after the other.
  182      */
  183     buffer[0] = '\0';
  184     currentString = 0;
  185 
  186     while (1) {
  187     /*
  188      * read one line
  189      */
  190     if (fgets(&line[0], sizeof(line) - 1, input) == NULL)
  191         break;
  192 
  193     str = &line[0];
  194     line[sizeof(line) - 1] = '\0';
  195     len = strlen(line);
  196     if ((len > 0) && (line[len - 1] == '\n'))
  197         line[len - 1] = '\0';
  198     SKIP_BLANK(str)
  199 
  200     /*
  201      * Comment starts with a semicolumn.
  202      */
  203     if (*str == ';')
  204     continue;
  205 
  206     /*
  207      * an empty line is a field separator.
  208      */
  209     if (*str == '\0') {
  210         if (buffer[0] != '\0') {
  211             /*
  212          * Check for localizedStrings overflow.
  213          */
  214         if (currentString >= NB_STRINGS) {
  215             fprintf(stderr,
  216           "File %s contains too many localized messages (%d expected)\n",
  217               filename, NB_STRINGS);
  218             break;
  219         }
  220 
  221         /*
  222          * the last paragraph correspond to the new localized
  223          * string. Replace the old one and reset the buffer.
  224          */
  225         localizedStrings[currentString] = xmlStrdup(buffer);
  226         currentString++;
  227         buffer[0] = '\0';
  228         }
  229         continue;
  230     }
  231 
  232     /*
  233      * Aggregate the current line to the buffer.
  234      */
  235     if (buffer[0] == '\0')
  236         strcpy(buffer, line);
  237     else {
  238         /*
  239          * this is a multiline text field
  240          */
  241         strcat(buffer, "\n");
  242         strcat(buffer, line);
  243     }
  244     }
  245 
  246     fclose(input);
  247     return (0);
  248 }
  249 
  250 /*
  251  * dump the internal set of string to an external language file.
  252  */
  253 int writeLanguageFile(char *filename)
  254 {
  255     FILE *output;
  256     int currentString;
  257 
  258     output = fopen(filename, "w");
  259     if (output == NULL) {
  260     fprintf(stderr, "Cannot write language to %s :\n", filename);
  261     perror("fopen failed");
  262     return -1;
  263     }
  264     fprintf(output, ";\n; Automatically generated %s %s language file\n;\n",
  265             RPM2HTML_NAME, RPM2HTML_VER);
  266     for (currentString = 0; currentString < NB_STRINGS; currentString++) {
  267     fprintf(output, "%s\n\n", localizedStrings[currentString]);
  268     }
  269     fclose(output);
  270     return (0);
  271 }
  272