|
root / base / usr / src / cmd / geniconvtbl / samples
samples Plain Text 806 lines 16.6 KB
  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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
// ident	"%Z%%M%	%I%	%E% SMI"
// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
// Use is subject to license terms.
//
// CDDL HEADER START
//
// The contents of this file are subject to the terms of the
// Common Development and Distribution License, Version 1.0 only
// (the "License").  You may not use this file except in compliance
// with the License.
//
// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
// or http://www.opensolaris.org/os/licensing.
// See the License for the specific language governing permissions
// and limitations under the License.
//
// When distributing Covered Code, include this CDDL HEADER in each
// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
// If applicable, add the following below this CDDL HEADER, with the
// fields enclosed by brackets "[]" replaced with your own identifying
// information: Portions Copyright [yyyy] [name of copyright owner]
//
// CDDL HEADER END
//

//
// ISO-2022-JP to eucJP
//

#include <sys/errno.h>

ISO-2022-JP%eucJP {
	operation init {
		cs = 0;
	};

	operation reset {
		if (cs != 0) {
			// Emit state reset sequence, ESC ( J, for
			// ISO-2022-JP.
			output = 0x1b284a;
		}
		operation init;
	};

	direction {
		condition {		// JIS X 0201 Latin (ASCII)
			between	0x00...0x7f;
		} operation {
			if (cs != 0) {
				// We will emit four bytes.
				if (outputsize <= 3) {
					error E2BIG;
				}
				// Emit state reset sequence, ESC ( J.
				output = 0x1b284a;
				cs = 0;
			} else {
				if (outputsize <= 0) {
					error E2BIG;
				}
			}
			output = input[0];

			// Move input buffer pointer one byte.
			discard;
		};

		condition {		// JIS X 0208
			between	0xa1a1...0xfefe;
		} operation {
			if (cs != 1) {
				if (outputsize <= 4) {
					error E2BIG;
				}
				// Emit JIS X 0208 sequence, ESC $ B.
				output = 0x1b2442;
				cs = 1;
			} else {
				if (outputsize <= 1) {
					error E2BIG;
				}
			}
			output = (input[0] & 0x7f);
			output = (input[1] & 0x7f);

			// Move input buffer pointer two bytes.
			discard 2;
		};

		condition {		// JIS X 0201 Kana
			between	0x8ea1...0x8edf;
		} operation {
			if (cs != 2) {
				if (outputsize <= 3) {
					error E2BIG;
				}
				// Emit JIS X 0201 Kana sequence,
				// ESC ( I.
				output = 0x1b2849;
				cs = 2;
			} else {
				if (outputsize <= 0) {
					error E2BIG;
				}
			}
			output = (input[1] & 127);

			// Move input buffer pointer two bytes.
			discard 2;
		};

		condition {		// JIS X 0212
			between	0x8fa1a1...0x8ffefe;
		} operation {
			if (cs != 3) {
				if (outputsize <= 5) {
					error E2BIG;
				}
				// Emit JIS X 0212 sequence, ESC $ ( D.
				output = 0x1b242844;
				cs = 3;
			} else {
				if (outputsize <= 1) {
					error E2BIG;
				}
			}
			output = (input[1] & 127);
			output = (input[2] & 127);
			discard 3;
		};
	
		true	operation {	// error
			error EILSEQ;
		};
	};
}
// ident	"%Z%%M%	%I%	%E% SMI"
// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
// Use is subject to license terms.
//
// CDDL HEADER START
//
// The contents of this file are subject to the terms of the
// Common Development and Distribution License, Version 1.0 only
// (the "License").  You may not use this file except in compliance
// with the License.
//
// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
// or http://www.opensolaris.org/os/licensing.
// See the License for the specific language governing permissions
// and limitations under the License.
//
// When distributing Covered Code, include this CDDL HEADER in each
// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
// If applicable, add the following below this CDDL HEADER, with the
// fields enclosed by brackets "[]" replaced with your own identifying
// information: Portions Copyright [yyyy] [name of copyright owner]
//
// CDDL HEADER END
//

//
// from ISO646 to ISO8859-1
//

ISO646%ISO8859_1 {
	map {
		0x00...0x7f	0x00
		// default error
		// if no input sequence match, it occur EILSEQ.
	};
}
// ident	"%Z%%M%	%I%	%E% SMI"
// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
// Use is subject to license terms.
//
// CDDL HEADER START
//
// The contents of this file are subject to the terms of the
// Common Development and Distribution License, Version 1.0 only
// (the "License").  You may not use this file except in compliance
// with the License.
//
// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
// or http://www.opensolaris.org/os/licensing.
// See the License for the specific language governing permissions
// and limitations under the License.
//
// When distributing Covered Code, include this CDDL HEADER in each
// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
// If applicable, add the following below this CDDL HEADER, with the
// fields enclosed by brackets "[]" replaced with your own identifying
// information: Portions Copyright [yyyy] [name of copyright owner]
//
// CDDL HEADER END
//

//
// from  ISO8859-1 to ISO646
//

ISO8859_1%ISO646 {
	map {
		default		0x3f
		0x00...0x7f	0x00
	};
}
// ident	"%Z%%M%	%I%	%E% SMI"
// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
// Use is subject to license terms.
//
// CDDL HEADER START
//
// The contents of this file are subject to the terms of the
// Common Development and Distribution License, Version 1.0 only
// (the "License").  You may not use this file except in compliance
// with the License.
//
// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
// or http://www.opensolaris.org/os/licensing.
// See the License for the specific language governing permissions
// and limitations under the License.
//
// When distributing Covered Code, include this CDDL HEADER in each
// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
// If applicable, add the following below this CDDL HEADER, with the
// fields enclosed by brackets "[]" replaced with your own identifying
// information: Portions Copyright [yyyy] [name of copyright owner]
//
// CDDL HEADER END
//

//
// ISO8859-1 to UTF-8 mapping:
//

ISO8859-1%UTF-8 {
    direction {
	condition {
		between 0x0...0x7f;
	} map {
		0x0...0x7f	0x0
	};
	condition {
		between 0x80...0xff;
	} map {
		0x80		0xc280
		0x81		0xc281
		0x82		0xc282
		0x83		0xc283
		0x84		0xc284
		0x85		0xc285
		0x86		0xc286
		0x87		0xc287
		0x88		0xc288
		0x89		0xc289
		0x8a		0xc28a
		0x8b		0xc28b
		0x8c		0xc28c
		0x8d		0xc28d
		0x8e		0xc28e
		0x8f		0xc28f
		0x90		0xc290
		0x91		0xc291
		0x92		0xc292
		0x93		0xc293
		0x94		0xc294
		0x95		0xc295
		0x96		0xc296
		0x97		0xc297
		0x98		0xc298
		0x99		0xc299
		0x9a		0xc29a
		0x9b		0xc29b
		0x9c		0xc29c
		0x9d		0xc29d
		0x9e		0xc29e
		0x9f		0xc29f
		0xa0		0xc2a0
		0xa1		0xc2a1
		0xa2		0xc2a2
		0xa3		0xc2a3
		0xa4		0xc2a4
		0xa5		0xc2a5
		0xa6		0xc2a6
		0xa7		0xc2a7
		0xa8		0xc2a8
		0xa9		0xc2a9
		0xaa		0xc2aa
		0xab		0xc2ab
		0xac		0xc2ac
		0xad		0xc2ad
		0xae		0xc2ae
		0xaf		0xc2af
		0xb0		0xc2b0
		0xb1		0xc2b1
		0xb2		0xc2b2
		0xb3		0xc2b3
		0xb4		0xc2b4
		0xb5		0xc2b5
		0xb6		0xc2b6
		0xb7		0xc2b7
		0xb8		0xc2b8
		0xb9		0xc2b9
		0xba		0xc2ba
		0xbb		0xc2bb
		0xbc		0xc2bc
		0xbd		0xc2bd
		0xbe		0xc2be
		0xbf		0xc2bf
		0xc0		0xc380
		0xc1		0xc381
		0xc2		0xc382
		0xc3		0xc383
		0xc4		0xc384
		0xc5		0xc385
		0xc6		0xc386
		0xc7		0xc387
		0xc8		0xc388
		0xc9		0xc389
		0xca		0xc38a
		0xcb		0xc38b
		0xcc		0xc38c
		0xcd		0xc38d
		0xce		0xc38e
		0xcf		0xc38f
		0xd0		0xc390
		0xd1		0xc391
		0xd2		0xc392
		0xd3		0xc393
		0xd4		0xc394
		0xd5		0xc395
		0xd6		0xc396
		0xd7		0xc397
		0xd8		0xc398
		0xd9		0xc399
		0xda		0xc39a
		0xdb		0xc39b
		0xdc		0xc39c
		0xdd		0xc39d
		0xde		0xc39e
		0xdf		0xc39f
		0xe0		0xc3a0
		0xe1		0xc3a1
		0xe2		0xc3a2
		0xe3		0xc3a3
		0xe4		0xc3a4
		0xe5		0xc3a5
		0xe6		0xc3a6
		0xe7		0xc3a7
		0xe8		0xc3a8
		0xe9		0xc3a9
		0xea		0xc3aa
		0xeb		0xc3ab
		0xec		0xc3ac
		0xed		0xc3ad
		0xee		0xc3ae
		0xef		0xc3af
		0xf0		0xc3b0
		0xf1		0xc3b1
		0xf2		0xc3b2
		0xf3		0xc3b3
		0xf4		0xc3b4
		0xf5		0xc3b5
		0xf6		0xc3b6
		0xf7		0xc3b7
		0xf8		0xc3b8
		0xf9		0xc3b9
		0xfa		0xc3ba
		0xfb		0xc3bb
		0xfc		0xc3bc
		0xfd		0xc3bd
		0xfe		0xc3be
		0xff		0xc3bf
	};
  };
}
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

INPUTFILES = ISO8859-1_to_UTF-8.src UTF-8_to_ISO8859-1.src\
		eucJP_to_ISO-2022-JP.src ISO-2022-JP_to_eucJP.src \
		ISO646_to_ISO8859-1.src ISO8859-1_to_ISO646.src

OUTPUTFILES	= ISO646%ISO8859-1.bt ISO8859-1%ISO646.bt
# ONLY TWO binarytables are deliverables

#		ISO8859-1%UTF-8.bt UTF-8%ISO8859-1.bt
#		eucJP%ISO-2022-JP.bt ISO-2022-JP%eucJP.bt \
#		ISO646%ISO8859-1.bt ISO8859-1%ISO646.bt
# OUTPUTFILES	= $(INPUTFILES:%.src=%.bt)   NEVER USE ( WATCH OUT FILE NAME )

# include ../../../lib/Makefile.lib
include ../../Makefile.cmd


ROOTICONVDIRS	=	$(ROOTLIB)/iconv
ROOTDIRS	=	$(ROOTICONVDIRS)/geniconvtbl
SRCSDIRS	=	$(ROOTDIRS)/srcs
BTSDIRS		=	$(ROOTDIRS)/binarytables
ROOTINPUTFILES	=	$(INPUTFILES:%=$(SRCSDIRS)/%)
ROOTOUTPUTFILES =	$(OUTPUTFILES:%=$(BTSDIRS)/%)

$(ROOTINPUTFILES) :	FILEMODE = 444
$(ROOTOUTPUTFILES) :	FILEMODE = 444


.KEEP_STATE:

.PARALLEL: $(OUTPUTFILES)


all:	$(OUTPUTFILES)

install: all $(ROOTOUTPUTFILES) $(ROOTINPUTFILES)

clean clobber:
	$(RM) $(OUTPUTFILES)


ISO8859-1%UTF-8.bt: ISO8859-1_to_UTF-8.src
	$(GENICONVTBL) -o $@ -f ISO8859-1_to_UTF-8.src

UTF-8%ISO8859_1.bt: UTF-8_to_ISO8859_1.src
	$(GENICONVTBL) -o $@ -f UTF-8_to_ISO8859_1.src

eucJP%ISO-2022-JP.bt: eucJP_to_ISO-2022-JP.src
	$(GENICONVTBL) -o $@ -f eucJP_to_ISO-2022-JP.src

ISO-2022-JP%eucJP.bt: ISO-2022-JP_to_eucJP.src
	$(GENICONVTBL) -o $@ -f ISO-2022-JP_to_eucJP.src

ISO646%ISO8859-1.bt: ISO646_to_ISO8859-1.src
	$(GENICONVTBL) -o $@ -f ISO646_to_ISO8859-1.src

ISO8859-1%ISO646.bt: ISO8859-1_to_ISO646.src
	$(GENICONVTBL) -o $@ -f ISO8859-1_to_ISO646.src


# install rule
#
$(SRCSDIRS)/%: % $(SRCSDIRS)
	$(INS.file)

$(BTSDIRS)/%: % $(BTSDIRS)
	$(INS.file)

$(SRCSDIRS) $(BTSDIRS): $(ROOTDIRS)
	$(INS.dir)

$(ROOTDIRS): $(ROOTICONVDIRS)
	$(INS.dir)

$(ROOTICONVDIRS):
	$(INS.dir)

$(SRCSDIRS)/%: $(SRCSDIRS) %
	$(INS.file)

$(BTSDIRS)/%: $(BTSDIRS) %
	$(INS.file)

# rule of making BinaryTable
# ( must be placed after install rule )
#
# .SUFFIXES: $(SUFFIXES) .src
# .SUFFIXES: $(SUFFIXES) .bt

#
# %.bt:	%.src
#	$(GENICONVTBL) -o $@ -f $<

#   include ../../Makefile.targ
// ident	"%Z%%M%	%I%	%E% SMI"
// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
// Use is subject to license terms.
//
// CDDL HEADER START
//
// The contents of this file are subject to the terms of the
// Common Development and Distribution License, Version 1.0 only
// (the "License").  You may not use this file except in compliance
// with the License.
//
// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
// or http://www.opensolaris.org/os/licensing.
// See the License for the specific language governing permissions
// and limitations under the License.
//
// When distributing Covered Code, include this CDDL HEADER in each
// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
// If applicable, add the following below this CDDL HEADER, with the
// fields enclosed by brackets "[]" replaced with your own identifying
// information: Portions Copyright [yyyy] [name of copyright owner]
//
// CDDL HEADER END
//

//
// UTF-8 to ISO8859-1 mapping:
//

UTF-8%ISO8859-1 {
    direction {
	condition {
		between 0x0...0x7f;
	} map {
		0x0...0x7f	0x0
	};

	condition {
		between 0xc280...0xc3bf;
	} map {
		0xc280		0x80
		0xc281		0x81
		0xc282		0x82
		0xc283		0x83
		0xc284		0x84
		0xc285		0x85
		0xc286		0x86
		0xc287		0x87
		0xc288		0x88
		0xc289		0x89
		0xc28a		0x8a
		0xc28b		0x8b
		0xc28c		0x8c
		0xc28d		0x8d
		0xc28e		0x8e
		0xc28f		0x8f
		0xc290		0x90
		0xc291		0x91
		0xc292		0x92
		0xc293		0x93
		0xc294		0x94
		0xc295		0x95
		0xc296		0x96
		0xc297		0x97
		0xc298		0x98
		0xc299		0x99
		0xc29a		0x9a
		0xc29b		0x9b
		0xc29c		0x9c
		0xc29d		0x9d
		0xc29e		0x9e
		0xc29f		0x9f
		0xc2a0		0xa0
		0xc2a1		0xa1
		0xc2a2		0xa2
		0xc2a3		0xa3
		0xc2a4		0xa4
		0xc2a5		0xa5
		0xc2a6		0xa6
		0xc2a7		0xa7
		0xc2a8		0xa8
		0xc2a9		0xa9
		0xc2aa		0xaa
		0xc2ab		0xab
		0xc2ac		0xac
		0xc2ad		0xad
		0xc2ae		0xae
		0xc2af		0xaf
		0xc2b0		0xb0
		0xc2b1		0xb1
		0xc2b2		0xb2
		0xc2b3		0xb3
		0xc2b4		0xb4
		0xc2b5		0xb5
		0xc2b6		0xb6
		0xc2b7		0xb7
		0xc2b8		0xb8
		0xc2b9		0xb9
		0xc2ba		0xba
		0xc2bb		0xbb
		0xc2bc		0xbc
		0xc2bd		0xbd
		0xc2be		0xbe
		0xc2bf		0xbf
		0xc380		0xc0
		0xc381		0xc1
		0xc382		0xc2
		0xc383		0xc3
		0xc384		0xc4
		0xc385		0xc5
		0xc386		0xc6
		0xc387		0xc7
		0xc388		0xc8
		0xc389		0xc9
		0xc38a		0xca
		0xc38b		0xcb
		0xc38c		0xcc
		0xc38d		0xcd
		0xc38e		0xce
		0xc38f		0xcf
		0xc390		0xd0
		0xc391		0xd1
		0xc392		0xd2
		0xc393		0xd3
		0xc394		0xd4
		0xc395		0xd5
		0xc396		0xd6
		0xc397		0xd7
		0xc398		0xd8
		0xc399		0xd9
		0xc39a		0xda
		0xc39b		0xdb
		0xc39c		0xdc
		0xc39d		0xdd
		0xc39e		0xde
		0xc39f		0xdf
		0xc3a0		0xe0
		0xc3a1		0xe1
		0xc3a2		0xe2
		0xc3a3		0xe3
		0xc3a4		0xe4
		0xc3a5		0xe5
		0xc3a6		0xe6
		0xc3a7		0xe7
		0xc3a8		0xe8
		0xc3a9		0xe9
		0xc3aa		0xea
		0xc3ab		0xeb
		0xc3ac		0xec
		0xc3ad		0xed
		0xc3ae		0xee
		0xc3af		0xef
		0xc3b0		0xf0
		0xc3b1		0xf1
		0xc3b2		0xf2
		0xc3b3		0xf3
		0xc3b4		0xf4
		0xc3b5		0xf5
		0xc3b6		0xf6
		0xc3b7		0xf7
		0xc3b8		0xf8
		0xc3b9		0xf9
		0xc3ba		0xfa
		0xc3bb		0xfb
		0xc3bc		0xfc
		0xc3bd		0xfd
		0xc3be		0xfe
		0xc3bf		0xff
	};

	// We convert every other character to '?', i.e., non-identical
	// character.
	true 	operation {
		output = 0x3f;
		discard 1;
	};
   };
}

// Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
// Use is subject to license terms.
//
// CDDL HEADER START
//
// The contents of this file are subject to the terms of the
// Common Development and Distribution License, Version 1.0 only
// (the "License").  You may not use this file except in compliance
// with the License.
//
// You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
// or http://www.opensolaris.org/os/licensing.
// See the License for the specific language governing permissions
// and limitations under the License.
//
// When distributing Covered Code, include this CDDL HEADER in each
// file and include the License file at usr/src/OPENSOLARIS.LICENSE.
// If applicable, add the following below this CDDL HEADER, with the
// fields enclosed by brackets "[]" replaced with your own identifying
// information: Portions Copyright [yyyy] [name of copyright owner]
//
// CDDL HEADER END
//
// ident	"%Z%%M%	%I%	%E% SMI"

//
// eucJP to SJIS
//


#include <sys/errno.h>
#define	SS2	0x008e
#define	SS3	0x008f

eucJP%SJIS {
	operation init {
		cs = 0;
		offset = 0;
	};

	direction {

		condition {
			cs == 2;
		} operation {
			output = input[0];
			cs = 0;
			discard;
		};

		condition {
			cs == 1;
		} operation {
			var_input = input[0] & 0x7f;
			var_input = var_input + offset; 
			if (var_input >= 0x7f) {
				var_input = var_input + 0x01; 
			}
			output = var_input;
			cs = 0;
			discard;
		};

		condition { 
			between 0x00 ... 0x7f ;
		} operation {
			if ( outputsize < 1 ) {
				error E2BIG;
			}
			output = input[0];
			discard;
		};

		condition {
			between SS2 ... SS2 ;
		} operation {
			// Note this, in the .c file check is made
			// against ileft > 0 ,  but it's since the
			// ileft is already decremented.

			if ( inputsize > 1 ) {
				if ( ( input[1] >= 0xa1 ) && ( input[1] <= 0xfe )) {
					if (outputsize < 1 ) {
						error E2BIG;
					}
					cs = 2;
				} else {
					error EILSEQ;
				}
			} else {
				error EINVAL;
			}
		};

		condition {
			between 0xa1 ... 0xfe;
		} operation {
			if ( inputsize > 1 ) {
				if ( ( input[1]   >= 0xa1 ) && (  input[1]  <= 0xfe)) {
					if ( outputsize < 2 ) {
						error E2BIG;
					}

					cs = 1;
					var_input = input[0] & 0x7f;
					if ( var_input & 0x01) {
						offset = 0x1f;
					} else {
						offset = 0x7d;
					}
					var_input = ((var_input - 0x21 ) >> 1) + 0x81;
					if ( var_input > 0x9f ) {
						var_input = var_input + 0x40;
					}
					output = var_input;
					discard;

				} else {
					error EINVAL;
				}
			} else {
				error EILSEQ;
			}
		};

		true operation {
			error EILSEQ;
		};
	};
	
}