forked from HandBrake/HandBrake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeccc608sub.c
2539 lines (2396 loc) · 77.5 KB
/
deccc608sub.c
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
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* From ccextractor, leave this file as intact and close to the original as possible so that
* it is easy to patch in fixes - even though this file contains code that we don't need.
*
* Note that the SRT sub generation from CC could be useful for mkv subs.
*/
#include "hb.h"
#include "deccc608sub.h"
/*
* ccextractor static configuration variables.
*/
static int debug_608 = 0;
static int trim_subs = 1;
static int nofontcolor = 0;
static enum encoding_type encoding = ENC_UTF_8;
static int cc_channel = 1;
static enum output_format write_format = OF_SRT;
static int sentence_cap = 0;
static int subs_delay = 0;
static int64_t screens_to_process = -1;
static int processed_enough = 0;
static int gui_mode_reports = 0;
static int norollup = 1;
static int direct_rollup = 0;
/*
* Get the time of the last buffer that we have received.
*/
static int64_t get_fts(struct s_write *wb)
{
return wb->last_pts;
}
#define fatal(N, ...) // N
#define XMLRPC_APPEND(N, ...) // N
int rowdata[] = {11,-1,1,2,3,4,12,13,14,15,5,6,7,8,9,10};
// Relationship between the first PAC byte and the row number
// The following enc_buffer is not used at the moment, if it does get used
// we need to bring it into the swrite struct. Same for "str".
#define INITIAL_ENC_BUFFER_CAPACITY 2048
unsigned char str[2048]; // Another generic general purpose buffer
#define GUARANTEE(wb, length) if (length>wb->enc_buffer_capacity) \
{wb->enc_buffer_capacity*=2; wb->enc_buffer=(unsigned char*) realloc (wb->enc_buffer, wb->enc_buffer_capacity); \
if (wb->enc_buffer==NULL) { fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory, bailing out\n"); } \
}
const unsigned char pac2_attribs[][3]= // Color, font, ident
{
{COL_WHITE, FONT_REGULAR, 0}, // 0x40 || 0x60
{COL_WHITE, FONT_UNDERLINED, 0}, // 0x41 || 0x61
{COL_GREEN, FONT_REGULAR, 0}, // 0x42 || 0x62
{COL_GREEN, FONT_UNDERLINED, 0}, // 0x43 || 0x63
{COL_BLUE, FONT_REGULAR, 0}, // 0x44 || 0x64
{COL_BLUE, FONT_UNDERLINED, 0}, // 0x45 || 0x65
{COL_CYAN, FONT_REGULAR, 0}, // 0x46 || 0x66
{COL_CYAN, FONT_UNDERLINED, 0}, // 0x47 || 0x67
{COL_RED, FONT_REGULAR, 0}, // 0x48 || 0x68
{COL_RED, FONT_UNDERLINED, 0}, // 0x49 || 0x69
{COL_YELLOW, FONT_REGULAR, 0}, // 0x4a || 0x6a
{COL_YELLOW, FONT_UNDERLINED, 0}, // 0x4b || 0x6b
{COL_MAGENTA, FONT_REGULAR, 0}, // 0x4c || 0x6c
{COL_MAGENTA, FONT_UNDERLINED, 0}, // 0x4d || 0x6d
{COL_WHITE, FONT_ITALICS, 0}, // 0x4e || 0x6e
{COL_WHITE, FONT_UNDERLINED_ITALICS, 0}, // 0x4f || 0x6f
{COL_WHITE, FONT_REGULAR, 0}, // 0x50 || 0x70
{COL_WHITE, FONT_UNDERLINED, 0}, // 0x51 || 0x71
{COL_WHITE, FONT_REGULAR, 4}, // 0x52 || 0x72
{COL_WHITE, FONT_UNDERLINED, 4}, // 0x53 || 0x73
{COL_WHITE, FONT_REGULAR, 8}, // 0x54 || 0x74
{COL_WHITE, FONT_UNDERLINED, 8}, // 0x55 || 0x75
{COL_WHITE, FONT_REGULAR, 12}, // 0x56 || 0x76
{COL_WHITE, FONT_UNDERLINED, 12}, // 0x57 || 0x77
{COL_WHITE, FONT_REGULAR, 16}, // 0x58 || 0x78
{COL_WHITE, FONT_UNDERLINED, 16}, // 0x59 || 0x79
{COL_WHITE, FONT_REGULAR, 20}, // 0x5a || 0x7a
{COL_WHITE, FONT_UNDERLINED, 20}, // 0x5b || 0x7b
{COL_WHITE, FONT_REGULAR, 24}, // 0x5c || 0x7c
{COL_WHITE, FONT_UNDERLINED, 24}, // 0x5d || 0x7d
{COL_WHITE, FONT_REGULAR, 28}, // 0x5e || 0x7e
{COL_WHITE, FONT_UNDERLINED, 28} // 0x5f || 0x7f
};
// Preencoded strings
unsigned char encoded_crlf[16];
unsigned int encoded_crlf_length;
unsigned char encoded_br[16];
unsigned int encoded_br_length;
// Default color
unsigned char usercolor_rgb[8]="";
enum color_code default_color=COL_WHITE;
const char *sami_header= // TODO: Revise the <!-- comments
"<SAMI>\n\
<HEAD>\n\
<STYLE TYPE=\"text/css\">\n\
<!--\n\
P {margin-left: 16pt; margin-right: 16pt; margin-bottom: 16pt; margin-top: 16pt;\n\
text-align: center; font-size: 18pt; font-family: arial; font-weight: bold; color: #f0f0f0;}\n\
.UNKNOWNCC {Name:Unknown; lang:en-US; SAMIType:CC;}\n\
-->\n\
</STYLE>\n\
</HEAD>\n\n\
<BODY>\n";
const char *command_type[] =
{
"Unknown",
"EDM - EraseDisplayedMemory",
"RCL - ResumeCaptionLoading",
"EOC - End Of Caption",
"TO1 - Tab Offset, 1 column",
"TO2 - Tab Offset, 2 column",
"TO3 - Tab Offset, 3 column",
"RU2 - Roll up 2 rows",
"RU3 - Roll up 3 rows",
"RU4 - Roll up 4 rows",
"CR - Carriage Return",
"ENM - Erase non-displayed memory",
"BS - Backspace",
"RTD - Resume Text Display"
};
const char *font_text[]=
{
"regular",
"italics",
"underlined",
"underlined italics"
};
const char *cc_modes_text[]=
{
"Pop-Up captions"
};
const char *color_text[][2]=
{
{"white",""},
{"green","<font color=\"#00ff00\">"},
{"blue","<font color=\"#0000ff\">"},
{"cyan","<font color=\"#00ffff\">"},
{"red","<font color=\"#ff0000\">"},
{"yellow","<font color=\"#ffff00\">"},
{"magenta","<font color=\"#ff00ff\">"},
{"userdefined","<font color=\""}
};
int general_608_init (struct s_write *wb)
{
if( !wb->enc_buffer )
{
wb->enc_buffer=(unsigned char *) malloc (INITIAL_ENC_BUFFER_CAPACITY);
if (wb->enc_buffer==NULL)
return -1;
wb->enc_buffer_capacity=INITIAL_ENC_BUFFER_CAPACITY;
}
if( !wb->subline) {
wb->subline = malloc(2048);
if (!wb->subline)
{
return -1;
}
}
wb->new_sentence = 1;
wb->new_channel = 1;
wb->in_xds_mode = 0;
wb->hb_buffer = NULL;
wb->hb_last_buffer = NULL;
wb->last_pts = 0;
return 0;
}
/*
* Free up CC memory - don't call this from HB just yet since it will cause
* parallel encodes to fail - to be honest they will be stuffed anyway since
* the CC's may be overwriting the buffers.
*/
void general_608_close (struct s_write *wb)
{
if( wb->enc_buffer ) {
free(wb->enc_buffer);
wb->enc_buffer_capacity = 0;
wb->enc_buffer_used = 0;
}
if( wb->subline ) {
free(wb->subline);
}
if( wb->hb_buffer ) {
hb_buffer_close( &wb->hb_buffer );
}
}
#include <ctype.h>
void get_char_in_latin_1 (unsigned char *buffer, unsigned char c)
{
unsigned char c1='?';
if (c<0x80)
{
// Regular line-21 character set, mostly ASCII except these exceptions
switch (c)
{
case 0x2a: // lowercase a, acute accent
c1=0xe1;
break;
case 0x5c: // lowercase e, acute accent
c1=0xe9;
break;
case 0x5e: // lowercase i, acute accent
c1=0xed;
break;
case 0x5f: // lowercase o, acute accent
c1=0xf3;
break;
case 0x60: // lowercase u, acute accent
c1=0xfa;
break;
case 0x7b: // lowercase c with cedilla
c1=0xe7;
break;
case 0x7c: // division symbol
c1=0xf7;
break;
case 0x7d: // uppercase N tilde
c1=0xd1;
break;
case 0x7e: // lowercase n tilde
c1=0xf1;
break;
default:
c1=c;
break;
}
*buffer=c1;
return;
}
switch (c)
{
// THIS BLOCK INCLUDES THE 16 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x11 AND LOW BETWEEN 0x30 AND 0x3F
case 0x80: // Registered symbol (R)
c1=0xae;
break;
case 0x81: // degree sign
c1=0xb0;
break;
case 0x82: // 1/2 symbol
c1=0xbd;
break;
case 0x83: // Inverted (open) question mark
c1=0xbf;
break;
case 0x84: // Trademark symbol (TM) - Does not exist in Latin 1
break;
case 0x85: // Cents symbol
c1=0xa2;
break;
case 0x86: // Pounds sterling
c1=0xa3;
break;
case 0x87: // Music note - Not in latin 1, so we use 'pilcrow'
c1=0xb6;
break;
case 0x88: // lowercase a, grave accent
c1=0xe0;
break;
case 0x89: // transparent space, we make it regular
c1=0x20;
break;
case 0x8a: // lowercase e, grave accent
c1=0xe8;
break;
case 0x8b: // lowercase a, circumflex accent
c1=0xe2;
break;
case 0x8c: // lowercase e, circumflex accent
c1=0xea;
break;
case 0x8d: // lowercase i, circumflex accent
c1=0xee;
break;
case 0x8e: // lowercase o, circumflex accent
c1=0xf4;
break;
case 0x8f: // lowercase u, circumflex accent
c1=0xfb;
break;
// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x12 AND LOW BETWEEN 0x20 AND 0x3F
case 0x90: // capital letter A with acute
c1=0xc1;
break;
case 0x91: // capital letter E with acute
c1=0xc9;
break;
case 0x92: // capital letter O with acute
c1=0xd3;
break;
case 0x93: // capital letter U with acute
c1=0xda;
break;
case 0x94: // capital letter U with diaresis
c1=0xdc;
break;
case 0x95: // lowercase letter U with diaeresis
c1=0xfc;
break;
case 0x96: // apostrophe
c1=0x27;
break;
case 0x97: // inverted exclamation mark
c1=0xa1;
break;
case 0x98: // asterisk
c1=0x2a;
break;
case 0x99: // apostrophe (yes, duped). See CCADI source code.
c1=0x27;
break;
case 0x9a: // hyphen-minus
c1=0x2d;
break;
case 0x9b: // copyright sign
c1=0xa9;
break;
case 0x9c: // Service Mark - not available in latin 1
break;
case 0x9d: // Full stop (.)
c1=0x2e;
break;
case 0x9e: // Quoatation mark
c1=0x22;
break;
case 0x9f: // Quoatation mark
c1=0x22;
break;
case 0xa0: // uppercase A, grave accent
c1=0xc0;
break;
case 0xa1: // uppercase A, circumflex
c1=0xc2;
break;
case 0xa2: // uppercase C with cedilla
c1=0xc7;
break;
case 0xa3: // uppercase E, grave accent
c1=0xc8;
break;
case 0xa4: // uppercase E, circumflex
c1=0xca;
break;
case 0xa5: // capital letter E with diaresis
c1=0xcb;
break;
case 0xa6: // lowercase letter e with diaresis
c1=0xeb;
break;
case 0xa7: // uppercase I, circumflex
c1=0xce;
break;
case 0xa8: // uppercase I, with diaresis
c1=0xcf;
break;
case 0xa9: // lowercase i, with diaresis
c1=0xef;
break;
case 0xaa: // uppercase O, circumflex
c1=0xd4;
break;
case 0xab: // uppercase U, grave accent
c1=0xd9;
break;
case 0xac: // lowercase u, grave accent
c1=0xf9;
break;
case 0xad: // uppercase U, circumflex
c1=0xdb;
break;
case 0xae: // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
c1=0xab;
break;
case 0xaf: // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
c1=0xbb;
break;
// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x13 AND LOW BETWEEN 0x20 AND 0x3F
case 0xb0: // Uppercase A, tilde
c1=0xc3;
break;
case 0xb1: // Lowercase a, tilde
c1=0xe3;
break;
case 0xb2: // Uppercase I, acute accent
c1=0xcd;
break;
case 0xb3: // Uppercase I, grave accent
c1=0xcc;
break;
case 0xb4: // Lowercase i, grave accent
c1=0xec;
break;
case 0xb5: // Uppercase O, grave accent
c1=0xd2;
break;
case 0xb6: // Lowercase o, grave accent
c1=0xf2;
break;
case 0xb7: // Uppercase O, tilde
c1=0xd5;
break;
case 0xb8: // Lowercase o, tilde
c1=0xf5;
break;
case 0xb9: // Open curly brace
c1=0x7b;
break;
case 0xba: // Closing curly brace
c1=0x7d;
break;
case 0xbb: // Backslash
c1=0x5c;
break;
case 0xbc: // Caret
c1=0x5e;
break;
case 0xbd: // Underscore
c1=0x5f;
break;
case 0xbe: // Pipe (broken bar)
c1=0xa6;
break;
case 0xbf: // Tilde
c1=0x7e;
break;
case 0xc0: // Uppercase A, umlaut
c1=0xc4;
break;
case 0xc1: // Lowercase A, umlaut
c1=0xe3;
break;
case 0xc2: // Uppercase O, umlaut
c1=0xd6;
break;
case 0xc3: // Lowercase o, umlaut
c1=0xf6;
break;
case 0xc4: // Esszett (sharp S)
c1=0xdf;
break;
case 0xc5: // Yen symbol
c1=0xa5;
break;
case 0xc6: // Currency symbol
c1=0xa4;
break;
case 0xc7: // Vertical bar
c1=0x7c;
break;
case 0xc8: // Uppercase A, ring
c1=0xc5;
break;
case 0xc9: // Lowercase A, ring
c1=0xe5;
break;
case 0xca: // Uppercase O, slash
c1=0xd8;
break;
case 0xcb: // Lowercase o, slash
c1=0xf8;
break;
case 0xcc: // Upper left corner
case 0xcd: // Upper right corner
case 0xce: // Lower left corner
case 0xcf: // Lower right corner
default: // For those that don't have representation
*buffer='?'; // I'll do it eventually, I promise
break; // This are weird chars anyway
}
*buffer=c1;
}
void get_char_in_unicode (unsigned char *buffer, unsigned char c)
{
unsigned char c1,c2;
switch (c)
{
case 0x84: // Trademark symbol (TM)
c2=0x21;
c1=0x22;
break;
case 0x87: // Music note
c2=0x26;
c1=0x6a;
break;
case 0x9c: // Service Mark
c2=0x21;
c1=0x20;
break;
case 0xcc: // Upper left corner
c2=0x23;
c1=0x1c;
break;
case 0xcd: // Upper right corner
c2=0x23;
c1=0x1d;
break;
case 0xce: // Lower left corner
c2=0x23;
c1=0x1e;
break;
case 0xcf: // Lower right corner
c2=0x23;
c1=0x1f;
break;
default: // Everything else, same as latin-1 followed by 00
get_char_in_latin_1 (&c1,c);
c2=0;
break;
}
*buffer=c1;
*(buffer+1)=c2;
}
int get_char_in_utf_8 (unsigned char *buffer, unsigned char c) // Returns number of bytes used
{
if (c==0x00)
return 0;
if (c<0x80) // Regular line-21 character set, mostly ASCII except these exceptions
{
switch (c)
{
case 0x2a: // lowercase a, acute accent
*buffer=0xc3;
*(buffer+1)=0xa1;
return 2;
case 0x5c: // lowercase e, acute accent
*buffer=0xc3;
*(buffer+1)=0xa9;
return 2;
case 0x5e: // lowercase i, acute accent
*buffer=0xc3;
*(buffer+1)=0xad;
return 2;
case 0x5f: // lowercase o, acute accent
*buffer=0xc3;
*(buffer+1)=0xb3;
return 2;
case 0x60: // lowercase u, acute accent
*buffer=0xc3;
*(buffer+1)=0xba;
return 2;
case 0x7b: // lowercase c with cedilla
*buffer=0xc3;
*(buffer+1)=0xa7;
return 2;
case 0x7c: // division symbol
*buffer=0xc3;
*(buffer+1)=0xb7;
return 2;
case 0x7d: // uppercase N tilde
*buffer=0xc3;
*(buffer+1)=0x91;
return 2;
case 0x7e: // lowercase n tilde
*buffer=0xc3;
*(buffer+1)=0xb1;
return 2;
default:
*buffer=c;
return 1;
}
}
switch (c)
{
// THIS BLOCK INCLUDES THE 16 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x11 AND LOW BETWEEN 0x30 AND 0x3F
case 0x80: // Registered symbol (R)
*buffer=0xc2;
*(buffer+1)=0xae;
return 2;
case 0x81: // degree sign
*buffer=0xc2;
*(buffer+1)=0xb0;
return 2;
case 0x82: // 1/2 symbol
*buffer=0xc2;
*(buffer+1)=0xbd;
return 2;
case 0x83: // Inverted (open) question mark
*buffer=0xc2;
*(buffer+1)=0xbf;
return 2;
case 0x84: // Trademark symbol (TM)
*buffer=0xe2;
*(buffer+1)=0x84;
*(buffer+2)=0xa2;
return 3;
case 0x85: // Cents symbol
*buffer=0xc2;
*(buffer+1)=0xa2;
return 2;
case 0x86: // Pounds sterling
*buffer=0xc2;
*(buffer+1)=0xa3;
return 2;
case 0x87: // Music note
*buffer=0xe2;
*(buffer+1)=0x99;
*(buffer+2)=0xaa;
return 3;
case 0x88: // lowercase a, grave accent
*buffer=0xc3;
*(buffer+1)=0xa0;
return 2;
case 0x89: // transparent space, we make it regular
*buffer=0x20;
return 1;
case 0x8a: // lowercase e, grave accent
*buffer=0xc3;
*(buffer+1)=0xa8;
return 2;
case 0x8b: // lowercase a, circumflex accent
*buffer=0xc3;
*(buffer+1)=0xa2;
return 2;
case 0x8c: // lowercase e, circumflex accent
*buffer=0xc3;
*(buffer+1)=0xaa;
return 2;
case 0x8d: // lowercase i, circumflex accent
*buffer=0xc3;
*(buffer+1)=0xae;
return 2;
case 0x8e: // lowercase o, circumflex accent
*buffer=0xc3;
*(buffer+1)=0xb4;
return 2;
case 0x8f: // lowercase u, circumflex accent
*buffer=0xc3;
*(buffer+1)=0xbb;
return 2;
// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x12 AND LOW BETWEEN 0x20 AND 0x3F
case 0x90: // capital letter A with acute
*buffer=0xc3;
*(buffer+1)=0x81;
return 2;
case 0x91: // capital letter E with acute
*buffer=0xc3;
*(buffer+1)=0x89;
return 2;
case 0x92: // capital letter O with acute
*buffer=0xc3;
*(buffer+1)=0x93;
return 2;
case 0x93: // capital letter U with acute
*buffer=0xc3;
*(buffer+1)=0x9a;
return 2;
case 0x94: // capital letter U with diaresis
*buffer=0xc3;
*(buffer+1)=0x9c;
return 2;
case 0x95: // lowercase letter U with diaeresis
*buffer=0xc3;
*(buffer+1)=0xbc;
return 2;
case 0x96: // apostrophe
*buffer=0x27;
return 1;
case 0x97: // inverted exclamation mark
*buffer=0xc2;
*(buffer+1)=0xa1;
return 2;
case 0x98: // asterisk
*buffer=0x2a;
return 1;
case 0x99: // apostrophe (yes, duped). See CCADI source code.
*buffer=0x27;
return 1;
case 0x9a: // hyphen-minus
*buffer=0x2d;
return 1;
case 0x9b: // copyright sign
*buffer=0xc2;
*(buffer+1)=0xa9;
return 2;
case 0x9c: // Service mark
*buffer=0xe2;
*(buffer+1)=0x84;
*(buffer+2)=0xa0;
return 3;
case 0x9d: // Full stop (.)
*buffer=0x2e;
return 1;
case 0x9e: // Quoatation mark
*buffer=0x22;
return 1;
case 0x9f: // Quoatation mark
*buffer=0x22;
return 1;
case 0xa0: // uppercase A, grave accent
*buffer=0xc3;
*(buffer+1)=0x80;
return 2;
case 0xa1: // uppercase A, circumflex
*buffer=0xc3;
*(buffer+1)=0x82;
return 2;
case 0xa2: // uppercase C with cedilla
*buffer=0xc3;
*(buffer+1)=0x87;
return 2;
case 0xa3: // uppercase E, grave accent
*buffer=0xc3;
*(buffer+1)=0x88;
return 2;
case 0xa4: // uppercase E, circumflex
*buffer=0xc3;
*(buffer+1)=0x8a;
return 2;
case 0xa5: // capital letter E with diaresis
*buffer=0xc3;
*(buffer+1)=0x8b;
return 2;
case 0xa6: // lowercase letter e with diaresis
*buffer=0xc3;
*(buffer+1)=0xab;
return 2;
case 0xa7: // uppercase I, circumflex
*buffer=0xc3;
*(buffer+1)=0x8e;
return 2;
case 0xa8: // uppercase I, with diaresis
*buffer=0xc3;
*(buffer+1)=0x8f;
return 2;
case 0xa9: // lowercase i, with diaresis
*buffer=0xc3;
*(buffer+1)=0xaf;
return 2;
case 0xaa: // uppercase O, circumflex
*buffer=0xc3;
*(buffer+1)=0x94;
return 2;
case 0xab: // uppercase U, grave accent
*buffer=0xc3;
*(buffer+1)=0x99;
return 2;
case 0xac: // lowercase u, grave accent
*buffer=0xc3;
*(buffer+1)=0xb9;
return 2;
case 0xad: // uppercase U, circumflex
*buffer=0xc3;
*(buffer+1)=0x9b;
return 2;
case 0xae: // LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
*buffer=0xc2;
*(buffer+1)=0xab;
return 2;
case 0xaf: // RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
*buffer=0xc2;
*(buffer+1)=0xbb;
return 2;
// THIS BLOCK INCLUDES THE 32 EXTENDED (TWO-BYTE) LINE 21 CHARACTERS
// THAT COME FROM HI BYTE=0x13 AND LOW BETWEEN 0x20 AND 0x3F
case 0xb0: // Uppercase A, tilde
*buffer=0xc3;
*(buffer+1)=0x83;
return 2;
case 0xb1: // Lowercase a, tilde
*buffer=0xc3;
*(buffer+1)=0xa3;
return 2;
case 0xb2: // Uppercase I, acute accent
*buffer=0xc3;
*(buffer+1)=0x8d;
return 2;
case 0xb3: // Uppercase I, grave accent
*buffer=0xc3;
*(buffer+1)=0x8c;
return 2;
case 0xb4: // Lowercase i, grave accent
*buffer=0xc3;
*(buffer+1)=0xac;
return 2;
case 0xb5: // Uppercase O, grave accent
*buffer=0xc3;
*(buffer+1)=0x92;
return 2;
case 0xb6: // Lowercase o, grave accent
*buffer=0xc3;
*(buffer+1)=0xb2;
return 2;
case 0xb7: // Uppercase O, tilde
*buffer=0xc3;
*(buffer+1)=0x95;
return 2;
case 0xb8: // Lowercase o, tilde
*buffer=0xc3;
*(buffer+1)=0xb5;
return 2;
case 0xb9: // Open curly brace
*buffer=0x7b;
return 1;
case 0xba: // Closing curly brace
*buffer=0x7d;
return 1;
case 0xbb: // Backslash
*buffer=0x5c;
return 1;
case 0xbc: // Caret
*buffer=0x5e;
return 1;
case 0xbd: // Underscore
*buffer=0x5f;
return 1;
case 0xbe: // Pipe (broken bar)
*buffer=0xc2;
*(buffer+1)=0xa6;
return 1;
case 0xbf: // Tilde
*buffer=0x7e; // Not sure
return 1;
case 0xc0: // Uppercase A, umlaut
*buffer=0xc3;
*(buffer+1)=0x84;
return 2;
case 0xc1: // Lowercase A, umlaut
*buffer=0xc3;
*(buffer+1)=0xa4;
return 2;
case 0xc2: // Uppercase O, umlaut
*buffer=0xc3;
*(buffer+1)=0x96;
return 2;
case 0xc3: // Lowercase o, umlaut
*buffer=0xc3;
*(buffer+1)=0xb6;
return 2;
case 0xc4: // Esszett (sharp S)
*buffer=0xc3;
*(buffer+1)=0x9f;
return 2;
case 0xc5: // Yen symbol
*buffer=0xc2;
*(buffer+1)=0xa5;
return 2;
case 0xc6: // Currency symbol
*buffer=0xc2;
*(buffer+1)=0xa4;
return 2;
case 0xc7: // Vertical bar
*buffer=0x7c;
return 1;
case 0xc8: // Uppercase A, ring
*buffer=0xc3;
*(buffer+1)=0x85;
return 2;
case 0xc9: // Lowercase A, ring
*buffer=0xc3;
*(buffer+1)=0xa5;
return 2;
case 0xca: // Uppercase O, slash
*buffer=0xc3;
*(buffer+1)=0x98;
return 2;
case 0xcb: // Lowercase o, slash
*buffer=0xc3;
*(buffer+1)=0xb8;
return 2;
case 0xcc: // Upper left corner
*buffer=0xe2;
*(buffer+1)=0x8c;
*(buffer+2)=0x9c;
return 3;
case 0xcd: // Upper right corner
*buffer=0xe2;
*(buffer+1)=0x8c;
*(buffer+2)=0x9d;
return 3;
case 0xce: // Lower left corner
*buffer=0xe2;
*(buffer+1)=0x8c;
*(buffer+2)=0x9e;
return 3;
case 0xcf: // Lower right corner
*buffer=0xe2;
*(buffer+1)=0x8c;
*(buffer+2)=0x9f;
return 3;
default: //
*buffer='?'; // I'll do it eventually, I promise
return 1; // This are weird chars anyway
}
}
unsigned char cctolower (unsigned char c)
{
if (c>='A' && c<='Z')
return tolower(c);
switch (c)
{
case 0x7d: // uppercase N tilde
return 0x7e;
case 0x90: // capital letter A with acute
return 0x2a;
case 0x91: // capital letter E with acute
return 0x5c;
case 0x92: // capital letter O with acute
return 0x5f;
case 0x93: // capital letter U with acute
return 0x60;
case 0xa2: // uppercase C with cedilla
return 0x7b;
case 0xa0: // uppercase A, grave accent
return 0x88;
case 0xa3: // uppercase E, grave accent
return 0x8a;
case 0xa1: // uppercase A, circumflex
return 0x8b;
case 0xa4: // uppercase E, circumflex
return 0x8c;
case 0xa7: // uppercase I, circumflex
return 0x8d;
case 0xaa: // uppercase O, circumflex
return 0x8e;
case 0xad: // uppercase U, circumflex
return 0x8f;
case 0x94: // capital letter U with diaresis
return 0x95;
case 0xa5: // capital letter E with diaresis
return 0xa6;
case 0xa8: // uppercase I, with diaresis
return 0xa9;
case 0xab: // uppercase U, grave accent
return 0xac;
case 0xb0: // Uppercase A, tilde
return 0xb1;
case 0xb2: // Uppercase I, acute accent
return 0x5e;
case 0xb3: // Uppercase I, grave accent
return 0xb4;
case 0xb5: // Uppercase O, grave accent
return 0xb6;
case 0xb7: // Uppercase O, tilde
return 0xb8;
case 0xc0: // Uppercase A, umlaut
return 0xc1;
case 0xc2: // Uppercase O, umlaut
return 0xc3;
case 0xc8: // Uppercase A, ring
return 0xc9;
case 0xca: // Uppercase O, slash
return 0xcb;
}
return c;
}
unsigned char cctoupper (unsigned char c)
{
if (c>='a' && c<='z')
return toupper(c);
switch (c)
{
case 0x7e: // lowercase n tilde
return 0x7d;
case 0x2a: // lowercase a, acute accent
return 0x90;
case 0x5c: // lowercase e, acute accent
return 0x91;
case 0x5e: // lowercase i, acute accent
return 0xb2;
case 0x5f: // lowercase o, acute accent
return 0x92;
case 0x60: // lowercase u, acute accent
return 0x93;
case 0x7b: // lowercase c with cedilla
return 0xa2;
case 0x88: // lowercase a, grave accent
return 0xa0;
case 0x8a: // lowercase e, grave accent
return 0xa3;
case 0x8b: // lowercase a, circumflex accent
return 0xa1;
case 0x8c: // lowercase e, circumflex accent
return 0xa4;