Swipe data structures from gettext.
CVS patchset: 2311 CVS date: 1998/09/14 20:58:51
This commit is contained in:
parent
b4f7b7d126
commit
679e135014
|
@ -314,6 +314,101 @@ rewriteBinaryRPM(char *fni, char *fno)
|
|||
}
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
#define xstrdup strdup
|
||||
#define xmalloc malloc
|
||||
#define xrealloc realloc
|
||||
#define PARAMS(_x) _x
|
||||
|
||||
#include "str-list.c"
|
||||
|
||||
#include "rpmpo.h"
|
||||
|
||||
message_ty *
|
||||
message_alloc (msgid)
|
||||
char *msgid;
|
||||
{
|
||||
message_ty *mp;
|
||||
|
||||
mp = xmalloc (sizeof (message_ty));
|
||||
mp->msgid = msgid;
|
||||
mp->comment = NULL;
|
||||
mp->comment_dot = NULL;
|
||||
mp->filepos_count = 0;
|
||||
mp->filepos = NULL;
|
||||
mp->variant_count = 0;
|
||||
mp->variant = NULL;
|
||||
mp->used = 0;
|
||||
mp->obsolete = 0;
|
||||
mp->is_fuzzy = 0;
|
||||
mp->is_c_format = undecided;
|
||||
mp->do_wrap = undecided;
|
||||
return mp;
|
||||
}
|
||||
|
||||
void
|
||||
message_free (mp)
|
||||
message_ty *mp;
|
||||
{
|
||||
size_t j;
|
||||
|
||||
if (mp->comment != NULL)
|
||||
string_list_free (mp->comment);
|
||||
if (mp->comment_dot != NULL)
|
||||
string_list_free (mp->comment_dot);
|
||||
free ((char *) mp->msgid);
|
||||
for (j = 0; j < mp->variant_count; ++j)
|
||||
free ((char *) mp->variant[j].msgstr);
|
||||
if (mp->variant != NULL)
|
||||
free (mp->variant);
|
||||
for (j = 0; j < mp->filepos_count; ++j)
|
||||
free ((char *) mp->filepos[j].file_name);
|
||||
if (mp->filepos != NULL)
|
||||
free (mp->filepos);
|
||||
free (mp);
|
||||
}
|
||||
|
||||
message_list_ty *
|
||||
message_list_alloc ()
|
||||
{
|
||||
message_list_ty *mlp;
|
||||
|
||||
mlp = xmalloc (sizeof (message_list_ty));
|
||||
mlp->nitems = 0;
|
||||
mlp->nitems_max = 0;
|
||||
mlp->item = 0;
|
||||
return mlp;
|
||||
}
|
||||
|
||||
void
|
||||
message_list_append (mlp, mp)
|
||||
message_list_ty *mlp;
|
||||
message_ty *mp;
|
||||
{
|
||||
if (mlp->nitems >= mlp->nitems_max)
|
||||
{
|
||||
size_t nbytes;
|
||||
|
||||
mlp->nitems_max = mlp->nitems_max * 2 + 4;
|
||||
nbytes = mlp->nitems_max * sizeof (message_ty *);
|
||||
mlp->item = xrealloc (mlp->item, nbytes);
|
||||
}
|
||||
mlp->item[mlp->nitems++] = mp;
|
||||
}
|
||||
|
||||
void
|
||||
message_list_free (mlp)
|
||||
message_list_ty *mlp;
|
||||
{
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < mlp->nitems; ++j)
|
||||
message_free (mlp->item[j]);
|
||||
if (mlp->item)
|
||||
free (mlp->item);
|
||||
free (mlp);
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
|
||||
static int
|
||||
|
@ -363,18 +458,16 @@ slurp(const char *file, char **ibufp, size_t *nbp)
|
|||
typedef struct {
|
||||
char *name;
|
||||
int len;
|
||||
int haslang;
|
||||
} KW_t;
|
||||
|
||||
KW_t keywords[] = {
|
||||
{ "domain", 6 },
|
||||
{ "msgid", 5 },
|
||||
{ "msgstr", 6 },
|
||||
{ "domain", 6, 0 },
|
||||
{ "msgid", 5, 0 },
|
||||
{ "msgstr", 6, 1 },
|
||||
NULL
|
||||
};
|
||||
|
||||
#define SKIPWHITE {while ((c = *se) && strchr("\b\f\n\r\t ", c)) se++;}
|
||||
#define NEXTLINE {state = 0; if (!(se = strchr(se, '\n'))) se = s + strlen(s);}
|
||||
|
||||
static char *
|
||||
matchchar(const char *p, char pl, char pr)
|
||||
{
|
||||
|
@ -398,9 +491,13 @@ matchchar(const char *p, char pl, char pr)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#define SKIPWHITE {while ((c = *se) && strchr("\b\f\n\r\t ", c)) se++;}
|
||||
#define NEXTLINE {state = 0; while ((c = *se) && c != '\n') se++; if (c == '\n') se++;}
|
||||
|
||||
static int
|
||||
parsepofile(const char *file)
|
||||
parsepofile(const char *file, message_list_ty **mlpp)
|
||||
{
|
||||
message_list_ty *mlp;
|
||||
KW_t *kw;
|
||||
char *buf, *s, *se;
|
||||
size_t nb;
|
||||
|
@ -411,6 +508,7 @@ fprintf(stderr, "================ %s\n", file);
|
|||
if ((rc = slurp(file, &buf, &nb)) != 0)
|
||||
return rc;
|
||||
|
||||
mlp = message_list_alloc();
|
||||
s = buf;
|
||||
while ((c = *s) != '\0') {
|
||||
se = s;
|
||||
|
@ -421,13 +519,18 @@ fprintf(stderr, "================ %s\n", file);
|
|||
break;
|
||||
case 1: /* comment "domain" "msgid" "msgstr" */
|
||||
SKIPWHITE;
|
||||
if (!isalpha(c)) {
|
||||
if (c != '#')
|
||||
fprintf(stderr, "non-alpha char at \"%.20s\"\n", se);
|
||||
s = se;
|
||||
if (!(isalpha(c) || c == '#')) {
|
||||
fprintf(stderr, "non-alpha char at \"%.20s\"\n", se);
|
||||
NEXTLINE;
|
||||
break;
|
||||
}
|
||||
for (kw = keywords; kw->name; kw++) {
|
||||
if (c == '#') {
|
||||
NEXTLINE;
|
||||
/* === s:se has comment */
|
||||
break;
|
||||
}
|
||||
for (kw = keywords; kw->name != NULL; kw++) {
|
||||
if (!strncmp(s, kw->name, kw->len)) {
|
||||
se += kw->len;
|
||||
break;
|
||||
|
@ -438,20 +541,24 @@ fprintf(stderr, "================ %s\n", file);
|
|||
NEXTLINE;
|
||||
break;
|
||||
}
|
||||
/* === s:se has keyword */
|
||||
|
||||
SKIPWHITE;
|
||||
s = se;
|
||||
if (*se == '(') {
|
||||
if ((se = strchr(se, ')')) == NULL) {
|
||||
if (kw->haslang && *se == '(') {
|
||||
while ((c = *se) && c != ')') se++;
|
||||
if (c != ')') {
|
||||
fprintf(stderr, "unclosed paren at \"%.20s\"\n", s);
|
||||
se = s;
|
||||
NEXTLINE;
|
||||
break;
|
||||
}
|
||||
s++; /* skip ( */
|
||||
/* === s:se has lang */
|
||||
se++; /* skip ) */
|
||||
}
|
||||
|
||||
SKIPWHITE;
|
||||
s = se;
|
||||
if (*se != '"') {
|
||||
fprintf(stderr, "missing string at \"%.20s\"\n", s);
|
||||
se = s;
|
||||
|
@ -461,26 +568,36 @@ fprintf(stderr, "================ %s\n", file);
|
|||
state = 2;
|
||||
break;
|
||||
case 2: /* "...." */
|
||||
SKIPWHITE;
|
||||
if (c != '"') {
|
||||
fprintf(stderr, "not a string at \"%.20s\"\n", s);
|
||||
NEXTLINE;
|
||||
break;
|
||||
}
|
||||
s++; /* skip open quote */
|
||||
if ((se = matchchar(s, c, c)) == NULL) {
|
||||
fprintf(stderr, "missing close %c at \"%.20s\"\n", c, s);
|
||||
NEXTLINE;
|
||||
break;
|
||||
}
|
||||
se++; /* skip close quote */
|
||||
SKIPWHITE;
|
||||
if (c != '"')
|
||||
state = 0;
|
||||
s = se;
|
||||
do {
|
||||
s++; /* skip open quote */
|
||||
if ((se = matchchar(s, c, c)) == NULL) {
|
||||
fprintf(stderr, "missing close %c at \"%.20s\"\n", c, s);
|
||||
se = s;
|
||||
NEXTLINE;
|
||||
break;
|
||||
}
|
||||
/* === s:se has next part of string */
|
||||
se++; /* skip close quote */
|
||||
SKIPWHITE;
|
||||
} while (c == '"');
|
||||
state = 0;
|
||||
break;
|
||||
}
|
||||
s = se;
|
||||
}
|
||||
|
||||
if (mlpp)
|
||||
*mlpp = mlp;
|
||||
else
|
||||
message_list_free(mlp);
|
||||
|
||||
FREE(buf);
|
||||
return rc;
|
||||
}
|
||||
|
@ -584,7 +701,7 @@ rpmputtext(int fd, const char *file, FILE *ofp)
|
|||
static int
|
||||
rpmchktext(int fd, const char *file, FILE *ofp)
|
||||
{
|
||||
return parsepofile(file);
|
||||
return parsepofile(file, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
#ifndef _H_RPMPO_
|
||||
#define _H_RPMPO_
|
||||
|
||||
/* XXX lifted from gettext/src/po-lex.h */
|
||||
typedef struct lex_pos_ty lex_pos_ty;
|
||||
struct lex_pos_ty
|
||||
{
|
||||
char *file_name;
|
||||
size_t line_number;
|
||||
};
|
||||
|
||||
/* XXX lifted from gettext/src/message.h */
|
||||
|
||||
/* Is current msgid a format string? */
|
||||
enum is_c_format
|
||||
{
|
||||
undecided,
|
||||
yes,
|
||||
no,
|
||||
possible,
|
||||
impossible
|
||||
};
|
||||
|
||||
typedef struct message_variant_ty message_variant_ty;
|
||||
struct message_variant_ty
|
||||
{
|
||||
const char *domain;
|
||||
lex_pos_ty pos;
|
||||
const char *msgstr;
|
||||
};
|
||||
|
||||
typedef struct message_ty message_ty;
|
||||
struct message_ty
|
||||
{
|
||||
/* Plain comments (#) appearing before the message. */
|
||||
string_list_ty *comment;
|
||||
|
||||
/* Extracted comments (#.) appearing before the message. */
|
||||
string_list_ty *comment_dot;
|
||||
|
||||
/* File position comments (#:) appearing before the message, one for
|
||||
each unique file position instance, sorted by file name and then
|
||||
by line. */
|
||||
size_t filepos_count;
|
||||
lex_pos_ty *filepos;
|
||||
|
||||
/* Informations from special comments (e.g. generated by msgmerge). */
|
||||
int is_fuzzy;
|
||||
enum is_c_format is_c_format;
|
||||
|
||||
/* Do we want the string to be wrapped in the emitted PO file? */
|
||||
enum is_c_format do_wrap;
|
||||
|
||||
/* The msgid string. */
|
||||
const char *msgid;
|
||||
|
||||
/* The msgstr strings, one for each observed domain in the file. */
|
||||
size_t variant_count;
|
||||
message_variant_ty *variant;
|
||||
|
||||
/* Used for checking that messages have been used, in the msgcmp and
|
||||
msgmerge programs. */
|
||||
int used;
|
||||
|
||||
/* If set the message is obsolete and while writing out it should be
|
||||
commented out. */
|
||||
int obsolete;
|
||||
};
|
||||
|
||||
typedef struct message_list_ty message_list_ty;
|
||||
struct message_list_ty
|
||||
{
|
||||
message_ty **item;
|
||||
size_t nitems;
|
||||
size_t nitems_max;
|
||||
};
|
||||
|
||||
#endif /* _H_RPMPO_ */
|
|
@ -0,0 +1,146 @@
|
|||
/* GNU gettext - internationalization aids
|
||||
Copyright (C) 1995, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This file was written by Peter Miller <millerp@canb.auug.org.au>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "str-list.h"
|
||||
|
||||
|
||||
string_list_ty *
|
||||
string_list_alloc ()
|
||||
{
|
||||
string_list_ty *slp;
|
||||
|
||||
slp = (string_list_ty *) xmalloc (sizeof (*slp));
|
||||
slp->item = NULL;
|
||||
slp->nitems = 0;
|
||||
slp->nitems_max = 0;
|
||||
|
||||
return slp;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
string_list_append (slp, s)
|
||||
string_list_ty *slp;
|
||||
const char *s;
|
||||
{
|
||||
/* Grow the list. */
|
||||
if (slp->nitems >= slp->nitems_max)
|
||||
{
|
||||
size_t nbytes;
|
||||
|
||||
slp->nitems_max = slp->nitems_max * 2 + 4;
|
||||
nbytes = slp->nitems_max * sizeof (slp->item[0]);
|
||||
slp->item = (const char **) xrealloc (slp->item, nbytes);
|
||||
}
|
||||
|
||||
/* Add a copy of the string to the end of the list. */
|
||||
slp->item[slp->nitems++] = xstrdup (s);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
string_list_append_unique (slp, s)
|
||||
string_list_ty *slp;
|
||||
const char *s;
|
||||
{
|
||||
size_t j;
|
||||
|
||||
/* Do not if the string is already in the list. */
|
||||
for (j = 0; j < slp->nitems; ++j)
|
||||
if (strcmp (slp->item[j], s) == 0)
|
||||
return;
|
||||
|
||||
/* Grow the list. */
|
||||
if (slp->nitems >= slp->nitems_max)
|
||||
{
|
||||
slp->nitems_max = slp->nitems_max * 2 + 4;
|
||||
slp->item = (const char **) xrealloc (slp->item,
|
||||
slp->nitems_max
|
||||
* sizeof (slp->item[0]));
|
||||
}
|
||||
|
||||
/* Add a copy of the string to the end of the list. */
|
||||
slp->item[slp->nitems++] = xstrdup (s);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
string_list_free (slp)
|
||||
string_list_ty *slp;
|
||||
{
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < slp->nitems; ++j)
|
||||
free ((char *) slp->item[j]);
|
||||
if (slp->item != NULL)
|
||||
free (slp->item);
|
||||
free (slp);
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
string_list_join (slp)
|
||||
const string_list_ty *slp;
|
||||
{
|
||||
size_t len;
|
||||
size_t j;
|
||||
char *result;
|
||||
size_t pos;
|
||||
|
||||
len = 1;
|
||||
for (j = 0; j < slp->nitems; ++j)
|
||||
{
|
||||
if (j)
|
||||
++len;
|
||||
len += strlen (slp->item[j]);
|
||||
}
|
||||
result = xmalloc (len);
|
||||
pos = 0;
|
||||
for (j = 0; j < slp->nitems; ++j)
|
||||
{
|
||||
if (j)
|
||||
result[pos++] = ' ';
|
||||
len = strlen (slp->item[j]);
|
||||
memcpy (result + pos, slp->item[j], len);
|
||||
pos += len;
|
||||
}
|
||||
result[pos] = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
string_list_member (slp, s)
|
||||
const string_list_ty *slp;
|
||||
const char *s;
|
||||
{
|
||||
size_t j;
|
||||
|
||||
for (j = 0; j < slp->nitems; ++j)
|
||||
if (strcmp (slp->item[j], s) == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/* GNU gettext - internationalization aids
|
||||
Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
|
||||
|
||||
This file was written by Peter Miller <millerp@canb.auug.org.au>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef SRC_STR_LIST_H
|
||||
#define SRC_STR_LIST_H 1
|
||||
|
||||
#ifdef STC_HEADERS
|
||||
# define __need_size_t
|
||||
# define __need_NULL
|
||||
# include <stddef.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
|
||||
/* Type describing list of strings implemented using a dynamic array. */
|
||||
typedef struct string_list_ty string_list_ty;
|
||||
struct string_list_ty
|
||||
{
|
||||
const char **item;
|
||||
size_t nitems;
|
||||
size_t nitems_max;
|
||||
};
|
||||
|
||||
|
||||
string_list_ty *string_list_alloc PARAMS ((void));
|
||||
void string_list_append PARAMS ((string_list_ty *__slp, const char *__s));
|
||||
void string_list_append_unique PARAMS ((string_list_ty *__slp,
|
||||
const char *__s));
|
||||
void string_list_free PARAMS ((string_list_ty *__slp));
|
||||
char *string_list_join PARAMS ((const string_list_ty *__slp));
|
||||
int string_list_member PARAMS ((const string_list_ty *__slp, const char *__s));
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue