Tue Aug 17 13:53:45 2004 Jonathan Blandford <jrb@redhat.com>
[jelmer/krb5-auth-dialog.git] / etpo / grammar.y
1 %{
2 /*
3  * Copyright (C) 2004 Red Hat, Inc.
4  *
5  * This is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Library General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 #include "config.h"
20 #include <glib.h>
21 static const char *table = "unknown";
22 extern const char *currentfile;
23 %}
24 %union {
25         char *sval;
26         int ival;
27 }
28 %token ERROR_TABLE_START
29 %token ERROR_TABLE_END
30 %token ERROR_CODE_START
31 %token COMMA
32 %token QUOTE
33 %token <sval>EMPTY
34 %token <sval>TOKEN
35 %token <sval>LITERAL
36 %type  <sval>literal
37 %%
38 statements: statement | statements statement ;
39 statement: table_start | error_code | table_end ;
40 table_start: ERROR_TABLE_START TOKEN { table = $2; };
41 literal: literal LITERAL { $$ = g_strconcat($1, $2, NULL);} | LITERAL;
42 error_code: ERROR_CODE_START TOKEN COMMA QUOTE literal QUOTE {
43                 {
44                         gchar **lines;
45                         int i;
46                         const char *p;
47                         /* Find the basename of the current file. */
48                         if (strchr(currentfile, '/') != NULL) {
49                                 p = strrchr(currentfile, '/') + 1;
50                         } else {
51                                 p = currentfile;
52                         }
53                         printf("\n# %s:%s:%s\n", p, table, $2);
54                         /* If the string doesn't contain a newline, just print
55                          * it on a single line. */
56                         if (strchr($5, '\n') == NULL) {
57                                 printf("msgid \"%s\"\n", $5);
58                         } else {
59                                 /* Split the string up along newline
60                                  * boundaries, for readability. */
61                                 lines = g_strsplit($5, "\n", -1);
62                                 if (lines != NULL) {
63                                         printf("msgid \n");
64                                         for (i = 0; lines[i] != NULL; i++) {
65                                                 printf("\"%s\"\n", lines[i]);
66                                         }
67                                         g_strfreev(lines);
68                                 }
69                         }
70                         /* Output the template translation. */
71                         printf("msgstr \"\"\n");
72                 }
73         } |
74         ERROR_CODE_START TOKEN COMMA QUOTE QUOTE {
75         };
76 table_end: ERROR_TABLE_END { table = "unknown"; };