This file is indexed.

/usr/share/gtk-doc/html/libtranslate/ch02s02.html is in libtranslate-dev 0.99-0ubuntu9.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Implementing Translation Services</title><meta name="generator" content="DocBook XSL Stylesheets V1.66.1"><link rel="start" href="index.html" title="libtranslate Reference Manual"><link rel="up" href="tutorials.html" title="Tutorials"><link rel="prev" href="tutorials.html" title="Tutorials"><link rel="next" href="api-reference.html" title="API Reference"><meta name="generator" content="GTK-Doc V1.2 (XML mode)"><style type="text/css">
        .synopsis, .classsynopsis {
            background: #eeeeee;
            border: solid 1px #aaaaaa;
            padding: 0.5em;
        }
        .programlisting {
            background: #eeeeff;
            border: solid 1px #aaaaff;
            padding: 0.5em;
        }
        .variablelist {
            padding: 4px;
            margin-left: 3em;
        }
        .navigation {
            background: #ffeeee;
            border: solid 1px #ffaaaa;
            margin-top: 0.5em;
            margin-bottom: 0.5em;
        }
        .navigation a {
            color: #770000;
        }
        .navigation a:visited {
            color: #550000;
        }
        .navigation .title {
            font-size: 200%;
        }
      </style></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="tutorials.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="tutorials.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">libtranslate Reference Manual</th><td><a accesskey="n" href="api-reference.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2534723"></a>Implementing Translation Services</h2></div></div></div><p>
	To implement a translation service, you need to create a
	subclass of <a href="TranslateService.html" title="TranslateService">TranslateService</a>, create an
	instance of your subclass with g_object_new(), and add the
	service using <a href="libtranslate-translate.html#translate-add-service">translate_add_service()</a>.
	</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Web-Based Services</h3><p>
	    If you are implementing support for a web-based service,
	    just adding a definition to the <tt class="filename">services.xml</tt>
	    file (without having to resort to C code) might be sufficient.
	    See the
	    <span class="citerefentry"><span class="refentrytitle">services.xml</span>(5)</span>
	    manual page.
	  </p></div><p>
      </p><div class="example"><a name="id2534834"></a><p class="title"><b>Example 2. A Simple Service for Reversing Text</b></p><p>
	  The following example demonstrates how to create an add-on
	  service for libtranslate, and compile it either as a module or as a
	  standalone application.
	</p><p>
	  The source code of this example is available in the libtranslate
	  source distribution
	  (<tt class="filename">docs/reference/example-service.c</tt>),
	  and is reproduced below.
	  To build a module on UNIX, compile the source as follows:
	  </p><pre class="programlisting">$ cc `pkg-config --cflags libtranslate` -shared -fPIC example-service.c -o example-service.so</pre><p>
	  To build a standalone application on UNIX, compile the
	  source as follows:
	  </p><pre class="programlisting">$ cc `pkg-config --cflags --libs libtranslate` -DSTANDALONE example-service.c -o example-service</pre><p>
	</p><pre class="programlisting">/*
 * Copyright (C) 2005 Jean-Yves Lefort
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of Jean-Yves Lefort nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include &lt;locale.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;gmodule.h&gt;
#include &lt;translate.h&gt;

#define REVERSE_TYPE_SERVICE		(reverse_service_get_type())

typedef struct
{
  TranslateService	parent;
} ReverseService;

typedef struct
{
  TranslateServiceClass	parent;
} ReverseServiceClass;

static gboolean
reverse_service_get_pairs (TranslateService *service,
			   GSList **pairs,
			   TranslateProgressFunc progress_func,
			   gpointer user_data,
			   GError **err)
{
  /* initialize the list */
  *pairs = NULL;

  /* add the English -&gt; English (reversed) pair */
  *pairs = g_slist_append(*pairs,
			  translate_pair_new(TRANSLATE_PAIR_TEXT,
					     "en", "en-x-rev"));

  /* add the English (reversed) -&gt; English pair */
  *pairs = g_slist_append(*pairs,
			  translate_pair_new(TRANSLATE_PAIR_TEXT,
					     "en-x-rev", "en"));

  return TRUE;			/* success */
}

static char *
reverse_service_translate_text (TranslateService *service,
				const char *text,
				const char *from,
				const char *to,
				TranslateProgressFunc progress_func,
				gpointer user_data,
				GError **err)
{
  return g_utf8_strreverse(text, -1);
}

static void
reverse_service_class_init (ReverseServiceClass *class)
{
  TranslateServiceClass *service_class = TRANSLATE_SERVICE_CLASS(class);
  
  service_class-&gt;get_pairs = reverse_service_get_pairs;
  service_class-&gt;translate_text = reverse_service_translate_text;
}

static void
reverse_service_register_type (GType *type)
{
  static const GTypeInfo info = {
    sizeof(ReverseServiceClass),
    NULL,
    NULL,
    (GClassInitFunc) reverse_service_class_init,
    NULL,
    NULL,
    sizeof(ReverseService),
    0,
    NULL
  };
  
  *type = g_type_register_static(TRANSLATE_TYPE_SERVICE,
				 "ReverseService",
				 &amp;info,
				 0);
}

static GType
reverse_service_get_type (void)
{
  static GType type;
  static GOnce once = G_ONCE_INIT;

  g_once(&amp;once, (GThreadFunc) reverse_service_register_type, &amp;type);

  return type;
}

static TranslateService *
reverse_service_new (void)
{
  return g_object_new(REVERSE_TYPE_SERVICE,
		      "name", "reverse",
		      "nick", "Reverse",
		      NULL);
}

static void
reverse_service_register_tag (void)
{
  /*
   * Register our en-x-rev custom tag. The tag name was chosen
   * according to rules specified in RFC 3066 section 2.2.
   *
   * Note that registering a language name is optional and has
   * aesthetical purposes only. If no name exists for a particular
   * tag, the tag itself will be used.
   */
  translate_add_language("en-x-rev", "English (reversed)");
}

#ifdef STANDALONE

int
main (int argc, char **argv)
{
  GError *err = NULL;
  GSList *services = NULL;
  TranslateSession *session;
  char *reversed;

  setlocale(LC_ALL, "");	/* use user's locale */

  if (argc != 2)
    {
      g_printerr("Usage: rev TEXT\n");
      exit(1);
    }
  
  /* initialize libtranslate */
  if (! translate_init(&amp;err))
    {
      g_printerr("Unable to initialize libtranslate: %s\n", err-&gt;message);
      g_error_free(err);
      exit(1);
    }

  /* register our custom tag */
  reverse_service_register_tag();

  /* create a session which will use our reverse service */
  services = g_slist_append(services, reverse_service_new());
  session = translate_session_new(services);
  g_slist_foreach(services, (GFunc) g_object_unref, NULL);
  g_slist_free(services);

  /* reverse the given text */
  reversed = translate_session_translate_text(session, argv[1], "en", "en-x-rev",
					      NULL, NULL, &amp;err);

  /* handle failure */
  if (! reversed)
    {
      g_printerr("Unable to reverse text: %s\n", err-&gt;message);
      g_error_free(err);
      exit(1);
    }

  /* success, print the reversed text, cleanup and exit */
  g_print("%s", reversed);
  g_free(reversed);
  g_object_unref(session);

  return 0;
}

#else /* ! STANDALONE */

G_MODULE_EXPORT gboolean
translate_module_init (GError **err)
{
  TranslateService *service;

  /* register our custom tag */
  reverse_service_register_tag();

  /* add the reverse service */
  service = reverse_service_new();
  translate_add_service(service);
  g_object_unref(service);

  return TRUE;			/* success */
}

#endif /* ! STANDALONE */
</pre></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="tutorials.html"><b>&lt;&lt; Tutorials</b></a></td><td align="right"><a accesskey="n" href="api-reference.html"><b>API Reference &gt;&gt;</b></a></td></tr></table></body></html>