summaryrefslogtreecommitdiff
path: root/src/xml/extract-strings.c
blob: 0c3d56b19f6ec7f3f99a1fe622eefe9e6ffc14f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Extract translation strings
 *
 * Copyright 2008 by Robert Krawitz.
 *
 * 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 of the License, 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.
 */

/*
 * Include necessary headers...
 */

#include <stdio.h>
#include <gutenprint/gutenprint.h>
#include <gutenprint/mxml.h>
#include "config.h"

int
main(int argc, char **argv)
{
  int status = 0;
  argv++;
  while (*argv)
    {
      stp_mxml_node_t *top =
	stp_mxmlLoadFromFile(NULL, *argv, STP_MXML_NO_CALLBACK);
      if (top)
	{
	  stp_mxml_node_t *n = top;
	  stp_string_list_t *sl = stp_string_list_create();
	  do
	    {
	      const char *attr = stp_mxmlElementGetAttr(n, "translate");
	      if (attr)
		{
		  const char *str = stp_mxmlElementGetAttr(n, attr);
		  if (! stp_string_list_is_present(sl, str))
		    {
		      char *s;
		      stp_string_list_add_string_unsafe(sl, str, str);
		      stp_asprintf(&s, "N_(\"%s\");", str);
		      printf("%-40s /* %s */\n", s, *argv);
		      stp_free(s);
		    }
		}
	      n = stp_mxmlWalkNext(n, top, STP_MXML_DESCEND);
	    } while (n);
	  stp_string_list_destroy(sl);
	  stp_mxmlDelete(top);
	}
      else
	{
	  fprintf(stderr, "Cannot read %s: %s\n", *argv, strerror(errno));
	  status = 1;
	}
      argv++;
    }
  return status;
}