1/*
2 * XXX.c --
3 *
4 *	Implements and registers conversion from and to XXX representation.
5 *
6 *
7 * Copyright (c) 1995 Andreas Kupries (a.kupries@westend.com)
8 * All rights reserved.
9 *
10 * Permission is hereby granted, without written agreement and without
11 * license or royalty fees, to use, copy, modify, and distribute this
12 * software and its documentation for any purpose, provided that the
13 * above copyright notice and the following two paragraphs appear in
14 * all copies of this software.
15 *
16 * IN NO EVENT SHALL I LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
17 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
18 * SOFTWARE AND ITS DOCUMENTATION, EVEN IF I HAVE BEEN ADVISED OF THE
19 * POSSIBILITY OF SUCH DAMAGE.
20 *
21 * I SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
24 * I HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
25 * ENHANCEMENTS, OR MODIFICATIONS.
26 *
27 * CVS: $Id: cvt_template.c,v 1.3 2009/05/07 04:57:27 andreas_kupries Exp $
28 */
29
30#include "transformInt.h"
31
32/*
33 * Converter description
34 * ---------------------
35 */
36
37
38/*
39 * Declarations of internal procedures.
40 */
41
42static Trf_ControlBlock CreateEncoder  _ANSI_ARGS_ ((ClientData writeClientData,
43						     Trf_WriteProc fun,
44						     Trf_Options optInfo,
45						     Tcl_Interp*   interp,
46						     ClientData clientData));
47static void             DeleteEncoder  _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
48						     ClientData clientData));
49static int              Encode         _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
50						     int character,
51						     Tcl_Interp* interp,
52						     ClientData clientData));
53static int              EncodeBuffer   _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
54						     unsigned char* buffer, int bufLen,
55						     Tcl_Interp* interp,
56						     ClientData clientData));
57static int              FlushEncoder   _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
58						     Tcl_Interp* interp,
59						     ClientData clientData));
60static void             ClearEncoder   _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
61						     ClientData clientData));
62
63static Trf_ControlBlock CreateDecoder  _ANSI_ARGS_ ((ClientData writeClientData,
64						     Trf_WriteProc fun,
65						     Trf_Options optInfo,
66						     Tcl_Interp*   interp,
67						     ClientData clientData));
68static void             DeleteDecoder  _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
69						     ClientData clientData));
70static int              Decode         _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
71						     int character,
72						     Tcl_Interp* interp,
73						     ClientData clientData));
74static int              DecodeBuffer   _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
75						     unsigned char* buffer, int bufLen,
76						     Tcl_Interp* interp,
77						     ClientData clientData));
78static int              FlushDecoder   _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
79						     Tcl_Interp* interp,
80						     ClientData clientData));
81static void             ClearDecoder   _ANSI_ARGS_ ((Trf_ControlBlock ctrlBlock,
82						     ClientData clientData));
83
84
85/*
86 * Converter definition.
87 */
88
89static Trf_TypeDefinition convDefinition =
90{
91  "XXX",
92  NULL, /* filled later (TrfInit_XXX) */
93  NULL, /* filled later (TrfInit_XXX) */
94  {
95    CreateEncoder,
96    DeleteEncoder,
97    Encode,
98    EncodeBuffer,
99    FlushEncoder,
100    ClearEncoder
101  }, {
102    CreateDecoder,
103    DeleteDecoder,
104    Decode,
105    DecodeBuffer,
106    FlushDecoder,
107    ClearDecoder
108  }
109};
110
111/*
112 * Definition of the control blocks for en- and decoder.
113 */
114
115typedef struct _EncoderControl_ {
116  Trf_WriteProc* write;
117  ClientData     writeClientData;
118
119  /* add conversion specific items here (XXX) */
120
121} EncoderControl;
122
123
124typedef struct _DecoderControl_ {
125  Trf_WriteProc* write;
126  ClientData     writeClientData;
127
128  /* add conversion specific items here (XXX) */
129
130} DecoderControl;
131
132
133
134
135/*
136 *------------------------------------------------------*
137 *
138 *	TrfInit_XXX --
139 *
140 *	------------------------------------------------*
141 *	Register the conversion implemented in this file.
142 *	------------------------------------------------*
143 *
144 *	Sideeffects:
145 *		As of 'Trf_Register'.
146 *
147 *	Result:
148 *		A standard Tcl error code.
149 *
150 *------------------------------------------------------*
151 */
152
153int
154TrfInit_XXX (interp)
155Tcl_Interp* interp;
156{
157  convDefinition.options = TrfYYYOptions ();
158
159  return Trf_Register (interp, &convDefinition);
160}
161
162/*
163 *------------------------------------------------------*
164 *
165 *	CreateEncoder --
166 *
167 *	------------------------------------------------*
168 *	Allocate and initialize the control block of a
169 *	data encoder.
170 *	------------------------------------------------*
171 *
172 *	Sideeffects:
173 *		Allocates memory.
174 *
175 *	Result:
176 *		An opaque reference to the control block.
177 *
178 *------------------------------------------------------*
179 */
180
181static Trf_ControlBlock
182CreateEncoder (writeClientData, fun, optInfo, interp, clientData)
183ClientData    writeClientData;
184Trf_WriteProc fun;
185Trf_Options   optInfo;
186Tcl_Interp*   interp;
187ClientData clientData;
188{
189  EncoderControl* c;
190
191  c = (EncoderControl*) ckalloc (sizeof (EncoderControl));
192  c->write           = fun;
193  c->writeClientData = writeClientData;
194
195  /* initialize conversion specific items here (XXX) */
196
197  return (ClientData) c;
198}
199
200/*
201 *------------------------------------------------------*
202 *
203 *	DeleteEncoder --
204 *
205 *	------------------------------------------------*
206 *	Destroy the control block of an encoder.
207 *	------------------------------------------------*
208 *
209 *	Sideeffects:
210 *		Releases the memory allocated by 'CreateEncoder'
211 *
212 *	Result:
213 *		None.
214 *
215 *------------------------------------------------------*
216 */
217
218static void
219DeleteEncoder (ctrlBlock, clientData)
220Trf_ControlBlock ctrlBlock;
221ClientData clientData;
222{
223  EncoderControl* c = (EncoderControl*) ctrlBlock;
224
225  /* release conversion specific items here (XXX) */
226
227  ckfree ((char*) c);
228}
229
230/*
231 *------------------------------------------------------*
232 *
233 *	Encode --
234 *
235 *	------------------------------------------------*
236 *	Encode the given character and write the result.
237 *	------------------------------------------------*
238 *
239 *	Sideeffects:
240 *		As of the called WriteFun.
241 *
242 *	Result:
243 *		Generated bytes implicitly via WriteFun.
244 *		A standard Tcl error code.
245 *
246 *------------------------------------------------------*
247 */
248
249static int
250Encode (ctrlBlock, character, interp, clientData)
251Trf_ControlBlock ctrlBlock;
252int character;
253Tcl_Interp* interp;
254ClientData clientData;
255{
256  EncoderControl* c = (EncoderControl*) ctrlBlock;
257
258  /* execute conversion specific code here (XXX) */
259}
260
261/*
262 *------------------------------------------------------*
263 *
264 *	EncodeBuffer --
265 *
266 *	------------------------------------------------*
267 *	Encode the given buffer and write the result.
268 *	------------------------------------------------*
269 *
270 *	Sideeffects:
271 *		As of the called WriteFun.
272 *
273 *	Result:
274 *		Generated bytes implicitly via WriteFun.
275 *		A standard Tcl error code.
276 *
277 *------------------------------------------------------*
278 */
279
280static int
281EncodeBuffer (ctrlBlock, buffer, bufLen, interp, clientData)
282Trf_ControlBlock ctrlBlock;
283unsigned char* buffer;
284int bufLen;
285Tcl_Interp* interp;
286ClientData clientData;
287{
288  EncoderControl* c = (EncoderControl*) ctrlBlock;
289
290  /* execute conversion specific code here (XXX) */
291}
292
293/*
294 *------------------------------------------------------*
295 *
296 *	FlushEncoder --
297 *
298 *	------------------------------------------------*
299 *	Encode an incomplete character sequence (if possible).
300 *	------------------------------------------------*
301 *
302 *	Sideeffects:
303 *		As of the called WriteFun.
304 *
305 *	Result:
306 *		Generated bytes implicitly via WriteFun.
307 *		A standard Tcl error code.
308 *
309 *------------------------------------------------------*
310 */
311
312static int
313FlushEncoder (ctrlBlock, interp, clientData)
314Trf_ControlBlock ctrlBlock;
315Tcl_Interp* interp;
316ClientData clientData;
317{
318  EncoderControl* c = (EncoderControl*) ctrlBlock;
319
320  /* execute conversion specific code here (XXX) */
321}
322
323/*
324 *------------------------------------------------------*
325 *
326 *	ClearEncoder --
327 *
328 *	------------------------------------------------*
329 *	Discard an incomplete character sequence.
330 *	------------------------------------------------*
331 *
332 *	Sideeffects:
333 *		See above.
334 *
335 *	Result:
336 *		None.
337 *
338 *------------------------------------------------------*
339 */
340
341static void
342ClearEncoder (ctrlBlock, clientData)
343Trf_ControlBlock ctrlBlock;
344ClientData clientData;
345{
346  EncoderControl* c = (EncoderControl*) ctrlBlock;
347
348  /* execute conversion specific code here (XXX) */
349}
350
351/*
352 *------------------------------------------------------*
353 *
354 *	CreateDecoder --
355 *
356 *	------------------------------------------------*
357 *	Allocate and initialize the control block of a
358 *	data decoder.
359 *	------------------------------------------------*
360 *
361 *	Sideeffects:
362 *		Allocates memory.
363 *
364 *	Result:
365 *		An opaque reference to the control block.
366 *
367 *------------------------------------------------------*
368 */
369
370static Trf_ControlBlock
371CreateDecoder (writeClientData, fun, optInfo, interp, clientData)
372ClientData    writeClientData;
373Trf_WriteProc fun;
374Trf_Options   optInfo;
375Tcl_Interp*   interp;
376ClientData clientData;
377{
378  DecoderControl* c;
379
380  c = (DecoderControl*) ckalloc (sizeof (DecoderControl));
381  c->write           = fun;
382  c->writeClientData = writeClientData;
383
384  /* initialize conversion specific items here (XXX) */
385
386  return (ClientData) c;
387}
388
389/*
390 *------------------------------------------------------*
391 *
392 *	DeleteDecoder --
393 *
394 *	------------------------------------------------*
395 *	Destroy the control block of an decoder.
396 *	------------------------------------------------*
397 *
398 *	Sideeffects:
399 *		Releases the memory allocated by 'CreateDecoder'
400 *
401 *	Result:
402 *		None.
403 *
404 *------------------------------------------------------*
405 */
406
407static void
408DeleteDecoder (ctrlBlock, clientData)
409Trf_ControlBlock ctrlBlock;
410ClientData clientData;
411{
412  DecoderControl* c = (DecoderControl*) ctrlBlock;
413
414  /* release conversion specific items here (XXX) */
415
416  ckfree ((char*) c);
417}
418
419/*
420 *------------------------------------------------------*
421 *
422 *	Decode --
423 *
424 *	------------------------------------------------*
425 *	Decode the given character and write the result.
426 *	------------------------------------------------*
427 *
428 *	Sideeffects:
429 *		As of the called WriteFun.
430 *
431 *	Result:
432 *		Generated bytes implicitly via WriteFun.
433 *		A standard Tcl error code.
434 *
435 *------------------------------------------------------*
436 */
437
438static int
439Decode (ctrlBlock, character, interp, clientData)
440Trf_ControlBlock ctrlBlock;
441int character;
442Tcl_Interp* interp;
443ClientData clientData;
444{
445  DecoderControl* c = (DecoderControl*) ctrlBlock;
446
447  /* execute conversion specific code here (XXX) */
448}
449
450/*
451 *------------------------------------------------------*
452 *
453 *	DecodeBuffer --
454 *
455 *	------------------------------------------------*
456 *	Decode the given buffer and write the result.
457 *	------------------------------------------------*
458 *
459 *	Sideeffects:
460 *		As of the called WriteFun.
461 *
462 *	Result:
463 *		Generated bytes implicitly via WriteFun.
464 *		A standard Tcl error code.
465 *
466 *------------------------------------------------------*
467 */
468
469static int
470DecodeBuffer (ctrlBlock, buffer, bufLen, interp, clientData)
471Trf_ControlBlock ctrlBlock;
472unsigned char* buffer;
473int bufLen;
474Tcl_Interp* interp;
475ClientData clientData;
476{
477  DecoderControl* c = (DecoderControl*) ctrlBlock;
478
479  /* execute conversion specific code here (XXX) */
480}
481
482/*
483 *------------------------------------------------------*
484 *
485 *	FlushDecoder --
486 *
487 *	------------------------------------------------*
488 *	Decode an incomplete character sequence (if possible).
489 *	------------------------------------------------*
490 *
491 *	Sideeffects:
492 *		As of the called WriteFun.
493 *
494 *	Result:
495 *		Generated bytes implicitly via WriteFun.
496 *		A standard Tcl error code.
497 *
498 *------------------------------------------------------*
499 */
500
501static int
502FlushDecoder (ctrlBlock, interp, clientData)
503Trf_ControlBlock ctrlBlock;
504Tcl_Interp* interp;
505ClientData clientData;
506{
507  DecoderControl* c = (DecoderControl*) ctrlBlock;
508
509  /* execute conversion specific code here (XXX) */
510}
511
512/*
513 *------------------------------------------------------*
514 *
515 *	ClearDecoder --
516 *
517 *	------------------------------------------------*
518 *	Discard an incomplete character sequence.
519 *	------------------------------------------------*
520 *
521 *	Sideeffects:
522 *		See above.
523 *
524 *	Result:
525 *		None.
526 *
527 *------------------------------------------------------*
528 */
529
530static void
531ClearDecoder (ctrlBlock, clientData)
532Trf_ControlBlock ctrlBlock;
533ClientData clientData;
534{
535  DecoderControl* c = (DecoderControl*) ctrlBlock;
536
537  /* execute conversion specific code here (XXX) */
538}
539
540