~ubuntu-branches/ubuntu/trusty/gettext/trusty

« back to all changes in this revision

Viewing changes to misc/tcl_gettext.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2002-04-10 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20020410131742-npf89tsaygdolprj
Tags: upstream-0.10.40
ImportĀ upstreamĀ versionĀ 0.10.40

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* tcl_gettext - Module implementing gettext interface for Tcl.
 
2
   Copyright (C) 1995, 1998 Free Software Foundation, Inc.
 
3
   Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, December 1995.
 
4
 
 
5
   This program is free software; you can redistribute it and/or modify
 
6
   it under the terms of the GNU General Public License as published by
 
7
   the Free Software Foundation; either version 2, or (at your option)
 
8
   any later version.
 
9
 
 
10
   This program is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
   GNU General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with this program; if not, write to the Free Software Foundation,
 
17
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
# include <config.h>
 
21
#endif
 
22
 
 
23
#include <libintl.h>
 
24
#include <locale.h>
 
25
#include <string.h>
 
26
 
 
27
/* Data for Tcl interpreter interface.  */
 
28
#include "tcl.h"
 
29
 
 
30
/* Prototypes for local functions.  */
 
31
static int
 
32
tcl_gettext (ClientData client_data, Tcl_Interp *interp, int argc,
 
33
             char *argv[]);
 
34
static int
 
35
tcl_textdomain (ClientData client_data, Tcl_Interp *interp, int argc,
 
36
                char *argv[]);
 
37
static int
 
38
tcl_bindtextdomain (ClientData client_data, Tcl_Interp *interp, int argc,
 
39
                    char *argv[]);
 
40
 
 
41
 
 
42
/* Initialization functions.  Called from the tclAppInit.c/tkAppInit.c
 
43
   or while the dynamic loading with Tcl7.x, x>= 5.  */
 
44
int
 
45
Gettext_Init (interp)
 
46
     Tcl_Interp *interp;
 
47
{
 
48
  Tcl_CreateCommand (interp, "gettext", tcl_gettext, (ClientData) 0,
 
49
                     (Tcl_CmdDeleteProc *) NULL);
 
50
  Tcl_CreateCommand (interp, "textdomain", tcl_textdomain, (ClientData) 0,
 
51
                     (Tcl_CmdDeleteProc *) NULL);
 
52
  Tcl_CreateCommand (interp, "bindtextdomain", tcl_bindtextdomain,
 
53
                     (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
 
54
 
 
55
  return TCL_OK;
 
56
}
 
57
 
 
58
 
 
59
static int
 
60
tcl_gettext (client_data, interp, argc, argv)
 
61
     ClientData client_data;
 
62
     Tcl_Interp *interp;
 
63
     int argc;
 
64
     char *argv[];
 
65
{
 
66
  const char *domainname = NULL;
 
67
  int category = LC_MESSAGES;
 
68
  const char *msgid;
 
69
 
 
70
  /* The pointer which is assigned in the following statement might
 
71
     reference an invalid part of the address space.  But we don't use
 
72
     this value before we know the pointer is correct.  */
 
73
  msgid = argv[1];
 
74
 
 
75
  switch (argc)
 
76
    {
 
77
    case 4:
 
78
#ifdef LC_CTYPE
 
79
      if (strcmp (argv[3], "LC_CTYPE") == 0)
 
80
        category = LC_CTYPE;
 
81
      else
 
82
#endif
 
83
#ifdef LC_COLLATE
 
84
        if (strcmp (argv[3], "LC_COLLATE") == 0)
 
85
          category = LC_COLLATE;
 
86
        else
 
87
#endif
 
88
#ifdef LC_MESSAGES
 
89
          if (strcmp (argv[3], "LC_MESSAGES") == 0)
 
90
            category = LC_MESSAGES;
 
91
          else
 
92
#endif
 
93
#ifdef LC_MONETARY
 
94
            if (strcmp (argv[3], "LC_MONETARY") == 0)
 
95
              category = LC_MONETARY;
 
96
            else
 
97
#endif
 
98
#ifdef LC_NUMERIC
 
99
              if (strcmp (argv[3], "LC_NUMERIC") == 0)
 
100
                category = LC_NUMERIC;
 
101
              else
 
102
#endif
 
103
#ifdef LC_TIME
 
104
                if (strcmp (argv[3], "LC_TIME") == 0)
 
105
                  category = LC_TIME;
 
106
                else
 
107
#endif
 
108
                  {
 
109
                    interp->result = gettext ("invalid third argument");
 
110
                    return TCL_ERROR;
 
111
                  }
 
112
      /* FALLTHROUGH */
 
113
 
 
114
    case 3:
 
115
      domainname = argv[1];
 
116
      msgid = argv[2];
 
117
      /* FALLTHROUGH */
 
118
 
 
119
    case 2:
 
120
      interp->result = dcgettext (domainname, msgid, category);
 
121
      break;
 
122
 
 
123
    default:
 
124
      interp->result = gettext ("wrong number of arguments");
 
125
      return TCL_ERROR;
 
126
    }
 
127
 
 
128
  return TCL_OK;
 
129
}
 
130
 
 
131
 
 
132
static int
 
133
tcl_textdomain (client_data, interp, argc, argv)
 
134
     ClientData client_data;
 
135
     Tcl_Interp *interp;
 
136
     int argc;
 
137
     char *argv[];
 
138
{
 
139
  if (argc != 2)
 
140
    {
 
141
      interp->result = gettext ("wrong number of arguments");
 
142
      return TCL_ERROR;
 
143
    }
 
144
 
 
145
  interp->result = textdomain (argv[1]);
 
146
 
 
147
  return TCL_OK;
 
148
}
 
149
 
 
150
 
 
151
static int
 
152
tcl_bindtextdomain (client_data, interp, argc, argv)
 
153
     ClientData client_data;
 
154
     Tcl_Interp *interp;
 
155
     int argc;
 
156
     char *argv[];
 
157
{
 
158
  if (argc != 3)
 
159
    {
 
160
      interp->result = gettext ("wrong number of arguments");
 
161
      return TCL_ERROR;
 
162
    }
 
163
 
 
164
  return bindtextdomain (argv[1], argv[2]) == NULL ? TCL_ERROR : TCL_OK;
 
165
}