]> git.pld-linux.org Git - packages/gettext.git/blob - gettext-dml.patch
added patch for parsing dml {{ }}. rel++
[packages/gettext.git] / gettext-dml.patch
1 diff -ur gettext-0.10.35/src/xgettext.c gettext-0.10.35-dml/src/xgettext.c
2 --- gettext-0.10.35/src/xgettext.c      Wed Apr 29 18:57:50 1998
3 +++ gettext-0.10.35-dml/src/xgettext.c  Sat Jan 13 00:40:22 2001
4 @@ -711,6 +711,195 @@
5    NULL, /* comment_special */
6  };
7  
8 +/* DML scanner */
9 +struct dml_parser_state {
10 +       FILE *in;
11 +       char *filename;
12 +       int line;
13 +       int close;
14 +       
15 +       char *buf;
16 +       int buflen, bufpos;
17 +       int seen;
18 +       message_list_ty *mlp;
19 +};
20 +
21 +static void
22 +dml_open_file(ctx)
23 +       struct dml_parser_state *ctx;
24 +{
25 +       size_t len1, len2;
26 +       int j;
27 +       const char *dir;
28 +       char *new_name;
29 +
30 +       ctx->line = 1;
31 +       ctx->close = 1;
32 +       ctx->buf = NULL;
33 +       ctx->buflen = 0;
34 +       ctx->bufpos = 0;
35 +
36 +       if (strcmp(ctx->filename, "-") == 0) {
37 +               ctx->filename = xstrdup(_("standard input"));
38 +               ctx->in = stdin;
39 +               ctx->close = 0;
40 +               return;
41 +       }
42 +       if (ctx->filename[0] == '/') {
43 +               ctx->in = fopen(ctx->filename, "r");
44 +               if (ctx->in == 0)
45 +                       error(EXIT_FAILURE, errno, _("\
46 +error while opening \"%s\" for reading"),
47 +                             ctx->filename);
48 +               ctx->filename = xstrdup(ctx->filename);
49 +               return;
50 +       }
51 +
52 +       len2 = strlen(ctx->filename);
53 +       for (j = 0;; ++j) {
54 +               dir = dir_list_nth(j);
55 +               if (dir == NULL)
56 +                       error(EXIT_FAILURE, ENOENT, _("\
57 +error while opening \"%s\" for reading"), ctx->filename);
58 +
59 +               if (dir[0] == '.' && dir[1] == '\0')
60 +                       new_name = xstrdup(ctx->filename);
61 +               else {
62 +                       len1 = strlen(dir);
63 +                       new_name = xmalloc(len1 + len2 + 2);
64 +                       stpcpy(stpcpy(stpcpy(new_name, dir), "/"), ctx->filename);
65 +               }
66 +
67 +               ctx->in = fopen(new_name, "r");
68 +               if (ctx->in != NULL)
69 +                       break;
70 +
71 +               if (errno != ENOENT)
72 +                       error(EXIT_FAILURE, errno, _("\
73 +error while opening \"%s\" for reading"), new_name);
74 +               free(new_name);
75 +       }
76 +       
77 +       ctx->filename = new_name;
78 +}
79 +
80 +static void dml_remember_a_message(ctx)
81 +       struct dml_parser_state *ctx;
82 +{
83 +       char *msgid;
84 +       message_ty *mp;
85 +       char *msgstr;
86 +
87 +       msgid = ctx->buf;
88 +
89 +       /* See whether we shall exclude this message.  */
90 +       if (exclude != NULL && message_list_search(exclude, msgid) != NULL)
91 +               return;
92 +
93 +       /* See if we have seen this message before.  */
94 +       mp = message_list_search(ctx->mlp, msgid);
95 +       if (mp == NULL) {
96 +               static lex_pos_ty pos = { __FILE__, __LINE__ };
97 +
98 +               /* Allocate a new message and append the message to the list.  */
99 +               mp = message_alloc(xstrdup(msgid));
100 +               /* Do not free msgid.  */
101 +               message_list_append(ctx->mlp, mp);
102 +
103 +               /* Construct the msgstr from the prefix and suffix, otherwise use the
104 +                  empty string.  */
105 +               if (msgstr_prefix) {
106 +                       msgstr = (char *) xmalloc(strlen(msgstr_prefix)
107 +                                                 + strlen(msgid)
108 +                                                 + strlen(msgstr_suffix) +
109 +                                                 1);
110 +                       stpcpy(stpcpy
111 +                              (stpcpy(msgstr, msgstr_prefix), msgid),
112 +                              msgstr_suffix);
113 +               } else
114 +                       msgstr = "";
115 +               message_variant_append(mp, MESSAGE_DOMAIN_DEFAULT, msgstr,
116 +                                      &pos);
117 +                                      
118 +               mp->is_c_format = no;
119 +               mp->do_wrap = yes;      /* By default we wrap. Is it ok?  */
120 +       }
121 +
122 +       /* Remember where we saw this msgid.  */
123 +       if (line_comment)
124 +               message_comment_filepos(mp, ctx->filename, ctx->line);
125 +}
126 +
127 +/* Read a string until '}}' is found. */
128 +static void
129 +dml_get_string(ctx)
130 +    struct dml_parser_state *ctx;
131 +{
132 +       int c, last_brace = 0;
133 +
134 +       ctx->seen = ctx->line;
135 +       ctx->bufpos = 0;
136 +       
137 +       for (;;) {
138 +               c = fgetc(ctx->in);
139 +               if (c == EOF)
140 +                       error(EXIT_FAILURE, 0, _("%s:%d: unmatched {{"), 
141 +                               ctx->filename, ctx->seen);
142 +               if (c == '\n')
143 +                       ctx->line++;
144 +                       
145 +               if (c == '}') {
146 +                       if (last_brace)
147 +                               break;
148 +                       last_brace = 1;
149 +               } else
150 +                       last_brace = 0;
151 +               if (ctx->bufpos == ctx->buflen) {
152 +                       if (ctx->buflen == 0)
153 +                               ctx->buflen = 128;
154 +                       ctx->buf = xrealloc(ctx->buf, ctx->buflen *= 2);
155 +               }
156 +               ctx->buf[ctx->bufpos++] = c;
157 +       }
158 +
159 +       /* remove last } */
160 +       ctx->buf[--ctx->bufpos] = 0;
161 +       dml_remember_a_message(ctx);
162 +}
163 +
164 +/* We don't really bother scanning the shell syntax.
165 +   We just hunt for strings in {{ }} 
166 +   */
167 +static void
168 +scanner_dml(filename, mlp)
169 +     char *filename;
170 +     message_list_ty *mlp;
171 +{
172 +       struct dml_parser_state ctx;
173 +       int c;
174 +
175 +       ctx.filename = filename;
176 +       ctx.mlp = mlp;
177 +       dml_open_file(&ctx);
178 +
179 +       for (;;) {
180 +               while ((c = fgetc(ctx.in)) != EOF) 
181 +                       if (c == '{' &&
182 +                           ((c = fgetc(ctx.in)) == EOF || c == '{'))
183 +                               break;
184 +                       else if (c == '\n')
185 +                               ctx.line++;
186 +                               
187 +               if (c == EOF)
188 +                       break;
189 +               dml_get_string(&ctx);
190 +       }
191 +
192 +       if (ctx.close)
193 +               fclose(ctx.in);
194 +       free(ctx.buf);
195 +       free(ctx.filename);
196 +}
197  
198  static void
199  read_exclusion_file (file_name)
200 @@ -1330,6 +1519,7 @@
201      { "C", scanner_c, },
202      { "C++", scanner_cxx, },
203      { "PO", read_po_file, },
204 +    { "DML", scanner_dml, },
205      /* Here will follow more languages and their scanners: awk, perl,
206         etc...  Make sure new scanners honor the --exlude-file option.  */
207    };
This page took 0.045451 seconds and 3 git commands to generate.